Skip to main content

Crate jmap_base_client

Crate jmap_base_client 

Source
Expand description

RFC 8620 base JMAP client: auth, session fetch, blob, SSE, and WebSocket.

Extension-specific clients (jmap-chat-client, jmap-mail-client) depend on this crate.

§Usage

let auth = BearerAuth::new("...")?;
let client = JmapClient::new(
    DefaultTransport,
    auth,
    "https://jmap.example.com",
    ClientConfig::default(),
)?;
let session = client.fetch_session().await?;

§extra field equality and the serde_json/preserve_order feature (bd:JMAP-6r7c.43)

Every public deserializable struct in this crate carries an extra: serde_json::Map<String, serde_json::Value> field per the workspace extras-preservation policy (see workspace AGENTS.md). Several of these structs also derive PartialEq / Eq so callers can write assert_eq!(a, b) in tests and if state_a == state_b { ... } in application code.

The derived PartialEq impl compares the extra field via serde_json::Map’s PartialEq impl, whose semantics depend on a third-party feature flag:

  • Default (this workspace’s posture). serde_json::Map is BTreeMap-backed; equality is order-insensitive (keys are stored in lexicographic order regardless of insertion order).
  • serde_json/preserve_order enabled anywhere in the dep graph. serde_json::Map switches to IndexMap (insertion-order preserved); equality becomes order-sensitive.

Two values constructed with the same extra entries inserted in different orders therefore compare EQUAL under the default configuration and UNEQUAL under preserve_order. The feature flag is a global toggle: any crate in the consumer’s dep graph that enables preserve_order flips the semantics for every crate in the graph.

In-scope structs: BlobUploadResponse, Session, AccountInfo, WebSocketCapability, and StateChange.

Workspace memory note: jmap-base-client (and the full workspace) does NOT enable preserve_order. Consumers in the same posture get deterministic == behaviour on extra. Consumers that enable preserve_order elsewhere and need stable equality independent of that flag should compare the serialised forms instead:

let a_json = serde_json::to_value(&a)?;
let b_json = serde_json::to_value(&b)?;
assert_eq!(a_json, b_json);

Re-exports§

pub use auth::AuthHeader;
pub use auth::AuthProvider;
pub use auth::BasicAuth;
pub use auth::BearerAuth;
pub use auth::BuilderTransport;
pub use auth::CustomCaTransport;
pub use auth::CustomTransportBuilder;
pub use auth::DefaultTransport;
pub use auth::HttpClient;
pub use auth::NoneAuth;
pub use auth::TransportConfig;
pub use blob::expand_url_template;
pub use blob::BlobUploadResponse;
pub use blob::DownloadBlobParams;
pub use blob::DownloadBlobSessionParams;
pub use blob::UploadBlobParams;
pub use blob::UploadBlobSessionParams;
pub use client::extract_response;
pub use client::ClientConfig;
pub use client::JmapClient;
pub use client::SubscribeEventsSessionParams;
pub use error::ClientError;
pub use error::HttpError;
pub use error::InvalidHeaderValueError;
pub use error::ParseCategory;
pub use error::ParseError;
pub use error::SerializeError;
pub use error::WebSocketError;
pub use push::StateChange;
pub use request::AccountInfo;
pub use request::AccountName;
pub use request::JmapRequestBuilder;
pub use request::JmapUrl;
pub use request::JmapUrlTemplate;
pub use request::Session;
pub use request::Username;
pub use request::WebSocketCapability;
pub use sse::parse_sse_block;
pub use sse::SseEvent;
pub use sse::SseFrame;
pub use ws::connect_ws;
pub use ws::WsFrame;
pub use ws::WsReceiver;
pub use ws::WsSender;
pub use ws::WsSession;

Modules§

auth
Auth traits and credential implementations for JMAP clients.
blob
Blob upload/download operations and supporting types (RFC 8620 §6.1, §6.2)
client
Auth-agnostic base JMAP HTTP client (RFC 8620).
error
ClientError and the opaque wrapper types (HttpError, WebSocketError, InvalidHeaderValueError, ParseError, SerializeError) that hide reqwest, tokio_tungstenite, and the underlying JSON parser from this crate’s public API.
push
Canonical push notification types shared by SSE and WebSocket transports. Spec: RFC 8620 §7.1 (Push Subscriptions)
request
Base JMAP request and session types: JmapRequestBuilder, Session, AccountInfo, WebSocketCapability.
sse
SSE types and frame parser for JMAP push notifications. Spec: RFC 8620 §7.3 (Push via Server-Sent Events) Wire format: RFC 8895 (Server-Sent Events)
ws
WebSocket transport for JMAP (RFC 8887).