@firebase/messaging 0.11.0 → 0.12.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.
@@ -315,26 +315,26 @@ function getKey({ appConfig }) {
315
315
  * limitations under the License.
316
316
  */
317
317
  const ERROR_MAP = {
318
- ["missing-app-config-values" /* MISSING_APP_CONFIG_VALUES */]: 'Missing App configuration value: "{$valueName}"',
319
- ["only-available-in-window" /* AVAILABLE_IN_WINDOW */]: 'This method is available in a Window context.',
320
- ["only-available-in-sw" /* AVAILABLE_IN_SW */]: 'This method is available in a service worker context.',
321
- ["permission-default" /* PERMISSION_DEFAULT */]: 'The notification permission was not granted and dismissed instead.',
322
- ["permission-blocked" /* PERMISSION_BLOCKED */]: 'The notification permission was not granted and blocked instead.',
323
- ["unsupported-browser" /* UNSUPPORTED_BROWSER */]: "This browser doesn't support the API's required to use the Firebase SDK.",
324
- ["indexed-db-unsupported" /* INDEXED_DB_UNSUPPORTED */]: "This browser doesn't support indexedDb.open() (ex. Safari iFrame, Firefox Private Browsing, etc)",
325
- ["failed-service-worker-registration" /* FAILED_DEFAULT_REGISTRATION */]: 'We are unable to register the default service worker. {$browserErrorMessage}',
326
- ["token-subscribe-failed" /* TOKEN_SUBSCRIBE_FAILED */]: 'A problem occurred while subscribing the user to FCM: {$errorInfo}',
327
- ["token-subscribe-no-token" /* TOKEN_SUBSCRIBE_NO_TOKEN */]: 'FCM returned no token when subscribing the user to push.',
328
- ["token-unsubscribe-failed" /* TOKEN_UNSUBSCRIBE_FAILED */]: 'A problem occurred while unsubscribing the ' +
318
+ ["missing-app-config-values" /* ErrorCode.MISSING_APP_CONFIG_VALUES */]: 'Missing App configuration value: "{$valueName}"',
319
+ ["only-available-in-window" /* ErrorCode.AVAILABLE_IN_WINDOW */]: 'This method is available in a Window context.',
320
+ ["only-available-in-sw" /* ErrorCode.AVAILABLE_IN_SW */]: 'This method is available in a service worker context.',
321
+ ["permission-default" /* ErrorCode.PERMISSION_DEFAULT */]: 'The notification permission was not granted and dismissed instead.',
322
+ ["permission-blocked" /* ErrorCode.PERMISSION_BLOCKED */]: 'The notification permission was not granted and blocked instead.',
323
+ ["unsupported-browser" /* ErrorCode.UNSUPPORTED_BROWSER */]: "This browser doesn't support the API's required to use the Firebase SDK.",
324
+ ["indexed-db-unsupported" /* ErrorCode.INDEXED_DB_UNSUPPORTED */]: "This browser doesn't support indexedDb.open() (ex. Safari iFrame, Firefox Private Browsing, etc)",
325
+ ["failed-service-worker-registration" /* ErrorCode.FAILED_DEFAULT_REGISTRATION */]: 'We are unable to register the default service worker. {$browserErrorMessage}',
326
+ ["token-subscribe-failed" /* ErrorCode.TOKEN_SUBSCRIBE_FAILED */]: 'A problem occurred while subscribing the user to FCM: {$errorInfo}',
327
+ ["token-subscribe-no-token" /* ErrorCode.TOKEN_SUBSCRIBE_NO_TOKEN */]: 'FCM returned no token when subscribing the user to push.',
328
+ ["token-unsubscribe-failed" /* ErrorCode.TOKEN_UNSUBSCRIBE_FAILED */]: 'A problem occurred while unsubscribing the ' +
329
329
  'user from FCM: {$errorInfo}',
330
- ["token-update-failed" /* TOKEN_UPDATE_FAILED */]: 'A problem occurred while updating the user from FCM: {$errorInfo}',
331
- ["token-update-no-token" /* TOKEN_UPDATE_NO_TOKEN */]: 'FCM returned no token when updating the user to push.',
332
- ["use-sw-after-get-token" /* USE_SW_AFTER_GET_TOKEN */]: 'The useServiceWorker() method may only be called once and must be ' +
330
+ ["token-update-failed" /* ErrorCode.TOKEN_UPDATE_FAILED */]: 'A problem occurred while updating the user from FCM: {$errorInfo}',
331
+ ["token-update-no-token" /* ErrorCode.TOKEN_UPDATE_NO_TOKEN */]: 'FCM returned no token when updating the user to push.',
332
+ ["use-sw-after-get-token" /* ErrorCode.USE_SW_AFTER_GET_TOKEN */]: 'The useServiceWorker() method may only be called once and must be ' +
333
333
  'called before calling getToken() to ensure your service worker is used.',
334
- ["invalid-sw-registration" /* INVALID_SW_REGISTRATION */]: 'The input to useServiceWorker() must be a ServiceWorkerRegistration.',
335
- ["invalid-bg-handler" /* INVALID_BG_HANDLER */]: 'The input to setBackgroundMessageHandler() must be a function.',
336
- ["invalid-vapid-key" /* INVALID_VAPID_KEY */]: 'The public VAPID key must be a string.',
337
- ["use-vapid-key-after-get-token" /* USE_VAPID_KEY_AFTER_GET_TOKEN */]: 'The usePublicVapidKey() method may only be called once and must be ' +
334
+ ["invalid-sw-registration" /* ErrorCode.INVALID_SW_REGISTRATION */]: 'The input to useServiceWorker() must be a ServiceWorkerRegistration.',
335
+ ["invalid-bg-handler" /* ErrorCode.INVALID_BG_HANDLER */]: 'The input to setBackgroundMessageHandler() must be a function.',
336
+ ["invalid-vapid-key" /* ErrorCode.INVALID_VAPID_KEY */]: 'The public VAPID key must be a string.',
337
+ ["use-vapid-key-after-get-token" /* ErrorCode.USE_VAPID_KEY_AFTER_GET_TOKEN */]: 'The usePublicVapidKey() method may only be called once and must be ' +
338
338
  'called before calling getToken() to ensure your VAPID key is used.'
339
339
  };
340
340
  const ERROR_FACTORY = new ErrorFactory('messaging', 'Messaging', ERROR_MAP);
@@ -356,7 +356,6 @@ const ERROR_FACTORY = new ErrorFactory('messaging', 'Messaging', ERROR_MAP);
356
356
  * limitations under the License.
357
357
  */
358
358
  async function requestGetToken(firebaseDependencies, subscriptionOptions) {
359
- var _a;
360
359
  const headers = await getHeaders(firebaseDependencies);
361
360
  const body = getBody(subscriptionOptions);
362
361
  const subscribeOptions = {
@@ -370,23 +369,22 @@ async function requestGetToken(firebaseDependencies, subscriptionOptions) {
370
369
  responseData = await response.json();
371
370
  }
372
371
  catch (err) {
373
- throw ERROR_FACTORY.create("token-subscribe-failed" /* TOKEN_SUBSCRIBE_FAILED */, {
374
- errorInfo: (_a = err) === null || _a === void 0 ? void 0 : _a.toString()
372
+ throw ERROR_FACTORY.create("token-subscribe-failed" /* ErrorCode.TOKEN_SUBSCRIBE_FAILED */, {
373
+ errorInfo: err === null || err === void 0 ? void 0 : err.toString()
375
374
  });
376
375
  }
377
376
  if (responseData.error) {
378
377
  const message = responseData.error.message;
379
- throw ERROR_FACTORY.create("token-subscribe-failed" /* TOKEN_SUBSCRIBE_FAILED */, {
378
+ throw ERROR_FACTORY.create("token-subscribe-failed" /* ErrorCode.TOKEN_SUBSCRIBE_FAILED */, {
380
379
  errorInfo: message
381
380
  });
382
381
  }
383
382
  if (!responseData.token) {
384
- throw ERROR_FACTORY.create("token-subscribe-no-token" /* TOKEN_SUBSCRIBE_NO_TOKEN */);
383
+ throw ERROR_FACTORY.create("token-subscribe-no-token" /* ErrorCode.TOKEN_SUBSCRIBE_NO_TOKEN */);
385
384
  }
386
385
  return responseData.token;
387
386
  }
388
387
  async function requestUpdateToken(firebaseDependencies, tokenDetails) {
389
- var _a;
390
388
  const headers = await getHeaders(firebaseDependencies);
391
389
  const body = getBody(tokenDetails.subscriptionOptions);
392
390
  const updateOptions = {
@@ -400,23 +398,22 @@ async function requestUpdateToken(firebaseDependencies, tokenDetails) {
400
398
  responseData = await response.json();
401
399
  }
402
400
  catch (err) {
403
- throw ERROR_FACTORY.create("token-update-failed" /* TOKEN_UPDATE_FAILED */, {
404
- errorInfo: (_a = err) === null || _a === void 0 ? void 0 : _a.toString()
401
+ throw ERROR_FACTORY.create("token-update-failed" /* ErrorCode.TOKEN_UPDATE_FAILED */, {
402
+ errorInfo: err === null || err === void 0 ? void 0 : err.toString()
405
403
  });
406
404
  }
407
405
  if (responseData.error) {
408
406
  const message = responseData.error.message;
409
- throw ERROR_FACTORY.create("token-update-failed" /* TOKEN_UPDATE_FAILED */, {
407
+ throw ERROR_FACTORY.create("token-update-failed" /* ErrorCode.TOKEN_UPDATE_FAILED */, {
410
408
  errorInfo: message
411
409
  });
412
410
  }
413
411
  if (!responseData.token) {
414
- throw ERROR_FACTORY.create("token-update-no-token" /* TOKEN_UPDATE_NO_TOKEN */);
412
+ throw ERROR_FACTORY.create("token-update-no-token" /* ErrorCode.TOKEN_UPDATE_NO_TOKEN */);
415
413
  }
416
414
  return responseData.token;
417
415
  }
418
416
  async function requestDeleteToken(firebaseDependencies, token) {
419
- var _a;
420
417
  const headers = await getHeaders(firebaseDependencies);
421
418
  const unsubscribeOptions = {
422
419
  method: 'DELETE',
@@ -427,14 +424,14 @@ async function requestDeleteToken(firebaseDependencies, token) {
427
424
  const responseData = await response.json();
428
425
  if (responseData.error) {
429
426
  const message = responseData.error.message;
430
- throw ERROR_FACTORY.create("token-unsubscribe-failed" /* TOKEN_UNSUBSCRIBE_FAILED */, {
427
+ throw ERROR_FACTORY.create("token-unsubscribe-failed" /* ErrorCode.TOKEN_UNSUBSCRIBE_FAILED */, {
431
428
  errorInfo: message
432
429
  });
433
430
  }
434
431
  }
435
432
  catch (err) {
436
- throw ERROR_FACTORY.create("token-unsubscribe-failed" /* TOKEN_UNSUBSCRIBE_FAILED */, {
437
- errorInfo: (_a = err) === null || _a === void 0 ? void 0 : _a.toString()
433
+ throw ERROR_FACTORY.create("token-unsubscribe-failed" /* ErrorCode.TOKEN_UNSUBSCRIBE_FAILED */, {
434
+ errorInfo: err === null || err === void 0 ? void 0 : err.toString()
438
435
  });
439
436
  }
440
437
  }
@@ -757,7 +754,7 @@ function extractAppConfig(app) {
757
754
  };
758
755
  }
759
756
  function getMissingValueError(valueName) {
760
- return ERROR_FACTORY.create("missing-app-config-values" /* MISSING_APP_CONFIG_VALUES */, {
757
+ return ERROR_FACTORY.create("missing-app-config-values" /* ErrorCode.MISSING_APP_CONFIG_VALUES */, {
761
758
  valueName
762
759
  });
763
760
  }
@@ -816,7 +813,6 @@ class MessagingService {
816
813
  * limitations under the License.
817
814
  */
818
815
  async function registerDefaultSw(messaging) {
819
- var _a;
820
816
  try {
821
817
  messaging.swRegistration = await navigator.serviceWorker.register(DEFAULT_SW_PATH, {
822
818
  scope: DEFAULT_SW_SCOPE
@@ -831,8 +827,8 @@ async function registerDefaultSw(messaging) {
831
827
  });
832
828
  }
833
829
  catch (e) {
834
- throw ERROR_FACTORY.create("failed-service-worker-registration" /* FAILED_DEFAULT_REGISTRATION */, {
835
- browserErrorMessage: (_a = e) === null || _a === void 0 ? void 0 : _a.message
830
+ throw ERROR_FACTORY.create("failed-service-worker-registration" /* ErrorCode.FAILED_DEFAULT_REGISTRATION */, {
831
+ browserErrorMessage: e === null || e === void 0 ? void 0 : e.message
836
832
  });
837
833
  }
838
834
  }
@@ -861,7 +857,7 @@ async function updateSwReg(messaging, swRegistration) {
861
857
  return;
862
858
  }
863
859
  if (!(swRegistration instanceof ServiceWorkerRegistration)) {
864
- throw ERROR_FACTORY.create("invalid-sw-registration" /* INVALID_SW_REGISTRATION */);
860
+ throw ERROR_FACTORY.create("invalid-sw-registration" /* ErrorCode.INVALID_SW_REGISTRATION */);
865
861
  }
866
862
  messaging.swRegistration = swRegistration;
867
863
  }
@@ -909,13 +905,13 @@ async function updateVapidKey(messaging, vapidKey) {
909
905
  */
910
906
  async function getToken$1(messaging, options) {
911
907
  if (!navigator) {
912
- throw ERROR_FACTORY.create("only-available-in-window" /* AVAILABLE_IN_WINDOW */);
908
+ throw ERROR_FACTORY.create("only-available-in-window" /* ErrorCode.AVAILABLE_IN_WINDOW */);
913
909
  }
914
910
  if (Notification.permission === 'default') {
915
911
  await Notification.requestPermission();
916
912
  }
917
913
  if (Notification.permission !== 'granted') {
918
- throw ERROR_FACTORY.create("permission-blocked" /* PERMISSION_BLOCKED */);
914
+ throw ERROR_FACTORY.create("permission-blocked" /* ErrorCode.PERMISSION_BLOCKED */);
919
915
  }
920
916
  await updateVapidKey(messaging, options === null || options === void 0 ? void 0 : options.vapidKey);
921
917
  await updateSwReg(messaging, options === null || options === void 0 ? void 0 : options.serviceWorkerRegistration);
@@ -1000,7 +996,7 @@ async function messageEventListener(messaging, event) {
1000
996
  }
1001
997
 
1002
998
  const name = "@firebase/messaging";
1003
- const version = "0.11.0";
999
+ const version = "0.12.0";
1004
1000
 
1005
1001
  /**
1006
1002
  * @license
@@ -1033,8 +1029,8 @@ const WindowMessagingInternalFactory = (container) => {
1033
1029
  return messagingInternal;
1034
1030
  };
1035
1031
  function registerMessagingInWindow() {
1036
- _registerComponent(new Component('messaging', WindowMessagingFactory, "PUBLIC" /* PUBLIC */));
1037
- _registerComponent(new Component('messaging-internal', WindowMessagingInternalFactory, "PRIVATE" /* PRIVATE */));
1032
+ _registerComponent(new Component('messaging', WindowMessagingFactory, "PUBLIC" /* ComponentType.PUBLIC */));
1033
+ _registerComponent(new Component('messaging-internal', WindowMessagingInternalFactory, "PRIVATE" /* ComponentType.PRIVATE */));
1038
1034
  registerVersion(name, version);
1039
1035
  // BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation
1040
1036
  registerVersion(name, version, 'esm2017');
@@ -1103,7 +1099,7 @@ async function isWindowSupported() {
1103
1099
  */
1104
1100
  async function deleteToken$1(messaging) {
1105
1101
  if (!navigator) {
1106
- throw ERROR_FACTORY.create("only-available-in-window" /* AVAILABLE_IN_WINDOW */);
1102
+ throw ERROR_FACTORY.create("only-available-in-window" /* ErrorCode.AVAILABLE_IN_WINDOW */);
1107
1103
  }
1108
1104
  if (!messaging.swRegistration) {
1109
1105
  await registerDefaultSw(messaging);
@@ -1129,7 +1125,7 @@ async function deleteToken$1(messaging) {
1129
1125
  */
1130
1126
  function onMessage$1(messaging, nextOrObserver) {
1131
1127
  if (!navigator) {
1132
- throw ERROR_FACTORY.create("only-available-in-window" /* AVAILABLE_IN_WINDOW */);
1128
+ throw ERROR_FACTORY.create("only-available-in-window" /* ErrorCode.AVAILABLE_IN_WINDOW */);
1133
1129
  }
1134
1130
  messaging.onMessageHandler = nextOrObserver;
1135
1131
  return () => {
@@ -1168,11 +1164,11 @@ function getMessagingInWindow(app = getApp()) {
1168
1164
  isWindowSupported().then(isSupported => {
1169
1165
  // If `isWindowSupported()` resolved, but returned false.
1170
1166
  if (!isSupported) {
1171
- throw ERROR_FACTORY.create("unsupported-browser" /* UNSUPPORTED_BROWSER */);
1167
+ throw ERROR_FACTORY.create("unsupported-browser" /* ErrorCode.UNSUPPORTED_BROWSER */);
1172
1168
  }
1173
1169
  }, _ => {
1174
1170
  // If `isWindowSupported()` rejected.
1175
- throw ERROR_FACTORY.create("indexed-db-unsupported" /* INDEXED_DB_UNSUPPORTED */);
1171
+ throw ERROR_FACTORY.create("indexed-db-unsupported" /* ErrorCode.INDEXED_DB_UNSUPPORTED */);
1176
1172
  });
1177
1173
  return _getProvider(getModularInstance(app), 'messaging').getImmediate();
1178
1174
  }