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 GetApiApiV1DocumentsArgs = {page_size?: number | undefined, cursor?: string | undefined, id?: Array | undefined, email?: Array | undefined, creator?: Array | undefined, created_at_before?: string | undefined, created_at_after?: string | undefined, arrived_at_before?: string | undefined, arrived_at_after?: string | undefined, original_file_name?: string | undefined, attachment_status?: DocumentAttachmentStatus | undefined, parent?: number | undefined, ordering?: ('id' | '-id' | 'arrived_at' | '-arrived_at' | 'created_at' | '-created_at' | 'original_file_name' | '-original_file_name' | 'mime_type' | '-mime_type' | 'attachment_status' | '-attachment_status') | undefined}; export type GetApiApiV1DocumentsOptions = {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 pagination = z.object({next: z.string().nullable().optional(), previous: z.string().nullable().optional()}); export const getApiApiV1DocumentsResponse = z.object({results: z.array(document), pagination: pagination}); 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 }; /** * List documents * * GET /api/v1/documents */ export const getApiApiV1Documents = async (args: GetApiApiV1DocumentsArgs, options?: GetApiApiV1DocumentsOptions) => { 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 (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.id != null) query.append("id", args.id.join(',')) if (args.email != null) query.append("email", args.email.join(',')) if (args.creator != null) query.append("creator", args.creator.join(',')) if (args.created_at_before != null) query.append("created_at_before", String(args.created_at_before)) if (args.created_at_after != null) query.append("created_at_after", String(args.created_at_after)) if (args.arrived_at_before != null) query.append("arrived_at_before", String(args.arrived_at_before)) if (args.arrived_at_after != null) query.append("arrived_at_after", String(args.arrived_at_after)) if (args.original_file_name != null) query.append("original_file_name", String(args.original_file_name)) if (args.attachment_status != null) query.append("attachment_status", String(args.attachment_status)) if (args.parent != null) query.append("parent", String(args.parent)) if (args.ordering != null) query.append("ordering", String(args.ordering)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/documents${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(getApiApiV1DocumentsResponse, await res.json()) };