firebase
Version:
Firebase JavaScript library for web and Node.js
3 lines (2 loc) • 27.9 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("@firebase/app-compat"),require("@firebase/app")):"function"==typeof define&&define.amd?define(["@firebase/app-compat","@firebase/app"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).firebase,e.firebase.INTERNAL.modularAPIs)}(this,(function(e,t){"use strict";try{(function(){function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r,i,o=n(e),a=function(e,t){return(a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)};function s(e,t){for(var n=0,r=t.length,i=e.length;n<r;n++,i++)e[i]=t[n];return e}!function(e){e[e.DEBUG=0]="DEBUG",e[e.VERBOSE=1]="VERBOSE",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e[e.SILENT=5]="SILENT"}(i||(i={}));var c={debug:i.DEBUG,verbose:i.VERBOSE,info:i.INFO,warn:i.WARN,error:i.ERROR,silent:i.SILENT},u=i.INFO,l=((r={})[i.DEBUG]="log",r[i.VERBOSE]="log",r[i.INFO]="info",r[i.WARN]="warn",r[i.ERROR]="error",r),p=function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];if(!(t<e.logLevel)){var i=(new Date).toISOString(),o=l[t];if(!o)throw new Error("Attempted to log a message with an invalid logType (value: "+t+")");console[o].apply(console,s(["["+i+"] "+e.name+":"],n))}},f=function(){function e(e){this.name=e,this._logLevel=u,this._logHandler=p,this._userLogHandler=null}return Object.defineProperty(e.prototype,"logLevel",{get:function(){return this._logLevel},set:function(e){if(!(e in i))throw new TypeError('Invalid value "'+e+'" assigned to `logLevel`');this._logLevel=e},enumerable:!1,configurable:!0}),e.prototype.setLogLevel=function(e){this._logLevel="string"==typeof e?c[e]:e},Object.defineProperty(e.prototype,"logHandler",{get:function(){return this._logHandler},set:function(e){if("function"!=typeof e)throw new TypeError("Value assigned to `logHandler` must be a function");this._logHandler=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"userLogHandler",{get:function(){return this._userLogHandler},set:function(e){this._userLogHandler=e},enumerable:!1,configurable:!0}),e.prototype.debug=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._userLogHandler&&this._userLogHandler.apply(this,s([this,i.DEBUG],e)),this._logHandler.apply(this,s([this,i.DEBUG],e))},e.prototype.log=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._userLogHandler&&this._userLogHandler.apply(this,s([this,i.VERBOSE],e)),this._logHandler.apply(this,s([this,i.VERBOSE],e))},e.prototype.info=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._userLogHandler&&this._userLogHandler.apply(this,s([this,i.INFO],e)),this._logHandler.apply(this,s([this,i.INFO],e))},e.prototype.warn=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._userLogHandler&&this._userLogHandler.apply(this,s([this,i.WARN],e)),this._logHandler.apply(this,s([this,i.WARN],e))},e.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._userLogHandler&&this._userLogHandler.apply(this,s([this,i.ERROR],e)),this._logHandler.apply(this,s([this,i.ERROR],e))},e}();function d(){var e="object"==typeof chrome?chrome.runtime:"object"==typeof browser?browser.runtime:void 0;return"object"==typeof e&&void 0!==e.id}function h(){return"indexedDB"in self&&null!=indexedDB}function g(){return new Promise((function(e,t){try{var n=!0,r="validate-browser-context-for-indexeddb-analytics-module",i=self.indexedDB.open(r);i.onsuccess=function(){i.result.close(),n||self.indexedDB.deleteDatabase(r),e(!0)},i.onupgradeneeded=function(){n=!1},i.onerror=function(){var e;t((null===(e=i.error)||void 0===e?void 0:e.message)||"")}}catch(e){t(e)}}))}function m(){return!(!navigator||!navigator.cookieEnabled)}var y=function(e){function t(n,r,i){var o=e.call(this,r)||this;return o.code=n,o.customData=i,o.name="FirebaseError",Object.setPrototypeOf(o,t.prototype),Error.captureStackTrace&&Error.captureStackTrace(o,w.prototype.create),o}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}a(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(t,e),t}(Error),w=function(){function e(e,t,n){this.service=e,this.serviceName=t,this.errors=n}return e.prototype.create=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var r=t[0]||{},i=this.service+"/"+e,o=this.errors[e],a=o?v(o,r):"Error",s=this.serviceName+": "+a+" ("+i+").",c=new y(i,s,r);return c},e}();function v(e,t){return e.replace(I,(function(e,n){var r=t[n];return null!=r?String(r):"<"+n+"?>"}))}var I=/\{\$([^}]+)}/g;function b(e,t,n){void 0===t&&(t=1e3),void 0===n&&(n=2);var r=t*Math.pow(n,e),i=Math.round(.5*r*(Math.random()-.5)*2);return Math.min(144e5,r+i)}function _(e){return e&&e._delegate?e._delegate:e}var E=function(){function e(e,t,n){this.name=e,this.instanceFactory=t,this.type=n,this.multipleInstances=!1,this.serviceProps={},this.instantiationMode="LAZY",this.onInstanceCreated=null}return e.prototype.setInstantiationMode=function(e){return this.instantiationMode=e,this},e.prototype.setMultipleInstances=function(e){return this.multipleInstances=e,this},e.prototype.setServiceProps=function(e){return this.serviceProps=e,this},e.prototype.setInstanceCreatedCallback=function(e){return this.onInstanceCreated=e,this},e}();function T(e){return Array.prototype.slice.call(e)}function S(e){return new Promise((function(t,n){e.onsuccess=function(){t(e.result)},e.onerror=function(){n(e.error)}}))}function C(e,t,n){var r,i=new Promise((function(i,o){S(r=e[t].apply(e,n)).then(i,o)}));return i.request=r,i}function O(e,t,n){var r=C(e,t,n);return r.then((function(e){if(e)return new N(e,r.request)}))}function P(e,t,n){n.forEach((function(n){Object.defineProperty(e.prototype,n,{get:function(){return this[t][n]},set:function(e){this[t][n]=e}})}))}function D(e,t,n,r){r.forEach((function(r){r in n.prototype&&(e.prototype[r]=function(){return C(this[t],r,arguments)})}))}function A(e,t,n,r){r.forEach((function(r){r in n.prototype&&(e.prototype[r]=function(){return this[t][r].apply(this[t],arguments)})}))}function j(e,t,n,r){r.forEach((function(r){r in n.prototype&&(e.prototype[r]=function(){return O(this[t],r,arguments)})}))}function x(e){this._index=e}function N(e,t){this._cursor=e,this._request=t}function k(e){this._store=e}function R(e){this._tx=e,this.complete=new Promise((function(t,n){e.oncomplete=function(){t()},e.onerror=function(){n(e.error)},e.onabort=function(){n(e.error)}}))}function L(e,t,n){this._db=e,this.oldVersion=t,this.transaction=new R(n)}function M(e){this._db=e}P(x,"_index",["name","keyPath","multiEntry","unique"]),D(x,"_index",IDBIndex,["get","getKey","getAll","getAllKeys","count"]),j(x,"_index",IDBIndex,["openCursor","openKeyCursor"]),P(N,"_cursor",["direction","key","primaryKey","value"]),D(N,"_cursor",IDBCursor,["update","delete"]),["advance","continue","continuePrimaryKey"].forEach((function(e){e in IDBCursor.prototype&&(N.prototype[e]=function(){var t=this,n=arguments;return Promise.resolve().then((function(){return t._cursor[e].apply(t._cursor,n),S(t._request).then((function(e){if(e)return new N(e,t._request)}))}))})})),k.prototype.createIndex=function(){return new x(this._store.createIndex.apply(this._store,arguments))},k.prototype.index=function(){return new x(this._store.index.apply(this._store,arguments))},P(k,"_store",["name","keyPath","indexNames","autoIncrement"]),D(k,"_store",IDBObjectStore,["put","add","delete","clear","get","getAll","getKey","getAllKeys","count"]),j(k,"_store",IDBObjectStore,["openCursor","openKeyCursor"]),A(k,"_store",IDBObjectStore,["deleteIndex"]),R.prototype.objectStore=function(){return new k(this._tx.objectStore.apply(this._tx,arguments))},P(R,"_tx",["objectStoreNames","mode"]),A(R,"_tx",IDBTransaction,["abort"]),L.prototype.createObjectStore=function(){return new k(this._db.createObjectStore.apply(this._db,arguments))},P(L,"_db",["name","version","objectStoreNames"]),A(L,"_db",IDBDatabase,["deleteObjectStore","close"]),M.prototype.transaction=function(){return new R(this._db.transaction.apply(this._db,arguments))},P(M,"_db",["name","version","objectStoreNames"]),A(M,"_db",IDBDatabase,["close"]),["openCursor","openKeyCursor"].forEach((function(e){[k,x].forEach((function(t){e in t.prototype&&(t.prototype[e.replace("open","iterate")]=function(){var t=T(arguments),n=t[t.length-1],r=this._store||this._index,i=r[e].apply(r,t.slice(0,-1));i.onsuccess=function(){n(i.result)}})}))})),[x,k].forEach((function(e){e.prototype.getAll||(e.prototype.getAll=function(e,t){var n=this,r=[];return new Promise((function(i){n.iterateCursor(e,(function(e){e?(r.push(e.value),void 0===t||r.length!=t?e.continue():i(r)):i(r)}))}))})}));const F="0.0.900-exp.6ef484a04",B=1e4,$=`w:${F}`,H="FIS_v2",q=36e5,V=new w("installations","Installations",{"missing-app-config-values":'Missing App configuration value: "{$valueName}"',"not-registered":"Firebase Installation is not registered.","installation-not-found":"Firebase Installation not found.","request-failed":'{$requestName} request failed with error "{$serverCode} {$serverStatus}: {$serverMessage}"',"app-offline":"Could not process request. Application offline.","delete-pending-registration":"Can't delete installation while there is a pending registration request."});function K(e){return e instanceof y&&e.code.includes("request-failed")}function U({projectId:e}){return`https://firebaseinstallations.googleapis.com/v1/projects/${e}/installations`}function G(e){return{token:e.token,requestStatus:2,expiresIn:(t=e.expiresIn,Number(t.replace("s","000"))),creationTime:Date.now()};var t}async function W(e,t){const n=(await t.json()).error;return V.create("request-failed",{requestName:e,serverCode:n.code,serverMessage:n.message,serverStatus:n.status})}function z({apiKey:e}){return new Headers({"Content-Type":"application/json",Accept:"application/json","x-goog-api-key":e})}function J(e,{refreshToken:t}){const n=z(e);return n.append("Authorization",function(e){return`FIS_v2 ${e}`}(t)),n}async function Y(e){const t=await e();return t.status>=500&&t.status<600?e():t}function X(e){return new Promise((t=>{setTimeout(t,e)}))}const Z=/^[cdef][\w-]{21}$/;function Q(){try{const e=new Uint8Array(17);(self.crypto||self.msCrypto).getRandomValues(e),e[0]=112+e[0]%16;const t=function(e){return(t=e,btoa(String.fromCharCode(...t)).replace(/\+/g,"-").replace(/\//g,"_")).substr(0,22);var t}(e);return Z.test(t)?t:""}catch(e){return""}}function ee(e){return`${e.appName}!${e.appId}`}const te=new Map;function ne(e,t){const n=ee(e);re(n,t),function(e,t){const n=function(){!ie&&"BroadcastChannel"in self&&(ie=new BroadcastChannel("[Firebase] FID Change"),ie.onmessage=e=>{re(e.data.key,e.data.fid)});return ie}();n&&n.postMessage({key:e,fid:t});0===te.size&&ie&&(ie.close(),ie=null)}(n,t)}function re(e,t){const n=te.get(e);if(n)for(const e of n)e(t)}let ie=null;const oe="firebase-installations-store";let ae=null;function se(){return ae||(ae=function(e,t,n){var r=C(indexedDB,"open",[e,t]),i=r.request;return i&&(i.onupgradeneeded=function(e){n&&n(new L(i.result,e.oldVersion,i.transaction))}),r.then((function(e){return new M(e)}))}("firebase-installations-database",1,(e=>{switch(e.oldVersion){case 0:e.createObjectStore(oe)}}))),ae}async function ce(e,t){const n=ee(e),r=(await se()).transaction(oe,"readwrite"),i=r.objectStore(oe),o=await i.get(n);return await i.put(t,n),await r.complete,o&&o.fid===t.fid||ne(e,t.fid),t}async function ue(e){const t=ee(e),n=(await se()).transaction(oe,"readwrite");await n.objectStore(oe).delete(t),await n.complete}async function le(e,t){const n=ee(e),r=(await se()).transaction(oe,"readwrite"),i=r.objectStore(oe),o=await i.get(n),a=t(o);return void 0===a?await i.delete(n):await i.put(a,n),await r.complete,!a||o&&o.fid===a.fid||ne(e,a.fid),a}async function pe(e){let t;const n=await le(e,(n=>{const r=function(e){return he(e||{fid:Q(),registrationStatus:0})}(n),i=function(e,t){if(0===t.registrationStatus){if(!navigator.onLine){return{installationEntry:t,registrationPromise:Promise.reject(V.create("app-offline"))}}const n={fid:t.fid,registrationStatus:1,registrationTime:Date.now()};return{installationEntry:n,registrationPromise:async function(e,t){try{return ce(e,await async function(e,{fid:t}){const n=U(e),r=z(e),i={fid:t,authVersion:H,appId:e.appId,sdkVersion:$},o={method:"POST",headers:r,body:JSON.stringify(i)},a=await Y((()=>fetch(n,o)));if(a.ok){const e=await a.json();return{fid:e.fid||t,registrationStatus:2,refreshToken:e.refreshToken,authToken:G(e.authToken)}}throw await W("Create Installation",a)}(e,t))}catch(n){throw K(n)&&409===n.customData.serverCode?await ue(e):await ce(e,{fid:t.fid,registrationStatus:0}),n}}(e,n)}}return 1===t.registrationStatus?{installationEntry:t,registrationPromise:fe(e)}:{installationEntry:t}}(e,r);return t=i.registrationPromise,i.installationEntry}));return""===n.fid?{installationEntry:await t}:{installationEntry:n,registrationPromise:t}}async function fe(e){let t=await de(e);for(;1===t.registrationStatus;)await X(100),t=await de(e);if(0===t.registrationStatus){const{installationEntry:t,registrationPromise:n}=await pe(e);return n||t}return t}function de(e){return le(e,(e=>{if(!e)throw V.create("installation-not-found");return he(e)}))}function he(e){return 1===(t=e).registrationStatus&&t.registrationTime+B<Date.now()?{fid:e.fid,registrationStatus:0}:e;var t}async function ge({appConfig:e,platformLoggerProvider:t},n){const r=function(e,{fid:t}){return`${U(e)}/${t}/authTokens:generate`}(e,n),i=J(e,n),o=t.getImmediate({optional:!0});o&&i.append("x-firebase-client",o.getPlatformInfoString());const a={installation:{sdkVersion:$}},s={method:"POST",headers:i,body:JSON.stringify(a)},c=await Y((()=>fetch(r,s)));if(c.ok){return G(await c.json())}throw await W("Generate Auth Token",c)}async function me(e,t=!1){let n;const r=await le(e.appConfig,(r=>{if(!we(r))throw V.create("not-registered");const i=r.authToken;if(!t&&function(e){return 2===e.requestStatus&&!function(e){const t=Date.now();return t<e.creationTime||e.creationTime+e.expiresIn<t+q}(e)}(i))return r;if(1===i.requestStatus)return n=async function(e,t){let n=await ye(e.appConfig);for(;1===n.authToken.requestStatus;)await X(100),n=await ye(e.appConfig);const r=n.authToken;return 0===r.requestStatus?me(e,t):r}(e,t),r;{if(!navigator.onLine)throw V.create("app-offline");const t=function(e){const t={requestStatus:1,requestTime:Date.now()};return Object.assign(Object.assign({},e),{authToken:t})}(r);return n=async function(e,t){try{const n=await ge(e,t),r=Object.assign(Object.assign({},t),{authToken:n});return await ce(e.appConfig,r),n}catch(n){if(!K(n)||401!==n.customData.serverCode&&404!==n.customData.serverCode){const n=Object.assign(Object.assign({},t),{authToken:{requestStatus:0}});await ce(e.appConfig,n)}else await ue(e.appConfig);throw n}}(e,t),t}}));return n?await n:r.authToken}function ye(e){return le(e,(e=>{if(!we(e))throw V.create("not-registered");const t=e.authToken;return 1===(n=t).requestStatus&&n.requestTime+B<Date.now()?Object.assign(Object.assign({},e),{authToken:{requestStatus:0}}):e;var n}))}function we(e){return void 0!==e&&2===e.registrationStatus}async function ve(e,t=!1){const n=e;await async function(e){const{registrationPromise:t}=await pe(e);t&&await t}(n.appConfig);return(await me(n,t)).token}function Ie(e){return V.create("missing-app-config-values",{valueName:e})}const be="installations-exp",_e=e=>{const n=e.getProvider("app-exp").getImmediate();return{app:n,appConfig:function(e){if(!e||!e.options)throw Ie("App Configuration");if(!e.name)throw Ie("App Name");const t=["projectId","apiKey","appId"];for(const n of t)if(!e.options[n])throw Ie(n);return{appName:e.name,projectId:e.options.projectId,apiKey:e.options.apiKey,appId:e.options.appId}}(n),platformLoggerProvider:t._getProvider(n,"platform-logger"),_delete:()=>Promise.resolve()}},Ee=e=>{const n=e.getProvider("app-exp").getImmediate(),r=t._getProvider(n,be).getImmediate();return{getId:()=>async function(e){const t=e,{installationEntry:n,registrationPromise:r}=await pe(t.appConfig);return r?r.catch(console.error):me(t).catch(console.error),n.fid}(r),getToken:e=>ve(r,e)}};t._registerComponent(new E(be,_e,"PUBLIC")),t._registerComponent(new E("installations-exp-internal",Ee,"PRIVATE")),t.registerVersion("@firebase/installations-exp",F);const Te="analytics-exp",Se="https://www.googletagmanager.com/gtag/js",Ce=new f("@firebase/analytics");function Oe(e){return Promise.all(e.map((e=>e.catch((e=>e)))))}function Pe(e,t,n,r){return async function(i,o,a){try{"event"===i?await async function(e,t,n,r,i){try{let o=[];if(i&&i.send_to){let e=i.send_to;Array.isArray(e)||(e=[e]);const r=await Oe(n);for(const n of e){const e=r.find((e=>e.measurementId===n)),i=e&&t[e.appId];if(!i){o=[];break}o.push(i)}}0===o.length&&(o=Object.values(t)),await Promise.all(o),e("event",r,i||{})}catch(e){Ce.error(e)}}(e,t,n,o,a):"config"===i?await async function(e,t,n,r,i,o){const a=r[i];try{if(a)await t[a];else{const e=(await Oe(n)).find((e=>e.measurementId===i));e&&await t[e.appId]}}catch(e){Ce.error(e)}e("config",i,o)}(e,t,n,r,o,a):e("set",o)}catch(e){Ce.error(e)}}}const De=new w("analytics","Analytics",{"already-exists":"A Firebase Analytics instance with the appId {$id} already exists. Only one Firebase Analytics instance can be created for each appId.","already-initialized":"Firebase Analytics has already been initialized. initializeAnalytics() must only be called once. getAnalytics() can be used to get a reference to the already-intialized instance.","already-initialized-settings":"Firebase Analytics has already been initialized.settings() must be called before initializing any Analytics instanceor it will have no effect.","interop-component-reg-failed":"Firebase Analytics Interop Component failed to instantiate: {$reason}","invalid-analytics-context":"Firebase Analytics is not supported in this environment. Wrap initialization of analytics in analytics.isSupported() to prevent initialization in unsupported environments. Details: {$errorInfo}","indexeddb-unavailable":"IndexedDB unavailable or restricted in this environment. Wrap initialization of analytics in analytics.isSupported() to prevent initialization in unsupported environments. Details: {$errorInfo}","fetch-throttle":"The config fetch request timed out while in an exponential backoff state. Unix timestamp in milliseconds when fetch request throttling ends: {$throttleEndTimeMillis}.","config-fetch-failed":"Dynamic config fetch failed: [{$httpStatus}] {$responseMessage}","no-api-key":'The "apiKey" field is empty in the local Firebase config. Firebase Analytics requires this field tocontain a valid API key.',"no-app-id":'The "appId" field is empty in the local Firebase config. Firebase Analytics requires this field tocontain a valid app ID.'});const Ae=new class{constructor(e={},t=1e3){this.throttleMetadata=e,this.intervalMillis=t}getThrottleMetadata(e){return this.throttleMetadata[e]}setThrottleMetadata(e,t){this.throttleMetadata[e]=t}deleteThrottleMetadata(e){delete this.throttleMetadata[e]}};function je(e){return new Headers({Accept:"application/json","x-goog-api-key":e})}async function xe(e,t=Ae,n){const{appId:r,apiKey:i,measurementId:o}=e.options;if(!r)throw De.create("no-app-id");if(!i){if(o)return{measurementId:o,appId:r};throw De.create("no-api-key")}const a=t.getThrottleMetadata(r)||{backoffCount:0,throttleEndTimeMillis:Date.now()},s=new ke;return setTimeout((async()=>{s.abort()}),void 0!==n?n:6e4),Ne({appId:r,apiKey:i,measurementId:o},a,s,t)}async function Ne(e,{throttleEndTimeMillis:t,backoffCount:n},r,i=Ae){const{appId:o,measurementId:a}=e;try{await function(e,t){return new Promise(((n,r)=>{const i=Math.max(t-Date.now(),0),o=setTimeout(n,i);e.addEventListener((()=>{clearTimeout(o),r(De.create("fetch-throttle",{throttleEndTimeMillis:t}))}))}))}(r,t)}catch(e){if(a)return Ce.warn(`Timed out fetching this Firebase app's measurement ID from the server. Falling back to the measurement ID ${a} provided in the "measurementId" field in the local Firebase config. [${e.message}]`),{appId:o,measurementId:a};throw e}try{const t=await async function(e){var t;const{appId:n,apiKey:r}=e,i={method:"GET",headers:je(r)},o="https://firebase.googleapis.com/v1alpha/projects/-/apps/{app-id}/webConfig".replace("{app-id}",n),a=await fetch(o,i);if(200!==a.status&&304!==a.status){let e="";try{const n=await a.json();(null===(t=n.error)||void 0===t?void 0:t.message)&&(e=n.error.message)}catch(e){}throw De.create("config-fetch-failed",{httpStatus:a.status,responseMessage:e})}return a.json()}(e);return i.deleteThrottleMetadata(o),t}catch(t){if(!function(e){if(!(e instanceof y&&e.customData))return!1;const t=Number(e.customData.httpStatus);return 429===t||500===t||503===t||504===t}(t)){if(i.deleteThrottleMetadata(o),a)return Ce.warn(`Failed to fetch this Firebase app's measurement ID from the server. Falling back to the measurement ID ${a} provided in the "measurementId" field in the local Firebase config. [${t.message}]`),{appId:o,measurementId:a};throw t}const s=503===Number(t.customData.httpStatus)?b(n,i.intervalMillis,30):b(n,i.intervalMillis),c={throttleEndTimeMillis:Date.now()+s,backoffCount:n+1};return i.setThrottleMetadata(o,c),Ce.debug(`Calling attemptFetch again in ${s} millis`),Ne(e,c,r,i)}}class ke{constructor(){this.listeners=[]}addEventListener(e){this.listeners.push(e)}abort(){this.listeners.forEach((e=>e()))}}async function Re(e,t,n,r,i,o,a){var s;const c=xe(e);c.then((t=>{n[t.measurementId]=t.appId,e.options.measurementId&&t.measurementId!==e.options.measurementId&&Ce.warn(`The measurement ID in the local Firebase config (${e.options.measurementId}) does not match the measurement ID fetched from the server (${t.measurementId}). To ensure analytics events are always sent to the correct Analytics property, update the measurement ID field in the local config or remove it from the local config.`)})).catch((e=>Ce.error(e))),t.push(c);const u=async function(){if(!h())return Ce.warn(De.create("indexeddb-unavailable",{errorInfo:"IndexedDB is not available in this environment."}).message),!1;try{await g()}catch(e){return Ce.warn(De.create("indexeddb-unavailable",{errorInfo:e}).message),!1}return!0}().then((e=>e?r.getId():void 0)),[l,p]=await Promise.all([c,u]);(function(){const e=window.document.getElementsByTagName("script");for(const t of Object.values(e))if(t.src&&t.src.includes(Se))return t;return null})()||function(e,t){const n=document.createElement("script");n.src=`${Se}?l=${e}&id=${t}`,n.async=!0,document.head.appendChild(n)}(o,l.measurementId),i("js",new Date);const f=null!==(s=null==a?void 0:a.config)&&void 0!==s?s:{};return f.origin="firebase",f.update=!0,null!=p&&(f.firebase_id=p),i("config",l.measurementId,f),l.measurementId}class Le{constructor(e){this.app=e}_delete(){return delete Me[this.app.options.appId],Promise.resolve()}}let Me={},Fe=[];const Be={};let $e,He,qe="dataLayer",Ve="gtag",Ke=!1;function Ue(e){if(Ke)throw De.create("already-initialized");e.dataLayerName&&(qe=e.dataLayerName),e.gtagName&&(Ve=e.gtagName)}function Ge(e,t,n){!function(){const e=[];if(d()&&e.push("This is a browser extension environment."),m()||e.push("Cookies are not available."),e.length>0){const t=e.map(((e,t)=>`(${t+1}) ${e}`)).join(" "),n=De.create("invalid-analytics-context",{errorInfo:t});Ce.warn(n.message)}}();const r=e.options.appId;if(!r)throw De.create("no-app-id");if(!e.options.apiKey){if(!e.options.measurementId)throw De.create("no-api-key");Ce.warn(`The "apiKey" field is empty in the local Firebase config. This is needed to fetch the latest measurement ID for this Firebase app. Falling back to the measurement ID ${e.options.measurementId} provided in the "measurementId" field in the local Firebase config.`)}if(null!=Me[r])throw De.create("already-exists",{id:r});if(!Ke){!function(e){let t=[];Array.isArray(window[e])?t=window[e]:window[e]=t}(qe);const{wrappedGtag:e,gtagCore:t}=function(e,t,n,r,i){let o=function(...e){window[r].push(arguments)};return window[i]&&"function"==typeof window[i]&&(o=window[i]),window[i]=Pe(o,e,t,n),{gtagCore:o,wrappedGtag:window[i]}}(Me,Fe,Be,qe,Ve);He=e,$e=t,Ke=!0}Me[r]=Re(e,Fe,Be,t,$e,qe,n);return new Le(e)}async function We(){if(d())return!1;if(!m())return!1;if(!h())return!1;try{return await g()}catch(e){return!1}}function ze(e,t,n){e=_(e),async function(e,t,n,r){if(r&&r.global)return e("set",{screen_name:n}),Promise.resolve();e("config",await t,{update:!0,screen_name:n})}(He,Me[e.app.options.appId],t,n).catch((e=>Ce.error(e)))}function Je(e,t,n){e=_(e),async function(e,t,n,r){if(r&&r.global)return e("set",{user_id:n}),Promise.resolve();e("config",await t,{update:!0,user_id:n})}(He,Me[e.app.options.appId],t,n).catch((e=>Ce.error(e)))}function Ye(e,t,n){e=_(e),async function(e,t,n,r){if(r&&r.global){const t={};for(const e of Object.keys(n))t[`user_properties.${e}`]=n[e];return e("set",t),Promise.resolve()}e("config",await t,{update:!0,user_properties:n})}(He,Me[e.app.options.appId],t,n).catch((e=>Ce.error(e)))}function Xe(e,t){e=_(e),async function(e,t){const n=await e;window[`ga-disable-${n}`]=!t}(Me[e.app.options.appId],t).catch((e=>Ce.error(e)))}function Ze(e,t,n,r){e=_(e),async function(e,t,n,r,i){if(i&&i.global)e("event",n,r);else{const i=await t;e("event",n,Object.assign(Object.assign({},r),{send_to:i}))}}(He,Me[e.app.options.appId],t,n,r).catch((e=>Ce.error(e)))}t._registerComponent(new E(Te,((e,{options:t})=>Ge(e.getProvider("app-exp").getImmediate(),e.getProvider("installations-exp-internal").getImmediate(),t)),"PUBLIC")),t._registerComponent(new E("analytics-internal",(function(e){try{const t=e.getProvider(Te).getImmediate();return{logEvent:(e,n,r)=>Ze(t,e,n,r)}}catch(e){throw De.create("interop-component-reg-failed",{reason:e})}}),"PRIVATE")),t.registerVersion("@firebase/analytics-exp","0.0.900-exp.6ef484a04");class Qe{constructor(e,t){this.app=e,this._delegate=t}logEvent(e,t,n){Ze(this._delegate,e,t,n)}setCurrentScreen(e,t){ze(this._delegate,e,t)}setUserId(e,t){Je(this._delegate,e,t)}setUserProperties(e,t){Ye(this._delegate,e,t)}setAnalyticsCollectionEnabled(e){Xe(this._delegate,e)}}var et;!function(e){e.ADD_SHIPPING_INFO="add_shipping_info",e.ADD_PAYMENT_INFO="add_payment_info",e.ADD_TO_CART="add_to_cart",e.ADD_TO_WISHLIST="add_to_wishlist",e.BEGIN_CHECKOUT="begin_checkout",e.CHECKOUT_PROGRESS="checkout_progress",e.EXCEPTION="exception",e.GENERATE_LEAD="generate_lead",e.LOGIN="login",e.PAGE_VIEW="page_view",e.PURCHASE="purchase",e.REFUND="refund",e.REMOVE_FROM_CART="remove_from_cart",e.SCREEN_VIEW="screen_view",e.SEARCH="search",e.SELECT_CONTENT="select_content",e.SELECT_ITEM="select_item",e.SELECT_PROMOTION="select_promotion",e.SET_CHECKOUT_OPTION="set_checkout_option",e.SHARE="share",e.SIGN_UP="sign_up",e.TIMING_COMPLETE="timing_complete",e.VIEW_CART="view_cart",e.VIEW_ITEM="view_item",e.VIEW_ITEM_LIST="view_item_list",e.VIEW_PROMOTION="view_promotion",e.VIEW_SEARCH_RESULTS="view_search_results"}(et||(et={}));const tt=e=>{const t=e.getProvider("app-compat").getImmediate(),n=e.getProvider("analytics-exp").getImmediate();return new Qe(t,n)};!function(){const e={Analytics:Qe,settings:Ue,isSupported:We,EventName:et};o.default.INTERNAL.registerComponent(new E("analytics-compat",tt,"PUBLIC").setServiceProps(e).setMultipleInstances(!0))}(),o.default.registerVersion("@firebase/analytics-compat","0.0.900-exp.6ef484a04")}).apply(this,arguments)}catch(e){throw console.error(e),new Error("Cannot instantiate firebase-analytics-compat.js - be sure to load firebase-app.js first.")}}));
//# sourceMappingURL=firebase-analytics-compat.js.map