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 AddressCreateDTO = {address_line1: string, address_line2?: (string | null) | undefined, city: string, state: string, postal_code: string, country: string}; export type PersonCreateDTO = {identifications?: (Array | null) | undefined, birth_date?: (string | null) | undefined, email?: (string | null) | undefined, first_name: string, last_name: string, mobile_number?: (string | null) | undefined, base_address?: AddressCreateDTO | undefined, nationality?: (string | null) | undefined, client_reference_id?: (string | null) | undefined}; export type CreatePersonRequest = {create_account?: boolean | undefined, person_details: PersonCreateDTO, account_currencies?: (Array<'USD' | 'AED' | 'ALL' | 'AMD' | 'ANG' | 'AOA' | 'ARS' | 'AUD' | 'AWG' | 'AZN' | 'BAM' | 'BBD' | 'BDT' | 'BGN' | 'BHD' | 'BIF' | 'BMD' | 'BND' | 'BOB' | 'BRL' | 'BSD' | 'BTN' | 'BWP' | 'BZD' | 'CAD' | 'CDF' | 'CHF' | 'CLP' | 'CNY' | 'COP' | 'CRC' | 'CVE' | 'CZK' | 'DJF' | 'DKK' | 'DOP' | 'DZD' | 'EGP' | 'ERN' | 'ETB' | 'EUR' | 'FJD' | 'FKP' | 'FOK' | 'GBP' | 'GEL' | 'GGP' | 'GHS' | 'GIP' | 'GMD' | 'GNF' | 'GTQ' | 'GYD' | 'HKD' | 'HNL' | 'HNL' | 'HTG' | 'HUF' | 'IDR' | 'ILS' | 'IMP' | 'INR' | 'IQD' | 'ISK' | 'JEP' | 'JMD' | 'JOD' | 'JPY' | 'KES' | 'KGS' | 'KHR' | 'KID' | 'KMF' | 'KRW' | 'KWD' | 'KYD' | 'KZT' | 'LAK' | 'LBP' | 'LKR' | 'LRD' | 'LSL' | 'LYD' | 'MAD' | 'MDL' | 'MGA' | 'MKD' | 'MMK' | 'MNT' | 'MOP' | 'MRU' | 'MUR' | 'MVR' | 'MWK' | 'MXN' | 'MYR' | 'MZN' | 'NAD' | 'NGN' | 'NIO' | 'NOK' | 'NPR' | 'NZD' | 'OMR' | 'PAB' | 'PEN' | 'PGK' | 'PHP' | 'PKR' | 'PLN' | 'PYG' | 'QAR' | 'RON' | 'RSD' | 'SAR' | 'SBD' | 'SCR' | 'SDG' | 'SEK' | 'SGD' | 'SHP' | 'SLE' | 'SLL' | 'SOS' | 'SRD' | 'SSP' | 'STN' | 'SYP' | 'SZL' | 'THB' | 'TJS' | 'TMT' | 'TND' | 'TOP' | 'TRY' | 'TTD' | 'TVD' | 'TWD' | 'TZS' | 'UAH' | 'UGX' | 'UYU' | 'UZS' | 'VES' | 'VND' | 'VUV' | 'WST' | 'XAF' | 'XCD' | 'XOF' | 'XPF' | 'YER' | 'ZAR' | 'ZMW' | 'ZWL'> | null) | undefined, program_guid: string}; export type CreateApiConnectedDepositsVersionPersonsCreateArgs = {IdempotencyKey: string, version: string, body: CreatePersonRequest}; export type CreateApiConnectedDepositsVersionPersonsCreateOptions = {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 accountResponseDTO = z.object({account_guid: z.string().optional(), wallet_guid: z.string().optional(), account_currency: z.string().optional(), account_name: z.string().optional(), account_type: z.string().optional(), available_balance: z.number().optional(), ledger_balance: z.number().optional(), suspense_balance: z.number().optional(), account_status: z.string().optional(), sys_utcinserted: z.string().optional()}); export const walletResponseDTO = z.object({wallet_guid: z.string().optional(), wallet_id: z.string().optional(), person_guid: z.string().optional(), program_guid: z.string().optional(), account_status: z.string().optional(), accounts: z.array(accountResponseDTO).optional(), cards: z.array(z.unknown()).optional(), account_instruments: z.array(z.unknown()).optional()}); export const createPersonResponse = z.object({person_details: personResponseDTO.optional(), wallets: z.array(walletResponseDTO).nullable().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 }; /** * Create Person * * POST /connected-deposits/{version}/persons/create */ export const createApiConnectedDepositsVersionPersonsCreate = async (args: CreateApiConnectedDepositsVersionPersonsCreateArgs, options?: CreateApiConnectedDepositsVersionPersonsCreateOptions) => { 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 (args.IdempotencyKey != null) headers.set("IdempotencyKey", String(args.IdempotencyKey)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/connected-deposits/${encodeURIComponent(String(args.version))}/persons/create${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(createPersonResponse, await res.json()) };