forked from firebase/firebase-bower
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirebase-messaging.js
2 lines (2 loc) · 47 KB
/
firebase-messaging.js
1
2
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("@firebase/app")):"function"==typeof define&&define.amd?define(["@firebase/app"],t):t((e=e||self).firebase)}(this,function(ot){"use strict";try{(function(){ot=ot&&ot.hasOwnProperty("default")?ot.default:ot;var r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function e(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var s=function(){return(s=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};function l(o,s,a,c){return new(a=a||Promise)(function(e,t){function n(e){try{i(c.next(e))}catch(e){t(e)}}function r(e){try{i(c.throw(e))}catch(e){t(e)}}function i(t){t.done?e(t.value):new a(function(e){e(t.value)}).then(n,r)}i((c=c.apply(o,s||[])).next())})}function p(n,r){var i,o,s,e,a={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return e={next:t(0),throw:t(1),return:t(2)},"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function t(t){return function(e){return function(t){if(i)throw new TypeError("Generator is already executing.");for(;a;)try{if(i=1,o&&(s=2&t[0]?o.return:t[0]?o.throw||((s=o.return)&&s.call(o),0):o.next)&&!(s=s.call(o,t[1])).done)return s;switch(o=0,s&&(t=[2&t[0],s.value]),t[0]){case 0:case 1:s=t;break;case 4:return a.label++,{value:t[1],done:!1};case 5:a.label++,o=t[1],t=[0];continue;case 7:t=a.ops.pop(),a.trys.pop();continue;default:if(!(s=0<(s=a.trys).length&&s[s.length-1])&&(6===t[0]||2===t[0])){a=0;continue}if(3===t[0]&&(!s||t[1]>s[0]&&t[1]<s[3])){a.label=t[1];break}if(6===t[0]&&a.label<s[1]){a.label=s[1],s=t;break}if(s&&a.label<s[2]){a.label=s[2],a.ops.push(t);break}s[2]&&a.ops.pop(),a.trys.pop();continue}t=r.call(n,a)}catch(e){t=[6,e],o=0}finally{i=s=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}}function n(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,i,o=n.call(e),s=[];try{for(;(void 0===t||0<t--)&&!(r=o.next()).done;)s.push(r.value)}catch(e){i={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s}function i(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(n(arguments[t]));return e}var o,d=(e(a,o=Error),a);function a(e,t){var n=o.call(this,t)||this;return n.code=e,n.name="FirebaseError",Object.setPrototypeOf(n,a.prototype),Error.captureStackTrace&&Error.captureStackTrace(n,c.prototype.create),n}var c=(t.prototype.create=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];for(var r=t[0]||{},i=this.service+"/"+e,o=this.errors[e],s=o?function(e,r){return e.replace(h,function(e,t){var n=r[t];return null!=n?n.toString():"<"+t+"?>"})}(o,r):"Error",a=this.serviceName+": "+s+" ("+i+").",c=new d(i,a),u=0,f=Object.keys(r);u<f.length;u++){var l=f[u];"_"!==l.slice(-1)&&(l in c&&console.warn('Overwriting FirebaseError base field "'+l+'" can cause unexpected behavior.'),c[l]=r[l])}return c},t);function t(e,t,n){this.service=e,this.serviceName=t,this.errors=n}var h=/\{\$([^}]+)}/g;function u(e,t){var n=new f(e,t);return n.subscribe.bind(n)}var f=(v.prototype.next=function(t){this.forEachObserver(function(e){e.next(t)})},v.prototype.error=function(t){this.forEachObserver(function(e){e.error(t)}),this.close(t)},v.prototype.complete=function(){this.forEachObserver(function(e){e.complete()}),this.close()},v.prototype.subscribe=function(e,t,n){var r,i=this;if(void 0===e&&void 0===t&&void 0===n)throw new Error("Missing Observer.");void 0===(r=function(e,t){if("object"!=typeof e||null===e)return!1;for(var n=0,r=t;n<r.length;n++){var i=r[n];if(i in e&&"function"==typeof e[i])return!0}return!1}(e,["next","error","complete"])?e:{next:e,error:t,complete:n}).next&&(r.next=b),void 0===r.error&&(r.error=b),void 0===r.complete&&(r.complete=b);var o=this.unsubscribeOne.bind(this,this.observers.length);return this.finalized&&this.task.then(function(){try{i.finalError?r.error(i.finalError):r.complete()}catch(e){}}),this.observers.push(r),o},v.prototype.unsubscribeOne=function(e){void 0!==this.observers&&void 0!==this.observers[e]&&(delete this.observers[e],this.observerCount-=1,0===this.observerCount&&void 0!==this.onNoObservers&&this.onNoObservers(this))},v.prototype.forEachObserver=function(e){if(!this.finalized)for(var t=0;t<this.observers.length;t++)this.sendOne(t,e)},v.prototype.sendOne=function(e,t){var n=this;this.task.then(function(){if(void 0!==n.observers&&void 0!==n.observers[e])try{t(n.observers[e])}catch(e){"undefined"!=typeof console&&console.error&&console.error(e)}})},v.prototype.close=function(e){var t=this;this.finalized||(this.finalized=!0,void 0!==e&&(this.finalError=e),this.task.then(function(){t.observers=void 0,t.onNoObservers=void 0}))},v);function v(e,t){var n=this;this.observers=[],this.unsubscribes=[],this.observerCount=0,this.task=Promise.resolve(),this.finalized=!1,this.onNoObservers=t,this.task.then(function(){e(n)}).catch(function(e){n.error(e)})}function b(){}var g=(y.prototype.setInstantiationMode=function(e){return this.instantiationMode=e,this},y.prototype.setMultipleInstances=function(e){return this.multipleInstances=e,this},y.prototype.setServiceProps=function(e){return this.serviceProps=e,this},y);function y(e,t,n){this.name=e,this.instanceFactory=t,this.type=n,this.multipleInstances=!1,this.serviceProps={},this.instantiationMode="LAZY"}function w(n){return new Promise(function(e,t){n.onsuccess=function(){e(n.result)},n.onerror=function(){t(n.error)}})}function m(n,r,i){var o,e=new Promise(function(e,t){w(o=n[r].apply(n,i)).then(e,t)});return e.request=o,e}function k(e,n,t){t.forEach(function(t){Object.defineProperty(e.prototype,t,{get:function(){return this[n][t]},set:function(e){this[n][t]=e}})})}function S(t,n,r,e){e.forEach(function(e){e in r.prototype&&(t.prototype[e]=function(){return m(this[n],e,arguments)})})}function T(t,n,r,e){e.forEach(function(e){e in r.prototype&&(t.prototype[e]=function(){return this[n][e].apply(this[n],arguments)})})}function _(t,n,r,e){e.forEach(function(e){e in r.prototype&&(t.prototype[e]=function(){return function(e,t,n){var r=m(e,t,n);return r.then(function(e){if(e)return new I(e,r.request)})}(this[n],e,arguments)})})}function P(e){this._index=e}function I(e,t){this._cursor=e,this._request=t}function D(e){this._store=e}function C(n){this._tx=n,this.complete=new Promise(function(e,t){n.oncomplete=function(){e()},n.onerror=function(){t(n.error)},n.onabort=function(){t(n.error)}})}function M(e,t,n){this._db=e,this.oldVersion=t,this.transaction=new C(n)}function N(e){this._db=e}k(P,"_index",["name","keyPath","multiEntry","unique"]),S(P,"_index",IDBIndex,["get","getKey","getAll","getAllKeys","count"]),_(P,"_index",IDBIndex,["openCursor","openKeyCursor"]),k(I,"_cursor",["direction","key","primaryKey","value"]),S(I,"_cursor",IDBCursor,["update","delete"]),["advance","continue","continuePrimaryKey"].forEach(function(n){n in IDBCursor.prototype&&(I.prototype[n]=function(){var t=this,e=arguments;return Promise.resolve().then(function(){return t._cursor[n].apply(t._cursor,e),w(t._request).then(function(e){if(e)return new I(e,t._request)})})})}),D.prototype.createIndex=function(){return new P(this._store.createIndex.apply(this._store,arguments))},D.prototype.index=function(){return new P(this._store.index.apply(this._store,arguments))},k(D,"_store",["name","keyPath","indexNames","autoIncrement"]),S(D,"_store",IDBObjectStore,["put","add","delete","clear","get","getAll","getKey","getAllKeys","count"]),_(D,"_store",IDBObjectStore,["openCursor","openKeyCursor"]),T(D,"_store",IDBObjectStore,["deleteIndex"]),C.prototype.objectStore=function(){return new D(this._tx.objectStore.apply(this._tx,arguments))},k(C,"_tx",["objectStoreNames","mode"]),T(C,"_tx",IDBTransaction,["abort"]),M.prototype.createObjectStore=function(){return new D(this._db.createObjectStore.apply(this._db,arguments))},k(M,"_db",["name","version","objectStoreNames"]),T(M,"_db",IDBDatabase,["deleteObjectStore","close"]),N.prototype.transaction=function(){return new C(this._db.transaction.apply(this._db,arguments))},k(N,"_db",["name","version","objectStoreNames"]),T(N,"_db",IDBDatabase,["close"]),["openCursor","openKeyCursor"].forEach(function(i){[D,P].forEach(function(e){i in e.prototype&&(e.prototype[i.replace("open","iterate")]=function(){var e=function(e){return Array.prototype.slice.call(e)}(arguments),t=e[e.length-1],n=this._store||this._index,r=n[i].apply(n,e.slice(0,-1));r.onsuccess=function(){t(r.result)}})})}),[P,D].forEach(function(e){e.prototype.getAll||(e.prototype.getAll=function(e,n){var r=this,i=[];return new Promise(function(t){r.iterateCursor(e,function(e){e?(i.push(e.value),void 0===n||i.length!=n?e.continue():t(i)):t(i)})})})});var x,E="0.3.9",j=1e4,O="w:"+E,K="FIS_v2",A="https://firebaseinstallations.googleapis.com/v1",V=36e5,q=((x={})["missing-app-config-values"]='Missing App configuration value: "{$valueName}"',x["not-registered"]="Firebase Installation is not registered.",x["installation-not-found"]="Firebase Installation not found.",x["request-failed"]='{$requestName} request failed with error "{$serverCode} {$serverStatus}: {$serverMessage}"',x["app-offline"]="Could not process request. Application offline.",x["delete-pending-registration"]="Can't delete installation while there is a pending registration request.",x),U=new c("installations","Installations",q);function W(e){return e instanceof d&&e.code.includes("request-failed")}function F(e){var t=e.projectId;return A+"/projects/"+t+"/installations"}function L(e){return{token:e.token,requestStatus:2,expiresIn:function(e){return Number(e.replace("s","000"))}(e.expiresIn),creationTime:Date.now()}}function R(r,i){return l(this,void 0,void 0,function(){var t,n;return p(this,function(e){switch(e.label){case 0:return[4,i.json()];case 1:return t=e.sent(),n=t.error,[2,U.create("request-failed",{requestName:r,serverCode:n.code,serverMessage:n.message,serverStatus:n.status})]}})})}function B(e){var t=e.apiKey;return new Headers({"Content-Type":"application/json",Accept:"application/json","x-goog-api-key":t})}function H(e,t){var n=t.refreshToken,r=B(e);return r.append("Authorization",function(e){return K+" "+e}(n)),r}function $(n){return l(this,void 0,void 0,function(){var t;return p(this,function(e){switch(e.label){case 0:return[4,n()];case 1:return 500<=(t=e.sent()).status&&t.status<600?[2,n()]:[2,t]}})})}function G(t){return new Promise(function(e){setTimeout(e,t)})}var z=/^[cdef][\w-]{21}$/,J="";function Y(){try{var e=new Uint8Array(17);(self.crypto||self.msCrypto).getRandomValues(e),e[0]=112+e[0]%16;var t=function(e){return function(e){return btoa(String.fromCharCode.apply(String,i(e))).replace(/\+/g,"-").replace(/\//g,"_")}(e).substr(0,22)}(e);return z.test(t)?t:J}catch(e){return J}}var Z,Q,X="firebase-installations-database",ee=1,te="firebase-installations-store",ne=null;function re(){return ne=ne||function(e,t,n){var r=m(indexedDB,"open",[e,t]),i=r.request;return i&&(i.onupgradeneeded=function(e){n&&n(new M(i.result,e.oldVersion,i.transaction))}),r.then(function(e){return new N(e)})}(X,ee,function(e){switch(e.oldVersion){case 0:e.createObjectStore(te)}})}function ie(i,o){return l(this,void 0,void 0,function(){var t,n,r;return p(this,function(e){switch(e.label){case 0:return t=ae(i),[4,re()];case 1:return n=e.sent(),[4,(r=n.transaction(te,"readwrite")).objectStore(te).put(o,t)];case 2:return e.sent(),[4,r.complete];case 3:return e.sent(),[2,o]}})})}function oe(i){return l(this,void 0,void 0,function(){var t,n,r;return p(this,function(e){switch(e.label){case 0:return t=ae(i),[4,re()];case 1:return n=e.sent(),[4,(r=n.transaction(te,"readwrite")).objectStore(te).delete(t)];case 2:return e.sent(),[4,r.complete];case 3:return e.sent(),[2]}})})}function se(a,c){return l(this,void 0,void 0,function(){var t,n,r,i,o,s;return p(this,function(e){switch(e.label){case 0:return t=ae(a),[4,re()];case 1:return n=e.sent(),r=n.transaction(te,"readwrite"),[4,(i=r.objectStore(te)).get(t)];case 2:return o=e.sent(),void 0!==(s=c(o))?[3,4]:[4,i.delete(t)];case 3:return e.sent(),[3,6];case 4:return[4,i.put(s,t)];case 5:e.sent(),e.label=6;case 6:return[4,r.complete];case 7:return e.sent(),[2,s]}})})}function ae(e){return e.appName+"!"+e.appId}function ce(i){return l(this,void 0,void 0,function(){var r,t,n;return p(this,function(e){switch(e.label){case 0:return[4,se(i,function(e){var t=function(e){return fe(e||{fid:Y(),registrationStatus:0})}(e),n=function(e,t){{if(0!==t.registrationStatus)return 1===t.registrationStatus?{installationEntry:t,registrationPromise:function(o){return l(this,void 0,void 0,function(){var t,n,r,i;return p(this,function(e){switch(e.label){case 0:return[4,ue(o)];case 1:t=e.sent(),e.label=2;case 2:return 1!==t.registrationStatus?[3,5]:[4,G(100)];case 3:return e.sent(),[4,ue(o)];case 4:return t=e.sent(),[3,2];case 5:return 0!==t.registrationStatus?[3,7]:[4,ce(o)];case 6:return n=e.sent(),r=n.installationEntry,(i=n.registrationPromise)?[2,i]:[2,r];case 7:return[2,t]}})})}(e)}:{installationEntry:t};if(!navigator.onLine){var n=Promise.reject(U.create("app-offline"));return{installationEntry:t,registrationPromise:n}}var r={fid:t.fid,registrationStatus:1,registrationTime:Date.now()},i=function(r,i){return l(this,void 0,void 0,function(){var t,n;return p(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,7]),[4,function(a,e){var c=e.fid;return l(this,void 0,void 0,function(){var t,n,r,i,o,s;return p(this,function(e){switch(e.label){case 0:return t=F(a),n=B(a),r={fid:c,authVersion:K,appId:a.appId,sdkVersion:O},i={method:"POST",headers:n,body:JSON.stringify(r)},[4,$(function(){return fetch(t,i)})];case 1:return(o=e.sent()).ok?[4,o.json()]:[3,3];case 2:return s=e.sent(),[2,{fid:s.fid||c,registrationStatus:2,refreshToken:s.refreshToken,authToken:L(s.authToken)}];case 3:return[4,R("Create Installation",o)];case 4:throw e.sent()}})})}(r,i)];case 1:return t=e.sent(),[2,ie(r,t)];case 2:return W(n=e.sent())&&409===n.serverCode?[4,oe(r)]:[3,4];case 3:return e.sent(),[3,6];case 4:return[4,ie(r,{fid:i.fid,registrationStatus:0})];case 5:e.sent(),e.label=6;case 6:throw n;case 7:return[2]}})})}(e,r);return{installationEntry:r,registrationPromise:i}}}(i,t);return r=n.registrationPromise,n.installationEntry})];case 1:return(t=e.sent()).fid!==J?[3,3]:(n={},[4,r]);case 2:return[2,(n.installationEntry=e.sent(),n)];case 3:return[2,{installationEntry:t,registrationPromise:r}]}})})}function ue(e){return se(e,function(e){if(!e)throw U.create("installation-not-found");return fe(e)})}function fe(e){return function(e){return 1===e.registrationStatus&&e.registrationTime+j<Date.now()}(e)?{fid:e.fid,registrationStatus:0}:e}function le(e,c){var u=e.appConfig,f=e.platformLoggerProvider;return l(this,void 0,void 0,function(){var t,n,r,i,o,s,a;return p(this,function(e){switch(e.label){case 0:return t=function(e,t){var n=t.fid;return F(e)+"/"+n+"/authTokens:generate"}(u,c),n=H(u,c),(r=f.getImmediate({optional:!0}))&&n.append("x-firebase-client",r.getPlatformInfoString()),i={installation:{sdkVersion:O}},o={method:"POST",headers:n,body:JSON.stringify(i)},[4,$(function(){return fetch(t,o)})];case 1:return(s=e.sent()).ok?[4,s.json()]:[3,3];case 2:return a=e.sent(),[2,L(a)];case 3:return[4,R("Generate Auth Token",s)];case 4:throw e.sent()}})})}function pe(i,o){return void 0===o&&(o=!1),l(this,void 0,void 0,function(){var r,t,n;return p(this,function(e){switch(e.label){case 0:return[4,se(i.appConfig,function(e){if(!he(e))throw U.create("not-registered");var t=e.authToken;if(!o&&function(e){return 2===e.requestStatus&&!function(e){var t=Date.now();return t<e.creationTime||e.creationTime+e.expiresIn<t+V}(e)}(t))return e;if(1===t.requestStatus)return r=function(r,i){return l(this,void 0,void 0,function(){var t,n;return p(this,function(e){switch(e.label){case 0:return[4,de(r.appConfig)];case 1:t=e.sent(),e.label=2;case 2:return 1!==t.authToken.requestStatus?[3,5]:[4,G(100)];case 3:return e.sent(),[4,de(r.appConfig)];case 4:return t=e.sent(),[3,2];case 5:return 0===(n=t.authToken).requestStatus?[2,pe(r,i)]:[2,n]}})})}(i,o),e;if(!navigator.onLine)throw U.create("app-offline");var n=function(e){var t={requestStatus:1,requestTime:Date.now()};return s(s({},e),{authToken:t})}(e);return r=function(i,o){return l(this,void 0,void 0,function(){var t,n,r;return p(this,function(e){switch(e.label){case 0:return e.trys.push([0,3,,8]),[4,le(i,o)];case 1:return t=e.sent(),r=s(s({},o),{authToken:t}),[4,ie(i.appConfig,r)];case 2:return e.sent(),[2,t];case 3:return!W(n=e.sent())||401!==n.serverCode&&404!==n.serverCode?[3,5]:[4,oe(i.appConfig)];case 4:return e.sent(),[3,7];case 5:return r=s(s({},o),{authToken:{requestStatus:0}}),[4,ie(i.appConfig,r)];case 6:e.sent(),e.label=7;case 7:throw n;case 8:return[2]}})})}(i,n),n})];case 1:return t=e.sent(),r?[4,r]:[3,3];case 2:return n=e.sent(),[3,4];case 3:n=t.authToken,e.label=4;case 4:return[2,n]}})})}function de(e){return se(e,function(e){if(!he(e))throw U.create("not-registered");return function(e){return 1===e.requestStatus&&e.requestTime+j<Date.now()}(e.authToken)?s(s({},e),{authToken:{requestStatus:0}}):e})}function he(e){return void 0!==e&&2===e.registrationStatus}function ve(t,n){return void 0===n&&(n=!1),l(this,void 0,void 0,function(){return p(this,function(e){switch(e.label){case 0:return[4,function(n){return l(this,void 0,void 0,function(){var t;return p(this,function(e){switch(e.label){case 0:return[4,ce(n)];case 1:return(t=e.sent().registrationPromise)?[4,t]:[3,3];case 2:e.sent(),e.label=3;case 3:return[2]}})})}(t.appConfig)];case 1:return e.sent(),[4,pe(t,n)];case 2:return[2,e.sent().token]}})})}function be(o,s){return l(this,void 0,void 0,function(){var t,n,r,i;return p(this,function(e){switch(e.label){case 0:return t=function(e,t){var n=t.fid;return F(e)+"/"+n}(o,s),n=H(o,s),r={method:"DELETE",headers:n},[4,$(function(){return fetch(t,r)})];case 1:return(i=e.sent()).ok?[3,3]:[4,R("Delete Installation",i)];case 2:throw e.sent();case 3:return[2]}})})}function ge(e){var t,n;if(!e||!e.options)throw ye("App Configuration");if(!e.name)throw ye("App Name");try{for(var r=function(e){var t="function"==typeof Symbol&&e[Symbol.iterator],n=0;return t?t.call(e):{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}}(["projectId","apiKey","appId"]),i=r.next();!i.done;i=r.next()){var o=i.value;if(!e.options[o])throw ye(o)}}catch(e){t={error:e}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(t)throw t.error}}return{appName:e.name,projectId:e.options.projectId,apiKey:e.options.apiKey,appId:e.options.appId}}function ye(e){return U.create("missing-app-config-values",{valueName:e})}(Z=ot).INTERNAL.registerComponent(new g("installations",function(e){var t=e.getProvider("app").getImmediate(),n={appConfig:ge(t),platformLoggerProvider:e.getProvider("platform-logger")};return{app:t,getId:function(){return function(i){return l(this,void 0,void 0,function(){var t,n,r;return p(this,function(e){switch(e.label){case 0:return[4,ce(i.appConfig)];case 1:return t=e.sent(),n=t.installationEntry,(r=t.registrationPromise)?r.catch(console.error):pe(i).catch(console.error),[2,n.fid]}})})}(n)},getToken:function(e){return ve(n,e)},delete:function(){return function(r){return l(this,void 0,void 0,function(){var t,n;return p(this,function(e){switch(e.label){case 0:return[4,se(t=r.appConfig,function(e){if(!e||0!==e.registrationStatus)return e})];case 1:if(!(n=e.sent()))return[3,6];if(1!==n.registrationStatus)return[3,2];throw U.create("delete-pending-registration");case 2:if(2!==n.registrationStatus)return[3,6];if(navigator.onLine)return[3,3];throw U.create("app-offline");case 3:return[4,be(t,n)];case 4:return e.sent(),[4,oe(t)];case 5:e.sent(),e.label=6;case 6:return[2]}})})}(n)}}},"PUBLIC")),Z.registerVersion("@firebase/installations",E);var we,me,ke=((Q={})["only-available-in-window"]="This method is available in a Window context.",Q["only-available-in-sw"]="This method is available in a service worker context.",Q["should-be-overriden"]="This method should be overriden by extended classes.",Q["bad-sender-id"]="Please ensure that 'messagingSenderId' is set correctly in the options passed into firebase.initializeApp().",Q["permission-default"]="The required permissions were not granted and dismissed instead.",Q["permission-blocked"]="The required permissions were not granted and blocked instead.",Q["unsupported-browser"]="This browser doesn't support the API's required to use the firebase SDK.",Q["notifications-blocked"]="Notifications have been blocked.",Q["failed-serviceworker-registration"]="We are unable to register the default service worker. {$browserErrorMessage}",Q["sw-registration-expected"]="A service worker registration was the expected input.",Q["get-subscription-failed"]="There was an error when trying to get any existing Push Subscriptions.",Q["invalid-saved-token"]="Unable to access details of the saved token.",Q["sw-reg-redundant"]="The service worker being used for push was made redundant.",Q["token-subscribe-failed"]="A problem occured while subscribing the user to FCM: {$errorInfo}",Q["token-subscribe-no-token"]="FCM returned no token when subscribing the user to push.",Q["token-unsubscribe-failed"]="A problem occured while unsubscribing the user from FCM: {$errorInfo}",Q["token-update-failed"]="A problem occured while updating the user from FCM: {$errorInfo}",Q["token-update-no-token"]="FCM returned no token when updating the user to push.",Q["use-sw-before-get-token"]="The useServiceWorker() method may only be called once and must be called before calling getToken() to ensure your service worker is used.",Q["invalid-delete-token"]="You must pass a valid token into deleteToken(), i.e. the token from getToken().",Q["delete-token-not-found"]="The deletion attempt for token could not be performed as the token was not found.",Q["delete-scope-not-found"]="The deletion attempt for service worker scope could not be performed as the scope was not found.",Q["bg-handler-function-expected"]="The input to setBackgroundMessageHandler() must be a function.",Q["no-window-client-to-msg"]="An attempt was made to message a non-existant window client.",Q["unable-to-resubscribe"]="There was an error while re-subscribing the FCM token for push messaging. Will have to resubscribe the user on next visit. {$errorInfo}",Q["no-fcm-token-for-resubscribe"]="Could not find an FCM token and as a result, unable to resubscribe. Will have to resubscribe the user on next visit.",Q["failed-to-delete-token"]="Unable to delete the currently saved token.",Q["no-sw-in-reg"]="Even though the service worker registration was successful, there was a problem accessing the service worker itself.",Q["bad-scope"]="The service worker scope must be a string with at least one character.",Q["bad-vapid-key"]="The public VAPID key is not a Uint8Array with 65 bytes.",Q["bad-subscription"]="The subscription must be a valid PushSubscription.",Q["bad-token"]="The FCM Token used for storage / lookup was not a valid token string.",Q["failed-delete-vapid-key"]="The VAPID key could not be deleted.",Q["invalid-public-vapid-key"]="The public VAPID key must be a string.",Q["use-public-key-before-get-token"]="The usePublicVapidKey() method may only be called once and must be called before calling getToken() to ensure your VAPID key is used.",Q["public-vapid-key-decryption-failed"]="The public VAPID key did not equal 65 bytes when decrypted.",Q),Se=new c("messaging","Messaging",ke),Te=new Uint8Array([4,51,148,247,223,161,235,177,220,3,162,94,21,113,219,72,211,46,237,237,178,52,219,183,71,58,12,143,196,204,225,111,60,140,132,223,171,182,102,62,242,12,212,139,254,227,249,118,47,20,28,99,8,106,111,45,177,26,149,176,206,55,192,156,110]),_e="google.c.a.c_id";function Pe(e,t){if(null==e||null==t)return!1;if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(var n=new DataView(e),r=new DataView(t),i=0;i<e.byteLength;i++)if(n.getUint8(i)!==r.getUint8(i))return!1;return!0}function Ie(e){return function(e){var t=new Uint8Array(e);return btoa(String.fromCharCode.apply(String,i(t)))}(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}(me=we=we||{}).PUSH_MSG_RECEIVED="push-msg-received",me.NOTIFICATION_CLICKED="notification-clicked";var De=(Ce.prototype.getToken=function(a,c,u){return l(this,void 0,void 0,function(){var t,n,r,i,o,s;return p(this,function(e){switch(e.label){case 0:return[4,Ne(a)];case 1:t=e.sent(),n=xe(c,u),r={method:"POST",headers:t,body:JSON.stringify(n)},e.label=2;case 2:return e.trys.push([2,5,,6]),[4,fetch(Me(a.app),r)];case 3:return[4,e.sent().json()];case 4:return i=e.sent(),[3,6];case 5:throw o=e.sent(),Se.create("token-subscribe-failed",{errorInfo:o});case 6:if(i.error)throw s=i.error.message,Se.create("token-subscribe-failed",{errorInfo:s});if(!i.token)throw Se.create("token-subscribe-no-token");return[2,i.token]}})})},Ce.prototype.updateToken=function(a,c,u,f){return l(this,void 0,void 0,function(){var t,n,r,i,o,s;return p(this,function(e){switch(e.label){case 0:return[4,Ne(c)];case 1:t=e.sent(),n=xe(u,f),r={method:"PATCH",headers:t,body:JSON.stringify(n)},e.label=2;case 2:return e.trys.push([2,5,,6]),[4,fetch(Me(c.app)+"/"+a.fcmToken,r)];case 3:return[4,e.sent().json()];case 4:return i=e.sent(),[3,6];case 5:throw o=e.sent(),Se.create("token-update-failed",{errorInfo:o});case 6:if(i.error)throw s=i.error.message,Se.create("token-update-failed",{errorInfo:s});if(!i.token)throw Se.create("token-update-no-token");return[2,i.token]}})})},Ce.prototype.deleteToken=function(s,a){return l(this,void 0,void 0,function(){var t,n,r,i,o;return p(this,function(e){switch(e.label){case 0:return[4,Ne(s)];case 1:t=e.sent(),n={method:"DELETE",headers:t},e.label=2;case 2:return e.trys.push([2,5,,6]),[4,fetch(Me(s.app)+"/"+a.fcmToken,n)];case 3:return[4,e.sent().json()];case 4:if((r=e.sent()).error)throw i=r.error.message,Se.create("token-unsubscribe-failed",{errorInfo:i});return[3,6];case 5:throw o=e.sent(),Se.create("token-unsubscribe-failed",{errorInfo:o});case 6:return[2]}})})},Ce);function Ce(){}function Me(e){return"https://fcmregistrations.googleapis.com/v1/projects/"+e.options.projectId+"/registrations"}function Ne(e){var n=e.app,r=e.installations;return l(this,void 0,void 0,function(){var t;return p(this,function(e){switch(e.label){case 0:return[4,r.getToken()];case 1:return t=e.sent(),[2,new Headers({"Content-Type":"application/json",Accept:"application/json","x-goog-api-key":n.options.apiKey,"x-goog-firebase-installations-auth":"FIS "+t})]}})})}function xe(e,t){var n=Ie(e.getKey("p256dh")),r=Ie(e.getKey("auth")),i={web:{endpoint:e.endpoint,p256dh:n,auth:r}};return Pe(t.buffer,Te.buffer)||(i.web.applicationPubKey=Ie(t)),i}function Ee(e){for(var t=(e+"=".repeat((4-e.length%4)%4)).replace(/\-/g,"+").replace(/_/g,"/"),n=atob(t),r=new Uint8Array(n.length),i=0;i<n.length;++i)r[i]=n.charCodeAt(i);return r}var je="undefined",Oe="fcm_token_object_Store";function Ke(t){var n=indexedDB.open(je);n.onerror=function(e){},n.onsuccess=function(e){!function(n,r){if(n.objectStoreNames.contains(Oe)){var e=n.transaction(Oe).objectStore(Oe),i=new De,o=e.openCursor();o.onerror=function(e){console.warn("Unable to cleanup old IDB.",e)},o.onsuccess=function(){var e=o.result;if(e){var t=e.value;i.deleteToken(r,t),e.continue()}else n.close(),indexedDB.deleteDatabase(je)}}}(n.result,t)}}var Ae=(Ve.prototype.get=function(t){return this.createTransaction(function(e){return e.get(t)})},Ve.prototype.getIndex=function(t,n){return this.createTransaction(function(e){return e.index(t).get(n)})},Ve.prototype.put=function(t){return this.createTransaction(function(e){return e.put(t)},"readwrite")},Ve.prototype.delete=function(t){return this.createTransaction(function(e){return e.delete(t)},"readwrite")},Ve.prototype.closeDatabase=function(){return l(this,void 0,void 0,function(){return p(this,function(e){switch(e.label){case 0:return this.dbPromise?[4,this.dbPromise]:[3,2];case 1:e.sent().close(),this.dbPromise=null,e.label=2;case 2:return[2]}})})},Ve.prototype.createTransaction=function(o,s){return void 0===s&&(s="readonly"),l(this,void 0,void 0,function(){var t,n,r,i;return p(this,function(e){switch(e.label){case 0:return[4,this.getDb()];case 1:return t=e.sent(),n=t.transaction(this.objectStoreName,s),r=n.objectStore(this.objectStoreName),[4,function(n){return new Promise(function(e,t){n.onsuccess=function(){e(n.result)},n.onerror=function(){t(n.error)}})}(o(r))];case 2:return i=e.sent(),[2,new Promise(function(e,t){n.oncomplete=function(){e(i)},n.onerror=function(){t(n.error)}})]}})})},Ve.prototype.getDb=function(){var r=this;return this.dbPromise||(this.dbPromise=new Promise(function(e,t){var n=indexedDB.open(r.dbName,r.dbVersion);n.onsuccess=function(){e(n.result)},n.onerror=function(){r.dbPromise=null,t(n.error)},n.onupgradeneeded=function(e){return r.onDbUpgrade(n,e)}})),this.dbPromise},Ve);function Ve(){this.dbPromise=null}var qe,Ue=(e(We,qe=Ae),We.prototype.onDbUpgrade=function(e,t){var n=e.result;switch(t.oldVersion){case 0:(i=n.createObjectStore(this.objectStoreName,{keyPath:"swScope"})).createIndex("fcmSenderId","fcmSenderId",{unique:!1}),i.createIndex("fcmToken","fcmToken",{unique:!0});case 1:Ke(this.services);case 2:var r=(i=e.transaction.objectStore(this.objectStoreName)).openCursor();r.onsuccess=function(){var e=r.result;if(e){var t=e.value,n=s({},t);t.createTime||(n.createTime=Date.now()),"string"==typeof t.vapidKey&&(n.vapidKey=Ee(t.vapidKey)),"string"==typeof t.auth&&(n.auth=Ee(t.auth).buffer),"string"==typeof t.auth&&(n.p256dh=Ee(t.p256dh).buffer),"string"==typeof t.fcmPushSet&&delete n.fcmPushSet,e.update(n),e.continue()}};break;case 3:var i,o=(i=e.transaction.objectStore(this.objectStoreName)).openCursor();o.onsuccess=function(){var e=o.result;if(e){var t=e.value,n=s({},t);"string"==typeof t.fcmPushSet&&delete n.fcmPushSet,e.update(n),e.continue()}}}},We.prototype.getTokenDetailsFromToken=function(t){return l(this,void 0,void 0,function(){return p(this,function(e){if(!t)throw Se.create("bad-token");return Fe({fcmToken:t}),[2,this.getIndex("fcmToken",t)]})})},We.prototype.getTokenDetailsFromSWScope=function(t){return l(this,void 0,void 0,function(){return p(this,function(e){if(!t)throw Se.create("bad-scope");return Fe({swScope:t}),[2,this.get(t)]})})},We.prototype.saveTokenDetails=function(t){return l(this,void 0,void 0,function(){return p(this,function(e){if(!t.swScope)throw Se.create("bad-scope");if(!t.vapidKey)throw Se.create("bad-vapid-key");if(!t.endpoint||!t.auth||!t.p256dh)throw Se.create("bad-subscription");if(!t.fcmSenderId)throw Se.create("bad-sender-id");if(!t.fcmToken)throw Se.create("bad-token");return Fe(t),[2,this.put(t)]})})},We.prototype.deleteToken=function(n){return l(this,void 0,void 0,function(){var t;return p(this,function(e){switch(e.label){case 0:return"string"!=typeof n||0===n.length?[2,Promise.reject(Se.create("invalid-delete-token"))]:[4,this.getTokenDetailsFromToken(n)];case 1:if(!(t=e.sent()))throw Se.create("delete-token-not-found");return[4,this.delete(t.swScope)];case 2:return e.sent(),[2,t]}})})},We);function We(e){var t=qe.call(this)||this;return t.services=e,t.dbName="fcm_token_details_db",t.dbVersion=4,t.objectStoreName="fcm_token_object_Store",t}function Fe(e){if(e.fcmToken&&("string"!=typeof e.fcmToken||0===e.fcmToken.length))throw Se.create("bad-token");if(e.swScope&&("string"!=typeof e.swScope||0===e.swScope.length))throw Se.create("bad-scope");if(e.vapidKey&&(!(e.vapidKey instanceof Uint8Array)||65!==e.vapidKey.length))throw Se.create("bad-vapid-key");if(e.endpoint&&("string"!=typeof e.endpoint||0===e.endpoint.length))throw Se.create("bad-subscription");if(e.auth&&!(e.auth instanceof ArrayBuffer))throw Se.create("bad-subscription");if(e.p256dh&&!(e.p256dh instanceof ArrayBuffer))throw Se.create("bad-subscription");if(e.fcmSenderId&&("string"!=typeof e.fcmSenderId||0===e.fcmSenderId.length))throw Se.create("bad-sender-id")}var Le,Re=(e(Be,Le=Ae),Be.prototype.onDbUpgrade=function(e){e.result.createObjectStore(this.objectStoreName,{keyPath:"swScope"})},Be.prototype.getVapidFromSWScope=function(n){return l(this,void 0,void 0,function(){var t;return p(this,function(e){switch(e.label){case 0:if("string"!=typeof n||0===n.length)throw Se.create("bad-scope");return[4,this.get(n)];case 1:return[2,(t=e.sent())?t.vapidKey:void 0]}})})},Be.prototype.saveVapidDetails=function(n,r){return l(this,void 0,void 0,function(){var t;return p(this,function(e){if("string"!=typeof n||0===n.length)throw Se.create("bad-scope");if(null===r||65!==r.length)throw Se.create("bad-vapid-key");return t={swScope:n,vapidKey:r},[2,this.put(t)]})})},Be.prototype.deleteVapidDetails=function(n){return l(this,void 0,void 0,function(){var t;return p(this,function(e){switch(e.label){case 0:return[4,this.getVapidFromSWScope(n)];case 1:if(!(t=e.sent()))throw Se.create("delete-scope-not-found");return[4,this.delete(n)];case 2:return e.sent(),[2,t]}})})},Be);function Be(){var e=null!==Le&&Le.apply(this,arguments)||this;return e.dbName="fcm_vapid_details_db",e.dbVersion=1,e.objectStoreName="fcm_vapid_object_Store",e}var He=($e.prototype.getToken=function(){return l(this,void 0,void 0,function(){var t,n,r,i,o;return p(this,function(e){switch(e.label){case 0:return"default"!==(t=this.getNotificationPermission())?[3,2]:[4,this.requestNotificationPermission()];case 1:t=e.sent(),e.label=2;case 2:if("granted"!==t)throw Se.create("notifications-blocked");return[4,this.getSWRegistration_()];case 3:return n=e.sent(),[4,this.getPublicVapidKey_()];case 4:return r=e.sent(),[4,this.getPushSubscription(n,r)];case 5:return i=e.sent(),[4,this.tokenDetailsModel.getTokenDetailsFromSWScope(n.scope)];case 6:return(o=e.sent())?[2,this.manageExistingToken(n,i,r,o)]:[2,this.getNewToken(n,i,r)]}})})},$e.prototype.manageExistingToken=function(t,n,r,i){return l(this,void 0,void 0,function(){return p(this,function(e){switch(e.label){case 0:return function(e,t,n){if(!n.vapidKey||!Pe(t.buffer,n.vapidKey.buffer))return!1;var r=e.endpoint===n.endpoint,i=Pe(e.getKey("auth"),n.auth),o=Pe(e.getKey("p256dh"),n.p256dh);return r&&i&&o}(n,r,i)?Date.now()<i.createTime+6048e5?[2,i.fcmToken]:[2,this.updateToken(t,n,r,i)]:[3,1];case 1:return[4,this.deleteTokenFromDB(i.fcmToken)];case 2:return e.sent(),[2,this.getNewToken(t,n,r)];case 3:return[2]}})})},$e.prototype.updateToken=function(i,o,s,a){return l(this,void 0,void 0,function(){var t,n,r;return p(this,function(e){switch(e.label){case 0:return e.trys.push([0,4,,6]),[4,this.subscriptionManager.updateToken(a,this.services,o,s)];case 1:return t=e.sent(),n={swScope:i.scope,vapidKey:s,fcmSenderId:this.services.app.options.messagingSenderId,fcmToken:t,createTime:Date.now(),endpoint:o.endpoint,auth:o.getKey("auth"),p256dh:o.getKey("p256dh")},[4,this.tokenDetailsModel.saveTokenDetails(n)];case 2:return e.sent(),[4,this.vapidDetailsModel.saveVapidDetails(i.scope,s)];case 3:return e.sent(),[2,t];case 4:return r=e.sent(),[4,this.deleteToken(a.fcmToken)];case 5:throw e.sent(),r;case 6:return[2]}})})},$e.prototype.getNewToken=function(r,i,o){return l(this,void 0,void 0,function(){var t,n;return p(this,function(e){switch(e.label){case 0:return[4,this.subscriptionManager.getToken(this.services,i,o)];case 1:return t=e.sent(),n={swScope:r.scope,vapidKey:o,fcmSenderId:this.app.options.messagingSenderId,fcmToken:t,createTime:Date.now(),endpoint:i.endpoint,auth:i.getKey("auth"),p256dh:i.getKey("p256dh")},[4,this.tokenDetailsModel.saveTokenDetails(n)];case 2:return e.sent(),[4,this.vapidDetailsModel.saveVapidDetails(r.scope,o)];case 3:return e.sent(),[2,t]}})})},$e.prototype.deleteToken=function(r){return l(this,void 0,void 0,function(){var t,n;return p(this,function(e){switch(e.label){case 0:return[4,this.deleteTokenFromDB(r)];case 1:return e.sent(),[4,this.getSWRegistration_()];case 2:return(t=e.sent())?[4,t.pushManager.getSubscription()]:[3,4];case 3:if(n=e.sent())return[2,n.unsubscribe()];e.label=4;case 4:return[2,!0]}})})},$e.prototype.deleteTokenFromDB=function(r){return l(this,void 0,void 0,function(){var t,n;return p(this,function(e){switch(e.label){case 0:return[4,this.tokenDetailsModel.deleteToken(r)];case 1:t=e.sent(),e.label=2;case 2:return e.trys.push([2,4,,5]),[4,this.subscriptionManager.deleteToken(this.services,t)];case 3:return e.sent(),[3,5];case 4:return n=e.sent(),console.error(n),[3,5];case 5:return[2]}})})},$e.prototype.getPushSubscription=function(n,r){return l(this,void 0,void 0,function(){var t;return p(this,function(e){switch(e.label){case 0:return[4,n.pushManager.getSubscription()];case 1:return(t=e.sent())?[2,t]:[2,n.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:r})]}})})},$e.prototype.requestPermission=function(){throw Se.create("only-available-in-window")},$e.prototype.useServiceWorker=function(e){throw Se.create("only-available-in-window")},$e.prototype.usePublicVapidKey=function(e){throw Se.create("only-available-in-window")},$e.prototype.onMessage=function(e,t,n){throw Se.create("only-available-in-window")},$e.prototype.onTokenRefresh=function(e,t,n){throw Se.create("only-available-in-window")},$e.prototype.setBackgroundMessageHandler=function(e){throw Se.create("only-available-in-sw")},$e.prototype.delete=function(){return l(this,void 0,void 0,function(){return p(this,function(e){switch(e.label){case 0:return[4,Promise.all([this.tokenDetailsModel.closeDatabase(),this.vapidDetailsModel.closeDatabase()])];case 1:return e.sent(),[2]}})})},$e.prototype.getNotificationPermission=function(){return Notification.permission},$e.prototype.requestNotificationPermission=function(){return l(this,void 0,void 0,function(){return p(this,function(e){return Notification.requestPermission?[2,Notification.requestPermission()]:[2,Notification.permission]})})},$e.prototype.getTokenDetailsModel=function(){return this.tokenDetailsModel},$e.prototype.getVapidDetailsModel=function(){return this.vapidDetailsModel},$e.prototype.getSubscriptionManager=function(){return this.subscriptionManager},$e);function $e(e){var t=this;this.services=e,this.vapidDetailsModel=new Re,this.subscriptionManager=new De;var n=e.app;if(!(this.app=n).options.messagingSenderId||"string"!=typeof n.options.messagingSenderId)throw Se.create("bad-sender-id");this.INTERNAL={delete:function(){return t.delete()}},this.tokenDetailsModel=new Ue(e)}var Ge,ze="FCM_MSG",Je=(e(Ye,Ge=He),Ye.prototype.onPush=function(e){e.waitUntil(this.onPush_(e))},Ye.prototype.onSubChange=function(e){e.waitUntil(this.onSubChange_(e))},Ye.prototype.onNotificationClick=function(e){e.waitUntil(this.onNotificationClick_(e))},Ye.prototype.onPush_=function(a){return l(this,void 0,void 0,function(){var t,n,r,i,o,s;return p(this,function(e){switch(e.label){case 0:if(!a.data)return[2];try{t=a.data.json()}catch(e){return[2]}return[4,this.hasVisibleClients_()];case 1:return e.sent()?[2,this.sendMessageToWindowClients_(t)]:(n=this.getNotificationData_(t))?(r=n.title||"",[4,this.getSWRegistration_()]):[3,3];case 2:return i=e.sent(),o=n.actions,s=Notification.maxActions,o&&s&&o.length>s&&console.warn("This browser only supports "+s+" actions.The remaining actions will not be displayed."),[2,i.showNotification(r,n)];case 3:return this.bgMessageHandler?[4,this.bgMessageHandler(t)]:[3,5];case 4:return e.sent(),[2];case 5:return[2]}})})},Ye.prototype.onSubChange_=function(e){return l(this,void 0,void 0,function(){var t,n,r,i;return p(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this.getSWRegistration_()];case 1:return t=e.sent(),[3,3];case 2:throw n=e.sent(),Se.create("unable-to-resubscribe",{errorInfo:n});case 3:return e.trys.push([3,5,,8]),[4,t.pushManager.getSubscription()];case 4:return e.sent(),[3,8];case 5:return r=e.sent(),[4,this.getTokenDetailsModel().getTokenDetailsFromSWScope(t.scope)];case 6:if(!(i=e.sent()))throw r;return[4,this.deleteToken(i.fcmToken)];case 7:throw e.sent(),r;case 8:return[2]}})})},Ye.prototype.onNotificationClick_=function(o){return l(this,void 0,void 0,function(){var t,n,r,i;return p(this,function(e){switch(e.label){case 0:if(!(o.notification&&o.notification.data&&o.notification.data[ze]))return[2];if(o.action)return[2];if(o.stopImmediatePropagation(),o.notification.close(),!(t=o.notification.data[ze]).notification)return[2];if(!(n=t.fcmOptions&&t.fcmOptions.link||t.notification.click_action)){if(!(t.data&&_e in t.data))return[2];n=self.location.origin}return[4,this.getWindowClient_(n)];case 1:return(r=e.sent())?[3,4]:[4,self.clients.openWindow(n)];case 2:return r=e.sent(),[4,function(t){return new Promise(function(e){setTimeout(e,t)})}(3e3)];case 3:return e.sent(),[3,6];case 4:return[4,r.focus()];case 5:r=e.sent(),e.label=6;case 6:return r?(delete t.notification,delete t.fcmOptions,i=Qe(we.NOTIFICATION_CLICKED,t),[2,this.attemptToMessageClient_(r,i)]):[2]}})})},Ye.prototype.getNotificationData_=function(e){var t;if(e&&"object"==typeof e.notification){var n=s({},e.notification);return n.data=s(s({},e.notification.data),((t={})[ze]=e,t)),n}},Ye.prototype.setBackgroundMessageHandler=function(e){if(!e||"function"!=typeof e)throw Se.create("bg-handler-function-expected");this.bgMessageHandler=e},Ye.prototype.getWindowClient_=function(o){return l(this,void 0,void 0,function(){var t,n,r,i;return p(this,function(e){switch(e.label){case 0:return t=new URL(o,self.location.href).href,[4,Ze()];case 1:for(n=e.sent(),r=null,i=0;i<n.length;i++)if(new URL(n[i].url,self.location.href).href===t){r=n[i];break}return[2,r]}})})},Ye.prototype.attemptToMessageClient_=function(t,n){return l(this,void 0,void 0,function(){return p(this,function(e){if(!t)throw Se.create("no-window-client-to-msg");return t.postMessage(n),[2]})})},Ye.prototype.hasVisibleClients_=function(){return l(this,void 0,void 0,function(){return p(this,function(e){switch(e.label){case 0:return[4,Ze()];case 1:return[2,e.sent().some(function(e){return"visible"===e.visibilityState&&!e.url.startsWith("chrome-extension://")})]}})})},Ye.prototype.sendMessageToWindowClients_=function(i){return l(this,void 0,void 0,function(){var t,n,r=this;return p(this,function(e){switch(e.label){case 0:return[4,Ze()];case 1:return t=e.sent(),n=Qe(we.PUSH_MSG_RECEIVED,i),[4,Promise.all(t.map(function(e){return r.attemptToMessageClient_(e,n)}))];case 2:return e.sent(),[2]}})})},Ye.prototype.getSWRegistration_=function(){return l(this,void 0,void 0,function(){return p(this,function(e){return[2,self.registration]})})},Ye.prototype.getPublicVapidKey_=function(){return l(this,void 0,void 0,function(){var t,n;return p(this,function(e){switch(e.label){case 0:return[4,this.getSWRegistration_()];case 1:if(!(t=e.sent()))throw Se.create("sw-registration-expected");return[4,this.getVapidDetailsModel().getVapidFromSWScope(t.scope)];case 2:return null==(n=e.sent())?[2,Te]:[2,n]}})})},Ye);function Ye(e){var t=Ge.call(this,e)||this;return t.bgMessageHandler=null,self.addEventListener("push",function(e){t.onPush(e)}),self.addEventListener("pushsubscriptionchange",function(e){t.onSubChange(e)}),self.addEventListener("notificationclick",function(e){t.onNotificationClick(e)}),t}function Ze(){return self.clients.matchAll({type:"window",includeUncontrolled:!0})}function Qe(e,t){return{firebaseMessagingType:e,firebaseMessagingData:t}}var Xe,et=(e(tt,Xe=He),tt.prototype.requestPermission=function(){return l(this,void 0,void 0,function(){var t;return p(this,function(e){switch(e.label){case 0:return"granted"===Notification.permission?[2]:[4,Notification.requestPermission()];case 1:if("granted"===(t=e.sent()))return[2];throw"denied"===t?Se.create("permission-blocked"):Se.create("permission-default")}})})},tt.prototype.useServiceWorker=function(e){if(!(e instanceof ServiceWorkerRegistration))throw Se.create("sw-registration-expected");if(null!=this.registrationToUse)throw Se.create("use-sw-before-get-token");this.registrationToUse=e},tt.prototype.usePublicVapidKey=function(e){if("string"!=typeof e)throw Se.create("invalid-public-vapid-key");if(null!=this.publicVapidKeyToUse)throw Se.create("use-public-key-before-get-token");var t=Ee(e);if(65!==t.length)throw Se.create("public-vapid-key-decryption-failed");this.publicVapidKeyToUse=t},tt.prototype.onMessage=function(e,t,n){return"function"==typeof e?this.onMessageInternal(e,t,n):this.onMessageInternal(e)},tt.prototype.onTokenRefresh=function(e,t,n){return"function"==typeof e?this.onTokenRefreshInternal(e,t,n):this.onTokenRefreshInternal(e)},tt.prototype.waitForRegistrationToActivate_=function(r){var i=r.installing||r.waiting||r.active;return new Promise(function(e,t){if(i)if("activated"!==i.state)if("redundant"!==i.state){var n=function(){if("activated"===i.state)e(r);else{if("redundant"!==i.state)return;t(Se.create("sw-reg-redundant"))}i.removeEventListener("statechange",n)};i.addEventListener("statechange",n)}else t(Se.create("sw-reg-redundant"));else e(r);else t(Se.create("no-sw-in-reg"))})},tt.prototype.getSWRegistration_=function(){var t=this;return this.registrationToUse?this.waitForRegistrationToActivate_(this.registrationToUse):(this.registrationToUse=null,navigator.serviceWorker.register("/firebase-messaging-sw.js",{scope:"/firebase-cloud-messaging-push-scope"}).catch(function(e){throw Se.create("failed-serviceworker-registration",{browserErrorMessage:e.message})}).then(function(e){return t.waitForRegistrationToActivate_(e).then(function(){return(t.registrationToUse=e).update(),e})}))},tt.prototype.getPublicVapidKey_=function(){return l(this,void 0,void 0,function(){return p(this,function(e){return this.publicVapidKeyToUse?[2,this.publicVapidKeyToUse]:[2,Te]})})},tt.prototype.setupSWMessageListener_=function(){var e=this;navigator.serviceWorker.addEventListener("message",function(s){return l(e,void 0,void 0,function(){var t,n,r,i,o;return p(this,function(e){switch(e.label){case 0:return s.data&&s.data.firebaseMessagingType&&s.data.firebaseMessagingData?(t=s.data,n=t.firebaseMessagingType,r=t.firebaseMessagingData,this.messageObserver&&this.messageObserver.next(r),(i=r.data)&&_e in i&&"1"===i["google.c.a.e"]?(o=function(e){switch(e){case we.NOTIFICATION_CLICKED:return"notification_open";case we.PUSH_MSG_RECEIVED:return"notification_foreground";default:throw new Error}}(n),[4,this.services.analyticsProvider.get()]):[3,2]):[2];case 1:e.sent().logEvent(o,{message_name:i["google.c.a.c_l"],message_id:i[_e],message_time:i["google.c.a.ts"],message_device_time:Math.floor(Date.now()/1e3)}),e.label=2;case 2:return[2]}})})},!1)},tt);function tt(e){var t=Xe.call(this,e)||this;return t.registrationToUse=null,t.publicVapidKeyToUse=null,t.messageObserver=null,t.tokenRefreshObserver=null,t.onMessageInternal=u(function(e){t.messageObserver=e}),t.onTokenRefreshInternal=u(function(e){t.tokenRefreshObserver=e}),t.setupSWMessageListener_(),t}var nt,rt;function it(){return self&&"ServiceWorkerGlobalScope"in self?"PushManager"in self&&"Notification"in self&&ServiceWorkerRegistration.prototype.hasOwnProperty("showNotification")&&PushSubscription.prototype.hasOwnProperty("getKey"):navigator.cookieEnabled&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window&&"fetch"in window&&ServiceWorkerRegistration.prototype.hasOwnProperty("showNotification")&&PushSubscription.prototype.hasOwnProperty("getKey")}rt={isSupported:it},(nt=ot).INTERNAL.registerComponent(new g("messaging",function(e){var t={app:e.getProvider("app").getImmediate(),installations:e.getProvider("installations").getImmediate(),analyticsProvider:e.getProvider("analytics-internal")};if(!it())throw Se.create("unsupported-browser");return self&&"ServiceWorkerGlobalScope"in self?new Je(t):new et(t)},"PUBLIC").setServiceProps(rt)),nt.registerVersion("@firebase/messaging","0.6.1")}).apply(this,arguments)}catch(e){throw console.error(e),new Error("Cannot instantiate firebase-messaging - be sure to load firebase-app.js first.")}});
//# sourceMappingURL=firebase-messaging.js.map