import {z} from 'zod' export type Creator = string | null; export type CreatedAt = string; export type ModifiedBy = string | null; export type ModifiedAt = string | null; export type Metadata = Record; export type Assignees = Array; export type AnnotationBase = {id?: number | undefined, url?: string | undefined, status?: ('confirmed' | 'created' | 'deleted' | 'exported' | 'exporting' | 'failed_export' | 'failed_import' | 'importing' | 'in_workflow' | 'postponed' | 'purged' | 'rejected' | 'reviewing' | 'split' | 'to_review') | undefined, document?: string | undefined, queue?: string | undefined, schema?: string | undefined, relations?: Array | undefined, pages?: Array | undefined, creator?: Creator | undefined, created_at?: CreatedAt | undefined, modifier?: (string | null) | undefined, modified_by?: ModifiedBy | undefined, modified_at?: ModifiedAt | undefined, assigned_at?: (string | null) | undefined, confirmed_at?: (string | null) | undefined, deleted_at?: (string | null) | undefined, exported_at?: (string | null) | undefined, export_failed_at?: (string | null) | undefined, purged_at?: (string | null) | undefined, rejected_at?: (string | null) | undefined, confirmed_by?: (string | null) | undefined, deleted_by?: (string | null) | undefined, exported_by?: (string | null) | undefined, purged_by?: (string | null) | undefined, rejected_by?: (string | null) | undefined, rir_poll_id?: (string | null) | undefined, messages?: (Array<{content?: string | undefined, id?: (number | null) | undefined, type?: ('error' | 'warning' | 'info') | undefined}> | null) | undefined, content?: string | undefined, suggested_edit?: (string | null) | undefined, time_spent?: number | undefined, metadata?: Metadata | undefined, automated?: boolean | undefined, related_emails?: Array | undefined, email?: (string | null) | undefined, automation_blocker?: (string | null) | undefined, email_thread?: (string | null) | undefined, has_email_thread_with_replies?: boolean | undefined, has_email_thread_with_new_replies?: boolean | undefined, organization?: string | undefined, automatically_rejected?: boolean | undefined, prediction?: (Record | null) | undefined, assignees?: Assignees | undefined, labels?: Array | undefined, restricted_access?: boolean | undefined, training_enabled?: boolean | undefined}; export type PatchApiApiV1AnnotationsAnnotationIDArgs = {body: AnnotationBase}; export type PatchApiApiV1AnnotationsAnnotationIDOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const creator = z.string().nullable(); export const createdAt = z.string(); export const modifiedBy = z.string().nullable(); export const modifiedAt = z.string().nullable(); export const metadata = z.object({}); export const assignees = z.array(z.string()); export const annotation = z.object({id: z.number().int(), url: z.string(), status: z.enum(["confirmed", "created", "deleted", "exported", "exporting", "failed_export", "failed_import", "importing", "in_workflow", "postponed", "purged", "rejected", "reviewing", "split", "to_review"]), document: z.string(), queue: z.string(), schema: z.string(), relations: z.array(z.string()), pages: z.array(z.string()), creator: creator, created_at: createdAt, modifier: z.string().nullable(), modified_by: modifiedBy, modified_at: modifiedAt, assigned_at: z.string().nullable(), confirmed_at: z.string().nullable(), deleted_at: z.string().nullable(), exported_at: z.string().nullable(), export_failed_at: z.string().nullable(), purged_at: z.string().nullable(), rejected_at: z.string().nullable(), confirmed_by: z.string().nullable(), deleted_by: z.string().nullable(), exported_by: z.string().nullable(), purged_by: z.string().nullable(), rejected_by: z.string().nullable(), rir_poll_id: z.string().nullable(), messages: z.array(z.object({content: z.string().optional(), id: z.number().int().nullable().optional(), type: z.enum(["error", "warning", "info"]).optional()})).nullable(), content: z.string(), suggested_edit: z.string().nullable(), time_spent: z.number(), metadata: metadata, automated: z.boolean(), related_emails: z.array(z.string()), email: z.string().nullable(), automation_blocker: z.string().nullable(), email_thread: z.string().nullable(), has_email_thread_with_replies: z.boolean().optional(), has_email_thread_with_new_replies: z.boolean().optional(), organization: z.string(), automatically_rejected: z.boolean(), prediction: z.object({}).nullable(), assignees: assignees, labels: z.array(z.string()), restricted_access: z.boolean(), training_enabled: z.boolean()}); 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 }; /** * Partial update annotation * * PATCH /api/v1/annotations/{annotationID} */ export const patchApiApiV1AnnotationsAnnotationID = async (args: PatchApiApiV1AnnotationsAnnotationIDArgs, options?: PatchApiApiV1AnnotationsAnnotationIDOptions) => { 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 (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/annotations/${encodeURIComponent(String(args.annotationID))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(annotation, await res.json()) };