import {z} from 'zod' export type CreateApiApiV1AnnotationsAnnotationIDContentValidateArgs = {messages_for_hidden_datapoints?: boolean | undefined, body: {actions?: (Array<'user_update' | 'updated' | 'started'>) | undefined, updated_datapoint_ids?: Array | undefined}}; export type CreateApiApiV1AnnotationsAnnotationIDContentValidateOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV1AnnotationsAnnotationIDContentValidateResponse = z.object({messages: z.array(z.object({id: z.string().optional(), type: z.enum(["error", "warning", "info", "aggregation"]).optional(), content: z.string().optional(), detail: z.object({hook_id: z.number().int().nullable().optional(), hook_name: z.string().optional(), request_id: z.string().optional(), timestamp: z.string().optional(), is_exception: z.boolean().optional(), traceback_line_number: z.number().int().optional(), source_id: z.number().int().optional(), source_schema_id: z.string().optional()}).optional(), aggregation_type: z.string().optional(), schema_id: z.string().optional()})).optional(), updated_datapoints: z.array(z.object({})).optional(), suggested_operations: z.array(z.object({})).optional(), matched_trigger_rules: z.array(z.object({})).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 }; /** * Validate annotation content * * POST /api/v1/annotations/{annotationID}/content/validate */ export const createApiApiV1AnnotationsAnnotationIDContentValidate = async (args: CreateApiApiV1AnnotationsAnnotationIDContentValidateArgs, options?: CreateApiApiV1AnnotationsAnnotationIDContentValidateOptions) => { const {baseUrl = "https://example.rossum.app", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.messages_for_hidden_datapoints != null) query.append("messages_for_hidden_datapoints", String(args.messages_for_hidden_datapoints)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/annotations/${encodeURIComponent(String(args.annotationID))}/content/validate${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiApiV1AnnotationsAnnotationIDContentValidateResponse, await res.json()) };