import {z} from 'zod' export type CreateApiApiV1AnnotationsAnnotationIDEditPagesStartArgs = {annotationID: number}; export type CreateApiApiV1AnnotationsAnnotationIDEditPagesStartOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const editPage = z.object({page: z.string(), rotation_deg: z.union([z.literal(0), z.literal(90), z.literal(180), z.literal(270)]).optional(), deleted: z.boolean().optional()}); export const createApiApiV1AnnotationsAnnotationIDEditPagesStartResponse = z.object({parent_annotation: z.string().optional(), children: z.array(z.object({parent_pages: z.array(editPage).optional(), queue: z.string().nullable().optional(), status: z.string().nullable().optional(), url: z.string().nullable().optional(), original_file_name: z.string().optional(), values: z.object({}).optional(), started: z.boolean().optional()})).optional(), session_timeout: z.string().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 }; /** * Start edit pages session * * POST /api/v1/annotations/{annotationID}/edit_pages/start */ export const createApiApiV1AnnotationsAnnotationIDEditPagesStart = async (args: CreateApiApiV1AnnotationsAnnotationIDEditPagesStartArgs, options?: CreateApiApiV1AnnotationsAnnotationIDEditPagesStartOptions) => { 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))}/edit_pages/start${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiApiV1AnnotationsAnnotationIDEditPagesStartResponse, await res.json()) };