import {z} from 'zod' export type GetApiConnectivitySyncsArgs = {limit?: number | undefined, starting_after?: string | undefined, sort_order?: ('asc' | 'desc') | undefined, start_date?: string | undefined, end_date?: string | undefined, type?: ('up' | 'down' | 'transfer_file') | undefined, status?: ('success' | 'warning' | 'failure') | undefined, connected_account_id?: string | undefined}; export type GetApiConnectivitySyncsOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const connectivitySyncDetails = z.object({id: z.string(), object: z.literal("connectivity_sync"), type: z.enum(["up", "down", "transfer_file"]), connected_account_ids: z.array(z.string()), status: z.enum(["success", "warning", "failure"]), status_details: z.string().nullable(), created_at: z.string()}); export const connectivitySyncSearchResult = z.object({records: z.array(connectivitySyncDetails).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 connectivity syncs * * GET /connectivity_syncs */ export const getApiConnectivitySyncs = async (args: GetApiConnectivitySyncsArgs, options?: GetApiConnectivitySyncsOptions) => { 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.type != null) query.append("type", String(args.type)) if (args.status != null) query.append("status", String(args.status)) if (args.connected_account_id != null) query.append("connected_account_id", String(args.connected_account_id)) if (sec0 !== undefined) headers.set("x-api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/connectivity_syncs${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(connectivitySyncSearchResult, await res.json()) };