import {z} from 'zod' export type GetApiV2IndividualsEntityIdExternalreferencesArgs = {api_key: string, 'X-Frankie-CustomerID': string, 'X-Frankie-CustomerChildID'?: string | undefined, 'X-Frankie-Channel'?: string | undefined, 'X-Frankie-Username'?: string | undefined}; export type GetApiV2IndividualsEntityIdExternalreferencesOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const requestID = z.string(); export const externalReference = z.object({referenceId: z.string().optional(), type: z.enum(["SYSTEM", "CUSTOMER", "OTHER"]).optional(), sourceId: z.string().optional(), name: z.string(), value: z.string(), description: z.string().optional()}); export const getApiV2IndividualsEntityIdExternalreferencesResponse = z.object({requestId: requestID.optional(), externalReferences: z.array(externalReference).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get a list of external references * * GET /v2/individuals/{entityId}/externalreferences * * Also accepts auth: jwt */ export const getApiV2IndividualsEntityIdExternalreferences = async (args: GetApiV2IndividualsEntityIdExternalreferencesArgs, options?: GetApiV2IndividualsEntityIdExternalreferencesOptions) => { const {baseUrl = "https://api.uat.frankie.one", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.api_key != null) headers.set("api_key", String(args.api_key)) if (args['X-Frankie-CustomerID'] != null) headers.set("X-Frankie-CustomerID", String(args['X-Frankie-CustomerID'])) if (args['X-Frankie-CustomerChildID'] != null) headers.set("X-Frankie-CustomerChildID", String(args['X-Frankie-CustomerChildID'])) if (args['X-Frankie-Channel'] != null) headers.set("X-Frankie-Channel", String(args['X-Frankie-Channel'])) if (args['X-Frankie-Username'] != null) headers.set("X-Frankie-Username", String(args['X-Frankie-Username'])) if (ApiKey !== undefined) headers.set("api_key", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v2/individuals/${encodeURIComponent(String(args.entityId))}/externalreferences${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV2IndividualsEntityIdExternalreferencesResponse, await res.json()) };