@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.
Files changed (53) hide show
  1. package/es/index.d.ts +3 -0
  2. package/es/index.js +3 -0
  3. package/es/model/client.d.ts +2 -1
  4. package/es/model/client.js +2 -2
  5. package/es/model/configManager.d.ts +58 -0
  6. package/es/model/configManager.js +177 -0
  7. package/es/model/context.d.ts +3 -1
  8. package/es/model/context.js +13 -2
  9. package/es/model/reporter.d.ts +2 -4
  10. package/es/model/reporter.js +53 -11
  11. package/es/model/shell.d.ts +1 -15
  12. package/es/model/shell.js +62 -52
  13. package/es/types/client.d.ts +60 -8
  14. package/es/types/client.js +6 -1
  15. package/es/types/config.d.ts +49 -0
  16. package/es/types/config.js +1 -0
  17. package/es/types/rum-event.d.ts +2 -0
  18. package/es/utils/base.d.ts +4 -4
  19. package/es/utils/base.js +70 -42
  20. package/es/utils/combineConfig.js +89 -101
  21. package/es/utils/match.d.ts +6 -0
  22. package/es/utils/match.js +34 -0
  23. package/es/utils/trace.d.ts +5 -1
  24. package/es/utils/url.d.ts +2 -0
  25. package/es/utils/url.js +61 -0
  26. package/lib/index.d.ts +3 -0
  27. package/lib/index.js +21 -0
  28. package/lib/model/client.d.ts +2 -1
  29. package/lib/model/client.js +2 -2
  30. package/lib/model/configManager.d.ts +58 -0
  31. package/lib/model/configManager.js +182 -0
  32. package/lib/model/context.d.ts +3 -1
  33. package/lib/model/context.js +13 -2
  34. package/lib/model/reporter.d.ts +2 -4
  35. package/lib/model/reporter.js +54 -11
  36. package/lib/model/shell.d.ts +1 -15
  37. package/lib/model/shell.js +61 -53
  38. package/lib/types/client.d.ts +60 -8
  39. package/lib/types/client.js +5 -1
  40. package/lib/types/config.d.ts +49 -0
  41. package/lib/types/config.js +3 -0
  42. package/lib/types/rum-event.d.ts +2 -0
  43. package/lib/utils/base.d.ts +4 -4
  44. package/lib/utils/base.js +71 -43
  45. package/lib/utils/combineConfig.js +90 -107
  46. package/lib/utils/match.d.ts +6 -0
  47. package/lib/utils/match.js +35 -0
  48. package/lib/utils/trace.d.ts +5 -1
  49. package/lib/utils/url.d.ts +2 -0
  50. package/lib/utils/url.js +65 -0
  51. package/package.json +2 -2
  52. package/es/utils/combineConfig.d.ts +0 -15
  53. package/lib/utils/combineConfig.d.ts +0 -15
@@ -1,107 +1,90 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- exports.__esModule = true;
5
- exports["default"] = void 0;
6
- exports.getRemoteConfigUrl = getRemoteConfigUrl;
7
- exports.isRemoteConfigEnable = isRemoteConfigEnable;
8
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
- var _base = require("./base");
10
- // 需要检查是否需要字符串格式化为正则的配置路径
11
- var REG_FORMAT_PATHS = ['filters.exception', 'filters.resource', 'tracing.allowedUrls.[].match'];
12
- function isRemoteConfigEnable(config) {
13
- return config.remoteConfig === true || config.remoteConfig && config.remoteConfig.enable !== false;
14
- }
15
-
16
- /**
17
- *
18
- * @param config
19
- * @returns
20
- */
21
- function getRemoteConfigUrl(config) {
22
- if (config.remoteConfig && config.remoteConfig.url) {
23
- return config.remoteConfig.url;
24
- }
25
- var sereis = config.pid.split('@');
26
- if (!sereis || sereis.length < 2) return;
27
- var 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, remoteConfig) {
37
- if (oldConfig === void 0) {
38
- oldConfig = {};
39
- }
40
- if (remoteConfig === void 0) {
41
- remoteConfig = {};
42
- }
43
- for (var key in oldConfig) {
44
- var _remoteConfig, _remoteConfig2;
45
- if (key === 'pid' || key === 'endpoint') continue;
46
- if (((_remoteConfig = remoteConfig) === null || _remoteConfig === void 0 ? void 0 : _remoteConfig[key]) === undefined) continue;
47
- var oldV = oldConfig[key];
48
- var newV = (_remoteConfig2 = remoteConfig) === null || _remoteConfig2 === void 0 ? void 0 : _remoteConfig2[key];
49
- if ((0, _base.getType)(oldV) === 'object' && (0, _base.getType)(newV) === 'object') {
50
- doCover(oldV, newV);
51
- } else {
52
- oldConfig[key] = newV;
53
- }
54
- }
55
- }
56
-
57
- /**
58
- *
59
- * @param oldConfig
60
- * @param remoteConfig
61
- */
62
- function doSupplement(oldConfig, remoteConfig) {
63
- if (oldConfig === void 0) {
64
- oldConfig = {};
65
- }
66
- if (remoteConfig === void 0) {
67
- remoteConfig = {};
68
- }
69
- for (var key in remoteConfig) {
70
- var _oldConfig;
71
- if (((_oldConfig = oldConfig) === null || _oldConfig === void 0 ? void 0 : _oldConfig[key]) === undefined) {
72
- oldConfig[key] = remoteConfig[key];
73
- } else {
74
- var oldV = oldConfig[key];
75
- var newV = remoteConfig[key];
76
- if ((0, _base.getType)(oldV) === 'object' && (0, _base.getType)(newV) === 'object') {
77
- doSupplement(oldV, newV);
78
- }
79
- }
80
- }
81
- }
82
-
83
- /**
84
- *
85
- * @param oldConfig
86
- * @param remoteConfig
87
- * @returns config
88
- */
89
- function combineConfig(oldConfig, remoteConfig) {
90
- if (oldConfig === void 0) {
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";
@@ -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;
@@ -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
  }
@@ -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: PropagatorType[];
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 {
@@ -0,0 +1,2 @@
1
+ export type UrlParams = Record<string, string | string[]>;
2
+ export declare function getUrlParams(input: string): UrlParams;
@@ -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.0.39",
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": "node ./__tests__/@arms/core.test.js"
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;