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