import {z} from 'zod' export type GetApiApiV1PipelinesPipelineIdStatusArgs = {pipeline_id: string, full_details?: (boolean | null) | undefined, project_id?: (string | null) | undefined, session?: (string | null) | undefined}; export type GetApiApiV1PipelinesPipelineIdStatusOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const managedIngestionStatus = z.enum(["NOT_STARTED", "IN_PROGRESS", "SUCCESS", "ERROR", "PARTIAL_SUCCESS", "CANCELLED"]); export const jobNameMapping = z.enum(["MANAGED_INGESTION", "DATA_SOURCE", "FILE_UPDATER", "PARSE", "TRANSFORM", "INGESTION", "METADATA_UPDATE"]); export const ingestionErrorResponse = z.object({job_id: z.string(), message: z.string(), step: jobNameMapping}); export const managedIngestionStatusResponse = z.object({job_id: z.string().nullable().optional(), deployment_date: z.string().nullable().optional(), status: managedIngestionStatus, error: z.array(ingestionErrorResponse).nullable().optional(), effective_at: z.string().nullable().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 }; /** * Get Pipeline Status * * GET /api/v1/pipelines/{pipeline_id}/status */ export const getApiApiV1PipelinesPipelineIdStatus = async (args: GetApiApiV1PipelinesPipelineIdStatusArgs, options: GetApiApiV1PipelinesPipelineIdStatusOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() const cookies: string[] = [] headers.set('accept', "application/json") if (args.full_details != null) query.append("full_details", String(args.full_details)) if (args.project_id != null) query.append("project_id", String(args.project_id)) if (args.session != null) cookies.push("session=" + encodeURIComponent(String(args.session))) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) if (cookies.length > 0) headers.set('cookie', cookies.join('; ')) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/pipelines/${encodeURIComponent(String(args.pipeline_id))}/status${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(managedIngestionStatusResponse, await res.json()) };