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

@delimitus/ssc-reconnect

v0.0.3

Published

Keep a WebSocket or an event stream going past the SSC request limit (X-SSC-Request-Deadline). Zero dependencies.

Readme

@delimitus/ssc-reconnect

Keep a WebSocket or an event stream going past the platform's limit. Zero dependencies; Node 22 or newer. An ES module; a CommonJS app can require() it on Node 22.12 or newer.

npm install @delimitus/ssc-reconnect

Cloud Run ends every request at the limit the gateway reports (5 minutes for most apps, 60 for session apps), and an open WebSocket or event stream is one request. The gateway tells the app when in the X-SSC-Request-Deadline header. These helpers end the stream cleanly a little before then, and the browser opens a new one by itself.

import { browserClient, closeBeforeDeadline, endBeforeDeadline, secondsLeft } from '@delimitus/ssc-reconnect';

// Event stream: EventSource reconnects by itself, with Last-Event-ID if your events carry an id.
res.writeHead(200, { 'content-type': 'text/event-stream' });
endBeforeDeadline(res, req.headers);

// WebSocket (the `ws` package or anything with close(code, reason)): closed with code 1012.
wss.on('connection', (socket, req) => closeBeforeDeadline(socket, req.headers));

// The browser side of the WebSocket: serve this file and use sscSocket() instead of new WebSocket().
app.get('/ssc-reconnect.js', (_req, res) => res.type('text/javascript').send(browserClient()));

secondsLeft(req.headers); // seconds until the limit; null when run without the gateway

In the page:

<script src="/ssc-reconnect.js"></script>
<script>
  let last = -1;
  const socket = sscSocket(() => `wss://${location.host}/ws?after=${last}`, {
    onopen() { /* runs again after every reconnect: send what the server needs */ },
    onmessage(event) { last = Number(event.data); },
  });
</script>

sscSocket reconnects at once after code 1012 and after a growing pause on an unclean drop. WebKit (Safari) reports any close the server starts as 1005, so 1005 counts as 1012. It gives up, calling onclose, after 10 reconnects in a row that did not stay open, or on a clean close with any other code. Options: protocols, onopen, onmessage, onclose, delayMs (250), maxDelayMs (10000), attempts (10).

Both server helpers take { margin } in seconds (30) and endBeforeDeadline also { retryMs } (1000). Both return a function that cancels, and cancel themselves when the stream closes first. A stream that opens with less than the margin left is ended after half the time left (secondsToWait), never at once. Without the header, as on a laptop, nothing is cut.

A reconnect is a new connection. Keep anything that must outlive one in Postgres or in the browser. Streamlit, Gradio, Dash and Shiny use their own connections and cannot use this; see the session-app note in docs/contracts/manifest.md.

npm test runs the shared vectors in conformance/reconnect/vectors.json, the same ones the Python helper ssc_app.reconnect runs, and holds a stream across a limit shortened to two seconds.