UNPKG

smr-performance-monitor

Version:

smr-performance-monitor

2 lines (1 loc) 47.2 kB
class e{constructor(e,t,n){this.name=e,this.version=t,this.os=n}}class t{constructor(e){this.version=e,this.name="node",this.os=process.platform}}class n{constructor(){this.bot=!0,this.name="bot",this.version=null,this.os=null}}const r=3,o=[["aol",/AOLShield\/([0-9\._]+)/],["edge",/Edge\/([0-9\._]+)/],["yandexbrowser",/YaBrowser\/([0-9\._]+)/],["vivaldi",/Vivaldi\/([0-9\.]+)/],["kakaotalk",/KAKAOTALK\s([0-9\.]+)/],["samsung",/SamsungBrowser\/([0-9\.]+)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["phantomjs",/PhantomJS\/([0-9\.]+)(:?\s|$)/],["crios",/CriOS\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["fxios",/FxiOS\/([0-9\.]+)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)$/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/Version\/([0-9\._]+).*Mobile.*Safari.*/],["safari",/Version\/([0-9\._]+).*Safari/],["facebook",/FBAV\/([0-9\.]+)/],["instagram",/Instagram\s([0-9\.]+)/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Mobile/],["searchbot",/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/]],s=[["iOS",/iP(hone|od|ad)/],["Android OS",/Android/],["BlackBerry OS",/BlackBerry|BB10/],["Windows Mobile",/IEMobile/],["Amazon OS",/Kindle/],["Windows 3.11",/Win16/],["Windows 95",/(Windows 95)|(Win95)|(Windows_95)/],["Windows 98",/(Windows 98)|(Win98)/],["Windows 2000",/(Windows NT 5.0)|(Windows 2000)/],["Windows XP",/(Windows NT 5.1)|(Windows XP)/],["Windows Server 2003",/(Windows NT 5.2)/],["Windows Vista",/(Windows NT 6.0)/],["Windows 7",/(Windows NT 6.1)/],["Windows 8",/(Windows NT 6.2)/],["Windows 8.1",/(Windows NT 6.3)/],["Windows 10",/(Windows NT 10.0)/],["Windows ME",/Windows ME/],["Open BSD",/OpenBSD/],["Sun OS",/SunOS/],["Linux",/(Linux)|(X11)/],["Mac OS",/(Mac_PowerPC)|(Macintosh)/],["QNX",/QNX/],["BeOS",/BeOS/],["OS/2",/OS\/2/],["Search Bot",/(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves\/Teoma)|(ia_archiver)/]];function i(){return"undefined"!=typeof navigator?function(t){const i=""!==t&&o.reduce(((e,[n,r])=>{if(e)return e;const o=r.exec(t);return!!o&&[n,o]}),!1);if(!i)return null;const[a,c]=i;if("searchbot"===a)return new n;let u=c[1]&&c[1].split(/[._]/).slice(0,3);u?u.length<r&&(u=[...u,...new Array(r-u.length).fill("0")]):u=[];return new e(a,u.join("."),function(e){const t=s.find((([t,n])=>n.test(e)));return t?t[0]:null}(t))}(navigator.userAgent):"undefined"!=typeof process&&process.version?new t(process.version.slice(1)):null}class a{constructor(){this.navigationTimingCached={},this.basePerfCount={},this.tcpLoadCount=0,this.calcBasePerfCount()}static supported(){return window.performance&&!!performance.getEntriesByType&&!!performance.now&&!!performance.mark}static supportedPerformanceObserver(){return window.chrome&&"PerformanceObserver"in window}getNavigationTiming(e=!1){if(!a.supported())return this.navigationTimingCached;const t=performance.getEntriesByType("navigation")[0];return t?e?{pageLoadTime:parseFloat((t.loadEventEnd-t.startTime).toFixed(2))}:(this.navigationTimingCached={fetchTime:parseFloat((t.responseEnd-t.fetchStart).toFixed(2)),workerTime:parseFloat((t.workerStart>0?t.responseEnd-t.workerStart:0).toFixed(2)),totalTime:parseFloat((t.responseEnd-t.requestStart).toFixed(2)),downloadTime:parseFloat((t.responseEnd-t.responseStart).toFixed(2)),timeToFirstByte:parseFloat((t.responseStart-t.requestStart).toFixed(2)),headerSize:parseFloat((t.transferSize-t.encodedBodySize||0).toFixed(2)),dnsLookupTime:parseFloat((t.domainLookupEnd-t.domainLookupStart).toFixed(2))},this.navigationTimingCached):this.navigationTimingCached}get tcpLoadCountInfo(){return this.tcpLoadCount}calcBasePerfCount(){new PerformanceObserver((e=>{e.getEntries().forEach((e=>{this.basePerfCount={dnsCount:e.domainLookupEnd-e.domainLookupStart,tcpDnsCount:e.connectEnd-e.connectStart,reqCount:e.responseEnd-e.responseStart,dParseCount:e.domComplete-e.domInteractive,resLoadCount:e.loadEventStart-e.domContentLoadedEventEnd,dclCount:e.domContentLoadedEventEnd-e.domInteractive,pldCount:e.domComplete-e.startTime,oldCount:e.loadEventEnd-e.loadEventStart},this.tcpLoadCount=e.connectEnd-e.startTime}))})).observe({entryTypes:["navigation"],buffered:!0})}get basePerfCountInfo(){return this.basePerfCount}get networkInformation(){if("connection"in window.navigator){const e=window.navigator.connection;return"object"!=typeof e?{}:{downlink:e.downlink,effectiveType:e.effectiveType,rtt:e.rtt,saveData:!!e.saveData,hardwareConcurrency:window.navigator.hardwareConcurrency}}return{}}now(){return window.performance.now()}mark(e,t){const n=`mark_${e}_${t}`;window.performance.mark(n)}checkStartMarkName(e){const t=window.performance.getEntriesByName(this.getStartMarkName(e),"mark");return!(!t||!t.length)}measure(e){const t=this.getStartMarkName(e),n=this.getEndMarkName(e);window.performance.measure(e,t,n);const r=window.performance.getEntriesByName(e);return r[r.length-1].duration}performanceObserver(e,t){return this.perfObserver=new PerformanceObserver(this.performanceObserverCb.bind(this,t)),this.perfObserver.observe({type:e,buffered:!0}),this.perfObserver}performanceObserverCb(e,t){e(t.getEntries())}getStartMarkName(e){return`mark_${e}_start`}getEndMarkName(e){return`mark_${e}_end`}}const c=e=>e.split("_").map(((e,t)=>0===t?e:e.charAt(0).toUpperCase()+e.slice(1))).join(""),u=e=>{let{data:t,switchToUnderline:n=!0,ntnArr:r=[]}=e;if("object"!=typeof t||null===t)return t;if(Array.isArray(t))return t.map((e=>u({data:e,switchToUnderline:n,ntnArr:r})));const o={};for(const e in t)if(Object.hasOwnProperty.call(t,e)){let s="";r.includes(e)?o[e]=u({data:t[e],switchToUnderline:n,ntnArr:r}):(s=n?e.replace(/[A-Z]/g,(e=>"_"+e.toLowerCase())):c(e),o[s]=u({data:t[e],switchToUnderline:n,ntnArr:r}))}return o};function l(e,t){return function(){return e.apply(t,arguments)}}const{toString:h}=Object.prototype,{getPrototypeOf:d}=Object,p=(f=Object.create(null),e=>{const t=h.call(e);return f[t]||(f[t]=t.slice(8,-1).toLowerCase())});var f;const m=e=>(e=e.toLowerCase(),t=>p(t)===e),g=e=>t=>typeof t===e,{isArray:w}=Array,b=g("undefined");const y=m("ArrayBuffer");const R=g("string"),T=g("function"),E=g("number"),C=e=>null!==e&&"object"==typeof e,S=e=>{if("object"!==p(e))return!1;const t=d(e);return!(null!==t&&t!==Object.prototype&&null!==Object.getPrototypeOf(t)||Symbol.toStringTag in e||Symbol.iterator in e)},k=m("Date"),v=m("File"),O=m("Blob"),A=m("FileList"),N=m("URLSearchParams");function _(e,t,{allOwnKeys:n=!1}={}){if(null==e)return;let r,o;if("object"!=typeof e&&(e=[e]),w(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{const o=n?Object.getOwnPropertyNames(e):Object.keys(e),s=o.length;let i;for(r=0;r<s;r++)i=o[r],t.call(null,e[i],i,e)}}function P(e,t){t=t.toLowerCase();const n=Object.keys(e);let r,o=n.length;for(;o-- >0;)if(r=n[o],t===r.toLowerCase())return r;return null}const x="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:global,j=e=>!b(e)&&e!==x;const F=(L="undefined"!=typeof Uint8Array&&d(Uint8Array),e=>L&&e instanceof L);var L;const B=m("HTMLFormElement"),I=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),U=m("RegExp"),M=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};_(n,((n,o)=>{let s;!1!==(s=t(n,o,e))&&(r[o]=s||n)})),Object.defineProperties(e,r)},D="abcdefghijklmnopqrstuvwxyz",W="0123456789",q={DIGIT:W,ALPHA:D,ALPHA_DIGIT:D+D.toUpperCase()+W};const H=m("AsyncFunction");var V={isArray:w,isArrayBuffer:y,isBuffer:function(e){return null!==e&&!b(e)&&null!==e.constructor&&!b(e.constructor)&&T(e.constructor.isBuffer)&&e.constructor.isBuffer(e)},isFormData:e=>{let t;return e&&("function"==typeof FormData&&e instanceof FormData||T(e.append)&&("formdata"===(t=p(e))||"object"===t&&T(e.toString)&&"[object FormData]"===e.toString()))},isArrayBufferView:function(e){let t;return t="undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&y(e.buffer),t},isString:R,isNumber:E,isBoolean:e=>!0===e||!1===e,isObject:C,isPlainObject:S,isUndefined:b,isDate:k,isFile:v,isBlob:O,isRegExp:U,isFunction:T,isStream:e=>C(e)&&T(e.pipe),isURLSearchParams:N,isTypedArray:F,isFileList:A,forEach:_,merge:function e(){const{caseless:t}=j(this)&&this||{},n={},r=(r,o)=>{const s=t&&P(n,o)||o;S(n[s])&&S(r)?n[s]=e(n[s],r):S(r)?n[s]=e({},r):w(r)?n[s]=r.slice():n[s]=r};for(let e=0,t=arguments.length;e<t;e++)arguments[e]&&_(arguments[e],r);return n},extend:(e,t,n,{allOwnKeys:r}={})=>(_(t,((t,r)=>{n&&T(t)?e[r]=l(t,n):e[r]=t}),{allOwnKeys:r}),e),trim:e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""),stripBOM:e=>(65279===e.charCodeAt(0)&&(e=e.slice(1)),e),inherits:(e,t,n,r)=>{e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},toFlatObject:(e,t,n,r)=>{let o,s,i;const a={};if(t=t||{},null==e)return t;do{for(o=Object.getOwnPropertyNames(e),s=o.length;s-- >0;)i=o[s],r&&!r(i,e,t)||a[i]||(t[i]=e[i],a[i]=!0);e=!1!==n&&d(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},kindOf:p,kindOfTest:m,endsWith:(e,t,n)=>{e=String(e),(void 0===n||n>e.length)&&(n=e.length),n-=t.length;const r=e.indexOf(t,n);return-1!==r&&r===n},toArray:e=>{if(!e)return null;if(w(e))return e;let t=e.length;if(!E(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},forEachEntry:(e,t)=>{const n=(e&&e[Symbol.iterator]).call(e);let r;for(;(r=n.next())&&!r.done;){const n=r.value;t.call(e,n[0],n[1])}},matchAll:(e,t)=>{let n;const r=[];for(;null!==(n=e.exec(t));)r.push(n);return r},isHTMLForm:B,hasOwnProperty:I,hasOwnProp:I,reduceDescriptors:M,freezeMethods:e=>{M(e,((t,n)=>{if(T(e)&&-1!==["arguments","caller","callee"].indexOf(n))return!1;const r=e[n];T(r)&&(t.enumerable=!1,"writable"in t?t.writable=!1:t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")}))}))},toObjectSet:(e,t)=>{const n={},r=e=>{e.forEach((e=>{n[e]=!0}))};return w(e)?r(e):r(String(e).split(t)),n},toCamelCase:e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,(function(e,t,n){return t.toUpperCase()+n})),noop:()=>{},toFiniteNumber:(e,t)=>(e=+e,Number.isFinite(e)?e:t),findKey:P,global:x,isContextDefined:j,ALPHABET:q,generateString:(e=16,t=q.ALPHA_DIGIT)=>{let n="";const{length:r}=t;for(;e--;)n+=t[Math.random()*r|0];return n},isSpecCompliantForm:function(e){return!!(e&&T(e.append)&&"FormData"===e[Symbol.toStringTag]&&e[Symbol.iterator])},toJSONObject:e=>{const t=new Array(10),n=(e,r)=>{if(C(e)){if(t.indexOf(e)>=0)return;if(!("toJSON"in e)){t[r]=e;const o=w(e)?[]:{};return _(e,((e,t)=>{const s=n(e,r+1);!b(s)&&(o[t]=s)})),t[r]=void 0,o}}return e};return n(e,0)},isAsyncFn:H,isThenable:e=>e&&(C(e)||T(e))&&T(e.then)&&T(e.catch)};function z(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=(new Error).stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o)}V.inherits(z,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:V.toJSONObject(this.config),code:this.code,status:this.response&&this.response.status?this.response.status:null}}});const K=z.prototype,$={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach((e=>{$[e]={value:e}})),Object.defineProperties(z,$),Object.defineProperty(K,"isAxiosError",{value:!0}),z.from=(e,t,n,r,o,s)=>{const i=Object.create(K);return V.toFlatObject(e,i,(function(e){return e!==Error.prototype}),(e=>"isAxiosError"!==e)),z.call(i,e.message,t,n,r,o),i.cause=e,i.name=e.name,s&&Object.assign(i,s),i};function J(e){return V.isPlainObject(e)||V.isArray(e)}function G(e){return V.endsWith(e,"[]")?e.slice(0,-2):e}function X(e,t,n){return e?e.concat(t).map((function(e,t){return e=G(e),!n&&t?"["+e+"]":e})).join(n?".":""):t}const Q=V.toFlatObject(V,{},null,(function(e){return/^is[A-Z]/.test(e)}));function Y(e,t,n){if(!V.isObject(e))throw new TypeError("target must be an object");t=t||new FormData;const r=(n=V.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,(function(e,t){return!V.isUndefined(t[e])}))).metaTokens,o=n.visitor||u,s=n.dots,i=n.indexes,a=(n.Blob||"undefined"!=typeof Blob&&Blob)&&V.isSpecCompliantForm(t);if(!V.isFunction(o))throw new TypeError("visitor must be a function");function c(e){if(null===e)return"";if(V.isDate(e))return e.toISOString();if(!a&&V.isBlob(e))throw new z("Blob is not supported. Use a Buffer instead.");return V.isArrayBuffer(e)||V.isTypedArray(e)?a&&"function"==typeof Blob?new Blob([e]):Buffer.from(e):e}function u(e,n,o){let a=e;if(e&&!o&&"object"==typeof e)if(V.endsWith(n,"{}"))n=r?n:n.slice(0,-2),e=JSON.stringify(e);else if(V.isArray(e)&&function(e){return V.isArray(e)&&!e.some(J)}(e)||(V.isFileList(e)||V.endsWith(n,"[]"))&&(a=V.toArray(e)))return n=G(n),a.forEach((function(e,r){!V.isUndefined(e)&&null!==e&&t.append(!0===i?X([n],r,s):null===i?n:n+"[]",c(e))})),!1;return!!J(e)||(t.append(X(o,n,s),c(e)),!1)}const l=[],h=Object.assign(Q,{defaultVisitor:u,convertValue:c,isVisitable:J});if(!V.isObject(e))throw new TypeError("data must be an object");return function e(n,r){if(!V.isUndefined(n)){if(-1!==l.indexOf(n))throw Error("Circular reference detected in "+r.join("."));l.push(n),V.forEach(n,(function(n,s){!0===(!(V.isUndefined(n)||null===n)&&o.call(t,n,V.isString(s)?s.trim():s,r,h))&&e(n,r?r.concat(s):[s])})),l.pop()}}(e),t}function Z(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,(function(e){return t[e]}))}function ee(e,t){this._pairs=[],e&&Y(e,this,t)}const te=ee.prototype;function ne(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function re(e,t,n){if(!t)return e;const r=n&&n.encode||ne,o=n&&n.serialize;let s;if(s=o?o(t,n):V.isURLSearchParams(t)?t.toString():new ee(t,n).toString(r),s){const t=e.indexOf("#");-1!==t&&(e=e.slice(0,t)),e+=(-1===e.indexOf("?")?"?":"&")+s}return e}te.append=function(e,t){this._pairs.push([e,t])},te.toString=function(e){const t=e?function(t){return e.call(this,t,Z)}:Z;return this._pairs.map((function(e){return t(e[0])+"="+t(e[1])}),"").join("&")};var oe=class{constructor(){this.handlers=[]}use(e,t,n){return this.handlers.push({fulfilled:e,rejected:t,synchronous:!!n&&n.synchronous,runWhen:n?n.runWhen:null}),this.handlers.length-1}eject(e){this.handlers[e]&&(this.handlers[e]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(e){V.forEach(this.handlers,(function(t){null!==t&&e(t)}))}},se={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},ie={isBrowser:!0,classes:{URLSearchParams:"undefined"!=typeof URLSearchParams?URLSearchParams:ee,FormData:"undefined"!=typeof FormData?FormData:null,Blob:"undefined"!=typeof Blob?Blob:null},protocols:["http","https","file","blob","url","data"]};const ae="undefined"!=typeof window&&"undefined"!=typeof document,ce=(ue="undefined"!=typeof navigator&&navigator.product,ae&&["ReactNative","NativeScript","NS"].indexOf(ue)<0);var ue;const le="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope&&"function"==typeof self.importScripts;var he={...Object.freeze({__proto__:null,hasBrowserEnv:ae,hasStandardBrowserWebWorkerEnv:le,hasStandardBrowserEnv:ce}),...ie};function de(e){function t(e,n,r,o){let s=e[o++];if("__proto__"===s)return!0;const i=Number.isFinite(+s),a=o>=e.length;if(s=!s&&V.isArray(r)?r.length:s,a)return V.hasOwnProp(r,s)?r[s]=[r[s],n]:r[s]=n,!i;r[s]&&V.isObject(r[s])||(r[s]=[]);return t(e,n,r[s],o)&&V.isArray(r[s])&&(r[s]=function(e){const t={},n=Object.keys(e);let r;const o=n.length;let s;for(r=0;r<o;r++)s=n[r],t[s]=e[s];return t}(r[s])),!i}if(V.isFormData(e)&&V.isFunction(e.entries)){const n={};return V.forEachEntry(e,((e,r)=>{t(function(e){return V.matchAll(/\w+|\[(\w*)]/g,e).map((e=>"[]"===e[0]?"":e[1]||e[0]))}(e),r,n,0)})),n}return null}const pe={transitional:se,adapter:["xhr","http"],transformRequest:[function(e,t){const n=t.getContentType()||"",r=n.indexOf("application/json")>-1,o=V.isObject(e);o&&V.isHTMLForm(e)&&(e=new FormData(e));if(V.isFormData(e))return r?JSON.stringify(de(e)):e;if(V.isArrayBuffer(e)||V.isBuffer(e)||V.isStream(e)||V.isFile(e)||V.isBlob(e))return e;if(V.isArrayBufferView(e))return e.buffer;if(V.isURLSearchParams(e))return t.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),e.toString();let s;if(o){if(n.indexOf("application/x-www-form-urlencoded")>-1)return function(e,t){return Y(e,new he.classes.URLSearchParams,Object.assign({visitor:function(e,t,n,r){return he.isNode&&V.isBuffer(e)?(this.append(t,e.toString("base64")),!1):r.defaultVisitor.apply(this,arguments)}},t))}(e,this.formSerializer).toString();if((s=V.isFileList(e))||n.indexOf("multipart/form-data")>-1){const t=this.env&&this.env.FormData;return Y(s?{"files[]":e}:e,t&&new t,this.formSerializer)}}return o||r?(t.setContentType("application/json",!1),function(e,t,n){if(V.isString(e))try{return(t||JSON.parse)(e),V.trim(e)}catch(e){if("SyntaxError"!==e.name)throw e}return(n||JSON.stringify)(e)}(e)):e}],transformResponse:[function(e){const t=this.transitional||pe.transitional,n=t&&t.forcedJSONParsing,r="json"===this.responseType;if(e&&V.isString(e)&&(n&&!this.responseType||r)){const n=!(t&&t.silentJSONParsing)&&r;try{return JSON.parse(e)}catch(e){if(n){if("SyntaxError"===e.name)throw z.from(e,z.ERR_BAD_RESPONSE,this,null,this.response);throw e}}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:he.classes.FormData,Blob:he.classes.Blob},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};V.forEach(["delete","get","head","post","put","patch"],(e=>{pe.headers[e]={}}));var fe=pe;const me=V.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]);const ge=Symbol("internals");function we(e){return e&&String(e).trim().toLowerCase()}function be(e){return!1===e||null==e?e:V.isArray(e)?e.map(be):String(e)}function ye(e,t,n,r,o){return V.isFunction(r)?r.call(this,t,n):(o&&(t=n),V.isString(t)?V.isString(r)?-1!==t.indexOf(r):V.isRegExp(r)?r.test(t):void 0:void 0)}class Re{constructor(e){e&&this.set(e)}set(e,t,n){const r=this;function o(e,t,n){const o=we(t);if(!o)throw new Error("header name must be a non-empty string");const s=V.findKey(r,o);(!s||void 0===r[s]||!0===n||void 0===n&&!1!==r[s])&&(r[s||t]=be(e))}const s=(e,t)=>V.forEach(e,((e,n)=>o(e,n,t)));return V.isPlainObject(e)||e instanceof this.constructor?s(e,t):V.isString(e)&&(e=e.trim())&&!/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim())?s((e=>{const t={};let n,r,o;return e&&e.split("\n").forEach((function(e){o=e.indexOf(":"),n=e.substring(0,o).trim().toLowerCase(),r=e.substring(o+1).trim(),!n||t[n]&&me[n]||("set-cookie"===n?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)})),t})(e),t):null!=e&&o(t,e,n),this}get(e,t){if(e=we(e)){const n=V.findKey(this,e);if(n){const e=this[n];if(!t)return e;if(!0===t)return function(e){const t=Object.create(null),n=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let r;for(;r=n.exec(e);)t[r[1]]=r[2];return t}(e);if(V.isFunction(t))return t.call(this,e,n);if(V.isRegExp(t))return t.exec(e);throw new TypeError("parser must be boolean|regexp|function")}}}has(e,t){if(e=we(e)){const n=V.findKey(this,e);return!(!n||void 0===this[n]||t&&!ye(0,this[n],n,t))}return!1}delete(e,t){const n=this;let r=!1;function o(e){if(e=we(e)){const o=V.findKey(n,e);!o||t&&!ye(0,n[o],o,t)||(delete n[o],r=!0)}}return V.isArray(e)?e.forEach(o):o(e),r}clear(e){const t=Object.keys(this);let n=t.length,r=!1;for(;n--;){const o=t[n];e&&!ye(0,this[o],o,e,!0)||(delete this[o],r=!0)}return r}normalize(e){const t=this,n={};return V.forEach(this,((r,o)=>{const s=V.findKey(n,o);if(s)return t[s]=be(r),void delete t[o];const i=e?function(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,((e,t,n)=>t.toUpperCase()+n))}(o):String(o).trim();i!==o&&delete t[o],t[i]=be(r),n[i]=!0})),this}concat(...e){return this.constructor.concat(this,...e)}toJSON(e){const t=Object.create(null);return V.forEach(this,((n,r)=>{null!=n&&!1!==n&&(t[r]=e&&V.isArray(n)?n.join(", "):n)})),t}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map((([e,t])=>e+": "+t)).join("\n")}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(e){return e instanceof this?e:new this(e)}static concat(e,...t){const n=new this(e);return t.forEach((e=>n.set(e))),n}static accessor(e){const t=(this[ge]=this[ge]={accessors:{}}).accessors,n=this.prototype;function r(e){const r=we(e);t[r]||(!function(e,t){const n=V.toCamelCase(" "+t);["get","set","has"].forEach((r=>{Object.defineProperty(e,r+n,{value:function(e,n,o){return this[r].call(this,t,e,n,o)},configurable:!0})}))}(n,e),t[r]=!0)}return V.isArray(e)?e.forEach(r):r(e),this}}Re.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),V.reduceDescriptors(Re.prototype,(({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(e){this[n]=e}}})),V.freezeMethods(Re);var Te=Re;function Ee(e,t){const n=this||fe,r=t||n,o=Te.from(r.headers);let s=r.data;return V.forEach(e,(function(e){s=e.call(n,s,o.normalize(),t?t.status:void 0)})),o.normalize(),s}function Ce(e){return!(!e||!e.__CANCEL__)}function Se(e,t,n){z.call(this,null==e?"canceled":e,z.ERR_CANCELED,t,n),this.name="CanceledError"}V.inherits(Se,z,{__CANCEL__:!0});var ke=he.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];V.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),V.isString(r)&&i.push("path="+r),V.isString(o)&&i.push("domain="+o),!0===s&&i.push("secure"),document.cookie=i.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read:()=>null,remove(){}};function ve(e,t){return e&&!/^([a-z][a-z\d+\-.]*:)?\/\//i.test(t)?function(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}(e,t):t}var Oe=he.hasStandardBrowserEnv?function(){const e=/(msie|trident)/i.test(navigator.userAgent),t=document.createElement("a");let n;function r(n){let r=n;return e&&(t.setAttribute("href",r),r=t.href),t.setAttribute("href",r),{href:t.href,protocol:t.protocol?t.protocol.replace(/:$/,""):"",host:t.host,search:t.search?t.search.replace(/^\?/,""):"",hash:t.hash?t.hash.replace(/^#/,""):"",hostname:t.hostname,port:t.port,pathname:"/"===t.pathname.charAt(0)?t.pathname:"/"+t.pathname}}return n=r(window.location.href),function(e){const t=V.isString(e)?r(e):e;return t.protocol===n.protocol&&t.host===n.host}}():function(){return!0};function Ae(e,t){let n=0;const r=function(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o,s=0,i=0;return t=void 0!==t?t:1e3,function(a){const c=Date.now(),u=r[i];o||(o=c),n[s]=a,r[s]=c;let l=i,h=0;for(;l!==s;)h+=n[l++],l%=e;if(s=(s+1)%e,s===i&&(i=(i+1)%e),c-o<t)return;const d=u&&c-u;return d?Math.round(1e3*h/d):void 0}}(50,250);return o=>{const s=o.loaded,i=o.lengthComputable?o.total:void 0,a=s-n,c=r(a);n=s;const u={loaded:s,total:i,progress:i?s/i:void 0,bytes:a,rate:c||void 0,estimated:c&&i&&s<=i?(i-s)/c:void 0,event:o};u[t?"download":"upload"]=!0,e(u)}}const Ne={http:null,xhr:"undefined"!=typeof XMLHttpRequest&&function(e){return new Promise((function(t,n){let r=e.data;const o=Te.from(e.headers).normalize();let s,i,{responseType:a,withXSRFToken:c}=e;function u(){e.cancelToken&&e.cancelToken.unsubscribe(s),e.signal&&e.signal.removeEventListener("abort",s)}if(V.isFormData(r))if(he.hasStandardBrowserEnv||he.hasStandardBrowserWebWorkerEnv)o.setContentType(!1);else if(!1!==(i=o.getContentType())){const[e,...t]=i?i.split(";").map((e=>e.trim())).filter(Boolean):[];o.setContentType([e||"multipart/form-data",...t].join("; "))}let l=new XMLHttpRequest;if(e.auth){const t=e.auth.username||"",n=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";o.set("Authorization","Basic "+btoa(t+":"+n))}const h=ve(e.baseURL,e.url);function d(){if(!l)return;const r=Te.from("getAllResponseHeaders"in l&&l.getAllResponseHeaders());!function(e,t,n){const r=n.config.validateStatus;n.status&&r&&!r(n.status)?t(new z("Request failed with status code "+n.status,[z.ERR_BAD_REQUEST,z.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n)):e(n)}((function(e){t(e),u()}),(function(e){n(e),u()}),{data:a&&"text"!==a&&"json"!==a?l.response:l.responseText,status:l.status,statusText:l.statusText,headers:r,config:e,request:l}),l=null}if(l.open(e.method.toUpperCase(),re(h,e.params,e.paramsSerializer),!0),l.timeout=e.timeout,"onloadend"in l?l.onloadend=d:l.onreadystatechange=function(){l&&4===l.readyState&&(0!==l.status||l.responseURL&&0===l.responseURL.indexOf("file:"))&&setTimeout(d)},l.onabort=function(){l&&(n(new z("Request aborted",z.ECONNABORTED,e,l)),l=null)},l.onerror=function(){n(new z("Network Error",z.ERR_NETWORK,e,l)),l=null},l.ontimeout=function(){let t=e.timeout?"timeout of "+e.timeout+"ms exceeded":"timeout exceeded";const r=e.transitional||se;e.timeoutErrorMessage&&(t=e.timeoutErrorMessage),n(new z(t,r.clarifyTimeoutError?z.ETIMEDOUT:z.ECONNABORTED,e,l)),l=null},he.hasStandardBrowserEnv&&(c&&V.isFunction(c)&&(c=c(e)),c||!1!==c&&Oe(h))){const t=e.xsrfHeaderName&&e.xsrfCookieName&&ke.read(e.xsrfCookieName);t&&o.set(e.xsrfHeaderName,t)}void 0===r&&o.setContentType(null),"setRequestHeader"in l&&V.forEach(o.toJSON(),(function(e,t){l.setRequestHeader(t,e)})),V.isUndefined(e.withCredentials)||(l.withCredentials=!!e.withCredentials),a&&"json"!==a&&(l.responseType=e.responseType),"function"==typeof e.onDownloadProgress&&l.addEventListener("progress",Ae(e.onDownloadProgress,!0)),"function"==typeof e.onUploadProgress&&l.upload&&l.upload.addEventListener("progress",Ae(e.onUploadProgress)),(e.cancelToken||e.signal)&&(s=t=>{l&&(n(!t||t.type?new Se(null,e,l):t),l.abort(),l=null)},e.cancelToken&&e.cancelToken.subscribe(s),e.signal&&(e.signal.aborted?s():e.signal.addEventListener("abort",s)));const p=function(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}(h);p&&-1===he.protocols.indexOf(p)?n(new z("Unsupported protocol "+p+":",z.ERR_BAD_REQUEST,e)):l.send(r||null)}))}};V.forEach(Ne,((e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch(e){}Object.defineProperty(e,"adapterName",{value:t})}}));const _e=e=>`- ${e}`,Pe=e=>V.isFunction(e)||null===e||!1===e;var xe=e=>{e=V.isArray(e)?e:[e];const{length:t}=e;let n,r;const o={};for(let s=0;s<t;s++){let t;if(n=e[s],r=n,!Pe(n)&&(r=Ne[(t=String(n)).toLowerCase()],void 0===r))throw new z(`Unknown adapter '${t}'`);if(r)break;o[t||"#"+s]=r}if(!r){const e=Object.entries(o).map((([e,t])=>`adapter ${e} `+(!1===t?"is not supported by the environment":"is not available in the build")));throw new z("There is no suitable adapter to dispatch the request "+(t?e.length>1?"since :\n"+e.map(_e).join("\n"):" "+_e(e[0]):"as no adapter specified"),"ERR_NOT_SUPPORT")}return r};function je(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new Se(null,e)}function Fe(e){je(e),e.headers=Te.from(e.headers),e.data=Ee.call(e,e.transformRequest),-1!==["post","put","patch"].indexOf(e.method)&&e.headers.setContentType("application/x-www-form-urlencoded",!1);return xe(e.adapter||fe.adapter)(e).then((function(t){return je(e),t.data=Ee.call(e,e.transformResponse,t),t.headers=Te.from(t.headers),t}),(function(t){return Ce(t)||(je(e),t&&t.response&&(t.response.data=Ee.call(e,e.transformResponse,t.response),t.response.headers=Te.from(t.response.headers))),Promise.reject(t)}))}const Le=e=>e instanceof Te?{...e}:e;function Be(e,t){t=t||{};const n={};function r(e,t,n){return V.isPlainObject(e)&&V.isPlainObject(t)?V.merge.call({caseless:n},e,t):V.isPlainObject(t)?V.merge({},t):V.isArray(t)?t.slice():t}function o(e,t,n){return V.isUndefined(t)?V.isUndefined(e)?void 0:r(void 0,e,n):r(e,t,n)}function s(e,t){if(!V.isUndefined(t))return r(void 0,t)}function i(e,t){return V.isUndefined(t)?V.isUndefined(e)?void 0:r(void 0,e):r(void 0,t)}function a(n,o,s){return s in t?r(n,o):s in e?r(void 0,n):void 0}const c={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(e,t)=>o(Le(e),Le(t),!0)};return V.forEach(Object.keys(Object.assign({},e,t)),(function(r){const s=c[r]||o,i=s(e[r],t[r],r);V.isUndefined(i)&&s!==a||(n[r]=i)})),n}const Ie="1.6.8",Ue={};["object","boolean","number","function","string","symbol"].forEach(((e,t)=>{Ue[e]=function(n){return typeof n===e||"a"+(t<1?"n ":" ")+e}}));const Me={};Ue.transitional=function(e,t,n){function r(e,t){return"[Axios v1.6.8] Transitional option '"+e+"'"+t+(n?". "+n:"")}return(n,o,s)=>{if(!1===e)throw new z(r(o," has been removed"+(t?" in "+t:"")),z.ERR_DEPRECATED);return t&&!Me[o]&&(Me[o]=!0,console.warn(r(o," has been deprecated since v"+t+" and will be removed in the near future"))),!e||e(n,o,s)}};var De={assertOptions:function(e,t,n){if("object"!=typeof e)throw new z("options must be an object",z.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let o=r.length;for(;o-- >0;){const s=r[o],i=t[s];if(i){const t=e[s],n=void 0===t||i(t,s,e);if(!0!==n)throw new z("option "+s+" must be "+n,z.ERR_BAD_OPTION_VALUE)}else if(!0!==n)throw new z("Unknown option "+s,z.ERR_BAD_OPTION)}},validators:Ue};const We=De.validators;class qe{constructor(e){this.defaults=e,this.interceptors={request:new oe,response:new oe}}async request(e,t){try{return await this._request(e,t)}catch(e){if(e instanceof Error){let t;Error.captureStackTrace?Error.captureStackTrace(t={}):t=new Error;const n=t.stack?t.stack.replace(/^.+\n/,""):"";e.stack?n&&!String(e.stack).endsWith(n.replace(/^.+\n.+\n/,""))&&(e.stack+="\n"+n):e.stack=n}throw e}}_request(e,t){"string"==typeof e?(t=t||{}).url=e:t=e||{},t=Be(this.defaults,t);const{transitional:n,paramsSerializer:r,headers:o}=t;void 0!==n&&De.assertOptions(n,{silentJSONParsing:We.transitional(We.boolean),forcedJSONParsing:We.transitional(We.boolean),clarifyTimeoutError:We.transitional(We.boolean)},!1),null!=r&&(V.isFunction(r)?t.paramsSerializer={serialize:r}:De.assertOptions(r,{encode:We.function,serialize:We.function},!0)),t.method=(t.method||this.defaults.method||"get").toLowerCase();let s=o&&V.merge(o.common,o[t.method]);o&&V.forEach(["delete","get","head","post","put","patch","common"],(e=>{delete o[e]})),t.headers=Te.concat(s,o);const i=[];let a=!0;this.interceptors.request.forEach((function(e){"function"==typeof e.runWhen&&!1===e.runWhen(t)||(a=a&&e.synchronous,i.unshift(e.fulfilled,e.rejected))}));const c=[];let u;this.interceptors.response.forEach((function(e){c.push(e.fulfilled,e.rejected)}));let l,h=0;if(!a){const e=[Fe.bind(this),void 0];for(e.unshift.apply(e,i),e.push.apply(e,c),l=e.length,u=Promise.resolve(t);h<l;)u=u.then(e[h++],e[h++]);return u}l=i.length;let d=t;for(h=0;h<l;){const e=i[h++],t=i[h++];try{d=e(d)}catch(e){t.call(this,e);break}}try{u=Fe.call(this,d)}catch(e){return Promise.reject(e)}for(h=0,l=c.length;h<l;)u=u.then(c[h++],c[h++]);return u}getUri(e){return re(ve((e=Be(this.defaults,e)).baseURL,e.url),e.params,e.paramsSerializer)}}V.forEach(["delete","get","head","options"],(function(e){qe.prototype[e]=function(t,n){return this.request(Be(n||{},{method:e,url:t,data:(n||{}).data}))}})),V.forEach(["post","put","patch"],(function(e){function t(t){return function(n,r,o){return this.request(Be(o||{},{method:e,headers:t?{"Content-Type":"multipart/form-data"}:{},url:n,data:r}))}}qe.prototype[e]=t(),qe.prototype[e+"Form"]=t(!0)}));var He=qe;class Ve{constructor(e){if("function"!=typeof e)throw new TypeError("executor must be a function.");let t;this.promise=new Promise((function(e){t=e}));const n=this;this.promise.then((e=>{if(!n._listeners)return;let t=n._listeners.length;for(;t-- >0;)n._listeners[t](e);n._listeners=null})),this.promise.then=e=>{let t;const r=new Promise((e=>{n.subscribe(e),t=e})).then(e);return r.cancel=function(){n.unsubscribe(t)},r},e((function(e,r,o){n.reason||(n.reason=new Se(e,r,o),t(n.reason))}))}throwIfRequested(){if(this.reason)throw this.reason}subscribe(e){this.reason?e(this.reason):this._listeners?this._listeners.push(e):this._listeners=[e]}unsubscribe(e){if(!this._listeners)return;const t=this._listeners.indexOf(e);-1!==t&&this._listeners.splice(t,1)}static source(){let e;return{token:new Ve((function(t){e=t})),cancel:e}}}var ze=Ve;const Ke={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Ke).forEach((([e,t])=>{Ke[t]=e}));var $e=Ke;const Je=function e(t){const n=new He(t),r=l(He.prototype.request,n);return V.extend(r,He.prototype,n,{allOwnKeys:!0}),V.extend(r,n,null,{allOwnKeys:!0}),r.create=function(n){return e(Be(t,n))},r}(fe);Je.Axios=He,Je.CanceledError=Se,Je.CancelToken=ze,Je.isCancel=Ce,Je.VERSION=Ie,Je.toFormData=Y,Je.AxiosError=z,Je.Cancel=Je.CanceledError,Je.all=function(e){return Promise.all(e)},Je.spread=function(e){return function(t){return e.apply(null,t)}},Je.isAxiosError=function(e){return V.isObject(e)&&!0===e.isAxiosError},Je.mergeConfig=Be,Je.AxiosHeaders=Te,Je.formToJSON=e=>de(V.isHTMLForm(e)?new FormData(e):e),Je.getAdapter=xe,Je.HttpStatusCode=$e,Je.default=Je;const Ge=Je.create({});Ge.interceptors.request.use((e=>e),(e=>{console.log(e),Promise.reject(e)})),Ge.interceptors.response.use((e=>e.data),(e=>{console.error("sdk https:err"+e);let{message:t}=e;return"Network Error"==t?t="后端接口连接异常":t.includes("timeout")?t="系统接口请求超时":t.includes("Request failed with status code")&&(t="系统接口"+t.substr(t.length-3)+"异常"),Promise.reject(e)}));const Xe={debug:"https://console-debug.smartlink.intlgame.com",test:"https://console-test.smartlink.intlgame.com",gcp:"https://console-gcp.smartlink.intlgame.com",prod:"https://console.smartlink.intlgame.com",auto:""};var Qe,Ye={setBaseUrl(e){Ge.defaults.baseURL=Xe[e]||Xe.auto},setRequestHeaders(e){Object.entries(e).forEach((([e,t])=>{Ge.defaults.headers[e]=t}))},customReport(e,t){const n={};let r=Object.keys(n).map((e=>`${e}=${n[e]}`)).join("&");r=r?`?${r}`:"";const o=(null==t?void 0:t.reportPath)?null==t?void 0:t.reportPath:"/api/v2/report/web-add";return Ge.post(`${o}${r}`,{data:e})}};!function(e){e[e.PV=1]="PV",e[e.UV=2]="UV",e[e.CLICK=3]="CLICK",e[e.INFO=4]="INFO",e[e.ERROR=5]="ERROR",e[e.WARN=6]="WARN",e[e.INPUT=7]="INPUT",e[e.HOVER=8]="HOVER",e[e.APP_PE=9]="APP_PE",e[e.PAGE_PE=10]="PAGE_PE"}(Qe||(Qe={}));class Ze{constructor(e){this.config={},this.config={uin:e.uin,accountId:e.accountId,token:e.token,env:e.env,serviceType:e.serviceType,reportPath:e.reportPath},Ye.setBaseUrl(this.config.env),Ye.setRequestHeaders({"Access-Token":this.config.token,"X-User-id":this.config.accountId,"X-Service-Type":this.config.serviceType})}async uploadReport(e){try{const{uin:t,accountId:n}=this.config;if(t&&n){const r=u({data:{uin:t,accountId:n,path:window.location.pathname,...e},switchToUnderline:!0}),o=await Ye.customReport(r,{reportPath:this.config.reportPath}),{code:s,msg:i}=o;0===s||console.error(`sdk 上报失败==>>[${s}]:`,i)}else console.error("sdk uploadReport - 上报失败, 必填信息不存在")}catch(e){console.error("sdk uploadReport - 上报失败",e)}}reportAppRelaunch(e){this.uploadReport({eventType:Qe.APP_PE,eventName:"app_relaunch_performance",moduleName:"layouts",...e})}reportChangeRouter(e){this.uploadReport({eventType:Qe.PAGE_PE,eventName:"page_performance",moduleName:"layoutContainer",...e})}reportEvent(e){this.uploadReport(e)}}const et=()=>+new Date;class tt{constructor(e){this.initTime_=e}get didTimeout(){return!1}timeRemaining(){return Math.max(0,50-(et()-this.initTime_))}}const nt="function"==typeof Promise&&Promise.toString().indexOf("[native code]")>-1,rt="MutationObserver"in window||"WebKitMutationObserver"in window||"MozMutationObserver"in window,ot=nt?e=>{Promise.resolve().then(e)}:rt?(()=>{let e=0,t=[];const n=new MutationObserver((()=>{t.forEach((e=>e())),t=[]})),r=document.createTextNode("");return n.observe(r,{characterData:!0}),n=>{t.push(n),r.data=String(++e%2)}})():e=>{},st=!("object"!=typeof window.safari||!window.safari.pushNotification);class it{constructor({ensureTasksRun:e=!1,defaultMinTaskTime:t=0}={}){this.taskQueue_=[],this.isProcessing_=!1,this.state_=null,this.idleCallbackHandle_=null,this.taskQueue_=[],this.isProcessing_=!1,this.state_=null,this.defaultMinTaskTime_=t,this.ensureTasksRun_=e,this.runTasksImmediately=this.runTasksImmediately.bind(this),this.runTasks_=this.runTasks_.bind(this),this.onVisibilityChange_=this.onVisibilityChange_.bind(this),this.ensureTasksRun_&&(addEventListener("visibilitychange",this.onVisibilityChange_,!0),st&&addEventListener("beforeunload",this.runTasksImmediately,!0))}pushTask(e){this.addTask_(Array.prototype.push,e)}unshiftTask(e){this.addTask_(Array.prototype.unshift,e)}runTasksImmediately(){this.runTasks_()}hasPendingTasks(){return this.taskQueue_.length>0}clearPendingTasks(){this.taskQueue_=[],this.cancelScheduledRun_()}getState(){return this.state_}destroy(){this.taskQueue_=[],this.cancelScheduledRun_(),this.ensureTasksRun_&&(removeEventListener("visibilitychange",this.onVisibilityChange_,!0),st&&removeEventListener("beforeunload",this.runTasksImmediately,!0))}addTask_(e,t,{minTaskTime:n=this.defaultMinTaskTime_}={}){const r={time:et(),visibilityState:document.visibilityState};e.call(this.taskQueue_,{state:r,task:t,minTaskTime:n}),this.scheduleTasksToRun_()}scheduleTasksToRun_(){this.ensureTasksRun_&&"hidden"===document.visibilityState?ot(this.runTasks_):this.idleCallbackHandle_||(this.idleCallbackHandle_=(e=>{const t=new tt(et());return setTimeout((()=>e(t)),0)})(this.runTasks_))}runTasks_(e){if(this.cancelScheduledRun_(),!this.isProcessing_){for(this.isProcessing_=!0;this.hasPendingTasks()&&!at(e,this.taskQueue_[0].minTaskTime);){const{task:e,state:t}=this.taskQueue_.shift();this.state_=t,e(t),this.state_=null}this.isProcessing_=!1,this.hasPendingTasks()&&this.scheduleTasksToRun_()}}cancelScheduledRun_(){var e;e=this.idleCallbackHandle_,clearTimeout(e),this.idleCallbackHandle_=null}onVisibilityChange_(){"hidden"===document.visibilityState&&this.runTasksImmediately()}}const at=(e,t)=>!!(e&&e.timeRemaining()<=t);class ct{constructor(e){this.config={},this.metrics={},this.isHidden=!1,this.networkStore={},this.maxFindCount=800,this.reportApi=null,this.appRelaunchCount={fpCount:0,fmpCount:0,allRenderCount:0},this.changeRouterCount={fpCount:0,fmpCount:0,allRenderCount:0},this.appRelaunchReportFinish=!1,this.appRelaunchCalculateFinish=!1,this.changeRouterStartTime=0,this.exitsChangeRouterMetricName=!1,this.didVisibilityChange=()=>{document.hidden&&(this.isHidden=document.hidden)},this.config=Object.assign({},this.config,e),this.perf=new a,this.queue=new it({ensureTasksRun:!0}),this.browser=i(),this.networkStore={},this.onBeforeUnload()}setReportApi(e){if(this.reportApi=new Ze({...e,reportPath:this.config.reportPath}),this.appRelaunchCalculateFinish&&!this.appRelaunchReportFinish){const e=this.browser,t=this.perf.networkInformation,n=this.perf.basePerfCountInfo,r={exts:{browser:e,networkInformation:t,tcpLoadCount:this.perf.tcpLoadCountInfo},performance:{fpCount:this.appRelaunchCount.fpCount,fmpCount:this.appRelaunchCount.fmpCount,allRenderCount:this.appRelaunchCount.allRenderCount,...n}};this.pushTask((()=>{this.reportAppRelaunch(r)}))}}reportAppRelaunch(e){if(!this.reportApi)return this.appRelaunchReportFinish=!1,void console.warn("warn reportApi null;");e.performance&&Object.keys(e.performance).forEach((t=>{e.performance[t]=Math.floor(e.performance[t])})),this.reportApi.reportAppRelaunch({eventType:Qe.APP_PE,...e}),this.appRelaunchReportFinish=!0}pushTask(e){this.queue&&this.queue.pushTask?this.queue.pushTask((()=>{e()})):e()}reportChangeRouter(e){this.reportApi?(e.performance&&Object.keys(e.performance).forEach((t=>{e.performance[t]=Math.floor(e.performance[t])})),this.reportApi.reportChangeRouter({eventType:Qe.PAGE_PE,...e})):console.warn("warn reportApi null;")}reportEvent(e){this.reportApi?this.reportApi.reportEvent(e):console.warn("warn reportApi null;")}searchDom(e,t){var n;e.searchCount+=1;let r=null;e.domIdName?r=document.querySelector(e.domIdName):e.domClassName?r=document.querySelector(e.domClassName):e.domTagName&&(r=null===(n=document.getElementsByTagName(e.domTagName))||void 0===n?void 0:n[0]),r?t(r):e.searchCount<100&&setTimeout((()=>this.searchDom(e,t)))}listenApprelaunchSectionDom(e){const t=t=>{new MutationObserver(((n,r)=>{const o=Number(t.offsetHeight);if(Math.ceil(o)){this.appRelaunchCount.fmpCount=this.perf.now()-this.changeRouterStartTime;const t=this.getNetworkInfoKeys();this.searchAppRelauchNetworkInfo(t,0,e),r.disconnect()}})).observe(t,{attributes:!0,childList:!0,subtree:!0})};setTimeout((()=>{this.searchDom({domTagName:"MAIN",searchCount:0},t)}))}listenAppRelaunchDomChange(e,t){const n=e=>{new MutationObserver(((n,r)=>{const o=Number(e.offsetHeight);let s=!1;for(let e=0;e<n.length&&!s;++e){const t=n[e];if("childList"===t.type){const e=t.addedNodes;for(let t=0;t<e.length&&!s;++t){"SECTION"===e[t].tagName&&(s=!0)}}}if(s)this.listenApprelaunchSectionDom(t),r.disconnect();else if(Math.ceil(o)){this.appRelaunchCount.fmpCount=this.perf.now()-this.changeRouterStartTime;const e=this.getNetworkInfoKeys();this.searchAppRelauchNetworkInfo(e,0,t),r.disconnect()}})).observe(e,{attributes:!0,childList:!0,subtree:!0})};setTimeout((()=>{this.searchDom({...e,searchCount:0},n)}))}listenChangeRouterDomChange(e,t){const n=e=>{new MutationObserver(((n,r)=>{const o=Number(e.offsetHeight);if(Math.ceil(o)){this.changeRouterCount.fmpCount=this.perf.now()-this.changeRouterStartTime;const e=this.getNetworkInfoKeys();this.searchChangeRouterNetworkInfo(e,0,t),r.disconnect()}})).observe(e,{attributes:!0,childList:!0,subtree:!0})};setTimeout((()=>{this.searchDom({...e,searchCount:0},n)}))}setNetworkInfo(e,t){this.networkStore[e]=t}delNetworkCount(e){delete this.networkStore[e]}getNetworkInfoKeys(){return[...Object.keys(this.networkStore)]}searchAppRelauchNetworkInfo(e,t=0,n){const r=[...e],o=this.getNetworkInfoKeys(),s=r.reduce(((e,t)=>(o.includes(t)&&e.push(t),e)),[]);if(s.length&&t<this.maxFindCount)setTimeout((()=>this.searchAppRelauchNetworkInfo(s,t+1,n)));else{this.appRelaunchCount.allRenderCount=this.perf.now();const e=this.browser,t=this.perf.networkInformation,r=this.perf.basePerfCountInfo,o=this.perf.tcpLoadCountInfo,s={exts:{browser:e,networkInformation:t,tcpLoadCount:o},performance:{fpCount:this.appRelaunchCount.fpCount-o,fmpCount:this.appRelaunchCount.fmpCount-o,allRenderCount:this.appRelaunchCount.allRenderCount-o,...r}};this.appRelaunchCalculateFinish=!0,this.pushTask((()=>{this.reportAppRelaunch(s)})),n&&n(s)}}searchChangeRouterNetworkInfo(e,t=0,n){const r=[...e],o=this.getNetworkInfoKeys(),s=r.reduce(((e,t)=>(o.includes(t)&&e.push(t),e)),[]);if(s.length&&t<this.maxFindCount)setTimeout((()=>this.searchChangeRouterNetworkInfo(s,t+1,n)));else{this.changeRouterCount.allRenderCount=this.perf.now()-this.changeRouterStartTime;const e={exts:{browser:this.browser,networkInformation:this.perf.networkInformation,tcpLoadCount:this.perf.tcpLoadCountInfo},performance:{fpCount:this.changeRouterCount.fpCount,fmpCount:this.changeRouterCount.fmpCount,allRenderCount:this.changeRouterCount.allRenderCount}};this.pushTask((()=>{this.exitsChangeRouterMetricName&&this.reportChangeRouter(e)})),n&&n(e)}}get networkInformation(){return this.config.networkInformation?this.perf.networkInformation:{}}start(e){if(!this.checkMetricName(e)||!a.supported())return;this.metrics[e]&&console.warn("Recording already started.");const t=this.perf.now();this.changeRouterStartTime=t,this.metrics[e]={end:0,start:t},this.perf.mark(e,"start"),this.isHidden=!1}checkStartMarkName(e){return this.perf.checkStartMarkName(e)}end(e,t){if(!this.checkMetricName(e)||!a.supported())return void console.warn("not support");const n=this.metrics[e];if(!n)return console.warn("!metric:\t"+e),"appRelaunch"===t?this.appRelaunchCount.fpCount=this.perf.now():"changeRouter"===t&&(this.exitsChangeRouterMetricName=!1,this.changeRouterCount.fpCount=this.perf.now()),this.perf.now();if("appRelaunch"===t)return this.appRelaunchCount.fpCount=this.perf.now(),this.perf.now();"changeRouter"===t&&(this.exitsChangeRouterMetricName=!0,this.changeRouterCount.fpCount=this.perf.now()-this.changeRouterStartTime),n.end=this.perf.now(),this.perf.mark(e,"end");const r=this.perf.measure(e),o=Math.floor(r);return delete this.metrics[e],o}clear(e){window.performance.clearMarks(this.perf.getStartMarkName(e)),window.performance.clearMarks(this.perf.getEndMarkName(e)),delete this.metrics[e]}endPaint(e){return new Promise((t=>{setTimeout((()=>{const n=this.end(e,"enPaint");t(n)}))}))}checkMetricName(e){return!!e}onBeforeUnload(){void 0!==document.hidden&&document.addEventListener("beforeunload",this.didVisibilityChange)}sendTiming(e){this.isHidden||this.config.analyticsTracker&&Math.random()<this.config.sampleRate&&this.config.analyticsTracker(e)}}export{ct as SmlMonitor};