@parse/push-adapter 6.9.0 → 6.10.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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Parse Server Push Adapter <!-- omit in toc -->
2
2
 
3
- [![Build Status](https://github.com/parse-community/parse-server-push-adapter/workflows/ci/badge.svg?branch=master)](https://github.com/parse-community/parse-server-push-adapter/actions?query=workflow%3Aci+branch%3Amaster)
3
+ [![Build Status](https://github.com/parse-community/parse-server-push-adapter/actions/workflows/ci.yml/badge.svg)](https://github.com/parse-community/parse-server-push-adapter/actions/workflows/ci.yml)
4
4
  [![Snyk Badge](https://snyk.io/test/github/parse-community/parse-server-push-adapter/badge.svg)](https://snyk.io/test/github/parse-community/parse-server-push-adapter)
5
5
  [![Coverage](https://img.shields.io/codecov/c/github/parse-community/parse-server-push-adapter/master.svg)](https://codecov.io/github/parse-community/parse-server-push-adapter?branch=master)
6
6
  [![auto-release](https://img.shields.io/badge/%F0%9F%9A%80-auto--release-9e34eb.svg)](https://github.com/parse-community/parse-server-push-adapter/releases)
@@ -72,10 +72,11 @@ Parse Server Push Adapter currently supports these types of Apple ecosystems:
72
72
  - `ios`: iPhone, iPad, and iPod touch apps
73
73
  - `osx`: macOS, and macCatalyst apps
74
74
  - `tvos`: tvOS apps
75
+ - `watchos`: watchOS apps
75
76
 
76
- Delivering push notifications to Apple devices can be done either via Apple Push Notification Service (APNS), or via Firebase Cloud Messaging (FMC). Note that each category of Apple devices require their own configuration section:
77
+ Push notifications can be delivered to Apple devices either via Apple Push Notification Service (APNS) or Firebase Cloud Messaging (FMC). Note that each category of Apple devices requires their own configuration section:
77
78
 
78
- - APNS requires a private key that can be downloaded from the Apple Developer Center at https://developer.apple.com/account under _Certificates > Identifiers & Profiles._ The adapter options also require the app ID and team ID which can be found there.
79
+ - APNS requires a private key that can be downloaded from the Apple Developer Center at https://developer.apple.com/account under _Certificates > Identifiers & Profiles._ The adapter options also require the app ID and team ID, which can be found there.
79
80
  - FCM requires a private key that can be downloaded from the Firebase Console at https://console.firebase.google.com in your project under _Settings > Cloud Messaging._
80
81
 
81
82
  Example options:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parse/push-adapter",
3
- "version": "6.9.0",
3
+ "version": "6.10.0",
4
4
  "description": "Base parse-server-push-adapter",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -33,19 +33,19 @@
33
33
  "web-push": "3.6.7"
34
34
  },
35
35
  "devDependencies": {
36
- "@eslint/js": "9.17.0",
36
+ "@eslint/js": "9.18.0",
37
37
  "@semantic-release/changelog": "6.0.3",
38
- "@semantic-release/commit-analyzer": "13.0.0",
38
+ "@semantic-release/commit-analyzer": "13.0.1",
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.2",
42
+ "@semantic-release/release-notes-generator": "14.0.3",
43
43
  "c8": "10.1.3",
44
44
  "codecov": "3.8.3",
45
45
  "eslint": "9.17.0",
46
46
  "jasmine": "5.5.0",
47
47
  "jasmine-spec-reporter": "7.0.0",
48
- "semantic-release": "24.2.0"
48
+ "semantic-release": "24.2.1"
49
49
  },
50
50
  "engines": {
51
51
  "node": "18 || 20 || 22"
package/src/APNS.js CHANGED
@@ -151,7 +151,7 @@ export class APNS {
151
151
  static _createProvider(apnsArgs) {
152
152
  // if using certificate, then topic must be defined
153
153
  if (!APNS._validateAPNArgs(apnsArgs)) {
154
- throw new Parse.Error(Parse.Error.PUSH_MISCONFIGURED, 'topic is mssing for %j', apnsArgs);
154
+ throw new Parse.Error(Parse.Error.PUSH_MISCONFIGURED, 'topic is missing for %j', apnsArgs);
155
155
  }
156
156
 
157
157
  const provider = new apn.Provider(apnsArgs);
@@ -213,6 +213,16 @@ export class APNS {
213
213
  case 'threadId':
214
214
  notification.setThreadId(coreData.threadId);
215
215
  break;
216
+ case 'id':
217
+ case 'collapseId':
218
+ case 'channelId':
219
+ case 'requestId':
220
+ case 'pushType':
221
+ case 'topic':
222
+ case 'expiry':
223
+ case 'priority':
224
+ // Header information is skipped and added later.
225
+ break;
216
226
  default:
217
227
  payload[key] = coreData[key];
218
228
  break;
@@ -221,21 +231,53 @@ export class APNS {
221
231
 
222
232
  notification.payload = payload;
223
233
 
224
- notification.topic = headers.topic;
225
- notification.expiry = Math.round(headers.expirationTime / 1000);
226
- notification.collapseId = headers.collapseId;
234
+ // Update header information if necessary.
235
+ notification.id = coreData.id ?? headers.id;
236
+ notification.collapseId = coreData.collapseId ?? headers.collapseId;
237
+ notification.requestId = coreData.requestId ?? headers.requestId;
238
+ notification.channelId = coreData.channelId ?? headers.channelId;
227
239
  // set alert as default push type. If push type is not set notifications are not delivered to devices running iOS 13, watchOS 6 and later.
228
- notification.pushType = 'alert';
229
- if (headers.pushType) {
230
- notification.pushType = headers.pushType;
231
- }
232
- if (headers.priority) {
233
- // if headers priority is not set 'node-apn' defaults it to 5 which is min. required value for background pushes to launch the app in background.
234
- notification.priority = headers.priority
240
+ const pushType = coreData.pushType ?? headers.pushType ?? 'alert';
241
+ notification.pushType = pushType;
242
+ const topic = coreData.topic ?? APNS._determineTopic(headers.topic, pushType);
243
+ notification.topic = topic;
244
+ let expiry = notification.expiry;
245
+ if (headers.expirationTime) {
246
+ expiry = Math.round(headers.expirationTime / 1000);
235
247
  }
248
+ notification.expiry = coreData.expiry ?? expiry;
249
+ // if headers priority is not set 'node-apn' defaults it to notification's default value. Required value for background pushes to launch the app in background.
250
+ notification.priority = coreData.priority ?? headers.priority ?? notification.priority;
251
+
236
252
  return notification;
237
253
  }
238
254
 
255
+ /**
256
+ * Updates the topic based on the pushType.
257
+ *
258
+ * @param {String} topic The current topic to append additional information to for required provider
259
+ * @param {any} pushType The current push type of the notification
260
+ * @returns {String} Returns the updated topic
261
+ */
262
+ static _determineTopic(topic, pushType) {
263
+ switch(pushType) {
264
+ case 'location':
265
+ return topic + '.location-query';
266
+ case 'voip':
267
+ return topic + '.voip';
268
+ case 'complication':
269
+ return topic + '.complication';
270
+ case 'fileprovider':
271
+ return topic + '.pushkit.fileprovider';
272
+ case 'liveactivity':
273
+ return topic + '.push-type.liveactivity';
274
+ case 'pushtotalk':
275
+ return topic + '.voip-ptt';
276
+ default:
277
+ return topic;
278
+ }
279
+ }
280
+
239
281
  /**
240
282
  * Choose appropriate providers based on device appIdentifier.
241
283
  *
@@ -243,10 +285,6 @@ export class APNS {
243
285
  * @returns {Array} Returns Array with appropriate providers
244
286
  */
245
287
  _chooseProviders(appIdentifier) {
246
- // If the device we need to send to does not have appIdentifier, any provider could be a qualified provider
247
- /*if (!appIdentifier || appIdentifier === '') {
248
- return this.providers.map((provider) => provider.index);
249
- }*/
250
288
 
251
289
  // Otherwise we try to match the appIdentifier with topic on provider
252
290
  const qualifiedProviders = this.providers.filter((provider) => appIdentifier === provider.topic);
@@ -15,7 +15,7 @@ export default class ParsePushAdapter {
15
15
  supportsPushTracking = true;
16
16
 
17
17
  constructor(pushConfig = {}) {
18
- this.validPushTypes = ['ios', 'osx', 'tvos', 'android', 'fcm', 'web', 'expo'];
18
+ this.validPushTypes = ['ios', 'osx', 'tvos', 'watchos', 'android', 'fcm', 'web', 'expo'];
19
19
  this.senderMap = {};
20
20
  // used in PushController for Dashboard Features
21
21
  this.feature = {
@@ -32,6 +32,7 @@ export default class ParsePushAdapter {
32
32
  switch (pushType) {
33
33
  case 'ios':
34
34
  case 'tvos':
35
+ case 'watchos':
35
36
  case 'osx':
36
37
  if (pushConfig[pushType].hasOwnProperty('firebaseServiceAccount')) {
37
38
  this.senderMap[pushType] = new FCM(pushConfig[pushType], 'apple');