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

@senkronla/client

v0.1.11

Published

Senkronla client SDK — RelayClient, SyncEngine, EsrSync facade

Readme

@senkronla/client

Client SDK for Senkronla — connect to a self-hosted Envelope Sync Relay (ESR), sync JSON document snapshots per namespace, handle pairing, recovery, conflicts, and optional WebSocket notifications.

Your app owns the data model and encryption choices. The relay stores opaque ESR-DOC1 envelopes; this SDK handles transport, revision tracking, and user-facing sync lifecycle.

Install

npm install @senkronla/client
# or
pnpm add @senkronla/client

@senkronla/protocol is installed automatically as a dependency. You also re-export protocol helpers from @senkronla/client when convenient.

Node.js 22+ or modern browsers. Works with fetch, localStorage, and WebSocket where available.

Quick start

import {
  EsrSync,
  createDocumentAdapter,
  createLocalStorageAdapter,
  generateNamespaceId,
} from '@senkronla/client'

const namespaceId = generateNamespaceId() // persist before ensureNamespace

const sync = await EsrSync.connect({
  relayUrl: 'https://sync.example.com/v1',
  appId: 'esr_app_myapp', // when relay GET /health → apps.enabled is true
  storage: createLocalStorageAdapter('myapp'),
  document: createDocumentAdapter({
    namespaceId,
    namespaceLabel: 'My workspace',
    contentType: 'application/vnd.myapp+json',
    exportDocument: () => appStore.exportState(),
    importDocument: (data) => appStore.importState(data),
  }),
  onRecoveryPhrase: async ({ phrase }) => {
    await showRecoveryModal(phrase) // user must save offline
  },
  onConflict: async (ctx) => {
    return askKeepLocalOrRemote(ctx.remoteMeta.writtenAt) // 'local' | 'remote' | 'cancel'
  },
})

await sync.ensureNamespace()
await sync.sync()

appStore.onChange(() => sync.notifyLocalChange('primary'))

Core concepts

| Concept | Role | |---------|------| | Namespace | Isolated sync space (UUID v4) — usually one per customer account | | Document | Named JSON snapshot (primary by default; multi-document supported) | | DocumentAdapter | Your bridge: export/import app state, contentType, optional encryption | | EsrSync | Facade: connect, ensureNamespace, sync, pairing, recovery |

Implement sync by:

  1. Persist a stable namespaceId before the first ensureNamespace()
  2. Call notifyLocalChange(documentId) after every local edit
  3. Handle onRecoveryPhrase and onConflict (required)

Multi-document

const sync = await EsrSync.connect({
  relayUrl: 'https://sync.example.com/v1',
  storage: createLocalStorageAdapter('myapp'),
  documents: [
    { adapter: mainAdapter },
    { documentId: 'settings', adapter: settingsAdapter },
  ],
  onRecoveryPhrase: async ({ phrase }) => showRecoveryModal(phrase),
  onConflict: async (ctx) => askKeepLocalOrRemote(ctx.remoteMeta.writtenAt),
})

sync.notifyLocalChange('settings')
await sync.sync('settings')

All adapters must return the same namespaceId().

Application registry

When the relay operator enables apps.enabled, pass appId to EsrSync.connect(). The SDK sends X-ESR-App-Id on every request.

Native apps may also need:

  • appPlatform — ios, android, or desktop
  • bundleId
  • clientSecret when GET /health → apps.nativeRequireClientSecret is true

Web clients rely on browser Origin; do not embed client secrets in front-end builds.

Encryption (optional)

createDocumentAdapter({
  namespaceId,
  namespaceLabel: 'My workspace',
  contentType: 'application/vnd.myapp+json',
  encrypt: true,
  resolvePassword: async () => userSyncPassword,
  exportDocument: () => state,
  importDocument: (data) => { state = data },
})

The SDK builds and decrypts ENV-ENC1 envelopes on push/pull.

Advanced modules

Lower-level building blocks (same package):

| Export | Use case | |--------|----------| | RelayClient | Direct REST /v1 without the facade | | SyncEngine | Custom push/pull loop | | NotificationClient | WebSocket + poll fallback | | buildEnvelope / extractDocument | Manual envelope assembly |

Protocol types and helpers are re-exported from @senkronla/protocol.

Documentation

License

MIT