Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@xm-fe/xm-mp-log

Package Overview
Dependencies
Maintainers
8
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xm-fe/xm-mp-log - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

4

lib/xm-mp-log.es5.min.js

@@ -1,2 +0,2 @@

/*! @xm-fe/xm-mp-log 0.1.5 */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).monitor={})}(this,(function(e){"use strict";function t(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,r)}return o}function o(e){for(var o=1;o<arguments.length;o++){var r=null!=arguments[o]?arguments[o]:{};o%2?t(Object(r),!0).forEach((function(t){i(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):t(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function r(e){return r="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},r(e)}function i(e,t,o){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var o=e[Symbol.toPrimitive];if(void 0!==o){var r=o.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function n(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var r,i,n,a,s=[],c=!0,l=!1;try{if(n=(o=o.call(e)).next,0===t){if(Object(o)!==o)return;c=!1}else for(;!(c=(r=n.call(o)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&null!=o.return&&(a=o.return(),Object(a)!==a))return}finally{if(l)throw i}}return s}}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return a(e,t);var o=Object.prototype.toString.call(e).slice(8,-1);"Object"===o&&e.constructor&&(o=e.constructor.name);if("Map"===o||"Set"===o)return Array.from(e);if("Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o))return a(e,t)}(e,t)||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 a(e,t){(null==t||t>e.length)&&(t=e.length);for(var o=0,r=new Array(t);o<t;o++)r[o]=e[o];return r}var s={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(e){var t=this;if(wx&&wx.getAccountInfoSync?this.env="mp":this.env="h5",e.logUrl&&(this.logUrl=e.logUrl),e.logstores&&(this.logstores=e.logstores),e.uid&&(this.uid=e.uid),e.ignoreLoginLog&&(this.ignoreLoginLog=e.ignoreLoginLog),e.userName&&(this.userName=e.userName),e.phone&&(this.phone=e.phone,!this.ignoreLoginLog&&this.customLog("login:"+e.phone+":"+this.userName)),e.isDev&&(this.isDev=e.isDev),e.isTrack){this.isTrack=e.isTrack;try{var o={};wx&&wx.onAppRoute&&wx.onAppHide&&(wx.onAppRoute((function(e){var r,i=o;t.pageName=null==e||null===(r=e.page)||void 0===r?void 0:r.window.navigationBarTitleText,o={path:e.path,query:e.query,ot:e.openType,n:t.pageName},t.pvLog(e.path,{ext:{to:o,from:i}}),t.departureViewport()})),wx.onAppHide((function(e){console.log("onAppHide res",e),t.departureViewport()})))}catch(e){console.log("e onAppRoute",e)}}},pvLog:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.log(this.level.log,this.type.pv,o({tag:1,pageName:e},t))},viewLog:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.log(this.level.log,this.type.view,o({tag:1},e))},customLog:function(e,t){this.log(this.level.log,this.type.custom,{msg:e,ext:t})},clickLog:function(e){this.log(this.level.log,this.type.click,o({tag:1},e))},warn:function(e,t){this.log(this.level.warn,this.type.custom,{msg:e,ext:t})},onResponse:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=e.statusCode,r=e.data,i=!1,n=!1;try{200!==o&&(i=!0);var a=r||{},c=a.code,l=a.status;if((c&&200!==c&&"SUCCESS"!==c||l&&200!==l)&&(n=!0),i||n){var u=r.message||r.error||r.msg,p={data:t.data,method:t.method||"get",qh:t.header,rh:e.header,rt:r},g={ap:t.apiPath,code:o,msg:u,ai:JSON.stringify(p)};i?s.log(this.level.error,this.type.api,g):n&&s.log(this.level.log,this.type.apiBusiness,g)}}catch(e){try{s.jsError("onResponse err: "+e.message,e.stack)}catch(t){console.log("监控报错:",t,e)}}},onError:function(e){this.log(this.level.error,this.type.js,{msg:e})},onFail:function(e,t){try{var o={};o=e&&(e.errMsg||e.errno||e.errCode)?{msg:e.errMsg,eno:e.errno,eco:e.errCode}:{ext:e},t&&t.apiPath?(o.ap=t.apiPath,o.ai=JSON.stringify({data:t.data,method:t.method||"get",header:t.header})):t&&(o.extt=t),this.log(this.level.error,this.type.fail,o)}catch(e){console.log(e)}},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(e,t,r){try{var i={};if(wx&&wx.getAccountInfoSync){if(i=wx.getAccountInfoSync().miniProgram,!s.isDev&&"develop"==i.envVersion)return}else{if(!s.isDev&&window&&window.location&&window.location.origin&&!window.location.origin.includes("//mall.cosfo.cn"))return;i.version="h5",window&&window.location&&window.location.origin&&!window.location.origin.includes("//mall.cosfo.cn")?i.envVersion="release":i.envVersion="develop"}var n=void 0===r.pageName?this.pageName:r.pageName,a=o({v:"0.1.5",url:getCurrentPages().map((function(e){return e.route})).join("_"),mpv:JSON.stringify({v:i.version,e:i.envVersion}),cid:s.cid,uid:s.uid,phone:s.phone,uName:s.userName,en:s.env,pageName:n,sid:s.singleId,level:e,type:t,count:s.rqCount++},r);a.ext&&(a.ext=s._toStr(a.ext));var c=s.logUrl+("release"==i.envVersion?s.logstores:"fe-test")+"/track_ua.gif";wx.request({url:"".concat(c,"?APIVersion=0.6.0&").concat(s.objectToQuery(a))})}catch(e){console.log(e)}},jsError:function(e,t,o){this.log(this.level.error,this.type.js,{msg:e,stack:t,ext:o})},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(e){return"object"===r(e)?JSON.stringify(e):e},_getStr:function(e,t,o){if("[object Object]"==Object.prototype.toString.call(e))for(var r in e)this._getStr(e[r],t+"."+r,o);else"[object Array]"==Object.prototype.toString.call(e)?e.forEach((function(e){o.push("".concat(t,"=").concat(encodeURIComponent(e)))})):o.push("".concat(t,"=").concat(encodeURIComponent(e)))},objectToQuery:function(e){var t=[];for(var o in e)void 0!==e[o]&&this._getStr(e[o],o,t);return t.join("&")},observer:function(e,t){this.isTrack&&(this.viewportMap[e.dataset.xm]&&!t&&((e.time-this.viewportMap[e.dataset.xm]>=this.viewTime&&!this.reportedData[e.dataset.xm]||e.time-this.reportedData[e.dataset.xm]>this.reportedTime)&&(this.viewLog(this.datasetStrByData(e.dataset.xm)),this.reportedData[e.dataset.xm]=e.time),delete this.viewportMap[e.dataset.xm]),!this.viewportMap[e.dataset.xm]&&t&&(this.viewportMap[e.dataset.xm]=e.time))},departureViewport:function(){var e=this;Object.entries(this.viewportMap).forEach((function(t){var o=n(t,2),r=o[0],i=o[1];Date.now()-i>=e.viewTime&&(e.viewLog(e.datasetStrByData(r)),e.reportedData[r]=Date.now())})),this.viewportMap={}},datasetStrByData:function(e){return e.split(",").reduce((function(e,t){var o=n(t.split(":"),2),r=o[0],i=o[1];return e[r]=i,e}),{})}};try{var c=wx.getStorageSync("_xm_log_cid");c?s.cid=c:(s.cid=Date.now()+"-"+Math.ceil(1e6*Math.random()),wx.setStorage({key:"_xm_log_cid",data:s.cid}))}catch(e){try{console.log(e),s.jsError("_xm_log_cid init err",e)}catch(e){console.log(e)}}e._xmLog=s,Object.defineProperty(e,"__esModule",{value:!0})}));
/*! @xm-fe/xm-mp-log 0.1.6 */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).monitor={})}(this,(function(e){"use strict";function t(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,r)}return o}function o(e){for(var o=1;o<arguments.length;o++){var r=null!=arguments[o]?arguments[o]:{};o%2?t(Object(r),!0).forEach((function(t){i(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):t(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function r(e){return r="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},r(e)}function i(e,t,o){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var o=e[Symbol.toPrimitive];if(void 0!==o){var r=o.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function n(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var r,i,n,a,s=[],c=!0,l=!1;try{if(n=(o=o.call(e)).next,0===t){if(Object(o)!==o)return;c=!1}else for(;!(c=(r=n.call(o)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&null!=o.return&&(a=o.return(),Object(a)!==a))return}finally{if(l)throw i}}return s}}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return a(e,t);var o=Object.prototype.toString.call(e).slice(8,-1);"Object"===o&&e.constructor&&(o=e.constructor.name);if("Map"===o||"Set"===o)return Array.from(e);if("Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o))return a(e,t)}(e,t)||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 a(e,t){(null==t||t>e.length)&&(t=e.length);for(var o=0,r=new Array(t);o<t;o++)r[o]=e[o];return r}var s={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(e){var t=this;if(wx&&wx.getAccountInfoSync?this.env="mp":this.env="h5",e.logUrl&&(this.logUrl=e.logUrl),e.logstores&&(this.logstores=e.logstores),e.uid&&(this.uid=e.uid),e.ignoreLoginLog&&(this.ignoreLoginLog=e.ignoreLoginLog),e.userName&&(this.userName=e.userName),e.phone&&(this.phone=e.phone,!this.ignoreLoginLog&&this.customLog("login:"+e.phone+":"+this.userName)),e.isDev&&(this.isDev=e.isDev),e.isTrack){this.isTrack=e.isTrack;try{var o={};wx&&wx.onAppRoute&&wx.onAppHide&&(wx.onAppRoute((function(e){var r,i=o;t.pageName=null==e||null===(r=e.page)||void 0===r?void 0:r.window.navigationBarTitleText,o={path:e.path,query:e.query,ot:e.openType,n:t.pageName},t.pvLog(e.path,{ext:{to:o,from:i}}),t.departureViewport()})),wx.onAppHide((function(e){console.log("onAppHide res",e),t.departureViewport()})))}catch(e){console.log("e onAppRoute",e)}}},pvLog:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.log(this.level.log,this.type.pv,o({tag:1,pageName:e},t))},viewLog:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.log(this.level.log,this.type.view,o({tag:1},e))},customLog:function(e,t){this.log(this.level.log,this.type.custom,{msg:e,ext:t})},clickLog:function(e){this.log(this.level.log,this.type.click,o({tag:1},e))},warn:function(e,t){this.log(this.level.warn,this.type.custom,{msg:e,ext:t})},onResponse:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=e.statusCode,r=e.data,i=!1,n=!1;try{200!==o&&(i=!0);var a=r||{},c=a.code,l=a.status;(c&&200!==c&&"SUCCESS"!==c||l&&200!==l)&&(n=!0);var u=r.message||r.error||r.msg,p=r.message||r.msg,g={data:t.data,method:t.method||"get",qh:t.header,rh:e.header,rt:r},h={ap:t.apiPath,code:o,msg:p,ai:JSON.stringify(g)};i||n?(h.msg=u,i?s.log(this.level.error,this.type.api,h):n&&s.log(this.level.log,this.type.apiBusiness,h)):s.log(this.level.log,this.type.api,h)}catch(e){try{s.jsError("onResponse err: "+e.message,e.stack)}catch(t){console.log("监控报错:",t,e)}}},onError:function(e){this.log(this.level.error,this.type.js,{msg:e})},onFail:function(e,t){try{var o={};o=e&&(e.errMsg||e.errno||e.errCode)?{msg:e.errMsg,eno:e.errno,eco:e.errCode}:{ext:e},t&&t.apiPath?(o.ap=t.apiPath,o.ai=JSON.stringify({data:t.data,method:t.method||"get",header:t.header})):t&&(o.extt=t),this.log(this.level.error,this.type.fail,o)}catch(e){console.log(e)}},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(e,t,r){try{var i={};if(wx&&wx.getAccountInfoSync){if(i=wx.getAccountInfoSync().miniProgram,!s.isDev&&"develop"==i.envVersion)return}else{if(!s.isDev&&window&&window.location&&window.location.origin&&!window.location.origin.includes("//mall.cosfo.cn"))return;i.version="h5",window&&window.location&&window.location.origin&&!window.location.origin.includes("//mall.cosfo.cn")?i.envVersion="release":i.envVersion="develop"}var n=void 0===r.pageName?this.pageName:r.pageName,a=o({v:"0.1.6",url:getCurrentPages().map((function(e){return e.route})).join("_"),mpv:JSON.stringify({v:i.version,e:i.envVersion}),cid:s.cid,uid:s.uid,phone:s.phone,uName:s.userName,en:s.env,pageName:n,sid:s.singleId,level:e,type:t,count:s.rqCount++},r);a.ext&&(a.ext=s._toStr(a.ext));var c=s.logUrl+("release"==i.envVersion?s.logstores:"fe-test")+"/track_ua.gif";wx.request({url:"".concat(c,"?APIVersion=0.6.0&").concat(s.objectToQuery(a))})}catch(e){console.log(e)}},jsError:function(e,t,o){this.log(this.level.error,this.type.js,{msg:e,stack:t,ext:o})},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(e){return"object"===r(e)?JSON.stringify(e):e},_getStr:function(e,t,o){if("[object Object]"==Object.prototype.toString.call(e))for(var r in e)this._getStr(e[r],t+"."+r,o);else"[object Array]"==Object.prototype.toString.call(e)?e.forEach((function(e){o.push("".concat(t,"=").concat(encodeURIComponent(e)))})):o.push("".concat(t,"=").concat(encodeURIComponent(e)))},objectToQuery:function(e){var t=[];for(var o in e)void 0!==e[o]&&this._getStr(e[o],o,t);return t.join("&")},observer:function(e,t){this.isTrack&&(this.viewportMap[e.dataset.xm]&&!t&&((e.time-this.viewportMap[e.dataset.xm]>=this.viewTime&&!this.reportedData[e.dataset.xm]||e.time-this.reportedData[e.dataset.xm]>this.reportedTime)&&(this.viewLog(this.datasetStrByData(e.dataset.xm)),this.reportedData[e.dataset.xm]=e.time),delete this.viewportMap[e.dataset.xm]),!this.viewportMap[e.dataset.xm]&&t&&(this.viewportMap[e.dataset.xm]=e.time))},departureViewport:function(){var e=this;Object.entries(this.viewportMap).forEach((function(t){var o=n(t,2),r=o[0],i=o[1];Date.now()-i>=e.viewTime&&(e.viewLog(e.datasetStrByData(r)),e.reportedData[r]=Date.now())})),this.viewportMap={}},datasetStrByData:function(e){return e.split(",").reduce((function(e,t){var o=n(t.split(":"),2),r=o[0],i=o[1];return e[r]=i,e}),{})}};try{var c=wx.getStorageSync("_xm_log_cid");c?s.cid=c:(s.cid=Date.now()+"-"+Math.ceil(1e6*Math.random()),wx.setStorage({key:"_xm_log_cid",data:s.cid}))}catch(e){try{console.log(e),s.jsError("_xm_log_cid init err",e)}catch(e){console.log(e)}}e._xmLog=s,Object.defineProperty(e,"__esModule",{value:!0})}));
{
"name": "@xm-fe/xm-mp-log",
"version": "0.1.5",
"version": "0.1.6",
"description": "xm-mp-log",

@@ -5,0 +5,0 @@ "keywords": [

@@ -14,2 +14,5 @@ # xm-log

### 0.1.6
- feat: xm-mp-log 小程序接口请求日志收集
### 0.1.5

@@ -16,0 +19,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc