import {z} from 'zod' export type GetApiApiV1InboxesArgs = {page_size?: number | undefined, cursor?: string | undefined, id?: Array | undefined, name?: string | undefined, email?: string | undefined, email_prefix?: string | undefined, bounce_email_to?: string | undefined, bounce_unprocessable_attachments?: boolean | undefined, bounce_postponed_annotations?: boolean | undefined, bounce_deleted_annotations?: boolean | undefined, bounce_email_with_no_attachments?: boolean | undefined, ordering?: ('id' | '-id' | 'name' | '-name' | 'email' | '-email' | 'email_prefix' | '-email_prefix' | 'bounce_email_to' | '-bounce_email_to') | undefined}; export type GetApiApiV1InboxesOptions = {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 pagination = z.object({next: z.string().nullable().optional(), previous: z.string().nullable().optional()}); export const getApiApiV1InboxesResponse = z.object({results: z.array(inbox).optional(), pagination: pagination.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 }; /** * List inboxes * * GET /api/v1/inboxes */ export const getApiApiV1Inboxes = async (args: GetApiApiV1InboxesArgs, options?: GetApiApiV1InboxesOptions) => { 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.name != null) query.append("name", String(args.name)) if (args.email != null) query.append("email", String(args.email)) if (args.email_prefix != null) query.append("email_prefix", String(args.email_prefix)) if (args.bounce_email_to != null) query.append("bounce_email_to", String(args.bounce_email_to)) if (args.bounce_unprocessable_attachments != null) query.append("bounce_unprocessable_attachments", String(args.bounce_unprocessable_attachments)) if (args.bounce_postponed_annotations != null) query.append("bounce_postponed_annotations", String(args.bounce_postponed_annotations)) if (args.bounce_deleted_annotations != null) query.append("bounce_deleted_annotations", String(args.bounce_deleted_annotations)) if (args.bounce_email_with_no_attachments != null) query.append("bounce_email_with_no_attachments", String(args.bounce_email_with_no_attachments)) if (args.ordering != null) query.append("ordering", String(args.ordering)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/inboxes${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(getApiApiV1InboxesResponse, await res.json()) };