import {z} from 'zod' export type GetApiStablecoinsPaymentsArgs = {accountId: string, budgetId?: string | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiStablecoinsPaymentsOptions = {baseUrl?: string | undefined, CommonAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiStablecoinsPaymentsResponse = z.object({limit: z.number().int().gte(1).lte(1000).optional(), offset: z.number().int().optional(), count: z.number().int(), rows: z.array(z.object({id: z.string(), accountId: z.string(), budgetId: z.string().max(36), status: z.enum(["PENDING", "PROCESSING", "CANCELLED", "COMPLETE", "UNDERPAID", "OVERPAID", "EXPIRED"]), remitterId: z.string(), amount: z.number().gt(0), displayName: z.string().min(1).max(255).nullable().optional(), sourceCurrencyCode: z.string().min(3).max(4), destinationCurrencyCode: z.string().min(3).max(4), expiresAt: z.string().optional(), createdBy: z.string().min(1).max(255), createdAt: z.string(), updatedAt: z.string()}))}); 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 inbound payments * * GET /stablecoins/payments */ export const getApiStablecoinsPayments = async (args: GetApiStablecoinsPaymentsArgs, options?: GetApiStablecoinsPaymentsOptions) => { const {baseUrl = "https://api.equalsmoney.com/v2", fetch: fetchFn = fetch, CommonAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.accountId != null) query.append("accountId", String(args.accountId)) if (args.budgetId != null) query.append("budgetId", String(args.budgetId)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (CommonAuth !== undefined) headers.set("Authorization", CommonAuth) const url = `${baseUrl.replace(/\/+$/, '')}/stablecoins/payments${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(getApiStablecoinsPaymentsResponse, await res.json()) };