import {z} from 'zod' export type GetApiV1DomainsDomainIdSweepThresholdsArgs = {domainId: string, page?: number | undefined, size?: number | undefined, ledgerId?: string | undefined}; export type GetApiV1DomainsDomainIdSweepThresholdsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const omnibusSweepThresholdConfig = z.object({id: z.string().optional(), domainId: z.string(), tickerId: z.string(), tickerSymbol: z.string(), tickerName: z.string().optional(), tickerDecimals: z.number().int().optional(), ledgerId: z.string(), ledgerName: z.string(), contractAddress: z.string().optional(), minSweepAmount: z.string(), minSweepAmountFormatted: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), version: z.number().int().optional()}); export const omnibusPageMetadata = z.object({number: z.number().int().gte(0), size: z.number().int().gte(1), totalElements: z.number().int().gte(0), totalPages: z.number().int().gte(0), first: z.boolean(), last: z.boolean()}); export const omnibusSweepThresholdPageResponse = z.object({content: z.array(omnibusSweepThresholdConfig), page: omnibusPageMetadata}); 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 sweep threshold configurations for a domain * * GET /v1/domains/{domainId}/sweep-thresholds */ export const getApiV1DomainsDomainIdSweepThresholds = async (args: GetApiV1DomainsDomainIdSweepThresholdsArgs, options: GetApiV1DomainsDomainIdSweepThresholdsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) if (args.ledgerId != null) query.append("ledgerId", String(args.ledgerId)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/domains/${encodeURIComponent(String(args.domainId))}/sweep-thresholds${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(omnibusSweepThresholdPageResponse, await res.json()) };