@snapcap/native
@snapcap/native v0.0.1
@snapcap/native — browser-free Snapchat client for Node.
Loads Snap's web JavaScript bundle and 814 KB of WASM directly inside an
isolated Node vm.Context, with shimmed Chrome APIs so the bundle "thinks"
it's still running in Chromium. No Playwright, no emulator, no rooted phone
— many accounts run on a fraction of the resources a browser harness would
require.
Remarks
The package is the public surface for the Snap automation runner — a thin facade over Snap's own bundle plus an opt-in observability + throttling layer. Authentication, friends, messaging, stories, presence, and inbox are surfaced via the SnapcapClient entry point; persistence plugs in via the DataStore interface.
Examples
Quick start:
import { SnapcapClient, FileDataStore } from "@snapcap/native";
const dataStore = new FileDataStore(".tmp/auth/auth.json");
const client = new SnapcapClient({
dataStore,
credentials: { username: "...", password: "..." },
browser: {
userAgent:
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36",
},
});
await client.authenticate(); // warm-or-cold login, idempotent
const friends = await client.friends.list();Multi-tenant runners should share one throttle gate across clients — see createSharedThrottle and RECOMMENDED_THROTTLE_RULES:
import {
SnapcapClient,
createSharedThrottle,
RECOMMENDED_THROTTLE_RULES,
} from "@snapcap/native";
const gate = createSharedThrottle({ rules: RECOMMENDED_THROTTLE_RULES });
const clients = tenants.map(t => new SnapcapClient({ ...t, throttle: gate }));Opt into structured network observability with setLogger (or set
SNAP_NETLOG=1 in the environment for the built-in text formatter):
import { setLogger, defaultTextLogger } from "@snapcap/native";
setLogger(defaultTextLogger);See
- SnapcapClient — the main entry point
- Friends — friends domain manager
- DataStore — persistence interface
- ThrottleConfig — opt-in HTTP throttling
- Logger — structured network observability
Classes
| Class | Description |
|---|---|
| CookieJarStore | DataStore-backed wrapper around a tough-cookie CookieJar. |
| FileDataStore | File-backed DataStore implementation. |
| Friends | Concrete IFriendsManager implementation. |
| Media | Placeholder for the upcoming Media domain manager. |
| MemoryDataStore | In-memory DataStore implementation — useful for tests and ephemeral sandboxes. |
| Messaging | Messaging manager — inbox enumeration + live decrypt + presence. |
| Presence | Placeholder for the upcoming Presence domain manager. |
| SnapcapClient | Concrete ISnapcapClient implementation — main SDK entry point. |
| StorageShim | Web Storage API (localStorage / sessionStorage) implementation backed by a DataStore. |
| Stories | Stories domain manager — held as SnapcapClient.stories. |
| TypedEventBus | Typed event bus — the shared subscription primitive every domain manager (Friends, Messaging, Stories, Presence) composes. |
Interfaces
| Interface | Description |
|---|---|
| BitmojiPublicInfo | Bitmoji avatar identifiers. Used to render a user's bitmoji via Snap's images.bitmoji.com CDN — the avatar id pairs with a sticker / pose id to construct the URL. |
| ConversationSummary | Per-conversation summary returned by Messaging.listConversations. |
| DataStore | Persistent key-value storage interface — the SDK's pluggable persistence backbone. |
| Friend | A friend in the logged-in user's social graph. |
| FriendsEvents | Map of event name → callback signature for IFriendsManager.on. The callback's argument type narrows automatically per event key via TypeScript's keyof inference. |
| FriendsSnapshot | A point-in-time view of the entire friend graph — mutuals + pending requests in both directions. |
| FriendsUser | A user surfaced from search / lookup / friends list. Mirrors the shape of Snap's GetSnapchatterPublicInfo response — every public field Snap returns is typed here, with the same camel-cased names. |
| IFriendsManager | Friends domain manager — all friend-graph operations live here. |
| ISnapcapClient | The public contract that SnapcapClient implements. |
| RawEncryptedMessage | One message envelope as captured from BatchDeltaSync. |
| ReceivedRequest | An inbound friend request — someone has added the logged-in user and is waiting for IFriendsManager.acceptRequest or IFriendsManager.rejectRequest. |
| SentRequest | An outbound friend request — the logged-in user has added this account and is waiting for them to accept. |
Type Aliases
| Type Alias | Description |
|---|---|
| BrowserContext | Browser-context fingerprint settings — what "browser" the SDK pretends to be when talking to Snap. |
| Credentials | Login credentials passed to SnapcapClient's constructor. |
| FriendLinkType | Friend-link state. |
| FriendSource | String-keyed enum form of FriendSource — the type of any value read off the const object. |
| LogEvent | All emitted log events. Closed discriminated union — switch on event.kind to narrow. |
| Logger | Handler signature passed to setLogger. |
| MessagingEvents | Event map for Messaging.on. |
| PlaintextMessage | Plaintext message handed to the consumer's onPlaintext callback. |
| PresenceStatus | Presence status — what the client reports for the active session's global "I'm here" / "I'm away" slot. |
| SnapcapClientOpts | Public constructor options for SnapcapClient. |
| Subscription | A live subscription — callable thunk that tears down when invoked, with .signal exposing the subscription's combined lifetime (fires on sub() OR on an externally-passed opts.signal abort). |
| ThrottleConfig | Throttle configuration accepted by SnapcapClient's throttle option. |
| ThrottleGate | Function shape that throttles outbound requests. Awaited once per wire request, immediately before the SDK calls into the underlying fetch / XHR layer. |
| ThrottleRule | One throttle rule. Matches outbound URLs and gates them at a minimum inter-call interval, with optional burst headroom. |
| Unsubscribe | Thunk returned by subscription methods (e.g. IFriendsManager.onChange). Calling it cancels the subscription. Idempotent — calling more than once is a no-op. |
| UserId | 16-byte UUID rendered as a hyphenated string. |
Variables
| Variable | Description |
|---|---|
| defaultTextLogger | Built-in human-readable formatter. One line per event, no embedded newlines. Tag column is fixed-width (15 chars) so the output aligns regardless of which event variant is being logged. |
| FriendSource | Attribution source for IFriendsManager.sendRequest. |
| RECOMMENDED_THROTTLE_RULES | Recommended starter rules tuned for human-cadence anti-spam friendliness against Snap's web endpoints. |
Functions
| Function | Description |
|---|---|
| activeIdentifier | - |
| bytesToUuid | Inverse of uuidToBytes: 16-byte buffer → hyphenated UUID string. |
| createSharedThrottle | Build a SHARED ThrottleGate for use across multiple SnapcapClient instances in the same process. |
| highLowToUuid | Inverse of uuidToHighLow: assemble a UUID string from the {high, low} pair. |
| idbDelete | Delete the entry at (dbName, storeName, key) in the given Sandbox's IndexedDB. No-op if absent. |
| idbGet | Read a value from the given Sandbox's IndexedDB at (dbName, storeName, key). |
| idbPut | Write value into the given Sandbox's IndexedDB at (dbName, storeName, key). |
| setLogger | Install (or clear) the active logger. |
| uuidToBytes | Convert a hyphenated UUID string into its 16-byte representation. |
| uuidToHighLow | Split a UUID into the {high, low} fixed64 pair Snap uses in some RPCs (e.g. FriendAction.AddFriends) instead of the bytes16 wrapper. |