New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@firebase/messaging

Package Overview
Dependencies
Maintainers
3
Versions
3364
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@firebase/messaging - npm Package Compare versions

Comparing version 0.2.3-canary.92f3809 to 0.2.3-canary.a1020bf

8

dist/cjs/index.js

@@ -0,1 +1,2 @@

"use strict";
/**

@@ -16,3 +17,2 @@ * Copyright 2017 Google Inc.

*/
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });

@@ -26,10 +26,10 @@ var window_controller_1 = require("./src/controllers/window-controller");

if (self && 'ServiceWorkerGlobalScope' in self) {
return new sw_controller_1.default(app);
return new sw_controller_1.SWController(app);
}
// Assume we are in the window context.
return new window_controller_1.default(app);
return new window_controller_1.WindowController(app);
};
var namespaceExports = {
// no-inline
Messaging: window_controller_1.default
Messaging: window_controller_1.WindowController
};

@@ -36,0 +36,0 @@ instance.INTERNAL.registerService(messagingName, factoryMethod, namespaceExports);

@@ -1,6 +0,6 @@

import TokenDetailsModel from '../models/token-details-model';
import VapidDetailsModel from '../models/vapid-details-model';
import IIDModel from '../models/iid-model';
import { TokenDetailsModel } from '../models/token-details-model';
import { VapidDetailsModel } from '../models/vapid-details-model';
import { IIDModel } from '../models/iid-model';
export declare const TOKEN_EXPIRATION_MILLIS: number;
export default class ControllerInterface {
export declare class ControllerInterface {
app: any;

@@ -43,5 +43,10 @@ INTERNAL: any;

deleteToken(token: string): Promise<Boolean>;
/**
* This method will delete the token from the client database, and make a
* call to FCM to remove it from the server DB. Does not temper with the
* push subscription.
*/
private deleteTokenFromDB(token);
getSWRegistration_(): Promise<ServiceWorkerRegistration>;
getPublicVapidKey_(): Promise<Uint8Array>;
requestPermission(): void;
/**

@@ -51,2 +56,3 @@ * Gets a PushSubscription for the current user.

getPushSubscription(swRegistration: ServiceWorkerRegistration, publicVapidKey: Uint8Array): Promise<PushSubscription>;
requestPermission(): void;
/**

@@ -53,0 +59,0 @@ * @export

@@ -0,1 +1,2 @@

"use strict";
/**

@@ -16,3 +17,2 @@ * Copyright 2017 Google Inc.

*/
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });

@@ -37,11 +37,11 @@ var tslib_1 = require("tslib");

var _this = this;
this.errorFactory_ = new util_1.ErrorFactory('messaging', 'Messaging', errors_1.default.map);
this.errorFactory_ = new util_1.ErrorFactory('messaging', 'Messaging', errors_1.ERROR_MAP);
if (!app.options[SENDER_ID_OPTION_NAME] ||
typeof app.options[SENDER_ID_OPTION_NAME] !== 'string') {
throw this.errorFactory_.create(errors_1.default.codes.BAD_SENDER_ID);
throw this.errorFactory_.create(errors_1.ERROR_CODES.BAD_SENDER_ID);
}
this.messagingSenderId_ = app.options[SENDER_ID_OPTION_NAME];
this.tokenDetailsModel_ = new token_details_model_1.default();
this.vapidDetailsModel_ = new vapid_details_model_1.default();
this.iidModel_ = new iid_model_1.default();
this.tokenDetailsModel_ = new token_details_model_1.TokenDetailsModel();
this.vapidDetailsModel_ = new vapid_details_model_1.VapidDetailsModel();
this.iidModel_ = new iid_model_1.IIDModel();
this.app = app;

@@ -61,5 +61,5 @@ this.INTERNAL = {};

currentPermission = this.getNotificationPermission_();
if (currentPermission !== notification_permission_1.default.granted) {
if (currentPermission === notification_permission_1.default.denied) {
return [2 /*return*/, Promise.reject(this.errorFactory_.create(errors_1.default.codes.NOTIFICATIONS_BLOCKED))];
if (currentPermission !== notification_permission_1.NotificationPermission.GRANTED) {
if (currentPermission === notification_permission_1.NotificationPermission.DENIED) {
return [2 /*return*/, Promise.reject(this.errorFactory_.create(errors_1.ERROR_CODES.NOTIFICATIONS_BLOCKED))];
}

@@ -115,7 +115,11 @@ // We must wait for permission to be granted

// If the token is no longer valid (for example if the VAPID details
// have changed), delete the existing token, and create a new one.
return [4 /*yield*/, this.deleteToken(tokenDetails['fcmToken'])];
// have changed), delete the existing token from the FCM client and server
// database. No need to unsubscribe from the Service Worker as we have a
// good push subscription that we'd like to use in getNewToken.
return [4 /*yield*/, this.deleteTokenFromDB(tokenDetails['fcmToken'])];
case 1:
// If the token is no longer valid (for example if the VAPID details
// have changed), delete the existing token, and create a new one.
// have changed), delete the existing token from the FCM client and server
// database. No need to unsubscribe from the Service Worker as we have a
// good push subscription that we'd like to use in getNewToken.
_a.sent();

@@ -131,3 +135,3 @@ return [2 /*return*/, this.getNewToken(swReg, pushSubscription, publicVapidKey)];

ControllerInterface.prototype.isTokenStillValid = function (pushSubscription, publicVapidKey, tokenDetails) {
if (array_buffer_to_base64_1.default(publicVapidKey) !== tokenDetails['vapidKey']) {
if (array_buffer_to_base64_1.arrayBufferToBase64(publicVapidKey) !== tokenDetails['vapidKey']) {
return false;

@@ -138,5 +142,5 @@ }

return (pushSubscription.endpoint === tokenDetails['endpoint'] &&
array_buffer_to_base64_1.default(pushSubscription['getKey']('auth')) ===
array_buffer_to_base64_1.arrayBufferToBase64(pushSubscription['getKey']('auth')) ===
tokenDetails['auth'] &&
array_buffer_to_base64_1.default(pushSubscription['getKey']('p256dh')) ===
array_buffer_to_base64_1.arrayBufferToBase64(pushSubscription['getKey']('p256dh')) ===
tokenDetails['p256dh']);

@@ -215,18 +219,47 @@ };

ControllerInterface.prototype.deleteToken = function (token) {
var _this = this;
return this.tokenDetailsModel_
.deleteToken(token)
.then(function (details) {
return _this.iidModel_.deleteToken(details['fcmSenderId'], details['fcmToken'], details['fcmPushSet']);
})
.then(function () {
return _this.getSWRegistration_()
.then(function (registration) {
if (registration) {
return registration.pushManager.getSubscription();
return tslib_1.__awaiter(this, void 0, void 0, function () {
var registration, pushSubscription;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
// Delete the token details from the database.
return [4 /*yield*/, this.deleteTokenFromDB(token)];
case 1:
// Delete the token details from the database.
_a.sent();
return [4 /*yield*/, this.getSWRegistration_()];
case 2:
registration = _a.sent();
if (!registration) return [3 /*break*/, 4];
return [4 /*yield*/, registration.pushManager.getSubscription()];
case 3:
pushSubscription = _a.sent();
if (pushSubscription) {
return [2 /*return*/, pushSubscription.unsubscribe()];
}
_a.label = 4;
case 4:
// If there's no SW, consider it a success.
return [2 /*return*/, true];
}
})
.then(function (subscription) {
if (subscription) {
return subscription.unsubscribe();
});
});
};
/**
* This method will delete the token from the client database, and make a
* call to FCM to remove it from the server DB. Does not temper with the
* push subscription.
*/
ControllerInterface.prototype.deleteTokenFromDB = function (token) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var details;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.tokenDetailsModel_.deleteToken(token)];
case 1:
details = _a.sent();
return [4 /*yield*/, this.iidModel_.deleteToken(details['fcmSenderId'], details['fcmToken'], details['fcmPushSet'])];
case 2:
_a.sent();
return [2 /*return*/];
}

@@ -237,13 +270,7 @@ });

ControllerInterface.prototype.getSWRegistration_ = function () {
throw this.errorFactory_.create(errors_1.default.codes.SHOULD_BE_INHERITED);
throw this.errorFactory_.create(errors_1.ERROR_CODES.SHOULD_BE_INHERITED);
};
ControllerInterface.prototype.getPublicVapidKey_ = function () {
throw this.errorFactory_.create(errors_1.default.codes.SHOULD_BE_INHERITED);
throw this.errorFactory_.create(errors_1.ERROR_CODES.SHOULD_BE_INHERITED);
};
//
// The following methods should only be available in the window.
//
ControllerInterface.prototype.requestPermission = function () {
throw this.errorFactory_.create(errors_1.default.codes.AVAILABLE_IN_WINDOW);
};
/**

@@ -263,2 +290,8 @@ * Gets a PushSubscription for the current user.

};
//
// The following methods should only be available in the window.
//
ControllerInterface.prototype.requestPermission = function () {
throw this.errorFactory_.create(errors_1.ERROR_CODES.AVAILABLE_IN_WINDOW);
};
/**

@@ -269,3 +302,3 @@ * @export

ControllerInterface.prototype.useServiceWorker = function (registration) {
throw this.errorFactory_.create(errors_1.default.codes.AVAILABLE_IN_WINDOW);
throw this.errorFactory_.create(errors_1.ERROR_CODES.AVAILABLE_IN_WINDOW);
};

@@ -277,3 +310,3 @@ /**

ControllerInterface.prototype.usePublicVapidKey = function (b64PublicKey) {
throw this.errorFactory_.create(errors_1.default.codes.AVAILABLE_IN_WINDOW);
throw this.errorFactory_.create(errors_1.ERROR_CODES.AVAILABLE_IN_WINDOW);
};

@@ -288,3 +321,3 @@ /**

ControllerInterface.prototype.onMessage = function (nextOrObserver, optError, optCompleted) {
throw this.errorFactory_.create(errors_1.default.codes.AVAILABLE_IN_WINDOW);
throw this.errorFactory_.create(errors_1.ERROR_CODES.AVAILABLE_IN_WINDOW);
};

@@ -302,3 +335,3 @@ /**

ControllerInterface.prototype.onTokenRefresh = function (nextOrObserver, optError, optCompleted) {
throw this.errorFactory_.create(errors_1.default.codes.AVAILABLE_IN_WINDOW);
throw this.errorFactory_.create(errors_1.ERROR_CODES.AVAILABLE_IN_WINDOW);
};

@@ -313,3 +346,3 @@ //

ControllerInterface.prototype.setBackgroundMessageHandler = function (callback) {
throw this.errorFactory_.create(errors_1.default.codes.AVAILABLE_IN_SW);
throw this.errorFactory_.create(errors_1.ERROR_CODES.AVAILABLE_IN_SW);
};

@@ -353,4 +386,4 @@ //

}());
exports.default = ControllerInterface;
exports.ControllerInterface = ControllerInterface;
//# sourceMappingURL=controller-interface.js.map

@@ -1,3 +0,18 @@

import ControllerInterface from './controller-interface';
export default class SWController extends ControllerInterface {
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ControllerInterface } from './controller-interface';
export declare class SWController extends ControllerInterface {
private bgMessageHandler_;

@@ -65,3 +80,3 @@ constructor(app: any);

*/
attemptToMessageClient_(client: any, message: any): Promise<never>;
attemptToMessageClient_(client: any, message: any): Promise<undefined>;
/**

@@ -68,0 +83,0 @@ * @private

@@ -0,1 +1,2 @@

"use strict";
/**

@@ -16,3 +17,2 @@ * Copyright 2017 Google Inc.

*/
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });

@@ -29,10 +29,6 @@ var tslib_1 = require("tslib");

var _this = _super.call(this, app) || this;
_this.bgMessageHandler_ = null;
self.addEventListener('push', function (e) { return _this.onPush_(e); }, false);
self.addEventListener('pushsubscriptionchange', function (e) { return _this.onSubChange_(e); }, false);
self.addEventListener('notificationclick', function (e) { return _this.onNotificationClick_(e); }, false);
/**
* @private
* @type {function(Object)|null}
*/
_this.bgMessageHandler_ = null;
return _this;

@@ -118,3 +114,3 @@ }

.catch(function (err) {
throw _this.errorFactory_.create(errors_1.default.codes.UNABLE_TO_RESUBSCRIBE, {
throw _this.errorFactory_.create(errors_1.ERROR_CODES.UNABLE_TO_RESUBSCRIBE, {
message: err

@@ -212,3 +208,3 @@ });

if (!callback || typeof callback !== 'function') {
throw this.errorFactory_.create(errors_1.default.codes.BG_HANDLER_FUNCTION_EXPECTED);
throw this.errorFactory_.create(errors_1.ERROR_CODES.BG_HANDLER_FUNCTION_EXPECTED);
}

@@ -262,3 +258,3 @@ this.bgMessageHandler_ = callback;

if (!client) {
return [2 /*return*/, Promise.reject(this.errorFactory_.create(errors_1.default.codes.NO_WINDOW_CLIENT_TO_MSG))];
return [2 /*return*/, Promise.reject(this.errorFactory_.create(errors_1.ERROR_CODES.NO_WINDOW_CLIENT_TO_MSG))];
}

@@ -327,3 +323,3 @@ client.postMessage(message);

if (vapidKeyFromDatabase === null) {
return fcm_details_1.default.DEFAULT_PUBLIC_VAPID_KEY;
return fcm_details_1.DEFAULT_PUBLIC_VAPID_KEY;
}

@@ -334,5 +330,5 @@ return vapidKeyFromDatabase;

return SWController;
}(controller_interface_1.default));
exports.default = SWController;
}(controller_interface_1.ControllerInterface));
exports.SWController = SWController;
//# sourceMappingURL=sw-controller.js.map

@@ -0,4 +1,19 @@

/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { FirebaseMessaging } from '@firebase/messaging-types';
import ControllerInterface from './controller-interface';
export default class WindowController extends ControllerInterface implements FirebaseMessaging {
import { ControllerInterface } from './controller-interface';
export declare class WindowController extends ControllerInterface implements FirebaseMessaging {
private registrationToUse_;

@@ -40,3 +55,3 @@ private publicVapidKeyToUse_;

*/
requestPermission(): Promise<{}>;
requestPermission(): Promise<{} | undefined>;
/**

@@ -43,0 +58,0 @@ * This method allows a developer to override the default service worker and

@@ -0,1 +1,2 @@

"use strict";
/**

@@ -16,3 +17,2 @@ * Copyright 2017 Google Inc.

*/
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });

@@ -90,3 +90,3 @@ var tslib_1 = require("tslib");

if (!this.isSupported_()) {
return Promise.reject(this.errorFactory_.create(errors_1.default.codes.UNSUPPORTED_BROWSER));
return Promise.reject(this.errorFactory_.create(errors_1.ERROR_CODES.UNSUPPORTED_BROWSER));
}

@@ -130,3 +130,3 @@ return this.manifestCheck_().then(function () {

if (manifestContent['gcm_sender_id'] !== '103953800507') {
throw _this.errorFactory_.create(errors_1.default.codes.INCORRECT_GCM_SENDER_ID);
throw _this.errorFactory_.create(errors_1.ERROR_CODES.INCORRECT_GCM_SENDER_ID);
}

@@ -147,3 +147,3 @@ });

