Architecture
High-Level Design
The SDK is organized into clear layers:
TooLostClient: orchestration, token state, manager wiring.OAuthManager: OAuth URL generation, code exchange, token refresh, PKCE utilities.REST: HTTP transport, retries, auth header application, error normalization.Managers: endpoint-level domain APIs.Types: request/response contracts organized by domain.
Runtime Flow
Standard request flow
- Manager method calls
BaseManager.requestorBaseManager.requestData. TooLostClient.requestruns pre-request refresh check.REST.requestbuilds URL, headers, emits events, executes fetch.- Response body is parsed.
- Non-2xx responses become
TooLostAPIError. requestDataunwraps{ data: ... }responses automatically.
Auto refresh behavior
The client can refresh in two ways:
- Pre-request refresh:
- Happens only when
autoRefreshis true. - Requires a known
expiresAtandrefreshToken. - Triggers when token expires in <= 30 seconds.
- Happens only when
- 401 recovery:
- If request fails with
TooLostAPIErrorstatus 401. - Requires
autoRefreshandrefreshToken. - Performs one refresh and retries the request.
- If request fails with
Eventing Model
The client extends a typed event emitter and supports:
requestresponseerrortokenRefresh
Event listener methods:
ononceoffemit
Module Layout
src/client: client runtime and typed event emitter.src/oauth: OAuth manager.src/rest: REST transport.src/managers: domain managers.src/types: SDK type system and API contracts.src/structures: normalized output models.src/utils: shared runtime helpers and errors.
Type Architecture
API types are split by domain under src/types/api/:
common.tsenums.tsshared.tsuser.tsreleases.tstracks.tspreferences.tslookup.tsdeprecated.ts
Public compatibility is preserved through:
src/types/api.ts(barrel)src/types/api/index.ts(domain barrel)