import {z} from 'zod' export type Address = {line1?: string | undefined, line2?: string | undefined, city?: string | undefined, state?: string | undefined, country?: string | undefined, postal_code?: string | undefined}; export type Phone = {calling_code?: string | undefined, number?: string | undefined}; export type BankCodes = {swift_code?: string | undefined, bic_code?: string | undefined, ifsc_code?: string | undefined, aba_code?: string | undefined, sort_code?: string | undefined, branch_code?: string | undefined, bsb_code?: string | undefined, bank_code?: string | undefined, cnaps?: string | undefined}; export type Bank = {account_number?: string | undefined, iban?: string | undefined, bank_name?: string | undefined, branch_name?: string | undefined, country?: string | undefined, currency?: string | undefined, purpose_code?: string | undefined, bank_codes?: BankCodes | undefined, firc_required?: boolean | undefined, account_type?: ('savings' | 'checking' | 'payment') | undefined, account_holder_name?: string | undefined, transfer_type?: string | undefined}; export type Wallet = {deposit_address: string, type: 'ethereum' | 'tron' | 'polygon' | 'solana' | 'bitcoin_lightning_network', currency: string, hosted?: ('yes' | 'no') | undefined, vasp_name?: string | undefined, vasp_website?: string | undefined}; export type LocalPaymentNetwork = {type: string, deposit_key_type?: string | undefined, deposit_key: string, currency?: string | undefined}; export type TazapayAccount = {deposit_address: string}; export type DestinationDetails = {type: 'bank' | 'wallet' | 'local_payment_network' | 'tazapay_account', bank?: Bank | undefined, wallet?: Wallet | undefined, local_payment_network?: LocalPaymentNetwork | undefined, tazapay_account?: TazapayAccount | undefined}; export type UpdateApiV3BeneficiaryIdArgs = {id: string, body: {name?: string | undefined, type?: string | undefined, address?: Address | undefined, phone?: Phone | undefined, destination_details?: DestinationDetails | undefined, metadata?: unknown | undefined, tax_id?: string | undefined, documents?: ({type?: string | undefined, url?: string | undefined}) | undefined, national_identification_number?: string | undefined}}; export type UpdateApiV3BeneficiaryIdOptions = {baseUrl?: string | undefined, sec0?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const address = z.object({line1: z.string().optional(), line2: z.string().optional(), city: z.string().optional(), state: z.string().optional(), country: z.string().optional(), postal_code: z.string().optional()}); export const bankCodes = z.object({swift_code: z.string().optional(), bic_code: z.string().optional(), ifsc_code: z.string().optional(), aba_code: z.string().optional(), sort_code: z.string().optional(), branch_code: z.string().optional(), bsb_code: z.string().optional(), bank_code: z.string().optional(), cnaps: z.string().optional()}); export const bank = z.object({account_number: z.string().optional(), iban: z.string().optional(), bank_name: z.string().optional(), branch_name: z.string().optional(), country: z.string().optional(), currency: z.string().optional(), purpose_code: z.string().optional(), bank_codes: bankCodes.optional(), firc_required: z.boolean().optional(), account_type: z.enum(["savings", "checking", "payment"]).optional(), account_holder_name: z.string().optional(), transfer_type: z.string().optional()}); export const wallet = z.object({deposit_address: z.string(), type: z.enum(["ethereum", "tron", "polygon", "solana", "bitcoin_lightning_network"]), currency: z.string(), hosted: z.enum(["yes", "no"]).optional(), vasp_name: z.string().optional(), vasp_website: z.string().optional()}); export const localPaymentNetwork = z.object({type: z.string(), deposit_key_type: z.string().optional(), deposit_key: z.string(), currency: z.string().optional()}); export const tazapayAccount = z.object({deposit_address: z.string()}); export const destinationDetails = z.object({type: z.enum(["bank", "wallet", "local_payment_network", "tazapay_account"]), bank: bank.optional(), wallet: wallet.optional(), local_payment_network: localPaymentNetwork.optional(), tazapay_account: tazapayAccount.optional()}); export const phone = z.object({calling_code: z.string().optional(), number: z.string().optional()}); export const updateApiV3BeneficiaryIdResponse = z.object({address: address.optional(), date_of_birth: z.string().optional(), nationality: z.string().optional(), destination: z.string().optional(), destination_details: destinationDetails.optional(), documents: z.array(z.object({})).optional(), email: z.string().optional(), name: z.string().optional(), name_local: z.string().optional(), national_identification_number: z.string().optional(), party_classification: z.string().optional(), phone: phone.optional(), registration_number: z.string().optional(), tax_id: z.string().optional(), type: 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 Beneficiary * * PUT /v3/beneficiary/{id} */ export const updateApiV3BeneficiaryId = async (args: UpdateApiV3BeneficiaryIdArgs, options?: UpdateApiV3BeneficiaryIdOptions) => { const {baseUrl = "https://service-sandbox.tazapay.com", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (sec0 !== undefined) headers.set('authorization', `Basic ${btoa(`${sec0.username}:${sec0.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/beneficiary/${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(updateApiV3BeneficiaryIdResponse, await res.json()) };