import {z} from 'zod' export type QueueUrl = string; export type EmailAddress = {email: string, name?: (string | null) | undefined}; export type Metadata = Record; export type AnnotationCounts = {annotations?: number | undefined, annotations_processed?: number | undefined, annotations_purged?: number | undefined, annotations_unprocessed?: number | undefined, annotations_rejected?: number | undefined, related_annotations?: number | undefined}; export type EmailBase = {id?: number | undefined, url?: string | undefined, queue?: QueueUrl | undefined, inbox?: string | undefined, parent?: (string | null) | undefined, email_thread?: (string | null) | undefined, children?: Array | undefined, documents?: Array | undefined, created_at?: string | undefined, last_thread_email_created_at?: (string | null) | undefined, subject?: (string | null) | undefined, from?: ({email: string, name?: (string | null) | undefined}) | undefined, to?: Array | undefined, cc?: Array | undefined, bcc?: Array | undefined, body_text_plain?: (string | null) | undefined, body_text_html?: (string | null) | undefined, metadata?: Metadata | undefined, type?: ('incoming' | 'outgoing') | undefined, annotation_counts?: AnnotationCounts | undefined, annotations?: Array | undefined, related_annotations?: Array | undefined, related_documents?: Array | undefined, creator?: (string | null) | undefined, filtered_out_document_count?: number | undefined, labels?: (Array<'rejection' | 'automatic_rejection' | 'rejected' | 'automatic_status_changed_info' | 'forwarded' | 'reply'>) | undefined, content?: string | undefined}; export type UpdateApiApiV1EmailsEmailIDArgs = {emailID: number, body: EmailBase}; export type UpdateApiApiV1EmailsEmailIDOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const queueUrl = z.string(); export const emailAddress = z.object({email: z.string(), name: z.string().nullable().optional()}); export const metadata = z.object({}); export const annotationCounts = z.object({annotations: z.number().int().optional(), annotations_processed: z.number().int().optional(), annotations_purged: z.number().int().optional(), annotations_unprocessed: z.number().int().optional(), annotations_rejected: z.number().int().optional(), related_annotations: z.number().int().optional()}); export const email = z.object({id: z.number().int(), url: z.string(), queue: queueUrl, inbox: z.string(), parent: z.string().nullable(), email_thread: z.string().nullable(), children: z.array(z.string()), documents: z.array(z.string()), created_at: z.string(), last_thread_email_created_at: z.string().nullable(), subject: z.string().nullable(), from: z.object({email: z.string(), name: z.string().nullable().optional()}), to: z.array(emailAddress), cc: z.array(emailAddress), bcc: z.array(emailAddress), body_text_plain: z.string().nullable(), body_text_html: z.string().nullable(), metadata: metadata, type: z.enum(["incoming", "outgoing"]), annotation_counts: annotationCounts, annotations: z.array(z.string()), related_annotations: z.array(z.string()), related_documents: z.array(z.string()), creator: z.string().nullable(), filtered_out_document_count: z.number().int(), labels: z.array(z.enum(["rejection", "automatic_rejection", "rejected", "automatic_status_changed_info", "forwarded", "reply"])), content: 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 }; /** * Update email * * PUT /api/v1/emails/{emailID} */ export const updateApiApiV1EmailsEmailID = async (args: UpdateApiApiV1EmailsEmailIDArgs, options?: UpdateApiApiV1EmailsEmailIDOptions) => { 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/emails/${encodeURIComponent(String(args.emailID))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(email, await res.json()) };