"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var i=0;i>6|192,63&s|128):String.fromCharCode(s>>12|224,s>>6&63|128,63&s|128),null!==o&&(n>18&63,i=a>>12&63,n=a>>6&63,a=63&a,u[o++]=r.charAt(t)+r.charAt(i)+r.charAt(n)+r.charAt(a),sthis.timeout}}]),r}(),HttpTaskDebug=function(){function o(e,t,i,n,a,r,s){_classCallCheck(this,o),this.data=e,this.serverDebugUrl=t,this.callback=s,this.tryCount=_.isNumber(i)?i:1,this.timeout=_.isNumber(n)?n:3e3,this.dryrun=a,this.deviceId=r,this.taClassName="HttpTaskDebug"}return _createClass(o,[{key:"run",value:function(){var t=this,e="appid="+this.data["#app_id"]+"&source=client&dryRun="+this.dryrun+"&deviceId="+this.deviceId+"&data="+encodeURIComponent(JSON.stringify(this.data.data[0])),i=_.createExtraHeaders();i["content-type"]="application/x-www-form-urlencoded";var n=PlatformAPI.request({url:this.serverDebugUrl,method:"POST",data:e,header:i,success:function(e){t.onSuccess(e),clearTimeout(a)},fail:function(e){t.onFailed(e),clearTimeout(a)}}),a=setTimeout(function(){(_.isObject(n)||_.isPromise(n))&&_.isFunction(n.abort)&&n.abort()},this.timeout)}},{key:"onSuccess",value:function(e){if(_.isObject(e)&&200===e.statusCode){var t;if((_.isUndefined(e.data)||_.isUndefined(e.data.errorLevel))&&(e.data={errorLevel:0}),0===e.data.errorLevel)t="Verify data success.";else if(1===e.data.errorLevel){for(var i=e.data.errorProperties,n="",a=0;ae)return!0;return!1}},{key:"resetTimeout",value:function(){this.isRunning=!1,delete this.runTime}}]),e}(),senderQueue=new SenderQueue,DEFAULT_CONFIG={name:"thinkingdata",is_plugin:!1,maxRetries:3,sendTimeout:3e3,enablePersistence:!0,asyncPersistence:!1,enableLog:!0,strict:!1,debugMode:"none",enableCalibrationTime:!1,enableBatch:!1,cloudEnv:"online"},systemInformation={properties:{"#lib":Config.LIB_NAME,"#lib_version":Config.LIB_VERSION},initDeviceId:function(e){_.isString(e)&&(this.properties["#device_id"]=e)},getSystemInfo:function(e){var i=this;PlatformAPI.onNetworkStatusChange(function(e){i.properties["#network_type"]=e.networkType}),PlatformAPI.getNetworkType({success:function(e){i.properties["#network_type"]=e.networkType},complete:function(){PlatformAPI.getSystemInfo({success:function(e){var t=e.system?e.system.replace(/\s+/g," ").split(" "):[],t={"#manufacturer":e.brand,"#device_model":e.model,"#screen_width":Number(e.screenWidth),"#screen_height":Number(e.screenHeight),"#os":t[0],"#os_version":t[1],"#mp_platform":e.mp_platform,"#system_language":e.systemLanguage};_.extend(i.properties,t),_.setMpPlatform(e.mp_platform)},complete:function(){e()}})}})}},ThinkingDataPersistence=function(){function e(t,i){var n=this;_classCallCheck(this,e),this.enabled=t.enablePersistence,this.enabled?(t.isChildInstance?(this.name=t.persistenceName+"_"+t.name,this.nameOld=t.persistenceNameOld+"_"+t.name):(this.name=t.persistenceName,this.nameOld=t.persistenceNameOld),t.asyncPersistence?(this._state={},PlatformAPI.getStorage(this.name,!0,function(e){_.isEmptyObject(e)?PlatformAPI.getStorage(n.nameOld,!0,function(e){n._state=_.extend2Layers({},e,n._state),n._init(t,i),n._save()}):(n._state=_.extend2Layers({},e,n._state),n._init(t,i),n._save())})):(this._state=PlatformAPI.getStorage(this.name)||{},_.isEmptyObject(this._state)&&(this._state=PlatformAPI.getStorage(this.nameOld)||{}),this._init(t,i))):(this._state={},this._init(t,i))}return _createClass(e,[{key:"_init",value:function(e,t){this.getDistinctId()||this.setDistinctId(_.UUID()),e.isChildInstance||(this.getDeviceId()||this._setDeviceId(_.UUID()),systemInformation.initDeviceId(this.getDeviceId())),this.initComplete=!0,"function"==typeof t&&t(),this._save()}},{key:"_save",value:function(){this.enabled&&this.initComplete&&PlatformAPI.setStorage(this.name,JSON.stringify(this._state))}},{key:"_set",value:function(e,t){var i,n=this;"string"==typeof e?(i={})[e]=t:"object"===_typeof(e)&&(i=e),_.each(i,function(e,t){n._state[t]=e}),this._save()}},{key:"_get",value:function(e){return this._state[e]}},{key:"setEventTimer",value:function(e,t){var i=this._state.event_timers||{};i[e]=t,this._set("event_timers",i)}},{key:"removeEventTimer",value:function(e){var t=(this._state.event_timers||{})[e];return _.isUndefined(t)||(delete this._state.event_timers[e],this._save()),t}},{key:"getDeviceId",value:function(){return this._state.device_id}},{key:"_setDeviceId",value:function(e){this.getDeviceId()?logger$1.warn("cannot modify the device id."):this._set("device_id",e)}},{key:"getDistinctId",value:function(){return this._state.distinct_id}},{key:"setDistinctId",value:function(e){this._set("distinct_id",e)}},{key:"getAccountId",value:function(){return this._state.account_id}},{key:"setAccountId",value:function(e){this._set("account_id",e)}},{key:"getSuperProperties",value:function(){return this._state.props||{}}},{key:"setSuperProperties",value:function(e,t){e=t?e:_.extend(this.getSuperProperties(),e);this._set("props",e)}}]),e}(),dataStoragePrefix="ta_mpsdk_",tabStoragePrefix="tab_tampsdk_",BatchConsumer=function(){function r(e,t){_classCallCheck(this,r),this.config=e,this.ta=t,this.timer=null,this.batchConfig=_.extend({size:6,interval:6e3,maxLimit:500},this.config.batchConfig),this.batchConfig.size<1&&(this.batchConfig.size=1),30this.maxLimit&&this.batchList.shift(),this.batchList.push(e),this.dataHasChange=!0,this.batchList.length>this.batchConfig.size&&this.batchSend()}},{key:"flush",value:function(){clearTimeout(this.timer),this.batchSend(),this.loopSend()}},{key:"batchSend",value:function(){var t,i,n,e=new Date;0!==this.dataSendTimeStamp&&e.getTime()-this.dataSendTimeStamp