import {z} from 'zod' export type CreateApiApiRampV1SwaporderArgs = {Authorization: string, body: {taxId: string, taxIdCountry: 'ALB' | 'AND' | 'ARE' | 'ARG' | 'ARM' | 'AUS' | 'AUT' | 'AZE' | 'BEL' | 'BGR' | 'BHR' | 'BIH' | 'BLR' | 'BOL' | 'BRA' | 'CAN' | 'CHE' | 'CHL' | 'CHN' | 'COL' | 'CRI' | 'CUB' | 'CYP' | 'CZE' | 'DEU' | 'DNK' | 'DOM' | 'ECU' | 'ESP' | 'EST' | 'FIN' | 'FLK' | 'FRA' | 'FRO' | 'GBR' | 'GEO' | 'GRC' | 'GTM' | 'GUF' | 'GUY' | 'HKG' | 'HRV' | 'HUN' | 'IDN' | 'IND' | 'IRL' | 'ISL' | 'ISR' | 'ITA' | 'JPN' | 'KAZ' | 'KOR' | 'LTU' | 'LUX' | 'LVA' | 'MCO' | 'MDA' | 'MEX' | 'MKD' | 'MLT' | 'MNE' | 'MUS' | 'MYS' | 'NGA' | 'NLD' | 'NOR' | 'NZL' | 'PAK' | 'PER' | 'PHL' | 'POL' | 'PRT' | 'PRY' | 'ROU' | 'RUS' | 'SLV' | 'SMR' | 'SRB' | 'SUR' | 'SVK' | 'SVN' | 'SWE' | 'THA' | 'TUR' | 'TWN' | 'UKR' | 'URY' | 'USA' | 'UZB' | 'VEN' | 'ZAF', externalId?: string | undefined, name?: string | undefined, email?: string | undefined, quoteId?: string | undefined, quoteRequest?: ({side?: string | undefined, baseCurrency?: string | undefined, quoteCurrency?: string | undefined, baseAmount?: number | undefined, quoteAmount?: number | undefined}) | undefined, fiatWithdrawalInformation?: ({bankAccount?: string | undefined, bankBranch?: string | undefined, accountType?: string | undefined, iban?: string | undefined, key?: string | undefined, qrCode?: string | undefined}) | undefined, cryptoWithdrawalInformation?: ({blockchain: 'None' | 'Ethereum' | 'BinanceSmartChain' | 'Solana' | 'Stellar' | 'Ripple' | 'Bitcoin' | 'Polygon' | 'Avalanche' | 'Polkadot' | 'Fantom' | 'Cosmos' | 'Terra' | 'Tron' | 'Optimism' | 'Arbitrum' | 'Tezos' | 'Rootstock' | 'Moonbeam' | 'Injective' | 'Sui' | 'Aptos' | 'Celo' | 'Aurora' | 'Cronos' | 'Base' | 'ZkSync' | 'Linea' | 'Zeniq' | 'PolygonZkEVM' | 'Mantle' | 'TONBinancePayGnosisChiliz' | 'LightningNetwork', key: string}) | undefined, depositBlockchain?: ('None' | 'Ethereum' | 'BinanceSmartChain' | 'Solana' | 'Stellar' | 'Ripple' | 'Bitcoin' | 'Polygon' | 'Avalanche' | 'Polkadot' | 'Fantom' | 'Cosmos' | 'Terra' | 'Tron' | 'Optimism' | 'Arbitrum' | 'Tezos' | 'Rootstock' | 'Moonbeam' | 'Injective' | 'Sui' | 'Aptos' | 'Celo' | 'Aurora' | 'Cronos' | 'Base' | 'ZkSync' | 'Linea' | 'Zeniq' | 'PolygonZkEVM' | 'Mantle' | 'TON' | 'BinancePay' | 'Gnosis' | 'Chiliz' | 'LightningNetwork') | undefined, refundCryptoAddress?: string | undefined}}; export type CreateApiApiRampV1SwaporderOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiRampV1SwaporderResponse = z.object({id: z.string().optional(), currency: z.string().optional(), blockchain: z.string().optional(), depositAmount: z.number().optional(), referenceId: z.string().optional(), expireAt: z.string().optional(), depositAddress: z.string().optional(), blockchainFee: z.number().int().optional(), walletAddress: z.string().optional(), base64QRCode: z.string().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 a Ramp * * POST /api/ramp/v1/swaporder */ export const createApiApiRampV1Swaporder = async (args: CreateApiApiRampV1SwaporderArgs, options?: CreateApiApiRampV1SwaporderOptions) => { const {baseUrl = "https://sandbox-api-baasic.transfero.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/api/ramp/v1/swaporder${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(createApiApiRampV1SwaporderResponse, await res.json()) };