@arms/rum-core 0.0.40 → 0.1.2

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 (49) 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 +178 -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 +48 -9
  11. package/es/model/shell.d.ts +1 -15
  12. package/es/model/shell.js +23 -52
  13. package/es/types/client.d.ts +58 -7
  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 +1 -0
  18. package/es/utils/base.d.ts +4 -4
  19. package/es/utils/base.js +62 -33
  20. package/es/utils/match.d.ts +6 -0
  21. package/es/utils/match.js +34 -0
  22. package/es/utils/trace.d.ts +5 -1
  23. package/lib/index.d.ts +3 -0
  24. package/lib/index.js +21 -0
  25. package/lib/model/client.d.ts +2 -1
  26. package/lib/model/client.js +2 -2
  27. package/lib/model/configManager.d.ts +58 -0
  28. package/lib/model/configManager.js +183 -0
  29. package/lib/model/context.d.ts +3 -1
  30. package/lib/model/context.js +13 -2
  31. package/lib/model/reporter.d.ts +2 -4
  32. package/lib/model/reporter.js +48 -9
  33. package/lib/model/shell.d.ts +1 -15
  34. package/lib/model/shell.js +22 -53
  35. package/lib/types/client.d.ts +58 -7
  36. package/lib/types/client.js +5 -1
  37. package/lib/types/config.d.ts +49 -0
  38. package/lib/types/config.js +3 -0
  39. package/lib/types/rum-event.d.ts +1 -0
  40. package/lib/utils/base.d.ts +4 -4
  41. package/lib/utils/base.js +63 -34
  42. package/lib/utils/match.d.ts +6 -0
  43. package/lib/utils/match.js +35 -0
  44. package/lib/utils/trace.d.ts +5 -1
  45. package/package.json +1 -1
  46. package/es/utils/combineConfig.d.ts +0 -15
  47. package/es/utils/combineConfig.js +0 -101
  48. package/lib/utils/combineConfig.d.ts +0 -15
  49. package/lib/utils/combineConfig.js +0 -107
package/lib/utils/base.js CHANGED
@@ -9,8 +9,8 @@ exports.generateSpanId = generateSpanId;
9
9
  exports.generateTraceId = generateTraceId;
10
10
  exports.getType = getType;
11
11
  exports.interceptFunction = interceptFunction;
12
+ exports.parseRegExpString = parseRegExpString;
12
13
  exports.restoreFunction = restoreFunction;
13
- exports.toRegFormat = toRegFormat;
14
14
  exports.transStrToReg = transStrToReg;
15
15
  var _is = require("./is");
16
16
  // 类型匹配正则
@@ -187,42 +187,71 @@ function transStrToReg(str) {
187
187
  return str;
188
188
  }
189
189
 
190
+ // /**
191
+ // *
192
+ // * @param config 配置
193
+ // * @param keys 需要转换的字段
194
+ // */
195
+ // export function toRegFormat(config: any, keys: any[]) {
196
+ // if (getType(keys) === 'string') {
197
+ // keys = [keys];
198
+ // }
199
+ // for (let i = 0, len = keys.length; i < len; i++) {
200
+ // const paths = keys[i].split('.');
201
+ // const lastIndex = paths.length - 1;
202
+ // if (!config) break;
203
+ // let tmp = config;
204
+ // for (let j = 0, jlen = paths.length; j < jlen; j++) {
205
+ // if (paths[j] === '[]') {
206
+ // if (getType(tmp) === 'array') {
207
+ // let lastPath = paths.splice(j + 1);
208
+ // lastPath = lastPath.join('.');
209
+ // for (let x = 0, xlen = tmp.length; x < xlen; x++) {
210
+ // toRegFormat(tmp[x], lastPath);
211
+ // }
212
+ // }
213
+ // break;
214
+ // }
215
+ // // 最后一层了,需要往前一层才能修改对象
216
+ // if (lastIndex === j && getType(tmp[paths[j]]) === 'string') {
217
+ // tmp[paths[j]] = transStrToReg(tmp[paths[j]]);
218
+ // break;
219
+ // }
220
+ // tmp = tmp[paths[j]];
221
+ // if (!tmp) break;
222
+ // }
223
+ // if (!tmp || getType(tmp) !== 'array') continue;
224
+ // for (let j = 0, jlen = tmp.length; j < jlen; j++) {
225
+ // tmp[j] = transStrToReg(tmp[j]);
226
+ // }
227
+ // }
228
+ // }
229
+
190
230
  /**
191
- *
192
- * @param config 配置
193
- * @param keys 需要转换的字段
231
+ * 解析正则表达式字符串,支持 /pattern/flags 格式
232
+ * @param str 正则表达式字符串,如 "/a/ig" 或 "a"
233
+ * @returns RegExp 对象
194
234
  */
