import {z} from 'zod' export type PartnersCreatePayoutToWalletAddressRequest = {amount: string, ccy: string, chain_id: number, reference?: string | undefined, token_address?: string | undefined, wallet_address: string}; export type CreateApiPartnersAccountsAccountRefPayoutAddressArgs = {account_ref: string, body: PartnersCreatePayoutToWalletAddressRequest}; export type CreateApiPartnersAccountsAccountRefPayoutAddressOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const modelsCustomer = z.object({created_at: z.string().optional(), deleted_at: z.string().optional(), email: z.string().optional(), id: z.string().optional(), metadata: z.array(z.number().int()).optional(), name: z.string().optional(), org_id: z.string().optional(), phone: z.string().optional(), properties: z.array(z.number().int()).optional(), reference: z.string().optional(), updated_at: z.string().optional(), wallet_address: z.string().optional()}); export const modelsPaymentMethod = z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(6), z.literal(7), z.literal(8), z.literal(9), z.literal(10), z.literal(11)]); export const modelsBillingSource = z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4)]); export const modelsPaymentStatus = z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(6), z.literal(7), z.literal(8)]); export const partnersPaymentResponse = z.object({amount: z.string().optional(), created_at: z.string().optional(), currency: z.string().optional(), customer: modelsCustomer.optional(), customer_id: z.string().optional(), id: z.string().optional(), invoice_id: z.string().optional(), next_action: z.string().optional(), org_id: z.string().optional(), parent_id: z.string().optional(), payment_method: modelsPaymentMethod.optional(), properties: z.record(z.string(), z.unknown()).optional(), scheduled_time: z.number().int().optional(), source: modelsBillingSource.optional(), status: modelsPaymentStatus.optional(), 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 }; /** * Create Payout to a Crypto Wallet Address * * POST /partners/accounts/{account_ref}/payout/address * * Also accepts auth: ApiSignature, ApiNonce */ export const createApiPartnersAccountsAccountRefPayoutAddress = async (args: CreateApiPartnersAccountsAccountRefPayoutAddressArgs, options: CreateApiPartnersAccountsAccountRefPayoutAddressOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/partners/accounts/${encodeURIComponent(String(args.account_ref))}/payout/address${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(partnersPaymentResponse, await res.json()) };