UNPKG

@mitojs/wx-mini

Version:
2 lines (1 loc) 28.6 kB
var MITO=function(e){"use strict";var n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])})(e,t)};function t(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var r=function(){return(r=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var o in n=arguments[t])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e}).apply(this,arguments)};function o(e,n,t,r){return new(t||(t=Promise))((function(o,i){function a(e){try{s(r.next(e))}catch(e){i(e)}}function c(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(a,c)}s((r=r.apply(e,n||[])).next())}))}function i(e,n){var t,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(t)throw new TypeError("Generator is already executing.");for(;a;)try{if(t=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=n.call(e,a)}catch(e){i=[6,e],r=0}finally{t=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}function a(e,n,t){if(t||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return e.concat(r||Array.prototype.slice.call(n))}var c={isLogAddBreadcrumb:!0,crossOriginThreshold:1e3},s=Object.prototype.toString;function u(e){return function(n){return s.call(n)==="[object ".concat(e,"]")}}var l={isNumber:u("Number"),isString:u("String"),isBoolean:u("Boolean"),isNull:u("Null"),isUndefined:u("Undefined"),isSymbol:u("Symbol"),isFunction:u("Function"),isObject:u("Object"),isArray:u("Array"),isProcess:u("process"),isWindow:u("Window")};function p(e){switch(s.call(e)){case"[object Error]":case"[object Exception]":case"[object DOMException]":return!0;default:return function(e,n){try{return e instanceof n}catch(e){return!1}}(e,Error)}}function f(e){return l.isObject(e)&&0===Object.keys(e).length}var h=l.isProcess("undefined"!=typeof process?process:0),d=l.isObject("undefined"!=typeof wx?wx:0)&&l.isFunction("undefined"!=typeof App?App:0),g=l.isWindow("undefined"!=typeof window?window:0);var m=g?window:d?wx:h?process:void 0,v=(m.__MITO__=m.__MITO__||{},m.__MITO__);var y="MITO Logger",O=function(){function e(){var e=this;if(this.enabled=!1,this._console={},m.console=console||m.console,console||m.console){["log","debug","info","warn","error","assert"].forEach((function(n){n in m.console&&(e._console[n]=m.console[n])}))}}return e.prototype.disable=function(){this.enabled=!1},e.prototype.bindOptions=function(e){this.enabled=!!e},e.prototype.enable=function(){this.enabled=!0},e.prototype.getEnableStatus=function(){return this.enabled},e.prototype.log=function(){for(var e,n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];this.enabled&&(e=this._console).log.apply(e,a(["".concat(y,"[Log]:")],n,!1))},e.prototype.warn=function(){for(var e,n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];this.enabled&&(e=this._console).warn.apply(e,a(["".concat(y,"[Warn]:")],n,!1))},e.prototype.error=function(){for(var e,n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];(e=this._console).error.apply(e,a(["".concat(y,"[Error]:")],n,!1))},e}(),b=v.logger||(v.logger=new O);function x(){return d?A():g?"undefined"==typeof document||null==document.location?"":document.location.href:""}function T(e,n,t,r){if(void 0===r&&(r=!1),void 0!==e&&(n in e||r)){var o=t(e[n]);"function"==typeof o&&(e[n]=o)}}function w(){return Date.now()}function P(e,n,t){return!!function(e,n){return s.call(e)==="[object ".concat(n,"]")}(e,t)||(void 0!==e&&b.error("".concat(n,"期望传入:").concat(t,"类型,当前是:").concat(s.call(e),"类型")),!1)}function S(e){return l.isString(e)?e:l.isUndefined(e)?"undefined":JSON.stringify(e)}function k(e,n){var t=[];return Object.keys(n).forEach((function(e){t.push("".concat(e,"=").concat(n[e]))})),e=-1!==e.indexOf("?")?"".concat(e,"&").concat(t.join("&")):"".concat(e,"?").concat(t.join("&"))}function A(){if(!l.isFunction(getCurrentPages))return"";var e=getCurrentPages();if(!e.length)return"App";var n=e.pop();return k(n.route,n.options)}function I(e){return e.replace(/\b(\w)(\w*)/g,(function(e,n,t){return"".concat(n.toLowerCase()).concat(t)}))}function N(e){var n=this;e.forEach((function(e){var t=e[0],r=e[1];return P(t,r,e[2])&&(n[r]=t)}))}function E(e,n){var t={time:w(),url:x(),name:e.name,level:n,message:e.message};if(void 0===e.stack||!e.stack)return t;for(var o,i,a,c=/^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|<anonymous>|[a-z]:|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,s=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|resource|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i,u=/^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i,l=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i,p=/\((\S*)(?::(\d+))(?::(\d+))\)/,f=e.stack.split("\n"),h=[],d=0,g=f.length;d<g;++d){if(i=c.exec(f[d])){var m=i[2]&&0===i[2].indexOf("native");i[2]&&0===i[2].indexOf("eval")&&(o=p.exec(i[2]))&&(i[2]=o[1],i[3]=o[2],i[4]=o[3]),a={url:m?null:i[2],func:i[1]||"UNKNOWN_FUNCTION",args:m?[i[2]]:[],line:i[3]?+i[3]:null,column:i[4]?+i[4]:null}}else if(i=u.exec(f[d]))a={url:i[2],func:i[1]||"UNKNOWN_FUNCTION",args:[],line:+i[3],column:i[4]?+i[4]:null};else{if(!(i=s.exec(f[d])))continue;i[3]&&i[3].indexOf(" > eval")>-1&&(o=l.exec(i[3]))?(i[3]=o[1],i[4]=o[2],i[5]=null):0!==d||i[5]||void 0===e.columnNumber||(h[0].column=e.columnNumber+1),a={url:i[3],func:i[1]||"UNKNOWN_FUNCTION",args:i[2]?i[2].split(","):[],line:i[4]?+i[4]:null,column:i[5]?+i[5]:null}}!a.func&&a.line&&(a.func="UNKNOWN_FUNCTION"),h.push(a)}return h.length?r(r({},t),{stack:h}):null}var F,R=function(){function e(){this.stack=[],this.isFlushing=!1,"Promise"in m&&(this.micro=Promise.resolve())}return e.prototype.addTask=function(e){var n=this;"function"==typeof e&&("Promise"in m?(this.stack.push(e),this.isFlushing||(this.isFlushing=!0,this.micro.then((function(){return n.flushStack()})))):e())},e.prototype.clear=function(){this.stack=[]},e.prototype.getStack=function(){return this.stack},e.prototype.flushStack=function(){var e=this.stack.slice(0);this.stack.length=0,this.isFlushing=!1;for(var n=0,t=e;n<t.length;n++){(0,t[n])()}},e}();!function(e){e.Else="else",e.Error="error",e.Warning="warning",e.Info="info",e.Debug="debug",e.Low="low",e.Normal="normal",e.High="high",e.Critical="critical"}(F||(F={})),function(e){e.fromString=function(n){switch(n){case"debug":return e.Debug;case"info":case"log":case"assert":return e.Info;case"warn":case"warning":return e.Warning;case e.Low:case e.Normal:case e.High:case e.Critical:case"error":return e.Error;default:return e.Else}}}(F||(F={}));var _={};function U(e,n,t){var r;switch(e.type){case"HTTP":r=e.type+e.request.method+e.response.status+C(e.request.url)+n;break;case"JAVASCRIPT":case"VUE":case"REACT":r=e.type+e.name+e.message+n;break;case"LOG":r=e.customTag+e.type+e.name+n;break;case"PROMISE":r=function(e,n){var t=C(e.url);if("unhandledrejection"===e.name)return e.type+j(e.message)+n;return e.type+e.name+j(e.message)+t}(e,n);break;default:r=e.type+e.message+n}return r=function(e){var n=0;if(0==e.length)return n;for(var t=0;t<e.length;t++){var r=e.charCodeAt(t);n=(n<<5)-n+r,n&=n}return n}(r),_[r]>=t?null:("number"==typeof _[r]?_[r]++:_[r]=1,r)}function j(e){try{if(/\{.*\}/.test(e)){var n=JSON.parse(e);return n=function e(n){return Object.keys(n).sort().reduce((function(t,r){return l.isObject(n[r])?t[r]=e(n[r]):t[r]=n[r],t}),{})}(n),JSON.stringify(n)}return e}catch(n){return e}}function C(e){return e.replace(/[?#].*$/,"").replace(/\/(\d+)\//g,"/{param}/$1").replace(/\/\d+([/]*$)/g,"/{param}$1")}function M(e){switch(e){case"Xhr":return"http";case"Route":case"UI.Tap":case"UI.Touchmove":return"user";case"Customer":case"Console":return"debug";case"App On Launch":case"App On Show":case"App On Hide":case"Page On Load":case"Page On Show":case"Page On Ready":case"Page On Hide":case"Page On Share App Message":case"Page On Share Timeline":case"Page On Tab Item Tap":return"lifecycle";case"Unhandledrejection":case"Code Error":case"Resource":case"Vue":case"React":default:return"exception"}}function B(){return getCurrentPages().pop()}function L(){return o(this,void 0,void 0,(function(){var e,n,t,r,o;return i(this,(function(i){switch(i.label){case 0:return e=wx.getSystemInfoSync(),n=e.pixelRatio,t=e.screenHeight,r=e.screenWidth,[4,H()];case 1:return o=i.sent(),[2,{ratio:n,clientHeight:t,clientWidth:r,netType:o}]}}))}))}function H(){return o(this,void 0,void 0,(function(){return i(this,(function(e){return[2,new Promise((function(e){wx.getNetworkType({success:function(n){e(n.networkType)},fail:function(n){console.error("获取微信小程序网络类型失败:".concat(n)),e("getNetWrokType failed")}})}))]}))}))}function q(e,n,t,o){return void 0===t&&(t=F.Info),void 0===o&&(o={}),this.breadcrumb.push(r({type:n,data:e,category:M(n),level:t},o))}var W=new Map;W.set("AppOnLaunch",{transform:function(e){return this.options.appOnLaunch(e),{path:e.path,query:e.query}},consumer:function(e){q.call(this,e,"App On Launch")}}),W.set("AppOnShow",{transform:function(e){return this.options.appOnShow(e),{path:e.path,query:e.query}},consumer:function(e){return o(this,void 0,void 0,(function(){var n;return i(this,(function(t){switch(t.label){case 0:return n=v,[4,L()];case 1:return n.deviceInfo=t.sent(),q.call(this,e,"App On Show"),[2]}}))}))}}),W.set("AppOnHide",{transform:function(){this.options.appOnHide()},consumer:function(){q.call(this,null,"App On Hide")}}),W.set("AppOnError",{transform:function(e){var n={type:"JAVASCRIPT",time:w(),level:F.Normal,url:A()};if("string"==typeof e){var t=function(e){var n=e.split("\n");if(n.length<2)return null;-1!==n[0].indexOf("MiniProgramError")&&n.splice(0,1);var t=n.splice(0,1)[0],r=n.splice(0,1)[0].split(":")[0],o=[];return n.forEach((function(e){var n=/at\s+([\S]+)\s+\(/.exec(e),t=/\(([^)]+)\)/.exec(e);t||(t=/\s+at\s+(\S+)/.exec(e));var r=Array.isArray(n)&&n.length>0?n[1].trim():"",i=(Array.isArray(t)&&t.length>0?t[1]:"").split(":");o.push({args:[],func:r||"UNKNOWN_FUNCTION",column:Number(i.pop()),line:Number(i.pop()),url:i.join(":")})})),{message:t,name:r,stack:o}}(e);n=r(r({},t),n)}else p(e)?n=r(r({},E(e,F.Normal)),n):b.error("AppOnError params isn't string or error");return n},consumer:function(e){var n=q.call(this,e,"Code Error",F.Error);this.transport.send(e,n)}}),W.set("AppOnPageNotFound",{transform:function(e){return this.options.appOnPageNotFound(e),e},consumer:function(e){q.call(this,e,"Route",F.Error)}}),W.set("AppOnUnhandledRejection",{transform:function(e){var n={type:"PROMISE",message:S(e.reason),url:A(),name:"Unhandledrejection",time:w(),level:F.Low};return p(e.reason)&&(n=r(r(r({},n),E(e.reason,F.Low)),{url:A()})),n},consumer:function(e){var n=q.call(this,e,"Unhandledrejection",F.Error);this.transport.send(e,n)}});var D=App?["AppOnLaunch","AppOnShow","AppOnHide","AppOnPageNotFound","AppOnError","AppOnUnhandledRejection"].map((function(e){return{name:e,monitor:function(n){var t=App;App=function(r){return T(r,e.replace("AppOn","on"),(function(t){return function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];t&&t.apply(this,r),n.apply(null,a([e],r,!0))}}),!0),t(r)}}}})).map((function(e){return r(r({},e),W.has(e.name)?W.get(e.name):{})})):[],$={name:"console",monitor:function(e){if(console&&l.isObject(console)){["log","debug","info","warn","error","assert"].forEach((function(n){n in console&&T(console,n,(function(t){return function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];t&&(e("console",{args:r,level:n}),t.apply(console,r))}}))}))}},transform:function(e){return e},consumer:function(e){c.isLogAddBreadcrumb&&q.call(this,e,"Console",F.fromString(e.level))}};function X(e){var n=B(),t=this.options;if(n)return t[I(e)](n),{path:n.route,query:n.options};t[I(e)]()}function J(e,n){var t=B();return this.options[I(e)](n,t),{path:null==t?void 0:t.route,query:null==t?void 0:t.options,options:n}}var K=new Map;function V(e){var n=Page;Page=function(t){return e(t),n(t)}}function G(e){if(Component){var n=Component;Component=function(t){return f(t.methods)||e(t.methods),n.call(this,t)}}}K.set("PageOnLoad",{transform:function(){return X.call(this,"PageOnLoad")},consumer:function(e){q.call(this,e,"Page On Load")}}),K.set("PageOnShow",{transform:function(){return X.call(this,"PageOnShow")},consumer:function(e){q.call(this,e,"Page On Show")}}),K.set("PageOnReady",{transform:function(){return X.call(this,"PageOnReady")},consumer:function(){q.call(this,null,"Page On Ready")}}),K.set("PageOnHide",{transform:function(){return X.call(this,"PageOnHide")},consumer:function(e){q.call(this,e,"Page On Hide")}}),K.set("PageOnUnload",{transform:function(){return X.call(this,"PageOnUnload")},consumer:function(e){q.call(this,e,"Page On Unload")}}),K.set("PageOnShareTimeline",{transform:function(e){return J.call(this,"PageOnShareTimeline",e)},consumer:function(e){q.call(this,e,"Page On Share Timeline")}}),K.set("PageOnShareAppMessage",{transform:function(e){return J.call(this,"PageOnShareAppMessage",e)},consumer:function(e){q.call(this,e,"Page On Share App Message")}}),K.set("PageOnTabItemTap",{transform:function(e){return J.call(this,"PageOnTabItemTap",e)},consumer:function(e){q.call(this,e,"Page On Tab Item Tap")}});var z,Q=Page?["PageOnLoad","PageOnReady","PageOnShow","PageOnUnload","PageOnHide","PageOnShareAppMessage","PageOnShareTimeline","PageOnTabItemTap"].map((function(e){return{name:e,monitor:function(n){function t(t){T(t,e.replace("PageOn","on"),(function(t){return function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];if(n.apply(null,a([e],r,!0)),t)return t.apply(this,r)}}),!0)}V((function(e){t(e)})),G((function(e){t(e)}))}}})).map((function(e){return r(r({},e),K.has(e.name)?K.get(e.name):{})})):[],Y={name:"dom",monitor:function(e){var n=this.options;function t(t){var r,o,i,a=(r=function(n){n.mitoWorked=!0,e("dom",n)},o=n.throttleDelayTime,i=!0,function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];i&&(r.apply(this,e),i=!1,setTimeout((function(){i=!0}),o))}),c=["touchmove","tap"];t&&Object.keys(t).forEach((function(e){"function"==typeof t[e]&&T(t,e,(function(e){return function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];if(this.$vm&&!this.$vm._mito_hook_){var o=this;o._mito_hook_||(o._mito_hook_=!0,Object.keys(o).forEach((function(e){if(!~e.indexOf("$")&&"function"==typeof o[e]){var t=o[e];o[e]=function(){var e=arguments[0];return e&&e.type&&e.currentTarget&&!e.mitoWorked&&(n.triggerWxEvent(e),c.indexOf(e.type)>-1&&a(e)),t.apply(this,arguments)}}})))}var i=t[0];return i&&i.type&&i.currentTarget&&!i.mitoWorked&&(n.triggerWxEvent(i),c.indexOf(i.type)>-1&&a(i)),e.apply(this,t)}}),!0)}))}V((function(e){t(e)})),function(e){if(!Behavior)return;var n=Behavior;Behavior=function(t){return f(t.methods)||e(t.methods),n.call(this,t)}}((function(e){t(e)})),G((function(e){t(e)}))},transform:function(e){var n="UI.Touchmove";return"tap"===e.type&&(n="UI.Tap"),{data:function(e){var n,t,r=(null===(n=e.currentTarget)||void 0===n?void 0:n.id)?' id="'.concat(null===(t=e.currentTarget)||void 0===t?void 0:t.id,'"'):"",o=Object.keys(e.currentTarget.dataset).map((function(n){return"data-".concat(n,"=").concat(e.currentTarget.dataset[n])}));return"<element ".concat(r," ").concat(o.join(" "),"/>")}(e),type:n}},consumer:function(e){var n=e.data,t=e.type;q.call(this,n,t)}};!function(e){e.request="request",e.downloadFile="downloadFile",e.uploadFile="uploadFile"}(z||(z={}));var Z={name:"request",monitor:function(e){ee.call(this,e)},transform:function(e){return function(e){var n="",t=e.request,o=t.httpType,i=t.method,a=t.url,s=e.response.status,u=e.elapsedTime,l="".concat(o,"--").concat(i);n=0===s?u<=c.crossOriginThreshold?"http请求失败,失败原因:跨域限制或域名不存在":"http请求失败,失败原因:超时":function(e){if(e<400)return"ok";if(e>=400&&e<500)switch(e){case 401:return"unauthenticated";case 403:return"permission_denied";case 404:return"not_found";case 409:return"already_exists";case 413:return"failed_precondition";case 429:return"resource_exhausted";default:return"invalid_argument"}if(e>=500&&e<600)switch(e){case 501:return"unimplemented";case 503:return"unavailable";case 504:return"deadline_exceeded";default:return"internal_error"}return"unknown_error"}(s);return n="ok"===n?n:"".concat(n," ").concat(C(a)),r(r({},e),{type:"HTTP",url:A(),level:F.Low,message:n,name:l})}(e)},consumer:function(e){ne.call(this,e)}};function ee(e){var n=Object.keys(z),t=this,o=this.options;n.forEach((function(n){var i=wx[n];Object.defineProperty(wx,n,{writable:!0,enumerable:!0,configurable:!0,value:function(){for(var a=[],c=0;c<arguments.length;c++)a[c]=arguments[c];var s,u=a[0],p=u.url,f=void 0;s=u.method?u.method:n===z.downloadFile?"GET":"POST";var h=u.header;if(!h&&(h={}),"POST"===s&&t.transport.isSelfDsn(p)||o.isFilterHttpUrl(p))return i.call(this,u);switch(n){case z.request:f=u.data;break;case z.downloadFile:f={filePath:u.filePath};break;default:f={filePath:u.filePath,name:u.name}}var d={request:{httpType:"xhr",url:p,method:s,data:f},response:{},time:w()};function g(e,n){h[e]=n}o.setTraceId(p,(function(e,n){d.request.traceId=n,h[e]=n})),o.beforeAppAjaxSend&&o.beforeAppAjaxSend({method:s,url:p},{setRequestHeader:g});var m=function(n){var t=w();if(d.response.data=(l.isString(n.data)||l.isObject(n.data))&&n.data,d.elapsedTime=t-d.time,d.response.status=n.statusCode,d.errMsg=n.errMsg,e("request",d),l.isFunction(u.success))return u.success(n)},v=u.fail,y=function(n){var t=w();if(d.elapsedTime=t-d.time,d.errMsg=n.errMsg,d.response.status=0,e("request",d),l.isFunction(v))return v(n)},O=r(r({},u),{success:m,fail:y});return i.call(this,O)}})}))}function ne(e){var n=e.response.status,t=e.time,o=0===n||400===n||n>401;if(q.call(this,e,"Xhr",F.Info,{time:t}),o){var i=this.breadcrumb.push({type:"Xhr",category:"exception",data:r({},e),level:F.Error,time:t});this.transport.send(e,i)}}var te={name:"route",monitor:function(e){re.call(this,e)},transform:function(e){return{data:{type:"ROUTE",message:e.message,url:e.to,name:"MINI_ROUTE",level:F.Error},collectedData:e}},consumer:function(e){var n=e.data,t=e.collectedData;if(t.isFail){var r=q.call(this,t,"Code Error",F.Error);return this.transport.send(n,r)}q.call(this,t,"Route")}};function re(e){var n=this.options;["switchTab","reLaunch","redirectTo","navigateTo","navigateBack","navigateToMiniProgram"].forEach((function(t){var o=wx[t];Object.defineProperty(wx,t,{writable:!0,enumerable:!0,configurable:!0,value:function(i){var a;a="navigateBack"===t?function(e){if(!l.isFunction(getCurrentPages))return"";var n=getCurrentPages();if(!n.length)return"App";e=e||1;var t=n[n.length-e];return k(t.route,t.options)}(null==i?void 0:i.delta):i.url;var c={from:A(),to:a};if(e("route",c),l.isFunction(i.complete)||l.isFunction(i.success)||l.isFunction(i.fail)){var s=i.fail;i.fail=function(n){var t=r(r({},c),{isFail:!0,message:n.errMsg});if(e("route",t),l.isFunction(s))return s(n)}}return"navigateToMiniProgram"===t&&l.isFunction(n.wxNavigateToMiniProgram)&&(i=n.wxNavigateToMiniProgram(i)),o.call(this,i)}})}))}var oe=function(){function e(e){void 0===e&&(e={}),this.maxBreadcrumbs=10,this.beforePushBreadcrumb=null,this.stack=[],this.bindOptions(e)}return e.prototype.push=function(e){var n,t=this;if("function"==typeof this.beforePushBreadcrumb){var r=null,o=this.beforePushBreadcrumb;return n=function(){r=o.call(t,t,e)},c.isLogAddBreadcrumb=!1,n(),c.isLogAddBreadcrumb=!0,r?this.immediatePush(r):this.stack}return this.immediatePush(e)},e.prototype.immediatePush=function(e){return e.time||(e.time=w()),this.stack.length>=this.maxBreadcrumbs&&this.shift(),this.stack.push(e),this.stack.sort((function(e,n){return e.time-n.time})),b.log(this.stack),this.stack},e.prototype.shift=function(){return void 0!==this.stack.shift()},e.prototype.clear=function(){this.stack=[]},e.prototype.getStack=function(){return this.stack},e.prototype.bindOptions=function(e){void 0===e&&(e={});var n=e.maxBreadcrumbs,t=e.beforePushBreadcrumb;P(n,"maxBreadcrumbs","Number")&&(this.maxBreadcrumbs=n),P(t,"beforePushBreadcrumb","Function")&&(this.beforePushBreadcrumb=t)},e}(),ie=function(){function e(){this.dep=new Map}return e.prototype.watch=function(e,n){var t=this.dep.get(e);t?this.dep.set(e,t.concat(n)):this.dep.set(e,[n])},e.prototype.notify=function(e,n){var t=this.dep.get(e);e&&t&&t.forEach((function(t){!function(e,n){try{e()}catch(e){console.error("err",e),n&&n(e)}}((function(){t(n)}),(function(n){b.error("Subscribe.notify:监听事件的回调函数发生错误\neventName:".concat(e,"\nName: ").concat(function(e){return e&&"function"==typeof e&&e.name||"<anonymous>"}(t),"\nError: ").concat(n))}))}))},e}(),ae=function(){function e(e){this.SDK_VERSION="3.0.1",this.options=e,b.bindOptions(e.debug)}return e.prototype.use=function(e){var n=this;if(!this.options.disabled){var t=new ie;e.forEach((function(e){if(n.isPluginEnable(e.name)){e.monitor.call(n,t.notify.bind(t));t.watch(e.name,(function(){for(var t,r,o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];var a=null===(t=e.transform)||void 0===t?void 0:t.apply(n,o);null===(r=e.consumer)||void 0===r||r.call(n,a)}))}}))}},e.prototype.getOptions=function(){return this.options},e}(),ce=function(){function e(){this.enableTraceId=!1,this.includeHttpUrlTraceIdRegExp=/.*/,this.traceIdFieldName="Trace-Id",this.throttleDelayTime=0,this.beforeAppAjaxSend=null,this.vue=null}return e.prototype.bindOptions=function(e){var n=e.enableTraceId,t=e.vue,r=e.filterXhrUrlRegExp,o=[[n,"enableTraceId","Boolean"],[e.traceIdFieldName,"traceIdFieldName","String"],[e.throttleDelayTime,"throttleDelayTime","Number"],[r,"filterXhrUrlRegExp","RegExp"],[e.includeHttpUrlTraceIdRegExp,"includeHttpUrlTraceIdRegExp","RegExp"],[e.beforeAppAjaxSend,"beforeAppAjaxSend","Function"]];N.call(this,o),this.vue=t},e.prototype.isFilterHttpUrl=function(e){return this.filterXhrUrlRegExp&&this.filterXhrUrlRegExp.test(e)},e.prototype.setTraceId=function(e,n){var t,r=this.includeHttpUrlTraceIdRegExp;if(this.enableTraceId&&r&&r.test(e)){var o=(t=(new Date).getTime(),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var n=(t+16*Math.random())%16|0;return t=Math.floor(t/16),("x"==e?n:3&n|8).toString(16)})));n(this.traceIdFieldName,o)}},e}(),se=function(){function e(){this.apikey="",this.dsn="",this.beforeDataReport=null,this.backTrackerId=null,this.configReportUrl=null,this.maxDuplicateCount=3,this.queue=new R}return e.prototype.getAuthInfo=function(){var e=this.getTrackerId();return{trackerId:String(e),sdkVersion:"3.0.1",sdkName:"mitojs",apikey:this.apikey}},e.prototype.getTrackerId=function(){if("function"==typeof this.backTrackerId){var e=this.backTrackerId();if("string"==typeof e||"number"==typeof e)return e;b.error("trackerId:".concat(e," 期望 string 或 number 类型,但是传入 ").concat(typeof e))}return""},e.prototype.isSelfDsn=function(e){return this.dsn&&(n=e,t=this.dsn,!!~n.indexOf(t));var n,t},e.prototype.bindOptions=function(e){void 0===e&&(e={});var n=e.dsn,t=e.beforeDataReport,r=[[e.apikey,"apikey","String"],[n,"dsn","String"],[e.maxDuplicateCount,"maxDuplicateCount","Number"],[t,"beforeDataReport","Function"],[e.backTrackerId,"backTrackerId","Function"],[e.configReportUrl,"configReportUrl","Function"]];N.call(this,r)},e.prototype.send=function(e,n){return void 0===n&&(n=[]),o(this,void 0,void 0,(function(){var t,o,a;return i(this,(function(i){switch(i.label){case 0:if(!e.isTrack){if(!(t=U(e,this.apikey,this.maxDuplicateCount)))return[2];e.errorId=t}return o=r(r({},this.getTransportData(e)),{breadcrumb:n}),"function"!=typeof this.beforeDataReport?[3,2]:[4,this.beforeDataReport(o)];case 1:if(!(o=i.sent()))return[2];i.label=2;case 2:return a=this.dsn,c=a,l.isString(c)&&""===c.trim()||null==c?(b.error("dsn is empty,pass in when initializing please"),[2]):"function"!=typeof this.configReportUrl||(a=this.configReportUrl(o,a))?[2,this.sendToServer(o,a)]:[2]}var c}))}))},e}(),ue=function(e){function n(n){var t=e.call(this)||this;return t.appOnLaunch=function(){},t.appOnShow=function(){},t.appOnHide=function(){},t.pageOnLoad=function(){},t.pageOnShow=function(){},t.pageOnReady=function(){},t.pageOnHide=function(){},t.pageOnUnload=function(){},t.appOnPageNotFound=function(){},t.pageOnShareAppMessage=function(){},t.pageOnShareTimeline=function(){},t.pageOnTabItemTap=function(){},t.triggerWxEvent=function(){},e.prototype.bindOptions.call(t,n),t.bindOptions(n),t}return t(n,e),n.prototype.bindOptions=function(e){var n=e.beforeAppAjaxSend,t=e.appOnLaunch,r=e.appOnShow,o=e.appOnHide,i=e.appOnPageNotFound,a=e.pageOnLoad,c=e.pageOnReady,s=e.pageOnShow,u=e.pageOnUnload,l=e.pageOnHide,p=e.pageOnShareAppMessage,f=e.pageOnShareTimeline,h=e.pageOnTabItemTap,d=e.wxNavigateToMiniProgram,g=e.triggerWxEvent,m=[[e.silentRequest,"silentRequest","Boolean"],[e.silentConsole,"silentConsole","Boolean"],[e.silentDom,"silentDom","Boolean"],[e.silentRoute,"silentRoute","Boolean"],[e.silentAppOnError,"silentAppOnError","Boolean"],[e.silentAppOnUnhandledRejection,"silentAppOnUnhandledRejection","Boolean"],[e.silentAppOnPageNotFound,"silentAppOnPageNotFound","Boolean"],[e.silentPageOnShareAppMessage,"silentPageOnShareAppMessage","Boolean"],[e.silentPageOnShareTimeline,"silentPageOnShareTimeline","Boolean"],[n,"beforeAppAjaxSend","Function"],[t,"appOnLaunch","Function"],[r,"appOnShow","Function"],[o,"appOnHide","Function"],[i,"appOnPageNotFound","Function"],[a,"pageOnLoad","Function"],[c,"pageOnReady","Function"],[s,"pageOnShow","Function"],[u,"pageOnUnload","Function"],[l,"pageOnHide","Function"],[p,"pageOnShareAppMessage","Function"],[f,"pageOnShareTimeline","Function"],[h,"pageOnTabItemTap","Function"],[d,"wxNavigateToMiniProgram","Function"],[g,"triggerWxEvent","Function"]];N.call(this,m)},n}(ce),le=function(e){function n(n){void 0===n&&(n={});var t=e.call(this)||this;return t.useImgUpload=!1,e.prototype.bindOptions.call(t,n),t.bindOptions(n),t}return t(n,e),n.prototype.post=function(e,n){var t=this;this.queue.addTask((function(){var o={method:"POST"};if("function"==typeof t.configReportWxRequest){var i=t.configReportWxRequest(e);o=r(r({},o),i)}o=r(r({},o),{data:JSON.stringify(e),url:n}),wx.request(o)}))},n.prototype.sendToServer=function(e,n){return this.post(e,n)},n.prototype.getTransportData=function(e){return{authInfo:this.getAuthInfo(),data:e,deviceInfo:v.deviceInfo}},n.prototype.bindOptions=function(e){void 0===e&&(e={});var n=e.configReportWxRequest;P(n,"configReportWxRequest","Function")&&(this.configReportWxRequest=n)},n}(se),pe=function(e){function n(n){void 0===n&&(n={});var t=e.call(this,n)||this;return t.options=new ue(n),t.transport=new le(n),t.breadcrumb=new oe(n),t}return t(n,e),n.prototype.isPluginEnable=function(e){var n="".concat("silent").concat(e.replace(/\b(\w)(\w*)/g,(function(e,n,t){return"".concat(n.toUpperCase()).concat(t)})));return!this.options[n]},n.prototype.log=function(e){var n=e.message,t=void 0===n?"empty.msg":n,o=e.tag,i=void 0===o?"empty.tag":o,a=e.level,c=void 0===a?F.Critical:a,s=e.ex,u=void 0===s?"":s,l={};p(u)&&(l=E(u,c));var f=r({type:"LOG",level:c,message:S(t),name:"Mito.log",customTag:S(i),time:w(),url:A()},l),h=q.call(this,t,"Customer",F.fromString(c.toString()));this.transport.send(f,h)},n.prototype.trackSend=function(e){this.transport.send(r({isTrack:!0},e),this.breadcrumb.getStack())},n}(ae);var fe=function(e,n){void 0===n&&(n=[]);var t=new pe(e),r=a(a(a([Z,te,$,Y],D,!0),Q,!0),n,!0);return t.use(r),t};return e.WxClient=pe,e.init=fe,Object.defineProperty(e,"__esModule",{value:!0}),e}({});