import {z} from 'zod' export type GetApiIssuerQuotesArgs = {profile_id?: string | undefined, status?: (Array<'PENDING' | 'COMPLETE' | 'FAILED'>) | undefined, 'created_range.begin'?: string | undefined, 'created_range.end'?: string | undefined, limit?: number | undefined, page_cursor?: string | undefined, order?: ('DESC' | 'ASC') | undefined}; export type GetApiIssuerQuotesOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const issuerQuoteExecutionStatus = z.enum(["PENDING", "COMPLETE", "FAILED"]); export const issuerQuoteExecution = z.object({id: z.string(), created_at: z.string(), asset_type: z.string(), principal: z.string(), fee: z.string(), status: issuerQuoteExecutionStatus, ref_id: z.string().optional(), token_fee: z.string(), token_price: z.string(), token_principal: z.string(), profile_id: z.string()}); export const listIssuerQuoteExecutionsResponse = z.object({issuer_quote_executions: z.array(issuerQuoteExecution).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 Issuer Quote Executions * * GET /issuer-quotes */ export const getApiIssuerQuotes = async (args: GetApiIssuerQuotesArgs, options?: GetApiIssuerQuotesOptions) => { 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)) for (const item of args.status ?? []) query.append("status", String(item)) if (args['created_range.begin'] != null) query.append("created_range.begin", String(args['created_range.begin'])) if (args['created_range.end'] != null) query.append("created_range.end", String(args['created_range.end'])) if (args.limit != null) query.append("limit", String(args.limit)) if (args.page_cursor != null) query.append("page_cursor", String(args.page_cursor)) if (args.order != null) query.append("order", String(args.order)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/issuer-quotes${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(listIssuerQuoteExecutionsResponse, await res.json()) };