From 72e71151d3b6e27d254c9a83478b5d2fac458d09 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Maigrot Date: Wed, 19 Feb 2020 11:09:50 +0100 Subject: [PATCH] Revert "Add type overload for Push.Permission.request()" This reverts commit aa0c042c6d4384e63009a4e2b927e0294b198745. --- bin/push.js | 39 +-------------------------------------- bin/push.js.map | 2 +- bin/push.min.js | 39 +-------------------------------------- bin/push.min.js.map | 2 +- index.d.ts | 6 +++--- 5 files changed, 7 insertions(+), 81 deletions(-) diff --git a/bin/push.js b/bin/push.js index 2a9aa076..37fba19a 100644 --- a/bin/push.js +++ b/bin/push.js @@ -35,42 +35,5 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -/** - * @license - * - * Push v1.0.9 - * ========= - * A compact, cross-browser solution for the JavaScript Notifications API - * - * Credits - * ------- - * Tsvetan Tsvetkov (ttsvetko) - * Alex Gibson (alexgibson) - * - * License - * ------- - * - * The MIT License (MIT) - * - * Copyright (c) 2015-2017 Tyler Nickerson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -!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;n0?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,i),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}(l),_=function(t){function e(){return n(this,e),a(this,s(e).apply(this,arguments))}return r(e,t),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}(l),v=function(i){function t(){return n(this,t),a(this,s(t).apply(this,arguments))}return r(t,i),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}(l),d=function(i){function t(){return n(this,t),a(this,s(t).apply(this,arguments))}return r(t,i),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}(l),w=function(i){function t(){return n(this,t),a(this,s(t).apply(this,arguments))}return r(t,i),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}(l);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)})); +!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;n0?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 diff --git a/bin/push.js.map b/bin/push.js.map index accf0bea..7cf980fe 100644 --- a/bin/push.js.map +++ b/bin/push.js.map @@ -1 +1 @@ -{"version":3,"file":"push.js","sources":["../src/push/Messages.js","../src/push/Permission.js","../src/push/Util.js","../src/agents/AbstractAgent.js","../src/agents/DesktopAgent.js","../src/agents/MobileChromeAgent.js","../src/agents/MobileFirefoxAgent.js","../src/agents/MSAgent.js","../src/agents/WebKitAgent.js","../src/index.js","../src/push/Push.js"],"sourcesContent":["// @flow\nconst errorPrefix = 'PushError:';\n\nexport default {\n errors: {\n incompatible: `${errorPrefix} Push.js is incompatible with browser.`,\n invalid_plugin: `${errorPrefix} plugin class missing from plugin manifest (invalid plugin). Please check the documentation.`,\n invalid_title: `${errorPrefix} title of notification must be a string`,\n permission_denied: `${errorPrefix} permission request declined`,\n sw_notification_error: `${errorPrefix} could not show a ServiceWorker notification due to the following reason: `,\n sw_registration_error: `${errorPrefix} could not register the ServiceWorker due to the following reason: `,\n unknown_interface: `${errorPrefix} unable to create notification: unknown interface`\n }\n};\n","// @flow\nimport type { Global } from 'types';\n\nexport default class Permission {\n // Private members\n _permissions: string[];\n _win: Global;\n\n // Public members\n GRANTED: string;\n DEFAULT: string;\n DENIED: string;\n\n constructor(win: Global) {\n this._win = win;\n this.GRANTED = 'granted';\n this.DEFAULT = 'default';\n this.DENIED = 'denied';\n this._permissions = [this.GRANTED, this.DEFAULT, this.DENIED];\n }\n\n /**\n * Requests permission for desktop notifications\n * @param {Function} onGranted - Function to execute once permission is granted\n * @param {Function} onDenied - Function to execute once permission is denied\n * @return {void, Promise}\n */\n request(onGranted: () => void, onDenied: () => void) {\n return arguments.length > 0\n ? this._requestWithCallback(...arguments)\n : this._requestAsPromise();\n }\n\n /**\n * Old permissions implementation deprecated in favor of a promise based one\n * @deprecated Since V1.0.4\n * @param {Function} onGranted - Function to execute once permission is granted\n * @param {Function} onDenied - Function to execute once permission is denied\n * @return {void}\n */\n _requestWithCallback(onGranted: () => void, onDenied: () => void) {\n const existing = this.get();\n\n var resolved = false;\n var resolve = (result = this._win.Notification.permission) => {\n if (resolved) return;\n resolved = true;\n if (typeof result === 'undefined' && this._win.webkitNotifications)\n result = this._win.webkitNotifications.checkPermission();\n if (result === this.GRANTED || result === 0) {\n if (onGranted) onGranted();\n } else if (onDenied) onDenied();\n };\n var request;\n\n /* Permissions already set */\n if (existing !== this.DEFAULT) {\n resolve(existing);\n } else if (\n this._win.webkitNotifications &&\n this._win.webkitNotifications.checkPermission\n ) {\n /* Safari 6+, Legacy webkit browsers */\n this._win.webkitNotifications.requestPermission(resolve);\n } else if (\n this._win.Notification &&\n this._win.Notification.requestPermission\n ) {\n /* Safari 12+ */\n /* This resolve argument will only be used in Safari */\n /* CHrome, instead, returns a Promise */\n request = this._win.Notification.requestPermission(resolve);\n if (request && request.then) {\n /* Chrome 23+ */\n request.then(resolve).catch(function() {\n if (onDenied) onDenied();\n });\n }\n } else if (onGranted) {\n /* Let the user continue by default */\n onGranted();\n }\n }\n\n /**\n * Requests permission for desktop notifications in a promise based way\n * @return {Promise}\n */\n _requestAsPromise(): Promise {\n const existing = this.get();\n\n let isGranted = result => result === this.GRANTED || result === 0;\n\n /* Permissions already set */\n var hasPermissions = existing !== this.DEFAULT;\n\n /* Safari 6+, Chrome 23+ */\n var isModernAPI =\n this._win.Notification && this._win.Notification.requestPermission;\n\n /* Legacy webkit browsers */\n var isWebkitAPI =\n this._win.webkitNotifications &&\n this._win.webkitNotifications.checkPermission;\n\n return new Promise((resolvePromise, rejectPromise) => {\n var resolved = false;\n var resolver = result => {\n if (resolved) return;\n resolved = true;\n isGranted(result) ? resolvePromise() : rejectPromise();\n };\n var request;\n\n if (hasPermissions) {\n resolver(existing);\n } else if (isWebkitAPI) {\n this._win.webkitNotifications.requestPermission(result => {\n resolver(result);\n });\n } else if (isModernAPI) {\n /* Safari 12+ */\n /* This resolver argument will only be used in Safari */\n /* CHrome, instead, returns a Promise */\n request = this._win.Notification.requestPermission(resolver);\n if (request && request.then) {\n /* Chrome 23+ */\n request.then(resolver).catch(rejectPromise);\n }\n } else resolvePromise();\n });\n }\n\n /**\n * Returns whether Push has been granted permission to run\n * @return {Boolean}\n */\n has() {\n return this.get() === this.GRANTED;\n }\n\n /**\n * Gets the permission level\n * @return {Permission} The permission level\n */\n get() {\n let permission;\n\n /* Safari 6+, Chrome 23+ */\n if (this._win.Notification && this._win.Notification.permission)\n permission = this._win.Notification.permission;\n else if (\n this._win.webkitNotifications &&\n this._win.webkitNotifications.checkPermission\n )\n /* Legacy webkit browsers */\n permission = this._permissions[\n this._win.webkitNotifications.checkPermission()\n ];\n else if (navigator.mozNotification)\n /* Firefox Mobile */\n permission = this.GRANTED;\n else if (this._win.external && this._win.external.msIsSiteMode)\n /* IE9+ */\n permission = this._win.external.msIsSiteMode()\n ? this.GRANTED\n : this.DEFAULT;\n else permission = this.GRANTED;\n\n return permission;\n }\n}\n","// @flow\nexport default class Util {\n static isUndefined(obj) {\n return obj === undefined;\n }\n\n static isNull(obs) {\n return obj === null;\n }\n\n static isString(obj) {\n return typeof obj === 'string';\n }\n\n static isFunction(obj) {\n return obj && {}.toString.call(obj) === '[object Function]';\n }\n\n static isObject(obj) {\n return typeof obj === 'object';\n }\n\n static objectMerge(target, source) {\n for (var key in source) {\n if (\n target.hasOwnProperty(key) &&\n this.isObject(target[key]) &&\n this.isObject(source[key])\n ) {\n this.objectMerge(target[key], source[key]);\n } else {\n target[key] = source[key];\n }\n }\n }\n}\n","// @flow\nimport type { Global } from 'types';\n\nexport default class AbstractAgent {\n _win: Global;\n\n constructor(win: Global) {\n this._win = win;\n }\n}\n","// @flow\nimport { AbstractAgent } from 'agents';\nimport { Util } from 'push';\nimport type { PushOptions, GenericNotification, Global } from 'types';\n\n/**\n * Notification agent for modern desktop browsers:\n * Safari 6+, Firefox 22+, Chrome 22+, Opera 25+\n */\nexport default class DesktopAgent extends AbstractAgent {\n _win: Global;\n\n /**\n * Returns a boolean denoting support\n * @returns {Boolean} boolean denoting whether webkit notifications are supported\n */\n isSupported() {\n return this._win.Notification !== undefined;\n }\n\n /**\n * Creates a new notification\n * @param title - notification title\n * @param options - notification options array\n * @returns {Notification}\n */\n create(title: string, options: PushOptions) {\n return new this._win.Notification(title, {\n icon:\n Util.isString(options.icon) ||\n Util.isUndefined(options.icon) ||\n Util.isNull(options.icon)\n ? options.icon\n : options.icon.x32,\n body: options.body,\n tag: options.tag,\n requireInteraction: options.requireInteraction\n });\n }\n\n /**\n * Close a given notification\n * @param notification - notification to close\n */\n close(notification: GenericNotification) {\n notification.close();\n }\n}\n","// @flow\nimport { Util, Messages } from 'push';\nimport { AbstractAgent } from 'agents';\nimport type { Global, GenericNotification, PushOptions } from 'types';\n\n/**\n * Notification agent for modern desktop browsers:\n * Safari 6+, Firefox 22+, Chrome 22+, Opera 25+\n */\nexport default class MobileChromeAgent extends AbstractAgent {\n _win: Global;\n\n /**\n * Returns a boolean denoting support\n * @returns {Boolean} boolean denoting whether webkit notifications are supported\n */\n isSupported() {\n return (\n this._win.navigator !== undefined &&\n this._win.navigator.serviceWorker !== undefined\n );\n }\n\n /**\n * Returns the function body as a string\n * @param func\n */\n getFunctionBody(func: () => void) {\n const str = func.toString().match(/function[^{]+{([\\s\\S]*)}$/);\n return typeof str !== 'undefined' && str !== null && str.length > 1\n ? str[1]\n : null;\n }\n\n /**\n * Creates a new notification\n * @param id ID of notification\n * @param title Title of notification\n * @param options Options object\n * @param serviceWorker ServiceWorker path\n * @param callback Callback function\n */\n create(\n id: number,\n title: string,\n options: PushOptions,\n serviceWorker: string,\n callback: (GenericNotification[]) => void\n ) {\n /* Register ServiceWorker */\n this._win.navigator.serviceWorker.register(serviceWorker);\n\n this._win.navigator.serviceWorker.ready\n .then(registration => {\n /* Local data the service worker will use */\n let localData = {\n id: id,\n link: options.link,\n origin: document.location.href,\n onClick: Util.isFunction(options.onClick)\n ? this.getFunctionBody(options.onClick)\n : '',\n onClose: Util.isFunction(options.onClose)\n ? this.getFunctionBody(options.onClose)\n : ''\n };\n\n /* Merge the local data with user-provided data */\n if (options.data !== undefined && options.data !== null)\n localData = Object.assign(localData, options.data);\n\n /* Show the notification */\n registration\n .showNotification(title, {\n icon: options.icon,\n body: options.body,\n vibrate: options.vibrate,\n tag: options.tag,\n data: localData,\n requireInteraction: options.requireInteraction,\n silent: options.silent\n })\n .then(() => {\n registration.getNotifications().then(notifications => {\n /* Send an empty message so the ServiceWorker knows who the client is */\n registration.active.postMessage('');\n\n /* Trigger callback */\n callback(notifications);\n });\n })\n .catch(function(error) {\n throw new Error(\n Messages.errors.sw_notification_error +\n error.message\n );\n });\n })\n .catch(function(error) {\n throw new Error(\n Messages.errors.sw_registration_error + error.message\n );\n });\n }\n\n /**\n * Close all notification\n */\n close() {\n // Can't do this with service workers\n }\n}\n","// @flow\nimport { AbstractAgent } from 'agents';\nimport type { Global, PushOptions } from 'types';\n\n/**\n * Notification agent for modern desktop browsers:\n * Safari 6+, Firefox 22+, Chrome 22+, Opera 25+\n */\nexport default class MobileFirefoxAgent extends AbstractAgent {\n _win: Global;\n\n /**\n * Returns a boolean denoting support\n * @returns {Boolean} boolean denoting whether webkit notifications are supported\n */\n isSupported() {\n return this._win.navigator.mozNotification !== undefined;\n }\n\n /**\n * Creates a new notification\n * @param title - notification title\n * @param options - notification options array\n * @returns {Notification}\n */\n create(title: string, options: PushOptions) {\n let notification = this._win.navigator.mozNotification.createNotification(\n title,\n options.body,\n options.icon\n );\n\n notification.show();\n\n return notification;\n }\n}\n","// @flow\nimport { AbstractAgent } from 'agents';\nimport { Util } from 'push';\nimport type { PushOptions, Global } from 'types';\n\n/**\n * Notification agent for IE9\n */\nexport default class MSAgent extends AbstractAgent {\n _win: Global;\n\n /**\n * Returns a boolean denoting support\n * @returns {Boolean} boolean denoting whether webkit notifications are supported\n */\n isSupported() {\n return (\n this._win.external !== undefined &&\n this._win.external.msIsSiteMode !== undefined\n );\n }\n\n /**\n * Creates a new notification\n * @param title - notification title\n * @param options - notification options array\n * @returns {Notification}\n */\n create(title: string, options: PushOptions) {\n /* Clear any previous notifications */\n this._win.external.msSiteModeClearIconOverlay();\n\n this._win.external.msSiteModeSetIconOverlay(\n Util.isString(options.icon) || Util.isUndefined(options.icon)\n ? options.icon\n : options.icon.x16,\n title\n );\n\n this._win.external.msSiteModeActivate();\n\n return null;\n }\n\n /**\n * Close a given notification\n * @param notification - notification to close\n */\n close() {\n this._win.external.msSiteModeClearIconOverlay();\n }\n}\n","// @flow\nimport { AbstractAgent } from 'agents';\nimport type { Global, GenericNotification, PushOptions } from 'types';\n\n/**\n * Notification agent for old Chrome versions (and some) Firefox\n */\nexport default class WebKitAgent extends AbstractAgent {\n _win: Global;\n\n /**\n * Returns a boolean denoting support\n * @returns {Boolean} boolean denoting whether webkit notifications are supported\n */\n isSupported() {\n return this._win.webkitNotifications !== undefined;\n }\n\n /**\n * Creates a new notification\n * @param title - notification title\n * @param options - notification options array\n * @returns {Notification}\n */\n create(title: string, options: PushOptions) {\n let notification = this._win.webkitNotifications.createNotification(\n options.icon,\n title,\n options.body\n );\n\n notification.show();\n\n return notification;\n }\n\n /**\n * Close a given notification\n * @param notification - notification to close\n */\n close(notification: GenericNotification) {\n notification.cancel();\n }\n}\n","// @flow\nimport { Push } from 'push';\n\nexport default new Push(typeof window !== 'undefined' ? window : global);\n","// @flow\nimport { Messages, Permission, Util } from 'push';\nimport type { PluginManifest, GenericNotification, PushOptions } from 'types';\n\n/* Import notification agents */\nimport {\n DesktopAgent,\n MobileChromeAgent,\n MobileFirefoxAgent,\n MSAgent,\n WebKitAgent\n} from 'agents';\n\nexport default class Push {\n // Private members\n _agents: {\n desktop: DesktopAgent,\n chrome: MobileChromeAgent,\n firefox: MobileFirefoxAgent,\n ms: MSAgent,\n webkit: WebKitAgent\n };\n _configuration: {\n serviceWorker: string,\n fallback: ({}) => void\n };\n _currentId: number;\n _notifications: {};\n _win: {};\n\n // Public members\n Permission: Permission;\n\n constructor(win: {}) {\n /* Private variables */\n\n /* ID to use for new notifications */\n this._currentId = 0;\n\n /* Map of open notifications */\n this._notifications = {};\n\n /* Window object */\n this._win = win;\n\n /* Public variables */\n this.Permission = new Permission(win);\n\n /* Agents */\n this._agents = {\n desktop: new DesktopAgent(win),\n chrome: new MobileChromeAgent(win),\n firefox: new MobileFirefoxAgent(win),\n ms: new MSAgent(win),\n webkit: new WebKitAgent(win)\n };\n\n this._configuration = {\n serviceWorker: '/serviceWorker.min.js',\n fallback: function(payload) {}\n };\n }\n\n /**\n * Closes a notification\n * @param id ID of notification\n * @returns {boolean} denotes whether the operation was successful\n * @private\n */\n _closeNotification(id: number | string) {\n let success = true;\n const notification = this._notifications[id];\n\n if (notification !== undefined) {\n success = this._removeNotification(id);\n\n /* Safari 6+, Firefox 22+, Chrome 22+, Opera 25+ */\n if (this._agents.desktop.isSupported())\n this._agents.desktop.close(notification);\n else if (this._agents.webkit.isSupported())\n /* Legacy WebKit browsers */\n this._agents.webkit.close(notification);\n else if (this._agents.ms.isSupported())\n /* IE9 */\n this._agents.ms.close();\n else {\n success = false;\n throw new Error(Messages.errors.unknown_interface);\n }\n\n return success;\n }\n\n return false;\n }\n\n /**\n * Adds a notification to the global dictionary of notifications\n * @param {Notification} notification\n * @return {Integer} Dictionary key of the notification\n * @private\n */\n _addNotification(notification: GenericNotification) {\n const id = this._currentId;\n this._notifications[id] = notification;\n this._currentId++;\n return id;\n }\n\n /**\n * Removes a notification with the given ID\n * @param {Integer} id - Dictionary key/ID of the notification to remove\n * @return {Boolean} boolean denoting success\n * @private\n */\n _removeNotification(id: number | string) {\n let success = false;\n\n if (this._notifications.hasOwnProperty(id)) {\n /* We're successful if we omit the given ID from the new array */\n delete this._notifications[id];\n success = true;\n }\n\n return success;\n }\n\n /**\n * Creates the wrapper for a given notification\n *\n * @param {Integer} id - Dictionary key/ID of the notification\n * @param {Map} options - Options used to create the notification\n * @returns {Map} wrapper hashmap object\n * @private\n */\n _prepareNotification(id: number, options: PushOptions) {\n let wrapper;\n\n /* Wrapper used to get/close notification later on */\n wrapper = {\n get: () => {\n return this._notifications[id];\n },\n\n close: () => {\n this._closeNotification(id);\n }\n };\n\n /* Autoclose timeout */\n if (options.timeout) {\n setTimeout(() => {\n wrapper.close();\n }, options.timeout);\n }\n\n return wrapper;\n }\n\n /**\n * Find the most recent notification from a ServiceWorker and add it to the global array\n * @param notifications\n * @private\n */\n _serviceWorkerCallback(\n notifications: GenericNotification[],\n options: PushOptions,\n resolve: ({} | null) => void\n ) {\n let id = this._addNotification(notifications[notifications.length - 1]);\n\n /* Listen for close requests from the ServiceWorker */\n if (navigator && navigator.serviceWorker) {\n navigator.serviceWorker.addEventListener('message', event => {\n const data = JSON.parse(event.data);\n\n if (data.action === 'close' && Number.isInteger(data.id))\n this._removeNotification(data.id);\n });\n\n resolve(this._prepareNotification(id, options));\n }\n\n resolve(null);\n }\n\n /**\n * Callback function for the 'create' method\n * @return {void}\n * @private\n */\n _createCallback(\n title: string,\n options: PushOptions,\n resolve: ({} | null) => void\n ) {\n let notification = null;\n let onClose;\n\n /* Set empty settings if none are specified */\n options = options || {};\n\n /* onClose event handler */\n onClose = id => {\n /* A bit redundant, but covers the cases when close() isn't explicitly called */\n this._removeNotification(id);\n if (Util.isFunction(options.onClose)) {\n options.onClose.call(this, notification);\n }\n };\n\n /* Safari 6+, Firefox 22+, Chrome 22+, Opera 25+ */\n if (this._agents.desktop.isSupported()) {\n try {\n /* Create a notification using the API if possible */\n notification = this._agents.desktop.create(title, options);\n } catch (e) {\n const id = this._currentId;\n const sw = this.config().serviceWorker;\n const cb = notifications =>\n this._serviceWorkerCallback(\n notifications,\n options,\n resolve\n );\n /* Create a Chrome ServiceWorker notification if it isn't supported */\n if (this._agents.chrome.isSupported()) {\n this._agents.chrome.create(id, title, options, sw, cb);\n }\n }\n /* Legacy WebKit browsers */\n } else if (this._agents.webkit.isSupported())\n notification = this._agents.webkit.create(title, options);\n else if (this._agents.firefox.isSupported())\n /* Firefox Mobile */\n this._agents.firefox.create(title, options);\n else if (this._agents.ms.isSupported())\n /* IE9 */\n notification = this._agents.ms.create(title, options);\n else {\n /* Default fallback */\n options.title = title;\n this.config().fallback(options);\n }\n\n if (notification !== null) {\n const id = this._addNotification(notification);\n const wrapper = this._prepareNotification(id, options);\n\n /* Notification callbacks */\n if (Util.isFunction(options.onShow))\n notification.addEventListener('show', options.onShow);\n\n if (Util.isFunction(options.onError))\n notification.addEventListener('error', options.onError);\n\n if (Util.isFunction(options.onClick))\n notification.addEventListener('click', options.onClick);\n\n notification.addEventListener('close', () => {\n onClose(id);\n });\n\n notification.addEventListener('cancel', () => {\n onClose(id);\n });\n\n /* Return the wrapper so the user can call close() */\n resolve(wrapper);\n }\n\n /* By default, pass an empty wrapper */\n resolve(null);\n }\n\n /**\n * Creates and displays a new notification\n * @param {Array} options\n * @return {Promise}\n */\n create(title: string, options: {}): Promise {\n let promiseCallback;\n\n /* Fail if no or an invalid title is provided */\n if (!Util.isString(title)) {\n throw new Error(Messages.errors.invalid_title);\n }\n\n /* Request permission if it isn't granted */\n if (!this.Permission.has()) {\n promiseCallback = (resolve: () => void, reject: string => void) => {\n this.Permission\n .request()\n .then(() => {\n this._createCallback(title, options, resolve);\n })\n .catch(() => {\n reject(Messages.errors.permission_denied);\n });\n };\n } else {\n promiseCallback = (resolve: () => void, reject: string => void) => {\n try {\n this._createCallback(title, options, resolve);\n } catch (e) {\n reject(e);\n }\n };\n }\n\n return new Promise(promiseCallback);\n }\n\n /**\n * Returns the notification count\n * @return {Integer} The notification count\n */\n count() {\n let count = 0;\n let key;\n\n for (key in this._notifications)\n if (this._notifications.hasOwnProperty(key)) count++;\n\n return count;\n }\n\n /**\n * Closes a notification with the given tag\n * @param {String} tag - Tag of the notification to close\n * @return {Boolean} boolean denoting success\n */\n close(tag: string) {\n let key, notification;\n\n for (key in this._notifications) {\n if (this._notifications.hasOwnProperty(key)) {\n notification = this._notifications[key];\n\n /* Run only if the tags match */\n if (notification.tag === tag) {\n /* Call the notification's close() method */\n return this._closeNotification(key);\n }\n }\n }\n }\n\n /**\n * Clears all notifications\n * @return {Boolean} boolean denoting whether the clear was successful in closing all notifications\n */\n clear() {\n let key,\n success = true;\n\n for (key in this._notifications)\n if (this._notifications.hasOwnProperty(key))\n success = success && this._closeNotification(key);\n\n return success;\n }\n\n /**\n * Denotes whether Push is supported in the current browser\n * @returns {boolean}\n */\n supported() {\n let supported = false;\n\n for (var agent in this._agents)\n if (this._agents.hasOwnProperty(agent))\n supported = supported || this._agents[agent].isSupported();\n\n return supported;\n }\n\n /**\n * Modifies settings or returns all settings if no parameter passed\n * @param settings\n */\n config(settings?: {}) {\n if (\n typeof settings !== 'undefined' ||\n (settings !== null && Util.isObject(settings))\n )\n Util.objectMerge(this._configuration, settings);\n\n return this._configuration;\n }\n\n /**\n * Copies the functions from a plugin to the main library\n * @param plugin\n */\n extend(manifest: PluginManifest) {\n var plugin,\n Plugin,\n hasProp = {}.hasOwnProperty;\n\n if (!hasProp.call(manifest, 'plugin')) {\n throw new Error(Messages.errors.invalid_plugin);\n } else {\n if (\n hasProp.call(manifest, 'config') &&\n Util.isObject(manifest.config) &&\n manifest.config !== null\n ) {\n this.config(manifest.config);\n }\n\n Plugin = manifest.plugin;\n plugin = new Plugin(this.config());\n\n for (var member in plugin) {\n if (\n hasProp.call(plugin, member) &&\n Util.isFunction(plugin[member])\n )\n // $FlowFixMe\n this[member] = plugin[member];\n }\n }\n }\n}\n"],"names":["errors","incompatible","invalid_plugin","invalid_title","permission_denied","sw_notification_error","sw_registration_error","unknown_interface","Permission","win","_win","GRANTED","DEFAULT","DENIED","_permissions","this","onGranted","onDenied","arguments","length","_requestWithCallback","_requestAsPromise","request","existing","get","resolved","resolve","result","_this","Notification","permission","webkitNotifications","checkPermission","requestPermission","then","hasPermissions","isModernAPI","isWebkitAPI","Promise","resolvePromise","rejectPromise","resolver","_this2","isGranted","navigator","mozNotification","external","msIsSiteMode","Util","obj","undefined","obs","toString","call","_typeof","target","source","key","hasOwnProperty","isObject","objectMerge","AbstractAgent","DesktopAgent","title","options","icon","isString","isUndefined","isNull","x32","body","tag","requireInteraction","notification","close","MobileChromeAgent","serviceWorker","func","str","match","id","callback","register","ready","registration","localData","link","origin","document","location","href","onClick","isFunction","getFunctionBody","onClose","data","Object","assign","showNotification","vibrate","silent","getNotifications","notifications","active","postMessage","error","Error","Messages","message","MobileFirefoxAgent","createNotification","show","MSAgent","msSiteModeClearIconOverlay","msSiteModeSetIconOverlay","x16","msSiteModeActivate","WebKitAgent","cancel","_currentId","_notifications","_agents","desktop","chrome","firefox","ms","webkit","_configuration","fallback","payload","success","_removeNotification","isSupported","wrapper","_closeNotification","timeout","setTimeout","_addNotification","addEventListener","event","JSON","parse","action","Number","isInteger","_prepareNotification","_this3","create","e","sw","config","_serviceWorkerCallback","onShow","onError","promiseCallback","has","reject","_this4","_createCallback","count","supported","agent","settings","manifest","plugin","hasProp","member","Plugin","window","global"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2LACA,MAEe,CACXA,OAAQ,CACJC,uBAJY,uDAKZC,yBALY,6GAMZC,wBANY,wDAOZC,4BAPY,6CAQZC,gCARY,2FASZC,gCATY,oFAUZC,4BAVY,6uCCECC,wBAULC,kBACHC,KAAOD,OACPE,QAAU,eACVC,QAAU,eACVC,OAAS,cACTC,aAAe,CAACC,KAAKJ,QAASI,KAAKH,QAASG,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EdxD,KAAKuH,mBAAmB7E,uCAWvCA,EACAyE,GAAU,MAETzE,KAAO1C,KAAKyG,eACTzG,KAAKyG,eAAe9D,eAAeD,KACnCyE,EAAUA,GAAWnH,KAAKuH,mBAAmB7E,WAE9CyE,0CAQH8B,GAAY,MAEX,IAAIC,KAASlJ,KAAK0G,QACf1G,KAAK0G,QAAQ/D,eAAeuG,KAC5BD,EAAYA,GAAajJ,KAAK0G,QAAQwC,GAAO7B,sBAE9C4B,iCAOJE,eAEqB,IAAbA,GACO,OAAbA,GAAqBlH,EAAKW,SAASuG,KAEpClH,EAAKY,YAAY7C,KAAKgH,eAAgBmC,GAEnCnJ,KAAKgH,8CAOToC,OACCC,EAEAC,EAAU,GAAG3G,mBAEZ2G,EAAQhH,KAAK8G,EAAU,gBAClB,IAAIzD,MAAMC,EAAS3G,OAAOE,oBAa3B,IAAIoK,KAVLD,EAAQhH,KAAK8G,EAAU,WACvBnH,EAAKW,SAASwG,EAASb,SACH,OAApBa,EAASb,aAEJA,OAAOa,EAASb,QAIzBc,EAAS,IADTG,EAASJ,EAASC,QACErJ,KAAKuI,UAIjBe,EAAQhH,KAAK+G,EAAQE,IACrBtH,EAAK4C,WAAWwE,EAAOE,WAGlBA,GAAUF,EAAOE,aDja3B,CAA2B,oBAAXE,OAAyBA,OAASC"} \ No newline at end of file +{"version":3,"file":"push.js","sources":["../src/push/Messages.js","../src/push/Permission.js","../src/push/Util.js","../src/agents/AbstractAgent.js","../src/agents/DesktopAgent.js","../src/agents/MobileChromeAgent.js","../src/agents/MobileFirefoxAgent.js","../src/agents/MSAgent.js","../src/agents/WebKitAgent.js","../src/index.js","../src/push/Push.js"],"sourcesContent":["// @flow\nconst errorPrefix = 'PushError:';\n\nexport default {\n errors: {\n incompatible: `${errorPrefix} Push.js is incompatible with browser.`,\n invalid_plugin: `${errorPrefix} plugin class missing from plugin manifest (invalid plugin). Please check the documentation.`,\n invalid_title: `${errorPrefix} title of notification must be a string`,\n permission_denied: `${errorPrefix} permission request declined`,\n sw_notification_error: `${errorPrefix} could not show a ServiceWorker notification due to the following reason: `,\n sw_registration_error: `${errorPrefix} could not register the ServiceWorker due to the following reason: `,\n unknown_interface: `${errorPrefix} unable to create notification: unknown interface`\n }\n};\n","// @flow\nimport type { Global } from 'types';\n\nexport default class Permission {\n // Private members\n _permissions: string[];\n _win: Global;\n\n // Public members\n GRANTED: string;\n DEFAULT: string;\n DENIED: string;\n\n constructor(win: Global) {\n this._win = win;\n this.GRANTED = 'granted';\n this.DEFAULT = 'default';\n this.DENIED = 'denied';\n this._permissions = [this.GRANTED, this.DEFAULT, this.DENIED];\n }\n\n /**\n * Requests permission for desktop notifications\n * @param {Function} onGranted - Function to execute once permission is granted\n * @param {Function} onDenied - Function to execute once permission is denied\n * @return {void, Promise}\n */\n request(onGranted: () => void, onDenied: () => void) {\n return arguments.length > 0\n ? this._requestWithCallback(...arguments)\n : this._requestAsPromise();\n }\n\n /**\n * Old permissions implementation deprecated in favor of a promise based one\n * @deprecated Since V1.0.4\n * @param {Function} onGranted - Function to execute once permission is granted\n * @param {Function} onDenied - Function to execute once permission is denied\n * @return {void}\n */\n _requestWithCallback(onGranted: () => void, onDenied: () => void) {\n const existing = this.get();\n\n var resolved = false;\n var resolve = (result = this._win.Notification.permission) => {\n if (resolved) return;\n resolved = true;\n if (typeof result === 'undefined' && this._win.webkitNotifications)\n result = this._win.webkitNotifications.checkPermission();\n if (result === this.GRANTED || result === 0) {\n if (onGranted) onGranted();\n } else if (onDenied) onDenied();\n };\n var request;\n\n /* Permissions already set */\n if (existing !== this.DEFAULT) {\n resolve(existing);\n } else if (\n this._win.webkitNotifications &&\n this._win.webkitNotifications.checkPermission\n ) {\n /* Safari 6+, Legacy webkit browsers */\n this._win.webkitNotifications.requestPermission(resolve);\n } else if (\n this._win.Notification &&\n this._win.Notification.requestPermission\n ) {\n /* Safari 12+ */\n /* This resolve argument will only be used in Safari */\n /* CHrome, instead, returns a Promise */\n request = this._win.Notification.requestPermission(resolve);\n if (request && request.then) {\n /* Chrome 23+ */\n request.then(resolve).catch(function() {\n if (onDenied) onDenied();\n });\n }\n } else if (onGranted) {\n /* Let the user continue by default */\n onGranted();\n }\n }\n\n /**\n * Requests permission for desktop notifications in a promise based way\n * @return {Promise}\n */\n _requestAsPromise(): Promise {\n const existing = this.get();\n\n let isGranted = result => result === this.GRANTED || result === 0;\n\n /* Permissions already set */\n var hasPermissions = existing !== this.DEFAULT;\n\n /* Safari 6+, Chrome 23+ */\n var isModernAPI =\n this._win.Notification && this._win.Notification.requestPermission;\n\n /* Legacy webkit browsers */\n var isWebkitAPI =\n this._win.webkitNotifications &&\n this._win.webkitNotifications.checkPermission;\n\n return new Promise((resolvePromise, rejectPromise) => {\n var resolved = false;\n var resolver = result => {\n if (resolved) return;\n resolved = true;\n isGranted(result) ? resolvePromise() : rejectPromise();\n };\n var request;\n\n if (hasPermissions) {\n resolver(existing);\n } else if (isWebkitAPI) {\n this._win.webkitNotifications.requestPermission(result => {\n resolver(result);\n });\n } else if (isModernAPI) {\n /* Safari 12+ */\n /* This resolver argument will only be used in Safari */\n /* CHrome, instead, returns a Promise */\n request = this._win.Notification.requestPermission(resolver);\n if (request && request.then) {\n /* Chrome 23+ */\n request.then(resolver).catch(rejectPromise);\n }\n } else resolvePromise();\n });\n }\n\n /**\n * Returns whether Push has been granted permission to run\n * @return {Boolean}\n */\n has() {\n return this.get() === this.GRANTED;\n }\n\n /**\n * Gets the permission level\n * @return {Permission} The permission level\n */\n get() {\n let permission;\n\n /* Safari 6+, Chrome 23+ */\n if (this._win.Notification && this._win.Notification.permission)\n permission = this._win.Notification.permission;\n else if (\n this._win.webkitNotifications &&\n this._win.webkitNotifications.checkPermission\n )\n /* Legacy webkit browsers */\n permission = this._permissions[\n this._win.webkitNotifications.checkPermission()\n ];\n else if (navigator.mozNotification)\n /* Firefox Mobile */\n permission = this.GRANTED;\n else if (this._win.external && this._win.external.msIsSiteMode)\n /* IE9+ */\n permission = this._win.external.msIsSiteMode()\n ? this.GRANTED\n : this.DEFAULT;\n else permission = this.GRANTED;\n\n return permission;\n }\n}\n","// @flow\nexport default class Util {\n static isUndefined(obj) {\n return obj === undefined;\n }\n\n static isNull(obs) {\n return obj === null;\n }\n\n static isString(obj) {\n return typeof obj === 'string';\n }\n\n static isFunction(obj) {\n return obj && {}.toString.call(obj) === '[object Function]';\n }\n\n static isObject(obj) {\n return typeof obj === 'object';\n }\n\n static objectMerge(target, source) {\n for (var key in source) {\n if (\n target.hasOwnProperty(key) &&\n this.isObject(target[key]) &&\n this.isObject(source[key])\n ) {\n this.objectMerge(target[key], source[key]);\n } else {\n target[key] = source[key];\n }\n }\n }\n}\n","// @flow\nimport type { Global } from 'types';\n\nexport default class AbstractAgent {\n _win: Global;\n\n constructor(win: Global) {\n this._win = win;\n }\n}\n","// @flow\nimport { AbstractAgent } from 'agents';\nimport { Util } from 'push';\nimport type { PushOptions, GenericNotification, Global } from 'types';\n\n/**\n * Notification agent for modern desktop browsers:\n * Safari 6+, Firefox 22+, Chrome 22+, Opera 25+\n */\nexport default class DesktopAgent extends AbstractAgent {\n _win: Global;\n\n /**\n * Returns a boolean denoting support\n * @returns {Boolean} boolean denoting whether webkit notifications are supported\n */\n isSupported() {\n return this._win.Notification !== undefined;\n }\n\n /**\n * Creates a new notification\n * @param title - notification title\n * @param options - notification options array\n * @returns {Notification}\n */\n create(title: string, options: PushOptions) {\n return new this._win.Notification(title, {\n icon:\n Util.isString(options.icon) ||\n Util.isUndefined(options.icon) ||\n Util.isNull(options.icon)\n ? options.icon\n : options.icon.x32,\n body: options.body,\n tag: options.tag,\n requireInteraction: options.requireInteraction\n });\n }\n\n /**\n * Close a given notification\n * @param notification - notification to close\n */\n close(notification: GenericNotification) {\n notification.close();\n }\n}\n","// @flow\nimport { Util, Messages } from 'push';\nimport { AbstractAgent } from 'agents';\nimport type { Global, GenericNotification, PushOptions } from 'types';\n\n/**\n * Notification agent for modern desktop browsers:\n * Safari 6+, Firefox 22+, Chrome 22+, Opera 25+\n */\nexport default class MobileChromeAgent extends AbstractAgent {\n _win: Global;\n\n /**\n * Returns a boolean denoting support\n * @returns {Boolean} boolean denoting whether webkit notifications are supported\n */\n isSupported() {\n return (\n this._win.navigator !== undefined &&\n this._win.navigator.serviceWorker !== undefined\n );\n }\n\n /**\n * Returns the function body as a string\n * @param func\n */\n getFunctionBody(func: () => void) {\n const str = func.toString().match(/function[^{]+{([\\s\\S]*)}$/);\n return typeof str !== 'undefined' && str !== null && str.length > 1\n ? str[1]\n : null;\n }\n\n /**\n * Creates a new notification\n * @param id ID of notification\n * @param title Title of notification\n * @param options Options object\n * @param serviceWorker ServiceWorker path\n * @param callback Callback function\n */\n create(\n id: number,\n title: string,\n options: PushOptions,\n serviceWorker: string,\n callback: (GenericNotification[]) => void\n ) {\n /* Register ServiceWorker */\n this._win.navigator.serviceWorker.register(serviceWorker);\n\n this._win.navigator.serviceWorker.ready\n .then(registration => {\n /* Local data the service worker will use */\n let localData = {\n id: id,\n link: options.link,\n origin: document.location.href,\n onClick: Util.isFunction(options.onClick)\n ? this.getFunctionBody(options.onClick)\n : '',\n onClose: Util.isFunction(options.onClose)\n ? this.getFunctionBody(options.onClose)\n : ''\n };\n\n /* Merge the local data with user-provided data */\n if (options.data !== undefined && options.data !== null)\n localData = Object.assign(localData, options.data);\n\n /* Show the notification */\n registration\n .showNotification(title, {\n icon: options.icon,\n body: options.body,\n vibrate: options.vibrate,\n tag: options.tag,\n data: localData,\n requireInteraction: options.requireInteraction,\n silent: options.silent\n })\n .then(() => {\n registration.getNotifications().then(notifications => {\n /* Send an empty message so the ServiceWorker knows who the client is */\n registration.active.postMessage('');\n\n /* Trigger callback */\n callback(notifications);\n });\n })\n .catch(function(error) {\n throw new Error(\n Messages.errors.sw_notification_error +\n error.message\n );\n });\n })\n .catch(function(error) {\n throw new Error(\n Messages.errors.sw_registration_error + error.message\n );\n });\n }\n\n /**\n * Close all notification\n */\n close() {\n // Can't do this with service workers\n }\n}\n","// @flow\nimport { AbstractAgent } from 'agents';\nimport type { Global, PushOptions } from 'types';\n\n/**\n * Notification agent for modern desktop browsers:\n * Safari 6+, Firefox 22+, Chrome 22+, Opera 25+\n */\nexport default class MobileFirefoxAgent extends AbstractAgent {\n _win: Global;\n\n /**\n * Returns a boolean denoting support\n * @returns {Boolean} boolean denoting whether webkit notifications are supported\n */\n isSupported() {\n return this._win.navigator.mozNotification !== undefined;\n }\n\n /**\n * Creates a new notification\n * @param title - notification title\n * @param options - notification options array\n * @returns {Notification}\n */\n create(title: string, options: PushOptions) {\n let notification = this._win.navigator.mozNotification.createNotification(\n title,\n options.body,\n options.icon\n );\n\n notification.show();\n\n return notification;\n }\n}\n","// @flow\nimport { AbstractAgent } from 'agents';\nimport { Util } from 'push';\nimport type { PushOptions, Global } from 'types';\n\n/**\n * Notification agent for IE9\n */\nexport default class MSAgent extends AbstractAgent {\n _win: Global;\n\n /**\n * Returns a boolean denoting support\n * @returns {Boolean} boolean denoting whether webkit notifications are supported\n */\n isSupported() {\n return (\n this._win.external !== undefined &&\n this._win.external.msIsSiteMode !== undefined\n );\n }\n\n /**\n * Creates a new notification\n * @param title - notification title\n * @param options - notification options array\n * @returns {Notification}\n */\n create(title: string, options: PushOptions) {\n /* Clear any previous notifications */\n this._win.external.msSiteModeClearIconOverlay();\n\n this._win.external.msSiteModeSetIconOverlay(\n Util.isString(options.icon) || Util.isUndefined(options.icon)\n ? options.icon\n : options.icon.x16,\n title\n );\n\n this._win.external.msSiteModeActivate();\n\n return null;\n }\n\n /**\n * Close a given notification\n * @param notification - notification to close\n */\n close() {\n this._win.external.msSiteModeClearIconOverlay();\n }\n}\n","// @flow\nimport { AbstractAgent } from 'agents';\nimport type { Global, GenericNotification, PushOptions } from 'types';\n\n/**\n * Notification agent for old Chrome versions (and some) Firefox\n */\nexport default class WebKitAgent extends AbstractAgent {\n _win: Global;\n\n /**\n * Returns a boolean denoting support\n * @returns {Boolean} boolean denoting whether webkit notifications are supported\n */\n isSupported() {\n return this._win.webkitNotifications !== undefined;\n }\n\n /**\n * Creates a new notification\n * @param title - notification title\n * @param options - notification options array\n * @returns {Notification}\n */\n create(title: string, options: PushOptions) {\n let notification = this._win.webkitNotifications.createNotification(\n options.icon,\n title,\n options.body\n );\n\n notification.show();\n\n return notification;\n }\n\n /**\n * Close a given notification\n * @param notification - notification to close\n */\n close(notification: GenericNotification) {\n notification.cancel();\n }\n}\n","// @flow\nimport { Push } from 'push';\n\nexport default new Push(typeof window !== 'undefined' ? window : global);\n","// @flow\nimport { Messages, Permission, Util } from 'push';\nimport type { PluginManifest, GenericNotification, PushOptions } from 'types';\n\n/* Import notification agents */\nimport {\n DesktopAgent,\n MobileChromeAgent,\n MobileFirefoxAgent,\n MSAgent,\n WebKitAgent\n} from 'agents';\n\nexport default class Push {\n // Private members\n _agents: {\n desktop: DesktopAgent,\n chrome: MobileChromeAgent,\n firefox: MobileFirefoxAgent,\n ms: MSAgent,\n webkit: WebKitAgent\n };\n _configuration: {\n serviceWorker: string,\n fallback: ({}) => void\n };\n _currentId: number;\n _notifications: {};\n _win: {};\n\n // Public members\n Permission: Permission;\n\n constructor(win: {}) {\n /* Private variables */\n\n /* ID to use for new notifications */\n this._currentId = 0;\n\n /* Map of open notifications */\n this._notifications = {};\n\n /* Window object */\n this._win = win;\n\n /* Public variables */\n this.Permission = new Permission(win);\n\n /* Agents */\n this._agents = {\n desktop: new DesktopAgent(win),\n chrome: new MobileChromeAgent(win),\n firefox: new MobileFirefoxAgent(win),\n ms: new MSAgent(win),\n webkit: new WebKitAgent(win)\n };\n\n this._configuration = {\n serviceWorker: '/serviceWorker.min.js',\n fallback: function(payload) {}\n };\n }\n\n /**\n * Closes a notification\n * @param id ID of notification\n * @returns {boolean} denotes whether the operation was successful\n * @private\n */\n _closeNotification(id: number | string) {\n let success = true;\n const notification = this._notifications[id];\n\n if (notification !== undefined) {\n success = this._removeNotification(id);\n\n /* Safari 6+, Firefox 22+, Chrome 22+, Opera 25+ */\n if (this._agents.desktop.isSupported())\n this._agents.desktop.close(notification);\n else if (this._agents.webkit.isSupported())\n /* Legacy WebKit browsers */\n this._agents.webkit.close(notification);\n else if (this._agents.ms.isSupported())\n /* IE9 */\n this._agents.ms.close();\n else {\n success = false;\n throw new Error(Messages.errors.unknown_interface);\n }\n\n return success;\n }\n\n return false;\n }\n\n /**\n * Adds a notification to the global dictionary of notifications\n * @param {Notification} notification\n * @return {Integer} Dictionary key of the notification\n * @private\n */\n _addNotification(notification: GenericNotification) {\n const id = this._currentId;\n this._notifications[id] = notification;\n this._currentId++;\n return id;\n }\n\n /**\n * Removes a notification with the given ID\n * @param {Integer} id - Dictionary key/ID of the notification to remove\n * @return {Boolean} boolean denoting success\n * @private\n */\n _removeNotification(id: number | string) {\n let success = false;\n\n if (this._notifications.hasOwnProperty(id)) {\n /* We're successful if we omit the given ID from the new array */\n delete this._notifications[id];\n success = true;\n }\n\n return success;\n }\n\n /**\n * Creates the wrapper for a given notification\n *\n * @param {Integer} id - Dictionary key/ID of the notification\n * @param {Map} options - Options used to create the notification\n * @returns {Map} wrapper hashmap object\n * @private\n */\n _prepareNotification(id: number, options: PushOptions) {\n let wrapper;\n\n /* Wrapper used to get/close notification later on */\n wrapper = {\n get: () => {\n return this._notifications[id];\n },\n\n close: () => {\n this._closeNotification(id);\n }\n };\n\n /* Autoclose timeout */\n if (options.timeout) {\n setTimeout(() => {\n wrapper.close();\n }, options.timeout);\n }\n\n return wrapper;\n }\n\n /**\n * Find the most recent notification from a ServiceWorker and add it to the global array\n * @param notifications\n * @private\n */\n _serviceWorkerCallback(\n notifications: GenericNotification[],\n options: PushOptions,\n resolve: ({} | null) => void\n ) {\n let id = this._addNotification(notifications[notifications.length - 1]);\n\n /* Listen for close requests from the ServiceWorker */\n if (navigator && navigator.serviceWorker) {\n navigator.serviceWorker.addEventListener('message', event => {\n const data = JSON.parse(event.data);\n\n if (data.action === 'close' && Number.isInteger(data.id))\n this._removeNotification(data.id);\n });\n\n resolve(this._prepareNotification(id, options));\n }\n\n resolve(null);\n }\n\n /**\n * Callback function for the 'create' method\n * @return {void}\n * @private\n */\n _createCallback(\n title: string,\n options: PushOptions,\n resolve: ({} | null) => void\n ) {\n let notification = null;\n let onClose;\n\n /* Set empty settings if none are specified */\n options = options || {};\n\n /* onClose event handler */\n onClose = id => {\n /* A bit redundant, but covers the cases when close() isn't explicitly called */\n this._removeNotification(id);\n if (Util.isFunction(options.onClose)) {\n options.onClose.call(this, notification);\n }\n };\n\n /* Safari 6+, Firefox 22+, Chrome 22+, Opera 25+ */\n if (this._agents.desktop.isSupported()) {\n try {\n /* Create a notification using the API if possible */\n notification = this._agents.desktop.create(title, options);\n } catch (e) {\n const id = this._currentId;\n const sw = this.config().serviceWorker;\n const cb = notifications =>\n this._serviceWorkerCallback(\n notifications,\n options,\n resolve\n );\n /* Create a Chrome ServiceWorker notification if it isn't supported */\n if (this._agents.chrome.isSupported()) {\n this._agents.chrome.create(id, title, options, sw, cb);\n }\n }\n /* Legacy WebKit browsers */\n } else if (this._agents.webkit.isSupported())\n notification = this._agents.webkit.create(title, options);\n else if (this._agents.firefox.isSupported())\n /* Firefox Mobile */\n this._agents.firefox.create(title, options);\n else if (this._agents.ms.isSupported())\n /* IE9 */\n notification = this._agents.ms.create(title, options);\n else {\n /* Default fallback */\n options.title = title;\n this.config().fallback(options);\n }\n\n if (notification !== null) {\n const id = this._addNotification(notification);\n const wrapper = this._prepareNotification(id, options);\n\n /* Notification callbacks */\n if (Util.isFunction(options.onShow))\n notification.addEventListener('show', options.onShow);\n\n if (Util.isFunction(options.onError))\n notification.addEventListener('error', options.onError);\n\n if (Util.isFunction(options.onClick))\n notification.addEventListener('click', options.onClick);\n\n notification.addEventListener('close', () => {\n onClose(id);\n });\n\n notification.addEventListener('cancel', () => {\n onClose(id);\n });\n\n /* Return the wrapper so the user can call close() */\n resolve(wrapper);\n }\n\n /* By default, pass an empty wrapper */\n resolve(null);\n }\n\n /**\n * Creates and displays a new notification\n * @param {Array} options\n * @return {Promise}\n */\n create(title: string, options: {}): Promise {\n let promiseCallback;\n\n /* Fail if no or an invalid title is provided */\n if (!Util.isString(title)) {\n throw new Error(Messages.errors.invalid_title);\n }\n\n /* Request permission if it isn't granted */\n if (!this.Permission.has()) {\n promiseCallback = (resolve: () => void, reject: string => void) => {\n this.Permission\n .request()\n .then(() => {\n this._createCallback(title, options, resolve);\n })\n .catch(() => {\n reject(Messages.errors.permission_denied);\n });\n };\n } else {\n promiseCallback = (resolve: () => void, reject: string => void) => {\n try {\n this._createCallback(title, options, resolve);\n } catch (e) {\n reject(e);\n }\n };\n }\n\n return new Promise(promiseCallback);\n }\n\n /**\n * Returns the notification count\n * @return {Integer} The notification count\n */\n count() {\n let count = 0;\n let key;\n\n for (key in this._notifications)\n if (this._notifications.hasOwnProperty(key)) count++;\n\n return count;\n }\n\n /**\n * Closes a notification with the given tag\n * @param {String} tag - Tag of the notification to close\n * @return {Boolean} boolean denoting success\n */\n close(tag: string) {\n let key, notification;\n\n for (key in this._notifications) {\n if (this._notifications.hasOwnProperty(key)) {\n notification = this._notifications[key];\n\n /* Run only if the tags match */\n if (notification.tag === tag) {\n /* Call the notification's close() method */\n return this._closeNotification(key);\n }\n }\n }\n }\n\n /**\n * Clears all notifications\n * @return {Boolean} boolean denoting whether the clear was successful in closing all notifications\n */\n clear() {\n let key,\n success = true;\n\n for (key in this._notifications)\n if (this._notifications.hasOwnProperty(key))\n success = success && this._closeNotification(key);\n\n return success;\n }\n\n /**\n * Denotes whether Push is supported in the current browser\n * @returns {boolean}\n */\n supported() {\n let supported = false;\n\n for (var agent in this._agents)\n if (this._agents.hasOwnProperty(agent))\n supported = supported || this._agents[agent].isSupported();\n\n return supported;\n }\n\n /**\n * Modifies settings or returns all settings if no parameter passed\n * @param settings\n */\n config(settings?: {}) {\n if (\n typeof settings !== 'undefined' ||\n (settings !== null && Util.isObject(settings))\n )\n Util.objectMerge(this._configuration, settings);\n\n return this._configuration;\n }\n\n /**\n * Copies the functions from a plugin to the main library\n * @param plugin\n */\n extend(manifest: PluginManifest) {\n var plugin,\n Plugin,\n hasProp = {}.hasOwnProperty;\n\n if (!hasProp.call(manifest, 'plugin')) {\n throw new Error(Messages.errors.invalid_plugin);\n } else {\n if (\n hasProp.call(manifest, 'config') &&\n Util.isObject(manifest.config) &&\n manifest.config !== null\n ) {\n this.config(manifest.config);\n }\n\n Plugin = manifest.plugin;\n plugin = new Plugin(this.config());\n\n for (var member in plugin) {\n if (\n hasProp.call(plugin, member) &&\n Util.isFunction(plugin[member])\n )\n // $FlowFixMe\n this[member] = plugin[member];\n }\n }\n }\n}\n"],"names":["errors","incompatible","invalid_plugin","invalid_title","permission_denied","sw_notification_error","sw_registration_error","unknown_interface","Permission","win","_win","GRANTED","DEFAULT","DENIED","_permissions","this","onGranted","onDenied","arguments","length","_requestWithCallback","_requestAsPromise","request","existing","get","resolved","resolve","result","_this","Notification","permission","webkitNotifications","checkPermission","requestPermission","then","hasPermissions","isModernAPI","isWebkitAPI","Promise","resolvePromise","rejectPromise","resolver","_this2","isGranted","navigator","mozNotification","external","msIsSiteMode","Util","obj","undefined","obs","toString","call","_typeof","target","source","key","hasOwnProperty","isObject","objectMerge","AbstractAgent","DesktopAgent","title","options","icon","isString","isUndefined","isNull","x32","body","tag","requireInteraction","notification","close","MobileChromeAgent","serviceWorker","func","str","match","id","callback","register","ready","registration","localData","link","origin","document","location","href","onClick","isFunction","getFunctionBody","onClose","data","Object","assign","showNotification","vibrate","silent","getNotifications","notifications","active","postMessage","error","Error","Messages","message","MobileFirefoxAgent","createNotification","show","MSAgent","msSiteModeClearIconOverlay","msSiteModeSetIconOverlay","x16","msSiteModeActivate","WebKitAgent","cancel","_currentId","_notifications","_agents","desktop","chrome","firefox","ms","webkit","_configuration","fallback","payload","success","_removeNotification","isSupported","wrapper","_closeNotification","timeout","setTimeout","_addNotification","addEventListener","event","JSON","parse","action","Number","isInteger","_prepareNotification","_this3","create","e","sw","config","_serviceWorkerCallback","onShow","onError","promiseCallback","has","reject","_this4","_createCallback","count","supported","agent","settings","manifest","plugin","hasProp","member","Plugin","window","global"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0LACA,MAEe,CACXA,OAAQ,CACJC,uBAJY,uDAKZC,yBALY,6GAMZC,wBANY,wDAOZC,4BAPY,6CAQZC,gCARY,2FASZC,gCATY,oFAUZC,4BAVY,6uCCECC,wBAULC,kBACHC,KAAOD,OACPE,QAAU,eACVC,QAAU,eACVC,OAAS,cACTC,aAAe,CAACC,KAAKJ,QAASI,KAAKH,QAASG,KAAKF,kDASlDG,EAAuBC,UACpBC,UAAUC,OAAS,EACpBJ,KAAKK,gCAAwBF,WAC7BH,KAAKM,iEAUML,EAAuBC,OAapCK,SAZEC,EAAWR,KAAKS,MAElBC,GAAW,EACXC,EAAU,eAACC,yDAASC,EAAKlB,KAAKmB,aAAaC,WACvCL,IACJA,GAAW,OACW,IAAXE,GAA0BC,EAAKlB,KAAKqB,sBAC3CJ,EAASC,EAAKlB,KAAKqB,oBAAoBC,mBACvCL,IAAWC,EAAKjB,SAAsB,IAAXgB,EACvBX,GAAWA,IACRC,GAAUA,MAKrBM,IAAaR,KAAKH,QAClBc,EAAQH,GAERR,KAAKL,KAAKqB,qBACVhB,KAAKL,KAAKqB,oBAAoBC,qBAGzBtB,KAAKqB,oBAAoBE,kBAAkBP,GAEhDX,KAAKL,KAAKmB,cACVd,KAAKL,KAAKmB,aAAaI,mBAKvBX,EAAUP,KAAKL,KAAKmB,aAAaI,kBAAkBP,KACpCJ,EAAQY,MAEnBZ,EAAQY,KAAKR,SAAe,WACpBT,GAAUA,MAGfD,GAEPA,2DASEO,EAAWR,KAAKS,MAKlBW,EAAiBZ,IAAaR,KAAKH,QAGnCwB,EACArB,KAAKL,KAAKmB,cAAgBd,KAAKL,KAAKmB,aAAaI,kBAGjDI,EACAtB,KAAKL,KAAKqB,qBACVhB,KAAKL,KAAKqB,oBAAoBC,uBAE3B,IAAIM,QAAQ,SAACC,EAAgBC,OAO5BlB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Ac,UACAY,KAAK,WACF2H,EAAKC,gBAAgB/F,EAAOC,EAAStC,WAElC,WACHkI,EAAOjD,EAAS3G,OAAOI,sBAahC,IAAIkC,QAAQoH,uCASfjG,EADAsG,EAAQ,MAGPtG,KAAO1C,KAAKyG,eACTzG,KAAKyG,eAAe9D,eAAeD,IAAMsG,WAE1CA,gCAQLxF,OACEd,MAECA,KAAO1C,KAAKyG,kBACTzG,KAAKyG,eAAe9D,eAAeD,IACpB1C,KAAKyG,eAAe/D,GAGlBc,MAAQA,SAEdxD,KAAKuH,mBAAmB7E,uCAWvCA,EACAyE,GAAU,MAETzE,KAAO1C,KAAKyG,eACTzG,KAAKyG,eAAe9D,eAAeD,KACnCyE,EAAUA,GAAWnH,KAAKuH,mBAAmB7E,WAE9CyE,0CAQH8B,GAAY,MAEX,IAAIC,KAASlJ,KAAK0G,QACf1G,KAAK0G,QAAQ/D,eAAeuG,KAC5BD,EAAYA,GAAajJ,KAAK0G,QAAQwC,GAAO7B,sBAE9C4B,iCAOJE,eAEqB,IAAbA,GACO,OAAbA,GAAqBlH,EAAKW,SAASuG,KAEpClH,EAAKY,YAAY7C,KAAKgH,eAAgBmC,GAEnCnJ,KAAKgH,8CAOToC,OACCC,EAEAC,EAAU,GAAG3G,mBAEZ2G,EAAQhH,KAAK8G,EAAU,gBAClB,IAAIzD,MAAMC,EAAS3G,OAAOE,oBAa3B,IAAIoK,KAVLD,EAAQhH,KAAK8G,EAAU,WACvBnH,EAAKW,SAASwG,EAASb,SACH,OAApBa,EAASb,aAEJA,OAAOa,EAASb,QAIzBc,EAAS,IADTG,EAASJ,EAASC,QACErJ,KAAKuI,UAIjBe,EAAQhH,KAAK+G,EAAQE,IACrBtH,EAAK4C,WAAWwE,EAAOE,WAGlBA,GAAUF,EAAOE,aDja3B,CAA2B,oBAAXE,OAAyBA,OAASC"} \ No newline at end of file diff --git a/bin/push.min.js b/bin/push.min.js index 35b7e6a0..2e7744c4 100644 --- a/bin/push.min.js +++ b/bin/push.min.js @@ -35,42 +35,5 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -/** - * @license - * - * Push v1.0.9 - * ========= - * A compact, cross-browser solution for the JavaScript Notifications API - * - * Credits - * ------- - * Tsvetan Tsvetkov (ttsvetko) - * Alex Gibson (alexgibson) - * - * License - * ------- - * - * The MIT License (MIT) - * - * Copyright (c) 2015-2017 Tyler Nickerson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -!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;n0?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,i),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}(l),_=function(t){function e(){return n(this,e),a(this,s(e).apply(this,arguments))}return r(e,t),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}(l),v=function(i){function t(){return n(this,t),a(this,s(t).apply(this,arguments))}return r(t,i),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}(l),d=function(i){function t(){return n(this,t),a(this,s(t).apply(this,arguments))}return r(t,i),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}(l),w=function(i){function t(){return n(this,t),a(this,s(t).apply(this,arguments))}return r(t,i),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}(l);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)})); +!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;n0?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 diff --git a/bin/push.min.js.map b/bin/push.min.js.map index 2709ac70..8d28da42 100644 --- a/bin/push.min.js.map +++ b/bin/push.min.js.map @@ -1 +1 @@ -{"version":3,"file":"push.min.js","sources":["../src/push/Messages.js","../src/push/Permission.js","../src/push/Util.js","../src/agents/AbstractAgent.js","../src/agents/DesktopAgent.js","../src/agents/MobileChromeAgent.js","../src/agents/MobileFirefoxAgent.js","../src/agents/MSAgent.js","../src/agents/WebKitAgent.js","../src/index.js","../src/push/Push.js"],"sourcesContent":["// @flow\nconst errorPrefix = 'PushError:';\n\nexport default {\n errors: {\n incompatible: `${errorPrefix} Push.js is incompatible with browser.`,\n invalid_plugin: `${errorPrefix} plugin class missing from plugin manifest (invalid plugin). Please check the documentation.`,\n invalid_title: `${errorPrefix} title of notification must be a string`,\n permission_denied: `${errorPrefix} permission request declined`,\n sw_notification_error: `${errorPrefix} could not show a ServiceWorker notification due to the following reason: `,\n sw_registration_error: `${errorPrefix} could not register the ServiceWorker due to the following reason: `,\n unknown_interface: `${errorPrefix} unable to create notification: unknown interface`\n }\n};\n","// @flow\nimport type { Global } from 'types';\n\nexport default class Permission {\n // Private members\n _permissions: string[];\n _win: Global;\n\n // Public members\n GRANTED: string;\n DEFAULT: string;\n DENIED: string;\n\n constructor(win: Global) {\n this._win = win;\n this.GRANTED = 'granted';\n this.DEFAULT = 'default';\n this.DENIED = 'denied';\n this._permissions = [this.GRANTED, this.DEFAULT, this.DENIED];\n }\n\n /**\n * Requests permission for desktop notifications\n * @param {Function} onGranted - Function to execute once permission is granted\n * @param {Function} onDenied - Function to execute once permission is denied\n * @return {void, Promise}\n */\n request(onGranted: () => void, onDenied: () => void) {\n return arguments.length > 0\n ? this._requestWithCallback(...arguments)\n : this._requestAsPromise();\n }\n\n /**\n * Old permissions implementation deprecated in favor of a promise based one\n * @deprecated Since V1.0.4\n * @param {Function} onGranted - Function to execute once permission is granted\n * @param {Function} onDenied - Function to execute once permission is denied\n * @return {void}\n */\n _requestWithCallback(onGranted: () => void, onDenied: () => void) {\n const existing = this.get();\n\n var resolved = false;\n var resolve = (result = this._win.Notification.permission) => {\n if (resolved) return;\n resolved = true;\n if (typeof result === 'undefined' && this._win.webkitNotifications)\n result = this._win.webkitNotifications.checkPermission();\n if (result === this.GRANTED || result === 0) {\n if (onGranted) onGranted();\n } else if (onDenied) onDenied();\n };\n var request;\n\n /* Permissions already set */\n if (existing !== this.DEFAULT) {\n resolve(existing);\n } else if (\n this._win.webkitNotifications &&\n this._win.webkitNotifications.checkPermission\n ) {\n /* Safari 6+, Legacy webkit browsers */\n this._win.webkitNotifications.requestPermission(resolve);\n } else if (\n this._win.Notification &&\n this._win.Notification.requestPermission\n ) {\n /* Safari 12+ */\n /* This resolve argument will only be used in Safari */\n /* CHrome, instead, returns a Promise */\n request = this._win.Notification.requestPermission(resolve);\n if (request && request.then) {\n /* Chrome 23+ */\n request.then(resolve).catch(function() {\n if (onDenied) onDenied();\n });\n }\n } else if (onGranted) {\n /* Let the user continue by default */\n onGranted();\n }\n }\n\n /**\n * Requests permission for desktop notifications in a promise based way\n * @return {Promise}\n */\n _requestAsPromise(): Promise {\n const existing = this.get();\n\n let isGranted = result => result === this.GRANTED || result === 0;\n\n /* Permissions already set */\n var hasPermissions = existing !== this.DEFAULT;\n\n /* Safari 6+, Chrome 23+ */\n var isModernAPI =\n this._win.Notification && this._win.Notification.requestPermission;\n\n /* Legacy webkit browsers */\n var isWebkitAPI =\n this._win.webkitNotifications &&\n this._win.webkitNotifications.checkPermission;\n\n return new Promise((resolvePromise, rejectPromise) => {\n var resolved = false;\n var resolver = result => {\n if (resolved) return;\n resolved = true;\n isGranted(result) ? resolvePromise() : rejectPromise();\n };\n var request;\n\n if (hasPermissions) {\n resolver(existing);\n } else if (isWebkitAPI) {\n this._win.webkitNotifications.requestPermission(result => {\n resolver(result);\n });\n } else if (isModernAPI) {\n /* Safari 12+ */\n /* This resolver argument will only be used in Safari */\n /* CHrome, instead, returns a Promise */\n request = this._win.Notification.requestPermission(resolver);\n if (request && request.then) {\n /* Chrome 23+ */\n request.then(resolver).catch(rejectPromise);\n }\n } else resolvePromise();\n });\n }\n\n /**\n * Returns whether Push has been granted permission to run\n * @return {Boolean}\n */\n has() {\n return this.get() === this.GRANTED;\n }\n\n /**\n * Gets the permission level\n * @return {Permission} The permission level\n */\n get() {\n let permission;\n\n /* Safari 6+, Chrome 23+ */\n if (this._win.Notification && this._win.Notification.permission)\n permission = this._win.Notification.permission;\n else if (\n this._win.webkitNotifications &&\n this._win.webkitNotifications.checkPermission\n )\n /* Legacy webkit browsers */\n permission = this._permissions[\n this._win.webkitNotifications.checkPermission()\n ];\n else if (navigator.mozNotification)\n /* Firefox Mobile */\n permission = this.GRANTED;\n else if (this._win.external && this._win.external.msIsSiteMode)\n /* IE9+ */\n permission = this._win.external.msIsSiteMode()\n ? this.GRANTED\n : this.DEFAULT;\n else permission = this.GRANTED;\n\n return permission;\n }\n}\n","// @flow\nexport default class Util {\n static isUndefined(obj) {\n return obj === undefined;\n }\n\n static isNull(obs) {\n return obj === null;\n }\n\n static isString(obj) {\n return typeof obj === 'string';\n }\n\n static isFunction(obj) {\n return obj && {}.toString.call(obj) === '[object Function]';\n }\n\n static isObject(obj) {\n return typeof obj === 'object';\n }\n\n static objectMerge(target, source) {\n for (var key in source) {\n if (\n target.hasOwnProperty(key) &&\n this.isObject(target[key]) &&\n this.isObject(source[key])\n ) {\n this.objectMerge(target[key], source[key]);\n } else {\n target[key] = source[key];\n }\n }\n }\n}\n","// @flow\nimport type { Global } from 'types';\n\nexport default class AbstractAgent {\n _win: Global;\n\n constructor(win: Global) {\n this._win = win;\n }\n}\n","// @flow\nimport { AbstractAgent } from 'agents';\nimport { Util } from 'push';\nimport type { PushOptions, GenericNotification, Global } from 'types';\n\n/**\n * Notification agent for modern desktop browsers:\n * Safari 6+, Firefox 22+, Chrome 22+, Opera 25+\n */\nexport default class DesktopAgent extends AbstractAgent {\n _win: Global;\n\n /**\n * Returns a boolean denoting support\n * @returns {Boolean} boolean denoting whether webkit notifications are supported\n */\n isSupported() {\n return this._win.Notification !== undefined;\n }\n\n /**\n * Creates a new notification\n * @param title - notification title\n * @param options - notification options array\n * @returns {Notification}\n */\n create(title: string, options: PushOptions) {\n return new this._win.Notification(title, {\n icon:\n Util.isString(options.icon) ||\n Util.isUndefined(options.icon) ||\n Util.isNull(options.icon)\n ? options.icon\n : options.icon.x32,\n body: options.body,\n tag: options.tag,\n requireInteraction: options.requireInteraction\n });\n }\n\n /**\n * Close a given notification\n * @param notification - notification to close\n */\n close(notification: GenericNotification) {\n notification.close();\n }\n}\n","// @flow\nimport { Util, Messages } from 'push';\nimport { AbstractAgent } from 'agents';\nimport type { Global, GenericNotification, PushOptions } from 'types';\n\n/**\n * Notification agent for modern desktop browsers:\n * Safari 6+, Firefox 22+, Chrome 22+, Opera 25+\n */\nexport default class MobileChromeAgent extends AbstractAgent {\n _win: Global;\n\n /**\n * Returns a boolean denoting support\n * @returns {Boolean} boolean denoting whether webkit notifications are supported\n */\n isSupported() {\n return (\n this._win.navigator !== undefined &&\n this._win.navigator.serviceWorker !== undefined\n );\n }\n\n /**\n * Returns the function body as a string\n * @param func\n */\n getFunctionBody(func: () => void) {\n const str = func.toString().match(/function[^{]+{([\\s\\S]*)}$/);\n return typeof str !== 'undefined' && str !== null && str.length > 1\n ? str[1]\n : null;\n }\n\n /**\n * Creates a new notification\n * @param id ID of notification\n * @param title Title of notification\n * @param options Options object\n * @param serviceWorker ServiceWorker path\n * @param callback Callback function\n */\n create(\n id: number,\n title: string,\n options: PushOptions,\n serviceWorker: string,\n callback: (GenericNotification[]) => void\n ) {\n /* Register ServiceWorker */\n this._win.navigator.serviceWorker.register(serviceWorker);\n\n this._win.navigator.serviceWorker.ready\n .then(registration => {\n /* Local data the service worker will use */\n let localData = {\n id: id,\n link: options.link,\n origin: document.location.href,\n onClick: Util.isFunction(options.onClick)\n ? this.getFunctionBody(options.onClick)\n : '',\n onClose: Util.isFunction(options.onClose)\n ? this.getFunctionBody(options.onClose)\n : ''\n };\n\n /* Merge the local data with user-provided data */\n if (options.data !== undefined && options.data !== null)\n localData = Object.assign(localData, options.data);\n\n /* Show the notification */\n registration\n .showNotification(title, {\n icon: options.icon,\n body: options.body,\n vibrate: options.vibrate,\n tag: options.tag,\n data: localData,\n requireInteraction: options.requireInteraction,\n silent: options.silent\n })\n .then(() => {\n registration.getNotifications().then(notifications => {\n /* Send an empty message so the ServiceWorker knows who the client is */\n registration.active.postMessage('');\n\n /* Trigger callback */\n callback(notifications);\n });\n })\n .catch(function(error) {\n throw new Error(\n Messages.errors.sw_notification_error +\n error.message\n );\n });\n })\n .catch(function(error) {\n throw new Error(\n Messages.errors.sw_registration_error + error.message\n );\n });\n }\n\n /**\n * Close all notification\n */\n close() {\n // Can't do this with service workers\n }\n}\n","// @flow\nimport { AbstractAgent } from 'agents';\nimport type { Global, PushOptions } from 'types';\n\n/**\n * Notification agent for modern desktop browsers:\n * Safari 6+, Firefox 22+, Chrome 22+, Opera 25+\n */\nexport default class MobileFirefoxAgent extends AbstractAgent {\n _win: Global;\n\n /**\n * Returns a boolean denoting support\n * @returns {Boolean} boolean denoting whether webkit notifications are supported\n */\n isSupported() {\n return this._win.navigator.mozNotification !== undefined;\n }\n\n /**\n * Creates a new notification\n * @param title - notification title\n * @param options - notification options array\n * @returns {Notification}\n */\n create(title: string, options: PushOptions) {\n let notification = this._win.navigator.mozNotification.createNotification(\n title,\n options.body,\n options.icon\n );\n\n notification.show();\n\n return notification;\n }\n}\n","// @flow\nimport { AbstractAgent } from 'agents';\nimport { Util } from 'push';\nimport type { PushOptions, Global } from 'types';\n\n/**\n * Notification agent for IE9\n */\nexport default class MSAgent extends AbstractAgent {\n _win: Global;\n\n /**\n * Returns a boolean denoting support\n * @returns {Boolean} boolean denoting whether webkit notifications are supported\n */\n isSupported() {\n return (\n this._win.external !== undefined &&\n this._win.external.msIsSiteMode !== undefined\n );\n }\n\n /**\n * Creates a new notification\n * @param title - notification title\n * @param options - notification options array\n * @returns {Notification}\n */\n create(title: string, options: PushOptions) {\n /* Clear any previous notifications */\n this._win.external.msSiteModeClearIconOverlay();\n\n this._win.external.msSiteModeSetIconOverlay(\n Util.isString(options.icon) || Util.isUndefined(options.icon)\n ? options.icon\n : options.icon.x16,\n title\n );\n\n this._win.external.msSiteModeActivate();\n\n return null;\n }\n\n /**\n * Close a given notification\n * @param notification - notification to close\n */\n close() {\n this._win.external.msSiteModeClearIconOverlay();\n }\n}\n","// @flow\nimport { AbstractAgent } from 'agents';\nimport type { Global, GenericNotification, PushOptions } from 'types';\n\n/**\n * Notification agent for old Chrome versions (and some) Firefox\n */\nexport default class WebKitAgent extends AbstractAgent {\n _win: Global;\n\n /**\n * Returns a boolean denoting support\n * @returns {Boolean} boolean denoting whether webkit notifications are supported\n */\n isSupported() {\n return this._win.webkitNotifications !== undefined;\n }\n\n /**\n * Creates a new notification\n * @param title - notification title\n * @param options - notification options array\n * @returns {Notification}\n */\n create(title: string, options: PushOptions) {\n let notification = this._win.webkitNotifications.createNotification(\n options.icon,\n title,\n options.body\n );\n\n notification.show();\n\n return notification;\n }\n\n /**\n * Close a given notification\n * @param notification - notification to close\n */\n close(notification: GenericNotification) {\n notification.cancel();\n }\n}\n","// @flow\nimport { Push } from 'push';\n\nexport default new Push(typeof window !== 'undefined' ? window : global);\n","// @flow\nimport { Messages, Permission, Util } from 'push';\nimport type { PluginManifest, GenericNotification, PushOptions } from 'types';\n\n/* Import notification agents */\nimport {\n DesktopAgent,\n MobileChromeAgent,\n MobileFirefoxAgent,\n MSAgent,\n WebKitAgent\n} from 'agents';\n\nexport default class Push {\n // Private members\n _agents: {\n desktop: DesktopAgent,\n chrome: MobileChromeAgent,\n firefox: MobileFirefoxAgent,\n ms: MSAgent,\n webkit: WebKitAgent\n };\n _configuration: {\n serviceWorker: string,\n fallback: ({}) => void\n };\n _currentId: number;\n _notifications: {};\n _win: {};\n\n // Public members\n Permission: Permission;\n\n constructor(win: {}) {\n /* Private variables */\n\n /* ID to use for new notifications */\n this._currentId = 0;\n\n /* Map of open notifications */\n this._notifications = {};\n\n /* Window object */\n this._win = win;\n\n /* Public variables */\n this.Permission = new Permission(win);\n\n /* Agents */\n this._agents = {\n desktop: new DesktopAgent(win),\n chrome: new MobileChromeAgent(win),\n firefox: new MobileFirefoxAgent(win),\n ms: new MSAgent(win),\n webkit: new WebKitAgent(win)\n };\n\n this._configuration = {\n serviceWorker: '/serviceWorker.min.js',\n fallback: function(payload) {}\n };\n }\n\n /**\n * Closes a notification\n * @param id ID of notification\n * @returns {boolean} denotes whether the operation was successful\n * @private\n */\n _closeNotification(id: number | string) {\n let success = true;\n const notification = this._notifications[id];\n\n if (notification !== undefined) {\n success = this._removeNotification(id);\n\n /* Safari 6+, Firefox 22+, Chrome 22+, Opera 25+ */\n if (this._agents.desktop.isSupported())\n this._agents.desktop.close(notification);\n else if (this._agents.webkit.isSupported())\n /* Legacy WebKit browsers */\n this._agents.webkit.close(notification);\n else if (this._agents.ms.isSupported())\n /* IE9 */\n this._agents.ms.close();\n else {\n success = false;\n throw new Error(Messages.errors.unknown_interface);\n }\n\n return success;\n }\n\n return false;\n }\n\n /**\n * Adds a notification to the global dictionary of notifications\n * @param {Notification} notification\n * @return {Integer} Dictionary key of the notification\n * @private\n */\n _addNotification(notification: GenericNotification) {\n const id = this._currentId;\n this._notifications[id] = notification;\n this._currentId++;\n return id;\n }\n\n /**\n * Removes a notification with the given ID\n * @param {Integer} id - Dictionary key/ID of the notification to remove\n * @return {Boolean} boolean denoting success\n * @private\n */\n _removeNotification(id: number | string) {\n let success = false;\n\n if (this._notifications.hasOwnProperty(id)) {\n /* We're successful if we omit the given ID from the new array */\n delete this._notifications[id];\n success = true;\n }\n\n return success;\n }\n\n /**\n * Creates the wrapper for a given notification\n *\n * @param {Integer} id - Dictionary key/ID of the notification\n * @param {Map} options - Options used to create the notification\n * @returns {Map} wrapper hashmap object\n * @private\n */\n _prepareNotification(id: number, options: PushOptions) {\n let wrapper;\n\n /* Wrapper used to get/close notification later on */\n wrapper = {\n get: () => {\n return this._notifications[id];\n },\n\n close: () => {\n this._closeNotification(id);\n }\n };\n\n /* Autoclose timeout */\n if (options.timeout) {\n setTimeout(() => {\n wrapper.close();\n }, options.timeout);\n }\n\n return wrapper;\n }\n\n /**\n * Find the most recent notification from a ServiceWorker and add it to the global array\n * @param notifications\n * @private\n */\n _serviceWorkerCallback(\n notifications: GenericNotification[],\n options: PushOptions,\n resolve: ({} | null) => void\n ) {\n let id = this._addNotification(notifications[notifications.length - 1]);\n\n /* Listen for close requests from the ServiceWorker */\n if (navigator && navigator.serviceWorker) {\n navigator.serviceWorker.addEventListener('message', event => {\n const data = JSON.parse(event.data);\n\n if (data.action === 'close' && Number.isInteger(data.id))\n this._removeNotification(data.id);\n });\n\n resolve(this._prepareNotification(id, options));\n }\n\n resolve(null);\n }\n\n /**\n * Callback function for the 'create' method\n * @return {void}\n * @private\n */\n _createCallback(\n title: string,\n options: PushOptions,\n resolve: ({} | null) => void\n ) {\n let notification = null;\n let onClose;\n\n /* Set empty settings if none are specified */\n options = options || {};\n\n /* onClose event handler */\n onClose = id => {\n /* A bit redundant, but covers the cases when close() isn't explicitly called */\n this._removeNotification(id);\n if (Util.isFunction(options.onClose)) {\n options.onClose.call(this, notification);\n }\n };\n\n /* Safari 6+, Firefox 22+, Chrome 22+, Opera 25+ */\n if (this._agents.desktop.isSupported()) {\n try {\n /* Create a notification using the API if possible */\n notification = this._agents.desktop.create(title, options);\n } catch (e) {\n const id = this._currentId;\n const sw = this.config().serviceWorker;\n const cb = notifications =>\n this._serviceWorkerCallback(\n notifications,\n options,\n resolve\n );\n /* Create a Chrome ServiceWorker notification if it isn't supported */\n if (this._agents.chrome.isSupported()) {\n this._agents.chrome.create(id, title, options, sw, cb);\n }\n }\n /* Legacy WebKit browsers */\n } else if (this._agents.webkit.isSupported())\n notification = this._agents.webkit.create(title, options);\n else if (this._agents.firefox.isSupported())\n /* Firefox Mobile */\n this._agents.firefox.create(title, options);\n else if (this._agents.ms.isSupported())\n /* IE9 */\n notification = this._agents.ms.create(title, options);\n else {\n /* Default fallback */\n options.title = title;\n this.config().fallback(options);\n }\n\n if (notification !== null) {\n const id = this._addNotification(notification);\n const wrapper = this._prepareNotification(id, options);\n\n /* Notification callbacks */\n if (Util.isFunction(options.onShow))\n notification.addEventListener('show', options.onShow);\n\n if (Util.isFunction(options.onError))\n notification.addEventListener('error', options.onError);\n\n if (Util.isFunction(options.onClick))\n notification.addEventListener('click', options.onClick);\n\n notification.addEventListener('close', () => {\n onClose(id);\n });\n\n notification.addEventListener('cancel', () => {\n onClose(id);\n });\n\n /* Return the wrapper so the user can call close() */\n resolve(wrapper);\n }\n\n /* By default, pass an empty wrapper */\n resolve(null);\n }\n\n /**\n * Creates and displays a new notification\n * @param {Array} options\n * @return {Promise}\n */\n create(title: string, options: {}): Promise {\n let promiseCallback;\n\n /* Fail if no or an invalid title is provided */\n if (!Util.isString(title)) {\n throw new Error(Messages.errors.invalid_title);\n }\n\n /* Request permission if it isn't granted */\n if (!this.Permission.has()) {\n promiseCallback = (resolve: () => void, reject: string => void) => {\n this.Permission\n .request()\n .then(() => {\n this._createCallback(title, options, resolve);\n })\n .catch(() => {\n reject(Messages.errors.permission_denied);\n });\n };\n } else {\n promiseCallback = (resolve: () => void, reject: string => void) => {\n try {\n this._createCallback(title, options, resolve);\n } catch (e) {\n reject(e);\n }\n };\n }\n\n return new Promise(promiseCallback);\n }\n\n /**\n * Returns the notification count\n * @return {Integer} The notification count\n */\n count() {\n let count = 0;\n let key;\n\n for (key in this._notifications)\n if (this._notifications.hasOwnProperty(key)) count++;\n\n return count;\n }\n\n /**\n * Closes a notification with the given tag\n * @param {String} tag - Tag of the notification to close\n * @return {Boolean} boolean denoting success\n */\n close(tag: string) {\n let key, notification;\n\n for (key in this._notifications) {\n if (this._notifications.hasOwnProperty(key)) {\n notification = this._notifications[key];\n\n /* Run only if the tags match */\n if (notification.tag === tag) {\n /* Call the notification's close() method */\n return this._closeNotification(key);\n }\n }\n }\n }\n\n /**\n * Clears all notifications\n * @return {Boolean} boolean denoting whether the clear was successful in closing all notifications\n */\n clear() {\n let key,\n success = true;\n\n for (key in this._notifications)\n if (this._notifications.hasOwnProperty(key))\n success = success && this._closeNotification(key);\n\n return success;\n }\n\n /**\n * Denotes whether Push is supported in the current browser\n * @returns {boolean}\n */\n supported() {\n let supported = false;\n\n for (var agent in this._agents)\n if (this._agents.hasOwnProperty(agent))\n supported = supported || this._agents[agent].isSupported();\n\n return supported;\n }\n\n /**\n * Modifies settings or returns all settings if no parameter passed\n * @param settings\n */\n config(settings?: {}) {\n if (\n typeof settings !== 'undefined' ||\n (settings !== null && Util.isObject(settings))\n )\n Util.objectMerge(this._configuration, settings);\n\n return this._configuration;\n }\n\n /**\n * Copies the functions from a plugin to the main library\n * @param plugin\n */\n extend(manifest: PluginManifest) {\n var plugin,\n Plugin,\n hasProp = {}.hasOwnProperty;\n\n if (!hasProp.call(manifest, 'plugin')) {\n throw new Error(Messages.errors.invalid_plugin);\n } else {\n if (\n hasProp.call(manifest, 'config') &&\n Util.isObject(manifest.config) &&\n manifest.config !== null\n ) {\n this.config(manifest.config);\n }\n\n Plugin = manifest.plugin;\n plugin = new Plugin(this.config());\n\n for (var member in plugin) {\n if (\n hasProp.call(plugin, member) &&\n Util.isFunction(plugin[member])\n )\n // $FlowFixMe\n this[member] = plugin[member];\n }\n }\n }\n}\n"],"names":["errors","incompatible","invalid_plugin","invalid_title","permission_denied","sw_notification_error","sw_registration_error","unknown_interface","Permission","win","_win","GRANTED","DEFAULT","DENIED","_permissions","this","onGranted","onDenied","arguments","length","_requestWithCallback","_requestAsPromise","request","existing","get","resolved","resolve","result","_this","Notification","permission","webkitNotifications","checkPermission","requestPermission","then","hasPermissions","isModernAPI","isWebkitAPI","Promise","resolvePromise","rejectPromise","resolver","_this2","isGranted","navigator","mozNotification","external","msIsSiteMode","Util","obj","undefined","obs","toString","call","_typeof","target","source","key","hasOwnProperty","isObject","objectMerge","AbstractAgent","DesktopAgent","title","options","icon","isString","isUndefined","isNull","x32","body","tag","requireInteraction","notification","close","MobileChromeAgent","serviceWorker","func","str","match","id","callback","register","ready","registration","localData","link","origin","document","location","href","onClick","isFunction","getFunctionBody","onClose","data","Object","assign","showNotification","vibrate","silent","getNotifications","notifications","active","postMessage","error","Error","Messages","message","MobileFirefoxAgent","createNotification","show","MSAgent","msSiteModeClearIconOverlay","msSiteModeSetIconOverlay","x16","msSiteModeActivate","WebKitAgent","cancel","_currentId","_notifications","_agents","desktop","chrome","firefox","ms","webkit","_configuration","fallback","payload","success","_removeNotification","isSupported","wrapper","_closeNotification","timeout","setTimeout","_addNotification","addEventListener","event","JSON","parse","action","Number","isInteger","_prepareNotification","_this3","create","e","sw","config","_serviceWorkerCallback","onShow","onError","promiseCallback","has","reject","_this4","_createCallback","count","supported","agent","settings","manifest","plugin","hasProp","member","Plugin","window","global"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2LACA,MAEe,CACXA,OAAQ,CACJC,uBAJY,uDAKZC,yBALY,6GAMZC,wBANY,wDAOZC,4BAPY,6CAQZC,gCARY,2FASZC,gCATY,oFAUZC,4BAVY,6uCCECC,wBAULC,kBACHC,KAAOD,OACPE,QAAU,eACVC,QAAU,eACVC,OAAS,cACTC,aAAe,CAACC,KAAKJ,QAASI,KAAKH,QAASG,KAAKF,kDASlDG,EAAuBC,UACpBC,UAAUC,OAAS,EACpBJ,KAAKK,gCAAwBF,WAC7BH,KAAKM,iEAUML,EAAuBC,OAapCK,SAZEC,EAAWR,KAAKS,MAElBC,GAAW,EACXC,EAAU,eAACC,yDAASC,EAAKlB,KAAKmB,aAAaC,WACvCL,IACJA,GAAW,OACW,IAAXE,GAA0BC,EAAKlB,KAAKqB,sBAC3CJ,EAASC,EAAKlB,KAAKqB,oBAAoBC,mBACvCL,IAAWC,EAAKjB,SAAsB,IAAXgB,EACvBX,GAAWA,IACRC,GAAUA,MAKrBM,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Y,YAAY7C,KAAKgH,eAAgBmC,GAEnCnJ,KAAKgH,8CAOToC,OACCC,EAEAC,EAAU,GAAG3G,mBAEZ2G,EAAQhH,KAAK8G,EAAU,gBAClB,IAAIzD,MAAMC,EAAS3G,OAAOE,oBAa3B,IAAIoK,KAVLD,EAAQhH,KAAK8G,EAAU,WACvBnH,EAAKW,SAASwG,EAASb,SACH,OAApBa,EAASb,aAEJA,OAAOa,EAASb,QAIzBc,EAAS,IADTG,EAASJ,EAASC,QACErJ,KAAKuI,UAIjBe,EAAQhH,KAAK+G,EAAQE,IACrBtH,EAAK4C,WAAWwE,EAAOE,WAGlBA,GAAUF,EAAOE,aDja3B,CAA2B,oBAAXE,OAAyBA,OAASC"} \ No newline at end of file +{"version":3,"file":"push.min.js","sources":["../src/push/Messages.js","../src/push/Permission.js","../src/push/Util.js","../src/agents/AbstractAgent.js","../src/agents/DesktopAgent.js","../src/agents/MobileChromeAgent.js","../src/agents/MobileFirefoxAgent.js","../src/agents/MSAgent.js","../src/agents/WebKitAgent.js","../src/index.js","../src/push/Push.js"],"sourcesContent":["// @flow\nconst errorPrefix = 'PushError:';\n\nexport default {\n errors: {\n incompatible: `${errorPrefix} Push.js is incompatible with browser.`,\n invalid_plugin: `${errorPrefix} plugin class missing from plugin manifest (invalid plugin). Please check the documentation.`,\n invalid_title: `${errorPrefix} title of notification must be a string`,\n permission_denied: `${errorPrefix} permission request declined`,\n sw_notification_error: `${errorPrefix} could not show a ServiceWorker notification due to the following reason: `,\n sw_registration_error: `${errorPrefix} could not register the ServiceWorker due to the following reason: `,\n unknown_interface: `${errorPrefix} unable to create notification: unknown interface`\n }\n};\n","// @flow\nimport type { Global } from 'types';\n\nexport default class Permission {\n // Private members\n _permissions: string[];\n _win: Global;\n\n // Public members\n GRANTED: string;\n DEFAULT: string;\n DENIED: string;\n\n constructor(win: Global) {\n this._win = win;\n this.GRANTED = 'granted';\n this.DEFAULT = 'default';\n this.DENIED = 'denied';\n this._permissions = [this.GRANTED, this.DEFAULT, this.DENIED];\n }\n\n /**\n * Requests permission for desktop notifications\n * @param {Function} onGranted - Function to execute once permission is granted\n * @param {Function} onDenied - Function to execute once permission is denied\n * @return {void, Promise}\n */\n request(onGranted: () => void, onDenied: () => void) {\n return arguments.length > 0\n ? this._requestWithCallback(...arguments)\n : this._requestAsPromise();\n }\n\n /**\n * Old permissions implementation deprecated in favor of a promise based one\n * @deprecated Since V1.0.4\n * @param {Function} onGranted - Function to execute once permission is granted\n * @param {Function} onDenied - Function to execute once permission is denied\n * @return {void}\n */\n _requestWithCallback(onGranted: () => void, onDenied: () => void) {\n const existing = this.get();\n\n var resolved = false;\n var resolve = (result = this._win.Notification.permission) => {\n if (resolved) return;\n resolved = true;\n if (typeof result === 'undefined' && this._win.webkitNotifications)\n result = this._win.webkitNotifications.checkPermission();\n if (result === this.GRANTED || result === 0) {\n if (onGranted) onGranted();\n } else if (onDenied) onDenied();\n };\n var request;\n\n /* Permissions already set */\n if (existing !== this.DEFAULT) {\n resolve(existing);\n } else if (\n this._win.webkitNotifications &&\n this._win.webkitNotifications.checkPermission\n ) {\n /* Safari 6+, Legacy webkit browsers */\n this._win.webkitNotifications.requestPermission(resolve);\n } else if (\n this._win.Notification &&\n this._win.Notification.requestPermission\n ) {\n /* Safari 12+ */\n /* This resolve argument will only be used in Safari */\n /* CHrome, instead, returns a Promise */\n request = this._win.Notification.requestPermission(resolve);\n if (request && request.then) {\n /* Chrome 23+ */\n request.then(resolve).catch(function() {\n if (onDenied) onDenied();\n });\n }\n } else if (onGranted) {\n /* Let the user continue by default */\n onGranted();\n }\n }\n\n /**\n * Requests permission for desktop notifications in a promise based way\n * @return {Promise}\n */\n _requestAsPromise(): Promise {\n const existing = this.get();\n\n let isGranted = result => result === this.GRANTED || result === 0;\n\n /* Permissions already set */\n var hasPermissions = existing !== this.DEFAULT;\n\n /* Safari 6+, Chrome 23+ */\n var isModernAPI =\n this._win.Notification && this._win.Notification.requestPermission;\n\n /* Legacy webkit browsers */\n var isWebkitAPI =\n this._win.webkitNotifications &&\n this._win.webkitNotifications.checkPermission;\n\n return new Promise((resolvePromise, rejectPromise) => {\n var resolved = false;\n var resolver = result => {\n if (resolved) return;\n resolved = true;\n isGranted(result) ? resolvePromise() : rejectPromise();\n };\n var request;\n\n if (hasPermissions) {\n resolver(existing);\n } else if (isWebkitAPI) {\n this._win.webkitNotifications.requestPermission(result => {\n resolver(result);\n });\n } else if (isModernAPI) {\n /* Safari 12+ */\n /* This resolver argument will only be used in Safari */\n /* CHrome, instead, returns a Promise */\n request = this._win.Notification.requestPermission(resolver);\n if (request && request.then) {\n /* Chrome 23+ */\n request.then(resolver).catch(rejectPromise);\n }\n } else resolvePromise();\n });\n }\n\n /**\n * Returns whether Push has been granted permission to run\n * @return {Boolean}\n */\n has() {\n return this.get() === this.GRANTED;\n }\n\n /**\n * Gets the permission level\n * @return {Permission} The permission level\n */\n get() {\n let permission;\n\n /* Safari 6+, Chrome 23+ */\n if (this._win.Notification && this._win.Notification.permission)\n permission = this._win.Notification.permission;\n else if (\n this._win.webkitNotifications &&\n this._win.webkitNotifications.checkPermission\n )\n /* Legacy webkit browsers */\n permission = this._permissions[\n this._win.webkitNotifications.checkPermission()\n ];\n else if (navigator.mozNotification)\n /* Firefox Mobile */\n permission = this.GRANTED;\n else if (this._win.external && this._win.external.msIsSiteMode)\n /* IE9+ */\n permission = this._win.external.msIsSiteMode()\n ? this.GRANTED\n : this.DEFAULT;\n else permission = this.GRANTED;\n\n return permission;\n }\n}\n","// @flow\nexport default class Util {\n static isUndefined(obj) {\n return obj === undefined;\n }\n\n static isNull(obs) {\n return obj === null;\n }\n\n static isString(obj) {\n return typeof obj === 'string';\n }\n\n static isFunction(obj) {\n return obj && {}.toString.call(obj) === '[object Function]';\n }\n\n static isObject(obj) {\n return typeof obj === 'object';\n }\n\n static objectMerge(target, source) {\n for (var key in source) {\n if (\n target.hasOwnProperty(key) &&\n this.isObject(target[key]) &&\n this.isObject(source[key])\n ) {\n this.objectMerge(target[key], source[key]);\n } else {\n target[key] = source[key];\n }\n }\n }\n}\n","// @flow\nimport type { Global } from 'types';\n\nexport default class AbstractAgent {\n _win: Global;\n\n constructor(win: Global) {\n this._win = win;\n }\n}\n","// @flow\nimport { AbstractAgent } from 'agents';\nimport { Util } from 'push';\nimport type { PushOptions, GenericNotification, Global } from 'types';\n\n/**\n * Notification agent for modern desktop browsers:\n * Safari 6+, Firefox 22+, Chrome 22+, Opera 25+\n */\nexport default class DesktopAgent extends AbstractAgent {\n _win: Global;\n\n /**\n * Returns a boolean denoting support\n * @returns {Boolean} boolean denoting whether webkit notifications are supported\n */\n isSupported() {\n return this._win.Notification !== undefined;\n }\n\n /**\n * Creates a new notification\n * @param title - notification title\n * @param options - notification options array\n * @returns {Notification}\n */\n create(title: string, options: PushOptions) {\n return new this._win.Notification(title, {\n icon:\n Util.isString(options.icon) ||\n Util.isUndefined(options.icon) ||\n Util.isNull(options.icon)\n ? options.icon\n : options.icon.x32,\n body: options.body,\n tag: options.tag,\n requireInteraction: options.requireInteraction\n });\n }\n\n /**\n * Close a given notification\n * @param notification - notification to close\n */\n close(notification: GenericNotification) {\n notification.close();\n }\n}\n","// @flow\nimport { Util, Messages } from 'push';\nimport { AbstractAgent } from 'agents';\nimport type { Global, GenericNotification, PushOptions } from 'types';\n\n/**\n * Notification agent for modern desktop browsers:\n * Safari 6+, Firefox 22+, Chrome 22+, Opera 25+\n */\nexport default class MobileChromeAgent extends AbstractAgent {\n _win: Global;\n\n /**\n * Returns a boolean denoting support\n * @returns {Boolean} boolean denoting whether webkit notifications are supported\n */\n isSupported() {\n return (\n this._win.navigator !== undefined &&\n this._win.navigator.serviceWorker !== undefined\n );\n }\n\n /**\n * Returns the function body as a string\n * @param func\n */\n getFunctionBody(func: () => void) {\n const str = func.toString().match(/function[^{]+{([\\s\\S]*)}$/);\n return typeof str !== 'undefined' && str !== null && str.length > 1\n ? str[1]\n : null;\n }\n\n /**\n * Creates a new notification\n * @param id ID of notification\n * @param title Title of notification\n * @param options Options object\n * @param serviceWorker ServiceWorker path\n * @param callback Callback function\n */\n create(\n id: number,\n title: string,\n options: PushOptions,\n serviceWorker: string,\n callback: (GenericNotification[]) => void\n ) {\n /* Register ServiceWorker */\n this._win.navigator.serviceWorker.register(serviceWorker);\n\n this._win.navigator.serviceWorker.ready\n .then(registration => {\n /* Local data the service worker will use */\n let localData = {\n id: id,\n link: options.link,\n origin: document.location.href,\n onClick: Util.isFunction(options.onClick)\n ? this.getFunctionBody(options.onClick)\n : '',\n onClose: Util.isFunction(options.onClose)\n ? this.getFunctionBody(options.onClose)\n : ''\n };\n\n /* Merge the local data with user-provided data */\n if (options.data !== undefined && options.data !== null)\n localData = Object.assign(localData, options.data);\n\n /* Show the notification */\n registration\n .showNotification(title, {\n icon: options.icon,\n body: options.body,\n vibrate: options.vibrate,\n tag: options.tag,\n data: localData,\n requireInteraction: options.requireInteraction,\n silent: options.silent\n })\n .then(() => {\n registration.getNotifications().then(notifications => {\n /* Send an empty message so the ServiceWorker knows who the client is */\n registration.active.postMessage('');\n\n /* Trigger callback */\n callback(notifications);\n });\n })\n .catch(function(error) {\n throw new Error(\n Messages.errors.sw_notification_error +\n error.message\n );\n });\n })\n .catch(function(error) {\n throw new Error(\n Messages.errors.sw_registration_error + error.message\n );\n });\n }\n\n /**\n * Close all notification\n */\n close() {\n // Can't do this with service workers\n }\n}\n","// @flow\nimport { AbstractAgent } from 'agents';\nimport type { Global, PushOptions } from 'types';\n\n/**\n * Notification agent for modern desktop browsers:\n * Safari 6+, Firefox 22+, Chrome 22+, Opera 25+\n */\nexport default class MobileFirefoxAgent extends AbstractAgent {\n _win: Global;\n\n /**\n * Returns a boolean denoting support\n * @returns {Boolean} boolean denoting whether webkit notifications are supported\n */\n isSupported() {\n return this._win.navigator.mozNotification !== undefined;\n }\n\n /**\n * Creates a new notification\n * @param title - notification title\n * @param options - notification options array\n * @returns {Notification}\n */\n create(title: string, options: PushOptions) {\n let notification = this._win.navigator.mozNotification.createNotification(\n title,\n options.body,\n options.icon\n );\n\n notification.show();\n\n return notification;\n }\n}\n","// @flow\nimport { AbstractAgent } from 'agents';\nimport { Util } from 'push';\nimport type { PushOptions, Global } from 'types';\n\n/**\n * Notification agent for IE9\n */\nexport default class MSAgent extends AbstractAgent {\n _win: Global;\n\n /**\n * Returns a boolean denoting support\n * @returns {Boolean} boolean denoting whether webkit notifications are supported\n */\n isSupported() {\n return (\n this._win.external !== undefined &&\n this._win.external.msIsSiteMode !== undefined\n );\n }\n\n /**\n * Creates a new notification\n * @param title - notification title\n * @param options - notification options array\n * @returns {Notification}\n */\n create(title: string, options: PushOptions) {\n /* Clear any previous notifications */\n this._win.external.msSiteModeClearIconOverlay();\n\n this._win.external.msSiteModeSetIconOverlay(\n Util.isString(options.icon) || Util.isUndefined(options.icon)\n ? options.icon\n : options.icon.x16,\n title\n );\n\n this._win.external.msSiteModeActivate();\n\n return null;\n }\n\n /**\n * Close a given notification\n * @param notification - notification to close\n */\n close() {\n this._win.external.msSiteModeClearIconOverlay();\n }\n}\n","// @flow\nimport { AbstractAgent } from 'agents';\nimport type { Global, GenericNotification, PushOptions } from 'types';\n\n/**\n * Notification agent for old Chrome versions (and some) Firefox\n */\nexport default class WebKitAgent extends AbstractAgent {\n _win: Global;\n\n /**\n * Returns a boolean denoting support\n * @returns {Boolean} boolean denoting whether webkit notifications are supported\n */\n isSupported() {\n return this._win.webkitNotifications !== undefined;\n }\n\n /**\n * Creates a new notification\n * @param title - notification title\n * @param options - notification options array\n * @returns {Notification}\n */\n create(title: string, options: PushOptions) {\n let notification = this._win.webkitNotifications.createNotification(\n options.icon,\n title,\n options.body\n );\n\n notification.show();\n\n return notification;\n }\n\n /**\n * Close a given notification\n * @param notification - notification to close\n */\n close(notification: GenericNotification) {\n notification.cancel();\n }\n}\n","// @flow\nimport { Push } from 'push';\n\nexport default new Push(typeof window !== 'undefined' ? window : global);\n","// @flow\nimport { Messages, Permission, Util } from 'push';\nimport type { PluginManifest, GenericNotification, PushOptions } from 'types';\n\n/* Import notification agents */\nimport {\n DesktopAgent,\n MobileChromeAgent,\n MobileFirefoxAgent,\n MSAgent,\n WebKitAgent\n} from 'agents';\n\nexport default class Push {\n // Private members\n _agents: {\n desktop: DesktopAgent,\n chrome: MobileChromeAgent,\n firefox: MobileFirefoxAgent,\n ms: MSAgent,\n webkit: WebKitAgent\n };\n _configuration: {\n serviceWorker: string,\n fallback: ({}) => void\n };\n _currentId: number;\n _notifications: {};\n _win: {};\n\n // Public members\n Permission: Permission;\n\n constructor(win: {}) {\n /* Private variables */\n\n /* ID to use for new notifications */\n this._currentId = 0;\n\n /* Map of open notifications */\n this._notifications = {};\n\n /* Window object */\n this._win = win;\n\n /* Public variables */\n this.Permission = new Permission(win);\n\n /* Agents */\n this._agents = {\n desktop: new DesktopAgent(win),\n chrome: new MobileChromeAgent(win),\n firefox: new MobileFirefoxAgent(win),\n ms: new MSAgent(win),\n webkit: new WebKitAgent(win)\n };\n\n this._configuration = {\n serviceWorker: '/serviceWorker.min.js',\n fallback: function(payload) {}\n };\n }\n\n /**\n * Closes a notification\n * @param id ID of notification\n * @returns {boolean} denotes whether the operation was successful\n * @private\n */\n _closeNotification(id: number | string) {\n let success = true;\n const notification = this._notifications[id];\n\n if (notification !== undefined) {\n success = this._removeNotification(id);\n\n /* Safari 6+, Firefox 22+, Chrome 22+, Opera 25+ */\n if (this._agents.desktop.isSupported())\n this._agents.desktop.close(notification);\n else if (this._agents.webkit.isSupported())\n /* Legacy WebKit browsers */\n this._agents.webkit.close(notification);\n else if (this._agents.ms.isSupported())\n /* IE9 */\n this._agents.ms.close();\n else {\n success = false;\n throw new Error(Messages.errors.unknown_interface);\n }\n\n return success;\n }\n\n return false;\n }\n\n /**\n * Adds a notification to the global dictionary of notifications\n * @param {Notification} notification\n * @return {Integer} Dictionary key of the notification\n * @private\n */\n _addNotification(notification: GenericNotification) {\n const id = this._currentId;\n this._notifications[id] = notification;\n this._currentId++;\n return id;\n }\n\n /**\n * Removes a notification with the given ID\n * @param {Integer} id - Dictionary key/ID of the notification to remove\n * @return {Boolean} boolean denoting success\n * @private\n */\n _removeNotification(id: number | string) {\n let success = false;\n\n if (this._notifications.hasOwnProperty(id)) {\n /* We're successful if we omit the given ID from the new array */\n delete this._notifications[id];\n success = true;\n }\n\n return success;\n }\n\n /**\n * Creates the wrapper for a given notification\n *\n * @param {Integer} id - Dictionary key/ID of the notification\n * @param {Map} options - Options used to create the notification\n * @returns {Map} wrapper hashmap object\n * @private\n */\n _prepareNotification(id: number, options: PushOptions) {\n let wrapper;\n\n /* Wrapper used to get/close notification later on */\n wrapper = {\n get: () => {\n return this._notifications[id];\n },\n\n close: () => {\n this._closeNotification(id);\n }\n };\n\n /* Autoclose timeout */\n if (options.timeout) {\n setTimeout(() => {\n wrapper.close();\n }, options.timeout);\n }\n\n return wrapper;\n }\n\n /**\n * Find the most recent notification from a ServiceWorker and add it to the global array\n * @param notifications\n * @private\n */\n _serviceWorkerCallback(\n notifications: GenericNotification[],\n options: PushOptions,\n resolve: ({} | null) => void\n ) {\n let id = this._addNotification(notifications[notifications.length - 1]);\n\n /* Listen for close requests from the ServiceWorker */\n if (navigator && navigator.serviceWorker) {\n navigator.serviceWorker.addEventListener('message', event => {\n const data = JSON.parse(event.data);\n\n if (data.action === 'close' && Number.isInteger(data.id))\n this._removeNotification(data.id);\n });\n\n resolve(this._prepareNotification(id, options));\n }\n\n resolve(null);\n }\n\n /**\n * Callback function for the 'create' method\n * @return {void}\n * @private\n */\n _createCallback(\n title: string,\n options: PushOptions,\n resolve: ({} | null) => void\n ) {\n let notification = null;\n let onClose;\n\n /* Set empty settings if none are specified */\n options = options || {};\n\n /* onClose event handler */\n onClose = id => {\n /* A bit redundant, but covers the cases when close() isn't explicitly called */\n this._removeNotification(id);\n if (Util.isFunction(options.onClose)) {\n options.onClose.call(this, notification);\n }\n };\n\n /* Safari 6+, Firefox 22+, Chrome 22+, Opera 25+ */\n if (this._agents.desktop.isSupported()) {\n try {\n /* Create a notification using the API if possible */\n notification = this._agents.desktop.create(title, options);\n } catch (e) {\n const id = this._currentId;\n const sw = this.config().serviceWorker;\n const cb = notifications =>\n this._serviceWorkerCallback(\n notifications,\n options,\n resolve\n );\n /* Create a Chrome ServiceWorker notification if it isn't supported */\n if (this._agents.chrome.isSupported()) {\n this._agents.chrome.create(id, title, options, sw, cb);\n }\n }\n /* Legacy WebKit browsers */\n } else if (this._agents.webkit.isSupported())\n notification = this._agents.webkit.create(title, options);\n else if (this._agents.firefox.isSupported())\n /* Firefox Mobile */\n this._agents.firefox.create(title, options);\n else if (this._agents.ms.isSupported())\n /* IE9 */\n notification = this._agents.ms.create(title, options);\n else {\n /* Default fallback */\n options.title = title;\n this.config().fallback(options);\n }\n\n if (notification !== null) {\n const id = this._addNotification(notification);\n const wrapper = this._prepareNotification(id, options);\n\n /* Notification callbacks */\n if (Util.isFunction(options.onShow))\n notification.addEventListener('show', options.onShow);\n\n if (Util.isFunction(options.onError))\n notification.addEventListener('error', options.onError);\n\n if (Util.isFunction(options.onClick))\n notification.addEventListener('click', options.onClick);\n\n notification.addEventListener('close', () => {\n onClose(id);\n });\n\n notification.addEventListener('cancel', () => {\n onClose(id);\n });\n\n /* Return the wrapper so the user can call close() */\n resolve(wrapper);\n }\n\n /* By default, pass an empty wrapper */\n resolve(null);\n }\n\n /**\n * Creates and displays a new notification\n * @param {Array} options\n * @return {Promise}\n */\n create(title: string, options: {}): Promise {\n let promiseCallback;\n\n /* Fail if no or an invalid title is provided */\n if (!Util.isString(title)) {\n throw new Error(Messages.errors.invalid_title);\n }\n\n /* Request permission if it isn't granted */\n if (!this.Permission.has()) {\n promiseCallback = (resolve: () => void, reject: string => void) => {\n this.Permission\n .request()\n .then(() => {\n this._createCallback(title, options, resolve);\n })\n .catch(() => {\n reject(Messages.errors.permission_denied);\n });\n };\n } else {\n promiseCallback = (resolve: () => void, reject: string => void) => {\n try {\n this._createCallback(title, options, resolve);\n } catch (e) {\n reject(e);\n }\n };\n }\n\n return new Promise(promiseCallback);\n }\n\n /**\n * Returns the notification count\n * @return {Integer} The notification count\n */\n count() {\n let count = 0;\n let key;\n\n for (key in this._notifications)\n if (this._notifications.hasOwnProperty(key)) count++;\n\n return count;\n }\n\n /**\n * Closes a notification with the given tag\n * @param {String} tag - Tag of the notification to close\n * @return {Boolean} boolean denoting success\n */\n close(tag: string) {\n let key, notification;\n\n for (key in this._notifications) {\n if (this._notifications.hasOwnProperty(key)) {\n notification = this._notifications[key];\n\n /* Run only if the tags match */\n if (notification.tag === tag) {\n /* Call the notification's close() method */\n return this._closeNotification(key);\n }\n }\n }\n }\n\n /**\n * Clears all notifications\n * @return {Boolean} boolean denoting whether the clear was successful in closing all notifications\n */\n clear() {\n let key,\n success = true;\n\n for (key in this._notifications)\n if (this._notifications.hasOwnProperty(key))\n success = success && this._closeNotification(key);\n\n return success;\n }\n\n /**\n * Denotes whether Push is supported in the current browser\n * @returns {boolean}\n */\n supported() {\n let supported = false;\n\n for (var agent in this._agents)\n if (this._agents.hasOwnProperty(agent))\n supported = supported || this._agents[agent].isSupported();\n\n return supported;\n }\n\n /**\n * Modifies settings or returns all settings if no parameter passed\n * @param settings\n */\n config(settings?: {}) {\n if (\n typeof settings !== 'undefined' ||\n (settings !== null && Util.isObject(settings))\n )\n Util.objectMerge(this._configuration, settings);\n\n return this._configuration;\n }\n\n /**\n * Copies the functions from a plugin to the main library\n * @param plugin\n */\n extend(manifest: PluginManifest) {\n var plugin,\n Plugin,\n hasProp = {}.hasOwnProperty;\n\n if (!hasProp.call(manifest, 'plugin')) {\n throw new Error(Messages.errors.invalid_plugin);\n } else {\n if (\n hasProp.call(manifest, 'config') &&\n Util.isObject(manifest.config) &&\n manifest.config !== null\n ) {\n this.config(manifest.config);\n }\n\n Plugin = manifest.plugin;\n plugin = new Plugin(this.config());\n\n for (var member in plugin) {\n if (\n hasProp.call(plugin, member) &&\n Util.isFunction(plugin[member])\n )\n // $FlowFixMe\n this[member] = plugin[member];\n }\n }\n }\n}\n"],"names":["errors","incompatible","invalid_plugin","invalid_title","permission_denied","sw_notification_error","sw_registration_error","unknown_interface","Permission","win","_win","GRANTED","DEFAULT","DENIED","_permissions","this","onGranted","onDenied","arguments","length","_requestWithCallback","_requestAsPromise","request","existing","get","resolved","resolve","result","_this","Notification","permission","webkitNotifications","checkPermission","requestPermission","then","hasPermissions","isModernAPI","isWebkitAPI","Promise","resolvePromise","rejectPromise","resolver","_this2","isGranted","navigator","mozNotification","external","msIsSiteMode","Util","obj","undefined","obs","toString","call","_typeof","target","source","key","hasOwnProperty","isObject","objectMerge","AbstractAgent","DesktopAgent","title","options","icon","isString","isUndefined","isNull","x32","body","tag","requireInteraction","notification","close","MobileChromeAgent","serviceWorker","func","str","match","id","callback","register","ready","registration","localData","link","origin","document","location","href","onClick","isFunction","getFunctionBody","onClose","data","Object","assign","showNotification","vibrate","silent","getNotifications","notifications","active","postMessage","error","Error","Messages","message","MobileFirefoxAgent","createNotification","show","MSAgent","msSiteModeClearIconOverlay","msSiteModeSetIconOverlay","x16","msSiteModeActivate","WebKitAgent","cancel","_currentId","_notifications","_agents","desktop","chrome","firefox","ms","webkit","_configuration","fallback","payload","success","_removeNotification","isSupported","wrapper","_closeNotification","timeout","setTimeout","_addNotification","addEventListener","event","JSON","parse","action","Number","isInteger","_prepareNotification","_this3","create","e","sw","config","_serviceWorkerCallback","onShow","onError","promiseCallback","has","reject","_this4","_createCallback","count","supported","agent","settings","manifest","plugin","hasProp","member","Plugin","window","global"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0LACA,MAEe,CACXA,OAAQ,CACJC,uBAJY,uDAKZC,yBALY,6GAMZC,wBANY,wDAOZC,4BAPY,6CAQZC,gCARY,2FASZC,gCATY,oFAUZC,4BAVY,6uCCECC,wBAULC,kBACHC,KAAOD,OACPE,QAAU,eACVC,QAAU,eACVC,OAAS,cACTC,aAAe,CAACC,KAAKJ,QAASI,KAAKH,QAASG,KAAKF,kDASlDG,EAAuBC,UACpBC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yE,GAAU,MAETzE,KAAO1C,KAAKyG,eACTzG,KAAKyG,eAAe9D,eAAeD,KACnCyE,EAAUA,GAAWnH,KAAKuH,mBAAmB7E,WAE9CyE,0CAQH8B,GAAY,MAEX,IAAIC,KAASlJ,KAAK0G,QACf1G,KAAK0G,QAAQ/D,eAAeuG,KAC5BD,EAAYA,GAAajJ,KAAK0G,QAAQwC,GAAO7B,sBAE9C4B,iCAOJE,eAEqB,IAAbA,GACO,OAAbA,GAAqBlH,EAAKW,SAASuG,KAEpClH,EAAKY,YAAY7C,KAAKgH,eAAgBmC,GAEnCnJ,KAAKgH,8CAOToC,OACCC,EAEAC,EAAU,GAAG3G,mBAEZ2G,EAAQhH,KAAK8G,EAAU,gBAClB,IAAIzD,MAAMC,EAAS3G,OAAOE,oBAa3B,IAAIoK,KAVLD,EAAQhH,KAAK8G,EAAU,WACvBnH,EAAKW,SAASwG,EAASb,SACH,OAApBa,EAASb,aAEJA,OAAOa,EAASb,QAIzBc,EAAS,IADTG,EAASJ,EAASC,QACErJ,KAAKuI,UAIjBe,EAAQhH,KAAK+G,EAAQE,IACrBtH,EAAK4C,WAAWwE,EAAOE,WAGlBA,GAAUF,EAAOE,aDja3B,CAA2B,oBAAXE,OAAyBA,OAASC"} \ No newline at end of file diff --git a/index.d.ts b/index.d.ts index f2c4499c..1fe2e610 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,11 +1,12 @@ declare module 'push.js' { + const defaultPush: Push; export default defaultPush; class Push { Permission: PushPermission; - create(title: string, params?: PushNotificationParams): Promise; + create(title: string, params?: PushNotificationParams): Promise close(tag: string): void; @@ -37,8 +38,7 @@ declare module 'push.js' { GRANTED: string; DENIED: string; - request(): Promise; - request(onGranted: () => void, onDenied?: () => void): void; + request(onGranted?: Function, onDenied?: Function): void; has(): boolean;