@cloudcare/browser-core 3.1.1 → 3.1.2
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/htmlDomUtils.js +10 -4
- package/cjs/browser/htmlDomUtils.js.map +1 -1
- package/cjs/configuration/configuration.js +2 -1
- package/cjs/configuration/configuration.js.map +1 -1
- package/cjs/helper/enums.js +2 -1
- package/cjs/helper/enums.js.map +1 -1
- package/cjs/helper/serialisation/contextManager.js +20 -5
- package/cjs/helper/serialisation/contextManager.js.map +1 -1
- package/cjs/helper/serialisation/storedContextManager.js +47 -0
- package/cjs/helper/serialisation/storedContextManager.js.map +1 -0
- package/cjs/helper/tools.js +18 -3
- package/cjs/helper/tools.js.map +1 -1
- package/cjs/index.js +11 -0
- package/cjs/index.js.map +1 -1
- package/esm/browser/htmlDomUtils.js +9 -3
- package/esm/browser/htmlDomUtils.js.map +1 -1
- package/esm/configuration/configuration.js +2 -1
- package/esm/configuration/configuration.js.map +1 -1
- package/esm/helper/enums.js +2 -1
- package/esm/helper/enums.js.map +1 -1
- package/esm/helper/serialisation/contextManager.js +21 -6
- package/esm/helper/serialisation/contextManager.js.map +1 -1
- package/esm/helper/serialisation/storedContextManager.js +39 -0
- package/esm/helper/serialisation/storedContextManager.js.map +1 -0
- package/esm/helper/tools.js +17 -3
- package/esm/helper/tools.js.map +1 -1
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/package.json +2 -2
- package/src/browser/htmlDomUtils.js +8 -3
- package/src/configuration/configuration.js +2 -1
- package/src/helper/enums.js +2 -1
- package/src/helper/serialisation/contextManager.js +21 -6
- package/src/helper/serialisation/storedContextManager.js +56 -0
- package/src/helper/tools.js +18 -4
- package/src/index.js +1 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { computeBytesCount } from '../byteUtils'
|
|
2
|
-
import { deepClone, throttle } from '../tools'
|
|
2
|
+
import { deepClone, throttle, getType } from '../tools'
|
|
3
|
+
import { sanitize } from '../sanitize'
|
|
3
4
|
import { jsonStringify } from './jsonStringify'
|
|
5
|
+
import { Observable } from '../observable'
|
|
4
6
|
import { warnIfCustomerDataLimitReached } from './heavyCustomerDataWarning'
|
|
5
7
|
|
|
6
8
|
export var BYTES_COMPUTATION_THROTTLING_DELAY = 200
|
|
@@ -12,7 +14,7 @@ export function createContextManager(customerDataType, computeBytesCountImpl) {
|
|
|
12
14
|
var context = {}
|
|
13
15
|
var bytesCountCache
|
|
14
16
|
var alreadyWarned = false
|
|
15
|
-
|
|
17
|
+
var changeObservable = new Observable()
|
|
16
18
|
// Throttle the bytes computation to minimize the impact on performance.
|
|
17
19
|
// Especially useful if the user call context APIs synchronously multiple times in a row
|
|
18
20
|
var computeBytesCountThrottled = throttle(function (context) {
|
|
@@ -25,7 +27,7 @@ export function createContextManager(customerDataType, computeBytesCountImpl) {
|
|
|
25
27
|
}
|
|
26
28
|
}, BYTES_COMPUTATION_THROTTLING_DELAY).throttled
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
var contextManager = {
|
|
29
31
|
getBytesCount: function () {
|
|
30
32
|
return bytesCountCache
|
|
31
33
|
},
|
|
@@ -38,18 +40,21 @@ export function createContextManager(customerDataType, computeBytesCountImpl) {
|
|
|
38
40
|
add: function (key, value) {
|
|
39
41
|
context[key] = value
|
|
40
42
|
computeBytesCountThrottled(context)
|
|
43
|
+
changeObservable.notify()
|
|
41
44
|
},
|
|
42
45
|
|
|
43
46
|
/** @deprecated renamed to removeContextProperty */
|
|
44
47
|
remove: function (key) {
|
|
45
48
|
delete context[key]
|
|
46
49
|
computeBytesCountThrottled(context)
|
|
50
|
+
changeObservable.notify()
|
|
47
51
|
},
|
|
48
52
|
|
|
49
53
|
/** @deprecated use setContext instead */
|
|
50
54
|
set: function (newContext) {
|
|
51
55
|
context = newContext
|
|
52
56
|
computeBytesCountThrottled(context)
|
|
57
|
+
changeObservable.notify()
|
|
53
58
|
},
|
|
54
59
|
|
|
55
60
|
getContext: function () {
|
|
@@ -57,23 +62,33 @@ export function createContextManager(customerDataType, computeBytesCountImpl) {
|
|
|
57
62
|
},
|
|
58
63
|
|
|
59
64
|
setContext: function (newContext) {
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
if (getType(newContext) === 'object') {
|
|
66
|
+
context = sanitize(newContext)
|
|
67
|
+
computeBytesCountThrottled(context)
|
|
68
|
+
} else {
|
|
69
|
+
contextManager.clearContext()
|
|
70
|
+
}
|
|
71
|
+
changeObservable.notify()
|
|
62
72
|
},
|
|
63
73
|
|
|
64
74
|
setContextProperty: function (key, property) {
|
|
65
75
|
context[key] = deepClone(property)
|
|
66
76
|
computeBytesCountThrottled(context)
|
|
77
|
+
changeObservable.notify()
|
|
67
78
|
},
|
|
68
79
|
|
|
69
80
|
removeContextProperty: function (key) {
|
|
70
81
|
delete context[key]
|
|
71
82
|
computeBytesCountThrottled(context)
|
|
83
|
+
changeObservable.notify()
|
|
72
84
|
},
|
|
73
85
|
|
|
74
86
|
clearContext: function () {
|
|
75
87
|
context = {}
|
|
76
88
|
bytesCountCache = 0
|
|
77
|
-
|
|
89
|
+
changeObservable.notify()
|
|
90
|
+
},
|
|
91
|
+
changeObservable: changeObservable
|
|
78
92
|
}
|
|
93
|
+
return contextManager
|
|
79
94
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { computeBytesCount } from '../byteUtils'
|
|
2
|
+
import { DOM_EVENT } from '../enums'
|
|
3
|
+
import { map } from '../tools'
|
|
4
|
+
import { addEventListener } from '../../browser/addEventListener'
|
|
5
|
+
import { createContextManager } from './contextManager'
|
|
6
|
+
var CONTEXT_STORE_KEY_PREFIX = '_gc_s'
|
|
7
|
+
|
|
8
|
+
var storageListeners = []
|
|
9
|
+
|
|
10
|
+
export function createStoredContextManager(
|
|
11
|
+
productKey,
|
|
12
|
+
customerDataType,
|
|
13
|
+
computeBytesCountImpl
|
|
14
|
+
) {
|
|
15
|
+
if (computeBytesCountImpl === undefined) {
|
|
16
|
+
computeBytesCountImpl = computeBytesCount
|
|
17
|
+
}
|
|
18
|
+
var storageKey = buildStorageKey(productKey, customerDataType)
|
|
19
|
+
var contextManager = createContextManager(
|
|
20
|
+
customerDataType,
|
|
21
|
+
computeBytesCountImpl
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
synchronizeWithStorage()
|
|
25
|
+
storageListeners.push(
|
|
26
|
+
addEventListener(window, DOM_EVENT.STORAGE, function (params) {
|
|
27
|
+
if (storageKey === params.key) {
|
|
28
|
+
synchronizeWithStorage()
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
)
|
|
32
|
+
contextManager.changeObservable.subscribe(dumpToStorage)
|
|
33
|
+
function synchronizeWithStorage() {
|
|
34
|
+
var rawContext = localStorage.getItem(storageKey)
|
|
35
|
+
var context = rawContext !== null ? JSON.parse(rawContext) : {}
|
|
36
|
+
contextManager.setContext(context)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function dumpToStorage() {
|
|
40
|
+
localStorage.setItem(
|
|
41
|
+
storageKey,
|
|
42
|
+
JSON.stringify(contextManager.getContext())
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
return contextManager
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function buildStorageKey(productKey, customerDataType) {
|
|
49
|
+
return CONTEXT_STORE_KEY_PREFIX + '_' + productKey + '_' + customerDataType
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function removeStorageListeners() {
|
|
53
|
+
map(storageListeners, function (listener) {
|
|
54
|
+
listener.stop()
|
|
55
|
+
})
|
|
56
|
+
}
|
package/src/helper/tools.js
CHANGED
|
@@ -1594,14 +1594,28 @@ export function getLocationOrigin() {
|
|
|
1594
1594
|
return getLinkElementOrigin(window.location)
|
|
1595
1595
|
}
|
|
1596
1596
|
|
|
1597
|
+
var browserIsIE
|
|
1597
1598
|
export function isIE() {
|
|
1598
|
-
|
|
1599
|
+
if (browserIsIE === undefined) {
|
|
1600
|
+
browserIsIE = Boolean(document.documentMode)
|
|
1601
|
+
}
|
|
1602
|
+
return browserIsIE
|
|
1599
1603
|
}
|
|
1600
|
-
|
|
1604
|
+
var browserIsChromium
|
|
1601
1605
|
export function isChromium() {
|
|
1602
|
-
|
|
1606
|
+
if (browserIsChromium === undefined) {
|
|
1607
|
+
browserIsChromium =
|
|
1608
|
+
!!window.chrome || /HeadlessChrome/.test(window.navigator.userAgent)
|
|
1609
|
+
}
|
|
1610
|
+
return browserIsChromium
|
|
1611
|
+
}
|
|
1612
|
+
var browserIsSafari
|
|
1613
|
+
export function isSafari() {
|
|
1614
|
+
if (browserIsSafari === undefined) {
|
|
1615
|
+
browserIsSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent)
|
|
1616
|
+
}
|
|
1617
|
+
return browserIsSafari
|
|
1603
1618
|
}
|
|
1604
|
-
|
|
1605
1619
|
/**
|
|
1606
1620
|
* IE fallback
|
|
1607
1621
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/origin
|
package/src/index.js
CHANGED
|
@@ -47,6 +47,7 @@ export * from './helper/serialisation/contextManager'
|
|
|
47
47
|
export * from './helper/serialisation/heavyCustomerDataWarning'
|
|
48
48
|
export * from './helper/serialisation/jsonStringify'
|
|
49
49
|
export * from './helper/serialisation/rowData'
|
|
50
|
+
export * from './helper/serialisation/storedContextManager'
|
|
50
51
|
export * from './user'
|
|
51
52
|
|
|
52
53
|
export * from './telemetry/telemetry'
|