aegis-mp-sdk 1.36.3 → 1.36.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,6 +10,14 @@ aegis-mp-sdk 是针对微信小程序和QQ小程序开发的数据收集和上
10
10
 
11
11
  ## 使用
12
12
 
13
+ ### 安装
14
+
15
+ 在项目支持 NPM 时推荐使用 NPM 安装 Aegis SDK。
16
+
17
+ ```bash
18
+ $ npm install --save aegis-mp-sdk
19
+ ```
20
+
13
21
  ### 初始化
14
22
 
15
23
  使用非常简单,只需要新建一个 Aegis 实例,传入相应的配置即可:
@@ -18,14 +26,30 @@ aegis-mp-sdk 是针对微信小程序和QQ小程序开发的数据收集和上
18
26
  import Aegis from 'aegis-mp-sdk';
19
27
 
20
28
  const aegis = new Aegis({
21
- id: "pGUVFTCZyewxxxxx", // 项目key
29
+ id: "pGUVFTCZyewxxxxx", // 项目上报ID
22
30
  uin: 'xxx', // 用户唯一 ID(可选)
23
- reportApiSpeed: true // 接口测速
31
+ reportApiSpeed: true, // 接口测速
32
+ reportAssetSpeed: true, // 静态资源测速
33
+ spa: true, // spa 页面需要开启,页面切换的时候上报pv
24
34
  })
25
35
  ```
26
36
 
37
+ 如果使用 ES 模块的方式引入 Aegis 后报错,可以通过如下方式解决
38
+
39
+
40
+ 方法一:在 tsconfig.json 中设置 `esModuleInterop:true`,然后再通过 `import Aegis from 'aegis-mp-sdk'` 引入
41
+
42
+ 方法二:`import * as Aegis from 'aegis-mp-sdk'`
43
+
44
+ 方法三:`const Aegis = require('aegis-mp-sdk')`
45
+
46
+
27
47
  ::: warning 注意 ⚠️
28
48
  为了不遗漏数据,须尽早进行初始化;
49
+
50
+ aegis-sdk 默认使用 `aegis.qq.com` 作为上报域名,您也可以选择使用 `tamaegis.com` 作为上报域名。
51
+
52
+ 小程序接入,正式环境需要将上报域名添加到安全域名中。
29
53
  :::
30
54
 
31
55
  ::: tip 当您做了以上接入工作之后,您已经开始享受 Aegis 提供的以下功能:
@@ -34,24 +58,105 @@ const aegis = new Aegis({
34
58
  3、数据统计和分析:可在 [RUM 平台](https://console.cloud.tencent.com/rum) 上查看各个纬度的数据分析;
35
59
  :::
36
60
 
61
+ ## 日志
62
+
63
+ Aegis SDK 会主动收集用户的一些性能和错误日志,开发者可以根据不同的参数来配置哪些日志需要上报,以及上报的日志具体信息。
64
+
65
+ ### 日志类型
66
+
67
+ 全部日志类型如下:
68
+
69
+ ```javascript
70
+ { logType: 'custom', name: '自定义测速' }
71
+ { logType: 'event', name: '自定义事件' }
72
+ { logType: 'log', name: '日志' }
73
+ { logType: 'performance', name: '页面测速' }
74
+ { logType: 'pv', name: '页面PV' }
75
+ { logType: 'speed', name: '接口和静态资源测速' }
76
+ { logType: 'vitals', name: 'web vitals' }
77
+ ```
78
+
79
+
80
+ ### 日志等级
81
+
82
+ 全部日志等级如下:
83
+
84
+ ```javascript
85
+ { level: 1, name: '白名单日志' },
86
+ { level: 2, name: '一般日志' },
87
+ { level: 4, name: '错误日志' },
88
+ { level: 8, name: 'Promise 错误' },
89
+ { level: 16, name: 'Ajax 请求异常' },
90
+ { level: 32, name: 'JS 加载异常' },
91
+ { level: 64, name: '图片加载异常' },
92
+ { level: 128, name: 'css 加载异常' },
93
+ { level: 256, name: 'console.error' },
94
+ { level: 512, name: '音视频资源异常' }
95
+ { level: 1024, name: 'retcode 异常' }
96
+ { level: 2048, name: 'aegis report' }
97
+ { level: 4096, name: 'PV' }
98
+ { level: 8192, name: '自定义事件' }
99
+ { level: 16384, name: '小程序 页面不存在' }
100
+ { level: 32768, name: 'websocket错误' }
101
+ { level: 65536, name: 'js bridge错误' }
102
+ ```
103
+
37
104
  ### 日志上报
38
105
 
39
- 创建完 Aegis 实例之后,就可以开心的上报日志啦 🥰,日志上报同样简单
106
+ 创建完 Aegis 实例之后,就可以开心的上报日志啦 🥰,日志上报同样简单。
40
107
 
41
108
  ```javascript
42
- aegis.info(
43
- `我是一条白名单上报的信息,只有在白名单中的用户才会上报哟。`
44
- );
109
+ // info 可以上报任意字符串,数字,数组,对象,但是只有打开页面的用户在名单中才会上报
110
+ aegis.info('test');
111
+ aegis.info('test', 123, ['a', 'b', 'c', 1], {a: '123'});
112
+
113
+
114
+ // 也可以上报特定的对象,支持用户传ext参数和trace参数
115
+ // 注意这种 case 一定要传 msg 字段
116
+ aegis.info({
117
+ msg: 'test',
118
+ ext1: 'ext1',
119
+ ext2: 'ext2',
120
+ ext3: 'ext3',
121
+ trace: 'trace',
122
+ });
123
+
124
+ // 不同于 info,infoAll 表示全量上报
125
+ aegis.infoAll({
126
+ msg: 'test',
127
+ ext1: 'ext1',
128
+ ext2: 'ext2',
129
+ ext3: 'ext3',
130
+ trace: 'trace',
131
+ });
45
132
 
46
- aegis.infoAll(
47
- `我是一条普通的信息,如果上报量很大的话请谨慎使用哟。`
48
- );
49
133
 
50
- aegis.report(
51
- new Error('我是一条错误信息,推荐在try..catch或者Promise.reject中使用。')
52
- )
134
+ // error 用来表示 JS 错误日志,也是全量上报,一般用于开发者主动获取JS异常,然后进行上报
135
+ aegis.error({
136
+ msg: 'test',
137
+ ext1: 'ext1',
138
+ ext2: 'ext2',
139
+ ext3: 'ext3',
140
+ trace: 'trace',
141
+ });
142
+ aegis.error(new Error('主动上报一个错误'));
143
+
144
+ // report 默认是 aegis.report 的日志类型,但是现在你可以传入任何日志类型了
145
+ aegis.report({
146
+ msg: '这是一个ajax错误日志',
147
+ level: Aegis.LogType.AJAX_ERROR,
148
+ ext1: 'ext1',
149
+ ext2: 'ext2',
150
+ ext3: 'ext3',
151
+ trace: 'trace',
152
+ });
53
153
  ```
54
154
 
155
+ info vs infoAll
156
+
157
+ 1. 使用 “infoAll ” 所有用户都上报,方便排查问题。但是也会带来一定的上报和存储成本。
158
+ 2. 使用 “info” 白名单上报。出了问题,可能会缺少关键路径日志。需要添加白名单,重新操作收集日志(类似于染色系统操作)。
159
+
55
160
  ## aid
56
161
 
57
162
  Aegis SDK 为每个用户设备分配的唯一标示,会存储在小程序的 storage 里面,用来区分用户,计算 uv 等。aid 只有用户清理小程序缓存才会更新。
@@ -59,60 +164,45 @@ Aegis SDK 为每个用户设备分配的唯一标示,会存储在小程序的
59
164
  算法如下:
60
165
 
61
166
  ```javascript
62
- import { Plugin } from 'aegis-core';
63
-
64
- export default new Plugin({
65
- name: 'aid',
66
- aid: '',
67
- init() {
68
- const env = wx || qq;
69
- // 某些情况下操作 localStorage 会报错.
70
- try {
71
- let aid = env.getStorageSync('AEGIS_ID');
72
- if (!aid) {
73
- aid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
74
- const r = (Math.random() * 16) | 0;
75
- const v = c === 'x' ? r : (r & 0x3) | 0x8;
76
- return v.toString(16);
77
- });
78
- env.setStorageSync('AEGIS_ID', aid);
79
- }
80
- this.aid = aid;
81
- } catch (e) {}
82
- },
83
- onNewAegis(aegis) {
84
- aegis.bean.aid = this.aid;
85
- },
86
- });
167
+ let aid = env.getStorageSync('AEGIS_ID');
168
+ if (!aid) {
169
+ aid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
170
+ const r = (Math.random() * 16) | 0;
171
+ const v = c === 'x' ? r : (r & 0x3) | 0x8;
172
+ return v.toString(16);
173
+ });
174
+ env.setStorageSync('AEGIS_ID', aid);
175
+ }
87
176
  ```
88
177
 
89
178
  ## 实例方法
90
179
 
91
- Aegis 实例暴露接口简单实用,目前 Aegis 实例有以下方法供您使用:
92
- `setConfig` 、 `info` 、 `infoAll` 、 `report` 、 `error` 、 `reportEvent` 、 `reportTime` 、 `time` 、 `timeEnd`
180
+ Aegis 实例暴露接口简单实用,目前 Aegis 实例有以下方法供您使用:
181
+ `setConfig` 、 `info` 、 `infoAll` 、 `report` 、 `error` 、 `reportEvent` 、 `reportTime` 、 `time` 、 `timeEnd`、 `destroy`
93
182
 
94
183
  ### setConfig
95
184
 
96
- 该方法用来修改实例配置,比如下面场景:
97
- 在实例化 Aegis 时需要传入配置对象
185
+ 该方法用来修改实例配置,比如下面场景:
186
+
187
+ - 在实例化 Aegis 时需要传入配置对象。
98
188
 
99
189
  ```javascript
100
190
  const aegis = new Aegis({
101
- id: 'pGUVFTCZyewxxxxx',
102
- uin: 777
191
+ id: 'pGUVFTCZyewxxxxx',
192
+ uin: 777
103
193
  })
104
194
  ```
105
195
 
106
- 很多情况下,并不能一开始就获取到用户的 `uin`,而等获取到用户的 `uin` 才开始实例化 Aegis,如果这期间发生了错误 Aegis 将监听不到。`uin` 的设置可以在获取到用户的时候:
196
+ - 很多情况下,并不能一开始就获取到用户的 `uin`,而等获取到用户的 `uin` 才开始实例化 Aegis,如果这期间发生了错误 Aegis 将监听不到。`uin` 的设置可以在获取到用户的时候:
107
197
 
108
198
  ```javascript
109
199
  const aegis = new Aegis({
110
- id: 'pGUVFTCZyewxxxxx'
200
+ id: 'pGUVFTCZyewxxxxx'
111
201
  })
112
202
 
113
203
  // 拿到uin之后...
114
204
  aegis.setConfig({
115
- uin: 777
205
+ uin: 777
116
206
  })
117
207
  ```
118
208
 
@@ -132,24 +222,28 @@ aegis.report(new Error('上报一个错误'));
132
222
 
133
223
  该方法可用来上报自定义事件,平台将会自动统计上报事件的各项指标,诸如:PV、UV、平台分布等...
134
224
 
135
- reportEvent 可以支持两种类型上报参数类型,一种是字符串类型
225
+ reportEvent 可以支持两种类型上报参数类型。
226
+
227
+ 1. 字符串类型
136
228
 
137
229
  ```javascript
138
230
  aegis.reportEvent('XXX请求成功');
139
231
  ```
140
232
 
141
- 一种是对象类型,ext1 ext2 ext3 默认使用 new Aegis 的时候传入的参数,自定义事件上报的时候,可以覆盖默认值。
233
+ 2. 对象类型,ext1 ext2 ext3 默认使用 new Aegis 的时候传入的参数,自定义事件上报的时候,可以覆盖默认值。
142
234
 
143
235
  ```javascript
144
236
  aegis.reportEvent({
145
- name: 'XXX请求成功',
146
- ext1: '额外参数1',
147
- ext2: '额外参数2',
148
- ext3: '额外参数3',
237
+ name: 'XXX请求成功',
238
+ ext1: '额外参数1',
239
+ ext2: '额外参数2',
240
+ ext3: '额外参数3',
149
241
  })
150
242
  ```
151
243
 
152
- 注意,额外参数的三个 key 是固定的,目前只支持 ext1 ext2 ext3。
244
+ ::: warning 注意
245
+ 额外参数的三个 key 是固定的,目前只支持 `ext1`、 `ext2`、 `ext3`。
246
+ :::
153
247
 
154
248
  ### reportTime
155
249
 
@@ -164,16 +258,17 @@ aegis.reportTime('onload', 1000);
164
258
 
165
259
  ```javascript
166
260
  aegis.reportTime({
167
- name: 'onload', // 自定义测速 name
168
- duration: 1000, // 自定义测速耗时(0 - 60000)
169
- ext1: 'test1',
170
- ext2: 'test2',
171
- ext3: 'test3',
261
+ name: 'onload', // 自定义测速 name
262
+ duration: 1000, // 自定义测速耗时(0 - 60000)
263
+ ext1: 'test1',
264
+ ext2: 'test2',
265
+ ext3: 'test3',
172
266
  });
173
267
  ```
174
268
 
175
269
  > `onload` 可以修改为其他的命名。
176
270
 
271
+
177
272
  ### time、timeEnd
178
273
 
179
274
  该方法同样可用来上报自定义测速,适用于两个时间点之间时长的计算并上报,例如:
@@ -194,6 +289,15 @@ aegis.timeEnd('complexOperation'); /** 此时日志已经报上去了😄**/
194
289
  > 自定义测速是用户上报任意值,服务端对其进行统计和计算,因为服务端不能做脏数据处理,因此建议用户在上报端进行统计值限制,防止脏数据对整体产生影响。
195
290
  > 目前 Aegis 只支持 0-60000 的数值计算,如果大于该值,建议进行合理改造。
196
291
 
292
+
293
+ ### destroy
294
+
295
+ 该方法用于销毁 sdk 实例,销毁后,不再进行数据上报
296
+
297
+ ```javascript
298
+ aegis.destroy();
299
+ ```
300
+
197
301
  ## 白名单
198
302
 
199
303
  白名单功能是适用于开发者希望对某些特定的用户上报更多的日志,但是又不希望太多上报来影响到全部日志数据,并且减少用户的接口请求次数,因为 TAM 设定了白名单的逻辑。
@@ -204,147 +308,130 @@ aegis.timeEnd('complexOperation'); /** 此时日志已经报上去了😄**/
204
308
  4. 通过接口 whitelist 来判断当前用户是否是白名单用户,白名单用户的返回结果会绑定在 aegis 实例上 (aegis.isWhiteList) 用来给开发者使用。
205
309
  5. 用了减少开发者使用负担,白名单用户是团队有效,可以在 [应用管理-白名单管理](https://console.cloud.tencent.com/rum/web/group-whitelist-manage) 内创建白名单,则团队下全部项目都生效。
206
310
 
311
+
207
312
  ## 钩子函数
208
313
 
209
- ### beforeReport
314
+ ### beforeRequest
210
315
 
211
- 该钩子将会在日志上报前执行,例如:
316
+ 该钩子将会在日志上报前执行,用于对上报数据的拦截和修改,通过返回不同类型的值:
317
+ * 拦截:返回false
318
+ * 修改:修改入参的值并返回
212
319
 
213
320
  ```javascript
