import {z} from 'zod' export type TransferSourceDto = {accountId?: string | undefined, currency: 'USD' | 'EUR' | 'MXN' | 'USAT' | 'USDC' | 'USDT' | 'USDG' | 'DAI' | 'ETH' | 'BTC' | 'EURC' | 'USDB' | 'PYUSD' | 'USDP' | 'USDS' | 'CASH', 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', direction?: ('CREDIT' | 'DEBIT') | undefined, refundAccountId?: string | undefined}; export type TransferDestinationDto = {correspondentBankName?: string | undefined, correspondentBankSwiftCode?: string | undefined, correspondentAccountNumber?: string | undefined, accountId: string, 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', 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', wireMessage?: string | undefined, sepaReference?: string | undefined, achReference?: string | undefined, blockchainMemo?: string | undefined, swiftReference?: string | undefined, rtpReference?: string | undefined}; export type TransferIntentAmountDto = {value: string, side: 'SOURCE' | 'DESTINATION'}; export type CreateTransferIntentQuoteDto = {clientReferenceId?: string | undefined, onBehalfOf: string, counterpartyId?: string | undefined, source: TransferSourceDto, destination: TransferDestinationDto, remarks?: string | undefined, internalRemarks?: string | undefined, developerFeeFixed?: number | undefined, developerFeePercent?: number | undefined, documentIds?: Array | undefined, expiresAt?: string | undefined, requiresAuthorization?: boolean | undefined, amount: TransferIntentAmountDto, 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', lock?: boolean | undefined}; export type CreateApiV1TransfersQuotesArgs = {'X-API-Key'?: string | undefined, body: CreateTransferIntentQuoteDto}; export type CreateApiV1TransfersQuotesOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const moneyOutputDto = z.object({currency: z.string(), exponent: z.number(), value: z.string(), displayValue: z.string()}); export const transferIntentFeesDto = z.object({totalBps: z.string()}); export const routeEstimateDto = z.object({estimatedReceiveAt: z.string(), estimatedMinutes: z.number(), nextCutoff: z.string().optional(), cutoffTimezone: z.string().optional()}); export const transferIntentDeveloperFeeDto = z.object({fixed: z.number().nullable(), variable: z.number().nullable()}); export const transferIntentQuoteResponseDto = z.object({confirmationReference: z.string().optional(), sourceAmount: moneyOutputDto, destinationAmount: moneyOutputDto, destinationPaymentRail: z.string().optional(), exchangeRate: z.string(), fees: transferIntentFeesDto, expiresAt: z.string(), supported: z.boolean(), estimate: routeEstimateDto.optional(), lockable: z.boolean(), minimumAmount: moneyOutputDto.optional(), developerFee: transferIntentDeveloperFeeDto.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 }; /** * Quote a transfer intent * * POST /v1/transfers/quotes */ export const createApiV1TransfersQuotes = async (args: CreateApiV1TransfersQuotesArgs, options?: CreateApiV1TransfersQuotesOptions) => { 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/quotes${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(transferIntentQuoteResponseDto, await res.json()) };