import {z} from 'zod' export type CreateAccountInstrumentRequest = {account_guid: string}; export type CreateApiConnectedDepositsVersionAccountInstrumentsCreateArgs = {version: string, IdempotencyKey: string, body: CreateAccountInstrumentRequest}; export type CreateApiConnectedDepositsVersionAccountInstrumentsCreateOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const bankAccountType = z.enum(["DDA", "CHECKING", "SAVING"]); export const addressDTO = z.object({city: z.string().max(30).nullable().optional(), country: z.string().max(3).nullable().optional(), address_line1: z.string().max(48).nullable().optional(), address_line2: z.string().max(48).nullable().optional(), postal_code: z.string().max(10).nullable().optional(), state: z.string().max(30).nullable().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()}); export const instrumentType = z.enum(["BANKDDA", "IBAN", "BBAN", "CARD", "CHECK"]); export const instrumentStatus = z.enum(["ACTIVE", "SUSPEND", "NEGLIST", "FORGET", "UNPROVED", "REPLACED"]); export const accountInstrumentDTO = z.object({routing_number: z.string().min(6).max(16).nullable().optional(), account_instrument_guid: z.string().optional(), account_guid: z.string().optional(), account_info: bankAccount.optional(), mask_account_number: z.string().nullable().optional(), instrument_type: instrumentType.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 AccountInstrument * * POST /connected-deposits/{version}/account-instruments/create */ export const createApiConnectedDepositsVersionAccountInstrumentsCreate = async (args: CreateApiConnectedDepositsVersionAccountInstrumentsCreateArgs, options?: CreateApiConnectedDepositsVersionAccountInstrumentsCreateOptions) => { 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))}/account-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(accountInstrumentDTO, await res.json()) };