import {z} from 'zod' export type CreateApiPayoutDestinationArgs = {body: {account_id: string, source_type: 'bank_account' | 'wallet_account', label: string, type: 'internal' | 'wire' | 'nip' | 'stablecoin' | 'mobile_money', wire_type?: ('ach' | 'fedwire' | 'swift') | undefined, destination_account_id?: string | undefined, destination_type?: ('bank_account' | 'wallet_account' | 'address' | 'mobile_money') | undefined, account_type?: ('personal' | 'business') | undefined, bank_code?: string | undefined, account_number?: string | undefined, routing_number?: string | undefined, beneficiary_name?: string | undefined, beneficiary_address?: ({line1: string, line2?: string | undefined, city: string, state: string, country: string, postal_code: string}) | undefined, bank_name?: string | undefined, bank_address?: ({line1: string, line2?: string | undefined, city: string, state: string, country: string, postal_code: string}) | undefined, address_code?: string | undefined, address_network?: ('ERC20' | 'TRC20' | 'POL') | undefined, currency?: ('USDC' | 'USDT') | undefined, operator_code?: string | undefined, country_code?: string | undefined, phone_number?: string | undefined}}; export type CreateApiPayoutDestinationOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiPayoutDestinationResponse = z.union([z.object({data: z.object({id: z.string().optional(), account_id: z.string().optional(), destination_account_id: z.string().optional(), label: z.string().optional(), type: z.string().optional(), wire_type: z.unknown(), beneficiary_name: z.string().optional(), account_number: z.string().optional(), account_type: z.string().optional(), routing_number: z.string().optional(), routing_type: z.string().optional(), bank_name: z.string().optional(), bank_address: z.object({city: z.string().optional(), country: z.string().optional(), line1: z.string().optional(), line2: z.string().optional(), postal_code: z.string().optional(), state: z.string().optional()}).optional(), beneficiary_address: z.object({}).optional(), is_deleted: z.boolean().optional(), created_at: z.string().optional(), updated_at: z.string().optional()}).optional(), message: z.string().optional(), meta: z.unknown(), status: z.string().optional()}), z.object({data: z.object({id: z.string().optional(), account_id: z.string().optional(), destination_account_id: z.unknown(), source_type: z.string().optional(), destination_type: z.string().optional(), label: z.string().optional(), type: z.string().optional(), currency: z.string().optional(), wire_type: z.unknown(), account_name: z.string().optional(), account_number: z.string().optional(), account_type: z.string().optional(), routing_number: z.unknown(), routing_type: z.unknown(), bank_name: z.string().optional(), bank_code: z.string().optional(), bank_address: z.object({}).optional(), beneficiary_name: z.unknown(), beneficiary_address: z.object({}).optional(), is_deleted: z.boolean().optional(), created_at: z.string().optional(), updated_at: z.string().optional()}).optional(), message: z.string().optional(), meta: z.unknown(), status: z.string().optional()}), z.object({data: z.object({id: z.string().optional(), account_id: z.string().optional(), destination_account_id: z.unknown(), source_type: z.string().optional(), destination_type: z.string().optional(), label: z.string().optional(), type: z.string().optional(), currency: z.string().optional(), wire_type: z.unknown(), address_code: z.string().optional(), address_network: z.string().optional(), account_name: z.unknown(), account_number: z.unknown(), account_type: z.unknown(), routing_number: z.unknown(), routing_type: z.unknown(), bank_id: z.unknown(), bank_name: z.unknown(), bank_code: z.unknown(), bank_address: z.unknown(), beneficiary_name: z.unknown(), beneficiary_address: z.unknown(), is_deleted: z.boolean().optional(), created_at: z.string().optional(), updated_at: z.string().optional()}).optional(), message: z.string().optional(), meta: z.unknown(), status: z.string().optional()}), z.object({data: z.object({id: z.string().optional(), account_id: z.string().optional(), destination_account_id: z.unknown(), source_type: z.string().optional(), destination_type: z.string().optional(), label: z.string().optional(), type: z.string().optional(), currency: z.string().optional(), wire_type: z.unknown(), address_code: z.unknown(), address_network: z.unknown(), phone_number: z.string().optional(), account_name: z.unknown(), account_number: z.unknown(), account_type: z.unknown(), routing_number: z.unknown(), routing_type: z.unknown(), bank_id: z.unknown(), bank_name: z.unknown(), bank_code: z.unknown(), operator_code: z.string().optional(), operator_name: z.string().optional(), operator_country: z.string().optional(), bank_address: z.unknown(), beneficiary_name: z.unknown(), beneficiary_address: z.unknown(), beneficiary_id_number: z.unknown(), is_deleted: z.boolean().optional(), created_at: z.string().optional(), updated_at: z.string().optional()}).optional(), message: z.string().optional(), meta: z.unknown(), status: 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 Payout Destination * * POST /payout-destination */ export const createApiPayoutDestination = async (args: CreateApiPayoutDestinationArgs, options?: CreateApiPayoutDestinationOptions) => { const {baseUrl = "https://api.useoval.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", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/payout-destination${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(createApiPayoutDestinationResponse, await res.json()) };