import {z} from 'zod' export type CreateBookTransferRequest = {amount: number | string, to_account_id: string, description?: (string | null) | undefined, metadata?: ({[key: string]: string} | null) | undefined, idempotency_key?: (string | null) | undefined}; export type CreateApiAccountsAccountIdBookArgs = {account_id: string, 'Idempotency-Key'?: (string | null) | undefined, 'x-entity-id'?: string | undefined, body: CreateBookTransferRequest}; export type CreateApiAccountsAccountIdBookOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const transferMethod = z.enum(["book", "usdc", "usdt", "pyusd", "cash", "usdg", "path_usd", "ach", "wire", "international"]); export const transferStatus = z.enum(["pending", "pending_approval", "canceled", "processing", "error", "sent", "returned", "void"]); export const createBookTransferResponse = z.object({id: z.string().nullable().optional(), amount: z.string(), description: z.string().nullable(), created_time: z.number().int(), transfer_type: transferMethod, to_account_id: z.string(), to_account_name: z.string(), to_account_account_number_masked: z.string(), to_entity_id: z.string().nullable().optional(), to_entity_name: z.string().nullable().optional(), status: transferStatus.nullable().optional(), approval_id: z.string(), message: z.string().nullable().optional(), metadata: z.record(z.string(), z.string().max(200)).nullable().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 Book Transfer * * POST /accounts/{account_id}/book */ export const createApiAccountsAccountIdBook = async (args: CreateApiAccountsAccountIdBookArgs, options?: CreateApiAccountsAccountIdBookOptions) => { const {baseUrl = "https://api.meow.com/v1", 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 (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (args['x-entity-id'] != null) headers.set("x-entity-id", String(args['x-entity-id'])) if (apiKeyAuth !== undefined) headers.set("x-api-key", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/${encodeURIComponent(String(args.account_id))}/book${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(createBookTransferResponse, await res.json()) };