Skip to main content

Crate capsule_sdk

Crate capsule_sdk 

Source
Expand description

Capsule client SDK: the sanctioned network path for every Capsule client (upload protocol, sync/download, auth flows).

§REST client generation (spargen)

The typed REST client (rest) is generated from the server’s OpenAPI 3.2 schema by spargen, our in-house generator, at build time (see build.rs). The previous progenitor pipeline is gone deliberately: progenitor consumes OpenAPI 3.0 only, which forced a lossy down-conversion of the document the server actually emits — a standing source of drift and failures. We do not downgrade schemas. client::AuthenticatedClient wraps the generated Client, composing it with auth’s session/token store so callers issue typed calls and never juggle raw tokens.

The generated client covers the plain request/response surfaces (auth, quota, storage-verify, receipts, devices, escrow, the sync feed, …). What stays hand-written is orchestration, never a second parser:

  • upload — the resumable upload state machine, whose protocol is too stateful for request/response codegen;
  • sync — the cursor and anti-rewind state machine over the generated GET /v1/sync operation (there is no gRPC feed; the wire here is generated like every other);
  • directory, upgrade, and verify’s receipt fetch — the four application/cbor operations spargen 0.5 cannot lower, narrowed out in build.rs.

Modules§

albums
Album provisioning — telling the server an album exists.
auth
SDK-owned authentication: the session/token store and the auto-refresh engine.
cache_budget
The client cache budget driven by the connection class (SSoT: design/filesystem/client § Automatic cache management, and design/networking § Connection Classes).
client
The session-composed typed REST client.
cohort
Client-side device-cohort emission and the devices-grouping view model (SSoT: Authentication — Device Cohorts).
directory
Publishing and fetching the signed device directory (over the server’s directory surface).
events
The typed transfer event stream: what an upload, a push or a fetch is doing, as it does it, for a caller that renders progress (the TUI’s transfer view, a mobile progress bar).
federation
FederationPull — a peer server pulling one shared album from its home server.
fetch
Tiered, on-demand blob fetch (SSoT: Download & Sync).
ffi
uniffi surface over the SDK’s user-flow primitives (login → upload → status → sync) for Swift/Kotlin/Linux consumers (ffi feature). A thin, async-capable wrapper over auth, upload, and sync; tokens never cross the boundary (the session-handle pattern). See ffi. uniffi bindings: an async-capable wrapper over the SDK’s user-flow primitives, so iOS/macOS (Swift), Android (Kotlin), and Linux consumers call one SDK instead of reimplementing login/upload/sync flows.
net
Connection-class and retry-policy contract types (SSoT: the Network Resilience design doc). Detection (OS signals + behavioral promotion to ConnectionClass::Adverse) and the per-class retry engines live here: class detection feeds the sync and cache budgets, and the adverse class hardens the network behaviour.
peering
LAN peering: direct device-to-device sync within a single user’s own devices (SSoT: Peering).
push
Pushing a locally-imported asset to a server — the glue between capsule_core’s UploadBundle and the hand-written upload client.
recovery
Recovery-secret verification cadence and the guided re-wrap flow ( SSoT: Backup — Recovery Verification Cadence and § On Repeated Failure: Guided Re-Wrap).
rest
The typed REST client generated by spargen from the server’s committed OpenAPI 3.2 schema (openapi.json), emitted into OUT_DIR by build.rs and included verbatim here. One async method per operation, typed models, typed errors, and an embedded freestanding reqwest runtime — spargen never enters the runtime dependency tree. Do not edit: regenerate the schema with mise run openapi-kynos (and mise run openapi-check-kynos gates it); the client re-generates on every build. The ergonomic, session-composed entry point is client::AuthenticatedClient; reach for rest::Client directly only for unauthenticated calls.
share
The owner’s two share-link operations over the generated client (#622): register a link the issuing client published (POST /v1/shares), and revoke one (DELETE /v1/shares/{opaque_id}).
staged
The client-side staged upload scheduler (SSoT: Download & Sync — Upload Tiering (Staged Uploads)).
sync
The key-free sync consumer (SSoT: Download & Sync).
upgrade
The album-upgrade proposal client. Hand-written for one reason only: its request body is application/cbor, which spargen 0.5 cannot lower, so build.rs narrows the operation out of the generated client. The GET and DELETE on the same path are JSON and are generated — reach them through client::AuthenticatedClient. Proposing an album upgrade — the client half of the ceremony’s one server-side step (over the server’s album-upgrade wire).
upload
Upload client module for Capsule SDK.
verify
Verify-before-destroy: the client half of storage verification (SSoT: Storage Verification — Verify Before Destroy).