File
Blob: src/shared/contracts/inboxes.ts
| 1 | import { eg, type TypeFromCodec } from "@cloudflare/util-en-garde"; |
| 2 | import { NullableString, TurnstileToken } from "./common"; |
| 3 | |
| 4 | export const TEMP_MAILBOX_TTL_HOURS = [24, 48, 72] as const; |
| 5 | export type TempMailboxTtlHours = (typeof TEMP_MAILBOX_TTL_HOURS)[number]; |
| 6 | |
| 7 | const TempMailboxTtlHoursCodecs = TEMP_MAILBOX_TTL_HOURS.map((hours) => eg.literal(hours)); |
| 8 | export const TempMailboxTtlHours = eg.union([ |
| 9 | TempMailboxTtlHoursCodecs[0], |
| 10 | TempMailboxTtlHoursCodecs[1], |
| 11 | TempMailboxTtlHoursCodecs[2], |
| 12 | ]); |
| 13 | |
| 14 | const NullableTempMailboxTtlHours = eg.union([TempMailboxTtlHours, eg.null]); |
| 15 | |
| 16 | export const CreateInboxRequest = eg.object({ |
| 17 | domain: eg.string, |
| 18 | ttlHours: TempMailboxTtlHours, |
| 19 | turnstileToken: TurnstileToken, |
| 20 | }); |
| 21 | export type CreateInboxRequest = TypeFromCodec<typeof CreateInboxRequest>; |
| 22 | |
| 23 | export const InboxSession = eg.object({ |
| 24 | address: eg.string, |
| 25 | token: eg.string, |
| 26 | ttlHours: TempMailboxTtlHours, |
| 27 | expiresAt: eg.string, |
| 28 | }); |
| 29 | export type InboxSession = TypeFromCodec<typeof InboxSession>; |
| 30 | |
| 31 | export const CreateInboxResponse = InboxSession; |
| 32 | export type CreateInboxResponse = InboxSession; |
| 33 | |
| 34 | export const InboxSessionSummary = eg.object({ |
| 35 | address: eg.string, |
| 36 | ttlHours: TempMailboxTtlHours, |
| 37 | expiresAt: eg.string, |
| 38 | }); |
| 39 | export type InboxSessionSummary = TypeFromCodec<typeof InboxSessionSummary>; |
| 40 | |
| 41 | export const InboxSessionSummaryList = eg.array(InboxSessionSummary); |
| 42 | export type InboxSessionSummaryList = TypeFromCodec<typeof InboxSessionSummaryList>; |
| 43 | |
| 44 | export const InboxInfo = eg.object({ |
| 45 | address: eg.string, |
| 46 | isPermanent: eg.boolean, |
| 47 | ttlHours: NullableTempMailboxTtlHours, |
| 48 | expiresAt: NullableString, |
| 49 | createdAt: eg.string, |
| 50 | }); |
| 51 | export type InboxInfo = TypeFromCodec<typeof InboxInfo>; |
| 52 | |
| 53 | export const ExtendInboxRequest = eg.object({ |
| 54 | ttlHours: TempMailboxTtlHours, |
| 55 | }); |
| 56 | export type ExtendInboxRequest = TypeFromCodec<typeof ExtendInboxRequest>; |
| 57 | |
| 58 | export const ExtendInboxResponse = eg.object({ |
| 59 | address: eg.string, |
| 60 | ttlHours: TempMailboxTtlHours, |
| 61 | expiresAt: eg.string, |
| 62 | }); |
| 63 | export type ExtendInboxResponse = TypeFromCodec<typeof ExtendInboxResponse>; |