@arms/rum-core 0.0.39 → 0.1.1
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/es/index.d.ts +3 -0
- package/es/index.js +3 -0
- package/es/model/client.d.ts +2 -1
- package/es/model/client.js +2 -2
- package/es/model/configManager.d.ts +58 -0
- package/es/model/configManager.js +177 -0
- package/es/model/context.d.ts +3 -1
- package/es/model/context.js +13 -2
- package/es/model/reporter.d.ts +2 -4
- package/es/model/reporter.js +53 -11
- package/es/model/shell.d.ts +1 -15
- package/es/model/shell.js +62 -52
- package/es/types/client.d.ts +60 -8
- package/es/types/client.js +6 -1
- package/es/types/config.d.ts +49 -0
- package/es/types/config.js +1 -0
- package/es/types/rum-event.d.ts +2 -0
- package/es/utils/base.d.ts +4 -4
- package/es/utils/base.js +70 -42
- package/es/utils/combineConfig.js +89 -101
- package/es/utils/match.d.ts +6 -0
- package/es/utils/match.js +34 -0
- package/es/utils/trace.d.ts +5 -1
- package/es/utils/url.d.ts +2 -0
- package/es/utils/url.js +61 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +21 -0
- package/lib/model/client.d.ts +2 -1
- package/lib/model/client.js +2 -2
- package/lib/model/configManager.d.ts +58 -0
- package/lib/model/configManager.js +182 -0
- package/lib/model/context.d.ts +3 -1
- package/lib/model/context.js +13 -2
- package/lib/model/reporter.d.ts +2 -4
- package/lib/model/reporter.js +54 -11
- package/lib/model/shell.d.ts +1 -15
- package/lib/model/shell.js +61 -53
- package/lib/types/client.d.ts +60 -8
- package/lib/types/client.js +5 -1
- package/lib/types/config.d.ts +49 -0
- package/lib/types/config.js +3 -0
- package/lib/types/rum-event.d.ts +2 -0
- package/lib/utils/base.d.ts +4 -4
- package/lib/utils/base.js +71 -43
- package/lib/utils/combineConfig.js +90 -107
- package/lib/utils/match.d.ts +6 -0
- package/lib/utils/match.js +35 -0
- package/lib/utils/trace.d.ts +5 -1
- package/lib/utils/url.d.ts +2 -0
- package/lib/utils/url.js +65 -0
- package/package.json +2 -2
- package/es/utils/combineConfig.d.ts +0 -15
- package/lib/utils/combineConfig.d.ts +0 -15
|
@@ -1,107 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
function getRemoteConfigUrl(config)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
function doCover(oldConfig, remoteConfig
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
oldConfig = {};
|
|
92
|
-
}
|
|
93
|
-
if (remoteConfig === void 0) {
|
|
94
|
-
remoteConfig = null;
|
|
95
|
-
}
|
|
96
|
-
if (!remoteConfig) return null;
|
|
97
|
-
if ((0, _base.getType)(oldConfig) !== 'object' || (0, _base.getType)(remoteConfig) !== 'object') return null;
|
|
98
|
-
var config = (0, _extends2["default"])({}, oldConfig);
|
|
99
|
-
// 先检查远程配置的,是否有需要将字符串格式化为正则的
|
|
100
|
-
(0, _base.toRegFormat)(remoteConfig, REG_FORMAT_PATHS);
|
|
101
|
-
// 执行覆盖
|
|
102
|
-
doCover(config, remoteConfig);
|
|
103
|
-
// 执行补充
|
|
104
|
-
doSupplement(config, remoteConfig);
|
|
105
|
-
return config;
|
|
106
|
-
}
|
|
107
|
-
var _default = exports["default"] = combineConfig;
|
|
1
|
+
// import{ getType, toRegFormat} from './base';
|
|
2
|
+
//
|
|
3
|
+
//
|
|
4
|
+
// // 需要检查是否需要字符串格式化为正则的配置路径
|
|
5
|
+
// const REG_FORMAT_PATHS = [
|
|
6
|
+
// 'filters.exception',
|
|
7
|
+
// 'filters.resource',
|
|
8
|
+
// 'tracing.allowedUrls.[].match'
|
|
9
|
+
// ];
|
|
10
|
+
//
|
|
11
|
+
// export function isRemoteConfigEnable(config: any) {
|
|
12
|
+
// return config.remoteConfig === true ||
|
|
13
|
+
// (config.remoteConfig && config.remoteConfig.enable !== false);
|
|
14
|
+
// }
|
|
15
|
+
//
|
|
16
|
+
// /**
|
|
17
|
+
// *
|
|
18
|
+
// * @param config
|
|
19
|
+
// * @returns
|
|
20
|
+
// */
|
|
21
|
+
// export function getRemoteConfigUrl(config: any){
|
|
22
|
+
// if(config.remoteConfig && config.remoteConfig.url) {
|
|
23
|
+
// return config.remoteConfig.url;
|
|
24
|
+
// }
|
|
25
|
+
// const sereis = config.pid.split('@');
|
|
26
|
+
// if(!sereis || sereis.length<2) return;
|
|
27
|
+
// const timestamp = Date.now();
|
|
28
|
+
// return `//${sereis[0]}-sdk.rum.aliyuncs.com/config/${config.remoteConfig.region || 'cn-hangzhou'}/${sereis[1]}?t=${timestamp}`;
|
|
29
|
+
// }
|
|
30
|
+
//
|
|
31
|
+
// /**
|
|
32
|
+
// *
|
|
33
|
+
// * @param oldConfig
|
|
34
|
+
// * @param remoteConfig
|
|
35
|
+
// */
|
|
36
|
+
// function doCover(oldConfig: any ={}, remoteConfig: any ={}){
|
|
37
|
+
// for(const key in oldConfig) {
|
|
38
|
+
// if(key === 'pid' || key === 'endpoint') continue;
|
|
39
|
+
// if(remoteConfig?.[key] === undefined) continue;
|
|
40
|
+
// const oldV = oldConfig[key];
|
|
41
|
+
// const newV = remoteConfig?.[key];
|
|
42
|
+
// if(getType(oldV) === 'object' && getType(newV) === 'object') {
|
|
43
|
+
// doCover(oldV, newV);
|
|
44
|
+
// } else {
|
|
45
|
+
// oldConfig[key] = newV;
|
|
46
|
+
// }
|
|
47
|
+
// }
|
|
48
|
+
// }
|
|
49
|
+
//
|
|
50
|
+
// /**
|
|
51
|
+
// *
|
|
52
|
+
// * @param oldConfig
|
|
53
|
+
// * @param remoteConfig
|
|
54
|
+
// */
|
|
55
|
+
// function doSupplement(oldConfig: any ={}, remoteConfig: any ={}) {
|
|
56
|
+
// for(const key in remoteConfig) {
|
|
57
|
+
// if(oldConfig?.[key] === undefined) {
|
|
58
|
+
// oldConfig[key] = remoteConfig[key];
|
|
59
|
+
// } else {
|
|
60
|
+
// const oldV = oldConfig[key];
|
|
61
|
+
// const newV = remoteConfig[key];
|
|
62
|
+
// if(getType(oldV) === 'object' && getType(newV) === 'object') {
|
|
63
|
+
// doSupplement(oldV, newV);
|
|
64
|
+
// }
|
|
65
|
+
// }
|
|
66
|
+
// }
|
|
67
|
+
// }
|
|
68
|
+
//
|
|
69
|
+
// /**
|
|
70
|
+
// *
|
|
71
|
+
// * @param oldConfig
|
|
72
|
+
// * @param remoteConfig
|
|
73
|
+
// * @returns config
|
|
74
|
+
// */
|
|
75
|
+
// function combineConfig(oldConfig={}, remoteConfig=null) {
|
|
76
|
+
// if(!remoteConfig) return null;
|
|
77
|
+
// if(getType(oldConfig) !== 'object' || getType(remoteConfig) !== 'object') return null;
|
|
78
|
+
// const config = {...oldConfig};
|
|
79
|
+
// // 先检查远程配置的,是否有需要将字符串格式化为正则的
|
|
80
|
+
// toRegFormat(remoteConfig, REG_FORMAT_PATHS);
|
|
81
|
+
// // 执行覆盖
|
|
82
|
+
// doCover(config, remoteConfig);
|
|
83
|
+
// // 执行补充
|
|
84
|
+
// doSupplement(config, remoteConfig);
|
|
85
|
+
// return config;
|
|
86
|
+
// }
|
|
87
|
+
//
|
|
88
|
+
//
|
|
89
|
+
// export default combineConfig;
|
|
90
|
+
"use strict";
|
package/lib/utils/match.d.ts
CHANGED
|
@@ -5,3 +5,9 @@ export declare function isMatchOption(item: unknown): item is MatchOption;
|
|
|
5
5
|
*/
|
|
6
6
|
export declare function matchList(list: MatchOption[], value: string, useStartsWith?: boolean, options?: unknown): boolean;
|
|
7
7
|
export declare function urlMatch(url: string, list?: MatchOption | MatchOption[]): boolean;
|
|
8
|
+
export interface IRule {
|
|
9
|
+
match: string;
|
|
10
|
+
match_exp: string;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
export declare function parseRule2Match(rule: IRule | MatchOption): MatchOption;
|
package/lib/utils/match.js
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.isMatchOption = isMatchOption;
|
|
5
5
|
exports.matchList = matchList;
|
|
6
|
+
exports.parseRule2Match = parseRule2Match;
|
|
6
7
|
exports.urlMatch = urlMatch;
|
|
7
8
|
var _is = require("./is");
|
|
8
9
|
var _polyfills = require("./polyfills");
|
|
10
|
+
var _base = require("./base");
|
|
9
11
|
function isMatchOption(item) {
|
|
10
12
|
return (0, _is.isString)(item) || (0, _is.isFunction)(item) || (0, _is.isRegExp)(item);
|
|
11
13
|
}
|
|
@@ -43,4 +45,37 @@ function urlMatch(url, list) {
|
|
|
43
45
|
} catch (e) {
|
|
44
46
|
return false;
|
|
45
47
|
}
|
|
48
|
+
}
|
|
49
|
+
function parseRule2Match(rule) {
|
|
50
|
+
if (isMatchOption(rule)) {
|
|
51
|
+
return rule;
|
|
52
|
+
}
|
|
53
|
+
var match;
|
|
54
|
+
switch (rule.match_exp) {
|
|
55
|
+
case 'equals':
|
|
56
|
+
match = function match(value) {
|
|
57
|
+
return value === rule.match;
|
|
58
|
+
};
|
|
59
|
+
break;
|
|
60
|
+
case 'not_equals':
|
|
61
|
+
match = function match(value) {
|
|
62
|
+
return value !== rule.match;
|
|
63
|
+
};
|
|
64
|
+
break;
|
|
65
|
+
case 'regex':
|
|
66
|
+
match = (0, _base.parseRegExpString)(rule.match);
|
|
67
|
+
break;
|
|
68
|
+
case 'includes':
|
|
69
|
+
match = function match(value) {
|
|
70
|
+
return value.includes(rule.match);
|
|
71
|
+
};
|
|
72
|
+
break;
|
|
73
|
+
case 'starts_with':
|
|
74
|
+
default:
|
|
75
|
+
match = function match(value) {
|
|
76
|
+
return (0, _polyfills.startsWith)(value, rule.match);
|
|
77
|
+
};
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
return match;
|
|
46
81
|
}
|
package/lib/utils/trace.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { MatchOption } from "./match";
|
|
2
2
|
export type PropagatorType = 'tracecontext' | 'b3' | 'b3multi' | 'jaeger' | 'sw8';
|
|
3
3
|
export type TraceOption = {
|
|
4
|
+
enable?: boolean;
|
|
5
|
+
sampling?: number;
|
|
4
6
|
match: MatchOption;
|
|
5
|
-
propagatorTypes
|
|
7
|
+
propagatorTypes?: PropagatorType[];
|
|
8
|
+
baggage?: boolean;
|
|
9
|
+
tracestate?: boolean;
|
|
6
10
|
};
|
|
7
11
|
export declare function isTraceOption(option: any): option is TraceOption;
|
|
8
12
|
export interface ITracingOption {
|
package/lib/utils/url.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.getUrlParams = getUrlParams;
|
|
5
|
+
var safeDecode = function safeDecode(str) {
|
|
6
|
+
// 添加空值检查
|
|
7
|
+
if (str.length === 0) return "";
|
|
8
|
+
try {
|
|
9
|
+
// 先处理加号,然后进行 URL 解码
|
|
10
|
+
return decodeURIComponent(str.replace(/\+/g, ' '));
|
|
11
|
+
} catch (_unused) {
|
|
12
|
+
// 解码失败时的降级处理:处理常见的 URL 编码字符
|
|
13
|
+
return str.replace(/\+/g, ' ').replace(/%20/g, ' ').replace(/%2F/g, '/').replace(/%3D/g, '=').replace(/%26/g, '&').replace(/%3F/g, '?');
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var getQueryString = function getQueryString(input) {
|
|
17
|
+
// 添加空值检查
|
|
18
|
+
if (input.length === 0) return "";
|
|
19
|
+
|
|
20
|
+
// 移除 hash 部分,然后提取查询字符串
|
|
21
|
+
var hashIndex = input.indexOf('#');
|
|
22
|
+
var withoutHash = hashIndex >= 0 ? input.slice(0, hashIndex) : input;
|
|
23
|
+
var queryStart = withoutHash.indexOf('?');
|
|
24
|
+
if (queryStart === -1) return "";
|
|
25
|
+
return withoutHash.slice(queryStart + 1);
|
|
26
|
+
};
|
|
27
|
+
function getUrlParams(input) {
|
|
28
|
+
// 输入验证:检查是否为有效字符串
|
|
29
|
+
if (typeof input !== 'string' || !input.trim()) return {};
|
|
30
|
+
var params = {};
|
|
31
|
+
var query = getQueryString(input);
|
|
32
|
+
|
|
33
|
+
// 提前检查空查询
|
|
34
|
+
if (!query) return params;
|
|
35
|
+
|
|
36
|
+
// 使用 for 循环提高性能
|
|
37
|
+
var pairs = query.split('&');
|
|
38
|
+
for (var i = 0; i < pairs.length; i++) {
|
|
39
|
+
var pair = pairs[i];
|
|
40
|
+
|
|
41
|
+
// 跳过空键值对
|
|
42
|
+
if (!pair) continue;
|
|
43
|
+
|
|
44
|
+
// 查找第一个等号作为分隔符
|
|
45
|
+
var separatorIndex = pair.indexOf('=');
|
|
46
|
+
// 检查键是否存在且不为空
|
|
47
|
+
if (separatorIndex <= 0) continue;
|
|
48
|
+
var key = safeDecode(pair.slice(0, separatorIndex));
|
|
49
|
+
// 处理值为空的情况(如 key=)
|
|
50
|
+
var value = separatorIndex < pair.length - 1 ? safeDecode(pair.slice(separatorIndex + 1)) : "";
|
|
51
|
+
|
|
52
|
+
// 处理重复键:将单个值转换为数组
|
|
53
|
+
var existing = params[key];
|
|
54
|
+
if (existing !== undefined) {
|
|
55
|
+
if (Array.isArray(existing)) {
|
|
56
|
+
existing.push(value);
|
|
57
|
+
} else {
|
|
58
|
+
params[key] = [existing, value];
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
params[key] = value;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return params;
|
|
65
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arms/rum-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "arms rum javascript sdk core",
|
|
5
5
|
"author": "guangli.fj <guangli.fj@alibaba-inc.com>",
|
|
6
6
|
"license": "ISC",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"start": "build-scripts build --watch",
|
|
24
24
|
"build": "build-scripts build --skip-demo",
|
|
25
25
|
"prepublishOnly": "npm run build",
|
|
26
|
-
"test": "
|
|
26
|
+
"test": "npm run build && jest ./__tests__"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"@babel/runtime": "^7.24.5"
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export declare function isRemoteConfigEnable(config: any): boolean;
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
* @param config
|
|
5
|
-
* @returns
|
|
6
|
-
*/
|
|
7
|
-
export declare function getRemoteConfigUrl(config: any): any;
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
* @param oldConfig
|
|
11
|
-
* @param remoteConfig
|
|
12
|
-
* @returns config
|
|
13
|
-
*/
|
|
14
|
-
declare function combineConfig(oldConfig?: {}, remoteConfig?: any): {};
|
|
15
|
-
export default combineConfig;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export declare function isRemoteConfigEnable(config: any): boolean;
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
* @param config
|
|
5
|
-
* @returns
|
|
6
|
-
*/
|
|
7
|
-
export declare function getRemoteConfigUrl(config: any): any;
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
* @param oldConfig
|
|
11
|
-
* @param remoteConfig
|
|
12
|
-
* @returns config
|
|
13
|
-
*/
|
|
14
|
-
declare function combineConfig(oldConfig?: {}, remoteConfig?: any): {};
|
|
15
|
-
export default combineConfig;
|