214
321
  const aegis = new Aegis({
215
- id: 'pGUVFTCZyewxxxxx',
216
- beforeReport(log) {
217
- // 监听到下面抛出的错误
218
- console.log(log); // {level: "4", msg: "发生错误啦!!!!"}
322
+ id: "pGUVFTCZyewxxxxx",
323
+ beforeRequest: function(data) {
324
+ //入参data的数据结构:{logs: {…}, logType: "log"}
325
+ if(data.logType === 'log' && data.logs.msg.includes('otheve.beacon.qq.com')){
326
+ // 拦截:日志类型为log,且内容包含otheve.beacon.qq.com的请求
327
+ return false;
328
+ }
329
+ if(data.logType === 'performance'){
330
+ // 修改:将性能数据的首屏渲染时间改为2s
331
+ data.logs.firstScreenTiming = 2000;
332
+ return data;
333
+ }
219
334
  }
220
335
  });
221
-
222
- throw new Error('发生错误啦!!!!');
223
336
  ```
224
337
 
225
- 其中,`log` 将会有以下几个字段:
338
+ 其中,`msg` 将会有以下几个字段:
226
339
 
227
- > 1.`level`: 日志等级,例如:当 level 为 '4' 时代表错误日志;
340
+ > 1.`logs`: 上报的日志内容;
228
341
 
229
- > 2.`msg`: 日志内容;
342
+ > 2.`logType`: 日志类型
230
343
 
231
- 全部日志等级如下
344
+ logType等于`custom`时,logs的值如下:
232
345
 
233
346
  ```sh
234
- { level: '1', name: '白名单日志' },
235
- { level: '2', name: '一般日志' },
236
- { level: '4', name: '错误日志' },
237
- { level: '8', name: 'Promise 错误' },
238
- { level: '16', name: 'Ajax 请求异常' },
239
- { level: '32', name: 'JS 加载异常' },
240
- { level: '64', name: '图片加载异常' },
241
- { level: '128', name: 'css 加载异常' },
242
- { level: '256', name: 'console.error (废弃)' },
243
- { level: '512', name: '音视频资源异常' },
244
- { level: '1024', name: 'retcode 异常' },
245
- { level: '2048', name: 'aegis report' },
246
- { level: '16384', name: '页面不存在' },
347
+ {name: "白屏时间", duration: 3015.7000000178814, ext1: '', ext2: '', ext3: '', from: ''}
247
348
  ```
248
349
 
249
- 当该钩子返回 `false` 时,本条日志将不会进行上报,该功能可用来过滤某些不需要上报的错误,例如:
350
+ logType等于`event`时,logs的值如下:
250
351
 
251
- ```javascript
252
- const aegis = new Aegis({
253
- id: 'pGUVFTCZyewxxxxx',
254
- beforeReport(log) {
255
- if (log.level === '4' && log.msg && log.msg.indexOf('碍眼的错误') !== -1) {
256
- return false
257
- }
258
- }
259
- });
260
- throw new Error('碍眼的错误'); // 该错误将不会被上报
352
+ ```sh
353
+ {name: "ios", ext1: "", ext2: "", ext3: ""}
261
354
  ```
262
355
 
263
- 上面例子中,当上报的错误内容包含 `碍眼的错误` 几个关键字时,将不会上报至 RUM 后台中。
264
-
265
- ### onReport
266
-
267
- 该钩子将在日志上报成功之后执行,用法类似 `beforeReport` 钩子,唯一不同点在于,该钩子接收到的所有参数都是已经上报完成的日志,而 `beforeReport` 钩子接收的参数是即将上报的日志。
268
-
269
- ### beforeReportSpeed
270
-
271
- 该勾子将会在测速数据上报前被执行,例如:
356
+ logType等于`log`时,logs的值如下:
272
357
 
273
- ```javascript
274
- const aegis = new Aegis({
275
- id: 'pGUVFTCZyewxxxxx',
276
- reportApiSpeed: true,
277
- reportAssetSpeed: true,
278
- beforeReportSpeed(msg) {
279
- console.log(msg); // {url: "https://localhost:3001/example.e31bb0bc.js", method: "get", duration: 7.4, status: 200, type: "static"}
280
- return msg
281
- }
282
- });
283
- ```
284
-
285
- 其中,`msg` 将会有以下几个字段:
286
-
287
- > 1.`url`: 该资源的请求地址;
358
+ ```sh
359
+ { level: '1', msg: '接口请求日志(白名单日志)' } // 具体level信息参考日志等级
360
+ ```
288
361
 
289
- > 2.`type`: 该资源的类型,目前有 `fetch` 、 `static` 两种,当为 `fetch` 时,Aegis 将会把该资源当成 API 请求进行上报,`static` 时则视为静态资源;
362
+ logType等于`performance`时,logs的值如下:
290
363
 
291
- > 3.`duration`: 该资源请求耗时;
364
+ ```sh
365
+ {contentDownload: 2, dnsLookup: 0, domParse: 501, firstScreenTiming: 2315, resourceDownload: 2660, ssl: 4, tcp: 4, ttfb: 5}
366
+ ```
292
367
 
293
- > 4.`method`: 请求该资源时使用的 `http method`;
368
+ logType等于`speed`时,logs的值如下:
294
369
 
295
- > 5.`status`: 服务器返回状态码;
370
+ ```sh
371
+ // 静态资源
372
+ {connectTime: 0, domainLookup: 0, duration: 508.2, nextHopProtocol: "", isHttps: true, method: "get", status: 200, type: "static", url: "https://puui.qpic.cn/xxx", urlQuery: "max_age=1296000"}
296
373
 
297
- 上面的 🌰中,每当 Aegis 收集到一个资源的加载详情时,将会以该资源的加载情况(上面的`msg`)作为参数调用 `beforeReportSpeed` 勾子。
374
+ // API
375
+ {duration: 26, isErr: 0, isHttps: true, method: "GET", nextHopProtocol: "", ret: "0", status: 200, type: "fetch", url: "https://xx.com/cgi-bin/whoami"}
376
+ ```
298
377
 
299
- 如果您配置了该勾子,**Aegis 最终的上报内容将以勾子的执行结果为准**。例如:
378
+ logType等于`vitals`时,logs的值如下:
300
379
 
301
- ```javascript
302
- const aegis = new Aegis({
303
- id: 'pGUVFTCZyewxxxxx',
304
- reportApiSpeed: true,
305
- reportAssetSpeed: true,
306
- beforeReportSpeed(msg) {
307
- msg.type = 'static';
308
- }
309
- });
380
+ ```sh
381
+ {CLS: 3.365504747991234, FCP: 139.39999997615814, FID: -1, LCP: 127.899}
310
382
  ```
383
+ ### modifyRequest
311
384
 
312
- 上面的代码中,将所有的 `msg.type` 设置为 `static`,这意味着所有的资源都将被当成静态资源进行上报,API 请求也将被报至静态资源中。
313
-
314
- 使用该勾子,您可以校准 Aegis 类型判断错误的请求。
315
- 比方说,假如您有一条接口 `https://example.com/api`,该接口的响应头 `Content-Type` 为 `text/html`,
316
- 正常情况下,Aegis 会将该资源当成静态资源进行上报。但在您的业务中,该接口就必须视为 API 请求进行上报,您可以给 Aegis 配置如下勾子进行校正:
385
+ 该钩子函数会在所有请求发出前调用,参数中会传入请求的所有内容,必须返回待发送内容。
317
386
 
318
387
  ```javascript
388
+ function changeURLArg(url,arg,arg_val) {
389
+ var pattern=arg+' = ([^&]*)';
390
+ var replaceText = arg+'='+arg_val;
391
+ if (url.match(pattern)) {
392
+ var tmp = '/('+ arg+'=)([^&]*)/gi';
393
+ tmp = url.replace(eval(tmp),replaceText);
394
+ return tmp;
395
+ }
396
+ return url;
397
+ }
319
398
  const aegis = new Aegis({
320
399
  id: 'pGUVFTCZyewxxxxx',
321
- reportApiSpeed: true,
322
- reportAssetSpeed: true,
323
- beforeReportSpeed(msg) {
324
- if (msg.url === 'https://example.com/api') {
325
- msg.type = 'fetch';
400
+ modifyRequest(options) {
401
+ if (options.type === 'performance') {
402
+ // 页面测速,此时可以修改options内容,如修改页面测速platform
403
+ options.url = changeURLArg(options.url, 'platform', type)
326
404
  }
405
+ return options
327
406
  }
328
407
  });
329
408
  ```
409
+ ### afterRequest
330
410
 
331
- 您还可以屏蔽某些资源的测速上报,例如:
411
+ 该勾子将会在数据上报后被执行,例如:
332
412
 
333
413
  ```javascript
334
414
  const aegis = new Aegis({
335
- id: 'pGUVFTCZyewxxxxx',
415
+ id: "pGUVFTCZyewxxxxx",
336
416
  reportApiSpeed: true,
337
417
  reportAssetSpeed: true,
338
- beforeReportSpeed(msg) {
339
- // 地址中包含‘https://example.com/api’的都不上报
340
- if (msg.url.indexOf('https://example.com/api') !== -1) {
341
- // 返回 ‘false’ 将阻止本条测速日志的上报
342
- return false
343
- }
418
+ afterRequest: function(msg) {
419
+ // {isErr: false, result: Array(1), logType: "log", logs: Array(4)}
420
+ console.log(msg);
344
421
  }
345
422
  });
346
423
  ```
347
424
 
425
+ 其中,`msg` 将会有以下几个字段:
426
+
427
+ > 1.`isErr`: 请求上报接口是否错误;
428
+
429
+ > 2.`result`: 上报接口的返回结果;
430
+
431
+ > 3.`logs`: 上报的日志内容;
432
+
433
+ > 4.`logType`: 日志类型,有以下值speed:接口和静态资源测速,performance:页面测速,vitals:web vitals,event:自定义事件,custom:自定义测速;
434
+
348
435
  ## 错误监控
349
436
 
350
437
  ::: warning
@@ -353,56 +440,107 @@ Aegis 的实例会自动进行以下监控,注意!是 Aegis 实例会进行
353
440
 
354
441
  ### JS执行错误
355
442
 
356
- Aegis 通过监听 `wx.onerror` 事件来获取项目中的报错,并且通过解析错误和分析堆栈,将错误信息自动上报到后台服务中。该上报的上报等级为 error ,所以,当自动上报的错误达到阈值时,Aegis 将会自动告警,帮助您尽早发现异常。由于上报等级为 error ,自动上报也将影响项目的每日评分。
443
+ Aegis 通过监听 `window` 对象上的 `onerror` 事件来获取项目中的报错,并且通过解析错误和分析堆栈,将错误信息自动上报到后台服务中。该上报的上报等级为 error ,所以,当自动上报的错误达到阈值时,Aegis 将会自动告警,帮助您尽早发现异常。由于上报等级为 error ,自动上报也将影响项目的每日评分。
357
444
 
358
- ### Promise执行错误
445
+ ### request 请求异常
359
446
 
360
- 通过监听 `wx.onUnhandledRejection` 事件,捕获到未被 `catch` 的Promise错误,为了页面的健壮,建议您 `catch` 住所有的Promise错误哟。
447
+ Aegis 将会改写 `wx.request`(`qq.request`) 对象(请您放心,Aegis很专业),监听每次接口请求,当 `statusCode` 不存在或者大于等于 400 时认为该请求是一个失败的请求,亦或是接口超时,abort 和其他类型的失败。
361
448
 
362
- ### 页面不存在错误
449
+ 注意: Aegis SDK 在错误发生的时候,不会主动收集接口请求参数和返回信息,如果需要对进口信息进行上报,可以使用 api 参数里面的 apiDetail 进行开启。
363
450
 
364
- 通过监听 `wx.onPageNotFound` 事件,捕获小程序要打开的页面不存在错误。
451
+ ```javascript
452
+ new Aegis({
453
+ id: '',
454
+ api: {
455
+ apiDetail: true,
456
+ },
457
+ });
458
+ ```
365
459
 
366
- ### request 请求异常
460
+ ### retcode异常
367
461
 
368
- Aegis 将会改写 `wx.request`(`qq.request`) 对象,监听每次接口请求,当 `statusCode` 大于 400 时将认为该请求是一个失败的请求。
462
+ 同上,Aegis 在改写 `wx.request`(`qq.request`) 对象之后,将获得API返回的内容,并尝试在内容中获取到本次请求的 `retcode`。
369
463
 
370
- ### 返回码异常
464
+ > retcode 的值会从用户返回 response body 的第一层(如果第一层取不到,再取第二层)的 code、ret、retcode、errcode 中获取。
465
+ > Aegis 默认 retcode 的值为0是正常的,非0都是异常的。当 `retcode` 发生异常的时候,会上报一个 retcode异常的日志。
466
+ > 用户可以通过 api.retCodeHandler 对这个值和是否异常进行修正。
371
467
 
372
- 同上,Aegis 在改写 `wx.request`(`qq.request`) 对象之后,将获得API返回的内容,并尝试在内容中获取到本次请求的 `retcode`,
373
- 当 `retcode` 不符合预期的时候,会认为本次请求出现了异常,并进行上报。
374
- > 如何获取 `retcode` 以及哪些 `retcode` 是正常的可以在配置文档中查看。
468
+ ### websocket异常
469
+ Aegis默认不会对全局websocket对象进行重写,默认不会监控websocket相关错误,如果需要打开相关功能可以在创建Aegis对象时设置websocketHack: true。
470
+ ```javascript
471
+ new Aegis({
472
+ id: '',
473
+ websocketHack: true
474
+ });
475
+ ```
375
476
 
376
477
  ## 性能监控
478
+ ### 页面性能
479
+
480
+ > Aegis 小程序 SDK 会自动收集页面性能数据并上报。包括:
481
+ 1. 程序启动时间
482
+ 2. 代码注入时间
483
+ 3. 页面首次渲染时间
484
+ 4. 路由切换时间
485
+
486
+ ::: warning 注意 ⚠️
487
+ 获取页面性能数据依赖小程序的 Performance API,请保证基础库版本 `>2.11.0`。
488
+ 手Q小程序目前暂时不支持 Performance API,所以不会上报页面性能数据。
489
+ :::
490
+
491
+
492
+ ### 组件更新性能(setData)
493
+
494
+ > Aegis 小程序 SDK 默认会自动获取组件的更新性能数据并上报,便于对组件针对性优化。
495
+
496
+ ::: warning 注意 ⚠️
497
+ 获取更新性能统计信息依赖小程序框架提供的API `setUpdatePerformanceListener`,请保证基础库版本 `>2.12.0`。
498
+ 详情可以参考[这里](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/update-perf-stat.html)。
499
+ :::
500
+
501
+ ::: warning 注:
502
+ 某些应用场景下的小程序项目可能数据更新很频繁从而导致上报请求过多,因此 sdk 针对 setData 数据上报提供了额外的配置项,具体可见下方`配置文档`中的`setDataReportConfig`配置项。
503
+ :::
377
504
 
378
- ### 页面测速
379
505
 
380
- Aegis SDK 通过收集小程序的 performance 信息来对您的页面进行测速。
381
506
  ### 接口测速
382
507
 
383
- > 打开方式:初始化时传入配置 `reportApiSpeed: true`
508
+ > 打开方式:初始化时传入配置 `reportApiSpeed: true`
384
509
 
385
- Aegis 通过劫持 `wx.request || qq.request` 进行接口测速。
510
+ Aegis 通过劫持 `wx.request || qq.request` 进行接口测速,具体代码在 [这里](https://git.code.oa.com/tam/aegis-sdk/blob/master/packages/mp-sdk/src/plugins/cgi-speed.ts)
386
511
 
387
- ## 配置文档
388
512
 
513
+ ## 配置文档
389
514
  | 配置 | 描述 |
390
515
  | -------- | -------- |
391
- | id | 必须,number,默认 无。<br>开发者平台分配的项目key |
392
- | uin | 建议,string,默认取 cookie 中的 uin 字段。<br>当前用户的唯一标识符,白名单上报时将根据该字段判定用户是否在白名单中,字段仅支持`字母数字@=._-`,正则表达式: `/^[@=.0-9a-zA-Z_-]{1,60}$/` |
516
+ | id | 必须,string,默认 无。<br>开发者平台分配的项目上报ID |
517
+ | uin | 建议,string <br>业务定义的当前用户的唯一标识符,用来查找固定用户的日志。白名单上报时将根据该字段判定用户是否在白名单中,字段仅支持`字母数字@=._-`,正则表达式: `/^[@=.0-9a-zA-Z_-]{1,60}$/` |
393
518
  | reportApiSpeed | 可选,boolean,默认 false。<br>是否开启接口测速 |
519
+ | reportAssetSpeed | 可选,boolean,默认 false。<br>是否开启静态资源测速 |
520
+ | reportLoadPackageSpeed | 可选,boolean,默认 false。<br>是否开启包下载耗时上报 |
521
+ | pagePerformance | 可选,boolean 默认 true。<br>是否开启页面测速 |
394
522
  | version | 可选,string,默认 sdk 版本号。<br>当前上报版本,当页面使用了pwa或者存在离线包时,可用来判断当前的上报是来自哪一个版本的代码,仅支持`字母数字.,:_-`,长度在 60 位以内 `/^[0-9a-zA-Z.,:_-]{1,60}$/` |
395
523
  | delay | 可选,number,默认 1000 ms。<br>上报节流时间,在该时间段内的上报将会合并到一个上报请求中。 |
396
524
  | repeat | 可选,number,默认 5。<br>重复上报次数,对于同一个错误超过多少次不上报。 |
397
- | enableHttp2 | 可选,boolean,默认 false。<br> 上报数据是否支持 HTTP2,默认没有开启,以后会考虑改成默认开启。 |
525
+ | env | 可选,enum,默认 Aegis.environment.production。 <br> 当前项目运行所处的环境。|
526
+ | spa | 可选,boolean,默认 false。 <br> 当前页面是否是单页应用?true的话将会监听hashchange及history api,在页面跳转时进行pv上报 |
527
+ | pageUrl | 可选。默认是 location.href。 <br> 修改上报数据中页面地址,开发者可以主动对数据进行聚合和降低维度|
528
+ | urlHandler | 可选,Function。 <br> 动态修改上报数据中页面地址 from,可以配合 pageUrl 参数使用|
398
529
  | websocketHack | 可选,boolean,默认 false <br>是否开启websocket监控。 |
530
+ | enableHttp2 | 可选,boolean,默认 false。<br> 上报数据是否支持 HTTP2,默认没有开启。 |
399
531
  | offlineLog | 可选,boolean,默认 false。<br>是否使用离线日志 |
400
532
  | offlineLogExp | 可选,number,默认 3。<br>离线日志过期天数 |
401
- | url | 可选,string,默认 '//aegis.qq.com/collect'。<br>日志上报地址 |
402
- | speedUrl | 可选,string,默认 '//aegis.qq.com/speed'。<br>测速日志上报地址 |
403
- | performanceUrl | 可选,string,默认 '//aegis.qq.com/speed/performance'。<br>页面性能日志上报地址 |
404
- | whiteListUrl | 可选,string,默认 '//aegis.qq.com/collect/whitelist'。<br>白名单确认接口 <br>如果想要关闭白名单接口请求,可以传空字符串|
405
- | api | 可选,object,默认为{}。相关的配置: <br> apiDetail : 可选,boolean,默认false。api 失败的时候,是否上报 api 的请求参数和返回值; <br> retCodeHandler: Function, 返回码上报钩子函数。 会传入接口返回数据,返回值为{isErr: boolean, code: string}。<span id="jump">[见示例[1]](#exp1)</span> |
533
+ | hostUrl | 可选,默认是 `https://aegis.qq.com`。<br>影响全部上报数据的 host 地址,下面几个 url 地址设置后会覆盖对应的上报地址 |
534
+ | url | 可选,string,默认 'https://aegis.qq.com/collect'。<br>日志上报地址 |
535
+ | pvUrl | 可选,string, 默认 'https://aegis.qq.com/collect/pv' <br> pv 上报地址 |
536
+ | whiteListUrl | 可选,string,默认 'https://aegis.qq.com/collect/whitelist'。<br>白名单确认接口 <br>如果想要关闭白名单接口请求,可以传空字符串|
537
+ | offlineUrl | 可选,string,默认 'https://aegis.qq.com/collect/offline'。<br> 离线日志上报地址 |
538
+ | eventUrl | 可选,string,默认 'https://aegis.qq.com/collect/events'。<br> 自定义事件上报地址 |
539
+ | speedUrl | 可选,string,默认 'https://aegis.qq.com/speed'。<br>测速日志上报地址 |
540
+ | customTimeUrl | 可选,string,默认 'https://aegis.qq.com/speed/custom'。<br>自定义测速上报地址 |
541
+ | performanceUrl | 可选,string,默认 'https://aegis.qq.com/speed/performance'。<br>页面性能日志上报地址 |
542
+ | setDataReportConfig | 可选,object,默认为{}。相关的配置: <br> disabled: 可选,Boolean,默认false。是否禁用setData数据上报; <br> timeThreshold: 可选,Number,单位为ms,默认值为30。上报的耗时阈值,表示仅上报更新耗时超过该阈值的数据;<br> withDataPaths: 可选,Boolean,默认为true。是否上报本次更新的字段信息;|
543
+ | api | 可选,object,默认为 {}。相关的配置: <br> apiDetail : 可选,boolean,默认false。上报 api 信息的时候,是否上报 api 的请求参数和返回值; <br><br> retCodeHandler: Function(data: String, url: String, xhr: Object):{isErr: boolean, code: string}, 返回码上报钩子函数。 会传入接口返回数据,请求url和xhr对象; <br><br> reqParamHandler: Function(data: any, url: String) 上报请求参数的处理函数,可以对接口的请求参数进行处理,方便用户过滤上报请求参数的信息; <br><br> resBodyHandler: Function(data: any, url: String) 上报 response 返回 body 的处理函数,可以对接口返回值的 response body 进行处理,只上报关键信息; <br><br> reqHeaders: Array 需要上报的 http 请求 request headers 列表。 <br><br> resHeaders: Array 需要上报的 http 请求 response headers 列表。 <br><br> resourceTypeHandler: Function,请求资源类型修正钩子函数 会传入接口url,返回值为‘static’或‘fetch’。<span id="jump">[见示例[1]](#exp1)</span> <br><br> reportRequest: boolean, 默认为false。 开启aegis.info全量上报, 不需要白名单配置。并上报所有接口请求信息(请开启reportApiSpeed) |
406
544
  | ext1 | 可选,string,自定义上报的额外维度,上报的时候可以被覆盖 |
407
545
  | ext2 | 可选,string,自定义上报的额外维度,上报的时候可以被覆盖 |
408
546
  | ext3 | 可选,string,自定义上报的额外维度,上报的时候可以被覆盖 |
@@ -413,25 +551,27 @@ Aegis 通过劫持 `wx.request || qq.request` 进行接口测速。
413
551
 
414
552
  ```json
415
553
  {
416
- body: {
417
- code: 200,
418
- retCode: 0,
419
- data: {
420
- // xxx
421
- }
554
+ body: {
555
+ code: 200,
556
+ retCode: 0,
557
+ data: {
558
+ // xxx
422
559
  }
560
+ }
423
561
  }
562
+
424
563
  ```
425
564
 
426
565
  业务需要:code不为200,或者retCode不为0,此次请求就是错误的。此时只需进行以下配置:
427
566
 
428
567
  ```javascript
429
568
  new Aegis({
430
- reportApiSpeed: true, // 需要开两个,不然不会有返回码上报
569
+ // xxx
570
+ reportApiSpeed: true, // 需要开启,不然不会有返回码上报
431
571
  reportAssetSpeed: true,
432
572
  api: {
433
- retCodeHandler(data) {
434
- // 注意这里拿到的data是string类型,如果需要对象需要手动parse下
573
+ retCodeHandler(data) {
574
+ // 注意这里的data的数据类型,跟接口返回值的数据类型一致,开发者需要根据实际情况自行处理
435
575
  try {
436
576
  data = JSON.parse(data)
437
577
  } catch(e) {}
package/lib/aegis.min.js CHANGED
@@ -1,10 +1,10 @@
1
1
  /**
2
- * =================================================================
3
- * aegis-mp-sdk@1.36.3 (c) 2022 TencentCloud Real User Monitoring.
2
+ * ================================================================
3
+ * aegis-mp-sdk@1.36.4 (c) 2022 TencentCloud Real User Monitoring.
4
4
  * Author pumpkincai.
5
- * Last Release Time Mon Sep 26 2022 17:26:47 GMT+0800 (GMT+08:00).
5
+ * Last Release Time Thu Nov 24 2022 16:10:40 GMT+0800 (中国标准时间).
6
6
  * Released under the MIT License.
7
7
  * Thanks for supporting RUM & Aegis!
8
- * =================================================================
8
+ * ================================================================
9
9
  **/
10
- !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).Aegis=t()}(this,function(){"use strict";var _=function(e,t){return(_=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)};function e(e,t){function n(){this.constructor=e}_(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var p=function(){return(p=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function I(i,o){var r,a,s,l={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},e={next:t(0),throw:t(1),return:t(2)};return"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function t(n){return function(e){var t=[n,e];if(r)throw new TypeError("Generator is already executing.");for(;l;)try{if(r=1,a&&(s=2&t[0]?a.return:t[0]?a.throw||((s=a.return)&&s.call(a),0):a.next)&&!(s=s.call(a,t[1])).done)return s;switch(a=0,(t=s?[2&t[0],s.value]:t)[0]){case 0:case 1:s=t;break;case 4:return l.label++,{value:t[1],done:!1};case 5:l.label++,a=t[1],t=[0];continue;case 7:t=l.ops.pop(),l.trys.pop();continue;default:if(!((s=0<(s=l.trys).length&&s[s.length-1])||6!==t[0]&&2!==t[0])){l=0;continue}if(3===t[0]&&(!s||t[1]>s[0]&&t[1]<s[3]))l.label=t[1];else if(6===t[0]&&l.label<s[1])l.label=s[1],s=t;else{if(!(s&&l.label<s[2])){s[2]&&l.ops.pop(),l.trys.pop();continue}l.label=s[2],l.ops.push(t)}}t=o.call(i,l)}catch(e){t=[6,e],a=0}finally{r=s=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}}}function a(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;for(var i=Array(e),o=0,t=0;t<n;t++)for(var r=arguments[t],a=0,s=r.length;a<s;a++,o++)i[o]=r[a];return i}Object.assign||Object.defineProperty(Object,"assign",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(null==e)throw new TypeError("Cannot convert first argument to object");for(var t=Object(e),n=1;n<arguments.length;n++)if(null!=(i=arguments[n]))for(var i=Object(i),o=Object.keys(Object(i)),r=0,a=o.length;r<a;r++){var s=o[r],l=Object.getOwnPropertyDescriptor(i,s);null!=l&&l.enumerable&&(t[s]=i[s])}return t}});var D=["ext1","ext2","ext3","level","trace","tag","seq","code"],F=(t.prototype.indexOf=function(e,t){for(var n=0;n<e.length;n++)if(e[n].callback===t)return n;return-1},t.prototype.on=function(e,t,n){var i;if(void 0===n&&(n=0),this)return(i=this.eventsList[e])||(this.eventsList[e]=[],i=this.eventsList[e]),-1===this.indexOf(i,t)&&i.push({name:e,type:n||0,callback:t}),this},t.prototype.one=function(e,t){this.on(e,t,1)},t.prototype.remove=function(e,t){if(this){var n=this.eventsList[e];if(n){if(t)return n.length&&(t=this.indexOf(n,t),n.splice(t,1)),this;try{delete this.eventsList[e]}catch(e){}}return null}},t.prototype.clear=function(){this.eventsList={}},t),M=function(e){if(!e||0===e.length)return"{}";e=Array.isArray(e)?e:[e];var t=Object.keys(e[0]),n={},i=(t.forEach(function(t){n[t]=e.map(function(e){return e[t]})}),n.count=e.length,n);if("string"==typeof i)return i;try{return JSON.stringify(i,o())||"undefined"}catch(i){return"error happen when aegis stringify: \n "+i.message+" \n "+i.stack}};function t(){var a=this;this.emit=function(e,t){if(a){var n;if(null!=(i=a.eventsList[e])&&i.length)for(var i=i.slice(),o=0;o<i.length;o++){n=i[o];try{var r=n.callback.apply(a,[t]);if(1===n.type&&a.remove(e,n.callback),!1===r)break}catch(e){throw e}}return a}},this.eventsList={}}function l(e,t){return"string"==typeof e?e.split("?")[t?1:0]||"":e}function H(e){return"string"==typeof e&&e.startsWith("//")?"undefined"!=typeof location&&"https:"===location.protocol:/^https/.test(e)}function u(e,t,n){var i,o;try{if("function"==typeof(null==t?void 0:t.retCodeHandler))return{code:void 0===(r=(o=t.retCodeHandler(e,null==n?void 0:n.url,null==n?void 0:n.ctx)||{}).code)?"unknown":r,isErr:o.isErr};"string"==typeof e&&(e=JSON.parse(e)),"function"==typeof(null==(i=null==t?void 0:t.ret)?void 0:i.join)&&(B=[].concat(t.ret.map(function(e){return e.toLowerCase()})));var r,a=Object.getOwnPropertyNames(e).filter(function(e){return-1!==B.indexOf(e.toLowerCase())});return a.length?{code:""+(r=e[a[0]]),isErr:0!==r&&"0"!==r}:{code:"unknown",isErr:!1}}catch(e){return{code:"unknown",isErr:!1}}}function f(r,a){void 0===a&&(a=3);var o,s,l,c="";return Array.isArray(r)?(c+="[",o=r.length,r.forEach(function(e,t){var n,i;c=(c+="object"==typeof e&&1<a?f(e,a-1):(i="",i+="undefined"==(n=typeof(e=e))||"symbol"==n||"function"==n?"null":"string"==n||"object"==n?'"'+e+'"':e))+(t===o-1?"":",")}),c+="]"):r instanceof Object?(c="{",s=Object.keys(r),l=s.length,s.forEach(function(e,t){var n,i,o;"object"==typeof r[e]&&1<a?c+='"'+e+'":'+f(r[e],a-1):c+=(n=r[e=e],o="","string"==(i=typeof n)||"object"==i?o+='"'+e+'":"'+n+'"':"function"==typeof n?o+='"'+e+'":"function '+n.name+'"':"symbol"==typeof n?o+='"'+e+'":"symbol"':"number"!=typeof n&&"boolean"!=i||(o+='"'+e+'": '+n),o),c+=t===l-1||t<l-1&&void 0===r[s[t+1]]?"":","}),c+="}"):c+=r,c}var y,s,c,v,d,B=["ret","retcode","code","errcode"],o=function(){var n=new WeakSet;return function(e,t){if(t instanceof Error)return"Error.message: "+t.message+" \n Error.stack: "+t.stack;if("object"==typeof t&&null!==t){if(n.has(t))return"[Circular "+(e||"root")+"]";n.add(t)}return t}},b=function(e){if("string"==typeof e)return e;try{return e instanceof Error?(JSON.stringify(e,o(),4)||"undefined").replace(/"/gim,""):JSON.stringify(e,o(),4)||"undefined"}catch(e){return"error happen when aegis stringify: \n "+e.message+" \n "+e.stack}};(n=y=y||{}).INFO_ALL="-1",n.API_RESPONSE="1",n.INFO="2",n.ERROR="4",n.PROMISE_ERROR="8",n.AJAX_ERROR="16",n.SCRIPT_ERROR="32",n.IMAGE_ERROR="64",n.CSS_ERROR="128",n.CONSOLE_ERROR="256",n.MEDIA_ERROR="512",n.RET_ERROR="1024",n.REPORT="2048",n.PV="4096",n.EVENT="8192",n.PAGE_NOT_FOUND_ERROR="16384",n.WEBSOCKET_ERROR="32768",n.BRIDGE_ERROR="65536",(n=s=s||{})[n.android=1]="android",n[n.ios=2]="ios",n[n.windows=3]="windows",n[n.macos=4]="macos",n[n.linux=5]="linux",n[n.devtools=6]="devtools",n[n.other=100]="other",(n=c=c||{})[n.unknown=100]="unknown",n[n.wifi=1]="wifi",n[n.net2g=2]="net2g",n[n.net3g=3]="net3g",n[n.net4g=4]="net4g",n[n.net5g=5]="net5g",n[n.net6g=6]="net6g",(n=v=v||{}).LOG="log",n.SPEED="speed",n.PERFORMANCE="performance",n.OFFLINE="offline",n.WHITE_LIST="whiteList",n.VITALS="vitals",n.PV="pv",n.CUSTOM_PV="customPV",n.EVENT="event",n.CUSTOM="custom",n.SDK_ERROR="sdkError",n.SET_DATA="setData",n.LOAD_PACKAGE="loadPackage",(n=d=d||{}).production="production",n.development="development",n.gray="gray",n.pre="pre",n.daily="daily",n.local="local",n.test="test",n.others="others";function O(n,i){var o,r=[],a=n.config;return n.lifeCycle.on("destroy",function(){r.length=0}),function(e,t){Array.isArray(e)?r=r.concat(e):r.push(e),i&&r.length>=i||n.sendNow&&0<r.length?(r=Z(r),t(r.splice(0,r.length)),o&&clearTimeout(o)):(o&&clearTimeout(o),o=setTimeout(function(){o=null,0<(r=Z(r)).length&&t(r.splice(0,r.length))},a.delay))}}function J(e,t){return Array.isArray(e)?t(e.map(function(e){return t=p(p({},e),{msg:"string"==typeof e.msg?e.msg:[].concat(e.msg).map(b).join(" ")}),D.forEach(function(e){t[e]||delete t[e]}),t;var t})):t([p(p({},e),{msg:"string"==typeof e.msg?e.msg:b(e.msg)})])}function V(l,c){return function(e,t){var n,i,o,r=Array.isArray(e),a=r?e:[e],s=(l.lifeCycle.emit("beforeRequest",e),l.config.beforeRequest);(a="function"==typeof s?a.map(function(t){try{var e=s({logs:t,logType:c});return(null==e?void 0:e.logType)===c&&null!=e&&e.logs?e.logs:!1!==e&&t}catch(e){return t}}).filter(function(e){return!1!==e}):a).length&&(n=a,e=D,!Array.isArray(n)||n.length<=1||(i=[],o=[],!(o="string"==typeof e?[e]:e)||o.length<=0||(o.forEach(function(t){n.forEach(function(e){null!=e&&e[t]&&i.push(t)})}),0<i.length&&(n=n.map(function(e){var t={};return i.forEach(function(e){t[e]=""}),p(p({},t),e)})))),a=n,t(r?a:a[0]))}}function W(o){return function(e,t){o.lifeCycle.emit("modifyRequest",e);var n=o.config.modifyRequest;if("function"==typeof n)try{var i=n(e);"object"==typeof i&&"url"in i&&(e=i)}catch(e){console.error(e)}t(e)}}function G(i){return function(e,t){i.lifeCycle.emit("afterRequest",e);var n=i.config.afterRequest;"function"==typeof n&&!1===n(e)||t(e)}}function E(n){if(n&&n.reduce&&n.length)return 1===n.length?function(e,t){n[0](e,t||ie)}:n.reduce(function(n,i){return function(e,t){return void 0===t&&(t=ie),n(e,function(e){return null==i?void 0:i(e,t)})}});throw new TypeError("createPipeline need at least one function param")}function h(t,n){Object.getOwnPropertyNames(t).forEach(function(e){"function"==typeof t[e]&&"constructor"!==e&&(n?n[e]="sendPipeline"===e?function(){return function(){}}:function(){}:t[e]=function(){})})}function i(e){try{var t,n,i,o="";return o=e.pageUrl||(n=(t=getCurrentPages())[t.length-1]||{},r=n.options,i=Object.keys(r).length?"?"+Object.keys(r).map(function(e){return e+"="+r[e]}).join("&"):"",n.route?n.route+i:""),o="function"==typeof e.urlHandler?e.urlHandler():o}catch(e){return""}var r}function K(e,t){if("string"==typeof e&&"string"==typeof t){if(e===t)return 1;for(var n=e.split("."),i=t.split("."),o=Math.max(n.length,i.length),r=0;r<o;r++){var a=~~n[r],s=~~i[r];if(a<s)return;if(s<a)return 1}}}function g(e){return oe=oe||P.getSystemInfoSync().SDKVersion,K(oe,"1.1.1")&&P.canIUse?P.canIUse(e):!!P[e]}function m(e){for(var t,n={unknown:/unknown|none/i,wifi:/wifi/i,net2g:/2g/i,net3g:/3g/i,net4g:/4g/i,net5g:/5g/i,net6g:/6g/i},i=c.unknown,o=0;o<Object.keys(n).length;o++){var r=Object.keys(n)[o];if(null!=(t=n[r])&&t.test(e)){i=c[r];break}}return i}function w(e){var t=e.apiName,n=k[t];n?n.hackCloudReq.addCallback(e):(n=T.cloud[t],k[t]={hackCloudReq:new ue(e),originApi:n}),k[t]}function $(e){var t=e.apiName,n=x[t];n?n.hackReq.addCallback(e):(n=wx[t],x[t]={hackReq:new pe(e),originApi:n}),x[t]}var r,X,z,Q,Y,Z=function(e){return e.filter(function(n,i){return"static"!==n.type||!e.find(function(e,t){return n.url===e.url&&200===n.status&&i<t})})},ee=function(e){e.level===y.INFO_ALL&&(e.level=y.INFO)},te=function(e){return(Array.isArray(e)?e:[e]).map(function(n){return Object.getOwnPropertyNames(n).reduce(function(e,t){return"ctx"!==t&&(e[t]=n[t]),e},{level:y.INFO,msg:""})})},ne=function(i){return function(e){return i.sendPipeline([function(e,n){return n({url:i.config.url||"",data:M(te(e)),method:"post",contentType:"application/json",type:v.LOG,log:e,requestConfig:{timeout:5e3},success:function(){var t=i.config.onReport;"function"==typeof t&&e.forEach(function(e){t(e)}),"function"==typeof n&&n([])},fail:function(e){"403 forbidden"===e&&i.destroy()}})}],v.LOG)(e)}},ie=function(){},n=(Object.defineProperty(j.prototype,"__version__",{get:function(){return console.warn("__version__ has discard, please use version"),"1.36.3"},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"LogType",{get:function(){return console.warn("LogType has discard, please use logType"),y},enumerable:!1,configurable:!0}),j.prototype.init=function(e){this.setConfig(e);for(var t=0;t<j.installedPlugins.length;t++)try{j.installedPlugins[t].patch(this)}catch(e){this.sendSDKError(e)}this.lifeCycle.emit("onInited")},j.prototype.setConfig=function(e){Object.assign(this.config,e);var e=this.config,t=e.id,n=e.uin,i=e.version,o=e.ext1,r=e.ext2,a=e.ext3,s=e.aid,l=e.env,c=void 0===l?"production":l,l=e.pageUrl,e=this.bean.id!==t||this.bean.uin!==n||this.bean.aid!==s;return this.bean.id=t||"",this.bean.uin=n||"",this.bean.version=i||"1.36.3",this.bean.aid=s||"",this.bean.env=function(){switch(c){case d.production:case d.development:case d.gray:case d.pre:case d.daily:case d.local:case d.test:case d.others:return 1;default:return}}()?c:d.others,l&&this.extendBean("from",encodeURIComponent(l)),o&&this.extendBean("ext1",encodeURIComponent(o)),r&&this.extendBean("ext2",encodeURIComponent(r)),a&&this.extendBean("ext3",encodeURIComponent(a)),e&&this.lifeCycle.emit("onConfigChange",this.config),this.config},j.use=function(e){-1===j.installedPlugins.indexOf(e)&&e.aegisPlugin&&j.installedPlugins.push(e)},j.unuse=function(e){e=j.installedPlugins.indexOf(e);-1!==e&&j.installedPlugins.splice(e,1)},j.prototype.info=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={level:y.INFO,msg:e};1===e.length&&e[0].msg&&Object.assign(n,p({},e[0]),{level:y.INFO}),this.normalLogPipeline(n)},j.prototype.infoAll=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={level:y.INFO_ALL,msg:e};1===e.length&&e[0].msg&&Object.assign(n,p({},e[0]),{level:y.INFO_ALL}),this.normalLogPipeline(n)},j.prototype.report=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={level:y.REPORT,msg:e};1===e.length&&e[0].msg&&Object.assign(n,p({},e[0])),this.normalLogPipeline(n)},j.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={level:y.ERROR,msg:e};1===e.length&&e[0].msg&&Object.assign(n,p({},e[0]),{level:y.ERROR}),this.normalLogPipeline(n)},j.prototype.speedLogPipeline=function(e){throw new Error('You need to override "speedLogPipeline" method')},j.prototype.reportPv=function(n){var i,o=this;n&&(console.warn("reportPv is deprecated, please use reportEvent"),i=""+Object.getOwnPropertyNames(this.bean).filter(function(e){return"id"!==e}).map(function(e){return e+"="+o.bean[e]}).join("&"),this.sendPipeline([function(e,t){t({url:o.config.url+"/"+n+"?"+i,addBean:!1,type:v.CUSTOM_PV,fail:function(e){"403 forbidden"===e&&o.destroy()}})}],v.CUSTOM_PV)(null))},j.prototype.reportEvent=function(e){e&&((e="string"==typeof e?{name:e,ext1:this.config.ext1||"",ext2:this.config.ext2||"",ext3:this.config.ext3||""}:e).name?this.eventPipeline(e):console.warn("reportEvent params error"))},j.prototype.reportTime=function(e,t){if("object"==typeof e)return this.reportT(e);"string"==typeof e?"number"==typeof t?t<0||6e4<t?console.warn("reportTime: duration must between 0 and 60000"):this.submitCustomTime(e,t):console.warn("reportTime: second param must be number"):console.warn("reportTime: first param must be a string")},j.prototype.reportT=function(e){var t=e.name,n=e.duration,i=e.ext1,i=void 0===i?"":i,o=e.ext2,o=void 0===o?"":o,r=e.ext3,r=void 0===r?"":r,e=e.from;if("string"==typeof t&&"number"==typeof n&&"string"==typeof i&&"string"==typeof o&&"string"==typeof r){if(!(n<0||6e4<n))return this.submitCustomTime(t,n,i,o,r,void 0===e?"":e);console.warn("reportTime: duration must between 0 and 60000")}else console.warn("reportTime: params error")},j.prototype.time=function(e){"string"==typeof e?this.timeMap[e]?console.warn("Timer "+e+" already exists"):this.timeMap[e]=Date.now():console.warn("time: first param must be a string")},j.prototype.timeEnd=function(e){"string"==typeof e?this.timeMap[e]?(this.submitCustomTime(e,Date.now()-this.timeMap[e]),delete this.timeMap[e]):console.warn("Timer "+e+" does not exist"):console.warn("timeEnd: first param must be a string")},j.prototype.submitCustomTime=function(e,t,n,i,o,r){this.customTimePipeline({name:e,duration:t,ext1:n||this.config.ext1,ext2:i||this.config.ext2,ext3:o||this.config.ext3,from:r||void 0})},j.prototype.extendBean=function(e,t){this.bean[e]=t},j.prototype.sendPipeline=function(e,t){var n,r=this;return E(a([function(e,t){if("number"!=typeof n.config.random&&(console.warn("random must in [0, 1], default is 1."),n.config.random=1),!n.isHidden||!n.isGetSample)if(n.isGetSample)n.isHidden||t(e);else{if(n.isGetSample=!0,Math.random()<n.config.random)return n.isHidden=!1,t(e);n.isHidden=!0}},V(n=this,t)],e,[W(this),function(i,o){r.request(i,function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];r.failRequestCount=0,o({isErr:!1,result:t,logType:null==i?void 0:i.type,logs:null==i?void 0:i.log}),null!=(e=null==i?void 0:i.success)&&e.call.apply(e,a([i],t))},function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];10<=++r.failRequestCount&&r.destroy(),o({isErr:!0,result:t,logType:null==i?void 0:i.type,logs:null==i?void 0:i.log}),null!=(e=null==i?void 0:i.fail)&&e.call.apply(e,a([i],t))})},G(this)]))},j.prototype.send=function(e,o,r){var t=this;return E([W(this),function(n,i){t.request(n,function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];i({isErr:!1,result:e,logType:n.type,logs:n.log}),null!=o&&o.apply(void 0,e)},function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];i({isErr:!0,result:e,logType:n.type,logs:n.log}),null!=r&&r.apply(void 0,e)})},G(this)])(e)},j.prototype.ready=function(e,t,n){throw new Error('You need to override "ready" method')},j.prototype.request=function(e,t,n){throw new Error('You need to override "request" method')},j.prototype.sendSDKError=function(e){var n=this;this.sendPipeline([function(e,t){t({url:n.config.url+"?id=1085&msg[0]="+encodeURIComponent(b(e))+"&level[0]=2&from="+n.config.id+"&count=1&version="+n.config.id+"(1.36.3)",addBean:!1,method:"get",type:v.SDK_ERROR,log:e})}],v.SDK_ERROR)(e)},j.prototype.destroy=function(e){void 0===e&&(e=!1);var t,n,i=j.instances.indexOf(this);-1!==i&&j.instances.splice(i,1);for(var o=j.installedPlugins.length-1;0<=o;o--)try{j.installedPlugins[o].unpatch(this)}catch(e){this.sendSDKError(e)}if(this.lifeCycle.emit("destroy"),this.lifeCycle.clear(),e)t=this,n=Object.getOwnPropertyDescriptors(t),Object.keys(n).forEach(function(e){n[e].writable&&(t[e]=null)}),Object.setPrototypeOf(this,null);else{for(var r=this;r.constructor!==Object&&h(r,this),r=Object.getPrototypeOf(r););0===j.instances.length&&(i=Object.getPrototypeOf(this).constructor,h(i),h(j))}},j.version="1.36.3",j.instances=[],j.logType=y,j.environment=d,j.installedPlugins=[],j),R=(q.prototype.patch=function(e){this.canUse(e)&&this.exist(e)&&(this.instances.push(e),this.triggerInit(e),this.triggerOnNewAegis(e))},q.prototype.unpatch=function(e){e=this.instances.indexOf(e);-1!==e&&(this.instances.splice(e,1),0===this.instances.length&&this.uninstall())},q.prototype.countInstance=function(){return this.instances.length},q.prototype.uninstall=function(){var e;null!=(e=null==(e=this.option)?void 0:e.destroy)&&e.apply(this)},q.prototype.walk=function(n){var i=this;this.instances.forEach(function(e){var t=i.canUse(e);t&&n(e,t)})},q.prototype.canUse=function(e){e=this.getConfig(e);return!(!e||"object"!=typeof e)||!!e},q.prototype.getConfig=function(e){return null==(e=e.config)?void 0:e[this.name]},q.prototype.exist=function(e){return-1===this.instances.indexOf(e)},q.prototype.triggerInit=function(e){var t;this.inited||(this.inited=!0,null!=(t=null==(t=this.option)?void 0:t.init)&&t.call(this.option,this.getConfig(e)))},q.prototype.triggerOnNewAegis=function(e){var t;null!=(t=null==(t=this.option)?void 0:t.onNewAegis)&&t.call(this.option,e,this.getConfig(e))},q),P=wx||qq,oe="",re=new R({name:"offlineLog",onNewAegis:function(o){if(P.getFileSystemManager)try{var e=o.config,t=e.id,r=void 0===t?"":t,n=e.uin,a=void 0===n?0:n,i=e.offlineUrl,s=void 0===i?"":i,l=e.offlineLogLimit,c=new ae({limit:l});o.lifeCycle.on("beforeWrite",function(e){c.save2Offline(e=void 0===e?[]:e,o.config)}),c.ready(function(t){var e=(o.bean||{}).aid,i=void 0===e?"":e;!t&&r&&(a||i)&&o.send({url:s+"/offlineAuto",type:v.OFFLINE,log:v.OFFLINE},function(e){var n=(null==e?void 0:e.data).secretKey;n&&!t&&c.getLogs({id:r,uin:a},function(e,t){e?console.error(e):o.send({url:s+"/offlineLog",data:{logs:t,secretKey:n,id:r,uin:a,aid:i},method:"post",type:v.OFFLINE,log:t},function(){c.clearLogs()})})})})}catch(o){console.error(o)}else console.warn("[aegis-mp-sdk]unsupport getFileSystemManager offline log not work!")}}),ae=(we.prototype.getLogs=function(e,t){var n=this.fileSystem,i=this.filePath;n.readFile({filePath:i,encoding:"utf8",fail:function(e){console.error(e)},success:function(e){e=e.data,e=(void 0===e?"":e).toString().split("\n").filter(function(e){return e}).map(function(e){return JSON.parse(e)});t(null,e)}})},we.prototype.checkLimit=function(o,r){void 0===r&&(r=function(){});var a=this.fileSystem,s=this.filePath,l=this.limitSize;a.readFile({filePath:s,encoding:"utf8",success:function(e){e=e.data,e=void 0===e?"":e;if((e=e.toString()+o).length>l){for(var t=e.split("\n"),n="",i=t.length-1;0<=i&&!(t[i]&&(n=t[i]+"\n"+n).length>l);i--);a.writeFile({filePath:s,data:n,success:r})}else a.appendFile({data:o,filePath:s,encoding:"utf8",success:r,fail:function(e){console.error(e)}})}})},we),se=new R({name:"device",onNewAegis:function(t){return e=this,l=function(){return I(this,function(e){return this.setSystemInfo(t),this.refreshNetwork(t),this.setNetworkChange(t),[2]})},new(s=(s=a=void 0)||Promise)(function(n,t){function i(e){try{r(l.next(e))}catch(e){t(e)}}function o(e){try{r(l.throw(e))}catch(e){t(e)}}function r(e){var t;e.done?n(e.value):((t=e.value)instanceof s?t:new s(function(e){e(t)})).then(i,o)}r((l=l.apply(e,a||[])).next())});var e,a,s,l},setSystemInfo:function(a){var s=this;try{g("getSystemInfo")&&P.getSystemInfo({success:function(e){var t=e.platform,n=e.model,i=e.windowHeight,o=e.windowWidth,r=e.screenWidth,r=void 0===r?0:r,e=e.screenHeight,e=void 0===e?0:e;a.extendBean("platform",s.getPlatFormType(t)),a.extendBean("model",n),a.extendBean("vp",Math.round(o)+" * "+Math.round(i)),a.extendBean("sr",Math.round(r)+" * "+Math.round(e))}})}catch(a){}},getPlatFormType:function(e){for(var t,n={android:/android/i,ios:/ios/i,windows:/windows/i,macos:/mac/i,devtools:/devtools/i},i=s.other,o=0;o<Object.keys(n).length;o++){var r=Object.keys(n)[o];if(null!=(t=n[r])&&t.test(e)){i=s[r];break}}return i},setNetworkChange:function(t){g("onNetworkStatusChange")&&P.onNetworkStatusChange(function(e){e=m(e.networkType);t.extendBean("netType",e)})},setNetworkType:function(t){g("getNetworkType")&&P.getNetworkType({success:function(e){e=m(e.networkType);t.extendBean("netType",e)}})},refreshNetwork:function(e){var t=this;this.timer&&clearTimeout(this.timer),this.setNetworkType(e),this.timer=setTimeout(function(){t.refreshNetwork(e)},1e4)}}),le=P.request,n=(e(U,Y=n),Object.defineProperty(U.prototype,"getBean",{get:function(){var t=this;return this.bean?Object.getOwnPropertyNames(this.bean).map(function(e){return e+"="+t.bean[e]}).join("&")+"&from="+encodeURIComponent(i(this.config)):"from="+encodeURIComponent(i(this.config))},enumerable:!1,configurable:!0}),U.prototype.initOfflineLog=function(){U.use(re)},U.prototype.uploadLogs=function(e,t){this.lifeCycle.emit("uploadLogs",e=void 0===e?{}:e,t=void 0===t?{}:t)},U.prototype.reportPv=function(e){var t,n=this;e&&(t=Object.getOwnPropertyNames(this.bean).filter(function(e){return"id"!==e}).map(function(e){return e+"="+n.bean[e]}).join("&")+"&from="+encodeURIComponent(i(this.config)),this.send({url:this.config.url+"/"+e+"?"+t,addBean:!1,type:v.CUSTOM_PV,log:v.CUSTOM_PV},function(){},function(){}))},U.sessionID="session-"+Date.now(),U.asyncPluginIndex=0,U),ce=new R({name:"aid",onNewAegis:function(t){this.initAid(function(e){t.bean.aid=e,t.config.aid=e})},initAid:function(t){P.getStorage({key:"AEGIS_ID",success:function(e){t(e.data)},fail:function(){var e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)});P.setStorage({key:"AEGIS_ID",data:e,success:function(){t(e)}})}})}}),S=(A.prototype.addCallback=function(e){e&&this.callbacks.push(e)},A.prototype.prefixHandler=function(e){return p(p({},e),{aegisRequestStartTime:+new Date})},A.prototype.successHandler=function(n,i){var e;this.callbacks.forEach(function(e){var t;try{null!=(t=e.success)&&t.call(e,n,i)}catch(e){}}),null!=(e=i.success)&&e.call(i,n,i)},A.prototype.failHandler=function(n,i){var e;this.callbacks.forEach(function(e){var t;try{null!=(t=e.fail)&&t.call(e,n,i)}catch(e){}}),null!=(e=i.fail)&&e.call(i,n,i)},A.prototype.completeHandler=function(n,i){var e;this.callbacks.forEach(function(e){var t;try{null!=(t=e.complete)&&t.call(e,n,i)}catch(e){}}),null!=(e=i.complete)&&e.call(i,n,i)},A.prototype.override=function(){try{this.defineApiProperty()}catch(e){console.warn("cannot override `"+this.apiName+"`, error is: "+e)}finally{this.isOverride=!0}},A),T=wx||qq,k={},ue=(e(L,Q=S),L.prototype.defineApiProperty=function(){var e=this;T.cloud&&T.cloud[this.apiName]&&Object.defineProperty(T.cloud,this.apiName,{get:function(){return e.hackHandler.bind(e)}})},L.prototype.hackHandler=function(e){var i=this,o=this.prefixHandler(e);return new Promise(function(t,n){var e=null==(e=k[i.apiName])?void 0:e.originApi;null!=e&&e(p(p({},o),{success:function(e){i.successHandler(e,o),t(e)},fail:function(e){i.failHandler(e,o),n(e)},complete:function(e){i.completeHandler(e,o)}}))})},L),fe=wx||qq,x={},pe=(e(N,z=S),N.prototype.defineApiProperty=function(){var e=this;Object.defineProperty(fe,this.apiName,{get:function(){return e.hackHandler.bind(e)}})},N.prototype.hackHandler=function(e){var t=this,n=this.prefixHandler(e),e=null==(e=x[this.apiName])?void 0:e.originApi;return null==e?void 0:e(p(p({},n),{success:function(e){t.successHandler(e,n)},fail:function(e){t.failHandler(e,n)},complete:function(e){t.completeHandler(e,n)}}))},N),de=new R({name:"reportApiSpeed",override:!1,onNewAegis:function(e){this.override||(this.override=!0,this.hackRequest(e.config),this.overrideCallFunction(e.config),this.overrideCallContainer(e.config))},hackRequest:function(a){var s=this;$({apiName:"request",success:function(e,t){var n,i,o,r;a.hostUrl&&-1<t.url.indexOf(a.hostUrl)||(n={method:t.method||"get",url:l(t.url),duration:Date.now()-t.aegisRequestStartTime,status:e.statusCode||0,nextHopProtocol:"",isHttps:H(t.url),type:"fetch"},i=null==(i=a.api)?void 0:i.apiDetail,o=(r=u(e.data,a.api,{url:t.url,ctx:e})||{}).code,r=r.isErr,t="req url: "+n.url+" \n \nreq method: "+n.method+" \n \nreq param: "+(i?b(t.data):"")+" \n \nres duration: "+n.duration+"ms \n \nres status: "+(e.statusCode||0)+" \n \nres retcode: "+o+" \n \nres data: "+(i?f(e.data):""),s.publishNormalLog({msg:t,level:y.API_RESPONSE,ctx:e}),n.ret=o,n.isErr=+r,s.publishSpeedLog(n),r&&s.publishNormalLog({msg:t,level:y.RET_ERROR,ctx:e}))},fail:function(e,t){a.hostUrl&&-1<t.url.indexOf(a.hostUrl)||(t={method:t.method||"get",url:l(t.url),duration:Date.now()-t.aegisRequestStartTime,status:0,nextHopProtocol:"",isHttps:H(t.url),type:"fetch"},s.publishSpeedLog(t))}})},overrideCallFunction:function(n){var i=this;w({apiName:"callFunction",success:function(e,t){i.cloudSuccessCallback(n,t,e,"callFunction")},fail:function(e,t){t={method:"call",url:"wx.cloud.callFunction."+t.name,duration:Date.now()-t.aegisRequestStartTime,status:0,nextHopProtocol:"",type:"fetch",errMsg:e.errMsg,isHttps:!0};i.publishSpeedLog(t)}})},overrideCallContainer:function(n){var i=this;w({apiName:"callContainer",success:function(e,t){i.cloudSuccessCallback(n,t,e,"callContainer")},fail:function(e,t){t={method:"call",url:"wx.cloud.callContainer."+t.path,duration:Date.now()-t.aegisRequestStartTime,status:0,nextHopProtocol:"",type:"fetch",errMsg:e.errMsg,isHttps:!0};i.publishSpeedLog(t)}})},cloudSuccessCallback:function(e,n,t,i){var o="callFunction"===i?n.name:n.path,r="callFunction"===i?t.result:t.data,o={method:"call",url:"wx.cloud."+i+"."+o,duration:Date.now()-n.aegisRequestStartTime,status:200,nextHopProtocol:"",type:"fetch",isHttps:!0},a=["apiName","aegisRequestStartTime","config","success","fail","complete"],s=Object.keys(n).reduce(function(e,t){return a.includes(t)||(e[t]=n[t]),e},{}),i="callFunction"===i?(null==(i=t.data)?void 0:i.code)||0:t.statusCode,l=u(r,e.api,{url:o.url,ctx:t})||{},c=l.code,l=l.isErr,l=void 0!==l&&l,e=(o.ret=c,o.isErr=+l,null==(c=e.api)?void 0:c.apiDetail),c="req url: "+o.url+"\n \nreq type: "+o.type+"\n \nreq params: "+(e?f(s):"")+"\n \nres status: "+i+"\n \nres retcode: "+o.ret+"\n \nres duration: "+o.duration+"ms \n \nres data: "+(e?f(r):"")+"\n ";this.publishNormalLog({msg:c,level:y.API_RESPONSE,ctx:t}),this.publishSpeedLog(o),l&&this.publishNormalLog({msg:c,level:y.RET_ERROR,ctx:t})},publishSpeedLog:function(t){this.$walk(function(e){e.speedLogPipeline(t)})},publishNormalLog:function(t){this.$walk(function(e){e.normalLogPipeline(t)})}}),he=wx||qq,ge=he.connectSocket,me=(Ee.prototype.addConfig=function(e){var t=e.send,e=e.onError;t&&this.sends.push(t),e&&this.onErrors.push(e)},Ee.prototype.toHack=function(t){var o=this,n=(this.onErrors.forEach(function(e){t.onError(e)}),t.send);return Object.defineProperty(t,"send",{get:function(){return function(i){return new Promise(function(e){n.call(t,p(p({},i),{fail:function(n){o.sends.forEach(function(e){var t;null!=(t=e.fail)&&t.call(e,n,i)}),e(n)}}))})}}}),t},Ee),ye=(e(C,X=S),C.prototype.addTaskConf=function(e){this.taskHack.addConfig(e)},C.prototype.defineApiProperty=function(){var e=this;Object.defineProperty(he,"connectSocket",{get:function(){return e.hackHandler.bind(e)}})},C.prototype.hackHandler=function(e){var t=this,n=this.prefixHandler(e),e=ge(p(p({},n),{success:function(e){t.successHandler(e,n)},fail:function(e){t.failHandler(e,n)},complete:function(e){t.completeHandler(e,n)}}));return this.taskHack.toHack(e),e},C),S=new R({name:"onError",onNewAegis:function(e){var t=P.getSystemInfoSync().SDKVersion;this.listenError(),this.hackNetWork(e),this.hackCloud(e),e.config.websocketHack&&K(t,"1.7.0")&&this.hackWsConnect()},listenError:function(){var t=this;"function"==typeof P.onError&&P.onError(function(e){e&&t.publishErrorLog({msg:e,level:y.ERROR})}),g("onUnhandledRejection")&&P.onUnhandledRejection(function(e){e=e.reason;!e||-1<JSON.stringify(e).indexOf("request:fail")||t.publishErrorLog({msg:e,level:y.PROMISE_ERROR})}),g("onPageNotFound")&&P.onPageNotFound(function(e){e&&t.publishErrorLog({msg:e,level:y.PAGE_NOT_FOUND_ERROR})})},publishErrorLog:function(t){this.$walk(function(e){e.normalLogPipeline(t)})},hackNetWork:function(e){for(var n=this,i=e.config,t=0,o=[{apiName:"request",complete:function(e,t){return n.requestCompleteError(e,t,i)}},{apiName:"uploadFile",complete:function(e,t){return n.uploadFileCompleteError(e,t,i)}},{apiName:"downloadFile",complete:function(e,t){return n.downloadFileCompleteError(e,t,i)}}];t<o.length;t++){var r=o[t],a=r.apiName,r=r.complete;$({apiName:a,complete:r})}},requestCompleteError:function(e,t,n){var i,o=e.errMsg,r=e.statusCode;n.hostUrl&&-1<(null==(i=t.url)?void 0:i.indexOf(n.hostUrl))||(i=this.getErrorType({errMsg:o,statusCode:r}))&&this.publishNetWorkError({apiName:"request",opts:t,res:e,config:n,type:i})},downloadFileCompleteError:function(e,t,n){var i=e.errMsg,o=e.statusCode,r=e.filePath,e=e.tempFilePath,a=this.getErrorType({errMsg:i,statusCode:o});a&&(n=null==(n=n.api)?void 0:n.apiDetail,this.publishErrorLog({msg:"AJAX_ERROR: downloadFile "+a+"\n \nres status: "+(o||0)+"\n \nres duration: "+(Date.now()-t.aegisRequestStartTime)+"ms\n \nres filePath: "+r+"\n \nres tempFilePath: "+e+"\n \nreq url: "+t.url+"\n \nreq method: "+(t.method||"get")+"\n \nreq param: "+(n?b(t.data):"")+"\n \nerrMsg: "+i.slice(0,1e3),level:y.AJAX_ERROR}))},uploadFileCompleteError:function(e,t,n){var i=e.errMsg,o=e.statusCode,i=this.getErrorType({errMsg:i,statusCode:o});i&&this.publishNetWorkError({apiName:"uploadFile",opts:t,res:e,config:n,type:i})},hackCloud:function(e){for(var n=this,i=e.config,t=0,o=[{apiName:"callFunction",complete:function(e,t){return n.callFunctionCompleteError(e,t,i)}},{apiName:"callContainer",complete:function(e,t){return n.callContainerCompleteError(e,t,i)}}];t<o.length;t++){var r=o[t],a=r.apiName,r=r.complete;w({apiName:a,complete:r})}},callFunctionCompleteError:function(e,t,n){(-1<e.errMsg.indexOf("fail")||-1<e.errMsg.indexOf("timeout"))&&(n=null==(n=n.api)?void 0:n.apiDetail,this.publishErrorLog({msg:"AJAX_ERROR: cloud.callFunction:fail\n \nres status: 0\n \nres duration: "+(Date.now()-t.aegisRequestStartTime)+"ms\n \nres data: "+(n?b(e):"")+"\n \nreq url: cloud.callFunction."+t.name+"\n \nreq method: POST\n \nreq param: "+(n?b(t.data):"")+"\n \nerrMsg: "+e.errMsg.slice(0,1e3),level:y.AJAX_ERROR}))},callContainerCompleteError:function(e,t,n){var i=e.errMsg,o=e.statusCode;(400<=o||-1<i.indexOf("fail")||-1<i.indexOf("timeout"))&&(n=null==(n=n.api)?void 0:n.apiDetail,this.publishErrorLog({msg:"AJAX_ERROR: cloud.callContainer:fail\n \nres status: "+(o||0)+"\n \nres duration: "+(Date.now()-t.aegisRequestStartTime)+"ms\n \nres data: "+(n?b(e):"")+"\n \nreq url: "+t.path+"\n \nreq method: "+(t.method||"POST")+"\n \nreq param: "+(n?b(t.data):"")+"\n \nerrMsg: "+i.slice(0,1e3),level:y.AJAX_ERROR}))},publishNetWorkError:function(e){var t=e.apiName,n=e.opts,i=e.res,o=e.config,e=e.type,r=i.errMsg,a=i.statusCode,s=i.data,l=null==(l=o.api)?void 0:l.apiDetail,c="wx.cloud.callFunction."+n.url,o=u(s,o.api,{url:c,ctx:i}).code;this.publishErrorLog({msg:"AJAX_ERROR: "+t+" "+e+"\n \nres status: "+(a||0)+"\n \nres retcode: "+o+"\n \nres duration: "+(Date.now()-n.aegisRequestStartTime)+"ms\n \nres data: "+(l?b(s):"")+"\n \nreq url: "+n.url+"\n \nreq method: "+(n.method||"get")+"\n \nreq param: "+(l?b(n.data):"")+"\n \nerrMsg: "+r.slice(0,1e3),level:y.AJAX_ERROR})},getErrorType:function(e){var t=e.errMsg,e=e.statusCode,n="";return-1<t.indexOf("timeout")||-1<t.indexOf("超时")?n="timeout":400<=e?n="error":(-1<t.indexOf("fail")||!e||e<0)&&(n="failed"),n},hackWsConnect:function(){var e,t,n=this;$({apiName:"sendSocketMessage",fail:function(e){n.publishSocketError(e)}}),e=(t={connectCallback:{fail:function(e){n.publishSocketError(e)}},taskOpt:{onError:function(e){n.publishSocketError(e)},send:{fail:function(e){n.publishSocketError(e)}}}}).connectCallback,t=t.taskOpt,r?r.addCallback(e):r=new ye(e),t&&r.addTaskConf(t)},publishSocketError:function(e){e&&this.publishErrorLog({msg:e.errMsg,level:y.WEBSOCKET_ERROR})}}),ve=new R({name:"reportAssetSpeed",isStart:!1,onNewAegis:function(e){this.isStart||(this.isStart=!0,this.start(e))},start:function(){var t=this;P.getPerformance&&P.getPerformance().createObserver(function(e){e=e.getEntries();null!=e&&e.forEach(function(e){"number"!=typeof e.duration||e.duration<=0||t.publishAssetLog(e)})}).observe({entryTypes:["resource"]})},generateLog:function(e){return{url:""+l(e.uri),method:"get",duration:Math.round(100*e.duration)/100,status:200,type:"static",isHttps:!0,urlQuery:"",nextHopProtocol:"",domainLookup:0,connectTime:0}},publishAssetLog:function(t){var n=this;this.$walk(function(e){e.speedLogPipeline(n.generateLog(t))})}}),be=["onLaunch","onHide","onError","onLoad","onReady","onShow","onUnload"],Oe=new R({name:"pagePerformance",pageNavigationStartTime:{},onNewAegis:function(e){try{g("getPerformance")&&this.reportPerformance(e),this.setPagePV(e),this.reportSetDataTiming(e)}catch(e){}},reportPerformance:function(c){var u=this,e=P.getPerformance(),e=null==e?void 0:e.createObserver(function(e){var t={},n=null==(n=e.getEntriesByName("appLaunch"))?void 0:n[0],i=null==(i=e.getEntriesByName("firstRender"))?void 0:i[0],o=null==(o=e.getEntriesByName("evaluateScript"))?void 0:o[0],r=null==(r=e.getEntriesByName("route"))?void 0:r[0],a=null==(a=null==(a=e.getEntriesByName("firstPaint"))?void 0:a[0])?void 0:a.startTime,s=null==(s=(null==(s=e.getEntriesByName("firstPaint"))?void 0:s[0])||(null==(s=e.getEntriesByName("route"))?void 0:s[0])||(null==(s=e.getEntriesByName("appLaunch"))?void 0:s[0]))?void 0:s.pageId,l=null==(e=(null==(l=e.getEntriesByName("route"))?void 0:l[0])||(null==(l=e.getEntriesByName("appLaunch"))?void 0:l[0]))?void 0:e.startTime;s&&(u.pageNavigationStartTime[s]=null,l&&(u.pageNavigationStartTime[s]=l)),n&&(t.appLaunch=n.duration),i&&(t.firstScreenTiming=i.duration),o&&(t.scriptEvaluateTiming=o.duration),r&&(t.pageRouteTiming=r.duration),a&&l?t.firstPaintTiming=Math.max(a-l,0):a&&u.pageNavigationStartTime[s]&&(t.firstPaintTiming=Math.max(a-u.pageNavigationStartTime[s],0)),u.publish(t,c)});null!=e&&e.observe({entryTypes:["navigation","render","script"]})},publish:function(t,n){var e,i,o,r=[],a=n.config,s=-1===(null==(e=n.config.performanceUrl)?void 0:e.indexOf("?"))?"?":"&";for(i in t)r.push(i+"="+t[i]);"function"==typeof a.urlHandler?(o=a.urlHandler()||window.location.href,this.$walk(function(e){e.send({url:n.config.performanceUrl+s+r.join("&")+"&from="+encodeURIComponent(o),beanFilter:["from"],type:v.PERFORMANCE,log:t})})):this.$walk(function(e){e.send({url:n.config.performanceUrl+s+r.join("&"),type:v.PERFORMANCE,log:t})})},setPagePV:function(e){var t=this;P.onAppRoute&&P.onAppRoute(function(e){"appLaunch"!==e.openType&&(t.$walk(function(e){e.send({url:""+e.config.pvUrl,type:v.PV})}),t.reportPageLoaded(e))})},reportPageLoaded:function(e){e="infoType: behaviorBacktracking\ndataType: pageLoadAndRoute\npageLoadedPath: "+e.path+"\nopenType: "+e.openType;this.publishNormalLog({msg:e,level:y.INFO})},publishNormalLog:function(t){this.$walk(function(e){e.normalLogPipeline(t)})},reportSetDataTiming:function(t){var e,o,r,a,n,s,l,c,u,f=this,i=t.config,i=i.setDataReportConfig||(null==(i=i.pagePerformance)?void 0:i.setDataReportConfig)||{};!0!==i.disabled&&(e=i.timeThreshold,o=!1!==i.withDataPaths,r=e&&0<+e?+e:30,a=E([O(t,10),function(e){e=e.map(function(e){return{type:v.SET_DATA,component:e.from,duration:e.duration,fields:e.dataPaths&&e.dataPaths.length?e.dataPaths.sort().join(";"):void 0,size:e.size}});t.send({url:t.config.setDataReportUrl+"?payload="+encodeURIComponent(JSON.stringify({miniProgramData:e})),type:v.SET_DATA,log:e})}]),n=Page,s=Component,l=function(r,e){var a=0;return null!=r&&r.data?(e.forEach(function(e){for(var t=r.data[e[0]],n=1,i=e.length;n<i;n++)t[e[n]]&&(t=t[e[n]]);var o="";try{o=JSON.stringify(t)}catch(e){o=""}a+=2*(void 0===o?"":o).replace(/[\u4e00-\u9fa5]/g,"aa").length}),a=Math.min(a,10485760)):a},c=function(e,t){var n=t.updateStartTimestamp,i=t.updateEndTimestamp,t=t.dataPaths,t=void 0===t?[]:t,i=i-n;isNaN(i)||i<r||(n={from:e.is,duration:i},o&&0<t.length&&Object.assign(n,{dataPaths:t.slice(0,30),size:l(e,t)}),a(n))},u=function(i){var e="infoType: behaviorBacktracking\ndataType: tapEvent"+Object.keys(i[0]).reduce(function(e,t){var n="";try{n=t+": "+JSON.stringify(i[0][t])}catch(e){n=""}return e+"\n"+n},"");f.publishNormalLog({msg:e,level:y.INFO})},Page=function(t){var e=t.onReady;return t.onReady=function(){var t=this;return"function"==typeof this.setUpdatePerformanceListener&&this.setUpdatePerformanceListener({withDataPaths:o},function(e){c(t,e)}),null==e?void 0:e.call(this)},Object.keys(t).forEach(function(e){var n;"function"!=typeof t[e]||be.includes(e)||(n=t[e],t[e]=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return null!=e&&e[0]&&"tap"===e[0].type&&u(e),null==n?void 0:n.apply(this,e)})}),n(t)},Component=function(e){e.lifetimes&&e.lifetimes.attached?(n=e.lifetimes.attached,e.lifetimes.attached=function(){var t=this;return"function"==typeof this.setUpdatePerformanceListener&&this.setUpdatePerformanceListener({withDataPaths:o},function(e){c(t,e)}),null==n?void 0:n.call(this)}):(i=e.attached,e.attached=function(){var t=this;return"function"==typeof this.setUpdatePerformanceListener&&this.setUpdatePerformanceListener({withDataPaths:o},function(e){c(t,e)}),null==i?void 0:i.call(this)});var n,i,t=e.methods;return t&&"[object Object]"===Object.prototype.toString.call(t)&&Object.keys(t).forEach(function(e){var n;"function"==typeof t[e]&&(n=t[e],t[e]=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return null!=e&&e[0]&&"tap"===e[0].type&&u(e),null==n?void 0:n.apply(this,e)})}),s(e)})}}),R=new R({name:"reportLoadPackageSpeed",isLoaded:!1,onNewAegis:function(e){this.isLoaded||(this.isLoaded=!0,this.start(e))},start:function(){var t=this;P.getPerformance&&P.getPerformance().createObserver(function(e){e=e.getEntries();null!=e&&e.forEach(function(e){"number"!=typeof e.duration||e.duration<=0||t.publishPackageLog(e)})}).observe({entryTypes:["loadPackage"]})},generateLog:function(e){return[{type:v.LOAD_PACKAGE,packageName:e.packageName,size:Math.round(100*e.packageSize)/100,duration:Math.round(100*e.duration)/100}]},publishPackageLog:function(n){var i=this;this.$walk(function(e){var t=i.generateLog(n);e.send({url:e.config.setDataReportUrl+"?payload="+encodeURIComponent(JSON.stringify({miniProgramData:t})),type:v.LOAD_PACKAGE,log:t})})}});function C(e){e=X.call(this,e)||this;return e.taskHack=new me,e}function Ee(){this.onErrors=[],this.sends=[]}function N(){return null!==z&&z.apply(this,arguments)||this}function L(){return null!==Q&&Q.apply(this,arguments)||this}function A(e){this.callbacks=[],this.isOverride=!1;var t=e.apiName;this.apiName=t,this.isOverride||this.override(),this.callbacks.push(e)}function U(e){var i,o,r,f=Y.call(this,e)||this;f.originRequest=le,f.speedLogPipeline=E([(o=f.config,r={},function(e,t){var n,i;o.speedSample?(i="object"==typeof o.repeat?o.repeat:{repeat:o.repeat},n=+i.speed||+i.repeat||5,Array.isArray(e)?(i=e.filter(function(e){var t=!r[e.url]||r[e.url]<n;return r[e.url]=1+~~r[e.url],t})).length&&t(i):(!r[e.url]||r[e.url]<n)&&(r[e.url]=1+~~r[e.url],t(e))):t(e)}),O(f),function(t,n){g("getNetworkType")?P.getNetworkType({success:function(e){e=m(e.networkType);i.extendBean("netType",e),n(t)}}):n(t)},function(e,t){f.lifeCycle.emit("beforeReportSpeed",e);var n=f.config.beforeReportSpeed;if((e="function"==typeof n?e.filter(function(e){return!1!==n(e)}):e).length)return t(e)},V(i=f,v.SPEED),function(e){var t,n,i,o;f.send({url:""+f.config.speedUrl,method:"post",data:(e=e,t=f.bean,i={fetch:[],static:[],bridge:[]},o={},Array.isArray(e)?e.forEach(function(e){var t;null!=(t=i[e.type])&&t.push(e)}):null!=(n=i[e.type])&&n.push(e),o.payload=JSON.stringify(p({duration:i},t)),o)})}]),f.requestQueue=[],f.requesting=!1,f.request=function(e,t,n){if(e.url&&f.bean.id){var i,o,r,a,s;if(/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/.test(String(f.bean.aid))&&!(f.requesting||g("getNetworkType")&&void 0===f.bean.netType))return f.requesting=!0,i=e.url,f.config.whiteListUrl===i&&(o=t,t=function(e){null!=o&&o(JSON.stringify(e.data))}),!1!==e.addBean&&(i=i+(-1===i.indexOf("?")?"?":"&")+f.getBean),l=e.method||"get",r=function(){f.requesting=!1;var e=f.requestQueue.shift();e&&f.request(e.options,e.success,e.fail)},a=e,(a=(s=f.config.onBeforeRequest)?s(e,f):a)&&a.url?(s=f.config.enableHttp2||!1,"get"===l?(l=i,c=a.data,i="string"!=typeof l?"":"object"==typeof c&&c?(u=Object.getOwnPropertyNames(c).map(function(e){var t=c[e];return e+"="+("string"==typeof t?encodeURIComponent(t):encodeURIComponent(JSON.stringify(t)))}).join("&").replace(/eval/gi,"evaI"),l+(-1===l.indexOf("?")?"?":"&")+u):l,f.originRequest(p({url:i,enableHttp2:s,success:t,fail:n,complete:r},e.requestConfig))):("string"==typeof a.data&&(a.data=a.data.replace(/eval/gi,"evaI")),f.originRequest(p({url:i,enableHttp2:s,header:a.contentType?{"content-type":a.contentType}:void 0,method:"POST",data:a.data,success:t,fail:n,complete:r},e.requestConfig))),!0):(u="",a&&a.url||(u="Sending request blocked. Please handle the parameters reasonably, options.url is necessary",console.log(u)),null!=n&&n(u),r(),!1);f.requestQueue.push({options:e,success:t,fail:n})}var l,c,u};try{e.offlineLog&&f.initOfflineLog(),f.init(e),f.extendBean("sessionId",U.sessionID),f.extendBean("referer",(g("getLaunchOptionsSync")?P.getLaunchOptionsSync():{scene:""}).scene||"")}catch(e){console.warn(e),console.log("%cThe above error occurred in the process of initializing Aegis, which will affect your normal use of Aegis.\nIt is recommended that you contact us for feedback and thank you for your support.","color: red"),f.sendSDKError(e)}return f}function we(e){var o,r,a=this,e=void 0===e?{}:e,t=e.path,t=void 0===t?"/.aegis.offline.log":t,e=e.limit,e=void 0===e?2e4:e;this.offlineBuffer=[],this.insertLog=(o=null,r=[],function(e){r=r.concat(e),o=o||setTimeout(function(){o=null;var e,t=a.fileSystem,n=a.filePath,i=r.map(function(e){return JSON.stringify(e)}).join("\n")+"\n";i&&(e=function(e){e?a.checkLimit(i,function(){r=[]}):t.writeFile({data:i,filePath:n,encoding:"utf8",fail:function(e){console.error(e)},success:function(){r=[]}})},t.access({path:n,success:function(){e(!0)},fail:function(){e()}}))},2e3)}),this.ready=function(e){a.fileSystem?setTimeout(function(){e(null)},0):(e(new Error("getFileSystemManager file")),a.offlineLog=!1)},this.clearLogs=function(){var e=a.fileSystem,t=a.filePath;e.writeFile({filePath:t,data:"",fail:function(){e.unlinkSync(t)}})},this.save2Offline=function(e,t){e=(e=Array.isArray(e)?e:[e]).map(function(e){return"string"==typeof e&&(e={msg:e}),function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(0===e.length)throw new TypeError("Cannot convert undefined or null to object");for(var n=Object(e[0]),i=1;i<e.length;i++){var o=e[i];if(null!==o)for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&(n[r]=o[r])}return n}({id:t.id,uin:t.uin,time:+Date.now(),version:t.version,from:i(t)},e)});a.fileSystem?a.insertLog(e):(a.fileSystem||a.offlineBuffer.length||a.ready(function(e){e?console.error(e):a.offlineBuffer.length&&(a.addLogs(a.offlineBuffer),a.offlineBuffer=[])}),a.offlineBuffer=a.offlineBuffer.concat(e))},this.addLogs=function(e){a.fileSystem&&a.insertLog(e)},this.filePath=P.env.USER_DATA_PATH+t,this.fileSystem=P.getFileSystemManager(),this.limitSize=e}function q(e){this.aegisPlugin=!0,this.name="",this.instances=[],this.inited=!1,e.$walk=this.walk.bind(this),e.$getConfig=this.getConfig.bind(this),this.option=e,this.name=e.name}function j(e){var n,t,i,o,a,r,s,l,c,u,f,p,d,h,g,m=this;this.isGetSample=!1,this.isHidden=!1,this.config={version:0,delay:1e3,onError:!0,repeat:5,random:1,aid:!0,device:!0,pagePerformance:!0,webVitals:!0,speedSample:!0,onClose:!0,hostUrl:"https://aegis.qq.com",websocketHack:!1,env:"production",url:"",offlineUrl:"",whiteListUrl:"",pvUrl:"",speedUrl:"",customTimeUrl:"",performanceUrl:"",webVitalsUrl:"",eventUrl:"",setDataReportUrl:"",reportImmediately:!0},this.isWhiteList=!1,this.lifeCycle=new F,this.bean={},this.normalLogPipeline=E([O(this,5),J,function(e,t){var i=n.config;t(e=e.map(function(e){var t,n=i.maxLength||204800;try{if(!e.msg||e.msg.length<=n)return e;e.msg=null==(t=e.msg)?void 0:t.substring(0,n)}catch(t){e.msg=b(e.msg).substring(0,i.maxLength)}return e}))},(h=(n=this).config,g={},function(e,t){var n="number"==typeof h.repeat?h.repeat:5;if(0===n)return t(e);t(e.filter(function(e){return e.level!==y.ERROR&&e.level!==y.PROMISE_ERROR&&e.level!==y.AJAX_ERROR&&e.level!==y.SCRIPT_ERROR&&e.level!==y.IMAGE_ERROR&&e.level!==y.CSS_ERROR&&e.level!==y.MEDIA_ERROR||(g[e.msg]=g[e.msg]||0,g[e.msg]+=1,!(g[e.msg]>n))}))}),(p=this.lifeCycle.emit,d=this.config,function(e,t){var n,i=d.logCreated;return"function"==typeof i?(n=e.filter(function(e){return!1!==i(e)}),p("beforeWrite",n),t(n)):(p("beforeWrite",e),t(e))}),(f=this,setTimeout(function(){var e=f.config.pvUrl,n=void 0===e?"":e;n&&f.sendPipeline([function(e,t){t({url:n,type:v.PV,fail:function(e){"403 forbidden"===e&&f.destroy()}})}],v.PV)(null)},100),function(e,t){t(e)}),(c=l=s=!1,u=[],(a=this).lifeCycle.on("onConfigChange",function(){r&&clearTimeout(r),r=setTimeout(function(){var e,n;!c&&a.config&&(c=!0,e=a.config.whiteListUrl,(n=void 0===e?"":e)&&a.sendPipeline([function(e,t){t({url:n,type:v.WHITE_LIST,success:function(e){l=!0;try{var t=e.data||JSON.parse(e),n=t.retcode,i=t.result,o=void 0===i?{}:i;if(0===n){if(s=o.is_in_white_list,a.isWhiteList=s,o.shutdown)return void a.destroy();0<=o.rate&&o.rate<=1&&(a.config.random=o.rate,a.isGetSample=!1)}a.isWhiteList&&u.length?ne(a)(u.splice(0),function(){}):!a.isWhiteList&&u.length&&(u.length=0);var r=a.config.onWhitelist;"function"==typeof r&&r(s)}catch(e){}},fail:function(e){"403 forbidden"===e&&a.destroy(),l=!0}})}],v.WHITE_LIST)(null),c=!1)},a.config.uin?50:500)}),a.lifeCycle.on("destroy",function(){u.length=0}),function(e,t){var n;s||null!=(n=null==(n=a.config)?void 0:n.api)&&n.reportRequest?t(e.concat(u.splice(0)).map(function(e){return ee(e),e})):(n=e.filter(function(e){return e.level!==y.INFO&&e.level!==y.API_RESPONSE?(ee(e),!0):(l||(u.push(e),200<=u.length&&(u.length=200)),!1)})).length&&t(n)}),function(e,t){try{var n=JSON.parse(JSON.stringify(e)),i=(m.lifeCycle.emit("beforeReport",n),m.config.beforeReport);(e="function"==typeof i?e.filter(function(e){return!1!==i(e)}):e).length&&t(e)}catch(e){}},ne(this)]),this.eventPipeline=E([O(this,10),(o=this,function(e){o.sendPipeline([function(e,t){var n=e.map(function(e){return{name:e.name,ext1:e.ext1||o.config.ext1||"",ext2:e.ext2||o.config.ext2||"",ext3:e.ext3||o.config.ext3||""}});t({url:o.config.eventUrl+"?payload="+encodeURIComponent(JSON.stringify(n)),type:v.EVENT,log:e,fail:function(e){"403 forbidden"===e&&o.destroy()}})}],v.EVENT)(e)})]),this.timeMap={},this.failRequestCount=0,this.customTimePipeline=E([O(this,10),(i=this,function(e){return i.sendPipeline([function(e,t){t({url:i.config.customTimeUrl+"?payload="+encodeURIComponent(JSON.stringify({custom:e})),type:v.CUSTOM,log:e,fail:function(e){"403 forbidden"===e&&i.destroy()}})}],v.CUSTOM)(e)})]),this.config=(t=this.config,void 0===(e=e.hostUrl)&&(e="https://aegis.qq.com"),t.url=t.url||e+"/collect",t.offlineUrl=t.offlineUrl||e+"/offline",t.whiteListUrl=t.whiteListUrl||e+"/collect/whitelist",t.pvUrl=t.pvUrl||e+"/collect/pv",t.eventUrl=t.eventUrl||e+"/collect/events",t.speedUrl=t.speedUrl||e+"/speed",t.customTimeUrl=t.customTimeUrl||e+"/speed/custom",t.performanceUrl=t.performanceUrl||e+"/speed/performance",t.webVitalsUrl=t.webVitalsUrl||e+"/speed/webvitals",t.setDataReportUrl=t.SetDataReportUrl||e+"/speed/miniProgramData",t),j.instances.push(this)}return n.use(S),n.use(de),n.use(ce),n.use(ve),n.use(Oe),n.use(R),n.use(se),n});
10
+ !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).Aegis=t()}(this,function(){"use strict";var j=function(e,t){return(j=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)};function e(e,t){function n(){this.constructor=e}j(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var f=function(){return(f=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function _(i,o){var r,a,s,l={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},e={next:t(0),throw:t(1),return:t(2)};return"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function t(n){return function(e){var t=[n,e];if(r)throw new TypeError("Generator is already executing.");for(;l;)try{if(r=1,a&&(s=2&t[0]?a.return:t[0]?a.throw||((s=a.return)&&s.call(a),0):a.next)&&!(s=s.call(a,t[1])).done)return s;switch(a=0,(t=s?[2&t[0],s.value]:t)[0]){case 0:case 1:s=t;break;case 4:return l.label++,{value:t[1],done:!1};case 5:l.label++,a=t[1],t=[0];continue;case 7:t=l.ops.pop(),l.trys.pop();continue;default:if(!((s=0<(s=l.trys).length&&s[s.length-1])||6!==t[0]&&2!==t[0])){l=0;continue}if(3===t[0]&&(!s||t[1]>s[0]&&t[1]<s[3]))l.label=t[1];else if(6===t[0]&&l.label<s[1])l.label=s[1],s=t;else{if(!(s&&l.label<s[2])){s[2]&&l.ops.pop(),l.trys.pop();continue}l.label=s[2],l.ops.push(t)}}t=o.call(i,l)}catch(e){t=[6,e],a=0}finally{r=s=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}}}function a(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;for(var i=Array(e),o=0,t=0;t<n;t++)for(var r=arguments[t],a=0,s=r.length;a<s;a++,o++)i[o]=r[a];return i}Object.assign||Object.defineProperty(Object,"assign",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(null==e)throw new TypeError("Cannot convert first argument to object");for(var t=Object(e),n=1;n<arguments.length;n++)if(null!=(i=arguments[n]))for(var i=Object(i),o=Object.keys(Object(i)),r=0,a=o.length;r<a;r++){var s=o[r],l=Object.getOwnPropertyDescriptor(i,s);null!=l&&l.enumerable&&(t[s]=i[s])}return t}});var I=["ext1","ext2","ext3","level","trace","tag","seq","code"],D=(t.prototype.indexOf=function(e,t){for(var n=0;n<e.length;n++)if(e[n].callback===t)return n;return-1},t.prototype.on=function(e,t,n){var i;if(void 0===n&&(n=0),this)return(i=this.eventsList[e])||(this.eventsList[e]=[],i=this.eventsList[e]),-1===this.indexOf(i,t)&&i.push({name:e,type:n||0,callback:t}),this},t.prototype.one=function(e,t){this.on(e,t,1)},t.prototype.remove=function(e,t){if(this){var n=this.eventsList[e];if(n){if(t)return n.length&&(t=this.indexOf(n,t),n.splice(t,1)),this;try{delete this.eventsList[e]}catch(e){}}return null}},t.prototype.clear=function(){this.eventsList={}},t),F=function(e){if(!e||0===e.length)return"{}";e=Array.isArray(e)?e:[e];var t=Object.keys(e[0]),n={},i=(t.forEach(function(t){n[t]=e.map(function(e){return e[t]})}),n.count=e.length,n);if("string"==typeof i)return i;try{return JSON.stringify(i,ee())||"undefined"}catch(i){return"error happen when aegis stringify: \n "+i.message+" \n "+i.stack}};function t(){var a=this;this.emit=function(e,t){if(a){var n;if(null!=(i=a.eventsList[e])&&i.length)for(var i=i.slice(),o=0;o<i.length;o++){n=i[o];try{var r=n.callback.apply(a,[t]);if(1===n.type&&a.remove(e,n.callback),!1===r)break}catch(e){throw e}}return a}},this.eventsList={}}function p(e,t){return"string"==typeof e?e.split("?")[t?1:0]||"":e}function M(e){return"string"==typeof e&&e.startsWith("//")?"undefined"!=typeof location&&"https:"===location.protocol:/^https/.test(e)}function d(e,t,n){var i,o;try{if("function"==typeof(null==t?void 0:t.retCodeHandler))return{code:void 0===(r=(o=t.retCodeHandler(e,null==n?void 0:n.url,null==n?void 0:n.ctx,null==n?void 0:n.payload)||{}).code)?"unknown":r,isErr:o.isErr};"string"==typeof e&&(e=JSON.parse(e)),"function"==typeof(null==(i=null==t?void 0:t.ret)?void 0:i.join)&&(Z=[].concat(t.ret.map(function(e){return e.toLowerCase()})));var r,a=Object.getOwnPropertyNames(e).filter(function(e){return-1!==Z.indexOf(e.toLowerCase())});return a.length?{code:""+(r=e[a[0]]),isErr:0!==r&&"0"!==r}:{code:"unknown",isErr:!1}}catch(e){return{code:"unknown",isErr:!1}}}function h(e,t,n){try{var i="function"==typeof t?t(e,null==n?void 0:n.url)||"":e;return te(i).slice(0,102400)}catch(e){return""}}function y(n,i){var o,r=[],a=n.config;return n.lifeCycle.on("destroy",function(){r.length=0}),function(e,t){Array.isArray(e)?r=r.concat(e):r.push(e),i&&r.length>=i||n.sendNow&&0<r.length?(r=oe(r),t(r.splice(0,r.length)),o&&clearTimeout(o)):(o&&clearTimeout(o),o=setTimeout(function(){o=null,0<(r=oe(r)).length&&t(r.splice(0,r.length))},a.delay))}}function B(e,t){return Array.isArray(e)?t(e.map(function(e){return t=f(f({},e),{msg:"string"==typeof e.msg?e.msg:[].concat(e.msg).map(R).join(" ")}),I.forEach(function(e){t[e]||delete t[e]}),t;var t})):t([f(f({},e),{msg:"string"==typeof e.msg?e.msg:R(e.msg)})])}function J(l,u){return function(e,t){var n,i,o,r=Array.isArray(e),a=r?e:[e],s=(l.lifeCycle.emit("beforeRequest",e),l.config.beforeRequest);(a="function"==typeof s?a.map(function(t){try{var e=s({logs:t,logType:u});return(null==e?void 0:e.logType)===u&&null!=e&&e.logs?e.logs:!1!==e&&t}catch(e){return t}}).filter(function(e){return!1!==e}):a).length&&(n=a,e=I,!Array.isArray(n)||n.length<=1||(i=[],o=[],!(o="string"==typeof e?[e]:e)||o.length<=0||(o.forEach(function(t){n.forEach(function(e){null!=e&&e[t]&&i.push(t)})}),0<i.length&&(n=n.map(function(e){var t={};return i.forEach(function(e){t[e]=""}),f(f({},t),e)})))),a=n,t(r?a:a[0]))}}function V(o){return function(e,t){o.lifeCycle.emit("modifyRequest",e);var n=o.config.modifyRequest;if("function"==typeof n)try{var i=n(e);"object"==typeof i&&"url"in i&&(e=i)}catch(e){console.error(e)}t(e)}}function W(i){return function(e,t){i.lifeCycle.emit("afterRequest",e);var n=i.config.afterRequest;"function"==typeof n&&!1===n(e)||t(e)}}function v(n){if(n&&n.reduce&&n.length)return 1===n.length?function(e,t){n[0](e,t||le)}:n.reduce(function(n,i){return function(e,t){return void 0===t&&(t=le),n(e,function(e){return null==i?void 0:i(e,t)})}});throw new TypeError("createPipeline need at least one function param")}function s(t,n){Object.getOwnPropertyNames(t).forEach(function(e){"function"==typeof t[e]&&"constructor"!==e&&(n?n[e]="sendPipeline"===e?function(){return function(){}}:function(){}:t[e]=function(){})})}function i(e){try{var t,n,i,o="";return o=e.pageUrl||(n=(t=getCurrentPages())[t.length-1]||{},r=n.options,i=Object.keys(r).length?"?"+Object.keys(r).map(function(e){return e+"="+r[e]}).join("&"):"",n.route?n.route+i:""),o="function"==typeof e.urlHandler?e.urlHandler():o}catch(e){return""}var r}function G(e,t){if("string"==typeof e&&"string"==typeof t){if(e===t)return 1;for(var n=e.split("."),i=t.split("."),o=Math.max(n.length,i.length),r=0;r<o;r++){var a=~~n[r],s=~~i[r];if(a<s)return;if(s<a)return 1}}}function K(e,t){var n=this;this.taskQueue=[],this.count=1,this.maxCount=2,this.addTask=function(e){n.taskQueue.push(e)},this.fireTask=function(){var e=n.taskQueue.length;n.count>n.maxCount||0===e||(n.count=n.count+1,(e=n.taskQueue.shift())&&n.sendRequest(e.options,null==e?void 0:e.success,null==e?void 0:e.fail))},this.complete=function(){1<n.count&&(n.count=n.count-1),n.fireTask()},t&&(this.maxCount=t),this.sendRequest=e}function l(e){return ue=ue||w.getSystemInfoSync().SDKVersion,G(ue,"1.1.1")&&w.canIUse?w.canIUse(e):!!w[e]}function u(e){for(var t,n={unknown:/unknown|none/i,wifi:/wifi/i,net2g:/2g/i,net3g:/3g/i,net4g:/4g/i,net5g:/5g/i,net6g:/6g/i},i=m.unknown,o=0;o<Object.keys(n).length;o++){var r=Object.keys(n)[o];if(null!=(t=n[r])&&t.test(e)){i=m[r];break}}return i}function c(e){var t=e.apiName,n=S[t];n?n.hackCloudReq.addCallback(e):(n=P.cloud[t],S[t]={hackCloudReq:new ge(e),originApi:n}),S[t]}function $(e){var t=e.apiName,n=k[t];n?n.hackReq.addCallback(e):(n=wx[t],k[t]={hackReq:new ye(e),originApi:n}),k[t]}var b,g,m,O,E,X,z,Q,Y,Z=["ret","retcode","code","errcode"],ee=function(){var n=new WeakSet;return function(e,t){if(t instanceof Error)return"Error.message: "+t.message+" \n Error.stack: "+t.stack;if("object"==typeof t&&null!==t){if(n.has(t))return"[Circular "+(e||"root")+"]";n.add(t)}return t}},R=function(e){if("string"==typeof e)return e;try{return e instanceof Error?(JSON.stringify(e,ee(),4)||"undefined").replace(/"/gim,""):JSON.stringify(e,ee(),4)||"undefined"}catch(e){return"error happen when aegis stringify: \n "+e.message+" \n "+e.stack}},te=function(n,i){void 0===i&&(i=3);var o,r,a,s="";return Array.isArray(n)?(s+="[",o=n.length,n.forEach(function(e,t){s=(s+="object"==typeof e&&1<i?te(e,i-1):ie(e))+(t===o-1?"":",")}),s+="]"):n instanceof Object?(s="{",r=Object.keys(n),a=r.length,r.forEach(function(e,t){"object"==typeof n[e]&&1<i?s+='"'+e+'":'+te(n[e],i-1):s+=ne(e,n[e]),s+=t===a-1||t<a-1&&void 0===n[r[t+1]]?"":","}),s+="}"):s+=n,s},ne=function(e,t){var n=typeof t,i="";return"string"==n||"object"==n?i+='"'+e+'":"'+t+'"':"function"==typeof t?i+='"'+e+'":"function '+t.name+'"':"symbol"==typeof t?i+='"'+e+'":"symbol"':"number"!=typeof t&&"boolean"!=n||(i+='"'+e+'": '+t),i},ie=function(e){var t=typeof e;return""+("undefined"==t||"symbol"==t||"function"==t?"null":"string"==t||"object"==t?'"'+e+'"':e)},oe=((n=b=b||{}).INFO_ALL="-1",n.API_RESPONSE="1",n.INFO="2",n.ERROR="4",n.PROMISE_ERROR="8",n.AJAX_ERROR="16",n.SCRIPT_ERROR="32",n.IMAGE_ERROR="64",n.CSS_ERROR="128",n.CONSOLE_ERROR="256",n.MEDIA_ERROR="512",n.RET_ERROR="1024",n.REPORT="2048",n.PV="4096",n.EVENT="8192",n.PAGE_NOT_FOUND_ERROR="16384",n.WEBSOCKET_ERROR="32768",n.BRIDGE_ERROR="65536",(n=g=g||{})[n.android=1]="android",n[n.ios=2]="ios",n[n.windows=3]="windows",n[n.macos=4]="macos",n[n.linux=5]="linux",n[n.devtools=6]="devtools",n[n.other=100]="other",(n=m=m||{})[n.unknown=100]="unknown",n[n.wifi=1]="wifi",n[n.net2g=2]="net2g",n[n.net3g=3]="net3g",n[n.net4g=4]="net4g",n[n.net5g=5]="net5g",n[n.net6g=6]="net6g",(n=O=O||{}).LOG="log",n.SPEED="speed",n.PERFORMANCE="performance",n.OFFLINE="offline",n.WHITE_LIST="whiteList",n.VITALS="vitals",n.PV="pv",n.CUSTOM_PV="customPV",n.EVENT="event",n.CUSTOM="custom",n.SDK_ERROR="sdkError",n.SET_DATA="setData",n.LOAD_PACKAGE="loadPackage",(n=E=E||{}).production="production",n.development="development",n.gray="gray",n.pre="pre",n.daily="daily",n.local="local",n.test="test",n.others="others",function(e){return e.filter(function(n,i){return"static"!==n.type||!e.find(function(e,t){return n.url===e.url&&200===n.status&&i<t})})}),re=function(e){e.level===b.INFO_ALL&&(e.level=b.INFO)},ae=function(e){return(Array.isArray(e)?e:[e]).map(function(n){return Object.getOwnPropertyNames(n).reduce(function(e,t){return"ctx"!==t&&(e[t]=n[t]),e},{level:b.INFO,msg:""})})},se=function(i){return function(e){return i.sendPipeline([function(e,n){return n({url:i.config.url||"",data:F(ae(e)),method:"post",contentType:"application/json",type:O.LOG,log:e,requestConfig:{timeout:5e3},success:function(){var t=i.config.onReport;"function"==typeof t&&e.forEach(function(e){t(e)}),"function"==typeof n&&n([])},fail:function(e){"403 forbidden"===e&&i.destroy()}})}],O.LOG)(e)}},le=function(){},n=(Object.defineProperty(A.prototype,"__version__",{get:function(){return console.warn("__version__ has discard, please use version"),"1.36.4"},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"LogType",{get:function(){return console.warn("LogType has discard, please use logType"),b},enumerable:!1,configurable:!0}),A.prototype.init=function(e){this.setConfig(e);for(var t=0;t<A.installedPlugins.length;t++)try{A.installedPlugins[t].patch(this)}catch(e){this.sendSDKError(e)}this.lifeCycle.emit("onInited")},A.prototype.setConfig=function(e){Object.assign(this.config,e);var e=this.config,t=e.id,n=e.uin,i=e.version,o=e.ext1,r=e.ext2,a=e.ext3,s=e.aid,l=e.env,u=void 0===l?"production":l,l=e.pageUrl,e=this.bean.id!==t||this.bean.uin!==n||this.bean.aid!==s;return this.bean.id=t||"",this.bean.uin=n||"",this.bean.version=i||"1.36.4",this.bean.aid=s||"",this.bean.env=function(){switch(u){case E.production:case E.development:case E.gray:case E.pre:case E.daily:case E.local:case E.test:case E.others:return 1;default:return}}()?u:E.others,l&&this.extendBean("from",encodeURIComponent(l)),o&&this.extendBean("ext1",encodeURIComponent(o)),r&&this.extendBean("ext2",encodeURIComponent(r)),a&&this.extendBean("ext3",encodeURIComponent(a)),e&&this.lifeCycle.emit("onConfigChange",this.config),this.config},A.use=function(e){-1===A.installedPlugins.indexOf(e)&&e.aegisPlugin&&A.installedPlugins.push(e)},A.unuse=function(e){e=A.installedPlugins.indexOf(e);-1!==e&&A.installedPlugins.splice(e,1)},A.prototype.info=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={level:b.INFO,msg:e};1===e.length&&e[0].msg&&Object.assign(n,f({},e[0]),{level:b.INFO}),this.normalLogPipeline(n)},A.prototype.infoAll=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={level:b.INFO_ALL,msg:e};1===e.length&&e[0].msg&&Object.assign(n,f({},e[0]),{level:b.INFO_ALL}),this.normalLogPipeline(n)},A.prototype.report=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={level:b.REPORT,msg:e};1===e.length&&e[0].msg&&Object.assign(n,f({},e[0])),this.normalLogPipeline(n)},A.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={level:b.ERROR,msg:e};1===e.length&&e[0].msg&&Object.assign(n,f({},e[0]),{level:b.ERROR}),this.normalLogPipeline(n)},A.prototype.speedLogPipeline=function(e){throw new Error('You need to override "speedLogPipeline" method')},A.prototype.reportPv=function(n){var i,o=this;n&&(console.warn("reportPv is deprecated, please use reportEvent"),i=""+Object.getOwnPropertyNames(this.bean).filter(function(e){return"id"!==e}).map(function(e){return e+"="+o.bean[e]}).join("&"),this.sendPipeline([function(e,t){t({url:o.config.url+"/"+n+"?"+i,addBean:!1,type:O.CUSTOM_PV,fail:function(e){"403 forbidden"===e&&o.destroy()}})}],O.CUSTOM_PV)(null))},A.prototype.reportEvent=function(e){e&&((e="string"==typeof e?{name:e,ext1:this.config.ext1||"",ext2:this.config.ext2||"",ext3:this.config.ext3||""}:e).name?this.eventPipeline(e):console.warn("reportEvent params error"))},A.prototype.reportTime=function(e,t){if("object"==typeof e)return this.reportT(e);"string"==typeof e?"number"==typeof t?t<0||6e4<t?console.warn("reportTime: duration must between 0 and 60000"):this.submitCustomTime(e,t):console.warn("reportTime: second param must be number"):console.warn("reportTime: first param must be a string")},A.prototype.reportT=function(e){var t=e.name,n=e.duration,i=e.ext1,i=void 0===i?"":i,o=e.ext2,o=void 0===o?"":o,r=e.ext3,r=void 0===r?"":r,e=e.from;if("string"==typeof t&&"number"==typeof n&&"string"==typeof i&&"string"==typeof o&&"string"==typeof r){if(!(n<0||6e4<n))return this.submitCustomTime(t,n,i,o,r,void 0===e?"":e);console.warn("reportTime: duration must between 0 and 60000")}else console.warn("reportTime: params error")},A.prototype.time=function(e){"string"==typeof e?this.timeMap[e]?console.warn("Timer "+e+" already exists"):this.timeMap[e]=Date.now():console.warn("time: first param must be a string")},A.prototype.timeEnd=function(e){"string"==typeof e?this.timeMap[e]?(this.submitCustomTime(e,Date.now()-this.timeMap[e]),delete this.timeMap[e]):console.warn("Timer "+e+" does not exist"):console.warn("timeEnd: first param must be a string")},A.prototype.submitCustomTime=function(e,t,n,i,o,r){this.customTimePipeline({name:e,duration:t,ext1:n||this.config.ext1,ext2:i||this.config.ext2,ext3:o||this.config.ext3,from:r||void 0})},A.prototype.extendBean=function(e,t){this.bean[e]=t},A.prototype.sendPipeline=function(e,t){var n,r=this;return v(a([function(e,t){if("number"!=typeof n.config.random&&(console.warn("random must in [0, 1], default is 1."),n.config.random=1),!n.isHidden||!n.isGetSample)if(n.isGetSample)n.isHidden||t(e);else{if(n.isGetSample=!0,Math.random()<n.config.random)return n.isHidden=!1,t(e);n.isHidden=!0}},J(n=this,t)],e,[V(this),function(i,o){r.request(i,function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];r.failRequestCount=0,o({isErr:!1,result:t,logType:null==i?void 0:i.type,logs:null==i?void 0:i.log}),null!=(e=null==i?void 0:i.success)&&e.call.apply(e,a([i],t))},function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];10<=++r.failRequestCount&&r.destroy(),o({isErr:!0,result:t,logType:null==i?void 0:i.type,logs:null==i?void 0:i.log}),null!=(e=null==i?void 0:i.fail)&&e.call.apply(e,a([i],t))})},W(this)]))},A.prototype.send=function(e,o,r){var t=this;return v([V(this),function(n,i){t.request(n,function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];i({isErr:!1,result:e,logType:n.type,logs:n.log}),null!=o&&o.apply(void 0,e)},function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];i({isErr:!0,result:e,logType:n.type,logs:n.log}),null!=r&&r.apply(void 0,e)})},W(this)])(e)},A.prototype.ready=function(e,t,n){throw new Error('You need to override "ready" method')},A.prototype.request=function(e,t,n){throw new Error('You need to override "request" method')},A.prototype.sendSDKError=function(e){var n=this;this.sendPipeline([function(e,t){t({url:n.config.url+"?id=1085&msg[0]="+encodeURIComponent(R(e))+"&level[0]=2&from="+n.config.id+"&count=1&version="+n.config.id+"(1.36.4)",addBean:!1,method:"get",type:O.SDK_ERROR,log:e})}],O.SDK_ERROR)(e)},A.prototype.destroy=function(e){void 0===e&&(e=!1);var t,n,i=A.instances.indexOf(this);-1!==i&&A.instances.splice(i,1);for(var o=A.installedPlugins.length-1;0<=o;o--)try{A.installedPlugins[o].unpatch(this)}catch(e){this.sendSDKError(e)}if(this.lifeCycle.emit("destroy"),this.lifeCycle.clear(),e)t=this,n=Object.getOwnPropertyDescriptors(t),Object.keys(n).forEach(function(e){n[e].writable&&(t[e]=null)}),Object.setPrototypeOf(this,null);else{for(var r=this;r.constructor!==Object&&s(r,this),r=Object.getPrototypeOf(r););0===A.instances.length&&(i=Object.getPrototypeOf(this).constructor,s(i),s(A))}},A.version="1.36.4",A.instances=[],A.logType=b,A.environment=E,A.installedPlugins=[],A),o=(L.prototype.patch=function(e){this.canUse(e)&&this.exist(e)&&(this.instances.push(e),this.triggerInit(e),this.triggerOnNewAegis(e))},L.prototype.unpatch=function(e){e=this.instances.indexOf(e);-1!==e&&(this.instances.splice(e,1),0===this.instances.length&&this.uninstall())},L.prototype.countInstance=function(){return this.instances.length},L.prototype.uninstall=function(){var e;null!=(e=null==(e=this.option)?void 0:e.destroy)&&e.apply(this)},L.prototype.walk=function(n){var i=this;this.instances.forEach(function(e){var t=i.canUse(e);t&&n(e,t)})},L.prototype.canUse=function(e){e=this.getConfig(e);return!(!e||"object"!=typeof e)||!!e},L.prototype.getConfig=function(e){return null==(e=e.config)?void 0:e[this.name]},L.prototype.exist=function(e){return-1===this.instances.indexOf(e)},L.prototype.triggerInit=function(e){var t;this.inited||(this.inited=!0,null!=(t=null==(t=this.option)?void 0:t.init)&&t.call(this.option,this.getConfig(e)))},L.prototype.triggerOnNewAegis=function(e){var t;null!=(t=null==(t=this.option)?void 0:t.onNewAegis)&&t.call(this.option,e,this.getConfig(e))},L),w=wx||qq,ue="",ce=new o({name:"offlineLog",onNewAegis:function(o){if(w.getFileSystemManager)try{var e=o.config,t=e.id,r=void 0===t?"":t,n=e.uin,a=void 0===n?0:n,i=e.offlineUrl,s=void 0===i?"":i,l=e.offlineLogLimit,u=new fe({limit:l});o.lifeCycle.on("beforeWrite",function(e){u.save2Offline(e=void 0===e?[]:e,o.config)}),u.ready(function(t){var e=(o.bean||{}).aid,i=void 0===e?"":e;!t&&r&&(a||i)&&o.send({url:s+"/offlineAuto",type:O.OFFLINE,log:O.OFFLINE},function(e){var n=(null==e?void 0:e.data).secretKey;n&&!t&&u.getLogs({id:r,uin:a},function(e,t){e?console.error(e):o.send({url:s+"/offlineLog",data:{logs:t,secretKey:n,id:r,uin:a,aid:i},method:"post",type:O.OFFLINE,log:t},function(){u.clearLogs()})})})})}catch(o){console.error(o)}else console.warn("[aegis-mp-sdk]unsupport getFileSystemManager offline log not work!")}}),fe=(Oe.prototype.getLogs=function(e,t){var n=this.fileSystem,i=this.filePath;n.readFile({filePath:i,encoding:"utf8",fail:function(e){console.error(e)},success:function(e){e=e.data,e=(void 0===e?"":e).toString().split("\n").filter(function(e){return e}).map(function(e){return JSON.parse(e)});t(null,e)}})},Oe.prototype.checkLimit=function(o,r){void 0===r&&(r=function(){});var a=this.fileSystem,s=this.filePath,l=this.limitSize;a.readFile({filePath:s,encoding:"utf8",success:function(e){e=e.data,e=void 0===e?"":e;if((e=e.toString()+o).length>l){for(var t=e.split("\n"),n="",i=t.length-1;0<=i&&!(t[i]&&(n=t[i]+"\n"+n).length>l);i--);a.writeFile({filePath:s,data:n,success:r})}else a.appendFile({data:o,filePath:s,encoding:"utf8",success:r,fail:function(e){console.error(e)}})}})},Oe),pe=new o({name:"device",onNewAegis:function(t){return e=this,l=function(){return _(this,function(e){return this.setSystemInfo(t),this.refreshNetwork(t),this.setNetworkChange(t),[2]})},new(s=(s=a=void 0)||Promise)(function(n,t){function i(e){try{r(l.next(e))}catch(e){t(e)}}function o(e){try{r(l.throw(e))}catch(e){t(e)}}function r(e){var t;e.done?n(e.value):((t=e.value)instanceof s?t:new s(function(e){e(t)})).then(i,o)}r((l=l.apply(e,a||[])).next())});var e,a,s,l},setSystemInfo:function(a){var s=this;try{l("getSystemInfo")&&w.getSystemInfo({success:function(e){var t=e.platform,n=e.model,i=e.windowHeight,o=e.windowWidth,r=e.screenWidth,r=void 0===r?0:r,e=e.screenHeight,e=void 0===e?0:e;a.extendBean("platform",s.getPlatFormType(t)),a.extendBean("model",n),a.extendBean("vp",Math.round(o)+" * "+Math.round(i)),a.extendBean("sr",Math.round(r)+" * "+Math.round(e))}})}catch(a){}},getPlatFormType:function(e){for(var t,n={android:/android/i,ios:/ios/i,windows:/windows/i,macos:/mac/i,devtools:/devtools/i},i=g.other,o=0;o<Object.keys(n).length;o++){var r=Object.keys(n)[o];if(null!=(t=n[r])&&t.test(e)){i=g[r];break}}return i},setNetworkChange:function(t){l("onNetworkStatusChange")&&w.onNetworkStatusChange(function(e){e=u(e.networkType);t.extendBean("netType",e)})},setNetworkType:function(t){l("getNetworkType")&&w.getNetworkType({success:function(e){e=u(e.networkType);t.extendBean("netType",e)}})},refreshNetwork:function(e){var t=this;this.timer&&clearTimeout(this.timer),this.setNetworkType(e),this.timer=setTimeout(function(){t.refreshNetwork(e)},1e4)}}),de=w.request,n=(e(N,Q=n),Object.defineProperty(N.prototype,"getBean",{get:function(){var t=this;return this.bean?Object.getOwnPropertyNames(this.bean).map(function(e){return e+"="+t.bean[e]}).join("&")+"&from="+encodeURIComponent(i(this.config)):"from="+encodeURIComponent(i(this.config))},enumerable:!1,configurable:!0}),N.prototype.initOfflineLog=function(){N.use(ce)},N.prototype.initRequestSchedule=function(){this.requestSchedule=new K(this.sendRequest)},N.prototype.uploadLogs=function(e,t){this.lifeCycle.emit("uploadLogs",e=void 0===e?{}:e,t=void 0===t?{}:t)},N.prototype.reportPv=function(e){var t,n=this;e&&(t=Object.getOwnPropertyNames(this.bean).filter(function(e){return"id"!==e}).map(function(e){return e+"="+n.bean[e]}).join("&")+"&from="+encodeURIComponent(i(this.config)),this.send({url:this.config.url+"/"+e+"?"+t,addBean:!1,type:O.CUSTOM_PV,log:O.CUSTOM_PV},function(){},function(){}))},N.sessionID="session-"+Date.now(),N.asyncPluginIndex=0,N),he=new o({name:"aid",onNewAegis:function(t){this.initAid(function(e){t.bean.aid=e,t.config.aid=e})},initAid:function(t){w.getStorage({key:"AEGIS_ID",success:function(e){t(e.data)},fail:function(){var e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)});w.setStorage({key:"AEGIS_ID",data:e,success:function(){t(e)}})}})}}),r=(C.prototype.addCallback=function(e){e&&this.callbacks.push(e)},C.prototype.prefixHandler=function(e){return f(f({},e),{aegisRequestStartTime:+new Date})},C.prototype.successHandler=function(n,i){var e;this.callbacks.forEach(function(e){var t;try{null!=(t=e.success)&&t.call(e,n,i)}catch(e){}}),null!=(e=i.success)&&e.call(i,n,i)},C.prototype.failHandler=function(n,i){var e;this.callbacks.forEach(function(e){var t;try{null!=(t=e.fail)&&t.call(e,n,i)}catch(e){}}),null!=(e=i.fail)&&e.call(i,n,i)},C.prototype.completeHandler=function(n,i){var e;this.callbacks.forEach(function(e){var t;try{null!=(t=e.complete)&&t.call(e,n,i)}catch(e){}}),null!=(e=i.complete)&&e.call(i,n,i)},C.prototype.override=function(){try{this.defineApiProperty()}catch(e){console.warn("cannot override `"+this.apiName+"`, error is: "+e)}finally{this.isOverride=!0}},C),P=wx||qq,S={},ge=(e(x,z=r),x.prototype.defineApiProperty=function(){var e=this;P.cloud&&P.cloud[this.apiName]&&Object.defineProperty(P.cloud,this.apiName,{get:function(){return e.hackHandler.bind(e)}})},x.prototype.hackHandler=function(e){var i=this,o=this.prefixHandler(e);return new Promise(function(t,n){var e=null==(e=S[i.apiName])?void 0:e.originApi;null!=e&&e(f(f({},o),{success:function(e){i.successHandler(e,o),t(e)},fail:function(e){i.failHandler(e,o),n(e)},complete:function(e){i.completeHandler(e,o)}}))})},x),me=wx||qq,k={},ye=(e(T,X=r),T.prototype.defineApiProperty=function(){var e=this;Object.defineProperty(me,this.apiName,{get:function(){return e.hackHandler.bind(e)}})},T.prototype.hackHandler=function(e){var t=this,n=this.prefixHandler(e),e=null==(e=k[this.apiName])?void 0:e.originApi;return null==e?void 0:e(f(f({},n),{success:function(e){t.successHandler(e,n)},fail:function(e){t.failHandler(e,n)},complete:function(e){t.completeHandler(e,n)}}))},T),ve=wx||qq,be=ve.request;function T(){return null!==X&&X.apply(this,arguments)||this}function x(){return null!==z&&z.apply(this,arguments)||this}function C(e){this.callbacks=[],this.isOverride=!1;var t=e.apiName;this.apiName=t,this.isOverride||this.override(),this.callbacks.push(e)}function N(e){var i,o,r,c=Q.call(this,e)||this;c.originRequest=de,c.speedLogPipeline=v([(o=c.config,r={},function(e,t){var n,i;o.speedSample?(i="object"==typeof o.repeat?o.repeat:{repeat:o.repeat},n=+i.speed||+i.repeat||5,Array.isArray(e)?(i=e.filter(function(e){var t=!r[e.url]||r[e.url]<n;return r[e.url]=1+~~r[e.url],t})).length&&t(i):(!r[e.url]||r[e.url]<n)&&(r[e.url]=1+~~r[e.url],t(e))):t(e)}),y(c),function(t,n){l("getNetworkType")?w.getNetworkType({success:function(e){e=u(e.networkType);i.extendBean("netType",e),n(t)}}):n(t)},function(e,t){c.lifeCycle.emit("beforeReportSpeed",e);var n=c.config.beforeReportSpeed;if((e="function"==typeof n?e.filter(function(e){return!1!==n(e)}):e).length)return t(e)},J(i=c,O.SPEED),function(e){var t,n,i,o;c.send({url:""+c.config.speedUrl,method:"post",data:(e=e,t=c.bean,i={fetch:[],static:[],bridge:[]},o={},Array.isArray(e)?e.forEach(function(e){var t;null!=(t=i[e.type])&&t.push(e)}):null!=(n=i[e.type])&&n.push(e),o.payload=JSON.stringify(f({duration:i},t)),o)})}]),c.request=function(e,t,n){e.url&&c.bean.id&&(!/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/.test(String(c.bean.aid))||l("getNetworkType")&&void 0===c.bean.netType?c.requestSchedule.addTask({options:e,success:t,fail:n}):(c.requestSchedule.addTask({options:e,success:t,fail:n}),c.requestSchedule.fireTask()))},c.sendRequest=function(e,t,n){var i,o,r,a=e.url,s=(c.config.whiteListUrl===a&&(i=t,t=function(e){null!=i&&i(JSON.stringify(e.data))}),e.method),s=void 0===s?"get":s,l=(!1!==e.addBean&&(a=a+(-1===(null==a?void 0:a.indexOf("?"))?"?":"&")+c.getBean),e),u=c.config.onBeforeRequest;return(l=u?u(e,c):l)&&l.url?(u=c.config.enableHttp2||!1,"get"===s?(s=a,o=l.data,a="string"!=typeof s?"":"object"==typeof o&&o?(r=Object.getOwnPropertyNames(o).map(function(e){var t=o[e];return e+"="+("string"==typeof t?encodeURIComponent(t):encodeURIComponent(JSON.stringify(t)))}).join("&").replace(/eval/gi,"evaI"),s+(-1===s.indexOf("?")?"?":"&")+r):s,c.originRequest(f({url:a,enableHttp2:u,success:t,fail:n,complete:c.requestSchedule.complete},e.requestConfig))):("string"==typeof l.data&&(l.data=l.data.replace(/eval/gi,"evaI")),c.originRequest(f({url:a,enableHttp2:u,header:l.contentType?{"content-type":l.contentType}:void 0,method:"POST",data:l.data,success:t,fail:n,complete:c.requestSchedule.complete},e.requestConfig))),!0):(r="",l&&l.url||(r="Sending request blocked. Please handle the parameters reasonably, options.url is necessary",console.log(r)),null!=n&&n(r),c.requestSchedule.complete(),!1)};try{e.offlineLog&&c.initOfflineLog(),c.initRequestSchedule(),c.init(e),c.extendBean("sessionId",N.sessionID),c.extendBean("referer",(l("getLaunchOptionsSync")?w.getLaunchOptionsSync():{scene:""}).scene||"")}catch(e){console.warn(e),console.log("%cThe above error occurred in the process of initializing Aegis, which will affect your normal use of Aegis.\nIt is recommended that you contact us for feedback and thank you for your support.","color: red"),c.sendSDKError(e)}return c}function Oe(e){var o,r,a=this,e=void 0===e?{}:e,t=e.path,t=void 0===t?"/.aegis.offline.log":t,e=e.limit,e=void 0===e?2e4:e;this.offlineBuffer=[],this.insertLog=(o=null,r=[],function(e){r=r.concat(e),o=o||setTimeout(function(){o=null;var e,t=a.fileSystem,n=a.filePath,i=r.map(function(e){return JSON.stringify(e)}).join("\n")+"\n";i&&(e=function(e){e?a.checkLimit(i,function(){r=[]}):t.writeFile({data:i,filePath:n,encoding:"utf8",fail:function(e){console.error(e)},success:function(){r=[]}})},t.access({path:n,success:function(){e(!0)},fail:function(){e()}}))},2e3)}),this.ready=function(e){a.fileSystem?setTimeout(function(){e(null)},0):(e(new Error("getFileSystemManager file")),a.offlineLog=!1)},this.clearLogs=function(){var e=a.fileSystem,t=a.filePath;e.writeFile({filePath:t,data:"",fail:function(){e.unlinkSync(t)}})},this.save2Offline=function(e,t){e=(e=Array.isArray(e)?e:[e]).map(function(e){return"string"==typeof e&&(e={msg:e}),function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(0===e.length)throw new TypeError("Cannot convert undefined or null to object");for(var n=Object(e[0]),i=1;i<e.length;i++){var o=e[i];if(null!==o)for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&(n[r]=o[r])}return n}({id:t.id,uin:t.uin,time:+Date.now(),version:t.version,from:i(t)},e)});a.fileSystem?a.insertLog(e):(a.fileSystem||a.offlineBuffer.length||a.ready(function(e){e?console.error(e):a.offlineBuffer.length&&(a.addLogs(a.offlineBuffer),a.offlineBuffer=[])}),a.offlineBuffer=a.offlineBuffer.concat(e))},this.addLogs=function(e){a.fileSystem&&a.insertLog(e)},this.filePath=w.env.USER_DATA_PATH+t,this.fileSystem=w.getFileSystemManager(),this.limitSize=e}function L(e){this.aegisPlugin=!0,this.name="",this.instances=[],this.inited=!1,e.$walk=this.walk.bind(this),e.$getConfig=this.getConfig.bind(this),this.option=e,this.name=e.name}function A(e){var n,t,i,o,a,r,s,l,u,c,f,p,d,h,g,m=this;this.isGetSample=!1,this.isHidden=!1,this.config={version:0,delay:1e3,onError:!0,repeat:5,random:1,aid:!0,device:!0,pagePerformance:!0,webVitals:!0,speedSample:!0,onClose:!0,hostUrl:"https://aegis.qq.com",websocketHack:!1,env:"production",url:"",offlineUrl:"",whiteListUrl:"",pvUrl:"",speedUrl:"",customTimeUrl:"",performanceUrl:"",webVitalsUrl:"",eventUrl:"",setDataReportUrl:"",reportImmediately:!0},this.isWhiteList=!1,this.lifeCycle=new D,this.bean={},this.normalLogPipeline=v([y(this,5),B,function(e,t){var i=n.config;t(e=e.map(function(e){var t,n=i.maxLength||102400;try{if(!e.msg||e.msg.length<=n)return e;e.msg=null==(t=e.msg)?void 0:t.substring(0,n)}catch(t){e.msg=R(e.msg).substring(0,i.maxLength)}return e}))},(h=(n=this).config,g={},function(e,t){var n="number"==typeof h.repeat?h.repeat:5;if(0===n)return t(e);t(e.filter(function(e){return e.level!==b.ERROR&&e.level!==b.PROMISE_ERROR&&e.level!==b.AJAX_ERROR&&e.level!==b.SCRIPT_ERROR&&e.level!==b.IMAGE_ERROR&&e.level!==b.CSS_ERROR&&e.level!==b.MEDIA_ERROR||(g[e.msg]=g[e.msg]||0,g[e.msg]+=1,!(g[e.msg]>n))}))}),(p=this.lifeCycle.emit,d=this.config,function(e,t){var n,i=d.logCreated;return"function"==typeof i?(n=e.filter(function(e){return!1!==i(e)}),p("beforeWrite",n),t(n)):(p("beforeWrite",e),t(e))}),(f=this,setTimeout(function(){var e=f.config.pvUrl,n=void 0===e?"":e;n&&f.sendPipeline([function(e,t){t({url:n,type:O.PV,fail:function(e){"403 forbidden"===e&&f.destroy()}})}],O.PV)(null)},100),function(e,t){t(e)}),(u=l=s=!1,c=[],(a=this).lifeCycle.on("onConfigChange",function(){r&&clearTimeout(r),r=setTimeout(function(){var e,n;!u&&a.config&&(u=!0,e=a.config.whiteListUrl,(n=void 0===e?"":e)&&a.sendPipeline([function(e,t){t({url:n,type:O.WHITE_LIST,success:function(e){l=!0;try{var t=e.data||JSON.parse(e),n=t.retcode,i=t.result,o=void 0===i?{}:i;if(0===n){if(s=o.is_in_white_list,a.isWhiteList=s,o.shutdown)return void a.destroy();0<=o.rate&&o.rate<=1&&(a.config.random=o.rate,a.isGetSample=!1)}a.isWhiteList&&c.length?se(a)(c.splice(0),function(){}):!a.isWhiteList&&c.length&&(c.length=0);var r=a.config.onWhitelist;"function"==typeof r&&r(s)}catch(e){}},fail:function(e){"403 forbidden"===e&&a.destroy(),l=!0}})}],O.WHITE_LIST)(null),u=!1)},a.config.uin?50:500)}),a.lifeCycle.on("destroy",function(){c.length=0}),function(e,t){var n;s||null!=(n=null==(n=a.config)?void 0:n.api)&&n.reportRequest?t(e.concat(c.splice(0)).map(function(e){return re(e),e})):(n=e.filter(function(e){return e.level!==b.INFO&&e.level!==b.API_RESPONSE?(re(e),!0):(l||(c.push(e),200<=c.length&&(c.length=200)),!1)})).length&&t(n)}),function(e,t){try{var n=JSON.parse(JSON.stringify(e)),i=(m.lifeCycle.emit("beforeReport",n),m.config.beforeReport);(e="function"==typeof i?e.filter(function(e){return!1!==i(e)}):e).length&&t(e)}catch(e){}},se(this)]),this.eventPipeline=v([y(this,10),(o=this,function(e){o.sendPipeline([function(e,t){var n=e.map(function(e){return{name:e.name,ext1:e.ext1||o.config.ext1||"",ext2:e.ext2||o.config.ext2||"",ext3:e.ext3||o.config.ext3||""}});t({url:o.config.eventUrl+"?payload="+encodeURIComponent(JSON.stringify(n)),type:O.EVENT,log:e,fail:function(e){"403 forbidden"===e&&o.destroy()}})}],O.EVENT)(e)})]),this.timeMap={},this.failRequestCount=0,this.customTimePipeline=v([y(this,10),(i=this,function(e){return i.sendPipeline([function(e,t){t({url:i.config.customTimeUrl+"?payload="+encodeURIComponent(JSON.stringify({custom:e})),type:O.CUSTOM,log:e,fail:function(e){"403 forbidden"===e&&i.destroy()}})}],O.CUSTOM)(e)})]),this.config=(t=this.config,void 0===(e=e.hostUrl)&&(e="https://aegis.qq.com"),t.url=t.url||e+"/collect",t.offlineUrl=t.offlineUrl||e+"/offline",t.whiteListUrl=t.whiteListUrl||e+"/collect/whitelist",t.pvUrl=t.pvUrl||e+"/collect/pv",t.eventUrl=t.eventUrl||e+"/collect/events",t.speedUrl=t.speedUrl||e+"/speed",t.customTimeUrl=t.customTimeUrl||e+"/speed/custom",t.performanceUrl=t.performanceUrl||e+"/speed/performance",t.webVitalsUrl=t.webVitalsUrl||e+"/speed/webvitals",t.setDataReportUrl=t.SetDataReportUrl||e+"/speed/miniProgramData",t),A.instances.push(this)}function Ee(){return null!==Y&&Y.apply(this,arguments)||this}e(Ee,Y=r),Ee.prototype.defineApiProperty=function(){var e=this;Object.defineProperty(ve,"request",{get:function(){return e.hackHandler.bind(e)}})};function q(i,e,o){return null!=e&&e.length&&"object"==typeof i?e.reduce(function(e,t){var n=i[t];return n?e+(""===e?"\n":"\n\n")+o+" header "+t+": "+n:e},""):""}var U,Re,we=new o({name:"reportApiSpeed",override:!(Ee.prototype.hackHandler=function(e){var t=this,n=this.prefixHandler(e);return be(f(f({},n),{success:function(e){t.successHandler(e,n)},fail:function(e){t.failHandler(e,n)},complete:function(e){t.completeHandler(e,n)}}))}),onNewAegis:function(e){this.override||(this.override=!0,this.hackRequest(e.config),this.overrideCallFunction(e.config),this.overrideCallContainer(e.config))},hackRequest:function(u){var c=this;$({apiName:"request",success:function(e,t){var n,i,o,r,a,s,l;u.hostUrl&&-1<t.url.indexOf(u.hostUrl)||(n={method:t.method||"get",url:p(t.url),duration:Date.now()-t.aegisRequestStartTime,status:e.statusCode||0,nextHopProtocol:"",isHttps:M(t.url),type:"fetch"},r=null==(r=u.api)?void 0:r.apiDetail,i=(o=d(e.data,u.api,{url:t.url,ctx:e,payload:t.data})||{}).code,o=o.isErr,l=r?h(t.data,null==(l=u.api)?void 0:l.reqParamHandler,{url:t.url}):"",r=r?h(e.data,null==(r=u.api)?void 0:r.resBodyHandler,{url:t.url}):"",a=(null==(a=u.api)?void 0:a.reqHeaders)||[],a=q(null==t?void 0:t.header,a,"req"),s=(null==(s=u.api)?void 0:s.resHeaders)||[],s=q(null==e?void 0:e.header,s,"res"),l="req url: "+n.url+" \n \nres status: "+(e.statusCode||0)+" \n \nres duration: "+n.duration+"ms \n \nreq method: "+n.method+" \n \nreq param: "+l+" \n \nres retcode: "+i+" \n \nres data: "+r+"\n "+a+"\n "+s,c.publishNormalLog({msg:l,level:b.API_RESPONSE,ctx:e}),n.ret=i,n.isErr=+o,n.payload=t.data,c.publishSpeedLog(n),o&&c.publishNormalLog({msg:l,level:b.RET_ERROR,ctx:e}))},fail:function(e,t){u.hostUrl&&-1<t.url.indexOf(u.hostUrl)||(t={method:t.method||"get",url:p(t.url),duration:Date.now()-t.aegisRequestStartTime,status:0,nextHopProtocol:"",isHttps:M(t.url),type:"fetch"},c.publishSpeedLog(t))}})},overrideCallFunction:function(n){var i=this;c({apiName:"callFunction",success:function(e,t){i.cloudSuccessCallback(n,t,e,"callFunction")},fail:function(e,t){t={method:"call",url:"wx.cloud.callFunction."+t.name,duration:Date.now()-t.aegisRequestStartTime,status:0,nextHopProtocol:"",type:"fetch",errMsg:e.errMsg,isHttps:!0};i.publishSpeedLog(t)}})},overrideCallContainer:function(n){var i=this;c({apiName:"callContainer",success:function(e,t){i.cloudSuccessCallback(n,t,e,"callContainer")},fail:function(e,t){t={method:"call",url:"wx.cloud.callContainer."+t.path,duration:Date.now()-t.aegisRequestStartTime,status:0,nextHopProtocol:"",type:"fetch",errMsg:e.errMsg,isHttps:!0};i.publishSpeedLog(t)}})},cloudSuccessCallback:function(e,n,t,i){var o="callFunction"===i?n.name:n.path,r="callFunction"===i?t.result:t.data,o={method:"call",url:"wx.cloud."+i+"."+o,duration:Date.now()-n.aegisRequestStartTime,status:200,nextHopProtocol:"",type:"fetch",isHttps:!0},a=["apiName","aegisRequestStartTime","config","success","fail","complete"],s=Object.keys(n).reduce(function(e,t){return a.includes(t)||(e[t]=n[t]),e},{}),i="callFunction"===i?(null==(i=t.data)?void 0:i.code)||0:t.statusCode,l=d(r,e.api,{url:o.url,ctx:t,payload:s})||{},u=l.code,l=l.isErr,l=void 0!==l&&l,u=(o.ret=u,o.isErr=+l,o.payload=s,null==(u=e.api)?void 0:u.apiDetail),s=u?h(s,null==(s=e.api)?void 0:s.reqParamHandler,{url:o.url}):"",r=u?h(r,null==(u=e.api)?void 0:u.resBodyHandler,{url:o.url}):"",u=(null==(u=e.api)?void 0:u.reqHeaders)||[],u=q(null==n?void 0:n.header,u,"req"),e=(null==(e=e.api)?void 0:e.resHeaders)||[],e=q(null==t?void 0:t.header,e,"res"),i="req url: "+o.url+"\n \nres status: "+i+"\n \nres duration: "+o.duration+"ms \n \nreq type: "+o.type+"\n \nreq params: "+s+"\n \nres retcode: "+o.ret+"\n \nres data: "+r+"\n "+u+"\n "+e;this.publishNormalLog({msg:i,level:b.API_RESPONSE,ctx:t}),this.publishSpeedLog(o),l&&this.publishNormalLog({msg:i,level:b.RET_ERROR,ctx:t})},publishSpeedLog:function(t){this.$walk(function(e){e.speedLogPipeline(t)})},publishNormalLog:function(t){this.$walk(function(e){e.normalLogPipeline(t)})}}),Pe=wx||qq,Se=Pe.connectSocket,ke=(Le.prototype.addConfig=function(e){var t=e.send,e=e.onError;t&&this.sends.push(t),e&&this.onErrors.push(e)},Le.prototype.toHack=function(t){var o=this,n=(this.onErrors.forEach(function(e){t.onError(e)}),t.send);return Object.defineProperty(t,"send",{get:function(){return function(i){return new Promise(function(e){n.call(t,f(f({},i),{fail:function(n){o.sends.forEach(function(e){var t;null!=(t=e.fail)&&t.call(e,n,i)}),e(n)}}))})}}}),t},Le),Te=(e(H,Re=r),H.prototype.addTaskConf=function(e){this.taskHack.addConfig(e)},H.prototype.defineApiProperty=function(){var e=this;Object.defineProperty(Pe,"connectSocket",{get:function(){return e.hackHandler.bind(e)}})},H.prototype.hackHandler=function(e){var t=this,n=this.prefixHandler(e),e=Se(f(f({},n),{success:function(e){t.successHandler(e,n)},fail:function(e){t.failHandler(e,n)},complete:function(e){t.completeHandler(e,n)}}));return this.taskHack.toHack(e),e},H),r=new o({name:"onError",onNewAegis:function(e){var t=w.getSystemInfoSync().SDKVersion;this.listenError(),this.hackNetWork(e),this.hackCloud(e),e.config.websocketHack&&G(t,"1.7.0")&&this.hackWsConnect()},listenError:function(){var t=this;"function"==typeof w.onError&&w.onError(function(e){e&&t.publishErrorLog({msg:e,level:b.ERROR})}),l("onUnhandledRejection")&&w.onUnhandledRejection(function(e){e=e.reason;!e||-1<JSON.stringify(e).indexOf("request:fail")||t.publishErrorLog({msg:e,level:b.PROMISE_ERROR})}),l("onPageNotFound")&&w.onPageNotFound(function(e){e&&t.publishErrorLog({msg:e,level:b.PAGE_NOT_FOUND_ERROR})})},publishErrorLog:function(t){this.$walk(function(e){e.normalLogPipeline(t)})},hackNetWork:function(e){for(var n=this,i=e.config,t=0,o=[{apiName:"request",complete:function(e,t){return n.requestCompleteError(e,t,i)}},{apiName:"uploadFile",complete:function(e,t){return n.uploadFileCompleteError(e,t,i)}},{apiName:"downloadFile",complete:function(e,t){return n.downloadFileCompleteError(e,t,i)}}];t<o.length;t++){var r=o[t],a=r.apiName,r=r.complete;$({apiName:a,complete:r})}},requestCompleteError:function(e,t,n){var i,o=e.errMsg,r=e.statusCode;n.hostUrl&&-1<(null==(i=t.url)?void 0:i.indexOf(n.hostUrl))||(i=this.getErrorType({errMsg:o,statusCode:r}))&&this.publishNetWorkError({apiName:"request",opts:t,res:e,config:n,type:i})},downloadFileCompleteError:function(e,t,n){var i,o=e.errMsg,r=e.statusCode,a=e.filePath,e=e.tempFilePath,s=this.getErrorType({errMsg:o,statusCode:r});s&&(n=null!=(i=n.api)&&i.apiDetail?h(t.data,null==(i=n.api)?void 0:i.reqParamHandler,{url:t.url}):"",this.publishErrorLog({msg:"AJAX_ERROR: downloadFile "+s+"\n \nreq url: "+t.url+"\n \nres status: "+(r||0)+"\n \nres duration: "+(Date.now()-t.aegisRequestStartTime)+"ms\n \nres filePath: "+a+"\n \nres tempFilePath: "+e+"\n \nreq method: "+(t.method||"get")+"\n \nreq param: "+n+"\n \nerrMsg: "+o.slice(0,1e3),level:b.AJAX_ERROR}))},uploadFileCompleteError:function(e,t,n){var i=e.errMsg,o=e.statusCode,i=this.getErrorType({errMsg:i,statusCode:o});i&&this.publishNetWorkError({apiName:"uploadFile",opts:t,res:e,config:n,type:i})},hackCloud:function(e){for(var n=this,i=e.config,t=0,o=[{apiName:"callFunction",complete:function(e,t){return n.callFunctionCompleteError(e,t,i)}},{apiName:"callContainer",complete:function(e,t){return n.callContainerCompleteError(e,t,i)}}];t<o.length;t++){var r=o[t],a=r.apiName,r=r.complete;c({apiName:a,complete:r})}},callFunctionCompleteError:function(e,t,n){var i,o;(-1<e.errMsg.indexOf("fail")||-1<e.errMsg.indexOf("timeout"))&&(o=(i=null==(i=n.api)?void 0:i.apiDetail)?h(t.data,null==(o=n.api)?void 0:o.reqParamHandler,{url:null==t?void 0:t.url}):"",n=i?h(e,null==(i=n.api)?void 0:i.resBodyHandler,{url:null==t?void 0:t.url}):"",this.publishErrorLog({msg:"AJAX_ERROR: cloud.callFunction:fail\n \nreq url: cloud.callFunction."+t.name+"\n \nres status: 0\n \nres duration: "+(Date.now()-t.aegisRequestStartTime)+"ms\n \nres data: "+n+"\n \nreq method: POST\n \nreq param: "+o+"\n \nerrMsg: "+e.errMsg.slice(0,1e3),level:b.AJAX_ERROR}))},callContainerCompleteError:function(e,t,n){var i,o,r,a=e.errMsg,s=e.statusCode;(400<=s||-1<a.indexOf("fail")||-1<a.indexOf("timeout"))&&(i=(o=null==(o=n.api)?void 0:o.apiDetail)?h(t.data,null==(i=n.api)?void 0:i.reqParamHandler,{url:null==t?void 0:t.url}):"",o=o?h(e,null==(o=n.api)?void 0:o.resBodyHandler,{url:null==t?void 0:t.url}):"",r=(null==(r=n.api)?void 0:r.reqHeaders)||[],r=q(null==t?void 0:t.header,r,"req"),n=(null==(n=n.api)?void 0:n.resHeaders)||[],e=q(null==e?void 0:e.header,n,"res"),this.publishErrorLog({msg:"AJAX_ERROR: cloud.callContainer:fail\n \nreq url: "+t.path+"\n \nres status: "+(s||0)+"\n \nres duration: "+(Date.now()-t.aegisRequestStartTime)+"ms\n \nreq method: "+(t.method||"POST")+"\n \nreq param: "+i+"\n \nres data: "+o+"\n \nerrMsg: "+a.slice(0,1e3)+"\n "+r+"\n "+e,level:b.AJAX_ERROR}))},publishNetWorkError:function(e){var t=e.apiName,n=e.opts,i=e.res,o=e.config,e=e.type,r=i.errMsg,a=i.statusCode,s=i.data,l="wx.cloud.callFunction."+n.url,u=d(s,o.api,{url:l,ctx:i,payload:n.data}).code,c=null==(c=o.api)?void 0:c.apiDetail,f=c?h(n.data,null==(f=o.api)?void 0:f.reqParamHandler,{url:l}):"",s=c?h(s,null==(c=o.api)?void 0:c.resBodyHandler,{url:l}):"",l=(null==(c=o.api)?void 0:c.reqHeaders)||[],c=q(null==n?void 0:n.header,l,"req"),o=(null==(l=o.api)?void 0:l.resHeaders)||[],l=q(null==i?void 0:i.header,o,"res");this.publishErrorLog({msg:"AJAX_ERROR: "+t+" "+e+"\n \nreq url: "+n.url+"\n \nres status: "+(a||0)+"\n \nres duration: "+(Date.now()-n.aegisRequestStartTime)+"ms\n \nreq method: "+(n.method||"get")+"\n \nreq param: "+f+"\n \nres retcode: "+u+"\n \nres data: "+s+"\n \nerrMsg: "+r.slice(0,1e3)+"\n "+c+"\n "+l,level:b.AJAX_ERROR})},getErrorType:function(e){var t=e.errMsg,e=e.statusCode,n="";return-1<t.indexOf("timeout")||-1<t.indexOf("超时")?n="timeout":400<=e?n="error":(-1<t.indexOf("fail")||!e||e<0)&&(n="failed"),n},hackWsConnect:function(){var e,t,n=this;$({apiName:"sendSocketMessage",fail:function(e){n.publishSocketError(e)}}),e=(t={connectCallback:{fail:function(e){n.publishSocketError(e)}},taskOpt:{onError:function(e){n.publishSocketError(e)},send:{fail:function(e){n.publishSocketError(e)}}}}).connectCallback,t=t.taskOpt,U?U.addCallback(e):U=new Te(e),t&&U.addTaskConf(t)},publishSocketError:function(e){e&&this.publishErrorLog({msg:e.errMsg,level:b.WEBSOCKET_ERROR})}}),xe=new o({name:"reportAssetSpeed",isStart:!1,onNewAegis:function(e){this.isStart||(this.isStart=!0,this.start(e))},start:function(){var t=this;w.getPerformance&&w.getPerformance().createObserver(function(e){e=e.getEntries();null!=e&&e.forEach(function(e){"number"!=typeof e.duration||e.duration<=0||t.publishAssetLog(e)})}).observe({entryTypes:["resource"]})},generateLog:function(e){return{url:""+p(e.uri),method:"get",duration:Math.round(100*e.duration)/100,status:200,type:"static",isHttps:!0,urlQuery:"",nextHopProtocol:"",domainLookup:0,connectTime:0}},publishAssetLog:function(t){var n=this;this.$walk(function(e){e.speedLogPipeline(n.generateLog(t))})}}),Ce=["onLaunch","onHide","onError","onLoad","onReady","onShow","onUnload"],Ne=new o({name:"pagePerformance",pageNavigationStartTime:{},onNewAegis:function(e){try{l("getPerformance")&&this.reportPerformance(e),this.setPagePV(e),this.reportSetDataTiming(e)}catch(e){}},reportPerformance:function(u){var c=this,e=w.getPerformance(),e=null==e?void 0:e.createObserver(function(e){var t={},n=null==(n=e.getEntriesByName("appLaunch"))?void 0:n[0],i=null==(i=e.getEntriesByName("firstRender"))?void 0:i[0],o=null==(o=e.getEntriesByName("evaluateScript"))?void 0:o[0],r=null==(r=e.getEntriesByName("route"))?void 0:r[0],a=null==(a=null==(a=e.getEntriesByName("firstPaint"))?void 0:a[0])?void 0:a.startTime,s=null==(s=(null==(s=e.getEntriesByName("firstPaint"))?void 0:s[0])||(null==(s=e.getEntriesByName("route"))?void 0:s[0])||(null==(s=e.getEntriesByName("appLaunch"))?void 0:s[0]))?void 0:s.pageId,l=null==(e=(null==(l=e.getEntriesByName("route"))?void 0:l[0])||(null==(l=e.getEntriesByName("appLaunch"))?void 0:l[0]))?void 0:e.startTime;s&&(c.pageNavigationStartTime[s]=null,l&&(c.pageNavigationStartTime[s]=l)),n&&(t.appLaunch=n.duration),i&&(t.firstScreenTiming=i.duration),o&&(t.scriptEvaluateTiming=o.duration),r&&(t.pageRouteTiming=r.duration),a&&l?t.firstPaintTiming=Math.max(a-l,0):a&&c.pageNavigationStartTime[s]&&(t.firstPaintTiming=Math.max(a-c.pageNavigationStartTime[s],0)),c.publish(t,u)});null!=e&&e.observe({entryTypes:["navigation","render","script"]})},publish:function(t,n){var e,i,o,r=[],a=n.config,s=-1===(null==(e=n.config.performanceUrl)?void 0:e.indexOf("?"))?"?":"&";for(i in t)r.push(i+"="+t[i]);"function"==typeof a.urlHandler?(o=a.urlHandler()||window.location.href,this.$walk(function(e){e.send({url:n.config.performanceUrl+s+r.join("&")+"&from="+encodeURIComponent(o),beanFilter:["from"],type:O.PERFORMANCE,log:t})})):this.$walk(function(e){e.send({url:n.config.performanceUrl+s+r.join("&"),type:O.PERFORMANCE,log:t})})},setPagePV:function(e){var t=this;w.onAppRoute&&w.onAppRoute(function(e){"appLaunch"!==e.openType&&(t.$walk(function(e){e.send({url:""+e.config.pvUrl,type:O.PV})}),t.reportPageLoaded(e))})},reportPageLoaded:function(e){e="infoType: behaviorBacktracking\ndataType: pageLoadAndRoute\npageLoadedPath: "+e.path+"\nopenType: "+e.openType;this.publishNormalLog({msg:e,level:b.INFO})},publishNormalLog:function(t){this.$walk(function(e){e.normalLogPipeline(t)})},reportSetDataTiming:function(t){var e,o,r,a,n,s,l,u,c,f=this,i=t.config.setDataReportConfig,i=void 0===i?{}:i;!0!==i.disabled&&(e=i.timeThreshold,o=!1!==i.withDataPaths,r=e&&0<+e?+e:30,a=v([y(t,10),function(e){e=e.map(function(e){return{type:O.SET_DATA,component:e.from,duration:e.duration,fields:e.dataPaths&&e.dataPaths.length?e.dataPaths.sort().join(";"):void 0,size:e.size}});t.send({url:t.config.setDataReportUrl+"?payload="+encodeURIComponent(JSON.stringify({miniProgramData:e})),type:O.SET_DATA,log:e})}]),n=Page,s=Component,l=function(r,e){var a=0;return null!=r&&r.data?(e.forEach(function(e){for(var t=r.data[e[0]],n=1,i=e.length;n<i;n++)t[e[n]]&&(t=t[e[n]]);var o="";try{o=JSON.stringify(t)}catch(e){o=""}a+=2*(void 0===o?"":o).replace(/[\u4e00-\u9fa5]/g,"aa").length}),a=Math.min(a,10485760)):a},u=function(e,t){var n=t.updateStartTimestamp,i=t.updateEndTimestamp,t=t.dataPaths,t=void 0===t?[]:t,i=i-n;isNaN(i)||i<r||(n={from:e.is,duration:i},o&&0<t.length&&Object.assign(n,{dataPaths:t.slice(0,30),size:l(e,t)}),a(n))},c=function(i){var e="infoType: behaviorBacktracking\ndataType: tapEvent"+Object.keys(i[0]).reduce(function(e,t){var n="";try{n=t+": "+JSON.stringify(i[0][t])}catch(e){n=""}return e+"\n"+n},"");f.publishNormalLog({msg:e,level:b.INFO})},Page=function(t){var e=t.onReady;return t.onReady=function(){var t=this;return"function"==typeof this.setUpdatePerformanceListener&&this.setUpdatePerformanceListener({withDataPaths:o},function(e){u(t,e)}),null==e?void 0:e.call(this)},Object.keys(t).forEach(function(e){var n;"function"!=typeof t[e]||Ce.includes(e)||(n=t[e],t[e]=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return null!=e&&e[0]&&"tap"===e[0].type&&c(e),null==n?void 0:n.apply(this,e)})}),n(t)},Component=function(e){e.lifetimes&&e.lifetimes.attached?(n=e.lifetimes.attached,e.lifetimes.attached=function(){var t=this;return"function"==typeof this.setUpdatePerformanceListener&&this.setUpdatePerformanceListener({withDataPaths:o},function(e){u(t,e)}),null==n?void 0:n.call(this)}):(i=e.attached,e.attached=function(){var t=this;return"function"==typeof this.setUpdatePerformanceListener&&this.setUpdatePerformanceListener({withDataPaths:o},function(e){u(t,e)}),null==i?void 0:i.call(this)});var n,i,t=e.methods;return t&&"[object Object]"===Object.prototype.toString.call(t)&&Object.keys(t).forEach(function(e){var n;"function"==typeof t[e]&&(n=t[e],t[e]=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return null!=e&&e[0]&&"tap"===e[0].type&&c(e),null==n?void 0:n.apply(this,e)})}),s(e)})}}),o=new o({name:"reportLoadPackageSpeed",isLoaded:!1,onNewAegis:function(e){this.isLoaded||(this.isLoaded=!0,this.start(e))},start:function(){var t=this;w.getPerformance&&w.getPerformance().createObserver(function(e){e=e.getEntries();null!=e&&e.forEach(function(e){"number"!=typeof e.duration||e.duration<=0||t.publishPackageLog(e)})}).observe({entryTypes:["loadPackage"]})},generateLog:function(e){return[{type:O.LOAD_PACKAGE,packageName:e.packageName,size:Math.round(100*e.packageSize)/100,duration:Math.round(100*e.duration)/100}]},publishPackageLog:function(n){var i=this;this.$walk(function(e){var t=i.generateLog(n);e.send({url:e.config.setDataReportUrl+"?payload="+encodeURIComponent(JSON.stringify({miniProgramData:t})),type:O.LOAD_PACKAGE,log:t})})}});function H(e){e=Re.call(this,e)||this;return e.taskHack=new ke,e}function Le(){this.onErrors=[],this.sends=[]}return n.use(r),n.use(we),n.use(he),n.use(xe),n.use(Ne),n.use(o),n.use(pe),n});
@@ -1,8 +1,8 @@
1
- import Core, { Config, SendOption, SendSuccess, SendFail, PayloadXHR, PayloadFetch, SpeedLog } from "../../core/src";
1
+ import Core, { Config, SendOption, SendSuccess, SendFail, SpeedLog } from "../../core/src";
2
2
  export interface CocosConfig extends Config {
3
3
  asyncPlugin?: boolean;
4
4
  reportApiSpeed?: boolean | {
5
- urlHandler: (url: string, payload: PayloadXHR | PayloadFetch) => string;
5
+ urlHandler: (url: string, payload: object) => string;
6
6
  };
7
7
  reportAssetSpeed?: boolean;
8
8
  performanceMonitor?: boolean;
@@ -1,5 +1,6 @@
1
1
  import { Config } from '../interface';
2
2
  export declare const REPORT_TIMEOUT = 5000;
3
3
  export declare const MAX_FAIL_REQUEST_NUM = 10;
4
+ export declare const MAX_LOG_LENGTH: number;
4
5
  export declare const getDefaultConfig: () => Config;
5
6
  export declare const setConfigUrl: (config: Config, hostUrl?: string) => Config;
@@ -1,3 +1,3 @@
1
- export { getDefaultConfig, setConfigUrl, REPORT_TIMEOUT, MAX_FAIL_REQUEST_NUM } from './config';
2
- export declare const completionKeys: string[];
1
+ export { getDefaultConfig, setConfigUrl, REPORT_TIMEOUT, MAX_FAIL_REQUEST_NUM, MAX_LOG_LENGTH } from './config';
2
+ export declare const COMPLETION_KEYS: string[];
3
3
  export * from './global';
@@ -39,6 +39,8 @@ export interface Config {
39
39
  resourceTypeHandler?: Function | undefined;
40
40
  retCodeHandler?: Function | undefined;
41
41
  retCodeCloudHandler?: Function | undefined;
42
+ reqParamHandler?: Function | undefined;
43
+ resBodyHandler?: Function | undefined;
42
44
  resHeaders?: Array<string>;
43
45
  reqHeaders?: Array<string>;
44
46
  };
@@ -51,7 +51,7 @@ export interface SpeedLog {
51
51
  ret?: string | number | 'unknown';
52
52
  status?: number;
53
53
  isErr?: number;
54
- payload?: object;
54
+ payload?: any;
55
55
  [key: string]: any;
56
56
  }
57
57
  export interface BridgeLog {
@@ -23,39 +23,17 @@ interface TryToGetRetCodeRsp {
23
23
  interface TryToGetRetCodeParams {
24
24
  url?: string;
25
25
  ctx?: any;
26
+ payload?: any;
26
27
  }
27
28
  export declare const tryToGetRetCodeAsync: (obj: any, api?: Record<string, any> | undefined, params?: TryToGetRetCodeParams | undefined, callback?: Function | undefined) => void;
28
29
  export declare const tryToGetRetCode: (obj: any, api?: Record<string, any> | undefined, params?: TryToGetRetCodeParams | undefined) => TryToGetRetCodeRsp;
30
+ export declare const formatApiDetail: (data: any, invokeFunc: Function | undefined, params: {
31
+ url?: string;
32
+ ctx?: any;
33
+ }) => string;
29
34
  export declare const stringifyPlus: (target: any) => string;
30
35
  export declare const stringify: (target: any) => string;
31
36
  export declare const stringifyObj: (obj: any, deep?: number) => string;
32
- /**
33
- * 获取xhr相关资源
34
- * 此类存在意义:是fetch请求和XMLHttpRequest请求的payload数据格式相同
35
- * @param {Any} data XMLHttpRequest对象
36
- */
37
- export declare class PayloadXHR {
38
- type: string;
39
- data: any | {};
40
- constructor(data: any);
41
- sourceURL(): string;
42
- status(): number;
43
- headers(): object;
44
- }
45
- /**
46
- * 获取fetch相关资源
47
- * 此类存在意义:是fetch请求和XMLHttpRequest请求的payload数据格式相同
48
- * @param {Any} data fetch请求的response对象
49
- */
50
- export declare class PayloadFetch {
51
- type: string;
52
- data: any | {};
53
- response: any | {};
54
- constructor(data: any, response: any);
55
- sourceURL(): string;
56
- status(): number;
57
- headers(): object;
58
- }
59
37
  export declare const generateAid: () => string;
60
38
  export declare const speedShim: (logs: SpeedLog | SpeedLog[] | BridgeLog | BridgeLog[], bean: any) => any;
61
39
  export declare const completeLogs: (logs: any, keys: string[] | string) => any;
@@ -1,8 +1,6 @@
1
- import Core, { Config, SendOption, SendSuccess, SendFail, PagePerformanceStruct } from "../../core/src";
1
+ import Core, { Config, SendOption, SendSuccess, SendFail } from "../../core/src";
2
+ import { RequestSchedule } from './util/request-schedule';
2
3
  import { SetDataConfig } from './interface';
3
- interface PagePerformanceConfig extends PagePerformanceStruct {
4
- setDataReportConfig?: SetDataConfig;
5
- }
6
4
  export interface MpConfig extends Config {
7
5
  reportApiSpeed?: boolean;
8
6
  reportAssetSpeed?: boolean;
@@ -13,22 +11,21 @@ export interface MpConfig extends Config {
13
11
  offlineLog?: boolean;
14
12
  offlineLogExp?: number;
15
13
  offlineLogLimit?: number;
16
- pagePerformance?: PagePerformanceConfig;
17
14
  enableHttp2?: boolean;
18
15
  setDataReportConfig?: SetDataConfig;
19
16
  }
20
17
  export default class Aegis extends Core {
21
18
  static sessionID: string;
22
19
  static asyncPluginIndex: number;
20
+ requestSchedule: RequestSchedule;
23
21
  originRequest: <T extends string | Record<string, any> | ArrayBuffer = string | Record<string, any> | ArrayBuffer>(option: WechatMiniprogram.RequestOption<T>) => WechatMiniprogram.RequestTask;
24
22
  speedLogPipeline: import("../../core/src").Pipeline<any, any>;
25
23
  constructor(config: MpConfig);
26
24
  get getBean(): string;
27
25
  initOfflineLog(): void;
28
- private requestQueue;
29
- private requesting;
30
- request: (options: SendOption, success?: SendSuccess | undefined, fail?: SendFail | undefined) => boolean | undefined;
26
+ initRequestSchedule(): void;
27
+ request: (options: SendOption, success?: SendSuccess | undefined, fail?: SendFail | undefined) => void;
28
+ private sendRequest;
31
29
  uploadLogs(params?: any, conds?: any): void;
32
30
  reportPv(id: number): void;
33
31
  }
34
- export {};
@@ -7,3 +7,4 @@ export declare class HackRequest extends HackApiCore<RequestOption, HackRequestC
7
7
  private hackHandler;
8
8
  }
9
9
  export declare const hackRequest: (option: HackRequestCallback) => HackRequest;
10
+ export declare const formatHeader: (headers: HeadersInit | undefined, reqHeaders: string[], tag: string) => string;
@@ -0,0 +1,17 @@
1
+ import { SendOption, SendSuccess, SendFail } from "../../../core/src";
2
+ declare type Task = {
3
+ options: SendOption;
4
+ success?: SendSuccess;
5
+ fail?: SendFail;
6
+ };
7
+ export declare class RequestSchedule {
8
+ private taskQueue;
9
+ private count;
10
+ private sendRequest;
11
+ private maxCount;
12
+ constructor(sendRequest: Function, maxCount?: number | undefined);
13
+ addTask: (task: Task) => void;
14
+ fireTask: () => void;
15
+ complete: () => void;
16
+ }
17
+ export {};
@@ -1,8 +1,8 @@
1
- import Core, { Config, SendOption, SendSuccess, SendFail, PayloadXHR, PayloadFetch } from "../../core/src";
1
+ import Core, { Config, SendOption, SendSuccess, SendFail } from "../../core/src";
2
2
  export interface WebConfig extends Config {
3
3
  asyncPlugin?: boolean;
4
4
  reportApiSpeed?: boolean | {
5
- urlHandler: (url: string, payload: PayloadXHR | PayloadFetch) => string;
5
+ urlHandler: (url: string, payload: object) => string;
6
6
  };
7
7
  reportAssetSpeed?: boolean;
8
8
  beforeReportSpeed?: Function;
@@ -0,0 +1,3 @@
1
+ import { Plugin } from "../../../core/src";
2
+ declare let plugin: Plugin<import("../../../core/src").default>;
3
+ export default plugin;
@@ -10,4 +10,5 @@ import offlineLog from './offline-log';
10
10
  import spa from './spa';
11
11
  import ie from './ie-patch';
12
12
  import onClose from './on-close';
13
- export { aid, assetSpeed, cgiSpeed, bridgeSpeed, device, onError, pagePerformance, webVitals, offlineLog, spa, ie, onClose, };
13
+ import fingerId from './fingerId';
14
+ export { aid, fingerId, assetSpeed, cgiSpeed, bridgeSpeed, device, onError, pagePerformance, webVitals, offlineLog, spa, ie, onClose, };
@@ -0,0 +1,2 @@
1
+ declare const hashTo32: (key: string) => string;
2
+ export { hashTo32, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aegis-mp-sdk",
3
- "version": "1.36.3",
3
+ "version": "1.36.4",
4
4
  "description": "aegis sdk for wechat and qq mini program",
5
5
  "author": "tickli <tickli@tencent.com>",
6
6
  "homepage": "",
@@ -22,9 +22,11 @@
22
22
  "test": "echo \"Error: run tests from root\" && exit 1"
23
23
  },
24
24
  "devDependencies": {
25
- "@types/sinon": "^9.0.0",
26
- "miniprogram-simulate": "^1.1.5",
27
- "sinon": "^9.2.3"
25
+ "@types/sinon": "^10.0.13",
26
+ "miniprogram-simulate": "^1.5.7",
27
+ "sinon": "^14.0.0"
28
28
  },
29
- "dependencies": {}
29
+ "dependencies": {
30
+ "miniprogram-api-typings": "^3.6.0"
31
+ }
30
32
  }
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- import '../../src/util/polyfill';
@@ -1 +0,0 @@
1
- export {};