@arms/rum-core 0.0.40 → 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 (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 +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 +48 -9
  11. package/es/model/shell.d.ts +1 -15
  12. package/es/model/shell.js +62 -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/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/lib/index.d.ts +3 -0
  25. package/lib/index.js +21 -0
  26. package/lib/model/client.d.ts +2 -1
  27. package/lib/model/client.js +2 -2
  28. package/lib/model/configManager.d.ts +58 -0
  29. package/lib/model/configManager.js +182 -0
  30. package/lib/model/context.d.ts +3 -1
  31. package/lib/model/context.js +13 -2
  32. package/lib/model/reporter.d.ts +2 -4
  33. package/lib/model/reporter.js +48 -9
  34. package/lib/model/shell.d.ts +1 -15
  35. package/lib/model/shell.js +61 -53
  36. package/lib/types/client.d.ts +58 -7
  37. package/lib/types/client.js +5 -1
  38. package/lib/types/config.d.ts +49 -0
  39. package/lib/types/config.js +3 -0
  40. package/lib/types/rum-event.d.ts +1 -0
  41. package/lib/utils/base.d.ts +4 -4
  42. package/lib/utils/base.js +63 -34
  43. package/lib/utils/combineConfig.js +90 -107
  44. package/lib/utils/match.d.ts +6 -0
  45. package/lib/utils/match.js +35 -0
  46. package/lib/utils/trace.d.ts +5 -1
  47. package/package.json +1 -1
  48. package/es/utils/combineConfig.d.ts +0 -15
  49. package/lib/utils/combineConfig.d.ts +0 -15
@@ -0,0 +1,49 @@
1
+ import { IConfiguration } from './client';
2
+ export interface ICacheConfiguration {
3
+ /**
4
+ * 时间戳
5
+ */
6
+ timestamp: number;
7
+ /**
8
+ * 内容
9
+ */
10
+ content: any;
11
+ }
12
+ /**
13
+ * 配置管理器接口
14
+ * 统一管理配置的获取、存储、合并等操作
15
+ */
16
+ export interface IConfigManager {
17
+ /**
18
+ * 初始化配置管理器
19
+ * @param config 初始配置
20
+ */
21
+ init(config: IConfiguration): Promise<void> | void;
22
+ /**
23
+ * 获取配置
24
+ * @returns 配置数据
25
+ */
26
+ getConfig(): Promise<IConfiguration> | any;
27
+ /**
28
+ * 更新配置
29
+ * @param config 新配置
30
+ */
31
+ setConfig(config: Partial<IConfiguration>): Promise<void> | void;
32
+ /**
33
+ * 抽象方法:获取远程配置
34
+ * 各平台需要实现此方法来适配不同的网络请求方式
35
+ * @param config 当前配置
36
+ */
37
+ fetchRemoteCfg(config: IConfiguration): Promise<any>;
38
+ /**
39
+ * 合并配置
40
+ * @param baseConfig 基础配置
41
+ * @param remoteConfig 远程配置
42
+ * @returns 合并后的配置
43
+ */
44
+ mergeRemoteCfg(baseConfig: IConfiguration, remoteConfig: any): IConfiguration | null;
45
+ /**
46
+ * 销毁配置管理器
47
+ */
48
+ destroy(): void;
49
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
@@ -176,5 +176,6 @@ export interface RumEventBundle {
176
176
  events: Array<RumEvent>;
177
177
  properties?: BaseObject;
178
178
  _v?: string;
179
+ _retry?: number;
179
180
  [key: string]: unknown;
180
181
  }
@@ -53,8 +53,8 @@ export declare function getType(obj: any): any;
53
53
  */
54
54
  export declare function transStrToReg(str: string): string | RegExp;
55
55
  /**
56
- *
57
- * @param config 配置
58
- * @param keys 需要转换的字段
56
+ * 解析正则表达式字符串,支持 /pattern/flags 格式
57
+ * @param str 正则表达式字符串,如 "/a/ig" 或 "a"
58
+ * @returns RegExp 对象
59
59
  */
60
- export declare function toRegFormat(config: any, keys: any[]): void;
60
+ export declare function parseRegExpString(str: string): RegExp;
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
  }
@@ -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 {
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.1",
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,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;