import {z} from 'zod' export type GetApiApiV1AnnotationsAnnotationIDOptions = {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 }; /** * Retrieve annotation * * GET /api/v1/annotations/{annotationID} */ export const getApiApiV1AnnotationsAnnotationID = async (options?: GetApiApiV1AnnotationsAnnotationIDOptions) => { 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 (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: "GET", headers}) 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()) };