import {z} from 'zod' export type MoneyInputDto = {currency: string, rawValue: string}; export type UpdateTransferSourceDto = {currency?: ('USD' | 'EUR' | 'MXN' | 'USAT' | 'USDC' | 'USDT' | 'USDG' | 'DAI' | 'ETH' | 'BTC' | 'EURC' | 'USDB' | 'PYUSD' | 'USDP' | 'USDS' | 'CASH') | undefined, paymentRail?: ('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, refundAccountId?: string | undefined}; export type UpdateTransferDestinationDto = {correspondentBankName?: string | undefined, correspondentBankSwiftCode?: string | undefined, correspondentAccountNumber?: string | undefined, accountId?: string | undefined, currency?: ('USD' | 'EUR' | 'GBP' | 'CAD' | 'JPY' | 'AUD' | 'MXN' | 'BRL' | 'AED' | 'BHD' | 'KWD' | 'QAR' | 'ARS' | 'CHF' | 'CNY' | 'CNH' | 'COP' | 'CZK' | 'DKK' | 'EGP' | 'HKD' | 'HUF' | 'IDR' | 'ILS' | 'INR' | 'KRW' | 'MYR' | 'NOK' | 'NZD' | 'PHP' | 'PKR' | 'PLN' | 'RON' | 'RUB' | 'SAR' | 'SEK' | 'SGD' | 'THB' | 'TRY' | 'TWD' | 'VND' | 'ZAR' | 'USAT' | 'USDC' | 'USDT' | 'USDG' | 'DAI' | 'EURC' | 'PYUSD' | 'USDB' | 'USDP' | 'USDS' | 'BTC' | 'ETH') | undefined, paymentRail?: ('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, wireMessage?: string | undefined, sepaReference?: string | undefined, achReference?: string | undefined, blockchainMemo?: string | undefined, swiftReference?: string | undefined, rtpReference?: string | undefined}; export type UpdateTransferDto = {clientReferenceId?: string | undefined, counterpartyId?: string | undefined, amount?: MoneyInputDto | undefined, quoteId?: string | undefined, source?: UpdateTransferSourceDto | undefined, destination?: UpdateTransferDestinationDto | undefined, paymentReason?: ('CAPITAL_CONTRIBUTIONS' | 'CHARITABLE_CONTRIBUTIONS' | 'CONSULTING_FEES' | 'CORPORATE_TAX_PAYMENTS' | 'DOWN_PAYMENTS_FOR_REAL_ESTATE' | 'EDUCATION_FEES' | 'EMPLOYEE_SALARIES_OR_WAGES' | 'EXPENSES_REIMBURSEMENT' | 'GIFTS' | 'GOVERNMENT_GRANTS' | 'INCOME_TAX_PAYMENTS' | 'INHERITANCE_PAYMENTS' | 'INSURANCE_CLAIM_PAYOUTS' | 'INSURANCE_PREMIUM_PAYMENTS' | 'INVESTMENTS' | 'LOAN_ADVANCES' | 'MORTGAGE_PAYMENTS' | 'OTHER' | 'PAYMENT_FOR_GOODS_AND_SERVICES' | 'PERSONAL_TRANSFERS' | 'REAL_ESTATE_PURCHASES' | 'REMITTANCES' | 'RENT' | 'REPAYMENT_OF_LOANS' | 'ROYALTIES' | 'SELF' | 'TRADE_SETTLEMENT' | 'TRUST_FUND_DISTRIBUTIONS' | 'UTILITY_BILLS' | 'WELFARE_OR_BENEFITS' | 'WINNINGS_AND_PRIZES') | undefined, remarks?: string | undefined, internalRemarks?: string | undefined, documentIds?: Array | undefined}; export type PatchApiV1TransfersIdArgs = {'X-API-Key'?: string | undefined, id: string, body: UpdateTransferDto}; export type PatchApiV1TransfersIdOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const agentApprovalStatus = z.enum(["PENDING", "APPROVED", "DECLINED"]); export const transferDepositOriginatorDto = z.object({name: z.string().nullable().optional(), bankName: z.string().nullable().optional(), routingNumber: z.string().nullable().optional(), accountNumber: z.string().nullable().optional(), swiftBic: z.string().nullable().optional(), bankCountry: z.string().nullable().optional(), paymentReference: z.string().nullable().optional()}); export const transferSourceResponseDto = z.object({currency: z.string(), fundingCurrency: z.string().nullable().optional(), paymentRail: z.string(), direction: z.enum(["CREDIT", "DEBIT"]).nullable().optional(), accountId: z.string().nullable().optional(), accountType: z.enum(["VIRTUAL_BANK", "VIRTUAL_WALLET", "INFINITE_BANK", "INFINITE_WALLET", "EXTERNAL_BANK", "EXTERNAL_WALLET", "EXTERNAL_PROXY", "PROVIDER_BALANCE"]).nullable().optional(), externalAccountId: z.string().nullable().optional(), fromAddress: z.string().nullable().optional(), refundAccountId: z.string().nullable().optional(), accountName: z.string().nullable().optional(), originator: transferDepositOriginatorDto.nullable().optional()}); export const transferDestinationResponseDto = z.object({currency: z.string(), paymentRail: z.string(), accountId: z.string().nullable().optional(), accountType: z.enum(["VIRTUAL_BANK", "VIRTUAL_WALLET", "INFINITE_BANK", "INFINITE_WALLET", "EXTERNAL_BANK", "EXTERNAL_WALLET", "EXTERNAL_PROXY", "PROVIDER_BALANCE"]).nullable().optional(), externalAccountId: z.string().nullable().optional(), toAddress: z.string().nullable().optional(), accountName: z.string().nullable().optional(), bankName: z.string().nullable().optional(), bankCountryCode: z.string().nullable().optional(), wireMessage: z.string().nullable().optional(), achReference: z.string().nullable().optional(), swiftReference: z.string().nullable().optional(), rtpReference: z.string().nullable().optional(), payoutReference: z.string().nullable().optional()}); export const moneyOutputDto = z.object({currency: z.string(), exponent: z.number(), value: z.string(), displayValue: z.string()}); export const transferRefundResponseDto = z.object({status: z.enum(["INITIATED", "COMPLETED"]), reason: z.string().nullable().optional(), amount: moneyOutputDto.nullable().optional(), address: z.string().nullable().optional(), txHash: z.string().nullable().optional(), initiatedAt: z.string().nullable().optional(), completedAt: z.string().nullable().optional()}); export const transferDeveloperFeeDto = z.object({amount: moneyOutputDto.nullable().optional(), fixed: z.string().nullable().optional(), percent: z.number().nullable().optional(), txHash: z.string().nullable().optional()}); export const cryptoDepositInstructionsDto = z.object({type: z.string(), paymentRail: z.string(), toAddress: z.string(), amount: moneyOutputDto, blockchainMemo: z.string().nullable().optional(), accountId: z.string().nullable().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 fiatDepositInstructionsDto = z.object({type: z.string(), paymentRail: z.string(), direction: z.enum(["CREDIT", "DEBIT"]).nullable().optional(), amount: moneyOutputDto, bankName: z.string().nullable().optional(), bankAddress: bankAddressDto.nullable().optional(), accountNumber: z.string().nullable().optional(), routingNumber: z.string().nullable().optional(), beneficiaryName: z.string().nullable().optional(), beneficiaryAddress: bankAddressDto.nullable().optional(), iban: z.string().nullable().optional(), swiftBic: z.string().nullable().optional(), depositMessage: z.string().nullable().optional(), clabe: z.string().nullable().optional(), accountId: z.string().nullable().optional()}); export const transferStepDto = z.object({id: z.string(), sequence: z.number(), type: z.enum(["DEPOSIT_CRYPTO", "DEPOSIT_FIAT", "ONRAMP", "CONVERT", "OFFRAMP", "CRYPTO_TRANSFER", "BRIDGE", "OUTBOUND_TOP_UP", "INBOUND_TOP_UP", "REFUND_CRYPTO", "REFUND_FIAT", "LIQUIDITY_ADVANCE"]), inputCurrency: z.string(), outputCurrency: z.string(), inputRail: z.string(), outputRail: z.string(), status: z.enum(["PENDING", "IN_PROGRESS", "COMPLETED", "FAILED", "SKIPPED"]), startedAt: z.string().nullable().optional(), completedAt: z.string().nullable().optional(), uetr: z.string().nullable().optional(), imad: z.string().nullable().optional(), omad: z.string().nullable().optional(), achTraceNumber: z.string().nullable().optional(), txHash: z.string().nullable().optional(), developerFee: moneyOutputDto.nullable().optional(), feeTxHash: z.string().nullable().optional()}); export const transferWireTrackingResponseDto = z.object({uetr: z.string().nullable().optional(), imad: z.string().nullable().optional(), omad: z.string().nullable().optional(), achTraceNumber: z.string().nullable().optional(), wirePaymentReference: z.string().nullable().optional()}); export const transferStatusDetailResponseDto = z.object({kind: z.enum(["FAILED", "CANCELLED", "REVERSED"]), reason: z.string(), code: z.string().nullable().optional(), occurredAt: z.string().nullable().optional()}); export const originatingAccountDto = z.object({bankName: z.string().nullable().optional(), routingNumber: z.string().nullable().optional(), accountNumber: z.string().nullable().optional()}); export const transliteratedAddressDto = 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()}); export const addressDto = z.object({addressLine1: z.string().min(1).max(1024), addressLine2: z.string().min(1).max(1024).optional(), city: z.string().min(1).max(256), state: z.string().min(1).max(256).optional(), postalCode: z.string().min(1).max(50), country: z.string().min(2).max(2), transliterated: transliteratedAddressDto.optional()}); export const counterpartyResponseDto = z.object({id: z.string(), name: z.string(), beneficiaryType: z.enum(["INDIVIDUAL", "BUSINESS"]), address: addressDto.nullable().optional(), createdAt: z.string(), updatedAt: z.string()}); export const transferResponseDto = z.object({id: z.string(), organizationId: z.string(), clientReferenceId: z.string().nullable().optional(), sourceCustomerId: z.string(), counterpartyId: z.string().nullable().optional(), agentId: z.string().nullable().optional(), agentApprovalStatus: agentApprovalStatus.nullable().optional(), flow: z.enum(["CRYPTO_TO_CRYPTO", "CRYPTO_TO_FIAT", "FIAT_TO_CRYPTO", "FIAT_TO_FIAT", "FIAT_TO_CRYPTO_TO_FIAT", "FX", "INTERNAL", "FEE_CRYPTO", "REFUND_CRYPTO", "REFUND_FIAT"]), status: z.enum(["DRAFT", "PENDING_AUTHORIZATION", "IN_REVIEW", "PENDING", "PROCESSING", "COMPLETED", "FAILED", "CANCELLED", "REVERSED"]), source: transferSourceResponseDto, destination: transferDestinationResponseDto, sourceAmount: moneyOutputDto, destinationAmount: moneyOutputDto.nullable().optional(), deliveredAmount: moneyOutputDto.optional(), providerFee: moneyOutputDto.optional(), refund: transferRefundResponseDto.nullable().optional(), quoteId: z.string().nullable().optional(), exchangeRate: z.string().nullable().optional(), referenceRate: z.string().optional(), referenceRateAsOf: z.string().optional(), referenceProvider: z.literal("XE").optional(), developerFeeFixed: z.string().nullable().optional(), developerFeePercent: z.number().nullable().optional(), developerFee: transferDeveloperFeeDto.nullable().optional(), depositInstructions: z.union([cryptoDepositInstructionsDto, fiatDepositInstructionsDto]).nullable().optional(), createdAt: z.string(), updatedAt: z.string(), returnedToAccountId: z.string().nullable().optional(), returnedAt: z.string().nullable().optional(), legs: z.array(transferStepDto), currentLegIndex: z.number().nullable().optional(), fundingNeeded: z.boolean(), isThirdParty: z.boolean().optional(), remarks: z.string().nullable().optional(), internalRemarks: z.string().nullable().optional(), uetr: z.string().nullable().optional(), imad: z.string().nullable().optional(), omad: z.string().nullable().optional(), achTraceNumber: z.string().nullable().optional(), wireTracking: transferWireTrackingResponseDto.nullable().optional(), statusDetail: transferStatusDetailResponseDto.nullable().optional(), originatingAccount: originatingAccountDto.nullable().optional(), txHash: z.string().nullable().optional(), systemRemark: z.string().nullable().optional(), metadata: z.record(z.string(), z.unknown()).optional(), estimatedSettlementAt: z.string().nullable().optional(), nextCutoffAt: z.string().nullable().optional(), cutoffTimezone: z.string().nullable().optional(), counterparty: counterpartyResponseDto.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 }; /** * Update transfer details * * PATCH /v1/transfers/{id} */ export const patchApiV1TransfersId = async (args: PatchApiV1TransfersIdArgs, options?: PatchApiV1TransfersIdOptions) => { 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 (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/transfers/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(transferResponseDto, await res.json()) };