File
Blob: src/shared/contracts/emails.ts
| 1 | import { eg, type TypeFromCodec } from "@cloudflare/util-en-garde"; |
| 2 | import { NullableNumber, NullableString } from "./common"; |
| 3 | |
| 4 | export const EMAIL_PAGE_SIZE = 20; |
| 5 | |
| 6 | export const EmailSummary = eg.object({ |
| 7 | id: eg.string, |
| 8 | recipientAddress: eg.string, |
| 9 | fromAddress: eg.string, |
| 10 | fromName: NullableString, |
| 11 | subject: eg.string, |
| 12 | receivedAt: eg.string, |
| 13 | isRead: eg.boolean, |
| 14 | hasAttachments: eg.boolean, |
| 15 | sizeBytes: eg.number, |
| 16 | }); |
| 17 | export type EmailSummary = TypeFromCodec<typeof EmailSummary>; |
| 18 | |
| 19 | export const EmailAttachment = eg.object({ |
| 20 | id: eg.string, |
| 21 | filename: NullableString, |
| 22 | contentType: NullableString, |
| 23 | sizeBytes: eg.number, |
| 24 | }); |
| 25 | export type EmailAttachment = TypeFromCodec<typeof EmailAttachment>; |
| 26 | |
| 27 | export const EmailDetail = eg.object({ |
| 28 | id: eg.string, |
| 29 | recipientAddress: eg.string, |
| 30 | fromAddress: eg.string, |
| 31 | fromName: NullableString, |
| 32 | subject: eg.string, |
| 33 | receivedAt: eg.string, |
| 34 | isRead: eg.boolean, |
| 35 | hasAttachments: eg.boolean, |
| 36 | sizeBytes: eg.number, |
| 37 | text: NullableString, |
| 38 | html: NullableString, |
| 39 | attachments: eg.array(EmailAttachment), |
| 40 | }); |
| 41 | export type EmailDetail = TypeFromCodec<typeof EmailDetail>; |
| 42 | |
| 43 | export const EmailPage = eg.object({ |
| 44 | emails: eg.array(EmailSummary), |
| 45 | total: NullableNumber, |
| 46 | page: eg.number, |
| 47 | }); |
| 48 | export type EmailPage = TypeFromCodec<typeof EmailPage>; |
| 49 | |
| 50 | export const NewEmailEvent = eg.object({ |
| 51 | type: eg.literal("new_email"), |
| 52 | email: EmailSummary, |
| 53 | }); |
| 54 | export type NewEmailEvent = TypeFromCodec<typeof NewEmailEvent>; |
| 55 | |
| 56 | export const NewEmailNotification = eg.omit(NewEmailEvent, ["type"]); |
| 57 | export type NewEmailNotification = TypeFromCodec<typeof NewEmailNotification>; |