@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
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ exports.__esModule = true;
5
+ exports.ConfigManager = void 0;
6
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
7
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
8
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
9
+ function parseRemoteConfig(config) {
10
+ var remoteConfig = config.remoteConfig || {};
11
+ return {
12
+ enable: remoteConfig.enable !== false && !!(remoteConfig.url || remoteConfig.region),
13
+ url: remoteConfig.url || '',
14
+ mode: remoteConfig.mode || 'launch-first',
15
+ cacheTimeout: remoteConfig.cacheTimeout || 3600000,
16
+ region: remoteConfig.region
17
+ };
18
+ }
19
+
20
+ /**
21
+ * 配置管理器
22
+ * 提供配置管理的通用实现,各平台可以继承并实现特定方法
23
+ */
24
+ var ConfigManager = exports.ConfigManager = /*#__PURE__*/function () {
25
+ function ConfigManager() {
26
+ this.currentConfig = null;
27
+ this.initialized = false;
28
+ }
29
+ var _proto = ConfigManager.prototype;
30
+ /**
31
+ * 初始化配置管理器
32
+ * @param config 初始配置
33
+ */
34
+ _proto.init =
35
+ /*#__PURE__*/
36
+ function () {
37
+ var _init = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee(config) {
38
+ var _this = this;
39
+ var remoteConfig, cacheConfig, asyncConfigPromise;
40
+ return _regenerator["default"].wrap(function _callee$(_context) {
41
+ while (1) switch (_context.prev = _context.next) {
42
+ case 0:
43
+ if (!this.initialized) {
44
+ _context.next = 2;
45
+ break;
46
+ }
47
+ return _context.abrupt("return");
48
+ case 2:
49
+ this.currentConfig = (0, _extends2["default"])({}, config);
50
+ this.initialized = true;
51
+ remoteConfig = parseRemoteConfig(config);
52
+ this.currentConfig.remoteConfig = remoteConfig;
53
+ if (remoteConfig.enable) {
54
+ _context.next = 8;
55
+ break;
56
+ }
57
+ return _context.abrupt("return");
58
+ case 8:
59
+ _context.next = 10;
60
+ return this.getCacheConfig();
61
+ case 10:
62
+ cacheConfig = _context.sent;
63
+ if (cacheConfig && cacheConfig.content) {
64
+ this.currentConfig = this.mergeRemoteCfg(cacheConfig.content);
65
+ }
66
+ if (!this.isCacheValid(cacheConfig, remoteConfig.cacheTimeout)) {
67
+ _context.next = 14;
68
+ break;
69
+ }
70
+ return _context.abrupt("return");
71
+ case 14:
72
+ asyncConfigPromise = this.fetchRemoteCfg(this.currentConfig).then(function (resp) {
73
+ if (!resp) return;
74
+ var asyncRemoteConfig = _this.parseConfig(resp);
75
+ _this.currentConfig = _this.mergeRemoteCfg(asyncRemoteConfig);
76
+ _this.setCacheConfig({
77
+ timestamp: Date.now(),
78
+ content: resp
79
+ });
80
+ });
81
+ if (!(remoteConfig.mode === 'remote-first')) {
82
+ _context.next = 18;
83
+ break;
84
+ }
85
+ _context.next = 18;
86
+ return asyncConfigPromise;
87
+ case 18:
88
+ case "end":
89
+ return _context.stop();
90
+ }
91
+ }, _callee, this);
92
+ }));
93
+ function init(_x) {
94
+ return _init.apply(this, arguments);
95
+ }
96
+ return init;
97
+ }()
98
+ /**
99
+ * 获取配置
100
+ * @returns 配置数据
101
+ */
102
+ ;
103
+ _proto.getConfig = function getConfig() {
104
+ if (!this.currentConfig) {
105
+ throw new Error('Config not initialized');
106
+ }
107
+ return this.currentConfig;
108
+ }
109
+
110
+ /**
111
+ * 更新配置
112
+ * @param config 新配置
113
+ */;
114
+ _proto.setConfig =
115
+ /*#__PURE__*/
116
+ function () {
117
+ var _setConfig = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2(config) {
118
+ return _regenerator["default"].wrap(function _callee2$(_context2) {
119
+ while (1) switch (_context2.prev = _context2.next) {
120
+ case 0:
121
+ if (this.currentConfig) {
122
+ _context2.next = 2;
123
+ break;
124
+ }
125
+ return _context2.abrupt("return");
126
+ case 2:
127
+ this.currentConfig = (0, _extends2["default"])({}, this.currentConfig, config);
128
+ case 3:
129
+ case "end":
130
+ return _context2.stop();
131
+ }
132
+ }, _callee2, this);
133
+ }));
134
+ function setConfig(_x2) {
135
+ return _setConfig.apply(this, arguments);
136
+ }
137
+ return setConfig;
138
+ }()
139
+ /**
140
+ * 检查缓存是否有效
141
+ * @param cachedData 缓存数据
142
+ * @param cacheTimeout 缓存超时时间
143
+ */
144
+ ;
145
+ _proto.isCacheValid = function isCacheValid(cachedData, cacheTimeout) {
146
+ if (!cachedData || !cachedData.timestamp) {
147
+ return false;
148
+ }
149
+ var timeout = cacheTimeout || 3600000; // 默认1小时
150
+ return Date.now() - cachedData.timestamp < timeout;
151
+ }
152
+
153
+ /**
154
+ * 合并配置
155
+ * @param remoteCfg 远程配置
156
+ * @returns 合并后的配置
157
+ */;
158
+ _proto.mergeRemoteCfg = function mergeRemoteCfg(remoteCfg) {
159
+ var _this$currentConfig = this.currentConfig,
160
+ pid = _this$currentConfig.pid,
161
+ app = _this$currentConfig.app,
162
+ endpoint = _this$currentConfig.endpoint,
163
+ remoteConfig = _this$currentConfig.remoteConfig,
164
+ beforeReport = _this$currentConfig.beforeReport,
165
+ properties = _this$currentConfig.properties;
166
+ return (0, _extends2["default"])({}, this.currentConfig, remoteCfg, {
167
+ pid: pid,
168
+ app: app,
169
+ endpoint: endpoint,
170
+ remoteConfig: remoteConfig,
171
+ beforeReport: beforeReport,
172
+ properties: properties
173
+ });
174
+ };
175
+ /**
176
+ * 销毁配置管理器
177
+ */
178
+ _proto.destroy = function destroy() {
179
+ this.currentConfig = null;
180
+ this.initialized = false;
181
+ };
182
+ return ConfigManager;
183
+ }();
@@ -1,11 +1,13 @@
1
1
  import { IConfiguration, IContext, IRumSession } from "../types/client";
