@arms/rum-core 0.0.34 → 0.0.36

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 (47) hide show
  1. package/es/index.d.ts +18 -0
  2. package/es/index.js +18 -0
  3. package/es/model/client.d.ts +21 -0
  4. package/es/model/client.js +76 -0
  5. package/es/model/context.d.ts +18 -0
  6. package/es/model/context.js +38 -0
  7. package/es/model/reporter.d.ts +31 -0
  8. package/es/model/reporter.js +196 -0
  9. package/es/model/shell.d.ts +51 -0
  10. package/es/model/shell.js +160 -0
  11. package/es/style.js +1 -0
  12. package/es/types/client.d.ts +162 -0
  13. package/es/types/client.js +7 -0
  14. package/es/types/collector.d.ts +7 -0
  15. package/es/types/collector.js +1 -0
  16. package/es/types/processor.d.ts +8 -0
  17. package/es/types/processor.js +1 -0
  18. package/es/types/reporter.d.ts +8 -0
  19. package/es/types/reporter.js +1 -0
  20. package/es/types/rum-event.d.ts +177 -0
  21. package/es/types/rum-event.js +26 -0
  22. package/es/types/shell.d.ts +28 -0
  23. package/es/types/shell.js +1 -0
  24. package/es/utils/base.d.ts +60 -0
  25. package/es/utils/base.js +216 -0
  26. package/es/utils/combineConfig.d.ts +15 -0
  27. package/es/utils/combineConfig.js +101 -0
  28. package/es/utils/exception.d.ts +7 -0
  29. package/es/utils/exception.js +10 -0
  30. package/es/utils/is.d.ts +12 -0
  31. package/es/utils/is.js +39 -0
  32. package/es/utils/match.d.ts +7 -0
  33. package/es/utils/match.js +40 -0
  34. package/es/utils/number.d.ts +17 -0
  35. package/es/utils/number.js +40 -0
  36. package/es/utils/polyfills.d.ts +7 -0
  37. package/es/utils/polyfills.js +28 -0
  38. package/es/utils/trace.d.ts +28 -0
  39. package/es/utils/trace.js +105 -0
  40. package/es/utils/verify.d.ts +2 -0
  41. package/es/utils/verify.js +35 -0
  42. package/lib/model/reporter.js +1 -4
  43. package/lib/model/shell.d.ts +2 -1
  44. package/lib/model/shell.js +26 -20
  45. package/lib/utils/base.d.ts +2 -2
  46. package/lib/utils/base.js +9 -5
  47. package/package.json +6 -2
@@ -0,0 +1,35 @@
1
+ import { isNumber, isObject, isString } from "./is";
2
+ export function verifyProperties(attrs) {
3
+ if (!isObject(attrs)) {
4
+ return;
5
+ }
6
+ var copyAttrs = Object.assign({}, attrs);
7
+ Object.keys(copyAttrs).forEach(function (key) {
8
+ var val = copyAttrs[key];
9
+ // 验证 key 长度
10
+ if (key.length > 50) {
11
+ var shortKey = key.substring(0, 50);
12
+ copyAttrs[shortKey] = val;
13
+ delete copyAttrs[key];
14
+ key = shortKey;
15
+ }
16
+ // 验证 value 类型和长度
17
+ if (!isString(val) && !isNumber(val)) {
18
+ delete copyAttrs[key];
19
+ } else if (isString(val) && val.length > 2e3) {
20
+ copyAttrs[key] = val.substring(0, 2e3);
21
+ }
22
+ });
23
+ var keys = Object.keys(copyAttrs);
24
+ if (!keys.length) {
25
+ return;
26
+ }
27
+ if (keys.length > 20) {
28
+ keys.forEach(function (key, index) {
29
+ if (index > 19) {
30
+ delete copyAttrs[key];
31
+ }
32
+ });
33
+ }
34
+ return copyAttrs;
35
+ }
@@ -125,7 +125,6 @@ var Reporter = exports["default"] = /*#__PURE__*/function () {
125
125
  this.eventQueue = [];
126
126
  };
