Socket
Socket
Sign inDemoInstall

push.js

Package Overview
Dependencies
0
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.11 to 1.0.12

1049

bin/push.js
/**
* @license
*
* Push v1.0.9

@@ -36,1048 +38,3 @@ * =========

*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.Push = factory());
}(this, (function () { 'use strict';
var errorPrefix = 'PushError:';
var Messages = {
errors: {
incompatible: "".concat(errorPrefix, " Push.js is incompatible with browser."),
invalid_plugin: "".concat(errorPrefix, " plugin class missing from plugin manifest (invalid plugin). Please check the documentation."),
invalid_title: "".concat(errorPrefix, " title of notification must be a string"),
permission_denied: "".concat(errorPrefix, " permission request declined"),
sw_notification_error: "".concat(errorPrefix, " could not show a ServiceWorker notification due to the following reason: "),
sw_registration_error: "".concat(errorPrefix, " could not register the ServiceWorker due to the following reason: "),
unknown_interface: "".concat(errorPrefix, " unable to create notification: unknown interface")
}
};
function _typeof(obj) {
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof = function (obj) {
return typeof obj;
};
} else {
_typeof = function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
}
return _typeof(obj);
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
});
if (superClass) _setPrototypeOf(subClass, superClass);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _possibleConstructorReturn(self, call) {
if (call && (typeof call === "object" || typeof call === "function")) {
return call;
}
return _assertThisInitialized(self);
}
var Permission =
/*#__PURE__*/
function () {
// Private members
// Public members
function Permission(win) {
_classCallCheck(this, Permission);
this._win = win;
this.GRANTED = 'granted';
this.DEFAULT = 'default';
this.DENIED = 'denied';
this._permissions = [this.GRANTED, this.DEFAULT, this.DENIED];
}
/**
* Requests permission for desktop notifications
* @param {Function} onGranted - Function to execute once permission is granted
* @param {Function} onDenied - Function to execute once permission is denied
* @return {void, Promise}
*/
_createClass(Permission, [{
key: "request",
value: function request(onGranted, onDenied) {
return arguments.length > 0 ? this._requestWithCallback.apply(this, arguments) : this._requestAsPromise();
}
/**
* Old permissions implementation deprecated in favor of a promise based one
* @deprecated Since V1.0.4
* @param {Function} onGranted - Function to execute once permission is granted
* @param {Function} onDenied - Function to execute once permission is denied
* @return {void}
*/
}, {
key: "_requestWithCallback",
value: function _requestWithCallback(onGranted, onDenied) {
var _this = this;
var existing = this.get();
var resolved = false;
var resolve = function resolve() {
var result = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this._win.Notification.permission;
if (resolved) return;
resolved = true;
if (typeof result === 'undefined' && _this._win.webkitNotifications) result = _this._win.webkitNotifications.checkPermission();
if (result === _this.GRANTED || result === 0) {
if (onGranted) onGranted();
} else if (onDenied) onDenied();
};
var request;
/* Permissions already set */
if (existing !== this.DEFAULT) {
resolve(existing);
} else if (this._win.webkitNotifications && this._win.webkitNotifications.checkPermission) {
/* Safari 6+, Legacy webkit browsers */
this._win.webkitNotifications.requestPermission(resolve);
} else if (this._win.Notification && this._win.Notification.requestPermission) {
/* Safari 12+ */
/* This resolve argument will only be used in Safari */
/* CHrome, instead, returns a Promise */
request = this._win.Notification.requestPermission(resolve);
if (request && request.then) {
/* Chrome 23+ */
request.then(resolve).catch(function () {
if (onDenied) onDenied();
});
}
} else if (onGranted) {
/* Let the user continue by default */
onGranted();
}
}
/**
* Requests permission for desktop notifications in a promise based way
* @return {Promise}
*/
}, {
key: "_requestAsPromise",
value: function _requestAsPromise() {
var _this2 = this;
var existing = this.get();
var isGranted = function isGranted(result) {
return result === _this2.GRANTED || result === 0;
};
/* Permissions already set */
var hasPermissions = existing !== this.DEFAULT;
/* Safari 6+, Chrome 23+ */
var isModernAPI = this._win.Notification && this._win.Notification.requestPermission;
/* Legacy webkit browsers */
var isWebkitAPI = this._win.webkitNotifications && this._win.webkitNotifications.checkPermission;
return new Promise(function (resolvePromise, rejectPromise) {
var resolved = false;
var resolver = function resolver(result) {
if (resolved) return;
resolved = true;
isGranted(result) ? resolvePromise() : rejectPromise();
};
var request;
if (hasPermissions) {
resolver(existing);
} else if (isWebkitAPI) {
_this2._win.webkitNotifications.requestPermission(function (result) {
resolver(result);
});
} else if (isModernAPI) {
/* Safari 12+ */
/* This resolver argument will only be used in Safari */
/* CHrome, instead, returns a Promise */
request = _this2._win.Notification.requestPermission(resolver);
if (request && request.then) {
/* Chrome 23+ */
request.then(resolver).catch(rejectPromise);
}
} else resolvePromise();
});
}
/**
* Returns whether Push has been granted permission to run
* @return {Boolean}
*/
}, {
key: "has",
value: function has() {
return this.get() === this.GRANTED;
}
/**
* Gets the permission level
* @return {Permission} The permission level
*/
}, {
key: "get",
value: function get() {
var permission;
/* Safari 6+, Chrome 23+ */
if (this._win.Notification && this._win.Notification.permission) permission = this._win.Notification.permission;else if (this._win.webkitNotifications && this._win.webkitNotifications.checkPermission)
/* Legacy webkit browsers */
permission = this._permissions[this._win.webkitNotifications.checkPermission()];else if (navigator.mozNotification)
/* Firefox Mobile */
permission = this.GRANTED;else if (this._win.external && this._win.external.msIsSiteMode)
/* IE9+ */
permission = this._win.external.msIsSiteMode() ? this.GRANTED : this.DEFAULT;else permission = this.GRANTED;
return permission;
}
}]);
return Permission;
}();
var Util =
/*#__PURE__*/
function () {
function Util() {
_classCallCheck(this, Util);
}
_createClass(Util, null, [{
key: "isUndefined",
value: function isUndefined(obj) {
return obj === undefined;
}
}, {
key: "isNull",
value: function isNull(obs) {
return obj === null;
}
}, {
key: "isString",
value: function isString(obj) {
return typeof obj === 'string';
}
}, {
key: "isFunction",
value: function isFunction(obj) {
return obj && {}.toString.call(obj) === '[object Function]';
}
}, {
key: "isObject",
value: function isObject(obj) {
return _typeof(obj) === 'object';
}
}, {
key: "objectMerge",
value: function objectMerge(target, source) {
for (var key in source) {
if (target.hasOwnProperty(key) && this.isObject(target[key]) && this.isObject(source[key])) {
this.objectMerge(target[key], source[key]);
} else {
target[key] = source[key];
}
}
}
}]);
return Util;
}();
var AbstractAgent = function AbstractAgent(win) {
_classCallCheck(this, AbstractAgent);
this._win = win;
};
/**
* Notification agent for modern desktop browsers:
* Safari 6+, Firefox 22+, Chrome 22+, Opera 25+
*/
var DesktopAgent$$1 =
/*#__PURE__*/
function (_AbstractAgent) {
_inherits(DesktopAgent$$1, _AbstractAgent);
function DesktopAgent$$1() {
_classCallCheck(this, DesktopAgent$$1);
return _possibleConstructorReturn(this, (DesktopAgent$$1.__proto__ || Object.getPrototypeOf(DesktopAgent$$1)).apply(this, arguments));
}
_createClass(DesktopAgent$$1, [{
key: "isSupported",
/**
* Returns a boolean denoting support
* @returns {Boolean} boolean denoting whether webkit notifications are supported
*/
value: function isSupported() {
return this._win.Notification !== undefined;
}
/**
* Creates a new notification
* @param title - notification title
* @param options - notification options array
* @returns {Notification}
*/
}, {
key: "create",
value: function create(title, options) {
return new this._win.Notification(title, {
icon: Util.isString(options.icon) || Util.isUndefined(options.icon) || Util.isNull(options.icon) ? options.icon : options.icon.x32,
body: options.body,
tag: options.tag,
requireInteraction: options.requireInteraction
});
}
/**
* Close a given notification
* @param notification - notification to close
*/
}, {
key: "close",
value: function close(notification) {
notification.close();
}
}]);
return DesktopAgent$$1;
}(AbstractAgent);
/**
* Notification agent for modern desktop browsers:
* Safari 6+, Firefox 22+, Chrome 22+, Opera 25+
*/
var MobileChromeAgent$$1 =
/*#__PURE__*/
function (_AbstractAgent) {
_inherits(MobileChromeAgent$$1, _AbstractAgent);
function MobileChromeAgent$$1() {
_classCallCheck(this, MobileChromeAgent$$1);
return _possibleConstructorReturn(this, (MobileChromeAgent$$1.__proto__ || Object.getPrototypeOf(MobileChromeAgent$$1)).apply(this, arguments));
}
_createClass(MobileChromeAgent$$1, [{
key: "isSupported",
/**
* Returns a boolean denoting support
* @returns {Boolean} boolean denoting whether webkit notifications are supported
*/
value: function isSupported() {
return this._win.navigator !== undefined && this._win.navigator.serviceWorker !== undefined;
}
/**
* Returns the function body as a string
* @param func
*/
}, {
key: "getFunctionBody",
value: function getFunctionBody(func) {
var str = func.toString().match(/function[^{]+{([\s\S]*)}$/);
return typeof str !== 'undefined' && str !== null && str.length > 1 ? str[1] : null;
}
/**
* Creates a new notification
* @param id ID of notification
* @param title Title of notification
* @param options Options object
* @param serviceWorker ServiceWorker path
* @param callback Callback function
*/
}, {
key: "create",
value: function create(id, title, options, serviceWorker, callback) {
var _this = this;
/* Register ServiceWorker */
this._win.navigator.serviceWorker.register(serviceWorker);
this._win.navigator.serviceWorker.ready.then(function (registration) {
/* Local data the service worker will use */
var localData = {
id: id,
link: options.link,
origin: document.location.href,
onClick: Util.isFunction(options.onClick) ? _this.getFunctionBody(options.onClick) : '',
onClose: Util.isFunction(options.onClose) ? _this.getFunctionBody(options.onClose) : ''
};
/* Merge the local data with user-provided data */
if (options.data !== undefined && options.data !== null) localData = Object.assign(localData, options.data);
/* Show the notification */
registration.showNotification(title, {
icon: options.icon,
body: options.body,
vibrate: options.vibrate,
tag: options.tag,
data: localData,
requireInteraction: options.requireInteraction,
silent: options.silent
}).then(function () {
registration.getNotifications().then(function (notifications) {
/* Send an empty message so the ServiceWorker knows who the client is */
registration.active.postMessage('');
/* Trigger callback */
callback(notifications);
});
}).catch(function (error) {
throw new Error(Messages.errors.sw_notification_error + error.message);
});
}).catch(function (error) {
throw new Error(Messages.errors.sw_registration_error + error.message);
});
}
/**
* Close all notification
*/
}, {
key: "close",
value: function close() {// Can't do this with service workers
}
}]);
return MobileChromeAgent$$1;
}(AbstractAgent);
/**
* Notification agent for modern desktop browsers:
* Safari 6+, Firefox 22+, Chrome 22+, Opera 25+
*/
var MobileFirefoxAgent$$1 =
/*#__PURE__*/
function (_AbstractAgent) {
_inherits(MobileFirefoxAgent$$1, _AbstractAgent);
function MobileFirefoxAgent$$1() {
_classCallCheck(this, MobileFirefoxAgent$$1);
return _possibleConstructorReturn(this, (MobileFirefoxAgent$$1.__proto__ || Object.getPrototypeOf(MobileFirefoxAgent$$1)).apply(this, arguments));
}
_createClass(MobileFirefoxAgent$$1, [{
key: "isSupported",
/**
* Returns a boolean denoting support
* @returns {Boolean} boolean denoting whether webkit notifications are supported
*/
value: function isSupported() {
return this._win.navigator.mozNotification !== undefined;
}
/**
* Creates a new notification
* @param title - notification title
* @param options - notification options array
* @returns {Notification}
*/
}, {
key: "create",
value: function create(title, options) {
var notification = this._win.navigator.mozNotification.createNotification(title, options.body, options.icon);
notification.show();
return notification;
}
}]);
return MobileFirefoxAgent$$1;
}(AbstractAgent);
/**
* Notification agent for IE9
*/
var MSAgent$$1 =
/*#__PURE__*/
function (_AbstractAgent) {
_inherits(MSAgent$$1, _AbstractAgent);
function MSAgent$$1() {
_classCallCheck(this, MSAgent$$1);
return _possibleConstructorReturn(this, (MSAgent$$1.__proto__ || Object.getPrototypeOf(MSAgent$$1)).apply(this, arguments));
}
_createClass(MSAgent$$1, [{
key: "isSupported",
/**
* Returns a boolean denoting support
* @returns {Boolean} boolean denoting whether webkit notifications are supported
*/
value: function isSupported() {
return this._win.external !== undefined && this._win.external.msIsSiteMode !== undefined;
}
/**
* Creates a new notification
* @param title - notification title
* @param options - notification options array
* @returns {Notification}
*/
}, {
key: "create",
value: function create(title, options) {
/* Clear any previous notifications */
this._win.external.msSiteModeClearIconOverlay();
this._win.external.msSiteModeSetIconOverlay(Util.isString(options.icon) || Util.isUndefined(options.icon) ? options.icon : options.icon.x16, title);
this._win.external.msSiteModeActivate();
return null;
}
/**
* Close a given notification
* @param notification - notification to close
*/
}, {
key: "close",
value: function close() {
this._win.external.msSiteModeClearIconOverlay();
}
}]);
return MSAgent$$1;
}(AbstractAgent);
/**
* Notification agent for old Chrome versions (and some) Firefox
*/
var WebKitAgent$$1 =
/*#__PURE__*/
function (_AbstractAgent) {
_inherits(WebKitAgent$$1, _AbstractAgent);
function WebKitAgent$$1() {
_classCallCheck(this, WebKitAgent$$1);
return _possibleConstructorReturn(this, (WebKitAgent$$1.__proto__ || Object.getPrototypeOf(WebKitAgent$$1)).apply(this, arguments));
}
_createClass(WebKitAgent$$1, [{
key: "isSupported",
/**
* Returns a boolean denoting support
* @returns {Boolean} boolean denoting whether webkit notifications are supported
*/
value: function isSupported() {
return this._win.webkitNotifications !== undefined;
}
/**
* Creates a new notification
* @param title - notification title
* @param options - notification options array
* @returns {Notification}
*/
}, {
key: "create",
value: function create(title, options) {
var notification = this._win.webkitNotifications.createNotification(options.icon, title, options.body);
notification.show();
return notification;
}
/**
* Close a given notification
* @param notification - notification to close
*/
}, {
key: "close",
value: function close(notification) {
notification.cancel();
}
}]);
return WebKitAgent$$1;
}(AbstractAgent);
var Push$$1 =
/*#__PURE__*/
function () {
// Private members
// Public members
function Push$$1(win) {
_classCallCheck(this, Push$$1);
/* Private variables */
/* ID to use for new notifications */
this._currentId = 0;
/* Map of open notifications */
this._notifications = {};
/* Window object */
this._win = win;
/* Public variables */
this.Permission = new Permission(win);
/* Agents */
this._agents = {
desktop: new DesktopAgent$$1(win),
chrome: new MobileChromeAgent$$1(win),
firefox: new MobileFirefoxAgent$$1(win),
ms: new MSAgent$$1(win),
webkit: new WebKitAgent$$1(win)
};
this._configuration = {
serviceWorker: '/serviceWorker.min.js',
fallback: function fallback(payload) {}
};
}
/**
* Closes a notification
* @param id ID of notification
* @returns {boolean} denotes whether the operation was successful
* @private
*/
_createClass(Push$$1, [{
key: "_closeNotification",
value: function _closeNotification(id) {
var success = true;
var notification = this._notifications[id];
if (notification !== undefined) {
success = this._removeNotification(id);
/* Safari 6+, Firefox 22+, Chrome 22+, Opera 25+ */
if (this._agents.desktop.isSupported()) this._agents.desktop.close(notification);else if (this._agents.webkit.isSupported())
/* Legacy WebKit browsers */
this._agents.webkit.close(notification);else if (this._agents.ms.isSupported())
/* IE9 */
this._agents.ms.close();else {
success = false;
throw new Error(Messages.errors.unknown_interface);
}
return success;
}
return false;
}
/**
* Adds a notification to the global dictionary of notifications
* @param {Notification} notification
* @return {Integer} Dictionary key of the notification
* @private
*/
}, {
key: "_addNotification",
value: function _addNotification(notification) {
var id = this._currentId;
this._notifications[id] = notification;
this._currentId++;
return id;
}
/**
* Removes a notification with the given ID
* @param {Integer} id - Dictionary key/ID of the notification to remove
* @return {Boolean} boolean denoting success
* @private
*/
}, {
key: "_removeNotification",
value: function _removeNotification(id) {
var success = false;
if (this._notifications.hasOwnProperty(id)) {
/* We're successful if we omit the given ID from the new array */
delete this._notifications[id];
success = true;
}
return success;
}
/**
* Creates the wrapper for a given notification
*
* @param {Integer} id - Dictionary key/ID of the notification
* @param {Map} options - Options used to create the notification
* @returns {Map} wrapper hashmap object
* @private
*/
}, {
key: "_prepareNotification",
value: function _prepareNotification(id, options) {
var _this = this;
var wrapper;
/* Wrapper used to get/close notification later on */
wrapper = {
get: function get() {
return _this._notifications[id];
},
close: function close() {
_this._closeNotification(id);
}
};
/* Autoclose timeout */
if (options.timeout) {
setTimeout(function () {
wrapper.close();
}, options.timeout);
}
return wrapper;
}
/**
* Find the most recent notification from a ServiceWorker and add it to the global array
* @param notifications
* @private
*/
}, {
key: "_serviceWorkerCallback",
value: function _serviceWorkerCallback(notifications, options, resolve) {
var _this2 = this;
var id = this._addNotification(notifications[notifications.length - 1]);
/* Listen for close requests from the ServiceWorker */
if (navigator && navigator.serviceWorker) {
navigator.serviceWorker.addEventListener('message', function (event) {
var data = JSON.parse(event.data);
if (data.action === 'close' && Number.isInteger(data.id)) _this2._removeNotification(data.id);
});
resolve(this._prepareNotification(id, options));
}
resolve(null);
}
/**
* Callback function for the 'create' method
* @return {void}
* @private
*/
}, {
key: "_createCallback",
value: function _createCallback(title, options, resolve) {
var _this3 = this;
var notification = null;
var onClose;
/* Set empty settings if none are specified */
options = options || {};
/* onClose event handler */
onClose = function onClose(id) {
/* A bit redundant, but covers the cases when close() isn't explicitly called */
_this3._removeNotification(id);
if (Util.isFunction(options.onClose)) {
options.onClose.call(_this3, notification);
}
};
/* Safari 6+, Firefox 22+, Chrome 22+, Opera 25+ */
if (this._agents.desktop.isSupported()) {
try {
/* Create a notification using the API if possible */
notification = this._agents.desktop.create(title, options);
} catch (e) {
var id = this._currentId;
var sw = this.config().serviceWorker;
var cb = function cb(notifications) {
return _this3._serviceWorkerCallback(notifications, options, resolve);
};
/* Create a Chrome ServiceWorker notification if it isn't supported */
if (this._agents.chrome.isSupported()) {
this._agents.chrome.create(id, title, options, sw, cb);
}
}
/* Legacy WebKit browsers */
} else if (this._agents.webkit.isSupported()) notification = this._agents.webkit.create(title, options);else if (this._agents.firefox.isSupported())
/* Firefox Mobile */
this._agents.firefox.create(title, options);else if (this._agents.ms.isSupported())
/* IE9 */
notification = this._agents.ms.create(title, options);else {
/* Default fallback */
options.title = title;
this.config().fallback(options);
}
if (notification !== null) {
var _id = this._addNotification(notification);
var wrapper = this._prepareNotification(_id, options);
/* Notification callbacks */
if (Util.isFunction(options.onShow)) notification.addEventListener('show', options.onShow);
if (Util.isFunction(options.onError)) notification.addEventListener('error', options.onError);
if (Util.isFunction(options.onClick)) notification.addEventListener('click', options.onClick);
notification.addEventListener('close', function () {
onClose(_id);
});
notification.addEventListener('cancel', function () {
onClose(_id);
});
/* Return the wrapper so the user can call close() */
resolve(wrapper);
}
/* By default, pass an empty wrapper */
resolve(null);
}
/**
* Creates and displays a new notification
* @param {Array} options
* @return {Promise}
*/
}, {
key: "create",
value: function create(title, options) {
var _this4 = this;
var promiseCallback;
/* Fail if no or an invalid title is provided */
if (!Util.isString(title)) {
throw new Error(Messages.errors.invalid_title);
}
/* Request permission if it isn't granted */
if (!this.Permission.has()) {
promiseCallback = function promiseCallback(resolve, reject) {
_this4.Permission.request().then(function () {
_this4._createCallback(title, options, resolve);
}).catch(function () {
reject(Messages.errors.permission_denied);
});
};
} else {
promiseCallback = function promiseCallback(resolve, reject) {
try {
_this4._createCallback(title, options, resolve);
} catch (e) {
reject(e);
}
};
}
return new Promise(promiseCallback);
}
/**
* Returns the notification count
* @return {Integer} The notification count
*/
}, {
key: "count",
value: function count() {
var count = 0;
var key;
for (key in this._notifications) {
if (this._notifications.hasOwnProperty(key)) count++;
}
return count;
}
/**
* Closes a notification with the given tag
* @param {String} tag - Tag of the notification to close
* @return {Boolean} boolean denoting success
*/
}, {
key: "close",
value: function close(tag) {
var key, notification;
for (key in this._notifications) {
if (this._notifications.hasOwnProperty(key)) {
notification = this._notifications[key];
/* Run only if the tags match */
if (notification.tag === tag) {
/* Call the notification's close() method */
return this._closeNotification(key);
}
}
}
}
/**
* Clears all notifications
* @return {Boolean} boolean denoting whether the clear was successful in closing all notifications
*/
}, {
key: "clear",
value: function clear() {
var key,
success = true;
for (key in this._notifications) {
if (this._notifications.hasOwnProperty(key)) success = success && this._closeNotification(key);
}
return success;
}
/**
* Denotes whether Push is supported in the current browser
* @returns {boolean}
*/
}, {
key: "supported",
value: function supported() {
var supported = false;
for (var agent in this._agents) {
if (this._agents.hasOwnProperty(agent)) supported = supported || this._agents[agent].isSupported();
}
return supported;
}
/**
* Modifies settings or returns all settings if no parameter passed
* @param settings
*/
}, {
key: "config",
value: function config(settings) {
if (typeof settings !== 'undefined' || settings !== null && Util.isObject(settings)) Util.objectMerge(this._configuration, settings);
return this._configuration;
}
/**
* Copies the functions from a plugin to the main library
* @param plugin
*/
}, {
key: "extend",
value: function extend(manifest) {
var plugin,
Plugin,
hasProp = {}.hasOwnProperty;
if (!hasProp.call(manifest, 'plugin')) {
throw new Error(Messages.errors.invalid_plugin);
} else {
if (hasProp.call(manifest, 'config') && Util.isObject(manifest.config) && manifest.config !== null) {
this.config(manifest.config);
}
Plugin = manifest.plugin;
plugin = new Plugin(this.config());
for (var member in plugin) {
if (hasProp.call(plugin, member) && Util.isFunction(plugin[member])) // $FlowFixMe
this[member] = plugin[member];
}
}
}
}]);
return Push$$1;
}();
var index = new Push$$1(typeof window !== 'undefined' ? window : global);
return index;
})));
!function(i,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(i=i||self).Push=t()}(this,function(){"use strict";var i={errors:{incompatible:"".concat("PushError:"," Push.js is incompatible with browser."),invalid_plugin:"".concat("PushError:"," plugin class missing from plugin manifest (invalid plugin). Please check the documentation."),invalid_title:"".concat("PushError:"," title of notification must be a string"),permission_denied:"".concat("PushError:"," permission request declined"),sw_notification_error:"".concat("PushError:"," could not show a ServiceWorker notification due to the following reason: "),sw_registration_error:"".concat("PushError:"," could not register the ServiceWorker due to the following reason: "),unknown_interface:"".concat("PushError:"," unable to create notification: unknown interface")}};function t(i){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(i){return typeof i}:function(i){return i&&"function"==typeof Symbol&&i.constructor===Symbol&&i!==Symbol.prototype?"symbol":typeof i})(i)}function n(i,t){if(!(i instanceof t))throw new TypeError("Cannot call a class as a function")}function e(i,t){for(var n=0;n<t.length;n++){var e=t[n];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(i,e.key,e)}}function o(i,t,n){return t&&e(i.prototype,t),n&&e(i,n),i}function r(i,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");i.prototype=Object.create(t&&t.prototype,{constructor:{value:i,writable:!0,configurable:!0}}),t&&c(i,t)}function s(i){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(i){return i.__proto__||Object.getPrototypeOf(i)})(i)}function c(i,t){return(c=Object.setPrototypeOf||function(i,t){return i.__proto__=t,i})(i,t)}function a(i,t){return!t||"object"!=typeof t&&"function"!=typeof t?function(i){if(void 0===i)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return i}(i):t}var u=function(){function i(t){n(this,i),this._win=t,this.GRANTED="granted",this.DEFAULT="default",this.DENIED="denied",this._permissions=[this.GRANTED,this.DEFAULT,this.DENIED]}return o(i,[{key:"request",value:function(i,t){return arguments.length>0?this._requestWithCallback.apply(this,arguments):this._requestAsPromise()}},{key:"_requestWithCallback",value:function(i,t){var n,e=this,o=this.get(),r=!1,s=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:e._win.Notification.permission;r||(r=!0,void 0===n&&e._win.webkitNotifications&&(n=e._win.webkitNotifications.checkPermission()),n===e.GRANTED||0===n?i&&i():t&&t())};o!==this.DEFAULT?s(o):this._win.webkitNotifications&&this._win.webkitNotifications.checkPermission?this._win.webkitNotifications.requestPermission(s):this._win.Notification&&this._win.Notification.requestPermission?(n=this._win.Notification.requestPermission(s))&&n.then&&n.then(s).catch(function(){t&&t()}):i&&i()}},{key:"_requestAsPromise",value:function(){var i=this,t=this.get(),n=t!==this.DEFAULT,e=this._win.Notification&&this._win.Notification.requestPermission,o=this._win.webkitNotifications&&this._win.webkitNotifications.checkPermission;return new Promise(function(r,s){var c,a=!1,u=function(t){a||(a=!0,!function(t){return t===i.GRANTED||0===t}(t)?s():r())};n?u(t):o?i._win.webkitNotifications.requestPermission(function(i){u(i)}):e?(c=i._win.Notification.requestPermission(u))&&c.then&&c.then(u).catch(s):r()})}},{key:"has",value:function(){return this.get()===this.GRANTED}},{key:"get",value:function(){return this._win.Notification&&this._win.Notification.permission?this._win.Notification.permission:this._win.webkitNotifications&&this._win.webkitNotifications.checkPermission?this._permissions[this._win.webkitNotifications.checkPermission()]:navigator.mozNotification?this.GRANTED:this._win.external&&this._win.external.msIsSiteMode?this._win.external.msIsSiteMode()?this.GRANTED:this.DEFAULT:this.GRANTED}}]),i}(),f=function(){function i(){n(this,i)}return o(i,null,[{key:"isUndefined",value:function(i){return void 0===i}},{key:"isNull",value:function(i){return null===obj}},{key:"isString",value:function(i){return"string"==typeof i}},{key:"isFunction",value:function(i){return i&&"[object Function]"==={}.toString.call(i)}},{key:"isObject",value:function(i){return"object"===t(i)}},{key:"objectMerge",value:function(i,t){for(var n in t)i.hasOwnProperty(n)&&this.isObject(i[n])&&this.isObject(t[n])?this.objectMerge(i[n],t[n]):i[n]=t[n]}}]),i}(),l=function i(t){n(this,i),this._win=t},h=function(i){function t(){return n(this,t),a(this,s(t).apply(this,arguments))}return r(t,l),o(t,[{key:"isSupported",value:function(){return void 0!==this._win.Notification}},{key:"create",value:function(i,t){return new this._win.Notification(i,{icon:f.isString(t.icon)||f.isUndefined(t.icon)||f.isNull(t.icon)?t.icon:t.icon.x32,body:t.body,tag:t.tag,requireInteraction:t.requireInteraction})}},{key:"close",value:function(i){i.close()}}]),t}(),_=function(t){function e(){return n(this,e),a(this,s(e).apply(this,arguments))}return r(e,l),o(e,[{key:"isSupported",value:function(){return void 0!==this._win.navigator&&void 0!==this._win.navigator.serviceWorker}},{key:"getFunctionBody",value:function(i){var t=i.toString().match(/function[^{]+{([\s\S]*)}$/);return null!=t&&t.length>1?t[1]:null}},{key:"create",value:function(t,n,e,o,r){var s=this;this._win.navigator.serviceWorker.register(o),this._win.navigator.serviceWorker.ready.then(function(o){var c={id:t,link:e.link,origin:document.location.href,onClick:f.isFunction(e.onClick)?s.getFunctionBody(e.onClick):"",onClose:f.isFunction(e.onClose)?s.getFunctionBody(e.onClose):""};void 0!==e.data&&null!==e.data&&(c=Object.assign(c,e.data)),o.showNotification(n,{icon:e.icon,body:e.body,vibrate:e.vibrate,tag:e.tag,data:c,requireInteraction:e.requireInteraction,silent:e.silent}).then(function(){o.getNotifications().then(function(i){o.active.postMessage(""),r(i)})}).catch(function(t){throw new Error(i.errors.sw_notification_error+t.message)})}).catch(function(t){throw new Error(i.errors.sw_registration_error+t.message)})}},{key:"close",value:function(){}}]),e}(),v=function(i){function t(){return n(this,t),a(this,s(t).apply(this,arguments))}return r(t,l),o(t,[{key:"isSupported",value:function(){return void 0!==this._win.navigator.mozNotification}},{key:"create",value:function(i,t){var n=this._win.navigator.mozNotification.createNotification(i,t.body,t.icon);return n.show(),n}}]),t}(),d=function(i){function t(){return n(this,t),a(this,s(t).apply(this,arguments))}return r(t,l),o(t,[{key:"isSupported",value:function(){return void 0!==this._win.external&&void 0!==this._win.external.msIsSiteMode}},{key:"create",value:function(i,t){return this._win.external.msSiteModeClearIconOverlay(),this._win.external.msSiteModeSetIconOverlay(f.isString(t.icon)||f.isUndefined(t.icon)?t.icon:t.icon.x16,i),this._win.external.msSiteModeActivate(),null}},{key:"close",value:function(){this._win.external.msSiteModeClearIconOverlay()}}]),t}(),w=function(i){function t(){return n(this,t),a(this,s(t).apply(this,arguments))}return r(t,l),o(t,[{key:"isSupported",value:function(){return void 0!==this._win.webkitNotifications}},{key:"create",value:function(i,t){var n=this._win.webkitNotifications.createNotification(t.icon,i,t.body);return n.show(),n}},{key:"close",value:function(i){i.cancel()}}]),t}();return new(function(){function t(i){n(this,t),this._currentId=0,this._notifications={},this._win=i,this.Permission=new u(i),this._agents={desktop:new h(i),chrome:new _(i),firefox:new v(i),ms:new d(i),webkit:new w(i)},this._configuration={serviceWorker:"/serviceWorker.min.js",fallback:function(i){}}}return o(t,[{key:"_closeNotification",value:function(t){var n=!0,e=this._notifications[t];if(void 0!==e){if(n=this._removeNotification(t),this._agents.desktop.isSupported())this._agents.desktop.close(e);else if(this._agents.webkit.isSupported())this._agents.webkit.close(e);else{if(!this._agents.ms.isSupported())throw n=!1,new Error(i.errors.unknown_interface);this._agents.ms.close()}return n}return!1}},{key:"_addNotification",value:function(i){var t=this._currentId;return this._notifications[t]=i,this._currentId++,t}},{key:"_removeNotification",value:function(i){var t=!1;return this._notifications.hasOwnProperty(i)&&(delete this._notifications[i],t=!0),t}},{key:"_prepareNotification",value:function(i,t){var n,e=this;return n={get:function(){return e._notifications[i]},close:function(){e._closeNotification(i)}},t.timeout&&setTimeout(function(){n.close()},t.timeout),n}},{key:"_serviceWorkerCallback",value:function(i,t,n){var e=this,o=this._addNotification(i[i.length-1]);navigator&&navigator.serviceWorker&&(navigator.serviceWorker.addEventListener("message",function(i){var t=JSON.parse(i.data);"close"===t.action&&Number.isInteger(t.id)&&e._removeNotification(t.id)}),n(this._prepareNotification(o,t))),n(null)}},{key:"_createCallback",value:function(i,t,n){var e,o=this,r=null;if(t=t||{},e=function(i){o._removeNotification(i),f.isFunction(t.onClose)&&t.onClose.call(o,r)},this._agents.desktop.isSupported())try{r=this._agents.desktop.create(i,t)}catch(e){var s=this._currentId,c=this.config().serviceWorker;this._agents.chrome.isSupported()&&this._agents.chrome.create(s,i,t,c,function(i){return o._serviceWorkerCallback(i,t,n)})}else this._agents.webkit.isSupported()?r=this._agents.webkit.create(i,t):this._agents.firefox.isSupported()?this._agents.firefox.create(i,t):this._agents.ms.isSupported()?r=this._agents.ms.create(i,t):(t.title=i,this.config().fallback(t));if(null!==r){var a=this._addNotification(r),u=this._prepareNotification(a,t);f.isFunction(t.onShow)&&r.addEventListener("show",t.onShow),f.isFunction(t.onError)&&r.addEventListener("error",t.onError),f.isFunction(t.onClick)&&r.addEventListener("click",t.onClick),r.addEventListener("close",function(){e(a)}),r.addEventListener("cancel",function(){e(a)}),n(u)}n(null)}},{key:"create",value:function(t,n){var e,o=this;if(!f.isString(t))throw new Error(i.errors.invalid_title);return e=this.Permission.has()?function(i,e){try{o._createCallback(t,n,i)}catch(i){e(i)}}:function(e,r){o.Permission.request().then(function(){o._createCallback(t,n,e)}).catch(function(){r(i.errors.permission_denied)})},new Promise(e)}},{key:"count",value:function(){var i,t=0;for(i in this._notifications)this._notifications.hasOwnProperty(i)&&t++;return t}},{key:"close",value:function(i){var t;for(t in this._notifications)if(this._notifications.hasOwnProperty(t)&&this._notifications[t].tag===i)return this._closeNotification(t)}},{key:"clear",value:function(){var i,t=!0;for(i in this._notifications)this._notifications.hasOwnProperty(i)&&(t=t&&this._closeNotification(i));return t}},{key:"supported",value:function(){var i=!1;for(var t in this._agents)this._agents.hasOwnProperty(t)&&(i=i||this._agents[t].isSupported());return i}},{key:"config",value:function(i){return(void 0!==i||null!==i&&f.isObject(i))&&f.objectMerge(this._configuration,i),this._configuration}},{key:"extend",value:function(t){var n,e={}.hasOwnProperty;if(!e.call(t,"plugin"))throw new Error(i.errors.invalid_plugin);for(var o in e.call(t,"config")&&f.isObject(t.config)&&null!==t.config&&this.config(t.config),n=new(0,t.plugin)(this.config()))e.call(n,o)&&f.isFunction(n[o])&&(this[o]=n[o])}}]),t}())("undefined"!=typeof window?window:global)});
//# sourceMappingURL=push.js.map

4

bin/push.min.js
/**
* @license
*
* Push v1.0.9

@@ -36,3 +38,3 @@ * =========

*/
!function(i,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):i.Push=t()}(this,function(){"use strict";function i(t){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(i){return typeof i}:function(i){return i&&"function"==typeof Symbol&&i.constructor===Symbol&&i!==Symbol.prototype?"symbol":typeof i})(t)}function t(i,t){if(!(i instanceof t))throw new TypeError("Cannot call a class as a function")}function n(i,t){for(var n=0;n<t.length;n++){var e=t[n];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(i,e.key,e)}}function e(i,t,e){return t&&n(i.prototype,t),e&&n(i,e),i}function o(i,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");i.prototype=Object.create(t&&t.prototype,{constructor:{value:i,writable:!0,configurable:!0}}),t&&r(i,t)}function r(i,t){return(r=Object.setPrototypeOf||function(i,t){return i.__proto__=t,i})(i,t)}function s(i,t){return!t||"object"!=typeof t&&"function"!=typeof t?function(i){if(void 0===i)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return i}(i):t}var c="PushError:",a={errors:{incompatible:"".concat(c," Push.js is incompatible with browser."),invalid_plugin:"".concat(c," plugin class missing from plugin manifest (invalid plugin). Please check the documentation."),invalid_title:"".concat(c," title of notification must be a string"),permission_denied:"".concat(c," permission request declined"),sw_notification_error:"".concat(c," could not show a ServiceWorker notification due to the following reason: "),sw_registration_error:"".concat(c," could not register the ServiceWorker due to the following reason: "),unknown_interface:"".concat(c," unable to create notification: unknown interface")}},u=function(){function i(n){t(this,i),this._win=n,this.GRANTED="granted",this.DEFAULT="default",this.DENIED="denied",this._permissions=[this.GRANTED,this.DEFAULT,this.DENIED]}return e(i,[{key:"request",value:function(i,t){return arguments.length>0?this._requestWithCallback.apply(this,arguments):this._requestAsPromise()}},{key:"_requestWithCallback",value:function(i,t){var n,e=this,o=this.get(),r=!1,s=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:e._win.Notification.permission;r||(r=!0,void 0===n&&e._win.webkitNotifications&&(n=e._win.webkitNotifications.checkPermission()),n===e.GRANTED||0===n?i&&i():t&&t())};o!==this.DEFAULT?s(o):this._win.webkitNotifications&&this._win.webkitNotifications.checkPermission?this._win.webkitNotifications.requestPermission(s):this._win.Notification&&this._win.Notification.requestPermission?(n=this._win.Notification.requestPermission(s))&&n.then&&n.then(s).catch(function(){t&&t()}):i&&i()}},{key:"_requestAsPromise",value:function(){var i=this,t=this.get(),n=t!==this.DEFAULT,e=this._win.Notification&&this._win.Notification.requestPermission,o=this._win.webkitNotifications&&this._win.webkitNotifications.checkPermission;return new Promise(function(r,s){var c,a=!1,u=function(t){a||(a=!0,!function(t){return t===i.GRANTED||0===t}(t)?s():r())};n?u(t):o?i._win.webkitNotifications.requestPermission(function(i){u(i)}):e?(c=i._win.Notification.requestPermission(u))&&c.then&&c.then(u).catch(s):r()})}},{key:"has",value:function(){return this.get()===this.GRANTED}},{key:"get",value:function(){return this._win.Notification&&this._win.Notification.permission?this._win.Notification.permission:this._win.webkitNotifications&&this._win.webkitNotifications.checkPermission?this._permissions[this._win.webkitNotifications.checkPermission()]:navigator.mozNotification?this.GRANTED:this._win.external&&this._win.external.msIsSiteMode?this._win.external.msIsSiteMode()?this.GRANTED:this.DEFAULT:this.GRANTED}}]),i}(),f=function(){function n(){t(this,n)}return e(n,null,[{key:"isUndefined",value:function(i){return void 0===i}},{key:"isNull",value:function(i){return null===obj}},{key:"isString",value:function(i){return"string"==typeof i}},{key:"isFunction",value:function(i){return i&&"[object Function]"==={}.toString.call(i)}},{key:"isObject",value:function(t){return"object"===i(t)}},{key:"objectMerge",value:function(i,t){for(var n in t)i.hasOwnProperty(n)&&this.isObject(i[n])&&this.isObject(t[n])?this.objectMerge(i[n],t[n]):i[n]=t[n]}}]),n}(),l=function i(n){t(this,i),this._win=n},h=function(i){function n(){return t(this,n),s(this,(n.__proto__||Object.getPrototypeOf(n)).apply(this,arguments))}return o(n,l),e(n,[{key:"isSupported",value:function(){return void 0!==this._win.Notification}},{key:"create",value:function(i,t){return new this._win.Notification(i,{icon:f.isString(t.icon)||f.isUndefined(t.icon)||f.isNull(t.icon)?t.icon:t.icon.x32,body:t.body,tag:t.tag,requireInteraction:t.requireInteraction})}},{key:"close",value:function(i){i.close()}}]),n}(),_=function(i){function n(){return t(this,n),s(this,(n.__proto__||Object.getPrototypeOf(n)).apply(this,arguments))}return o(n,l),e(n,[{key:"isSupported",value:function(){return void 0!==this._win.navigator&&void 0!==this._win.navigator.serviceWorker}},{key:"getFunctionBody",value:function(i){var t=i.toString().match(/function[^{]+{([\s\S]*)}$/);return void 0!==t&&null!==t&&t.length>1?t[1]:null}},{key:"create",value:function(i,t,n,e,o){var r=this;this._win.navigator.serviceWorker.register(e),this._win.navigator.serviceWorker.ready.then(function(e){var s={id:i,link:n.link,origin:document.location.href,onClick:f.isFunction(n.onClick)?r.getFunctionBody(n.onClick):"",onClose:f.isFunction(n.onClose)?r.getFunctionBody(n.onClose):""};void 0!==n.data&&null!==n.data&&(s=Object.assign(s,n.data)),e.showNotification(t,{icon:n.icon,body:n.body,vibrate:n.vibrate,tag:n.tag,data:s,requireInteraction:n.requireInteraction,silent:n.silent}).then(function(){e.getNotifications().then(function(i){e.active.postMessage(""),o(i)})}).catch(function(i){throw new Error(a.errors.sw_notification_error+i.message)})}).catch(function(i){throw new Error(a.errors.sw_registration_error+i.message)})}},{key:"close",value:function(){}}]),n}(),v=function(i){function n(){return t(this,n),s(this,(n.__proto__||Object.getPrototypeOf(n)).apply(this,arguments))}return o(n,l),e(n,[{key:"isSupported",value:function(){return void 0!==this._win.navigator.mozNotification}},{key:"create",value:function(i,t){var n=this._win.navigator.mozNotification.createNotification(i,t.body,t.icon);return n.show(),n}}]),n}(),d=function(i){function n(){return t(this,n),s(this,(n.__proto__||Object.getPrototypeOf(n)).apply(this,arguments))}return o(n,l),e(n,[{key:"isSupported",value:function(){return void 0!==this._win.external&&void 0!==this._win.external.msIsSiteMode}},{key:"create",value:function(i,t){return this._win.external.msSiteModeClearIconOverlay(),this._win.external.msSiteModeSetIconOverlay(f.isString(t.icon)||f.isUndefined(t.icon)?t.icon:t.icon.x16,i),this._win.external.msSiteModeActivate(),null}},{key:"close",value:function(){this._win.external.msSiteModeClearIconOverlay()}}]),n}(),p=function(i){function n(){return t(this,n),s(this,(n.__proto__||Object.getPrototypeOf(n)).apply(this,arguments))}return o(n,l),e(n,[{key:"isSupported",value:function(){return void 0!==this._win.webkitNotifications}},{key:"create",value:function(i,t){var n=this._win.webkitNotifications.createNotification(t.icon,i,t.body);return n.show(),n}},{key:"close",value:function(i){i.cancel()}}]),n}();return new(function(){function i(n){t(this,i),this._currentId=0,this._notifications={},this._win=n,this.Permission=new u(n),this._agents={desktop:new h(n),chrome:new _(n),firefox:new v(n),ms:new d(n),webkit:new p(n)},this._configuration={serviceWorker:"/serviceWorker.min.js",fallback:function(i){}}}return e(i,[{key:"_closeNotification",value:function(i){var t=!0,n=this._notifications[i];if(void 0!==n){if(t=this._removeNotification(i),this._agents.desktop.isSupported())this._agents.desktop.close(n);else if(this._agents.webkit.isSupported())this._agents.webkit.close(n);else{if(!this._agents.ms.isSupported())throw t=!1,new Error(a.errors.unknown_interface);this._agents.ms.close()}return t}return!1}},{key:"_addNotification",value:function(i){var t=this._currentId;return this._notifications[t]=i,this._currentId++,t}},{key:"_removeNotification",value:function(i){var t=!1;return this._notifications.hasOwnProperty(i)&&(delete this._notifications[i],t=!0),t}},{key:"_prepareNotification",value:function(i,t){var n,e=this;return n={get:function(){return e._notifications[i]},close:function(){e._closeNotification(i)}},t.timeout&&setTimeout(function(){n.close()},t.timeout),n}},{key:"_serviceWorkerCallback",value:function(i,t,n){var e=this,o=this._addNotification(i[i.length-1]);navigator&&navigator.serviceWorker&&(navigator.serviceWorker.addEventListener("message",function(i){var t=JSON.parse(i.data);"close"===t.action&&Number.isInteger(t.id)&&e._removeNotification(t.id)}),n(this._prepareNotification(o,t))),n(null)}},{key:"_createCallback",value:function(i,t,n){var e,o=this,r=null;if(t=t||{},e=function(i){o._removeNotification(i),f.isFunction(t.onClose)&&t.onClose.call(o,r)},this._agents.desktop.isSupported())try{r=this._agents.desktop.create(i,t)}catch(e){var s=this._currentId,c=this.config().serviceWorker,a=function(i){return o._serviceWorkerCallback(i,t,n)};this._agents.chrome.isSupported()&&this._agents.chrome.create(s,i,t,c,a)}else this._agents.webkit.isSupported()?r=this._agents.webkit.create(i,t):this._agents.firefox.isSupported()?this._agents.firefox.create(i,t):this._agents.ms.isSupported()?r=this._agents.ms.create(i,t):(t.title=i,this.config().fallback(t));if(null!==r){var u=this._addNotification(r),l=this._prepareNotification(u,t);f.isFunction(t.onShow)&&r.addEventListener("show",t.onShow),f.isFunction(t.onError)&&r.addEventListener("error",t.onError),f.isFunction(t.onClick)&&r.addEventListener("click",t.onClick),r.addEventListener("close",function(){e(u)}),r.addEventListener("cancel",function(){e(u)}),n(l)}n(null)}},{key:"create",value:function(i,t){var n,e=this;if(!f.isString(i))throw new Error(a.errors.invalid_title);return n=this.Permission.has()?function(n,o){try{e._createCallback(i,t,n)}catch(i){o(i)}}:function(n,o){e.Permission.request().then(function(){e._createCallback(i,t,n)}).catch(function(){o(a.errors.permission_denied)})},new Promise(n)}},{key:"count",value:function(){var i,t=0;for(i in this._notifications)this._notifications.hasOwnProperty(i)&&t++;return t}},{key:"close",value:function(i){var t;for(t in this._notifications)if(this._notifications.hasOwnProperty(t)&&this._notifications[t].tag===i)return this._closeNotification(t)}},{key:"clear",value:function(){var i,t=!0;for(i in this._notifications)this._notifications.hasOwnProperty(i)&&(t=t&&this._closeNotification(i));return t}},{key:"supported",value:function(){var i=!1;for(var t in this._agents)this._agents.hasOwnProperty(t)&&(i=i||this._agents[t].isSupported());return i}},{key:"config",value:function(i){return(void 0!==i||null!==i&&f.isObject(i))&&f.objectMerge(this._configuration,i),this._configuration}},{key:"extend",value:function(i){var t,n={}.hasOwnProperty;if(!n.call(i,"plugin"))throw new Error(a.errors.invalid_plugin);n.call(i,"config")&&f.isObject(i.config)&&null!==i.config&&this.config(i.config),t=new(0,i.plugin)(this.config());for(var e in t)n.call(t,e)&&f.isFunction(t[e])&&(this[e]=t[e])}}]),i}())("undefined"!=typeof window?window:global)});
!function(i,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(i=i||self).Push=t()}(this,function(){"use strict";var i={errors:{incompatible:"".concat("PushError:"," Push.js is incompatible with browser."),invalid_plugin:"".concat("PushError:"," plugin class missing from plugin manifest (invalid plugin). Please check the documentation."),invalid_title:"".concat("PushError:"," title of notification must be a string"),permission_denied:"".concat("PushError:"," permission request declined"),sw_notification_error:"".concat("PushError:"," could not show a ServiceWorker notification due to the following reason: "),sw_registration_error:"".concat("PushError:"," could not register the ServiceWorker due to the following reason: "),unknown_interface:"".concat("PushError:"," unable to create notification: unknown interface")}};function t(i){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(i){return typeof i}:function(i){return i&&"function"==typeof Symbol&&i.constructor===Symbol&&i!==Symbol.prototype?"symbol":typeof i})(i)}function n(i,t){if(!(i instanceof t))throw new TypeError("Cannot call a class as a function")}function e(i,t){for(var n=0;n<t.length;n++){var e=t[n];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(i,e.key,e)}}function o(i,t,n){return t&&e(i.prototype,t),n&&e(i,n),i}function r(i,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");i.prototype=Object.create(t&&t.prototype,{constructor:{value:i,writable:!0,configurable:!0}}),t&&c(i,t)}function s(i){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(i){return i.__proto__||Object.getPrototypeOf(i)})(i)}function c(i,t){return(c=Object.setPrototypeOf||function(i,t){return i.__proto__=t,i})(i,t)}function a(i,t){return!t||"object"!=typeof t&&"function"!=typeof t?function(i){if(void 0===i)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return i}(i):t}var u=function(){function i(t){n(this,i),this._win=t,this.GRANTED="granted",this.DEFAULT="default",this.DENIED="denied",this._permissions=[this.GRANTED,this.DEFAULT,this.DENIED]}return o(i,[{key:"request",value:function(i,t){return arguments.length>0?this._requestWithCallback.apply(this,arguments):this._requestAsPromise()}},{key:"_requestWithCallback",value:function(i,t){var n,e=this,o=this.get(),r=!1,s=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:e._win.Notification.permission;r||(r=!0,void 0===n&&e._win.webkitNotifications&&(n=e._win.webkitNotifications.checkPermission()),n===e.GRANTED||0===n?i&&i():t&&t())};o!==this.DEFAULT?s(o):this._win.webkitNotifications&&this._win.webkitNotifications.checkPermission?this._win.webkitNotifications.requestPermission(s):this._win.Notification&&this._win.Notification.requestPermission?(n=this._win.Notification.requestPermission(s))&&n.then&&n.then(s).catch(function(){t&&t()}):i&&i()}},{key:"_requestAsPromise",value:function(){var i=this,t=this.get(),n=t!==this.DEFAULT,e=this._win.Notification&&this._win.Notification.requestPermission,o=this._win.webkitNotifications&&this._win.webkitNotifications.checkPermission;return new Promise(function(r,s){var c,a=!1,u=function(t){a||(a=!0,!function(t){return t===i.GRANTED||0===t}(t)?s():r())};n?u(t):o?i._win.webkitNotifications.requestPermission(function(i){u(i)}):e?(c=i._win.Notification.requestPermission(u))&&c.then&&c.then(u).catch(s):r()})}},{key:"has",value:function(){return this.get()===this.GRANTED}},{key:"get",value:function(){return this._win.Notification&&this._win.Notification.permission?this._win.Notification.permission:this._win.webkitNotifications&&this._win.webkitNotifications.checkPermission?this._permissions[this._win.webkitNotifications.checkPermission()]:navigator.mozNotification?this.GRANTED:this._win.external&&this._win.external.msIsSiteMode?this._win.external.msIsSiteMode()?this.GRANTED:this.DEFAULT:this.GRANTED}}]),i}(),f=function(){function i(){n(this,i)}return o(i,null,[{key:"isUndefined",value:function(i){return void 0===i}},{key:"isNull",value:function(i){return null===obj}},{key:"isString",value:function(i){return"string"==typeof i}},{key:"isFunction",value:function(i){return i&&"[object Function]"==={}.toString.call(i)}},{key:"isObject",value:function(i){return"object"===t(i)}},{key:"objectMerge",value:function(i,t){for(var n in t)i.hasOwnProperty(n)&&this.isObject(i[n])&&this.isObject(t[n])?this.objectMerge(i[n],t[n]):i[n]=t[n]}}]),i}(),l=function i(t){n(this,i),this._win=t},h=function(i){function t(){return n(this,t),a(this,s(t).apply(this,arguments))}return r(t,l),o(t,[{key:"isSupported",value:function(){return void 0!==this._win.Notification}},{key:"create",value:function(i,t){return new this._win.Notification(i,{icon:f.isString(t.icon)||f.isUndefined(t.icon)||f.isNull(t.icon)?t.icon:t.icon.x32,body:t.body,tag:t.tag,requireInteraction:t.requireInteraction})}},{key:"close",value:function(i){i.close()}}]),t}(),_=function(t){function e(){return n(this,e),a(this,s(e).apply(this,arguments))}return r(e,l),o(e,[{key:"isSupported",value:function(){return void 0!==this._win.navigator&&void 0!==this._win.navigator.serviceWorker}},{key:"getFunctionBody",value:function(i){var t=i.toString().match(/function[^{]+{([\s\S]*)}$/);return null!=t&&t.length>1?t[1]:null}},{key:"create",value:function(t,n,e,o,r){var s=this;this._win.navigator.serviceWorker.register(o),this._win.navigator.serviceWorker.ready.then(function(o){var c={id:t,link:e.link,origin:document.location.href,onClick:f.isFunction(e.onClick)?s.getFunctionBody(e.onClick):"",onClose:f.isFunction(e.onClose)?s.getFunctionBody(e.onClose):""};void 0!==e.data&&null!==e.data&&(c=Object.assign(c,e.data)),o.showNotification(n,{icon:e.icon,body:e.body,vibrate:e.vibrate,tag:e.tag,data:c,requireInteraction:e.requireInteraction,silent:e.silent}).then(function(){o.getNotifications().then(function(i){o.active.postMessage(""),r(i)})}).catch(function(t){throw new Error(i.errors.sw_notification_error+t.message)})}).catch(function(t){throw new Error(i.errors.sw_registration_error+t.message)})}},{key:"close",value:function(){}}]),e}(),v=function(i){function t(){return n(this,t),a(this,s(t).apply(this,arguments))}return r(t,l),o(t,[{key:"isSupported",value:function(){return void 0!==this._win.navigator.mozNotification}},{key:"create",value:function(i,t){var n=this._win.navigator.mozNotification.createNotification(i,t.body,t.icon);return n.show(),n}}]),t}(),d=function(i){function t(){return n(this,t),a(this,s(t).apply(this,arguments))}return r(t,l),o(t,[{key:"isSupported",value:function(){return void 0!==this._win.external&&void 0!==this._win.external.msIsSiteMode}},{key:"create",value:function(i,t){return this._win.external.msSiteModeClearIconOverlay(),this._win.external.msSiteModeSetIconOverlay(f.isString(t.icon)||f.isUndefined(t.icon)?t.icon:t.icon.x16,i),this._win.external.msSiteModeActivate(),null}},{key:"close",value:function(){this._win.external.msSiteModeClearIconOverlay()}}]),t}(),w=function(i){function t(){return n(this,t),a(this,s(t).apply(this,arguments))}return r(t,l),o(t,[{key:"isSupported",value:function(){return void 0!==this._win.webkitNotifications}},{key:"create",value:function(i,t){var n=this._win.webkitNotifications.createNotification(t.icon,i,t.body);return n.show(),n}},{key:"close",value:function(i){i.cancel()}}]),t}();return new(function(){function t(i){n(this,t),this._currentId=0,this._notifications={},this._win=i,this.Permission=new u(i),this._agents={desktop:new h(i),chrome:new _(i),firefox:new v(i),ms:new d(i),webkit:new w(i)},this._configuration={serviceWorker:"/serviceWorker.min.js",fallback:function(i){}}}return o(t,[{key:"_closeNotification",value:function(t){var n=!0,e=this._notifications[t];if(void 0!==e){if(n=this._removeNotification(t),this._agents.desktop.isSupported())this._agents.desktop.close(e);else if(this._agents.webkit.isSupported())this._agents.webkit.close(e);else{if(!this._agents.ms.isSupported())throw n=!1,new Error(i.errors.unknown_interface);this._agents.ms.close()}return n}return!1}},{key:"_addNotification",value:function(i){var t=this._currentId;return this._notifications[t]=i,this._currentId++,t}},{key:"_removeNotification",value:function(i){var t=!1;return this._notifications.hasOwnProperty(i)&&(delete this._notifications[i],t=!0),t}},{key:"_prepareNotification",value:function(i,t){var n,e=this;return n={get:function(){return e._notifications[i]},close:function(){e._closeNotification(i)}},t.timeout&&setTimeout(function(){n.close()},t.timeout),n}},{key:"_serviceWorkerCallback",value:function(i,t,n){var e=this,o=this._addNotification(i[i.length-1]);navigator&&navigator.serviceWorker&&(navigator.serviceWorker.addEventListener("message",function(i){var t=JSON.parse(i.data);"close"===t.action&&Number.isInteger(t.id)&&e._removeNotification(t.id)}),n(this._prepareNotification(o,t))),n(null)}},{key:"_createCallback",value:function(i,t,n){var e,o=this,r=null;if(t=t||{},e=function(i){o._removeNotification(i),f.isFunction(t.onClose)&&t.onClose.call(o,r)},this._agents.desktop.isSupported())try{r=this._agents.desktop.create(i,t)}catch(e){var s=this._currentId,c=this.config().serviceWorker;this._agents.chrome.isSupported()&&this._agents.chrome.create(s,i,t,c,function(i){return o._serviceWorkerCallback(i,t,n)})}else this._agents.webkit.isSupported()?r=this._agents.webkit.create(i,t):this._agents.firefox.isSupported()?this._agents.firefox.create(i,t):this._agents.ms.isSupported()?r=this._agents.ms.create(i,t):(t.title=i,this.config().fallback(t));if(null!==r){var a=this._addNotification(r),u=this._prepareNotification(a,t);f.isFunction(t.onShow)&&r.addEventListener("show",t.onShow),f.isFunction(t.onError)&&r.addEventListener("error",t.onError),f.isFunction(t.onClick)&&r.addEventListener("click",t.onClick),r.addEventListener("close",function(){e(a)}),r.addEventListener("cancel",function(){e(a)}),n(u)}n(null)}},{key:"create",value:function(t,n){var e,o=this;if(!f.isString(t))throw new Error(i.errors.invalid_title);return e=this.Permission.has()?function(i,e){try{o._createCallback(t,n,i)}catch(i){e(i)}}:function(e,r){o.Permission.request().then(function(){o._createCallback(t,n,e)}).catch(function(){r(i.errors.permission_denied)})},new Promise(e)}},{key:"count",value:function(){var i,t=0;for(i in this._notifications)this._notifications.hasOwnProperty(i)&&t++;return t}},{key:"close",value:function(i){var t;for(t in this._notifications)if(this._notifications.hasOwnProperty(t)&&this._notifications[t].tag===i)return this._closeNotification(t)}},{key:"clear",value:function(){var i,t=!0;for(i in this._notifications)this._notifications.hasOwnProperty(i)&&(t=t&&this._closeNotification(i));return t}},{key:"supported",value:function(){var i=!1;for(var t in this._agents)this._agents.hasOwnProperty(t)&&(i=i||this._agents[t].isSupported());return i}},{key:"config",value:function(i){return(void 0!==i||null!==i&&f.isObject(i))&&f.objectMerge(this._configuration,i),this._configuration}},{key:"extend",value:function(t){var n,e={}.hasOwnProperty;if(!e.call(t,"plugin"))throw new Error(i.errors.invalid_plugin);for(var o in e.call(t,"config")&&f.isObject(t.config)&&null!==t.config&&this.config(t.config),n=new(0,t.plugin)(this.config()))e.call(n,o)&&f.isFunction(n[o])&&(this[o]=n[o])}}]),t}())("undefined"!=typeof window?window:global)});
//# sourceMappingURL=push.min.js.map
# Contributing Guidelines
So you want to contribute to Push, huh? Well lucky for you, it's really easy to do so, because you're just dealing with like, a few hundred lines of JavaScript. It's not hard.

@@ -8,20 +9,31 @@

```bash
$ npm run build
```
npm run build
```
To TEST Push, run:
To TEST Push on BrowserStack, run:
```bash
$ npm run test
```
npm run test
```
See? Not hard at all. Unfortunately the Notifications API doesn't always play nicely with local sites, so don't get discouraged if you try running Push in a local HTML file and it doesn't work.
### Testing & Travis ###
To TEST Push on a specific, locally-installed browser, you can run one of the following:
```bash
$ npm run test:opera
$ npm run test:firefox
$ npm run test:chrome
$ npm run test:safari
```
### Testing & Travis
Push uses the [Karma](https://karma-runner.github.io/1.0/index.html) JavaScript test runner, so read up on that if you want to make changes to any of the tests that are run. These tests are run post-push by [Travis CI](https://travis-ci.org), so look into that if you want to make any Travis configuration changes. Although, at this point I'd say Travis is all set. The tests might want to be expanded though.
### REAL IMPORTANT STUFF ###
### REAL IMPORTANT STUFF
**THERE IS ONLY ONE RULE TO PUSH CLUB** (and no, it's not that you can't talk about it). **WHENEVER** you make changes to `Push.js`, **RECOMPILE** and commit `push.min.js` as well. Until this build process can be wrapped into a sexy git hook of some sort, this is how changes to the library need to occur. **YOUR PR WILL NOT BE APPROVED UNLESS THIS HAPPENS**. That said, I did let it slide once because I wasn't thinking, but that's why I wrote this file to make sure it will never happen again.
Outside of that, contributing should not be at all scary and should be a fun and positive process. Now go out and write some killer JS! Wait... is there even such a thing?
{
"name": "push.js",
"version": "1.0.11",
"description":
"A compact, cross-browser solution for the Javascript Notifications API",
"version": "1.0.12",
"description": "A compact, cross-browser solution for the Javascript Notifications API",
"main": "bin/push.min.js",
"scripts": {
"clean": "rimraf bin/",
"build":
"rollup -c && uglifyjs --source-map -o bin/serviceWorker.min.js src/serviceWorker.js",
"build": "rollup -c && uglifyjs --source-map -o bin/serviceWorker.min.js src/serviceWorker.js",
"test": "npm run build && karma start tests/karma.conf.js",
"test:chrome": "PUSHJS_TEST_BROWSER=Chrome npm run test",
"test:opera": "PUSHJS_TEST_BROWSER=Opera npm run test",
"test:firefox": "PUSHJS_TEST_BROWSER=Firefox npm run test",
"test:safari": "PUSHJS_TEST_BROWSER=Safari npm run test",
"prepublish": "npm run build",
"precommit": "lint-staged && npm run build && git add ./bin"
},
"files": ["bin", "*.md", "*.png", "*.d.ts"],
"files": [
"bin",
"*.md",
"*.png",
"*.d.ts"
],
"repository": {

@@ -27,44 +34,50 @@ "type": "git",

"devDependencies": {
"@babel/core": "^7.0.0-rc.2",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-decorators": "^7.0.0",
"@babel/plugin-proposal-export-namespace-from": "^7.0.0",
"@babel/plugin-proposal-function-sent": "^7.0.0",
"@babel/plugin-proposal-json-strings": "^7.0.0",
"@babel/plugin-proposal-numeric-separator": "^7.0.0",
"@babel/plugin-proposal-throw-expressions": "^7.0.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-syntax-import-meta": "^7.0.0",
"@babel/plugin-transform-flow-strip-types": "^7.0.0-beta.35",
"@babel/plugin-transform-strict-mode": "^7.0.0-beta.35",
"@babel/polyfill": "^7.0.0-beta.35",
"@babel/preset-env": "^7.0.0-beta.35",
"@babel/core": "^7.5.5",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-proposal-decorators": "^7.4.4",
"@babel/plugin-proposal-export-namespace-from": "^7.5.2",
"@babel/plugin-proposal-function-sent": "^7.5.0",
"@babel/plugin-proposal-json-strings": "^7.2.0",
"@babel/plugin-proposal-numeric-separator": "^7.2.0",
"@babel/plugin-proposal-throw-expressions": "^7.2.0",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/plugin-syntax-import-meta": "^7.2.0",
"@babel/plugin-transform-flow-strip-types": "^7.4.4",
"@babel/plugin-transform-strict-mode": "^7.2.0",
"@babel/polyfill": "^7.4.4",
"@babel/preset-env": "^7.5.5",
"@babel/preset-flow": "^7.0.0",
"browserify": "^16.0.0",
"coveralls": "^3.0.0",
"flow-bin": "^0.65.0",
"husky": "^0.14.3",
"jasmine-core": "^2.8.0",
"js-yaml": "^3.10.0",
"karma": "^2.0.0",
"karma-browserstack-launcher": "^1.3.0",
"karma-coverage": "^1.1.1",
"karma-jasmine": "^1.1.1",
"browserify": "^16.3.0",
"coveralls": "^3.0.5",
"flow-bin": "^0.103.0",
"husky": "^3.0.1",
"jasmine-core": "^3.4.0",
"js-yaml": "^3.13.1",
"karma": "^4.2.0",
"karma-browserstack-launcher": "~1.4.0",
"karma-chrome-launcher": "^3.0.0",
"karma-coverage": "^1.1.2",
"karma-firefox-launcher": "^1.1.0",
"karma-jasmine": "^2.0.1",
"karma-mocha-reporter": "^2.2.5",
"karma-opera-launcher": "^1.0.0",
"karma-safari-launcher": "^1.0.0",
"karma-sourcemap-loader": "^0.3.7",
"lint-staged": "^7.0.0",
"lint-staged": "^9.2.0",
"natives": "^1.1.6",
"platform": "^1.3.4",
"prettier": "^1.9.2",
"rimraf": "^2.6.2",
"rollup": "^0.57.0",
"rollup-plugin-alias": "^1.4.0",
"rollup-plugin-babel": "^4.0.1",
"rollup-plugin-commonjs": "^8.2.6",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-uglify": "^2.0.1",
"uglify-es": "^3.2.2"
"platform": "^1.3.5",
"prettier": "^1.18.2",
"rimraf": "^2.6.3",
"rollup": "^1.17.0",
"rollup-plugin-alias": "^1.5.2",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-commonjs": "^10.0.1",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-terser": "^5.1.1"
},
"lint-staged": {
"*.{js,json,css}": ["prettier --write", "git add"]
"*.{js,json,css}": [
"prettier --write",
"git add"
]
},

@@ -71,0 +84,0 @@ "dependencies": {},

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc