Skip to content
File

Blob: src/shared/contracts/emails.ts

typescript58 lines
1import { eg, type TypeFromCodec } from "@cloudflare/util-en-garde";
2import { NullableNumber, NullableString } from "./common";
3 
4export const EMAIL_PAGE_SIZE = 20;
5 
6export 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});
17export type EmailSummary = TypeFromCodec<typeof EmailSummary>;
18 
19export const EmailAttachment = eg.object({
20 id: eg.string,
21 filename: NullableString,
22 contentType: NullableString,
23 sizeBytes: eg.number,
24});
25export type EmailAttachment = TypeFromCodec<typeof EmailAttachment>;
26 
27export 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});
41export type EmailDetail = TypeFromCodec<typeof EmailDetail>;
42 
43export const EmailPage = eg.object({
44 emails: eg.array(EmailSummary),
45 total: NullableNumber,
46 page: eg.number,
47});
48export type EmailPage = TypeFromCodec<typeof EmailPage>;
49 
50export const NewEmailEvent = eg.object({
51 type: eg.literal("new_email"),
52 email: EmailSummary,
53});
54export type NewEmailEvent = TypeFromCodec<typeof NewEmailEvent>;
55 
56export const NewEmailNotification = eg.omit(NewEmailEvent, ["type"]);
57export type NewEmailNotification = TypeFromCodec<typeof NewEmailNotification>;