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

@moltcms/client

v0.4.0

Published

Type-safe client for the moltcms read-only sync API: a typed Server-Sent Events feed of content changes for incremental builds.

Readme

@moltcms/client

Type-safe client for the moltcms read-only sync API. moltcms is an incremental-build, multi-tenant headless CMS: instead of polling REST endpoints, build and frontend clients drain a Server-Sent Events feed of content changes and resume from a cursor.

This package ships:

  • openSyncStream — a dependency-free, typed EventSource wrapper for the /tenants/{tenant}/sync feed (drain-to-completion semantics, cursor resume).
  • openServerSyncStream — a fetch-based variant for Bun/Node build scripts: sends the API key in the Authorization header and reconnects automatically with backoff.
  • Generated types (DeliveryItem, FieldDef, FieldType, …) produced from the API's OpenAPI spec, so payloads narrow as discriminated unions.
  • openapi-public.json — the read-only subset of the OpenAPI 3.1 spec (importable as @moltcms/client/openapi.json).
npm install @moltcms/client   # or: bun add @moltcms/client

Usage

import { openSyncStream } from "@moltcms/client";

const stream = openSyncStream(
  `${BASE_URL}/tenants/${TENANT_ID}/sync`,
  {
    onChange: (item) => {
      // `item` is a DeliveryItem — narrow on the `type` discriminator:
      switch (item.type) {
        case "content":         /* item.id, item.data, item.schema_version */ break;
        case "content_deleted": /* remove item.id locally */ break;
        case "schema_changed":  /* item.fields: FieldDef[] */ break;
      }
    },
    onComplete: (cursor) => save(cursor), // persist; pass back as `cursor` next run
    onError: (msg) => console.error("sync error:", msg),
  },
  { cursor: loadSavedCursor() },
);
// The stream closes itself after `sync-complete` (drain-to-completion).
// To stop early: stream.close();

Server-side (Bun/Node)

Use openServerSyncStream in build scripts and other non-browser runtimes. It authenticates with the Authorization: Bearer header (native EventSource cannot) and reconnects automatically:

import { openServerSyncStream } from "@moltcms/client";

const stream = openServerSyncStream(
  `${BASE_URL}/tenants/${TENANT_ID}/sync`,
  {
    onChange: (item) => apply(item),
    onComplete: (cursor) => save(cursor),
    onTransportError: (err) => console.warn("sync transport:", err),
  },
  { apiKey: process.env.MOLTCMS_READ_KEY!, cursor: loadSavedCursor() },
);
// To stop early: stream.close();

Reconnection contract:

  • HTTP 429 and 5xx, and transport failures (dropped connection, network error), are retried with exponential backoff: 1s initial delay, doubling up to a 30s cap, with ±20% jitter. The backoff attempt resets once a change or sync-complete event is delivered — not on a bare 200 that delivers nothing.
  • A Retry-After header (seconds or HTTP-date) raises the wait to at least the requested time; the backoff schedule keeps advancing underneath, so a later header-less failure continues where the schedule left off.
  • Other 4xx (e.g. 401/403) is terminal: the stream closes and reports the status via onTransportError as a ServerSyncHttpError.
  • Resume sends Last-Event-ID like the browser feed, which keeps replays rare. Delivery is still at-least-once — after a crash, events past the last completed cursor may be redelivered — so onChange handlers and projections must be idempotent.
  • stream.close() stops reconnecting immediately, including mid-backoff.

Feed semantics

  • change events carry one DeliveryItem; the SSE event id is its raw seq, so a dropped connection resumes automatically mid-stream (Last-Event-ID).
  • sync-complete carries an opaque cursor. Persist it and pass it as the cursor option on the next run to sync incrementally. Do not put it in Last-Event-ID — that header only accepts a raw seq.
  • A server error event ends the stream. The client closes itself after sync-complete/error by default (autoClose: false opts out, degrading the feed into a coarse poll).
  • Pass kind: "draft" to read draft content (requires a draft-capable key) — e.g. for preview builds.

Authentication

The feed is authenticated with a read-only API key (Bearer). Native EventSource cannot send an Authorization header, so in browsers prefer a backend-set cookie (eventSourceInit: { withCredentials: true }, mind CORS/CSRF) or an EventSource polyfill that supports custom headers. Avoid query-parameter keys — URLs leak into access logs, proxies and browser history. In server-side runtimes (Node/Bun build scripts), use openServerSyncStream, which sends the header natively.

Versioning

The package version tracks the moltcms server release. Generated code and the bundled spec always match the server version of the same number.