@parse/push-adapter 6.9.0 → 6.9.1
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/package.json +1 -1
- package/src/APNS.js +53 -15
package/package.json
CHANGED
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
|
|
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
|
-
|
|
225
|
-
notification.
|
|
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
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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);
|