@seliseblocks/notifications
v0.0.3
Published
A modern ESM-based SignalR notification package.
Maintainers
Keywords
Readme
@seliseblocks/notifications
Blocks cloud's notification package.
Features
- Connects to a notification hub
- Dynamically loads notification channels from your API
- Handles authentication via access token factory
- Simple subscription and cleanup API
Installation
npm install @seliseblocks/notificationsUsage
import { subscribeNotifications } from "@seliseblocks/notifications";
const apiBaseUrl = "https://your-api-url";
const projectKey = "your-project-key";
const accessTokenFactory = () => "your-access-token";
const { stop } = await subscribeNotifications(
apiBaseUrl,
{
projectKey,
configSize: 100, // optional, default is 100
accessTokenFactory
},
(channel, message) => {
console.log(`Received message on channel ${channel}:`, message);
}
);
// To stop receiving notifications:
await stop();API
subscribeNotifications(apiBaseUrl, options, onMessage)
apiBaseUrl(string): Base URL for your API.options(object):projectKey(string): Unique key for your project.configSize(number, optional): Number of configs to fetch (default: 100).accessTokenFactory(function): Returns a valid access token.
onMessage(function): Callback(channel, message)for incoming notifications.
Returns: { stop: () => Promise<void> }
License
MIT
