diff --git a/keyserver/src/push/crypto.js b/keyserver/src/push/crypto.js --- a/keyserver/src/push/crypto.js +++ b/keyserver/src/push/crypto.js @@ -132,8 +132,8 @@ notificationSizeValidator?: apn.Notification => boolean, ): Promise< $ReadOnlyArray<{ - +cookieID: string, - +deviceToken: string, + +cryptoID: string, + +deliveryID: string, +notification: apn.Notification, +payloadSizeExceeded: boolean, +encryptedPayloadHash?: string, @@ -141,17 +141,17 @@ }>, > { const notificationPromises = devices.map( - async ({ cookieID, deviceToken, blobHolder }) => { + async ({ cryptoID, deliveryID, blobHolder }) => { const notif = await encryptAPNsNotification( encryptedNotifUtilsAPI, - cookieID, + cryptoID, senderDeviceDescriptor, notification, codeVersion, notificationSizeValidator, blobHolder, ); - return { cookieID, deviceToken, ...notif }; + return { cryptoID, deliveryID, ...notif }; }, ); return Promise.all(notificationPromises); @@ -165,23 +165,21 @@ codeVersion?: ?number, ): Promise< $ReadOnlyArray<{ - +cookieID: string, - +deviceToken: string, + +cryptoID: string, + +deliveryID: string, +notification: apn.Notification, }>, > { - const notificationPromises = devices.map( - async ({ deviceToken, cookieID }) => { - const { notification: notif } = await encryptAPNsNotification( - encryptedNotifUtilsAPI, - cookieID, - senderDeviceDescriptor, - notification, - codeVersion, - ); - return { deviceToken, cookieID, notification: notif }; - }, - ); + const notificationPromises = devices.map(async ({ deliveryID, cryptoID }) => { + const { notification: notif } = await encryptAPNsNotification( + encryptedNotifUtilsAPI, + cryptoID, + senderDeviceDescriptor, + notification, + codeVersion, + ); + return { cryptoID, deliveryID, notification: notif }; + }); return Promise.all(notificationPromises); } diff --git a/keyserver/src/push/rescind.js b/keyserver/src/push/rescind.js --- a/keyserver/src/push/rescind.js +++ b/keyserver/src/push/rescind.js @@ -152,8 +152,8 @@ if (delivery.platform === 'ios') { const devices = delivery.deviceTokens.map(deviceToken => ({ - deviceToken, - cookieID: deviceTokenToCookieID[deviceToken], + deliveryID: deviceToken, + cryptoID: deviceTokenToCookieID[deviceToken], })); const deliveryPromise = (async () => { const targetedNotifications = await prepareIOSNotification( @@ -175,8 +175,8 @@ deliveryPromises[id] = deliveryPromise; } else if (delivery.platform === 'android') { const devices = delivery.deviceTokens.map(deviceToken => ({ - deviceToken, - cookieID: deviceTokenToCookieID[deviceToken], + deliveryID: deviceToken, + cryptoID: deviceTokenToCookieID[deviceToken], })); const deliveryPromise = (async () => { const targetedNotifications = await prepareAndroidNotification( @@ -289,17 +289,17 @@ ) => Promise< $ReadOnlyArray<{ +notification: T, - +cookieID: string, - +deviceToken: string, + +cryptoID: string, + +deliveryID: string, +encryptionOrder?: number, }>, >, -): Promise<$ReadOnlyArray<{ +deviceToken: string, +notification: T }>> { +): Promise<$ReadOnlyArray<{ +deliveryID: string, +notification: T }>> { const shouldBeEncrypted = codeVersion && codeVersion >= 233; if (!shouldBeEncrypted) { - return devices.map(({ deviceToken }) => ({ + return devices.map(({ deliveryID }) => ({ notification, - deviceToken, + deliveryID, })); } const notifications = await encryptCallback( @@ -309,8 +309,8 @@ notification, codeVersion, ); - return notifications.map(({ deviceToken, notification: notif }) => ({ - deviceToken, + return notifications.map(({ deliveryID, notification: notif }) => ({ + deliveryID, notification: notif, })); } diff --git a/keyserver/src/push/send.js b/keyserver/src/push/send.js --- a/keyserver/src/push/send.js +++ b/keyserver/src/push/send.js @@ -901,8 +901,8 @@ const innerMostArray = innerMostArrayTmp; innerMostArray.push({ - cookieID: device.cookieID, - deviceToken: device.deviceToken, + cryptoID: device.cookieID, + deliveryID: device.deviceToken, }); } return byPlatform; @@ -1029,9 +1029,9 @@ ) ? copyWithMessageInfos : notification; - return devices.map(({ deviceToken }) => ({ + return devices.map(({ deliveryID }) => ({ notification: notificationToSend, - deviceToken, + deliveryID, })); } @@ -1047,9 +1047,9 @@ platformDetails.codeVersion, ); return macOSNotifsWithoutMessageInfos.map( - ({ notification: notif, deviceToken }) => ({ + ({ notification: notif, deliveryID }) => ({ notification: notif, - deviceToken, + deliveryID, }), ); } @@ -1065,21 +1065,21 @@ const devicesWithExcessiveSizeNoHolders = notifsWithMessageInfos .filter(({ payloadSizeExceeded }) => payloadSizeExceeded) - .map(({ deviceToken, cookieID }) => ({ - deviceToken, - cookieID, + .map(({ cryptoID, deliveryID }) => ({ + cryptoID, + deliveryID, })); if (devicesWithExcessiveSizeNoHolders.length === 0) { return notifsWithMessageInfos.map( ({ notification: notif, - deviceToken, + deliveryID, encryptedPayloadHash, encryptionOrder, }) => ({ notification: notif, - deviceToken, + deliveryID, encryptedPayloadHash, encryptionOrder, }), @@ -1138,12 +1138,12 @@ .map( ({ notification: notif, - deviceToken, + deliveryID, encryptedPayloadHash, encryptionOrder, }) => ({ notification: notif, - deviceToken, + deliveryID, encryptedPayloadHash, encryptionOrder, }), @@ -1152,12 +1152,12 @@ const targetedNotifsWithoutMessageInfos = notifsWithoutMessageInfos.map( ({ notification: notif, - deviceToken, + deliveryID, encryptedPayloadHash, encryptionOrder, }) => ({ notification: notif, - deviceToken, + deliveryID, encryptedPayloadHash, encryptionOrder, }), @@ -1266,7 +1266,7 @@ ); const iosID = targetedNotifications[0].notification.id; const deviceTokens = targetedNotifications.map( - ({ deviceToken }) => deviceToken, + ({ deliveryID }) => deliveryID, ); let delivery: APNsDelivery = { source, @@ -1286,7 +1286,7 @@ const deviceTokensToPayloadHash: { [string]: string } = {}; for (const targetedNotification of targetedNotifications) { if (targetedNotification.encryptedPayloadHash) { - deviceTokensToPayloadHash[targetedNotification.deviceToken] = + deviceTokensToPayloadHash[targetedNotification.deliveryID] = targetedNotification.encryptedPayloadHash; } } @@ -1337,7 +1337,7 @@ codeVersion, }); const deviceTokens = targetedNotifications.map( - ({ deviceToken }) => deviceToken, + ({ deliveryID }) => deliveryID, ); const androidIDs = response.fcmIDs ? response.fcmIDs : []; const delivery: AndroidDelivery = { @@ -1383,7 +1383,7 @@ const response = await webPush(targetedNotifications); const deviceTokens = targetedNotifications.map( - ({ deviceToken }) => deviceToken, + ({ deliveryID }) => deliveryID, ); const delivery: WebDelivery = { source, @@ -1424,7 +1424,7 @@ const response = await wnsPush(targetedNotifications); const deviceTokens = targetedNotifications.map( - ({ deviceToken }) => deviceToken, + ({ deliveryID }) => deliveryID, ); const wnsIDs = response.wnsIDs ?? []; const delivery: WNSDelivery = { @@ -1568,16 +1568,16 @@ codeVersion, ); targetedNotifications = notificationsArray.map( - ({ notification: notif, deviceToken, encryptionOrder }) => ({ + ({ notification: notif, deliveryID, encryptionOrder }) => ({ notification: notif, - deviceToken, + deliveryID, encryptionOrder, }), ); } else { - targetedNotifications = deviceInfos.map(({ deviceToken }) => ({ + targetedNotifications = deviceInfos.map(({ deliveryID }) => ({ notification, - deviceToken, + deliveryID, })); } return targetedNotifications.map(targetedNotification => ({ @@ -1620,17 +1620,17 @@ notification, ); targetedNotifications = notificationsArray.map( - ({ notification: notif, deviceToken, encryptionOrder }) => ({ + ({ notification: notif, deliveryID, encryptionOrder }) => ({ priority, notification: notif, - deviceToken, + deliveryID, encryptionOrder, }), ); } else { - targetedNotifications = deviceInfos.map(({ deviceToken }) => ({ + targetedNotifications = deviceInfos.map(({ deliveryID }) => ({ priority, - deviceToken, + deliveryID, notification, })); } @@ -1680,15 +1680,15 @@ codeVersion, ); targetedNotifications = notificationsArray.map( - ({ notification: notif, deviceToken, encryptionOrder }) => ({ + ({ notification: notif, deliveryID, encryptionOrder }) => ({ notification: notif, - deviceToken, + deliveryID, encryptionOrder, }), ); } else { - targetedNotifications = deviceInfos.map(({ deviceToken }) => ({ - deviceToken, + targetedNotifications = deviceInfos.map(({ deliveryID }) => ({ + deliveryID, notification, })); } diff --git a/keyserver/src/push/types.js b/keyserver/src/push/types.js --- a/keyserver/src/push/types.js +++ b/keyserver/src/push/types.js @@ -4,7 +4,7 @@ export type TargetedAPNsNotification = { +notification: apn.Notification, - +deviceToken: string, + +deliveryID: string, +encryptedPayloadHash?: string, +encryptionOrder?: number, }; diff --git a/keyserver/src/push/utils.js b/keyserver/src/push/utils.js --- a/keyserver/src/push/utils.js +++ b/keyserver/src/push/utils.js @@ -66,8 +66,8 @@ invariant(apnProvider, `keyserver/secrets/${pushProfile}.json should exist`); const results = await Promise.all( - targetedNotifications.map(({ notification, deviceToken }) => { - return apnProvider.send(notification, deviceToken); + targetedNotifications.map(({ notification, deliveryID }) => { + return apnProvider.send(notification, deliveryID); }), ); @@ -131,8 +131,8 @@ // avoid the multicast functionality and call it once per deviceToken. const results = await Promise.all( - targetedNotifications.map(({ notification, deviceToken, priority }) => { - return fcmSinglePush(fcmProvider, notification, deviceToken, { + targetedNotifications.map(({ notification, deliveryID, priority }) => { + return fcmSinglePush(fcmProvider, notification, deliveryID, { ...options, priority, }); @@ -151,7 +151,7 @@ ? error.error.errorInfo.code : undefined; if (errorCode && fcmTokenInvalidationErrors.has(errorCode)) { - invalidTokens.push(targetedNotifications[i].deviceToken); + invalidTokens.push(targetedNotifications[i].deliveryID); } } for (const id of pushResult.fcmIDs) { @@ -254,7 +254,7 @@ const pushResults: $ReadOnlyArray = await Promise.all( targetedNotifications.map( - async ({ notification, deviceToken: deviceTokenString }) => { + async ({ notification, deliveryID: deviceTokenString }) => { const deviceToken: PushSubscriptionJSON = JSON.parse(deviceTokenString); const notificationString = JSON.stringify(notification); try { @@ -270,7 +270,7 @@ const errors = []; const invalidTokens = []; const deviceTokens = targetedNotifications.map( - ({ deviceToken }) => deviceToken, + ({ deliveryID }) => deliveryID, ); for (let i = 0; i < pushResults.length; i++) { const pushResult = pushResults[i]; @@ -322,7 +322,7 @@ return await wnsSinglePush( token, notificationString, - targetedNotification.deviceToken, + targetedNotification.deliveryID, ); } catch (error) { return { error }; @@ -333,7 +333,7 @@ const notifIDs = []; const invalidTokens = []; const deviceTokens = targetedNotifications.map( - ({ deviceToken }) => deviceToken, + ({ deliveryID }) => deliveryID, ); for (let i = 0; i < pushResults.length; i++) { const pushResult = await pushResults[i]; diff --git a/lib/push/android-notif-creators.js b/lib/push/android-notif-creators.js --- a/lib/push/android-notif-creators.js +++ b/lib/push/android-notif-creators.js @@ -140,10 +140,10 @@ ? copyWithMessageInfos : notification; - return devices.map(({ deviceToken }) => ({ + return devices.map(({ deliveryID }) => ({ priority, notification: notificationToSend, - deviceToken, + deliveryID, })); } @@ -167,14 +167,14 @@ const devicesWithExcessiveSizeNoHolders = notifsWithMessageInfos .filter(({ payloadSizeExceeded }) => payloadSizeExceeded) - .map(({ cookieID, deviceToken }) => ({ cookieID, deviceToken })); + .map(({ cryptoID, deliveryID }) => ({ cryptoID, deliveryID })); if (devicesWithExcessiveSizeNoHolders.length === 0) { return notifsWithMessageInfos.map( - ({ notification: notif, deviceToken, encryptionOrder }) => ({ + ({ notification: notif, deliveryID, encryptionOrder }) => ({ priority, notification: notif, - deviceToken, + deliveryID, encryptionOrder, }), ); @@ -229,18 +229,18 @@ const targetedNotifsWithMessageInfos = notifsWithMessageInfos .filter(({ payloadSizeExceeded }) => !payloadSizeExceeded) - .map(({ notification: notif, deviceToken, encryptionOrder }) => ({ + .map(({ notification: notif, deliveryID, encryptionOrder }) => ({ priority, notification: notif, - deviceToken, + deliveryID, encryptionOrder, })); const targetedNotifsWithoutMessageInfos = notifsWithoutMessageInfos.map( - ({ notification: notif, deviceToken, encryptionOrder }) => ({ + ({ notification: notif, deliveryID, encryptionOrder }) => ({ priority, notification: notif, - deviceToken, + deliveryID, encryptionOrder, }), ); diff --git a/lib/push/crypto.js b/lib/push/crypto.js --- a/lib/push/crypto.js +++ b/lib/push/crypto.js @@ -281,24 +281,24 @@ ) => boolean, ): Promise< $ReadOnlyArray<{ - +cookieID: string, - +deviceToken: string, + +cryptoID: string, + +deliveryID: string, +notification: AndroidVisualNotification, +payloadSizeExceeded: boolean, +encryptionOrder?: number, }>, > { const notificationPromises = devices.map( - async ({ deviceToken, cookieID, blobHolder }) => { + async ({ deliveryID, cryptoID, blobHolder }) => { const notif = await encryptAndroidVisualNotification( encryptedNotifUtilsAPI, senderDeviceDescriptor, - cookieID, + cryptoID, notification, notificationSizeValidator, blobHolder, ); - return { deviceToken, cookieID, ...notif }; + return { deliveryID, cryptoID, ...notif }; }, ); return Promise.all(notificationPromises); @@ -311,23 +311,21 @@ notification: AndroidNotificationRescind | AndroidBadgeOnlyNotification, ): Promise< $ReadOnlyArray<{ - +cookieID: string, - +deviceToken: string, + +cryptoID: string, + +deliveryID: string, +notification: AndroidNotificationRescind | AndroidBadgeOnlyNotification, +encryptionOrder?: number, }>, > { - const notificationPromises = devices.map( - async ({ deviceToken, cookieID }) => { - const notif = await encryptAndroidSilentNotification( - encryptedNotifUtilsAPI, - cookieID, - senderDeviceDescriptor, - notification, - ); - return { deviceToken, cookieID, notification: notif }; - }, - ); + const notificationPromises = devices.map(async ({ deliveryID, cryptoID }) => { + const notif = await encryptAndroidSilentNotification( + encryptedNotifUtilsAPI, + cryptoID, + senderDeviceDescriptor, + notification, + ); + return { deliveryID, cryptoID, notification: notif }; + }); return Promise.all(notificationPromises); } @@ -338,22 +336,20 @@ notification: PlainTextWebNotification, ): Promise< $ReadOnlyArray<{ - +deviceToken: string, + +deliveryID: string, +notification: WebNotification, +encryptionOrder?: number, }>, > { - const notificationPromises = devices.map( - async ({ deviceToken, cookieID }) => { - const notif = await encryptWebNotification( - encryptedNotifUtilsAPI, - cookieID, - senderDeviceDescriptor, - notification, - ); - return { ...notif, deviceToken }; - }, - ); + const notificationPromises = devices.map(async ({ deliveryID, cryptoID }) => { + const notif = await encryptWebNotification( + encryptedNotifUtilsAPI, + cryptoID, + senderDeviceDescriptor, + notification, + ); + return { ...notif, deliveryID }; + }); return Promise.all(notificationPromises); } @@ -364,22 +360,20 @@ notification: PlainTextWNSNotification, ): Promise< $ReadOnlyArray<{ - +deviceToken: string, + +deliveryID: string, +notification: WNSNotification, +encryptionOrder?: number, }>, > { - const notificationPromises = devices.map( - async ({ deviceToken, cookieID }) => { - const notif = await encryptWNSNotification( - encryptedNotifUtilsAPI, - cookieID, - senderDeviceDescriptor, - notification, - ); - return { ...notif, deviceToken }; - }, - ); + const notificationPromises = devices.map(async ({ deliveryID, cryptoID }) => { + const notif = await encryptWNSNotification( + encryptedNotifUtilsAPI, + cryptoID, + senderDeviceDescriptor, + notification, + ); + return { ...notif, deliveryID }; + }); return Promise.all(notificationPromises); } diff --git a/lib/push/web-notif-creators.js b/lib/push/web-notif-creators.js --- a/lib/push/web-notif-creators.js +++ b/lib/push/web-notif-creators.js @@ -56,7 +56,7 @@ }); if (!shouldBeEncrypted) { - return devices.map(({ deviceToken }) => ({ deviceToken, notification })); + return devices.map(({ deliveryID }) => ({ deliveryID, notification })); } return prepareEncryptedWebNotifications( diff --git a/lib/push/wns-notif-creators.js b/lib/push/wns-notif-creators.js --- a/lib/push/wns-notif-creators.js +++ b/lib/push/wns-notif-creators.js @@ -61,8 +61,8 @@ }); if (!shouldBeEncrypted) { - return devices.map(({ deviceToken }) => ({ - deviceToken, + return devices.map(({ deliveryID }) => ({ + deliveryID, notification, })); } diff --git a/lib/types/notif-types.js b/lib/types/notif-types.js --- a/lib/types/notif-types.js +++ b/lib/types/notif-types.js @@ -171,25 +171,25 @@ export type TargetedAndroidNotification = $ReadOnly<{ ...AndroidNotificationWithPriority, - +deviceToken: string, + +deliveryID: string, +encryptionOrder?: number, }>; export type TargetedWebNotification = { +notification: WebNotification, - +deviceToken: string, + +deliveryID: string, +encryptionOrder?: number, }; export type TargetedWNSNotification = { +notification: WNSNotification, - +deviceToken: string, + +deliveryID: string, +encryptionOrder?: number, }; export type NotificationTargetDevice = { - +cookieID: string, - +deviceToken: string, + +cryptoID: string, + +deliveryID: string, +blobHolder?: string, };