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

@rajoni/notification-service-sdk

v1.1.6

Published

Realtime in-app notification SDK for Notification Service

Readme

@rajoni/notification-service-sdk

Realtime in-app + browser push notification SDK. Works with Laravel Reverb (WebSocket) and Firebase / OneSignal (push). Compatible with any frontend framework.

Zero config on the client. No public/ folder files, no Reverb keys, no Firebase credentials — everything is fetched automatically from the server.


Install

npm (React / Vue / Angular / Next.js)

npm install @rajoni/notification-service-sdk@latest

CDN (Blade / Django / plain HTML)

<script src="https://unpkg.com/@rajoni/notification-service-sdk@latest/dist/sdk.min.js"></script>

Quick Start

NotificationService.init({
  apiKey:     "your_workspace_api_key",
  userId:     1,
  enablePush: true,   // ← set true to enable browser push notifications
  onNotify: (data) => {
    console.log(data.short_message);
  },
});

How It Works

When NotificationService.init() is called, the SDK does the following automatically:

init()
   │
   ├─ 1. Fetch config from server (/api/sdk/auth)
   │       └─ Reverb host/port/key, socket token, push credentials
   │
   ├─ 2. Connect to Laravel Reverb via WebSocket (laravel-echo + pusher-js)
   │       └─ Subscribe to private channel → fires onNotify callback
   │
   └─ 3. If enablePush: true, initialize push notifications
           ├─ Firebase: registers Service Worker via Blob URL (no public/ file needed)
           └─ OneSignal: Service Worker is served from the notification server

Reverb (In-App, Real-time)

laravel-echo and pusher-js are bundled inside the SDK — no separate install needed. Reverb host, port, key, scheme, and auth endpoint are all fetched from the server automatically. No .env setup required on the client.

Push Notifications (Firebase / OneSignal)

Used to deliver notifications even when the page is closed. No credentials needed on the client — everything comes from the server.

  • Firebase: A Service Worker is created at runtime using a Blob URL with the Firebase config injected directly. No public/firebase-messaging-sw.js needed.
  • OneSignal: The Service Worker is served directly from the notification server. No public/OneSignalSDKWorker.js needed.

If no push credentials are configured on the server, setting enablePush: true will still work — only in-app (Reverb) notifications will run. No errors thrown.


Framework Examples

React

import NotificationService from "@rajoni/notification-service-sdk";
import { useEffect } from "react";

function App() {
  useEffect(() => {
    NotificationService.init({
      apiKey:     "cust_abc123",
      userId:     6,
      enablePush: true,
      onNotify: (data) => {
        alert(data.short_message);
      },
    });

    return () => NotificationService.disconnect();
  }, []);

  return <div>Your App</div>;
}

Next.js (App Router)

"use client";
import NotificationService from "@rajoni/notification-service-sdk";
import { useEffect } from "react";

export default function NotificationProvider({ userId }) {
  useEffect(() => {
    NotificationService.init({
      apiKey:     process.env.NEXT_PUBLIC_API_KEY,
      userId,
      enablePush: true,
      onNotify: (data) => console.log("New notification:", data.short_message),
    });

    return () => NotificationService.disconnect();
  }, [userId]);

  return null;
}

Vue 3

<script setup>
import NotificationService from "@rajoni/notification-service-sdk";
import { onMounted, onUnmounted } from "vue";

onMounted(() => {
  NotificationService.init({
    apiKey:     "cust_abc123",
    userId:     6,
    enablePush: true,
    onNotify:   (data) => alert(data.short_message),
  });
});

onUnmounted(() => NotificationService.disconnect());
</script>

Angular

import { Component, OnInit, OnDestroy } from "@angular/core";
import NotificationService from "@rajoni/notification-service-sdk";

@Component({ selector: "app-root", template: "<router-outlet />" })
export class AppComponent implements OnInit, OnDestroy {
  ngOnInit() {
    NotificationService.init({
      apiKey:     "cust_abc123",
      userId:     6,
      enablePush: true,
      onNotify:   (data) => console.log(data.short_message),
    });
  }

  ngOnDestroy() {
    NotificationService.disconnect();
  }
}

Laravel Blade

@auth
<script src="https://unpkg.com/@rajoni/notification-service-sdk@latest/dist/sdk.min.js"></script>
<script>
  const SDK = window.NotificationService?.default ?? window.NotificationService;

  SDK.init({
    apiKey:     '{{ $workspace->api_key }}',
    userId:     {{ auth()->id() }},
    enablePush: true,
    onNotify:   function(data) { console.log(data.short_message); }
  });
</script>
@endauth

Django Template

{% if user.is_authenticated %}
<script src="https://unpkg.com/@rajoni/notification-service-sdk@latest/dist/sdk.min.js"></script>
<script>
  const SDK = window.NotificationService?.default ?? window.NotificationService;

  SDK.init({
    apiKey:     '{{ api_key }}',
    userId:     {{ user.id }},
    enablePush: true,
    onNotify:   function(data) { console.log(data.short_message); }
  });
</script>
{% endif %}

Plain HTML (CDN)

<!DOCTYPE html>
<html>
<head>
  <script src="https://unpkg.com/@rajoni/notification-service-sdk@latest/dist/sdk.min.js"></script>
</head>
<body>
  <script>
    const SDK = window.NotificationService?.default ?? window.NotificationService;

    SDK.init({
      apiKey:     "cust_abc123",
      userId:     1,
      enablePush: true,
      onNotify: function(data) {
        alert(data.short_message);
      }
    });
  </script>
</body>
</html>

API Reference

NotificationService.init(options)

| Option | Type | Required | Default | Description | |--------|------|----------|---------|-------------| | apiKey | string | ✅ | — | Workspace API key | | userId | number\|string | ✅ | — | Logged-in user ID | | onNotify | function | ✅ | — | Callback fired on in-app notification (Reverb) | | enablePush | boolean | ❌ | false | Enable browser push notifications (Firebase / OneSignal) |

NotificationService.disconnect()

Closes the WebSocket connection. Call on component unmount or page unload.


onNotify Callback Payload

onNotify: (data) => {
  data.id;            // Notification ID
  data.type;          // Notification type (e.g. "order_placed")
  data.short_message; // Notification body text
  data.raw;           // Full raw payload from the server
}

Supported Channels

| Channel | Provider | Works when page is closed? | How it works | |---------|----------|----------------------------|--------------| | In-App | Laravel Reverb | No | WebSocket — real-time while page is open | | Push | Firebase FCM | Yes | Blob SW — no public/ file needed | | Push | OneSignal | Yes | Server-side SW — no public/ file needed |


Server Endpoints

The SDK calls these endpoints internally — no manual configuration needed on the client.

| Endpoint | Method | Description | |----------|--------|-------------| | /api/sdk/auth | GET | Fetch Reverb config + push credentials | | /api/sdk/broadcasting/auth | POST | Authenticate private channel | | /api/sdk/device-token | POST | Register device push token | | /api/sdk/sw/onesignal | GET | Serve OneSignal service worker |


Build from Source

git clone <repo>
cd sdk-v2
npm install
npm run build

Output files:

| File | Use case | |------|----------| | dist/sdk.min.js | CDN, Blade, Django, plain HTML | | dist/sdk.esm.js | npm, React, Vue, Angular |


Browser Support

Chrome, Firefox, Edge, Safari (iOS 16.4+) — any modern browser with Service Worker support.

Note: On localhost, Chrome may show push notifications with a generic title. This is a browser limitation for non-HTTPS origins. Everything works correctly in production on https://.


License

MIT