@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,58 @@
1
+ import { ICacheConfiguration, IConfigManager } from '../types/config';
2
+ import { IConfiguration } from '../types/client';
3
+ /**
4
+ * 配置管理器
5
+ * 提供配置管理的通用实现,各平台可以继承并实现特定方法
6
+ */
7
+ export declare abstract class ConfigManager implements IConfigManager {
8
+ protected currentConfig: IConfiguration | null;
9
+ protected initialized: boolean;
10
+ /**
11
+ * 初始化配置管理器
12
+ * @param config 初始配置
13
+ */
14
+ init(config: IConfiguration): Promise<void>;
15
+ /**
16
+ * 获取配置
17
+ * @returns 配置数据
18
+ */
19
+ getConfig(): IConfiguration;
20
+ /**
21
+ * 更新配置
22
+ * @param config 新配置
23
+ */
24
+ setConfig(config: Partial<IConfiguration>): Promise<void>;
25
+ /**
26
+ * 检查缓存是否有效
27
+ * @param cachedData 缓存数据
28
+ * @param cacheTimeout 缓存超时时间
29
+ */
30
+ protected isCacheValid(cachedData: any, cacheTimeout?: number): boolean;
31
+ /**
32
+ * 合并配置
33
+ * @param remoteCfg 远程配置
34
+ * @returns 合并后的配置
35
+ */
36
+ mergeRemoteCfg(remoteCfg: any): IConfiguration | null;
37
+ abstract fetchRemoteCfg(config: IConfiguration): Promise<any>;
38
+ /**
39
+ * 抽象方法:获取本地存储的配置
40
+ * 各平台需要实现此方法来适配不同的本地存储方式
41
+ */
42
+ abstract getCacheConfig(): Promise<ICacheConfiguration> | ICacheConfiguration | void;
43
+ /**
44
+ * 抽象方法:存储配置到本地
45
+ * 各平台需要实现此方法来适配不同的本地存储方式
46
+ * @param config 配置数据
47
+ */
48
+ abstract setCacheConfig(config: ICacheConfiguration): void;
49
+ /**
50
+ * 抽象方法:解析远端配置为本地配置
51
+ * @param json 远端下发的配置数据
52
+ */
53
+ abstract parseConfig(json: any): unknown;
54
+ /**
55
+ * 销毁配置管理器
56
+ */
57
+ destroy(): void;
58
+ }
@@ -0,0 +1,182 @@
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
+ };
17
+ }
18
+
19
+ /**
20
+ * 配置管理器
21
+ * 提供配置管理的通用实现,各平台可以继承并实现特定方法
22
+ */
23
+ var ConfigManager = exports.ConfigManager = /*#__PURE__*/function () {
24
+ function ConfigManager() {
25
+ this.currentConfig = null;
26
+ this.initialized = false;
27
+ }
28
+ var _proto = ConfigManager.prototype;
29
+ /**
30
+ * 初始化配置管理器
31
+ * @param config 初始配置
32
+ */
33
+ _proto.init =
34
+ /*#__PURE__*/
35
+ function () {
36
+ var _init = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee(config) {
37
+ var _this = this;
38
+ var remoteConfig, cacheConfig, asyncConfigPromise;
39
+ return _regenerator["default"].wrap(function _callee$(_context) {
40
+ while (1) switch (_context.prev = _context.next) {
41
+ case 0:
42
+ if (!this.initialized) {
43
+ _context.next = 2;
44
+ break;
45
+ }
46
+ return _context.abrupt("return");
47
+ case 2:
48
+ this.currentConfig = (0, _extends2["default"])({}, config);
49
+ this.initialized = true;
50
+ remoteConfig = parseRemoteConfig(config);
51
+ this.currentConfig.remoteConfig = remoteConfig;
52
+ if (remoteConfig.enable) {
53
+ _context.next = 8;
54
+ break;
55
+ }
56
+ return _context.abrupt("return");
57
+ case 8:
58
+ _context.next = 10;
59
+ return this.getCacheConfig();
60
+ case 10:
61
+ cacheConfig = _context.sent;
62
+ if (cacheConfig && cacheConfig.content) {
63
+ this.currentConfig = this.mergeRemoteCfg(cacheConfig.content);
64
+ }
65
+ if (!this.isCacheValid(cacheConfig, remoteConfig.cacheTimeout)) {
66
+ _context.next = 14;
67
+ break;
68
+ }
69
+ return _context.abrupt("return");
70
+ case 14:
71
+ asyncConfigPromise = this.fetchRemoteCfg(this.currentConfig).then(function (resp) {
72
+ if (!resp) return;
73
+ var asyncRemoteConfig = _this.parseConfig(resp);
74
+ _this.currentConfig = _this.mergeRemoteCfg(asyncRemoteConfig);
75
+ _this.setCacheConfig({
76
+ timestamp: Date.now(),
77
+ content: resp
78
+ });
79
+ });
80
+ if (!(remoteConfig.mode === 'remote-first')) {
81
+ _context.next = 18;
82
+ break;
83
+ }
84
+ _context.next = 18;
85
+ return asyncConfigPromise;
86
+ case 18:
87
+ case "end":
88
+ return _context.stop();
89
+ }
90
+ }, _callee, this);
91
+ }));
92
+ function init(_x) {
93
+ return _init.apply(this, arguments);
94
+ }
95
+ return init;
96
+ }()
97
+ /**
98
+ * 获取配置
99
+ * @returns 配置数据
100
+ */
101
+ ;
102
+ _proto.getConfig = function getConfig() {
103
+ if (!this.currentConfig) {
104
+ throw new Error('Config not initialized');
105
+ }
106
+ return this.currentConfig;
107
+ }
108
+
109
+ /**
110
+ * 更新配置
111
+ * @param config 新配置
112
+ */;
113
+ _proto.setConfig =
114
+ /*#__PURE__*/
115
+ function () {
116
+ var _setConfig = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2(config) {
117
+ return _regenerator["default"].wrap(function _callee2$(_context2) {
118
+ while (1) switch (_context2.prev = _context2.next) {
119
+ case 0:
120
+ if (this.currentConfig) {
121
+ _context2.next = 2;
122
+ break;
123
+ }
124
+ return _context2.abrupt("return");
125
+ case 2:
126
+ this.currentConfig = (0, _extends2["default"])({}, this.currentConfig, config);
127
+ case 3:
128
+ case "end":
129
+ return _context2.stop();
130
+ }
131
+ }, _callee2, this);
132
+ }));
133
+ function setConfig(_x2) {
134
+ return _setConfig.apply(this, arguments);
135
+ }
136
+ return setConfig;
137
+ }()
138
+ /**
139
+ * 检查缓存是否有效
140
+ * @param cachedData 缓存数据
141
+ * @param cacheTimeout 缓存超时时间
142
+ */
143
+ ;
144
+ _proto.isCacheValid = function isCacheValid(cachedData, cacheTimeout) {
145
+ if (!cachedData || !cachedData.timestamp) {
146
+ return false;
147
+ }
148
+ var timeout = cacheTimeout || 3600000; // 默认1小时
149
+ return Date.now() - cachedData.timestamp < timeout;
150
+ }
151
+
152
+ /**
153
+ * 合并配置
154
+ * @param remoteCfg 远程配置
155
+ * @returns 合并后的配置
156
+ */;
157
+ _proto.mergeRemoteCfg = function mergeRemoteCfg(remoteCfg) {
158
+ var _this$currentConfig = this.currentConfig,
159
+ pid = _this$currentConfig.pid,
160
+ app = _this$currentConfig.app,
161
+ endpoint = _this$currentConfig.endpoint,
162
+ remoteConfig = _this$currentConfig.remoteConfig,
163
+ beforeReport = _this$currentConfig.beforeReport,
164
+ properties = _this$currentConfig.properties;
165
+ return (0, _extends2["default"])({}, this.currentConfig, remoteCfg, {
166
+ pid: pid,
167
+ app: app,
168
+ endpoint: endpoint,
169
+ remoteConfig: remoteConfig,
170
+ beforeReport: beforeReport,
171
+ properties: properties
172
+ });
173
+ };
174
+ /**
175
+ * 销毁配置管理器
176
+ */
177
+ _proto.destroy = function destroy() {
178
+ this.currentConfig = null;
179
+ this.initialized = false;
180
+ };
181
+ return ConfigManager;
182
+ }();
@@ -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,9 +7,7 @@ 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; }
10
+ // import combineConfig, { isRemoteConfigEnable, getRemoteConfigUrl } from "../utils/combineConfig";
13
11
  var Shell = exports["default"] = /*#__PURE__*/function () {
14
12
  function Shell(config) {
15
13
  this.client = void 0;
@@ -17,60 +15,55 @@ var Shell = exports["default"] = /*#__PURE__*/function () {
17
15
  if (config && this.init) {
18
16
  this.init(config);
19
17
  }
20
- // if (config && this.init) {
21
- // this.init(this.getCombinedConfig(config));
22
-
23
- // // 拉取远程配置进行更新
24
- // this.updateFromRemoteConfig(config);
25
- // }
26
18
  }
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
-
48
- // 无有效的新配置,无需更新
49
- if (!combinedConf) return;
50
19
 
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
- }
20
+ // getCombinedConfig(config?: IConfiguration) {
21
+ // let combinedConf;
22
+ // if(isRemoteConfigEnable(config) && isFunction(this.getLocalConfig)) {
23
+ // const localConfig = this.getLocalConfig(0, config.pid);
24
+ // combinedConf = combineConfig(config, localConfig);
25
+ // }
26
+ // return combinedConf || config;
27
+ // }
28
+ //
29
+ // updateFromRemoteConfig(config: any, reSetup: boolean = true) {
30
+ // // 请求动态配置
31
+ // if( config.pid && isRemoteConfigEnable(config) && isFunction(this.getRemoteConfig) ){
32
+ // const that = this;
33
+ // const proms = this.getRemoteConfig(getRemoteConfigUrl(config), config);
34
+ // proms?.then(remoteConfig => {
35
+ // if(!remoteConfig || remoteConfig.errorStatus !== undefined) return;
36
+ // const combinedConf = combineConfig(config, remoteConfig);
37
+ //
38
+ // // 无有效的新配置,无需更新
39
+ // if(!combinedConf) return;
40
+ //
41
+ // // 存储到本地
42
+ // if(isFunction(that.storeRemoteConfig)) {
43
+ // that.storeRemoteConfig(remoteConfig, config.pid);
44
+ // }
45
+ //
46
+ // if(reSetup === false || config.remoteConfig.reSetup === false) return;
47
+ //
48
+ // const context = that.client.getContext();
49
+ // // 更新配置
50
+ // context.setConfig(combinedConf);
51
+ // // 逐个更新collector
52
+ // const collectors = that.client.getCollectors();
53
+ // collectors.forEach(collector => {
54
+ // if(isFunction(collector.destroy)) {
55
+ // collector.destroy();
56
+ // collector.setup(context, that.client.sendEvent);
57
+ // }
58
+ // });
59
+ // });
60
+ // }
61
+ // }
70
62
 
71
63
  /**
72
64
  * 初始化
73
- */;
65
+ */
66
+ var _proto = Shell.prototype;
74
67
  _proto.sendEvent = function sendEvent(payload) {
75
68
  if (this.client) {
76
69
  this.client.sendEvent(payload);
@@ -86,8 +79,23 @@ var Shell = exports["default"] = /*#__PURE__*/function () {
86
79
  }
87
80
  }
88
81
 
82
+ // /**
83
+ // * 获取远程配置
84
+ // */
85
+ // abstract getRemoteConfig(url: string, config: any): object;
86
+ //
87
+ // /**
88
+ // * 存储远程配置到本地
89
+ // */
90
+ // abstract storeRemoteConfig(config: any, pid: string): boolean;
91
+ //
92
+ // /**
93
+ // * 提取本地存储的配置
94
+ // */
95
+ // abstract getLocalConfig(duration: number, pid: string): any;
96
+
89
97
  /**
90
- * 获取远程配置
98
+ * set config
91
99
  */;
92
100
  /**
93
101
  * 自定义事件上报
@@ -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
+ */