import {z} from 'zod' export type GetApiConversionStablecoinsArgs = {profile_id?: string | undefined, ref_id?: string | undefined, 'created_at.begin'?: string | undefined, 'created_at.end'?: string | undefined, 'updated_at.begin'?: string | undefined, 'updated_at.end'?: string | undefined, order?: ('DESC' | 'ASC') | undefined, page_cursor?: string | undefined, limit?: number | undefined}; export type GetApiConversionStablecoinsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const stablecoinConversion = z.object({id: z.string().optional(), profile_id: z.string().optional(), amount: z.string().optional(), source_asset: z.string().optional(), target_asset: z.string().optional(), status: z.string().optional(), ref_id: z.string().optional(), identity_id: z.string().optional(), account_id: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), settled_at: z.string().optional(), cancelled_at: z.string().optional(), metadata: z.record(z.string(), z.string()).optional(), recipient_profile_id: z.string().optional()}); export const listStablecoinConversionsResponse = z.object({items: z.array(stablecoinConversion).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 Stablecoin Conversions * * GET /conversion/stablecoins */ export const getApiConversionStablecoins = async (args: GetApiConversionStablecoinsArgs, options?: GetApiConversionStablecoinsOptions) => { 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.profile_id != null) query.append("profile_id", String(args.profile_id)) if (args.ref_id != null) query.append("ref_id", String(args.ref_id)) if (args['created_at.begin'] != null) query.append("created_at.begin", String(args['created_at.begin'])) if (args['created_at.end'] != null) query.append("created_at.end", String(args['created_at.end'])) if (args['updated_at.begin'] != null) query.append("updated_at.begin", String(args['updated_at.begin'])) if (args['updated_at.end'] != null) query.append("updated_at.end", String(args['updated_at.end'])) if (args.order != null) query.append("order", String(args.order)) if (args.page_cursor != null) query.append("page_cursor", String(args.page_cursor)) if (args.limit != null) query.append("limit", String(args.limit)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/conversion/stablecoins${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(listStablecoinConversionsResponse, await res.json()) };