2
2
  import { RumEvent, IViewData } from "../types/rum-event";
3
+ import { IConfigManager } from "../types/config";
3
4
  declare class Context implements IContext {
4
5
  private config;
5
6
  private rumEvent;
6
7
  private views;
7
8
  session: IRumSession;
8
- constructor(config: IConfiguration, rumSession?: IRumSession);
9
+ configManager: IConfigManager;
10
+ constructor(config: IConfiguration, rumSession?: IRumSession, configManager?: IConfigManager);
9
11
  getConfig(): IConfiguration;
10
12
  setConfig(config: IConfiguration): void;
11
13
  getViews(): IViewData[];
@@ -3,22 +3,33 @@
3
3
  exports.__esModule = true;
4
4
  exports["default"] = void 0;
5
5
  var Context = /*#__PURE__*/function () {
6
- function Context(config, rumSession) {
6
+ function Context(config, rumSession, configManager) {
7
7
  this.config = config;
8
8
  this.rumEvent = void 0;
9
9
  this.views = [];
10
10
  this.session = void 0;
11
+ this.configManager = void 0;
11
12
  if (rumSession) {
12
13
  this.session = rumSession;
13
14
  this.session.init(this);
14
15
  }
16
+ if (configManager) {
17
+ this.configManager = configManager;
18
+ }
15
19
  }
16
20
  var _proto = Context.prototype;
17
21
  _proto.getConfig = function getConfig() {
22
+ if (this.configManager) {
23
+ return this.configManager.getConfig();
24
+ }
18
25
  return this.config;
19
26
  };
20
27
  _proto.setConfig = function setConfig(config) {
21
- this.config = config;
28
+ if (this.configManager) {
29
+ this.configManager.setConfig(config);
30
+ } else {
31
+ this.config = config;
32
+ }
22
33
  };
23
34
  _proto.getViews = function getViews() {
24
35
  return this.views;
@@ -10,10 +10,7 @@ export default abstract class Reporter {
10
10
  protected ctx: IContext;
11
11
  private timer;
12
12
  private _init;
13
- getReportCfg(): {
14
- flushTime?: number;
15
- maxEventCount?: number;
16
- };
13
+ getReportCfg(): import("../types/client").IReportConfig;
17
14
  report(ctx: IContext): void;
18
15
  private pushToQueue;
19
16
  /**
@@ -21,6 +18,7 @@ export default abstract class Reporter {
21
18
  */
22
19
  protected flushEventQueue(): void;
23
20
  mergeEvent(ctx: IContext, events: RumEvent[], view: IViewData): void;
21
+ private tryRequest;
24
22
  /**
25
23
  * 接口请求由各平台 sdk reporter 实现
26
24
  */
@@ -3,6 +3,8 @@
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
  exports.__esModule = true;
5
5
  exports["default"] = void 0;
6
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
7
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
6
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
7
9
  var _rumEvent = require("../types/rum-event");
8
10
  var _exception = require("../utils/exception");
@@ -188,17 +190,54 @@ var Reporter = exports["default"] = /*#__PURE__*/function () {
188
190
  bundle = config.beforeReport(bundle);
189
191
  if (!bundle) return;
190
192
  }
191
- this.request(ctx, bundle);
192
- }
193
-
194
- // /**
195
- // * 接口请求由各平台 sdk reporter 实现
196
- // */
197
- // abstract request(ctx: IContext, events: RumEvent[], view: IViewData): void;
198
-
193
+ this.tryRequest(bundle);
194
+ };
195
+ _proto.tryRequest = /*#__PURE__*/function () {
196
+ var _tryRequest = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee(bundle, retry) {
197
+ var _this$ctx$getConfig,
198
+ _reportConfig$maxRetr,
199
+ _reportConfig$retryDe,
200
+ _this2 = this;
201
+ var reportConfig, maxRetryCount, retryDelay;
202
+ return _regenerator["default"].wrap(function _callee$(_context) {
203
+ while (1) switch (_context.prev = _context.next) {
204
+ case 0:
205
+ if (retry === void 0) {
206
+ retry = 0;
207
+ }
208
+ reportConfig = (_this$ctx$getConfig = this.ctx.getConfig()) === null || _this$ctx$getConfig === void 0 ? void 0 : _this$ctx$getConfig.reportConfig;
209
+ maxRetryCount = (_reportConfig$maxRetr = reportConfig === null || reportConfig === void 0 ? void 0 : reportConfig.maxRetryCount) !== null && _reportConfig$maxRetr !== void 0 ? _reportConfig$maxRetr : 0;
210
+ retryDelay = (_reportConfig$retryDe = reportConfig === null || reportConfig === void 0 ? void 0 : reportConfig.retryDelay) !== null && _reportConfig$retryDe !== void 0 ? _reportConfig$retryDe : 3000;
211
+ _context.prev = 4;
212
+ bundle._retry = retry;
213
+ _context.next = 8;
214
+ return this.request(this.ctx, bundle);
215
+ case 8:
216
+ _context.next = 13;
217
+ break;
218
+ case 10:
219
+ _context.prev = 10;
220
+ _context.t0 = _context["catch"](4);
221
+ if (retry < maxRetryCount - 1) {
222
+ setTimeout(function () {
223
+ return _this2.tryRequest(bundle, retry + 1);
224
+ }, retryDelay);
225
+ }
226
+ case 13:
227
+ case "end":
228
+ return _context.stop();
229
+ }
230
+ }, _callee, this, [[4, 10]]);
231
+ }));
232
+ function tryRequest(_x, _x2) {
233
+ return _tryRequest.apply(this, arguments);
234
+ }
235
+ return tryRequest;
236
+ }()
199
237
  /**
200
238
  * 接口请求由各平台 sdk reporter 实现
201
- */;
239
+ */
240
+ ;
202
241
  /**
203
242
  * 初始化时
204
243
  */
@@ -4,29 +4,15 @@ import { IShell } from "../types/shell";
4
4
  export default abstract class Shell implements IShell {
5
5
  client: IClient;
6
6
  constructor(config?: IConfiguration);
7
- getCombinedConfig(config?: IConfiguration): any;
8
- updateFromRemoteConfig(config: any, reSetup?: boolean): void;
9
7
  /**
10
8
  * 初始化
11
9
  */
12
- abstract init(configuration: IConfiguration): void;
10
+ abstract init(configuration: IConfiguration): Promise<Shell> | Shell;
13
11
  sendEvent(payload: RumEvent): void;
14
12
  /**
15
13
  * get config
16
14
  */
17
15
  getConfig(): IConfiguration;
18
- /**
19
- * 获取远程配置
20
- */
21
- abstract getRemoteConfig(url: string, config: any): object;
22
- /**
23
- * 存储远程配置到本地
24
- */
25
- abstract storeRemoteConfig(config: any, pid: string): boolean;
26
- /**
27
- * 提取本地存储的配置
28
- */
29
- abstract getLocalConfig(duration: number, pid: string): any;
30
16
  /**
31
17
  * set config
32
18
  */
@@ -7,70 +7,39 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
7
7
  var _rumEvent = require("../types/rum-event");
8
8
  var _client = _interopRequireDefault(require("../model/client"));
9
9
  var _is = require("../utils/is");
10
- var _combineConfig = _interopRequireWildcard(require("../utils/combineConfig"));
11
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
12
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
13
10
  var Shell = exports["default"] = /*#__PURE__*/function () {
14
11
  function Shell(config) {
12
+ // private callbacks: Function[] = [];
13
+ // private initialized = false;
15
14
  this.client = void 0;
16
15
  this.client = new _client["default"]();
17
16
  if (config && this.init) {
18
17
  this.init(config);
18
+ // const p = this.init(config) as Promise<Shell>;
19
+ // if(isFunction(p?.then)){
20
+ // p.then(this.shellReady);
21
+ // } else {
22
+ // this.shellReady()
23
+ // }
19
24
  }
20
- // if (config && this.init) {
21
- // this.init(this.getCombinedConfig(config));
22
-
23
- // // 拉取远程配置进行更新
24
- // this.updateFromRemoteConfig(config);
25
- // }
26
25
  }
27
- var _proto = Shell.prototype;
28
- _proto.getCombinedConfig = function getCombinedConfig(config) {
29
- var combinedConf;
30
- if ((0, _combineConfig.isRemoteConfigEnable)(config) && (0, _is.isFunction)(this.getLocalConfig)) {
31
- var localConfig = this.getLocalConfig(0, config.pid);
32
- combinedConf = (0, _combineConfig["default"])(config, localConfig);
33
- }
34
- return combinedConf || config;
35
- };
36
- _proto.updateFromRemoteConfig = function updateFromRemoteConfig(config, reSetup) {
37
- if (reSetup === void 0) {
38
- reSetup = true;
39
- }
40
- // 请求动态配置
41
- if (config.pid && (0, _combineConfig.isRemoteConfigEnable)(config) && (0, _is.isFunction)(this.getRemoteConfig)) {
42
- var that = this;
43
- var proms = this.getRemoteConfig((0, _combineConfig.getRemoteConfigUrl)(config), config);
44
- proms === null || proms === void 0 ? void 0 : proms.then(function (remoteConfig) {
45
- if (!remoteConfig || remoteConfig.errorStatus !== undefined) return;
46
- var combinedConf = (0, _combineConfig["default"])(config, remoteConfig);
47
26
 
48
- // 无有效的新配置,无需更新
49
- if (!combinedConf) return;
50
-
51
- // 存储到本地
52
- if ((0, _is.isFunction)(that.storeRemoteConfig)) {
53
- that.storeRemoteConfig(remoteConfig, config.pid);
54
- }
55
- if (reSetup === false || config.remoteConfig.reSetup === false) return;
56
- var context = that.client.getContext();
57
- // 更新配置
58
- context.setConfig(combinedConf);
59
- // 逐个更新collector
60
- var collectors = that.client.getCollectors();
61
- collectors.forEach(function (collector) {
62
- if ((0, _is.isFunction)(collector.destroy)) {
63
- collector.destroy();
64
- collector.setup(context, that.client.sendEvent);
65
- }
66
- });
67
- });
68
- }
69
- }
27
+ // private shellReady = () => {
28
+ // this.initialized = true;
29
+ // this.callbacks.forEach(cb => cb());
30
+ // }
31
+ //
32
+ // onReady(callback: Function) {
33
+ // if (this.initialized) {
34
+ // callback();
35
+ // }
36
+ // this.callbacks.push(callback);
37
+ // }
70
38
 
71
39
  /**
72
40
  * 初始化
73
- */;
41
+ */
42
+ var _proto = Shell.prototype;
74
43
  _proto.sendEvent = function sendEvent(payload) {
75
44
  if (this.client) {
76
45
  this.client.sendEvent(payload);
@@ -87,7 +56,7 @@ var Shell = exports["default"] = /*#__PURE__*/function () {
87
56
  }
88
57
 
89
58
  /**
90
- * 获取远程配置
59
+ * set config
91
60
  */;
92
61
  /**
93
62
  * 自定义事件上报
@@ -3,6 +3,7 @@ import { IProcessor } from './processor';
3
3
  import { IReporter } from './reporter';
4
4
  import { RumEvent, RumEventBundle, IViewData } from './rum-event';
5
5
  import { MatchOption } from "../utils/match";
6
+ import { IConfigManager } from "./config";
6
7
  export declare enum EventType {
7
8
  /**
8
9
  * 收集数据
@@ -35,6 +36,12 @@ export interface SessionConfig {
35
36
  overtime?: number;
36
37
  storage?: string;
37
38
  }
39
+ export interface IReportConfig {
40
+ flushTime?: number;
41
+ maxEventCount?: number;
42
+ maxRetryCount?: number;
43
+ retryDelay?: number;
44
+ }
38
45
  export interface IRumSession {
39
46
  init(ctx: IContext): void;
40
47
  sessionConfig: SessionConfig;
@@ -46,11 +53,54 @@ export interface IRumSession {
46
53
  getUserId: () => string;
47
54
  getBaseEvent: () => any;
48
55
  }
56
+ /**
57
+ * 远端监控配置接口
58
+ * @remarks 用于控制RUM数据采集的远程配置策略
59
+ */
60
+ export interface IRemoteConfig {
61
+ /**
62
+ * 是否启用远端配置 (default: false)
63
+ * @example true - 开启云端配置动态管控
64
+ */
65
+ enable?: boolean;
66
+ /**
67
+ * 配置服务器URL (required when enable=true)
68
+ * @format URL
69
+ */
70
+ url?: string;
71
+ /**
72
+ * 配置获取策略模式 (default: 'launch-first')
73
+ * @enum
74
+ * - 'launch-first': 启动优先模式,先使用本地配置快速启动,异步获取最新配置
75
+ * - 'remote-first': 云端优先模式,阻塞等待云端配置,超时后降级到本地
76
+ */
77
+ mode?: 'launch-first' | 'remote-first';
78
+ /**
79
+ * 配置缓存有效期(单位:毫秒,默认:3600000/1小时)
80
+ * @remarks 控制本地配置缓存刷新频率,超时后重新请求云端配置
81
+ * @example 1800000 - 30分钟更新一次配置
82
+ */
83
+ cacheTimeout?: number;
84
+ /**
85
+ * 配置远程配置拉取Region,兼容 0.0.x 版本远端配置
86
+ * @remarks 拉取远端配置地域
87
+ * @example cn-hangzhou 国内主要地区
88
+ */
89
+ region?: string;
90
+ [key: string]: unknown;
91
+ }
92
+ export interface ICollectorConfig {
93
+ name: string;
94
+ enable?: boolean;
95
+ sampling?: number;
96
+ filters?: MatchOption[];
97
+ [key: string]: unknown;
98
+ }
49
99
  export interface IClient {
50
100
  /**
51
101
  * 初始化
52
102
  */
53
- init: (configuration: IConfiguration, rumSession?: IRumSession) => void;
103
+ init: (configuration: IConfiguration, rumSession?: IRumSession, configManager?: IConfigManager) => void;
54
104
  /**
55
105
  * 业务自定义上传数据
56
106
  */
@@ -81,6 +131,10 @@ export interface IClient {
81
131
  useReporter(reporter: IReporter): void;
82
132
  }
83
133
  export interface IConfiguration {
134
+ /**
135
+ * 是否开启SDK
136
+ */
137
+ enable?: boolean;
84
138
  /**
85
139
  * 项目 id
86
140
  * v0.0.40开始,不强依赖该参数,通过Endpoint获取 service_id 确定应用
@@ -126,15 +180,12 @@ export interface IConfiguration {
126
180
  /**
127
181
  * reporter 发送节奏配置
128
182
  */
129
- reportConfig?: {
130
- flushTime?: number;
131
- maxEventCount?: number;
132
- };
183
+ reportConfig?: IReportConfig;
133
184
  /**
134
185
  * 配置下发
135
186
  * - 运行时动态配置更新,根据端侧特点来做定制化配置
136
187
  */
137
- remoteConfig?: Boolean;
188
+ remoteConfig?: IRemoteConfig | Boolean;
138
189
  /**
139
190
  * session config
140
191
  */
@@ -143,7 +194,7 @@ export interface IConfiguration {
143
194
  * 各个 collector config
144
195
  */
145
196
  collectors?: {
146
- [key: string]: boolean;
197
+ [key: string]: boolean | ICollectorConfig;
147
198
  };
148
199
  /**
149
200
  * 事件过滤器配置
@@ -8,4 +8,8 @@ var EventType = exports.EventType = /*#__PURE__*/function (EventType) {
8
8
  */
9
9
  EventType["collect"] = "collect";
10
10
  return EventType;
11
- }({});
11
+ }({});
12
+ /**
13
+ * 远端监控配置接口
14
+ * @remarks 用于控制RUM数据采集的远程配置策略
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;