return tslib_1.__generator(this, function (_a) {
if (Notification.permission === notification_permission_1.default.granted) {
if (Notification.permission === notification_permission_1.NotificationPermission.GRANTED) {
return [2 /*return*/];

@@ -153,10 +153,10 @@ }

var managePermissionResult = function (result) {
if (result === notification_permission_1.default.granted) {
if (result === notification_permission_1.NotificationPermission.GRANTED) {
return resolve();
}
else if (result === notification_permission_1.default.denied) {
return reject(_this.errorFactory_.create(errors_1.default.codes.PERMISSION_BLOCKED));
else if (result === notification_permission_1.NotificationPermission.DENIED) {
return reject(_this.errorFactory_.create(errors_1.ERROR_CODES.PERMISSION_BLOCKED));
}
else {
return reject(_this.errorFactory_.create(errors_1.default.codes.PERMISSION_DEFAULT));
return reject(_this.errorFactory_.create(errors_1.ERROR_CODES.PERMISSION_DEFAULT));
}

@@ -185,6 +185,6 @@ };

if (!(registration instanceof ServiceWorkerRegistration)) {
throw this.errorFactory_.create(errors_1.default.codes.SW_REGISTRATION_EXPECTED);
throw this.errorFactory_.create(errors_1.ERROR_CODES.SW_REGISTRATION_EXPECTED);
}
if (typeof this.registrationToUse_ !== 'undefined') {
throw this.errorFactory_.create(errors_1.default.codes.USE_SW_BEFORE_GET_TOKEN);
throw this.errorFactory_.create(errors_1.ERROR_CODES.USE_SW_BEFORE_GET_TOKEN);
}

@@ -201,10 +201,10 @@ this.registrationToUse_ = registration;

if (typeof publicKey !== 'string') {
throw this.errorFactory_.create(errors_1.default.codes.INVALID_PUBLIC_VAPID_KEY);
throw this.errorFactory_.create(errors_1.ERROR_CODES.INVALID_PUBLIC_VAPID_KEY);
}
if (typeof this.publicVapidKeyToUse_ !== 'undefined') {
throw this.errorFactory_.create(errors_1.default.codes.USE_PUBLIC_KEY_BEFORE_GET_TOKEN);
throw this.errorFactory_.create(errors_1.ERROR_CODES.USE_PUBLIC_KEY_BEFORE_GET_TOKEN);
}
var parsedKey = base64_to_array_buffer_1.default(publicKey);
var parsedKey = base64_to_array_buffer_1.base64ToArrayBuffer(publicKey);
if (parsedKey.length !== 65) {
throw this.errorFactory_.create(errors_1.default.codes.PUBLIC_KEY_DECRYPTION_FAILED);
throw this.errorFactory_.create(errors_1.ERROR_CODES.PUBLIC_KEY_DECRYPTION_FAILED);
}

@@ -254,3 +254,3 @@ this.publicVapidKeyToUse_ = parsedKey;

// This is a rare scenario but has occured in firefox
reject(_this.errorFactory_.create(errors_1.default.codes.NO_SW_IN_REG));
reject(_this.errorFactory_.create(errors_1.ERROR_CODES.NO_SW_IN_REG));
return;

@@ -265,3 +265,3 @@ }

if (serviceWorker.state === 'redundant') {
reject(_this.errorFactory_.create(errors_1.default.codes.SW_REG_REDUNDANT));
reject(_this.errorFactory_.create(errors_1.ERROR_CODES.SW_REG_REDUNDANT));
return;

@@ -274,3 +274,3 @@ }

else if (serviceWorker.state === 'redundant') {
reject(_this.errorFactory_.create(errors_1.default.codes.SW_REG_REDUNDANT));
reject(_this.errorFactory_.create(errors_1.ERROR_CODES.SW_REG_REDUNDANT));
}

@@ -301,7 +301,7 @@ else {

return navigator.serviceWorker
.register(default_sw_1.default.path, {
scope: default_sw_1.default.scope
.register(default_sw_1.DEFAULT_SW_PATH, {
scope: default_sw_1.DEFAULT_SW_SCOPE
})
.catch(function (err) {
throw _this.errorFactory_.create(errors_1.default.codes.FAILED_DEFAULT_REGISTRATION, {
throw _this.errorFactory_.create(errors_1.ERROR_CODES.FAILED_DEFAULT_REGISTRATION, {
browserErrorMessage: err.message

@@ -330,3 +330,3 @@ });

}
return Promise.resolve(fcm_details_1.default.DEFAULT_PUBLIC_VAPID_KEY);
return Promise.resolve(fcm_details_1.DEFAULT_PUBLIC_VAPID_KEY);
};

@@ -379,5 +379,5 @@ /**

return WindowController;
}(controller_interface_1.default));
exports.default = WindowController;
}(controller_interface_1.ControllerInterface));
exports.WindowController = WindowController;
//# sourceMappingURL=window-controller.js.map

@@ -1,2 +0,1 @@

declare const _default: (arrayBuffer: any) => string;
export default _default;
export declare function arrayBufferToBase64(arrayBuffer: any): string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**

@@ -18,7 +17,8 @@ * Copyright 2017 Google Inc.

*/
Object.defineProperty(exports, "__esModule", { value: true });
function toBase64(arrayBuffer) {
var uint8Version = new Uint8Array(arrayBuffer);
return window.btoa(String.fromCharCode.apply(null, uint8Version));
return btoa(String.fromCharCode.apply(null, uint8Version));
}
exports.default = (function (arrayBuffer) {
function arrayBufferToBase64(arrayBuffer) {
var base64String = toBase64(arrayBuffer);

@@ -29,4 +29,5 @@ return base64String

.replace(/\//g, '_');
});
}
exports.arrayBufferToBase64 = arrayBufferToBase64;
//# sourceMappingURL=array-buffer-to-base64.js.map

@@ -1,2 +0,16 @@

declare const _default: (base64String: any) => Uint8Array;
export default _default;
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare function base64ToArrayBuffer(base64String: any): Uint8Array;

@@ -18,3 +18,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.default = (function (base64String) {
function base64ToArrayBuffer(base64String) {
var padding = '='.repeat((4 - base64String.length % 4) % 4);

@@ -30,4 +30,5 @@ var base64 = (base64String + padding)

return outputArray;
});
}
exports.base64ToArrayBuffer = base64ToArrayBuffer;
//# sourceMappingURL=base64-to-array-buffer.js.map

@@ -40,3 +40,3 @@ "use strict";

var objectStore = transaction.objectStore(OLD_OBJECT_STORE_NAME);
var iidModel = new iid_model_1.default();
var iidModel = new iid_model_1.IIDModel();
var openCursorRequest = objectStore.openCursor();

@@ -43,0 +43,0 @@ openCursorRequest.onerror = function (event) {

@@ -0,3 +1,18 @@

/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ErrorFactory } from '@firebase/util';
export default class DBInterface {
export declare class DBInterface {
private DB_NAME_;

@@ -4,0 +19,0 @@ private dbVersion_;

@@ -0,1 +1,2 @@

"use strict";
/**

@@ -16,3 +17,2 @@ * Copyright 2017 Google Inc.

*/
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });

@@ -27,3 +27,3 @@ var util_1 = require("@firebase/util");

function DBInterface(dbName, dbVersion) {
this.errorFactory_ = new util_1.ErrorFactory('messaging', 'Messaging', errors_1.default.map);
this.errorFactory_ = new util_1.ErrorFactory('messaging', 'Messaging', errors_1.ERROR_MAP);
this.DB_NAME_ = dbName;

@@ -86,8 +86,8 @@ this.dbVersion_ = dbVersion;

DBInterface.prototype.onDBUpgrade = function (db, event) {
throw this.errorFactory_.create(errors_1.default.codes.SHOULD_BE_INHERITED);
throw this.errorFactory_.create(errors_1.ERROR_CODES.SHOULD_BE_INHERITED);
};
return DBInterface;
}());
exports.default = DBInterface;
exports.DBInterface = DBInterface;
//# sourceMappingURL=db-interface.js.map

@@ -1,5 +0,17 @@

declare const _default: {
path: string;
scope: string;
};
export default _default;
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const DEFAULT_SW_PATH = "/firebase-messaging-sw.js";
export declare const DEFAULT_SW_SCOPE = "/firebase-cloud-messaging-push-scope";

@@ -0,1 +1,2 @@

"use strict";
/**

@@ -16,9 +17,6 @@ * Copyright 2017 Google Inc.

*/
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = {
path: '/firebase-messaging-sw.js',
scope: '/firebase-cloud-messaging-push-scope'
};
exports.DEFAULT_SW_PATH = '/firebase-messaging-sw.js';
exports.DEFAULT_SW_SCOPE = '/firebase-cloud-messaging-push-scope';
//# sourceMappingURL=default-sw.js.map

@@ -1,47 +0,59 @@

declare const _default: {
codes: {
AVAILABLE_IN_WINDOW: string;
AVAILABLE_IN_SW: string;
SHOULD_BE_INHERITED: string;
BAD_SENDER_ID: string;
INCORRECT_GCM_SENDER_ID: string;
PERMISSION_DEFAULT: string;
PERMISSION_BLOCKED: string;
UNSUPPORTED_BROWSER: string;
NOTIFICATIONS_BLOCKED: string;
FAILED_DEFAULT_REGISTRATION: string;
SW_REGISTRATION_EXPECTED: string;
GET_SUBSCRIPTION_FAILED: string;
INVALID_SAVED_TOKEN: string;
SW_REG_REDUNDANT: string;
TOKEN_SUBSCRIBE_FAILED: string;
TOKEN_SUBSCRIBE_NO_TOKEN: string;
TOKEN_SUBSCRIBE_NO_PUSH_SET: string;
TOKEN_UNSUBSCRIBE_FAILED: string;
TOKEN_UPDATE_FAILED: string;
TOKEN_UPDATE_NO_TOKEN: string;
USE_SW_BEFORE_GET_TOKEN: string;
INVALID_DELETE_TOKEN: string;
DELETE_TOKEN_NOT_FOUND: string;
DELETE_SCOPE_NOT_FOUND: string;
BG_HANDLER_FUNCTION_EXPECTED: string;
NO_WINDOW_CLIENT_TO_MSG: string;
UNABLE_TO_RESUBSCRIBE: string;
NO_FCM_TOKEN_FOR_RESUBSCRIBE: string;
FAILED_TO_DELETE_TOKEN: string;
NO_SW_IN_REG: string;
BAD_SCOPE: string;
BAD_VAPID_KEY: string;
BAD_SUBSCRIPTION: string;
BAD_TOKEN: string;
BAD_PUSH_SET: string;
FAILED_DELETE_VAPID_KEY: string;
INVALID_PUBLIC_VAPID_KEY: string;
USE_PUBLIC_KEY_BEFORE_GET_TOKEN: string;
PUBLIC_KEY_DECRYPTION_FAILED: string;
};
map: {
[x: string]: string;
};
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const ERROR_CODES: {
AVAILABLE_IN_WINDOW: string;
AVAILABLE_IN_SW: string;
SHOULD_BE_INHERITED: string;
BAD_SENDER_ID: string;
INCORRECT_GCM_SENDER_ID: string;
PERMISSION_DEFAULT: string;
PERMISSION_BLOCKED: string;
UNSUPPORTED_BROWSER: string;
NOTIFICATIONS_BLOCKED: string;
FAILED_DEFAULT_REGISTRATION: string;
SW_REGISTRATION_EXPECTED: string;
GET_SUBSCRIPTION_FAILED: string;
INVALID_SAVED_TOKEN: string;
SW_REG_REDUNDANT: string;
TOKEN_SUBSCRIBE_FAILED: string;
TOKEN_SUBSCRIBE_NO_TOKEN: string;
TOKEN_SUBSCRIBE_NO_PUSH_SET: string;
TOKEN_UNSUBSCRIBE_FAILED: string;
TOKEN_UPDATE_FAILED: string;
TOKEN_UPDATE_NO_TOKEN: string;
USE_SW_BEFORE_GET_TOKEN: string;
INVALID_DELETE_TOKEN: string;
DELETE_TOKEN_NOT_FOUND: string;
DELETE_SCOPE_NOT_FOUND: string;
BG_HANDLER_FUNCTION_EXPECTED: string;
NO_WINDOW_CLIENT_TO_MSG: string;
UNABLE_TO_RESUBSCRIBE: string;
NO_FCM_TOKEN_FOR_RESUBSCRIBE: string;
FAILED_TO_DELETE_TOKEN: string;
NO_SW_IN_REG: string;
BAD_SCOPE: string;
BAD_VAPID_KEY: string;
BAD_SUBSCRIPTION: string;
BAD_TOKEN: string;
BAD_PUSH_SET: string;
FAILED_DELETE_VAPID_KEY: string;
INVALID_PUBLIC_VAPID_KEY: string;
USE_PUBLIC_KEY_BEFORE_GET_TOKEN: string;
PUBLIC_KEY_DECRYPTION_FAILED: string;
};
export default _default;
export declare const ERROR_MAP: {
[x: string]: string;
};

@@ -0,1 +1,2 @@

"use strict";
/**

@@ -16,5 +17,4 @@ * Copyright 2017 Google Inc.

*/
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
var CODES = {
exports.ERROR_CODES = {
AVAILABLE_IN_WINDOW: 'only-available-in-window',

@@ -60,65 +60,61 @@ AVAILABLE_IN_SW: 'only-available-in-sw',

};
var ERROR_MAP = (_a = {},
_a[CODES.AVAILABLE_IN_WINDOW] = 'This method is available in a Window context.',
_a[CODES.AVAILABLE_IN_SW] = 'This method is available in a service worker ' + 'context.',
_a[CODES.SHOULD_BE_INHERITED] = 'This method should be overriden by ' + 'extended classes.',
_a[CODES.BAD_SENDER_ID] = "Please ensure that 'messagingSenderId' is set " +
exports.ERROR_MAP = (_a = {},
_a[exports.ERROR_CODES.AVAILABLE_IN_WINDOW] = 'This method is available in a Window context.',
_a[exports.ERROR_CODES.AVAILABLE_IN_SW] = 'This method is available in a service worker ' + 'context.',
_a[exports.ERROR_CODES.SHOULD_BE_INHERITED] = 'This method should be overriden by ' + 'extended classes.',
_a[exports.ERROR_CODES.BAD_SENDER_ID] = "Please ensure that 'messagingSenderId' is set " +
'correctly in the options passed into firebase.initializeApp().',
_a[CODES.PERMISSION_DEFAULT] = 'The required permissions were not granted and ' + 'dismissed instead.',
_a[CODES.PERMISSION_BLOCKED] = 'The required permissions were not granted and ' + 'blocked instead.',
_a[CODES.UNSUPPORTED_BROWSER] = "This browser doesn't support the API's " +
_a[exports.ERROR_CODES.PERMISSION_DEFAULT] = 'The required permissions were not granted and ' + 'dismissed instead.',
_a[exports.ERROR_CODES.PERMISSION_BLOCKED] = 'The required permissions were not granted and ' + 'blocked instead.',
_a[exports.ERROR_CODES.UNSUPPORTED_BROWSER] = "This browser doesn't support the API's " +
'required to use the firebase SDK.',
_a[CODES.NOTIFICATIONS_BLOCKED] = 'Notifications have been blocked.',
_a[CODES.FAILED_DEFAULT_REGISTRATION] = 'We are unable to register the ' +
_a[exports.ERROR_CODES.NOTIFICATIONS_BLOCKED] = 'Notifications have been blocked.',
_a[exports.ERROR_CODES.FAILED_DEFAULT_REGISTRATION] = 'We are unable to register the ' +
'default service worker. {$browserErrorMessage}',
_a[CODES.SW_REGISTRATION_EXPECTED] = 'A service worker registration was the ' + 'expected input.',
_a[CODES.GET_SUBSCRIPTION_FAILED] = 'There was an error when trying to get ' +
_a[exports.ERROR_CODES.SW_REGISTRATION_EXPECTED] = 'A service worker registration was the ' + 'expected input.',
_a[exports.ERROR_CODES.GET_SUBSCRIPTION_FAILED] = 'There was an error when trying to get ' +
'any existing Push Subscriptions.',
_a[CODES.INVALID_SAVED_TOKEN] = 'Unable to access details of the saved token.',
_a[CODES.SW_REG_REDUNDANT] = 'The service worker being used for push was made ' + 'redundant.',
_a[CODES.TOKEN_SUBSCRIBE_FAILED] = 'A problem occured while subscribing the ' + 'user to FCM: {$message}',
_a[CODES.TOKEN_SUBSCRIBE_NO_TOKEN] = 'FCM returned no token when subscribing ' + 'the user to push.',
_a[CODES.TOKEN_SUBSCRIBE_NO_PUSH_SET] = 'FCM returned an invalid response ' + 'when getting an FCM token.',
_a[CODES.TOKEN_UNSUBSCRIBE_FAILED] = 'A problem occured while unsubscribing the ' + 'user from FCM: {$message}',
_a[CODES.TOKEN_UPDATE_FAILED] = 'A problem occured while updating the ' + 'user from FCM: {$message}',
_a[CODES.TOKEN_UPDATE_NO_TOKEN] = 'FCM returned no token when updating ' + 'the user to push.',
_a[CODES.USE_SW_BEFORE_GET_TOKEN] = 'The useServiceWorker() method may only be called once and must be ' +
_a[exports.ERROR_CODES.INVALID_SAVED_TOKEN] = 'Unable to access details of the saved token.',
_a[exports.ERROR_CODES.SW_REG_REDUNDANT] = 'The service worker being used for push was made ' + 'redundant.',
_a[exports.ERROR_CODES.TOKEN_SUBSCRIBE_FAILED] = 'A problem occured while subscribing the ' + 'user to FCM: {$message}',
_a[exports.ERROR_CODES.TOKEN_SUBSCRIBE_NO_TOKEN] = 'FCM returned no token when subscribing ' + 'the user to push.',
_a[exports.ERROR_CODES.TOKEN_SUBSCRIBE_NO_PUSH_SET] = 'FCM returned an invalid response ' + 'when getting an FCM token.',
_a[exports.ERROR_CODES.TOKEN_UNSUBSCRIBE_FAILED] = 'A problem occured while unsubscribing the ' + 'user from FCM: {$message}',
_a[exports.ERROR_CODES.TOKEN_UPDATE_FAILED] = 'A problem occured while updating the ' + 'user from FCM: {$message}',
_a[exports.ERROR_CODES.TOKEN_UPDATE_NO_TOKEN] = 'FCM returned no token when updating ' + 'the user to push.',
_a[exports.ERROR_CODES.USE_SW_BEFORE_GET_TOKEN] = 'The useServiceWorker() method may only be called once and must be ' +
'called before calling getToken() to ensure your service worker is used.',
_a[CODES.INVALID_DELETE_TOKEN] = 'You must pass a valid token into ' +
_a[exports.ERROR_CODES.INVALID_DELETE_TOKEN] = 'You must pass a valid token into ' +
'deleteToken(), i.e. the token from getToken().',
_a[CODES.DELETE_TOKEN_NOT_FOUND] = 'The deletion attempt for token could not ' +
_a[exports.ERROR_CODES.DELETE_TOKEN_NOT_FOUND] = 'The deletion attempt for token could not ' +
'be performed as the token was not found.',
_a[CODES.DELETE_SCOPE_NOT_FOUND] = 'The deletion attempt for service worker ' +
_a[exports.ERROR_CODES.DELETE_SCOPE_NOT_FOUND] = 'The deletion attempt for service worker ' +
'scope could not be performed as the scope was not found.',
_a[CODES.BG_HANDLER_FUNCTION_EXPECTED] = 'The input to ' + 'setBackgroundMessageHandler() must be a function.',
_a[CODES.NO_WINDOW_CLIENT_TO_MSG] = 'An attempt was made to message a ' + 'non-existant window client.',
_a[CODES.UNABLE_TO_RESUBSCRIBE] = 'There was an error while re-subscribing ' +
_a[exports.ERROR_CODES.BG_HANDLER_FUNCTION_EXPECTED] = 'The input to ' + 'setBackgroundMessageHandler() must be a function.',
_a[exports.ERROR_CODES.NO_WINDOW_CLIENT_TO_MSG] = 'An attempt was made to message a ' + 'non-existant window client.',
_a[exports.ERROR_CODES.UNABLE_TO_RESUBSCRIBE] = 'There was an error while re-subscribing ' +
'the FCM token for push messaging. Will have to resubscribe the ' +
'user on next visit. {$message}',
_a[CODES.NO_FCM_TOKEN_FOR_RESUBSCRIBE] = 'Could not find an FCM token ' +
_a[exports.ERROR_CODES.NO_FCM_TOKEN_FOR_RESUBSCRIBE] = 'Could not find an FCM token ' +
'and as a result, unable to resubscribe. Will have to resubscribe the ' +
'user on next visit.',
_a[CODES.FAILED_TO_DELETE_TOKEN] = 'Unable to delete the currently saved token.',
_a[CODES.NO_SW_IN_REG] = 'Even though the service worker registration was ' +
_a[exports.ERROR_CODES.FAILED_TO_DELETE_TOKEN] = 'Unable to delete the currently saved token.',
_a[exports.ERROR_CODES.NO_SW_IN_REG] = 'Even though the service worker registration was ' +
'successful, there was a problem accessing the service worker itself.',
_a[CODES.INCORRECT_GCM_SENDER_ID] = "Please change your web app manifest's " +
_a[exports.ERROR_CODES.INCORRECT_GCM_SENDER_ID] = "Please change your web app manifest's " +
"'gcm_sender_id' value to '103953800507' to use Firebase messaging.",
_a[CODES.BAD_SCOPE] = 'The service worker scope must be a string with at ' +
_a[exports.ERROR_CODES.BAD_SCOPE] = 'The service worker scope must be a string with at ' +
'least one character.',
_a[CODES.BAD_VAPID_KEY] = 'The public VAPID key is not a Uint8Array with 65 bytes.',
_a[CODES.BAD_SUBSCRIPTION] = 'The subscription must be a valid ' + 'PushSubscription.',
_a[CODES.BAD_TOKEN] = 'The FCM Token used for storage / lookup was not ' +
_a[exports.ERROR_CODES.BAD_VAPID_KEY] = 'The public VAPID key is not a Uint8Array with 65 bytes.',
_a[exports.ERROR_CODES.BAD_SUBSCRIPTION] = 'The subscription must be a valid ' + 'PushSubscription.',
_a[exports.ERROR_CODES.BAD_TOKEN] = 'The FCM Token used for storage / lookup was not ' +
'a valid token string.',
_a[CODES.BAD_PUSH_SET] = 'The FCM push set used for storage / lookup was not ' +
_a[exports.ERROR_CODES.BAD_PUSH_SET] = 'The FCM push set used for storage / lookup was not ' +
'not a valid push set string.',
_a[CODES.FAILED_DELETE_VAPID_KEY] = 'The VAPID key could not be deleted.',
_a[CODES.INVALID_PUBLIC_VAPID_KEY] = 'The public VAPID key must be a string.',
_a[CODES.PUBLIC_KEY_DECRYPTION_FAILED] = 'The public VAPID key did not equal ' + '65 bytes when decrypted.',
_a[exports.ERROR_CODES.FAILED_DELETE_VAPID_KEY] = 'The VAPID key could not be deleted.',
_a[exports.ERROR_CODES.INVALID_PUBLIC_VAPID_KEY] = 'The public VAPID key must be a string.',
_a[exports.ERROR_CODES.PUBLIC_KEY_DECRYPTION_FAILED] = 'The public VAPID key did not equal ' + '65 bytes when decrypted.',
_a);
exports.default = {
codes: CODES,
map: ERROR_MAP
};
var _a;
//# sourceMappingURL=errors.js.map

@@ -1,9 +0,21 @@

declare const _default: {
DEFAULT_PUBLIC_VAPID_KEY: Uint8Array;
SUBSCRIPTION_DETAILS: {
userVisibleOnly: boolean;
applicationServerKey: Uint8Array;
};
ENDPOINT: string;
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const DEFAULT_PUBLIC_VAPID_KEY: Uint8Array;
export declare const SUBSCRIPTION_DETAILS: {
userVisibleOnly: boolean;
applicationServerKey: Uint8Array;
};
export default _default;
export declare const ENDPOINT = "https://fcm.googleapis.com";

@@ -0,1 +1,2 @@

"use strict";
/**

@@ -16,5 +17,4 @@ * Copyright 2017 Google Inc.

*/
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
var DEFAULT_PUBLIC_VAPID_KEY = new Uint8Array([
exports.DEFAULT_PUBLIC_VAPID_KEY = new Uint8Array([
0x04,

@@ -86,13 +86,8 @@ 0x33,

]);
var SUBSCRIPTION_DETAILS = {
exports.SUBSCRIPTION_DETAILS = {
userVisibleOnly: true,
applicationServerKey: DEFAULT_PUBLIC_VAPID_KEY
applicationServerKey: exports.DEFAULT_PUBLIC_VAPID_KEY
};
exports.default = {
DEFAULT_PUBLIC_VAPID_KEY: DEFAULT_PUBLIC_VAPID_KEY,
SUBSCRIPTION_DETAILS: SUBSCRIPTION_DETAILS,
ENDPOINT: 'https://fcm.googleapis.com'
// ENDPOINT: 'https://jmt17.google.com'
};
exports.ENDPOINT = 'https://fcm.googleapis.com';
//# sourceMappingURL=fcm-details.js.map

@@ -1,15 +0,10 @@

export default class IIDModel {
export interface IIDDetails {
token: string;
pushSet: string;
}
export declare class IIDModel {
private errorFactory_;
constructor();
getToken(senderId: string, subscription: PushSubscription, publicVapidKey: Uint8Array): Promise<IIDDetails>;
/**
* Given a PushSubscription and messagingSenderId, get an FCM token.
* @public
* @param {string} senderId The 'messagingSenderId' to tie the token to.
* @param {PushSubscription} subscription The PushSusbcription to "federate".
* @param {Uint8Array} publicVapidKey The public VAPID key.
* @return {Promise<!Object>} Returns the FCM token to be used in place
* of the PushSubscription.
*/
getToken(senderId: any, subscription: any, publicVapidKey: any): Promise<Object>;
/**
* Update the underlying token details for fcmToken.

@@ -16,0 +11,0 @@ */

@@ -0,1 +1,2 @@

"use strict";
/**

@@ -16,4 +17,4 @@ * Copyright 2017 Google Inc.

*/
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var util_1 = require("@firebase/util");

@@ -25,55 +26,61 @@ var errors_1 = require("./errors");

function IIDModel() {
this.errorFactory_ = new util_1.ErrorFactory('messaging', 'Messaging', errors_1.default.map);
this.errorFactory_ = new util_1.ErrorFactory('messaging', 'Messaging', errors_1.ERROR_MAP);
}
/**
* Given a PushSubscription and messagingSenderId, get an FCM token.
* @public
* @param {string} senderId The 'messagingSenderId' to tie the token to.
* @param {PushSubscription} subscription The PushSusbcription to "federate".
* @param {Uint8Array} publicVapidKey The public VAPID key.
* @return {Promise<!Object>} Returns the FCM token to be used in place
* of the PushSubscription.
*/
IIDModel.prototype.getToken = function (senderId, subscription, publicVapidKey) {
var _this = this;
var p256dh = array_buffer_to_base64_1.default(subscription['getKey']('p256dh'));
var auth = array_buffer_to_base64_1.default(subscription['getKey']('auth'));
var fcmSubscribeBody = "authorized_entity=" + senderId + "&" +
("endpoint=" + subscription.endpoint + "&") +
("encryption_key=" + p256dh + "&") +
("encryption_auth=" + auth);
if (publicVapidKey !== fcm_details_1.default.DEFAULT_PUBLIC_VAPID_KEY) {
var applicationPubKey = array_buffer_to_base64_1.default(publicVapidKey);
fcmSubscribeBody += "&application_pub_key=" + applicationPubKey;
}
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
var subscribeOptions = {
method: 'POST',
headers: headers,
body: fcmSubscribeBody
};
return fetch(fcm_details_1.default.ENDPOINT + '/fcm/connect/subscribe', subscribeOptions)
.then(function (response) { return response.json(); })
.catch(function () {
throw _this.errorFactory_.create(errors_1.default.codes.TOKEN_SUBSCRIBE_FAILED);
})
.then(function (response) {
var fcmTokenResponse = response;
if (fcmTokenResponse['error']) {
var message = fcmTokenResponse['error']['message'];
throw _this.errorFactory_.create(errors_1.default.codes.TOKEN_SUBSCRIBE_FAILED, {
message: message
});
}
if (!fcmTokenResponse['token']) {
throw _this.errorFactory_.create(errors_1.default.codes.TOKEN_SUBSCRIBE_NO_TOKEN);
}
if (!fcmTokenResponse['pushSet']) {
throw _this.errorFactory_.create(errors_1.default.codes.TOKEN_SUBSCRIBE_NO_PUSH_SET);
}
return {
token: fcmTokenResponse['token'],
pushSet: fcmTokenResponse['pushSet']
};
return tslib_1.__awaiter(this, void 0, void 0, function () {
var p256dh, auth, fcmSubscribeBody, applicationPubKey, headers, subscribeOptions, responseData, response, err_1, message;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
p256dh = array_buffer_to_base64_1.arrayBufferToBase64(subscription['getKey']('p256dh'));
auth = array_buffer_to_base64_1.arrayBufferToBase64(subscription['getKey']('auth'));
fcmSubscribeBody = "authorized_entity=" + senderId + "&" +
("endpoint=" + subscription.endpoint + "&") +
("encryption_key=" + p256dh + "&") +
("encryption_auth=" + auth);
if (publicVapidKey !== fcm_details_1.DEFAULT_PUBLIC_VAPID_KEY) {
applicationPubKey = array_buffer_to_base64_1.arrayBufferToBase64(publicVapidKey);
fcmSubscribeBody += "&application_pub_key=" + applicationPubKey;
}
headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
subscribeOptions = {
method: 'POST',
headers: headers,
body: fcmSubscribeBody
};
responseData = null;
_a.label = 1;
case 1:
_a.trys.push([1, 4, , 5]);
return [4 /*yield*/, fetch(fcm_details_1.ENDPOINT + '/fcm/connect/subscribe', subscribeOptions)];
case 2:
response = _a.sent();
return [4 /*yield*/, response.json()];
case 3:
responseData = _a.sent();
return [3 /*break*/, 5];
case 4:
err_1 = _a.sent();
throw this.errorFactory_.create(errors_1.ERROR_CODES.TOKEN_SUBSCRIBE_FAILED);
case 5:
responseData = responseData;
if (responseData['error']) {
message = responseData['error']['message'];
throw this.errorFactory_.create(errors_1.ERROR_CODES.TOKEN_SUBSCRIBE_FAILED, {
message: message
});
}
if (!responseData['token']) {
throw this.errorFactory_.create(errors_1.ERROR_CODES.TOKEN_SUBSCRIBE_NO_TOKEN);
}
if (!responseData['pushSet']) {
throw this.errorFactory_.create(errors_1.ERROR_CODES.TOKEN_SUBSCRIBE_NO_PUSH_SET);
}
return [2 /*return*/, {
token: responseData['token'],
pushSet: responseData['pushSet']
}];
}
});
});

@@ -85,42 +92,54 @@ };

IIDModel.prototype.updateToken = function (senderId, fcmToken, fcmPushSet, subscription, publicVapidKey) {
var _this = this;
var p256dh = array_buffer_to_base64_1.default(subscription['getKey']('p256dh'));
var auth = array_buffer_to_base64_1.default(subscription['getKey']('auth'));
var fcmUpdateBody = "push_set=" + fcmPushSet + "&" +
("token=" + fcmToken + "&") +
("authorized_entity=" + senderId + "&") +
("endpoint=" + subscription.endpoint + "&") +
("encryption_key=" + p256dh + "&") +
("encryption_auth=" + auth);
if (publicVapidKey !== fcm_details_1.default.DEFAULT_PUBLIC_VAPID_KEY) {
var applicationPubKey = array_buffer_to_base64_1.default(publicVapidKey);
fcmUpdateBody += "&application_pub_key=" + applicationPubKey;
}
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
var updateOptions = {
method: 'POST',
headers: headers,
body: fcmUpdateBody
};
var updateFetchRes;
return fetch(fcm_details_1.default.ENDPOINT + '/fcm/connect/subscribe', updateOptions)
.then(function (fetchResponse) {
updateFetchRes = fetchResponse;
return fetchResponse.json();
})
.catch(function () {
throw _this.errorFactory_.create(errors_1.default.codes.TOKEN_UPDATE_FAILED);
})
.then(function (fcmTokenResponse) {
if (!updateFetchRes.ok) {
var message = fcmTokenResponse['error']['message'];
throw _this.errorFactory_.create(errors_1.default.codes.TOKEN_UPDATE_FAILED, {
message: message
});
}
if (!fcmTokenResponse['token']) {
throw _this.errorFactory_.create(errors_1.default.codes.TOKEN_UPDATE_NO_TOKEN);
}
return fcmTokenResponse['token'];
return tslib_1.__awaiter(this, void 0, void 0, function () {
var p256dh, auth, fcmUpdateBody, applicationPubKey, headers, updateOptions, responseData, response, err_2, message;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
p256dh = array_buffer_to_base64_1.arrayBufferToBase64(subscription['getKey']('p256dh'));
auth = array_buffer_to_base64_1.arrayBufferToBase64(subscription['getKey']('auth'));
fcmUpdateBody = "push_set=" + fcmPushSet + "&" +
("token=" + fcmToken + "&") +
("authorized_entity=" + senderId + "&") +
("endpoint=" + subscription.endpoint + "&") +
("encryption_key=" + p256dh + "&") +
("encryption_auth=" + auth);
if (publicVapidKey !== fcm_details_1.DEFAULT_PUBLIC_VAPID_KEY) {
applicationPubKey = array_buffer_to_base64_1.arrayBufferToBase64(publicVapidKey);
fcmUpdateBody += "&application_pub_key=" + applicationPubKey;
}
headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
updateOptions = {
method: 'POST',
headers: headers,
body: fcmUpdateBody
};
responseData = null;
_a.label = 1;
case 1:
_a.trys.push([1, 4, , 5]);
return [4 /*yield*/, fetch(fcm_details_1.ENDPOINT + '/fcm/connect/subscribe', updateOptions)];
case 2:
response = _a.sent();
return [4 /*yield*/, response.json()];
case 3:
responseData = _a.sent();
return [3 /*break*/, 5];
case 4:
err_2 = _a.sent();
throw this.errorFactory_.create(errors_1.ERROR_CODES.TOKEN_UPDATE_FAILED);
case 5:
responseData = responseData;
if (responseData['error']) {
message = responseData['error']['message'];
throw this.errorFactory_.create(errors_1.ERROR_CODES.TOKEN_UPDATE_FAILED, {
message: message
});
}
if (!responseData['token']) {
throw this.errorFactory_.create(errors_1.ERROR_CODES.TOKEN_UPDATE_NO_TOKEN);
}
return [2 /*return*/, responseData['token']];
}
});
});

@@ -132,26 +151,39 @@ };

IIDModel.prototype.deleteToken = function (senderId, fcmToken, fcmPushSet) {
var _this = this;
var fcmUnsubscribeBody = "authorized_entity=" + senderId + "&" +
("token=" + fcmToken + "&") +
("pushSet=" + fcmPushSet);
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
var unsubscribeOptions = {
method: 'POST',
headers: headers,
body: fcmUnsubscribeBody
};
return fetch(fcm_details_1.default.ENDPOINT + '/fcm/connect/unsubscribe', unsubscribeOptions).then(function (fetchResponse) {
if (!fetchResponse.ok) {
return fetchResponse.json().then(function (fcmTokenResponse) {
if (fcmTokenResponse['error']) {
var message = fcmTokenResponse['error']['message'];
throw _this.errorFactory_.create(errors_1.default.codes.TOKEN_UNSUBSCRIBE_FAILED, {
message: message
});
}
}, function (err) {
throw _this.errorFactory_.create(errors_1.default.codes.TOKEN_UNSUBSCRIBE_FAILED);
});
}
return tslib_1.__awaiter(this, void 0, void 0, function () {
var fcmUnsubscribeBody, headers, unsubscribeOptions, response, responseData, message, err_3;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
fcmUnsubscribeBody = "authorized_entity=" + senderId + "&" +
("token=" + fcmToken + "&") +
("pushSet=" + fcmPushSet);
headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
unsubscribeOptions = {
method: 'POST',
headers: headers,
body: fcmUnsubscribeBody
};
_a.label = 1;
case 1:
_a.trys.push([1, 4, , 5]);
return [4 /*yield*/, fetch(fcm_details_1.ENDPOINT + '/fcm/connect/unsubscribe', unsubscribeOptions)];
case 2:
response = _a.sent();
return [4 /*yield*/, response.json()];
case 3:
responseData = _a.sent();
if (responseData['error']) {
message = responseData['error']['message'];
throw this.errorFactory_.create(errors_1.ERROR_CODES.TOKEN_UNSUBSCRIBE_FAILED, {
message: message
});
}
return [3 /*break*/, 5];
case 4:
err_3 = _a.sent();
throw this.errorFactory_.create(errors_1.ERROR_CODES.TOKEN_UNSUBSCRIBE_FAILED);
case 5: return [2 /*return*/];
}
});
});

@@ -161,4 +193,4 @@ };

}());
exports.default = IIDModel;
exports.IIDModel = IIDModel;
//# sourceMappingURL=iid-model.js.map

@@ -1,6 +0,20 @@

declare const _default: {
granted: string;
default: string;
denied: string;
};
export default _default;
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare enum NotificationPermission {
DEFAULT = "default",
GRANTED = "granted",
DENIED = "denied",
}

@@ -0,1 +1,2 @@

"use strict";
/**

@@ -16,10 +17,10 @@ * Copyright 2017 Google Inc.

*/
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = {
granted: 'granted',
default: 'default',
denied: 'denied'
};
var NotificationPermission;
(function (NotificationPermission) {
NotificationPermission["DEFAULT"] = "default";
NotificationPermission["GRANTED"] = "granted";
NotificationPermission["DENIED"] = "denied";
})(NotificationPermission = exports.NotificationPermission || (exports.NotificationPermission = {}));
//# sourceMappingURL=notification-permission.js.map

@@ -1,3 +0,18 @@

import DBInterface from './db-interface';
export default class TokenDetailsModel extends DBInterface {
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { DBInterface } from './db-interface';
export declare class TokenDetailsModel extends DBInterface {
constructor();

@@ -13,3 +28,3 @@ onDBUpgrade(db: IDBDatabase, evt: IDBVersionChangeEvent): void;

*/
validateInputs_(input: any): Promise<never>;
validateInputs_(input: any): Promise<undefined>;
/**

@@ -16,0 +31,0 @@ * Given a token, this method will look up the details in indexedDB.

@@ -0,1 +1,2 @@

"use strict";
/**

@@ -16,3 +17,2 @@ * Copyright 2017 Google Inc.

*/
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });

@@ -80,3 +80,3 @@ var tslib_1 = require("tslib");

if (typeof input.fcmToken !== 'string' || input.fcmToken.length === 0) {
return [2 /*return*/, Promise.reject(this.errorFactory_.create(errors_1.default.codes.BAD_TOKEN))];
return [2 /*return*/, Promise.reject(this.errorFactory_.create(errors_1.ERROR_CODES.BAD_TOKEN))];
}

@@ -86,3 +86,3 @@ }

if (typeof input.swScope !== 'string' || input.swScope.length === 0) {
return [2 /*return*/, Promise.reject(this.errorFactory_.create(errors_1.default.codes.BAD_SCOPE))];
return [2 /*return*/, Promise.reject(this.errorFactory_.create(errors_1.ERROR_CODES.BAD_SCOPE))];
}

@@ -93,3 +93,3 @@ }

input.vapidKey.length !== 65) {
return [2 /*return*/, Promise.reject(this.errorFactory_.create(errors_1.default.codes.BAD_VAPID_KEY))];
return [2 /*return*/, Promise.reject(this.errorFactory_.create(errors_1.ERROR_CODES.BAD_VAPID_KEY))];
}

@@ -99,3 +99,3 @@ }

if (!(input.subscription instanceof PushSubscription)) {
return [2 /*return*/, Promise.reject(this.errorFactory_.create(errors_1.default.codes.BAD_SUBSCRIPTION))];
return [2 /*return*/, Promise.reject(this.errorFactory_.create(errors_1.ERROR_CODES.BAD_SUBSCRIPTION))];
}

@@ -106,3 +106,3 @@ }

input.fcmSenderId.length === 0) {
return [2 /*return*/, Promise.reject(this.errorFactory_.create(errors_1.default.codes.BAD_SENDER_ID))];
return [2 /*return*/, Promise.reject(this.errorFactory_.create(errors_1.ERROR_CODES.BAD_SENDER_ID))];
}

@@ -113,3 +113,3 @@ }

input.fcmPushSet.length === 0) {
return [2 /*return*/, Promise.reject(this.errorFactory_.create(errors_1.default.codes.BAD_PUSH_SET))];
return [2 /*return*/, Promise.reject(this.errorFactory_.create(errors_1.ERROR_CODES.BAD_PUSH_SET))];
}

@@ -129,3 +129,3 @@ }

if (!fcmToken) {
return Promise.reject(this.errorFactory_.create(errors_1.default.codes.BAD_TOKEN));
return Promise.reject(this.errorFactory_.create(errors_1.ERROR_CODES.BAD_TOKEN));
}

@@ -164,3 +164,3 @@ return this.validateInputs_({ fcmToken: fcmToken })

if (!swScope) {
return Promise.reject(this.errorFactory_.create(errors_1.default.codes.BAD_SCOPE));
return Promise.reject(this.errorFactory_.create(errors_1.ERROR_CODES.BAD_SCOPE));
}

@@ -199,18 +199,18 @@ return this.validateInputs_({ swScope: swScope })

if (!swScope) {
return Promise.reject(this.errorFactory_.create(errors_1.default.codes.BAD_SCOPE));
return Promise.reject(this.errorFactory_.create(errors_1.ERROR_CODES.BAD_SCOPE));
}
if (!vapidKey) {
return Promise.reject(this.errorFactory_.create(errors_1.default.codes.BAD_VAPID_KEY));
return Promise.reject(this.errorFactory_.create(errors_1.ERROR_CODES.BAD_VAPID_KEY));
}
if (!subscription) {
return Promise.reject(this.errorFactory_.create(errors_1.default.codes.BAD_SUBSCRIPTION));
return Promise.reject(this.errorFactory_.create(errors_1.ERROR_CODES.BAD_SUBSCRIPTION));
}
if (!fcmSenderId) {
return Promise.reject(this.errorFactory_.create(errors_1.default.codes.BAD_SENDER_ID));
return Promise.reject(this.errorFactory_.create(errors_1.ERROR_CODES.BAD_SENDER_ID));
}
if (!fcmToken) {
return Promise.reject(this.errorFactory_.create(errors_1.default.codes.BAD_TOKEN));
return Promise.reject(this.errorFactory_.create(errors_1.ERROR_CODES.BAD_TOKEN));
}
if (!fcmPushSet) {
return Promise.reject(this.errorFactory_.create(errors_1.default.codes.BAD_PUSH_SET));
return Promise.reject(this.errorFactory_.create(errors_1.ERROR_CODES.BAD_PUSH_SET));
}

@@ -234,6 +234,6 @@ return this.validateInputs_({

swScope: swScope,
vapidKey: array_buffer_to_base64_1.default(vapidKey),
vapidKey: array_buffer_to_base64_1.arrayBufferToBase64(vapidKey),
endpoint: subscription.endpoint,
auth: array_buffer_to_base64_1.default(subscription['getKey']('auth')),
p256dh: array_buffer_to_base64_1.default(subscription['getKey']('p256dh')),
auth: array_buffer_to_base64_1.arrayBufferToBase64(subscription['getKey']('auth')),
p256dh: array_buffer_to_base64_1.arrayBufferToBase64(subscription['getKey']('p256dh')),
fcmSenderId: fcmSenderId,

@@ -267,7 +267,7 @@ fcmToken: fcmToken,

if (typeof token !== 'string' || token.length === 0) {
return Promise.reject(this.errorFactory_.create(errors_1.default.codes.INVALID_DELETE_TOKEN));
return Promise.reject(this.errorFactory_.create(errors_1.ERROR_CODES.INVALID_DELETE_TOKEN));
}
return this.getTokenDetailsFromToken(token).then(function (details) {
if (!details) {
throw _this.errorFactory_.create(errors_1.default.codes.DELETE_TOKEN_NOT_FOUND);
throw _this.errorFactory_.create(errors_1.ERROR_CODES.DELETE_TOKEN_NOT_FOUND);
}

@@ -284,3 +284,3 @@ return _this.openDatabase().then(function (db) {

if (event.target.result === 0) {
reject(_this.errorFactory_.create(errors_1.default.codes.FAILED_TO_DELETE_TOKEN));
reject(_this.errorFactory_.create(errors_1.ERROR_CODES.FAILED_TO_DELETE_TOKEN));
return;

@@ -295,5 +295,5 @@ }

return TokenDetailsModel;
}(db_interface_1.default));
exports.default = TokenDetailsModel;
}(db_interface_1.DBInterface));
exports.TokenDetailsModel = TokenDetailsModel;
//# sourceMappingURL=token-details-model.js.map

@@ -1,3 +0,18 @@

import DBInterface from './db-interface';
export default class VapidDetailsModel extends DBInterface {
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { DBInterface } from './db-interface';
export declare class VapidDetailsModel extends DBInterface {
constructor();

@@ -4,0 +19,0 @@ /**

@@ -0,1 +1,2 @@

"use strict";
/**

@@ -16,3 +17,2 @@ * Copyright 2017 Google Inc.

*/
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });

@@ -46,3 +46,3 @@ var tslib_1 = require("tslib");

if (typeof swScope !== 'string' || swScope.length === 0) {
return Promise.reject(this.errorFactory_.create(errors_1.default.codes.BAD_SCOPE));
return Promise.reject(this.errorFactory_.create(errors_1.ERROR_CODES.BAD_SCOPE));
}

@@ -74,6 +74,6 @@ return this.openDatabase().then(function (db) {

if (typeof swScope !== 'string' || swScope.length === 0) {
return Promise.reject(this.errorFactory_.create(errors_1.default.codes.BAD_SCOPE));
return Promise.reject(this.errorFactory_.create(errors_1.ERROR_CODES.BAD_SCOPE));
}
if (vapidKey === null || vapidKey.length !== UNCOMPRESSED_PUBLIC_KEY_SIZE) {
return Promise.reject(this.errorFactory_.create(errors_1.default.codes.BAD_VAPID_KEY));
return Promise.reject(this.errorFactory_.create(errors_1.ERROR_CODES.BAD_VAPID_KEY));
}

@@ -107,3 +107,3 @@ var details = {

if (!vapidKey) {
throw _this.errorFactory_.create(errors_1.default.codes.DELETE_SCOPE_NOT_FOUND);
throw _this.errorFactory_.create(errors_1.ERROR_CODES.DELETE_SCOPE_NOT_FOUND);
}

@@ -120,3 +120,3 @@ return _this.openDatabase().then(function (db) {

if (request.result === 0) {
reject(_this.errorFactory_.create(errors_1.default.codes.FAILED_DELETE_VAPID_KEY));
reject(_this.errorFactory_.create(errors_1.ERROR_CODES.FAILED_DELETE_VAPID_KEY));
return;

@@ -131,5 +131,5 @@ }

return VapidDetailsModel;
}(db_interface_1.default));
exports.default = VapidDetailsModel;
}(db_interface_1.DBInterface));
exports.VapidDetailsModel = VapidDetailsModel;
//# sourceMappingURL=vapid-details-model.js.map

@@ -0,1 +1,20 @@

/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const PARAMS: {
TYPE_OF_MSG: string;
DATA: string;
};
declare const _default: {

@@ -2,0 +21,0 @@ PARAMS: {

@@ -0,1 +1,2 @@

"use strict";
/**

@@ -16,7 +17,6 @@ * Copyright 2017 Google Inc.

*/
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
// These fields are strings to prevent closure from thinking goog.getMsg
// should be used to initialise the values
var PARAMS = {
exports.PARAMS = {
TYPE_OF_MSG: 'firebase-messaging-msg-type',

@@ -33,4 +33,4 @@ DATA: 'firebase-messaging-msg-data'

var message = (_a = {},
_a[PARAMS.TYPE_OF_MSG] = msgType,
_a[PARAMS.DATA] = msgData,
_a[exports.PARAMS.TYPE_OF_MSG] = msgType,
_a[exports.PARAMS.DATA] = msgData,
_a);

@@ -41,3 +41,3 @@ return message;

exports.default = {
PARAMS: PARAMS,
PARAMS: exports.PARAMS,
TYPES_OF_MSG: msgType,

@@ -44,0 +44,0 @@ createNewMsg: createNewMsg

@@ -16,5 +16,4 @@ /**

*/
'use strict';
import WindowController from './src/controllers/window-controller';
import SWController from './src/controllers/sw-controller';
import { WindowController } from './src/controllers/window-controller';
import { SWController } from './src/controllers/sw-controller';
import { firebase } from '@firebase/app';

@@ -21,0 +20,0 @@ export function registerMessaging(instance) {

@@ -1,6 +0,6 @@

import TokenDetailsModel from '../models/token-details-model';
import VapidDetailsModel from '../models/vapid-details-model';
import IIDModel from '../models/iid-model';
import { TokenDetailsModel } from '../models/token-details-model';
import { VapidDetailsModel } from '../models/vapid-details-model';
import { IIDModel } from '../models/iid-model';
export declare const TOKEN_EXPIRATION_MILLIS: number;
export default class ControllerInterface {
export declare class ControllerInterface {
app: any;

@@ -43,5 +43,10 @@ INTERNAL: any;

deleteToken(token: string): Promise<Boolean>;
/**
* This method will delete the token from the client database, and make a
* call to FCM to remove it from the server DB. Does not temper with the
* push subscription.
*/
private deleteTokenFromDB(token);
getSWRegistration_(): Promise<ServiceWorkerRegistration>;
getPublicVapidKey_(): Promise<Uint8Array>;
requestPermission(): void;
/**

@@ -51,2 +56,3 @@ * Gets a PushSubscription for the current user.

getPushSubscription(swRegistration: ServiceWorkerRegistration, publicVapidKey: Uint8Array): Promise<PushSubscription>;
requestPermission(): void;
/**

@@ -53,0 +59,0 @@ * @export

@@ -16,11 +16,10 @@ /**

*/
'use strict';
import * as tslib_1 from "tslib";
import { ErrorFactory } from '@firebase/util';
import Errors from '../models/errors';
import TokenDetailsModel from '../models/token-details-model';
import VapidDetailsModel from '../models/vapid-details-model';
import NOTIFICATION_PERMISSION from '../models/notification-permission';
import IIDModel from '../models/iid-model';
import arrayBufferToBase64 from '../helpers/array-buffer-to-base64';
import { ERROR_CODES, ERROR_MAP } from '../models/errors';
import { TokenDetailsModel } from '../models/token-details-model';
import { VapidDetailsModel } from '../models/vapid-details-model';
import { NotificationPermission } from '../models/notification-permission';
import { IIDModel } from '../models/iid-model';
import { arrayBufferToBase64 } from '../helpers/array-buffer-to-base64';
var SENDER_ID_OPTION_NAME = 'messagingSenderId';

@@ -36,6 +35,6 @@ // Database cache should be invalidated once a week.

var _this = this;
this.errorFactory_ = new ErrorFactory('messaging', 'Messaging', Errors.map);
this.errorFactory_ = new ErrorFactory('messaging', 'Messaging', ERROR_MAP);
if (!app.options[SENDER_ID_OPTION_NAME] ||
typeof app.options[SENDER_ID_OPTION_NAME] !== 'string') {
throw this.errorFactory_.create(Errors.codes.BAD_SENDER_ID);
throw this.errorFactory_.create(ERROR_CODES.BAD_SENDER_ID);
}

@@ -60,5 +59,5 @@ this.messagingSenderId_ = app.options[SENDER_ID_OPTION_NAME];

currentPermission = this.getNotificationPermission_();
if (currentPermission !== NOTIFICATION_PERMISSION.granted) {
if (currentPermission === NOTIFICATION_PERMISSION.denied) {
return [2 /*return*/, Promise.reject(this.errorFactory_.create(Errors.codes.NOTIFICATIONS_BLOCKED))];
if (currentPermission !== NotificationPermission.GRANTED) {
if (currentPermission === NotificationPermission.DENIED) {
return [2 /*return*/, Promise.reject(this.errorFactory_.create(ERROR_CODES.NOTIFICATIONS_BLOCKED))];
}

@@ -114,7 +113,11 @@ // We must wait for permission to be granted

// If the token is no longer valid (for example if the VAPID details
// have changed), delete the existing token, and create a new one.
return [4 /*yield*/, this.deleteToken(tokenDetails['fcmToken'])];
// have changed), delete the existing token from the FCM client and server
// database. No need to unsubscribe from the Service Worker as we have a
// good push subscription that we'd like to use in getNewToken.
return [4 /*yield*/, this.deleteTokenFromDB(tokenDetails['fcmToken'])];
case 1:
// If the token is no longer valid (for example if the VAPID details
// have changed), delete the existing token, and create a new one.
// have changed), delete the existing token from the FCM client and server
// database. No need to unsubscribe from the Service Worker as we have a
// good push subscription that we'd like to use in getNewToken.
_a.sent();

@@ -212,18 +215,47 @@ return [2 /*return*/, this.getNewToken(swReg, pushSubscription, publicVapidKey)];

ControllerInterface.prototype.deleteToken = function (token) {
var _this = this;
return this.tokenDetailsModel_
.deleteToken(token)
.then(function (details) {
return _this.iidModel_.deleteToken(details['fcmSenderId'], details['fcmToken'], details['fcmPushSet']);
})
.then(function () {
return _this.getSWRegistration_()
.then(function (registration) {
if (registration) {
return registration.pushManager.getSubscription();
return tslib_1.__awaiter(this, void 0, void 0, function () {
var registration, pushSubscription;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
// Delete the token details from the database.
return [4 /*yield*/, this.deleteTokenFromDB(token)];
case 1:
// Delete the token details from the database.
_a.sent();
return [4 /*yield*/, this.getSWRegistration_()];
case 2:
registration = _a.sent();
if (!registration) return [3 /*break*/, 4];
return [4 /*yield*/, registration.pushManager.getSubscription()];
case 3:
pushSubscription = _a.sent();
if (pushSubscription) {
return [2 /*return*/, pushSubscription.unsubscribe()];
}
_a.label = 4;
case 4:
// If there's no SW, consider it a success.
return [2 /*return*/, true];
}
})
.then(function (subscription) {
if (subscription) {
return subscription.unsubscribe();
});
});
};
/**
* This method will delete the token from the client database, and make a
* call to FCM to remove it from the server DB. Does not temper with the
* push subscription.
*/
ControllerInterface.prototype.deleteTokenFromDB = function (token) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var details;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.tokenDetailsModel_.deleteToken(token)];
case 1:
details = _a.sent();
return [4 /*yield*/, this.iidModel_.deleteToken(details['fcmSenderId'], details['fcmToken'], details['fcmPushSet'])];
case 2:
_a.sent();
return [2 /*return*/];
}

@@ -234,13 +266,7 @@ });

ControllerInterface.prototype.getSWRegistration_ = function () {
throw this.errorFactory_.create(Errors.codes.SHOULD_BE_INHERITED);
throw this.errorFactory_.create(ERROR_CODES.SHOULD_BE_INHERITED);
};
ControllerInterface.prototype.getPublicVapidKey_ = function () {
throw this.errorFactory_.create(Errors.codes.SHOULD_BE_INHERITED);
throw this.errorFactory_.create(ERROR_CODES.SHOULD_BE_INHERITED);
};
//
// The following methods should only be available in the window.
//
ControllerInterface.prototype.requestPermission = function () {
throw this.errorFactory_.create(Errors.codes.AVAILABLE_IN_WINDOW);
};
/**

@@ -260,2 +286,8 @@ * Gets a PushSubscription for the current user.

};
//
// The following methods should only be available in the window.
//
ControllerInterface.prototype.requestPermission = function () {
throw this.errorFactory_.create(ERROR_CODES.AVAILABLE_IN_WINDOW);
};
/**

@@ -266,3 +298,3 @@ * @export

ControllerInterface.prototype.useServiceWorker = function (registration) {
throw this.errorFactory_.create(Errors.codes.AVAILABLE_IN_WINDOW);
throw this.errorFactory_.create(ERROR_CODES.AVAILABLE_IN_WINDOW);
};

@@ -274,3 +306,3 @@ /**

ControllerInterface.prototype.usePublicVapidKey = function (b64PublicKey) {
throw this.errorFactory_.create(Errors.codes.AVAILABLE_IN_WINDOW);
throw this.errorFactory_.create(ERROR_CODES.AVAILABLE_IN_WINDOW);
};

@@ -285,3 +317,3 @@ /**

ControllerInterface.prototype.onMessage = function (nextOrObserver, optError, optCompleted) {
throw this.errorFactory_.create(Errors.codes.AVAILABLE_IN_WINDOW);
throw this.errorFactory_.create(ERROR_CODES.AVAILABLE_IN_WINDOW);
};

@@ -299,3 +331,3 @@ /**

ControllerInterface.prototype.onTokenRefresh = function (nextOrObserver, optError, optCompleted) {
throw this.errorFactory_.create(Errors.codes.AVAILABLE_IN_WINDOW);
throw this.errorFactory_.create(ERROR_CODES.AVAILABLE_IN_WINDOW);
};

@@ -310,3 +342,3 @@ //

ControllerInterface.prototype.setBackgroundMessageHandler = function (callback) {
throw this.errorFactory_.create(Errors.codes.AVAILABLE_IN_SW);
throw this.errorFactory_.create(ERROR_CODES.AVAILABLE_IN_SW);
};

@@ -350,4 +382,4 @@ //

}());
export default ControllerInterface;
export { ControllerInterface };
//# sourceMappingURL=controller-interface.js.map

@@ -1,3 +0,18 @@

import ControllerInterface from './controller-interface';
export default class SWController extends ControllerInterface {
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ControllerInterface } from './controller-interface';
export declare class SWController extends ControllerInterface {
private bgMessageHandler_;

@@ -65,3 +80,3 @@ constructor(app: any);

*/
attemptToMessageClient_(client: any, message: any): Promise<never>;
attemptToMessageClient_(client: any, message: any): Promise<undefined>;
/**

@@ -68,0 +83,0 @@ * @private

@@ -16,7 +16,6 @@ /**

*/
'use strict';
import * as tslib_1 from "tslib";
import ControllerInterface from './controller-interface';
import Errors from '../models/errors';
import FCMDetails from '../models/fcm-details';
import { ControllerInterface } from './controller-interface';
import { ERROR_CODES } from '../models/errors';
import { DEFAULT_PUBLIC_VAPID_KEY } from '../models/fcm-details';
import WorkerPageMessage from '../models/worker-page-message';

@@ -28,10 +27,6 @@ var FCM_MSG = 'FCM_MSG';

var _this = _super.call(this, app) || this;
_this.bgMessageHandler_ = null;
self.addEventListener('push', function (e) { return _this.onPush_(e); }, false);
self.addEventListener('pushsubscriptionchange', function (e) { return _this.onSubChange_(e); }, false);
self.addEventListener('notificationclick', function (e) { return _this.onNotificationClick_(e); }, false);
/**
* @private
* @type {function(Object)|null}
*/
_this.bgMessageHandler_ = null;
return _this;

@@ -117,3 +112,3 @@ }

.catch(function (err) {
throw _this.errorFactory_.create(Errors.codes.UNABLE_TO_RESUBSCRIBE, {
throw _this.errorFactory_.create(ERROR_CODES.UNABLE_TO_RESUBSCRIBE, {
message: err

@@ -211,3 +206,3 @@ });

if (!callback || typeof callback !== 'function') {
throw this.errorFactory_.create(Errors.codes.BG_HANDLER_FUNCTION_EXPECTED);
throw this.errorFactory_.create(ERROR_CODES.BG_HANDLER_FUNCTION_EXPECTED);
}

@@ -261,3 +256,3 @@ this.bgMessageHandler_ = callback;

if (!client) {
return [2 /*return*/, Promise.reject(this.errorFactory_.create(Errors.codes.NO_WINDOW_CLIENT_TO_MSG))];
return [2 /*return*/, Promise.reject(this.errorFactory_.create(ERROR_CODES.NO_WINDOW_CLIENT_TO_MSG))];
}

@@ -326,3 +321,3 @@ client.postMessage(message);

if (vapidKeyFromDatabase === null) {
return FCMDetails.DEFAULT_PUBLIC_VAPID_KEY;
return DEFAULT_PUBLIC_VAPID_KEY;
}

@@ -334,4 +329,4 @@ return vapidKeyFromDatabase;

}(ControllerInterface));
export default SWController;
export { SWController };
//# sourceMappingURL=sw-controller.js.map

@@ -0,4 +1,19 @@

/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { FirebaseMessaging } from '@firebase/messaging-types';
import ControllerInterface from './controller-interface';
export default class WindowController extends ControllerInterface implements FirebaseMessaging {
import { ControllerInterface } from './controller-interface';
export declare class WindowController extends ControllerInterface implements FirebaseMessaging {
private registrationToUse_;

@@ -40,3 +55,3 @@ private publicVapidKeyToUse_;

*/
requestPermission(): Promise<{}>;
requestPermission(): Promise<{} | undefined>;
/**

@@ -43,0 +58,0 @@ * This method allows a developer to override the default service worker and

@@ -16,11 +16,10 @@ /**

*/
'use strict';
import * as tslib_1 from "tslib";
import ControllerInterface from './controller-interface';
import Errors from '../models/errors';
import { ControllerInterface } from './controller-interface';
import { ERROR_CODES } from '../models/errors';
import WorkerPageMessage from '../models/worker-page-message';
import DefaultSW from '../models/default-sw';
import NOTIFICATION_PERMISSION from '../models/notification-permission';
import FCMDetails from '../models/fcm-details';
import base64ToArrayBuffer from '../helpers/base64-to-array-buffer';
import { DEFAULT_SW_PATH, DEFAULT_SW_SCOPE } from '../models/default-sw';
import { NotificationPermission } from '../models/notification-permission';
import { DEFAULT_PUBLIC_VAPID_KEY } from '../models/fcm-details';
import { base64ToArrayBuffer } from '../helpers/base64-to-array-buffer';
import { createSubscribe } from '@firebase/util';

@@ -89,3 +88,3 @@ var WindowController = /** @class */ (function (_super) {

if (!this.isSupported_()) {
return Promise.reject(this.errorFactory_.create(Errors.codes.UNSUPPORTED_BROWSER));
return Promise.reject(this.errorFactory_.create(ERROR_CODES.UNSUPPORTED_BROWSER));
}

@@ -129,3 +128,3 @@ return this.manifestCheck_().then(function () {

if (manifestContent['gcm_sender_id'] !== '103953800507') {
throw _this.errorFactory_.create(Errors.codes.INCORRECT_GCM_SENDER_ID);
throw _this.errorFactory_.create(ERROR_CODES.INCORRECT_GCM_SENDER_ID);
}

@@ -146,3 +145,3 @@ });

return tslib_1.__generator(this, function (_a) {
if (Notification.permission === NOTIFICATION_PERMISSION.granted) {
if (Notification.permission === NotificationPermission.GRANTED) {
return [2 /*return*/];

@@ -152,10 +151,10 @@ }

var managePermissionResult = function (result) {
if (result === NOTIFICATION_PERMISSION.granted) {
if (result === NotificationPermission.GRANTED) {
return resolve();
}
else if (result === NOTIFICATION_PERMISSION.denied) {
return reject(_this.errorFactory_.create(Errors.codes.PERMISSION_BLOCKED));
else if (result === NotificationPermission.DENIED) {
return reject(_this.errorFactory_.create(ERROR_CODES.PERMISSION_BLOCKED));
}
else {
return reject(_this.errorFactory_.create(Errors.codes.PERMISSION_DEFAULT));
return reject(_this.errorFactory_.create(ERROR_CODES.PERMISSION_DEFAULT));
}

@@ -184,6 +183,6 @@ };

if (!(registration instanceof ServiceWorkerRegistration)) {
throw this.errorFactory_.create(Errors.codes.SW_REGISTRATION_EXPECTED);
throw this.errorFactory_.create(ERROR_CODES.SW_REGISTRATION_EXPECTED);
}
if (typeof this.registrationToUse_ !== 'undefined') {
throw this.errorFactory_.create(Errors.codes.USE_SW_BEFORE_GET_TOKEN);
throw this.errorFactory_.create(ERROR_CODES.USE_SW_BEFORE_GET_TOKEN);
}

@@ -200,10 +199,10 @@ this.registrationToUse_ = registration;

if (typeof publicKey !== 'string') {
throw this.errorFactory_.create(Errors.codes.INVALID_PUBLIC_VAPID_KEY);
throw this.errorFactory_.create(ERROR_CODES.INVALID_PUBLIC_VAPID_KEY);
}
if (typeof this.publicVapidKeyToUse_ !== 'undefined') {
throw this.errorFactory_.create(Errors.codes.USE_PUBLIC_KEY_BEFORE_GET_TOKEN);
throw this.errorFactory_.create(ERROR_CODES.USE_PUBLIC_KEY_BEFORE_GET_TOKEN);
}
var parsedKey = base64ToArrayBuffer(publicKey);
if (parsedKey.length !== 65) {
throw this.errorFactory_.create(Errors.codes.PUBLIC_KEY_DECRYPTION_FAILED);
throw this.errorFactory_.create(ERROR_CODES.PUBLIC_KEY_DECRYPTION_FAILED);
}

@@ -253,3 +252,3 @@ this.publicVapidKeyToUse_ = parsedKey;

// This is a rare scenario but has occured in firefox
reject(_this.errorFactory_.create(Errors.codes.NO_SW_IN_REG));
reject(_this.errorFactory_.create(ERROR_CODES.NO_SW_IN_REG));
return;

@@ -264,3 +263,3 @@ }

if (serviceWorker.state === 'redundant') {
reject(_this.errorFactory_.create(Errors.codes.SW_REG_REDUNDANT));
reject(_this.errorFactory_.create(ERROR_CODES.SW_REG_REDUNDANT));
return;

@@ -273,3 +272,3 @@ }

else if (serviceWorker.state === 'redundant') {
reject(_this.errorFactory_.create(Errors.codes.SW_REG_REDUNDANT));
reject(_this.errorFactory_.create(ERROR_CODES.SW_REG_REDUNDANT));
}

@@ -300,7 +299,7 @@ else {

return navigator.serviceWorker
.register(DefaultSW.path, {
scope: DefaultSW.scope
.register(DEFAULT_SW_PATH, {
scope: DEFAULT_SW_SCOPE
})
.catch(function (err) {
throw _this.errorFactory_.create(Errors.codes.FAILED_DEFAULT_REGISTRATION, {
throw _this.errorFactory_.create(ERROR_CODES.FAILED_DEFAULT_REGISTRATION, {
browserErrorMessage: err.message

@@ -329,3 +328,3 @@ });

}
return Promise.resolve(FCMDetails.DEFAULT_PUBLIC_VAPID_KEY);
return Promise.resolve(DEFAULT_PUBLIC_VAPID_KEY);
};

@@ -379,4 +378,4 @@ /**

}(ControllerInterface));
export default WindowController;
export { WindowController };
//# sourceMappingURL=window-controller.js.map

@@ -1,2 +0,1 @@

declare const _default: (arrayBuffer: any) => string;
export default _default;
export declare function arrayBufferToBase64(arrayBuffer: any): string;

@@ -18,5 +18,5 @@ /**

var uint8Version = new Uint8Array(arrayBuffer);
return window.btoa(String.fromCharCode.apply(null, uint8Version));
return btoa(String.fromCharCode.apply(null, uint8Version));
}
export default (function (arrayBuffer) {
export function arrayBufferToBase64(arrayBuffer) {
var base64String = toBase64(arrayBuffer);

@@ -27,4 +27,4 @@ return base64String

.replace(/\//g, '_');
});
}
//# sourceMappingURL=array-buffer-to-base64.js.map

@@ -1,2 +0,16 @@

declare const _default: (base64String: any) => Uint8Array;
export default _default;
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare function base64ToArrayBuffer(base64String: any): Uint8Array;

@@ -16,3 +16,3 @@ /**

*/
export default (function (base64String) {
export function base64ToArrayBuffer(base64String) {
var padding = '='.repeat((4 - base64String.length % 4) % 4);

@@ -28,4 +28,4 @@ var base64 = (base64String + padding)

return outputArray;
});
}
//# sourceMappingURL=base64-to-array-buffer.js.map

@@ -27,3 +27,3 @@ /**

*/
import IIDModel from '../models/iid-model';
import { IIDModel } from '../models/iid-model';
var OLD_DB_NAME = 'undefined';

@@ -30,0 +30,0 @@ var OLD_OBJECT_STORE_NAME = 'fcm_token_object_Store';

@@ -0,3 +1,18 @@

/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ErrorFactory } from '@firebase/util';
export default class DBInterface {
export declare class DBInterface {
private DB_NAME_;

@@ -4,0 +19,0 @@ private dbVersion_;

@@ -16,5 +16,4 @@ /**

*/
'use strict';
import { ErrorFactory } from '@firebase/util';
import Errors from './errors';
import { ERROR_CODES, ERROR_MAP } from './errors';
var DBInterface = /** @class */ (function () {

@@ -26,3 +25,3 @@ /**

function DBInterface(dbName, dbVersion) {
this.errorFactory_ = new ErrorFactory('messaging', 'Messaging', Errors.map);
this.errorFactory_ = new ErrorFactory('messaging', 'Messaging', ERROR_MAP);
this.DB_NAME_ = dbName;

@@ -85,8 +84,8 @@ this.dbVersion_ = dbVersion;

DBInterface.prototype.onDBUpgrade = function (db, event) {
throw this.errorFactory_.create(Errors.codes.SHOULD_BE_INHERITED);
throw this.errorFactory_.create(ERROR_CODES.SHOULD_BE_INHERITED);
};
return DBInterface;
}());
export default DBInterface;
export { DBInterface };
//# sourceMappingURL=db-interface.js.map

@@ -1,5 +0,17 @@

declare const _default: {
path: string;
scope: string;
};
export default _default;
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const DEFAULT_SW_PATH = "/firebase-messaging-sw.js";
export declare const DEFAULT_SW_SCOPE = "/firebase-cloud-messaging-push-scope";

@@ -16,8 +16,5 @@ /**

*/
'use strict';
export default {
path: '/firebase-messaging-sw.js',
scope: '/firebase-cloud-messaging-push-scope'
};
export var DEFAULT_SW_PATH = '/firebase-messaging-sw.js';
export var DEFAULT_SW_SCOPE = '/firebase-cloud-messaging-push-scope';
//# sourceMappingURL=default-sw.js.map

@@ -1,47 +0,59 @@

declare const _default: {
codes: {
AVAILABLE_IN_WINDOW: string;
AVAILABLE_IN_SW: string;
SHOULD_BE_INHERITED: string;
BAD_SENDER_ID: string;
INCORRECT_GCM_SENDER_ID: string;
PERMISSION_DEFAULT: string;
PERMISSION_BLOCKED: string;
UNSUPPORTED_BROWSER: string;
NOTIFICATIONS_BLOCKED: string;
FAILED_DEFAULT_REGISTRATION: string;
SW_REGISTRATION_EXPECTED: string;
GET_SUBSCRIPTION_FAILED: string;
INVALID_SAVED_TOKEN: string;
SW_REG_REDUNDANT: string;
TOKEN_SUBSCRIBE_FAILED: string;
TOKEN_SUBSCRIBE_NO_TOKEN: string;
TOKEN_SUBSCRIBE_NO_PUSH_SET: string;
TOKEN_UNSUBSCRIBE_FAILED: string;
TOKEN_UPDATE_FAILED: string;
TOKEN_UPDATE_NO_TOKEN: string;
USE_SW_BEFORE_GET_TOKEN: string;
INVALID_DELETE_TOKEN: string;
DELETE_TOKEN_NOT_FOUND: string;
DELETE_SCOPE_NOT_FOUND: string;
BG_HANDLER_FUNCTION_EXPECTED: string;
NO_WINDOW_CLIENT_TO_MSG: string;
UNABLE_TO_RESUBSCRIBE: string;
NO_FCM_TOKEN_FOR_RESUBSCRIBE: string;
FAILED_TO_DELETE_TOKEN: string;
NO_SW_IN_REG: string;
BAD_SCOPE: string;
BAD_VAPID_KEY: string;
BAD_SUBSCRIPTION: string;
BAD_TOKEN: string;
BAD_PUSH_SET: string;
FAILED_DELETE_VAPID_KEY: string;
INVALID_PUBLIC_VAPID_KEY: string;
USE_PUBLIC_KEY_BEFORE_GET_TOKEN: string;
PUBLIC_KEY_DECRYPTION_FAILED: string;
};
map: {
[x: string]: string;
};
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const ERROR_CODES: {
AVAILABLE_IN_WINDOW: string;
AVAILABLE_IN_SW: string;
SHOULD_BE_INHERITED: string;
BAD_SENDER_ID: string;
INCORRECT_GCM_SENDER_ID: string;
PERMISSION_DEFAULT: string;
PERMISSION_BLOCKED: string;
UNSUPPORTED_BROWSER: string;
NOTIFICATIONS_BLOCKED: string;
FAILED_DEFAULT_REGISTRATION: string;
SW_REGISTRATION_EXPECTED: string;
GET_SUBSCRIPTION_FAILED: string;
INVALID_SAVED_TOKEN: string;
SW_REG_REDUNDANT: string;
TOKEN_SUBSCRIBE_FAILED: string;
TOKEN_SUBSCRIBE_NO_TOKEN: string;
TOKEN_SUBSCRIBE_NO_PUSH_SET: string;
TOKEN_UNSUBSCRIBE_FAILED: string;
TOKEN_UPDATE_FAILED: string;
TOKEN_UPDATE_NO_TOKEN: string;
USE_SW_BEFORE_GET_TOKEN: string;
INVALID_DELETE_TOKEN: string;
DELETE_TOKEN_NOT_FOUND: string;
DELETE_SCOPE_NOT_FOUND: string;
BG_HANDLER_FUNCTION_EXPECTED: string;
NO_WINDOW_CLIENT_TO_MSG: string;
UNABLE_TO_RESUBSCRIBE: string;
NO_FCM_TOKEN_FOR_RESUBSCRIBE: string;
FAILED_TO_DELETE_TOKEN: string;
NO_SW_IN_REG: string;
BAD_SCOPE: string;
BAD_VAPID_KEY: string;
BAD_SUBSCRIPTION: string;
BAD_TOKEN: string;
BAD_PUSH_SET: string;
FAILED_DELETE_VAPID_KEY: string;
INVALID_PUBLIC_VAPID_KEY: string;
USE_PUBLIC_KEY_BEFORE_GET_TOKEN: string;
PUBLIC_KEY_DECRYPTION_FAILED: string;
};
export default _default;
export declare const ERROR_MAP: {
[x: string]: string;
};

@@ -16,4 +16,3 @@ /**

*/
'use strict';
var CODES = {
export var ERROR_CODES = {
AVAILABLE_IN_WINDOW: 'only-available-in-window',

@@ -59,65 +58,61 @@ AVAILABLE_IN_SW: 'only-available-in-sw',

};
var ERROR_MAP = (_a = {},
_a[CODES.AVAILABLE_IN_WINDOW] = 'This method is available in a Window context.',
_a[CODES.AVAILABLE_IN_SW] = 'This method is available in a service worker ' + 'context.',
_a[CODES.SHOULD_BE_INHERITED] = 'This method should be overriden by ' + 'extended classes.',
_a[CODES.BAD_SENDER_ID] = "Please ensure that 'messagingSenderId' is set " +
export var ERROR_MAP = (_a = {},
_a[ERROR_CODES.AVAILABLE_IN_WINDOW] = 'This method is available in a Window context.',
_a[ERROR_CODES.AVAILABLE_IN_SW] = 'This method is available in a service worker ' + 'context.',
_a[ERROR_CODES.SHOULD_BE_INHERITED] = 'This method should be overriden by ' + 'extended classes.',
_a[ERROR_CODES.BAD_SENDER_ID] = "Please ensure that 'messagingSenderId' is set " +
'correctly in the options passed into firebase.initializeApp().',
_a[CODES.PERMISSION_DEFAULT] = 'The required permissions were not granted and ' + 'dismissed instead.',
_a[CODES.PERMISSION_BLOCKED] = 'The required permissions were not granted and ' + 'blocked instead.',
_a[CODES.UNSUPPORTED_BROWSER] = "This browser doesn't support the API's " +
_a[ERROR_CODES.PERMISSION_DEFAULT] = 'The required permissions were not granted and ' + 'dismissed instead.',
_a[ERROR_CODES.PERMISSION_BLOCKED] = 'The required permissions were not granted and ' + 'blocked instead.',
_a[ERROR_CODES.UNSUPPORTED_BROWSER] = "This browser doesn't support the API's " +
'required to use the firebase SDK.',
_a[CODES.NOTIFICATIONS_BLOCKED] = 'Notifications have been blocked.',
_a[CODES.FAILED_DEFAULT_REGISTRATION] = 'We are unable to register the ' +
_a[ERROR_CODES.NOTIFICATIONS_BLOCKED] = 'Notifications have been blocked.',
_a[ERROR_CODES.FAILED_DEFAULT_REGISTRATION] = 'We are unable to register the ' +
'default service worker. {$browserErrorMessage}',
_a[CODES.SW_REGISTRATION_EXPECTED] = 'A service worker registration was the ' + 'expected input.',
_a[CODES.GET_SUBSCRIPTION_FAILED] = 'There was an error when trying to get ' +
_a[ERROR_CODES.SW_REGISTRATION_EXPECTED] = 'A service worker registration was the ' + 'expected input.',
_a[ERROR_CODES.GET_SUBSCRIPTION_FAILED] = 'There was an error when trying to get ' +
'any existing Push Subscriptions.',
_a[CODES.INVALID_SAVED_TOKEN] = 'Unable to access details of the saved token.',
_a[CODES.SW_REG_REDUNDANT] = 'The service worker being used for push was made ' + 'redundant.',
_a[CODES.TOKEN_SUBSCRIBE_FAILED] = 'A problem occured while subscribing the ' + 'user to FCM: {$message}',
_a[CODES.TOKEN_SUBSCRIBE_NO_TOKEN] = 'FCM returned no token when subscribing ' + 'the user to push.',
_a[CODES.TOKEN_SUBSCRIBE_NO_PUSH_SET] = 'FCM returned an invalid response ' + 'when getting an FCM token.',
_a[CODES.TOKEN_UNSUBSCRIBE_FAILED] = 'A problem occured while unsubscribing the ' + 'user from FCM: {$message}',
_a[CODES.TOKEN_UPDATE_FAILED] = 'A problem occured while updating the ' + 'user from FCM: {$message}',
_a[CODES.TOKEN_UPDATE_NO_TOKEN] = 'FCM returned no token when updating ' + 'the user to push.',
_a[CODES.USE_SW_BEFORE_GET_TOKEN] = 'The useServiceWorker() method may only be called once and must be ' +
_a[ERROR_CODES.INVALID_SAVED_TOKEN] = 'Unable to access details of the saved token.',
_a[ERROR_CODES.SW_REG_REDUNDANT] = 'The service worker being used for push was made ' + 'redundant.',
_a[ERROR_CODES.TOKEN_SUBSCRIBE_FAILED] = 'A problem occured while subscribing the ' + 'user to FCM: {$message}',
_a[ERROR_CODES.TOKEN_SUBSCRIBE_NO_TOKEN] = 'FCM returned no token when subscribing ' + 'the user to push.',
_a[ERROR_CODES.TOKEN_SUBSCRIBE_NO_PUSH_SET] = 'FCM returned an invalid response ' + 'when getting an FCM token.',
_a[ERROR_CODES.TOKEN_UNSUBSCRIBE_FAILED] = 'A problem occured while unsubscribing the ' + 'user from FCM: {$message}',
_a[ERROR_CODES.TOKEN_UPDATE_FAILED] = 'A problem occured while updating the ' + 'user from FCM: {$message}',
_a[ERROR_CODES.TOKEN_UPDATE_NO_TOKEN] = 'FCM returned no token when updating ' + 'the user to push.',
_a[ERROR_CODES.USE_SW_BEFORE_GET_TOKEN] = 'The useServiceWorker() method may only be called once and must be ' +
'called before calling getToken() to ensure your service worker is used.',
_a[CODES.INVALID_DELETE_TOKEN] = 'You must pass a valid token into ' +
_a[ERROR_CODES.INVALID_DELETE_TOKEN] = 'You must pass a valid token into ' +
'deleteToken(), i.e. the token from getToken().',
_a[CODES.DELETE_TOKEN_NOT_FOUND] = 'The deletion attempt for token could not ' +
_a[ERROR_CODES.DELETE_TOKEN_NOT_FOUND] = 'The deletion attempt for token could not ' +
'be performed as the token was not found.',
_a[CODES.DELETE_SCOPE_NOT_FOUND] = 'The deletion attempt for service worker ' +
_a[ERROR_CODES.DELETE_SCOPE_NOT_FOUND] = 'The deletion attempt for service worker ' +
'scope could not be performed as the scope was not found.',
_a[CODES.BG_HANDLER_FUNCTION_EXPECTED] = 'The input to ' + 'setBackgroundMessageHandler() must be a function.',
_a[CODES.NO_WINDOW_CLIENT_TO_MSG] = 'An attempt was made to message a ' + 'non-existant window client.',
_a[CODES.UNABLE_TO_RESUBSCRIBE] = 'There was an error while re-subscribing ' +
_a[ERROR_CODES.BG_HANDLER_FUNCTION_EXPECTED] = 'The input to ' + 'setBackgroundMessageHandler() must be a function.',
_a[ERROR_CODES.NO_WINDOW_CLIENT_TO_MSG] = 'An attempt was made to message a ' + 'non-existant window client.',
_a[ERROR_CODES.UNABLE_TO_RESUBSCRIBE] = 'There was an error while re-subscribing ' +
'the FCM token for push messaging. Will have to resubscribe the ' +
'user on next visit. {$message}',
_a[CODES.NO_FCM_TOKEN_FOR_RESUBSCRIBE] = 'Could not find an FCM token ' +
_a[ERROR_CODES.NO_FCM_TOKEN_FOR_RESUBSCRIBE] = 'Could not find an FCM token ' +
'and as a result, unable to resubscribe. Will have to resubscribe the ' +
'user on next visit.',
_a[CODES.FAILED_TO_DELETE_TOKEN] = 'Unable to delete the currently saved token.',
_a[CODES.NO_SW_IN_REG] = 'Even though the service worker registration was ' +
_a[ERROR_CODES.FAILED_TO_DELETE_TOKEN] = 'Unable to delete the currently saved token.',
_a[ERROR_CODES.NO_SW_IN_REG] = 'Even though the service worker registration was ' +
'successful, there was a problem accessing the service worker itself.',
_a[CODES.INCORRECT_GCM_SENDER_ID] = "Please change your web app manifest's " +
_a[ERROR_CODES.INCORRECT_GCM_SENDER_ID] = "Please change your web app manifest's " +
"'gcm_sender_id' value to '103953800507' to use Firebase messaging.",
_a[CODES.BAD_SCOPE] = 'The service worker scope must be a string with at ' +
_a[ERROR_CODES.BAD_SCOPE] = 'The service worker scope must be a string with at ' +
'least one character.',
_a[CODES.BAD_VAPID_KEY] = 'The public VAPID key is not a Uint8Array with 65 bytes.',
_a[CODES.BAD_SUBSCRIPTION] = 'The subscription must be a valid ' + 'PushSubscription.',
_a[CODES.BAD_TOKEN] = 'The FCM Token used for storage / lookup was not ' +
_a[ERROR_CODES.BAD_VAPID_KEY] = 'The public VAPID key is not a Uint8Array with 65 bytes.',
_a[ERROR_CODES.BAD_SUBSCRIPTION] = 'The subscription must be a valid ' + 'PushSubscription.',
_a[ERROR_CODES.BAD_TOKEN] = 'The FCM Token used for storage / lookup was not ' +
'a valid token string.',
_a[CODES.BAD_PUSH_SET] = 'The FCM push set used for storage / lookup was not ' +
_a[ERROR_CODES.BAD_PUSH_SET] = 'The FCM push set used for storage / lookup was not ' +
'not a valid push set string.',
_a[CODES.FAILED_DELETE_VAPID_KEY] = 'The VAPID key could not be deleted.',
_a[CODES.INVALID_PUBLIC_VAPID_KEY] = 'The public VAPID key must be a string.',
_a[CODES.PUBLIC_KEY_DECRYPTION_FAILED] = 'The public VAPID key did not equal ' + '65 bytes when decrypted.',
_a[ERROR_CODES.FAILED_DELETE_VAPID_KEY] = 'The VAPID key could not be deleted.',
_a[ERROR_CODES.INVALID_PUBLIC_VAPID_KEY] = 'The public VAPID key must be a string.',
_a[ERROR_CODES.PUBLIC_KEY_DECRYPTION_FAILED] = 'The public VAPID key did not equal ' + '65 bytes when decrypted.',
_a);
export default {
codes: CODES,
map: ERROR_MAP
};
var _a;
//# sourceMappingURL=errors.js.map

@@ -1,9 +0,21 @@

declare const _default: {
DEFAULT_PUBLIC_VAPID_KEY: Uint8Array;
SUBSCRIPTION_DETAILS: {
userVisibleOnly: boolean;
applicationServerKey: Uint8Array;
};
ENDPOINT: string;
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const DEFAULT_PUBLIC_VAPID_KEY: Uint8Array;
export declare const SUBSCRIPTION_DETAILS: {
userVisibleOnly: boolean;
applicationServerKey: Uint8Array;
};
export default _default;
export declare const ENDPOINT = "https://fcm.googleapis.com";

@@ -16,4 +16,3 @@ /**

*/
'use strict';
var DEFAULT_PUBLIC_VAPID_KEY = new Uint8Array([
export var DEFAULT_PUBLIC_VAPID_KEY = new Uint8Array([
0x04,

@@ -85,13 +84,8 @@ 0x33,

]);
var SUBSCRIPTION_DETAILS = {
export var SUBSCRIPTION_DETAILS = {
userVisibleOnly: true,
applicationServerKey: DEFAULT_PUBLIC_VAPID_KEY
};
export default {
DEFAULT_PUBLIC_VAPID_KEY: DEFAULT_PUBLIC_VAPID_KEY,
SUBSCRIPTION_DETAILS: SUBSCRIPTION_DETAILS,
ENDPOINT: 'https://fcm.googleapis.com'
// ENDPOINT: 'https://jmt17.google.com'
};
export var ENDPOINT = 'https://fcm.googleapis.com';
//# sourceMappingURL=fcm-details.js.map

@@ -1,15 +0,10 @@

export default class IIDModel {
export interface IIDDetails {
token: string;
pushSet: string;
}
export declare class IIDModel {
private errorFactory_;
constructor();
getToken(senderId: string, subscription: PushSubscription, publicVapidKey: Uint8Array): Promise<IIDDetails>;
/**
* Given a PushSubscription and messagingSenderId, get an FCM token.
* @public
* @param {string} senderId The 'messagingSenderId' to tie the token to.
* @param {PushSubscription} subscription The PushSusbcription to "federate".
* @param {Uint8Array} publicVapidKey The public VAPID key.
* @return {Promise<!Object>} Returns the FCM token to be used in place
* of the PushSubscription.
*/
getToken(senderId: any, subscription: any, publicVapidKey: any): Promise<Object>;
/**
* Update the underlying token details for fcmToken.

@@ -16,0 +11,0 @@ */

@@ -16,62 +16,68 @@ /**

*/
'use strict';
import * as tslib_1 from "tslib";
import { ErrorFactory } from '@firebase/util';
import Errors from './errors';
import arrayBufferToBase64 from '../helpers/array-buffer-to-base64';
import FCMDetails from './fcm-details';
import { ERROR_CODES, ERROR_MAP } from './errors';
import { arrayBufferToBase64 } from '../helpers/array-buffer-to-base64';
import { DEFAULT_PUBLIC_VAPID_KEY, ENDPOINT } from './fcm-details';
var IIDModel = /** @class */ (function () {
function IIDModel() {
this.errorFactory_ = new ErrorFactory('messaging', 'Messaging', Errors.map);
this.errorFactory_ = new ErrorFactory('messaging', 'Messaging', ERROR_MAP);
}
/**
* Given a PushSubscription and messagingSenderId, get an FCM token.
* @public
* @param {string} senderId The 'messagingSenderId' to tie the token to.
* @param {PushSubscription} subscription The PushSusbcription to "federate".
* @param {Uint8Array} publicVapidKey The public VAPID key.
* @return {Promise<!Object>} Returns the FCM token to be used in place
* of the PushSubscription.
*/
IIDModel.prototype.getToken = function (senderId, subscription, publicVapidKey) {
var _this = this;
var p256dh = arrayBufferToBase64(subscription['getKey']('p256dh'));
var auth = arrayBufferToBase64(subscription['getKey']('auth'));
var fcmSubscribeBody = "authorized_entity=" + senderId + "&" +
("endpoint=" + subscription.endpoint + "&") +
("encryption_key=" + p256dh + "&") +
("encryption_auth=" + auth);
if (publicVapidKey !== FCMDetails.DEFAULT_PUBLIC_VAPID_KEY) {
var applicationPubKey = arrayBufferToBase64(publicVapidKey);
fcmSubscribeBody += "&application_pub_key=" + applicationPubKey;
}
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
var subscribeOptions = {
method: 'POST',
headers: headers,
body: fcmSubscribeBody
};
return fetch(FCMDetails.ENDPOINT + '/fcm/connect/subscribe', subscribeOptions)
.then(function (response) { return response.json(); })
.catch(function () {
throw _this.errorFactory_.create(Errors.codes.TOKEN_SUBSCRIBE_FAILED);
})
.then(function (response) {
var fcmTokenResponse = response;
if (fcmTokenResponse['error']) {
var message = fcmTokenResponse['error']['message'];
throw _this.errorFactory_.create(Errors.codes.TOKEN_SUBSCRIBE_FAILED, {
message: message
});
}
if (!fcmTokenResponse['token']) {
throw _this.errorFactory_.create(Errors.codes.TOKEN_SUBSCRIBE_NO_TOKEN);
}
if (!fcmTokenResponse['pushSet']) {
throw _this.errorFactory_.create(Errors.codes.TOKEN_SUBSCRIBE_NO_PUSH_SET);
}
return {
token: fcmTokenResponse['token'],
pushSet: fcmTokenResponse['pushSet']
};
return tslib_1.__awaiter(this, void 0, void 0, function () {
var p256dh, auth, fcmSubscribeBody, applicationPubKey, headers, subscribeOptions, responseData, response, err_1, message;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
p256dh = arrayBufferToBase64(subscription['getKey']('p256dh'));
auth = arrayBufferToBase64(subscription['getKey']('auth'));
fcmSubscribeBody = "authorized_entity=" + senderId + "&" +
("endpoint=" + subscription.endpoint + "&") +
("encryption_key=" + p256dh + "&") +
("encryption_auth=" + auth);
if (publicVapidKey !== DEFAULT_PUBLIC_VAPID_KEY) {
applicationPubKey = arrayBufferToBase64(publicVapidKey);
fcmSubscribeBody += "&application_pub_key=" + applicationPubKey;
}
headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
subscribeOptions = {
method: 'POST',
headers: headers,
body: fcmSubscribeBody
};
responseData = null;
_a.label = 1;
case 1:
_a.trys.push([1, 4, , 5]);
return [4 /*yield*/, fetch(ENDPOINT + '/fcm/connect/subscribe', subscribeOptions)];
case 2:
response = _a.sent();
return [4 /*yield*/, response.json()];
case 3:
responseData = _a.sent();
return [3 /*break*/, 5];
case 4:
err_1 = _a.sent();
throw this.errorFactory_.create(ERROR_CODES.TOKEN_SUBSCRIBE_FAILED);
case 5:
responseData = responseData;
if (responseData['error']) {
message = responseData['error']['message'];
throw this.errorFactory_.create(ERROR_CODES.TOKEN_SUBSCRIBE_FAILED, {
message: message
});
}
if (!responseData['token']) {
throw this.errorFactory_.create(ERROR_CODES.TOKEN_SUBSCRIBE_NO_TOKEN);
}
if (!responseData['pushSet']) {
throw this.errorFactory_.create(ERROR_CODES.TOKEN_SUBSCRIBE_NO_PUSH_SET);
}
return [2 /*return*/, {
token: responseData['token'],
pushSet: responseData['pushSet']
}];
}
});
});

@@ -83,42 +89,54 @@ };

IIDModel.prototype.updateToken = function (senderId, fcmToken, fcmPushSet, subscription, publicVapidKey) {
var _this = this;
var p256dh = arrayBufferToBase64(subscription['getKey']('p256dh'));
var auth = arrayBufferToBase64(subscription['getKey']('auth'));
var fcmUpdateBody = "push_set=" + fcmPushSet + "&" +
("token=" + fcmToken + "&") +
("authorized_entity=" + senderId + "&") +
("endpoint=" + subscription.endpoint + "&") +
("encryption_key=" + p256dh + "&") +
("encryption_auth=" + auth);
if (publicVapidKey !== FCMDetails.DEFAULT_PUBLIC_VAPID_KEY) {
var applicationPubKey = arrayBufferToBase64(publicVapidKey);
fcmUpdateBody += "&application_pub_key=" + applicationPubKey;
}
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
var updateOptions = {
method: 'POST',
headers: headers,
body: fcmUpdateBody
};
var updateFetchRes;
return fetch(FCMDetails.ENDPOINT + '/fcm/connect/subscribe', updateOptions)
.then(function (fetchResponse) {
updateFetchRes = fetchResponse;
return fetchResponse.json();
})
.catch(function () {
throw _this.errorFactory_.create(Errors.codes.TOKEN_UPDATE_FAILED);
})
.then(function (fcmTokenResponse) {
if (!updateFetchRes.ok) {
var message = fcmTokenResponse['error']['message'];
throw _this.errorFactory_.create(Errors.codes.TOKEN_UPDATE_FAILED, {
message: message
});
}
if (!fcmTokenResponse['token']) {
throw _this.errorFactory_.create(Errors.codes.TOKEN_UPDATE_NO_TOKEN);
}
return fcmTokenResponse['token'];
return tslib_1.__awaiter(this, void 0, void 0, function () {
var p256dh, auth, fcmUpdateBody, applicationPubKey, headers, updateOptions, responseData, response, err_2, message;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
p256dh = arrayBufferToBase64(subscription['getKey']('p256dh'));
auth = arrayBufferToBase64(subscription['getKey']('auth'));
fcmUpdateBody = "push_set=" + fcmPushSet + "&" +
("token=" + fcmToken + "&") +
("authorized_entity=" + senderId + "&") +
("endpoint=" + subscription.endpoint + "&") +
("encryption_key=" + p256dh + "&") +
("encryption_auth=" + auth);
if (publicVapidKey !== DEFAULT_PUBLIC_VAPID_KEY) {
applicationPubKey = arrayBufferToBase64(publicVapidKey);
fcmUpdateBody += "&application_pub_key=" + applicationPubKey;
}
headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
updateOptions = {
method: 'POST',
headers: headers,
body: fcmUpdateBody
};
responseData = null;
_a.label = 1;
case 1:
_a.trys.push([1, 4, , 5]);
return [4 /*yield*/, fetch(ENDPOINT + '/fcm/connect/subscribe', updateOptions)];
case 2:
response = _a.sent();
return [4 /*yield*/, response.json()];
case 3:
responseData = _a.sent();
return [3 /*break*/, 5];
case 4:
err_2 = _a.sent();
throw this.errorFactory_.create(ERROR_CODES.TOKEN_UPDATE_FAILED);
case 5:
responseData = responseData;
if (responseData['error']) {
message = responseData['error']['message'];
throw this.errorFactory_.create(ERROR_CODES.TOKEN_UPDATE_FAILED, {
message: message
});
}
if (!responseData['token']) {
throw this.errorFactory_.create(ERROR_CODES.TOKEN_UPDATE_NO_TOKEN);
}
return [2 /*return*/, responseData['token']];
}
});
});

@@ -130,26 +148,39 @@ };

IIDModel.prototype.deleteToken = function (senderId, fcmToken, fcmPushSet) {
var _this = this;
var fcmUnsubscribeBody = "authorized_entity=" + senderId + "&" +
("token=" + fcmToken + "&") +
("pushSet=" + fcmPushSet);
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
var unsubscribeOptions = {
method: 'POST',
headers: headers,
body: fcmUnsubscribeBody
};
return fetch(FCMDetails.ENDPOINT + '/fcm/connect/unsubscribe', unsubscribeOptions).then(function (fetchResponse) {
if (!fetchResponse.ok) {
return fetchResponse.json().then(function (fcmTokenResponse) {
if (fcmTokenResponse['error']) {
var message = fcmTokenResponse['error']['message'];
throw _this.errorFactory_.create(Errors.codes.TOKEN_UNSUBSCRIBE_FAILED, {
message: message
});
}
}, function (err) {
throw _this.errorFactory_.create(Errors.codes.TOKEN_UNSUBSCRIBE_FAILED);
});
}
return tslib_1.__awaiter(this, void 0, void 0, function () {
var fcmUnsubscribeBody, headers, unsubscribeOptions, response, responseData, message, err_3;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
fcmUnsubscribeBody = "authorized_entity=" + senderId + "&" +
("token=" + fcmToken + "&") +
("pushSet=" + fcmPushSet);
headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
unsubscribeOptions = {
method: 'POST',
headers: headers,
body: fcmUnsubscribeBody
};
_a.label = 1;
case 1:
_a.trys.push([1, 4, , 5]);
return [4 /*yield*/, fetch(ENDPOINT + '/fcm/connect/unsubscribe', unsubscribeOptions)];
case 2:
response = _a.sent();
return [4 /*yield*/, response.json()];
case 3:
responseData = _a.sent();
if (responseData['error']) {
message = responseData['error']['message'];
throw this.errorFactory_.create(ERROR_CODES.TOKEN_UNSUBSCRIBE_FAILED, {
message: message
});
}
return [3 /*break*/, 5];
case 4:
err_3 = _a.sent();
throw this.errorFactory_.create(ERROR_CODES.TOKEN_UNSUBSCRIBE_FAILED);
case 5: return [2 /*return*/];
}
});
});

@@ -159,4 +190,4 @@ };

}());
export default IIDModel;
export { IIDModel };
//# sourceMappingURL=iid-model.js.map

@@ -1,6 +0,20 @@

declare const _default: {
granted: string;
default: string;
denied: string;
};
export default _default;
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare enum NotificationPermission {
DEFAULT = "default",
GRANTED = "granted",
DENIED = "denied",
}

@@ -16,9 +16,9 @@ /**

*/
'use strict';
export default {
granted: 'granted',
default: 'default',
denied: 'denied'
};
export var NotificationPermission;
(function (NotificationPermission) {
NotificationPermission["DEFAULT"] = "default";
NotificationPermission["GRANTED"] = "granted";
NotificationPermission["DENIED"] = "denied";
})(NotificationPermission || (NotificationPermission = {}));
//# sourceMappingURL=notification-permission.js.map

@@ -1,3 +0,18 @@

import DBInterface from './db-interface';
export default class TokenDetailsModel extends DBInterface {
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { DBInterface } from './db-interface';
export declare class TokenDetailsModel extends DBInterface {
constructor();

@@ -13,3 +28,3 @@ onDBUpgrade(db: IDBDatabase, evt: IDBVersionChangeEvent): void;

*/
validateInputs_(input: any): Promise<never>;
validateInputs_(input: any): Promise<undefined>;
/**

@@ -16,0 +31,0 @@ * Given a token, this method will look up the details in indexedDB.

@@ -16,7 +16,6 @@ /**

*/
'use strict';
import * as tslib_1 from "tslib";
import DBInterface from './db-interface';
import Errors from './errors';
import arrayBufferToBase64 from '../helpers/array-buffer-to-base64';
import { DBInterface } from './db-interface';
import { ERROR_CODES } from './errors';
import { arrayBufferToBase64 } from '../helpers/array-buffer-to-base64';
import { cleanV1 } from './clean-v1-undefined';

@@ -79,3 +78,3 @@ var FCM_TOKEN_OBJ_STORE = 'fcm_token_object_Store';

if (typeof input.fcmToken !== 'string' || input.fcmToken.length === 0) {
return [2 /*return*/, Promise.reject(this.errorFactory_.create(Errors.codes.BAD_TOKEN))];
return [2 /*return*/, Promise.reject(this.errorFactory_.create(ERROR_CODES.BAD_TOKEN))];
}

@@ -85,3 +84,3 @@ }

if (typeof input.swScope !== 'string' || input.swScope.length === 0) {
return [2 /*return*/, Promise.reject(this.errorFactory_.create(Errors.codes.BAD_SCOPE))];
return [2 /*return*/, Promise.reject(this.errorFactory_.create(ERROR_CODES.BAD_SCOPE))];
}

@@ -92,3 +91,3 @@ }

input.vapidKey.length !== 65) {
return [2 /*return*/, Promise.reject(this.errorFactory_.create(Errors.codes.BAD_VAPID_KEY))];
return [2 /*return*/, Promise.reject(this.errorFactory_.create(ERROR_CODES.BAD_VAPID_KEY))];
}

@@ -98,3 +97,3 @@ }

if (!(input.subscription instanceof PushSubscription)) {
return [2 /*return*/, Promise.reject(this.errorFactory_.create(Errors.codes.BAD_SUBSCRIPTION))];
return [2 /*return*/, Promise.reject(this.errorFactory_.create(ERROR_CODES.BAD_SUBSCRIPTION))];
}

@@ -105,3 +104,3 @@ }

input.fcmSenderId.length === 0) {
return [2 /*return*/, Promise.reject(this.errorFactory_.create(Errors.codes.BAD_SENDER_ID))];
return [2 /*return*/, Promise.reject(this.errorFactory_.create(ERROR_CODES.BAD_SENDER_ID))];
}

@@ -112,3 +111,3 @@ }

input.fcmPushSet.length === 0) {
return [2 /*return*/, Promise.reject(this.errorFactory_.create(Errors.codes.BAD_PUSH_SET))];
return [2 /*return*/, Promise.reject(this.errorFactory_.create(ERROR_CODES.BAD_PUSH_SET))];
}

@@ -128,3 +127,3 @@ }

if (!fcmToken) {
return Promise.reject(this.errorFactory_.create(Errors.codes.BAD_TOKEN));
return Promise.reject(this.errorFactory_.create(ERROR_CODES.BAD_TOKEN));
}

@@ -163,3 +162,3 @@ return this.validateInputs_({ fcmToken: fcmToken })

if (!swScope) {
return Promise.reject(this.errorFactory_.create(Errors.codes.BAD_SCOPE));
return Promise.reject(this.errorFactory_.create(ERROR_CODES.BAD_SCOPE));
}

@@ -198,18 +197,18 @@ return this.validateInputs_({ swScope: swScope })

if (!swScope) {
return Promise.reject(this.errorFactory_.create(Errors.codes.BAD_SCOPE));
return Promise.reject(this.errorFactory_.create(ERROR_CODES.BAD_SCOPE));
}
if (!vapidKey) {
return Promise.reject(this.errorFactory_.create(Errors.codes.BAD_VAPID_KEY));
return Promise.reject(this.errorFactory_.create(ERROR_CODES.BAD_VAPID_KEY));
}
if (!subscription) {
return Promise.reject(this.errorFactory_.create(Errors.codes.BAD_SUBSCRIPTION));
return Promise.reject(this.errorFactory_.create(ERROR_CODES.BAD_SUBSCRIPTION));
}
if (!fcmSenderId) {
return Promise.reject(this.errorFactory_.create(Errors.codes.BAD_SENDER_ID));
return Promise.reject(this.errorFactory_.create(ERROR_CODES.BAD_SENDER_ID));
}
if (!fcmToken) {
return Promise.reject(this.errorFactory_.create(Errors.codes.BAD_TOKEN));
return Promise.reject(this.errorFactory_.create(ERROR_CODES.BAD_TOKEN));
}
if (!fcmPushSet) {
return Promise.reject(this.errorFactory_.create(Errors.codes.BAD_PUSH_SET));
return Promise.reject(this.errorFactory_.create(ERROR_CODES.BAD_PUSH_SET));
}

@@ -265,7 +264,7 @@ return this.validateInputs_({

if (typeof token !== 'string' || token.length === 0) {
return Promise.reject(this.errorFactory_.create(Errors.codes.INVALID_DELETE_TOKEN));
return Promise.reject(this.errorFactory_.create(ERROR_CODES.INVALID_DELETE_TOKEN));
}
return this.getTokenDetailsFromToken(token).then(function (details) {
if (!details) {
throw _this.errorFactory_.create(Errors.codes.DELETE_TOKEN_NOT_FOUND);
throw _this.errorFactory_.create(ERROR_CODES.DELETE_TOKEN_NOT_FOUND);
}

@@ -282,3 +281,3 @@ return _this.openDatabase().then(function (db) {

if (event.target.result === 0) {
reject(_this.errorFactory_.create(Errors.codes.FAILED_TO_DELETE_TOKEN));
reject(_this.errorFactory_.create(ERROR_CODES.FAILED_TO_DELETE_TOKEN));
return;

@@ -294,4 +293,4 @@ }

}(DBInterface));
export default TokenDetailsModel;
export { TokenDetailsModel };
//# sourceMappingURL=token-details-model.js.map

@@ -1,3 +0,18 @@

import DBInterface from './db-interface';
export default class VapidDetailsModel extends DBInterface {
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { DBInterface } from './db-interface';
export declare class VapidDetailsModel extends DBInterface {
constructor();

@@ -4,0 +19,0 @@ /**

@@ -16,6 +16,5 @@ /**

*/
'use strict';
import * as tslib_1 from "tslib";
import DBInterface from './db-interface';
import Errors from './errors';
import { DBInterface } from './db-interface';
import { ERROR_CODES } from './errors';
var FCM_VAPID_OBJ_STORE = 'fcm_vapid_object_Store';

@@ -45,3 +44,3 @@ var DB_NAME = 'fcm_vapid_details_db';

if (typeof swScope !== 'string' || swScope.length === 0) {
return Promise.reject(this.errorFactory_.create(Errors.codes.BAD_SCOPE));
return Promise.reject(this.errorFactory_.create(ERROR_CODES.BAD_SCOPE));
}

@@ -73,6 +72,6 @@ return this.openDatabase().then(function (db) {

if (typeof swScope !== 'string' || swScope.length === 0) {
return Promise.reject(this.errorFactory_.create(Errors.codes.BAD_SCOPE));
return Promise.reject(this.errorFactory_.create(ERROR_CODES.BAD_SCOPE));
}
if (vapidKey === null || vapidKey.length !== UNCOMPRESSED_PUBLIC_KEY_SIZE) {
return Promise.reject(this.errorFactory_.create(Errors.codes.BAD_VAPID_KEY));
return Promise.reject(this.errorFactory_.create(ERROR_CODES.BAD_VAPID_KEY));
}

@@ -106,3 +105,3 @@ var details = {

if (!vapidKey) {
throw _this.errorFactory_.create(Errors.codes.DELETE_SCOPE_NOT_FOUND);
throw _this.errorFactory_.create(ERROR_CODES.DELETE_SCOPE_NOT_FOUND);
}

@@ -119,3 +118,3 @@ return _this.openDatabase().then(function (db) {

if (request.result === 0) {
reject(_this.errorFactory_.create(Errors.codes.FAILED_DELETE_VAPID_KEY));
reject(_this.errorFactory_.create(ERROR_CODES.FAILED_DELETE_VAPID_KEY));
return;

@@ -131,4 +130,4 @@ }

}(DBInterface));
export default VapidDetailsModel;
export { VapidDetailsModel };
//# sourceMappingURL=vapid-details-model.js.map

@@ -0,1 +1,20 @@

/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const PARAMS: {
TYPE_OF_MSG: string;
DATA: string;
};
declare const _default: {

@@ -2,0 +21,0 @@ PARAMS: {

@@ -16,6 +16,5 @@ /**

*/
'use strict';
// These fields are strings to prevent closure from thinking goog.getMsg
// should be used to initialise the values
var PARAMS = {
export var PARAMS = {
TYPE_OF_MSG: 'firebase-messaging-msg-type',

@@ -22,0 +21,0 @@ DATA: 'firebase-messaging-msg-data'

{
"name": "@firebase/messaging",
"version": "0.2.3-canary.92f3809",
"version": "0.2.3-canary.a1020bf",
"description": "",

@@ -10,13 +10,14 @@ "author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",

"dev": "gulp dev",
"test": "karma start --single-run",
"test": "karma start --single-run && yarn type-check",
"test:debug": "karma start --browsers=Chrome --auto-watch",
"prepare": "gulp build"
"prepare": "gulp build",
"type-check": "tsc --noEmit"
},
"license": "Apache-2.0",
"peerDependencies": {
"@firebase/app": "0.1.10-canary.92f3809"
"@firebase/app": "0.1.10-canary.a1020bf"
},
"dependencies": {
"@firebase/messaging-types": "0.1.2-canary.92f3809",
"@firebase/util": "0.1.10-canary.92f3809",
"@firebase/messaging-types": "0.1.2-canary.a1020bf",
"@firebase/util": "0.1.10-canary.a1020bf",
"tslib": "^1.9.0"

@@ -23,0 +24,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc