@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.
- package/es/index.d.ts +3 -0
- package/es/index.js +3 -0
- package/es/model/client.d.ts +2 -1
- package/es/model/client.js +2 -2
- package/es/model/configManager.d.ts +58 -0
- package/es/model/configManager.js +177 -0
- package/es/model/context.d.ts +3 -1
- package/es/model/context.js +13 -2
- package/es/model/reporter.d.ts +2 -4
- package/es/model/reporter.js +48 -9
- package/es/model/shell.d.ts +1 -15
- package/es/model/shell.js +62 -52
- package/es/types/client.d.ts +58 -7
- package/es/types/client.js +6 -1
- package/es/types/config.d.ts +49 -0
- package/es/types/config.js +1 -0
- package/es/types/rum-event.d.ts +1 -0
- package/es/utils/base.d.ts +4 -4
- package/es/utils/base.js +62 -33
- package/es/utils/combineConfig.js +89 -101
- package/es/utils/match.d.ts +6 -0
- package/es/utils/match.js +34 -0
- package/es/utils/trace.d.ts +5 -1
- package/lib/index.d.ts +3 -0
- package/lib/index.js +21 -0
- package/lib/model/client.d.ts +2 -1
- package/lib/model/client.js +2 -2
- package/lib/model/configManager.d.ts +58 -0
- package/lib/model/configManager.js +182 -0
- package/lib/model/context.d.ts +3 -1
- package/lib/model/context.js +13 -2
- package/lib/model/reporter.d.ts +2 -4
- package/lib/model/reporter.js +48 -9
- package/lib/model/shell.d.ts +1 -15
- package/lib/model/shell.js +61 -53
- package/lib/types/client.d.ts +58 -7
- package/lib/types/client.js +5 -1
- package/lib/types/config.d.ts +49 -0
- package/lib/types/config.js +3 -0
- package/lib/types/rum-event.d.ts +1 -0
- package/lib/utils/base.d.ts +4 -4
- package/lib/utils/base.js +63 -34
- package/lib/utils/combineConfig.js +90 -107
- package/lib/utils/match.d.ts +6 -0
- package/lib/utils/match.js +35 -0
- package/lib/utils/trace.d.ts +5 -1
- package/package.json +1 -1
- package/es/utils/combineConfig.d.ts +0 -15
- package/lib/utils/combineConfig.d.ts +0 -15
package/es/index.d.ts
CHANGED
|
@@ -2,12 +2,14 @@ import Client from './model/client';
|
|
|
2
2
|
import Context from './model/context';
|
|
3
3
|
import Reporter from './model/reporter';
|
|
4
4
|
import Shell from './model/shell';
|
|
5
|
+
export * from './model/configManager';
|
|
5
6
|
export * from './types/client';
|
|
6
7
|
export * from './types/collector';
|
|
7
8
|
export * from './types/processor';
|
|
8
9
|
export * from './types/reporter';
|
|
9
10
|
export * from './types/rum-event';
|
|
10
11
|
export * from './types/shell';
|
|
12
|
+
export * from './types/config';
|
|
11
13
|
export * from './utils/base';
|
|
12
14
|
export * from './utils/polyfills';
|
|
13
15
|
export * from './utils/is';
|
|
@@ -15,4 +17,5 @@ export * from './utils/number';
|
|
|
15
17
|
export * from './utils/match';
|
|
16
18
|
export * from './utils/trace';
|
|
17
19
|
export * from './utils/verify';
|
|
20
|
+
export * from './utils/url';
|
|
18
21
|
export { Client, Context, Reporter, Shell };
|
package/es/index.js
CHANGED
|
@@ -2,12 +2,14 @@ import Client from './model/client';
|
|
|
2
2
|
import Context from './model/context';
|
|
3
3
|
import Reporter from './model/reporter';
|
|
4
4
|
import Shell from './model/shell';
|
|
5
|
+
export * from './model/configManager';
|
|
5
6
|
export * from './types/client';
|
|
6
7
|
export * from './types/collector';
|
|
7
8
|
export * from './types/processor';
|
|
8
9
|
export * from './types/reporter';
|
|
9
10
|
export * from './types/rum-event';
|
|
10
11
|
export * from './types/shell';
|
|
12
|
+
export * from './types/config';
|
|
11
13
|
export * from './utils/base';
|
|
12
14
|
export * from './utils/polyfills';
|
|
13
15
|
export * from './utils/is';
|
|
@@ -15,4 +17,5 @@ export * from './utils/number';
|
|
|
15
17
|
export * from './utils/match';
|
|
16
18
|
export * from './utils/trace';
|
|
17
19
|
export * from './utils/verify';
|
|
20
|
+
export * from './utils/url';
|
|
18
21
|
export { Client, Context, Reporter, Shell };
|
package/es/model/client.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IClient, IConfiguration, IContext, IRumSession } from '../types/client';
|
|
2
|
+
import { IConfigManager } from "../types/config";
|
|
2
3
|
import { RumEvent } from '../types/rum-event';
|
|
3
4
|
import { IProcessor } from '../types/processor';
|
|
4
5
|
import { ICollector } from '../types/collector';
|
|
@@ -9,7 +10,7 @@ declare class Client implements IClient {
|
|
|
9
10
|
private processors;
|
|
10
11
|
private reporter;
|
|
11
12
|
private ctx;
|
|
12
|
-
init(config: IConfiguration, rumSession?: IRumSession): void;
|
|
13
|
+
init(config: IConfiguration, rumSession?: IRumSession, configManager?: IConfigManager): void;
|
|
13
14
|
sendEvent: (payload: RumEvent) => void;
|
|
14
15
|
setContext(ctx: IContext): void;
|
|
15
16
|
getContext(): IContext;
|
package/es/model/client.js
CHANGED
|
@@ -18,9 +18,9 @@ var Client = /*#__PURE__*/function () {
|
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
var _proto = Client.prototype;
|
|
21
|
-
_proto.init = function init(config, rumSession) {
|
|
21
|
+
_proto.init = function init(config, rumSession, configManager) {
|
|
22
22
|
var _this2 = this;
|
|
23
|
-
this.ctx = new Context(config, rumSession);
|
|
23
|
+
this.ctx = new Context(config, rumSession, configManager);
|
|
24
24
|
var ctx = this.ctx,
|
|
25
25
|
collectors = this.collectors,
|
|
26
26
|
processors = this.processors,
|
|
@@ -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,177 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
+
function parseRemoteConfig(config) {
|
|
5
|
+
var remoteConfig = config.remoteConfig || {};
|
|
6
|
+
return {
|
|
7
|
+
enable: remoteConfig.enable !== false && !!(remoteConfig.url || remoteConfig.region),
|
|
8
|
+
url: remoteConfig.url || '',
|
|
9
|
+
mode: remoteConfig.mode || 'launch-first',
|
|
10
|
+
cacheTimeout: remoteConfig.cacheTimeout || 3600000
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 配置管理器
|
|
16
|
+
* 提供配置管理的通用实现,各平台可以继承并实现特定方法
|
|
17
|
+
*/
|
|
18
|
+
export var ConfigManager = /*#__PURE__*/function () {
|
|
19
|
+
function ConfigManager() {
|
|
20
|
+
this.currentConfig = null;
|
|
21
|
+
this.initialized = false;
|
|
22
|
+
}
|
|
23
|
+
var _proto = ConfigManager.prototype;
|
|
24
|
+
/**
|
|
25
|
+
* 初始化配置管理器
|
|
26
|
+
* @param config 初始配置
|
|
27
|
+
*/
|
|
28
|
+
_proto.init =
|
|
29
|
+
/*#__PURE__*/
|
|
30
|
+
function () {
|
|
31
|
+
var _init = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(config) {
|
|
32
|
+
var _this = this;
|
|
33
|
+
var remoteConfig, cacheConfig, asyncConfigPromise;
|
|
34
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
35
|
+
while (1) switch (_context.prev = _context.next) {
|
|
36
|
+
case 0:
|
|
37
|
+
if (!this.initialized) {
|
|
38
|
+
_context.next = 2;
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
return _context.abrupt("return");
|
|
42
|
+
case 2:
|
|
43
|
+
this.currentConfig = _extends({}, config);
|
|
44
|
+
this.initialized = true;
|
|
45
|
+
remoteConfig = parseRemoteConfig(config);
|
|
46
|
+
this.currentConfig.remoteConfig = remoteConfig;
|
|
47
|
+
if (remoteConfig.enable) {
|
|
48
|
+
_context.next = 8;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
return _context.abrupt("return");
|
|
52
|
+
case 8:
|
|
53
|
+
_context.next = 10;
|
|
54
|
+
return this.getCacheConfig();
|
|
55
|
+
case 10:
|
|
56
|
+
cacheConfig = _context.sent;
|
|
57
|
+
if (cacheConfig && cacheConfig.content) {
|
|
58
|
+
this.currentConfig = this.mergeRemoteCfg(cacheConfig.content);
|
|
59
|
+
}
|
|
60
|
+
if (!this.isCacheValid(cacheConfig, remoteConfig.cacheTimeout)) {
|
|
61
|
+
_context.next = 14;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
return _context.abrupt("return");
|
|
65
|
+
case 14:
|
|
66
|
+
asyncConfigPromise = this.fetchRemoteCfg(this.currentConfig).then(function (resp) {
|
|
67
|
+
if (!resp) return;
|
|
68
|
+
var asyncRemoteConfig = _this.parseConfig(resp);
|
|
69
|
+
_this.currentConfig = _this.mergeRemoteCfg(asyncRemoteConfig);
|
|
70
|
+
_this.setCacheConfig({
|
|
71
|
+
timestamp: Date.now(),
|
|
72
|
+
content: resp
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
if (!(remoteConfig.mode === 'remote-first')) {
|
|
76
|
+
_context.next = 18;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
_context.next = 18;
|
|
80
|
+
return asyncConfigPromise;
|
|
81
|
+
case 18:
|
|
82
|
+
case "end":
|
|
83
|
+
return _context.stop();
|
|
84
|
+
}
|
|
85
|
+
}, _callee, this);
|
|
86
|
+
}));
|
|
87
|
+
function init(_x) {
|
|
88
|
+
return _init.apply(this, arguments);
|
|
89
|
+
}
|
|
90
|
+
return init;
|
|
91
|
+
}()
|
|
92
|
+
/**
|
|
93
|
+
* 获取配置
|
|
94
|
+
* @returns 配置数据
|
|
95
|
+
*/
|
|
96
|
+
;
|
|
97
|
+
_proto.getConfig = function getConfig() {
|
|
98
|
+
if (!this.currentConfig) {
|
|
99
|
+
throw new Error('Config not initialized');
|
|
100
|
+
}
|
|
101
|
+
return this.currentConfig;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* 更新配置
|
|
106
|
+
* @param config 新配置
|
|
107
|
+
*/;
|
|
108
|
+
_proto.setConfig =
|
|
109
|
+
/*#__PURE__*/
|
|
110
|
+
function () {
|
|
111
|
+
var _setConfig = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(config) {
|
|
112
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
113
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
114
|
+
case 0:
|
|
115
|
+
if (this.currentConfig) {
|
|
116
|
+
_context2.next = 2;
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
return _context2.abrupt("return");
|
|
120
|
+
case 2:
|
|
121
|
+
this.currentConfig = _extends({}, this.currentConfig, config);
|
|
122
|
+
case 3:
|
|
123
|
+
case "end":
|
|
124
|
+
return _context2.stop();
|
|
125
|
+
}
|
|
126
|
+
}, _callee2, this);
|
|
127
|
+
}));
|
|
128
|
+
function setConfig(_x2) {
|
|
129
|
+
return _setConfig.apply(this, arguments);
|
|
130
|
+
}
|
|
131
|
+
return setConfig;
|
|
132
|
+
}()
|
|
133
|
+
/**
|
|
134
|
+
* 检查缓存是否有效
|
|
135
|
+
* @param cachedData 缓存数据
|
|
136
|
+
* @param cacheTimeout 缓存超时时间
|
|
137
|
+
*/
|
|
138
|
+
;
|
|
139
|
+
_proto.isCacheValid = function isCacheValid(cachedData, cacheTimeout) {
|
|
140
|
+
if (!cachedData || !cachedData.timestamp) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
var timeout = cacheTimeout || 3600000; // 默认1小时
|
|
144
|
+
return Date.now() - cachedData.timestamp < timeout;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 合并配置
|
|
149
|
+
* @param remoteCfg 远程配置
|
|
150
|
+
* @returns 合并后的配置
|
|
151
|
+
*/;
|
|
152
|
+
_proto.mergeRemoteCfg = function mergeRemoteCfg(remoteCfg) {
|
|
153
|
+
var _this$currentConfig = this.currentConfig,
|
|
154
|
+
pid = _this$currentConfig.pid,
|
|
155
|
+
app = _this$currentConfig.app,
|
|
156
|
+
endpoint = _this$currentConfig.endpoint,
|
|
157
|
+
remoteConfig = _this$currentConfig.remoteConfig,
|
|
158
|
+
beforeReport = _this$currentConfig.beforeReport,
|
|
159
|
+
properties = _this$currentConfig.properties;
|
|
160
|
+
return _extends({}, this.currentConfig, remoteCfg, {
|
|
161
|
+
pid: pid,
|
|
162
|
+
app: app,
|
|
163
|
+
endpoint: endpoint,
|
|
164
|
+
remoteConfig: remoteConfig,
|
|
165
|
+
beforeReport: beforeReport,
|
|
166
|
+
properties: properties
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* 销毁配置管理器
|
|
171
|
+
*/
|
|
172
|
+
_proto.destroy = function destroy() {
|
|
173
|
+
this.currentConfig = null;
|
|
174
|
+
this.initialized = false;
|
|
175
|
+
};
|
|
176
|
+
return ConfigManager;
|
|
177
|
+
}();
|
package/es/model/context.d.ts
CHANGED
|
@@ -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
|
-
|
|
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[];
|
package/es/model/context.js
CHANGED
|
@@ -1,20 +1,31 @@
|
|
|
1
1
|
var Context = /*#__PURE__*/function () {
|
|
2
|
-
function Context(config, rumSession) {
|
|
2
|
+
function Context(config, rumSession, configManager) {
|
|
3
3
|
this.config = config;
|
|
4
4
|
this.rumEvent = void 0;
|
|
5
5
|
this.views = [];
|
|
6
6
|
this.session = void 0;
|
|
7
|
+
this.configManager = void 0;
|
|
7
8
|
if (rumSession) {
|
|
8
9
|
this.session = rumSession;
|
|
9
10
|
this.session.init(this);
|
|
10
11
|
}
|
|
12
|
+
if (configManager) {
|
|
13
|
+
this.configManager = configManager;
|
|
14
|
+
}
|
|
11
15
|
}
|
|
12
16
|
var _proto = Context.prototype;
|
|
13
17
|
_proto.getConfig = function getConfig() {
|
|
18
|
+
if (this.configManager) {
|
|
19
|
+
return this.configManager.getConfig();
|
|
20
|
+
}
|
|
14
21
|
return this.config;
|
|
15
22
|
};
|
|
16
23
|
_proto.setConfig = function setConfig(config) {
|
|
17
|
-
this.
|
|
24
|
+
if (this.configManager) {
|
|
25
|
+
this.configManager.setConfig(config);
|
|
26
|
+
} else {
|
|
27
|
+
this.config = config;
|
|
28
|
+
}
|
|
18
29
|
};
|
|
19
30
|
_proto.getViews = function getViews() {
|
|
20
31
|
return this.views;
|
package/es/model/reporter.d.ts
CHANGED
|
@@ -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
|
*/
|
package/es/model/reporter.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
1
2
|
import _extends from "@babel/runtime/helpers/extends";
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
4
|
import { RumEventType } from '../types/rum-event';
|
|
3
5
|
import { getErrorID } from '../utils/exception';
|
|
4
6
|
import { isNumber, isObject, isString } from "../utils/is";
|
|
@@ -183,17 +185,54 @@ var Reporter = /*#__PURE__*/function () {
|
|
|
183
185
|
bundle = config.beforeReport(bundle);
|
|
184
186
|
if (!bundle) return;
|
|
185
187
|
}
|
|
186
|
-
this.
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
188
|
+
this.tryRequest(bundle);
|
|
189
|
+
};
|
|
190
|
+
_proto.tryRequest = /*#__PURE__*/function () {
|
|
191
|
+
var _tryRequest = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(bundle, retry) {
|
|
192
|
+
var _this$ctx$getConfig,
|
|
193
|
+
_reportConfig$maxRetr,
|
|
194
|
+
_reportConfig$retryDe,
|
|
195
|
+
_this2 = this;
|
|
196
|
+
var reportConfig, maxRetryCount, retryDelay;
|
|
197
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
198
|
+
while (1) switch (_context.prev = _context.next) {
|
|
199
|
+
case 0:
|
|
200
|
+
if (retry === void 0) {
|
|
201
|
+
retry = 0;
|
|
202
|
+
}
|
|
203
|
+
reportConfig = (_this$ctx$getConfig = this.ctx.getConfig()) === null || _this$ctx$getConfig === void 0 ? void 0 : _this$ctx$getConfig.reportConfig;
|
|
204
|
+
maxRetryCount = (_reportConfig$maxRetr = reportConfig === null || reportConfig === void 0 ? void 0 : reportConfig.maxRetryCount) !== null && _reportConfig$maxRetr !== void 0 ? _reportConfig$maxRetr : 0;
|
|
205
|
+
retryDelay = (_reportConfig$retryDe = reportConfig === null || reportConfig === void 0 ? void 0 : reportConfig.retryDelay) !== null && _reportConfig$retryDe !== void 0 ? _reportConfig$retryDe : 3000;
|
|
206
|
+
_context.prev = 4;
|
|
207
|
+
bundle._retry = retry;
|
|
208
|
+
_context.next = 8;
|
|
209
|
+
return this.request(this.ctx, bundle);
|
|
210
|
+
case 8:
|
|
211
|
+
_context.next = 13;
|
|
212
|
+
break;
|
|
213
|
+
case 10:
|
|
214
|
+
_context.prev = 10;
|
|
215
|
+
_context.t0 = _context["catch"](4);
|
|
216
|
+
if (retry < maxRetryCount - 1) {
|
|
217
|
+
setTimeout(function () {
|
|
218
|
+
return _this2.tryRequest(bundle, retry + 1);
|
|
219
|
+
}, retryDelay);
|
|
220
|
+
}
|
|
221
|
+
case 13:
|
|
222
|
+
case "end":
|
|
223
|
+
return _context.stop();
|
|
224
|
+
}
|
|
225
|
+
}, _callee, this, [[4, 10]]);
|
|
226
|
+
}));
|
|
227
|
+
function tryRequest(_x, _x2) {
|
|
228
|
+
return _tryRequest.apply(this, arguments);
|
|
229
|
+
}
|
|
230
|
+
return tryRequest;
|
|
231
|
+
}()
|
|
194
232
|
/**
|
|
195
233
|
* 接口请求由各平台 sdk reporter 实现
|
|
196
|
-
|
|
234
|
+
*/
|
|
235
|
+
;
|
|
197
236
|
/**
|
|
198
237
|
* 初始化时
|
|
199
238
|
*/
|
package/es/model/shell.d.ts
CHANGED
|
@@ -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):
|
|
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
|
*/
|
package/es/model/shell.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import { RumEventType } from "../types/rum-event";
|
|
3
3
|
import Client from '../model/client';
|
|
4
|
-
import { isNumber,
|
|
5
|
-
import combineConfig, { isRemoteConfigEnable, getRemoteConfigUrl } from "../utils/combineConfig";
|
|
4
|
+
import { isNumber, isObject } from "../utils/is";
|
|
5
|
+
// import combineConfig, { isRemoteConfigEnable, getRemoteConfigUrl } from "../utils/combineConfig";
|
|
6
6
|
var Shell = /*#__PURE__*/function () {
|
|
7
7
|
function Shell(config) {
|
|
8
8
|
this.client = void 0;
|
|
@@ -10,60 +10,55 @@ var Shell = /*#__PURE__*/function () {
|
|
|
10
10
|
if (config && this.init) {
|
|
11
11
|
this.init(config);
|
|
12
12
|
}
|
|
13
|
-
// if (config && this.init) {
|
|
14
|
-
// this.init(this.getCombinedConfig(config));
|
|
15
|
-
|
|
16
|
-
// // 拉取远程配置进行更新
|
|
17
|
-
// this.updateFromRemoteConfig(config);
|
|
18
|
-
// }
|
|
19
13
|
}
|
|
20
|
-
var _proto = Shell.prototype;
|
|
21
|
-
_proto.getCombinedConfig = function getCombinedConfig(config) {
|
|
22
|
-
var combinedConf;
|
|
23
|
-
if (isRemoteConfigEnable(config) && isFunction(this.getLocalConfig)) {
|
|
24
|
-
var localConfig = this.getLocalConfig(0, config.pid);
|
|
25
|
-
combinedConf = combineConfig(config, localConfig);
|
|
26
|
-
}
|
|
27
|
-
return combinedConf || config;
|
|
28
|
-
};
|
|
29
|
-
_proto.updateFromRemoteConfig = function updateFromRemoteConfig(config, reSetup) {
|
|
30
|
-
if (reSetup === void 0) {
|
|
31
|
-
reSetup = true;
|
|
32
|
-
}
|
|
33
|
-
// 请求动态配置
|
|
34
|
-
if (config.pid && isRemoteConfigEnable(config) && isFunction(this.getRemoteConfig)) {
|
|
35
|
-
var that = this;
|
|
36
|
-
var proms = this.getRemoteConfig(getRemoteConfigUrl(config), config);
|
|
37
|
-
proms === null || proms === void 0 ? void 0 : proms.then(function (remoteConfig) {
|
|
38
|
-
if (!remoteConfig || remoteConfig.errorStatus !== undefined) return;
|
|
39
|
-
var combinedConf = combineConfig(config, remoteConfig);
|
|
40
|
-
|
|
41
|
-
// 无有效的新配置,无需更新
|
|
42
|
-
if (!combinedConf) return;
|
|
43
14
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
15
|
+
// getCombinedConfig(config?: IConfiguration) {
|
|
16
|
+
// let combinedConf;
|
|
17
|
+
// if(isRemoteConfigEnable(config) && isFunction(this.getLocalConfig)) {
|
|
18
|
+
// const localConfig = this.getLocalConfig(0, config.pid);
|
|
19
|
+
// combinedConf = combineConfig(config, localConfig);
|
|
20
|
+
// }
|
|
21
|
+
// return combinedConf || config;
|
|
22
|
+
// }
|
|
23
|
+
//
|
|
24
|
+
// updateFromRemoteConfig(config: any, reSetup: boolean = true) {
|
|
25
|
+
// // 请求动态配置
|
|
26
|
+
// if( config.pid && isRemoteConfigEnable(config) && isFunction(this.getRemoteConfig) ){
|
|
27
|
+
// const that = this;
|
|
28
|
+
// const proms = this.getRemoteConfig(getRemoteConfigUrl(config), config);
|
|
29
|
+
// proms?.then(remoteConfig => {
|
|
30
|
+
// if(!remoteConfig || remoteConfig.errorStatus !== undefined) return;
|
|
31
|
+
// const combinedConf = combineConfig(config, remoteConfig);
|
|
32
|
+
//
|
|
33
|
+
// // 无有效的新配置,无需更新
|
|
34
|
+
// if(!combinedConf) return;
|
|
35
|
+
//
|
|
36
|
+
// // 存储到本地
|
|
37
|
+
// if(isFunction(that.storeRemoteConfig)) {
|
|
38
|
+
// that.storeRemoteConfig(remoteConfig, config.pid);
|
|
39
|
+
// }
|
|
40
|
+
//
|
|
41
|
+
// if(reSetup === false || config.remoteConfig.reSetup === false) return;
|
|
42
|
+
//
|
|
43
|
+
// const context = that.client.getContext();
|
|
44
|
+
// // 更新配置
|
|
45
|
+
// context.setConfig(combinedConf);
|
|
46
|
+
// // 逐个更新collector
|
|
47
|
+
// const collectors = that.client.getCollectors();
|
|
48
|
+
// collectors.forEach(collector => {
|
|
49
|
+
// if(isFunction(collector.destroy)) {
|
|
50
|
+
// collector.destroy();
|
|
51
|
+
// collector.setup(context, that.client.sendEvent);
|
|
52
|
+
// }
|
|
53
|
+
// });
|
|
54
|
+
// });
|
|
55
|
+
// }
|
|
56
|
+
// }
|
|
63
57
|
|
|
64
58
|
/**
|
|
65
59
|
* 初始化
|
|
66
|
-
|
|
60
|
+
*/
|
|
61
|
+
var _proto = Shell.prototype;
|
|
67
62
|
_proto.sendEvent = function sendEvent(payload) {
|
|
68
63
|
if (this.client) {
|
|
69
64
|
this.client.sendEvent(payload);
|
|
@@ -79,8 +74,23 @@ var Shell = /*#__PURE__*/function () {
|
|
|
79
74
|
}
|
|
80
75
|
}
|
|
81
76
|
|
|
77
|
+
// /**
|
|
78
|
+
// * 获取远程配置
|
|
79
|
+
// */
|
|
80
|
+
// abstract getRemoteConfig(url: string, config: any): object;
|
|
81
|
+
//
|
|
82
|
+
// /**
|
|
83
|
+
// * 存储远程配置到本地
|
|
84
|
+
// */
|
|
85
|
+
// abstract storeRemoteConfig(config: any, pid: string): boolean;
|
|
86
|
+
//
|
|
87
|
+
// /**
|
|
88
|
+
// * 提取本地存储的配置
|
|
89
|
+
// */
|
|
90
|
+
// abstract getLocalConfig(duration: number, pid: string): any;
|
|
91
|
+
|
|
82
92
|
/**
|
|
83
|
-
*
|
|
93
|
+
* set config
|
|
84
94
|
*/;
|
|
85
95
|
/**
|
|
86
96
|
* 自定义事件上报
|