127
127
  _proto.mergeEvent = function mergeEvent(ctx, events, view) {
128
- var _config$net;
129
128
  var config = ctx.getConfig();
130
129
  var session = ctx.session;
131
130
  var sessionId = session.getSessionId();
@@ -157,9 +156,7 @@ var Reporter = exports["default"] = /*#__PURE__*/function () {
157
156
  session: {
158
157
  id: sessionId
159
158
  },
160
- net: {
161
- model: (_config$net = config.net) === null || _config$net === void 0 ? void 0 : _config$net.model
162
- },
159
+ net: {},
163
160
  view: view,
164
161
  events: events
165
162
  };
@@ -4,7 +4,8 @@ import { IShell } from "../types/shell";
4
4
  export default abstract class Shell implements IShell {
5
5
  client: IClient;
6
6
  constructor(config?: IConfiguration);
7
- updateFromRemoteConfig(config: any): void;
7
+ getCombinedConfig(config?: IConfiguration): any;
8
+ updateFromRemoteConfig(config: any, reSetup?: boolean): void;
8
9
  /**
9
10
  * 初始化
10
11
  */
@@ -15,36 +15,47 @@ var Shell = exports["default"] = /*#__PURE__*/function () {
15
15
  this.client = void 0;
16
16
  this.client = new _client["default"]();
17
17
  if (config && this.init) {
18
- var combinedConf;
19
- if ((0, _combineConfig.isRemoteConfigEnable)(config) && (0, _is.isFunction)(this.getLocalConfig)) {
20
- var localConfig = this.getLocalConfig(0, config.pid);
21
- combinedConf = (0, _combineConfig["default"])(config, localConfig);
22
- }
23
- this.init(combinedConf || config);
24
-
25
- // 拉取远程配置进行更新
26
- this.updateFromRemoteConfig(config);
18
+ this.init(config);
27
19
  }
20
+ // if (config && this.init) {
21
+ // this.init(this.getCombinedConfig(config));
22
+
23
+ // // 拉取远程配置进行更新
24
+ // this.updateFromRemoteConfig(config);
25
+ // }
28
26
  }
29
27
  var _proto = Shell.prototype;
30
- _proto.updateFromRemoteConfig = function updateFromRemoteConfig(config) {
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
+ }
31
40
  // 请求动态配置
32
41
  if (config.pid && (0, _combineConfig.isRemoteConfigEnable)(config) && (0, _is.isFunction)(this.getRemoteConfig)) {
33
42
  var that = this;
34
- this.getRemoteConfig((0, _combineConfig.getRemoteConfigUrl)(config), config).then(function (remoteConfig) {
43
+ var proms = this.getRemoteConfig((0, _combineConfig.getRemoteConfigUrl)(config), config);
44
+ proms === null || proms === void 0 ? void 0 : proms.then(function (remoteConfig) {
35
45
  if (!remoteConfig || remoteConfig.errorStatus !== undefined) return;
36
46
  var combinedConf = (0, _combineConfig["default"])(config, remoteConfig);
37
47
 
38
48
  // 无有效的新配置,无需更新
39
49
  if (!combinedConf) return;
40
- if ((0, _is.isObject)(console) && (0, _is.isFunction)(console.log)) {
41
- console.log("合并后动态配置后的新配置:\n", combinedConf);
50
+
51
+ // 存储到本地
52
+ if ((0, _is.isFunction)(that.storeRemoteConfig)) {
53
+ that.storeRemoteConfig(remoteConfig, config.pid);
42
54
  }
55
+ if (reSetup === false || config.remoteConfig.reSetup === false) return;
43
56
  var context = that.client.getContext();
44
-
45
57
  // 更新配置
46
58
  context.setConfig(combinedConf);
47
-
48
59
  // 逐个更新collector
49
60
  var collectors = that.client.getCollectors();
50
61
  collectors.forEach(function (collector) {
@@ -53,11 +64,6 @@ var Shell = exports["default"] = /*#__PURE__*/function () {
53
64
  collector.setup(context, that.client.sendEvent);
54
65
  }
55
66
  });
56
-
57
- // 存储到本地
58
- if ((0, _is.isFunction)(that.storeRemoteConfig)) {
59
- that.storeRemoteConfig(remoteConfig, config.pid);
60
- }
61
67
  });
62
68
  }
63
69
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
- * 劫持函数
2
+ * 劫持函数或原型
3
3
  */
4
- export declare function interceptFunction(target: any, name: string, callback: Function): void;
4
+ export declare function interceptFunction(target: any, name: string, callback: Function, isPrototype?: boolean): void;
5
5
  /**
6
6
  * 还原函数
7
7
  */
package/lib/utils/base.js CHANGED
@@ -19,18 +19,22 @@ var PRE_SUF_FIX = '__';
19
19
  var TYPE_REG = /^\[object ([a-z]*)\]$/;
20
20
 
21
21
  /**
22
- * 劫持函数
22
+ * 劫持函数或原型
23
23
  */
24
- function interceptFunction(target, name, callback) {
24
+ function interceptFunction(target, name, callback, isPrototype) {
25
+ if (isPrototype === void 0) {
26
+ isPrototype = false;
27
+ }
25
28
  var registeredMethod = target[name];
26
29
  target["" + PRE_SUF_FIX + name + PRE_SUF_FIX] = registeredMethod;
27
30
  target[name] = function () {
31
+ var ctx = isPrototype ? this : target;
28
32
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
29
33
  args[_key] = arguments[_key];
30
34
  }
31
- callback.apply(this, args);
35
+ callback.apply(ctx, args);
32
36
  if ((0, _is.isFunction)(registeredMethod)) {
33
- return registeredMethod.apply(this, args);
37
+ return registeredMethod.apply(ctx, args);
34
38
  }
35
39
  };
36
40
  }
@@ -185,7 +189,7 @@ function transStrToReg(str) {
185
189
  }
186
190
 
187
191
  /**
188
- *
192
+ *
189
193
  * @param config 配置
190
194
  * @param keys 需要转换的字段
191
195
  */
package/package.json CHANGED
@@ -1,16 +1,20 @@
1
1
  {
2
2
  "name": "@arms/rum-core",
3
- "version": "0.0.34",
3
+ "version": "0.0.36",
4
4
  "description": "arms rum javascript sdk core",
5
5
  "author": "guangli.fj <guangli.fj@alibaba-inc.com>",
6
6
  "license": "ISC",
7
7
  "main": "lib/index.js",
8
+ "module": "es/index.js",
8
9
  "directories": {
9
10
  "lib": "lib",
11
+ "es": "es",
10
12
  "test": "__tests__"
11
13
  },
12
14
  "files": [
13
- "lib"
15
+ "lib",
16
+ "es",
17
+ "dist"
14
18
  ],
15
19
  "publishConfig": {
16
20
  "access": "public"