@tmsfe/tms-core 0.0.90 → 0.0.93
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/package.json
CHANGED
|
@@ -3,17 +3,28 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
const maxArrLen = 10;
|
|
6
|
-
const maxStrLen =
|
|
6
|
+
const maxStrLen = 200;
|
|
7
7
|
const maxFieldLen = 20;
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
// 字符串字段白名单,白名单内的字段不截断
|
|
10
|
+
const fieldWhiteList = [
|
|
11
|
+
'tmapExtra', // 手图跳过来时附加的加密数据,用于分析用户操作路径,奉刚要求字段不能截断
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
function isBasicsType(obj: any, isConstraintLen = true): { isBasics: boolean, value: any } {
|
|
10
15
|
const type = typeof obj;
|
|
11
16
|
if (obj === null || obj === undefined
|
|
12
17
|
|| type === 'number' || type === 'boolean' || type === 'bigint') {
|
|
13
18
|
return { isBasics: true, value: obj };
|
|
14
19
|
}
|
|
15
20
|
if (type === 'string') {
|
|
16
|
-
|
|
21
|
+
// 简单判断是否encodeURIComponent字段,如果时的话则抛弃掉
|
|
22
|
+
// 因为在后端会被decode导致反序列化时语法错误
|
|
23
|
+
if (obj.match(/%/g)?.length >= 2) {
|
|
24
|
+
return { isBasics: true, value: '' };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const value = isConstraintLen ? obj.substring(0, maxStrLen) : obj;
|
|
17
28
|
return { isBasics: true, value };
|
|
18
29
|
}
|
|
19
30
|
if (type === 'function' || type === 'symbol') {
|
|
@@ -55,7 +66,8 @@ function deepClone(obj: any, depth = 0, maxDepth = 5): any {
|
|
|
55
66
|
continue;
|
|
56
67
|
}
|
|
57
68
|
const value = obj[name];
|
|
58
|
-
const
|
|
69
|
+
const isConstraintLen = !fieldWhiteList.includes(name);
|
|
70
|
+
const res1 = isBasicsType(value, isConstraintLen);
|
|
59
71
|
if (res1.isBasics) {
|
|
60
72
|
// @ts-ignore
|
|
61
73
|
newObj[name] = res1.value;
|
package/src/report/helper.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
// / <reference path='./types.ts'/>
|
|
6
6
|
import syncApi from '../syncfnmanager';
|
|
7
|
+
import clone from './clone';
|
|
7
8
|
|
|
8
9
|
function getTms(): any {
|
|
9
10
|
// 如果是在app.js的onLaunch中调用,则没有getApp().tms为空
|
|
@@ -33,7 +34,8 @@ function init(options: IInitOptions): void {
|
|
|
33
34
|
};
|
|
34
35
|
|
|
35
36
|
wx.onAppShow((options) => {
|
|
36
|
-
|
|
37
|
+
// 克隆函数内会限制对象字段
|
|
38
|
+
launchOptions = clone.deepClone(options);
|
|
37
39
|
});
|
|
38
40
|
}
|
|
39
41
|
|
|
@@ -145,6 +147,10 @@ function getPageInfo(): IPage {
|
|
|
145
147
|
options = page?.options;
|
|
146
148
|
depth = pages.length;
|
|
147
149
|
}
|
|
150
|
+
|
|
151
|
+
// 克隆函数内会限制对象字段
|
|
152
|
+
options = clone.deepClone(options);
|
|
153
|
+
|
|
148
154
|
// wx_navigate_before埋点上报时可能route是一个很大的对象而不是字符串,原因不详
|
|
149
155
|
if (typeof route as any !== 'string') {
|
|
150
156
|
route = '';
|
|
@@ -160,6 +166,8 @@ let launchOptions: any = null;
|
|
|
160
166
|
function getLaunchOptions(): any {
|
|
161
167
|
if (launchOptions === null) {
|
|
162
168
|
launchOptions = syncApi.getLaunchOptionsSync();
|
|
169
|
+
// 克隆函数内会限制对象字段
|
|
170
|
+
launchOptions = clone.deepClone(launchOptions);
|
|
163
171
|
}
|
|
164
172
|
return launchOptions;
|
|
165
173
|
}
|
package/src/report/proxy/app.ts
CHANGED
|
@@ -17,7 +17,19 @@ function proxyNavigateApi(api: string): void {
|
|
|
17
17
|
value(...args: any) {
|
|
18
18
|
const { url = '' } = args[0] || {};
|
|
19
19
|
const [path, params = ''] = url.split('?');
|
|
20
|
-
|
|
20
|
+
const data = {};
|
|
21
|
+
params.split('&').forEach((str: string) => {
|
|
22
|
+
const [key, val] = str.split('=');
|
|
23
|
+
let value = val || '';
|
|
24
|
+
// 简单判断是否encodeURIComponent字段,如果时的话则抛弃掉
|
|
25
|
+
// 因为在后端会被decode导致反序列化时语法错误
|
|
26
|
+
if (value.indexOf('%') !== -1) {
|
|
27
|
+
value = '';
|
|
28
|
+
}
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
data[key] = value;
|
|
31
|
+
});
|
|
32
|
+
helper.reportData(`wx_${api}_before`, path, data);
|
|
21
33
|
|
|
22
34
|
originalApi.apply(this, args);
|
|
23
35
|
},
|