import {z} from 'zod' export type AccountMetadataDto = {nickname?: string | undefined, purpose?: string | undefined, tags?: Array | undefined}; export type CreateVirtualWalletFixedRouteDto = {correspondentBankName?: string | undefined, correspondentBankSwiftCode?: string | undefined, correspondentAccountNumber?: string | undefined, customerId: string, sweepTargetAccountId: string, chainType: 'EVM' | 'TRON' | 'BITCOIN' | 'SOLANA', sourceRail?: ('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' | 'ETHEREUM' | 'BASE' | 'POLYGON' | 'SOLANA' | 'TRON' | 'BITCOIN' | 'ARBITRUM') | undefined, sourceCurrency?: string | undefined, destinationRail?: ('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' | 'ETHEREUM' | 'BASE' | 'POLYGON' | 'SOLANA' | 'TRON' | 'BITCOIN' | 'ARBITRUM') | undefined, destinationCurrency?: string | undefined, destinationAchReference?: string | undefined, destinationWireMessage?: string | undefined, destinationSepaReference?: string | undefined, destinationSpeiReference?: string | undefined, developerFeeFixed?: string | undefined, developerFeePercent?: number | undefined, refundAccountId?: string | undefined, externalReference?: string | undefined, metadata?: AccountMetadataDto | undefined, documentIds?: Array | undefined}; export type CreateApiV1FixedRoutesVirtualWalletsArgs = {'X-API-Key'?: string | undefined, 'Idempotency-Key'?: string | undefined, body: CreateVirtualWalletFixedRouteDto}; export type CreateApiV1FixedRoutesVirtualWalletsOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const accountMetadataDto = z.object({nickname: z.string().max(256).optional(), purpose: z.string().max(512).optional(), tags: z.array(z.string()).optional()}); 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 bankDepositInstructions = z.object({bankName: z.string().optional(), bankAddress: bankAddressDto.nullable().optional(), accountNumber: z.string(), routingNumber: z.string().optional(), iban: z.string().optional(), swiftBic: z.string().optional(), bankCountryCode: z.string().optional(), reference: z.string().optional(), depositMessage: z.string().optional(), beneficiaryName: z.string().optional(), beneficiaryAddress: bankAddressDto.nullable().optional()}); export const sourceAccountDto = z.object({id: z.string(), type: z.enum(["VIRTUAL_BANK", "VIRTUAL_WALLET", "INFINITE_BANK", "INFINITE_WALLET", "EXTERNAL_BANK", "EXTERNAL_WALLET", "EXTERNAL_PROXY", "PROVIDER_BALANCE"]), metadata: accountMetadataDto.optional(), depositInstructions: bankDepositInstructions.optional(), sourceCurrency: z.string().optional(), sourceRail: z.string().optional(), sourceRails: z.array(z.string()).optional(), walletAddress: z.string().optional(), addressType: z.string().optional(), chains: z.array(z.string()).optional(), walletType: z.enum(["TREASURY", "TRANSACTION", "VIRTUAL"]).optional()}); export const sweepTargetAccountDto = z.object({id: z.string(), type: z.enum(["VIRTUAL_BANK", "VIRTUAL_WALLET", "INFINITE_BANK", "INFINITE_WALLET", "EXTERNAL_BANK", "EXTERNAL_WALLET", "EXTERNAL_PROXY", "PROVIDER_BALANCE"]), isThirdParty: z.boolean(), metadata: accountMetadataDto.optional(), walletAddress: z.string().optional(), addressType: z.string().optional(), chains: z.array(z.string()).optional(), accountNumber: z.string().optional(), routingNumber: z.string().optional(), bankName: z.string().optional()}); export const fixedRouteCorrespondentBankDto = z.object({name: z.string().nullable().optional(), swiftCode: z.string().nullable().optional(), accountNumber: z.string().nullable().optional()}); export const allowedSenderBankDto = z.object({bankName: z.string().max(200).optional(), routingNumber: z.string().optional(), swiftBic: z.string().optional()}); export const moneyOutputDto = z.object({currency: z.string(), exponent: z.number(), value: z.string(), displayValue: z.string()}); export const fixedRouteResponseDto = z.object({id: z.string(), customerId: z.string(), type: z.enum(["FIAT_TO_CRYPTO", "CRYPTO_TO_FIAT", "CRYPTO_TO_BALANCE", "CRYPTO_TO_CRYPTO", "FIAT_TO_FIAT", "FIAT_TO_CRYPTO_TO_FIAT"]), status: z.string(), enabled: z.boolean(), depositMatching: z.enum(["DEDICATED", "REFERENCE"]).optional(), metadata: accountMetadataDto.optional(), sourceAccount: sourceAccountDto, destinationCurrency: z.string().optional(), destinationRail: z.string().optional(), sweepTargetAccountId: z.string(), previousSweepTargetAccountId: z.string().optional(), previousDestinationRail: z.string().optional(), previousDestinationCurrency: z.string().optional(), sweepTargetAccount: sweepTargetAccountDto.optional(), developerFeeFixed: z.string().nullable().optional(), developerFeePercent: z.number().nullable().optional(), refundAccountId: z.string().nullable().optional(), correspondentBank: fixedRouteCorrespondentBankDto.nullable().optional(), allowedSenderBanks: z.array(allowedSenderBankDto).nullable().optional(), documentIds: z.array(z.string()).nullable().optional(), minimumAmount: moneyOutputDto.optional(), sharesBalanceAccountCoordinates: z.boolean(), payinCloseable: z.boolean(), payinClosed: z.boolean(), sourceClosed: z.boolean(), canReenable: z.boolean(), depositsForwardWhileDisabled: z.boolean(), createdAt: z.string(), updatedAt: z.string()}); 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 a virtual wallet fixed route * * POST /v1/fixed-routes/virtual-wallets */ export const createApiV1FixedRoutesVirtualWallets = async (args: CreateApiV1FixedRoutesVirtualWalletsArgs, options?: CreateApiV1FixedRoutesVirtualWalletsOptions) => { const {baseUrl = "https://sandbox.api.infinite.dev", fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-API-Key'] != null) headers.set("X-API-Key", String(args['X-API-Key'])) if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/fixed-routes/virtual-wallets${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(fixedRouteResponseDto, await res.json()) };