@cloudcare/browser-core 2.0.4 → 2.0.6
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/cjs/browser/addEventListener.js +57 -0
- package/cjs/browser/fetchObservable.js +4 -5
- package/cjs/browser/pageExitObservable.js +4 -2
- package/cjs/browser/runOnReadyState.js +21 -0
- package/cjs/browser/xhrObservable.js +7 -5
- package/cjs/configuration/configuration.js +5 -3
- package/cjs/console/consoleObservable.js +3 -1
- package/cjs/dataMap.js +1 -0
- package/cjs/helper/byteUtils.js +26 -0
- package/cjs/helper/contextHistory.js +4 -2
- package/cjs/helper/createEventRateLimiter.js +3 -1
- package/cjs/helper/errorTools.js +4 -2
- package/cjs/helper/instrumentMethod.js +2 -4
- package/cjs/helper/serialisation/contextManager.js +84 -0
- package/cjs/helper/serialisation/heavyCustomerDataWarning.js +34 -0
- package/cjs/helper/serialisation/jsonStringify.js +57 -0
- package/cjs/helper/serialisation/rowData.js +50 -0
- package/cjs/helper/timer.js +29 -0
- package/cjs/helper/tools.js +10 -331
- package/cjs/index.js +117 -0
- package/cjs/init.js +6 -6
- package/cjs/report/reportObservable.js +4 -2
- package/cjs/session/sessionCookieStore.js +3 -1
- package/cjs/session/sessionManagement.js +10 -5
- package/cjs/session/sessionStore.js +10 -4
- package/cjs/transport/batch.js +40 -91
- package/cjs/transport/flushController.js +121 -0
- package/cjs/transport/httpRequest.js +6 -2
- package/cjs/transport/index.js +9 -1
- package/cjs/transport/sendWithRetryStrategy.js +8 -4
- package/cjs/transport/startBatchWithReplica.js +10 -2
- package/cjs/user/index.js +18 -0
- package/cjs/user/user.js +42 -0
- package/esm/browser/addEventListener.js +46 -0
- package/esm/browser/fetchObservable.js +4 -3
- package/esm/browser/pageExitObservable.js +2 -1
- package/esm/browser/runOnReadyState.js +12 -0
- package/esm/browser/xhrObservable.js +6 -5
- package/esm/configuration/configuration.js +2 -1
- package/esm/console/consoleObservable.js +2 -1
- package/esm/dataMap.js +1 -0
- package/esm/helper/byteUtils.js +16 -0
- package/esm/helper/contextHistory.js +1 -0
- package/esm/helper/createEventRateLimiter.js +1 -0
- package/esm/helper/errorTools.js +2 -1
- package/esm/helper/instrumentMethod.js +1 -3
- package/esm/helper/serialisation/contextManager.js +70 -0
- package/esm/helper/serialisation/heavyCustomerDataWarning.js +20 -0
- package/esm/helper/serialisation/jsonStringify.js +46 -0
- package/esm/helper/serialisation/rowData.js +33 -0
- package/esm/helper/timer.js +14 -0
- package/esm/helper/tools.js +1 -292
- package/esm/index.js +10 -1
- package/esm/init.js +6 -6
- package/esm/report/reportObservable.js +3 -2
- package/esm/session/sessionCookieStore.js +1 -0
- package/esm/session/sessionManagement.js +5 -2
- package/esm/session/sessionStore.js +7 -2
- package/esm/transport/batch.js +31 -85
- package/esm/transport/flushController.js +114 -0
- package/esm/transport/httpRequest.js +5 -2
- package/esm/transport/index.js +2 -1
- package/esm/transport/sendWithRetryStrategy.js +3 -1
- package/esm/transport/startBatchWithReplica.js +9 -2
- package/esm/user/index.js +1 -0
- package/esm/user/user.js +32 -0
- package/package.json +22 -22
- package/src/browser/addEventListener.js +50 -0
- package/src/browser/fetchObservable.js +5 -5
- package/src/browser/pageExitObservable.js +4 -5
- package/src/browser/runOnReadyState.js +16 -0
- package/src/browser/xhrObservable.js +57 -32
- package/src/configuration/configuration.js +1 -1
- package/src/console/consoleObservable.js +22 -12
- package/src/dataMap.js +1 -0
- package/src/helper/byteUtils.js +17 -0
- package/src/helper/contextHistory.js +1 -1
- package/src/helper/createEventRateLimiter.js +7 -9
- package/src/helper/errorTools.js +2 -1
- package/src/helper/instrumentMethod.js +1 -2
- package/src/helper/serialisation/contextManager.js +79 -0
- package/src/helper/serialisation/heavyCustomerDataWarning.js +28 -0
- package/src/helper/serialisation/jsonStringify.js +47 -0
- package/src/helper/serialisation/rowData.js +41 -0
- package/src/helper/timer.js +21 -0
- package/src/helper/tools.js +2 -301
- package/src/index.js +11 -0
- package/src/init.js +6 -6
- package/src/report/reportObservable.js +40 -25
- package/src/session/sessionCookieStore.js +24 -14
- package/src/session/sessionManagement.js +34 -17
- package/src/session/sessionStore.js +7 -2
- package/src/transport/batch.js +39 -91
- package/src/transport/flushController.js +115 -0
- package/src/transport/httpRequest.js +13 -6
- package/src/transport/index.js +1 -0
- package/src/transport/sendWithRetryStrategy.js +3 -7
- package/src/transport/startBatchWithReplica.js +11 -7
- package/src/user/index.js +1 -0
- package/src/user/user.js +31 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { noop } from './tools'
|
|
2
|
-
import {
|
|
2
|
+
import { setTimeout } from './timer'
|
|
3
3
|
export function instrumentMethod(object, method, instrumentationFactory) {
|
|
4
4
|
var original = object[method]
|
|
5
5
|
|
|
@@ -54,7 +54,6 @@ export function instrumentSetter(object, property, after) {
|
|
|
54
54
|
}
|
|
55
55
|
// Using the patched `setTimeout` from Zone.js triggers a rendering loop in some Angular
|
|
56
56
|
// component, see issue RUMF-1443
|
|
57
|
-
var setTimeout = getZoneJsOriginalValue(window, 'setTimeout')
|
|
58
57
|
var instrumentation = function (thisObject, value) {
|
|
59
58
|
// put hooked setter into event loop to avoid of set latency
|
|
60
59
|
setTimeout(function () {
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { computeBytesCount } from '../byteUtils'
|
|
2
|
+
import { deepClone, throttle } from '../tools'
|
|
3
|
+
import { jsonStringify } from './jsonStringify'
|
|
4
|
+
import { warnIfCustomerDataLimitReached } from './heavyCustomerDataWarning'
|
|
5
|
+
|
|
6
|
+
export var BYTES_COMPUTATION_THROTTLING_DELAY = 200
|
|
7
|
+
|
|
8
|
+
export function createContextManager(customerDataType, computeBytesCountImpl) {
|
|
9
|
+
if (typeof computeBytesCountImpl === 'undefined') {
|
|
10
|
+
computeBytesCountImpl = computeBytesCount
|
|
11
|
+
}
|
|
12
|
+
var context = {}
|
|
13
|
+
var bytesCountCache
|
|
14
|
+
var alreadyWarned = false
|
|
15
|
+
|
|
16
|
+
// Throttle the bytes computation to minimize the impact on performance.
|
|
17
|
+
// Especially useful if the user call context APIs synchronously multiple times in a row
|
|
18
|
+
var computeBytesCountThrottled = throttle(function (context) {
|
|
19
|
+
bytesCountCache = computeBytesCountImpl(jsonStringify(context))
|
|
20
|
+
if (!alreadyWarned) {
|
|
21
|
+
alreadyWarned = warnIfCustomerDataLimitReached(
|
|
22
|
+
bytesCountCache,
|
|
23
|
+
customerDataType
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
}, BYTES_COMPUTATION_THROTTLING_DELAY).throttled
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
getBytesCount: function () {
|
|
30
|
+
return bytesCountCache
|
|
31
|
+
},
|
|
32
|
+
/** @deprecated use getContext instead */
|
|
33
|
+
get: function () {
|
|
34
|
+
return context
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
/** @deprecated use setContextProperty instead */
|
|
38
|
+
add: function (key, value) {
|
|
39
|
+
context[key] = value
|
|
40
|
+
computeBytesCountThrottled(context)
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
/** @deprecated renamed to removeContextProperty */
|
|
44
|
+
remove: function (key) {
|
|
45
|
+
delete context[key]
|
|
46
|
+
computeBytesCountThrottled(context)
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
/** @deprecated use setContext instead */
|
|
50
|
+
set: function (newContext) {
|
|
51
|
+
context = newContext
|
|
52
|
+
computeBytesCountThrottled(context)
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
getContext: function () {
|
|
56
|
+
return deepClone(context)
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
setContext: function (newContext) {
|
|
60
|
+
context = deepClone(newContext)
|
|
61
|
+
computeBytesCountThrottled(context)
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
setContextProperty: function (key, property) {
|
|
65
|
+
context[key] = deepClone(property)
|
|
66
|
+
computeBytesCountThrottled(context)
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
removeContextProperty: function (key) {
|
|
70
|
+
delete context[key]
|
|
71
|
+
computeBytesCountThrottled(context)
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
clearContext: function () {
|
|
75
|
+
context = {}
|
|
76
|
+
bytesCountCache = 0
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ONE_KIBI_BYTE } from '../byteUtils'
|
|
2
|
+
import { display } from '../display'
|
|
3
|
+
|
|
4
|
+
// RUM and logs batch bytes limit is 16KB
|
|
5
|
+
// ensure that we leave room for other event attributes and maintain a decent amount of event per batch
|
|
6
|
+
// (3KB (customer data) + 1KB (other attributes)) * 4 (events per batch) = 16KB
|
|
7
|
+
export var CUSTOMER_DATA_BYTES_LIMIT = 3 * ONE_KIBI_BYTE
|
|
8
|
+
|
|
9
|
+
export var CustomerDataType = {
|
|
10
|
+
FeatureFlag: 'feature flag evaluation',
|
|
11
|
+
User: 'user',
|
|
12
|
+
GlobalContext: 'global context',
|
|
13
|
+
LoggerContext: 'logger context'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function warnIfCustomerDataLimitReached(bytesCount, customerDataType) {
|
|
17
|
+
if (bytesCount > CUSTOMER_DATA_BYTES_LIMIT) {
|
|
18
|
+
display.warn(
|
|
19
|
+
'The ' +
|
|
20
|
+
customerDataType +
|
|
21
|
+
'data is over ' +
|
|
22
|
+
CUSTOMER_DATA_BYTES_LIMIT / ONE_KIBI_BYTE +
|
|
23
|
+
" KiB. On low connectivity, the SDK has the potential to exhaust the user's upload bandwidth."
|
|
24
|
+
)
|
|
25
|
+
return true
|
|
26
|
+
}
|
|
27
|
+
return false
|
|
28
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { noop } from '../tools'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Custom implementation of JSON.stringify that ignores some toJSON methods. We need to do that
|
|
5
|
+
* because some sites badly override toJSON on certain objects. Removing all toJSON methods from
|
|
6
|
+
* nested values would be too costly, so we just detach them from the root value, and native classes
|
|
7
|
+
* used to build JSON values (Array and Object).
|
|
8
|
+
*
|
|
9
|
+
* Note: this still assumes that JSON.stringify is correct.
|
|
10
|
+
*/
|
|
11
|
+
export function jsonStringify(value, replacer, space) {
|
|
12
|
+
if (typeof value !== 'object' || value === null) {
|
|
13
|
+
return JSON.stringify(value)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Note: The order matter here. We need to detach toJSON methods on parent classes before their
|
|
17
|
+
// subclasses.
|
|
18
|
+
var restoreObjectPrototypeToJson = detachToJsonMethod(Object.prototype)
|
|
19
|
+
var restoreArrayPrototypeToJson = detachToJsonMethod(Array.prototype)
|
|
20
|
+
var restoreValuePrototypeToJson = detachToJsonMethod(
|
|
21
|
+
Object.getPrototypeOf(value)
|
|
22
|
+
)
|
|
23
|
+
var restoreValueToJson = detachToJsonMethod(value)
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
return JSON.stringify(value, replacer, space)
|
|
27
|
+
} catch {
|
|
28
|
+
return '<error: unable to serialize object>'
|
|
29
|
+
} finally {
|
|
30
|
+
restoreObjectPrototypeToJson()
|
|
31
|
+
restoreArrayPrototypeToJson()
|
|
32
|
+
restoreValuePrototypeToJson()
|
|
33
|
+
restoreValueToJson()
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function detachToJsonMethod(value) {
|
|
38
|
+
const object = value
|
|
39
|
+
const objectToJson = object.toJSON
|
|
40
|
+
if (objectToJson) {
|
|
41
|
+
delete object.toJSON
|
|
42
|
+
return () => {
|
|
43
|
+
object.toJSON = objectToJson
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return noop
|
|
47
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsonStringify } from './jsonStringify'
|
|
2
|
+
import { isString } from '../tools'
|
|
3
|
+
export function escapeRowData(str) {
|
|
4
|
+
if (typeof str === 'object' && str) {
|
|
5
|
+
str = jsonStringify(str)
|
|
6
|
+
} else if (!isString(str)) {
|
|
7
|
+
return str
|
|
8
|
+
}
|
|
9
|
+
var reg = /[\s=,"]/g
|
|
10
|
+
return String(str).replace(reg, function (word) {
|
|
11
|
+
return '\\' + word
|
|
12
|
+
})
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function escapeJsonValue(value) {
|
|
16
|
+
if (isString(value)) {
|
|
17
|
+
return value
|
|
18
|
+
} else {
|
|
19
|
+
return jsonStringify(value)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function escapeFieldValueStr(str) {
|
|
24
|
+
return (
|
|
25
|
+
'"' +
|
|
26
|
+
str
|
|
27
|
+
.replace(/\\/g, '\\\\')
|
|
28
|
+
.replace(/[\\]*"/g, '"')
|
|
29
|
+
.replace(/"/g, '\\"') +
|
|
30
|
+
'"'
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
export function escapeRowField(value) {
|
|
34
|
+
if (typeof value === 'object' && value) {
|
|
35
|
+
return escapeFieldValueStr(jsonStringify(value))
|
|
36
|
+
} else if (isString(value)) {
|
|
37
|
+
return escapeFieldValueStr(value)
|
|
38
|
+
} else {
|
|
39
|
+
return value
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getZoneJsOriginalValue } from './getZoneJsOriginalValue'
|
|
2
|
+
import { getGlobalObject } from '../init'
|
|
3
|
+
|
|
4
|
+
export function setTimeout(callback, delay) {
|
|
5
|
+
return getZoneJsOriginalValue(getGlobalObject(), 'setTimeout')(
|
|
6
|
+
callback,
|
|
7
|
+
delay
|
|
8
|
+
)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function clearTimeout(timeoutId) {
|
|
12
|
+
getZoneJsOriginalValue(getGlobalObject(), 'clearTimeout')(timeoutId)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function setInterval(callback, delay) {
|
|
16
|
+
return getZoneJsOriginalValue(window, 'setInterval')(callback, delay)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function clearInterval(timeoutId) {
|
|
20
|
+
getZoneJsOriginalValue(window, 'clearInterval')(timeoutId)
|
|
21
|
+
}
|
package/src/helper/tools.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { DOM_EVENT } from './enums'
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { setTimeout, clearTimeout } from './timer'
|
|
4
3
|
var ArrayProto = Array.prototype
|
|
5
4
|
var FuncProto = Function.prototype
|
|
6
5
|
var ObjProto = Object.prototype
|
|
@@ -735,109 +734,7 @@ export function elementMatches(element, selector) {
|
|
|
735
734
|
}
|
|
736
735
|
return false
|
|
737
736
|
}
|
|
738
|
-
export var addEvent = function () {
|
|
739
|
-
function fixEvent(event) {
|
|
740
|
-
if (event) {
|
|
741
|
-
event.preventDefault = fixEvent.preventDefault
|
|
742
|
-
event.stopPropagation = fixEvent.stopPropagation
|
|
743
|
-
event._getPath = fixEvent._getPath
|
|
744
|
-
}
|
|
745
|
-
return event
|
|
746
|
-
}
|
|
747
|
-
fixEvent._getPath = function () {
|
|
748
|
-
var ev = this
|
|
749
|
-
var polyfill = function () {
|
|
750
|
-
try {
|
|
751
|
-
var element = ev.target
|
|
752
|
-
var pathArr = [element]
|
|
753
|
-
if (element === null || element.parentElement === null) {
|
|
754
|
-
return []
|
|
755
|
-
}
|
|
756
|
-
while (element.parentElement !== null) {
|
|
757
|
-
element = element.parentElement
|
|
758
|
-
pathArr.unshift(element)
|
|
759
|
-
}
|
|
760
|
-
return pathArr
|
|
761
|
-
} catch (error) {
|
|
762
|
-
return []
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
return (
|
|
766
|
-
this.path || (this.composedPath() && this.composedPath()) || polyfill()
|
|
767
|
-
)
|
|
768
|
-
}
|
|
769
|
-
fixEvent.preventDefault = function () {
|
|
770
|
-
this.returnValue = false
|
|
771
|
-
}
|
|
772
|
-
fixEvent.stopPropagation = function () {
|
|
773
|
-
this.cancelBubble = true
|
|
774
|
-
}
|
|
775
|
-
var register_event = function (element, type, handle) {
|
|
776
|
-
if (element && element.addEventListener) {
|
|
777
|
-
element.addEventListener(
|
|
778
|
-
type,
|
|
779
|
-
function (e) {
|
|
780
|
-
e._getPath = fixEvent._getPath
|
|
781
|
-
handler.call(this, e)
|
|
782
|
-
},
|
|
783
|
-
false
|
|
784
|
-
)
|
|
785
|
-
} else {
|
|
786
|
-
var ontype = 'on' + type
|
|
787
|
-
var old_handler = element[ontype]
|
|
788
|
-
element[ontype] = makeHandler(element, handler, old_handler)
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
function makeHandler(element, new_handler, old_handlers) {
|
|
792
|
-
var handler = function (event) {
|
|
793
|
-
event = event || fixEvent(window.event)
|
|
794
|
-
if (!event) {
|
|
795
|
-
return undefined
|
|
796
|
-
}
|
|
797
|
-
event.target = event.srcElement
|
|
798
737
|
|
|
799
|
-
var ret = true
|
|
800
|
-
var old_result, new_result
|
|
801
|
-
if (typeof old_handlers === 'function') {
|
|
802
|
-
old_result = old_handlers(event)
|
|
803
|
-
}
|
|
804
|
-
new_result = new_handler.call(element, event)
|
|
805
|
-
if (false === old_result || false === new_result) {
|
|
806
|
-
ret = false
|
|
807
|
-
}
|
|
808
|
-
return ret
|
|
809
|
-
}
|
|
810
|
-
return handler
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
register_event.apply(null, arguments)
|
|
814
|
-
}
|
|
815
|
-
export var addHashEvent = function (callback) {
|
|
816
|
-
var hashEvent = 'pushState' in window.history ? 'popstate' : 'hashchange'
|
|
817
|
-
addEvent(window, hashEvent, callback)
|
|
818
|
-
}
|
|
819
|
-
export var addSinglePageEvent = function (callback) {
|
|
820
|
-
var current_url = location.href
|
|
821
|
-
var historyPushState = window.history.pushState
|
|
822
|
-
var historyReplaceState = window.history.replaceState
|
|
823
|
-
|
|
824
|
-
window.history.pushState = function () {
|
|
825
|
-
historyPushState.apply(window.history, arguments)
|
|
826
|
-
callback(current_url)
|
|
827
|
-
current_url = location.href
|
|
828
|
-
}
|
|
829
|
-
window.history.replaceState = function () {
|
|
830
|
-
historyReplaceState.apply(window.history, arguments)
|
|
831
|
-
callback(current_url)
|
|
832
|
-
current_url = location.href
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
var singlePageEvent = historyPushState ? 'popstate' : 'hashchange'
|
|
836
|
-
addEvent(window, singlePageEvent, function () {
|
|
837
|
-
callback(current_url)
|
|
838
|
-
current_url = location.href
|
|
839
|
-
})
|
|
840
|
-
}
|
|
841
738
|
export var cookie = {
|
|
842
739
|
get: function (name) {
|
|
843
740
|
var nameEQ = name + '='
|
|
@@ -1493,51 +1390,6 @@ export var getReferrer = function () {
|
|
|
1493
1390
|
export var typeDecide = function (o, type) {
|
|
1494
1391
|
return toString.call(o) === '[object ' + type + ']'
|
|
1495
1392
|
}
|
|
1496
|
-
export function jsonStringify(value, replacer, space) {
|
|
1497
|
-
if (value === null || value === undefined) {
|
|
1498
|
-
return JSON.stringify(value)
|
|
1499
|
-
}
|
|
1500
|
-
var originalToJSON = [false, undefined]
|
|
1501
|
-
if (hasToJSON(value)) {
|
|
1502
|
-
// We need to add a flag and not rely on the truthiness of value.toJSON
|
|
1503
|
-
// because it can be set but undefined and that's actually significant.
|
|
1504
|
-
originalToJSON = [true, value.toJSON]
|
|
1505
|
-
delete value.toJSON
|
|
1506
|
-
}
|
|
1507
|
-
|
|
1508
|
-
var originalProtoToJSON = [false, undefined]
|
|
1509
|
-
var prototype
|
|
1510
|
-
if (typeof value === 'object') {
|
|
1511
|
-
prototype = Object.getPrototypeOf(value)
|
|
1512
|
-
if (hasToJSON(prototype)) {
|
|
1513
|
-
originalProtoToJSON = [true, prototype.toJSON]
|
|
1514
|
-
delete prototype.toJSON
|
|
1515
|
-
}
|
|
1516
|
-
}
|
|
1517
|
-
|
|
1518
|
-
var result
|
|
1519
|
-
try {
|
|
1520
|
-
result = JSON.stringify(value, undefined, space)
|
|
1521
|
-
} catch (e) {
|
|
1522
|
-
result = '<error: unable to serialize object>'
|
|
1523
|
-
} finally {
|
|
1524
|
-
if (originalToJSON[0]) {
|
|
1525
|
-
value.toJSON = originalToJSON[1]
|
|
1526
|
-
}
|
|
1527
|
-
if (originalProtoToJSON[0]) {
|
|
1528
|
-
prototype.toJSON = originalProtoToJSON[1]
|
|
1529
|
-
}
|
|
1530
|
-
}
|
|
1531
|
-
return result
|
|
1532
|
-
}
|
|
1533
|
-
|
|
1534
|
-
function hasToJSON(value) {
|
|
1535
|
-
return (
|
|
1536
|
-
typeof value === 'object' &&
|
|
1537
|
-
value !== null &&
|
|
1538
|
-
value.hasOwnProperty('toJSON')
|
|
1539
|
-
)
|
|
1540
|
-
}
|
|
1541
1393
|
|
|
1542
1394
|
export function noop() {}
|
|
1543
1395
|
|
|
@@ -1546,8 +1398,7 @@ export var ONE_MINUTE = 60 * ONE_SECOND
|
|
|
1546
1398
|
export var ONE_HOUR = 60 * ONE_MINUTE
|
|
1547
1399
|
export var ONE_DAY = 24 * ONE_HOUR
|
|
1548
1400
|
export var ONE_YEAR = 365 * ONE_DAY
|
|
1549
|
-
|
|
1550
|
-
export var ONE_MEBI_BYTE = 1024 * ONE_KIBI_BYTE
|
|
1401
|
+
|
|
1551
1402
|
/**
|
|
1552
1403
|
* Return true if the draw is successful
|
|
1553
1404
|
* @param threshold between 0 and 100
|
|
@@ -1679,108 +1530,11 @@ export function safeTruncate(candidate, length) {
|
|
|
1679
1530
|
return candidate.slice(0, length)
|
|
1680
1531
|
}
|
|
1681
1532
|
|
|
1682
|
-
export function addEventListener(eventTarget, event, listener, options) {
|
|
1683
|
-
return addEventListeners(eventTarget, [event], listener, options)
|
|
1684
|
-
}
|
|
1685
|
-
|
|
1686
|
-
/**
|
|
1687
|
-
* Add event listeners to an event emitter object (Window, Element, mock object...). This provides
|
|
1688
|
-
* a few conveniences compared to using `element.addEventListener` directly:
|
|
1689
|
-
*
|
|
1690
|
-
* * supports IE11 by:
|
|
1691
|
-
* * using an option object only if needed
|
|
1692
|
-
* * emulating the `once` option
|
|
1693
|
-
*
|
|
1694
|
-
* * wraps the listener with a `monitor` function
|
|
1695
|
-
*
|
|
1696
|
-
* * returns a `stop` function to remove the listener
|
|
1697
|
-
*
|
|
1698
|
-
* * with `once: true`, the listener will be called at most once, even if different events are
|
|
1699
|
-
* listened
|
|
1700
|
-
*/
|
|
1701
|
-
|
|
1702
|
-
export function addEventListeners(eventTarget, events, listener, options) {
|
|
1703
|
-
var wrappedListener =
|
|
1704
|
-
options && options.once
|
|
1705
|
-
? function (event) {
|
|
1706
|
-
stop()
|
|
1707
|
-
listener(event)
|
|
1708
|
-
}
|
|
1709
|
-
: listener
|
|
1710
|
-
|
|
1711
|
-
options =
|
|
1712
|
-
options && options.passive
|
|
1713
|
-
? { capture: options.capture, passive: options.passive }
|
|
1714
|
-
: options && options.capture
|
|
1715
|
-
var add = getZoneJsOriginalValue(eventTarget, 'addEventListener')
|
|
1716
|
-
|
|
1717
|
-
each(events, function (event) {
|
|
1718
|
-
add.call(eventTarget, event, wrappedListener, options)
|
|
1719
|
-
})
|
|
1720
|
-
var stop = function () {
|
|
1721
|
-
var remove = getZoneJsOriginalValue(eventTarget, 'removeEventListener')
|
|
1722
|
-
each(events, function (event) {
|
|
1723
|
-
remove.call(eventTarget, event, wrappedListener, options)
|
|
1724
|
-
})
|
|
1725
|
-
}
|
|
1726
|
-
return {
|
|
1727
|
-
stop: stop
|
|
1728
|
-
}
|
|
1729
|
-
}
|
|
1730
|
-
|
|
1731
1533
|
export function includes(candidate, search) {
|
|
1732
1534
|
// tslint:disable-next-line: no-unsafe-any
|
|
1733
1535
|
return candidate.indexOf(search) !== -1
|
|
1734
1536
|
}
|
|
1735
1537
|
|
|
1736
|
-
export function createContextManager() {
|
|
1737
|
-
var context = {}
|
|
1738
|
-
|
|
1739
|
-
return {
|
|
1740
|
-
get: function () {
|
|
1741
|
-
return context
|
|
1742
|
-
},
|
|
1743
|
-
|
|
1744
|
-
add: function (key, value) {
|
|
1745
|
-
if (isString(key)) {
|
|
1746
|
-
context[key] = value
|
|
1747
|
-
} else {
|
|
1748
|
-
console.error('key 需要传递字符串类型')
|
|
1749
|
-
}
|
|
1750
|
-
},
|
|
1751
|
-
|
|
1752
|
-
remove: function (key) {
|
|
1753
|
-
delete context[key]
|
|
1754
|
-
},
|
|
1755
|
-
|
|
1756
|
-
set: function (newContext) {
|
|
1757
|
-
if (isObject(newContext)) {
|
|
1758
|
-
context = newContext
|
|
1759
|
-
} else {
|
|
1760
|
-
console.error('content 需要传递对象类型数据')
|
|
1761
|
-
}
|
|
1762
|
-
},
|
|
1763
|
-
getContext: function () {
|
|
1764
|
-
return deepClone(context)
|
|
1765
|
-
},
|
|
1766
|
-
|
|
1767
|
-
setContext: function (newContext) {
|
|
1768
|
-
context = deepClone(newContext)
|
|
1769
|
-
},
|
|
1770
|
-
|
|
1771
|
-
setContextProperty: function (key, property) {
|
|
1772
|
-
context[key] = deepClone(property)
|
|
1773
|
-
},
|
|
1774
|
-
|
|
1775
|
-
removeContextProperty: function (key) {
|
|
1776
|
-
delete context[key]
|
|
1777
|
-
},
|
|
1778
|
-
|
|
1779
|
-
clearContext: function () {
|
|
1780
|
-
context = {}
|
|
1781
|
-
}
|
|
1782
|
-
}
|
|
1783
|
-
}
|
|
1784
1538
|
export function find(array, predicate) {
|
|
1785
1539
|
for (var i = 0; i < array.length; i += 1) {
|
|
1786
1540
|
var item = array[i]
|
|
@@ -1871,44 +1625,6 @@ export function toSnakeCase(word) {
|
|
|
1871
1625
|
.replace(/-/g, '_')
|
|
1872
1626
|
}
|
|
1873
1627
|
|
|
1874
|
-
export function escapeRowData(str) {
|
|
1875
|
-
if (typeof str === 'object' && str) {
|
|
1876
|
-
str = jsonStringify(str)
|
|
1877
|
-
} else if (!isString(str)) {
|
|
1878
|
-
return str
|
|
1879
|
-
}
|
|
1880
|
-
var reg = /[\s=,"]/g
|
|
1881
|
-
return String(str).replace(reg, function (word) {
|
|
1882
|
-
return '\\' + word
|
|
1883
|
-
})
|
|
1884
|
-
}
|
|
1885
|
-
|
|
1886
|
-
export function escapeJsonValue(value) {
|
|
1887
|
-
if (isString(value)) {
|
|
1888
|
-
return value
|
|
1889
|
-
} else {
|
|
1890
|
-
return jsonStringify(value)
|
|
1891
|
-
}
|
|
1892
|
-
}
|
|
1893
|
-
export function escapeFieldValueStr(str) {
|
|
1894
|
-
return (
|
|
1895
|
-
'"' +
|
|
1896
|
-
str
|
|
1897
|
-
.replace(/\\/g, '\\\\')
|
|
1898
|
-
.replace(/[\\]*"/g, '"')
|
|
1899
|
-
.replace(/"/g, '\\"') +
|
|
1900
|
-
'"'
|
|
1901
|
-
)
|
|
1902
|
-
}
|
|
1903
|
-
export function escapeRowField(value) {
|
|
1904
|
-
if (typeof value === 'object' && value) {
|
|
1905
|
-
return escapeFieldValueStr(jsonStringify(value))
|
|
1906
|
-
} else if (isString(value)) {
|
|
1907
|
-
return escapeFieldValueStr(value)
|
|
1908
|
-
} else {
|
|
1909
|
-
return value
|
|
1910
|
-
}
|
|
1911
|
-
}
|
|
1912
1628
|
export function isNullUndefinedDefaultValue(data, defaultValue) {
|
|
1913
1629
|
if (data !== null && data !== void 0) {
|
|
1914
1630
|
return data
|
|
@@ -1917,21 +1633,6 @@ export function isNullUndefinedDefaultValue(data, defaultValue) {
|
|
|
1917
1633
|
}
|
|
1918
1634
|
}
|
|
1919
1635
|
|
|
1920
|
-
export function runOnReadyState(expectedReadyState, callback) {
|
|
1921
|
-
if (
|
|
1922
|
-
document.readyState === expectedReadyState ||
|
|
1923
|
-
document.readyState === 'complete'
|
|
1924
|
-
) {
|
|
1925
|
-
callback()
|
|
1926
|
-
} else {
|
|
1927
|
-
var eventName =
|
|
1928
|
-
expectedReadyState === 'complete'
|
|
1929
|
-
? DOM_EVENT.LOAD
|
|
1930
|
-
: DOM_EVENT.DOM_CONTENT_LOADED
|
|
1931
|
-
addEventListener(window, eventName, callback, { once: true })
|
|
1932
|
-
}
|
|
1933
|
-
}
|
|
1934
|
-
|
|
1935
1636
|
export function requestIdleCallback(callback, opts) {
|
|
1936
1637
|
// Use 'requestIdleCallback' when available: it will throttle the mutation processing if the
|
|
1937
1638
|
// browser is busy rendering frames (ex: when frames are below 60fps). When not available, the
|
package/src/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export * from './helper/deviceInfo'
|
|
|
4
4
|
export * from './helper/enums'
|
|
5
5
|
export * from './helper/instrumentMethod'
|
|
6
6
|
export * from './helper/errorTools'
|
|
7
|
+
export * from './helper/byteUtils'
|
|
7
8
|
export * from './error/trackRuntimeError'
|
|
8
9
|
export * from './console/consoleObservable'
|
|
9
10
|
export * from './report/reportObservable'
|
|
@@ -17,6 +18,7 @@ export * from './helper/tools'
|
|
|
17
18
|
export * from './helper/urlPolyfill'
|
|
18
19
|
export * from './helper/mobileUtil'
|
|
19
20
|
export * from './helper/getZoneJsOriginalValue'
|
|
21
|
+
export * from './helper/timer'
|
|
20
22
|
export * from './helper/readBytesFromStream'
|
|
21
23
|
export * from './tracekit'
|
|
22
24
|
export * from './configuration/configuration'
|
|
@@ -26,6 +28,9 @@ export * from './browser/fetchObservable'
|
|
|
26
28
|
export * from './browser/xhrObservable'
|
|
27
29
|
export * from './browser/pageExitObservable'
|
|
28
30
|
export * from './browser/htmlDomUtils'
|
|
31
|
+
export * from './browser/addEventListener'
|
|
32
|
+
export * from './browser/runOnReadyState'
|
|
33
|
+
|
|
29
34
|
export * from './dataMap'
|
|
30
35
|
export * from './init'
|
|
31
36
|
export * from './session/sessionManagement'
|
|
@@ -34,3 +39,9 @@ export * from './session/sessionCookieStore'
|
|
|
34
39
|
export * from './session/sessionStore'
|
|
35
40
|
export * from './transport'
|
|
36
41
|
export * from './synthetics/syntheticsWorkerValues'
|
|
42
|
+
|
|
43
|
+
export * from './helper/serialisation/contextManager'
|
|
44
|
+
export * from './helper/serialisation/heavyCustomerDataWarning'
|
|
45
|
+
export * from './helper/serialisation/jsonStringify'
|
|
46
|
+
export * from './helper/serialisation/rowData'
|
|
47
|
+
export * from './user'
|
package/src/init.js
CHANGED
|
@@ -16,12 +16,12 @@ export function makePublicApi(stub) {
|
|
|
16
16
|
|
|
17
17
|
// Add an "hidden" property to set debug mode. We define it that way to hide it
|
|
18
18
|
// as much as possible but of course it's not a real protection.
|
|
19
|
-
Object.defineProperty(publicApi, '_setDebug', {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
})
|
|
19
|
+
// Object.defineProperty(publicApi, '_setDebug', {
|
|
20
|
+
// get: function () {
|
|
21
|
+
// return setDebugMode
|
|
22
|
+
// },
|
|
23
|
+
// enumerable: false
|
|
24
|
+
// })
|
|
25
25
|
|
|
26
26
|
return publicApi
|
|
27
27
|
}
|