@xm-fe/xm-mp-log
Advanced tools
Comparing version 0.2.2-gamma.1 to 0.2.2-gamma.2
@@ -1,2 +0,2 @@ | ||
/*! @xm-fe/xm-mp-log 0.2.2-gamma.1 */ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).monitor={})}(this,(function(t){"use strict";function e(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function r(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?e(Object(n),!0).forEach((function(e){c(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):e(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function n(){n=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",s=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function l(t,e,r,n){var i=e&&e.prototype instanceof p?e:p,a=Object.create(i.prototype),s=new _(n||[]);return o(a,"_invoke",{value:x(t,r,s)}),a}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=l;var h={};function p(){}function d(){}function y(){}var g={};u(g,a,(function(){return this}));var v=Object.getPrototypeOf,m=v&&v(v(k([])));m&&m!==e&&r.call(m,a)&&(g=m);var w=y.prototype=p.prototype=Object.create(g);function b(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function S(t,e){function n(o,i,a,s){var c=f(t[o],t,i);if("throw"!==c.type){var u=c.arg,l=u.value;return l&&"object"==typeof l&&r.call(l,"__await")?e.resolve(l.__await).then((function(t){n("next",t,a,s)}),(function(t){n("throw",t,a,s)})):e.resolve(l).then((function(t){u.value=t,a(u)}),(function(t){return n("throw",t,a,s)}))}s(c.arg)}var i;o(this,"_invoke",{value:function(t,r){function o(){return new e((function(e,o){n(t,r,e,o)}))}return i=i?i.then(o,o):o()}})}function x(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return L()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var s=j(a,r);if(s){if(s===h)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=f(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===h)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function j(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,j(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),h;var o=f(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,h;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,h):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,h)}function O(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function P(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function _(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(O,this),this.reset(!0)}function k(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:L}}function L(){return{value:void 0,done:!0}}return d.prototype=y,o(w,"constructor",{value:y,configurable:!0}),o(y,"constructor",{value:d,configurable:!0}),d.displayName=u(y,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,y):(t.__proto__=y,u(t,c,"GeneratorFunction")),t.prototype=Object.create(w),t},t.awrap=function(t){return{__await:t}},b(S.prototype),u(S.prototype,s,(function(){return this})),t.AsyncIterator=S,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new S(l(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},b(w),u(w,c,"Generator"),u(w,a,(function(){return this})),u(w,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=k,_.prototype={constructor:_,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(P),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var s=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(s&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,h):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),h},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),P(r),h}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;P(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:k(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),h}},t}function o(t){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o(t)}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,v(n.key),n)}}function s(t,e,r){return e&&a(t.prototype,e),r&&a(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function c(t,e,r){return(e=v(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function u(t){return u=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},u(t)}function l(t,e){return l=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},l(t,e)}function f(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function h(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=u(t);if(e){var o=u(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return f(this,r)}}function p(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,s=[],c=!0,u=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(s.push(n.value),s.length!==e);c=!0);}catch(t){u=!0,o=t}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(u)throw o}}return s}}(t,e)||y(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function d(t){return function(t){if(Array.isArray(t))return g(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||y(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function y(t,e){if(t){if("string"==typeof t)return g(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?g(t,e):void 0}}function g(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function v(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}function m(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=[];return Object.keys(e).forEach((function(t){r.push("".concat(t,"=").concat(e[t]))})),0===r.length?"/".concat(t):"/".concat(t).concat(-1!==t.indexOf("?")?"&":"?").concat(r.join("&"))}var w=Object.defineProperty,b=Object.getOwnPropertySymbols,S=Object.prototype.hasOwnProperty,x=Object.prototype.propertyIsEnumerable,j=function(t,e,r){return e in t?w(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r},O=function(t,e){for(var r in e||(e={}))S.call(e,r)&&j(t,r,e[r]);if(b){var n,o=function(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=y(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,s=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return a=t.done,t},e:function(t){s=!0,i=t},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw i}}}}(b(e));try{for(o.s();!(n=o.n()).done;){r=n.value;x.call(e,r)&&j(t,r,e[r])}}catch(t){o.e(t)}finally{o.f()}}return t};var P=function(t){var e={request:function(){},httpRequest:function(){},getSystemInfoSync:function(){}},r="unknown";if("object"===("undefined"==typeof wx?"undefined":o(wx)))e=wx,r="wechat";else if("object"===("undefined"==typeof dd?"undefined":o(dd)))e=dd,r="dingtalk";else if("object"===("undefined"==typeof my?"undefined":o(my)))e=my,r="alipay";else if("object"===("undefined"==typeof tt?"undefined":o(tt)))e=tt,r="bytedance";else if("object"===("undefined"==typeof qq?"undefined":o(qq)))e=qq,r="qq";else if("object"===("undefined"==typeof swan?"undefined":o(swan)))e=swan,r="swan";else{if(!t.platformSDK)throw new Error("Current platform is not default supported by SLS API, Pleace config platformSDK or contack Aliyun SLS team.");e=t.platformSDK}var n,i,a=(n=e,{getStorageSync:function(t){return"function"==typeof n.getStorageSync?n.getStorageSync(t):null},setStorageSync:function(t,e){"function"==typeof n.setStorageSync&&n.setStorageSync(t,e)},getCurrentPagesInterop:i=function(){return"function"!=typeof getCurrentPages?[]:getCurrentPages()},getNavigateBackUrl:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,e=getCurrentPages();if(!e.length)return"";var r=e[e.length-t];return m(r.route,r.options)},getCurrentUrl:function(){var t=i();if(!t.length)return"";var e=t.pop();return m(e.route,e.options)}});return O({sdk:e,appName:r},a)};function _(t,e){var r,n="unknown";if(e&&t[e])r=t[e],n=e;else if(t.request)r=t.request,n="request";else{if(!t.httpRequest)throw new Error("Current platform is not default supported by SLS API, Pleace config platformRequestName or contack Aliyun SLS team.");r=t.httpRequest,n="httpRequest"}return{request:r,requestName:n}}function k(t,e,r,o,i,a){return s=this,c=null,u=n().mark((function s(){var c,u,l;return n().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return t=t.slice(0,-6),n.next=3,i.process(t,e);case 3:c=n.sent,u=c.data,l=c.header,(0,_(r,a).request)(!o||"alipay"!=o&&"dingtalk"!=o?{url:t,method:"POST",data:u,header:l}:{url:t,method:"POST",data:u,headers:l});case 8:case"end":return n.stop()}}),s)})),new Promise((function(t,e){var r=function(t){try{o(u.next(t))}catch(t){e(t)}},n=function(t){try{o(u.throw(t))}catch(t){e(t)}},o=function(e){return e.done?t(e.value):Promise.resolve(e.value).then(r,n)};o((u=u.apply(s,c)).next())}));var s,c,u}var L=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&l(t,e)}(r,t);var e=h(r);function r(t){i(this,r);var n=P(t).sdk,o=Object.assign({},t,{sendPayload:function(e,r){!function(t,e,r,n){(0,_(r,n).request)({url:"".concat(t,"?APIVersion=0.6.0"),method:"POST",data:e})}(e,r,n,t.platformRequestName)}});return e.call(this,o)}return s(r,[{key:"useStsPlugin",value:function(t){var e=this,r=P(this.getOpt()),n=r.sdk,o=r.appName;this.getOpt().sendPayload=function(r,i){var a=e.getOpt();k(r,i,n,o,t,a.platformRequestName)},this.overwriteTransString(t)}}]),r}(function(){function t(e){var r,n,o=this;i(this,t),this.timer=null,this.time=10,this.count=10,this.arr=[],this.time=null!=(r=e.time)?r:10,this.count=null!=(n=e.count)?n:10,e.host.startsWith("http://")||e.host.startsWith("https://")?this.url=e.host+"/logstores/"+e.logstore+"/track":this.url="https://"+e.project+"."+e.host+"/logstores/"+e.logstore+"/track",this.opt=e,e.installUnloadHook&&"function"==typeof e.installUnloadHook&&e.installUnloadHook((function(){o.sendImmediateInner()}))}return s(t,[{key:"assemblePayload",value:function(t){var e={__logs__:t};return this.opt.tags&&(e.__tags__=this.opt.tags),this.opt.topic&&(e.__topic__=this.opt.topic),this.opt.source&&(e.__source__=this.opt.source),JSON.stringify(e)}},{key:"platformSend",value:function(){if(this.opt.sendPayload&&"function"==typeof this.opt.sendPayload){var t=this.assemblePayload(this.arr);this.opt.sendPayload(this.url,t)}}},{key:"transString",value:function(t){var e={};for(var r in t)"object"==o(t[r])?e[r]=JSON.stringify(t[r]):e[r]=String(t[r]);return e}},{key:"sendImmediateInner",value:function(){this.arr&&this.arr.length>0&&(this.platformSend(),null!=this.timer&&(clearTimeout(this.timer),this.timer=null),this.arr=[])}},{key:"sendInner",value:function(){if(this.timer)this.arr.length>=this.count&&(clearTimeout(this.timer),this.timer=null,this.sendImmediateInner());else{var t=this;this.arr.length>=this.count||this.time<=0?this.sendImmediateInner():this.timer=setTimeout((function(){t.sendImmediateInner()}),1e3*this.time)}}},{key:"send",value:function(t){var e=this.transString(t);this.arr.push(e),this.sendInner()}},{key:"sendImmediate",value:function(t){var e=this.transString(t);this.arr.push(e),this.sendImmediateInner()}},{key:"sendBatchLogs",value:function(t){var e,r=this,n=t.map((function(t){return r.transString(t)}));(e=this.arr).push.apply(e,d(n)),this.sendInner()}},{key:"sendBatchLogsImmediate",value:function(t){var e,r=this,n=t.map((function(t){return r.transString(t)}));(e=this.arr).push.apply(e,d(n)),this.sendImmediateInner()}},{key:"overwriteTransString",value:function(t){this.transString=t.transString}},{key:"getOpt",value:function(){return this.opt}}]),t}()),I="0.2.2-gamma.1",E={host:"https://xianmu-front-end-log.cn-hangzhou.log.aliyuncs.com",project:"xianmu-front-end-log",logstore:"fe-test",time:10,count:10},N={tracker:null,testTracker:new L(E),uid:"",phone:"",userName:"",cid:"",logUrl:"",logstores:"fe-test",env:"mp",ignoreLoginLog:!1,isDev:!1,isTrack:!1,rqCount:0,singleId:Date.now()+"-"+Math.ceil(1e6*Math.random()),viewTime:2e3,reportedTime:15e3,viewportMap:{},reportedData:{},pageName:"",set:function(t){var e=this;if(wx&&wx.getAccountInfoSync?this.env="mp":this.env="h5",t.logUrl&&(this.logUrl=t.logUrl),t.logstores){this.logstores=t.logstores;var n=r({},E);n.logstore=t.logstores,this.tracker=new L(n)}if(t.uid&&(this.uid=t.uid),t.ignoreLoginLog&&(this.ignoreLoginLog=t.ignoreLoginLog),t.userName&&(this.userName=t.userName),t.phone&&(this.phone=t.phone,!this.ignoreLoginLog&&this.customLog("login:"+t.phone+":"+this.userName)),t.isDev&&(this.isDev=t.isDev),t.isTrack){this.isTrack=t.isTrack;try{var o={};wx&&wx.onAppRoute&&wx.onAppHide&&(wx.onAppRoute((function(t){var r,n=o;e.pageName=null==t||null===(r=t.page)||void 0===r?void 0:r.window.navigationBarTitleText,o={path:t.path,query:t.query,ot:t.openType,n:e.pageName},e.pvLog(t.path,{ext:{to:o,from:n}}),e.departureViewport()})),wx.onAppHide((function(t){console.log("onAppHide res",t),e.departureViewport()})))}catch(t){console.log("e onAppRoute",t)}}},pvLog:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.log(this.level.log,this.type.pv,r({tag:1,pageName:t},e))},viewLog:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.log(this.level.log,this.type.view,r({tag:1},t))},customLog:function(t,e){this.log(this.level.log,this.type.custom,{msg:t,ext:e})},clickLog:function(t){this.log(this.level.log,this.type.click,r({tag:1},t))},warn:function(t,e){this.log(this.level.warn,this.type.custom,{msg:t,ext:e})},onResponse:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.statusCode,n=t.data,o=!1,i=!1;try{200!==r&&(o=!0);var a=n||{},s=a.code,c=a.status;(s&&200!==s&&"SUCCESS"!==s||c&&200!==c)&&(i=!0);var u="",l="";"[object Object]"===Object.prototype.toString.call(n)?(u=(null==n?void 0:n.message)||(null==n?void 0:n.error)||(null==n?void 0:n.msg),l=(null==n?void 0:n.message)||(null==n?void 0:n.msg)):(u=n,l=n);var f={data:e.data,method:e.method||"get",qh:e.header,rh:t.header,rt:n},h={ap:e.apiPath,code:r,msg:l,ai:JSON.stringify(f)};o||i?(h.msg=u,o?N.log(this.level.error,this.type.api,h):i&&N.log(this.level.log,this.type.apiBusiness,h)):N.log(this.level.log,this.type.api,h)}catch(t){try{N.jsError("onResponse err: "+t.message,t.stack)}catch(e){console.log("监控报错:",e,t)}}},onError:function(t){this.log(this.level.error,this.type.js,{msg:t})},onFail:function(t,e){try{var r={};r=t&&(t.errMsg||t.errno||t.errCode)?{msg:t.errMsg,eno:t.errno,eco:t.errCode}:{ext:t},e&&e.apiPath?(r.ap=e.apiPath,r.ai=JSON.stringify({data:e.data,method:e.method||"get",header:e.header})):e&&(r.extt=e);t&&([600001,600003,5].includes(t.errno)||600001===t.errCode)?this.log(this.level.warn,this.type.fail,r):this.log(this.level.error,this.type.fail,r)}catch(t){console.log(t)}},getReqHeaders:function(){return{"xm-rqid":Date.now()+"-"+Math.ceil(1e8*Math.random()),"xm-uid":this.uid,"xm-biz":this.logstores,"xm-phone":this.phone,"xm-platform":this.env}},log:function(t,e,n){try{var o={};if(wx&&wx.getAccountInfoSync){if(o=wx.getAccountInfoSync().miniProgram,!N.isDev&&"develop"==o.envVersion)return}else{if(o.version="h5",!N.isDev&&window&&window.location&&window.location.origin&&!window.location.origin.includes("//mall.cosfo.cn"))return;window&&window.location&&window.location.origin&&window.location.origin.includes("//mall.cosfo.cn")?o.envVersion="release":o.envVersion="develop"}var i,a,s=void 0===n.pageName?this.pageName:n.pageName,c=r({v:I,url:getCurrentPages().map((function(t){return t.route})).join("_"),mpv:JSON.stringify({v:o.version,e:o.envVersion}),cid:N.cid,uid:N.uid,phone:N.phone,uName:N.userName,en:N.env,pageName:s,sid:N.singleId,level:t,type:e,count:N.rqCount++},n);if(c.ext&&(c.ext=N._toStr(c.ext)),window&&window.navigator&&window.navigator.userAgent)c.userAgent=window.navigator.userAgent;else if(wx&&"function"==typeof wx.getSystemInfoSync){var u=wx.getSystemInfoSync();c.systemInfo=JSON.stringify(u)}if("release"==o.envVersion)null===(i=N.tracker)||void 0===i||i.send(c);else if(N.isDev)null===(a=N.testTracker)||void 0===a||a.send(c)}catch(t){console.log(t)}},jsError:function(t,e,r){this.log(this.level.error,this.type.js,{msg:t,stack:e,ext:r})},level:{log:"l",error:"e",warn:"w"},type:{click:"cl",pv:"pv",view:"view",custom:"c",api:"a",apiBusiness:"ab",js:"j",src:"s",promise:"p",fail:"f"},_toStr:function(t){return"object"===o(t)?JSON.stringify(t):t},_getStr:function(t,e,r){if("[object Object]"==Object.prototype.toString.call(t))for(var n in t)this._getStr(t[n],e+"."+n,r);else"[object Array]"==Object.prototype.toString.call(t)?t.forEach((function(t){r.push("".concat(e,"=").concat(encodeURIComponent(t)))})):r.push("".concat(e,"=").concat(encodeURIComponent(t)))},objectToQuery:function(t){var e=[];for(var r in t)void 0!==t[r]&&this._getStr(t[r],r,e);return e.join("&")},observer:function(t,e){this.isTrack&&(this.viewportMap[t.dataset.xm]&&!e&&((t.time-this.viewportMap[t.dataset.xm]>=this.viewTime&&!this.reportedData[t.dataset.xm]||t.time-this.reportedData[t.dataset.xm]>this.reportedTime)&&(this.viewLog(this.datasetStrByData(t.dataset.xm)),this.reportedData[t.dataset.xm]=t.time),delete this.viewportMap[t.dataset.xm]),!this.viewportMap[t.dataset.xm]&&e&&(this.viewportMap[t.dataset.xm]=t.time))},departureViewport:function(){var t=this;Object.entries(this.viewportMap).forEach((function(e){var r=p(e,2),n=r[0],o=r[1];Date.now()-o>=t.viewTime&&(t.viewLog(t.datasetStrByData(n)),t.reportedData[n]=Date.now())})),this.viewportMap={}},datasetStrByData:function(t){return t.split(",").reduce((function(t,e){var r=p(e.split(":"),2),n=r[0],o=r[1];return t[n]=o,t}),{})}};try{var T=wx.getStorageSync("_xm_log_cid");T?N.cid=T:(N.cid=Date.now()+"-"+Math.ceil(1e6*Math.random()),wx.setStorage({key:"_xm_log_cid",data:N.cid}))}catch(t){try{console.log(t),N.jsError("_xm_log_cid init err",t)}catch(t){console.log(t)}}t._xmLog=N,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
/*! @xm-fe/xm-mp-log 0.2.2-gamma.2 */ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).monitor={})}(this,(function(t){"use strict";function e(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function r(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?e(Object(n),!0).forEach((function(e){c(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):e(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function n(){n=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",s=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function l(t,e,r,n){var i=e&&e.prototype instanceof p?e:p,a=Object.create(i.prototype),s=new _(n||[]);return o(a,"_invoke",{value:x(t,r,s)}),a}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=l;var h={};function p(){}function d(){}function y(){}var g={};u(g,a,(function(){return this}));var v=Object.getPrototypeOf,m=v&&v(v(k([])));m&&m!==e&&r.call(m,a)&&(g=m);var w=y.prototype=p.prototype=Object.create(g);function b(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function S(t,e){function n(o,i,a,s){var c=f(t[o],t,i);if("throw"!==c.type){var u=c.arg,l=u.value;return l&&"object"==typeof l&&r.call(l,"__await")?e.resolve(l.__await).then((function(t){n("next",t,a,s)}),(function(t){n("throw",t,a,s)})):e.resolve(l).then((function(t){u.value=t,a(u)}),(function(t){return n("throw",t,a,s)}))}s(c.arg)}var i;o(this,"_invoke",{value:function(t,r){function o(){return new e((function(e,o){n(t,r,e,o)}))}return i=i?i.then(o,o):o()}})}function x(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return L()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var s=j(a,r);if(s){if(s===h)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=f(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===h)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function j(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,j(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),h;var o=f(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,h;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,h):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,h)}function O(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function P(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function _(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(O,this),this.reset(!0)}function k(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:L}}function L(){return{value:void 0,done:!0}}return d.prototype=y,o(w,"constructor",{value:y,configurable:!0}),o(y,"constructor",{value:d,configurable:!0}),d.displayName=u(y,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,y):(t.__proto__=y,u(t,c,"GeneratorFunction")),t.prototype=Object.create(w),t},t.awrap=function(t){return{__await:t}},b(S.prototype),u(S.prototype,s,(function(){return this})),t.AsyncIterator=S,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new S(l(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},b(w),u(w,c,"Generator"),u(w,a,(function(){return this})),u(w,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=k,_.prototype={constructor:_,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(P),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var s=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(s&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,h):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),h},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),P(r),h}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;P(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:k(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),h}},t}function o(t){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o(t)}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,v(n.key),n)}}function s(t,e,r){return e&&a(t.prototype,e),r&&a(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function c(t,e,r){return(e=v(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function u(t){return u=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},u(t)}function l(t,e){return l=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},l(t,e)}function f(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function h(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=u(t);if(e){var o=u(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return f(this,r)}}function p(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,s=[],c=!0,u=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(s.push(n.value),s.length!==e);c=!0);}catch(t){u=!0,o=t}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(u)throw o}}return s}}(t,e)||y(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function d(t){return function(t){if(Array.isArray(t))return g(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||y(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function y(t,e){if(t){if("string"==typeof t)return g(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?g(t,e):void 0}}function g(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function v(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}function m(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=[];return Object.keys(e).forEach((function(t){r.push("".concat(t,"=").concat(e[t]))})),0===r.length?"/".concat(t):"/".concat(t).concat(-1!==t.indexOf("?")?"&":"?").concat(r.join("&"))}var w=Object.defineProperty,b=Object.getOwnPropertySymbols,S=Object.prototype.hasOwnProperty,x=Object.prototype.propertyIsEnumerable,j=function(t,e,r){return e in t?w(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r},O=function(t,e){for(var r in e||(e={}))S.call(e,r)&&j(t,r,e[r]);if(b){var n,o=function(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=y(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,s=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return a=t.done,t},e:function(t){s=!0,i=t},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw i}}}}(b(e));try{for(o.s();!(n=o.n()).done;){r=n.value;x.call(e,r)&&j(t,r,e[r])}}catch(t){o.e(t)}finally{o.f()}}return t};var P=function(t){var e={request:function(){},httpRequest:function(){},getSystemInfoSync:function(){}},r="unknown";if("object"===("undefined"==typeof wx?"undefined":o(wx)))e=wx,r="wechat";else if("object"===("undefined"==typeof dd?"undefined":o(dd)))e=dd,r="dingtalk";else if("object"===("undefined"==typeof my?"undefined":o(my)))e=my,r="alipay";else if("object"===("undefined"==typeof tt?"undefined":o(tt)))e=tt,r="bytedance";else if("object"===("undefined"==typeof qq?"undefined":o(qq)))e=qq,r="qq";else if("object"===("undefined"==typeof swan?"undefined":o(swan)))e=swan,r="swan";else{if(!t.platformSDK)throw new Error("Current platform is not default supported by SLS API, Pleace config platformSDK or contack Aliyun SLS team.");e=t.platformSDK}var n,i,a=(n=e,{getStorageSync:function(t){return"function"==typeof n.getStorageSync?n.getStorageSync(t):null},setStorageSync:function(t,e){"function"==typeof n.setStorageSync&&n.setStorageSync(t,e)},getCurrentPagesInterop:i=function(){return"function"!=typeof getCurrentPages?[]:getCurrentPages()},getNavigateBackUrl:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,e=getCurrentPages();if(!e.length)return"";var r=e[e.length-t];return m(r.route,r.options)},getCurrentUrl:function(){var t=i();if(!t.length)return"";var e=t.pop();return m(e.route,e.options)}});return O({sdk:e,appName:r},a)};function _(t,e){var r,n="unknown";if(e&&t[e])r=t[e],n=e;else if(t.request)r=t.request,n="request";else{if(!t.httpRequest)throw new Error("Current platform is not default supported by SLS API, Pleace config platformRequestName or contack Aliyun SLS team.");r=t.httpRequest,n="httpRequest"}return{request:r,requestName:n}}function k(t,e,r,o,i,a){return s=this,c=null,u=n().mark((function s(){var c,u,l;return n().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return t=t.slice(0,-6),n.next=3,i.process(t,e);case 3:c=n.sent,u=c.data,l=c.header,(0,_(r,a).request)(!o||"alipay"!=o&&"dingtalk"!=o?{url:t,method:"POST",data:u,header:l}:{url:t,method:"POST",data:u,headers:l});case 8:case"end":return n.stop()}}),s)})),new Promise((function(t,e){var r=function(t){try{o(u.next(t))}catch(t){e(t)}},n=function(t){try{o(u.throw(t))}catch(t){e(t)}},o=function(e){return e.done?t(e.value):Promise.resolve(e.value).then(r,n)};o((u=u.apply(s,c)).next())}));var s,c,u}var L=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&l(t,e)}(r,t);var e=h(r);function r(t){i(this,r);var n=P(t).sdk,o=Object.assign({},t,{sendPayload:function(e,r){!function(t,e,r,n){(0,_(r,n).request)({url:"".concat(t,"?APIVersion=0.6.0"),method:"POST",data:e})}(e,r,n,t.platformRequestName)}});return e.call(this,o)}return s(r,[{key:"useStsPlugin",value:function(t){var e=this,r=P(this.getOpt()),n=r.sdk,o=r.appName;this.getOpt().sendPayload=function(r,i){var a=e.getOpt();k(r,i,n,o,t,a.platformRequestName)},this.overwriteTransString(t)}}]),r}(function(){function t(e){var r,n,o=this;i(this,t),this.timer=null,this.time=10,this.count=10,this.arr=[],this.time=null!=(r=e.time)?r:10,this.count=null!=(n=e.count)?n:10,e.host.startsWith("http://")||e.host.startsWith("https://")?this.url=e.host+"/logstores/"+e.logstore+"/track":this.url="https://"+e.project+"."+e.host+"/logstores/"+e.logstore+"/track",this.opt=e,e.installUnloadHook&&"function"==typeof e.installUnloadHook&&e.installUnloadHook((function(){o.sendImmediateInner()}))}return s(t,[{key:"assemblePayload",value:function(t){var e={__logs__:t};return this.opt.tags&&(e.__tags__=this.opt.tags),this.opt.topic&&(e.__topic__=this.opt.topic),this.opt.source&&(e.__source__=this.opt.source),JSON.stringify(e)}},{key:"platformSend",value:function(){if(this.opt.sendPayload&&"function"==typeof this.opt.sendPayload){var t=this.assemblePayload(this.arr);this.opt.sendPayload(this.url,t)}}},{key:"transString",value:function(t){var e={};for(var r in t)"object"==o(t[r])?e[r]=JSON.stringify(t[r]):e[r]=String(t[r]);return e}},{key:"sendImmediateInner",value:function(){this.arr&&this.arr.length>0&&(this.platformSend(),null!=this.timer&&(clearTimeout(this.timer),this.timer=null),this.arr=[])}},{key:"sendInner",value:function(){if(this.timer)this.arr.length>=this.count&&(clearTimeout(this.timer),this.timer=null,this.sendImmediateInner());else{var t=this;this.arr.length>=this.count||this.time<=0?this.sendImmediateInner():this.timer=setTimeout((function(){t.sendImmediateInner()}),1e3*this.time)}}},{key:"send",value:function(t){var e=this.transString(t);this.arr.push(e),this.sendInner()}},{key:"sendImmediate",value:function(t){var e=this.transString(t);this.arr.push(e),this.sendImmediateInner()}},{key:"sendBatchLogs",value:function(t){var e,r=this,n=t.map((function(t){return r.transString(t)}));(e=this.arr).push.apply(e,d(n)),this.sendInner()}},{key:"sendBatchLogsImmediate",value:function(t){var e,r=this,n=t.map((function(t){return r.transString(t)}));(e=this.arr).push.apply(e,d(n)),this.sendImmediateInner()}},{key:"overwriteTransString",value:function(t){this.transString=t.transString}},{key:"getOpt",value:function(){return this.opt}}]),t}()),I="0.2.2-gamma.2",E={host:"https://xianmu-front-end-log.cn-hangzhou.log.aliyuncs.com",project:"xianmu-front-end-log",logstore:"fe-test",time:10,count:10},N={tracker:null,testTracker:new L(E),uid:"",phone:"",userName:"",cid:"",logUrl:"",logstores:"fe-test",env:"mp",ignoreLoginLog:!1,isDev:!1,isTrack:!1,rqCount:0,singleId:Date.now()+"-"+Math.ceil(1e6*Math.random()),viewTime:2e3,reportedTime:15e3,viewportMap:{},reportedData:{},pageName:"",set:function(t){var e=this;if(wx&&wx.getAccountInfoSync?this.env="mp":this.env="h5",t.logUrl&&(this.logUrl=t.logUrl),t.logstores){this.logstores=t.logstores;var n=r({},E);n.logstore=t.logstores,this.tracker=new L(n)}if(t.uid&&(this.uid=t.uid),t.ignoreLoginLog&&(this.ignoreLoginLog=t.ignoreLoginLog),t.userName&&(this.userName=t.userName),t.phone&&(this.phone=t.phone,!this.ignoreLoginLog&&this.customLog("login:"+t.phone+":"+this.userName)),t.isDev&&(this.isDev=t.isDev),t.isTrack){this.isTrack=t.isTrack;try{var o={};wx&&wx.onAppRoute&&wx.onAppHide&&(wx.onAppRoute((function(t){var r,n=o;e.pageName=null==t||null===(r=t.page)||void 0===r?void 0:r.window.navigationBarTitleText,o={path:t.path,query:t.query,ot:t.openType,n:e.pageName},e.pvLog(t.path,{ext:{to:o,from:n}}),e.departureViewport()})),wx.onAppHide((function(t){console.log("onAppHide res",t),e.departureViewport()})))}catch(t){console.log("e onAppRoute",t)}}},pvLog:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.log(this.level.log,this.type.pv,r({tag:1,pageName:t},e))},viewLog:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.log(this.level.log,this.type.view,r({tag:1},t))},customLog:function(t,e){this.log(this.level.log,this.type.custom,{msg:t,ext:e})},clickLog:function(t){this.log(this.level.log,this.type.click,r({tag:1},t))},warn:function(t,e){this.log(this.level.warn,this.type.custom,{msg:t,ext:e})},onResponse:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.statusCode,n=t.data,o=!1,i=!1;try{200!==r&&(o=!0);var a=n||{},s=a.code,c=a.status;(s&&200!==s&&"SUCCESS"!==s||c&&200!==c)&&(i=!0);var u="",l="";"[object Object]"===Object.prototype.toString.call(n)?(u=(null==n?void 0:n.message)||(null==n?void 0:n.error)||(null==n?void 0:n.msg),l=(null==n?void 0:n.message)||(null==n?void 0:n.msg)):(u=n,l=n);var f={data:e.data,method:e.method||"get",qh:e.header,rh:t.header,rt:n},h={ap:e.apiPath,code:r,msg:l,ai:JSON.stringify(f)};o||i?(h.msg=u,o?N.log(this.level.error,this.type.api,h):i&&N.log(this.level.log,this.type.apiBusiness,h)):N.log(this.level.log,this.type.api,h)}catch(t){try{N.jsError("onResponse err: "+t.message,t.stack)}catch(e){console.log("监控报错:",e,t)}}},onError:function(t){this.log(this.level.error,this.type.js,{msg:t})},onFail:function(t,e){try{var r={};r=t&&(t.errMsg||t.errno||t.errCode)?{msg:t.errMsg,eno:t.errno,eco:t.errCode}:{ext:t},e&&e.apiPath?(r.ap=e.apiPath,r.ai=JSON.stringify({data:e.data,method:e.method||"get",header:e.header})):e&&(r.extt=e);t&&([600001,600003,5].includes(t.errno)||600001===t.errCode)?this.log(this.level.warn,this.type.fail,r):this.log(this.level.error,this.type.fail,r)}catch(t){console.log(t)}},getReqHeaders:function(){return{"xm-rqid":Date.now()+"-"+Math.ceil(1e8*Math.random()),"xm-uid":this.uid,"xm-biz":this.logstores,"xm-phone":this.phone,"xm-platform":this.env}},log:function(t,e,n){try{var o={};if(wx&&wx.getAccountInfoSync){if(o=wx.getAccountInfoSync().miniProgram,!N.isDev&&"develop"==o.envVersion)return}else{if(o.version="h5",!N.isDev&&window&&window.location&&window.location.origin&&!window.location.origin.includes("//mall.cosfo.cn"))return;window&&window.location&&window.location.origin&&window.location.origin.includes("//mall.cosfo.cn")?o.envVersion="release":o.envVersion="develop"}var i,a,s=void 0===n.pageName?this.pageName:n.pageName,c=r({v:I,url:getCurrentPages().map((function(t){return t.route})).join("_"),mpv:JSON.stringify({v:o.version,e:o.envVersion}),cid:N.cid,uid:N.uid,phone:N.phone,uName:N.userName,en:N.env,pageName:s,sid:N.singleId,level:t,type:e,count:N.rqCount++},n);if(c.ext&&(c.ext=N._toStr(c.ext)),window&&window.navigator&&window.navigator.userAgent)c.userAgent=window.navigator.userAgent;else if(wx&&"function"==typeof wx.getSystemInfoSync){var u=wx.getSystemInfoSync();c.systemInfo=JSON.stringify(u)}if("release"==o.envVersion)null===(i=N.tracker)||void 0===i||i.send(c);else if(N.isDev)null===(a=N.testTracker)||void 0===a||a.send(c)}catch(t){console.log(t)}},jsError:function(t,e,r){this.log(this.level.error,this.type.js,{msg:t,stack:e,ext:r})},level:{log:"l",error:"e",warn:"w"},type:{click:"cl",pv:"pv",view:"view",custom:"c",api:"a",apiBusiness:"ab",js:"j",src:"s",promise:"p",fail:"f"},_toStr:function(t){return"object"===o(t)?JSON.stringify(t):t},_getStr:function(t,e,r){if("[object Object]"==Object.prototype.toString.call(t))for(var n in t)this._getStr(t[n],e+"."+n,r);else"[object Array]"==Object.prototype.toString.call(t)?t.forEach((function(t){r.push("".concat(e,"=").concat(encodeURIComponent(t)))})):r.push("".concat(e,"=").concat(encodeURIComponent(t)))},objectToQuery:function(t){var e=[];for(var r in t)void 0!==t[r]&&this._getStr(t[r],r,e);return e.join("&")},observer:function(t,e){this.isTrack&&(this.viewportMap[t.dataset.xm]&&!e&&((t.time-this.viewportMap[t.dataset.xm]>=this.viewTime&&!this.reportedData[t.dataset.xm]||t.time-this.reportedData[t.dataset.xm]>this.reportedTime)&&(this.viewLog(this.datasetStrByData(t.dataset.xm)),this.reportedData[t.dataset.xm]=t.time),delete this.viewportMap[t.dataset.xm]),!this.viewportMap[t.dataset.xm]&&e&&(this.viewportMap[t.dataset.xm]=t.time))},departureViewport:function(){var t=this;Object.entries(this.viewportMap).forEach((function(e){var r=p(e,2),n=r[0],o=r[1];Date.now()-o>=t.viewTime&&(t.viewLog(t.datasetStrByData(n)),t.reportedData[n]=Date.now())})),this.viewportMap={}},datasetStrByData:function(t){return t.split(",").reduce((function(t,e){var r=p(e.split(":"),2),n=r[0],o=r[1];return t[n]=o,t}),{})}};try{var T=wx.getStorageSync("_xm_log_cid");T?N.cid=T:(N.cid=Date.now()+"-"+Math.ceil(1e6*Math.random()),wx.setStorage({key:"_xm_log_cid",data:N.cid}))}catch(t){try{console.log(t),N.jsError("_xm_log_cid init err",t)}catch(t){console.log(t)}}t._xmLog=N,Object.defineProperty(t,"__esModule",{value:!0})})); |
{ | ||
"name": "@xm-fe/xm-mp-log", | ||
"version": "0.2.2-gamma.1", | ||
"version": "0.2.2-gamma.2", | ||
"webSdkVersion": "0.1.24", | ||
@@ -5,0 +5,0 @@ "description": "xm-mp-log", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package