@firebase/messaging 0.12.21 → 0.12.22-canary.25b60fdaa

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/dist/index.sw.cjs CHANGED
@@ -129,7 +129,6 @@ async function migrateOldDatabase(senderId) {
129
129
  let tokenDetails = null;
130
130
  const db = await idb.openDB(OLD_DB_NAME, OLD_DB_VERSION, {
131
131
  upgrade: async (db, oldVersion, newVersion, upgradeTransaction) => {
132
- var _a;
133
132
  if (oldVersion < 2) {
134
133
  // Database too old, skip migration.
135
134
  return;
@@ -152,7 +151,7 @@ async function migrateOldDatabase(senderId) {
152
151
  }
153
152
  tokenDetails = {
154
153
  token: oldDetails.fcmToken,
155
- createTime: (_a = oldDetails.createTime) !== null && _a !== void 0 ? _a : Date.now(),
154
+ createTime: oldDetails.createTime ?? Date.now(),
156
155
  subscriptionOptions: {
157
156
  auth: oldDetails.auth,
158
157
  p256dh: oldDetails.p256dh,
@@ -373,7 +372,7 @@ async function requestGetToken(firebaseDependencies, subscriptionOptions) {
373
372
  }
374
373
  catch (err) {
375
374
  throw ERROR_FACTORY.create("token-subscribe-failed" /* ErrorCode.TOKEN_SUBSCRIBE_FAILED */, {
376
- errorInfo: err === null || err === void 0 ? void 0 : err.toString()
375
+ errorInfo: err?.toString()
377
376
  });
378
377
  }
379
378
  if (responseData.error) {
@@ -402,7 +401,7 @@ async function requestUpdateToken(firebaseDependencies, tokenDetails) {
402
401
  }
403
402
  catch (err) {
404
403
  throw ERROR_FACTORY.create("token-update-failed" /* ErrorCode.TOKEN_UPDATE_FAILED */, {
405
- errorInfo: err === null || err === void 0 ? void 0 : err.toString()
404
+ errorInfo: err?.toString()
406
405
  });
407
406
  }
408
407
  if (responseData.error) {
@@ -434,7 +433,7 @@ async function requestDeleteToken(firebaseDependencies, token) {
434
433
  }
435
434
  catch (err) {
436
435
  throw ERROR_FACTORY.create("token-unsubscribe-failed" /* ErrorCode.TOKEN_UNSUBSCRIBE_FAILED */, {
437
- errorInfo: err === null || err === void 0 ? void 0 : err.toString()
436
+ errorInfo: err?.toString()
438
437
  });
439
438
  }
440
439
  }
@@ -541,7 +540,11 @@ async function deleteTokenInternal(messaging) {
541
540
  async function updateToken(messaging, tokenDetails) {
542
541
  try {
543
542
  const updatedToken = await requestUpdateToken(messaging.firebaseDependencies, tokenDetails);
544
- const updatedTokenDetails = Object.assign(Object.assign({}, tokenDetails), { token: updatedToken, createTime: Date.now() });
543
+ const updatedTokenDetails = {
544
+ ...tokenDetails,
545
+ token: updatedToken,
546
+ createTime: Date.now()
547
+ };
545
548
  await dbSet(messaging.firebaseDependencies, updatedTokenDetails);
546
549
  return updatedToken;
547
550
  }
@@ -643,19 +646,19 @@ function propagateDataPayload(payload, messagePayloadInternal) {
643
646
  payload.data = messagePayloadInternal.data;
644
647
  }
645
648
  function propagateFcmOptions(payload, messagePayloadInternal) {
646
- var _a, _b, _c, _d, _e;
647
649
  // fcmOptions.link value is written into notification.click_action. see more in b/232072111
648
650
  if (!messagePayloadInternal.fcmOptions &&
649
- !((_a = messagePayloadInternal.notification) === null || _a === void 0 ? void 0 : _a.click_action)) {
651
+ !messagePayloadInternal.notification?.click_action) {
650
652
  return;
651
653
  }
652
654
  payload.fcmOptions = {};
653
- const link = (_c = (_b = messagePayloadInternal.fcmOptions) === null || _b === void 0 ? void 0 : _b.link) !== null && _c !== void 0 ? _c : (_d = messagePayloadInternal.notification) === null || _d === void 0 ? void 0 : _d.click_action;
655
+ const link = messagePayloadInternal.fcmOptions?.link ??
656
+ messagePayloadInternal.notification?.click_action;
654
657
  if (!!link) {
655
658
  payload.fcmOptions.link = link;
656
659
  }
657
660
  // eslint-disable-next-line camelcase
658
- const analyticsLabel = (_e = messagePayloadInternal.fcmOptions) === null || _e === void 0 ? void 0 : _e.analytics_label;
661
+ const analyticsLabel = messagePayloadInternal.fcmOptions?.analytics_label;
659
662
  if (!!analyticsLabel) {
660
663
  payload.fcmOptions.analyticsLabel = analyticsLabel;
661
664
  }
@@ -727,7 +730,6 @@ async function stageLog(messaging, internalPayload) {
727
730
  createAndEnqueueLogEvent(messaging, fcmEvent, internalPayload.productId);
728
731
  }
729
732
  function createFcmEvent(internalPayload, fid) {
730
- var _a, _b;
731
733
  const fcmEvent = {};
732
734
  /* eslint-disable camelcase */
733
735
  // some fields should always be non-null. Still check to ensure.
@@ -750,8 +752,8 @@ function createFcmEvent(internalPayload, fid) {
750
752
  fcmEvent.collapse_key = internalPayload.collapse_key;
751
753
  }
752
754
  fcmEvent.event = EVENT_MESSAGE_DELIVERED.toString();
753
- if (!!((_a = internalPayload.fcmOptions) === null || _a === void 0 ? void 0 : _a.analytics_label)) {
754
- fcmEvent.analytics_label = (_b = internalPayload.fcmOptions) === null || _b === void 0 ? void 0 : _b.analytics_label;
755
+ if (!!internalPayload.fcmOptions?.analytics_label) {
756
+ fcmEvent.analytics_label = internalPayload.fcmOptions?.analytics_label;
755
757
  }
756
758
  /* eslint-enable camelcase */
757
759
  return fcmEvent;
@@ -807,7 +809,6 @@ function _mergeStrings(s1, s2) {
807
809
  * limitations under the License.
808
810
  */
809
811
  async function onSubChange(event, messaging) {
810
- var _a, _b;
811
812
  const { newSubscription } = event;
812
813
  if (!newSubscription) {
813
814
  // Subscription revoked, delete token
@@ -817,7 +818,7 @@ async function onSubChange(event, messaging) {
817
818
  const tokenDetails = await dbGet(messaging.firebaseDependencies);
818
819
  await deleteTokenInternal(messaging);
819
820
  messaging.vapidKey =
820
- (_b = (_a = tokenDetails === null || tokenDetails === void 0 ? void 0 : tokenDetails.subscriptionOptions) === null || _a === void 0 ? void 0 : _a.vapidKey) !== null && _b !== void 0 ? _b : DEFAULT_VAPID_KEY;
821
+ tokenDetails?.subscriptionOptions?.vapidKey ?? DEFAULT_VAPID_KEY;
821
822
  await getTokenInternal(messaging);
822
823
  }
823
824
  async function onPush(event, messaging) {
@@ -853,8 +854,7 @@ async function onPush(event, messaging) {
853
854
  }
854
855
  }
855
856
  async function onNotificationClick(event) {
856
- var _a, _b;
857
- const internalPayload = (_b = (_a = event.notification) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b[FCM_MSG];
857
+ const internalPayload = event.notification?.data?.[FCM_MSG];
858
858
  if (!internalPayload) {
859
859
  return;
860
860
  }
@@ -896,7 +896,9 @@ async function onNotificationClick(event) {
896
896
  return client.postMessage(internalPayload);
897
897
  }
898
898
  function wrapInternalPayload(internalPayload) {
899
- const wrappedInternalPayload = Object.assign({}, internalPayload.notification);
899
+ const wrappedInternalPayload = {
900
+ ...internalPayload.notification
901
+ };
900
902
  // Put the message payload under FCM_MSG name so we can identify the notification as being an FCM
901
903
  // notification vs a notification from somewhere else (i.e. normal web push or developer generated
902
904
  // notification).
@@ -956,7 +958,6 @@ function getClientList() {
956
958
  });
957
959
  }
958
960
  function showNotification(notificationPayloadInternal) {
959
- var _a;
960
961
  // Note: Firefox does not support the maxActions property.
961
962
  // https://developer.mozilla.org/en-US/docs/Web/API/notification/maxActions
962
963
  const { actions } = notificationPayloadInternal;
@@ -965,12 +966,11 @@ function showNotification(notificationPayloadInternal) {
965
966
  console.warn(`This browser only supports ${maxActions} actions. The remaining actions will not be displayed.`);
966
967
  }
967
968
  return self.registration.showNotification(
968
- /* title= */ (_a = notificationPayloadInternal.title) !== null && _a !== void 0 ? _a : '', notificationPayloadInternal);
969
+ /* title= */ notificationPayloadInternal.title ?? '', notificationPayloadInternal);
969
970
  }
970
971
  function getLink(payload) {
971
- var _a, _b, _c;
972
972
  // eslint-disable-next-line camelcase
973
- const link = (_b = (_a = payload.fcmOptions) === null || _a === void 0 ? void 0 : _a.link) !== null && _b !== void 0 ? _b : (_c = payload.notification) === null || _c === void 0 ? void 0 : _c.click_action;
973
+ const link = payload.fcmOptions?.link ?? payload.notification?.click_action;
974
974
  if (link) {
975
975
  return link;
976
976
  }