import {z} from 'zod' export type GetApiOrgsOrgIdConnectorsJobsArgs = {org_id: string, connector_id?: (string | null) | undefined}; export type GetApiOrgsOrgIdConnectorsJobsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const jobView = z.object({connector_id: z.string(), created_at: z.string(), dest_table: z.string(), duration_ms: z.number().int().nullable().optional(), finished_at: z.string().nullable().optional(), id: z.string(), kb_uid: z.string(), kind: z.string(), message: z.string().nullable().optional(), mode: z.string(), rows_emitted: z.number().int(), rows_per_sec: z.number().nullable().optional(), started_at: z.string().nullable().optional(), state: z.string(), sync_id: z.string().nullable().optional(), updated_at: z.string()}); export const listJobsRes = z.object({jobs: z.array(jobView)}); 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 }; /** * `GET /orgs/{org_id}/connectors/jobs` * * GET /orgs/{org_id}/connectors/jobs */ export const getApiOrgsOrgIdConnectorsJobs = async (args: GetApiOrgsOrgIdConnectorsJobsArgs, options?: GetApiOrgsOrgIdConnectorsJobsOptions) => { const {baseUrl = "https://api.timbal.ai", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.connector_id != null) query.append("connector_id", String(args.connector_id)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/orgs/${encodeURIComponent(String(args.org_id))}/connectors/jobs${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(listJobsRes, await res.json()) };