import {z} from 'zod' export type GetApiCustomerProfileWithdrawalsArgs = {'X-XFERS-APP-API-KEY': string, 'X-PUBLIC-KEY-ID'?: string | undefined, 'X-TIMESTAMP'?: string | undefined, 'X-NONCE'?: string | undefined, 'X-SIGNATURE'?: string | undefined, 'page[size]'?: number | undefined, 'page[number]'?: number | undefined, sort?: string | undefined, 'filter[created_after]'?: string | undefined, 'filter[created_before]'?: string | undefined, 'filter[currency]'?: string | undefined, 'filter[status]'?: string | undefined}; export type GetApiCustomerProfileWithdrawalsOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiCustomerProfileWithdrawalsResponse = z.array(z.object({id: z.string().optional(), type: z.string().optional(), idempotency_id: z.string().optional(), amount: z.string().optional(), fees: z.string().optional(), status: z.string().optional(), account_no: z.string().optional(), bank_abbrev: z.string().optional(), failure_reason: z.string().optional(), arrival: z.string().optional(), currency: z.string().optional(), express: z.string().optional(), payout_invoice_id: z.string().optional(), wallet_name: z.string().optional(), created_at: z.string().optional(), external_reference: 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 }; /** * Get a list of outbound transfers * * GET /customer_profile/withdrawals */ export const getApiCustomerProfileWithdrawals = async (args: GetApiCustomerProfileWithdrawalsArgs, options?: GetApiCustomerProfileWithdrawalsOptions) => { const {baseUrl = "https://api-sandbox.straitsx.com/v1", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-XFERS-APP-API-KEY'] != null) headers.set("X-XFERS-APP-API-KEY", String(args['X-XFERS-APP-API-KEY'])) if (args['X-PUBLIC-KEY-ID'] != null) headers.set("X-PUBLIC-KEY-ID", String(args['X-PUBLIC-KEY-ID'])) if (args['X-TIMESTAMP'] != null) headers.set("X-TIMESTAMP", String(args['X-TIMESTAMP'])) if (args['X-NONCE'] != null) headers.set("X-NONCE", String(args['X-NONCE'])) if (args['X-SIGNATURE'] != null) headers.set("X-SIGNATURE", String(args['X-SIGNATURE'])) if (args['page[size]'] != null) query.append("page[size]", String(args['page[size]'])) if (args['page[number]'] != null) query.append("page[number]", String(args['page[number]'])) if (args.sort != null) query.append("sort", String(args.sort)) if (args['filter[created_after]'] != null) query.append("filter[created_after]", String(args['filter[created_after]'])) if (args['filter[created_before]'] != null) query.append("filter[created_before]", String(args['filter[created_before]'])) if (args['filter[currency]'] != null) query.append("filter[currency]", String(args['filter[currency]'])) if (args['filter[status]'] != null) query.append("filter[status]", String(args['filter[status]'])) if (sec0 !== undefined) headers.set("X-XFERS-APP-API-KEY", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/customer_profile/withdrawals${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiCustomerProfileWithdrawalsResponse, await res.json()) };