import {z} from 'zod' export type GetApiAccountHoldersArgs = {limit?: number | undefined, starting_after?: string | undefined, sort_order?: ('asc' | 'desc') | undefined, start_date?: string | undefined, end_date?: string | undefined, name?: string | undefined, disabled?: boolean | undefined, external_account_id?: string | undefined, internal_account_id?: string | undefined}; export type GetApiAccountHoldersOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const accountholdersAccountHolder = z.object({id: z.string(), name: z.string(), object: z.string(), created_at: z.string(), disabled_at: z.string().optional(), metadata: z.object({}).optional()}); export const accountholdersSearchResult = z.object({records: z.array(accountholdersAccountHolder).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 account holders * * GET /account_holders */ export const getApiAccountHolders = async (args: GetApiAccountHoldersArgs, options?: GetApiAccountHoldersOptions) => { const {baseUrl = "https://sandbox.numeral.io/v1", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.starting_after != null) query.append("starting_after", String(args.starting_after)) if (args.sort_order != null) query.append("sort_order", String(args.sort_order)) if (args.start_date != null) query.append("start_date", String(args.start_date)) if (args.end_date != null) query.append("end_date", String(args.end_date)) if (args.name != null) query.append("name", String(args.name)) if (args.disabled != null) query.append("disabled", String(args.disabled)) if (args.external_account_id != null) query.append("external_account_id", String(args.external_account_id)) if (args.internal_account_id != null) query.append("internal_account_id", String(args.internal_account_id)) if (sec0 !== undefined) headers.set("x-api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/account_holders${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(accountholdersSearchResult, await res.json()) };