This repository has no description
1(*---------------------------------------------------------------------------
2 Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
3 SPDX-License-Identifier: ISC
4 ---------------------------------------------------------------------------*)
5
6(** JMAP session object as defined in RFC 8620 Section 2
7
8 @canonical Jmap.Proto.Session *)
9
10(** {1 Account} *)
11
12(** An account available to the user. *)
13module Account : sig
14 type t = {
15 name : string;
16 (** Human-readable name for the account. *)
17 is_personal : bool;
18 (** Whether this is a personal account. *)
19 is_read_only : bool;
20 (** Whether the account is read-only. *)
21 account_capabilities : (string * Jsont.json) list;
22 (** Capabilities available for this account. *)
23 }
24
25 val name : t -> string
26 val is_personal : t -> bool
27 val is_read_only : t -> bool
28 val account_capabilities : t -> (string * Jsont.json) list
29
30 val jsont : t Jsont.t
31end
32
33(** {1 Session} *)
34
35(** The JMAP session resource. *)
36type t = {
37 capabilities : (string * Jsont.json) list;
38 (** Server capabilities. Keys are capability URIs. *)
39 accounts : (Proto_id.t * Account.t) list;
40 (** Available accounts keyed by account id. *)
41 primary_accounts : (string * Proto_id.t) list;
42 (** Map of capability URI to the primary account id for that capability. *)
43 username : string;
44 (** The username associated with the credentials. *)
45 api_url : string;
46 (** URL to POST JMAP requests to. *)
47 download_url : string;
48 (** URL template for downloading blobs. *)
49 upload_url : string;
50 (** URL template for uploading blobs. *)
51 event_source_url : string;
52 (** URL for push event source. *)
53 state : string;
54 (** Opaque session state string. *)
55}
56
57val capabilities : t -> (string * Jsont.json) list
58val accounts : t -> (Proto_id.t * Account.t) list
59val primary_accounts : t -> (string * Proto_id.t) list
60val username : t -> string
61val api_url : t -> string
62val download_url : t -> string
63val upload_url : t -> string
64val event_source_url : t -> string
65val state : t -> string
66
67val jsont : t Jsont.t
68(** JSON codec for session objects. *)
69
70(** {1 Session Helpers} *)
71
72val get_account : Proto_id.t -> t -> Account.t option
73(** [get_account id session] returns the account with the given id. *)
74
75val primary_account_for : string -> t -> Proto_id.t option
76(** [primary_account_for capability session] returns the primary account
77 for the given capability URI. *)
78
79val has_capability : string -> t -> bool
80(** [has_capability uri session] returns [true] if the server supports the capability. *)
81
82val get_core_capability : t -> Proto_capability.Core.t option
83(** [get_core_capability session] returns the parsed core capability. *)
84
85val get_mail_capability : t -> Proto_capability.Mail.t option
86(** [get_mail_capability session] returns the parsed mail capability. *)