UNPKG

34.8 kBJavaScriptView Raw
1!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("@firebase/app")):"function"==typeof define&&define.amd?define(["@firebase/app"],e):e((t=t||self).firebase)}(this,function($t){"use strict";try{(function(){$t=$t&&$t.hasOwnProperty("default")?$t.default:$t;var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};var s=function(){return(s=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function u(o,s,a,c){return new(a=a||Promise)(function(t,e){function r(t){try{i(c.next(t))}catch(t){e(t)}}function n(t){try{i(c.throw(t))}catch(t){e(t)}}function i(e){e.done?t(e.value):new a(function(t){t(e.value)}).then(r,n)}i((c=c.apply(o,s||[])).next())})}function _(r,n){var i,o,s,t,a={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return t={next:e(0),throw:e(1),return:e(2)},"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function e(e){return function(t){return function(e){if(i)throw new TypeError("Generator is already executing.");for(;a;)try{if(i=1,o&&(s=2&e[0]?o.return:e[0]?o.throw||((s=o.return)&&s.call(o),0):o.next)&&!(s=s.call(o,e[1])).done)return s;switch(o=0,s&&(e=[2&e[0],s.value]),e[0]){case 0:case 1:s=e;break;case 4:return a.label++,{value:e[1],done:!1};case 5:a.label++,o=e[1],e=[0];continue;case 7:e=a.ops.pop(),a.trys.pop();continue;default:if(!(s=0<(s=a.trys).length&&s[s.length-1])&&(6===e[0]||2===e[0])){a=0;continue}if(3===e[0]&&(!s||e[1]>s[0]&&e[1]<s[3])){a.label=e[1];break}if(6===e[0]&&a.label<s[1]){a.label=s[1],s=e;break}if(s&&a.label<s[2]){a.label=s[2],a.ops.push(e);break}s[2]&&a.ops.pop(),a.trys.pop();continue}e=n.call(r,a)}catch(t){e=[6,t],o=0}finally{i=s=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}([e,t])}}}function n(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,i,o=r.call(t),s=[];try{for(;(void 0===e||0<e--)&&!(n=o.next()).done;)s.push(n.value)}catch(t){i={error:t}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return s}var t,e,i,h=(i=Error,r(t=a,e=i),void(t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)),a);function o(){this.constructor=t}function a(t,e){var r=i.call(this,e)||this;return r.code=t,r.name="FirebaseError",Object.setPrototypeOf(r,a.prototype),Error.captureStackTrace&&Error.captureStackTrace(r,c.prototype.create),r}var c=(l.prototype.create=function(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];for(var n=e[0]||{},i=this.service+"/"+t,o=this.errors[t],s=o?function(t,n){return t.replace(p,function(t,e){var r=n[e];return null!=r?r.toString():"<"+e+"?>"})}(o,n):"Error",a=this.serviceName+": "+s+" ("+i+").",c=new h(i,a),u=0,l=Object.keys(n);u<l.length;u++){var f=l[u];"_"!==f.slice(-1)&&(f in c&&console.warn('Overwriting FirebaseError base field "'+f+'" can cause unexpected behavior.'),c[f]=n[f])}return c},l);function l(t,e,r){this.service=t,this.serviceName=e,this.errors=r}var p=/\{\$([^}]+)}/g;function f(r){return new Promise(function(t,e){r.onsuccess=function(){t(r.result)},r.onerror=function(){e(r.error)}})}function g(r,n,i){var o,t=new Promise(function(t,e){f(o=r[n].apply(r,i)).then(t,e)});return t.request=o,t}function d(t,r,e){e.forEach(function(e){Object.defineProperty(t.prototype,e,{get:function(){return this[r][e]},set:function(t){this[r][e]=t}})})}function v(e,r,n,t){t.forEach(function(t){t in n.prototype&&(e.prototype[t]=function(){return g(this[r],t,arguments)})})}function m(e,r,n,t){t.forEach(function(t){t in n.prototype&&(e.prototype[t]=function(){return this[r][t].apply(this[r],arguments)})})}function y(e,r,n,t){t.forEach(function(t){t in n.prototype&&(e.prototype[t]=function(){return function(t,e,r){var n=g(t,e,r);return n.then(function(t){if(t)return new w(t,n.request)})}(this[r],t,arguments)})})}function b(t){this._index=t}function w(t,e){this._cursor=t,this._request=e}function S(t){this._store=t}function E(r){this._tx=r,this.complete=new Promise(function(t,e){r.oncomplete=function(){t()},r.onerror=function(){e(r.error)},r.onabort=function(){e(r.error)}})}function T(t,e,r){this._db=t,this.oldVersion=e,this.transaction=new E(r)}function C(t){this._db=t}d(b,"_index",["name","keyPath","multiEntry","unique"]),v(b,"_index",IDBIndex,["get","getKey","getAll","getAllKeys","count"]),y(b,"_index",IDBIndex,["openCursor","openKeyCursor"]),d(w,"_cursor",["direction","key","primaryKey","value"]),v(w,"_cursor",IDBCursor,["update","delete"]),["advance","continue","continuePrimaryKey"].forEach(function(r){r in IDBCursor.prototype&&(w.prototype[r]=function(){var e=this,t=arguments;return Promise.resolve().then(function(){return e._cursor[r].apply(e._cursor,t),f(e._request).then(function(t){if(t)return new w(t,e._request)})})})}),S.prototype.createIndex=function(){return new b(this._store.createIndex.apply(this._store,arguments))},S.prototype.index=function(){return new b(this._store.index.apply(this._store,arguments))},d(S,"_store",["name","keyPath","indexNames","autoIncrement"]),v(S,"_store",IDBObjectStore,["put","add","delete","clear","get","getAll","getKey","getAllKeys","count"]),y(S,"_store",IDBObjectStore,["openCursor","openKeyCursor"]),m(S,"_store",IDBObjectStore,["deleteIndex"]),E.prototype.objectStore=function(){return new S(this._tx.objectStore.apply(this._tx,arguments))},d(E,"_tx",["objectStoreNames","mode"]),m(E,"_tx",IDBTransaction,["abort"]),T.prototype.createObjectStore=function(){return new S(this._db.createObjectStore.apply(this._db,arguments))},d(T,"_db",["name","version","objectStoreNames"]),m(T,"_db",IDBDatabase,["deleteObjectStore","close"]),C.prototype.transaction=function(){return new E(this._db.transaction.apply(this._db,arguments))},d(C,"_db",["name","version","objectStoreNames"]),m(C,"_db",IDBDatabase,["close"]),["openCursor","openKeyCursor"].forEach(function(i){[S,b].forEach(function(t){i in t.prototype&&(t.prototype[i.replace("open","iterate")]=function(){var t=function(t){return Array.prototype.slice.call(t)}(arguments),e=t[t.length-1],r=this._store||this._index,n=r[i].apply(r,t.slice(0,-1));n.onsuccess=function(){e(n.result)}})})}),[b,S].forEach(function(t){t.prototype.getAll||(t.prototype.getAll=function(t,r){var n=this,i=[];return new Promise(function(e){n.iterateCursor(t,function(t){t?(i.push(t.value),void 0===r||i.length!=r?t.continue():e(i)):e(i)})})})});var I,k=1e4,O="w:0.3.3",F="FIS_v2",M="https://firebaseinstallations.googleapis.com/v1",P=36e5,j=((I={})["missing-app-config-values"]='Missing App configuration value: "{$valueName}"',I["not-registered"]="Firebase Installation is not registered.",I["installation-not-found"]="Firebase Installation not found.",I["request-failed"]='{$requestName} request failed with error "{$serverCode} {$serverStatus}: {$serverMessage}"',I["app-offline"]="Could not process request. Application offline.",I["delete-pending-registration"]="Can't delete installation while there is a pending registration request.",I),A=new c("installations","Installations",j);function N(t){return t instanceof h&&t.code.includes("request-failed")}function L(t){var e,r;if(!t||!t.options)throw D("App Configuration");if(!t.name)throw D("App Name");try{for(var n=function(t){var e="function"==typeof Symbol&&t[Symbol.iterator],r=0;return e?e.call(t):{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}}}(["projectId","apiKey","appId"]),i=n.next();!i.done;i=n.next()){var o=i.value;if(!t.options[o])throw D(o)}}catch(t){e={error:t}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(e)throw e.error}}return{appName:t.name,projectId:t.options.projectId,apiKey:t.options.apiKey,appId:t.options.appId}}function D(t){return A.create("missing-app-config-values",{valueName:t})}function x(t){var e=t.projectId;return M+"/projects/"+e+"/installations"}function R(t){return{token:t.token,requestStatus:2,expiresIn:function(t){return Number(t.replace("s","000"))}(t.expiresIn),creationTime:Date.now()}}function q(n,i){return u(this,void 0,void 0,function(){var e,r;return _(this,function(t){switch(t.label){case 0:return[4,i.json()];case 1:return e=t.sent(),r=e.error,[2,A.create("request-failed",{requestName:n,serverCode:r.code,serverMessage:r.message,serverStatus:r.status})]}})})}function K(t){var e=t.apiKey;return new Headers({"Content-Type":"application/json",Accept:"application/json","x-goog-api-key":e})}function B(t,e){var r=e.refreshToken,n=K(t);return n.append("Authorization",function(t){return F+" "+t}(r)),n}function V(r){return u(this,void 0,void 0,function(){var e;return _(this,function(t){switch(t.label){case 0:return[4,r()];case 1:return 500<=(e=t.sent()).status&&e.status<600?[2,r()]:[2,e]}})})}function z(e){return new Promise(function(t){setTimeout(t,e)})}function $(t){return btoa(String.fromCharCode.apply(String,function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(n(arguments[e]));return t}(t))).replace(/\+/g,"-").replace(/\//g,"_")}var H=/^[cdef][\w-]{21}$/,U="";function G(){try{var t=new Uint8Array(17);(self.crypto||self.msCrypto).getRandomValues(t),t[0]=112+t[0]%16;var e=function(t){return $(t).substr(0,22)}(t);return H.test(e)?e:U}catch(t){return U}}var W,J,Y="firebase-installations-database",Q=1,X="firebase-installations-store",Z=null;function tt(){return Z=Z||function(t,e,r){var n=g(indexedDB,"open",[t,e]),i=n.request;return i&&(i.onupgradeneeded=function(t){r&&r(new T(i.result,t.oldVersion,i.transaction))}),n.then(function(t){return new C(t)})}(Y,Q,function(t){switch(t.oldVersion){case 0:t.createObjectStore(X)}})}function et(i,o){return u(this,void 0,void 0,function(){var e,r,n;return _(this,function(t){switch(t.label){case 0:return e=it(i),[4,tt()];case 1:return r=t.sent(),[4,(n=r.transaction(X,"readwrite")).objectStore(X).put(o,e)];case 2:return t.sent(),[4,n.complete];case 3:return t.sent(),[2,o]}})})}function rt(i){return u(this,void 0,void 0,function(){var e,r,n;return _(this,function(t){switch(t.label){case 0:return e=it(i),[4,tt()];case 1:return r=t.sent(),[4,(n=r.transaction(X,"readwrite")).objectStore(X).delete(e)];case 2:return t.sent(),[4,n.complete];case 3:return t.sent(),[2]}})})}function nt(a,c){return u(this,void 0,void 0,function(){var e,r,n,i,o,s;return _(this,function(t){switch(t.label){case 0:return e=it(a),[4,tt()];case 1:return r=t.sent(),n=r.transaction(X,"readwrite"),[4,(i=n.objectStore(X)).get(e)];case 2:return o=t.sent(),void 0!==(s=c(o))?[3,4]:[4,i.delete(e)];case 3:return t.sent(),[3,6];case 4:return[4,i.put(s,e)];case 5:t.sent(),t.label=6;case 6:return[4,n.complete];case 7:return t.sent(),[2,s]}})})}function it(t){return t.appName+"!"+t.appId}function ot(i){return u(this,void 0,void 0,function(){var n,e,r;return _(this,function(t){switch(t.label){case 0:return[4,nt(i,function(t){var e=function(t){return at(t||{fid:G(),registrationStatus:0})}(t),r=function(t,e){{if(0!==e.registrationStatus)return 1===e.registrationStatus?{installationEntry:e,registrationPromise:function(o){return u(this,void 0,void 0,function(){var e,r,n,i;return _(this,function(t){switch(t.label){case 0:return[4,st(o)];case 1:e=t.sent(),t.label=2;case 2:return 1!==e.registrationStatus?[3,5]:[4,z(100)];case 3:return t.sent(),[4,st(o)];case 4:return e=t.sent(),[3,2];case 5:return 0!==e.registrationStatus?[3,7]:[4,ot(o)];case 6:return r=t.sent(),n=r.installationEntry,(i=r.registrationPromise)?[2,i]:[2,n];case 7:return[2,e]}})})}(t)}:{installationEntry:e};if(!navigator.onLine){var r=Promise.reject(A.create("app-offline"));return{installationEntry:e,registrationPromise:r}}var n={fid:e.fid,registrationStatus:1,registrationTime:Date.now()},i=function(n,i){return u(this,void 0,void 0,function(){var e,r;return _(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,7]),[4,function(a,t){var c=t.fid;return u(this,void 0,void 0,function(){var e,r,n,i,o,s;return _(this,function(t){switch(t.label){case 0:return e=x(a),r=K(a),n={fid:c,authVersion:F,appId:a.appId,sdkVersion:O},i={method:"POST",headers:r,body:JSON.stringify(n)},[4,V(function(){return fetch(e,i)})];case 1:return(o=t.sent()).ok?[4,o.json()]:[3,3];case 2:return s=t.sent(),[2,{fid:s.fid||c,registrationStatus:2,refreshToken:s.refreshToken,authToken:R(s.authToken)}];case 3:return[4,q("Create Installation",o)];case 4:throw t.sent()}})})}(n,i)];case 1:return e=t.sent(),[2,et(n,e)];case 2:return N(r=t.sent())&&409===r.serverCode?[4,rt(n)]:[3,4];case 3:return t.sent(),[3,6];case 4:return[4,et(n,{fid:i.fid,registrationStatus:0})];case 5:t.sent(),t.label=6;case 6:throw r;case 7:return[2]}})})}(t,n);return{installationEntry:n,registrationPromise:i}}}(i,e);return n=r.registrationPromise,r.installationEntry})];case 1:return(e=t.sent()).fid!==U?[3,3]:(r={},[4,n]);case 2:return[2,(r.installationEntry=t.sent(),r)];case 3:return[2,{installationEntry:e,registrationPromise:n}]}})})}function st(t){return nt(t,function(t){if(!t)throw A.create("installation-not-found");return at(t)})}function at(t){return function(t){return 1===t.registrationStatus&&t.registrationTime+k<Date.now()}(t)?{fid:t.fid,registrationStatus:0}:t}function ct(a,c){return u(this,void 0,void 0,function(){var e,r,n,i,o,s;return _(this,function(t){switch(t.label){case 0:return e=function(t,e){var r=e.fid;return x(t)+"/"+r+"/authTokens:generate"}(a,c),r=B(a,c),n={installation:{sdkVersion:O}},i={method:"POST",headers:r,body:JSON.stringify(n)},[4,V(function(){return fetch(e,i)})];case 1:return(o=t.sent()).ok?[4,o.json()]:[3,3];case 2:return s=t.sent(),[2,R(s)];case 3:return[4,q("Generate Auth Token",o)];case 4:throw t.sent()}})})}function ut(i,o){return void 0===o&&(o=!1),u(this,void 0,void 0,function(){var n,e,r;return _(this,function(t){switch(t.label){case 0:return[4,nt(i,function(t){if(!ft(t))throw A.create("not-registered");var e=t.authToken;if(!o&&function(t){return 2===t.requestStatus&&!function(t){var e=Date.now();return e<t.creationTime||t.creationTime+t.expiresIn<e+P}(t)}(e))return t;if(1===e.requestStatus)return n=function(n,i){return u(this,void 0,void 0,function(){var e,r;return _(this,function(t){switch(t.label){case 0:return[4,lt(n)];case 1:e=t.sent(),t.label=2;case 2:return 1!==e.authToken.requestStatus?[3,5]:[4,z(100)];case 3:return t.sent(),[4,lt(n)];case 4:return e=t.sent(),[3,2];case 5:return 0===(r=e.authToken).requestStatus?[2,ut(n,i)]:[2,r]}})})}(i,o),t;if(!navigator.onLine)throw A.create("app-offline");var r=function(t){var e={requestStatus:1,requestTime:Date.now()};return s(s({},t),{authToken:e})}(t);return n=function(i,o){return u(this,void 0,void 0,function(){var e,r,n;return _(this,function(t){switch(t.label){case 0:return t.trys.push([0,3,,8]),[4,ct(i,o)];case 1:return e=t.sent(),n=s(s({},o),{authToken:e}),[4,et(i,n)];case 2:return t.sent(),[2,e];case 3:return!N(r=t.sent())||401!==r.serverCode&&404!==r.serverCode?[3,5]:[4,rt(i)];case 4:return t.sent(),[3,7];case 5:return n=s(s({},o),{authToken:{requestStatus:0}}),[4,et(i,n)];case 6:t.sent(),t.label=7;case 7:throw r;case 8:return[2]}})})}(i,r),r})];case 1:return e=t.sent(),n?[4,n]:[3,3];case 2:return r=t.sent(),[3,4];case 3:r=e.authToken,t.label=4;case 4:return[2,r]}})})}function lt(t){return nt(t,function(t){if(!ft(t))throw A.create("not-registered");return function(t){return 1===t.requestStatus&&t.requestTime+k<Date.now()}(t.authToken)?s(s({},t),{authToken:{requestStatus:0}}):t})}function ft(t){return void 0!==t&&2===t.registrationStatus}function ht(r,n){return void 0===n&&(n=!1),u(this,void 0,void 0,function(){var e;return _(this,function(t){switch(t.label){case 0:return[4,function(r){return u(this,void 0,void 0,function(){var e;return _(this,function(t){switch(t.label){case 0:return[4,ot(r)];case 1:return(e=t.sent().registrationPromise)?[4,e]:[3,3];case 2:t.sent(),t.label=3;case 3:return[2]}})})}(e=L(r))];case 1:return t.sent(),[4,ut(e,n)];case 2:return[2,t.sent().token]}})})}function pt(o,s){return u(this,void 0,void 0,function(){var e,r,n,i;return _(this,function(t){switch(t.label){case 0:return e=function(t,e){var r=e.fid;return x(t)+"/"+r}(o,s),r=B(o,s),n={method:"DELETE",headers:r},[4,V(function(){return fetch(e,n)})];case 1:return(i=t.sent()).ok?[3,3]:[4,q("Delete Installation",i)];case 2:throw t.sent();case 3:return[2]}})})}function gt(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;var n=Array(t),i=0;for(e=0;e<r;e++)for(var o=arguments[e],s=0,a=o.length;s<a;s++,i++)n[i]=o[s];return n}$t.INTERNAL.registerService("installations",function(e){return L(e),{app:e,getId:function(){return function(o){return u(this,void 0,void 0,function(){var e,r,n,i;return _(this,function(t){switch(t.label){case 0:return[4,ot(e=L(o))];case 1:return r=t.sent(),n=r.installationEntry,(i=r.registrationPromise)?i.catch(console.error):ut(e).catch(console.error),[2,n.fid]}})})}(e)},getToken:function(t){return ht(e,t)},delete:function(){return function(n){return u(this,void 0,void 0,function(){var e,r;return _(this,function(t){switch(t.label){case 0:return[4,nt(e=L(n),function(t){if(!t||0!==t.registrationStatus)return t})];case 1:if(!(r=t.sent()))return[3,6];if(1!==r.registrationStatus)return[3,2];throw A.create("delete-pending-registration");case 2:if(2!==r.registrationStatus)return[3,6];if(navigator.onLine)return[3,3];throw A.create("app-offline");case 3:return[4,pt(e,r)];case 4:return t.sent(),[4,rt(e)];case 5:t.sent(),t.label=6;case 6:return[2]}})})}(e)}}}),(J=W=W||{})[J.DEBUG=0]="DEBUG",J[J.VERBOSE=1]="VERBOSE",J[J.INFO=2]="INFO",J[J.WARN=3]="WARN",J[J.ERROR=4]="ERROR",J[J.SILENT=5]="SILENT";function dt(t,e){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];if(!(e<t.logLevel)){var i=(new Date).toISOString();switch(e){case W.DEBUG:case W.VERBOSE:console.log.apply(console,gt(["["+i+"] "+t.name+":"],r));break;case W.INFO:console.info.apply(console,gt(["["+i+"] "+t.name+":"],r));break;case W.WARN:console.warn.apply(console,gt(["["+i+"] "+t.name+":"],r));break;case W.ERROR:console.error.apply(console,gt(["["+i+"] "+t.name+":"],r));break;default:throw new Error("Attempted to log a message with an invalid logType (value: "+e+")")}}}var vt=W.INFO,mt=(Object.defineProperty(yt.prototype,"logLevel",{get:function(){return this._logLevel},set:function(t){if(!(t in W))throw new TypeError("Invalid value assigned to `logLevel`");this._logLevel=t},enumerable:!0,configurable:!0}),Object.defineProperty(yt.prototype,"logHandler",{get:function(){return this._logHandler},set:function(t){if("function"!=typeof t)throw new TypeError("Value assigned to `logHandler` must be a function");this._logHandler=t},enumerable:!0,configurable:!0}),yt.prototype.debug=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._logHandler.apply(this,gt([this,W.DEBUG],t))},yt.prototype.log=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._logHandler.apply(this,gt([this,W.VERBOSE],t))},yt.prototype.info=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._logHandler.apply(this,gt([this,W.INFO],t))},yt.prototype.warn=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._logHandler.apply(this,gt([this,W.WARN],t))},yt.prototype.error=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._logHandler.apply(this,gt([this,W.ERROR],t))},yt);function yt(t){this.name=t,this._logLevel=vt,this._logHandler=dt}var bt,wt=(_t.prototype.isCachedDataFresh=function(t,e){if(!e)return this.logger.debug("Config fetch cache check. Cache unpopulated."),!1;var r=Date.now()-e,n=r<=t;return this.logger.debug("Config fetch cache check. Cache age millis: "+r+". Cache max age millis (minimumFetchIntervalMillis setting): "+t+". Is cache hit: "+n+"."),n},_t.prototype.fetch=function(s){return u(this,void 0,void 0,function(){var e,r,n,i,o;return _(this,function(t){switch(t.label){case 0:return[4,Promise.all([this.storage.getLastSuccessfulFetchTimestampMillis(),this.storage.getLastSuccessfulFetchResponse()])];case 1:return e=t.sent(),r=e[0],(n=e[1])&&this.isCachedDataFresh(s.cacheMaxAgeMillis,r)?[2,n]:(s.eTag=n&&n.eTag,[4,this.client.fetch(s)]);case 2:return i=t.sent(),o=[this.storageCache.setLastSuccessfulFetchTimestampMillis(Date.now())],200===i.status&&o.push(this.storage.setLastSuccessfulFetchResponse(i)),[4,Promise.all(o)];case 3:return t.sent(),[2,i]}})})},_t);function _t(t,e,r,n){this.client=t,this.storage=e,this.storageCache=r,this.logger=n}var St=((bt={})["registration-window"]="Undefined window object. This SDK only supports usage in a browser environment.",bt["registration-project-id"]="Undefined project identifier. Check Firebase app initialization.",bt["registration-api-key"]="Undefined API key. Check Firebase app initialization.",bt["registration-app-id"]="Undefined app identifier. Check Firebase app initialization.",bt["storage-open"]="Error thrown when opening storage. Original error: {$originalErrorMessage}.",bt["storage-get"]="Error thrown when reading from storage. Original error: {$originalErrorMessage}.",bt["storage-set"]="Error thrown when writing to storage. Original error: {$originalErrorMessage}.",bt["storage-delete"]="Error thrown when deleting from storage. Original error: {$originalErrorMessage}.",bt["fetch-client-network"]="Fetch client failed to connect to a network. Check Internet connection. Original error: {$originalErrorMessage}.",bt["fetch-timeout"]='The config fetch request timed out. Configure timeout using "fetchTimeoutMillis" SDK setting.',bt["fetch-throttle"]='The config fetch request timed out while in an exponential backoff state. Configure timeout using "fetchTimeoutMillis" SDK setting. Unix timestamp in milliseconds when fetch request throttling ends: {$throttleEndTimeMillis}.',bt["fetch-client-parse"]="Fetch client could not parse response. Original error: {$originalErrorMessage}.",bt["fetch-status"]="Fetch server returned an HTTP error status. HTTP status: {$httpStatus}.",bt),Et=new c("remoteconfig","Remote Config",St);var Tt=(Ct.prototype.fetch=function(w){return u(this,void 0,void 0,function(){var e,r,n,i,o,s,a,c,u,l,f,h,p,g,d,v,m,y,b;return _(this,function(t){switch(t.label){case 0:return[4,Promise.all([this.firebaseInstallations.getId(),this.firebaseInstallations.getToken()])];case 1:e=t.sent(),r=e[0],n=e[1],i=window.FIREBASE_REMOTE_CONFIG_URL_BASE||"https://firebaseremoteconfig.googleapis.com",o=i+"/v1/projects/"+this.projectId+"/namespaces/"+this.namespace+":fetch?key="+this.apiKey,s={"Content-Type":"application/json","Content-Encoding":"gzip","If-None-Match":w.eTag||"*"},a={sdk_version:this.sdkVersion,app_instance_id:r,app_instance_id_token:n,app_id:this.appId,language_code:function(t){return void 0===t&&(t=navigator),t.languages&&t.languages[0]||t.language}()},c={method:"POST",headers:s,body:JSON.stringify(a)},u=fetch(o,c),l=new Promise(function(t,e){w.signal.addEventListener(function(){var t=new Error("The operation was aborted.");t.name="AbortError",e(t)})}),t.label=2;case 2:return t.trys.push([2,5,,6]),[4,Promise.race([u,l])];case 3:return t.sent(),[4,u];case 4:return f=t.sent(),[3,6];case 5:throw h=t.sent(),p="fetch-client-network","AbortError"===h.name&&(p="fetch-timeout"),Et.create(p,{originalErrorMessage:h.message});case 6:if(g=f.status,d=f.headers.get("ETag")||void 0,200!==f.status)return[3,11];y=void 0,t.label=7;case 7:return t.trys.push([7,9,,10]),[4,f.json()];case 8:return y=t.sent(),[3,10];case 9:throw b=t.sent(),Et.create("fetch-client-parse",{originalErrorMessage:b.message});case 10:v=y.entries,m=y.state,t.label=11;case 11:if("INSTANCE_STATE_UNSPECIFIED"===m?g=500:"NO_CHANGE"===m?g=304:"NO_TEMPLATE"!==m&&"EMPTY_CONFIG"!==m||(v={}),304!==g&&200!==g)throw Et.create("fetch-status",{httpStatus:g});return[2,{status:g,eTag:d,config:v}]}})})},Ct);function Ct(t,e,r,n,i,o){this.firebaseInstallations=t,this.sdkVersion=e,this.namespace=r,this.projectId=n,this.apiKey=i,this.appId=o}var It=(kt.prototype.addEventListener=function(t){this.listeners.push(t)},kt.prototype.abort=function(){this.listeners.forEach(function(t){return t()})},kt);function kt(){this.listeners=[]}var Ot=["1","true","t","yes","y","on"],Ft=(Mt.prototype.asString=function(){return this._value},Mt.prototype.asBoolean=function(){return"static"!==this._source&&0<=Ot.indexOf(this._value.toLowerCase())},Mt.prototype.asNumber=function(){if("static"===this._source)return 0;var t=Number(this._value);return isNaN(t)&&(t=0),t},Mt.prototype.getSource=function(){return this._source},Mt);function Mt(t,e){void 0===e&&(e=""),this._source=t,this._value=e}var Pt=(jt.prototype.setLogLevel=function(t){switch(t){case"debug":this._logger.logLevel=W.DEBUG;break;case"silent":this._logger.logLevel=W.SILENT;break;default:this._logger.logLevel=W.ERROR}},Object.defineProperty(jt.prototype,"fetchTimeMillis",{get:function(){return this._storageCache.getLastSuccessfulFetchTimestampMillis()||-1},enumerable:!0,configurable:!0}),Object.defineProperty(jt.prototype,"lastFetchStatus",{get:function(){return this._storageCache.getLastFetchStatus()||"no-fetch-yet"},enumerable:!0,configurable:!0}),jt.prototype.activate=function(){return u(this,void 0,void 0,function(){var e,r,n;return _(this,function(t){switch(t.label){case 0:return[4,Promise.all([this._storage.getLastSuccessfulFetchResponse(),this._storage.getActiveConfigEtag()])];case 1:return e=t.sent(),r=e[0],n=e[1],r&&r.config&&r.eTag&&r.eTag!==n?[4,Promise.all([this._storageCache.setActiveConfig(r.config),this._storage.setActiveConfigEtag(r.eTag)])]:[2,!1];case 2:return t.sent(),[2,!0]}})})},jt.prototype.ensureInitialized=function(){var t=this;return this._initializePromise||(this._initializePromise=this._storageCache.loadFromStorage().then(function(){t._isInitializationComplete=!0})),this._initializePromise},jt.prototype.fetch=function(){return u(this,void 0,void 0,function(){var e=this;return _(this,function(t){return[2,new Promise(function(o,s){return u(e,void 0,void 0,function(){var e,r,n,i=this;return _(this,function(t){switch(t.label){case 0:e=new It,setTimeout(function(){return u(i,void 0,void 0,function(){return _(this,function(t){return e.abort(),[2]})})},this.settings.fetchTimeoutMillis),t.label=1;case 1:return t.trys.push([1,4,,6]),[4,this._client.fetch({cacheMaxAgeMillis:this.settings.minimumFetchIntervalMillis,signal:e})];case 2:return t.sent(),[4,this._storageCache.setLastFetchStatus("success")];case 3:return t.sent(),o(),[3,6];case 4:return r=t.sent(),n=function(t,e){return t instanceof h&&-1!==t.code.indexOf(e)}(r,"fetch-throttle")?"throttle":"failure",[4,this._storageCache.setLastFetchStatus(n)];case 5:return t.sent(),s(r),[3,6];case 6:return[2]}})})})]})})},jt.prototype.fetchAndActivate=function(){return u(this,void 0,void 0,function(){return _(this,function(t){switch(t.label){case 0:return[4,this.fetch()];case 1:return t.sent(),[2,this.activate()]}})})},jt.prototype.getAll=function(){var r=this;return function(t,e){return void 0===t&&(t={}),void 0===e&&(e={}),Object.keys(s(s({},t),e))}(this._storageCache.getActiveConfig(),this.defaultConfig).reduce(function(t,e){return t[e]=r.getValue(e),t},{})},jt.prototype.getBoolean=function(t){return this.getValue(t).asBoolean()},jt.prototype.getNumber=function(t){return this.getValue(t).asNumber()},jt.prototype.getString=function(t){return this.getValue(t).asString()},jt.prototype.getValue=function(t){this._isInitializationComplete||this._logger.debug('A value was requested for key "'+t+'" before SDK initialization completed. Await on ensureInitialized if the intent was to get a previously activated value.');var e=this._storageCache.getActiveConfig();return e&&void 0!==e[t]?new Ft("remote",e[t]):this.defaultConfig&&void 0!==this.defaultConfig[t]?new Ft("default",String(this.defaultConfig[t])):(this._logger.debug('Returning static value for key "'+t+'". Define a default or remote value if this is unintentional.'),new Ft("static"))},jt);function jt(t,e,r,n,i){this.app=t,this._client=e,this._storageCache=r,this._storage=n,this._logger=i,this._isInitializationComplete=!1,this.settings={fetchTimeoutMillis:6e4,minimumFetchIntervalMillis:432e5},this.defaultConfig={}}function At(t,e){var r=t.target.error||void 0;return Et.create(e,{originalErrorMessage:r&&r.message})}var Nt="app_namespace_store",Lt="firebase_remote_config",Dt=1;var xt=(Rt.prototype.getLastFetchStatus=function(){return this.get("last_fetch_status")},Rt.prototype.setLastFetchStatus=function(t){return this.set("last_fetch_status",t)},Rt.prototype.getLastSuccessfulFetchTimestampMillis=function(){return this.get("last_successful_fetch_timestamp_millis")},Rt.prototype.setLastSuccessfulFetchTimestampMillis=function(t){return this.set("last_successful_fetch_timestamp_millis",t)},Rt.prototype.getLastSuccessfulFetchResponse=function(){return this.get("last_successful_fetch_response")},Rt.prototype.setLastSuccessfulFetchResponse=function(t){return this.set("last_successful_fetch_response",t)},Rt.prototype.getActiveConfig=function(){return this.get("active_config")},Rt.prototype.setActiveConfig=function(t){return this.set("active_config",t)},Rt.prototype.getActiveConfigEtag=function(){return this.get("active_config_etag")},Rt.prototype.setActiveConfigEtag=function(t){return this.set("active_config_etag",t)},Rt.prototype.getThrottleMetadata=function(){return this.get("throttle_metadata")},Rt.prototype.setThrottleMetadata=function(t){return this.set("throttle_metadata",t)},Rt.prototype.deleteThrottleMetadata=function(){return this.delete("throttle_metadata")},Rt.prototype.get=function(a){return u(this,void 0,void 0,function(){var o,s=this;return _(this,function(t){switch(t.label){case 0:return[4,this.openDbPromise];case 1:return o=t.sent(),[2,new Promise(function(r,e){var t=o.transaction([Nt],"readonly").objectStore(Nt),n=s.createCompositeKey(a);try{var i=t.get(n);i.onerror=function(t){e(At(t,"storage-get"))},i.onsuccess=function(t){var e=t.target.result;r(e?e.value:void 0)}}catch(t){e(Et.create("storage-get",{originalErrorMessage:t&&t.message}))}})]}})})},Rt.prototype.set=function(a,c){return u(this,void 0,void 0,function(){var o,s=this;return _(this,function(t){switch(t.label){case 0:return[4,this.openDbPromise];case 1:return o=t.sent(),[2,new Promise(function(t,e){var r=o.transaction([Nt],"readwrite").objectStore(Nt),n=s.createCompositeKey(a);try{var i=r.put({compositeKey:n,value:c});i.onerror=function(t){e(At(t,"storage-set"))},i.onsuccess=function(){t()}}catch(t){e(Et.create("storage-set",{originalErrorMessage:t&&t.message}))}})]}})})},Rt.prototype.delete=function(a){return u(this,void 0,void 0,function(){var o,s=this;return _(this,function(t){switch(t.label){case 0:return[4,this.openDbPromise];case 1:return o=t.sent(),[2,new Promise(function(t,e){var r=o.transaction([Nt],"readwrite").objectStore(Nt),n=s.createCompositeKey(a);try{var i=r.delete(n);i.onerror=function(t){e(At(t,"storage-delete"))},i.onsuccess=function(){t()}}catch(t){e(Et.create("storage-delete",{originalErrorMessage:t&&t.message}))}})]}})})},Rt.prototype.createCompositeKey=function(t){return[this.appId,this.appName,this.namespace,t].join()},Rt);function Rt(t,e,r,n){void 0===n&&(n=new Promise(function(e,r){var t=indexedDB.open(Lt,Dt);t.onerror=function(t){r(At(t,"storage-open"))},t.onsuccess=function(t){e(t.target.result)},t.onupgradeneeded=function(t){var e=t.target.result;switch(t.oldVersion){case 0:e.createObjectStore(Nt,{keyPath:"compositeKey"})}}})),this.appId=t,this.appName=e,this.namespace=r,this.openDbPromise=n}var qt=(Kt.prototype.getLastFetchStatus=function(){return this.lastFetchStatus},Kt.prototype.getLastSuccessfulFetchTimestampMillis=function(){return this.lastSuccessfulFetchTimestampMillis},Kt.prototype.getActiveConfig=function(){return this.activeConfig},Kt.prototype.loadFromStorage=function(){return u(this,void 0,void 0,function(){var e,r,n,i,o,s;return _(this,function(t){switch(t.label){case 0:return e=this.storage.getLastFetchStatus(),r=this.storage.getLastSuccessfulFetchTimestampMillis(),n=this.storage.getActiveConfig(),[4,e];case 1:return(i=t.sent())&&(this.lastFetchStatus=i),[4,r];case 2:return(o=t.sent())&&(this.lastSuccessfulFetchTimestampMillis=o),[4,n];case 3:return(s=t.sent())&&(this.activeConfig=s),[2]}})})},Kt.prototype.setLastFetchStatus=function(t){return this.lastFetchStatus=t,this.storage.setLastFetchStatus(t)},Kt.prototype.setLastSuccessfulFetchTimestampMillis=function(t){return this.lastSuccessfulFetchTimestampMillis=t,this.storage.setLastSuccessfulFetchTimestampMillis(t)},Kt.prototype.setActiveConfig=function(t){return this.activeConfig=t,this.storage.setActiveConfig(t)},Kt);function Kt(t){this.storage=t}var Bt=(Vt.prototype.fetch=function(r){return u(this,void 0,void 0,function(){var e;return _(this,function(t){switch(t.label){case 0:return[4,this.storage.getThrottleMetadata()];case 1:return e=t.sent()||{backoffCount:0,throttleEndTimeMillis:Date.now()},[2,this.attemptFetch(r,e)]}})})},Vt.prototype.attemptFetch=function(i,t){var o=t.throttleEndTimeMillis,s=t.backoffCount;return u(this,void 0,void 0,function(){var e,r,n;return _(this,function(t){switch(t.label){case 0:return[4,function(i,o){return new Promise(function(t,e){var r=Math.max(o-Date.now(),0),n=setTimeout(t,r);i.addEventListener(function(){clearTimeout(n),e(Et.create("fetch-throttle",{throttleEndTimeMillis:o}))})})}(i.signal,o)];case 1:t.sent(),t.label=2;case 2:return t.trys.push([2,5,,7]),[4,this.client.fetch(i)];case 3:return e=t.sent(),[4,this.storage.deleteThrottleMetadata()];case 4:return t.sent(),[2,e];case 5:if(!function(t){if(!(t instanceof h))return!1;var e=Number(t.httpStatus);return 429===e||500===e||503===e||504===e}(r=t.sent()))throw r;return n={throttleEndTimeMillis:Date.now()+function(t){var e=1e3*Math.pow(2,t),r=Math.round(.5*e*(Math.random()-.5)*2);return Math.min(144e5,e+r)}(s),backoffCount:s+1},[4,this.storage.setThrottleMetadata(n)];case 6:return t.sent(),[2,this.attemptFetch(i,n)];case 7:return[2]}})})},Vt);function Vt(t,e){this.client=t,this.storage=e}var zt;(zt=$t).INTERNAL.registerService("remoteConfig",function(t,e,r){if("undefined"==typeof window)throw Et.create("registration-window");var n=t.options,i=n.projectId,o=n.apiKey,s=n.appId;if(!i)throw Et.create("registration-project-id");if(!o)throw Et.create("registration-api-key");if(!s)throw Et.create("registration-app-id");r=r||"firebase";var a=new xt(s,t.name,r),c=new qt(a),u=new mt("@firebase/remote-config");u.logLevel=W.ERROR;var l=new Tt(t.installations(),zt.SDK_VERSION,r,i,o,s),f=new Bt(l,a),h=new wt(f,a,c,u),p=new Pt(t,h,c,a,u);return p.ensureInitialized(),p},void 0,void 0,!0)}).apply(this,arguments)}catch(t){throw console.error(t),new Error("Cannot instantiate firebase-remote-config - be sure to load firebase-app.js first.")}});
2//# sourceMappingURL=firebase-remote-config.js.map