snapcap
API Reference

@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

Classes

ClassDescription
CookieJarStoreDataStore-backed wrapper around a tough-cookie CookieJar.
FileDataStoreFile-backed DataStore implementation.
FriendsConcrete IFriendsManager implementation.
MediaPlaceholder for the upcoming Media domain manager.
MemoryDataStoreIn-memory DataStore implementation — useful for tests and ephemeral sandboxes.
MessagingMessaging manager — inbox enumeration + live decrypt + presence.
PresencePlaceholder for the upcoming Presence domain manager.
SnapcapClientConcrete ISnapcapClient implementation — main SDK entry point.
StorageShimWeb Storage API (localStorage / sessionStorage) implementation backed by a DataStore.
StoriesStories domain manager — held as SnapcapClient.stories.
TypedEventBusTyped event bus — the shared subscription primitive every domain manager (Friends, Messaging, Stories, Presence) composes.

Interfaces

InterfaceDescription
BitmojiPublicInfoBitmoji 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.
ConversationSummaryPer-conversation summary returned by Messaging.listConversations.
DataStorePersistent key-value storage interface — the SDK's pluggable persistence backbone.
FriendA friend in the logged-in user's social graph.
FriendsEventsMap of event name → callback signature for IFriendsManager.on. The callback's argument type narrows automatically per event key via TypeScript's keyof inference.
FriendsSnapshotA point-in-time view of the entire friend graph — mutuals + pending requests in both directions.
FriendsUserA 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.
IFriendsManagerFriends domain manager — all friend-graph operations live here.
ISnapcapClientThe public contract that SnapcapClient implements.
RawEncryptedMessageOne message envelope as captured from BatchDeltaSync.
ReceivedRequestAn inbound friend request — someone has added the logged-in user and is waiting for IFriendsManager.acceptRequest or IFriendsManager.rejectRequest.
SentRequestAn outbound friend request — the logged-in user has added this account and is waiting for them to accept.

Type Aliases

Type AliasDescription
BrowserContextBrowser-context fingerprint settings — what "browser" the SDK pretends to be when talking to Snap.
CredentialsLogin credentials passed to SnapcapClient's constructor.
FriendLinkTypeFriend-link state.
FriendSourceString-keyed enum form of FriendSource — the type of any value read off the const object.
LogEventAll emitted log events. Closed discriminated union — switch on event.kind to narrow.
LoggerHandler signature passed to setLogger.
MessagingEventsEvent map for Messaging.on.
PlaintextMessagePlaintext message handed to the consumer's onPlaintext callback.
PresenceStatusPresence status — what the client reports for the active session's global "I'm here" / "I'm away" slot.
SnapcapClientOptsPublic constructor options for SnapcapClient.
SubscriptionA 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).
ThrottleConfigThrottle configuration accepted by SnapcapClient's throttle option.
ThrottleGateFunction shape that throttles outbound requests. Awaited once per wire request, immediately before the SDK calls into the underlying fetch / XHR layer.
ThrottleRuleOne throttle rule. Matches outbound URLs and gates them at a minimum inter-call interval, with optional burst headroom.
UnsubscribeThunk returned by subscription methods (e.g. IFriendsManager.onChange). Calling it cancels the subscription. Idempotent — calling more than once is a no-op.
UserId16-byte UUID rendered as a hyphenated string.

Variables

VariableDescription
defaultTextLoggerBuilt-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.
FriendSourceAttribution source for IFriendsManager.sendRequest.
RECOMMENDED_THROTTLE_RULESRecommended starter rules tuned for human-cadence anti-spam friendliness against Snap's web endpoints.

Functions

FunctionDescription
activeIdentifier-
bytesToUuidInverse of uuidToBytes: 16-byte buffer → hyphenated UUID string.
createSharedThrottleBuild a SHARED ThrottleGate for use across multiple SnapcapClient instances in the same process.
highLowToUuidInverse of uuidToHighLow: assemble a UUID string from the {high, low} pair.
idbDeleteDelete the entry at (dbName, storeName, key) in the given Sandbox's IndexedDB. No-op if absent.
idbGetRead a value from the given Sandbox's IndexedDB at (dbName, storeName, key).
idbPutWrite value into the given Sandbox's IndexedDB at (dbName, storeName, key).
setLoggerInstall (or clear) the active logger.
uuidToBytesConvert a hyphenated UUID string into its 16-byte representation.
uuidToHighLowSplit a UUID into the {high, low} fixed64 pair Snap uses in some RPCs (e.g. FriendAction.AddFriends) instead of the bytes16 wrapper.

On this page