import {z} from 'zod' export type GetApiApiV1AutomationBlockersArgs = {page_size?: number | undefined, cursor?: string | undefined, id?: Array | undefined, annotation?: number | undefined, ordering?: ('id' | '-id') | undefined}; export type GetApiApiV1AutomationBlockersOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const pagination = z.object({next: z.string().nullable().optional(), previous: z.string().nullable().optional()}); export const automationBlocker = z.object({id: z.number().int(), url: z.string(), annotation: z.string(), content: z.array(z.object({level: z.enum(["datapoint", "annotation"]).optional(), type: z.enum(["automation_disabled", "is_duplicate", "suggested_edit_present", "low_score", "failed_checks", "no_validation_sources", "error_message", "delete_recommendation_filename", "delete_recommendation_page_count", "delete_recommendation_field", "extension", "human_confirmation_required", "alternative_prediction"]).optional(), schema_id: z.string().nullable().optional(), samples: z.array(z.object({datapoint_id: z.number().int().optional(), details: z.record(z.string(), z.unknown()).optional()})).optional(), samples_truncated: z.boolean().nullable().optional(), details: z.object({message_content: z.array(z.string()).optional()}).nullable().optional()}))}); export const getApiApiV1AutomationBlockersResponse = z.object({pagination: pagination, results: z.array(automationBlocker)}); 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 automation blockers * * GET /api/v1/automation_blockers */ export const getApiApiV1AutomationBlockers = async (args: GetApiApiV1AutomationBlockersArgs, options?: GetApiApiV1AutomationBlockersOptions) => { const {baseUrl = "https://example.rossum.app", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.id != null) query.append("id", args.id.join(',')) if (args.annotation != null) query.append("annotation", String(args.annotation)) if (args.ordering != null) query.append("ordering", String(args.ordering)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/automation_blockers${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(getApiApiV1AutomationBlockersResponse, await res.json()) };