External consumer sync protocols
Research for Dataset + View + External consumer + Grant (see root CONTEXT.md).
Question: which standard protocols should the vision use so phones and other External consumers talk to Datasets through Views?
Primary sources: IETF RFCs for WebDAV, CardDAV, CalDAV, and JMAP. Shortlist for the vision section of the future spec — not an implementation plan.
Shortlist for the vision
| Priority | Protocol | Role for us | RFC |
|---|---|---|---|
| P0 (phone sync) | CardDAV | Contacts / address books | RFC 6352 |
| P0 (phone sync) | CalDAV | Calendars / events | RFC 4791 |
| P0 (foundation) | WebDAV | Shared collection/ACL/locking model under Card/Cal; optional file Datasets | RFC 4918 |
| P1 (modern clients) | JMAP (+ Mail/Contacts/Calendars apps as they mature) | JSON session API; better filter/partial-get story than DAV REPORT XML | RFC 8620 core; mail RFC 8621 |
| P2 | Proprietary mobile sync (ActiveSync, vendor APIs) | Only if a specific client is required; prefer standards | — |
Vision line: Host adapters expose one CardDAV address book collection and/or one CalDAV calendar collection per Grant to a View (not per raw Dataset), so External consumers never see more rows/fields than the View allows.
Protocol sketches (from the RFCs)
WebDAV (RFC 4918)
HTTP extensions for collections, properties (PROPFIND/PROPPATCH), locking, and hierarchical URL namespaces. CardDAV and CalDAV are profiles of this model: a “book” or “calendar” is a WebDAV collection; each contact/event is a child resource.
Dataset mapping: a file-like Dataset can map onto a WebDAV collection of resources; ACL (RFC 3744, required by Card/Cal) roughly maps to Grants — but WebDAV ACL is principal/privilege oriented, not field-level Views.
CardDAV (RFC 6352)
- Address book collection = WebDAV collection with
DAV:collection+CARDDAV:addressbookinresourcetype(§5.2). - Address object resource = one child resource containing a single vCard; UID unique within the book (§5.1).
- Multiple address book collections may be siblings (§5.2) — matches “private vs work” Datasets / Views.
- Reports:
addressbook-query,addressbook-multiget; clients should restrict returned properties (§9.1). - Partial retrieval examples exist (e.g. return only some vCard props in REPORT) — server-enforced field limits are possible if the adapter strips properties on every response path (GET, PUT echo, REPORT).
CalDAV (RFC 4791)
- Calendar collection = WebDAV collection with
CALDAV:calendar(§4.2). - Calendar object resource = iCalendar data; typically one component type per resource (VEVENT/VTODO/…); UID uniqueness rules (§4.1).
- Recurring events + exceptions live in one resource (§3.2).
- Reports:
calendar-query,calendar-multiget, free-busy; partial retrieval of components/properties is specified (§7.6).
JMAP (RFC 8620 / 8621)
Session-based JSON API over HTTP; mail is standardized in 8621; contacts/calendars exist as related JMAP specs/ecosystem (check current IETF status when implementing). Stronger fit for filter + properties arguments on method calls than relying on every DAV client to ask politely.
Mapping onto Dataset + View + Grant
| Domain concept | CardDAV | CalDAV | WebDAV files |
|---|---|---|---|
| Dataset | Canonical contact store (typed records) | Canonical event store | Canonical file tree / blob set |
| View | Exposed as one address book collection URL whose members are the row-filtered set, each vCard property-filtered | One calendar collection URL with filtered events / stripped props | Collection or folder URL with filtered children / metadata |
| Grant | Credentials (or capability token) that only mount that collection URL | Same | Same |
| Multiple books | Multiple collections (RFC allows) | Multiple calendars | Multiple collections |
Important: Do not expose the raw Dataset collection to External consumers and hope the client omits fields. Phone OS sync stacks typically pull full vCards/iCalendar objects. The Host adapter must materialize a View-shaped collection.
Enforcing field- and row-level Views (the hard part)
Naive full-book sync ignores Views. A Host-side CardDAV/CalDAV adapter must enforce Grants on every code path:
Row filters (which contacts/events exist)
- Collection listing (
PROPFINDdepth 1),multiget,queryREPORT, and directGETby URL must only reveal object URLs that pass the View’s row predicate. - Do not put excluded objects at guessable URLs under the same collection; prefer View-specific collection roots (e.g.
/dav/grants/<grant-id>/addressbook/). - Writes (
PUT/DELETE): reject or no-op for rows outside the View; define whether External consumers may create rows (Grant capability: read vs read-write).
Field filters (which vCard/iCal properties appear)
- On read: strip disallowed properties (e.g.
NOTE,URL, custom X- props) before responding — including REPORT partial-retrieve and plain GET. - On write: strip or reject disallowed properties on PUT so a client cannot smuggle notes into the Dataset through a limited View.
- ETag / sync token honesty: ETags must reflect the View projection, not the full Dataset record — otherwise clients cache full data from a previous wider Grant or confuse sync.
- UID stability: keep stable UIDs for the same underlying record across View revisions when possible, so phones update rather than duplicate; document when a View change forces UID remap.
What DAV gives you vs what you must add
| Built into Card/CalDAV | Host must add |
|---|---|
| Multiple collections ≈ multiple Views | Map Grant → collection |
| Optional client-requested property subsets | Mandatory server-side property allowlist per View |
| WebDAV ACL principals | Bind ACL identities to Instance accounts / tokens without exposing other Grants |
| Query filters (text match, time range) | Compose with View predicates (AND, never widen) |
JMAP advantage
Method calls that accept explicit property lists and filters make “View = server-side default filter + forced properties” easier to reason about than educating every DAV client. Still require server-side enforcement.
Phone sync practical notes
- iOS/Android account setup expects CardDAV/CalDAV endpoints far more than JMAP today → P0 adapters.
- Discovery: well-known URLs / principals (CardDAV/CalDAV ecosystem practice) should list only collections the account’s Grants allow.
- Separate Grant tokens per External consumer (phone vs laptop) so revocation is fine-grained.
- Files: WebDAV or later protocol; weighing-log / custom Datasets may have no standard sync — App-native export or a future generic API, out of P0.
Implications for later tickets / fog
- Vision/spec should state: External consumer ↔ View via protocol adapter, not App-private HTTP.
- Fog “protocol adapters…” can graduate to a grilling ticket once product priority (Card+Cal only vs +files vs +JMAP) is chosen — or fold into Draft the concept and requirements specification.
- Dataset declaration grilling should include export codecs (record ↔ vCard/iCalendar property maps) so Views can name field allowlists in Host terms.