import {z} from 'zod' 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 MailingAddress = {country: string, address1?: string | undefined, address2?: string | undefined, city?: string | undefined, province?: string | undefined, zip_code?: string | undefined}; export type UpdateWireUpdateRoutingDetails = {bank_name?: string | undefined, bank_address?: MailingAddress | undefined}; export type UpdateFiatNetworkInstructionsUpdateWire = {fiat_account_owner_address?: MailingAddress | undefined, routing_details?: UpdateWireUpdateRoutingDetails | undefined, intermediary_routing_details?: UpdateWireUpdateRoutingDetails | undefined}; export type UpdateFiatAccountRequestUpdateFiatNetworkInstructions = {wire?: UpdateFiatNetworkInstructionsUpdateWire | undefined}; export type TransferPublicUpdateFiatAccountBody = {fiat_account_owner?: FiatAccountOwner | undefined, fiat_network_instructions?: UpdateFiatAccountRequestUpdateFiatNetworkInstructions | undefined, metadata?: {[key: string]: string} | undefined}; export type UpdateApiTransferFiatAccountsIdArgs = {id: string, body: TransferPublicUpdateFiatAccountBody}; export type UpdateApiTransferFiatAccountsIdOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const fiatAccountOwnerPersonDetails = z.object({first_name: z.string(), last_name: z.string()}); export const fiatAccountOwnerInstitutionDetails = z.object({name: z.string()}); export const fiatAccountOwner = z.object({person_details: fiatAccountOwnerPersonDetails.optional(), institution_details: fiatAccountOwnerInstitutionDetails.optional()}); export const mailingAddress = z.object({country: z.string().max(35), address1: z.string().max(35).optional(), address2: z.string().max(35).optional(), city: z.string().max(35).optional(), province: z.string().max(35).optional(), zip_code: z.string().max(35).optional()}); export const fiatWireAccountType = z.enum(["ABA", "SWIFT"]); export const fiatNetworkInstructionsWireRoutingDetails = z.object({routing_number_type: fiatWireAccountType, routing_number: z.string(), bank_name: z.string(), bank_address: mailingAddress}); export const fiatNetworkInstructionsWire = z.object({account_number: z.string(), fiat_account_owner_address: mailingAddress, routing_details: fiatNetworkInstructionsWireRoutingDetails, intermediary_routing_details: fiatNetworkInstructionsWireRoutingDetails.optional()}); export const fiatNetworkInstructionsCbit = z.object({wallet_address: z.string()}); export const fiatNetworkInstructionsDbsAct = z.object({account_number: z.string()}); export const fiatNetworkInstructionsCubix = z.object({account_id: z.string()}); export const fiatNetworkInstructionsScb = z.object({account_number: z.string()}); export const fiatNetworkInstructionsRtpRoutingDetails = z.object({routing_number: z.string(), bank_name: z.string().optional(), bank_address: mailingAddress.optional()}); export const fiatNetworkInstructionsRtp = z.object({account_number: z.string(), fiat_account_owner_address: mailingAddress.optional(), routing_details: fiatNetworkInstructionsRtpRoutingDetails}); export const fiatNetworkInstructions = z.object({wire: fiatNetworkInstructionsWire.optional(), cbit: fiatNetworkInstructionsCbit.optional(), dbs_act: fiatNetworkInstructionsDbsAct.optional(), cubix: fiatNetworkInstructionsCubix.optional(), scb: fiatNetworkInstructionsScb.optional(), rtp: fiatNetworkInstructionsRtp.optional()}); export const fiatAccountStatus = z.enum(["PENDING", "APPROVED", "REJECTED"]); export const fiatAccount = z.object({id: z.string(), ref_id: z.string().optional(), identity_id: z.string().optional(), account_id: z.string().optional(), fiat_account_owner: fiatAccountOwner.optional(), fiat_network_instructions: fiatNetworkInstructions, status: fiatAccountStatus, metadata: z.record(z.string(), z.string()).optional(), created_at: z.string(), updated_at: 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 }; /** * Update Fiat Account * * PUT /transfer/fiat-accounts/{id} */ export const updateApiTransferFiatAccountsId = async (args: UpdateApiTransferFiatAccountsIdArgs, options?: UpdateApiTransferFiatAccountsIdOptions) => { 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(/\/+$/, '')}/transfer/fiat-accounts/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(fiatAccount, await res.json()) };