@artisan-cloud/ubt-js
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -15,3 +15,3 @@ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).UBT=t()}(this,(function(){"use strict"; | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */function e(e,t,s,n){return new(s||(s=Promise))((function(o,i){function r(e){try{c(n.next(e))}catch(e){i(e)}}function a(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(r,a)}c((n=n.apply(e,t||[])).next())}))}const t={config:{env:"dev",debug:!0},baseParams:{appName:"",appVersion:""},systemInfo:{platform:"Wechat",deviceModel:"-1",screenWidth:-1,screenHeight:-1,language:"-1",wechatVersion:"-1",mpSdkVersion:"-1",osVersion:"-1",brand:"-1",model:"-1",network:"-1",lon:"-1",lat:"-1"}};function s(e){return t=>new Promise(((s,n)=>{e(Object.assign(Object.assign({},t),{success(e){s(e)},fail(e){n(e)}}))}))}const n=s(wx.request),o=s(wx.getSystemInfo);class i{static request(e){return n(Object.assign({},e)).then((e=>(console.log("data...",e),e)))}static getSystemInfo(){return o()}}class r{static debug(...e){this.base("debug",...e)}static info(...e){this.base("info",e)}static warn(...e){this.base("warn",e)}static error(...e){this.base("error",e)}static base(e,...t){console.log(`%c [UBT] ${e.toUpperCase()}`,this.getColorMapping(e),...t)}static getColorMapping(e){const{colorMapping:t}=this;return t[e]?t[e]:"background: #222; color: #bada55"}}r.colorMapping={debug:"background: #222; color: #bada55",info:"background: #222; color: #bada55",warn:"background: #222; color: #bada55",error:"background: #222; color: #bada55"};class a{get(e){return i.request({url:e})}post(e,t){return i.request({method:"POST",url:e})}}return r.debug("Hello, UBT!!!"),class extends class extends class{constructor(e){this.ready=!1,this.config={reportUrl:"",bindData:{}},this.messageStacks=[];const{config:t}=this;Object.assign(t,e),r.debug("config: ",t)}init(){return e(this,void 0,void 0,(function*(){}))}debug(e,t){this.base("debug",e,t)}info(e,t){this.base("info",e,t)}notice(e,t){this.base("notice",e,t)}error(e,t){this.base("error",e,t)}sendError(e){try{if(!(e instanceof Error))return void r.warn("sendError收到了一个非Error类型的参数,已经被忽略",e);this.base("error",e.message,{},{error:{stack:e.stack}})}catch(e){r.error(e)}}base(e,t,s,n){return r.error("1111fuck..."),Promise.resolve()}sendStashMessage(){this.messageStacks.length&&(this.sendMessage(this.messageStacks),this.messageStacks=[])}sendMessage(t){return e(this,void 0,void 0,(function*(){}))}getBindData(){return e(this,void 0,void 0,(function*(){r.debug("fuck...",this);const e={},{config:{bindData:t}}=this;for(let s of Object.keys(t))if("function"==typeof t[s]){let n=t[s]();n&&n.then&&(n=yield n),e[s]=n}else e[s]=t[s];return e}))}}{clickButton({pageId:e,buttonName:t,categoryId:s,businessInfo:n}){this.base("info","",n,{buttonName:t,pageId:e,categoryId:s,logType:"clickButton"})}pageView({pageId:e,categoryId:t,businessInfo:s}){this.base("info","",s,{pageId:e,categoryId:t,logType:"pageView"})}pageViewOut({pageId:e,categoryId:t,businessInfo:s}){this.base("info","",s,{pageId:e,categoryId:t,logType:"pageViewOut"})}}{constructor(e){super(e),this.request=new a,this.init()}init(){return e(this,void 0,void 0,(function*(){try{r.debug("WechatUBT init...");const e=yield i.getSystemInfo();r.debug("systemInfo: ",e);const{brand:s,platform:n,screenWidth:o,screenHeight:a,language:c,model:g,version:d,wifiEnabled:u,SDKVersion:f,system:l}=e;Object.assign(t.systemInfo,{brand:s,platform:n,screenWidth:o,screenHeight:a,language:c,deviceModel:g,wechatVersion:d,network:u?"wifi":"cellular",sdkVersion:f,osVersion:l}),this.ready=!0,this.sendStashMessage(),r.debug("WechatUBT init success...")}catch(e){r.error(e)}}))}base(s,n,o,i={}){return e(this,void 0,void 0,(function*(){try{const{getBindData:e,messageStacks:a}=this,c=yield e.call(this),g=s.toUpperCase(),d=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},t.baseParams),t.systemInfo),c),{businessData:o,msg:n}),i),u=`${(new Date).toJSON()} ${g} ${JSON.stringify(d)}`;if(!this.ready&&a.length<100)return r.info("ubt not ready, message on wait...",u),void a.push(u);r.info("send Message: ",u),this.sendMessage([u])}catch(e){r.error("log请求参数生成失败:",e)}}))}sendMessage(t){return e(this,void 0,void 0,(function*(){try{const{request:e,config:{reportUrl:s}}=this;r.info(`${s}?loggingList=${encodeURIComponent(JSON.stringify(t))}`),yield e.get(`${s}?loggingList=${encodeURIComponent(JSON.stringify(t))}`)}catch(e){r.error("log请求出错了:",e)}}))}}})); | ||
***************************************************************************** */function e(e,t,s,n){return new(s||(s=Promise))((function(o,i){function r(e){try{c(n.next(e))}catch(e){i(e)}}function a(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(r,a)}c((n=n.apply(e,t||[])).next())}))}const t={config:{env:"dev",debug:!0},baseParams:{appName:"",appVersion:""},systemInfo:{platform:"Wechat",deviceModel:"-1",screenWidth:-1,screenHeight:-1,language:"-1",wechatVersion:"-1",mpSdkVersion:"-1",osVersion:"-1",brand:"-1",model:"-1",network:"-1",lon:"-1",lat:"-1"}};function s(e){return t=>new Promise(((s,n)=>{e(Object.assign(Object.assign({},t),{success(e){s(e)},fail(e){n(e)}}))}))}const n=s(wx.request),o=s(wx.getSystemInfo);class i{static request(e){return n(Object.assign({},e)).then((e=>(console.log("data...",e),e)))}static getSystemInfo(){return o()}}class r{static debug(...e){this.base("debug",...e)}static info(...e){this.base("info",...e)}static warn(...e){this.base("warn",...e)}static error(...e){this.base("error",...e)}static base(e,...t){const s=new Date,n=`${s.getFullYear()}-${`0${s.getMonth()+1}`.slice(-2)}-${`0${s.getDate()}`.slice(-2)} ${`0${s.getHours()}`.slice(-2)}:${`0${s.getMinutes()}`.slice(-2)}:${`0${s.getSeconds()}`.slice(-2)}`;console.log(`%c [UBT] ${n} ${e.toUpperCase()}`,this.getColorMapping(e),...t)}static getColorMapping(e){const{colorMapping:t}=this;return t[e]?t[e]:"background: #222; color: #bada55"}}r.colorMapping={debug:"background: #222; color: #59aaff",info:"background: #222; color: #29c3e0",warn:"background: #222; color: #ffcc2b",error:"background: #222; color: #f37f89"};class a{get(e){return i.request({url:e})}post(e,t){return i.request({method:"POST",url:e})}}return r.debug("Hello, UBT!!!"),class extends class extends class{constructor(e){this.ready=!1,this.config={reportUrl:"",bindData:{}},this.messageStacks=[];const{config:t}=this;Object.assign(t,e),r.debug("config: ",t)}init(){return e(this,void 0,void 0,(function*(){}))}debug(e,t){this.base("debug",e,t)}info(e,t){this.base("info",e,t)}notice(e,t){this.base("notice",e,t)}error(e,t){this.base("error",e,t)}sendError(e){try{if(!(e instanceof Error))return void r.warn("sendError收到了一个非Error类型的参数,已经被忽略",e);this.base("error",e.message,{},{error:{stack:e.stack}})}catch(e){r.error(e)}}base(e,t,s,n){return Promise.resolve()}sendStashMessage(){this.messageStacks.length&&(this.sendMessage(this.messageStacks),this.messageStacks=[])}sendMessage(t){return e(this,void 0,void 0,(function*(){}))}getBindData(){return e(this,void 0,void 0,(function*(){const e={},{config:{bindData:t}}=this;for(let s of Object.keys(t))if("function"==typeof t[s]){let n=t[s]();n&&n.then&&(n=yield n),e[s]=n}else e[s]=t[s];return e}))}}{clickButton({pageId:e,buttonName:t,categoryId:s,businessInfo:n}){this.base("info","",n,{buttonName:t,pageId:e,categoryId:s,logType:"clickButton"})}pageView({pageId:e,categoryId:t,businessInfo:s}){this.base("info","",s,{pageId:e,categoryId:t,logType:"pageView"})}pageViewOut({pageId:e,categoryId:t,businessInfo:s}){this.base("info","",s,{pageId:e,categoryId:t,logType:"pageViewOut"})}}{constructor(e){super(e),this.request=new a,this.init()}init(){return e(this,void 0,void 0,(function*(){try{r.debug("WechatUBT init...");const e=yield i.getSystemInfo();r.debug("systemInfo: ",e);const{brand:s,platform:n,screenWidth:o,screenHeight:a,language:c,model:g,version:d,wifiEnabled:u,SDKVersion:l,system:f}=e;Object.assign(t.systemInfo,{brand:s,platform:n,screenWidth:o,screenHeight:a,language:c,deviceModel:g,wechatVersion:d,network:u?"wifi":"cellular",sdkVersion:l,osVersion:f}),this.ready=!0,this.sendStashMessage(),r.debug("WechatUBT init success...")}catch(e){r.error(e)}}))}base(s,n,o,i={}){return e(this,void 0,void 0,(function*(){try{const{getBindData:e,messageStacks:a}=this,c=yield e.call(this),g=s.toUpperCase(),d=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},t.baseParams),t.systemInfo),c),{businessData:o,msg:n}),i),u=`${(new Date).toJSON()} ${g} ${JSON.stringify(d)}`;if(!this.ready&&a.length<100)return r.info("ubt not ready, message on wait...",u),void a.push(u);r.info("send Message: ",u),this.sendMessage([u])}catch(e){r.error("log请求参数生成失败:",e)}}))}setReportUrl(e){this.config.reportUrl=e,r.debug("change reportUrl "+e)}sendMessage(t){return e(this,void 0,void 0,(function*(){try{const{request:e,config:{reportUrl:s}}=this;yield e.get(`${s}?loggingList=${encodeURIComponent(JSON.stringify(t))}`)}catch(e){r.error("log请求出错了:",e)}}))}}})); | ||
//# sourceMappingURL=wechat.js.map |
@@ -90,12 +90,14 @@ /*! ***************************************************************************** | ||
static info(...args) { | ||
this.base('info', args); | ||
this.base('info', ...args); | ||
} | ||
static warn(...args) { | ||
this.base('warn', args); | ||
this.base('warn', ...args); | ||
} | ||
static error(...args) { | ||
this.base('error', args); | ||
this.base('error', ...args); | ||
} | ||
static base(logLevel, ...args) { | ||
console.log(`%c [UBT] ${logLevel.toUpperCase()}`, this.getColorMapping(logLevel), ...args); | ||
const m = new Date(); | ||
const dateString = `${m.getFullYear()}-${(`0${m.getMonth() + 1}`).slice(-2)}-${(`0${m.getDate()}`).slice(-2)} ${(`0${m.getHours()}`).slice(-2)}:${(`0${m.getMinutes()}`).slice(-2)}:${(`0${m.getSeconds()}`).slice(-2)}`; | ||
console.log(`%c [UBT] ${dateString} ${logLevel.toUpperCase()}`, this.getColorMapping(logLevel), ...args); | ||
} | ||
@@ -111,6 +113,6 @@ static getColorMapping(logLevel) { | ||
Log.colorMapping = { | ||
'debug': 'background: #222; color: #bada55', | ||
'info': 'background: #222; color: #bada55', | ||
'warn': 'background: #222; color: #bada55', | ||
'error': 'background: #222; color: #bada55', | ||
'debug': 'background: #222; color: #59aaff', | ||
'info': 'background: #222; color: #29c3e0', | ||
'warn': 'background: #222; color: #ffcc2b', | ||
'error': 'background: #222; color: #f37f89', | ||
}; | ||
@@ -163,3 +165,2 @@ | ||
base(logLevel, msg, businessData, extData) { | ||
Log.error('1111fuck...'); | ||
return Promise.resolve(); | ||
@@ -179,3 +180,2 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
Log.debug('fuck...', this); | ||
const data = {}; | ||
@@ -291,2 +291,10 @@ const { config: { bindData } } = this; | ||
} | ||
/** | ||
* 设置reportUrl | ||
* @param url | ||
*/ | ||
setReportUrl(url) { | ||
this.config.reportUrl = url; | ||
Log.debug("change reportUrl " + url); | ||
} | ||
sendMessage(messageList) { | ||
@@ -296,3 +304,2 @@ return __awaiter(this, void 0, void 0, function* () { | ||
const { request, config: { reportUrl } } = this; | ||
Log.info(`${reportUrl}?loggingList=${encodeURIComponent(JSON.stringify(messageList))}`); | ||
yield request.get(`${reportUrl}?loggingList=${encodeURIComponent(JSON.stringify(messageList))}`); | ||
@@ -299,0 +306,0 @@ } |
{ | ||
"name": "@artisan-cloud/ubt-js", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "ubt js", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
18585
365
0