@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
package/esm/helper/tools.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DOM_EVENT } from './enums';
|
|
2
|
-
import {
|
|
2
|
+
import { setTimeout, clearTimeout } from './timer';
|
|
3
3
|
var ArrayProto = Array.prototype;
|
|
4
4
|
var FuncProto = Function.prototype;
|
|
5
5
|
var ObjProto = Object.prototype;
|
|
@@ -749,121 +749,6 @@ export function elementMatches(element, selector) {
|
|
|
749
749
|
|
|
750
750
|
return false;
|
|
751
751
|
}
|
|
752
|
-
export var addEvent = function addEvent() {
|
|
753
|
-
function fixEvent(event) {
|
|
754
|
-
if (event) {
|
|
755
|
-
event.preventDefault = fixEvent.preventDefault;
|
|
756
|
-
event.stopPropagation = fixEvent.stopPropagation;
|
|
757
|
-
event._getPath = fixEvent._getPath;
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
return event;
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
fixEvent._getPath = function () {
|
|
764
|
-
var ev = this;
|
|
765
|
-
|
|
766
|
-
var polyfill = function polyfill() {
|
|
767
|
-
try {
|
|
768
|
-
var element = ev.target;
|
|
769
|
-
var pathArr = [element];
|
|
770
|
-
|
|
771
|
-
if (element === null || element.parentElement === null) {
|
|
772
|
-
return [];
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
while (element.parentElement !== null) {
|
|
776
|
-
element = element.parentElement;
|
|
777
|
-
pathArr.unshift(element);
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
return pathArr;
|
|
781
|
-
} catch (error) {
|
|
782
|
-
return [];
|
|
783
|
-
}
|
|
784
|
-
};
|
|
785
|
-
|
|
786
|
-
return this.path || this.composedPath() && this.composedPath() || polyfill();
|
|
787
|
-
};
|
|
788
|
-
|
|
789
|
-
fixEvent.preventDefault = function () {
|
|
790
|
-
this.returnValue = false;
|
|
791
|
-
};
|
|
792
|
-
|
|
793
|
-
fixEvent.stopPropagation = function () {
|
|
794
|
-
this.cancelBubble = true;
|
|
795
|
-
};
|
|
796
|
-
|
|
797
|
-
var register_event = function register_event(element, type, handle) {
|
|
798
|
-
if (element && element.addEventListener) {
|
|
799
|
-
element.addEventListener(type, function (e) {
|
|
800
|
-
e._getPath = fixEvent._getPath;
|
|
801
|
-
handler.call(this, e);
|
|
802
|
-
}, false);
|
|
803
|
-
} else {
|
|
804
|
-
var ontype = 'on' + type;
|
|
805
|
-
var old_handler = element[ontype];
|
|
806
|
-
element[ontype] = makeHandler(element, handler, old_handler);
|
|
807
|
-
}
|
|
808
|
-
};
|
|
809
|
-
|
|
810
|
-
function makeHandler(element, new_handler, old_handlers) {
|
|
811
|
-
var handler = function handler(event) {
|
|
812
|
-
event = event || fixEvent(window.event);
|
|
813
|
-
|
|
814
|
-
if (!event) {
|
|
815
|
-
return undefined;
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
event.target = event.srcElement;
|
|
819
|
-
var ret = true;
|
|
820
|
-
var old_result, new_result;
|
|
821
|
-
|
|
822
|
-
if (typeof old_handlers === 'function') {
|
|
823
|
-
old_result = old_handlers(event);
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
new_result = new_handler.call(element, event);
|
|
827
|
-
|
|
828
|
-
if (false === old_result || false === new_result) {
|
|
829
|
-
ret = false;
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
return ret;
|
|
833
|
-
};
|
|
834
|
-
|
|
835
|
-
return handler;
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
register_event.apply(null, arguments);
|
|
839
|
-
};
|
|
840
|
-
export var addHashEvent = function addHashEvent(callback) {
|
|
841
|
-
var hashEvent = 'pushState' in window.history ? 'popstate' : 'hashchange';
|
|
842
|
-
addEvent(window, hashEvent, callback);
|
|
843
|
-
};
|
|
844
|
-
export var addSinglePageEvent = function addSinglePageEvent(callback) {
|
|
845
|
-
var current_url = location.href;
|
|
846
|
-
var historyPushState = window.history.pushState;
|
|
847
|
-
var historyReplaceState = window.history.replaceState;
|
|
848
|
-
|
|
849
|
-
window.history.pushState = function () {
|
|
850
|
-
historyPushState.apply(window.history, arguments);
|
|
851
|
-
callback(current_url);
|
|
852
|
-
current_url = location.href;
|
|
853
|
-
};
|
|
854
|
-
|
|
855
|
-
window.history.replaceState = function () {
|
|
856
|
-
historyReplaceState.apply(window.history, arguments);
|
|
857
|
-
callback(current_url);
|
|
858
|
-
current_url = location.href;
|
|
859
|
-
};
|
|
860
|
-
|
|
861
|
-
var singlePageEvent = historyPushState ? 'popstate' : 'hashchange';
|
|
862
|
-
addEvent(window, singlePageEvent, function () {
|
|
863
|
-
callback(current_url);
|
|
864
|
-
current_url = location.href;
|
|
865
|
-
});
|
|
866
|
-
};
|
|
867
752
|
export var cookie = {
|
|
868
753
|
get: function get(name) {
|
|
869
754
|
var nameEQ = name + '=';
|
|
@@ -1510,63 +1395,12 @@ export var getReferrer = function getReferrer() {
|
|
|
1510
1395
|
export var typeDecide = function typeDecide(o, type) {
|
|
1511
1396
|
return toString.call(o) === '[object ' + type + ']';
|
|
1512
1397
|
};
|
|
1513
|
-
export function jsonStringify(value, replacer, space) {
|
|
1514
|
-
if (value === null || value === undefined) {
|
|
1515
|
-
return JSON.stringify(value);
|
|
1516
|
-
}
|
|
1517
|
-
|
|
1518
|
-
var originalToJSON = [false, undefined];
|
|
1519
|
-
|
|
1520
|
-
if (hasToJSON(value)) {
|
|
1521
|
-
// We need to add a flag and not rely on the truthiness of value.toJSON
|
|
1522
|
-
// because it can be set but undefined and that's actually significant.
|
|
1523
|
-
originalToJSON = [true, value.toJSON];
|
|
1524
|
-
delete value.toJSON;
|
|
1525
|
-
}
|
|
1526
|
-
|
|
1527
|
-
var originalProtoToJSON = [false, undefined];
|
|
1528
|
-
var prototype;
|
|
1529
|
-
|
|
1530
|
-
if (typeof value === 'object') {
|
|
1531
|
-
prototype = Object.getPrototypeOf(value);
|
|
1532
|
-
|
|
1533
|
-
if (hasToJSON(prototype)) {
|
|
1534
|
-
originalProtoToJSON = [true, prototype.toJSON];
|
|
1535
|
-
delete prototype.toJSON;
|
|
1536
|
-
}
|
|
1537
|
-
}
|
|
1538
|
-
|
|
1539
|
-
var result;
|
|
1540
|
-
|
|
1541
|
-
try {
|
|
1542
|
-
result = JSON.stringify(value, undefined, space);
|
|
1543
|
-
} catch (e) {
|
|
1544
|
-
result = '<error: unable to serialize object>';
|
|
1545
|
-
} finally {
|
|
1546
|
-
if (originalToJSON[0]) {
|
|
1547
|
-
value.toJSON = originalToJSON[1];
|
|
1548
|
-
}
|
|
1549
|
-
|
|
1550
|
-
if (originalProtoToJSON[0]) {
|
|
1551
|
-
prototype.toJSON = originalProtoToJSON[1];
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
|
|
1555
|
-
return result;
|
|
1556
|
-
}
|
|
1557
|
-
|
|
1558
|
-
function hasToJSON(value) {
|
|
1559
|
-
return typeof value === 'object' && value !== null && value.hasOwnProperty('toJSON');
|
|
1560
|
-
}
|
|
1561
|
-
|
|
1562
1398
|
export function noop() {}
|
|
1563
1399
|
export var ONE_SECOND = 1000;
|
|
1564
1400
|
export var ONE_MINUTE = 60 * ONE_SECOND;
|
|
1565
1401
|
export var ONE_HOUR = 60 * ONE_MINUTE;
|
|
1566
1402
|
export var ONE_DAY = 24 * ONE_HOUR;
|
|
1567
1403
|
export var ONE_YEAR = 365 * ONE_DAY;
|
|
1568
|
-
export var ONE_KIBI_BYTE = 1024;
|
|
1569
|
-
export var ONE_MEBI_BYTE = 1024 * ONE_KIBI_BYTE;
|
|
1570
1404
|
/**
|
|
1571
1405
|
* Return true if the draw is successful
|
|
1572
1406
|
* @param threshold between 0 and 100
|
|
@@ -1710,94 +1544,10 @@ export function safeTruncate(candidate, length) {
|
|
|
1710
1544
|
|
|
1711
1545
|
return candidate.slice(0, length);
|
|
1712
1546
|
}
|
|
1713
|
-
export function addEventListener(eventTarget, event, listener, options) {
|
|
1714
|
-
return addEventListeners(eventTarget, [event], listener, options);
|
|
1715
|
-
}
|
|
1716
|
-
/**
|
|
1717
|
-
* Add event listeners to an event emitter object (Window, Element, mock object...). This provides
|
|
1718
|
-
* a few conveniences compared to using `element.addEventListener` directly:
|
|
1719
|
-
*
|
|
1720
|
-
* * supports IE11 by:
|
|
1721
|
-
* * using an option object only if needed
|
|
1722
|
-
* * emulating the `once` option
|
|
1723
|
-
*
|
|
1724
|
-
* * wraps the listener with a `monitor` function
|
|
1725
|
-
*
|
|
1726
|
-
* * returns a `stop` function to remove the listener
|
|
1727
|
-
*
|
|
1728
|
-
* * with `once: true`, the listener will be called at most once, even if different events are
|
|
1729
|
-
* listened
|
|
1730
|
-
*/
|
|
1731
|
-
|
|
1732
|
-
export function addEventListeners(eventTarget, events, listener, options) {
|
|
1733
|
-
var wrappedListener = options && options.once ? function (event) {
|
|
1734
|
-
stop();
|
|
1735
|
-
listener(event);
|
|
1736
|
-
} : listener;
|
|
1737
|
-
options = options && options.passive ? {
|
|
1738
|
-
capture: options.capture,
|
|
1739
|
-
passive: options.passive
|
|
1740
|
-
} : options && options.capture;
|
|
1741
|
-
var add = getZoneJsOriginalValue(eventTarget, 'addEventListener');
|
|
1742
|
-
each(events, function (event) {
|
|
1743
|
-
add.call(eventTarget, event, wrappedListener, options);
|
|
1744
|
-
});
|
|
1745
|
-
|
|
1746
|
-
var stop = function stop() {
|
|
1747
|
-
var remove = getZoneJsOriginalValue(eventTarget, 'removeEventListener');
|
|
1748
|
-
each(events, function (event) {
|
|
1749
|
-
remove.call(eventTarget, event, wrappedListener, options);
|
|
1750
|
-
});
|
|
1751
|
-
};
|
|
1752
|
-
|
|
1753
|
-
return {
|
|
1754
|
-
stop: stop
|
|
1755
|
-
};
|
|
1756
|
-
}
|
|
1757
1547
|
export function includes(candidate, search) {
|
|
1758
1548
|
// tslint:disable-next-line: no-unsafe-any
|
|
1759
1549
|
return candidate.indexOf(search) !== -1;
|
|
1760
1550
|
}
|
|
1761
|
-
export function createContextManager() {
|
|
1762
|
-
var context = {};
|
|
1763
|
-
return {
|
|
1764
|
-
get: function get() {
|
|
1765
|
-
return context;
|
|
1766
|
-
},
|
|
1767
|
-
add: function add(key, value) {
|
|
1768
|
-
if (isString(key)) {
|
|
1769
|
-
context[key] = value;
|
|
1770
|
-
} else {
|
|
1771
|
-
console.error('key 需要传递字符串类型');
|
|
1772
|
-
}
|
|
1773
|
-
},
|
|
1774
|
-
remove: function remove(key) {
|
|
1775
|
-
delete context[key];
|
|
1776
|
-
},
|
|
1777
|
-
set: function set(newContext) {
|
|
1778
|
-
if (isObject(newContext)) {
|
|
1779
|
-
context = newContext;
|
|
1780
|
-
} else {
|
|
1781
|
-
console.error('content 需要传递对象类型数据');
|
|
1782
|
-
}
|
|
1783
|
-
},
|
|
1784
|
-
getContext: function getContext() {
|
|
1785
|
-
return deepClone(context);
|
|
1786
|
-
},
|
|
1787
|
-
setContext: function setContext(newContext) {
|
|
1788
|
-
context = deepClone(newContext);
|
|
1789
|
-
},
|
|
1790
|
-
setContextProperty: function setContextProperty(key, property) {
|
|
1791
|
-
context[key] = deepClone(property);
|
|
1792
|
-
},
|
|
1793
|
-
removeContextProperty: function removeContextProperty(key) {
|
|
1794
|
-
delete context[key];
|
|
1795
|
-
},
|
|
1796
|
-
clearContext: function clearContext() {
|
|
1797
|
-
context = {};
|
|
1798
|
-
}
|
|
1799
|
-
};
|
|
1800
|
-
}
|
|
1801
1551
|
export function find(array, predicate) {
|
|
1802
1552
|
for (var i = 0; i < array.length; i += 1) {
|
|
1803
1553
|
var item = array[i];
|
|
@@ -1889,37 +1639,6 @@ export function toSnakeCase(word) {
|
|
|
1889
1639
|
return (index !== 0 ? '_' : '') + uppercaseLetter.toLowerCase();
|
|
1890
1640
|
}).replace(/-/g, '_');
|
|
1891
1641
|
}
|
|
1892
|
-
export function escapeRowData(str) {
|
|
1893
|
-
if (typeof str === 'object' && str) {
|
|
1894
|
-
str = jsonStringify(str);
|
|
1895
|
-
} else if (!isString(str)) {
|
|
1896
|
-
return str;
|
|
1897
|
-
}
|
|
1898
|
-
|
|
1899
|
-
var reg = /[\s=,"]/g;
|
|
1900
|
-
return String(str).replace(reg, function (word) {
|
|
1901
|
-
return '\\' + word;
|
|
1902
|
-
});
|
|
1903
|
-
}
|
|
1904
|
-
export function escapeJsonValue(value) {
|
|
1905
|
-
if (isString(value)) {
|
|
1906
|
-
return value;
|
|
1907
|
-
} else {
|
|
1908
|
-
return jsonStringify(value);
|
|
1909
|
-
}
|
|
1910
|
-
}
|
|
1911
|
-
export function escapeFieldValueStr(str) {
|
|
1912
|
-
return '"' + str.replace(/\\/g, '\\\\').replace(/[\\]*"/g, '"').replace(/"/g, '\\"') + '"';
|
|
1913
|
-
}
|
|
1914
|
-
export function escapeRowField(value) {
|
|
1915
|
-
if (typeof value === 'object' && value) {
|
|
1916
|
-
return escapeFieldValueStr(jsonStringify(value));
|
|
1917
|
-
} else if (isString(value)) {
|
|
1918
|
-
return escapeFieldValueStr(value);
|
|
1919
|
-
} else {
|
|
1920
|
-
return value;
|
|
1921
|
-
}
|
|
1922
|
-
}
|
|
1923
1642
|
export function isNullUndefinedDefaultValue(data, defaultValue) {
|
|
1924
1643
|
if (data !== null && data !== void 0) {
|
|
1925
1644
|
return data;
|
|
@@ -1927,16 +1646,6 @@ export function isNullUndefinedDefaultValue(data, defaultValue) {
|
|
|
1927
1646
|
return defaultValue;
|
|
1928
1647
|
}
|
|
1929
1648
|
}
|
|
1930
|
-
export function runOnReadyState(expectedReadyState, callback) {
|
|
1931
|
-
if (document.readyState === expectedReadyState || document.readyState === 'complete') {
|
|
1932
|
-
callback();
|
|
1933
|
-
} else {
|
|
1934
|
-
var eventName = expectedReadyState === 'complete' ? DOM_EVENT.LOAD : DOM_EVENT.DOM_CONTENT_LOADED;
|
|
1935
|
-
addEventListener(window, eventName, callback, {
|
|
1936
|
-
once: true
|
|
1937
|
-
});
|
|
1938
|
-
}
|
|
1939
|
-
}
|
|
1940
1649
|
export function requestIdleCallback(callback, opts) {
|
|
1941
1650
|
// Use 'requestIdleCallback' when available: it will throttle the mutation processing if the
|
|
1942
1651
|
// browser is busy rendering frames (ex: when frames are below 60fps). When not available, the
|
package/esm/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,8 @@ 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';
|
|
29
33
|
export * from './dataMap';
|
|
30
34
|
export * from './init';
|
|
31
35
|
export * from './session/sessionManagement';
|
|
@@ -33,4 +37,9 @@ export * from './session/sessionConstants';
|
|
|
33
37
|
export * from './session/sessionCookieStore';
|
|
34
38
|
export * from './session/sessionStore';
|
|
35
39
|
export * from './transport';
|
|
36
|
-
export * from './synthetics/syntheticsWorkerValues';
|
|
40
|
+
export * from './synthetics/syntheticsWorkerValues';
|
|
41
|
+
export * from './helper/serialisation/contextManager';
|
|
42
|
+
export * from './helper/serialisation/heavyCustomerDataWarning';
|
|
43
|
+
export * from './helper/serialisation/jsonStringify';
|
|
44
|
+
export * from './helper/serialisation/rowData';
|
|
45
|
+
export * from './user';
|
package/esm/init.js
CHANGED
|
@@ -14,13 +14,13 @@ export function makePublicApi(stub) {
|
|
|
14
14
|
}
|
|
15
15
|
}); // Add an "hidden" property to set debug mode. We define it that way to hide it
|
|
16
16
|
// as much as possible but of course it's not a real protection.
|
|
17
|
+
// Object.defineProperty(publicApi, '_setDebug', {
|
|
18
|
+
// get: function () {
|
|
19
|
+
// return setDebugMode
|
|
20
|
+
// },
|
|
21
|
+
// enumerable: false
|
|
22
|
+
// })
|
|
17
23
|
|
|
18
|
-
Object.defineProperty(publicApi, '_setDebug', {
|
|
19
|
-
get: function get() {
|
|
20
|
-
return setDebugMode;
|
|
21
|
-
},
|
|
22
|
-
enumerable: false
|
|
23
|
-
});
|
|
24
24
|
return publicApi;
|
|
25
25
|
}
|
|
26
26
|
export function defineGlobal(global, name, api) {
|
|
@@ -1,6 +1,7 @@
|
|
|
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',
|
|
@@ -75,7 +76,7 @@ function buildRawReportFromReport(report) {
|
|
|
75
76
|
|
|
76
77
|
function buildRawReportFromCspViolation(event) {
|
|
77
78
|
var type = RawReportType.cspViolation;
|
|
78
|
-
var message = '
|
|
79
|
+
var message = "'" + event.blockedURI + "' blocked by '" + event.effectiveDirective + "' directive";
|
|
79
80
|
return {
|
|
80
81
|
type: RawReportType.cspViolation,
|
|
81
82
|
subtype: event.effectiveDirective,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getCookie, setCookie } from '../browser/cookie';
|
|
2
2
|
import { isChromium, dateNow, isEmptyObject, UUID, objectEntries, map, each } from '../helper/tools';
|
|
3
3
|
import { SESSION_EXPIRATION_DELAY } from './sessionConstants';
|
|
4
|
+
import { setTimeout } from '../helper/timer';
|
|
4
5
|
var SESSION_ENTRY_REGEXP = /^([a-z]+)=([a-z0-9-]+)$/;
|
|
5
6
|
var SESSION_ENTRY_SEPARATOR = '&';
|
|
6
7
|
export var SESSION_COOKIE_NAME = '_dataflux_s'; // arbitrary values
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { relativeNow, clocksOrigin, ONE_MINUTE, each
|
|
1
|
+
import { relativeNow, clocksOrigin, ONE_MINUTE, each } from '../helper/tools';
|
|
2
|
+
import { addEventListeners, addEventListener } from '../browser/addEventListener';
|
|
2
3
|
import { ContextHistory } from '../helper/contextHistory';
|
|
3
4
|
import { startSessionStore } from './sessionStore';
|
|
4
5
|
import { SESSION_TIME_OUT_DELAY } from './sessionConstants';
|
|
5
6
|
import { DOM_EVENT } from '../helper/enums';
|
|
7
|
+
import { clearInterval, setInterval } from '../helper/timer';
|
|
6
8
|
export var VISIBILITY_CHECK_DELAY = ONE_MINUTE;
|
|
7
9
|
var SESSION_CONTEXT_TIMEOUT_DELAY = SESSION_TIME_OUT_DELAY;
|
|
8
10
|
var stopCallbacks = [];
|
|
@@ -42,7 +44,8 @@ export var startSessionManager = function startSessionManager(options, productKe
|
|
|
42
44
|
return sessionContextHistory.find(startTime);
|
|
43
45
|
},
|
|
44
46
|
renewObservable: sessionStore.renewObservable,
|
|
45
|
-
expireObservable: sessionStore.expireObservable
|
|
47
|
+
expireObservable: sessionStore.expireObservable,
|
|
48
|
+
expire: sessionStore.expire
|
|
46
49
|
};
|
|
47
50
|
};
|
|
48
51
|
export function stopSessionManager() {
|
|
@@ -3,6 +3,7 @@ import { Observable } from '../helper/observable';
|
|
|
3
3
|
import { dateNow, UUID, throttle } from '../helper/tools';
|
|
4
4
|
import { SESSION_TIME_OUT_DELAY } from './sessionConstants';
|
|
5
5
|
import { retrieveSession, withCookieLockAccess } from './sessionCookieStore';
|
|
6
|
+
import { clearInterval, setInterval } from '../helper/timer';
|
|
6
7
|
/**
|
|
7
8
|
* Different session concepts:
|
|
8
9
|
* - tracked, the session has an id and is updated along the user navigation
|
|
@@ -67,7 +68,7 @@ export function startSessionStore(options, productKey, computeSessionState) {
|
|
|
67
68
|
|
|
68
69
|
if (hasSessionInCache()) {
|
|
69
70
|
if (isSessionInCacheOutdated(cookieSession)) {
|
|
70
|
-
|
|
71
|
+
expireSessionInCache();
|
|
71
72
|
} else {
|
|
72
73
|
sessionCache = cookieSession;
|
|
73
74
|
}
|
|
@@ -98,7 +99,7 @@ export function startSessionStore(options, productKey, computeSessionState) {
|
|
|
98
99
|
return sessionCache.id !== cookieSession.id || sessionCache[productKey] !== cookieSession[productKey];
|
|
99
100
|
}
|
|
100
101
|
|
|
101
|
-
function
|
|
102
|
+
function expireSessionInCache() {
|
|
102
103
|
sessionCache = {};
|
|
103
104
|
expireObservable.notify();
|
|
104
105
|
}
|
|
@@ -132,6 +133,10 @@ export function startSessionStore(options, productKey, computeSessionState) {
|
|
|
132
133
|
},
|
|
133
134
|
renewObservable: renewObservable,
|
|
134
135
|
expireObservable: expireObservable,
|
|
136
|
+
expire: function expire() {
|
|
137
|
+
deleteSessionCookie(options);
|
|
138
|
+
synchronizeSession({});
|
|
139
|
+
},
|
|
135
140
|
stop: function stop() {
|
|
136
141
|
clearInterval(watchSessionTimeoutId);
|
|
137
142
|
}
|
package/esm/transport/batch.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { display } from '../helper/display';
|
|
2
|
-
import {
|
|
2
|
+
import { values, findByPath, each, isNumber, isArray, extend, isString, toServerDuration, isBoolean, isEmptyObject, isObject } from '../helper/tools';
|
|
3
|
+
import { escapeJsonValue, escapeRowField, escapeRowData } from '../helper/serialisation/rowData';
|
|
3
4
|
import { commonTags, dataMap, commonFields } from '../dataMap';
|
|
4
|
-
import {
|
|
5
|
+
import { RumEventType } from '../helper/enums';
|
|
6
|
+
import { computeBytesCount } from '../helper/byteUtils';
|
|
7
|
+
import { isPageExitReason } from '../browser/pageExitObservable'; // https://en.wikipedia.org/wiki/UTF-8
|
|
5
8
|
// eslint-disable-next-line no-control-regex
|
|
6
9
|
|
|
7
10
|
var HAS_MULTI_BYTES_CHARACTERS = /[^\u0000-\u007F]/;
|
|
@@ -124,23 +127,18 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
|
|
|
124
127
|
};
|
|
125
128
|
};
|
|
126
129
|
|
|
127
|
-
var batch = function batch(request,
|
|
130
|
+
var batch = function batch(request, flushController, messageBytesLimit) {
|
|
128
131
|
this.pushOnlyBuffer = [];
|
|
129
132
|
this.upsertBuffer = {};
|
|
130
|
-
this.bufferBytesCount = 0;
|
|
131
|
-
this.bufferMessagesCount = 0;
|
|
132
133
|
this.request = request;
|
|
133
|
-
this.
|
|
134
|
-
this.batchBytesLimit = batchBytesLimit;
|
|
134
|
+
this.flushController = flushController;
|
|
135
135
|
this.messageBytesLimit = messageBytesLimit;
|
|
136
|
-
this.flushTimeout = flushTimeout;
|
|
137
136
|
|
|
138
137
|
var _this = this;
|
|
139
138
|
|
|
140
|
-
|
|
141
|
-
_this.flush(
|
|
139
|
+
this.flushController.flushObservable.subscribe(function (event) {
|
|
140
|
+
_this.flush(event);
|
|
142
141
|
});
|
|
143
|
-
this.flushPeriodically();
|
|
144
142
|
};
|
|
145
143
|
|
|
146
144
|
batch.prototype.add = function (message) {
|
|
@@ -151,45 +149,26 @@ batch.prototype.upsert = function (message, key) {
|
|
|
151
149
|
this.addOrUpdate(message, key);
|
|
152
150
|
};
|
|
153
151
|
|
|
154
|
-
batch.prototype.flush = function (
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
152
|
+
batch.prototype.flush = function (event) {
|
|
153
|
+
var messages = this.pushOnlyBuffer.concat(values(this.upsertBuffer));
|
|
154
|
+
this.pushOnlyBuffer = [];
|
|
155
|
+
this.upsertBuffer = {};
|
|
158
156
|
|
|
159
|
-
if (
|
|
160
|
-
var
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
bytesCount: bytesCount
|
|
171
|
-
});
|
|
157
|
+
if (messages.length > 0) {
|
|
158
|
+
var payload = {
|
|
159
|
+
data: messages.join('\n'),
|
|
160
|
+
bytesCount: event.bytesCount,
|
|
161
|
+
flushReason: event.reason
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
if (isPageExitReason(event.reason)) {
|
|
165
|
+
this.request.sendOnExit(payload);
|
|
166
|
+
} else {
|
|
167
|
+
this.request.send(payload);
|
|
172
168
|
}
|
|
173
169
|
}
|
|
174
170
|
};
|
|
175
171
|
|
|
176
|
-
batch.prototype.flushOnExit = function () {
|
|
177
|
-
this.flush(this.request.sendOnExit);
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
batch.prototype.computeBytesCount = function (candidate) {
|
|
181
|
-
// Accurate bytes count computations can degrade performances when there is a lot of events to process
|
|
182
|
-
if (!HAS_MULTI_BYTES_CHARACTERS.test(candidate)) {
|
|
183
|
-
return candidate.length;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (window.TextEncoder !== undefined) {
|
|
187
|
-
return new TextEncoder().encode(candidate).length;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return new Blob([candidate]).size;
|
|
191
|
-
};
|
|
192
|
-
|
|
193
172
|
batch.prototype.addOrUpdate = function (message, key) {
|
|
194
173
|
var _process = this.process(message);
|
|
195
174
|
|
|
@@ -205,20 +184,12 @@ batch.prototype.addOrUpdate = function (message, key) {
|
|
|
205
184
|
this.remove(key);
|
|
206
185
|
}
|
|
207
186
|
|
|
208
|
-
if (this.willReachedBytesLimitWith(messageBytesCount)) {
|
|
209
|
-
this.flush();
|
|
210
|
-
}
|
|
211
|
-
|
|
212
187
|
this.push(processedMessage, messageBytesCount, key);
|
|
213
|
-
|
|
214
|
-
if (this.isFull()) {
|
|
215
|
-
this.flush();
|
|
216
|
-
}
|
|
217
188
|
};
|
|
218
189
|
|
|
219
190
|
batch.prototype.process = function (message) {
|
|
220
191
|
var processedMessage = processedMessageByDataMap(message).rowStr;
|
|
221
|
-
var messageBytesCount =
|
|
192
|
+
var messageBytesCount = computeBytesCount(processedMessage);
|
|
222
193
|
return {
|
|
223
194
|
processedMessage: processedMessage,
|
|
224
195
|
messageBytesCount: messageBytesCount
|
|
@@ -226,10 +197,8 @@ batch.prototype.process = function (message) {
|
|
|
226
197
|
};
|
|
227
198
|
|
|
228
199
|
batch.prototype.push = function (processedMessage, messageBytesCount, key) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
this.bufferBytesCount += 1;
|
|
232
|
-
}
|
|
200
|
+
var separatorBytesCount = this.flushController.getMessagesCount() > 0 ? 1 : 0;
|
|
201
|
+
this.flushController.notifyBeforeAddMessage(messageBytesCount + separatorBytesCount);
|
|
233
202
|
|
|
234
203
|
if (key !== undefined) {
|
|
235
204
|
this.upsertBuffer[key] = processedMessage;
|
|
@@ -237,43 +206,20 @@ batch.prototype.push = function (processedMessage, messageBytesCount, key) {
|
|
|
237
206
|
this.pushOnlyBuffer.push(processedMessage);
|
|
238
207
|
}
|
|
239
208
|
|
|
240
|
-
this.
|
|
241
|
-
this.bufferMessagesCount += 1;
|
|
209
|
+
this.flushController.notifyAfterAddMessage();
|
|
242
210
|
};
|
|
243
211
|
|
|
244
212
|
batch.prototype.remove = function (key) {
|
|
245
213
|
var removedMessage = this.upsertBuffer[key];
|
|
246
214
|
delete this.upsertBuffer[key];
|
|
247
|
-
var messageBytesCount =
|
|
248
|
-
this.bufferBytesCount -= messageBytesCount;
|
|
249
|
-
this.bufferMessagesCount -= 1;
|
|
215
|
+
var messageBytesCount = computeBytesCount(removedMessage); // If there are other messages, a '\n' will be added at serialization
|
|
250
216
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
217
|
+
var separatorBytesCount = this.flushController.getMessagesCount() > 1 ? 1 : 0;
|
|
218
|
+
this.flushController.notifyAfterRemoveMessage(messageBytesCount + separatorBytesCount);
|
|
254
219
|
};
|
|
255
220
|
|
|
256
221
|
batch.prototype.hasMessageFor = function (key) {
|
|
257
222
|
return key !== undefined && this.upsertBuffer[key] !== undefined;
|
|
258
223
|
};
|
|
259
224
|
|
|
260
|
-
batch.prototype.willReachedBytesLimitWith = function (messageBytesCount) {
|
|
261
|
-
// byte of the separator at the end of the message
|
|
262
|
-
return this.bufferBytesCount + messageBytesCount + 1 >= this.batchBytesLimit;
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
batch.prototype.isFull = function () {
|
|
266
|
-
return this.bufferMessagesCount === this.batchMessagesLimit || this.bufferBytesCount >= this.batchBytesLimit;
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
batch.prototype.flushPeriodically = function () {
|
|
270
|
-
var _this = this;
|
|
271
|
-
|
|
272
|
-
setTimeout(function () {
|
|
273
|
-
_this.flush();
|
|
274
|
-
|
|
275
|
-
_this.flushPeriodically();
|
|
276
|
-
}, this.flushTimeout);
|
|
277
|
-
};
|
|
278
|
-
|
|
279
225
|
export var Batch = batch;
|