import {z} from 'zod' export type InstrumentType = 'BANKDDA' | 'IBAN' | 'BBAN' | 'CARD' | 'CHECK'; export type InstrumentCategory = 'INDIVIDUAL' | 'CORPORATE'; export type CardAccountCreate = {card_number: string, expiration_date: string, verification_code: string}; export type BankAccountType = 'DDA' | 'CHECKING' | 'SAVING'; export type BankAccountCreate = {account_type?: BankAccountType | undefined, account_number?: string | undefined, routing_number?: (string | null) | undefined, name_on_account?: (string | null) | undefined}; export type AccountInfoCreate = {card_account?: CardAccountCreate | undefined, bank_account?: BankAccountCreate | undefined}; export type CreateOutsideInstrumentRequest = {instrument_type: InstrumentType, instrument_category: InstrumentCategory, person_guid: string, instrument_country: string, financial_inst_name?: (string | null) | undefined, account_details: AccountInfoCreate}; export type CreateApiConnectedDepositsVersionOutsideInstrumentsCreateArgs = {version: string, IdempotencyKey: string, body: CreateOutsideInstrumentRequest}; export type CreateApiConnectedDepositsVersionOutsideInstrumentsCreateOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const instrumentType = z.enum(["BANKDDA", "IBAN", "BBAN", "CARD", "CHECK"]); export const instrumentCategory = z.enum(["INDIVIDUAL", "CORPORATE"]); export const cardAccount = z.object({card_number: z.string().min(13).max(19), expiration_date: z.string().min(4).max(4), verification_code: z.string().min(3).max(5).nullable().optional()}); export const bankAccountType = z.enum(["DDA", "CHECKING", "SAVING"]); export const addressDTO = z.object({city: z.string().optional(), country: z.string().optional(), address_line1: z.string().optional(), address_line2: z.string().nullable().optional(), postal_code: z.string().optional(), state: z.string().optional()}); export const bankAccount = z.object({account_type: bankAccountType, account_number: z.string().min(6).max(16), routing_number: z.string().min(6).max(16).nullable().optional(), bank_address: addressDTO.optional(), name_on_account: z.string().nullable().optional()}); export const accountInfo = z.object({card_account: cardAccount.optional(), bank_account: bankAccount.optional()}); export const instrumentStatus = z.enum(["ACTIVE", "SUSPEND", "NEGLIST", "FORGET", "UNPROVED", "REPLACED"]); export const outsideInstrumentDTO = z.object({outside_instrument_guid: z.string().optional(), person_guid: z.string().optional(), instrument_country: z.string().optional(), instrument_type: instrumentType.optional(), instrument_name: z.string().nullable().optional(), instrument_settlement_currency: z.string().nullable().optional(), instrument_category: instrumentCategory.optional(), instrument_usage: z.string().nullable().optional(), mask_account_number: z.string().nullable().optional(), account_details: accountInfo.optional(), financial_inst_name: z.string().nullable().optional(), instrument_status: instrumentStatus.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 Outside Instrument * * POST /connected-deposits/{version}/outside-instruments/create */ export const createApiConnectedDepositsVersionOutsideInstrumentsCreate = async (args: CreateApiConnectedDepositsVersionOutsideInstrumentsCreateArgs, options?: CreateApiConnectedDepositsVersionOutsideInstrumentsCreateOptions) => { 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))}/outside-instruments/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(outsideInstrumentDTO, await res.json()) };