Repository Public
1// API REST /api/v1 vue par la session web (docs/API.md) : types des objets échangés et petit client.2// La session agit avec les droits de l'utilisateur ; les règles anti-CSRF sont celles du reste du backend (jmap/http.ts).3import { api, type RequestOptions } from "../jmap/http"45export const V1 = "/api/v1"6export const v1 = <T>(path: string, opts: RequestOptions = {}) => api<T>(`${V1}${path}`, opts)78export type AddressKind = "mailbox" | "shared" | "alias" | "notification" | "send_only" | "receive_only" | "temporary"9export const ALIAS_KINDS: readonly AddressKind[] = ["alias", "notification", "send_only", "receive_only", "temporary"]10export const isAliasKind = (k: string): boolean => (ALIAS_KINDS as readonly string[]).includes(k)1112/** Objet « adresse » (docs/API.md §5.1). */13export interface ApiAddress {14 id: string15 address: string16 kind: AddressKind17 mailbox: string18 mailbox_id: string19 display_name: string20 signature_text: string21 signature_html: string22 avatar: string | null23 can_send: boolean24 can_receive: boolean25 status: "active" | "suspended"26 suspended_reason: string | null27 expired: boolean28 expires_at: string | null29 retention_days: number | null30 retention_trash_days: number | null31 retention_junk_days: number | null32 quota_bytes: number | null33 reply_policy: "reject" | "accept" | "discard"34 protected: boolean35 extra_destinations: string[]36 inbound: "accept" | "reject" | "discard"37 created_at: string38 updated_at: string39}4041export interface V1Addr {42 email: string43 name?: string | null44}45/** Résumé de message (docs/API.md §8.1). */46export interface V1Message {47 id: string48 thread_id: string49 mailbox: string50 delivered_to: string[]51 folders: { id: string; role: string | null; name: string }[]52 from: V1Addr[]53 to: V1Addr[]54 cc: V1Addr[]55 subject: string56 preview: string57 received_at: string58 sent_at: string | null59 size: number60 unread: boolean61 starred: boolean62 draft: boolean63 answered: boolean64 forwarded: boolean65 has_attachment: boolean66 labels: string[]67 /** mots-clés « $ » utiles aux listes (ajoutés par l'API ; absents d'un serveur plus ancien) */68 pinned?: boolean69 snoozed?: boolean70 followup?: boolean71}72export interface V1Page<T> {73 data: T[]74 next_cursor: string | null75 has_more: boolean76}7778export type OutboundStatus = "queued" | "scheduled" | "pending_approval" | "sent" | "delivered" | "deferred" | "bounced" | "failed" | "cancelled" | "draft"79/** Envoi suivi par l'API (docs/API.md §6.1, §7). */80export interface Outbound {81 id: string82 status: OutboundStatus83 from: string84 message_id: string | null85 thread_id?: string | null86 recipients: { address: string; status: string; smtp_reply: string | null }[]87 external: boolean88 send_at: string | null89 attempts: number90 last_error: string | null91 submitted_at: string | null92 final_at: string | null93 created_at: string94 updated_at: string95 approval_id?: string96 subject?: string97}98/** États après lesquels plus rien ne changera. */99export const FINAL_OUTBOUND: readonly OutboundStatus[] = ["delivered", "bounced", "failed", "cancelled", "draft"]100