@theshelf/notification
v0.0.3
Published
The notification package provides a universal interaction layer with an actual notification solution.
Keywords
Readme
Notification | The Shelf
The notification package provides a universal interaction layer with an actual notification solution.
This package is based on a push notification model.
Installation
npm install @theshelf/notificationImplementations
Currently, there are two implementations:
- Memory - non-persistent in memory notifications (suited for testing).
- WebPush - web browser based push notifications.
Configuration
The used implementation needs to be configured in the .env file with the debug enabled setting.
NOTIFICATION_IMPLEMENTATION="webpush" # (memory | webpush)In case of WebPush, additional configuration is required.
WEBPUSH_VAPID_SUBJECT="..."
WEBPUSH_VAPID_PUBLIC_KEY="..."
WEBPUSH_VAPID_PRIVATE_KEY="..."How to use
An instance of the configured notification service implementation can be imported for performing notification operations.
import notificationService from '@theshelf/notification';
// Perform operations with the notificationService instanceOperations
import notificationService from '@theshelf/notification';
// Open connection
await notificationService.connect();
// Close connection
await notificationService.disconnect();
// Subscribe to receive notifications
await notificationService.subscribe(recipientId);
// Unsubscribe from receiving notifications
// Throws SubscriptionNotFound if subscription not found.
await notificationService.unsubscribe(recipientId);
// Send a notification to a recipient
// Throws SubscriptionNotFound if subscription not found.
await notificationService.sendNotification(recipientId, title, body);