import {z} from 'zod' export type Address = {country_code: unknown, line_1: unknown, line_2?: (unknown | null) | undefined, line_3?: (unknown | null) | undefined, line_4?: (unknown | null) | undefined}; export type IndividualCurrencyExtra = {country_of_birth: unknown, country_of_issuance: unknown, currency: 'usd', id_number: unknown, ip_address?: unknown | undefined, occupation_code: unknown}; export type Gender = 'male' | 'female' | 'undefined'; export type IndividualIdentification = {country_of_issuance: unknown, expiry_date: string, number: unknown, type: 'passport'} | {country_of_issuance: unknown, expiry_date: string, number: unknown, type: 'national_id'}; export type CustomerRelationshipType = 'direct' | {indirect: {parent_customer_id: string}}; export type AddIndividualRequest = {address: Address, currency_extra?: (Array | null) | undefined, date_of_birth: string, display_name: unknown, first_name: unknown, gender: Gender | null, identification?: (IndividualIdentification | null) | undefined, last_name: unknown, middle_name?: (unknown | null) | undefined, nationality: unknown, reference: unknown, relationship_type?: CustomerRelationshipType | undefined}; export type CreateApiV1CustomersIndividualsArgs = {'Idempotency-Key'?: (string | null) | undefined, body: AddIndividualRequest}; export type CreateApiV1CustomersIndividualsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const addCustomerResponse = z.object({id: z.string()}); 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 }; /** * Add individual * * POST /v1/customers/individuals */ export const createApiV1CustomersIndividuals = async (args: CreateApiV1CustomersIndividualsArgs, options?: CreateApiV1CustomersIndividualsOptions) => { const {baseUrl = "https://auth-sandbox.fuse.me", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/customers/individuals${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(addCustomerResponse, await res.json()) };