import {z} from 'zod' export type GetApiApiV1EmailTemplatesArgs = {page_size?: number | undefined, cursor?: string | undefined, id?: Array | undefined, queue?: Array | undefined, type?: ('rejection' | 'rejection_default' | 'email_with_no_processable_attachments' | 'custom') | undefined, name?: string | undefined, ordering?: ('id' | '-id' | 'name' | '-name') | undefined}; export type GetApiApiV1EmailTemplatesOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const pagination = z.object({next: z.string().nullable().optional(), previous: z.string().nullable().optional()}); export const queueUrl = z.string(); export const emailAddress = z.object({email: z.string(), name: z.string().nullable().optional()}); export const modifiedBy = z.string().nullable(); export const modifiedAt = z.string().nullable(); export const emailTemplate = z.object({id: z.number().int(), url: z.string(), name: z.string(), queue: queueUrl, organization: z.string(), triggers: z.array(z.string()), type: z.enum(["rejection", "rejection_default", "email_with_no_processable_attachments", "custom"]), subject: z.string(), message: z.string(), enabled: z.boolean(), automate: z.boolean(), to: z.array(emailAddress), cc: z.array(emailAddress), bcc: z.array(emailAddress), modified_by: modifiedBy, modified_at: modifiedAt}); export const getApiApiV1EmailTemplatesResponse = z.object({pagination: pagination, results: z.array(emailTemplate)}); 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 email templates * * GET /api/v1/email_templates */ export const getApiApiV1EmailTemplates = async (args: GetApiApiV1EmailTemplatesArgs, options?: GetApiApiV1EmailTemplatesOptions) => { 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.queue != null) query.append("queue", args.queue.join(',')) if (args.type != null) query.append("type", String(args.type)) if (args.name != null) query.append("name", String(args.name)) if (args.ordering != null) query.append("ordering", String(args.ordering)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/email_templates${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(getApiApiV1EmailTemplatesResponse, await res.json()) };