Skip to main content

capsule_sdk/
lib.rs

1//! Capsule client SDK: the sanctioned network path for every Capsule client
2//! (upload protocol, sync/download, auth flows).
3//!
4//! # REST client generation (spargen)
5//!
6//! The typed REST client ([`rest`]) is generated from the server's **OpenAPI 3.2** schema by
7//! `spargen`, our in-house generator, at build time (see `build.rs`). The previous progenitor
8//! pipeline is gone deliberately: progenitor consumes OpenAPI 3.0 only, which forced a lossy
9//! down-conversion of the document the server actually emits — a standing source of drift and
10//! failures. We do not downgrade schemas. [`client::AuthenticatedClient`] wraps the generated
11//! `Client`, composing it with [`auth`]'s session/token store so callers issue typed calls and
12//! never juggle raw tokens.
13//!
14//! The generated client covers the plain request/response surfaces (auth, quota,
15//! storage-verify, receipts, devices, escrow, the sync feed, …). What stays hand-written is
16//! *orchestration*, never a second parser:
17//!
18//! - [`upload`] — the resumable upload state machine, whose protocol is too stateful for
19//!   request/response codegen;
20//! - [`sync`] — the cursor and anti-rewind state machine **over** the generated `GET /v1/sync`
21//!   operation (there is no gRPC feed; the wire here is generated like every other);
22//! - [`directory`], [`upgrade`], and [`verify`]'s receipt fetch — the four `application/cbor`
23//!   operations `spargen` 0.5 cannot lower, narrowed out in `build.rs`.
24
25pub mod albums;
26pub mod auth;
27pub mod cache_budget;
28pub mod client;
29pub mod cohort;
30pub mod directory;
31pub mod events;
32pub mod federation;
33pub mod fetch;
34pub mod net;
35pub mod peering;
36pub mod push;
37pub mod recovery;
38pub mod share;
39pub mod staged;
40pub mod sync;
41/// The album-upgrade proposal client. Hand-written for one reason only: its request
42/// body is `application/cbor`, which `spargen` 0.5 cannot lower, so `build.rs` narrows the
43/// operation out of the generated client. The `GET` and `DELETE` on the same path are JSON and
44/// *are* generated — reach them through [`client::AuthenticatedClient`].
45pub mod upgrade;
46pub mod upload;
47pub mod verify;
48
49/// An in-process mock HTTP server shared by the hand-written wire clients' tests.
50#[cfg(test)]
51mod testmock;
52
53/// The typed REST client generated by `spargen` from the server's committed OpenAPI **3.2**
54/// schema (`openapi.json`), emitted into `OUT_DIR` by `build.rs` and included verbatim here. One
55/// `async` method per operation, typed models, typed errors, and an
56/// embedded freestanding `reqwest` runtime — `spargen` never enters the runtime dependency
57/// tree. Do not edit: regenerate the schema with `mise run openapi-kynos` (and
58/// `mise run openapi-check-kynos` gates it); the client re-generates on every build. The
59/// ergonomic, session-composed entry point is [`client::AuthenticatedClient`]; reach for
60/// [`rest::Client`] directly only for unauthenticated calls.
61///
62/// The two `rustdoc::` allows are the generated text's, not ours to fix here: each operation's
63/// doc comment is the server handler's rustdoc carried through the schema's `description`, so
64/// its intra-doc links name `capsule-server` items (`crate::serve`, `ModerationStore`, …) that
65/// cannot resolve in this crate, and `spargen`'s runtime links its own private helpers. The
66/// workspace rustdoc gate (`mise run doc-check-rust`) still lints every hand-written module.
67pub mod rest {
68    #![allow(
69        clippy::all,
70        clippy::pedantic,
71        clippy::nursery,
72        missing_docs,
73        unreachable_pub,
74        dead_code,
75        rustdoc::broken_intra_doc_links,
76        rustdoc::private_intra_doc_links
77    )]
78    include!(concat!(env!("OUT_DIR"), "/rest_client.rs"));
79}
80
81/// uniffi surface over the SDK's user-flow primitives (login → upload → status →
82/// sync) for Swift/Kotlin/Linux consumers (`ffi` feature). A thin,
83/// async-capable wrapper over [`auth`], [`upload`], and [`sync`]; tokens never
84/// cross the boundary (the session-handle pattern). See [`ffi`].
85#[cfg(feature = "ffi")]
86pub mod ffi;
87
88#[cfg(feature = "ffi")]
89uniffi::setup_scaffolding!();
90
91// `AuthenticatedClient` (revived over the generated `rest::Client`, composed with the SDK
92// session store) now lives in [`client`]; the parked comment block it replaced is gone.