import {z} from 'zod' export type GetApiTransferLimitsUtilizationsArgs = {transfer_type: 'INTERNAL_TRANSFER_DEBIT' | 'INTERNAL_TRANSFER_CREDIT' | 'CRYPTO_DEPOSIT' | 'CRYPTO_WITHDRAWAL' | 'WIRE_DEPOSIT' | 'WIRE_WITHDRAWAL' | 'SEN_DEPOSIT' | 'SEN_WITHDRAWAL' | 'BANK_DEPOSIT' | 'BANK_WITHDRAWAL' | 'PAXOS_TRANSFER_DEBIT' | 'PAXOS_TRANSFER_CREDIT' | 'SIGNET_DEPOSIT' | 'SIGNET_WITHDRAWAL' | 'CBIT_WITHDRAWAL' | 'CBIT_DEPOSIT' | 'CUBIX_DEPOSIT' | 'CUBIX_WITHDRAWAL' | 'RTP_DEPOSIT'}; export type GetApiTransferLimitsUtilizationsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const transferType = z.enum(["INTERNAL_TRANSFER_DEBIT", "INTERNAL_TRANSFER_CREDIT", "CRYPTO_DEPOSIT", "CRYPTO_WITHDRAWAL", "WIRE_DEPOSIT", "WIRE_WITHDRAWAL", "SEN_DEPOSIT", "SEN_WITHDRAWAL", "BANK_DEPOSIT", "BANK_WITHDRAWAL", "PAXOS_TRANSFER_DEBIT", "PAXOS_TRANSFER_CREDIT", "SIGNET_DEPOSIT", "SIGNET_WITHDRAWAL", "CBIT_WITHDRAWAL", "CBIT_DEPOSIT", "CUBIX_DEPOSIT", "CUBIX_WITHDRAWAL", "RTP_DEPOSIT"]); export const transferLimit = z.object({id: z.string().optional(), rule_id: z.string().optional(), transfer_types: z.array(transferType).optional(), period_seconds: z.string().optional(), limit: z.string().optional(), remaining: z.string().optional(), limit_asset: z.string().optional()}); export const listTransferLimitsResponse = z.object({items: z.array(transferLimit).optional(), next_page_cursor: 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 }; /** * List Transfer Limits * * GET /transfer/limits/utilizations */ export const getApiTransferLimitsUtilizations = async (args: GetApiTransferLimitsUtilizationsArgs, options?: GetApiTransferLimitsUtilizationsOptions) => { const {baseUrl = "https://api.paxos.com/v2", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.transfer_type != null) query.append("transfer_type", String(args.transfer_type)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/transfer/limits/utilizations${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(listTransferLimitsResponse, await res.json()) };