import {z} from 'zod' export type MailingAddress = {country: string, address1?: string | undefined, address2?: string | undefined, city?: string | undefined, province?: string | undefined, zip_code?: string | undefined}; export type FiatWireAccountType = 'ABA' | 'SWIFT'; export type FiatNetworkInstructionsWireRoutingDetails = {routing_number_type: FiatWireAccountType, routing_number: string, bank_name: string, bank_address: MailingAddress}; export type FiatNetworkInstructionsWire = {account_number: string, fiat_account_owner_address: MailingAddress, routing_details: FiatNetworkInstructionsWireRoutingDetails, intermediary_routing_details?: FiatNetworkInstructionsWireRoutingDetails | undefined}; export type FiatNetworkInstructionsCbit = {wallet_address: string}; export type FiatNetworkInstructionsDbsAct = {account_number: string}; export type FiatNetworkInstructionsCubix = {account_id: string}; export type FiatNetworkInstructionsScb = {account_number: string}; export type FiatNetworkInstructionsRtpRoutingDetails = {routing_number: string, bank_name?: string | undefined, bank_address?: MailingAddress | undefined}; export type FiatNetworkInstructionsRtp = {account_number: string, fiat_account_owner_address?: MailingAddress | undefined, routing_details: FiatNetworkInstructionsRtpRoutingDetails}; export type FiatNetworkInstructions = {wire?: FiatNetworkInstructionsWire | undefined, cbit?: FiatNetworkInstructionsCbit | undefined, dbs_act?: FiatNetworkInstructionsDbsAct | undefined, cubix?: FiatNetworkInstructionsCubix | undefined, scb?: FiatNetworkInstructionsScb | undefined, rtp?: FiatNetworkInstructionsRtp | undefined}; export type FiatAccountOwnerPersonDetails = {first_name: string, last_name: string}; export type FiatAccountOwnerInstitutionDetails = {name: string}; export type FiatAccountOwner = {person_details?: FiatAccountOwnerPersonDetails | undefined, institution_details?: FiatAccountOwnerInstitutionDetails | undefined}; export type InitiateSandboxFiatDepositRequest = {amount: string, asset: string, memo_id: string, fiat_network_instructions: FiatNetworkInstructions, fiat_account_owner?: FiatAccountOwner | undefined}; export type CreateApiSandboxFiatDepositsArgs = {body: InitiateSandboxFiatDepositRequest}; export type CreateApiSandboxFiatDepositsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const initiateSandboxFiatDepositResponse = z.object({}); 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 }; /** * Initiate Sandbox Fiat Deposit * * POST /sandbox/fiat-deposits */ export const createApiSandboxFiatDeposits = async (args: CreateApiSandboxFiatDepositsArgs, options?: CreateApiSandboxFiatDepositsOptions) => { const {baseUrl = "https://api.paxos.com/v2", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/sandbox/fiat-deposits${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(initiateSandboxFiatDepositResponse, await res.json()) };