import { eg, type TypeFromCodec } from "@cloudflare/util-en-garde"; import { NullableNumber, NullableString } from "./common"; export const EMAIL_PAGE_SIZE = 20; export const EmailSummary = eg.object({ id: eg.string, recipientAddress: eg.string, fromAddress: eg.string, fromName: NullableString, subject: eg.string, receivedAt: eg.string, isRead: eg.boolean, hasAttachments: eg.boolean, sizeBytes: eg.number, }); export type EmailSummary = TypeFromCodec; export const EmailAttachment = eg.object({ id: eg.string, filename: NullableString, contentType: NullableString, sizeBytes: eg.number, }); export type EmailAttachment = TypeFromCodec; export const EmailDetail = eg.object({ id: eg.string, recipientAddress: eg.string, fromAddress: eg.string, fromName: NullableString, subject: eg.string, receivedAt: eg.string, isRead: eg.boolean, hasAttachments: eg.boolean, sizeBytes: eg.number, text: NullableString, html: NullableString, attachments: eg.array(EmailAttachment), }); export type EmailDetail = TypeFromCodec; export const EmailPage = eg.object({ emails: eg.array(EmailSummary), total: NullableNumber, page: eg.number, }); export type EmailPage = TypeFromCodec; export const NewEmailEvent = eg.object({ type: eg.literal("new_email"), email: EmailSummary, }); export type NewEmailEvent = TypeFromCodec; export const NewEmailNotification = eg.omit(NewEmailEvent, ["type"]); export type NewEmailNotification = TypeFromCodec;