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 🙏

© 2024 – Pkg Stats / Ryan Hefner

firebase-messaging-minimal

v1.2.0

Published

Firebase messaging minimal SDK for Node.js

Downloads

135

Readme

Firebase Cloud Messaging (FCM) API Usage

This module provides functions to interact with the Firebase Cloud Messaging (FCM) API for sending messages, subscribing/unsubscribing devices to/from topics, and handling multicast messages.

Functions

subscribeToTopic(accessToken, registrationTokenOrTokens, topic)

Subscribes a device or multiple devices to an FCM topic.

  • accessToken (string): Access token generated by Google JWT.
  • registrationTokenOrTokens (string|string[]): A token or array of registration tokens for the devices to subscribe to the topic.
  • topic (string): The topic to which to subscribe.

Returns a promise fulfilled with the server's response after the device(s) have been subscribed to the topic.

unsubscribeFromTopic(accessToken, registrationTokenOrTokens, topic)

Unsubscribes a device or multiple devices from an FCM topic.

  • accessToken (string): Access token generated by Google JWT.
  • registrationTokenOrTokens (string|string[]): A device registration token or an array of device registration tokens to unsubscribe from the topic.
  • topic (string): The topic from which to unsubscribe.

Returns a promise fulfilled with the server's response after the device(s) have been unsubscribed from the topic.

send(projectId, accessToken, message, dryRun)

Sends a message via FCM.

  • projectId (string): Project ID assigned in Firebase.
  • accessToken (string): Access token generated by Google JWT.
  • message (Message): The message payload.
  • dryRun (boolean): Whether to send the message in the dry-run (validation only) mode.

Returns a promise fulfilled with a unique message ID string after the message has been successfully handed off to the FCM service for delivery.

sendEachForMulticast(projectId, accessToken, message, dryRun)

Sends a multicast message to all specified device tokens.

  • projectId (string): Project ID assigned in Firebase.
  • accessToken (string): Access token generated by Google JWT.
  • message (MulticastMessage): A multicast message containing an array of device tokens.
  • dryRun (boolean): Whether to send the message in the dry-run (validation only) mode.

Returns a promise fulfilled with an object representing the result of the send operation.

sendEach(projectId, accessToken, messages, dryRun)

Sends each message in the given array via Firebase Cloud Messaging.

  • projectId (string): Project ID assigned in Firebase.
  • accessToken (string): Access token generated by Google JWT.
  • messages (Message[]): A non-empty array containing up to 500 messages.
  • dryRun (boolean): Whether to send the messages in the dry-run (validation only) mode.

Returns a promise fulfilled with an object representing the result of the send operation.

Message Structures

Message

Payload for sending messages via FCM.

{
  data?: { [key: string]: string };
  notification?: Notification;
  android?: AndroidConfig;
  webpush?: WebpushConfig;
  apns?: ApnsConfig;
  fcmOptions?: FcmOptions;
}

For more details, refer to the Firebase Admin Node SDK Messaging API documentation.

Test case coverage status

-----------------------------|---------|----------|---------|---------|-------------------------
File                         | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s       
-----------------------------|---------|----------|---------|---------|-------------------------
All files                    |   80.64 |     62.5 |   89.65 |   80.48 |                         
 app                         |    75.8 |       50 |   92.85 |    75.4 |                         
  messagin-error-internal.js |   51.85 |       50 |     100 |   51.85 | 11,14-17,24,35-36,42-49 
  messaging.js               |   94.28 |       50 |   91.66 |   94.11 | 124-126                 
 constants                   |     100 |      100 |     100 |     100 |                         
  apiConstants.js            |     100 |      100 |     100 |     100 |                         
  errorConstants.js          |     100 |      100 |     100 |     100 |                         
 util                        |   84.74 |    81.25 |   86.66 |   84.74 |                         
  apiRequest.js              |   33.33 |      100 |       0 |   33.33 | 4-7                     
  helper.js                  |      75 |      100 |     100 |      75 | 5                       
  request.js                 |   87.23 |       75 |   88.88 |   87.23 | 39,45,71-77,93          
  validator.js               |     100 |      100 |     100 |     100 |                         
-----------------------------|---------|----------|---------|---------|-------------------------