@cloudcare/browser-core 2.0.10 → 2.0.12

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.
@@ -46,7 +46,6 @@ function areCookiesAuthorized(options) {
46
46
  setCookie(testCookieName, testCookieValue, _tools.ONE_SECOND, options);
47
47
  return getCookie(testCookieName) === testCookieValue;
48
48
  } catch (error) {
49
- console.error(error);
50
49
  return false;
51
50
  }
52
51
  }
package/cjs/dataMap.js CHANGED
@@ -53,10 +53,10 @@ var dataMap = {
53
53
  type: _enums.RumEventType.VIEW,
54
54
  tags: {
55
55
  view_loading_type: 'view.loading_type',
56
- view_apdex_level: 'view.apdex_level',
57
- is_active: 'view.is_active'
56
+ view_apdex_level: 'view.apdex_level'
58
57
  },
59
58
  fields: {
59
+ is_active: 'view.is_active',
60
60
  session_replay_stats: '_dd.replay_stats',
61
61
  session_is_active: 'session.is_active',
62
62
  view_error_count: 'view.error.count',
@@ -14,9 +14,10 @@ var END_OF_TIMES = Infinity;
14
14
  var CLEAR_OLD_CONTEXTS_INTERVAL = _tools.ONE_MINUTE;
15
15
  exports.CLEAR_OLD_CONTEXTS_INTERVAL = CLEAR_OLD_CONTEXTS_INTERVAL;
16
16
 
17
- function ContextHistory(expireDelay) {
17
+ function ContextHistory(expireDelay, maxEntries) {
18
18
  this.expireDelay = expireDelay;
19
19
  this.entries = [];
20
+ this.maxEntries = maxEntries;
20
21
 
21
22
  var _this = this;
22
23
 
@@ -43,6 +44,11 @@ ContextHistory.prototype.add = function (context, startTime) {
43
44
  entry.endTime = endTime;
44
45
  }
45
46
  };
47
+
48
+ if (this.maxEntries && this.entries.length >= this.maxEntries) {
49
+ this.entries.pop();
50
+ }
51
+
46
52
  this.entries.unshift(entry);
47
53
  return entry;
48
54
  };
@@ -83,13 +89,19 @@ ContextHistory.prototype.closeActive = function (endTime) {
83
89
  */
84
90
 
85
91
 
86
- ContextHistory.prototype.findAll = function (startTime) {
92
+ ContextHistory.prototype.findAll = function (startTime, duration) {
93
+ if (typeof duration === 'undefined') {
94
+ duration = 0;
95
+ }
96
+
97
+ var endTime = (0, _tools.addDuration)(startTime, duration);
98
+
87
99
  if (typeof startTime === 'undefined') {
88
100
  startTime = END_OF_TIMES;
89
101
  }
90
102
 
91
103
  var result = (0, _tools.filter)(this.entries, function (entry) {
92
- return entry.startTime <= startTime && startTime <= entry.endTime;
104
+ return entry.startTime <= endTime && startTime <= entry.endTime;
93
105
  });
94
106
  return (0, _tools.map)(result, function (entry) {
95
107
  return entry.context;
@@ -86,7 +86,7 @@ exports.values = exports.utf8Encode = exports.urlParse = exports.unique = export
86
86
  exports.withSnakeCaseKeys = withSnakeCaseKeys;
87
87
  exports.xhr = void 0;
88
88
 
89
- var _enums = require("./enums");
89
+ var _display = require("./display");
90
90
 
91
91
  var _timer = require("./timer");
92
92
 
@@ -385,9 +385,23 @@ var every = function every(arr, fn, self) {
385
385
 
386
386
  exports.every = every;
387
387
 
388
- var matchList = function matchList(list, value) {
388
+ var matchList = function matchList(list, value, useStartsWith) {
389
+ if (useStartsWith === undefined) {
390
+ useStartsWith = false;
391
+ }
392
+
389
393
  return some(list, function (item) {
390
- return item === value || item instanceof RegExp && item.test(value);
394
+ try {
395
+ if (typeof item === 'function') {
396
+ return item(value);
397
+ } else if (item instanceof RegExp) {
398
+ return item.test(value);
399
+ } else if (typeof item === 'string') {
400
+ return useStartsWith ? startsWith(value, item) : item === value;
401
+ }
402
+ } catch (e) {
403
+ _display.display.error(e);
404
+ }
391
405
  });
392
406
  }; // https://github.com/jquery/jquery/blob/a684e6ba836f7c553968d7d026ed7941e1a612d8/src/selector/escapeSelector.js
393
407
 
@@ -57,21 +57,14 @@ var processedMessageByDataMap = function processedMessageByDataMap(message) {
57
57
  var fields = (0, _tools.extend)({}, _dataMap.commonFields, value.fields);
58
58
  (0, _tools.each)(fields, function (_value, _key) {
59
59
  if ((0, _tools.isArray)(_value) && _value.length === 2) {
60
- var type = _value[0],
61
- value_path = _value[1];
60
+ var value_path = _value[1];
62
61
 
63
62
  var _valueData = (0, _tools.findByPath)(message, value_path);
64
63
 
65
64
  filterFileds.push(_key);
66
65
 
67
- if (_valueData || (0, _tools.isNumber)(_valueData)) {
66
+ if (_valueData !== undefined && _valueData !== null) {
68
67
  rowData.fields[_key] = _valueData; // 这里不需要转译
69
- // _valueData =
70
- // type === 'string'
71
- // ? '"' +
72
- // _valueData.replace(/[\\]*"/g, '"').replace(/"/g, '\\"') +
73
- // '"'
74
- // : escapeRowData(_valueData)
75
68
 
76
69
  fieldsStr.push((0, _rowData.escapeRowData)(_key) + '=' + (0, _rowData.escapeRowField)(_valueData));
77
70
  }
@@ -80,7 +73,7 @@ var processedMessageByDataMap = function processedMessageByDataMap(message) {
80
73
 
81
74
  filterFileds.push(_key);
82
75
 
83
- if (_valueData || (0, _tools.isNumber)(_valueData)) {
76
+ if (_valueData !== undefined && _valueData !== null) {
84
77
  rowData.fields[_key] = _valueData; // 这里不需要转译
85
78
 
86
79
  fieldsStr.push((0, _rowData.escapeRowData)(_key) + '=' + (0, _rowData.escapeRowField)(_valueData));
@@ -96,7 +89,7 @@ var processedMessageByDataMap = function processedMessageByDataMap(message) {
96
89
  if (filterFileds.indexOf(_key) > -1) return;
97
90
  filterFileds.push(_key);
98
91
 
99
- if (_value || (0, _tools.isNumber)(_value)) {
92
+ if (_value !== undefined && _value !== null) {
100
93
  _tagKeys.push(_key);
101
94
 
102
95
  rowData.fields[_key] = _value; // 这里不需要转译
@@ -114,7 +107,7 @@ var processedMessageByDataMap = function processedMessageByDataMap(message) {
114
107
  if (message.type === _enums.RumEventType.LOGGER) {
115
108
  // 这里处理日志类型数据自定义字段
116
109
  (0, _tools.each)(message, function (value, key) {
117
- if (filterFileds.indexOf(key) === -1 && ((0, _tools.isNumber)(value) || value)) {
110
+ if (filterFileds.indexOf(key) === -1 && value !== undefined && value !== null) {
118
111
  rowData.fields[key] = value; // 这里不需要转译
119
112
 
120
113
  fieldsStr.push((0, _rowData.escapeRowData)(key) + '=' + (0, _rowData.escapeRowField)(value));
@@ -28,7 +28,6 @@ export function areCookiesAuthorized(options) {
28
28
  setCookie(testCookieName, testCookieValue, ONE_SECOND, options);
29
29
  return getCookie(testCookieName) === testCookieValue;
30
30
  } catch (error) {
31
- console.error(error);
32
31
  return false;
33
32
  }
34
33
  }
package/esm/dataMap.js CHANGED
@@ -43,10 +43,10 @@ export var dataMap = {
43
43
  type: RumEventType.VIEW,
44
44
  tags: {
45
45
  view_loading_type: 'view.loading_type',
46
- view_apdex_level: 'view.apdex_level',
47
- is_active: 'view.is_active'
46
+ view_apdex_level: 'view.apdex_level'
48
47
  },
49
48
  fields: {
49
+ is_active: 'view.is_active',
50
50
  session_replay_stats: '_dd.replay_stats',
51
51
  session_is_active: 'session.is_active',
52
52
  view_error_count: 'view.error.count',
@@ -1,10 +1,11 @@
1
- import { relativeNow, ONE_MINUTE, filter, map } from './tools';
1
+ import { relativeNow, ONE_MINUTE, filter, map, addDuration } from './tools';
2
2
  import { setInterval, clearInterval } from './timer';
3
3
  var END_OF_TIMES = Infinity;
4
4
  export var CLEAR_OLD_CONTEXTS_INTERVAL = ONE_MINUTE;
5
- export function ContextHistory(expireDelay) {
5
+ export function ContextHistory(expireDelay, maxEntries) {
6
6
  this.expireDelay = expireDelay;
7
7
  this.entries = [];
8
+ this.maxEntries = maxEntries;
8
9
 
9
10
  var _this = this;
10
11
 
@@ -31,6 +32,11 @@ ContextHistory.prototype.add = function (context, startTime) {
31
32
  entry.endTime = endTime;
32
33
  }
33
34
  };
35
+
36
+ if (this.maxEntries && this.entries.length >= this.maxEntries) {
37
+ this.entries.pop();
38
+ }
39
+
34
40
  this.entries.unshift(entry);
35
41
  return entry;
36
42
  };
@@ -71,13 +77,19 @@ ContextHistory.prototype.closeActive = function (endTime) {
71
77
  */
72
78
 
73
79
 
74
- ContextHistory.prototype.findAll = function (startTime) {
80
+ ContextHistory.prototype.findAll = function (startTime, duration) {
81
+ if (typeof duration === 'undefined') {
82
+ duration = 0;
83
+ }
84
+
85
+ var endTime = addDuration(startTime, duration);
86
+
75
87
  if (typeof startTime === 'undefined') {
76
88
  startTime = END_OF_TIMES;
77
89
  }
78
90
 
79
91
  var result = filter(this.entries, function (entry) {
80
- return entry.startTime <= startTime && startTime <= entry.endTime;
92
+ return entry.startTime <= endTime && startTime <= entry.endTime;
81
93
  });
82
94
  return map(result, function (entry) {
83
95
  return entry.context;
@@ -1,4 +1,4 @@
1
- import { DOM_EVENT } from './enums';
1
+ import { display } from './display';
2
2
  import { setTimeout, clearTimeout } from './timer';
3
3
  var ArrayProto = Array.prototype;
4
4
  var FuncProto = Function.prototype;
@@ -242,9 +242,23 @@ export var every = function every(arr, fn, self) {
242
242
 
243
243
  return flag;
244
244
  };
245
- export var matchList = function matchList(list, value) {
245
+ export var matchList = function matchList(list, value, useStartsWith) {
246
+ if (useStartsWith === undefined) {
247
+ useStartsWith = false;
248
+ }
249
+
246
250
  return some(list, function (item) {
247
- return item === value || item instanceof RegExp && item.test(value);
251
+ try {
252
+ if (typeof item === 'function') {
253
+ return item(value);
254
+ } else if (item instanceof RegExp) {
255
+ return item.test(value);
256
+ } else if (typeof item === 'string') {
257
+ return useStartsWith ? startsWith(value, item) : item === value;
258
+ }
259
+ } catch (e) {
260
+ display.error(e);
261
+ }
248
262
  });
249
263
  }; // https://github.com/jquery/jquery/blob/a684e6ba836f7c553968d7d026ed7941e1a612d8/src/selector/escapeSelector.js
250
264
 
@@ -42,21 +42,14 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
42
42
  var fields = extend({}, commonFields, value.fields);
43
43
  each(fields, function (_value, _key) {
44
44
  if (isArray(_value) && _value.length === 2) {
45
- var type = _value[0],
46
- value_path = _value[1];
45
+ var value_path = _value[1];
47
46
 
48
47
  var _valueData = findByPath(message, value_path);
49
48
 
50
49
  filterFileds.push(_key);
51
50
 
52
- if (_valueData || isNumber(_valueData)) {
51
+ if (_valueData !== undefined && _valueData !== null) {
53
52
  rowData.fields[_key] = _valueData; // 这里不需要转译
54
- // _valueData =
55
- // type === 'string'
56
- // ? '"' +
57
- // _valueData.replace(/[\\]*"/g, '"').replace(/"/g, '\\"') +
58
- // '"'
59
- // : escapeRowData(_valueData)
60
53
 
61
54
  fieldsStr.push(escapeRowData(_key) + '=' + escapeRowField(_valueData));
62
55
  }
@@ -65,7 +58,7 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
65
58
 
66
59
  filterFileds.push(_key);
67
60
 
68
- if (_valueData || isNumber(_valueData)) {
61
+ if (_valueData !== undefined && _valueData !== null) {
69
62
  rowData.fields[_key] = _valueData; // 这里不需要转译
70
63
 
71
64
  fieldsStr.push(escapeRowData(_key) + '=' + escapeRowField(_valueData));
@@ -81,7 +74,7 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
81
74
  if (filterFileds.indexOf(_key) > -1) return;
82
75
  filterFileds.push(_key);
83
76
 
84
- if (_value || isNumber(_value)) {
77
+ if (_value !== undefined && _value !== null) {
85
78
  _tagKeys.push(_key);
86
79
 
87
80
  rowData.fields[_key] = _value; // 这里不需要转译
@@ -99,7 +92,7 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
99
92
  if (message.type === RumEventType.LOGGER) {
100
93
  // 这里处理日志类型数据自定义字段
101
94
  each(message, function (value, key) {
102
- if (filterFileds.indexOf(key) === -1 && (isNumber(value) || value)) {
95
+ if (filterFileds.indexOf(key) === -1 && value !== undefined && value !== null) {
103
96
  rowData.fields[key] = value; // 这里不需要转译
104
97
 
105
98
  fieldsStr.push(escapeRowData(key) + '=' + escapeRowField(value));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudcare/browser-core",
3
- "version": "2.0.10",
3
+ "version": "2.0.12",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "scripts": {
@@ -20,5 +20,5 @@
20
20
  "author": "dataflux",
21
21
  "license": "MIT",
22
22
  "description": "DataFlux RUM Web 端数据指标监控",
23
- "gitHead": "197457783c66faf642df01e4a6149fd4fc559d37"
23
+ "gitHead": "98664a15be351def98c4e9b33c8366b1fb8aa652"
24
24
  }
@@ -28,7 +28,6 @@ export function deleteCookie(name, options) {
28
28
  setCookie(name, '', 0, options)
29
29
  }
30
30
 
31
-
32
31
  export function areCookiesAuthorized(options) {
33
32
  if (document.cookie === undefined || document.cookie === null) {
34
33
  return false
@@ -41,7 +40,6 @@ export function areCookiesAuthorized(options) {
41
40
  setCookie(testCookieName, testCookieValue, ONE_SECOND, options)
42
41
  return getCookie(testCookieName) === testCookieValue
43
42
  } catch (error) {
44
- console.error(error)
45
43
  return false
46
44
  }
47
45
  }
package/src/dataMap.js CHANGED
@@ -42,10 +42,10 @@ export var dataMap = {
42
42
  type: RumEventType.VIEW,
43
43
  tags: {
44
44
  view_loading_type: 'view.loading_type',
45
- view_apdex_level: 'view.apdex_level',
46
- is_active: 'view.is_active'
45
+ view_apdex_level: 'view.apdex_level'
47
46
  },
48
47
  fields: {
48
+ is_active: 'view.is_active',
49
49
  session_replay_stats: '_dd.replay_stats',
50
50
  session_is_active: 'session.is_active',
51
51
  view_error_count: 'view.error.count',
@@ -1,16 +1,18 @@
1
- import { relativeNow, ONE_MINUTE, filter, map } from './tools'
1
+ import { relativeNow, ONE_MINUTE, filter, map, addDuration } from './tools'
2
2
  import { setInterval, clearInterval } from './timer'
3
3
  var END_OF_TIMES = Infinity
4
4
 
5
5
  export var CLEAR_OLD_CONTEXTS_INTERVAL = ONE_MINUTE
6
- export function ContextHistory(expireDelay) {
6
+ export function ContextHistory(expireDelay, maxEntries) {
7
7
  this.expireDelay = expireDelay
8
8
  this.entries = []
9
+ this.maxEntries = maxEntries
9
10
  var _this = this
10
11
  this.clearOldContextsInterval = setInterval(function () {
11
12
  _this.clearOldContexts()
12
13
  }, CLEAR_OLD_CONTEXTS_INTERVAL)
13
14
  }
15
+
14
16
  ContextHistory.prototype.add = function (context, startTime) {
15
17
  var _this = this
16
18
  var entry = {
@@ -27,6 +29,9 @@ ContextHistory.prototype.add = function (context, startTime) {
27
29
  entry.endTime = endTime
28
30
  }
29
31
  }
32
+ if (this.maxEntries && this.entries.length >= this.maxEntries) {
33
+ this.entries.pop()
34
+ }
30
35
  this.entries.unshift(entry)
31
36
  return entry
32
37
  }
@@ -58,12 +63,16 @@ ContextHistory.prototype.closeActive = function (endTime) {
58
63
  * Return all contexts that were active during `startTime`, or all currently active contexts if no
59
64
  * `startTime` is provided.
60
65
  */
61
- ContextHistory.prototype.findAll = function (startTime) {
66
+ ContextHistory.prototype.findAll = function (startTime, duration) {
67
+ if (typeof duration === 'undefined') {
68
+ duration = 0
69
+ }
70
+ var endTime = addDuration(startTime, duration)
62
71
  if (typeof startTime === 'undefined') {
63
72
  startTime = END_OF_TIMES
64
73
  }
65
74
  var result = filter(this.entries, function (entry) {
66
- return entry.startTime <= startTime && startTime <= entry.endTime
75
+ return entry.startTime <= endTime && startTime <= entry.endTime
67
76
  })
68
77
  return map(result, function (entry) {
69
78
  return entry.context
@@ -1,4 +1,4 @@
1
- import { DOM_EVENT } from './enums'
1
+ import { display } from './display'
2
2
  import { setTimeout, clearTimeout } from './timer'
3
3
  var ArrayProto = Array.prototype
4
4
  var FuncProto = Function.prototype
@@ -214,9 +214,22 @@ export var every = function (arr, fn, self) {
214
214
  }
215
215
  return flag
216
216
  }
217
- export var matchList = function (list, value) {
217
+ export var matchList = function (list, value, useStartsWith) {
218
+ if (useStartsWith === undefined) {
219
+ useStartsWith = false
220
+ }
218
221
  return some(list, function (item) {
219
- return item === value || (item instanceof RegExp && item.test(value))
222
+ try {
223
+ if (typeof item === 'function') {
224
+ return item(value)
225
+ } else if (item instanceof RegExp) {
226
+ return item.test(value)
227
+ } else if (typeof item === 'string') {
228
+ return useStartsWith ? startsWith(value, item) : item === value
229
+ }
230
+ } catch (e) {
231
+ display.error(e)
232
+ }
220
233
  })
221
234
  }
222
235
  // https://github.com/jquery/jquery/blob/a684e6ba836f7c553968d7d026ed7941e1a612d8/src/selector/escapeSelector.js
@@ -55,18 +55,11 @@ export var processedMessageByDataMap = function (message) {
55
55
  var fields = extend({}, commonFields, value.fields)
56
56
  each(fields, function (_value, _key) {
57
57
  if (isArray(_value) && _value.length === 2) {
58
- var type = _value[0],
59
- value_path = _value[1]
58
+ var value_path = _value[1]
60
59
  var _valueData = findByPath(message, value_path)
61
60
  filterFileds.push(_key)
62
- if (_valueData || isNumber(_valueData)) {
61
+ if (_valueData !== undefined && _valueData !== null) {
63
62
  rowData.fields[_key] = _valueData // 这里不需要转译
64
- // _valueData =
65
- // type === 'string'
66
- // ? '"' +
67
- // _valueData.replace(/[\\]*"/g, '"').replace(/"/g, '\\"') +
68
- // '"'
69
- // : escapeRowData(_valueData)
70
63
  fieldsStr.push(
71
64
  escapeRowData(_key) + '=' + escapeRowField(_valueData)
72
65
  )
@@ -74,7 +67,7 @@ export var processedMessageByDataMap = function (message) {
74
67
  } else if (isString(_value)) {
75
68
  var _valueData = findByPath(message, _value)
76
69
  filterFileds.push(_key)
77
- if (_valueData || isNumber(_valueData)) {
70
+ if (_valueData !== undefined && _valueData !== null) {
78
71
  rowData.fields[_key] = _valueData // 这里不需要转译
79
72
  fieldsStr.push(
80
73
  escapeRowData(_key) + '=' + escapeRowField(_valueData)
@@ -93,7 +86,7 @@ export var processedMessageByDataMap = function (message) {
93
86
  // 如果和之前tag重名,则舍弃
94
87
  if (filterFileds.indexOf(_key) > -1) return
95
88
  filterFileds.push(_key)
96
- if (_value || isNumber(_value)) {
89
+ if (_value !== undefined && _value !== null) {
97
90
  _tagKeys.push(_key)
98
91
  rowData.fields[_key] = _value // 这里不需要转译
99
92
  fieldsStr.push(escapeRowData(_key) + '=' + escapeRowField(_value))
@@ -109,7 +102,11 @@ export var processedMessageByDataMap = function (message) {
109
102
  if (message.type === RumEventType.LOGGER) {
110
103
  // 这里处理日志类型数据自定义字段
111
104
  each(message, function (value, key) {
112
- if (filterFileds.indexOf(key) === -1 && (isNumber(value) || value)) {
105
+ if (
106
+ filterFileds.indexOf(key) === -1 &&
107
+ value !== undefined &&
108
+ value !== null
109
+ ) {
113
110
  rowData.fields[key] = value // 这里不需要转译
114
111
  fieldsStr.push(escapeRowData(key) + '=' + escapeRowField(value))
115
112
  }