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

@engageo/notifications

v0.1.0

Published

Engageo browser SDK for Firebase notification device registration

Downloads

23

Readme

@engageo/notifications

Engageo browser SDK for Firebase notification device registration.

The SDK creates a Firebase Cloud Messaging (FCM) registration token in the browser and POSTs it to your backend, which then registers the device with Engageo using a private eng_live_* API key. The browser never sees that private key, never decides which user owns the token, and never calls Engageo directly.

Install

npm install @engageo/notifications
# or
yarn add @engageo/notifications
# or
bun add @engageo/notifications

Quick start

1. Add the Firebase service worker

Web FCM requires a service worker on the customer origin. Copy the ready-to-use worker shipped with the SDK into your app's public/ folder:

cp node_modules/@engageo/notifications/public/firebase-messaging-sw.js public/

It must be served from the same origin as your app at /firebase-messaging-sw.js. The file is self-contained — it loads Firebase from Google's gstatic CDN and is preconfigured for Engageo's Firebase project.

If you want to customize background notification rendering, edit your local copy after copying.

2. Create the backend proxy endpoint

The browser sends only the FCM token. The backend resolves the authenticated user and calls Engageo with the private API key.

// app/api/engageo/register-device/route.ts
import { NextResponse } from "next/server";
import { auth } from "@/auth";

export async function POST(request: Request) {
  const session = await auth();
  if (!session?.user?.id) {
    return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
  }

  const body = await request.json();

  const response = await fetch(
    `${process.env.ENGAGEO_BASE_URL}/api/notifications/devices`,
    {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        Authorization: `Bearer ${process.env.ENGAGEO_NOTIFICATIONS_API_KEY}`,
      },
      body: JSON.stringify({
        externalUserId: `my-app:user:${session.user.id}`,
        platform: "web",
        token: body.token,
        appVersion: body.appVersion,
      }),
    }
  );

  const result = await response.json();
  return NextResponse.json(result, { status: response.status });
}

3. Register the device from the browser

import { registerDevice } from "@engageo/notifications";

async function onEnableNotificationsClick() {
  const permission = await Notification.requestPermission();
  if (permission !== "granted") return;

  const result = await registerDevice({
    registerEndpoint: "/api/engageo/register-device",
    appVersion: "1.0.0",
  });

  if (!result.ok) {
    console.error("Engageo registration failed", result);
    return;
  }

  console.log("Device registered:", result.deviceId);
}

API

registerDevice(options)

const result = await registerDevice({
  registerEndpoint: "/api/engageo/register-device",
  appVersion: "1.0.0",
  serviceWorkerRegistration: undefined,
  fetcher: undefined,
});

Options:

| name | type | description | | --- | --- | --- | | registerEndpoint | string (required) | URL of the customer backend proxy | | appVersion | string | Optional app version forwarded to Engageo | | serviceWorkerRegistration | ServiceWorkerRegistration | Provide an existing registration (useful for local dev) | | fetcher | typeof fetch | Inject a custom fetch — defaults to globalThis.fetch |

Returns a discriminated union — never throws for expected failure states:

type RegisterDeviceResult =
  | { ok: true; deviceId: string }
  | {
      ok: false;
      code:
        | "unsupported"
        | "permission_not_granted"
        | "service_worker_unavailable"
        | "token_unavailable"
        | "registration_failed";
      message: string;
      status?: number;
    };

registerDevice() will not call Notification.requestPermission() — your app keeps full control of the permission UX.

getNotificationPermission()

import { getNotificationPermission } from "@engageo/notifications";

const state = getNotificationPermission();
// "granted" | "denied" | "default" | "unsupported"

createEngageoNotifications(defaults)

Convenience wrapper for apps that register from multiple places:

import { createEngageoNotifications } from "@engageo/notifications";

const notifications = createEngageoNotifications({
  registerEndpoint: "/api/engageo/register-device",
  appVersion: "1.0.0",
});

await notifications.registerDevice();

Security notes

  • The SDK only contains browser-safe values: Firebase web config and the Web Push VAPID public key. Per Firebase docs, these identify the project, not authorize access.
  • Never put eng_live_* keys, Firebase Admin private keys, or any send-capable credentials in browser code.
  • The customer backend resolves the authenticated user — the browser must not send externalUserId.

License

MIT