Expand description
The session-composed typed REST client.
AuthenticatedClient revives the shape the parked wrapper in the crate root promised —
a thin skin over the spargen-generated rest::Client that owns
the base URL, swaps base URL/credentials without callers rebuilding anything, and
Derefs to the typed client so every generated operation is called directly. What the
parked sketch could not express, this composition does: instead of a static bearer string,
the client is wired to the SDK’s Session through spargen’s async
token-provider seam, so every typed call transparently gets a valid access token, with
the session’s proactive pre-flight refresh and single-flight coalescing — callers never
touch a raw token. The refresh/expiry/single-flight logic is reused wholesale from
crate::auth; nothing is duplicated here.
§Both halves of the refresh contract
The token provider is the proactive half: it refreshes when the stored token is within
its skew of expiry, before the request leaves. That cannot cover a token the server stops
honouring early — a revocation mid-flight, or a clock the two ends disagree about — so
RefreshOn401 is the reactive half: an rest::HttpBackend wrapping
rest::ReqwestBackend that, on a 401 whose problem code says the access token was
refused (error.request.unauthenticated), refreshes once through the session and replays
the request exactly once. A 401 carrying any other code is a refused credential — a
wrong password or second-factor code — and is surfaced untouched. The two are
complementary and neither duplicates the other; the refresh itself is still auth’s
single-flight gate.
It sits at the transport seam rather than in each caller, so every generated operation is covered by one layer that survives regeneration — no generated code is touched, and there is no per-call retry loop to keep in step.
Scope: this covers the plain request/response REST surfaces the OpenAPI schema declares
(auth/session, quota, storage-verify, receipts, devices, escrow, …). The stateful upload
protocol (crate::upload) stays hand-written. The sync feed (crate::sync) is a
generated operation (GET /v1/sync), but crate::sync::SyncConsumer drives it under its
own cursor/anti-rewind state machine and builds its own client, because it also serves a
static-token mode that has no session to refresh.
Structs§
- Authenticated
Client - A typed REST client that authenticates itself from an SDK
Session.
Enums§
- Client
Error - Failure constructing an
AuthenticatedClient— today only a malformed base URL. Wire failures surface later, per operation, through the generated client’s own typed error.
Functions§
- upgrade_
required_ of - The one typed
UpgradeRequireda generated-client failure carries, if it is one: a426— the server’s, or the typed transport’s local refusal of a write the latched window refuses — documented or not.Nonefor every other failure.