import {z} from 'zod' export type ChannelType = 'NotSet' | 'ACH' | 'SameDayACH' | 'RTP' | 'Wire' | 'ManualWire' | 'CrossBorder'; export type TransferType = 'UNKNOWN' | 'CARDTOCARD' | 'PARTNERTOCARD' | 'CARDTOPARTNER' | 'PARTNERTOPARTNER' | 'ACCOUNTTOACCOUNT' | 'ACCOUNTTOBANK' | 'BANKTOACCOUNT' | 'CHECKLOAD' | 'CHECKUNLOAD' | 'CARDTOPARTNER_UNLOADTOZERO' | 'CCDCTOACCOUNT' | 'ACCOUNTTOCCDC' | 'ACCOUNTTOBANKREALTIME' | 'BANKTOACCOUNTREQUESTREALTIME' | 'ACCOUNTTOCHECK' | 'PARTNERTOCHECK'; export type TransferDetail = {account_guid?: (string | null) | undefined, card_proxy?: (string | null) | undefined, outside_instrument_guid?: (string | null) | undefined}; export type SourceTransferDetail = {account_guid: string}; export type DestinationTransferDetail = {outside_instrument_guid: string}; export type ConversionFees = Record; export type ConversionDetails = Record; export type QuoteResponse = {source?: SourceTransferDetail | undefined, destination?: DestinationTransferDetail | undefined, fees?: (Array | null) | undefined, conversionDetails?: ConversionDetails | undefined}; export type SECCode = 'WEB' | 'PPD' | 'TEL' | 'CCD' | 'CTX'; export type EFTInfo = {sec_code?: SECCode | undefined, identifier_number?: (string | null) | undefined, addenda?: (string | null) | undefined}; export type CheckInfo = {template_alias: string}; export type TransferRequest = {client_reference_id: string, channel_type?: ChannelType | undefined, transfer_type: TransferType, amount: number, currency: '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', description?: (string | null) | undefined, source: TransferDetail, destination: TransferDetail, quote_reference?: (string | null) | undefined, quoteoutput?: QuoteResponse | undefined, destination_amount?: number | undefined, destination_currency?: (string | null) | undefined, memo_code?: (string | null) | undefined, verification_code?: (string | null) | undefined, eft_info?: EFTInfo | undefined, reason_code?: (string | null) | undefined, check_info?: CheckInfo | undefined}; export type CreateApiConnectedDepositsVersionTransfersCreateArgs = {version: string, IdempotencyKey: string, body: TransferRequest}; export type CreateApiConnectedDepositsVersionTransfersCreateOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const transferDetail = z.object({account_guid: z.string().nullable().optional(), card_proxy: z.string().nullable().optional(), outside_instrument_guid: z.string().nullable().optional()}); export const fees = z.object({account_guid: z.string().optional(), fee_request_code: z.string().nullable().optional(), fee_request_description: z.string().nullable().optional(), fee_amount: z.number().optional()}); export const transferResponse = z.object({txn_guid: z.string().optional(), amount: z.number(), currency: z.string().min(1), description: z.string().nullable().optional(), source: transferDetail, destination: transferDetail, destination_amount: z.number().optional(), destination_currency: z.string().nullable().optional(), entry_date: z.string().nullable().optional(), fees: z.array(fees).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 Transfer * * POST /connected-deposits/{version}/transfers/create */ export const createApiConnectedDepositsVersionTransfersCreate = async (args: CreateApiConnectedDepositsVersionTransfersCreateArgs, options?: CreateApiConnectedDepositsVersionTransfersCreateOptions) => { 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))}/transfers/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(transferResponse, await res.json()) };