import {z} from 'zod' export type ValidateBankCodeDto = {paymentNetwork: 'ACH' | 'ACH_SAME_DAY' | 'WIRE' | 'FED_NOW' | 'RTP' | 'EREBOR' | 'EREBOR_RAIL' | 'BALANCE' | 'SWIFT' | 'SEPA' | 'SEPA_INSTANT' | 'TIPS' | 'FASTER_PAYMENTS' | 'BACS' | 'CHAPS' | 'ELIXIR' | 'NICS' | 'EFT' | 'INTERAC' | 'NPP' | 'BECS' | 'UPI' | 'IMPS' | 'IMPS_WITH_FIRC' | 'NEFT' | 'RTGS' | 'BI_FAST' | 'ARTAJASA' | 'PIX' | 'TED' | 'TEF' | 'SPEI' | 'COELSA' | 'SINPE' | 'CNAPS' | 'CIPS' | 'CFXPS' | 'CHATS' | 'ZENGIN' | 'KFTC' | 'FAST_SG' | 'MEPS' | 'DUITNOW' | 'PROMPTPAY' | 'INSTAPAY' | 'PESONET' | 'NAPAS' | 'BEFTN' | 'SLIPS' | 'ZAHAV' | 'GHIPSS' | 'NIBSS' | 'PESALINK' | 'RTC_ZA' | 'TZS_RTGS' | 'EGP_ACH' | 'JOD_ACH' | 'NPSS' | 'MADA' | 'QPS' | 'DOP_ACH' | 'GTQ_ACH' | 'HNL_ACH' | 'PEN_ACH' | 'JMD_ACH' | 'USD_ACH_SV' | 'USD_ACH_EC' | 'CLP_TEF' | 'PSE' | 'COP_ACH' | 'BOB_RTGS' | 'PYG_ACH' | 'CERTIS' | 'DKK_TIPS' | 'SENT' | 'NKS' | 'BANKGIROT' | 'HKD_FPS' | 'IBFT' | 'TRY_FAST', code: string}; export type CreateApiV1ExternalBankAccountsValidateArgs = {body: ValidateBankCodeDto}; export type CreateApiV1ExternalBankAccountsValidateOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const bankAddressDto = z.object({addressLine1: z.string().min(1).max(1024).optional(), addressLine2: z.string().min(1).max(1024).optional(), city: z.string().min(1).max(256).optional(), state: z.string().min(1).max(256).optional(), postalCode: z.string().min(1).max(50).optional(), country: z.string().min(2).max(2).optional()}); export const bankCodeEnrichmentResponseDto = z.object({found: z.boolean(), code: z.string(), paymentNetwork: z.enum(["ACH", "ACH_SAME_DAY", "WIRE", "FEDWIRE", "FED_NOW", "RTP", "EREBOR", "EREBOR_RAIL", "BALANCE", "SWIFT", "SEPA", "SEPA_INSTANT", "TIPS", "FASTER_PAYMENTS", "BACS", "CHAPS", "ELIXIR", "NICS", "EFT", "INTERAC", "NPP", "BECS", "UPI", "IMPS", "IMPS_WITH_FIRC", "NEFT", "RTGS", "BI_FAST", "ARTAJASA", "PIX", "TED", "TEF", "SPEI", "COELSA", "SINPE", "CNAPS", "CIPS", "CFXPS", "CHATS", "ZENGIN", "KFTC", "FAST_SG", "MEPS", "DUITNOW", "PROMPTPAY", "INSTAPAY", "PESONET", "NAPAS", "BEFTN", "SLIPS", "ZAHAV", "GHIPSS", "NIBSS", "PESALINK", "RTC_ZA", "TZS_RTGS", "EGP_ACH", "JOD_ACH", "NPSS", "MADA", "QPS", "DOP_ACH", "GTQ_ACH", "HNL_ACH", "PEN_ACH", "JMD_ACH", "USD_ACH_SV", "USD_ACH_EC", "CLP_TEF", "PSE", "COP_ACH", "BOB_RTGS", "PYG_ACH", "CERTIS", "DKK_TIPS", "SENT", "NKS", "BANKGIROT", "HKD_FPS", "IBFT", "TRY_FAST"]), bankName: z.string().optional(), branch: z.string().optional(), address: bankAddressDto.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 }; /** * Validate and enrich bank code * * POST /v1/external-bank-accounts/validate */ export const createApiV1ExternalBankAccountsValidate = async (args: CreateApiV1ExternalBankAccountsValidateArgs, options?: CreateApiV1ExternalBankAccountsValidateOptions) => { const {baseUrl = "https://sandbox.api.infinite.dev", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/external-bank-accounts/validate${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(bankCodeEnrichmentResponseDto, await res.json()) };