import {z} from 'zod' export type CustomerId = string; export type GetApiApiV1CustomersCustomerIdVirtualAccountsVirtualAccountIdHistoryArgs = {deposit_id?: string | undefined, limit?: number | undefined, starting_after?: string | undefined, ending_before?: string | undefined, customerId: CustomerId, virtualAccountId: string}; export type GetApiApiV1CustomersCustomerIdVirtualAccountsVirtualAccountIdHistoryOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1CustomersCustomerIdVirtualAccountsVirtualAccountIdHistoryResponse = z.object({data: z.array(z.object({id: z.string(), virtual_account_id: z.string(), deposit_amount: z.string(), deposit_currency: z.string(), sender_name: z.string().nullable(), sender_reference: z.string().nullable(), handling_mode: z.enum(["auto_payout", "hold", "manual"]), payout_status: z.enum(["pending", "processing", "completed", "failed", "needs_manual_review"]).nullable(), payout_amount: z.string().nullable(), payout_currency: z.string().nullable(), payout_network: z.string().nullable(), payout_address: z.string().nullable(), payout_transaction_hash: z.string().nullable(), payout_completed_at: z.string().nullable(), platform_fee_amount: z.string().nullable(), platform_fee_currency: z.string().nullable(), platform_fee_swept: z.boolean().nullable(), deposited_at: z.string(), created_at: z.string()})), has_more: z.boolean()}); 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 }; /** * History of deposit activity for a virtual account * * GET /api/v1/customers/{customerId}/virtual-accounts/{virtualAccountId}/history * * Also accepts auth: apiKeyAuth */ export const getApiApiV1CustomersCustomerIdVirtualAccountsVirtualAccountIdHistory = async (args: GetApiApiV1CustomersCustomerIdVirtualAccountsVirtualAccountIdHistoryArgs, options?: GetApiApiV1CustomersCustomerIdVirtualAccountsVirtualAccountIdHistoryOptions) => { const {baseUrl = "https://api.stables.money", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.deposit_id != null) query.append("deposit_id", String(args.deposit_id)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.starting_after != null) query.append("starting_after", String(args.starting_after)) if (args.ending_before != null) query.append("ending_before", String(args.ending_before)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/customers/${encodeURIComponent(String(args.customerId))}/virtual-accounts/${encodeURIComponent(String(args.virtualAccountId))}/history${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(getApiApiV1CustomersCustomerIdVirtualAccountsVirtualAccountIdHistoryResponse, await res.json()) };