195
- function toRegFormat(config, keys) {
196
- if (getType(keys) === 'string') {
197
- keys = [keys];
235
+ function parseRegExpString(str) {
236
+ if (typeof str !== 'string') {
237
+ throw new TypeError('input must be a string');
198
238
  }
199
- for (var i = 0, len = keys.length; i < len; i++) {
200
- var paths = keys[i].split('.');
201
- var lastIndex = paths.length - 1;
202
- if (!config) break;
203
- var tmp = config;
204
- for (var j = 0, jlen = paths.length; j < jlen; j++) {
205
- if (paths[j] === '[]') {
206
- if (getType(tmp) === 'array') {
207
- var lastPath = paths.splice(j + 1);
208
- lastPath = lastPath.join('.');
209
- for (var x = 0, xlen = tmp.length; x < xlen; x++) {
210
- toRegFormat(tmp[x], lastPath);
211
- }
212
- }
213
- break;
214
- }
215
- // 最后一层了,需要往前一层才能修改对象
216
- if (lastIndex === j && getType(tmp[paths[j]]) === 'string') {
217
- tmp[paths[j]] = transStrToReg(tmp[paths[j]]);
218
- break;
219
- }
220
- tmp = tmp[paths[j]];
221
- if (!tmp) break;
222
- }
223
- if (!tmp || getType(tmp) !== 'array') continue;
224
- for (var _j = 0, _jlen = tmp.length; _j < _jlen; _j++) {
225
- tmp[_j] = transStrToReg(tmp[_j]);
239
+
240
+ // 检查是否是 /pattern/flags 格式
241
+ if (str.length > 2 && str[0] === '/') {
242
+ // 从后往前找最后一个 /,作为分隔符
243
+ var lastSlashIndex = str.lastIndexOf('/');
244
+ if (lastSlashIndex > 0) {
245
+ // 提取 pattern(第一个 / 和最后一个 / 之间的内容)
246
+ var pattern = str.substring(1, lastSlashIndex);
247
+ // 提取 flags(最后一个 / 之后的内容)
248
+ var flags = str.substring(lastSlashIndex + 1);
249
+ return new RegExp(pattern, flags);
226
250
  }
251
+ // 如果只有一个 /,当作 /pattern/ 格式处理(无 flags)
252
+ return new RegExp(str.substring(1, str.length - 1));
227
253
  }
254
+
255
+ // 如果不是 /pattern/flags 格式,直接作为 pattern 使用
256
+ return new RegExp(str);
228
257
  }
@@ -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 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arms/rum-core",
3
- "version": "0.0.40",
3
+ "version": "0.1.2",
4
4
  "description": "arms rum javascript sdk core",
5
5
  "author": "guangli.fj <guangli.fj@alibaba-inc.com>",
6
6
  "license": "ISC",
@@ -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,101 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/extends";
2
- import { getType, toRegFormat } from './base';
3
-
4
- // 需要检查是否需要字符串格式化为正则的配置路径
5
- var REG_FORMAT_PATHS = ['filters.exception', 'filters.resource', 'tracing.allowedUrls.[].match'];
6
- export function isRemoteConfigEnable(config) {
7
- return config.remoteConfig === true || config.remoteConfig && config.remoteConfig.enable !== false;
8
- }
9
-
10
- /**
11
- *
12
- * @param config
13
- * @returns
14
- */
15
- export function getRemoteConfigUrl(config) {
16
- if (config.remoteConfig && config.remoteConfig.url) {
17
- return config.remoteConfig.url;
18
- }
19
- var sereis = config.pid.split('@');
20
- if (!sereis || sereis.length < 2) return;
21
- var timestamp = Date.now();
22
- return "//" + sereis[0] + "-sdk.rum.aliyuncs.com/config/" + (config.remoteConfig.region || 'cn-hangzhou') + "/" + sereis[1] + "?t=" + timestamp;
23
- }
24
-
25
- /**
26
- *
27
- * @param oldConfig
28
- * @param remoteConfig
29
- */
30
- function doCover(oldConfig, remoteConfig) {
31
- if (oldConfig === void 0) {
32
- oldConfig = {};
33
- }
34
- if (remoteConfig === void 0) {
35
- remoteConfig = {};
36
- }
37
- for (var key in oldConfig) {
38
- var _remoteConfig, _remoteConfig2;
39
- if (key === 'pid' || key === 'endpoint') continue;
40
- if (((_remoteConfig = remoteConfig) === null || _remoteConfig === void 0 ? void 0 : _remoteConfig[key]) === undefined) continue;
41
- var oldV = oldConfig[key];
42
- var newV = (_remoteConfig2 = remoteConfig) === null || _remoteConfig2 === void 0 ? void 0 : _remoteConfig2[key];
43
- if (getType(oldV) === 'object' && getType(newV) === 'object') {
44
- doCover(oldV, newV);
45
- } else {
46
- oldConfig[key] = newV;
47
- }
48
- }
49
- }
50
-
51
- /**
52
- *
53
- * @param oldConfig
54
- * @param remoteConfig
55
- */
56
- function doSupplement(oldConfig, remoteConfig) {
57
- if (oldConfig === void 0) {
58
- oldConfig = {};
59
- }
60
- if (remoteConfig === void 0) {
61
- remoteConfig = {};
62
- }
63
- for (var key in remoteConfig) {
64
- var _oldConfig;
65
- if (((_oldConfig = oldConfig) === null || _oldConfig === void 0 ? void 0 : _oldConfig[key]) === undefined) {
66
- oldConfig[key] = remoteConfig[key];
67
- } else {
68
- var oldV = oldConfig[key];
69
- var newV = remoteConfig[key];
70
- if (getType(oldV) === 'object' && getType(newV) === 'object') {
71
- doSupplement(oldV, newV);
72
- }
73
- }
74
- }
75
- }
76
-
77
- /**
78
- *
79
- * @param oldConfig
80
- * @param remoteConfig
81
- * @returns config
82
- */
83
- function combineConfig(oldConfig, remoteConfig) {
84
- if (oldConfig === void 0) {
85
- oldConfig = {};
86
- }
87
- if (remoteConfig === void 0) {
88
- remoteConfig = null;
89
- }
90
- if (!remoteConfig) return null;
91
- if (getType(oldConfig) !== 'object' || getType(remoteConfig) !== 'object') return null;
92
- var config = _extends({}, oldConfig);
93
- // 先检查远程配置的,是否有需要将字符串格式化为正则的
94
- toRegFormat(remoteConfig, REG_FORMAT_PATHS);
95
- // 执行覆盖
96
- doCover(config, remoteConfig);
97
- // 执行补充
98
- doSupplement(config, remoteConfig);
99
- return config;
100
- }
101
- 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;
@@ -1,107 +0,0 @@
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;