snapcap
API ReferenceClasses

SnapcapClient

Class: SnapcapClient

Defined in: client.ts:143

Concrete ISnapcapClient implementation — main SDK entry point.

Each instance owns its own isolated vm.Context sandbox, Zustand state, bearer token, and webpack runtime cache, so multiple clients can coexist in one process without leaking state across tenants.

Method-level documentation (auth verbs, manager fields) lives on ISnapcapClient. The constructor and constructor options are documented here.

See

Implements

Constructors

Constructor

new SnapcapClient(opts: SnapcapClientOpts): SnapcapClient;

Defined in: client.ts:178

Construct a new client.

Parameters

ParameterTypeDescription
optsSnapcapClientOptsClient options. See SnapcapClientOpts.

Returns

SnapcapClient

Throws

If opts.browser.userAgent is missing — every consumer defaulting to the same UA would itself become a snapcap fingerprint signature.

Properties

PropertyModifierTypeDescriptionDefined in
friendsreadonlyFriendsFriend-graph manager — see IFriendsManager for the full surface (mutations, reads, search, subscriptions).client.ts:149
mediareadonlyMediaPlaceholder for the upcoming Media manager. No methods today.client.ts:157
messagingreadonlyMessagingMessaging manager — inbox enumeration, raw envelope reads, live decrypted message stream, and outbound presence (typing/viewing). See Messaging for the surface.client.ts:151
presencereadonlyPresencePlaceholder for the upcoming Presence manager. No methods today.client.ts:153
storiesreadonlyStoriesPlaceholder for the upcoming Stories manager. No methods today.client.ts:155

Methods

authenticate()

authenticate(): Promise<void>;

Defined in: client.ts:236

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.

Implementation of

ISnapcapClient.authenticate


getAuthState()

getAuthState(): number;

Defined in: client.ts:303

Live read: state.auth.authState enum value.

Returns

number

0 = LoggedOut, 1 = LoggedIn, 2 = Processing, 3 = MoreChallengesRequired.

Implementation of

ISnapcapClient.getAuthState


getAuthToken()

getAuthToken(): string;

Defined in: client.ts:298

Live read: current SSO bearer string from the Zustand auth slice.

Returns

string

The bearer token (suitable for use as Authorization: Bearer ...).

Implementation of

ISnapcapClient.getAuthToken


getStatus()

getStatus(): PresenceStatus;

Defined in: client.ts:326

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

PresenceStatus

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.

Implementation of

ISnapcapClient.getStatus


hasEverLoggedIn()

hasEverLoggedIn(): boolean;

Defined in: client.ts:308

Live read: the hasEverLoggedIn marker.

Survives logout — useful for distinguishing a fresh install from a signed-out returning user.

Returns

boolean

Implementation of

ISnapcapClient.hasEverLoggedIn


isAuthenticated()

isAuthenticated(): boolean;

Defined in: client.ts:289

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

Implementation of

ISnapcapClient.isAuthenticated


logout()

logout(force?: boolean): Promise<void>;

Defined in: client.ts:266

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

ParameterTypeDescription
force?booleanIf 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.

Implementation of

ISnapcapClient.logout


refreshAuthToken()

refreshAuthToken(): Promise<void>;

Defined in: client.ts:279

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.

Implementation of

ISnapcapClient.refreshAuthToken


setStatus()

setStatus(status: PresenceStatus): void;

Defined in: client.ts:315

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

ParameterTypeDescription
statusPresenceStatusone 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.

Implementation of

ISnapcapClient.setStatus

On this page