jmap-contacts-client
What it is
Typed client methods for JMAP Contacts (RFC 9610). Depends
on jmap-base-client for transport, authentication, and session management.
What it's for
Implements draft-ietf-jmap-contacts (RFC 9610) method bindings on top of
jmap-base-client: AddressBook/get|changes|set and
ContactCard/get|changes|set|copy|query|queryChanges. Sibling of
jmap-mail-client in the extension-client family — mirrors that crate's
shape. Depends on jmap-base-client for transport and session, and on
jmap-contacts-types for the wire types (including the RFC 9553 JSContact
sub-types re-exported under the jscontact module alias).
How to use
use ;
use ;
use ContactCard;
use ;
use json;
async
Id parameters are typed &jmap_types::Id (or &[jmap_types::Id] for slices)
to make invalid Ids unrepresentable. State tokens use &jmap_types::State.
Construct Ids with Id::new_validated(s) to enforce RFC 8620 §1.2 syntax at
the boundary, or with Id::from(s) when the value is known-valid (e.g.
already came back from a server response).
After constructing a SessionClient via with_contacts_session, all JMAP
Contacts methods are available without passing &Session on every call. If the
session expires, re-fetch with JmapClient::fetch_session and construct a new
SessionClient.
Registered methods
All method implementations live on SessionClient in the methods/ submodules.
| Method | Function | Returns |
|---|---|---|
AddressBook/get |
address_book_get |
GetResponse<AddressBook> |
AddressBook/changes |
address_book_changes |
ChangesResponse |
AddressBook/set |
address_book_set |
SetResponse<AddressBook> |
ContactCard/get |
contact_card_get |
GetResponse<ContactCard> |
ContactCard/changes |
contact_card_changes |
ChangesResponse |
ContactCard/set |
contact_card_set |
SetResponse<ContactCard> |
ContactCard/copy |
contact_card_copy |
SetResponse<ContactCard> |
ContactCard/query |
contact_card_query |
QueryResponse |
ContactCard/queryChanges |
contact_card_query_changes |
QueryChangesResponse |
Note: AddressBook/query and AddressBook/queryChanges are not implemented —
RFC 9610 does not define these methods.
AddressBook/set — extra arguments
address_book_set accepts an optional AddressBookSetParams for the
contacts-specific method-level arguments:
Pass None for params (or Some(Default::default())) when neither argument
is needed.
How it works
Every method follows the same five-step pattern:
- Validate arguments (defence-in-depth empty-state guards return
InvalidArgumentbefore any network call; Id-shaped parameters are typed&Id/&[Id]so empty-Id inputs are unrepresentable). - Call
session_parts()to extract(api_url, account_id)from the bound session. - Build the JMAP method arguments as a
serde_json::Value. - Call
build_request(method_name, args, USING_CONTACTS)to construct a single-methodJmapRequest. - POST to the API URL and extract the typed response via
jmap_base_client::extract_response.
The capability using array for all contacts requests is:
["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:contacts"].
Gotchas
- Creating or updating a
ContactCardrequires the caller to buildserde_json::Valuefor all JSContact sub-objects (name,phones,addresses,emails, etc.) manually. No typed builder or fluent API is provided. Use RFC 9553 as the schema when constructing these values. contact_card_queryandcontact_card_query_changesacceptfilterandsortas untypedserde_json::Value. UseContactCardFilterConditionandContactCardComparatorfromjmap-contacts-typesand serialize them withserde_json::to_valuebefore passing.- No integration tests against a real JMAP server. Tests use direct serialization assertions against known JSON shapes from the spec.
Crate family
jmap-types
└── jmap-base-client transport, auth, session
└── jmap-contacts-client ← this crate
(also depends on jmap-contacts-types for response types)