import {z} from 'zod' export type Metadata = Record; export type DocumentRejectionConditions = {enabled?: boolean | undefined, resolution_lower_than_px?: Array | undefined, file_size_less_than_b?: (number | null) | undefined, mime_types?: Array | undefined, file_name_regexes?: (Array | null) | undefined}; export type Filters = {allowed_senders?: Array | undefined, denied_senders?: Array | undefined, document_rejection_conditions?: DocumentRejectionConditions | undefined}; export type ModifiedBy = string | null; export type ModifiedAt = string | null; export type InboxBase = {id?: number | undefined, name?: string | undefined, url?: string | undefined, queues?: Array | undefined, email?: string | undefined, email_prefix?: string | undefined, bounce_email_to?: (string | null) | undefined, bounce_unprocessable_attachments?: boolean | undefined, bounce_postponed_annotations?: boolean | undefined, bounce_deleted_annotations?: boolean | undefined, bounce_email_with_no_attachments?: boolean | undefined, metadata?: Metadata | undefined, filters?: Filters | undefined, dmarc_check_action?: ('accept' | 'drop') | undefined, modified_by?: ModifiedBy | undefined, modified_at?: ModifiedAt | undefined}; export type PatchApiApiV1InboxesInboxIDArgs = {inboxID: number, body: InboxBase}; export type PatchApiApiV1InboxesInboxIDOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const metadata = z.object({}); export const documentRejectionConditions = z.object({enabled: z.boolean().optional(), resolution_lower_than_px: z.array(z.number().int()).optional(), file_size_less_than_b: z.number().int().nullable().optional(), mime_types: z.array(z.string()).optional(), file_name_regexes: z.array(z.string()).nullable().optional()}); export const filters = z.object({allowed_senders: z.array(z.string()).optional(), denied_senders: z.array(z.string()).optional(), document_rejection_conditions: documentRejectionConditions.optional()}); export const modifiedBy = z.string().nullable(); export const modifiedAt = z.string().nullable(); export const inbox = z.object({id: z.number().int(), name: z.string(), url: z.string(), queues: z.array(z.string()), email: z.string(), email_prefix: z.string().max(57), bounce_email_to: z.string().nullable(), bounce_unprocessable_attachments: z.boolean(), bounce_postponed_annotations: z.boolean(), bounce_deleted_annotations: z.boolean(), bounce_email_with_no_attachments: z.boolean(), metadata: metadata, filters: filters, dmarc_check_action: z.enum(["accept", "drop"]), modified_by: modifiedBy, modified_at: modifiedAt}); 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 inbox * * PATCH /api/v1/inboxes/{inboxID} */ export const patchApiApiV1InboxesInboxID = async (args: PatchApiApiV1InboxesInboxIDArgs, options?: PatchApiApiV1InboxesInboxIDOptions) => { 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/inboxes/${encodeURIComponent(String(args.inboxID))}${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(inbox, await res.json()) };