123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230 |
- /* eslint-disable */
- Date.now = Date.now || function () {
- return new Date().getTime();
- };
- let SEQUENCE = Date.now();
- const noop = function () {};
- const getCwarn = function () {
- const t = typeof console === 'object' ? console.warn : noop;
- try {
- const e = {
- warn: t
- };
- e.warn.call(e);
- } catch (n) {
- return noop;
- }
- return t;
- };
- var util = {
- noop,
- warn: getCwarn(),
- createObject(t) {
- if (Object.create) {
- return Object.create(t);
- }
- const e = function () {};
- return e.prototype = t, new e();
- },
- each(t, e) {
- let n = 0;
- const r = t.length;
- if (this.T(t, 'Array')) {
- for (; n < r && !1 !== e.call(t[n], t[n], n); n++) {}
- } else {
- for (n in t) {
- if (!1 === e.call(t[n], t[n], n)) {
- break;
- }
- }
- }
- return t;
- },
- safetyCall(t, e, n) {
- if (typeof t !== 'function') {
- return n;
- }
- try {
- return t.apply(this, e);
- } catch (r) {
- return n;
- }
- },
- ignoreByRule(t, e) {
- if (!t || !e) return !1;
- if ((this.isString(e) || e.source || this.T(e) === 'Function') && (e = [e]), !this.isArray(e)) {
- return util.warn('[cloudMonitor] invalid rules of ignore config, (list of) String/RegExp/Funcitons are available'), !1;
- }
- for (var n, r = [], o = 0, i = e.length; o < i; o++) if (n = e[o], this.isString(n)) r.push(n.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1'));else if (n && n.source) r.push(n.source);else if (n && this.T(n) === 'Function' && !0 === this.safetyCall(n, [t], !1)) return !0;
- const a = new RegExp(r.join('|'), 'i');
- return !!(r.length && a.test && a.test(t));
- },
- T(t, e) {
- const n = Object.prototype.toString.call(t).substring(8).replace(']', '');
- return e ? n === e : n;
- },
- J(t) {
- if (!t || typeof t !== 'string') {
- return t;
- }
- let e = null;
- try {
- e = JSON.parse(t);
- } catch (n) {}
- return e;
- },
- pick(t) {
- return t === 1 || Math.ceil(Math.random() * t) === 1;
- },
- verifyConfig(t) {
- if ('sample' in t) {
- const e = t.sample;
- let n = e;
- e && /^\d+(\.\d+)?%$/.test(e) && (n = parseInt(100 / parseFloat(e))), n > 0 && n < 1 && (n = parseInt(1 / n)), n >= 1 && n <= 100 ? t.sample = n : delete t.sample;
- }
- return t;
- },
- delay(t, e) {
- return e === -1 ? (t(), null) : setTimeout(t, e || 0);
- },
- ext(t) {
- for (let e = 1, n = arguments.length; e < n; e++) {
- const r = arguments[e];
- for (const o in r) {
- Object.prototype.hasOwnProperty.call(r, o) && (t[o] = r[o]);
- }
- }
- return t;
- },
- sub(t, e) {
- const n = {};
- return this.each(t, (t, r) => {
- e.indexOf(r) !== -1 && (n[r] = t);
- }), n;
- },
- uu() {
- for (var t, e, n = 20, r = new Array(n), o = Date.now().toString(36).split(''); n-- > 0;) {
- e = (t = 36 * Math.random() | 0).toString(36), r[n] = t % 3 ? e : e.toUpperCase();
- }
- for (let i = 0; i < 8; i++) {
- r.splice(3 * i + 2, 0, o[i]);
- }
- return r.join('');
- },
- seq() {
- return (SEQUENCE++).toString(36);
- },
- decode(t) {
- try {
- t = decodeURIComponent(t);
- } catch (e) {}
- return t;
- },
- encode(t, e) {
- try {
- t = e ? encodeURIComponent(t).replace(/\(/g, '%28').replace(/\)/g, '%29') : encodeURIComponent(t);
- } catch (n) {}
- return t;
- },
- serialize(t) {
- t = t || {};
- const e = [];
- for (const n in t) {
- Object.prototype.hasOwnProperty.call(t, n) && t[n] !== undefined && e.push(`${n}=${this.encode(t[n], n === 'msg')}`);
- }
- return e.join('&');
- },
- checkAPI(t, e) {
- if (!t || typeof t !== 'string') {
- return !1;
- }
- let n = /openmonitor(\.(dev|sit|test))?\.alipay[\w-]*/.test(t);
- return !n && e && (n = /(\.png)|(\.gif)|(alicdn\.com)/.test(t)), !n;
- },
- checkAutoError(t) {
- return !(!t || !t.message) && !/failed[\w\s]+fetch/i.test(t.message);
- },
- cutUrlSearch(t) {
- return t && typeof t === 'string' ? t.replace(/^(.*?https?:)?\/\//, '').replace(/\?.*$/, '').replace(/&.*$/, '').replace(/\/\d{1,}$/, '/*').replace(/\/\d{1,}\//, '/*/') : '';
- },
- patchPath(t) {
- if (!t || typeof t !== 'string') return '';
- t = t.replace(/^\//, '');
- return t.includes('pages/') ? t.replace(/\.\.\//g, '') : t.replace(/^\.\./, 'pages');
- },
- getRandIP() {
- for (var t = [], e = 0; e < 4; e++) {
- const n = Math.floor(256 * Math.random());
- t[e] = (n > 15 ? '' : '0') + n.toString(16);
- }
- return t.join('');
- },
- getSortNum(t) {
- return t ? (t += 1) >= 1000 && t <= 9999 ? t : t < 1000 ? t + 1000 : t % 10000 + 1000 : 1000;
- },
- getRandNum(t) {
- return t && typeof t === 'string' ? t.length < 5 ? this.getNum(5) : t.substring(t.length - 5) : this.getNum(5);
- },
- getNum(t) {
- for (var e = [], n = 0; n < t; n++) {
- const r = Math.floor(16 * Math.random());
- e[n] = r.toString(16);
- }
- return e.join('');
- },
- isFunction(t) {
- return typeof t === 'function';
- },
- isPlainObject(t) {
- return Object.prototype.toString.call(t) === '[object Object]';
- },
- isString(t) {
- return Object.prototype.toString.call(t) === '[object String]';
- },
- isArray(t) {
- return Object.prototype.toString.call(t) === '[object Array]';
- },
- joinRegExp(t) {
- for (var e, n = [], r = 0, o = t.length; r < o; r++) {
- e = t[r], this.isString(e) ? n.push(e.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1')) : e && e.source && n.push(e.source);
- }
- return new RegExp(n.join('|'), 'i');
- },
- getPropertyValue(j, arr) {
- if (!arr) return '';
- for (const k in j) {
- if (arr.indexOf(k) > -1 && typeof j[k] !== 'object') {
- return `${j[k]}`;
- }
- }
- return '';
- },
- hashCode(s) {
- let hash = 0;
- let i;
- let chr;
- for (i = 0; i < s.length; i++) {
- chr = s.charCodeAt(i);
- hash = (hash << 5) - hash + chr;
- hash |= 0; // Convert to 32bit integer
- }
- return hash;
- },
- toHex(s) {
- return !s ? null : `000${this.hashCode(s).toString(16)}`.slice(-4);
- },
- replaceAll(str, find, replace) {
- return str.replace(new RegExp(find, 'g'), replace);
- }
- };
- const util_1 = util;
- const pushToQueue = function (e, t) {
- let i;
- {
- if (t.t !== 'error' || !(i = e.requestQueue[0]) || i.t !== 'error' || t.msg !== i.msg) {
- if (t.t === 'behavior') {
- const n = e.requestQueue && e.requestQueue.length;
- if (n > 0 && e.requestQueue[n - 1].t === 'behavior') {
- const r = t.behavior || [];
- e.requestQueue[n - 1].behavior.concat(r);
- } else e.requestQueue.push(t);
- } else e.requestQueue.unshift(t);
- return e.onReady(() => {
- e.requestTimmer = util.delay(() => {
- e.clear();
- }, e.requestQueue[0] && e.requestQueue[0].t === 'error' ? 3e3 : -1);
- }), !0;
- }
- i.times++;
- }
- };
- var Base = function (t) {
- return this.ver = '1.0.9', this.syn = 0, this.err = 0, this._conf = util.ext({}, Base.dftCon), this.sampleCache = {}, this.requestQueue = [], this.hash = util.seq(), this.resetSession(), this.setConfig(t), this.rip = util.getRandIP(), this._common = {}, this;
- };
- Base.dftCon = {
- sample: 1,
- tag: '',
- imgUrls: ['https://openmonitor.alipay-eco.com/cloudmonitor/put.htm?'],
- release: undefined,
- environment: 'production',
- charset: 'utf-8'
- }, Base.prototype = {
- constructor: Base,
- getPage() {
- const e = this._conf.page;
- return util.safetyCall(e, [], `${e}`);
- },
- setPage() {},
- setConfig(e) {
- e && typeof e === 'object' && (util.verifyConfig(e), e = this.setImgUrl(e), this._conf = util.ext({}, this._conf, e));
- },
- setImgUrl(e) {
- return e.imgUrl && (this._conf.imgUrls = [e.imgUrl]), e;
- },
- sendRequest() {},
- postData() {},
- commonInfo() {
- return {};
- },
- setCommonInfo(e) {
- e && typeof e === 'object' && (this._common = util.ext({}, this._common, e));
- },
- resetSession() {
- this.session = util.uu(), this.sBegin = Date.now();
- },
- getConfig(e) {
- return e ? this._conf[e] : util.ext({}, this._conf);
- },
- sampling(e) {
- return e === 1 || (typeof this.sampleCache[e] === 'boolean' ? this.sampleCache[e] : (this.sampleCache[e] = util.pick(e), this.sampleCache[e]));
- },
- clear() {
- let e;
- const t = this;
- if (t.syn > 2) {
- return clearTimeout(t.requestTimmer), t.requestTimmer = setTimeout(() => {
- t.clear();
- }, 50), t;
- }
- for (clearTimeout(t.requestTimmer), t.requestTimmer = null; t.syn < 2 && (e = t.requestQueue.pop()); t.syn++) {
- e.t === 'res' ? t.postData(e, 'res') : e.t === 'error' ? t.postData(e, 'err') : e.t === 'behavior' ? t.postData(e, 'behavior') : t.sendRequest(e);
- }
- !!t.requestQueue.length && (t.requestTimmer = setTimeout(() => {
- t.clear();
- }, 50));
- return this;
- },
- getToken(e) {
- const t = this._conf.token;
- return !t ? '-' : t[e] || '-';
- },
- _lg(e, t, i) {
- const n = this._conf;
- const r = t.page || util.patchPath(this.getPage());
- const s = n.ignore || {};
- const o = s.ignoreErrors;
- const u = s.ignoreUrls;
- const a = s.ignoreApis;
- return util.ignoreByRule(r, u) || util.ignoreByRule(util.decode(r), u) ? this : e === 'error' && (util.ignoreByRule(t.msg, o) || util.ignoreByRule(util.decode(t.msg), o)) ? this : e === 'api' && (util.ignoreByRule(t.api, a) || util.ignoreByRule(util.decode(t.api), a)) ? this : t && !n.disabled && (n.pid || n.token) ? i && !this.sampling(i) ? this : (t = util.ext({
- t: e,
- page: r,
- environment: n.environment,
- _input_charset: n.charset,
- timestamp: Date.now()
- }, t, this.commonInfo(), this._common, {
- token: this.getToken(e),
- pid: n.pid || '-',
- _v: this.ver,
- sampling: i || 1
- }), pushToQueue(this, t)) : this;
- },
- custom(e, t) {
- if (!e || typeof e !== 'object') {
- return this;
- }
- let i = !1;
- const r = {
- timestamp: Date.now()
- };
- return util.each(e, (e, t) => !(i = t && t.length <= 20) && util.warn(`[CloudMonitor] invalid key: ${t}`), r[`x-${t}`] = e, i), i ? this._lg('custom', r, t || 1) : this;
- },
- logInfo() {
- if (arguments.length === 0) return;
- let msg = '';
- for (let e = 0, n = arguments.length; e < n; e++) {
- msg += ` ${JSON.stringify(arguments[e])}`;
- }
- const r = {
- timestamp: Date.now(),
- level: 'info',
- msg: msg.substring(1)
- };
- return this._lg('log', r, 1), this;
- },
- report(k, e) {
- if (!k || !e || typeof e !== 'object') {
- return this;
- }
- let i = !1;
- const r = {
- timestamp: Date.now()
- };
- return util.each(e, (e, t) => !(i = t && t.length <= 20) && util.warn(`[CloudMonitor] invalid key: ${t}`), r[`x-${t}`] = e, i), i ? this._lg(k, r, 1) : this;
- }
- };
- const base = Base;
- const validApiKeys = ['api', 'success', 'time', 'code', 'msg', 'begin', 'response', 'c1', 'c2', 'c3'];
- const parseStatData = function (t, e) {
- const r = t.split('::');
- return r.length > 1 ? util_1.ext({
- group: r[0],
- key: r[1]
- }, e) : util_1.ext({
- group: 'default_group',
- key: r[0]
- }, e);
- };
- const Reporter = function (t) {
- base.call(this, t);
- let e;
- try {
- e = typeof performance === 'object' ? performance.timing.fetchStart : Date.now();
- } catch (r) {
- e = Date.now();
- }
- return this._startTime = e, this;
- };
- Reporter.prototype = util_1.createObject(base.prototype), util_1.ext(base.dftCon, {
- startTime: null
- }), util_1.ext(Reporter.prototype, {
- constructor: Reporter,
- _super: base,
- sum(t, e, r) {
- try {
- return this._lg('sum', parseStatData(t, {
- val: e || 1,
- begin: Date.now()
- }), r);
- } catch (n) {
- util_1.warn(`[retcode] can not get parseStatData: ${n}`);
- }
- },
- avg(t, e, r) {
- try {
- return this._lg('avg', parseStatData(t, {
- val: e || 0,
- begin: Date.now()
- }), r);
- } catch (n) {
- util_1.warn(`[retcode] can not get parseStatData: ${n}`);
- }
- },
- percent(t, e, r, n) {
- try {
- return this._lg('percent', parseStatData(t, {
- subkey: e,
- val: r || 0,
- begin: Date.now()
- }), n);
- } catch (i) {
- util_1.warn(`[retcode] can not get parseStatData: ${i}`);
- }
- },
- msg(t, e) {
- if (t && !(t.length > 180)) {
- return this.custom({
- msg: t
- }, e);
- }
- },
- error(t, e) {
- if (!t) {
- return util_1.warn(`[cloudMonitor] invalid param e: ${t}`), this;
- }
- arguments.length === 1 ? (typeof t === 'string' && (t = {
- message: t
- }, e = {}), typeof t === 'object' && (e = t = t.error || t)) : (typeof t === 'string' && (t = {
- message: t
- }), typeof e !== 'object' && (e = {}));
- const r = t.name || 'CustomError';
- var n = util_1.encode(t.message);
- const i = util_1.encode(util_1.replaceAll(t.stack || '', 'http.*\\d*:\\d*', 'unknow'));
- e = e || {};
- const s = {
- begin: Date.now(),
- cate: r,
- msg: n.substring(0, 256),
- stack: i && i.substring(0, 256),
- file: e.filename || '',
- line: e.lineno || '',
- col: e.colno || '',
- err: {
- msg_raw: n,
- stack_raw: i
- }
- };
- var n = (this.getConfig('ignore') || {}).ignoreErrors;
- return util.ignoreByRule(s.msg, n) || util.ignoreByRule(util.decode(s.msg), n) ? this : this.beforeSend && this.beforeSend('error', s), this._lg('error', s, 1);
- },
- behavior(t) {
- if (t) {
- const e = typeof t === 'object' && t.behavior ? t : {
- behavior: t
- };
- return this.beforeSend && this.beforeSend('behavior', t), this._lg('behavior', e, 1);
- }
- },
- api(e, t, r, i, a, s) {
- if (!e) {
- return util.warn('[cloudMonitor] api is null'), this;
- }
- e = typeof e === 'string' ? {
- api: e,
- success: t,
- time: r,
- code: i,
- msg: a,
- begin: s
- } : util.sub(e, validApiKeys);
- if (e.code = e.code || '', e.msg = e.msg || '', e.success = e.success ? 1 : 0, e.time = +e.time, e.begin = e.begin || '', !e.api || isNaN(e.time)) {
- return util.warn('[cloudMonitor] invalid time or api'), this;
- }
- const c = (this.getConfig('ignore') || {}).ignoreApis;
- if (util.ignoreByRule(e.api, c) || util.ignoreByRule(util.decode(e.api), c)) return this;
- this.beforeSend && this.beforeSend('api', e);
- return this._lg('api', e, e.success && !e.response && this.getConfig('sample'));
- },
- resource(t, e) {
- if (!t || !util_1.isPlainObject(t)) {
- return util_1.warn(`[cloudMonitor] invalid param data: ${t}`), this;
- }
- const r = Object.keys(t);
- const n = ['begin', 'dom', 'load', 'res', 'dl'];
- let i = !1;
- for (const o in n) {
- if (r.indexOf(n[o]) < 0) {
- i = !0;
- break;
- }
- }
- if (i) {
- return util_1.warn(`[cloudMonitor] lack param data: ${t}`), this;
- }
- const a = {
- begin: t.begin || Date.now(),
- dom: t.dom || '',
- load: t.load || '',
- res: util_1.isArray(t.res) ? JSON.stringify(t.res) : JSON.stringify([]),
- dl: t.dl || ''
- };
- return this._lg('res', a, e);
- }
- }), Reporter._super = base, Reporter._root = base, base.Reporter = Reporter;
- const reporter = Reporter;
- const MiniProgramLogger = function (t) {
- const o = this;
- return Reporter.call(o, t), o._health = {
- errcount: 0,
- apisucc: 0,
- apifail: 0
- }, o.DEFAUT_PAGE_PATH = '[app]', o.isSendPerf = !1, o.beforeSend = function (e, t) {
- e === 'error' ? o._health.errcount++ : e === 'api' && o._health[t.success ? 'apisucc' : 'apifail']++;
- }, typeof o.autoSetCommonInfo === 'function' && o.autoSetCommonInfo(), this;
- };
- MiniProgramLogger.prototype = util.createObject(Reporter.prototype), util.ext(Reporter._root.dftCon, {
- sendRequest() {},
- getCurrentPage() {},
- getPrePage() {}
- }), util.ext(MiniProgramLogger.prototype, {
- constructor: MiniProgramLogger,
- _super: Reporter,
- onReady(e) {
- const t = this;
- t._common.uid ? e() : setTimeout(() => {
- t.onReady(e);
- }, 100);
- },
- sendRequest(e, o) {
- const a = this;
- if (a.getConfig('debug') || a.err > 0) {
- typeof console !== 'undefined' && console && typeof console.log === 'function' && console.log('[cloudMonitor] [DEBUG MODE] log data', e);
- } else {
- const r = a._conf.sendRequest;
- util.each(a.getConfig('imgUrls'), (t, i) => {
- typeof e === 'object' && (e = util.serialize(e));
- let n = t + e;
- o && (n += '&post_res=');
- if (typeof r === 'function') {
- try {
- !i ? r(n, o, a) : r(n, o);
- } catch (i) {
- util.warn('[cloudMonitor] error in sendRequest', i);
- }
- }
- });
- }
- },
- postData(e, o) {
- const t = {};
- t[o] = e[o], delete e[o], this.sendRequest(e, t);
- },
- getPage(delta) {
- const e = this._conf.getCurrentPage;
- if (typeof e === 'function') {
- try {
- const o = e();
- if (o && typeof o === 'string') {
- return o;
- }
- } catch (t) {
- util.warn('[cloudMonitor] error in getPage', t);
- }
- }
- return typeof e === 'string' && e ? e : this.DEFAUT_PAGE_PATH;
- },
- addHook() {
- return this;
- },
- removeHook() {
- return this;
- },
- hookApp(e) {
- const o = this;
- const t = {
- onError(t) {
- const n = arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments);
- const r = e.onError;
- try {
- o.error(t);
- } catch (t) {
- util.warn('[cloudMonitor] error in hookApp:onError', t);
- }
- if (typeof r === 'function') {
- return r.apply(this, n);
- }
- }
- };
- return util.ext({}, e, t);
- },
- autoSetCommonInfo() {
- this.setCommonInfo({
- app: 'mini_common',
- uid: this._conf.uid
- });
- },
- _lgPV(t) {
- if (!t) return;
- if (typeof t === 'string') {
- t = {
- page: t
- };
- }
- t.page = util.cutUrlSearch(t.page);
- t.url && (t.url = util.cutUrlSearch(t.url));
- !t.spmPre && (t.spmPre = util.toHex(this.getPage()) || ''), !t.spmId && (t.spmId = util.toHex(t.page) || ''), !t.scene && (t.scene = ''), this._lg('pv', t);
- },
- sendHealthOnPageShowOrHide() {
- try {
- this.sessionPage = this.getPage(), this.sendHealth(), this.speedCache && (this._lg('speed', this.speedCache), this.speedCache = null, clearTimeout(this.speedTimmer)), this.clear();
- } catch (o) {
- util.warn('[cloudMonitor] error in sendHealthOnPageShowOrHide', o);
- }
- },
- sendHealth() {
- if (this.sessionPage) {
- const e = util.ext({}, this._health);
- e.healthy = e.errcount > 0 ? 0 : 1, e.begin = Date.now();
- const o = e.begin - this.sBegin;
- e.page = this.sessionPage, e.stay = o, this._lg('health', e, 1), this._health = {
- errcount: 0,
- apisucc: 0,
- apifail: 0
- }, this.sessionPage = null;
- }
- },
- parseResponse(e) {
- if (!e || typeof e !== 'object') return {};
- const r = '';
- let c = util.getPropertyValue(e, this._conf.code) || e.stat || e.status || e.code || e.success;
- let u = util.getPropertyValue(e, this._conf.msg) || e.msg || e.message || e.subMsg || e.errorMsg || e.ret || e.errorResponse || '';
- typeof u === 'object' && (c = c || u.code, u = u.msg || u.message || u.info || u.ret || JSON.stringify(u));
- return {
- code: c,
- msg: u,
- response: util.pick(10000) ? JSON.stringify(e).substr(0, 256) : ''
- };
- }
- });
- MiniProgramLogger._super = reporter, MiniProgramLogger._root = reporter._root, reporter.MiniProgramLogger = MiniProgramLogger;
- const miniProgramLogger = MiniProgramLogger;
- const STORAGE_MINIPROGRAM_ALIPAY_UID_KEY = 'STORAGE_MINIPROGRAM_ALIPAY_UID';
- const AlipayLogger = function (t) {
- return MiniProgramLogger.call(this, t), this;
- };
- AlipayLogger.prototype = util.createObject(MiniProgramLogger.prototype), util.ext(MiniProgramLogger._root.dftCon, {
- sendRequest(t, e, a) {
- if (typeof my !== 'undefined' && my && typeof my.request === 'function') {
- try {
- let o;
- let r = 'GET';
- e && (r = 'POST', o = JSON.stringify(e)), my.request({
- url: t,
- method: r,
- data: o,
- dataType: 'json',
- fail(t) {
- util.warn('[cloudMonitor] sendRequest fail', t);
- a && a.err++;
- },
- complete(_t) {
- a && a.syn--;
- }
- });
- } catch (n) {
- util.warn('[cloudMonitor] error in conf sendRequest', n);
- }
- }
- },
- getCurrentPage() {
- if (typeof getCurrentPages === 'function') {
- try {
- const t = getCurrentPages() || [];
- const e = t[t.length - 1];
- return e && e.route || null;
- } catch (o) {
- util.warn('[cloudMonitor] error in conf getCurrentPage', o);
- }
- }
- },
- getPrePage(delta) {
- if (typeof getCurrentPages === 'function') {
- try {
- const t = getCurrentPages() || [];
- const e = delta === undefined ? t[t.length - 2] : delta >= t.length ? t[0] : t[t.length - 1 - delta];
- return e && e.route || null;
- } catch (o) {
- util.warn('[cloudMonitor] error in conf getCurrentPage', o);
- }
- }
- }
- }), util.ext(AlipayLogger.prototype, {
- constructor: AlipayLogger,
- _super: MiniProgramLogger,
- autoSetCommonInfo() {
- this.setCommonInfo({
- app: 'mini_alipay'
- }), this.autoSetNetworkType(), this.autoSetUid(), this.autoSystemInfo(), this.autoSetAppId(), this.autoSetSDKVersion(), this.autoSetRunScene();
- },
- autoSetUid() {
- const t = this;
- if (t._conf && t._conf.uid) {
- t.setCommonInfo({
- uid: t._conf.uid
- });
- } else if (typeof my !== 'undefined' && my && typeof my.getStorage === 'function') {
- try {
- my.getStorage({
- key: STORAGE_MINIPROGRAM_ALIPAY_UID_KEY,
- success(e) {
- if (e && e.data && typeof e.data === 'string') {
- t.setCommonInfo({
- uid: e.data
- });
- } else if (typeof my.setStorage === 'function') {
- const o = util.uu();
- my.setStorage({
- key: STORAGE_MINIPROGRAM_ALIPAY_UID_KEY,
- data: o,
- success() {
- t.setCommonInfo({
- uid: o
- });
- },
- fail(t) {
- util.warn('[cloudMonitor] error in setStorage', t);
- }
- });
- }
- },
- fail(t) {
- util.warn('[cloudMonitor] error in getStorage', t);
- }
- });
- } catch (e) {
- util.warn('[cloudMonitor] error in autoSetUid', e);
- }
- }
- },
- autoSystemInfo() {
- const t = this;
- if (typeof my !== 'undefined' && my && typeof my.getSystemInfo === 'function') {
- try {
- my.getSystemInfo({
- success(e) {
- e && typeof e.model === 'string' && typeof e.version === 'string' && typeof e.platform === 'string' && typeof e.language === 'string' && t.setCommonInfo({
- mobile: e.model,
- version: e.version,
- platform: e.platform,
- system: e.system,
- resolution: `${e.windowWidth}*${e.windowHeight}`,
- language: e.language
- });
- },
- fail(t) {
- util.warn('[cloudMonitor] autoSystemInfo getSystemInfo fail', t);
- }
- });
- } catch (e) {
- util.warn('[cloudMonitor] error in getSystemInfo', e);
- }
- }
- },
- autoSetNetworkType() {
- const t = this;
- if (typeof my !== 'undefined' && my && typeof my.getNetworkType === 'function') {
- try {
- my.getNetworkType({
- success(e) {
- e && typeof e.networkType === 'string' && t.setCommonInfo({
- net: e.networkType
- });
- },
- fail(t) {
- util.warn('[cloudMonitor] autoSetNetworkType getNetworkType fail', t);
- }
- });
- } catch (e) {
- util.warn('[cloudMonitor] error in autoSetNetworkType', e);
- }
- }
- },
- autoSetAppId() {
- const t = this;
- if (typeof my !== 'undefined' && my && typeof my.getAppIdSync === 'function') {
- try {
- const appIdRes = my.getAppIdSync();
- t.setCommonInfo({
- appId: appIdRes.appId
- });
- } catch (e) {
- util.warn('[cloudMonitor] error in autoSetNetworkType', e);
- }
- }
- },
- autoSetSDKVersion() {
- const t = this;
- if (typeof my !== 'undefined' && my && typeof my.SDKVersion === 'string') {
- t.setCommonInfo({
- sdk_version: my.SDKVersion
- });
- }
- },
- autoSetRunScene() {
- const t = this;
- if (typeof my !== 'undefined' && my && typeof my.getRunScene === 'function') {
- try {
- my.getRunScene({
- success(e) {
- t._conf.environment = e.envVersion;
- }
- });
- } catch (e) {
- util.warn('[cloudMonitor] error in autoSetRunScene', e);
- }
- }
- },
- addHook() {
- const e = this;
- const t = util;
- const ca = e._conf.autoReportApi;
- const cp = e._conf.autoReportPage;
- !e.isHookInstantiated && (function () {
- if (ca) {
- if (typeof my !== 'undefined' && my && typeof my.request === 'function') {
- const s = my.request;
- var a = Object.getOwnPropertyDescriptor(my, 'request');
- a && a.writable && (my.request = function (i) {
- const a = new Date().getTime();
- let n = i;
- if (i && i.url) {
- const o = t.cutUrlSearch(i.url);
- if (!t.checkAPI(o, !0)) {
- return s.call(my, n);
- }
- let u = n && n.headers;
- const f = e._conf.extendApi;
- u && typeof u === 'object' || (u = {});
- const p = {
- success(t) {
- typeof i.success === 'function' && i.success(t);
- const s = new Date().getTime();
- let u = {};
- if (t.data && (!i.dataType || i.dataType === 'json')) {
- u = e.parseResponse(t.data);
- f && (u = util.ext(u, util.safetyCall(f, [i.data, t.data], {})));
- }
- e.api(util.ext({
- api: o,
- success: !0,
- time: s - a,
- code: '',
- msg: '',
- response: ''
- }, u));
- },
- fail(t) {
- typeof i.fail === 'function' && i.fail(t);
- const s = new Date().getTime();
- let n = '';
- t && t.status && (n = t.status);
- n == '' && t.error && (n = t.error);
- let u = '';
- const r = f ? util.safetyCall(f, [i.data], {}) : {};
- t && t.body && (u = (u = JSON.stringify(t.body)).substring(0, 256)), e.api(util.ext({
- api: o,
- success: !1,
- time: s - a,
- code: n,
- msg: u
- }, r));
- }
- };
- n = t.ext({}, n, p);
- }
- return s.call(my, n);
- });
- }
- }
- if (cp && typeof my !== 'undefined' && my) {
- if (typeof my.call === 'function') {
- const c = my.call;
- var a = Object.getOwnPropertyDescriptor(my, 'call');
- a && a.writable && (my.call = function (i, j, k) {
- if (i && i == 'startApp' && j && j.param && j.param.url) {
- let o = j.param.url;
- o = t.cutUrlSearch(o);
- e._lgPV({
- page: o,
- c3: 'c'
- });
- }
- return e.sendHealthOnPageShowOrHide(), c.call(my, i, j, k);
- });
- }
- if (typeof my.navigateTo === 'function') {
- const n = my.navigateTo;
- var a = Object.getOwnPropertyDescriptor(my, 'navigateTo');
- a && a.writable && (my.navigateTo = function (i) {
- if (i && i.url) {
- const o = t.cutUrlSearch(t.patchPath(i.url));
- e._lgPV({
- page: o,
- c3: 'nt'
- });
- }
- return e.sendHealthOnPageShowOrHide(), n.call(my, i);
- });
- }
- if (typeof my.navigateBack === 'function') {
- const w = my.navigateBack;
- var a = Object.getOwnPropertyDescriptor(my, 'navigateBack');
- a && a.writable && (my.navigateBack = function (i) {
- e._lgPV({
- page: e._conf.getPrePage(i || 1),
- c3: 'nb'
- });
- return e.sendHealthOnPageShowOrHide(), w.call(my, i);
- });
- }
- if (typeof my.redirectTo === 'function') {
- const x = my.redirectTo;
- var a = Object.getOwnPropertyDescriptor(my, 'redirectTo');
- a && a.writable && (my.redirectTo = function (i) {
- if (i && i.url) {
- const o = t.cutUrlSearch(t.patchPath(i.url));
- e._lgPV({
- page: o,
- c3: 'rt'
- });
- }
- return e.sendHealthOnPageShowOrHide(), x.call(my, i);
- });
- }
- if (typeof my.switchTab === 'function') {
- const y = my.switchTab;
- var a = Object.getOwnPropertyDescriptor(my, 'switchTab');
- a && a.writable && (my.switchTab = function (i) {
- if (i && i.url) {
- const o = t.cutUrlSearch(t.patchPath(i.url));
- e._lgPV({
- page: o,
- spmPre: 'T',
- c3: 'st'
- });
- }
- return e.sendHealthOnPageShowOrHide(), y.call(my, i);
- });
- }
- if (typeof my.reLaunch === 'function') {
- const z = my.reLaunch;
- var a = Object.getOwnPropertyDescriptor(my, 'reLaunch');
- a && a.writable && (my.reLaunch = function (i) {
- if (i && i.url) {
- const o = t.cutUrlSearch(t.patchPath(i.url));
- e._lgPV({
- page: o,
- spmPre: 'T',
- c3: 'rl'
- });
- }
- return z.call(my, i);
- });
- }
- if (typeof my.navigateToMiniProgram === 'function') {
- const m = my.navigateToMiniProgram;
- var a = Object.getOwnPropertyDescriptor(my, 'navigateToMiniProgram');
- a && a.writable && (my.navigateToMiniProgram = function (i) {
- if (i) {
- let o = i.path || i.appId || '-';
- o = t.cutUrlSearch(o);
- e._lgPV({
- page: o,
- c3: 'ntmp'
- });
- }
- return m.call(my, i);
- });
- }
- }
- }.call(e), e.isHookInstantiated = !0);
- return e;
- },
- init(t) {
- if (!t || !t.pid) {
- util.warn('[cloudMonitor] not set pid');
- }
- let p;
- const e = this;
- if (t.options) {
- p = t.options.path, t.scene = t.options.scene, delete t.options;
- }
- if (!t.ignore) {
- t.ignore = {
- ignoreUrls: [/\.(png|jpg|gif|jpeg)$/, /[\"{}]+/, /\.tfs.alipayobjects.com\.*/]
- };
- }
- this.setConfig(t), this.addHook();
- if (p) {
- e.entrance = util.toHex(p);
- e.onReady(() => {
- e._lg('pv', {
- spmPre: 'E',
- spmId: e.entrance || '',
- scene: e._conf.scene || '',
- c3: 'init'
- });
- });
- }
- return this;
- }
- });
- AlipayLogger._super = miniProgramLogger, AlipayLogger._root = miniProgramLogger._root, miniProgramLogger.AlipayLogger = AlipayLogger;
- export default new AlipayLogger();
|