ISnapcapClient
Interface: ISnapcapClient
Defined in: client.interface.ts:25
The public contract that SnapcapClient implements.
Surface is intentionally minimal: auth methods plus six per-domain
managers. Consumers should code against ISnapcapClient rather than
the concrete class when writing tests, mocks, or library code that
accepts a client.
See
Properties
| Property | Modifier | Type | Description | Defined in |
|---|---|---|---|---|
friends | readonly | Friends | Friend-graph manager — see IFriendsManager for the full surface (mutations, reads, search, subscriptions). | client.interface.ts:185 |
media | readonly | Media | Placeholder for the upcoming Media manager. No methods today. | client.interface.ts:207 |
messaging | readonly | Messaging | Messaging manager — inbox enumeration, raw envelope reads, live decrypted message stream, and outbound presence (typing/viewing). See Messaging for the surface. | client.interface.ts:192 |
presence | readonly | Presence | Placeholder for the upcoming Presence manager. No methods today. | client.interface.ts:197 |
stories | readonly | Stories | Placeholder for the upcoming Stories manager. No methods today. | client.interface.ts:202 |
Methods
authenticate()
authenticate(): Promise<void>;Defined in: client.interface.ts:48
Bring up the bundles, run warm-or-cold WebLogin, and populate the Zustand auth slice.
The first call does the heavy lifting (loads the accounts and chat
bundles, runs kameleon attestation, drives WebLoginService if no
cookies are cached); subsequent process boots with restored cookies
short-circuit through the warm SSO path (~1 redirect, ~100ms).
Returns
Promise<void>
Resolves when the auth slice reports LoggedIn.
Throws
If credentials are missing on cold-start (no cached cookies), or if the server rejects the login attempt.
Example
const client = new SnapcapClient({ dataStore, browser, credentials });
await client.authenticate();
console.log(client.isAuthenticated()); // truegetAuthState()
getAuthState(): number;Defined in: client.interface.ts:99
Live read: state.auth.authState enum value.
Returns
number
0 = LoggedOut, 1 = LoggedIn, 2 = Processing,
3 = MoreChallengesRequired.
getAuthToken()
getAuthToken(): string;Defined in: client.interface.ts:91
Live read: current SSO bearer string from the Zustand auth slice.
Returns
string
The bearer token (suitable for use as Authorization: Bearer ...).
getStatus()
getStatus(): PresenceStatus;Defined in: client.interface.ts:177
Live read of the global presence status — same Zustand slot driven by ISnapcapClient.setStatus, plus whatever the bundle itself mutates in response to its own lifecycle events (focus / blur / presence-service signals).
Returns
the current PresenceStatus
Remarks
Synchronous; reads state.presence.awayState and maps the underlying
numeric enum value back to the canonical SDK string. If the slot
holds an unrecognized value (future-bundle drift), returns
"AwaitingReactivate" as the safest neutral fallback rather than
throwing.
Requires client.authenticate() to have completed first.
Throws
if called before ISnapcapClient.authenticate, or if the bundle's presence slice / state-enum module shape has shifted.
Example
await client.authenticate();
console.log(client.getStatus()); // "Present"See
hasEverLoggedIn()
hasEverLoggedIn(): boolean;Defined in: client.interface.ts:107
Live read: the hasEverLoggedIn marker.
Survives logout — useful for distinguishing a fresh install from a signed-out returning user.
Returns
boolean
isAuthenticated()
isAuthenticated(): boolean;Defined in: client.interface.ts:84
Live read: true iff the Zustand auth slice currently reports
LoggedIn.
Synchronous — backed by in-process state. Returns false before the
bundle is brought up (i.e. before ISnapcapClient.authenticate
has been called).
Returns
boolean
logout()
logout(force?: boolean): Promise<void>;Defined in: client.interface.ts:61
Tear down the bundle-side auth state.
Calls Snap's own state.auth.logout thunk — clears Zustand, fires
any subscribed teardown hooks, and (best-effort) revokes server-side.
Also deletes the persisted cookie jar entry from the DataStore.
Parameters
| Parameter | Type | Description |
|---|---|---|
force? | boolean | If true, force the logout even if the server-side revoke call fails. Defaults to false. |
Returns
Promise<void>
Resolves when local auth state has been cleared.
refreshAuthToken()
refreshAuthToken(): Promise<void>;Defined in: client.interface.ts:74
Refresh the bearer in-place via Snap's own state.auth.refreshToken.
Requires the client to have been constructed with credentials — the bundle's refresh path mints a fresh kameleon attestation bound to the active identifier.
Returns
Promise<void>
Resolves once the new bearer has been written back into the Zustand auth slice.
Throws
If the client was constructed without credentials.
setStatus()
setStatus(status: PresenceStatus): void;Defined in: client.interface.ts:147
Set the global presence status for this client's session — the same "I'm here" / "I'm away" slot the bundle's presence slice gates outbound typing-pulse broadcasts on.
Parameters
| Parameter | Type | Description |
|---|---|---|
status | PresenceStatus | one of PresenceStatus |
Returns
void
Remarks
Synchronous; writes through state.presence.setAwayState on the
bundle's Zustand store, mapping the canonical SDK string to the
underlying numeric enum (chat module 46471's
{Present: 0, Away: 1, AwaitingReactivate: 2}).
"Present" is the typical default — the chat-bundle loader patches
document.hasFocus = () => true so the slice initializes there at
factory time. Switching to "Away" causes the bundle to suppress
broadcastTypingActivity until the next setStatus("Present") call,
which is the right behaviour when a tenant is logically idle but the
SDK should keep the auth session live.
Requires client.authenticate() to have completed first — the
presence slice doesn't exist on the bundle store until the chat
bundle has loaded.
Throws
if called before ISnapcapClient.authenticate, or if the bundle's presence slice / state-enum module shape has shifted.
Example
await client.authenticate();
client.setStatus("Away"); // suppress typing broadcasts
client.setStatus("Present"); // reopen the gate