npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@snackbase/sdk

v0.9.0

Published

Core SDK for SnackBase

Readme

@snackbase/sdk

The official JavaScript/TypeScript client for the SnackBase API.

@snackbase/sdk provides a typed SnackBaseClient with authentication, account and collection management, dynamic records, files, realtime subscriptions, automation, and platform administration services.

Install

npm install @snackbase/sdk
# or: pnpm add @snackbase/sdk
# or: yarn add @snackbase/sdk

The SDK works in browsers, React Native, and fetch-compatible server runtimes. Realtime connections use WebSocket when available and fall back to Server-Sent Events.

Quick start

import { SnackBaseClient } from '@snackbase/sdk';

const client = new SnackBaseClient({
  baseUrl: 'https://your-snackbase-instance.example.com',
  // Use an API key for server-side/service authentication when appropriate.
  apiKey: process.env.SNACKBASE_API_KEY,
});

const session = await client.auth.login({
  email: '[email protected]',
  password: 'your-password',
});

console.log(session.user?.email);

type Post = {
  title: string;
  status: string;
};

const posts = await client.records.list<Post>('posts', {
  filter: 'status = "published"',
  sort: '-created_at',
  limit: 20,
});

const post = await client.records.create<Post>('posts', {
  title: 'Hello SnackBase',
  status: 'draft',
});

Keep API keys on trusted servers. Browser and mobile applications should normally use user authentication and the SDK's token storage instead of embedding privileged keys.

Configuration

const client = new SnackBaseClient({
  baseUrl: 'http://localhost:8000',
  storageBackend: 'localStorage', // memory, sessionStorage, or asyncStorage
  enableAutoRefresh: true,
  refreshBeforeExpiry: 300,
  timeout: 30_000,
  maxRetries: 3,
  accountId: 'AB1234', // anonymous public collection scope
});

baseUrl is required. Storage is auto-detected when storageBackend is omitted. Use accountId only when accessing a public collection without a user token; it sends the X-Account-ID header. defaultAccount is available for account-scoped auth flows.

Authentication

The client exposes auth methods both under client.auth and, for common operations, on the client itself:

await client.login({ email, password });
await client.register({ email, password, account_name: 'Acme' });
await client.refreshToken();
await client.getCurrentUser();
await client.logout();

client.user;             // User | null
client.account;          // Account | null
client.isAuthenticated;  // boolean
client.tokenType;        // TokenType

Email/password, OAuth, SAML, password reset, email verification, API-key, and personal token flows are represented by the exported SDK types and auth services. Subscribe to session changes with client.on('auth:login', ...), client.on('auth:refresh', ...), client.on('auth:logout', ...), and client.on('auth:error', ...).

Records and queries

Records are dynamic and can be typed with a generic:

const result = await client.records
  .query<Post>('posts')
  .select(['id', 'title'])
  .filter('status', '=', 'published')
  .sort('created_at', 'desc')
  .limit(20)
  .get();

await client.records.update('posts', post.id, { title: 'Replace fields' }); // PUT
await client.records.patch('posts', post.id, { status: 'published' });      // PATCH
await client.records.delete('posts', post.id);

records.list() accepts string filter expressions, field selection, expansion, offset pagination, cursor pagination, and sorting. The service also provides batchCreate, batchUpdate, batchDelete, and aggregate.

Realtime

Realtime requires an authenticated session. Register handlers, connect, and subscribe to the operations you need:

const off = client.realtime.on('posts.create', (record) => {
  console.log('Created:', record);
});

await client.realtime.connect();
await client.realtime.subscribe('posts', ['create', 'update', 'delete']);

// Later:
off();
await client.realtime.unsubscribe('posts');
client.realtime.disconnect();

Connection lifecycle events include connecting, connected, disconnected, error, and message. Collection handlers receive the event data; the message event receives the complete server message.

Services

Services are available as properties on SnackBaseClient:

| Accessor | Purpose | | --- | --- | | auth | Authentication and user session flows | | accounts, users | Account and user management | | collections, records | Collection schemas and dynamic records | | codelists | Shared dictionaries, effective values, and overrides | | groups, invitations, roles, collectionRules | Access control and membership | | apiKeys, auditLogs | API key and audit log administration | | macros, emailTemplates, migrations | Platform utilities | | dashboard, admin | Statistics and system configuration | | files | Uploads, download URLs, and file deletion | | realtime | WebSocket/SSE subscriptions | | webhooks, hooks, endpoints, workflows, jobs | Automation and background jobs |

The package entry point re-exports the client, query builder, record/auth/codelist and automation types, platform utilities, and typed SDK errors from @snackbase/sdk.

Error handling

SDK requests reject with typed errors:

import {
  AuthenticationError,
  NetworkError,
  RateLimitError,
  SnackBaseError,
  ValidationError,
} from '@snackbase/sdk';

try {
  await client.records.create('posts', { title: 'Hello' });
} catch (error) {
  if (error instanceof ValidationError) console.error(error.fields);
  else if (error instanceof RateLimitError) console.error(error.retryAfter);
  else if (error instanceof AuthenticationError) console.error('Sign in required');
  else if (error instanceof NetworkError) console.error('Retryable network failure');
  else if (error instanceof SnackBaseError) console.error(error.code, error.message);
}

Related packages

Development

From the repository root:

pnpm install
pnpm --filter @snackbase/sdk build
pnpm --filter @snackbase/sdk test
pnpm --filter @snackbase/sdk typecheck

Integration tests require a running SnackBase server. Set SNACKBASE_URL and, for admin/verification flows, SNACKBASE_API_KEY; see tests/integration/README.md.

License

MIT