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

@notificationhub/client

v0.2.1

Published

NotificationHub client: a live notification feed that survives dropped connections

Readme

@notificationhub/client

The NotificationHub client: a live notification feed that survives dropped connections, plus push-device registration.

pnpm add @notificationhub/client

Published to public npm, so there is no registry configuration and no token.

Use

import { NotificationClient } from '@notificationhub/client'

const client = new NotificationClient({
  baseUrl: 'https://notifications.example.com',
  // Called on EVERY connect, not once: the server closes sockets whose
  // authorization has aged out, and a stale token produces a reconnect loop.
  getToken: () => fetchShortLivedToken(),
  feed: 'learning-space',
})

const unsubscribe = client.subscribe(({ items, counts, hasMore }) => render(items, counts, hasMore))
await client.start()

subscribe + state are the pair React's useSyncExternalStore wants, so a hook layer is a few lines rather than a second copy of this state.

What it does

| | | |---|---| | start / stop | Reconcile, then hold a socket | | subscribe / state | Observe the feed | | onArrived | Items that just arrived — for a toast, chime or badge | | setFilter | all / unread / unseen, filtered server-side | | fetchNextPage | Older notifications, appended | | markSeen / markRead / markUnread | State changes, applied optimistically | | archive / unarchive / markAllRead | As above | | registerDevice / removeDevice | Push registration for this device | | handleFocus | Refetch after a tab has slept |

Registering a device without a feed

registerDevice and removeDevice are also exported as plain functions, for the two cases that cannot hold a client:

import { registerDevice, removeDevice } from '@notificationhub/client'

await registerDevice({ baseUrl, userToken, token: fcmToken, platform: 'web' })
await removeDevice({ baseUrl, userToken, token: fcmToken })

Logout is the one that forces this. The session is ending, so there is no way to mint a fresh end-user token — the caller has to pass the one it registered with, which a client's getToken cannot express because it always asks for a new one.

The second case is a page that registers a device without rendering a feed. Requiring a client there would tie push to whatever gates the feed.

The client's methods delegate to these, so both paths speak one wire format.

onArrived is not subscribe with extra steps. subscribe reports the whole state whenever anything changes, so a reconcile that delivered three notifications looks identical to one that changed nothing — which is exactly what a caller needs to tell apart before it pops a toast. It never fires for the first load, because existing history did not arrive.

state.loading means a full fetch is outstanding and the list below is not yet the answer; state.loadingMore means the list IS the answer and more is being appended. A skeleton belongs to the first and a spinner to the second, so they are two flags.

state.unread and state.unseen are for the feed this client renders, not across all of them. state.counts still carries every feed plus a total, which is what a client displaying several wants — but lighting a badge from the total means a notification in a feed this client never shows keeps it lit, and nothing the person does can clear it.

The assumption it is built on

The socket is unreliable. Sockets drop, tabs sleep, phones change network, and the server deliberately closes a connection once its token has aged out.

So the socket carries hints, not data: it says "something changed", and the client fetches the truth over HTTP. A missed message costs one extra request rather than a lost notification — which is what removes message ordering, replay buffers and acknowledgements from the design entirely.

Reconnection uses exponential backoff with jitter, because every client of a tenant is disconnected by the same deploy at the same instant and a bare schedule reconnects them in lockstep. After three failures it falls back to polling, so the feed still updates where a socket cannot be held at all — a corporate proxy, a restrictive network, an old WebView.

State changes are optimistic: applied locally and put back if the server disagrees. A round trip of latency on "mark as read" reads as a broken button.

Releasing

Versioned with semver and published by .github/workflows/publish-client.yml on a client-v* tag:

npm version --no-git-tag-version minor --prefix packages/client
git commit -am "client: v0.2.0" && git tag client-v0.2.0 && git push --follow-tags