@firebase/messaging 0.11.0 → 0.12.0-canary.41549bb86
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/CHANGELOG.md +14 -0
- package/dist/esm/index.esm.js +78 -82
- package/dist/esm/index.esm.js.map +1 -1
- package/dist/esm/index.esm2017.js +42 -46
- package/dist/esm/index.esm2017.js.map +1 -1
- package/dist/esm/src/testing/fakes/service-worker.d.ts +0 -1
- package/dist/esm/src/util/sw-types.d.ts +1 -1
- package/dist/index.cjs.js +78 -82
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.sw.cjs +64 -67
- package/dist/index.sw.cjs.map +1 -1
- package/dist/index.sw.esm2017.js +34 -37
- package/dist/index.sw.esm2017.js.map +1 -1
- package/dist/src/testing/fakes/service-worker.d.ts +0 -1
- package/dist/src/util/sw-types.d.ts +1 -1
- package/package.json +8 -8
package/dist/index.sw.cjs
CHANGED
|
@@ -77,7 +77,7 @@ var MessageType;
|
|
|
77
77
|
*/
|
|
78
78
|
function arrayToBase64(array) {
|
|
79
79
|
var uint8Array = new Uint8Array(array);
|
|
80
|
-
var base64String = btoa(String.fromCharCode.apply(String, tslib.__spreadArray([], tslib.__read(uint8Array))));
|
|
80
|
+
var base64String = btoa(String.fromCharCode.apply(String, tslib.__spreadArray([], tslib.__read(uint8Array), false)));
|
|
81
81
|
return base64String.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
|
|
82
82
|
}
|
|
83
83
|
function base64ToArray(base64String) {
|
|
@@ -392,26 +392,26 @@ function getKey(_a) {
|
|
|
392
392
|
*/
|
|
393
393
|
var _a;
|
|
394
394
|
var ERROR_MAP = (_a = {},
|
|
395
|
-
_a["missing-app-config-values" /* MISSING_APP_CONFIG_VALUES */] = 'Missing App configuration value: "{$valueName}"',
|
|
396
|
-
_a["only-available-in-window" /* AVAILABLE_IN_WINDOW */] = 'This method is available in a Window context.',
|
|
397
|
-
_a["only-available-in-sw" /* AVAILABLE_IN_SW */] = 'This method is available in a service worker context.',
|
|
398
|
-
_a["permission-default" /* PERMISSION_DEFAULT */] = 'The notification permission was not granted and dismissed instead.',
|
|
399
|
-
_a["permission-blocked" /* PERMISSION_BLOCKED */] = 'The notification permission was not granted and blocked instead.',
|
|
400
|
-
_a["unsupported-browser" /* UNSUPPORTED_BROWSER */] = "This browser doesn't support the API's required to use the Firebase SDK.",
|
|
401
|
-
_a["indexed-db-unsupported" /* INDEXED_DB_UNSUPPORTED */] = "This browser doesn't support indexedDb.open() (ex. Safari iFrame, Firefox Private Browsing, etc)",
|
|
402
|
-
_a["failed-service-worker-registration" /* FAILED_DEFAULT_REGISTRATION */] = 'We are unable to register the default service worker. {$browserErrorMessage}',
|
|
403
|
-
_a["token-subscribe-failed" /* TOKEN_SUBSCRIBE_FAILED */] = 'A problem occurred while subscribing the user to FCM: {$errorInfo}',
|
|
404
|
-
_a["token-subscribe-no-token" /* TOKEN_SUBSCRIBE_NO_TOKEN */] = 'FCM returned no token when subscribing the user to push.',
|
|
405
|
-
_a["token-unsubscribe-failed" /* TOKEN_UNSUBSCRIBE_FAILED */] = 'A problem occurred while unsubscribing the ' +
|
|
395
|
+
_a["missing-app-config-values" /* ErrorCode.MISSING_APP_CONFIG_VALUES */] = 'Missing App configuration value: "{$valueName}"',
|
|
396
|
+
_a["only-available-in-window" /* ErrorCode.AVAILABLE_IN_WINDOW */] = 'This method is available in a Window context.',
|
|
397
|
+
_a["only-available-in-sw" /* ErrorCode.AVAILABLE_IN_SW */] = 'This method is available in a service worker context.',
|
|
398
|
+
_a["permission-default" /* ErrorCode.PERMISSION_DEFAULT */] = 'The notification permission was not granted and dismissed instead.',
|
|
399
|
+
_a["permission-blocked" /* ErrorCode.PERMISSION_BLOCKED */] = 'The notification permission was not granted and blocked instead.',
|
|
400
|
+
_a["unsupported-browser" /* ErrorCode.UNSUPPORTED_BROWSER */] = "This browser doesn't support the API's required to use the Firebase SDK.",
|
|
401
|
+
_a["indexed-db-unsupported" /* ErrorCode.INDEXED_DB_UNSUPPORTED */] = "This browser doesn't support indexedDb.open() (ex. Safari iFrame, Firefox Private Browsing, etc)",
|
|
402
|
+
_a["failed-service-worker-registration" /* ErrorCode.FAILED_DEFAULT_REGISTRATION */] = 'We are unable to register the default service worker. {$browserErrorMessage}',
|
|
403
|
+
_a["token-subscribe-failed" /* ErrorCode.TOKEN_SUBSCRIBE_FAILED */] = 'A problem occurred while subscribing the user to FCM: {$errorInfo}',
|
|
404
|
+
_a["token-subscribe-no-token" /* ErrorCode.TOKEN_SUBSCRIBE_NO_TOKEN */] = 'FCM returned no token when subscribing the user to push.',
|
|
405
|
+
_a["token-unsubscribe-failed" /* ErrorCode.TOKEN_UNSUBSCRIBE_FAILED */] = 'A problem occurred while unsubscribing the ' +
|
|
406
406
|
'user from FCM: {$errorInfo}',
|
|
407
|
-
_a["token-update-failed" /* TOKEN_UPDATE_FAILED */] = 'A problem occurred while updating the user from FCM: {$errorInfo}',
|
|
408
|
-
_a["token-update-no-token" /* TOKEN_UPDATE_NO_TOKEN */] = 'FCM returned no token when updating the user to push.',
|
|
409
|
-
_a["use-sw-after-get-token" /* USE_SW_AFTER_GET_TOKEN */] = 'The useServiceWorker() method may only be called once and must be ' +
|
|
407
|
+
_a["token-update-failed" /* ErrorCode.TOKEN_UPDATE_FAILED */] = 'A problem occurred while updating the user from FCM: {$errorInfo}',
|
|
408
|
+
_a["token-update-no-token" /* ErrorCode.TOKEN_UPDATE_NO_TOKEN */] = 'FCM returned no token when updating the user to push.',
|
|
409
|
+
_a["use-sw-after-get-token" /* ErrorCode.USE_SW_AFTER_GET_TOKEN */] = 'The useServiceWorker() method may only be called once and must be ' +
|
|
410
410
|
'called before calling getToken() to ensure your service worker is used.',
|
|
411
|
-
_a["invalid-sw-registration" /* INVALID_SW_REGISTRATION */] = 'The input to useServiceWorker() must be a ServiceWorkerRegistration.',
|
|
412
|
-
_a["invalid-bg-handler" /* INVALID_BG_HANDLER */] = 'The input to setBackgroundMessageHandler() must be a function.',
|
|
413
|
-
_a["invalid-vapid-key" /* INVALID_VAPID_KEY */] = 'The public VAPID key must be a string.',
|
|
414
|
-
_a["use-vapid-key-after-get-token" /* USE_VAPID_KEY_AFTER_GET_TOKEN */] = 'The usePublicVapidKey() method may only be called once and must be ' +
|
|
411
|
+
_a["invalid-sw-registration" /* ErrorCode.INVALID_SW_REGISTRATION */] = 'The input to useServiceWorker() must be a ServiceWorkerRegistration.',
|
|
412
|
+
_a["invalid-bg-handler" /* ErrorCode.INVALID_BG_HANDLER */] = 'The input to setBackgroundMessageHandler() must be a function.',
|
|
413
|
+
_a["invalid-vapid-key" /* ErrorCode.INVALID_VAPID_KEY */] = 'The public VAPID key must be a string.',
|
|
414
|
+
_a["use-vapid-key-after-get-token" /* ErrorCode.USE_VAPID_KEY_AFTER_GET_TOKEN */] = 'The usePublicVapidKey() method may only be called once and must be ' +
|
|
415
415
|
'called before calling getToken() to ensure your VAPID key is used.',
|
|
416
416
|
_a);
|
|
417
417
|
var ERROR_FACTORY = new util.ErrorFactory('messaging', 'Messaging', ERROR_MAP);
|
|
@@ -433,44 +433,43 @@ var ERROR_FACTORY = new util.ErrorFactory('messaging', 'Messaging', ERROR_MAP);
|
|
|
433
433
|
* limitations under the License.
|
|
434
434
|
*/
|
|
435
435
|
function requestGetToken(firebaseDependencies, subscriptionOptions) {
|
|
436
|
-
var _a;
|
|
437
436
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
438
437
|
var headers, body, subscribeOptions, responseData, response, err_1, message;
|
|
439
|
-
return tslib.__generator(this, function (
|
|
440
|
-
switch (
|
|
438
|
+
return tslib.__generator(this, function (_a) {
|
|
439
|
+
switch (_a.label) {
|
|
441
440
|
case 0: return [4 /*yield*/, getHeaders(firebaseDependencies)];
|
|
442
441
|
case 1:
|
|
443
|
-
headers =
|
|
442
|
+
headers = _a.sent();
|
|
444
443
|
body = getBody(subscriptionOptions);
|
|
445
444
|
subscribeOptions = {
|
|
446
445
|
method: 'POST',
|
|
447
446
|
headers: headers,
|
|
448
447
|
body: JSON.stringify(body)
|
|
449
448
|
};
|
|
450
|
-
|
|
449
|
+
_a.label = 2;
|
|
451
450
|
case 2:
|
|
452
|
-
|
|
451
|
+
_a.trys.push([2, 5, , 6]);
|
|
453
452
|
return [4 /*yield*/, fetch(getEndpoint(firebaseDependencies.appConfig), subscribeOptions)];
|
|
454
453
|
case 3:
|
|
455
|
-
response =
|
|
454
|
+
response = _a.sent();
|
|
456
455
|
return [4 /*yield*/, response.json()];
|
|
457
456
|
case 4:
|
|
458
|
-
responseData =
|
|
457
|
+
responseData = _a.sent();
|
|
459
458
|
return [3 /*break*/, 6];
|
|
460
459
|
case 5:
|
|
461
|
-
err_1 =
|
|
462
|
-
throw ERROR_FACTORY.create("token-subscribe-failed" /* TOKEN_SUBSCRIBE_FAILED */, {
|
|
463
|
-
errorInfo:
|
|
460
|
+
err_1 = _a.sent();
|
|
461
|
+
throw ERROR_FACTORY.create("token-subscribe-failed" /* ErrorCode.TOKEN_SUBSCRIBE_FAILED */, {
|
|
462
|
+
errorInfo: err_1 === null || err_1 === void 0 ? void 0 : err_1.toString()
|
|
464
463
|
});
|
|
465
464
|
case 6:
|
|
466
465
|
if (responseData.error) {
|
|
467
466
|
message = responseData.error.message;
|
|
468
|
-
throw ERROR_FACTORY.create("token-subscribe-failed" /* TOKEN_SUBSCRIBE_FAILED */, {
|
|
467
|
+
throw ERROR_FACTORY.create("token-subscribe-failed" /* ErrorCode.TOKEN_SUBSCRIBE_FAILED */, {
|
|
469
468
|
errorInfo: message
|
|
470
469
|
});
|
|
471
470
|
}
|
|
472
471
|
if (!responseData.token) {
|
|
473
|
-
throw ERROR_FACTORY.create("token-subscribe-no-token" /* TOKEN_SUBSCRIBE_NO_TOKEN */);
|
|
472
|
+
throw ERROR_FACTORY.create("token-subscribe-no-token" /* ErrorCode.TOKEN_SUBSCRIBE_NO_TOKEN */);
|
|
474
473
|
}
|
|
475
474
|
return [2 /*return*/, responseData.token];
|
|
476
475
|
}
|
|
@@ -478,44 +477,43 @@ function requestGetToken(firebaseDependencies, subscriptionOptions) {
|
|
|
478
477
|
});
|
|
479
478
|
}
|
|
480
479
|
function requestUpdateToken(firebaseDependencies, tokenDetails) {
|
|
481
|
-
var _a;
|
|
482
480
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
483
481
|
var headers, body, updateOptions, responseData, response, err_2, message;
|
|
484
|
-
return tslib.__generator(this, function (
|
|
485
|
-
switch (
|
|
482
|
+
return tslib.__generator(this, function (_a) {
|
|
483
|
+
switch (_a.label) {
|
|
486
484
|
case 0: return [4 /*yield*/, getHeaders(firebaseDependencies)];
|
|
487
485
|
case 1:
|
|
488
|
-
headers =
|
|
486
|
+
headers = _a.sent();
|
|
489
487
|
body = getBody(tokenDetails.subscriptionOptions);
|
|
490
488
|
updateOptions = {
|
|
491
489
|
method: 'PATCH',
|
|
492
490
|
headers: headers,
|
|
493
491
|
body: JSON.stringify(body)
|
|
494
492
|
};
|
|
495
|
-
|
|
493
|
+
_a.label = 2;
|
|
496
494
|
case 2:
|
|
497
|
-
|
|
498
|
-
return [4 /*yield*/, fetch(getEndpoint(firebaseDependencies.appConfig)
|
|
495
|
+
_a.trys.push([2, 5, , 6]);
|
|
496
|
+
return [4 /*yield*/, fetch("".concat(getEndpoint(firebaseDependencies.appConfig), "/").concat(tokenDetails.token), updateOptions)];
|
|
499
497
|
case 3:
|
|
500
|
-
response =
|
|
498
|
+
response = _a.sent();
|
|
501
499
|
return [4 /*yield*/, response.json()];
|
|
502
500
|
case 4:
|
|
503
|
-
responseData =
|
|
501
|
+
responseData = _a.sent();
|
|
504
502
|
return [3 /*break*/, 6];
|
|
505
503
|
case 5:
|
|
506
|
-
err_2 =
|
|
507
|
-
throw ERROR_FACTORY.create("token-update-failed" /* TOKEN_UPDATE_FAILED */, {
|
|
508
|
-
errorInfo:
|
|
504
|
+
err_2 = _a.sent();
|
|
505
|
+
throw ERROR_FACTORY.create("token-update-failed" /* ErrorCode.TOKEN_UPDATE_FAILED */, {
|
|
506
|
+
errorInfo: err_2 === null || err_2 === void 0 ? void 0 : err_2.toString()
|
|
509
507
|
});
|
|
510
508
|
case 6:
|
|
511
509
|
if (responseData.error) {
|
|
512
510
|
message = responseData.error.message;
|
|
513
|
-
throw ERROR_FACTORY.create("token-update-failed" /* TOKEN_UPDATE_FAILED */, {
|
|
511
|
+
throw ERROR_FACTORY.create("token-update-failed" /* ErrorCode.TOKEN_UPDATE_FAILED */, {
|
|
514
512
|
errorInfo: message
|
|
515
513
|
});
|
|
516
514
|
}
|
|
517
515
|
if (!responseData.token) {
|
|
518
|
-
throw ERROR_FACTORY.create("token-update-no-token" /* TOKEN_UPDATE_NO_TOKEN */);
|
|
516
|
+
throw ERROR_FACTORY.create("token-update-no-token" /* ErrorCode.TOKEN_UPDATE_NO_TOKEN */);
|
|
519
517
|
}
|
|
520
518
|
return [2 /*return*/, responseData.token];
|
|
521
519
|
}
|
|
@@ -523,38 +521,37 @@ function requestUpdateToken(firebaseDependencies, tokenDetails) {
|
|
|
523
521
|
});
|
|
524
522
|
}
|
|
525
523
|
function requestDeleteToken(firebaseDependencies, token) {
|
|
526
|
-
var _a;
|
|
527
524
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
528
525
|
var headers, unsubscribeOptions, response, responseData, message, err_3;
|
|
529
|
-
return tslib.__generator(this, function (
|
|
530
|
-
switch (
|
|
526
|
+
return tslib.__generator(this, function (_a) {
|
|
527
|
+
switch (_a.label) {
|
|
531
528
|
case 0: return [4 /*yield*/, getHeaders(firebaseDependencies)];
|
|
532
529
|
case 1:
|
|
533
|
-
headers =
|
|
530
|
+
headers = _a.sent();
|
|
534
531
|
unsubscribeOptions = {
|
|
535
532
|
method: 'DELETE',
|
|
536
533
|
headers: headers
|
|
537
534
|
};
|
|
538
|
-
|
|
535
|
+
_a.label = 2;
|
|
539
536
|
case 2:
|
|
540
|
-
|
|
541
|
-
return [4 /*yield*/, fetch(getEndpoint(firebaseDependencies.appConfig)
|
|
537
|
+
_a.trys.push([2, 5, , 6]);
|
|
538
|
+
return [4 /*yield*/, fetch("".concat(getEndpoint(firebaseDependencies.appConfig), "/").concat(token), unsubscribeOptions)];
|
|
542
539
|
case 3:
|
|
543
|
-
response =
|
|
540
|
+
response = _a.sent();
|
|
544
541
|
return [4 /*yield*/, response.json()];
|
|
545
542
|
case 4:
|
|
546
|
-
responseData =
|
|
543
|
+
responseData = _a.sent();
|
|
547
544
|
if (responseData.error) {
|
|
548
545
|
message = responseData.error.message;
|
|
549
|
-
throw ERROR_FACTORY.create("token-unsubscribe-failed" /* TOKEN_UNSUBSCRIBE_FAILED */, {
|
|
546
|
+
throw ERROR_FACTORY.create("token-unsubscribe-failed" /* ErrorCode.TOKEN_UNSUBSCRIBE_FAILED */, {
|
|
550
547
|
errorInfo: message
|
|
551
548
|
});
|
|
552
549
|
}
|
|
553
550
|
return [3 /*break*/, 6];
|
|
554
551
|
case 5:
|
|
555
|
-
err_3 =
|
|
556
|
-
throw ERROR_FACTORY.create("token-unsubscribe-failed" /* TOKEN_UNSUBSCRIBE_FAILED */, {
|
|
557
|
-
errorInfo:
|
|
552
|
+
err_3 = _a.sent();
|
|
553
|
+
throw ERROR_FACTORY.create("token-unsubscribe-failed" /* ErrorCode.TOKEN_UNSUBSCRIBE_FAILED */, {
|
|
554
|
+
errorInfo: err_3 === null || err_3 === void 0 ? void 0 : err_3.toString()
|
|
558
555
|
});
|
|
559
556
|
case 6: return [2 /*return*/];
|
|
560
557
|
}
|
|
@@ -563,7 +560,7 @@ function requestDeleteToken(firebaseDependencies, token) {
|
|
|
563
560
|
}
|
|
564
561
|
function getEndpoint(_a) {
|
|
565
562
|
var projectId = _a.projectId;
|
|
566
|
-
return ENDPOINT
|
|
563
|
+
return "".concat(ENDPOINT, "/projects/").concat(projectId, "/registrations");
|
|
567
564
|
}
|
|
568
565
|
function getHeaders(_a) {
|
|
569
566
|
var appConfig = _a.appConfig, installations = _a.installations;
|
|
@@ -578,7 +575,7 @@ function getHeaders(_a) {
|
|
|
578
575
|
'Content-Type': 'application/json',
|
|
579
576
|
Accept: 'application/json',
|
|
580
577
|
'x-goog-api-key': appConfig.apiKey,
|
|
581
|
-
'x-goog-firebase-installations-auth': "FIS "
|
|
578
|
+
'x-goog-firebase-installations-auth': "FIS ".concat(authToken)
|
|
582
579
|
})];
|
|
583
580
|
}
|
|
584
581
|
});
|
|
@@ -1243,7 +1240,7 @@ function showNotification(notificationPayloadInternal) {
|
|
|
1243
1240
|
var actions = notificationPayloadInternal.actions;
|
|
1244
1241
|
var maxActions = Notification.maxActions;
|
|
1245
1242
|
if (actions && maxActions && actions.length > maxActions) {
|
|
1246
|
-
console.warn("This browser only supports "
|
|
1243
|
+
console.warn("This browser only supports ".concat(maxActions, " actions. The remaining actions will not be displayed."));
|
|
1247
1244
|
}
|
|
1248
1245
|
return self.registration.showNotification(
|
|
1249
1246
|
/* title= */ (_a = notificationPayloadInternal.title) !== null && _a !== void 0 ? _a : '', notificationPayloadInternal);
|
|
@@ -1320,7 +1317,7 @@ function extractAppConfig(app) {
|
|
|
1320
1317
|
};
|
|
1321
1318
|
}
|
|
1322
1319
|
function getMissingValueError(valueName) {
|
|
1323
|
-
return ERROR_FACTORY.create("missing-app-config-values" /* MISSING_APP_CONFIG_VALUES */, {
|
|
1320
|
+
return ERROR_FACTORY.create("missing-app-config-values" /* ErrorCode.MISSING_APP_CONFIG_VALUES */, {
|
|
1324
1321
|
valueName: valueName
|
|
1325
1322
|
});
|
|
1326
1323
|
}
|
|
@@ -1398,7 +1395,7 @@ var SwMessagingFactory = function (container) {
|
|
|
1398
1395
|
* `messaging-compat` and component with the same name can only be registered once.
|
|
1399
1396
|
*/
|
|
1400
1397
|
function registerMessagingInSw() {
|
|
1401
|
-
app._registerComponent(new component.Component('messaging-sw', SwMessagingFactory, "PUBLIC" /* PUBLIC */));
|
|
1398
|
+
app._registerComponent(new component.Component('messaging-sw', SwMessagingFactory, "PUBLIC" /* ComponentType.PUBLIC */));
|
|
1402
1399
|
}
|
|
1403
1400
|
|
|
1404
1401
|
/**
|
|
@@ -1467,7 +1464,7 @@ function isSwSupported() {
|
|
|
1467
1464
|
*/
|
|
1468
1465
|
function onBackgroundMessage$1(messaging, nextOrObserver) {
|
|
1469
1466
|
if (self.document !== undefined) {
|
|
1470
|
-
throw ERROR_FACTORY.create("only-available-in-sw" /* AVAILABLE_IN_SW */);
|
|
1467
|
+
throw ERROR_FACTORY.create("only-available-in-sw" /* ErrorCode.AVAILABLE_IN_SW */);
|
|
1471
1468
|
}
|
|
1472
1469
|
messaging.onBackgroundMessageHandler = nextOrObserver;
|
|
1473
1470
|
return function () {
|
|
@@ -1528,11 +1525,11 @@ function getMessagingInSw(app$1) {
|
|
|
1528
1525
|
isSwSupported().then(function (isSupported) {
|
|
1529
1526
|
// If `isSwSupported()` resolved, but returned false.
|
|
1530
1527
|
if (!isSupported) {
|
|
1531
|
-
throw ERROR_FACTORY.create("unsupported-browser" /* UNSUPPORTED_BROWSER */);
|
|
1528
|
+
throw ERROR_FACTORY.create("unsupported-browser" /* ErrorCode.UNSUPPORTED_BROWSER */);
|
|
1532
1529
|
}
|
|
1533
1530
|
}, function (_) {
|
|
1534
1531
|
// If `isSwSupported()` rejected.
|
|
1535
|
-
throw ERROR_FACTORY.create("indexed-db-unsupported" /* INDEXED_DB_UNSUPPORTED */);
|
|
1532
|
+
throw ERROR_FACTORY.create("indexed-db-unsupported" /* ErrorCode.INDEXED_DB_UNSUPPORTED */);
|
|
1536
1533
|
});
|
|
1537
1534
|
return app._getProvider(util.getModularInstance(app$1), 'messaging-sw').getImmediate();
|
|
1538
1535
|
}
|