@cloudcare/browser-core 2.0.3 → 2.0.5
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/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/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/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
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
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { toStackTraceString } from '../helper/errorTools'
|
|
2
2
|
import { mergeObservables, Observable } from '../helper/observable'
|
|
3
|
-
import { includes,
|
|
3
|
+
import { includes, safeTruncate, filter, each } from '../helper/tools'
|
|
4
|
+
import { addEventListener } from '../browser/addEventListener'
|
|
4
5
|
import { DOM_EVENT } from '../helper/enums'
|
|
5
6
|
export var RawReportType = {
|
|
6
7
|
intervention: 'intervention',
|
|
7
8
|
deprecation: 'deprecation',
|
|
8
|
-
cspViolation: 'csp_violation'
|
|
9
|
+
cspViolation: 'csp_violation'
|
|
9
10
|
}
|
|
10
11
|
export function initReportObservable(apis) {
|
|
11
12
|
var observables = []
|
|
@@ -14,7 +15,9 @@ export function initReportObservable(apis) {
|
|
|
14
15
|
observables.push(createCspViolationReportObservable())
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
var reportTypes = filter(apis, function(api) {
|
|
18
|
+
var reportTypes = filter(apis, function (api) {
|
|
19
|
+
return api !== RawReportType.cspViolation
|
|
20
|
+
})
|
|
18
21
|
if (reportTypes.length) {
|
|
19
22
|
observables.push(createReportObservable(reportTypes))
|
|
20
23
|
}
|
|
@@ -22,24 +25,24 @@ export function initReportObservable(apis) {
|
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
function createReportObservable(reportTypes) {
|
|
25
|
-
var observable = new Observable(function() {
|
|
28
|
+
var observable = new Observable(function () {
|
|
26
29
|
if (!window.ReportingObserver) {
|
|
27
30
|
return
|
|
28
31
|
}
|
|
29
32
|
|
|
30
|
-
var handleReports = function(reports) {
|
|
31
|
-
each(reports, function(report) {
|
|
33
|
+
var handleReports = function (reports) {
|
|
34
|
+
each(reports, function (report) {
|
|
32
35
|
observable.notify(buildRawReportFromReport(report))
|
|
33
36
|
})
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
var observer = new window.ReportingObserver(handleReports, {
|
|
37
40
|
types: reportTypes,
|
|
38
|
-
buffered: true
|
|
41
|
+
buffered: true
|
|
39
42
|
})
|
|
40
43
|
|
|
41
44
|
observer.observe()
|
|
42
|
-
return function() {
|
|
45
|
+
return function () {
|
|
43
46
|
observer.disconnect()
|
|
44
47
|
}
|
|
45
48
|
})
|
|
@@ -48,12 +51,16 @@ function createReportObservable(reportTypes) {
|
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
function createCspViolationReportObservable() {
|
|
51
|
-
var observable = new Observable(function() {
|
|
52
|
-
var handleCspViolation = function(event) {
|
|
54
|
+
var observable = new Observable(function () {
|
|
55
|
+
var handleCspViolation = function (event) {
|
|
53
56
|
observable.notify(buildRawReportFromCspViolation(event))
|
|
54
57
|
}
|
|
55
58
|
|
|
56
|
-
var _addEventListener = addEventListener(
|
|
59
|
+
var _addEventListener = addEventListener(
|
|
60
|
+
document,
|
|
61
|
+
DOM_EVENT.SECURITY_POLICY_VIOLATION,
|
|
62
|
+
handleCspViolation
|
|
63
|
+
)
|
|
57
64
|
|
|
58
65
|
return _addEventListener.stop
|
|
59
66
|
})
|
|
@@ -67,34 +74,42 @@ function buildRawReportFromReport(report) {
|
|
|
67
74
|
type: type,
|
|
68
75
|
subtype: body.id,
|
|
69
76
|
message: type + ': ' + body.message,
|
|
70
|
-
stack: buildStack(
|
|
77
|
+
stack: buildStack(
|
|
78
|
+
body.id,
|
|
79
|
+
body.message,
|
|
80
|
+
body.sourceFile,
|
|
81
|
+
body.lineNumber,
|
|
82
|
+
body.columnNumber
|
|
83
|
+
)
|
|
71
84
|
}
|
|
72
85
|
}
|
|
73
86
|
|
|
74
87
|
function buildRawReportFromCspViolation(event) {
|
|
75
88
|
var type = RawReportType.cspViolation
|
|
76
|
-
var message =
|
|
89
|
+
var message =
|
|
90
|
+
"'" +
|
|
91
|
+
event.blockedURI +
|
|
92
|
+
"' blocked by '" +
|
|
93
|
+
event.effectiveDirective +
|
|
94
|
+
"' directive"
|
|
77
95
|
return {
|
|
78
96
|
type: RawReportType.cspViolation,
|
|
79
97
|
subtype: event.effectiveDirective,
|
|
80
98
|
message: type + ': ' + message,
|
|
81
99
|
stack: buildStack(
|
|
82
100
|
event.effectiveDirective,
|
|
83
|
-
message +
|
|
101
|
+
message +
|
|
102
|
+
' of the policy "' +
|
|
103
|
+
safeTruncate(event.originalPolicy, 100, '...') +
|
|
104
|
+
'"',
|
|
84
105
|
event.sourceFile,
|
|
85
106
|
event.lineNumber,
|
|
86
107
|
event.columnNumber
|
|
87
|
-
)
|
|
108
|
+
)
|
|
88
109
|
}
|
|
89
110
|
}
|
|
90
111
|
|
|
91
|
-
function buildStack(
|
|
92
|
-
name,
|
|
93
|
-
message,
|
|
94
|
-
sourceFile,
|
|
95
|
-
lineNumber,
|
|
96
|
-
columnNumber
|
|
97
|
-
){
|
|
112
|
+
function buildStack(name, message, sourceFile, lineNumber, columnNumber) {
|
|
98
113
|
return (
|
|
99
114
|
sourceFile &&
|
|
100
115
|
toStackTraceString({
|
|
@@ -105,9 +120,9 @@ function buildStack(
|
|
|
105
120
|
func: '?',
|
|
106
121
|
url: sourceFile,
|
|
107
122
|
line: lineNumber,
|
|
108
|
-
column: columnNumber
|
|
109
|
-
}
|
|
110
|
-
]
|
|
123
|
+
column: columnNumber
|
|
124
|
+
}
|
|
125
|
+
]
|
|
111
126
|
})
|
|
112
127
|
)
|
|
113
128
|
}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { getCookie, setCookie } from '../browser/cookie'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
isChromium,
|
|
4
|
+
dateNow,
|
|
5
|
+
isEmptyObject,
|
|
6
|
+
UUID,
|
|
7
|
+
objectEntries,
|
|
8
|
+
map,
|
|
9
|
+
each
|
|
10
|
+
} from '../helper/tools'
|
|
3
11
|
import { SESSION_EXPIRATION_DELAY } from './sessionConstants'
|
|
4
|
-
|
|
12
|
+
import { setTimeout } from '../helper/timer'
|
|
5
13
|
var SESSION_ENTRY_REGEXP = /^([a-z]+)=([a-z0-9-]+)$/
|
|
6
14
|
var SESSION_ENTRY_SEPARATOR = '&'
|
|
7
15
|
|
|
@@ -11,8 +19,7 @@ export var SESSION_COOKIE_NAME = '_dataflux_s'
|
|
|
11
19
|
export var LOCK_RETRY_DELAY = 10
|
|
12
20
|
export var MAX_NUMBER_OF_LOCK_RETRIES = 100
|
|
13
21
|
|
|
14
|
-
|
|
15
|
-
var bufferedOperations= []
|
|
22
|
+
var bufferedOperations = []
|
|
16
23
|
var ongoingOperations
|
|
17
24
|
|
|
18
25
|
export function withCookieLockAccess(operations, numberOfRetries) {
|
|
@@ -93,12 +100,9 @@ function isCookieLockEnabled() {
|
|
|
93
100
|
}
|
|
94
101
|
|
|
95
102
|
function retryLater(operations, currentNumberOfRetries) {
|
|
96
|
-
setTimeout(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
},
|
|
100
|
-
LOCK_RETRY_DELAY
|
|
101
|
-
)
|
|
103
|
+
setTimeout(function () {
|
|
104
|
+
withCookieLockAccess(operations, currentNumberOfRetries + 1)
|
|
105
|
+
}, LOCK_RETRY_DELAY)
|
|
102
106
|
}
|
|
103
107
|
|
|
104
108
|
function next() {
|
|
@@ -119,11 +123,16 @@ export function persistSession(session, options) {
|
|
|
119
123
|
}
|
|
120
124
|
|
|
121
125
|
function setSession(session, options) {
|
|
122
|
-
setCookie(
|
|
126
|
+
setCookie(
|
|
127
|
+
SESSION_COOKIE_NAME,
|
|
128
|
+
toSessionString(session),
|
|
129
|
+
SESSION_EXPIRATION_DELAY,
|
|
130
|
+
options
|
|
131
|
+
)
|
|
123
132
|
}
|
|
124
133
|
|
|
125
134
|
export function toSessionString(session) {
|
|
126
|
-
return map(objectEntries(session), function(item) {
|
|
135
|
+
return map(objectEntries(session), function (item) {
|
|
127
136
|
return item[0] + '=' + item[1]
|
|
128
137
|
}).join(SESSION_ENTRY_SEPARATOR)
|
|
129
138
|
}
|
|
@@ -132,7 +141,7 @@ export function retrieveSession() {
|
|
|
132
141
|
var sessionString = getCookie(SESSION_COOKIE_NAME)
|
|
133
142
|
var session = {}
|
|
134
143
|
if (isValidSessionString(sessionString)) {
|
|
135
|
-
each(sessionString.split(SESSION_ENTRY_SEPARATOR), function(entry) {
|
|
144
|
+
each(sessionString.split(SESSION_ENTRY_SEPARATOR), function (entry) {
|
|
136
145
|
var matches = SESSION_ENTRY_REGEXP.exec(entry)
|
|
137
146
|
if (matches !== null) {
|
|
138
147
|
var key = matches[1]
|
|
@@ -147,7 +156,8 @@ export function retrieveSession() {
|
|
|
147
156
|
function isValidSessionString(sessionString) {
|
|
148
157
|
return (
|
|
149
158
|
sessionString !== undefined &&
|
|
150
|
-
(sessionString.indexOf(SESSION_ENTRY_SEPARATOR) !== -1 ||
|
|
159
|
+
(sessionString.indexOf(SESSION_ENTRY_SEPARATOR) !== -1 ||
|
|
160
|
+
SESSION_ENTRY_REGEXP.test(sessionString))
|
|
151
161
|
)
|
|
152
162
|
}
|
|
153
163
|
|