1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-11-13 02:20:18 +00:00
musix-oss/node_modules/firebase/firebase-performance.js
2019-10-10 16:43:04 +03:00

3 lines
33 KiB
JavaScript

!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(be){"use strict";try{(function(){be=be&&be.hasOwnProperty("default")?be.default:be;var n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};var a=function(){return(a=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function u(o,a,s,c){return new(s=s||Promise)(function(t,e){function n(t){try{i(c.next(t))}catch(t){e(t)}}function r(t){try{i(c.throw(t))}catch(t){e(t)}}function i(e){e.done?t(e.value):new s(function(t){t(e.value)}).then(n,r)}i((c=c.apply(o,a||[])).next())})}function f(n,r){var i,o,a,t,s={label:0,sent:function(){if(1&a[0])throw a[1];return a[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(;s;)try{if(i=1,o&&(a=2&e[0]?o.return:e[0]?o.throw||((a=o.return)&&a.call(o),0):o.next)&&!(a=a.call(o,e[1])).done)return a;switch(o=0,a&&(e=[2&e[0],a.value]),e[0]){case 0:case 1:a=e;break;case 4:return s.label++,{value:e[1],done:!1};case 5:s.label++,o=e[1],e=[0];continue;case 7:e=s.ops.pop(),s.trys.pop();continue;default:if(!(a=0<(a=s.trys).length&&a[a.length-1])&&(6===e[0]||2===e[0])){s=0;continue}if(3===e[0]&&(!a||e[1]>a[0]&&e[1]<a[3])){s.label=e[1];break}if(6===e[0]&&s.label<a[1]){s.label=a[1],a=e;break}if(a&&s.label<a[2]){s.label=a[2],s.ops.push(e);break}a[2]&&s.ops.pop(),s.trys.pop();continue}e=r.call(n,s)}catch(t){e=[6,t],o=0}finally{i=a=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}([e,t])}}}function r(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,o=n.call(t),a=[];try{for(;(void 0===e||0<e--)&&!(r=o.next()).done;)a.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return a}var t,e,i,p=(i=Error,n(t=s,e=i),void(t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)),s);function o(){this.constructor=t}function s(t,e){var n=i.call(this,e)||this;return n.code=t,n.name="FirebaseError",Object.setPrototypeOf(n,s.prototype),Error.captureStackTrace&&Error.captureStackTrace(n,c.prototype.create),n}var c=(l.prototype.create=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];for(var r=e[0]||{},i=this.service+"/"+t,o=this.errors[t],a=o?function(t,r){return t.replace(h,function(t,e){var n=r[e];return null!=n?n.toString():"<"+e+"?>"})}(o,r):"Error",s=this.serviceName+": "+a+" ("+i+").",c=new p(i,s),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},l);function l(t,e,n){this.service=t,this.serviceName=e,this.errors=n}var h=/\{\$([^}]+)}/g;function d(n){return new Promise(function(t,e){n.onsuccess=function(){t(n.result)},n.onerror=function(){e(n.error)}})}function g(n,r,i){var o,t=new Promise(function(t,e){d(o=n[r].apply(n,i)).then(t,e)});return t.request=o,t}function v(t,n,e){e.forEach(function(e){Object.defineProperty(t.prototype,e,{get:function(){return this[n][e]},set:function(t){this[n][e]=t}})})}function m(e,n,r,t){t.forEach(function(t){t in r.prototype&&(e.prototype[t]=function(){return g(this[n],t,arguments)})})}function b(e,n,r,t){t.forEach(function(t){t in r.prototype&&(e.prototype[t]=function(){return this[n][t].apply(this[n],arguments)})})}function y(e,n,r,t){t.forEach(function(t){t in r.prototype&&(e.prototype[t]=function(){return function(t,e,n){var r=g(t,e,n);return r.then(function(t){if(t)return new w(t,r.request)})}(this[n],t,arguments)})})}function _(t){this._index=t}function w(t,e){this._cursor=t,this._request=e}function I(t){this._store=t}function E(n){this._tx=n,this.complete=new Promise(function(t,e){n.oncomplete=function(){t()},n.onerror=function(){e(n.error)},n.onabort=function(){e(n.error)}})}function S(t,e,n){this._db=t,this.oldVersion=e,this.transaction=new E(n)}function T(t){this._db=t}v(_,"_index",["name","keyPath","multiEntry","unique"]),m(_,"_index",IDBIndex,["get","getKey","getAll","getAllKeys","count"]),y(_,"_index",IDBIndex,["openCursor","openKeyCursor"]),v(w,"_cursor",["direction","key","primaryKey","value"]),m(w,"_cursor",IDBCursor,["update","delete"]),["advance","continue","continuePrimaryKey"].forEach(function(n){n in IDBCursor.prototype&&(w.prototype[n]=function(){var e=this,t=arguments;return Promise.resolve().then(function(){return e._cursor[n].apply(e._cursor,t),d(e._request).then(function(t){if(t)return new w(t,e._request)})})})}),I.prototype.createIndex=function(){return new _(this._store.createIndex.apply(this._store,arguments))},I.prototype.index=function(){return new _(this._store.index.apply(this._store,arguments))},v(I,"_store",["name","keyPath","indexNames","autoIncrement"]),m(I,"_store",IDBObjectStore,["put","add","delete","clear","get","getAll","getKey","getAllKeys","count"]),y(I,"_store",IDBObjectStore,["openCursor","openKeyCursor"]),b(I,"_store",IDBObjectStore,["deleteIndex"]),E.prototype.objectStore=function(){return new I(this._tx.objectStore.apply(this._tx,arguments))},v(E,"_tx",["objectStoreNames","mode"]),b(E,"_tx",IDBTransaction,["abort"]),S.prototype.createObjectStore=function(){return new I(this._db.createObjectStore.apply(this._db,arguments))},v(S,"_db",["name","version","objectStoreNames"]),b(S,"_db",IDBDatabase,["deleteObjectStore","close"]),T.prototype.transaction=function(){return new E(this._db.transaction.apply(this._db,arguments))},v(T,"_db",["name","version","objectStoreNames"]),b(T,"_db",IDBDatabase,["close"]),["openCursor","openKeyCursor"].forEach(function(i){[I,_].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],n=this._store||this._index,r=n[i].apply(n,t.slice(0,-1));r.onsuccess=function(){e(r.result)}})})}),[_,I].forEach(function(t){t.prototype.getAll||(t.prototype.getAll=function(t,n){var r=this,i=[];return new Promise(function(e){r.iterateCursor(t,function(t){t?(i.push(t.value),void 0===n||i.length!=n?t.continue():e(i)):e(i)})})})});var k,A=1e4,N="w:0.2.6",O="FIS_v2",P="https://firebaseinstallations.googleapis.com/v1",R=36e5,j=((k={})["missing-app-config-values"]="Missing App configuration values.",k["create-installation-failed"]="Could not register Firebase Installation.",k["generate-token-failed"]="Could not generate Auth Token.",k["not-registered"]="Firebase Installation is not registered.",k["installation-not-found"]="Firebase Installation not found.",k["request-failed"]='{$requestName} request failed with error "{$serverCode} {$serverStatus}: {$serverMessage}"',k["app-offline"]="Could not process request. Application offline.",k["delete-pending-registration"]="Can't delete installation while there is a pending registration request.",k),M=new c("installations","Installations",j);function D(t){return t instanceof p&&t.code.includes("request-failed")}function B(t){if(!t||!t.options)throw M.create("missing-app-config-values");var e=t.name,n=t.options,r=n.projectId,i=n.apiKey,o=n.appId;if(!(e&&r&&i&&o))throw M.create("missing-app-config-values");return{appName:e,projectId:r,apiKey:i,appId:o}}function C(t){var e=t.projectId;return P+"/projects/"+e+"/installations"}function q(t){return{token:t.token,requestStatus:2,expiresIn:function(t){return Number(t.replace("s","000"))}(t.expiresIn),creationTime:Date.now()}}function x(r,i){return u(this,void 0,void 0,function(){var e,n;return f(this,function(t){switch(t.label){case 0:return[4,i.json()];case 1:return e=t.sent(),n=e.error,[2,M.create("request-failed",{requestName:r,serverCode:n.code,serverMessage:n.message,serverStatus:n.status})]}})})}function U(t){var e=t.apiKey;return new Headers({"Content-Type":"application/json",Accept:"application/json","x-goog-api-key":e})}function L(t,e){var n=e.refreshToken,r=U(t);return r.append("Authorization",function(t){return O+" "+t}(n)),r}function F(n){return u(this,void 0,void 0,function(){var e;return f(this,function(t){switch(t.label){case 0:return[4,n()];case 1:return 500<=(e=t.sent()).status&&e.status<600?[2,n()]:[2,e]}})})}function K(e){return new Promise(function(t){setTimeout(t,e)})}function V(t){return btoa(String.fromCharCode.apply(String,function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(r(arguments[e]));return t}(t))).replace(/\+/g,"-").replace(/\//g,"_")}var H=/^[cdef][\w-]{21}$/,W="";function $(){try{var t=new Uint8Array(17);(self.crypto||self.msCrypto).getRandomValues(t),t[0]=112+t[0]%16;var e=function(t){return V(t).substr(0,22)}(t);return H.test(e)?e:W}catch(t){return W}}var J,G,z="firebase-installations-database",Z=1,Q="firebase-installations-store",X=null;function Y(){return X=X||function(t,e,n){var r=g(indexedDB,"open",[t,e]),i=r.request;return i&&(i.onupgradeneeded=function(t){n&&n(new S(i.result,t.oldVersion,i.transaction))}),r.then(function(t){return new T(t)})}(z,Z,function(t){switch(t.oldVersion){case 0:t.createObjectStore(Q)}})}function tt(i,o){return u(this,void 0,void 0,function(){var e,n,r;return f(this,function(t){switch(t.label){case 0:return e=rt(i),[4,Y()];case 1:return n=t.sent(),[4,(r=n.transaction(Q,"readwrite")).objectStore(Q).put(o,e)];case 2:return t.sent(),[4,r.complete];case 3:return t.sent(),[2,o]}})})}function et(i){return u(this,void 0,void 0,function(){var e,n,r;return f(this,function(t){switch(t.label){case 0:return e=rt(i),[4,Y()];case 1:return n=t.sent(),[4,(r=n.transaction(Q,"readwrite")).objectStore(Q).delete(e)];case 2:return t.sent(),[4,r.complete];case 3:return t.sent(),[2]}})})}function nt(s,c){return u(this,void 0,void 0,function(){var e,n,r,i,o,a;return f(this,function(t){switch(t.label){case 0:return e=rt(s),[4,Y()];case 1:return n=t.sent(),r=n.transaction(Q,"readwrite"),[4,(i=r.objectStore(Q)).get(e)];case 2:return o=t.sent(),(a=c(o))===o?[2,a]:void 0!==a?[3,4]:[4,i.delete(e)];case 3:return t.sent(),[3,6];case 4:return[4,i.put(a,e)];case 5:t.sent(),t.label=6;case 6:return[4,r.complete];case 7:return t.sent(),[2,a]}})})}function rt(t){return t.appName+"!"+t.appId}function it(i){return u(this,void 0,void 0,function(){var r,e,n;return f(this,function(t){switch(t.label){case 0:return[4,nt(i,function(t){var e=function(t){var e=t||{fid:$(),registrationStatus:0};if(at(e))return{fid:e.fid,registrationStatus:0};return e}(t),n=function(t,e){{if(0!==e.registrationStatus)return 1===e.registrationStatus?{installationEntry:e,registrationPromise:function(n){return u(this,void 0,void 0,function(){var e;return f(this,function(t){switch(t.label){case 0:return[4,ot(n)];case 1:e=t.sent(),t.label=2;case 2:return 1!==e.registrationStatus?[3,5]:[4,K(100)];case 3:return t.sent(),[4,ot(n)];case 4:return e=t.sent(),[3,2];case 5:if(0===e.registrationStatus)throw M.create("create-installation-failed");return[2,e]}})})}(t)}:{installationEntry:e};if(!navigator.onLine){var n=Promise.reject(M.create("app-offline"));return{installationEntry:e,registrationPromise:n}}var r={fid:e.fid,registrationStatus:1,registrationTime:Date.now()},i=function(r,i){return u(this,void 0,void 0,function(){var e,n;return f(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,7]),[4,function(s,t){var c=t.fid;return u(this,void 0,void 0,function(){var e,n,r,i,o,a;return f(this,function(t){switch(t.label){case 0:return e=C(s),n=U(s),r={fid:c,authVersion:O,appId:s.appId,sdkVersion:N},i={method:"POST",headers:n,body:JSON.stringify(r)},[4,F(function(){return fetch(e,i)})];case 1:return(o=t.sent()).ok?[4,o.json()]:[3,3];case 2:return a=t.sent(),[2,{fid:a.fid||c,registrationStatus:2,refreshToken:a.refreshToken,authToken:q(a.authToken)}];case 3:return[4,x("Create Installation",o)];case 4:throw t.sent()}})})}(r,i)];case 1:return e=t.sent(),[2,tt(r,e)];case 2:return D(n=t.sent())&&409===n.serverCode?[4,et(r)]:[3,4];case 3:return t.sent(),[3,6];case 4:return[4,tt(r,{fid:i.fid,registrationStatus:0})];case 5:t.sent(),t.label=6;case 6:throw n;case 7:return[2]}})})}(t,r);return{installationEntry:r,registrationPromise:i}}}(i,e);return r=n.registrationPromise,n.installationEntry})];case 1:return(e=t.sent()).fid!==W?[3,3]:(n={},[4,r]);case 2:return[2,(n.installationEntry=t.sent(),n)];case 3:return[2,{installationEntry:e,registrationPromise:r}]}})})}function ot(t){return nt(t,function(t){if(!t)throw M.create("installation-not-found");return at(t)?{fid:t.fid,registrationStatus:0}:t})}function at(t){return 1===t.registrationStatus&&t.registrationTime+A<Date.now()}function st(s,c){return u(this,void 0,void 0,function(){var e,n,r,i,o,a;return f(this,function(t){switch(t.label){case 0:return e=function(t,e){var n=e.fid;return C(t)+"/"+n+"/authTokens:generate"}(s,c),n=L(s,c),r={installation:{sdkVersion:N}},i={method:"POST",headers:n,body:JSON.stringify(r)},[4,F(function(){return fetch(e,i)})];case 1:return(o=t.sent()).ok?[4,o.json()]:[3,3];case 2:return a=t.sent(),[2,q(a)];case 3:return[4,x("Generate Auth Token",o)];case 4:throw t.sent()}})})}function ct(i){return u(this,void 0,void 0,function(){var r,e,n;return f(this,function(t){switch(t.label){case 0:return[4,nt(i,function(t){if(!ft(t))throw M.create("not-registered");var e=t.authToken;if(function(t){return 2===t.requestStatus&&!function(t){var e=Date.now();return e<t.creationTime||t.creationTime+t.expiresIn<e+R}(t)}(e))return t;if(1===e.requestStatus)return r=function(r){return u(this,void 0,void 0,function(){var e,n;return f(this,function(t){switch(t.label){case 0:return[4,ut(r)];case 1:e=t.sent(),t.label=2;case 2:return 1!==e.authToken.requestStatus?[3,5]:[4,K(100)];case 3:return t.sent(),[4,ut(r)];case 4:return e=t.sent(),[3,2];case 5:if(0===(n=e.authToken).requestStatus)throw M.create("generate-token-failed");return[2,n]}})})}(i),t;if(!navigator.onLine)throw M.create("app-offline");var n=function(t){var e={requestStatus:1,requestTime:Date.now()};return a({},t,{authToken:e})}(t);return r=function(i,o){return u(this,void 0,void 0,function(){var e,n,r;return f(this,function(t){switch(t.label){case 0:return t.trys.push([0,3,,8]),[4,st(i,o)];case 1:return e=t.sent(),r=a({},o,{authToken:e}),[4,tt(i,r)];case 2:return t.sent(),[2,e];case 3:return!D(n=t.sent())||401!==n.serverCode&&404!==n.serverCode?[3,5]:[4,et(i)];case 4:return t.sent(),[3,7];case 5:return r=a({},o,{authToken:{requestStatus:0}}),[4,tt(i,r)];case 6:t.sent(),t.label=7;case 7:throw n;case 8:return[2]}})})}(i,n),n})];case 1:return e=t.sent(),r?[4,r]:[3,3];case 2:return n=t.sent(),[3,4];case 3:n=e.authToken,t.label=4;case 4:return[2,n.token]}})})}function ut(t){return nt(t,function(t){if(!ft(t))throw M.create("not-registered");return function(t){return 1===t.requestStatus&&t.requestTime+A<Date.now()}(t.authToken)?a({},t,{authToken:{requestStatus:0}}):t})}function ft(t){return void 0!==t&&2===t.registrationStatus}function lt(n){return u(this,void 0,void 0,function(){var e;return f(this,function(t){switch(t.label){case 0:return[4,function(i){return u(this,void 0,void 0,function(){var e,n,r;return f(this,function(t){switch(t.label){case 0:return[4,it(i)];case 1:return e=t.sent(),n=e.installationEntry,(r=e.registrationPromise)?[4,r]:[3,3];case 2:return t.sent(),[3,4];case 3:if(2!==n.registrationStatus)throw M.create("create-installation-failed");t.label=4;case 4:return[2]}})})}(e=B(n))];case 1:return t.sent(),[2,ct(e)]}})})}function pt(o,a){return u(this,void 0,void 0,function(){var e,n,r,i;return f(this,function(t){switch(t.label){case 0:return e=function(t,e){var n=e.fid;return C(t)+"/"+n}(o,a),n=L(o,a),r={method:"DELETE",headers:n},[4,F(function(){return fetch(e,r)})];case 1:return(i=t.sent()).ok?[3,3]:[4,x("Delete Installation",i)];case 2:throw t.sent();case 3:return[2]}})})}be.INTERNAL.registerService("installations",function(t){return B(t),{app:t,getId:function(){return function(o){return u(this,void 0,void 0,function(){var e,n,r,i;return f(this,function(t){switch(t.label){case 0:return[4,it(e=B(o))];case 1:return n=t.sent(),r=n.installationEntry,(i=n.registrationPromise)&&i.catch(function(){}),2===r.registrationStatus&&ct(e).catch(function(){}),[2,r.fid]}})})}(t)},getToken:function(){return lt(t)},delete:function(){return function(r){return u(this,void 0,void 0,function(){var e,n;return f(this,function(t){switch(t.label){case 0:return[4,nt(e=B(r),function(t){if(!t||0!==t.registrationStatus)return t})];case 1:if(!(n=t.sent()))return[3,6];if(1!==n.registrationStatus)return[3,2];throw M.create("delete-pending-registration");case 2:if(2!==n.registrationStatus)return[3,6];if(navigator.onLine)return[3,3];throw M.create("app-offline");case 3:return[4,pt(e,n)];case 4:return t.sent(),[4,et(e)];case 5:t.sent(),t.label=6;case 6:return[2]}})})}(t)}}}),(G=J=J||{})[G.DEBUG=0]="DEBUG",G[G.VERBOSE=1]="VERBOSE",G[G.INFO=2]="INFO",G[G.WARN=3]="WARN",G[G.ERROR=4]="ERROR",G[G.SILENT=5]="SILENT";function ht(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];if(!(e<t.logLevel)){var i=(new Date).toISOString();switch(e){case J.DEBUG:case J.VERBOSE:console.log.apply(console,["["+i+"] "+t.name+":"].concat(n));break;case J.INFO:console.info.apply(console,["["+i+"] "+t.name+":"].concat(n));break;case J.WARN:console.warn.apply(console,["["+i+"] "+t.name+":"].concat(n));break;case J.ERROR:console.error.apply(console,["["+i+"] "+t.name+":"].concat(n));break;default:throw new Error("Attempted to log a message with an invalid logType (value: "+e+")")}}}var dt=J.INFO,gt=(Object.defineProperty(vt.prototype,"logLevel",{get:function(){return this._logLevel},set:function(t){if(!(t in J))throw new TypeError("Invalid value assigned to `logLevel`");this._logLevel=t},enumerable:!0,configurable:!0}),Object.defineProperty(vt.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}),vt.prototype.debug=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._logHandler.apply(this,[this,J.DEBUG].concat(t))},vt.prototype.log=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._logHandler.apply(this,[this,J.VERBOSE].concat(t))},vt.prototype.info=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._logHandler.apply(this,[this,J.INFO].concat(t))},vt.prototype.warn=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._logHandler.apply(this,[this,J.WARN].concat(t))},vt.prototype.error=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._logHandler.apply(this,[this,J.ERROR].concat(t))},vt);function vt(t){this.name=t,this._logLevel=dt,this._logHandler=ht}var mt,bt,yt,_t,wt="0.2.18",It="FB-PERF-TRACE-MEASURE",Et="@firebase/performance/config",St="@firebase/performance/configexpire",Tt="Performance",kt=((mt={})["trace started"]="Trace {$traceName} was started before.",mt["trace stopped"]="Trace {$traceName} is not running.",mt["no window"]="Window is not available.",mt["no app id"]="App id is not available.",mt["no project id"]="Project id is not available.",mt["no api key"]="Api key is not available.",mt["invalid cc log"]="Attempted to queue invalid cc event",mt["FB not default"]="Performance can only start when Firebase app instance is the default one.",mt["RC response not ok"]="RC response is not ok",mt["invalid attribute name"]="Attribute name {$attributeName} is invalid.",mt["invalid attribute value"]="Attribute value {$attributeValue} is invalid.",mt["invalide custom metric name"]="Custom metric name {$customMetricName} is invalid",mt),At=new c("performance",Tt,kt),Nt=(Ot.prototype.getUrl=function(){return this.windowLocation.href.split("?")[0]},Ot.prototype.mark=function(t){this.performance&&this.performance.mark&&this.performance.mark(t)},Ot.prototype.measure=function(t,e,n){this.performance&&this.performance.measure&&this.performance.measure(t,e,n)},Ot.prototype.getEntriesByType=function(t){return this.performance&&this.performance.getEntriesByType?this.performance.getEntriesByType(t):[]},Ot.prototype.getEntriesByName=function(t){return this.performance&&this.performance.getEntriesByName?this.performance.getEntriesByName(t):[]},Ot.prototype.getTimeOrigin=function(){return this.performance&&(this.performance.timeOrigin||this.performance.timing.navigationStart)},Ot.prototype.requiredApisAvailable=function(){return!!(fetch&&Promise&&this.navigator&&this.navigator.cookieEnabled)},Ot.prototype.setupObserver=function(t,i){this.PerformanceObserver&&new this.PerformanceObserver(function(t){for(var e=0,n=t.getEntries();e<n.length;e++){var r=n[e];i(r)}}).observe({entryTypes:[t]})},Ot.getInstance=function(){return void 0===bt&&(bt=new Ot(yt)),bt},Ot);function Ot(t){if(!t)throw At.create("no window");this.performance=t.performance,this.PerformanceObserver=t.PerformanceObserver,this.windowLocation=t.location,this.navigator=t.navigator,this.document=t.document,this.navigator&&this.navigator.cookieEnabled&&(this.localStorage=t.localStorage),t.perfMetrics&&t.perfMetrics.onFirstInputDelay&&(this.onFirstInputDelay=t.perfMetrics.onFirstInputDelay)}var Pt,Rt,jt,Mt=(Dt.prototype.getAppId=function(){var t=this.firebaseAppInstance&&this.firebaseAppInstance.options&&this.firebaseAppInstance.options.appId;if(!t)throw At.create("no app id");return t},Dt.prototype.getProjectId=function(){var t=this.firebaseAppInstance&&this.firebaseAppInstance.options&&this.firebaseAppInstance.options.projectId;if(!t)throw At.create("no project id");return t},Dt.prototype.getApiKey=function(){var t=this.firebaseAppInstance&&this.firebaseAppInstance.options&&this.firebaseAppInstance.options.apiKey;if(!t)throw At.create("no api key");return t},Dt.getInstance=function(){return void 0===_t&&(_t=new Dt),_t},Dt);function Dt(){this.instrumentationEnabled=!0,this.dataCollectionEnabled=!0,this.loggingEnabled=!1,this.tracesSamplingRate=1,this.networkRequestsSamplingRate=1,this.logEndPointUrl="https://firebaselogging.googleapis.com/v0cc/log?format=json_proto",this.logSource=462,this.logTraceAfterSampling=!1,this.logNetworkAfterSampling=!1,this.configTimeToLive=12}function Bt(){return Pt}(jt=Rt=Rt||{})[jt.UNKNOWN=0]="UNKNOWN",jt[jt.VISIBLE=1]="VISIBLE",jt[jt.HIDDEN=2]="HIDDEN",jt[jt.PRERENDER=3]="PRERENDER",jt[jt.UNLOADED=4]="UNLOADED";var Ct=["firebase_","google_","ga_"],qt=new RegExp("^[a-zA-Z]\\w*$");function xt(){switch(Nt.getInstance().document.visibilityState){case"visible":return Rt.VISIBLE;case"hidden":return Rt.HIDDEN;case"prerender":return Rt.PRERENDER;default:return Rt.UNKNOWN}}var Ut=new gt(Tt);Ut.logLevel=J.INFO;var Lt="0.0.1",Ft={loggingEnabled:!0},Kt="FIREBASE_INSTALLATIONS_AUTH";function Vt(t){var e=function(){var t=Nt.getInstance().localStorage,e=t.getItem(St);if(!e||!function(t){return Number(t)>Date.now()}(e))return;var n=t.getItem(Et);if(!n)return;try{return JSON.parse(n)}catch(t){return}}();return e?(Wt(e),Promise.resolve()):function(r){return function(){var t=Mt.getInstance().firebaseAppInstance.installations().getToken();return t.then(function(t){}),t}().then(function(t){var e="https://firebaseremoteconfig.googleapis.com/v1/projects/"+Mt.getInstance().getProjectId()+"/namespaces/fireperf:fetch?key="+Mt.getInstance().getApiKey(),n=new Request(e,{method:"POST",headers:{Authorization:Kt+" "+t},body:JSON.stringify({app_instance_id:r,app_instance_id_token:t,app_id:Mt.getInstance().getAppId(),app_version:wt,sdk_version:Lt})});return fetch(n).then(function(t){if(t.ok)return t.json();throw At.create("RC response not ok")})}).catch(function(){Ut.info(Ht)})}(t).then(function(t){return Wt(t)}).then(function(t){return function(t){if(!t)return;var e=Nt.getInstance().localStorage;e.setItem(Et,JSON.stringify(t)),e.setItem(St,String(Date.now()+60*Mt.getInstance().configTimeToLive*60*1e3))}(t)},function(){})}var Ht="Could not fetch config, will use default configs";function Wt(t){if(!t)return t;var e=Mt.getInstance(),n=t.entries||{};return void 0!==n.fpr_enabled?e.loggingEnabled="true"===String(n.fpr_enabled):e.loggingEnabled=Ft.loggingEnabled,n.fpr_log_source&&(e.logSource=Number(n.fpr_log_source)),n.fpr_log_endpoint_url&&(e.logEndPointUrl=n.fpr_log_endpoint_url),void 0!==n.fpr_vc_network_request_sampling_rate&&(e.networkRequestsSamplingRate=Number(n.fpr_vc_network_request_sampling_rate)),void 0!==n.fpr_vc_trace_sampling_rate&&(e.tracesSamplingRate=Number(n.fpr_vc_trace_sampling_rate)),e.logTraceAfterSampling=$t(e.tracesSamplingRate),e.logNetworkAfterSampling=$t(e.networkRequestsSamplingRate),t}function $t(t){return Math.random()<=t}var Jt,Gt=1;function zt(){return Gt=2,Jt=Jt||function(){var n=Nt.getInstance().document;return new Promise(function(t){if(n&&"complete"!==n.readyState){var e=function(){"complete"===n.readyState&&(n.removeEventListener("readystatechange",e),t())};n.addEventListener("readystatechange",e)}else t()})}().then(function(){return function(){var t=Mt.getInstance().firebaseAppInstance.installations().getId();return t.then(function(t){Pt=t}),t}()}).then(function(t){return Vt(t)}).then(function(){return Zt()},function(){return Zt()})}function Zt(){Gt=3}var Qt,Xt=1e4,Yt=3,te=Yt,ee=[];function ne(i){return function(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];!function(t){if(!t.eventTime||!t.message)throw At.create("invalid cc log");ee=ee.concat([t])}({message:i.apply(void 0,n),eventTime:Date.now()})}}function re(){if(Qt)return Qt;var t=ne(ae);return(Qt=new gt("@firebase/performance/cc")).logHandler=t,Qt}function ie(t){var e=Mt.getInstance();!e.instrumentationEnabled&&t.isAuto||(e.dataCollectionEnabled||t.isAuto)&&Nt.getInstance().requiredApisAvailable()&&(t.isAuto&&xt()!==Rt.VISIBLE||e.loggingEnabled&&e.logTraceAfterSampling&&(3===Gt?oe(t):zt().then(function(){return oe(t)},function(){return oe(t)})))}function oe(t){Bt()&&setTimeout(function(){return re().log(t,1)},0)}function ae(t,e){return 0===e?function(t){var e={url:t.url,http_method:t.httpMethod||0,http_response_code:200,response_payload_bytes:t.responsePayloadBytes,client_start_time_us:t.startTimeUs,time_to_response_initiated_us:t.timeToResponseInitiatedUs,time_to_response_completed_us:t.timeToResponseCompletedUs},n={application_info:se(),network_request_metric:e};return JSON.stringify(n)}(t):function(t){var e={name:t.name,is_auto:t.isAuto,client_start_time_us:t.startTimeUs,duration_us:t.durationUs};0!==Object.keys(t.counters).length&&(e.counters=ce(t.counters));var n=t.getAttributes();0!==Object.keys(n).length&&(e.custom_attributes=ce(n));var r={application_info:se(),trace_metric:e};return JSON.stringify(r)}(t)}function se(){return{google_app_id:Mt.getInstance().getAppId(),app_instance_id:Bt(),web_app_info:{sdk_version:wt,page_url:Nt.getInstance().getUrl(),service_worker_status:function(){var t=Nt.getInstance().navigator;return"serviceWorker"in t?t.serviceWorker.controller?2:3:1}(),visibility_state:xt(),effective_connection_type:function(){var t=Nt.getInstance().navigator.connection;switch(t&&t.effectiveType){case"slow-2g":return 1;case"2g":return 2;case"3g":return 3;case"4g":return 4;default:return 0}}()},application_process_state:0}}function ce(e){return Object.keys(e).map(function(t){return{key:t,value:e[t]}})}!function r(t){setTimeout(function(){if(0!==te){if(!ee.length)return r(Xt);var t=ee.slice();ee=[];var e=t.map(function(t){return{source_extension_json:t.message,event_time_ms:String(t.eventTime)}}),n={request_time_ms:String(Date.now()),client_info:{client_type:1,js_client_info:{}},log_source:Mt.getInstance().logSource,log_event:e};fetch(Mt.getInstance().logEndPointUrl,{method:"POST",body:JSON.stringify(n)}).then(function(t){return t.ok||Ut.info("Call to Firebase backend failed."),t.json()}).then(function(t){var e=Number(t.next_request_wait_millis),n=isNaN(e)?Xt:Math.max(Xt,e);te=Yt,r(n)}).catch(function(){ee=t.concat(ee),te--,Ut.info("Tries left: "+te+"."),r(Xt)})}},t)}(5500);var ue=["_fp","_fcp","_fid"];var fe=(le.prototype.start=function(){if(1!==this.state)throw At.create("trace started",{traceName:this.name});this.api.mark(this.traceStartMark),this.state=2},le.prototype.stop=function(){if(2!==this.state)throw At.create("trace stopped",{traceName:this.name});this.state=3,this.api.mark(this.traceStopMark),this.api.measure(this.traceMeasure,this.traceStartMark,this.traceStopMark),this.calculateTraceMetrics(),ie(this)},le.prototype.record=function(t,e,n){if(this.durationUs=Math.floor(1e3*e),this.startTimeUs=Math.floor(1e3*t),n&&n.attributes&&(this.customAttributes=a({},n.attributes)),n&&n.metrics)for(var r=0,i=Object.keys(n.metrics);r<i.length;r++){var o=i[r];isNaN(Number(n.metrics[o]))||(this.counters[o]=Number(Math.floor(n.metrics[o])))}ie(this)},le.prototype.incrementMetric=function(t,e){void 0===e&&(e=1),void 0===this.counters[t]&&this.putMetric(t,0),this.counters[t]+=e},le.prototype.putMetric=function(t,e){if(!function(t,e){return!(0===t.length||100<t.length)&&(e&&e.startsWith("_wt_")&&-1<ue.indexOf(t)||!t.startsWith("_"))}(t,this.name))throw At.create("invalide custom metric name",{customMetricName:t});this.counters[t]=e},le.prototype.getMetric=function(t){return this.counters[t]||0},le.prototype.putAttribute=function(t,e){var n=function(e){return!(0===e.length||40<e.length||Ct.some(function(t){return e.startsWith(t)})||!e.match(qt))}(t),r=function(t){return 0!==t.length&&t.length<=100}(e);if(n&&r)this.customAttributes[t]=e;else{if(!n)throw At.create("invalid attribute name",{attributeName:t});if(!r)throw At.create("invalid attribute value",{attributeValue:e})}},le.prototype.getAttribute=function(t){return this.customAttributes[t]},le.prototype.removeAttribute=function(t){void 0!==this.customAttributes[t]&&delete this.customAttributes[t]},le.prototype.getAttributes=function(){return a({},this.customAttributes)},le.prototype.setStartTime=function(t){this.startTimeUs=t},le.prototype.setDuration=function(t){this.durationUs=t},le.prototype.calculateTraceMetrics=function(){var t=this.api.getEntriesByName(this.traceMeasure),e=t&&t[0];e&&(this.durationUs=Math.floor(1e3*e.duration),this.startTimeUs=Math.floor(1e3*(e.startTime+this.api.getTimeOrigin())))},le.createOobTrace=function(t,e,n){var r=Nt.getInstance().getUrl();if(r){var i=new le("_wt_"+r,!0),o=Math.floor(1e3*Nt.getInstance().getTimeOrigin());if(i.setStartTime(o),t&&t[0]&&(i.setDuration(Math.floor(1e3*t[0].duration)),i.putMetric("domInteractive",Math.floor(1e3*t[0].domInteractive)),i.putMetric("domContentLoadedEventEnd",Math.floor(1e3*t[0].domContentLoadedEventEnd)),i.putMetric("loadEventEnd",Math.floor(1e3*t[0].loadEventEnd))),e){var a=e.find(function(t){return"first-paint"===t.name});a&&a.startTime&&i.putMetric("_fp",Math.floor(1e3*a.startTime));var s=e.find(function(t){return"first-contentful-paint"===t.name});s&&s.startTime&&i.putMetric("_fcp",Math.floor(1e3*s.startTime)),n&&i.putMetric("_fid",Math.floor(1e3*n))}ie(i)}},le.createUserTimingTrace=function(t){ie(new le(t,!1,t))},le);function le(t,e,n){void 0===e&&(e=!1),this.name=t,this.isAuto=e,this.state=1,this.customAttributes={},this.counters={},this.api=Nt.getInstance(),this.randomId=Math.floor(1e6*Math.random()),this.isAuto||(this.traceStartMark="FB-PERF-TRACE-START-"+this.randomId+"-"+this.name,this.traceStopMark="FB-PERF-TRACE-STOP-"+this.randomId+"-"+this.name,this.traceMeasure=n||It+"-"+this.randomId+"-"+this.name,n&&this.calculateTraceMetrics())}function pe(t){var e=t;if(e&&void 0!==e.responseStart){var n=Nt.getInstance().getTimeOrigin(),r=Math.floor(1e3*(e.startTime+n)),i=e.responseStart?Math.floor(1e3*(e.responseStart-e.startTime)):void 0,o=Math.floor(1e3*(e.responseEnd-e.startTime));!function(t){var e=Mt.getInstance();e.instrumentationEnabled&&t.url!==e.logEndPointUrl.split("?")[0]&&e.loggingEnabled&&e.logNetworkAfterSampling&&setTimeout(function(){return re().log(t,0)},0)}({url:e.name&&e.name.split("?")[0],responsePayloadBytes:e.transferSize,startTimeUs:r,timeToResponseInitiatedUs:i,timeToResponseCompletedUs:o})}}var he=5e3;function de(){Bt()&&(setTimeout(function(){return function(){var t=Nt.getInstance(),e=t.getEntriesByType("navigation"),n=t.getEntriesByType("paint");if(t.onFirstInputDelay){var r=setTimeout(function(){fe.createOobTrace(e,n),r=void 0},he);t.onFirstInputDelay(function(t){r&&(clearTimeout(r),fe.createOobTrace(e,n,t))})}else fe.createOobTrace(e,n)}()},0),setTimeout(function(){return function(){for(var t=Nt.getInstance(),e=t.getEntriesByType("resource"),n=0,r=e;n<r.length;n++){pe(r[n])}t.setupObserver("resource",pe)}()},0),setTimeout(function(){return function(){for(var t=Nt.getInstance(),e=t.getEntriesByType("measure"),n=0,r=e;n<r.length;n++){ge(r[n])}t.setupObserver("measure",ge)}()},0))}function ge(t){var e=t.name;e.substring(0,It.length)!==It&&fe.createUserTimingTrace(e)}var ve=(me.prototype.trace=function(t){return new fe(t)},Object.defineProperty(me.prototype,"instrumentationEnabled",{get:function(){return Mt.getInstance().instrumentationEnabled},set:function(t){Mt.getInstance().instrumentationEnabled=t},enumerable:!0,configurable:!0}),Object.defineProperty(me.prototype,"dataCollectionEnabled",{get:function(){return Mt.getInstance().dataCollectionEnabled},set:function(t){Mt.getInstance().dataCollectionEnabled=t},enumerable:!0,configurable:!0}),me);function me(t){this.app=t,Nt.getInstance().requiredApisAvailable()?zt().then(de,de):Ut.info("Firebase Performance cannot start if browser does not support fetch and Promise or cookie is disabled.")}be.INTERNAL.registerService("performance",function(t){if("[DEFAULT]"!==t.name)throw At.create("FB not default");if("undefined"==typeof window)throw At.create("no window");return function(t){yt=t}(window),Mt.getInstance().firebaseAppInstance=t,new ve(t)},{})}).apply(this,arguments)}catch(t){throw console.error(t),new Error("Cannot instantiate firebase-performance - be sure to load firebase-app.js first.")}});
//# sourceMappingURL=firebase-performance.js.map