import {z} from 'zod' export type DocumentAttachmentStatus = 'null' | 'filtered_by_inbox_resolution' | 'filtered_by_inbox_size' | 'filtered_by_inbox_mime_type' | 'filtered_by_inbox_file_name' | 'filtered_by_hook_custom' | 'filtered_by_queue_mime_type' | 'hook_additional_file' | 'hook_converted' | 'filtered_by_insecure_mime_type' | 'extracted_archive' | 'failed_to_extract' | 'processed' | 'password_protected_archive' | 'broken_image' | null; export type Metadata = Record; export type Document = {id?: number | undefined, url?: string | undefined, s3_name?: string | undefined, parent?: (string | null) | undefined, email?: (string | null) | undefined, annotations?: Array | undefined, mime_type?: string | undefined, creator?: (string | null) | undefined, created_at?: string | undefined, arrived_at?: string | undefined, original_file_name?: string | undefined, content?: string | undefined, attachment_status?: DocumentAttachmentStatus | undefined, metadata?: Metadata | undefined}; export type PatchApiApiV1DocumentsDocumentIDArgs = {documentID: number, body: Document}; export type PatchApiApiV1DocumentsDocumentIDOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const documentAttachmentStatus = z.enum(["null", "filtered_by_inbox_resolution", "filtered_by_inbox_size", "filtered_by_inbox_mime_type", "filtered_by_inbox_file_name", "filtered_by_hook_custom", "filtered_by_queue_mime_type", "hook_additional_file", "hook_converted", "filtered_by_insecure_mime_type", "extracted_archive", "failed_to_extract", "processed", "password_protected_archive", "broken_image"]).nullable(); export const metadata = z.object({}); export const document = z.object({id: z.number().int().optional(), url: z.string().optional(), s3_name: z.string().optional(), parent: z.string().nullable().optional(), email: z.string().nullable().optional(), annotations: z.array(z.string()).optional(), mime_type: z.string().optional(), creator: z.string().nullable().optional(), created_at: z.string().optional(), arrived_at: z.string().optional(), original_file_name: z.string().optional(), content: z.string().optional(), attachment_status: documentAttachmentStatus.optional(), metadata: metadata.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 }; /** * Partial update document * * PATCH /api/v1/documents/{documentID} */ export const patchApiApiV1DocumentsDocumentID = async (args: PatchApiApiV1DocumentsDocumentIDArgs, options?: PatchApiApiV1DocumentsDocumentIDOptions) => { 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/documents/${encodeURIComponent(String(args.documentID))}${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(document, await res.json()) };