import {z} from 'zod' export type GovtIDType = 'NOTPROVIDED' | 'PASSPORT' | 'DRIVERLICENSE' | 'COUNTRYID' | 'TIN'; export type PersonIdentificationDTO = {govt_id_type: GovtIDType, govt_id_number: string}; export type AddressUpdateDTO = {address_line1?: (string | null) | undefined, address_line2?: (string | null) | undefined, city?: (string | null) | undefined, state?: (string | null) | undefined, postal_code?: (string | null) | undefined, country?: (string | null) | undefined}; export type PersonUpdateDTO = {person_guid: string, identifications?: (Array | null) | undefined, birth_date?: (string | null) | undefined, email?: (string | null) | undefined, first_name?: (string | null) | undefined, last_name?: (string | null) | undefined, mobile_number?: (string | null) | undefined, base_address?: AddressUpdateDTO | undefined, nationality?: (string | null) | undefined, client_reference_id?: (string | null) | undefined}; export type UpdateApiConnectedDepositsVersionPersonsUpdateArgs = {version: string, body: PersonUpdateDTO}; export type UpdateApiConnectedDepositsVersionPersonsUpdateOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const govtIDType = z.enum(["NOTPROVIDED", "PASSPORT", "DRIVERLICENSE", "COUNTRYID", "TIN"]); export const personIdentificationDTO = z.object({govt_id_type: govtIDType, govt_id_number: z.string().min(1).max(800)}); export const addressUpdateDTO = z.object({address_line1: z.string().max(48).nullable().optional(), address_line2: z.string().max(48).nullable().optional(), city: z.string().max(30).nullable().optional(), state: z.string().max(30).nullable().optional(), postal_code: z.string().max(10).nullable().optional(), country: z.string().max(3).nullable().optional()}); export const personResponseDTO = z.object({person_guid: z.string().optional(), identifications: z.array(personIdentificationDTO).nullable().optional(), birth_date: z.string().nullable().optional(), email: z.string().nullable().optional(), first_name: z.string().max(32).optional(), last_name: z.string().max(32).optional(), mobile_number: z.string().nullable().optional(), base_address: addressUpdateDTO.optional(), nationality: z.string().max(3).nullable().optional(), client_reference_id: z.string().nullable().optional(), verfication_mode: z.string().optional(), verfication_level: z.string().optional(), address_lat: z.number().optional(), address_lon: z.number().optional(), ledger_balance: z.number().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 }; /** * Update Person * * PUT /connected-deposits/{version}/persons/update */ export const updateApiConnectedDepositsVersionPersonsUpdate = async (args: UpdateApiConnectedDepositsVersionPersonsUpdateArgs, options?: UpdateApiConnectedDepositsVersionPersonsUpdateOptions) => { const {baseUrl = "https://agw-ext.huntington.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/connected-deposits/${encodeURIComponent(String(args.version))}/persons/update${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(personResponseDTO, await res.json()) };