Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
@kalisio/feathers-webpush
Advanced tools
feathers-webpush
simplifies the sending of web push notifications in a FeathersJS application.
The feathers-webpush
module provides a simplified way to send web push notifications in a FeathersJS application. It leverages the web-push package to interact with the Web Push protocol.
npm install @kalisio/feathers-webpush --save
or
yarn add @kalisio/feathers-webpush
The provided example illustrates how to setup:
feathers-webpush
consists of two parts:
Create an instance of the service with the given options:
Parameter | Description | Required |
---|---|---|
vapidDetails | The vapidDetails configuration. Refer to the web-push package documentation for more information. | yes |
app | The feathers app instance. | yes |
The create
method is used to send web push notifications. The data
payload must contain the following properties:
Property | Description | Required |
---|---|---|
notification | The data payload for the push notification. | yes |
subscriptionService | The name of the service where subscriptions are registered. | yes |
subscriptionProperty | The name of the key where subscriptions are regitered. It can be an array of subscriptions or a single subscription object | yes |
subscriptionFilter | The filter you wish to apply when retrieving subscriptions. | no |
Note: Subscription should be registered in the following format:
{ endpoint: 'url_google', keys: { auth: 'xxxx', p256dh: 'xxxx' }}
The feathers-webpush
module provides a hook for managing web push subscriptions.
The deleteExpiredSubscriptions
is an after
hook that deletes expired subscriptions. It should be used after the create
method.
To use this hook, you need to import it and include it in your FeathersJS application.
Exemple usage:
import { deleteExpiredSubscriptions } from '@kalisio/feathers-webpush'
app.service('push-notifications').hooks({
after: {
create: [deleteExpiredSubscriptions()]
}
})
The client.js
file provides a utility to manage client-side web push notifications with the following functions:
Before using web push notifications, you need to check if the necessary prerequisites are met. The checkPrerequisites
function provided by feathers-webpush
can be used for this purpose. It checks whether the browser supports notifications and returns error message 498 if it does not.
To ask the user for permission to send notifications, you can use the requestNotificationPermission
function provided by feathers-webpush
. This function requests permission from the user and returns code 499 if permission is denied, or the status of the permission.
The getPushSubscription
function retrieves the current push subscription, if it exists. It returns the subscription object or null if there is no active subscription.
To subscribe to push notifications, use the subscribePushNotifications
function. It requires a public VAPID key as a parameter and returns the subscription object.
To unsubscribe from push notifications, use the unsubscribePushNotifications
function. It retrieves the registration from the service worker and unsubscribes the current push subscription. It returns the unsubscribed subscription object.
You can add or remove subscriptions from a user object using the addSubscription
and removeSubscription
functions provided by feathers-webpush
. These functions require the user object, the current subscription, and the subscription property.
To run the tests for feathers-webpush
, install the required node modules and run npm run test
or yarn test
.
To perform the tests, you need to create web push subscription and set the following environment variables:
SUBSCRIPTION_TEST_ENDPOINT
SUBSCRIPTION_TEST_KEY_AUTH
SUBSCRIPTION_TEST_KEY_P256DH
Copyright (c) 2017-20xx Kalisio
Licensed under the MIT license.
This project is sponsored by
FAQs
Manage web push notifications
The npm package @kalisio/feathers-webpush receives a total of 62 weekly downloads. As such, @kalisio/feathers-webpush popularity was classified as not popular.
We found that @kalisio/feathers-webpush demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.