SPB Git

Repository Public

types.ts 11.1 KB 375 lines typescript

1// Types JMAP (RFC 8620 / 8621 / 9007 / 9425 / 9661) — seulement ce que le webmail utilise, mais typé de bout en bout.2export type Id = string3export type UTCDate = string45export interface EmailAddress {6  name: string | null7  email: string8}910export interface ResultReference {11  resultOf: string12  name: string13  path: string14}1516export interface Session {17  capabilities: Record<string, unknown>18  accounts: Record<Id, { name: string; isPersonal: boolean; isReadOnly: boolean; accountCapabilities: Record<string, unknown> }>19  primaryAccounts: Record<string, Id>20  username: string21  apiUrl: string22  downloadUrl: string23  uploadUrl: string24  eventSourceUrl: string25  state: string26}2728export interface MailboxRights {29  mayReadItems: boolean30  mayAddItems: boolean31  mayRemoveItems: boolean32  maySetSeen: boolean33  maySetKeywords: boolean34  mayCreateChild: boolean35  mayRename: boolean36  mayDelete: boolean37  maySubmit: boolean38}39export type MailboxRole = "inbox" | "drafts" | "sent" | "trash" | "junk" | "archive" | "important" | "all" | "flagged"40export interface Mailbox {41  id: Id42  name: string43  parentId: Id | null44  role: MailboxRole | string | null45  sortOrder: number46  totalEmails: number47  unreadEmails: number48  totalThreads: number49  unreadThreads: number50  myRights: MailboxRights51  isSubscribed: boolean52}5354export interface EmailBodyPart {55  partId: string | null56  blobId: Id | null57  size: number58  name: string | null59  type: string60  charset: string | null61  disposition: string | null62  cid: string | null63  location: string | null64}65export interface EmailBodyValue {66  value: string67  isEncodingProblem: boolean68  isTruncated: boolean69}70export interface EmailHeader {71  name: string72  value: string73}7475/** Propriétés chargées pour une ligne de la liste. */76export interface EmailSummary {77  id: Id78  blobId: Id79  threadId: Id80  mailboxIds: Record<Id, boolean>81  keywords: Record<string, boolean>82  size: number83  receivedAt: UTCDate84  from: EmailAddress[] | null85  to: EmailAddress[] | null86  subject: string | null87  preview: string88  hasAttachment: boolean89}90/** Propriétés chargées à l'ouverture d'un message. */91export interface EmailFull extends EmailSummary {92  sentAt: UTCDate | null93  messageId: string[] | null94  inReplyTo: string[] | null95  references: string[] | null96  sender: EmailAddress[] | null97  cc: EmailAddress[] | null98  bcc: EmailAddress[] | null99  replyTo: EmailAddress[] | null100  bodyValues: Record<string, EmailBodyValue>101  textBody: EmailBodyPart[]102  htmlBody: EmailBodyPart[]103  attachments: EmailBodyPart[]104  headers: EmailHeader[]105}106107export const SUMMARY_PROPS = ["id", "blobId", "threadId", "mailboxIds", "keywords", "size", "receivedAt", "from", "to", "subject", "preview", "hasAttachment"] as const108export const FULL_PROPS = [...SUMMARY_PROPS, "sentAt", "messageId", "inReplyTo", "references", "sender", "cc", "bcc", "replyTo", "bodyValues", "textBody", "htmlBody", "attachments", "headers"] as const109export const BODY_PROPS = ["partId", "blobId", "size", "name", "type", "charset", "disposition", "cid", "location"] as const110111export interface EmailCreate {112  mailboxIds: Record<Id, boolean>113  keywords?: Record<string, boolean>114  from?: EmailAddress[]115  to?: EmailAddress[]116  cc?: EmailAddress[]117  bcc?: EmailAddress[]118  replyTo?: EmailAddress[]119  subject?: string120  inReplyTo?: string[] | null121  references?: string[] | null122  sentAt?: UTCDate123  bodyValues?: Record<string, { value: string }>124  textBody?: { partId: string; type: "text/plain" }[]125  htmlBody?: { partId: string; type: "text/html" }[]126  attachments?: { blobId: Id; type: string; name: string | null; disposition: "attachment" | "inline"; cid?: string | null }[]127}128129export interface Thread {130  id: Id131  emailIds: Id[]132}133134export interface Identity {135  id: Id136  name: string137  email: string138  replyTo: EmailAddress[] | null139  bcc: EmailAddress[] | null140  textSignature: string141  htmlSignature: string142  mayDelete: boolean143}144145export type DeliveredState = "queued" | "yes" | "no" | "unknown"146export interface DeliveryStatus {147  smtpReply: string148  delivered: DeliveredState149  displayed: "unknown" | "yes"150}151export interface EmailSubmission {152  id: Id153  identityId: Id154  emailId: Id155  threadId: Id156  envelope: { mailFrom: { email: string }; rcptTo: { email: string }[] } | null157  sendAt: UTCDate158  undoStatus: "pending" | "final" | "canceled"159  deliveryStatus: Record<string, DeliveryStatus> | null160}161162export interface Quota {163  id: Id164  resourceType: "count" | "octets" | string165  used: number166  hardLimit: number167  warnLimit?: number | null168  softLimit?: number | null169  scope: string170  name: string171  description?: string | null172  types: string[]173}174175export interface VacationResponse {176  id: "singleton"177  isEnabled: boolean178  fromDate: UTCDate | null179  toDate: UTCDate | null180  subject: string | null181  textBody: string | null182  htmlBody: string | null183}184185export interface SieveScript {186  id: Id187  name: string | null188  blobId: Id189  isActive: boolean190}191192// ---------------------------------------------------------------- filtres et tris193export interface EmailFilterCondition {194  inMailbox?: Id195  inMailboxOtherThan?: Id[]196  before?: UTCDate197  after?: UTCDate198  hasKeyword?: string199  notKeyword?: string200  hasAttachment?: boolean201  text?: string202  from?: string203  to?: string204  cc?: string205  subject?: string206  body?: string207}208export interface EmailFilterOperator {209  operator: "AND" | "OR" | "NOT"210  conditions: EmailFilter[]211}212export type EmailFilter = EmailFilterCondition | EmailFilterOperator213export interface EmailSort {214  property: "receivedAt" | "sentAt" | "size" | "from" | "to" | "subject" | "hasKeyword"215  keyword?: string216  isAscending?: boolean217}218219// ---------------------------------------------------------------- arguments / réponses génériques220type WithRef<T, K extends keyof T> = Omit<T, K> & ({ [P in K]: T[P] } | { [P in K as `#${string & P}`]: ResultReference })221222export interface GetArgsBase {223  ids: Id[] | null224  properties?: readonly string[]225}226export type GetArgs = WithRef<GetArgsBase, "ids">227export interface GetResponse<T> {228  accountId: Id229  state: string230  list: T[]231  notFound: Id[] | null232}233export interface ChangesArgs {234  sinceState: string235  maxChanges?: number236}237export interface ChangesResponse {238  accountId: Id239  oldState: string240  newState: string241  hasMoreChanges: boolean242  created: Id[]243  updated: Id[]244  destroyed: Id[]245}246export interface SetError {247  type: string248  description?: string | null249  properties?: string[]250}251export interface SetArgs<TCreate> {252  ifInState?: string253  create?: Record<string, TCreate>254  update?: Record<Id, Record<string, unknown>>255  destroy?: Id[]256}257export interface SetResponse<T> {258  accountId: Id259  oldState: string | null260  newState: string261  created?: Record<string, Partial<T> & { id: Id }> | null262  updated?: Record<Id, Partial<T> | null> | null263  destroyed?: Id[] | null264  notCreated?: Record<string, SetError> | null265  notUpdated?: Record<Id, SetError> | null266  notDestroyed?: Record<Id, SetError> | null267}268export interface QueryArgs {269  filter?: EmailFilter | null270  sort?: EmailSort[]271  position?: number272  limit?: number273  calculateTotal?: boolean274  collapseThreads?: boolean275}276export interface QueryResponse {277  accountId: Id278  queryState: string279  canCalculateChanges: boolean280  position: number281  ids: Id[]282  total?: number283  limit?: number284}285/** Email/queryChanges (RFC 8620 §5.6) : ce qui a changé dans les résultats d'une requête depuis `sinceQueryState`. */286export interface QueryChangesArgs {287  filter?: EmailFilter | null288  sort?: EmailSort[]289  collapseThreads?: boolean290  sinceQueryState: string291  maxChanges?: number292  /** dernier identifiant que le client a en cache : le serveur n'a pas à décrire ce qui se passe au-delà */293  upToId?: Id | null294  calculateTotal?: boolean295}296export interface QueryChangesResponse {297  accountId: Id298  oldQueryState: string299  newQueryState: string300  total?: number301  removed: Id[]302  added: { id: Id; index: number }[]303}304export type EmailGetArgs = GetArgs & {305  bodyProperties?: readonly string[]306  fetchTextBodyValues?: boolean307  fetchHTMLBodyValues?: boolean308  fetchAllBodyValues?: boolean309  maxBodyValueBytes?: number310}311312export interface MailboxCreate {313  name: string314  parentId: Id | null315  role?: string | null316  isSubscribed?: boolean317}318export interface IdentityCreate {319  name: string320  email: string321  replyTo?: EmailAddress[] | null322  textSignature?: string323  htmlSignature?: string324}325export interface EmailSubmissionCreate {326  identityId: Id327  emailId: Id328  envelope?: { mailFrom: { email: string }; rcptTo: { email: string }[] } | null329}330331/** Carte des méthodes : nom → [arguments (sans accountId), réponse]. */332export interface MethodMap {333  "Mailbox/get": [GetArgs, GetResponse<Mailbox>]334  "Mailbox/changes": [ChangesArgs, ChangesResponse & { updatedProperties?: string[] | null }]335  "Mailbox/set": [SetArgs<MailboxCreate> & { onDestroyRemoveEmails?: boolean }, SetResponse<Mailbox>]336  "Email/query": [QueryArgs, QueryResponse]337  "Email/queryChanges": [QueryChangesArgs, QueryChangesResponse]338  "Email/get": [EmailGetArgs, GetResponse<EmailFull>]339  "Email/changes": [ChangesArgs, ChangesResponse]340  "Email/set": [SetArgs<EmailCreate>, SetResponse<EmailFull>]341  "Thread/get": [GetArgs, GetResponse<Thread>]342  "SearchSnippet/get": [WithRef<{ emailIds: Id[]; filter?: EmailFilter | null }, "emailIds">, { list: { emailId: Id; subject: string | null; preview: string | null }[]; notFound: Id[] | null }]343  "Identity/get": [GetArgs, GetResponse<Identity>]344  "Identity/set": [SetArgs<IdentityCreate>, SetResponse<Identity>]345  "EmailSubmission/get": [GetArgs, GetResponse<EmailSubmission>]346  "EmailSubmission/set": [SetArgs<EmailSubmissionCreate> & { onSuccessUpdateEmail?: Record<string, Record<string, unknown>>; onSuccessDestroyEmail?: string[] }, SetResponse<EmailSubmission>]347  "Quota/get": [GetArgs, GetResponse<Quota>]348  "VacationResponse/get": [GetArgs, GetResponse<VacationResponse>]349  "VacationResponse/set": [SetArgs<never>, SetResponse<VacationResponse>]350  "SieveScript/get": [GetArgs, GetResponse<SieveScript>]351  "SieveScript/set": [SetArgs<{ name: string | null; blobId: Id }> & { onSuccessActivateScript?: Id | null; onSuccessDeactivateScript?: boolean }, SetResponse<SieveScript>]352  "SieveScript/validate": [{ blobId: Id }, { accountId: Id; error: SetError | null }]353}354export type MethodName = keyof MethodMap355export type MethodArgs<M extends MethodName> = MethodMap[M][0]356export type MethodResponse<M extends MethodName> = MethodMap[M][1]357export type Invocation = [name: string, args: Record<string, unknown>, callId: string]358359export const CAP = {360  core: "urn:ietf:params:jmap:core",361  mail: "urn:ietf:params:jmap:mail",362  submission: "urn:ietf:params:jmap:submission",363  vacation: "urn:ietf:params:jmap:vacationresponse",364  sieve: "urn:ietf:params:jmap:sieve",365  quota: "urn:ietf:params:jmap:quota",366  blob: "urn:ietf:params:jmap:blob",367} as const368369/** Mots-clés. `$pinned` est propre à SP Mail (épingler en tête de liste) ; les autres sont enregistrés à l'IANA. */370export const KW = { seen: "$seen", flagged: "$flagged", draft: "$draft", answered: "$answered", forwarded: "$forwarded", junk: "$junk", notJunk: "$notjunk", pinned: "$pinned" } as const371372export interface StateChange {373  changed: Record<Id, Record<string, string>>374}375
Files main
Menu

Theme