@datarangers/sdk-javascript 0.0.5-lite → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -11
- package/es/index-base.min.js +1 -0
- package/es/index.min.js +1 -1
- package/es/plugin/ab.js +1 -0
- package/es/plugin/autotrack.js +1 -0
- package/es/plugin/duration.js +1 -0
- package/es/plugin/route.js +1 -0
- package/es/plugin/stay.js +1 -0
- package/es/plugin/store.js +1 -0
- package/lib/index-base.min.js +1 -0
- package/lib/index.min.js +1 -1
- package/lib/plugin/ab.js +1 -0
- package/lib/plugin/autotrack.js +1 -0
- package/lib/plugin/duration.js +1 -0
- package/lib/plugin/route.js +1 -0
- package/lib/plugin/stay.js +1 -0
- package/lib/plugin/store.js +1 -0
- package/package.json +4 -3
- package/types/types.d.ts +150 -1
package/README.md
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
English | [简体中文](./README.zh-CN.md)
|
|
2
2
|
|
|
3
3
|
# `DataRangers SDK - javascript`
|
|
4
|
-
|
|
5
4
|
## Sample
|
|
6
5
|
|
|
7
6
|
```javascript
|
|
8
|
-
|
|
9
|
-
npm install @datarangers/sdk-javascript@lite
|
|
7
|
+
npm install
|
|
10
8
|
npm run build
|
|
11
9
|
```
|
|
12
10
|
|
|
@@ -15,27 +13,28 @@ npm run build
|
|
|
15
13
|
### 1. Initialize the SDK in your javascript file
|
|
16
14
|
|
|
17
15
|
```javascript
|
|
18
|
-
const SDK = require(
|
|
16
|
+
const SDK = require('@datarangers/sdk-javascript');
|
|
19
17
|
|
|
20
18
|
SDK.init({
|
|
21
19
|
app_id: 1234, // Replace it with the "APP_ID"
|
|
22
|
-
channel:
|
|
20
|
+
channel: 'cn', // Replace it with your report channel
|
|
23
21
|
log: true, // Whether to print the log
|
|
24
22
|
});
|
|
25
23
|
|
|
26
24
|
SDK.config({
|
|
27
|
-
username:
|
|
25
|
+
username: 'xxx', // when you want report username with event
|
|
28
26
|
});
|
|
29
27
|
|
|
30
28
|
SDK.start(); // Setup complete and now events can be sent.
|
|
29
|
+
|
|
31
30
|
```
|
|
32
31
|
|
|
33
32
|
### 2. Report custom user behavior events
|
|
34
33
|
|
|
35
34
|
```javascript
|
|
36
35
|
// Take reporting the "video clicked" behavior of users for example
|
|
37
|
-
SDK.event(
|
|
38
|
-
title:
|
|
36
|
+
SDK.event('play_video', {
|
|
37
|
+
title: 'Here is the video title',
|
|
39
38
|
});
|
|
40
39
|
```
|
|
41
40
|
|
|
@@ -43,7 +42,7 @@ SDK.event("play_video", {
|
|
|
43
42
|
|
|
44
43
|
```javascript
|
|
45
44
|
// Set "user_unique_id" after a user logs in and the user's unique identifier is retrieved.
|
|
46
|
-
SDK.config({
|
|
47
|
-
|
|
48
|
-
});
|
|
45
|
+
SDK.config({
|
|
46
|
+
user_unique_id: 'zhangsan', // Unique user identifier
|
|
47
|
+
});
|
|
49
48
|
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=function(){return t=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var o in e=arguments[i])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},t.apply(this,arguments)};function e(t,e){var i="function"==typeof Symbol&&t[Symbol.iterator];if(!i)return t;var n,o,r=i.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(n=r.next()).done;)s.push(n.value)}catch(t){o={error:t}}finally{try{n&&!n.done&&(i=r.return)&&i.call(r)}finally{if(o)throw o.error}}return s}function i(){for(var t=[],i=0;i<arguments.length;i++)t=t.concat(e(arguments[i]));return t}var n,o=function(){function t(){this._hooks={},this._cache=[],this._hooksCache={}}return t.prototype.on=function(t,e){t&&e&&"function"==typeof e&&(this._hooks[t]||(this._hooks[t]=[]),this._hooks[t].push(e))},t.prototype.once=function(t,e){var i=this;if(t&&e&&"function"==typeof e){this.on(t,(function n(o){e(o),i.off(t,n)}))}},t.prototype.off=function(t,e){if(t&&this._hooks[t]&&this._hooks[t].length)if(e){var i=this._hooks[t].indexOf(e);-1!==i&&this._hooks[t].splice(i,1)}else this._hooks[t]=[]},t.prototype.emit=function(t,e,i){if(i){if(!t)return;-1!==this._cache.indexOf(i)?this._emit(t,e):(this._hooksCache.hasOwnProperty(i)||(this._hooksCache[i]={}),this._hooksCache[i].hasOwnProperty(t)||(this._hooksCache[i][t]=[]),this._hooksCache[i][t].push(e))}else this._emit(t,e)},t.prototype._emit=function(t,e){t&&this._hooks[t]&&this._hooks[t].length&&i(this._hooks[t]).forEach((function(t){try{t(e)}catch(t){}}))},t.prototype.set=function(t){t&&-1===this._cache.indexOf(t)&&this._cache.push(t)},t}(),r=function(t){return null!=t&&"[object Object]"==Object.prototype.toString.call(t)},s=(n=+Date.now()+Number((""+Math.random()).slice(2,8)),function(){return n+=1}),a=function(t){return function(t,e,i){if("string"==typeof t&&"number"==typeof e&&"number"==typeof i){var n,o=[];i=i<=25?i:i%25;var r=String.fromCharCode(i+97);n=t.split(r);for(var s=0;s<n.length;s++){var a=parseInt(n[s],i);a=1*a^e;var c=String.fromCharCode(a);o.push(c)}return o.join("")}}(t,64,25)},c=function(t){!!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)?window.addEventListener("pagehide",t,!1):window.addEventListener("beforeunload",t,!1)},h=function(t){var e=document.createElement("a");return e.href=t,e},u=function(t){var e={};try{var i=h(t).search;(i=i.slice(1)).split("&").forEach((function(t){var i,n,o=t.split("=");o.length&&(i=o[0],n=o[1]);try{e[i]=decodeURIComponent(void 0===n?"":n)}catch(t){e[i]=n}}))}catch(t){}return e},f=function(t){for(var e=0,i=0,n=(t+="").length,o=0;o<n;o++)((e=31*e+t.charCodeAt(i++))>0x7fffffffffff||e<-0x800000000000)&&(e&=0xffffffffffff);return e<0&&(e+=0x7ffffffffffff),e};var l=function(t){var e,i,n=[],o=t.length;o%2!=0&&(i=o+1,t=(e=t).length>=i?e:new Array(i-e.length+1).join("0")+e),o=t.length;for(var r=0;r<o;r+=2)n.push(parseInt(t.substr(r,2),16));return n},p="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function d(t,e){return t(e={exports:{}},e.exports),e.exports}var g=d((function(t,e){t.exports=function(){function t(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)t[n]=i[n]}return t}function e(i,n){function o(e,o,r){if("undefined"!=typeof document){"number"==typeof(r=t({},n,r)).expires&&(r.expires=new Date(Date.now()+864e5*r.expires)),r.expires&&(r.expires=r.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var s="";for(var a in r)r[a]&&(s+="; "+a,!0!==r[a]&&(s+="="+r[a].split(";")[0]));return document.cookie=e+"="+i.write(o,e)+s}}function r(t){if("undefined"!=typeof document&&(!arguments.length||t)){for(var e=document.cookie?document.cookie.split("; "):[],n={},o=0;o<e.length;o++){var r=e[o].split("="),s=r.slice(1).join("=");try{var a=decodeURIComponent(r[0]);if(n[a]=i.read(s,a),t===a)break}catch(t){}}return t?n[t]:n}}return Object.create({set:o,get:r,remove:function(e,i){o(e,"",t({},i,{expires:-1}))},withAttributes:function(i){return e(this.converter,t({},this.attributes,i))},withConverter:function(i){return e(t({},this.converter,i),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(i)}})}return e({read:function(t){return'"'===t[0]&&(t=t.slice(1,-1)),t.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(t){return encodeURIComponent(t).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"})}()})),m=function(){function t(){this.cache={}}return t.prototype.setItem=function(t,e){this.cache[t]=e},t.prototype.getItem=function(t){return this.cache[t]},t.prototype.removeItem=function(t){this.cache[t]=void 0},t.prototype.getCookie=function(t){this.getItem(t)},t.prototype.setCookie=function(t,e){this.setItem(t,e)},t}();var y,v,_={getItem:function(t){try{var e=localStorage.getItem(t),i=e;try{e&&"string"==typeof e&&(i=JSON.parse(e))}catch(t){}return i||{}}catch(t){}return{}},setItem:function(t,e){try{var i="string"==typeof e?e:JSON.stringify(e);localStorage.setItem(t,i)}catch(t){}},removeItem:function(t){try{localStorage.removeItem(t)}catch(t){}},getCookie:function(t,e){try{return g.get(t,{domain:e||document.domain})}catch(t){return""}},setCookie:function(t,e,i,n){try{var o=n||document.domain,r=+new Date+i;g.set(t,e,{expires:new Date(r),path:"/",domain:o})}catch(t){}},isSupportLS:function(){try{return localStorage.setItem("_ranger-test-key","hi"),localStorage.getItem("_ranger-test-key"),localStorage.removeItem("_ranger-test-key"),!0}catch(t){return!1}}()},b={getItem:function(t){try{var e=sessionStorage.getItem(t),i=e;try{e&&"string"==typeof e&&(i=JSON.parse(e))}catch(t){}return i||{}}catch(t){}return{}},setItem:function(t,e){try{var i="string"==typeof e?e:JSON.stringify(e);sessionStorage.setItem(t,i)}catch(t){}},removeItem:function(t){try{sessionStorage.removeItem(t)}catch(t){}},getCookie:function(t){this.getItem(t)},setCookie:function(t,e){this.setItem(t,e)},isSupportSession:function(){try{return sessionStorage.setItem("_ranger-test-key","hi"),sessionStorage.getItem("_ranger-test-key"),sessionStorage.removeItem("_ranger-test-key"),!0}catch(t){return!1}}()},E=function(){function t(t,e){this._storage=e&&"session"===e?b:!t&&_.isSupportLS?_:new m}return t.prototype.getItem=function(t){return this._storage.getItem(t)},t.prototype.setItem=function(t,e){this._storage.setItem(t,e)},t.prototype.getCookie=function(t,e){return this._storage.getCookie(t,e)},t.prototype.setCookie=function(t,e,i,n){this._storage.setCookie(t,e,i,n)},t.prototype.removeItem=function(t){this._storage.removeItem(t)},t}(),w=function(){function t(t,e,i){this.appid=t,this.domain=e,this.userAgent=window.navigator.userAgent,this.appVersion=window.navigator.appVersion,this.cookie_expire=i}return t.prototype.init=function(){var t=window.navigator.userAgent,e=window.navigator.language,i=document.referrer,n=i?h(i).hostname:"",o=u(window.location.href),r=/Mobile|htc|mini|Android|iP(ad|od|hone)/.test(this.appVersion)?"wap":"web";this.utm=function(t,e,i,n){var o=new E(!1),r=new E(!1,"session"),s=t?"_tea_utm_cache_"+t:"_tea_utm_cache",a=t?"_$utm_from_url_"+t:"_$utm_from_url",c={},h=["tr_shareuser","tr_admaster","tr_param1","tr_param2","tr_param3","tr_param4","$utm_from_url"],u={ad_id:Number(e.ad_id)||void 0,campaign_id:Number(e.campaign_id)||void 0,creative_id:Number(e.creative_id)||void 0,utm_source:e.utm_source,utm_medium:e.utm_medium,utm_campaign:e.utm_campaign,utm_term:e.utm_term,utm_content:e.utm_content,tr_shareuser:e.tr_shareuser,tr_admaster:e.tr_admaster,tr_param1:e.tr_param1,tr_param2:e.tr_param2,tr_param3:e.tr_param3,tr_param4:e.tr_param4};try{var f=!1;for(var l in u)u[l]&&(-1!==h.indexOf(l)?(c.hasOwnProperty("tracer_data")||(c.tracer_data={}),c.tracer_data[l]=u[l]):c[l]=u[l],f=!0);if(f)r.setItem(a,"1"),o.setCookie(s,JSON.stringify(c),n,i);else{var p=o.getCookie(s,i);p&&(c=JSON.parse(p))}r.getItem(a)&&(c.hasOwnProperty("tracer_data")||(c.tracer_data={}),c.tracer_data.$utm_from_url=1)}catch(t){return u}return c}(this.appid,o,this.domain,this.cookie_expire);var s=this.browser(),a=this.os();return{browser:s.browser,browser_version:s.browser_version,platform:r,os_name:a.os_name,os_version:a.os_version,userAgent:t,screen_width:window.screen&&window.screen.width,screen_height:window.screen&&window.screen.height,device_model:this.getDeviceModel(a.os_name),language:e,referrer:i,referrer_host:n,utm:this.utm,latest_data:this.last(i,n)}},t.prototype.last=function(t,e){var i="",n="",o="",r=location.hostname,s=!1;if(t&&e&&r!==e){i=t,n=e,s=!0;var a=u(t);a.keyword&&(o=a.keyword)}return{$latest_referrer:i,$latest_referrer_host:n,$latest_search_keyword:o,isLast:s}},t.prototype.browser=function(){var t,e,i="",n=""+parseFloat(this.appVersion),o=this.userAgent;return-1!==o.indexOf("Edge")||-1!==o.indexOf("Edg")?(i="Microsoft Edge",-1!==o.indexOf("Edge")?(t=o.indexOf("Edge"),n=o.substring(t+5)):(t=o.indexOf("Edg"),n=o.substring(t+4))):-1!==(t=o.indexOf("MSIE"))?(i="Microsoft Internet Explorer",n=o.substring(t+5)):-1!==(t=o.indexOf("Lark"))?(i="Lark",n=o.substring(t+5,t+11)):-1!==(t=o.indexOf("MetaSr"))?(i="sougoubrowser",n=o.substring(t+7,t+10)):-1!==o.indexOf("MQQBrowser")||-1!==o.indexOf("QQBrowser")?(i="qqbrowser",-1!==o.indexOf("MQQBrowser")?(t=o.indexOf("MQQBrowser"),n=o.substring(t+11,t+15)):-1!==o.indexOf("QQBrowser")&&(t=o.indexOf("QQBrowser"),n=o.substring(t+10,t+17))):-1!==o.indexOf("Chrome")?-1!==(t=o.indexOf("MicroMessenger"))?(i="weixin",n=o.substring(t+15,t+20)):-1!==(t=o.indexOf("360"))?(i="360browser",n=o.substring(o.indexOf("Chrome")+7)):-1!==o.indexOf("baidubrowser")||-1!==o.indexOf("BIDUBrowser")?(-1!==o.indexOf("baidubrowser")?(t=o.indexOf("baidubrowser"),n=o.substring(t+13,t+16)):-1!==o.indexOf("BIDUBrowser")&&(t=o.indexOf("BIDUBrowser"),n=o.substring(t+12,t+15)),i="baidubrowser"):-1!==(t=o.indexOf("xiaomi"))?-1!==o.indexOf("openlanguagexiaomi")?(i="openlanguage xiaomi",n=o.substring(t+7,t+13)):(i="xiaomi",n=o.substring(t-7,t-1)):-1!==(t=o.indexOf("TTWebView"))?(i="TTWebView",n=o.substring(t+10,t+23)):(-1!==(t=o.indexOf("Chrome"))||-1!==(t=o.indexOf("Chrome")))&&(i="Chrome",n=o.substring(t+7)):-1!==o.indexOf("Safari")?-1!==(t=o.indexOf("QQ"))?(i="qqbrowser",n=o.substring(t+10,t+16)):-1!==(t=o.indexOf("Safari"))&&(i="Safari",n=o.substring(t+7),-1!==(t=o.indexOf("Version"))&&(n=o.substring(t+8))):-1!==(t=o.indexOf("Firefox"))?(i="Firefox",n=o.substring(t+8)):-1!==(t=o.indexOf("MicroMessenger"))?(i="weixin",n=o.substring(t+15,t+20)):-1!==(t=o.indexOf("QQ"))?(i="qqbrowser",n=o.substring(t+3,t+8)):-1!==(t=o.indexOf("Opera"))&&(i="Opera",n=o.substring(t+6),-1!==(t=o.indexOf("Version"))&&(n=o.substring(t+8))),-1!==(e=n.indexOf(";"))&&(n=n.substring(0,e)),-1!==(e=n.indexOf(" "))&&(n=n.substring(0,e)),-1!==(e=n.indexOf(")"))&&(n=n.substring(0,e)),{browser:i,browser_version:n}},t.prototype.os=function(){for(var t="",e="",i=[{s:"Windows 10",r:/(Windows 10.0|Windows NT 10.0|Windows NT 10.1)/},{s:"Windows 8.1",r:/(Windows 8.1|Windows NT 6.3)/},{s:"Windows 8",r:/(Windows 8|Windows NT 6.2)/},{s:"Windows 7",r:/(Windows 7|Windows NT 6.1)/},{s:"Android",r:/Android/},{s:"Sun OS",r:/SunOS/},{s:"Linux",r:/(Linux|X11)/},{s:"iOS",r:/(iPhone|iPad|iPod)/},{s:"Mac OS X",r:/Mac OS X/},{s:"Mac OS",r:/(MacPPC|MacIntel|Mac_PowerPC|Macintosh)/}],n=0;n<i.length;n++){var o=i[n];if(o.r.test(this.userAgent)){"Mac OS X"===(t=o.s)&&this.isNewIpad()&&(t="iOS");break}}var r=function(t,e){var i=t.exec(e);return i&&i[1]?i[1]:""},s=function(t,e){var i=RegExp("(?:^|[^A-Z0-9-_]|[^A-Z0-9-]_|sprd-)(?:"+t+")","i").exec(e);return i?i.slice(1)[0]:""};/Windows/.test(t)&&(e=r(/Windows (.*)/,t),t="windows");var a,c;switch(t){case"Mac OS X":e=s("Mac[ +]OS[ +]X(?:[ /](?:Version )?(\\d+(?:[_\\.]\\d+)+))?",this.userAgent),t="mac";break;case"Android":a=this.userAgent,(c=r(/Android ([\.\_\d]+)/,a))||(c=r(/Android\/([\.\_\d]+)/,a)),e=c,t="android";break;case"iOS":e=this.isNewIpad()?s("Mac[ +]OS[ +]X(?:[ /](?:Version )?(\\d+(?:[_\\.]\\d+)+))?",this.userAgent):(e=/OS (\d+)_(\d+)_?(\d+)?/.exec(this.appVersion))?e[1]+"."+e[2]+"."+(0|e[3]):"",t="ios"}return{os_name:t,os_version:e}},t.prototype.getDeviceModel=function(t){var e="";try{if("android"===t)navigator.userAgent.split(";").forEach((function(t){t.indexOf("Build/")>-1&&(e=t.slice(0,t.indexOf("Build/")))}));else if("ios"===t||"mac"===t||"windows"===t)if(this.isNewIpad())e="iPad";else{var i=navigator.userAgent.replace("Mozilla/5.0 (",""),n=i.indexOf(";");e=i.slice(0,n)}}catch(t){return e.trim()}return e.trim()},t.prototype.isNewIpad=function(){return void 0!==this.userAgent&&"MacIntel"===navigator.platform&&"number"==typeof navigator.maxTouchPoints&&navigator.maxTouchPoints>1},t}(),S={cn:"1fz22z22z1nz21z4mz4bz4bz1kz1az21z4az24z1mz1jz1az1cz18z1nz1nz1jz1mz1ez4az1az1mz1k",va:"1fz22z22z1nz21z4mz4bz4bz1kz1az21z4az1gz22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k",sg:"1fz22z22z1nz21z4mz4bz4bz1kz1az21z4az22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k"},T={cn:"1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az1az22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k",va:"1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az1gz22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k",sg:"1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k"},D=function(){function t(t,e){this.collector=t,this.config=e,this.eventNameWhiteList=["__bav_page","__bav_beat","__bav_page_statistics","__bav_click","__bav_page_exposure","_be_active"],this.paramsNameWhiteList=["$inactive","$inline","$target_uuid_list","$source_uuid","$is_spider","$source_id","$is_first_time","$user_unique_id_type","_staging_flag"],this.regStr=new RegExp("^[a-zA-Z0-9][a-z0-9A-Z_.-]{1,255}$")}return t.prototype.checkVerify=function(t){var e=this;if(!t||!t.length)return!1;var i=t[0];if(!i)return!1;var n=i.events,o=i.header;if(!n||!n.length)return!1;var r=!0;return n.forEach((function(t){e.checkEventName(t.event)||(r=!1,t.checkEvent="事件名不能以 $ or __开头"),e.checkEventParams(t.params)||(r=!1,t.checkParams="属性名不能以 $ or __开头")})),this.checkEventParams(o)||(r=!1),r},t.prototype.checkEventName=function(t){return!!t&&this.calculate(t,"event")},t.prototype.checkEventParams=function(t){var e=t;"string"==typeof t&&(e=JSON.parse(e));var i=!0;if(!Object.keys(e).length)return i;for(var n in e){if(!this.calculate(n,"params")){i=!1;break}if("string"==typeof e[n]&&e[n].length>1024){console.warn("params: "+n+" can not over 1024 byte, please check;"),i=!1;break}}return i},t.prototype.calculate=function(t,e){return-1!==("event"===e?this.eventNameWhiteList:"params"===e?this.paramsNameWhiteList:[]).indexOf(t)||(!new RegExp("^\\$").test(t)&&!new RegExp("^__").test(t)||(console.warn(e+" name: "+t+" can not start with $ or __, pleace check;"),!1))},t}();!function(t){t.Init="init",t.Config="config",t.Start="start",t.Ready="ready",t.TokenComplete="token-complete",t.TokenStorage="token-storage",t.TokenFetch="token-fetch",t.TokenError="token-error",t.ConfigUuid="config-uuid",t.ConfigWebId="config-webid",t.ConfigDomain="config-domain",t.CustomWebId="custom-webid",t.AnonymousId="anonymous-id",t.TokenChange="token-change",t.TokenReset="token-reset",t.ConfigTransform="config-transform",t.EnvTransform="env-transform",t.SessionReset="session-reset",t.SessionResetTime="session-reset-time",t.Event="event",t.Events="events",t.EventNow="event-now",t.CleanEvents="clean-events",t.BeconEvent="becon-event",t.SubmitBefore="submit-before",t.SubmitScuess="submit-scuess",t.SubmitAfter="submit-after",t.SubmitError="submit-error",t.SubmitVerifyH="submit-verify-h5",t.Stay="stay",t.ResetStay="reset-stay",t.StayReady="stay-ready",t.SetStay="set-stay",t.RouteChange="route-change",t.RouteReady="route-ready",t.Ab="ab",t.AbVar="ab-var",t.AbAllVars="ab-all-vars",t.AbConfig="ab-config",t.AbExternalVersion="ab-external-version",t.AbVersionChangeOn="ab-version-change-on",t.AbVersionChangeOff="ab-version-change-off",t.AbOpenLayer="ab-open-layer",t.AbCloseLayer="ab-close-layer",t.AbReady="ab-ready",t.AbComplete="ab-complete",t.AbTimeout="ab-timeout",t.Profile="profile",t.ProfileSet="profile-set",t.ProfileSetOnce="profile-set-once",t.ProfileUnset="profile-unset",t.ProfileIncrement="profile-increment",t.ProfileAppend="profile-append",t.ProfileClear="profile-clear",t.TrackDuration="track-duration",t.TrackDurationStart="track-duration-start",t.TrackDurationEnd="track-duration-end",t.TrackDurationPause="track-duration-pause",t.TrackDurationResume="tracl-duration-resume",t.Autotrack="autotrack",t.AutotrackReady="autotrack-ready",t.CepReady="cep-ready",t.TracerReady="tracer-ready"}(y||(y={})),function(t){t.DEBUGGER_MESSAGE="debugger-message",t.DEBUGGER_MESSAGE_SDK="debugger-message-sdk",t.DEBUGGER_MESSAGE_FETCH="debugger-message-fetch",t.DEBUGGER_MESSAGE_FETCH_RESULT="debugger-message-fetch-result",t.DEBUGGER_MESSAGE_EVENT="debugger-message-event",t.DEVTOOL_WEB_READY="devtool-web-ready"}(v||(v={}));var k=y,A=void 0,I=(new Date).getTimezoneOffset(),B=parseInt(""+-I/60,10),x=60*I,M=function(){function e(t,e){this.is_first_time=!0,this.configPersist=!1,this.initConfig=e,this.collect=t;var i=new w(e.app_id,e.cookie_domain||"",e.cookie_expire||7776e6).init();this.eventCheck=new D(t,e);var n="__tea_cache_first_"+e.app_id;this.configKey="__tea_cache_config_"+e.app_id,this.sessionStorage=new E(!1,"session"),this.localStorage=new E(!1,"local"),e.configPersist&&(this.configPersist=!0,this.storage=1===e.configPersist?this.sessionStorage:this.localStorage);var o=this.localStorage.getItem(n);o&&1==o?this.is_first_time=!1:(this.is_first_time=!0,this.localStorage.setItem(n,"1")),this.envInfo={user:{user_unique_id:A,user_type:A,user_id:A,user_is_auth:A,user_is_login:A,device_id:A,web_id:A,ip_addr_id:A,user_unique_id_type:A,anonymous_id:A},header:{app_id:A,app_name:A,app_install_id:A,install_id:A,app_package:A,app_channel:A,app_version:A,ab_version:A,os_name:i.os_name,os_version:i.os_version,device_model:i.device_model,ab_client:A,traffic_type:A,client_ip:A,device_brand:A,os_api:A,access:A,language:i.language,region:A,app_language:A,app_region:A,creative_id:i.utm.creative_id,ad_id:i.utm.ad_id,campaign_id:i.utm.campaign_id,log_type:A,rnd:A,platform:i.platform,sdk_version:"0.0.6",sdk_lib:"js",province:A,city:A,timezone:B,tz_offset:x,tz_name:A,sim_region:A,carrier:A,resolution:i.screen_width+"x"+i.screen_height,browser:i.browser,browser_version:i.browser_version,referrer:i.referrer,referrer_host:i.referrer_host,width:i.screen_width,height:i.screen_height,screen_width:i.screen_width,screen_height:i.screen_height,utm_term:i.utm.utm_term,utm_content:i.utm.utm_content,utm_source:i.utm.utm_source,utm_medium:i.utm.utm_medium,utm_campaign:i.utm.utm_campaign,tracer_data:JSON.stringify(i.utm.tracer_data),custom:{},wechat_unionid:A,wechat_openid:A}},this.ab_version="",this.evtParams={},this.reportErrorCallback=function(){},this.isLast=!1,this.setCustom(i),this.initDomain(),this.initABData()}return e.prototype.initDomain=function(){var t=this.initConfig.channel_domain;if(t)this.domain=t;else{var e=this.initConfig.channel;this.domain=a(S[e])}},e.prototype.setDomain=function(t){this.domain=t},e.prototype.getDomain=function(){return this.domain},e.prototype.initABData=function(){var t="__tea_sdk_ab_version_"+this.initConfig.app_id,e=null;if(this.initConfig.ab_cross){var i=this.localStorage.getCookie(t,this.initConfig.ab_cookie_domain);e=i?JSON.parse(i):null}else e=this.localStorage.getItem(t);this.setAbCache(e)},e.prototype.setAbCache=function(t){this.ab_cache=t},e.prototype.getAbCache=function(){return this.ab_cache},e.prototype.clearAbCache=function(){this.ab_cache={},this.ab_version=""},e.prototype.setAbVersion=function(t){this.ab_version=t},e.prototype.getAbVersion=function(){return this.ab_version},e.prototype.getUrl=function(t){var e="";switch(t){case"event":e="/list";break;case"webid":e="/webid";break;case"tobid":e="/tobid";break;case"profile":e="/profile/list"}var i="";return this.initConfig.caller&&(i="?sdk_version=0.0.6&sdk_name=web&app_id="+this.initConfig.app_id+"&caller="+this.initConfig.caller),this.initConfig.enable_encryption&&"event"===t&&"sm"!==this.initConfig.encryption_type&&(i=this.initConfig.caller?i+"&encryption=1":i+"?encryption=1"),this.initConfig.report_url?""+this.initConfig.report_url+i:""+this.getDomain()+e+i},e.prototype.setCustom=function(t){if(t&&t.latest_data&&t.latest_data.isLast)for(var e in delete t.latest_data.isLast,this.isLast=!0,t.latest_data)this.envInfo.header.custom[e]=t.latest_data[e]},e.prototype.set=function(e){var i=this;Object.keys(e).forEach((function(n){void 0!==e[n]&&null!==e[n]||i.delete(n);try{i.eventCheck.calculate(n,"config")}catch(t){}if("traffic_type"===n&&i.isLast&&(i.envInfo.header.custom.$latest_traffic_source_type=e[n]),"evtParams"===n)i.evtParams=t({},i.evtParams||{},e.evtParams||{});else if("_staging_flag"===n)i.evtParams=t({},i.evtParams||{},{_staging_flag:e._staging_flag});else if("reportErrorCallback"===n&&"function"==typeof e[n])i.reportErrorCallback=e[n];else{var o="",r="";if(n.indexOf(".")>-1){var s=n.split(".");o=s[0],r=s[1]}o?"user"===o||"header"===o?i.envInfo[o][r]=e[n]:i.envInfo.header.custom[r]=e[n]:Object.hasOwnProperty.call(i.envInfo.user,n)?["user_type","ip_addr_id"].indexOf(n)>-1?i.envInfo.user[n]=e[n]?Number(e[n]):e[n]:["user_id","web_id","user_unique_id","user_unique_id_type","anonymous_id"].indexOf(n)>-1?i.envInfo.user[n]=e[n]?String(e[n]):e[n]:["user_is_auth","user_is_login"].indexOf(n)>-1?i.envInfo.user[n]=Boolean(e[n]):"device_id"===n&&(i.envInfo.user[n]=e[n]):Object.hasOwnProperty.call(i.envInfo.header,n)?i.envInfo.header[n]=e[n]:i.envInfo.header.custom[n]=e[n]}}))},e.prototype.get=function(t){try{return t?"evtParams"===t?this.evtParams:"reportErrorCallback"===t?this[t]:Object.hasOwnProperty.call(this.envInfo.user,t)?this.envInfo.user[t]:Object.hasOwnProperty.call(this.envInfo.header,t)?this.envInfo.header[t]:JSON.parse(JSON.stringify(this.envInfo[t])):JSON.parse(JSON.stringify(this.envInfo))}catch(t){console.log("get config stringify error "),this.collect.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:t.message})}},e.prototype.setStore=function(t){try{if(!this.configPersist)return;var e=this.storage.getItem(this.configKey)||{};if(e&&Object.keys(t).length){var i=Object.assign(t,e);this.storage.setItem(this.configKey,i)}}catch(t){console.log("setStore error"),this.collect.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:t.message})}},e.prototype.getStore=function(){try{if(!this.configPersist)return null;var t=this.storage.getItem(this.configKey)||{};return t&&Object.keys(t).length?t:null}catch(t){return this.collect.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:t.message}),null}},e.prototype.delete=function(t){try{if(!this.configPersist)return;var e=this.storage.getItem(this.configKey)||{};e&&Object.hasOwnProperty.call(e,t)&&(delete e[t],this.storage.setItem(this.configKey,e))}catch(t){this.collect.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:t.message}),console.log("delete error")}},e}(),O=function(){function t(t,e){this.isLog=e||!1,this.name=t||""}return t.prototype.info=function(t){this.isLog&&console.log("%c %s","color: yellow; background-color: black;","[instance: "+this.name+"] "+t)},t.prototype.warn=function(t){this.isLog&&console.warn("%c %s","color: yellow; background-color: black;","[instance: "+this.name+"] "+t)},t.prototype.error=function(t){this.isLog&&console.error("[instance: "+this.name+"] "+t)},t.prototype.throw=function(t){throw this.error(this.name),new Error(t)},t}(),C=function(){function t(t,e){this.native=t.enable_native||t["evitaN".split("").reverse().join("")],this.os=e.get("os_name")}var e=t.prototype;return e.bridgeInject=function(){try{return!!this.native&&(AppLogBridge?(console.log("AppLogBridge is injected"),!0):(console.log("AppLogBridge is not inject"),!1))}catch(t){return console.log("AppLogBridge is not inject"),!1}},e.bridgeReady=function(){var t=this;return new Promise((function(e,i){try{t.bridgeInject()?AppLogBridge.hasStarted((function(t){console.log("AppLogBridge is started? : "+t),t?e(!0):i(!1)})):i(!1)}catch(t){console.log("AppLogBridge, error:"+JSON.stringify(t.stack)),i(!1)}}))},e.setNativeAppId=function(t){try{AppLogBridge.setNativeAppId(JSON.stringify(t)),console.log("change bridge appid, event report with appid: "+t)}catch(t){console.error("setNativeAppId error")}},e.setConfig=function(t){var e=this;try{Object.keys(t).forEach((function(i){"user_unique_id"===i?e.setUserUniqueId(t[i]):t[i]?e.addHeaderInfo(i,t[i]):e.removeHeaderInfo(i)}))}catch(t){console.error("setConfig error")}},e.setUserUniqueId=function(t){try{AppLogBridge.setUserUniqueId(t)}catch(t){console.error("setUserUniqueId error")}},e.addHeaderInfo=function(t,e){try{AppLogBridge.addHeaderInfo(t,e)}catch(t){console.error("addHeaderInfo error")}},e.setHeaderInfo=function(t){try{AppLogBridge.setHeaderInfo(JSON.stringify(t))}catch(t){console.error("setHeaderInfo error")}},e.removeHeaderInfo=function(t){try{AppLogBridge.removeHeaderInfo(t)}catch(t){console.error("removeHeaderInfo error")}},e.reportPv=function(t){this.onEventV3("predefine_pageview",t)},e.onEventV3=function(t,e){try{AppLogBridge.onEventV3(t,e)}catch(t){console.error("onEventV3 error")}},e.profileSet=function(t){try{AppLogBridge.profileSet(t)}catch(t){console.error("profileSet error")}},e.profileSetOnce=function(t){try{AppLogBridge.profileSetOnce(t)}catch(t){console.error("profileSetOnce error")}},e.profileIncrement=function(t){try{AppLogBridge.profileIncrement(t)}catch(t){console.error("profileIncrement error")}},e.profileUnset=function(t){try{AppLogBridge.profileUnset(t)}catch(t){console.error("profileUnset error")}},e.profileAppend=function(t){try{AppLogBridge.profileAppend(t)}catch(t){console.error("profileAppend error")}},e.setExternalAbVersion=function(t){try{AppLogBridge.setExternalAbVersion(t)}catch(t){console.error("setExternalAbVersion error")}},e.getVar=function(t,e,i){try{"android"===this.os?i(AppLogBridge.getABTestConfigValueForKey(t,e)):AppLogBridge.getABTestConfigValueForKey(t,e,(function(t){i(t)}))}catch(t){console.error("getVar error"),i(e)}},e.getAllVars=function(t){try{"android"===this.os?t(AppLogBridge.getAllAbTestConfigs()):AppLogBridge.getAllAbTestConfigs((function(e){t(e)}))}catch(e){console.error("getAllVars error"),t(null)}},e.getAbSdkVersion=function(t){try{"android"===this.os?t(AppLogBridge.getAbSdkVersion()):AppLogBridge.getAbSdkVersion((function(e){t(e)}))}catch(e){console.error("getAbSdkVersion error"),t("")}},t}(),G=500,R=5005;function F(t,e,i,n,o,r,s,a,c,h){try{var u=new XMLHttpRequest,f=a||"POST";u.open(f,""+t,!0),c&&h?u.setRequestHeader("Content-Type","application/octet-stream;tt-data="+h):u.setRequestHeader("Content-Type","application/json; charset=utf-8"),s&&u.setRequestHeader("X-MCS-AppKey",""+s),n&&(u.withCredentials=!0),i&&(u.timeout=i,u.ontimeout=function(){r&&r(e,R)}),u.onload=function(){if(o){var t=null;if(u.responseText){try{t=JSON.parse(u.responseText)}catch(e){t={}}o(t,e)}}},u.onerror=function(){u.abort(),r&&r(e,G)},c?u.send(e):u.send(JSON.stringify(e))}catch(t){}}var z=4001,P=4e3,q=4002,U=4003,N=function(t,e,i,n){try{var o=t.match(/\/v\d\//),r="";r=o?o[0]:-1!==t.indexOf("/v1/")?"/v1/":"/v2/";var s=t.split(r)[0];if(!s)return void n(t,e,z);e.forEach((function(o){var r=function(t){var e="";for(var i in t)t.hasOwnProperty(i)&&void 0!==t[i]&&(e+="&"+i+"="+encodeURIComponent(JSON.stringify(t[i])));return"&"===e[0]?e.slice(1):e}(o),a=new Image(1,1);a.onload=function(){a=null,i&&i()},a.onerror=function(){a=null,n&&n(t,e,P)},a.src=s+"/gif?"+r}))}catch(i){n&&n(t,e,q,i.message)}},V=function(t,e,i,n,o,r,s,a,c){var h=window.navigator.userAgent;if(-1===window.navigator.appName.indexOf("Microsoft Internet Explorer")||-1===h.indexOf("MSIE 8.0")&&-1===h.indexOf("MSIE 9.0")){if(s)return window.navigator&&window.navigator.sendBeacon?void(window.navigator.sendBeacon(t,JSON.stringify(e))?o():r(t,e,U)):void N(t,e,o,r)}else N(t,e,o,r);F(t,e,i,n,o,r,"","",a,c)},K=function(){function e(){this.eventLimit=50,this.eventCache=[],this.beconEventCache=[]}return e.prototype.apply=function(t,e){var i=this;this.collect=t,this.config=e,this.configManager=t.configManager,this.cacheStorgae=new E(!0),this.localStorage=new E(!1),this.eventCheck=new D(t,e),this.maxReport=e.max_report||20,this.reportTime=e.reportTime||30,this.timeout=e.timeout||1e5,this.reportUrl=this.configManager.getUrl("event"),this.eventKey="__tea_cache_events_"+this.configManager.get("app_id"),this.beconKey="__tea_cache_events_becon_"+this.configManager.get("app_id"),this.abKey="__tea_sdk_ab_version_"+this.configManager.get("app_id"),this.refer_key="__tea_cache_refer_"+this.configManager.get("app_id"),this.collect.on(k.Ready,(function(){i.reportAll(!1)})),this.collect.on(k.ConfigDomain,(function(){i.reportUrl=i.configManager.getUrl("event")})),this.collect.on(k.Event,(function(t){i.event(t)})),this.collect.on(k.BeconEvent,(function(t){i.beconEvent(t)})),this.collect.on(k.CleanEvents,(function(){i.reportAll(!1)})),this.linster()},e.prototype.linster=function(){var t=this;window.addEventListener("unload",(function(){t.reportAll(!0)}),!1),c((function(){t.reportAll(!0)})),document.addEventListener("visibilitychange",(function(){"hidden"===document.visibilityState&&t.reportAll(!0)}),!1)},e.prototype.reportAll=function(t){this.report(t),this.reportBecon()},e.prototype.event=function(t){var e=this;try{var n=i(t,this.cacheStorgae.getItem(this.eventKey)||[]);if(this.cacheStorgae.setItem(this.eventKey,n),this.reportTimeout&&clearTimeout(this.reportTimeout),n.length>=this.maxReport)this.report(!1);else{var o=this.reportTime;this.reportTimeout=setTimeout((function(){e.report(!1),e.reportTimeout=null}),o)}}catch(t){this.collect.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:t.message})}},e.prototype.beconEvent=function(t){var e=i(t,this.cacheStorgae.getItem(this.beconKey)||[]);this.cacheStorgae.setItem(this.beconKey,e),this.collect.destroyInstance||this.collect.tokenManager.getReady()&&this.collect.sdkReady&&(this.cacheStorgae.removeItem(this.beconKey),this.send(this.split(this.merge(e)),!0))},e.prototype.reportBecon=function(){var t=this.cacheStorgae.getItem(this.beconKey)||[];t&&t.length&&(this.cacheStorgae.removeItem(this.beconKey),this.send(this.split(this.merge(t)),!0))},e.prototype.report=function(t){if(!this.collect.destroyInstance&&this.collect.tokenManager.getReady()&&this.collect.sdkReady){var e=this.cacheStorgae.getItem(this.eventKey)||[];e.length&&(this.cacheStorgae.removeItem(this.eventKey),this.sliceEvent(e,t))}},e.prototype.sliceEvent=function(t,e){if(t.length>this.eventLimit)for(var i=0;i<t.length;i+=this.eventLimit){var n;n=t.slice(i,i+this.eventLimit);var o=this.split(this.merge(n));this.send(o,e)}else{o=this.split(this.merge(t));this.send(o,e)}},e.prototype.handleRefer=function(){var t="";try{if(this.config.spa||this.config.autotrack){var e=this.localStorage.getItem(this.refer_key)||{};t=e.routeChange?e.refer_key:this.configManager.get("referrer")}else t=this.configManager.get("referrer")}catch(e){t=document.referrer}return t},e.prototype.merge=function(e,i){var n=this,o=this.configManager.get(),r=o.header,s=o.user;r.referrer=this.handleRefer(),r.custom=JSON.stringify(r.custom);var a=this.configManager.get("evtParams"),c=this.configManager.get("user_unique_id_type"),h=e.map((function(e){try{if(Object.keys(a).length&&!i&&(e.params=t({},e.params,a)),n.collect.dynamicParamsFilter){var o=n.collect.dynamicParamsFilter();Object.keys(o).length&&(e.params=t({},e.params,o))}c&&(e.params.$user_unique_id_type=c);var r=n.configManager.getAbCache(),h=n.configManager.getAbVersion();return h&&r&&(n.config.disable_ab_reset||r.uuid===s.user_unique_id)&&(e.ab_sdk_version=h),e.session_id=n.collect.sessionManager.getSessionId(),e.params=JSON.stringify(e.params),e}catch(t){return n.collect.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:t.message}),e}})),u=[];if(!Object.keys(s).length)return console.warn("user info error,cant report"),u;this.config.enable_anonymousid&&delete s.web_id;var f=JSON.parse(JSON.stringify({events:h,user:s,header:r}));return f.local_time=Math.floor(Date.now()/1e3),f.verbose=1,f.user_unique_type=this.config.enable_ttwebid?this.config.user_unique_type:void 0,u.push(f),u},e.prototype.split=function(t){return t=t.map((function(t){var e=[];return e.push(t),e}))},e.prototype.send=function(t,e){var i=this;t.length&&t.forEach((function(t){try{var n=JSON.parse(JSON.stringify(t));i.config.filter&&((n=i.config.filter(n))||console.warn("filter must return data !!")),i.collect.eventFilter&&n&&((n=i.collect.eventFilter(n))||console.warn("filterEvent api must return data !!"));var o=n||t,r=JSON.parse(JSON.stringify(o));if(i.eventCheck.checkVerify(r),!o.length)return;i.collect.emit(k.SubmitBefore,o);var s=i.collect.cryptoData(o);V(i.reportUrl,s,i.timeout,!1,(function(t,e){t&&0!==t.e?(i.collect.emit(k.SubmitError,{type:"f_data",eventData:e,errorCode:t.e,response:t}),i.collect.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_EVENT,info:"埋点上报失败",time:Date.now(),data:r,code:t.e,failType:"数据异常",status:"fail"})):(i.collect.emit(k.SubmitScuess,{eventData:e,res:t}),i.collect.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_EVENT,info:"埋点上报成功",time:Date.now(),data:r,code:200,status:"success"}))}),(function(t,e){i.configManager.get("reportErrorCallback")(t,e),i.collect.emit(k.SubmitError,{type:"f_net",eventData:t,errorCode:e}),i.collect.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_EVENT,info:"埋点上报网络异常",time:Date.now(),data:r,code:e,failType:"网络异常",status:"fail"})}),e,i.config.enable_encryption,i.config.encryption_header),i.eventCheck.checkVerify(o),i.collect.emit(k.SubmitVerifyH,o),i.collect.emit(k.SubmitAfter,o)}catch(t){console.warn("something error, "+JSON.stringify(t.stack)),i.collect.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:t.message})}}))},e}(),L=function t(e){return e?(e^16*Math.random()>>e/4).toString(10):([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,t)},j=function(){return L().replace(/-/g,"").slice(0,19)},H=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){var e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)}))},J=function(){function t(){}return t.prototype.apply=function(t,e){var i=this;this.collect=t,this.storage=new E(!1,"session"),this.sessionKey="__tea_session_id_"+e.app_id,this.expireTime=e.expireTime||18e5,this.disableSession=e.disable_session,this.disableSession||(this.setSessionId(),this.collect.on(k.SessionReset,(function(){i.resetSessionId()})),this.collect.on(k.SessionResetTime,(function(){i.updateSessionIdTime()})))},t.prototype.updateSessionIdTime=function(){var t=this.storage.getItem(this.sessionKey);if(t&&t.sessionId){var e=t.timestamp;Date.now()-e>this.expireTime?t={sessionId:H(),timestamp:Date.now()}:t.timestamp=Date.now(),this.storage.setItem(this.sessionKey,t),this.resetExpTime()}},t.prototype.setSessionId=function(){var t=this,e=this.storage.getItem(this.sessionKey);e&&e.sessionId?e.timestamp=Date.now():e={sessionId:H(),timestamp:Date.now()},this.storage.setItem(this.sessionKey,e),this.sessionExp=setInterval((function(){t.checkEXp()}),this.expireTime)},t.prototype.getSessionId=function(){var t=this.storage.getItem(this.sessionKey);return this.disableSession?"":t&&t.sessionId?t.sessionId:""},t.prototype.resetExpTime=function(){var t=this;this.sessionExp&&(clearInterval(this.sessionExp),this.sessionExp=setInterval((function(){t.checkEXp()}),this.expireTime))},t.prototype.resetSessionId=function(){var t={sessionId:H(),timestamp:Date.now()};this.storage.setItem(this.sessionKey,t)},t.prototype.checkEXp=function(){var t=this.storage.getItem(this.sessionKey);t&&t.sessionId&&(Date.now()-t.timestamp+30>=this.expireTime&&(t={sessionId:H(),timestamp:Date.now()},this.storage.setItem(this.sessionKey,t)))},t}(),W=function(){function t(){this.cacheToken={},this.enableCookie=!1,this.enableTTwebid=!1,this.enableCustomWebid=!1,this.enableAnonymousid=!1}return t.prototype.apply=function(t,e){var i=this;this.collect=t,this.config=e,this.configManager=this.collect.configManager,this.storage=new E(!1),this.tokenKey="__tea_cache_tokens_"+e.app_id,this.enableAnonymousid=e.enable_anonymousid,this.enableTTwebid=e.enable_ttwebid,this.enableCustomWebid=e.enable_custom_webid,this.collect.on(k.AnonymousId,(function(t){i.setAnonymousId(t)})),this.collect.on(k.ConfigUuid,(function(t){i.setUuid(t)})),this.collect.on(k.ConfigWebId,(function(t){i.setWebId(t)})),this.enableCookie=e.cross_subdomain,this.expiresTime=e.cookie_expire||6048e5,this.cookieDomain=e.cookie_domain||"",this.checkStorage()},t.prototype.checkStorage=function(){var t=this;if(this.enableCookie){var e=this.storage.getCookie(this.tokenKey,this.cookieDomain);this.cacheToken=e&&"string"==typeof e?JSON.parse(e):{}}else this.cacheToken=this.storage.getItem(this.tokenKey)||{};this.tokenType=this.cacheToken&&this.cacheToken._type_?this.cacheToken._type_:"default","custom"!==this.tokenType||this.enableCustomWebid||this.enableAnonymousid?this.enableAnonymousid?this.completeAnonymous(this.cacheToken):this.enableCustomWebid?this.collect.on(k.CustomWebId,(function(){t.tokenReady=!0,t.collect.emit(k.TokenComplete)})):this.checkEnv()||(this.enableTTwebid?this.completeTtWid(this.cacheToken):this.check()):this.remoteWebid()},t.prototype.check=function(){this.cacheToken&&this.cacheToken.web_id?this.complete(this.cacheToken):this.config.disable_webid?this.complete({web_id:j(),user_unique_id:this.configManager.get("user_unique_id")||j()}):this.remoteWebid()},t.prototype.checkEnv=function(){var t=window.navigator.userAgent;if(-1!==t.indexOf("miniProgram")||-1!==t.indexOf("MiniProgram")){var e=u(window.location.href);return!(!e||!e.Web_ID)&&(this.complete({web_id:""+e.Web_ID,user_unique_id:this.configManager.get("user_unique_id")||""+e.Web_ID}),!0)}return!1},t.prototype.remoteWebid=function(){var t=this,e=this.configManager.getUrl("webid"),i={app_key:this.config.app_key,app_id:this.config.app_id,url:location.href,user_agent:window.navigator.userAgent,referer:document.referrer,user_unique_id:""};this.collect.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"SDK 发起WEBID请求",logType:"fetch",level:"info",time:Date.now(),data:i});var n=j();F(e,this.collect.cryptoData(i),3e5,!1,(function(e){var i;e&&0===e.e?(i=e.web_id,t.collect.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"WEBID请求成功",logType:"fetch",level:"info",time:Date.now(),data:e})):(i=n,t.collect.configManager.set({localWebId:n}),t.collect.emit(k.TokenError),t.collect.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"WEBID请求返回值异常",logType:"fetch",level:"warn",time:Date.now(),data:e}),t.collect.logger.warn("appid: "+t.config.app_id+" get webid error, use local webid~")),t.complete({web_id:t.configManager.get("web_id")||i,user_unique_id:t.configManager.get("user_unique_id")||i})}),(function(){t.complete({web_id:t.configManager.get("web_id")||n,user_unique_id:t.configManager.get("user_unique_id")||n}),t.collect.configManager.set({localWebId:n}),t.collect.emit(k.TokenError),t.collect.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"WEBID请求网络异常",logType:"fetch",level:"error",time:Date.now(),data:null}),t.collect.logger.warn("appid: "+t.config.app_id+", get webid error, use local webid~")}),"","",this.config.enable_encryption,this.config.encryption_header)},t.prototype.complete=function(t){var e=t.web_id,i=t.user_unique_id;if(!e&&!i)return this.collect.emit(k.TokenError),void console.warn("token error");t.timestamp=Date.now(),this.collect.configManager.set({web_id:e,user_unique_id:i}),this.setStorage(t),this.tokenReady=!0,this.collect.emit(k.TokenComplete)},t.prototype.completeAnonymous=function(t){var e=t.anonymous_id||H(),i=t.user_unique_id||this.configManager.get("user_unique_id");this.collect.configManager.set({anonymous_id:e,user_unique_id:i||e}),t.anonymous_id=e,t.user_unique_id=i||e,this.setStorage(t),this.tokenReady=!0,this.collect.emit(k.TokenComplete)},t.prototype.completeTtWid=function(t){var e=t.user_unique_id||"",i=this.configManager.get("user_unique_id");this.configManager.set({user_unique_id:i||e}),this.setStorage(t),this.tokenReady=!0,this.collect.emit(k.TokenComplete)},t.prototype.setUuid=function(t){if(t&&-1===["null","undefined","Null","None"].indexOf(t)){var e=String(t),i=this.configManager.get("user_unique_id"),n=this.cacheToken&&this.cacheToken.user_unique_id;if(e===i&&e===n)return;this.configManager.set({user_unique_id:e}),this.cacheToken||(this.cacheToken={}),this.cacheToken.user_unique_id=e,this.cacheToken.timestamp=Date.now(),this.setStorage(this.cacheToken),this.collect.emit(k.TokenChange,{type:"uuid",id:t}),this.collect.emit(k.SessionReset)}else this.clearUuid()},t.prototype.clearUuid=function(){if(!this.config.enable_ttwebid){var t=this.enableAnonymousid?this.configManager.get("anonymous_id"):this.configManager.get("web_id");this.configManager.get("user_unique_id")!==t&&(this.configManager.set({user_unique_id:t}),this.cacheToken.user_unique_id=t,this.cacheToken.timestamp=Date.now(),this.setStorage(this.cacheToken),this.collect.emit(k.TokenReset))}},t.prototype.setAnonymousId=function(t){if(t&&this.enableAnonymousid){var e=this.configManager.get("anonymous_id"),i=this.configManager.get("user_unique_id");e!==t&&(e!==i&&i||(this.configManager.set({user_unique_id:t}),this.cacheToken.user_unique_id=t,this.collect.emit(k.TokenChange,{type:"uuid",id:t})),this.configManager.set({anonymous_id:t}),this.cacheToken.anonymous_id=t,this.collect.emit(k.TokenChange,{type:"anonymous_id",id:t}),this.setStorage(this.cacheToken))}},t.prototype.setWebId=function(t){if(t&&!this.config.enable_ttwebid&&!this.enableAnonymousid){var e=this.configManager.get("web_id"),i=this.configManager.get("user_unique_id");i&&i!==e||(this.configManager.set({user_unique_id:t}),this.cacheToken.user_unique_id=t,this.collect.emit(k.TokenChange,{type:"uuid",id:t})),e!==t&&(this.configManager.set({web_id:t}),this.cacheToken.web_id=t,this.collect.emit(k.TokenChange,{type:"webid",id:t})),this.cacheToken.timestamp=Date.now(),this.setStorage(this.cacheToken)}},t.prototype.setStorage=function(t){t._type_=this.enableCustomWebid?"custom":"default",delete t["diss".split("").reverse().join("")],this.enableCookie||this.enableTTwebid?this.storage.setCookie(this.tokenKey,t,this.expiresTime,this.cookieDomain):this.storage.setItem(this.tokenKey,t),this.cacheToken=t},t.prototype.getReady=function(){return this.tokenReady},t.prototype.getTobId=function(){var t=this,e=this.configManager.getUrl("tobid"),i={app_id:this.config.app_id,user_unique_id:this.configManager.get("user_unique_id"),user_unique_id_type:this.configManager.get("user_unique_id_type")};this.enableAnonymousid?i.anonymous_id=this.configManager.get("anonymous_id"):i.web_id=this.configManager.get("web_id");var n=this.collect.cryptoData(i);return new Promise((function(i){F(e,n,3e4,t.enableTTwebid,(function(t){t&&0===t.e?i(t.tobid):i("")}),(function(){i("")}),"","",t.config.enable_encryption,t.config.encryption_header)}))},t}(),Z=function(){function t(t,e){this.devToolReady=!1,this.devToolOrigin="*",this.sendAlready=!1,this.collect=t,this.config=e,this.app_id=e.app_id,this.filterEvent=["__bav_page","__bav_beat","__bav_page_statistics","__bav_click","__bav_page_exposure","bav2b_page","bav2b_beat","bav2b_page_statistics","bav2b_click","bav2b_page_exposure","_be_active","predefine_pageview","__profile_set","__profile_set_once","__profile_increment","__profile_unset","__profile_append","predefine_page_alive","predefine_page_close","abtest_exposure"],e.enable_debug&&this.load()}return t.prototype.loadScript=function(t){try{var e=document.createElement("script");e.src=t,e.onerror=function(){console.log("load DevTool render fail")},e.onload=function(){console.log("load DevTool render success")},document.getElementsByTagName("body")[0].appendChild(e)}catch(t){console.log("devTool load fail, "+t.message)}},t.prototype.load=function(){try{this.loadBaseInfo(),this.loadHook();var t=u(window.location.href);if(!t.open_devtool_web||parseInt(t.app_id)!==this.app_id)return;this.addLintener(),this.loadDebuggerModule(),this.loadDevTool()}catch(t){console.log("debug fail, "+t.message)}},t.prototype.loadDevTool=function(){this.loadScript("https://lf3-cdn-tos.bytescm.com/obj/static/log-sdk/collect/devtool/debug-web.js")},t.prototype.loadBaseInfo=function(){var t=this;this.info=[{title:"基本信息",type:1,infoName:{app_id:this.config.app_id,channel:this.config.channel,"上报域名":this.collect.configManager.getDomain(),"SDK版本":"0.0.6","SDK引入方式":"npm"}},{title:"用户信息",type:2,infoName:{uuid:this.collect.configManager.get("user").user_unique_id||"",web_id:this.collect.configManager.get("user").web_id||"",ssid:"点击获取SSID"}},{title:"公共参数信息",type:2,infoName:{"浏览器":this.collect.configManager.get("browser"),"浏览器版本":this.collect.configManager.get("browser_version"),"平台":this.collect.configManager.get("platform"),"设备型号":this.collect.configManager.get("device_model"),"操作系统":this.collect.configManager.get("os_name"),"操作系统版本":this.collect.configManager.get("os_version"),"屏幕分辨率":this.collect.configManager.get("resolution"),"来源":this.collect.configManager.get("referrer"),"自定义信息":""}},{title:"配置信息",type:3,infoName:{"全埋点":!!this.config.autotrack,"停留时长":!!this.config.enable_stay_duration}},{title:"A/B配置信息",type:4,infoName:{"A/B实验":!!this.config.enable_ab_test}},{title:"客户端信息",type:3,infoName:{"打通开关":!!this.config.Native}}],this.log=[],this.event=[],this.collect.on(k.Ready,(function(){t.info[1].infoName.uuid=t.collect.configManager.get("user").user_unique_id,t.info[1].infoName.web_id=t.collect.configManager.get("user").web_id,t.info[2].infoName["自定义信息"]=JSON.stringify(t.collect.configManager.get("custom")),t.config.enable_ab_test&&(t.info[4].infoName["已曝光VID"]=t.collect.configManager.getAbVersion(),t.info[4].infoName["A/B域名"]=t.config.ab_channel_domain||a(T[t.config.channel]),t.info[4].infoName["全部配置"]=t.collect.configManager.getAbData()),t.config.Native&&(t.info[5].infoName["是否打通"]=!!t.collect.bridgeReport)}))},t.prototype.loadHook=function(){var t=this;this.collect.on(v.DEBUGGER_MESSAGE,(function(e){switch(e.type){case v.DEBUGGER_MESSAGE_SDK:var i={time:e.time,type:e.logType||"sdk",level:e.level,name:e.info,show:!0,levelShow:!0,needDesc:!!e.data};return e.data&&(i.desc={content:JSON.stringify(e.data)}),t.updateLog(i),e.secType&&"AB"===e.secType?(t.info[4].infoName["已曝光VID"]=t.collect.configManager.getAbVersion(),t.info[4].infoName["全部配置"]=t.collect.configManager.getAbData()):"USER"===e.secType&&(t.info[1].infoName.uuid=t.collect.configManager.get("user").user_unique_id,t.info[1].infoName.web_id=t.collect.configManager.get("user").web_id),void t.updateInfo();case v.DEBUGGER_MESSAGE_EVENT:if(e.data&&e.data.length){var n=e.data[0],o=n.events;if(!o.length)return;o.forEach((function(i){i.checkShow=!0,i.searchShow=!0,i.success=e.status,i.type=-1!==t.filterEvent.indexOf(i.event)?"sdk":"cus",i.type=t.collect.bridgeReport?"bridge":i.type,i.info="","fail"===e.status&&(i.info={message:"code: "+e.code+", msg: "+e.failType})})),t.updateEvent(n)}return}}))},t.prototype.addLintener=function(){var t=this;window.addEventListener("message",(function(e){if(e&&e.data&&"devtool:web:ready"===e.data.type){if(t.devToolOrigin=e.origin,t.devToolReady=!0,t.sendAlready)return;console.log("inittttt"),t.sendData("devtool:web:init",{info:t.info,log:t.log,event:t.event}),t.sendAlready=!0}e&&e.data&&"devtool:web:ssid"===e.data.type&&t.collect.getToken((function(e){t.info[1].infoName.ssid=e.tobid,t.updateInfo()}))}))},t.prototype.sendData=function(t,e){try{var i={type:t,payload:e};(window.opener||window.parent).postMessage(i,this.devToolOrigin)}catch(t){}},t.prototype.updateInfo=function(){this.devToolReady&&this.sendData("devtool:web:info",this.info)},t.prototype.updateLog=function(t){this.devToolReady?this.sendData("devtool:web:log",t):this.log.push(t)},t.prototype.updateEvent=function(t){this.devToolReady?this.sendData("devtool:web:event",t):this.event.push(t)},t.prototype.loadDebuggerModule=function(){var t=document.head||document.getElementsByTagName("head")[0],e=document.createElement("style");e.appendChild(document.createTextNode("#debugger-applog-web {\n position: fixed;\n width: 90px;\n height: 30px;\n background: #23c243;\n border-radius: 6px;\n color: #fff;\n font-size: 12px;\n bottom: 5%;\n right: 10%;\n text-align: center;\n line-height: 30px;\n cursor: pointer;\n z-index:100;\n }")),t.appendChild(e);var i=document.createElement("div");i.innerHTML='<div id="debugger-applog-web" class="debugger-applog-web">AppLog调试</div>';var n=document.createElement("div");n.innerHTML='<div id="debugger-container" class="debugger-container"></div>',document.getElementsByTagName("body")[0].appendChild(i),document.getElementsByTagName("body")[0].appendChild(n),document.getElementById("debugger-applog-web").addEventListener("click",(function(){(window.opener||window.parent).postMessage({type:"devtool:web:open-draw"},location.origin)}))},t}(),X=d((function(t,e){(function(){var e;function i(t,e,i){null!=t&&("number"==typeof t?this.fromNumber(t,e,i):null==e&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,e))}function n(){return new i(null)}var o="undefined"!=typeof navigator;o&&"Microsoft Internet Explorer"==navigator.appName?(i.prototype.am=function(t,e,i,n,o,r){for(var s=32767&e,a=e>>15;--r>=0;){var c=32767&this[t],h=this[t++]>>15,u=a*c+h*s;o=((c=s*c+((32767&u)<<15)+i[n]+(1073741823&o))>>>30)+(u>>>15)+a*h+(o>>>30),i[n++]=1073741823&c}return o},e=30):o&&"Netscape"!=navigator.appName?(i.prototype.am=function(t,e,i,n,o,r){for(;--r>=0;){var s=e*this[t++]+i[n]+o;o=Math.floor(s/67108864),i[n++]=67108863&s}return o},e=26):(i.prototype.am=function(t,e,i,n,o,r){for(var s=16383&e,a=e>>14;--r>=0;){var c=16383&this[t],h=this[t++]>>14,u=a*c+h*s;o=((c=s*c+((16383&u)<<14)+i[n]+o)>>28)+(u>>14)+a*h,i[n++]=268435455&c}return o},e=28),i.prototype.DB=e,i.prototype.DM=(1<<e)-1,i.prototype.DV=1<<e;i.prototype.FV=Math.pow(2,52),i.prototype.F1=52-e,i.prototype.F2=2*e-52;var r,s,a=new Array;for(r="0".charCodeAt(0),s=0;s<=9;++s)a[r++]=s;for(r="a".charCodeAt(0),s=10;s<36;++s)a[r++]=s;for(r="A".charCodeAt(0),s=10;s<36;++s)a[r++]=s;function c(t){return"0123456789abcdefghijklmnopqrstuvwxyz".charAt(t)}function h(t,e){var i=a[t.charCodeAt(e)];return null==i?-1:i}function u(t){var e=n();return e.fromInt(t),e}function f(t){var e,i=1;return 0!=(e=t>>>16)&&(t=e,i+=16),0!=(e=t>>8)&&(t=e,i+=8),0!=(e=t>>4)&&(t=e,i+=4),0!=(e=t>>2)&&(t=e,i+=2),0!=(e=t>>1)&&(t=e,i+=1),i}function l(t){this.m=t}function p(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<t.DB-15)-1,this.mt2=2*t.t}function d(t,e){return t&e}function g(t,e){return t|e}function m(t,e){return t^e}function y(t,e){return t&~e}function v(t){if(0==t)return-1;var e=0;return 0==(65535&t)&&(t>>=16,e+=16),0==(255&t)&&(t>>=8,e+=8),0==(15&t)&&(t>>=4,e+=4),0==(3&t)&&(t>>=2,e+=2),0==(1&t)&&++e,e}function _(t){for(var e=0;0!=t;)t&=t-1,++e;return e}function b(){}function E(t){return t}function w(t){this.r2=n(),this.q3=n(),i.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}l.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},l.prototype.revert=function(t){return t},l.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},l.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},l.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},p.prototype.convert=function(t){var e=n();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(i.ZERO)>0&&this.m.subTo(e,e),e},p.prototype.revert=function(t){var e=n();return t.copyTo(e),this.reduce(e),e},p.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e<this.m.t;++e){var i=32767&t[e],n=i*this.mpl+((i*this.mph+(t[e]>>15)*this.mpl&this.um)<<15)&t.DM;for(t[i=e+this.m.t]+=this.m.am(0,n,t,e,0,this.m.t);t[i]>=t.DV;)t[i]-=t.DV,t[++i]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},p.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},p.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},i.prototype.copyTo=function(t){for(var e=this.t-1;e>=0;--e)t[e]=this[e];t.t=this.t,t.s=this.s},i.prototype.fromInt=function(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0},i.prototype.fromString=function(t,e){var n;if(16==e)n=4;else if(8==e)n=3;else if(256==e)n=8;else if(2==e)n=1;else if(32==e)n=5;else{if(4!=e)return void this.fromRadix(t,e);n=2}this.t=0,this.s=0;for(var o=t.length,r=!1,s=0;--o>=0;){var a=8==n?255&t[o]:h(t,o);a<0?"-"==t.charAt(o)&&(r=!0):(r=!1,0==s?this[this.t++]=a:s+n>this.DB?(this[this.t-1]|=(a&(1<<this.DB-s)-1)<<s,this[this.t++]=a>>this.DB-s):this[this.t-1]|=a<<s,(s+=n)>=this.DB&&(s-=this.DB))}8==n&&0!=(128&t[0])&&(this.s=-1,s>0&&(this[this.t-1]|=(1<<this.DB-s)-1<<s)),this.clamp(),r&&i.ZERO.subTo(this,this)},i.prototype.clamp=function(){for(var t=this.s&this.DM;this.t>0&&this[this.t-1]==t;)--this.t},i.prototype.dlShiftTo=function(t,e){var i;for(i=this.t-1;i>=0;--i)e[i+t]=this[i];for(i=t-1;i>=0;--i)e[i]=0;e.t=this.t+t,e.s=this.s},i.prototype.drShiftTo=function(t,e){for(var i=t;i<this.t;++i)e[i-t]=this[i];e.t=Math.max(this.t-t,0),e.s=this.s},i.prototype.lShiftTo=function(t,e){var i,n=t%this.DB,o=this.DB-n,r=(1<<o)-1,s=Math.floor(t/this.DB),a=this.s<<n&this.DM;for(i=this.t-1;i>=0;--i)e[i+s+1]=this[i]>>o|a,a=(this[i]&r)<<n;for(i=s-1;i>=0;--i)e[i]=0;e[s]=a,e.t=this.t+s+1,e.s=this.s,e.clamp()},i.prototype.rShiftTo=function(t,e){e.s=this.s;var i=Math.floor(t/this.DB);if(i>=this.t)e.t=0;else{var n=t%this.DB,o=this.DB-n,r=(1<<n)-1;e[0]=this[i]>>n;for(var s=i+1;s<this.t;++s)e[s-i-1]|=(this[s]&r)<<o,e[s-i]=this[s]>>n;n>0&&(e[this.t-i-1]|=(this.s&r)<<o),e.t=this.t-i,e.clamp()}},i.prototype.subTo=function(t,e){for(var i=0,n=0,o=Math.min(t.t,this.t);i<o;)n+=this[i]-t[i],e[i++]=n&this.DM,n>>=this.DB;if(t.t<this.t){for(n-=t.s;i<this.t;)n+=this[i],e[i++]=n&this.DM,n>>=this.DB;n+=this.s}else{for(n+=this.s;i<t.t;)n-=t[i],e[i++]=n&this.DM,n>>=this.DB;n-=t.s}e.s=n<0?-1:0,n<-1?e[i++]=this.DV+n:n>0&&(e[i++]=n),e.t=i,e.clamp()},i.prototype.multiplyTo=function(t,e){var n=this.abs(),o=t.abs(),r=n.t;for(e.t=r+o.t;--r>=0;)e[r]=0;for(r=0;r<o.t;++r)e[r+n.t]=n.am(0,o[r],e,r,0,n.t);e.s=0,e.clamp(),this.s!=t.s&&i.ZERO.subTo(e,e)},i.prototype.squareTo=function(t){for(var e=this.abs(),i=t.t=2*e.t;--i>=0;)t[i]=0;for(i=0;i<e.t-1;++i){var n=e.am(i,e[i],t,2*i,0,1);(t[i+e.t]+=e.am(i+1,2*e[i],t,2*i+1,n,e.t-i-1))>=e.DV&&(t[i+e.t]-=e.DV,t[i+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(i,e[i],t,2*i,0,1)),t.s=0,t.clamp()},i.prototype.divRemTo=function(t,e,o){var r=t.abs();if(!(r.t<=0)){var s=this.abs();if(s.t<r.t)return null!=e&&e.fromInt(0),void(null!=o&&this.copyTo(o));null==o&&(o=n());var a=n(),c=this.s,h=t.s,u=this.DB-f(r[r.t-1]);u>0?(r.lShiftTo(u,a),s.lShiftTo(u,o)):(r.copyTo(a),s.copyTo(o));var l=a.t,p=a[l-1];if(0!=p){var d=p*(1<<this.F1)+(l>1?a[l-2]>>this.F2:0),g=this.FV/d,m=(1<<this.F1)/d,y=1<<this.F2,v=o.t,_=v-l,b=null==e?n():e;for(a.dlShiftTo(_,b),o.compareTo(b)>=0&&(o[o.t++]=1,o.subTo(b,o)),i.ONE.dlShiftTo(l,b),b.subTo(a,a);a.t<l;)a[a.t++]=0;for(;--_>=0;){var E=o[--v]==p?this.DM:Math.floor(o[v]*g+(o[v-1]+y)*m);if((o[v]+=a.am(0,E,o,_,0,l))<E)for(a.dlShiftTo(_,b),o.subTo(b,o);o[v]<--E;)o.subTo(b,o)}null!=e&&(o.drShiftTo(l,e),c!=h&&i.ZERO.subTo(e,e)),o.t=l,o.clamp(),u>0&&o.rShiftTo(u,o),c<0&&i.ZERO.subTo(o,o)}}},i.prototype.invDigit=function(){if(this.t<1)return 0;var t=this[0];if(0==(1&t))return 0;var e=3&t;return(e=(e=(e=(e=e*(2-(15&t)*e)&15)*(2-(255&t)*e)&255)*(2-((65535&t)*e&65535))&65535)*(2-t*e%this.DV)%this.DV)>0?this.DV-e:-e},i.prototype.isEven=function(){return 0==(this.t>0?1&this[0]:this.s)},i.prototype.exp=function(t,e){if(t>4294967295||t<1)return i.ONE;var o=n(),r=n(),s=e.convert(this),a=f(t)-1;for(s.copyTo(o);--a>=0;)if(e.sqrTo(o,r),(t&1<<a)>0)e.mulTo(r,s,o);else{var c=o;o=r,r=c}return e.revert(o)},i.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var e;if(16==t)e=4;else if(8==t)e=3;else if(2==t)e=1;else if(32==t)e=5;else{if(4!=t)return this.toRadix(t);e=2}var i,n=(1<<e)-1,o=!1,r="",s=this.t,a=this.DB-s*this.DB%e;if(s-- >0)for(a<this.DB&&(i=this[s]>>a)>0&&(o=!0,r=c(i));s>=0;)a<e?(i=(this[s]&(1<<a)-1)<<e-a,i|=this[--s]>>(a+=this.DB-e)):(i=this[s]>>(a-=e)&n,a<=0&&(a+=this.DB,--s)),i>0&&(o=!0),o&&(r+=c(i));return o?r:"0"},i.prototype.negate=function(){var t=n();return i.ZERO.subTo(this,t),t},i.prototype.abs=function(){return this.s<0?this.negate():this},i.prototype.compareTo=function(t){var e=this.s-t.s;if(0!=e)return e;var i=this.t;if(0!=(e=i-t.t))return this.s<0?-e:e;for(;--i>=0;)if(0!=(e=this[i]-t[i]))return e;return 0},i.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+f(this[this.t-1]^this.s&this.DM)},i.prototype.mod=function(t){var e=n();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(i.ZERO)>0&&t.subTo(e,e),e},i.prototype.modPowInt=function(t,e){var i;return i=t<256||e.isEven()?new l(e):new p(e),this.exp(t,i)},i.ZERO=u(0),i.ONE=u(1),b.prototype.convert=E,b.prototype.revert=E,b.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i)},b.prototype.sqrTo=function(t,e){t.squareTo(e)},w.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var e=n();return t.copyTo(e),this.reduce(e),e},w.prototype.revert=function(t){return t},w.prototype.reduce=function(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)},w.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},w.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)};var S,T,D,k=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],A=(1<<26)/k[k.length-1];function I(){var t;t=(new Date).getTime(),T[D++]^=255&t,T[D++]^=t>>8&255,T[D++]^=t>>16&255,T[D++]^=t>>24&255,D>=R&&(D-=R)}if(i.prototype.chunkSize=function(t){return Math.floor(Math.LN2*this.DB/Math.log(t))},i.prototype.toRadix=function(t){if(null==t&&(t=10),0==this.signum()||t<2||t>36)return"0";var e=this.chunkSize(t),i=Math.pow(t,e),o=u(i),r=n(),s=n(),a="";for(this.divRemTo(o,r,s);r.signum()>0;)a=(i+s.intValue()).toString(t).substr(1)+a,r.divRemTo(o,r,s);return s.intValue().toString(t)+a},i.prototype.fromRadix=function(t,e){this.fromInt(0),null==e&&(e=10);for(var n=this.chunkSize(e),o=Math.pow(e,n),r=!1,s=0,a=0,c=0;c<t.length;++c){var u=h(t,c);u<0?"-"==t.charAt(c)&&0==this.signum()&&(r=!0):(a=e*a+u,++s>=n&&(this.dMultiply(o),this.dAddOffset(a,0),s=0,a=0))}s>0&&(this.dMultiply(Math.pow(e,s)),this.dAddOffset(a,0)),r&&i.ZERO.subTo(this,this)},i.prototype.fromNumber=function(t,e,n){if("number"==typeof e)if(t<2)this.fromInt(1);else for(this.fromNumber(t,n),this.testBit(t-1)||this.bitwiseTo(i.ONE.shiftLeft(t-1),g,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(e);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(i.ONE.shiftLeft(t-1),this);else{var o=new Array,r=7&t;o.length=1+(t>>3),e.nextBytes(o),r>0?o[0]&=(1<<r)-1:o[0]=0,this.fromString(o,256)}},i.prototype.bitwiseTo=function(t,e,i){var n,o,r=Math.min(t.t,this.t);for(n=0;n<r;++n)i[n]=e(this[n],t[n]);if(t.t<this.t){for(o=t.s&this.DM,n=r;n<this.t;++n)i[n]=e(this[n],o);i.t=this.t}else{for(o=this.s&this.DM,n=r;n<t.t;++n)i[n]=e(o,t[n]);i.t=t.t}i.s=e(this.s,t.s),i.clamp()},i.prototype.changeBit=function(t,e){var n=i.ONE.shiftLeft(t);return this.bitwiseTo(n,e,n),n},i.prototype.addTo=function(t,e){for(var i=0,n=0,o=Math.min(t.t,this.t);i<o;)n+=this[i]+t[i],e[i++]=n&this.DM,n>>=this.DB;if(t.t<this.t){for(n+=t.s;i<this.t;)n+=this[i],e[i++]=n&this.DM,n>>=this.DB;n+=this.s}else{for(n+=this.s;i<t.t;)n+=t[i],e[i++]=n&this.DM,n>>=this.DB;n+=t.s}e.s=n<0?-1:0,n>0?e[i++]=n:n<-1&&(e[i++]=this.DV+n),e.t=i,e.clamp()},i.prototype.dMultiply=function(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()},i.prototype.dAddOffset=function(t,e){if(0!=t){for(;this.t<=e;)this[this.t++]=0;for(this[e]+=t;this[e]>=this.DV;)this[e]-=this.DV,++e>=this.t&&(this[this.t++]=0),++this[e]}},i.prototype.multiplyLowerTo=function(t,e,i){var n,o=Math.min(this.t+t.t,e);for(i.s=0,i.t=o;o>0;)i[--o]=0;for(n=i.t-this.t;o<n;++o)i[o+this.t]=this.am(0,t[o],i,o,0,this.t);for(n=Math.min(t.t,e);o<n;++o)this.am(0,t[o],i,o,0,e-o);i.clamp()},i.prototype.multiplyUpperTo=function(t,e,i){--e;var n=i.t=this.t+t.t-e;for(i.s=0;--n>=0;)i[n]=0;for(n=Math.max(e-this.t,0);n<t.t;++n)i[this.t+n-e]=this.am(e-n,t[n],i,0,0,this.t+n-e);i.clamp(),i.drShiftTo(1,i)},i.prototype.modInt=function(t){if(t<=0)return 0;var e=this.DV%t,i=this.s<0?t-1:0;if(this.t>0)if(0==e)i=this[0]%t;else for(var n=this.t-1;n>=0;--n)i=(e*i+this[n])%t;return i},i.prototype.millerRabin=function(t){var e=this.subtract(i.ONE),o=e.getLowestSetBit();if(o<=0)return!1;var r=e.shiftRight(o);(t=t+1>>1)>k.length&&(t=k.length);for(var s=n(),a=0;a<t;++a){s.fromInt(k[Math.floor(Math.random()*k.length)]);var c=s.modPow(r,this);if(0!=c.compareTo(i.ONE)&&0!=c.compareTo(e)){for(var h=1;h++<o&&0!=c.compareTo(e);)if(0==(c=c.modPowInt(2,this)).compareTo(i.ONE))return!1;if(0!=c.compareTo(e))return!1}}return!0},i.prototype.clone=function(){var t=n();return this.copyTo(t),t},i.prototype.intValue=function(){if(this.s<0){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]},i.prototype.byteValue=function(){return 0==this.t?this.s:this[0]<<24>>24},i.prototype.shortValue=function(){return 0==this.t?this.s:this[0]<<16>>16},i.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1},i.prototype.toByteArray=function(){var t=this.t,e=new Array;e[0]=this.s;var i,n=this.DB-t*this.DB%8,o=0;if(t-- >0)for(n<this.DB&&(i=this[t]>>n)!=(this.s&this.DM)>>n&&(e[o++]=i|this.s<<this.DB-n);t>=0;)n<8?(i=(this[t]&(1<<n)-1)<<8-n,i|=this[--t]>>(n+=this.DB-8)):(i=this[t]>>(n-=8)&255,n<=0&&(n+=this.DB,--t)),0!=(128&i)&&(i|=-256),0==o&&(128&this.s)!=(128&i)&&++o,(o>0||i!=this.s)&&(e[o++]=i);return e},i.prototype.equals=function(t){return 0==this.compareTo(t)},i.prototype.min=function(t){return this.compareTo(t)<0?this:t},i.prototype.max=function(t){return this.compareTo(t)>0?this:t},i.prototype.and=function(t){var e=n();return this.bitwiseTo(t,d,e),e},i.prototype.or=function(t){var e=n();return this.bitwiseTo(t,g,e),e},i.prototype.xor=function(t){var e=n();return this.bitwiseTo(t,m,e),e},i.prototype.andNot=function(t){var e=n();return this.bitwiseTo(t,y,e),e},i.prototype.not=function(){for(var t=n(),e=0;e<this.t;++e)t[e]=this.DM&~this[e];return t.t=this.t,t.s=~this.s,t},i.prototype.shiftLeft=function(t){var e=n();return t<0?this.rShiftTo(-t,e):this.lShiftTo(t,e),e},i.prototype.shiftRight=function(t){var e=n();return t<0?this.lShiftTo(-t,e):this.rShiftTo(t,e),e},i.prototype.getLowestSetBit=function(){for(var t=0;t<this.t;++t)if(0!=this[t])return t*this.DB+v(this[t]);return this.s<0?this.t*this.DB:-1},i.prototype.bitCount=function(){for(var t=0,e=this.s&this.DM,i=0;i<this.t;++i)t+=_(this[i]^e);return t},i.prototype.testBit=function(t){var e=Math.floor(t/this.DB);return e>=this.t?0!=this.s:0!=(this[e]&1<<t%this.DB)},i.prototype.setBit=function(t){return this.changeBit(t,g)},i.prototype.clearBit=function(t){return this.changeBit(t,y)},i.prototype.flipBit=function(t){return this.changeBit(t,m)},i.prototype.add=function(t){var e=n();return this.addTo(t,e),e},i.prototype.subtract=function(t){var e=n();return this.subTo(t,e),e},i.prototype.multiply=function(t){var e=n();return this.multiplyTo(t,e),e},i.prototype.divide=function(t){var e=n();return this.divRemTo(t,e,null),e},i.prototype.remainder=function(t){var e=n();return this.divRemTo(t,null,e),e},i.prototype.divideAndRemainder=function(t){var e=n(),i=n();return this.divRemTo(t,e,i),new Array(e,i)},i.prototype.modPow=function(t,e){var i,o,r=t.bitLength(),s=u(1);if(r<=0)return s;i=r<18?1:r<48?3:r<144?4:r<768?5:6,o=r<8?new l(e):e.isEven()?new w(e):new p(e);var a=new Array,c=3,h=i-1,d=(1<<i)-1;if(a[1]=o.convert(this),i>1){var g=n();for(o.sqrTo(a[1],g);c<=d;)a[c]=n(),o.mulTo(g,a[c-2],a[c]),c+=2}var m,y,v=t.t-1,_=!0,b=n();for(r=f(t[v])-1;v>=0;){for(r>=h?m=t[v]>>r-h&d:(m=(t[v]&(1<<r+1)-1)<<h-r,v>0&&(m|=t[v-1]>>this.DB+r-h)),c=i;0==(1&m);)m>>=1,--c;if((r-=c)<0&&(r+=this.DB,--v),_)a[m].copyTo(s),_=!1;else{for(;c>1;)o.sqrTo(s,b),o.sqrTo(b,s),c-=2;c>0?o.sqrTo(s,b):(y=s,s=b,b=y),o.mulTo(b,a[m],s)}for(;v>=0&&0==(t[v]&1<<r);)o.sqrTo(s,b),y=s,s=b,b=y,--r<0&&(r=this.DB-1,--v)}return o.revert(s)},i.prototype.modInverse=function(t){var e=t.isEven();if(this.isEven()&&e||0==t.signum())return i.ZERO;for(var n=t.clone(),o=this.clone(),r=u(1),s=u(0),a=u(0),c=u(1);0!=n.signum();){for(;n.isEven();)n.rShiftTo(1,n),e?(r.isEven()&&s.isEven()||(r.addTo(this,r),s.subTo(t,s)),r.rShiftTo(1,r)):s.isEven()||s.subTo(t,s),s.rShiftTo(1,s);for(;o.isEven();)o.rShiftTo(1,o),e?(a.isEven()&&c.isEven()||(a.addTo(this,a),c.subTo(t,c)),a.rShiftTo(1,a)):c.isEven()||c.subTo(t,c),c.rShiftTo(1,c);n.compareTo(o)>=0?(n.subTo(o,n),e&&r.subTo(a,r),s.subTo(c,s)):(o.subTo(n,o),e&&a.subTo(r,a),c.subTo(s,c))}return 0!=o.compareTo(i.ONE)?i.ZERO:c.compareTo(t)>=0?c.subtract(t):c.signum()<0?(c.addTo(t,c),c.signum()<0?c.add(t):c):c},i.prototype.pow=function(t){return this.exp(t,new b)},i.prototype.gcd=function(t){var e=this.s<0?this.negate():this.clone(),i=t.s<0?t.negate():t.clone();if(e.compareTo(i)<0){var n=e;e=i,i=n}var o=e.getLowestSetBit(),r=i.getLowestSetBit();if(r<0)return e;for(o<r&&(r=o),r>0&&(e.rShiftTo(r,e),i.rShiftTo(r,i));e.signum()>0;)(o=e.getLowestSetBit())>0&&e.rShiftTo(o,e),(o=i.getLowestSetBit())>0&&i.rShiftTo(o,i),e.compareTo(i)>=0?(e.subTo(i,e),e.rShiftTo(1,e)):(i.subTo(e,i),i.rShiftTo(1,i));return r>0&&i.lShiftTo(r,i),i},i.prototype.isProbablePrime=function(t){var e,i=this.abs();if(1==i.t&&i[0]<=k[k.length-1]){for(e=0;e<k.length;++e)if(i[0]==k[e])return!0;return!1}if(i.isEven())return!1;for(e=1;e<k.length;){for(var n=k[e],o=e+1;o<k.length&&n<A;)n*=k[o++];for(n=i.modInt(n);e<o;)if(n%k[e++]==0)return!1}return i.millerRabin(t)},i.prototype.square=function(){var t=n();return this.squareTo(t),t},i.prototype.Barrett=w,null==T){var B;if(T=new Array,D=0,"undefined"!=typeof window&&window.crypto)if(window.crypto.getRandomValues){var x=new Uint8Array(32);for(window.crypto.getRandomValues(x),B=0;B<32;++B)T[D++]=x[B]}else if("Netscape"==navigator.appName&&navigator.appVersion<"5"){var M=window.crypto.random(32);for(B=0;B<M.length;++B)T[D++]=255&M.charCodeAt(B)}for(;D<R;)B=Math.floor(65536*Math.random()),T[D++]=B>>>8,T[D++]=255&B;D=0,I()}function O(){if(null==S){for(I(),(S=new G).init(T),D=0;D<T.length;++D)T[D]=0;D=0}return S.next()}function C(){}function G(){this.i=0,this.j=0,this.S=new Array}C.prototype.nextBytes=function(t){var e;for(e=0;e<t.length;++e)t[e]=O()},G.prototype.init=function(t){var e,i,n;for(e=0;e<256;++e)this.S[e]=e;for(i=0,e=0;e<256;++e)i=i+this.S[e]+t[e%t.length]&255,n=this.S[e],this.S[e]=this.S[i],this.S[i]=n;this.i=0,this.j=0},G.prototype.next=function(){var t;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,t=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=t,this.S[t+this.S[this.i]&255]};var R=256;t.exports={default:i,BigInteger:i,SecureRandom:C}}).call(p)}));X.BigInteger,X.SecureRandom;const{BigInteger:$}=X;class Q{constructor(){this.tlv=null,this.t="00",this.l="00",this.v=""}getEncodedHex(){return this.tlv||(this.v=this.getValue(),this.l=this.getLength(),this.tlv=this.t+this.l+this.v),this.tlv}getLength(){const t=this.v.length/2;let e=t.toString(16);if(e.length%2==1&&(e="0"+e),t<128)return e;return(128+e.length/2).toString(16)+e}getValue(){return""}}class Y extends Q{constructor(t){super(),this.t="02",t&&(this.v=function(t){let e=t.toString(16);if("-"!==e[0])e.length%2==1?e="0"+e:e.match(/^[0-7]/)||(e="00"+e);else{e=e.substr(1);let i=e.length;i%2==1?i+=1:e.match(/^[0-7]/)||(i+=2);let n="";for(let t=0;t<i;t++)n+="f";n=new $(n,16),e=n.xor(t).add($.ONE),e=e.toString(16).replace(/^-/,"")}return e}(t))}getValue(){return this.v}}class tt extends Q{constructor(t){super(),this.t="30",this.asn1Array=t}getValue(){return this.v=this.asn1Array.map((t=>t.getEncodedHex())).join(""),this.v}}function et(t,e){return+t[e+2]<8?1:128&+t.substr(e+2,2)}function it(t,e){const i=et(t,e),n=t.substr(e+2,2*i);if(!n)return-1;return(+n[0]<8?new $(n,16):new $(n.substr(2),16)).intValue()}function nt(t,e){return e+2*(et(t,e)+1)}var ot={encodeDer(t,e){const i=new Y(t),n=new Y(e);return new tt([i,n]).getEncodedHex()},decodeDer(t){const e=nt(t,0),i=nt(t,e),n=it(t,e),o=t.substr(i,2*n),r=i+o.length,s=nt(t,r),a=it(t,r),c=t.substr(s,2*a);return{r:new $(o,16),s:new $(c,16)}}};const{BigInteger:rt}=X,st=new rt("2"),at=new rt("3");class ct{constructor(t,e){this.x=e,this.q=t}equals(t){return t===this||this.q.equals(t.q)&&this.x.equals(t.x)}toBigInteger(){return this.x}negate(){return new ct(this.q,this.x.negate().mod(this.q))}add(t){return new ct(this.q,this.x.add(t.toBigInteger()).mod(this.q))}subtract(t){return new ct(this.q,this.x.subtract(t.toBigInteger()).mod(this.q))}multiply(t){return new ct(this.q,this.x.multiply(t.toBigInteger()).mod(this.q))}divide(t){return new ct(this.q,this.x.multiply(t.toBigInteger().modInverse(this.q)).mod(this.q))}square(){return new ct(this.q,this.x.square().mod(this.q))}}class ht{constructor(t,e,i,n){this.curve=t,this.x=e,this.y=i,this.z=null==n?rt.ONE:n,this.zinv=null}getX(){return null===this.zinv&&(this.zinv=this.z.modInverse(this.curve.q)),this.curve.fromBigInteger(this.x.toBigInteger().multiply(this.zinv).mod(this.curve.q))}getY(){return null===this.zinv&&(this.zinv=this.z.modInverse(this.curve.q)),this.curve.fromBigInteger(this.y.toBigInteger().multiply(this.zinv).mod(this.curve.q))}equals(t){if(t===this)return!0;if(this.isInfinity())return t.isInfinity();if(t.isInfinity())return this.isInfinity();if(!t.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(t.z)).mod(this.curve.q).equals(rt.ZERO))return!1;return t.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(t.z)).mod(this.curve.q).equals(rt.ZERO)}isInfinity(){return null===this.x&&null===this.y||this.z.equals(rt.ZERO)&&!this.y.toBigInteger().equals(rt.ZERO)}negate(){return new ht(this.curve,this.x,this.y.negate(),this.z)}add(t){if(this.isInfinity())return t;if(t.isInfinity())return this;const e=this.x.toBigInteger(),i=this.y.toBigInteger(),n=this.z,o=t.x.toBigInteger(),r=t.y.toBigInteger(),s=t.z,a=this.curve.q,c=e.multiply(s).mod(a),h=o.multiply(n).mod(a),u=c.subtract(h),f=i.multiply(s).mod(a),l=r.multiply(n).mod(a),p=f.subtract(l);if(rt.ZERO.equals(u))return rt.ZERO.equals(p)?this.twice():this.curve.infinity;const d=c.add(h),g=n.multiply(s).mod(a),m=u.square().mod(a),y=u.multiply(m).mod(a),v=g.multiply(p.square()).subtract(d.multiply(m)).mod(a),_=u.multiply(v).mod(a),b=p.multiply(m.multiply(c).subtract(v)).subtract(f.multiply(y)).mod(a),E=y.multiply(g).mod(a);return new ht(this.curve,this.curve.fromBigInteger(_),this.curve.fromBigInteger(b),E)}twice(){if(this.isInfinity())return this;if(!this.y.toBigInteger().signum())return this.curve.infinity;const t=this.x.toBigInteger(),e=this.y.toBigInteger(),i=this.z,n=this.curve.q,o=this.curve.a.toBigInteger(),r=t.square().multiply(at).add(o.multiply(i.square())).mod(n),s=e.shiftLeft(1).multiply(i).mod(n),a=e.square().mod(n),c=a.multiply(t).multiply(i).mod(n),h=s.square().mod(n),u=r.square().subtract(c.shiftLeft(3)).mod(n),f=s.multiply(u).mod(n),l=r.multiply(c.shiftLeft(2).subtract(u)).subtract(h.shiftLeft(1).multiply(a)).mod(n),p=s.multiply(h).mod(n);return new ht(this.curve,this.curve.fromBigInteger(f),this.curve.fromBigInteger(l),p)}multiply(t){if(this.isInfinity())return this;if(!t.signum())return this.curve.infinity;const e=t.multiply(at),i=this.negate();let n=this;for(let o=e.bitLength()-2;o>0;o--){n=n.twice();const r=e.testBit(o);r!==t.testBit(o)&&(n=n.add(r?this:i))}return n}}var ut={ECPointFp:ht,ECCurveFp:class{constructor(t,e,i){this.q=t,this.a=this.fromBigInteger(e),this.b=this.fromBigInteger(i),this.infinity=new ht(this,null,null)}equals(t){return t===this||this.q.equals(t.q)&&this.a.equals(t.a)&&this.b.equals(t.b)}fromBigInteger(t){return new ct(this.q,t)}decodePointHex(t){switch(parseInt(t.substr(0,2),16)){case 0:return this.infinity;case 2:case 3:const e=this.fromBigInteger(new rt(t.substr(2),16));let i=this.fromBigInteger(e.multiply(e.square()).add(e.multiply(this.a)).add(this.b).toBigInteger().modPow(this.q.divide(new rt("4")).add(rt.ONE),this.q));return i.toBigInteger().mod(st).equals(new rt(t.substr(0,2),16).subtract(st))||(i=i.negate()),new ht(this,e,i);case 4:case 6:case 7:const n=(t.length-2)/2,o=t.substr(2,n),r=t.substr(n+2,n);return new ht(this,this.fromBigInteger(new rt(o,16)),this.fromBigInteger(new rt(r,16)));default:return null}}}};const{BigInteger:ft,SecureRandom:lt}=X,{ECCurveFp:pt}=ut,dt=new lt,{curve:gt,G:mt,n:yt}=vt();function vt(){const t=new ft("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF",16),e=new ft("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC",16),i=new ft("28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93",16),n=new pt(t,e,i),o=n.decodePointHex("0432C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0");return{curve:n,G:o,n:new ft("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123",16)}}function _t(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t}var bt={getGlobalCurve:function(){return gt},generateEcparam:vt,generateKeyPairHex:function(t,e,i){const n=(t?new ft(t,e,i):new ft(yt.bitLength(),dt)).mod(yt.subtract(ft.ONE)).add(ft.ONE),o=_t(n.toString(16),64),r=mt.multiply(n);return{privateKey:o,publicKey:"04"+_t(r.getX().toBigInteger().toString(16),64)+_t(r.getY().toBigInteger().toString(16),64)}},compressPublicKeyHex:function(t){if(130!==t.length)throw new Error("Invalid public key to compress");const e=(t.length-2)/2,i=t.substr(2,e);let n="03";return new ft(t.substr(e+2,e),16).mod(new ft("2")).equals(ft.ZERO)&&(n="02"),n+i},utf8ToHex:function(t){const e=(t=unescape(encodeURIComponent(t))).length,i=[];for(let n=0;n<e;n++)i[n>>>2]|=(255&t.charCodeAt(n))<<24-n%4*8;const n=[];for(let t=0;t<e;t++){const e=i[t>>>2]>>>24-t%4*8&255;n.push((e>>>4).toString(16)),n.push((15&e).toString(16))}return n.join("")},leftPad:_t,arrayToHex:function(t){return t.map((t=>1===(t=t.toString(16)).length?"0"+t:t)).join("")},arrayToUtf8:function(t){const e=[];let i=0;for(let n=0;n<2*t.length;n+=2)e[n>>>3]|=parseInt(t[i],10)<<24-n%8*4,i++;try{const i=[];for(let n=0;n<t.length;n++){const t=e[n>>>2]>>>24-n%4*8&255;i.push(String.fromCharCode(t))}return decodeURIComponent(escape(i.join("")))}catch(t){throw new Error("Malformed UTF-8 data")}},hexToArray:function(t){const e=[];let i=t.length;i%2!=0&&(t=_t(t,i+1)),i=t.length;for(let n=0;n<i;n+=2)e.push(parseInt(t.substr(n,2),16));return e},verifyPublicKey:function(t){const e=gt.decodePointHex(t);if(!e)return!1;const i=e.getX();return e.getY().square().equals(i.multiply(i.square()).add(i.multiply(gt.a)).add(gt.b))},comparePublicKeyHex:function(t,e){const i=gt.decodePointHex(t);if(!i)return!1;const n=gt.decodePointHex(e);return!!n&&i.equals(n)}};const Et=new Uint32Array(68),wt=new Uint32Array(64);function St(t,e){const i=31&e;return t<<i|t>>>32-i}function Tt(t,e){const i=[];for(let n=t.length-1;n>=0;n--)i[n]=255&(t[n]^e[n]);return i}function Dt(t){return t^St(t,9)^St(t,17)}function kt(t){let e=8*t.length,i=e%512;i=i>=448?512-i%448-1:448-i-1;const n=new Array((i-7)/8),o=new Array(8);for(let t=0,e=n.length;t<e;t++)n[t]=0;for(let t=0,e=o.length;t<e;t++)o[t]=0;e=e.toString(2);for(let t=7;t>=0;t--)if(e.length>8){const i=e.length-8;o[t]=parseInt(e.substr(i),2),e=e.substr(0,i)}else e.length>0&&(o[t]=parseInt(e,2),e="");const r=new Uint8Array([...t,128,...n,...o]),s=new DataView(r.buffer,0),a=r.length/64,c=new Uint32Array([1937774191,1226093241,388252375,3666478592,2842636476,372324522,3817729613,2969243214]);for(let t=0;t<a;t++){Et.fill(0),wt.fill(0);const e=16*t;for(let t=0;t<16;t++)Et[t]=s.getUint32(4*(e+t),!1);for(let t=16;t<68;t++)Et[t]=(h=Et[t-16]^Et[t-9]^St(Et[t-3],15))^St(h,15)^St(h,23)^St(Et[t-13],7)^Et[t-6];for(let t=0;t<64;t++)wt[t]=Et[t]^Et[t+4];const i=2043430169,n=2055708042;let o,r,a,u,f,l=c[0],p=c[1],d=c[2],g=c[3],m=c[4],y=c[5],v=c[6],_=c[7];for(let t=0;t<64;t++)f=t>=0&&t<=15?i:n,o=St(St(l,12)+m+St(f,t),7),r=o^St(l,12),a=(t>=0&&t<=15?l^p^d:l&p|l&d|p&d)+g+r+wt[t],u=(t>=0&&t<=15?m^y^v:m&y|~m&v)+_+o+Et[t],g=d,d=St(p,9),p=l,l=a,_=v,v=St(y,19),y=m,m=Dt(u);c[0]^=l,c[1]^=p,c[2]^=d,c[3]^=g,c[4]^=m,c[5]^=y,c[6]^=v,c[7]^=_}var h;const u=[];for(let t=0,e=c.length;t<e;t++){const e=c[t];u.push((4278190080&e)>>>24,(16711680&e)>>>16,(65280&e)>>>8,255&e)}return u}const At=new Uint8Array(64),It=new Uint8Array(64);for(let t=0;t<64;t++)At[t]=54,It[t]=92;var Bt={sm3:kt,hmac:function(t,e){for(e.length>64&&(e=kt(e));e.length<64;)e.push(0);const i=Tt(e,At),n=Tt(e,It),o=kt([...i,...t]);return kt([...n,...o])}};const{BigInteger:xt}=X,{encodeDer:Mt,decodeDer:Ot}=ot,Ct=Bt.sm3,{G:Gt,curve:Rt,n:Ft}=bt.generateEcparam();function zt(t,e,i="1234567812345678"){i=bt.utf8ToHex(i);const n=bt.leftPad(Gt.curve.a.toBigInteger().toRadix(16),64),o=bt.leftPad(Gt.curve.b.toBigInteger().toRadix(16),64),r=bt.leftPad(Gt.getX().toBigInteger().toRadix(16),64),s=bt.leftPad(Gt.getY().toBigInteger().toRadix(16),64);let a,c;if(128===e.length)a=e.substr(0,64),c=e.substr(64,64);else{const t=Gt.curve.decodePointHex(e);a=bt.leftPad(t.getX().toBigInteger().toRadix(16),64),c=bt.leftPad(t.getY().toBigInteger().toRadix(16),64)}const h=bt.hexToArray(i+n+o+r+s+a+c),u=4*i.length;h.unshift(255&u),h.unshift(u>>8&255);const f=Ct(h);return bt.arrayToHex(Ct(f.concat(bt.hexToArray(t))))}function Pt(){const t=bt.generateKeyPairHex(),e=Rt.decodePointHex(t.publicKey);return t.k=new xt(t.privateKey,16),t.x1=e.getX().toBigInteger(),t}var qt={generateKeyPairHex:bt.generateKeyPairHex,compressPublicKeyHex:bt.compressPublicKeyHex,comparePublicKeyHex:bt.comparePublicKeyHex,doEncrypt:function(t,e,i=1){t="string"==typeof t?bt.hexToArray(bt.utf8ToHex(t)):Array.prototype.slice.call(t),e=bt.getGlobalCurve().decodePointHex(e);const n=bt.generateKeyPairHex(),o=new xt(n.privateKey,16);let r=n.publicKey;r.length>128&&(r=r.substr(r.length-128));const s=e.multiply(o),a=bt.hexToArray(bt.leftPad(s.getX().toBigInteger().toRadix(16),64)),c=bt.hexToArray(bt.leftPad(s.getY().toBigInteger().toRadix(16),64)),h=bt.arrayToHex(Ct([].concat(a,t,c)));let u=1,f=0,l=[];const p=[].concat(a,c),d=()=>{l=Ct([...p,u>>24&255,u>>16&255,u>>8&255,255&u]),u++,f=0};d();for(let e=0,i=t.length;e<i;e++)f===l.length&&d(),t[e]^=255&l[f++];const g=bt.arrayToHex(t);return 0===i?r+g+h:r+h+g},doDecrypt:function(t,e,i=1,{output:n="string"}={}){e=new xt(e,16);let o=t.substr(128,64),r=t.substr(192);0===i&&(o=t.substr(t.length-64),r=t.substr(128,t.length-128-64));const s=bt.hexToArray(r),a=bt.getGlobalCurve().decodePointHex("04"+t.substr(0,128)).multiply(e),c=bt.hexToArray(bt.leftPad(a.getX().toBigInteger().toRadix(16),64)),h=bt.hexToArray(bt.leftPad(a.getY().toBigInteger().toRadix(16),64));let u=1,f=0,l=[];const p=[].concat(c,h),d=()=>{l=Ct([...p,u>>24&255,u>>16&255,u>>8&255,255&u]),u++,f=0};d();for(let t=0,e=s.length;t<e;t++)f===l.length&&d(),s[t]^=255&l[f++];return bt.arrayToHex(Ct([].concat(c,s,h)))===o.toLowerCase()?"array"===n?s:bt.arrayToUtf8(s):"array"===n?[]:""},doSignature:function(t,e,{pointPool:i,der:n,hash:o,publicKey:r,userId:s}={}){let a="string"==typeof t?bt.utf8ToHex(t):bt.arrayToHex(t);o&&(r=r||function(t){const e=Gt.multiply(new xt(t,16)),i=bt.leftPad(e.getX().toBigInteger().toString(16),64),n=bt.leftPad(e.getY().toBigInteger().toString(16),64);return"04"+i+n}(e),a=zt(a,r,s));const c=new xt(e,16),h=new xt(a,16);let u=null,f=null,l=null;do{do{let t;t=i&&i.length?i.pop():Pt(),u=t.k,f=h.add(t.x1).mod(Ft)}while(f.equals(xt.ZERO)||f.add(u).equals(Ft));l=c.add(xt.ONE).modInverse(Ft).multiply(u.subtract(f.multiply(c))).mod(Ft)}while(l.equals(xt.ZERO));return n?Mt(f,l):bt.leftPad(f.toString(16),64)+bt.leftPad(l.toString(16),64)},doVerifySignature:function(t,e,i,{der:n,hash:o,userId:r}={}){let s,a,c="string"==typeof t?bt.utf8ToHex(t):bt.arrayToHex(t);if(o&&(c=zt(c,i,r)),n){const t=Ot(e);s=t.r,a=t.s}else s=new xt(e.substring(0,64),16),a=new xt(e.substring(64),16);const h=Rt.decodePointHex(i),u=new xt(c,16),f=s.add(a).mod(Ft);if(f.equals(xt.ZERO))return!1;const l=Gt.multiply(a).add(h.multiply(f)),p=u.add(l.getX().toBigInteger()).mod(Ft);return s.equals(p)},getPoint:Pt,verifyPublicKey:bt.verifyPublicKey};const{sm3:Ut,hmac:Nt}=Bt;function Vt(t){return t.map((t=>1===(t=t.toString(16)).length?"0"+t:t)).join("")}function Kt(t){const e=[];let i=t.length;var n,o;i%2!=0&&(o=i+1,t=(n=t).length>=o?n:new Array(o-n.length+1).join("0")+n),i=t.length;for(let n=0;n<i;n+=2)e.push(parseInt(t.substr(n,2),16));return e}const Lt=[214,144,233,254,204,225,61,183,22,182,20,194,40,251,44,5,43,103,154,118,42,190,4,195,170,68,19,38,73,134,6,153,156,66,80,244,145,239,152,122,51,84,11,67,237,207,172,98,228,179,28,169,201,8,232,149,128,223,148,250,117,143,63,166,71,7,167,252,243,115,23,186,131,89,60,25,230,133,79,168,104,107,129,178,113,100,218,139,248,235,15,75,112,86,157,53,30,36,14,94,99,88,209,162,37,34,124,59,1,33,120,135,212,0,70,87,159,211,39,82,76,54,2,231,160,196,200,158,234,191,138,210,64,199,56,181,163,247,242,206,249,97,21,161,224,174,93,164,155,52,26,85,173,147,50,48,245,140,177,227,29,246,226,46,130,102,202,96,192,41,35,171,13,83,78,111,213,219,55,69,222,253,142,47,3,255,106,114,109,108,91,81,141,27,175,146,187,221,188,127,17,217,92,65,31,16,90,216,10,193,49,136,165,205,123,189,45,116,208,18,184,229,180,176,137,105,151,74,12,150,119,126,101,185,241,9,197,110,198,132,24,240,125,236,58,220,77,32,121,238,95,62,215,203,57,72],jt=[462357,472066609,943670861,1415275113,1886879365,2358483617,2830087869,3301692121,3773296373,4228057617,404694573,876298825,1347903077,1819507329,2291111581,2762715833,3234320085,3705924337,4177462797,337322537,808926789,1280531041,1752135293,2223739545,2695343797,3166948049,3638552301,4110090761,269950501,741554753,1213159005,1684763257];function Ht(t){const e=[];for(let i=0,n=t.length;i<n;i+=2)e.push(parseInt(t.substr(i,2),16));return e}function Jt(t,e){return t<<e|t>>>32-e}function Wt(t){return(255&Lt[t>>>24&255])<<24|(255&Lt[t>>>16&255])<<16|(255&Lt[t>>>8&255])<<8|255&Lt[255&t]}function Zt(t){return t^Jt(t,2)^Jt(t,10)^Jt(t,18)^Jt(t,24)}function Xt(t){return t^Jt(t,13)^Jt(t,23)}function $t(t,e,i){const n=new Array(4),o=new Array(4);for(let e=0;e<4;e++)o[0]=255&t[4*e],o[1]=255&t[4*e+1],o[2]=255&t[4*e+2],o[3]=255&t[4*e+3],n[e]=o[0]<<24|o[1]<<16|o[2]<<8|o[3];for(let t,e=0;e<32;e+=4)t=n[1]^n[2]^n[3]^i[e+0],n[0]^=Zt(Wt(t)),t=n[2]^n[3]^n[0]^i[e+1],n[1]^=Zt(Wt(t)),t=n[3]^n[0]^n[1]^i[e+2],n[2]^=Zt(Wt(t)),t=n[0]^n[1]^n[2]^i[e+3],n[3]^=Zt(Wt(t));for(let t=0;t<16;t+=4)e[t]=n[3-t/4]>>>24&255,e[t+1]=n[3-t/4]>>>16&255,e[t+2]=n[3-t/4]>>>8&255,e[t+3]=255&n[3-t/4]}function Qt(t,e,i,{padding:n="pkcs#7",mode:o,iv:r=[],output:s="string"}={}){if("cbc"===o&&("string"==typeof r&&(r=Ht(r)),16!==r.length))throw new Error("iv is invalid");if("string"==typeof e&&(e=Ht(e)),16!==e.length)throw new Error("key is invalid");if(t="string"==typeof t?0!==i?function(t){const e=[];for(let i=0,n=t.length;i<n;i++){const n=t.codePointAt(i);if(n<=127)e.push(n);else if(n<=2047)e.push(192|n>>>6),e.push(128|63&n);else if(n<=55295||n>=57344&&n<=65535)e.push(224|n>>>12),e.push(128|n>>>6&63),e.push(128|63&n);else{if(!(n>=65536&&n<=1114111))throw e.push(n),new Error("input is not supported");i++,e.push(240|n>>>18&28),e.push(128|n>>>12&63),e.push(128|n>>>6&63),e.push(128|63&n)}}return e}(t):Ht(t):[...t],("pkcs#5"===n||"pkcs#7"===n)&&0!==i){const e=16-t.length%16;for(let i=0;i<e;i++)t.push(e)}const a=new Array(32);!function(t,e,i){const n=new Array(4),o=new Array(4);for(let e=0;e<4;e++)o[0]=255&t[0+4*e],o[1]=255&t[1+4*e],o[2]=255&t[2+4*e],o[3]=255&t[3+4*e],n[e]=o[0]<<24|o[1]<<16|o[2]<<8|o[3];n[0]^=2746333894,n[1]^=1453994832,n[2]^=1736282519,n[3]^=2993693404;for(let t,i=0;i<32;i+=4)t=n[1]^n[2]^n[3]^jt[i+0],e[i+0]=n[0]^=Xt(Wt(t)),t=n[2]^n[3]^n[0]^jt[i+1],e[i+1]=n[1]^=Xt(Wt(t)),t=n[3]^n[0]^n[1]^jt[i+2],e[i+2]=n[2]^=Xt(Wt(t)),t=n[0]^n[1]^n[2]^jt[i+3],e[i+3]=n[3]^=Xt(Wt(t));if(0===i)for(let t,i=0;i<16;i++)t=e[i],e[i]=e[31-i],e[31-i]=t}(e,a,i);const c=[];let h=r,u=t.length,f=0;for(;u>=16;){const e=t.slice(f,f+16),n=new Array(16);if("cbc"===o)for(let t=0;t<16;t++)0!==i&&(e[t]^=h[t]);$t(e,n,a);for(let t=0;t<16;t++)"cbc"===o&&0===i&&(n[t]^=h[t]),c[f+t]=n[t];"cbc"===o&&(h=0!==i?n:e),u-=16,f+=16}if(("pkcs#5"===n||"pkcs#7"===n)&&0===i){const t=c.length,e=c[t-1];for(let i=1;i<=e;i++)if(c[t-i]!==e)throw new Error("padding is invalid");c.splice(t-e,e)}return"array"!==s?0!==i?c.map((t=>1===(t=t.toString(16)).length?"0"+t:t)).join(""):function(t){const e=[];for(let i=0,n=t.length;i<n;i++)t[i]>=240&&t[i]<=247?(e.push(String.fromCodePoint(((7&t[i])<<18)+((63&t[i+1])<<12)+((63&t[i+2])<<6)+(63&t[i+3]))),i+=3):t[i]>=224&&t[i]<=239?(e.push(String.fromCodePoint(((15&t[i])<<12)+((63&t[i+1])<<6)+(63&t[i+2]))),i+=2):t[i]>=192&&t[i]<=223?(e.push(String.fromCodePoint(((31&t[i])<<6)+(63&t[i+1]))),i++):e.push(String.fromCodePoint(t[i]));return e.join("")}(c):c}var Yt={sm2:qt,sm3:function(t,e){if(t="string"==typeof t?function(t){const e=[];for(let i=0,n=t.length;i<n;i++){const n=t.codePointAt(i);if(n<=127)e.push(n);else if(n<=2047)e.push(192|n>>>6),e.push(128|63&n);else if(n<=55295||n>=57344&&n<=65535)e.push(224|n>>>12),e.push(128|n>>>6&63),e.push(128|63&n);else{if(!(n>=65536&&n<=1114111))throw e.push(n),new Error("input is not supported");i++,e.push(240|n>>>18&28),e.push(128|n>>>12&63),e.push(128|n>>>6&63),e.push(128|63&n)}}return e}(t):Array.prototype.slice.call(t),e){if("hmac"!==(e.mode||"hmac"))throw new Error("invalid mode");let i=e.key;if(!i)throw new Error("invalid key");return i="string"==typeof i?Kt(i):Array.prototype.slice.call(i),Vt(Nt(t,i))}return Vt(Ut(t))},sm4:{encrypt:(t,e,i)=>Qt(t,e,1,i),decrypt:(t,e,i)=>Qt(t,e,0,i)}}.sm2;var te=function(){function e(t){this.disableAutoPageView=!1,this.bridgeReport=!1,this.staging=!1,this.pluginInstances=[],this.sended=!1,this.started=!1,this.destroyInstance=!1,this.adapters={},this.sdkReady=!1,this.name=t,this.hook=new o,this.logger=new O(t),this.remotePlugin=new Map,this.Types=k,this.adapters.fetch=F,this.adapters.storage=E}return e.usePlugin=function(t,i,n){if(i){for(var o=!1,r=0,s=e.plugins.length;r<s;r++){if(e.plugins[r].name===i){e.plugins[r].plugin=t,e.plugins[r].options=n||{},o=!0;break}}o||e.plugins.push({name:i,plugin:t,options:n})}else e.plugins.push({plugin:t})},e.prototype.init=function(t){var i,n=this;this.inited?console.log("init can be call only one time"):t&&r(t)?t.app_id&&("number"==typeof(i=t.app_id)&&!isNaN(i))?!t.app_key||function(t){return"string"==typeof t}(t.app_key)?(t.channel_domain||-1!==["cn","sg","va"].indexOf(t.channel)||(console.warn("channel must be `cn`, `sg`,`va` !!!"),t.channel="cn"),this.logger=new O(this.name,t.log),this.configManager=new M(this,t),this.appBridge=new C(t,this.configManager),this.bridgeReport=this.appBridge.bridgeInject(),this.debugger=new Z(this,t),this.initConfig=t,this.env=t.channel_domain?"self":"public",this.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"SDK 执行INIT",data:t,level:"info",time:Date.now()}),t.disable_auto_pv&&(this.disableAutoPageView=!0),this.bridgeReport||(t.enable_encryption&&"sm"===t.encryption_type&&this.initCrypto(),this.configManager.set({app_id:t.app_id}),this.eventManager=new K,this.tokenManager=new W,this.sessionManager=new J,Promise.all([new Promise((function(t){n.once(k.TokenComplete,(function(){t(!0)}))})),new Promise((function(t){n.once(k.Start,(function(){t(!0)}))}))]).then((function(){try{e.plugins.reduce((function(t,e){var i=e.plugin,o=e.options,r=Object.assign(n.initConfig,o),s=new i;return s.apply(n,r),t.push(s),t}),n.pluginInstances)}catch(t){console.log("load plugin error, "+t.message),n.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:t.message})}n.sdkReady=!0,n.emit(k.Ready),n.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"SDK 初始化完成",time:Date.now(),level:"info",data:n.configManager.get("user")}),n.logger.info("appid: "+t.app_id+", userInfo:"+JSON.stringify(n.configManager.get("user"))),n.logger.info("appid: "+t.app_id+", sdk is ready, version is 0.0.6, you can report now !!!");try{(window.opener||window.parent).postMessage("[tea-sdk]ready","*")}catch(t){n.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:t.message})}n.pageView(),n.on(k.TokenChange,(function(e){"webid"!==e.type&&"anonymous_id"!==e.type||n.pageView(),n.logger.info("appid: "+t.app_id+" token change, new userInfo:"+JSON.stringify(n.configManager.get("user"))),n.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"SDK 设置了用户信息",time:Date.now(),secType:"USER",level:"info",data:n.configManager.get("user")})})),n.on(k.TokenReset,(function(){n.logger.info("appid: "+t.app_id+" token reset, new userInfo:"+JSON.stringify(n.configManager.get("user"))),n.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"SDK 重置了用户信息",time:Date.now(),secType:"USER",level:"info",data:n.configManager.get("user")})})),n.on(k.RouteChange,(function(e){e.init||t.disable_route_report||n.pageView()}))})),this.tokenManager.apply(this,t),this.eventManager.apply(this,t),this.sessionManager.apply(this,t),this.inited=!0,this.emit(k.Init))):console.warn("app_key param is error, must be string, please check!"):console.warn("app_id param is error, must be number, please check!"):console.warn("init params error,please check")},e.prototype.config=function(e){if(this.inited)if(e&&r(e))if(this.bridgeReport)this.appBridge.setConfig(e);else{e._staging_flag&&1===e._staging_flag&&(this.staging=!0),e.disable_auto_pv&&(this.disableAutoPageView=!0,delete e.disable_auto_pv);var i=t({},e);if(this.initConfig&&this.initConfig.configPersist){var n=this.configManager.getStore();n&&(i=Object.assign(n,e)),this.configManager.setStore(e)}i.web_id,i.user_unique_id;var o=function(t,e){var i={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(i[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(i[n[o]]=t[n[o]])}return i}(i,["web_id","user_unique_id"]);i.hasOwnProperty("web_id")&&this.emit(k.ConfigWebId,i.web_id),i.hasOwnProperty("user_unique_id")&&this.emit(k.ConfigUuid,i.user_unique_id),this.configManager.set(o),this.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"SDK 执行CONFIG",level:"info",time:Date.now(),data:i})}else this.logger.warn("config params is error, please check");else this.logger.warn("config must be use after function init")},e.prototype.setDomain=function(t){this.configManager&&this.configManager.setDomain(t),this.emit(k.ConfigDomain)},e.prototype.getConfig=function(t){return this.configManager.get(t)},e.prototype.send=function(){this.start()},e.prototype.start=function(){this.inited&&!this.sended&&(this.sended=!0,this.emit(k.Start),this.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"SDK 执行START",level:"info",time:Date.now()}),this.bridgeReport&&(this.pageView(),this.emit(k.Ready)))},e.prototype.event=function(t,e){var i=this;try{if(this.initConfig&&this.initConfig.disable_track_event)return;var n=[];if(Array.isArray(t))t.forEach((function(t){var e=i.processEvent(t[0],t[1]||{});e&&n.push(e)}));else{var o=this.processEvent(t,e);if(!o)return;n.push(o)}this.bridgeReport?n.forEach((function(t){var e=t.event,n=t.params;i.appBridge.onEventV3(e,JSON.stringify(n))})):n.length&&(this.emit(k.Event,n),this.emit(k.SessionResetTime))}catch(t){this.logger.warn("something error, please check"),this.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:t.message})}},e.prototype.beconEvent=function(t,e){if(!this.initConfig||!this.initConfig.disable_track_event)if(Array.isArray(t))console.warn("beconEvent not support batch report, please check");else{var i=[],n=this.processEvent(t,e||{});n&&(i.push(n),i.length&&(this.emit(k.BeconEvent,i),this.emit(k.SessionResetTime)))}},e.prototype.processEvent=function(t,e){void 0===e&&(e={});try{if(!t)return this.logger.warn("eventName is null, please check"),null;var i=t;/^event\./.test(t)&&(i=t.slice(6));var n=e;"object"!=typeof n&&(n={}),n.profile?delete n.profile:n.event_index=s();var o=void 0;return n.local_ms?(o=n.local_ms,delete n.local_ms):o=+new Date,{event:i,params:n,local_time_ms:o,is_bav:this.initConfig&&this.initConfig.autotrack?1:0}}catch(i){return this.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:i.message}),{event:t,params:e}}},e.prototype.dynamicParams=function(t){this.dynamicParamsFilter=t},e.prototype.filterEvent=function(t){this.eventFilter=t},e.prototype.on=function(t,e){this.hook.on(t,e)},e.prototype.once=function(t,e){this.hook.once(t,e)},e.prototype.off=function(t,e){this.hook.off(t,e)},e.prototype.emit=function(t,e,i){this.hook.emit(t,e,i)},e.prototype.set=function(t){this.hook.set(t)},e.prototype.pageView=function(){this.disableAutoPageView||this.predefinePageView()},e.prototype.predefinePageView=function(e){if(void 0===e&&(e={}),this.inited){var i={title:document.title||location.pathname,url:location.href,url_path:location.pathname,time:Date.now(),referrer:window.document.referrer,$is_first_time:""+(this.configManager&&this.configManager.is_first_time||!1)},n=t({},i,e);this.event("predefine_pageview",n)}else console.warn("predefinePageView should call after init")},e.prototype.clearEventCache=function(){this.emit(k.CleanEvents)},e.prototype.setWebIDviaUnionID=function(t){if(t){var e=f(t);this.config({web_id:""+e,wechat_unionid:t}),this.emit(k.CustomWebId)}},e.prototype.setWebIDviaOpenID=function(t){if(t){var e=f(t);this.config({web_id:""+e,wechat_openid:t}),this.emit(k.CustomWebId)}},e.prototype.setAnonymousId=function(t){this.emit(k.AnonymousId,t)},e.prototype.setNativeAppId=function(t){this.bridgeReport&&this.appBridge.setNativeAppId(t)},e.prototype.resetStayDuration=function(t,e,i){void 0===t&&(t=""),void 0===e&&(e=""),void 0===i&&(i=""),this.emit(k.ResetStay,{url_path:t,title:e,url:i},k.Stay)},e.prototype.resetStayParams=function(t,e,i){void 0===t&&(t=""),void 0===e&&(e=""),void 0===i&&(i=""),this.emit(k.SetStay,{url_path:t,title:e,url:i},k.Stay)},e.prototype.getToken=function(e,i){var n=this;if(this.inited){var o=!1,r=function(i){if(!o){o=!0;var r=n.configManager.get().user;return i&&(r.tobid=i,r["diss".split("").reverse().join("")]=i),e(t({},r))}},s=function(){n.tokenManager.getTobId().then((function(t){r(t)}))};this.sdkReady?s():(i&&setTimeout((function(){r()}),i),this.on(k.Ready,(function(){s()})))}else this.logger.warn("getToken must be use after function init")},e.prototype.startTrackEvent=function(t){t&&this.emit(k.TrackDurationStart,t,k.TrackDuration)},e.prototype.endTrackEvent=function(t,e){void 0===e&&(e={}),t&&this.emit(k.TrackDurationEnd,{eventName:t,params:e},k.TrackDuration)},e.prototype.pauseTrackEvent=function(t){t&&this.emit(k.TrackDurationPause,t,k.TrackDuration)},e.prototype.resumeTrackEvent=function(t){t&&this.emit(k.TrackDurationResume,t,k.TrackDuration)},e.prototype.profileSet=function(t){this.bridgeReport?this.appBridge.profileSet(JSON.stringify(t)):this.emit(k.ProfileSet,t,k.Profile),this.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"SDK 执行profileSet",level:"info",time:Date.now(),data:t})},e.prototype.profileSetOnce=function(t){this.bridgeReport?this.appBridge.profileSetOnce(JSON.stringify(t)):this.emit(k.ProfileSetOnce,t,k.Profile),this.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"SDK 执行profileSetOnce",level:"info",time:Date.now(),data:t})},e.prototype.profileIncrement=function(t){this.bridgeReport?this.appBridge.profileIncrement(JSON.stringify(t)):this.emit(k.ProfileIncrement,t,k.Profile),this.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"SDK 执行profileIncrement",level:"info",time:Date.now(),data:t})},e.prototype.profileUnset=function(t){this.bridgeReport?this.appBridge.profileUnset(t):this.emit(k.ProfileUnset,t,k.Profile),this.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"SDK 执行profileUnset",level:"info",time:Date.now(),data:t})},e.prototype.profileAppend=function(t){this.bridgeReport?this.appBridge.profileAppend(JSON.stringify(t)):this.emit(k.ProfileAppend,t,k.Profile),this.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"SDK 执行profileAppend",level:"info",time:Date.now(),data:t})},e.prototype.setExternalAbVersion=function(t){this.bridgeReport?this.appBridge.setExternalAbVersion(t):this.emit(k.AbExternalVersion,"string"==typeof t&&t?(""+t).trim():null,k.Ab)},e.prototype.getVar=function(t,e,i){this.bridgeReport?this.appBridge.getVar(t,e,i):this.emit(k.AbVar,{name:t,defaultValue:e,callback:i},k.Ab)},e.prototype.getAllVars=function(t){this.bridgeReport?this.appBridge.getAllVars(t):this.emit(k.AbAllVars,t,k.Ab)},e.prototype.getABconfig=function(t,e){this.emit(k.AbConfig,{params:t,callback:e},k.Ab)},e.prototype.getAbSdkVersion=function(t){if(!this.bridgeReport||!t)return this.configManager.getAbVersion()||"";this.appBridge.getAbSdkVersion(t)},e.prototype.onAbSdkVersionChange=function(t){var e=this;return this.emit(k.AbVersionChangeOn,t,k.Ab),function(){e.emit(k.AbVersionChangeOff,t,k.Ab)}},e.prototype.offAbSdkVersionChange=function(t){this.emit(k.AbVersionChangeOff,t,k.Ab)},e.prototype.openOverlayer=function(){this.emit(k.AbOpenLayer,"",k.Ab)},e.prototype.closeOverlayer=function(){this.emit(k.AbCloseLayer,"",k.Ab)},e.prototype.initCrypto=function(){this.publicKey=this.initConfig.crypto_publicKey||"04BA9E229380DC0E41E10839B0C52A4763D3EDFE8903F3B8E81395523381E03AA995D295BD4A4088792E4785B224F7837EB4D2C7C05973C7AE8687A35ACAE470A0"},e.prototype.cryptoData=function(t){try{if(!this.initConfig.enable_encryption)return t;var e=void 0;if("sm"===this.initConfig.encryption_type){var i=(r=JSON.stringify(t),s=this.publicKey,void 0===(a=1)&&(a=1),"04"+Yt.doEncrypt(r,s,a)),n=l(i);e=new Uint8Array(n)}else e="data="+(o=JSON.stringify(t),window.btoa?window.btoa(encodeURIComponent(o)):encodeURIComponent(o));return e}catch(e){return t}var o,r,s,a},e.prototype.destoryInstace=function(){this.destroyInstance||(this.destroyInstance=!0,this.off(k.TokenComplete))},e.plugins=[],e}(),ee=function(){function e(){}return e.prototype.apply=function(t,e){var i=this;this.collect=t,this.config=e,this.duration=6e4,this.reportUrl=t.configManager.getDomain()+"/profile/list";var n=t.Types,o=t.adapters.fetch;this.eventCheck=new D(t,e),this.fetch=o,this.cache={},this.collect.on(n.ProfileSet,(function(t){i.setProfile(t)})),this.collect.on(n.ProfileSetOnce,(function(t){i.setOnceProfile(t)})),this.collect.on(n.ProfileUnset,(function(t){i.unsetProfile(t)})),this.collect.on(n.ProfileIncrement,(function(t){i.incrementProfile(t)})),this.collect.on(n.ProfileAppend,(function(t){i.appendProfile(t)})),this.collect.on(n.ProfileClear,(function(){i.cache={}})),this.ready(n.Profile)},e.prototype.ready=function(t){var e=this;if(this.collect.set(t),this.collect.hook._hooksCache.hasOwnProperty(t)){var i=this.collect.hook._hooksCache[t];if(!Object.keys(i).length)return;var n=function(t){i[t].length&&i[t].forEach((function(i){e.collect.hook.emit(t,i)}))};for(var o in i)n(o)}},e.prototype.report=function(t,e){void 0===e&&(e={});try{if(this.config.disable_track_event)return;var i=[];i.push(this.collect.processEvent(t,e));var n=this.collect.eventManager.merge(i,!0),o=this.collect.cryptoData(n),r=this.collect.configManager.getUrl("profile");this.fetch(r,o,1e5,!1,(function(){}),(function(){}),"","POST",this.config.enable_encryption,this.config.encryption_header),this.collect.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_EVENT,info:"埋点上报成功",time:Date.now(),data:n,code:200,status:"success"})}catch(t){this.collect.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:t.message})}},e.prototype.setProfile=function(e){var i=this.formatParams(e);i&&Object.keys(i).length&&(this.pushCache(i),this.report("__profile_set",t({},i,{profile:!0})))},e.prototype.setOnceProfile=function(e){var i=this.formatParams(e,!0);i&&Object.keys(i).length&&(this.pushCache(i),this.report("__profile_set_once",t({},i,{profile:!0})))},e.prototype.incrementProfile=function(e){e?this.report("__profile_increment",t({},e,{profile:!0})):console.warn("please check the params, must be object!!!")},e.prototype.unsetProfile=function(e){if(e){var i={};i[e]="1",this.report("__profile_unset",t({},i,{profile:!0}))}else console.warn("please check the key, must be string!!!")},e.prototype.appendProfile=function(e){if(e){var i={};for(var n in e)"string"==typeof e[n]||"Array"===Object.prototype.toString.call(e[n]).slice(8,-1)?i[n]=e[n]:console.warn("please check the value of param: "+n+", must be string or array !!!");Object.keys(i).length&&this.report("__profile_append",t({},i,{profile:!0}))}else console.warn("please check the params, must be object!!!")},e.prototype.pushCache=function(t){var e=this;Object.keys(t).forEach((function(i){e.cache[i]={val:e.clone(t[i]),timestamp:Date.now()}}))},e.prototype.formatParams=function(t,e){var i=this;void 0===e&&(e=!1);try{if(!t||"[object Object]"!==Object.prototype.toString.call(t))return void console.warn("please check the params type, must be object !!!");var n={};for(var o in t)"string"==typeof t[o]||"number"==typeof t[o]||"Array"===Object.prototype.toString.call(t[o]).slice(8,-1)?n[o]=t[o]:console.warn("please check the value of params:"+o+", must be string,number,Array !!!");var r=Object.keys(n);if(!r.length)return;var s=Date.now();return r.filter((function(n){var o=i.cache[n];return e?!o:!(o&&i.compare(o.val,t[n])&&s-o.timestamp<i.duration)})).reduce((function(t,e){return t[e]=n[e],t}),{})}catch(t){this.collect.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:t.message}),console.log("error")}},e.prototype.compare=function(t,e){try{return JSON.stringify(t)===JSON.stringify(e)}catch(t){return this.collect.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:t.message}),!1}},e.prototype.clone=function(t){try{return JSON.parse(JSON.stringify(t))}catch(e){return this.collect.emit(v.DEBUGGER_MESSAGE,{type:v.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:e.message}),t}},e.prototype.unReady=function(){console.warn("sdk is not ready, please use this api after start")},e}(),ie=function(){function t(){var t=this;this.setInterval=function(){t.clearIntervalFunc=function(t,e){void 0===t&&(t=function(){}),void 0===e&&(e=1e3);var i,n=Date.now()+e;return i=window.setTimeout((function o(){var r=Date.now()-n;t(),n+=e,i=window.setTimeout(o,Math.max(0,e-r))}),e),function(){window.clearTimeout(i)}}((function(){t.isSessionhasEvent&&t.endCurrentSession()}),t.sessionInterval)},this.clearInterval=function(){t.clearIntervalFunc&&t.clearIntervalFunc()}}return t.prototype.apply=function(t,e){var i=this;if(this.collect=t,!e.disable_heartbeat){this.sessionInterval=6e4,this.startTime=0,this.lastTime=0,this.setInterval();var n=this.collect.Types;this.collect.on(n.SessionReset,(function(){i.process()}))}},t.prototype.endCurrentSession=function(){this.collect.event("_be_active",{start_time:this.startTime,end_time:this.lastTime,url:window.location.href,referrer:window.document.referrer,title:document.title||location.pathname}),this.isSessionhasEvent=!1,this.startTime=0},t.prototype.process=function(){this.isSessionhasEvent||(this.isSessionhasEvent=!0,this.startTime=+new Date);var t=this.lastTime||+new Date;this.lastTime=+new Date,this.lastTime-t>this.sessionInterval&&(this.clearInterval(),this.endCurrentSession(),this.setInterval())},t}(),ne=function(){function t(){}return t.prototype.apply=function(t,e){var i=this;if(this.collect=t,this.config=e,!this.config.channel_domain&&!this.config.disable_track_event&&!this.config.disable_sdk_monitor){var n=t.adapters.fetch;this.fetch=n,this.url=t.configManager.getUrl("event");var o=this.collect.Types;this.collect.on(o.Ready,(function(){i.sdkOnload()})),this.collect.on(o.SubmitError,(function(t){var e=t.type,n=t.eventData,o=t.errorCode;"f_data"===e&&i.sdkError(n,o)}))}},t.prototype.sdkOnload=function(){var t=this;try{var e=this.collect.configManager.get(),i=e.header,n=e.user,o=i.app_id,r=i.app_name,s=i.sdk_version,a=n.web_id,c={events:[{event:"onload",params:JSON.stringify({app_id:o,app_name:r||"",sdk_version:s,sdk_type:"npm",sdk_config:this.config,sdk_desc:"TOB"}),local_time_ms:Date.now()}],user:{user_unique_id:a},header:{}};setTimeout((function(){t.fetch(t.url,[c],3e4,!1,(function(){}),(function(){}),"566f58151b0ed37e")}),16)}catch(t){}},t.prototype.sdkError=function(t,e){var i=this;try{var n=t[0],o=n.user,r=n.header,s=[];t.forEach((function(t){t.events.forEach((function(t){s.push(t)}))}));var a={events:s.map((function(t){return{event:"on_error",params:JSON.stringify({error_code:e,app_id:r.app_id,app_name:r.app_name||"",error_event:t.event,sdk_version:r.sdk_version,local_time_ms:t.local_time_ms,tea_event_index:Date.now(),params:t.params,header:JSON.stringify(r),user:JSON.stringify(o)}),local_time_ms:Date.now()}})),user:{user_unique_id:o.user_unique_id},header:{}};setTimeout((function(){i.fetch(i.url,[a],3e4,!1,(function(){}),(function(){}),"566f58151b0ed37e")}),16)}catch(t){}},t}(),oe=function(){function t(){this.verifyReady=!1,this.cleanStatus=!1}return t.prototype.apply=function(t,e){var i=this;this.collector=t,this.config=e,this.eventStorage=[],this.collector.on("submit-verify-h5",(function(t){t&&t.length&&i.eventStore(t[0])})),this.checkUrl(),this.heartbeat()},t.prototype.checkUrl=function(){var t=window.location.href,e=u(t);e._r_d_&&e._r_c_k_?(this.verifyReady=!0,this.domain=e._r_d_,this.key=e._r_c_k_,this.checkCache()):this.collector.off("submit-verify-h5")},t.prototype.checkCache=function(){this.eventStorage.length&&this.postVerify(this.eventStorage)},t.prototype.heartbeat=function(){var t=this;this.heart=setInterval((function(){var e={event:"simulator_test__",local_time_ms:Date.now()},i=t.collector.configManager.get(),n=i.header,o={events:[e],user:i.user,header:n};t.eventStore(o)}),6e4)},t.prototype.eventStore=function(t){this.cleanStatus||(this.verifyReady?this.postVerify(t):this.eventStorage.push(t))},t.prototype.cleanVerify=function(){this.cleanStatus=!0,this.eventStorage=[],clearInterval(this.heart)},t.prototype.postVerify=function(t){var e,i=this;try{var n=JSON.parse(JSON.stringify(t));e=t,Array.isArray(e)?n.forEach((function(t){i.fetchLog(t)})):this.fetchLog(n)}catch(t){console.log("web verify post error ~")}},t.prototype.fetchLog=function(t){F(this.domain+"/simulator/h5/log?connection_key="+this.key,t,2e4,!1)},t.prototype.leave=function(){var t=this;document.addEventListener("visibilitychange",(function(){"hidden"===document.visibilityState&&t.cleanVerify()})),c((function(){t.cleanVerify()}))},t}();te.usePlugin(oe,"verifyH"),te.usePlugin(ee,"profile"),te.usePlugin(ie,"heartbeat"),te.usePlugin(ne,"monitor");var re=new te("default"),se=te;export{se as Collector,re as default};
|