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

@notifizz/subscribe-vanilla

v2.0.0

Published

Vanilla JS / TypeScript wrapper for the Notifizz subscribe widget — multi-instance per page

Downloads

260

Readme

@notifizz/subscribe-vanilla

Vanilla JavaScript / TypeScript wrapper around the Notifizz subscribe widget. Mount as many widget instances as you need on the same page — one per Kanban card, one per thread, one per resource.

Install

npm install @notifizz/subscribe-vanilla

Quick start

import { createSubscribe } from '@notifizz/subscribe-vanilla';

const subscribe = createSubscribe({
  apiKey: 'ntfz_pk_xxx',          // your env public key
  mode: 'secure',                  // or 'public' for resources with no privacy
  subscriberId: 'user_42',         // matches your backend HMAC input
});

const widget = await subscribe.mount({
  container: '#card-42',           // CSS selector or HTMLElement
  resourceId: 'proj_42',
  hash: 'a1b2c3...',               // required in secure mode
});

widget.subscribe();
widget.onStateChange((state) => {
  console.log('subscribed?', state.isSubscribed);
  console.log('total subs:', state.subscriberCount);
});

Multi-instance — N widgets on the same page

const subscribe = createSubscribe({ apiKey, mode: 'secure', subscriberId });

// Mount one widget per Kanban card
const projects = await fetchProjects();
for (const project of projects) {
  await subscribe.mount({
    container: `#card-${project.id}`,
    resourceId: project.id,
    hash: project.subscribeHash,   // generated server-side per project
  });
}

Widgets that share the same resourceId automatically stay in sync — clicking Subscribe on one updates the avatar list of all the others without a refetch.

Generating the hash (secure mode)

Server-side, using a Notifizz backend SDK:

// Node.js
const hash = notifizz.generateSubscribeToken(subscriberId, resourceId);
// = HMAC-SHA256(authSecretKey, subscriberId + resourceId)

Same method exists in the PHP and Java SDKs. The hash is then passed to mount() from the client.

In public mode, no hash is needed — the backend accepts any subscriberId.

API

createSubscribe(options): SubscribeVanillaApi

| Option | Required | Default | Notes | |---|---|---|---| | apiKey | ✅ | — | Public API key from your Notifizz environment | | mode | ✅ | — | 'secure' (HMAC required) or 'public' | | subscriberId | ✅ | — | Current user's ID — must match the server-side hash input | | apiUrl | | https://eu.api.notifizz.com/v1 | Override for self-hosted / staging | | serverUrl | | https://widget.notifizz.com | Where to load the widget loader from | | widgetPath | | /v1/subscribe-loader.js | Loader path | | autoMount | | false | Whether the widget should scan [data-notifizz-subscribe] automatically. Usually off when driving via mount() | | maxAvatars | | 5 | Default — overridden by org brand if defined | | readyTimeoutMs | | 10000 | How long to wait for the loader to finish |

subscribe.mount(options): Promise<SubscribeHandle>

Mount a widget on a container. Returns a handle to interact with that instance.

| Option | Required | Notes | |---|---|---| | container | ✅ | CSS selector or HTMLElement | | resourceId | ✅ | Identifier of the resource being subscribed to | | hash | If mode === 'secure' | HMAC hash for this (subscriberId, resourceId) pair |

SubscribeHandle methods

handle.subscribe()          // Promise<void>
handle.unsubscribe()        // Promise<void>
handle.toggle()             // Promise<void>
handle.refresh()            // Promise<void> — force refetch from server
handle.getState()           // { isSubscribed, subscriberCount, subscribers[] }
handle.onStateChange(cb)    // () => void — returns unsubscribe function
handle.destroy()            // tear down DOM + listeners

subscribe.destroy()

Tear down all active widget instances created via this subscribe controller. Does NOT remove the loader script (it may be shared with future mounts).

Lifecycle in SPAs

Pair mount() with cleanup in your framework's effect hook:

// React example
useEffect(() => {
  let widget: SubscribeHandle | null = null;
  let cancelled = false;

  subscribe.mount({
    container: ref.current!,
    resourceId: project.id,
    hash: project.subscribeHash,
  }).then((w) => {
    if (cancelled) {
      w.destroy();
    } else {
      widget = w;
    }
  });

  return () => {
    cancelled = true;
    widget?.destroy();
  };
}, [project.id]);

(For React, prefer @notifizz/subscribe-react — it does all this wiring for you.)

Errors

mount() rejects when:

  • The loader script fails to load (network / CSP) within readyTimeoutMs
  • The container doesn't exist or is already mounted
  • mode === 'secure' but no hash is provided
  • init() hasn't been called (shouldn't happen via this wrapper — it's automatic)

See also

  • @notifizz/subscribe-react — React-native multi-instance with useSubscription hook
  • @notifizz/subscribe-angular — Angular component
  • Documentation: https://docs.notifizz.com/sdks/subscribe (coming soon)