@parse/push-adapter 6.7.1 → 6.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +10 -0
  2. package/package.json +9 -9
  3. package/src/FCM.js +23 -7
package/README.md CHANGED
@@ -23,6 +23,7 @@ The official Push Notification adapter for Parse Server. See [Parse Server Push
23
23
  - [Google Cloud Service Account Key](#google-cloud-service-account-key)
24
24
  - [Migration to FCM HTTP v1 API (June 2024)](#migration-to-fcm-http-v1-api-june-2024)
25
25
  - [HTTP/1.1 Legacy Option](#http11-legacy-option)
26
+ - [Firebase Client Error](#firebase-client-error)
26
27
  - [Expo Push Options](#expo-push-options)
27
28
  - [Bundled with Parse Server](#bundled-with-parse-server)
28
29
  - [Logging](#logging)
@@ -158,6 +159,15 @@ android: {
158
159
  }
159
160
  ```
160
161
 
162
+ #### Firebase Client Error
163
+
164
+ Occasionally, errors within the Firebase Cloud Messaging (FCM) client may not be managed internally and are instead passed to the Parse Server Push Adapter. These errors can occur, for instance, due to unhandled FCM server connection issues.
165
+
166
+ - `resolveUnhandledClientError: true`: Logs the error and gracefully resolves it, ensuring that push sending does not result in a failure.
167
+ - `resolveUnhandledClientError: false`: Causes push sending to fail, returning a `Parse.Error.OTHER_CAUSE` with error details that can be parsed to handle it accordingly. This is the default.
168
+
169
+ In both cases, detailed error logs are recorded in the Parse Server logs for debugging purposes.
170
+
161
171
  ### Expo Push Options
162
172
 
163
173
  Example options:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parse/push-adapter",
3
- "version": "6.7.1",
3
+ "version": "6.9.0",
4
4
  "description": "Base parse-server-push-adapter",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -24,26 +24,26 @@
24
24
  "author": "Parse",
25
25
  "license": "MIT",
26
26
  "dependencies": {
27
- "@parse/node-apn": "6.2.1",
27
+ "@parse/node-apn": "6.3.0",
28
28
  "@parse/node-gcm": "1.0.2",
29
- "expo-server-sdk": "3.12.0",
30
- "firebase-admin": "12.7.0",
29
+ "expo-server-sdk": "3.13.0",
30
+ "firebase-admin": "13.0.2",
31
31
  "npmlog": "7.0.1",
32
32
  "parse": "5.3.0",
33
33
  "web-push": "3.6.7"
34
34
  },
35
35
  "devDependencies": {
36
- "@eslint/js": "9.15.0",
36
+ "@eslint/js": "9.17.0",
37
37
  "@semantic-release/changelog": "6.0.3",
38
38
  "@semantic-release/commit-analyzer": "13.0.0",
39
39
  "@semantic-release/git": "10.0.1",
40
40
  "@semantic-release/github": "11.0.1",
41
41
  "@semantic-release/npm": "12.0.1",
42
- "@semantic-release/release-notes-generator": "14.0.1",
43
- "c8": "10.1.2",
42
+ "@semantic-release/release-notes-generator": "14.0.2",
43
+ "c8": "10.1.3",
44
44
  "codecov": "3.8.3",
45
- "eslint": "9.15.0",
46
- "jasmine": "5.4.0",
45
+ "eslint": "9.17.0",
46
+ "jasmine": "5.5.0",
47
47
  "jasmine-spec-reporter": "7.0.0",
48
48
  "semantic-release": "24.2.0"
49
49
  },
package/src/FCM.js CHANGED
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- import Parse from 'parse';
4
- import log from 'npmlog';
5
- import { initializeApp, cert, getApps, getApp } from 'firebase-admin/app';
3
+ import { cert, getApp, getApps, initializeApp } from 'firebase-admin/app';
6
4
  import { getMessaging } from 'firebase-admin/messaging';
5
+ import log from 'npmlog';
6
+ import Parse from 'parse';
7
7
  import { randomString } from './PushAdapterUtils.js';
8
8
 
9
9
  const LOG_PREFIX = 'parse-server-push-adapter FCM';
@@ -28,6 +28,9 @@ export default function FCM(args, pushType) {
28
28
  const fcmEnableLegacyHttpTransport = typeof args.fcmEnableLegacyHttpTransport === 'boolean'
29
29
  ? args.fcmEnableLegacyHttpTransport
30
30
  : false;
31
+ this.resolveUnhandledClientError = typeof args.resolveUnhandledClientError === 'boolean'
32
+ ? args.resolveUnhandledClientError
33
+ : false;
31
34
 
32
35
  let app;
33
36
  if (getApps().length === 0) {
@@ -88,8 +91,18 @@ FCM.prototype.send = function (data, devices) {
88
91
  const length = deviceTokens.length;
89
92
  log.info(LOG_PREFIX, `sending push to ${length} devices`);
90
93
 
91
- return this.sender
92
- .sendEachForMulticast(fcmPayload.data)
94
+ // This is a safe wrapper for sendEachForMulticast, due to bug in the firebase-admin
95
+ // library, where it throws an exception instead of returning a rejected promise
96
+ const sendEachForMulticastSafe = fcmPayloadData => {
97
+ try {
98
+ return this.sender.sendEachForMulticast(fcmPayloadData);
99
+ } catch (err) {
100
+ log.error(LOG_PREFIX, `error sending push: firebase client exception: ${err}`);
101
+ return Promise.reject(new Parse.Error(Parse.Error.OTHER_CAUSE, err));
102
+ }
103
+ };
104
+
105
+ return sendEachForMulticastSafe(fcmPayload.data)
93
106
  .then((response) => {
94
107
  const promises = [];
95
108
  const failedTokens = [];
@@ -140,8 +153,11 @@ FCM.prototype.send = function (data, devices) {
140
153
 
141
154
  const allPromises = Promise.all(
142
155
  slices.map((slice) => sendToDeviceSlice(slice, this.pushType)),
143
- ).catch((err) => {
144
- log.error(LOG_PREFIX, `error sending push: ${err}`);
156
+ ).catch(e => {
157
+ log.error(LOG_PREFIX, `error sending push: ${e}`);
158
+ if (!this.resolveUnhandledClientError && e instanceof Parse.Error && e.code === Parse.Error.OTHER_CAUSE) {
159
+ return Promise.reject(e);
160
+ }
145
161
  });
146
162
 
147
163
  return allPromises;