Dough Git

clove/email

src/shared/types.ts

back to src/shared

// Shapes the API sends and receives, shared by the Worker and the Svelte app.

export type Folder = "inbox" | "sent" | "drafts";

/**
 * What the thread list can show: a folder, the Bin (anything deleted, from
 * any folder), or Starred (starred threads, from any folder, outside the Bin).
 */
export type ListFolder = Folder | "bin" | "starred";

/** What swiping a row does: toggle read, toggle starred, move to the Bin, or nothing. */
export const SWIPE_ACTIONS = ["none", "read", "star", "bin"] as const;
export type SwipeAction = (typeof SWIPE_ACTIONS)[number];

/** Settings that follow the user between the web and the app. */
export interface Preferences {
  /** Show `picture` as the account's picture; otherwise the default (an initial). */
  usePicture: boolean;
  swipeLeft: SwipeAction;
  swipeRight: SwipeAction;
}

export interface Me extends Preferences {
  username: string;
  /** Display name put on outgoing mail; null sends from the bare address. */
  name: string | null;
  /** The account's picture on the SSO (https), whether or not it's in use. */
  picture: string | null;
  isAdmin: boolean;
  /** Every address this user can send from, across all enabled domains. */
  addresses: string[];
  domains: string[];
  pushPublicKey: string | null;
}

export interface Page<T> {
  items: T[];
  nextCursor: string | null;
}

export interface ThreadSummary {
  id: string;
  /** The newest message in the folder being listed. */
  latestId: string;
  mailbox: string;
  subject: string;
  from: string;
  to: string[];
  snippet: string;
  lastAt: number;
  count: number;
  unread: number;
  hasAttachments: boolean;
  starred: boolean;
}

export interface AttachmentInfo {
  id: string;
  filename: string;
  contentType: string;
  size: number;
  contentId: string | null;
}

export interface Message {
  id: string;
  threadId: string;
  folder: Folder;
  mailbox: string;
  from: string;
  to: string[];
  cc: string[];
  /** Only on messages we sent (or drafts); always empty for received mail. */
  bcc: string[];
  subject: string;
  /** Plain-text preview, shown while the message is collapsed. */
  snippet: string;
  /** Email HTML. Only ever render it inside the sandboxed EmailFrame. */
  html: string | null;
  text: string | null;
  sentAt: number;
  read: boolean;
  attachments: AttachmentInfo[];
}

export interface Thread {
  id: string;
  subject: string;
  starred: boolean;
  messages: Message[];
}

export interface ComposeInput {
  from: string;
  to: string[];
  cc: string[];
  bcc: string[];
  subject: string;
  /** Plain text; the server renders the HTML part from it. */
  text: string;
  /** Uploads, or attachments of the user's other messages when forwarding. */
  attachmentIds: string[];
  /** Message being replied to; threads the new one onto it. */
  replyTo?: string | null;
}

export interface DomainInfo {
  name: string;
  /** The admin's switch. New domains from Resend start switched on. */
  enabled: boolean;
  /** Actually routing mail: enabled, and Resend has receiving on. */
  active: boolean;
  catchAll: string | null;
  syncedAt: number | null;
  /** What Resend last reported; null once the domain is gone from Resend. */
  resend: { status: string; sending: boolean; receiving: boolean } | null;
}

export interface AliasInfo {
  localPart: string;
  /** "" means every domain. */
  domain: string;
  username: string;
}

export interface UserInfo {
  username: string;
  name: string | null;
  isAdmin: boolean;
  createdAt: number;
  lastLoginAt: number;
  messageCount: number;
  addresses: string[];
}

export interface ApiError {
  error: string;
}