firebase-messaging-minimal
v1.2.0
Published
Firebase messaging minimal SDK for Node.js
Downloads
13
Maintainers
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 |
-----------------------------|---------|----------|---------|---------|-------------------------