@cloudcare/browser-core 3.0.29 → 3.1.1
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 +3 -8
- package/cjs/browser/addEventListener.js.map +1 -0
- package/cjs/browser/cookie.js +3 -14
- package/cjs/browser/cookie.js.map +1 -0
- package/cjs/browser/fetchObservable.js +4 -21
- package/cjs/browser/fetchObservable.js.map +1 -0
- package/cjs/browser/htmlDomUtils.js +3 -9
- package/cjs/browser/htmlDomUtils.js.map +1 -0
- package/cjs/browser/pageExitObservable.js +3 -9
- package/cjs/browser/pageExitObservable.js.map +1 -0
- package/cjs/browser/runOnReadyState.js +2 -4
- package/cjs/browser/runOnReadyState.js.map +1 -0
- package/cjs/browser/scroll.js +32 -0
- package/cjs/browser/scroll.js.map +1 -0
- package/cjs/browser/xhrObservable.js +2 -21
- package/cjs/browser/xhrObservable.js.map +1 -0
- package/cjs/configuration/configuration.js +9 -20
- package/cjs/configuration/configuration.js.map +1 -0
- package/cjs/configuration/transportConfiguration.js +6 -20
- package/cjs/configuration/transportConfiguration.js.map +1 -0
- package/cjs/console/consoleObservable.js +3 -21
- package/cjs/console/consoleObservable.js.map +1 -0
- package/cjs/dataMap.js +24 -10
- package/cjs/dataMap.js.map +1 -0
- package/cjs/error/trackRuntimeError.js +3 -7
- package/cjs/error/trackRuntimeError.js.map +1 -0
- package/cjs/helper/boundedBuffer.js +2 -6
- package/cjs/helper/boundedBuffer.js.map +1 -0
- package/cjs/helper/byteUtils.js +6 -16
- package/cjs/helper/byteUtils.js.map +1 -0
- package/cjs/helper/catchUserErrors.js +2 -4
- package/cjs/helper/catchUserErrors.js.map +1 -0
- package/cjs/helper/contextHistory.js +21 -37
- package/cjs/helper/contextHistory.js.map +1 -0
- package/cjs/helper/createEventRateLimiter.js +2 -10
- package/cjs/helper/createEventRateLimiter.js.map +1 -0
- package/cjs/helper/deviceInfo.js +10 -64
- package/cjs/helper/deviceInfo.js.map +1 -0
- package/cjs/helper/display.js +2 -5
- package/cjs/helper/display.js.map +1 -0
- package/cjs/helper/enums.js +8 -2
- package/cjs/helper/enums.js.map +1 -0
- package/cjs/helper/errorTools.js +32 -38
- package/cjs/helper/errorTools.js.map +1 -0
- package/cjs/helper/eventEmitter.js +2 -6
- package/cjs/helper/eventEmitter.js.map +1 -0
- package/cjs/helper/getZoneJsOriginalValue.js +2 -5
- package/cjs/helper/getZoneJsOriginalValue.js.map +1 -0
- package/cjs/helper/instrumentMethod.js +10 -22
- package/cjs/helper/instrumentMethod.js.map +1 -0
- package/cjs/helper/lifeCycle.js +2 -9
- package/cjs/helper/lifeCycle.js.map +1 -0
- package/cjs/helper/limitModification.js +4 -22
- package/cjs/helper/limitModification.js.map +1 -0
- package/cjs/helper/mobileUtil.js +2 -20
- package/cjs/helper/mobileUtil.js.map +1 -0
- package/cjs/helper/monitor.js +2 -11
- package/cjs/helper/monitor.js.map +1 -0
- package/cjs/helper/observable.js +2 -9
- package/cjs/helper/observable.js.map +1 -0
- package/cjs/helper/readBytesFromStream.js +4 -14
- package/cjs/helper/readBytesFromStream.js.map +1 -0
- package/cjs/helper/sanitize.js +38 -61
- package/cjs/helper/sanitize.js.map +1 -0
- package/cjs/helper/serialisation/contextManager.js +5 -15
- package/cjs/helper/serialisation/contextManager.js.map +1 -0
- package/cjs/helper/serialisation/heavyCustomerDataWarning.js +2 -7
- package/cjs/helper/serialisation/heavyCustomerDataWarning.js.map +1 -0
- package/cjs/helper/serialisation/jsonStringify.js +6 -12
- package/cjs/helper/serialisation/jsonStringify.js.map +1 -0
- package/cjs/helper/serialisation/rowData.js +3 -10
- package/cjs/helper/serialisation/rowData.js.map +1 -0
- package/cjs/helper/timer.js +2 -8
- package/cjs/helper/timer.js.map +1 -0
- package/cjs/helper/tools.js +57 -444
- package/cjs/helper/tools.js.map +1 -0
- package/cjs/helper/urlPolyfill.js +5 -18
- package/cjs/helper/urlPolyfill.js.map +1 -0
- package/cjs/index.js +24 -95
- package/cjs/index.js.map +1 -0
- package/cjs/init.js +14 -20
- package/cjs/init.js.map +1 -0
- package/cjs/report/reportObservable.js +5 -24
- package/cjs/report/reportObservable.js.map +1 -0
- package/cjs/session/sessionConstants.js +2 -3
- package/cjs/session/sessionConstants.js.map +1 -0
- package/cjs/session/sessionCookieStore.js +11 -46
- package/cjs/session/sessionCookieStore.js.map +1 -0
- package/cjs/session/sessionManagement.js +2 -19
- package/cjs/session/sessionManagement.js.map +1 -0
- package/cjs/session/sessionStore.js +3 -28
- package/cjs/session/sessionStore.js.map +1 -0
- package/cjs/synthetics/syntheticsWorkerValues.js +2 -6
- package/cjs/synthetics/syntheticsWorkerValues.js.map +1 -0
- package/cjs/synthetics/usr.js +2 -8
- package/cjs/synthetics/usr.js.map +1 -0
- package/cjs/telemetry/telemetry.js +125 -0
- package/cjs/telemetry/telemetry.js.map +1 -0
- package/cjs/telemetry/types.js +17 -0
- package/cjs/telemetry/types.js.map +1 -0
- package/cjs/tracekit/computeStackTrace.js +4 -34
- package/cjs/tracekit/computeStackTrace.js.map +1 -0
- package/cjs/tracekit/index.js +2 -3
- package/cjs/tracekit/index.js.map +1 -0
- package/cjs/tracekit/tracekit.js +3 -18
- package/cjs/tracekit/tracekit.js.map +1 -0
- package/cjs/transport/batch.js +5 -54
- package/cjs/transport/batch.js.map +1 -0
- package/cjs/transport/eventBridge.js +2 -7
- package/cjs/transport/eventBridge.js.map +1 -0
- package/cjs/transport/flushController.js +8 -21
- package/cjs/transport/flushController.js.map +1 -0
- package/cjs/transport/httpRequest.js +4 -18
- package/cjs/transport/httpRequest.js.map +1 -0
- package/cjs/transport/index.js +2 -6
- package/cjs/transport/index.js.map +1 -0
- package/cjs/transport/sendWithRetryStrategy.js +3 -27
- package/cjs/transport/sendWithRetryStrategy.js.map +1 -0
- package/cjs/transport/startBatchWithReplica.js +2 -7
- package/cjs/transport/startBatchWithReplica.js.map +1 -0
- package/cjs/user/index.js +2 -3
- package/cjs/user/index.js.map +1 -0
- package/cjs/user/user.js +3 -8
- package/cjs/user/user.js.map +1 -0
- package/cjs/worker.js +2 -2
- package/cjs/worker.js.map +1 -0
- package/esm/browser/addEventListener.js +3 -3
- package/esm/browser/addEventListener.js.map +1 -0
- package/esm/browser/cookie.js +3 -6
- package/esm/browser/cookie.js.map +1 -0
- package/esm/browser/fetchObservable.js +4 -14
- package/esm/browser/fetchObservable.js.map +1 -0
- package/esm/browser/htmlDomUtils.js +3 -2
- package/esm/browser/htmlDomUtils.js.map +1 -0
- package/esm/browser/pageExitObservable.js +3 -2
- package/esm/browser/pageExitObservable.js.map +1 -0
- package/esm/browser/runOnReadyState.js +2 -1
- package/esm/browser/runOnReadyState.js.map +1 -0
- package/esm/browser/scroll.js +25 -0
- package/esm/browser/scroll.js.map +1 -0
- package/esm/browser/xhrObservable.js +2 -14
- package/esm/browser/xhrObservable.js.map +1 -0
- package/esm/configuration/configuration.js +9 -9
- package/esm/configuration/configuration.js.map +1 -0
- package/esm/configuration/transportConfiguration.js +6 -17
- package/esm/configuration/transportConfiguration.js.map +1 -0
- package/esm/console/consoleObservable.js +3 -11
- package/esm/console/consoleObservable.js.map +1 -0
- package/esm/dataMap.js +24 -8
- package/esm/dataMap.js.map +1 -0
- package/esm/error/trackRuntimeError.js +4 -3
- package/esm/error/trackRuntimeError.js.map +1 -0
- package/esm/helper/boundedBuffer.js +2 -4
- package/esm/helper/boundedBuffer.js.map +1 -0
- package/esm/helper/byteUtils.js +6 -13
- package/esm/helper/byteUtils.js.map +1 -0
- package/esm/helper/catchUserErrors.js +2 -2
- package/esm/helper/catchUserErrors.js.map +1 -0
- package/esm/helper/contextHistory.js +21 -33
- package/esm/helper/contextHistory.js.map +1 -0
- package/esm/helper/createEventRateLimiter.js +2 -6
- package/esm/helper/createEventRateLimiter.js.map +1 -0
- package/esm/helper/deviceInfo.js +10 -62
- package/esm/helper/deviceInfo.js.map +1 -0
- package/esm/helper/display.js +2 -3
- package/esm/helper/display.js.map +1 -0
- package/esm/helper/enums.js +6 -1
- package/esm/helper/enums.js.map +1 -0
- package/esm/helper/errorTools.js +30 -25
- package/esm/helper/errorTools.js.map +1 -0
- package/esm/helper/eventEmitter.js +2 -5
- package/esm/helper/eventEmitter.js.map +1 -0
- package/esm/helper/getZoneJsOriginalValue.js +2 -4
- package/esm/helper/getZoneJsOriginalValue.js.map +1 -0
- package/esm/helper/instrumentMethod.js +10 -16
- package/esm/helper/instrumentMethod.js.map +1 -0
- package/esm/helper/lifeCycle.js +2 -5
- package/esm/helper/lifeCycle.js.map +1 -0
- package/esm/helper/limitModification.js +5 -20
- package/esm/helper/limitModification.js.map +1 -0
- package/esm/helper/mobileUtil.js +2 -16
- package/esm/helper/mobileUtil.js.map +1 -0
- package/esm/helper/monitor.js +2 -3
- package/esm/helper/monitor.js.map +1 -0
- package/esm/helper/observable.js +2 -7
- package/esm/helper/observable.js.map +1 -0
- package/esm/helper/readBytesFromStream.js +4 -12
- package/esm/helper/readBytesFromStream.js.map +1 -0
- package/esm/helper/sanitize.js +40 -57
- package/esm/helper/sanitize.js.map +1 -0
- package/esm/helper/serialisation/contextManager.js +5 -9
- package/esm/helper/serialisation/contextManager.js.map +1 -0
- package/esm/helper/serialisation/heavyCustomerDataWarning.js +5 -4
- package/esm/helper/serialisation/heavyCustomerDataWarning.js.map +1 -0
- package/esm/helper/serialisation/jsonStringify.js +7 -10
- package/esm/helper/serialisation/jsonStringify.js.map +1 -0
- package/esm/helper/serialisation/rowData.js +3 -4
- package/esm/helper/serialisation/rowData.js.map +1 -0
- package/esm/helper/timer.js +2 -1
- package/esm/helper/timer.js.map +1 -0
- package/esm/helper/tools.js +57 -256
- package/esm/helper/tools.js.map +1 -0
- package/esm/helper/urlPolyfill.js +5 -9
- package/esm/helper/urlPolyfill.js.map +1 -0
- package/esm/index.js +4 -1
- package/esm/index.js.map +1 -0
- package/esm/init.js +14 -14
- package/esm/init.js.map +1 -0
- package/esm/report/reportObservable.js +5 -16
- package/esm/report/reportObservable.js.map +1 -0
- package/esm/session/sessionConstants.js +2 -1
- package/esm/session/sessionConstants.js.map +1 -0
- package/esm/session/sessionCookieStore.js +11 -38
- package/esm/session/sessionCookieStore.js.map +1 -0
- package/esm/session/sessionManagement.js +2 -8
- package/esm/session/sessionManagement.js.map +1 -0
- package/esm/session/sessionStore.js +4 -22
- package/esm/session/sessionStore.js.map +1 -0
- package/esm/synthetics/syntheticsWorkerValues.js +2 -1
- package/esm/synthetics/syntheticsWorkerValues.js.map +1 -0
- package/esm/synthetics/usr.js +2 -3
- package/esm/synthetics/usr.js.map +1 -0
- package/esm/telemetry/telemetry.js +111 -0
- package/esm/telemetry/telemetry.js.map +1 -0
- package/esm/telemetry/types.js +9 -0
- package/esm/telemetry/types.js.map +1 -0
- package/esm/tracekit/computeStackTrace.js +4 -31
- package/esm/tracekit/computeStackTrace.js.map +1 -0
- package/esm/tracekit/index.js +2 -1
- package/esm/tracekit/index.js.map +1 -0
- package/esm/tracekit/tracekit.js +5 -14
- package/esm/tracekit/tracekit.js.map +1 -0
- package/esm/transport/batch.js +7 -45
- package/esm/transport/batch.js.map +1 -0
- package/esm/transport/eventBridge.js +2 -5
- package/esm/transport/eventBridge.js.map +1 -0
- package/esm/transport/flushController.js +11 -20
- package/esm/transport/flushController.js.map +1 -0
- package/esm/transport/httpRequest.js +4 -15
- package/esm/transport/httpRequest.js.map +1 -0
- package/esm/transport/index.js +2 -1
- package/esm/transport/index.js.map +1 -0
- package/esm/transport/sendWithRetryStrategy.js +3 -21
- package/esm/transport/sendWithRetryStrategy.js.map +1 -0
- package/esm/transport/startBatchWithReplica.js +2 -3
- package/esm/transport/startBatchWithReplica.js.map +1 -0
- package/esm/user/index.js.map +1 -0
- package/esm/user/user.js +4 -5
- package/esm/user/user.js.map +1 -0
- package/esm/worker.js.map +1 -0
- package/package.json +2 -2
- package/src/browser/scroll.js +25 -0
- package/src/configuration/configuration.js +16 -0
- package/src/configuration/transportConfiguration.js +2 -2
- package/src/dataMap.js +17 -3
- package/src/error/trackRuntimeError.js +2 -2
- package/src/helper/contextHistory.js +3 -3
- package/src/helper/enums.js +4 -0
- package/src/helper/errorTools.js +49 -19
- package/src/helper/tools.js +1 -0
- package/src/index.js +3 -0
- package/src/report/reportObservable.js +3 -3
- package/src/telemetry/telemetry.js +165 -0
- package/src/telemetry/types.js +9 -0
- package/src/transport/sendWithRetryStrategy.js +1 -5
|
@@ -5,26 +5,21 @@ import { monitor } from './monitor';
|
|
|
5
5
|
* the stream). The callback is invoked with the at most `limit` bytes, and indicates that the limit
|
|
6
6
|
* has been exceeded if more bytes were available.
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
8
|
export function readBytesFromStream(stream, callback, options) {
|
|
10
9
|
var reader = stream.getReader();
|
|
11
10
|
var chunks = [];
|
|
12
11
|
var readBytesCount = 0;
|
|
13
12
|
readMore();
|
|
14
|
-
|
|
15
13
|
function readMore() {
|
|
16
14
|
reader.read().then(monitor(function (result) {
|
|
17
15
|
if (result.done) {
|
|
18
16
|
onDone();
|
|
19
17
|
return;
|
|
20
18
|
}
|
|
21
|
-
|
|
22
19
|
if (options.collectStreamBody) {
|
|
23
20
|
chunks.push(result.value);
|
|
24
21
|
}
|
|
25
|
-
|
|
26
22
|
readBytesCount += result.value.length;
|
|
27
|
-
|
|
28
23
|
if (readBytesCount > options.bytesLimit) {
|
|
29
24
|
onDone();
|
|
30
25
|
} else {
|
|
@@ -34,17 +29,15 @@ export function readBytesFromStream(stream, callback, options) {
|
|
|
34
29
|
callback(error);
|
|
35
30
|
}));
|
|
36
31
|
}
|
|
37
|
-
|
|
38
32
|
function onDone() {
|
|
39
|
-
reader.cancel()["catch"](
|
|
33
|
+
reader.cancel()["catch"](
|
|
34
|
+
// we don't care if cancel fails, but we still need to catch the error to avoid reporting it
|
|
40
35
|
// as an unhandled rejection
|
|
41
36
|
noop);
|
|
42
37
|
var bytes;
|
|
43
38
|
var limitExceeded;
|
|
44
|
-
|
|
45
39
|
if (options.collectStreamBody) {
|
|
46
40
|
var completeBuffer;
|
|
47
|
-
|
|
48
41
|
if (chunks.length === 1) {
|
|
49
42
|
// optimization: if the response is small enough to fit in a single buffer (provided by the browser), just
|
|
50
43
|
// use it directly.
|
|
@@ -58,11 +51,10 @@ export function readBytesFromStream(stream, callback, options) {
|
|
|
58
51
|
offset += chunk.length;
|
|
59
52
|
});
|
|
60
53
|
}
|
|
61
|
-
|
|
62
54
|
bytes = completeBuffer.slice(0, options.bytesLimit);
|
|
63
55
|
limitExceeded = completeBuffer.length > options.bytesLimit;
|
|
64
56
|
}
|
|
65
|
-
|
|
66
57
|
callback(undefined, bytes, limitExceeded);
|
|
67
58
|
}
|
|
68
|
-
}
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=readBytesFromStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readBytesFromStream.js","names":["noop","each","monitor","readBytesFromStream","stream","callback","options","reader","getReader","chunks","readBytesCount","readMore","read","then","result","done","onDone","collectStreamBody","push","value","length","bytesLimit","error","cancel","bytes","limitExceeded","completeBuffer","Uint8Array","offset","chunk","set","slice","undefined"],"sources":["../../src/helper/readBytesFromStream.js"],"sourcesContent":["import { noop, each } from './tools'\nimport { monitor } from './monitor'\n/**\n * Read bytes from a ReadableStream until at least `limit` bytes have been read (or until the end of\n * the stream). The callback is invoked with the at most `limit` bytes, and indicates that the limit\n * has been exceeded if more bytes were available.\n */\nexport function readBytesFromStream(stream, callback, options) {\n var reader = stream.getReader()\n var chunks = []\n var readBytesCount = 0\n\n readMore()\n\n function readMore() {\n reader.read().then(\n monitor(function (result) {\n if (result.done) {\n onDone()\n return\n }\n\n if (options.collectStreamBody) {\n chunks.push(result.value)\n }\n readBytesCount += result.value.length\n\n if (readBytesCount > options.bytesLimit) {\n onDone()\n } else {\n readMore()\n }\n }),\n monitor(function (error) {\n callback(error)\n })\n )\n }\n\n function onDone() {\n reader.cancel().catch(\n // we don't care if cancel fails, but we still need to catch the error to avoid reporting it\n // as an unhandled rejection\n noop\n )\n\n var bytes\n var limitExceeded\n if (options.collectStreamBody) {\n var completeBuffer\n if (chunks.length === 1) {\n // optimization: if the response is small enough to fit in a single buffer (provided by the browser), just\n // use it directly.\n completeBuffer = chunks[0]\n } else {\n // else, we need to copy buffers into a larger buffer to concatenate them.\n completeBuffer = new Uint8Array(readBytesCount)\n var offset = 0\n each(chunks, function (chunk) {\n completeBuffer.set(chunk, offset)\n offset += chunk.length\n })\n }\n bytes = completeBuffer.slice(0, options.bytesLimit)\n limitExceeded = completeBuffer.length > options.bytesLimit\n }\n callback(undefined, bytes, limitExceeded)\n }\n}\n"],"mappings":"AAAA,SAASA,IAAI,EAAEC,IAAI,QAAQ,SAAS;AACpC,SAASC,OAAO,QAAQ,WAAW;AACnC;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,mBAAmBA,CAACC,MAAM,EAAEC,QAAQ,EAAEC,OAAO,EAAE;EAC7D,IAAIC,MAAM,GAAGH,MAAM,CAACI,SAAS,CAAC,CAAC;EAC/B,IAAIC,MAAM,GAAG,EAAE;EACf,IAAIC,cAAc,GAAG,CAAC;EAEtBC,QAAQ,CAAC,CAAC;EAEV,SAASA,QAAQA,CAAA,EAAG;IAClBJ,MAAM,CAACK,IAAI,CAAC,CAAC,CAACC,IAAI,CAChBX,OAAO,CAAC,UAAUY,MAAM,EAAE;MACxB,IAAIA,MAAM,CAACC,IAAI,EAAE;QACfC,MAAM,CAAC,CAAC;QACR;MACF;MAEA,IAAIV,OAAO,CAACW,iBAAiB,EAAE;QAC7BR,MAAM,CAACS,IAAI,CAACJ,MAAM,CAACK,KAAK,CAAC;MAC3B;MACAT,cAAc,IAAII,MAAM,CAACK,KAAK,CAACC,MAAM;MAErC,IAAIV,cAAc,GAAGJ,OAAO,CAACe,UAAU,EAAE;QACvCL,MAAM,CAAC,CAAC;MACV,CAAC,MAAM;QACLL,QAAQ,CAAC,CAAC;MACZ;IACF,CAAC,CAAC,EACFT,OAAO,CAAC,UAAUoB,KAAK,EAAE;MACvBjB,QAAQ,CAACiB,KAAK,CAAC;IACjB,CAAC,CACH,CAAC;EACH;EAEA,SAASN,MAAMA,CAAA,EAAG;IAChBT,MAAM,CAACgB,MAAM,CAAC,CAAC,SAAM;IACnB;IACA;IACAvB,IACF,CAAC;IAED,IAAIwB,KAAK;IACT,IAAIC,aAAa;IACjB,IAAInB,OAAO,CAACW,iBAAiB,EAAE;MAC7B,IAAIS,cAAc;MAClB,IAAIjB,MAAM,CAACW,MAAM,KAAK,CAAC,EAAE;QACvB;QACA;QACAM,cAAc,GAAGjB,MAAM,CAAC,CAAC,CAAC;MAC5B,CAAC,MAAM;QACL;QACAiB,cAAc,GAAG,IAAIC,UAAU,CAACjB,cAAc,CAAC;QAC/C,IAAIkB,MAAM,GAAG,CAAC;QACd3B,IAAI,CAACQ,MAAM,EAAE,UAAUoB,KAAK,EAAE;UAC5BH,cAAc,CAACI,GAAG,CAACD,KAAK,EAAED,MAAM,CAAC;UACjCA,MAAM,IAAIC,KAAK,CAACT,MAAM;QACxB,CAAC,CAAC;MACJ;MACAI,KAAK,GAAGE,cAAc,CAACK,KAAK,CAAC,CAAC,EAAEzB,OAAO,CAACe,UAAU,CAAC;MACnDI,aAAa,GAAGC,cAAc,CAACN,MAAM,GAAGd,OAAO,CAACe,UAAU;IAC5D;IACAhB,QAAQ,CAAC2B,SAAS,EAAER,KAAK,EAAEC,aAAa,CAAC;EAC3C;AACF"}
|
package/esm/helper/sanitize.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
|
2
|
-
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
3
2
|
import { display } from './display';
|
|
4
3
|
import { ONE_KIBI_BYTE } from './byteUtils';
|
|
5
|
-
import { detachToJsonMethod } from './serialisation/jsonStringify';
|
|
4
|
+
import { detachToJsonMethod } from './serialisation/jsonStringify';
|
|
5
|
+
|
|
6
|
+
// The maximum size of a single event is 256KiB. By default, we ensure that user-provided data
|
|
6
7
|
// going through sanitize fits inside our events, while leaving room for other contexts, metadata, ...
|
|
8
|
+
var SANITIZE_DEFAULT_MAX_CHARACTER_COUNT = 220 * ONE_KIBI_BYTE;
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
// Symbol for the root element of the JSONPath used for visited objects
|
|
11
|
+
var JSON_PATH_ROOT_ELEMENT = '$';
|
|
9
12
|
|
|
10
|
-
|
|
13
|
+
// When serializing (using JSON.stringify) a key of an object, { key: 42 } gets wrapped in quotes as "key".
|
|
11
14
|
// With the separator (:), we need to add 3 characters to the count.
|
|
12
|
-
|
|
13
15
|
var KEY_DECORATION_LENGTH = 3;
|
|
16
|
+
|
|
14
17
|
/**
|
|
15
18
|
* Ensures user-provided data is 'safe' for the SDK
|
|
16
19
|
* - Deep clones data
|
|
@@ -29,32 +32,29 @@ var KEY_DECORATION_LENGTH = 3;
|
|
|
29
32
|
export function sanitize(source, maxCharacterCount) {
|
|
30
33
|
if (maxCharacterCount === undefined) {
|
|
31
34
|
maxCharacterCount = SANITIZE_DEFAULT_MAX_CHARACTER_COUNT;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
}
|
|
36
|
+
// Unbind any toJSON function we may have on [] or {} prototypes
|
|
35
37
|
var restoreObjectPrototypeToJson = detachToJsonMethod(Object.prototype);
|
|
36
|
-
var restoreArrayPrototypeToJson = detachToJsonMethod(Array.prototype);
|
|
38
|
+
var restoreArrayPrototypeToJson = detachToJsonMethod(Array.prototype);
|
|
37
39
|
|
|
40
|
+
// Initial call to sanitizeProcessor - will populate containerQueue if source is an Array or a plain Object
|
|
38
41
|
var containerQueue = [];
|
|
39
42
|
var visitedObjectsWithPath = new WeakMap();
|
|
40
43
|
var sanitizedData = sanitizeProcessor(source, JSON_PATH_ROOT_ELEMENT, undefined, containerQueue, visitedObjectsWithPath);
|
|
41
44
|
var accumulatedCharacterCount = JSON.stringify(sanitizedData) && JSON.stringify(sanitizedData).length || 0;
|
|
42
|
-
|
|
43
45
|
if (accumulatedCharacterCount > maxCharacterCount) {
|
|
44
46
|
warnOverCharacterLimit(maxCharacterCount, 'discarded', source);
|
|
45
47
|
return undefined;
|
|
46
48
|
}
|
|
47
|
-
|
|
48
49
|
while (containerQueue.length > 0 && accumulatedCharacterCount < maxCharacterCount) {
|
|
49
50
|
var containerToProcess = containerQueue.shift();
|
|
50
51
|
var separatorLength = 0; // 0 for the first element, 1 for subsequent elements
|
|
52
|
+
|
|
51
53
|
// Arrays and Objects have to be handled distinctly to ensure
|
|
52
54
|
// we do not pick up non-numerical properties from Arrays
|
|
53
|
-
|
|
54
55
|
if (Array.isArray(containerToProcess.source)) {
|
|
55
56
|
for (var key = 0; key < containerToProcess.source.length; key++) {
|
|
56
57
|
var targetData = sanitizeProcessor(containerToProcess.source[key], containerToProcess.path, key, containerQueue, visitedObjectsWithPath);
|
|
57
|
-
|
|
58
58
|
if (targetData !== undefined) {
|
|
59
59
|
accumulatedCharacterCount += JSON.stringify(targetData).length;
|
|
60
60
|
} else {
|
|
@@ -62,74 +62,65 @@ export function sanitize(source, maxCharacterCount) {
|
|
|
62
62
|
// JSON.stringify([undefined]) => '[null]' - This accounts for 4 characters
|
|
63
63
|
accumulatedCharacterCount += 4;
|
|
64
64
|
}
|
|
65
|
-
|
|
66
65
|
accumulatedCharacterCount += separatorLength;
|
|
67
66
|
separatorLength = 1;
|
|
68
|
-
|
|
69
67
|
if (accumulatedCharacterCount > maxCharacterCount) {
|
|
70
68
|
warnOverCharacterLimit(maxCharacterCount, 'truncated', source);
|
|
71
69
|
break;
|
|
72
70
|
}
|
|
73
|
-
|
|
74
71
|
containerToProcess.target[key] = targetData;
|
|
75
72
|
}
|
|
76
73
|
} else {
|
|
77
74
|
for (var key in containerToProcess.source) {
|
|
78
75
|
if (Object.prototype.hasOwnProperty.call(containerToProcess.source, key)) {
|
|
79
|
-
var targetData = sanitizeProcessor(containerToProcess.source[key], containerToProcess.path, key, containerQueue, visitedObjectsWithPath);
|
|
76
|
+
var targetData = sanitizeProcessor(containerToProcess.source[key], containerToProcess.path, key, containerQueue, visitedObjectsWithPath);
|
|
77
|
+
// When a property of an object has an undefined value, it will be dropped during serialization:
|
|
80
78
|
// JSON.stringify({a:undefined}) => '{}'
|
|
81
|
-
|
|
82
79
|
if (targetData !== undefined) {
|
|
83
80
|
accumulatedCharacterCount += JSON.stringify(targetData).length + separatorLength + key.length + KEY_DECORATION_LENGTH;
|
|
84
81
|
separatorLength = 1;
|
|
85
82
|
}
|
|
86
|
-
|
|
87
83
|
if (accumulatedCharacterCount > maxCharacterCount) {
|
|
88
84
|
warnOverCharacterLimit(maxCharacterCount, 'truncated', source);
|
|
89
85
|
break;
|
|
90
86
|
}
|
|
91
|
-
|
|
92
87
|
containerToProcess.target[key] = targetData;
|
|
93
88
|
}
|
|
94
89
|
}
|
|
95
90
|
}
|
|
96
|
-
}
|
|
97
|
-
|
|
91
|
+
}
|
|
98
92
|
|
|
93
|
+
// Rebind detached toJSON functions
|
|
99
94
|
restoreObjectPrototypeToJson();
|
|
100
95
|
restoreArrayPrototypeToJson();
|
|
101
96
|
return sanitizedData;
|
|
102
97
|
}
|
|
98
|
+
|
|
103
99
|
/**
|
|
104
100
|
* Internal function to factorize the process common to the
|
|
105
101
|
* initial call to sanitize, and iterations for Arrays and Objects
|
|
106
102
|
*
|
|
107
103
|
*/
|
|
108
|
-
|
|
109
104
|
function sanitizeProcessor(source, parentPath, key, queue, visitedObjectsWithPath) {
|
|
110
105
|
// Start by handling toJSON, as we want to sanitize its output
|
|
111
106
|
var sourceToSanitize = tryToApplyToJSON(source);
|
|
112
|
-
|
|
113
107
|
if (!sourceToSanitize || _typeof(sourceToSanitize) !== 'object') {
|
|
114
108
|
return sanitizePrimitivesAndFunctions(sourceToSanitize);
|
|
115
109
|
}
|
|
116
|
-
|
|
117
110
|
var sanitizedSource = sanitizeObjects(sourceToSanitize);
|
|
118
|
-
|
|
119
111
|
if (sanitizedSource !== '[Object]' && sanitizedSource !== '[Array]' && sanitizedSource !== '[Error]') {
|
|
120
112
|
return sanitizedSource;
|
|
121
|
-
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Handle potential cyclic references
|
|
122
116
|
// We need to use source as sourceToSanitize could be a reference to a new object
|
|
123
117
|
// At this stage, we know the source is an object type
|
|
124
|
-
|
|
125
|
-
|
|
126
118
|
var sourceAsObject = source;
|
|
127
|
-
|
|
128
119
|
if (visitedObjectsWithPath.has(sourceAsObject)) {
|
|
129
120
|
return '[Reference seen at ' + visitedObjectsWithPath.get(sourceAsObject) + ']';
|
|
130
|
-
}
|
|
131
|
-
|
|
121
|
+
}
|
|
132
122
|
|
|
123
|
+
// Add processed source to queue
|
|
133
124
|
var currentPath = key !== undefined ? parentPath + '.' + key : parentPath;
|
|
134
125
|
var target = Array.isArray(sourceToSanitize) ? [] : {};
|
|
135
126
|
visitedObjectsWithPath.set(sourceAsObject, currentPath);
|
|
@@ -140,32 +131,29 @@ function sanitizeProcessor(source, parentPath, key, queue, visitedObjectsWithPat
|
|
|
140
131
|
});
|
|
141
132
|
return target;
|
|
142
133
|
}
|
|
134
|
+
|
|
143
135
|
/**
|
|
144
136
|
* Handles sanitization of simple, non-object types
|
|
145
137
|
*
|
|
146
138
|
*/
|
|
147
|
-
|
|
148
|
-
|
|
149
139
|
function sanitizePrimitivesAndFunctions(value) {
|
|
150
140
|
// BigInt cannot be serialized by JSON.stringify(), convert it to a string representation
|
|
151
141
|
if (typeof value === 'bigint') {
|
|
152
142
|
return '[BigInt] ' + value.toString();
|
|
153
|
-
}
|
|
143
|
+
}
|
|
144
|
+
// Functions cannot be serialized by JSON.stringify(). Moreover, if a faulty toJSON is present, it needs to be converted
|
|
154
145
|
// so it won't prevent stringify from serializing later
|
|
155
|
-
|
|
156
|
-
|
|
157
146
|
if (typeof value === 'function') {
|
|
158
147
|
return '[Function] ' + value.name || 'unknown';
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
148
|
+
}
|
|
149
|
+
// JSON.stringify() does not serialize symbols.
|
|
162
150
|
if (_typeof(value) === 'symbol') {
|
|
163
151
|
// symbol.description is part of ES2019+
|
|
164
152
|
return '[Symbol] ' + value.description || value.toString();
|
|
165
153
|
}
|
|
166
|
-
|
|
167
154
|
return value;
|
|
168
155
|
}
|
|
156
|
+
|
|
169
157
|
/**
|
|
170
158
|
* Handles sanitization of object types
|
|
171
159
|
*
|
|
@@ -176,8 +164,6 @@ function sanitizePrimitivesAndFunctions(value) {
|
|
|
176
164
|
* properties enumerated if any.
|
|
177
165
|
*
|
|
178
166
|
*/
|
|
179
|
-
|
|
180
|
-
|
|
181
167
|
function sanitizeObjects(value) {
|
|
182
168
|
try {
|
|
183
169
|
// Handle events - Keep a simple implementation to avoid breaking changes
|
|
@@ -185,44 +171,41 @@ function sanitizeObjects(value) {
|
|
|
185
171
|
return {
|
|
186
172
|
isTrusted: value.isTrusted
|
|
187
173
|
};
|
|
188
|
-
}
|
|
189
|
-
|
|
174
|
+
}
|
|
190
175
|
|
|
176
|
+
// Handle all remaining object types in a generic way
|
|
191
177
|
var result = Object.prototype.toString.call(value);
|
|
192
178
|
var match = result.match(/\[object (.*)\]/);
|
|
193
|
-
|
|
194
179
|
if (match && match[1]) {
|
|
195
180
|
return '[' + match[1] + ']';
|
|
196
181
|
}
|
|
197
|
-
} catch (_unused) {
|
|
182
|
+
} catch (_unused) {
|
|
183
|
+
// If the previous serialization attempts failed, and we cannot convert using
|
|
198
184
|
// Object.prototype.toString, declare the value unserializable
|
|
199
185
|
}
|
|
200
|
-
|
|
201
186
|
return '[Unserializable]';
|
|
202
187
|
}
|
|
188
|
+
|
|
203
189
|
/**
|
|
204
190
|
* Checks if a toJSON function exists and tries to execute it
|
|
205
191
|
*
|
|
206
192
|
*/
|
|
207
|
-
|
|
208
|
-
|
|
209
193
|
function tryToApplyToJSON(value) {
|
|
210
194
|
var object = value;
|
|
211
|
-
|
|
212
195
|
if (object && typeof object.toJSON === 'function') {
|
|
213
196
|
try {
|
|
214
197
|
return object.toJSON();
|
|
215
|
-
} catch (_unused2) {
|
|
198
|
+
} catch (_unused2) {
|
|
199
|
+
// If toJSON fails, we continue by trying to serialize the value manually
|
|
216
200
|
}
|
|
217
201
|
}
|
|
218
|
-
|
|
219
202
|
return value;
|
|
220
203
|
}
|
|
204
|
+
|
|
221
205
|
/**
|
|
222
206
|
* Helper function to display the warning when the accumulated character count is over the limit
|
|
223
207
|
*/
|
|
224
|
-
|
|
225
|
-
|
|
226
208
|
function warnOverCharacterLimit(maxCharacterCount, changeType, source) {
|
|
227
209
|
display.warn('The data provided has been ' + changeType + ' as it is over the limit of ' + maxCharacterCount + ' characters:', source);
|
|
228
|
-
}
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=sanitize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize.js","names":["display","ONE_KIBI_BYTE","detachToJsonMethod","SANITIZE_DEFAULT_MAX_CHARACTER_COUNT","JSON_PATH_ROOT_ELEMENT","KEY_DECORATION_LENGTH","sanitize","source","maxCharacterCount","undefined","restoreObjectPrototypeToJson","Object","prototype","restoreArrayPrototypeToJson","Array","containerQueue","visitedObjectsWithPath","WeakMap","sanitizedData","sanitizeProcessor","accumulatedCharacterCount","JSON","stringify","length","warnOverCharacterLimit","containerToProcess","shift","separatorLength","isArray","key","targetData","path","target","hasOwnProperty","call","parentPath","queue","sourceToSanitize","tryToApplyToJSON","_typeof","sanitizePrimitivesAndFunctions","sanitizedSource","sanitizeObjects","sourceAsObject","has","get","currentPath","set","push","value","toString","name","description","Event","isTrusted","result","match","_unused","object","toJSON","_unused2","changeType","warn"],"sources":["../../src/helper/sanitize.js"],"sourcesContent":["import { display } from './display'\nimport { ONE_KIBI_BYTE } from './byteUtils'\nimport { detachToJsonMethod } from './serialisation/jsonStringify'\n\n// The maximum size of a single event is 256KiB. By default, we ensure that user-provided data\n// going through sanitize fits inside our events, while leaving room for other contexts, metadata, ...\nvar SANITIZE_DEFAULT_MAX_CHARACTER_COUNT = 220 * ONE_KIBI_BYTE\n\n// Symbol for the root element of the JSONPath used for visited objects\nvar JSON_PATH_ROOT_ELEMENT = '$'\n\n// When serializing (using JSON.stringify) a key of an object, { key: 42 } gets wrapped in quotes as \"key\".\n// With the separator (:), we need to add 3 characters to the count.\nvar KEY_DECORATION_LENGTH = 3\n\n/**\n * Ensures user-provided data is 'safe' for the SDK\n * - Deep clones data\n * - Removes cyclic references\n * - Transforms unserializable types to a string representation\n *\n * LIMITATIONS:\n * - Size is in characters, not byte count (may differ according to character encoding)\n * - Size does not take into account indentation that can be applied to JSON.stringify\n * - Non-numerical properties of Arrays are ignored. Same behavior as JSON.stringify\n *\n * @param source User-provided data meant to be serialized using JSON.stringify\n * @param maxCharacterCount Maximum number of characters allowed in serialized form\n */\n\nexport function sanitize(source, maxCharacterCount) {\n if (maxCharacterCount === undefined) {\n maxCharacterCount = SANITIZE_DEFAULT_MAX_CHARACTER_COUNT\n }\n // Unbind any toJSON function we may have on [] or {} prototypes\n var restoreObjectPrototypeToJson = detachToJsonMethod(Object.prototype)\n var restoreArrayPrototypeToJson = detachToJsonMethod(Array.prototype)\n\n // Initial call to sanitizeProcessor - will populate containerQueue if source is an Array or a plain Object\n var containerQueue = []\n var visitedObjectsWithPath = new WeakMap()\n var sanitizedData = sanitizeProcessor(\n source,\n JSON_PATH_ROOT_ELEMENT,\n undefined,\n containerQueue,\n visitedObjectsWithPath\n )\n var accumulatedCharacterCount =\n (JSON.stringify(sanitizedData) && JSON.stringify(sanitizedData).length) || 0\n if (accumulatedCharacterCount > maxCharacterCount) {\n warnOverCharacterLimit(maxCharacterCount, 'discarded', source)\n return undefined\n }\n\n while (\n containerQueue.length > 0 &&\n accumulatedCharacterCount < maxCharacterCount\n ) {\n var containerToProcess = containerQueue.shift()\n var separatorLength = 0 // 0 for the first element, 1 for subsequent elements\n\n // Arrays and Objects have to be handled distinctly to ensure\n // we do not pick up non-numerical properties from Arrays\n if (Array.isArray(containerToProcess.source)) {\n for (var key = 0; key < containerToProcess.source.length; key++) {\n var targetData = sanitizeProcessor(\n containerToProcess.source[key],\n containerToProcess.path,\n key,\n containerQueue,\n visitedObjectsWithPath\n )\n\n if (targetData !== undefined) {\n accumulatedCharacterCount += JSON.stringify(targetData).length\n } else {\n // When an element of an Array (targetData) is undefined, it is serialized as null:\n // JSON.stringify([undefined]) => '[null]' - This accounts for 4 characters\n accumulatedCharacterCount += 4\n }\n accumulatedCharacterCount += separatorLength\n separatorLength = 1\n if (accumulatedCharacterCount > maxCharacterCount) {\n warnOverCharacterLimit(maxCharacterCount, 'truncated', source)\n break\n }\n containerToProcess.target[key] = targetData\n }\n } else {\n for (var key in containerToProcess.source) {\n if (\n Object.prototype.hasOwnProperty.call(containerToProcess.source, key)\n ) {\n var targetData = sanitizeProcessor(\n containerToProcess.source[key],\n containerToProcess.path,\n key,\n containerQueue,\n visitedObjectsWithPath\n )\n // When a property of an object has an undefined value, it will be dropped during serialization:\n // JSON.stringify({a:undefined}) => '{}'\n if (targetData !== undefined) {\n accumulatedCharacterCount +=\n JSON.stringify(targetData).length +\n separatorLength +\n key.length +\n KEY_DECORATION_LENGTH\n separatorLength = 1\n }\n if (accumulatedCharacterCount > maxCharacterCount) {\n warnOverCharacterLimit(maxCharacterCount, 'truncated', source)\n break\n }\n containerToProcess.target[key] = targetData\n }\n }\n }\n }\n\n // Rebind detached toJSON functions\n restoreObjectPrototypeToJson()\n restoreArrayPrototypeToJson()\n\n return sanitizedData\n}\n\n/**\n * Internal function to factorize the process common to the\n * initial call to sanitize, and iterations for Arrays and Objects\n *\n */\nfunction sanitizeProcessor(\n source,\n parentPath,\n key,\n queue,\n visitedObjectsWithPath\n) {\n // Start by handling toJSON, as we want to sanitize its output\n var sourceToSanitize = tryToApplyToJSON(source)\n\n if (!sourceToSanitize || typeof sourceToSanitize !== 'object') {\n return sanitizePrimitivesAndFunctions(sourceToSanitize)\n }\n\n var sanitizedSource = sanitizeObjects(sourceToSanitize)\n if (\n sanitizedSource !== '[Object]' &&\n sanitizedSource !== '[Array]' &&\n sanitizedSource !== '[Error]'\n ) {\n return sanitizedSource\n }\n\n // Handle potential cyclic references\n // We need to use source as sourceToSanitize could be a reference to a new object\n // At this stage, we know the source is an object type\n var sourceAsObject = source\n if (visitedObjectsWithPath.has(sourceAsObject)) {\n return (\n '[Reference seen at ' + visitedObjectsWithPath.get(sourceAsObject) + ']'\n )\n }\n\n // Add processed source to queue\n var currentPath = key !== undefined ? parentPath + '.' + key : parentPath\n var target = Array.isArray(sourceToSanitize) ? [] : {}\n visitedObjectsWithPath.set(sourceAsObject, currentPath)\n queue.push({ source: sourceToSanitize, target, path: currentPath })\n\n return target\n}\n\n/**\n * Handles sanitization of simple, non-object types\n *\n */\nfunction sanitizePrimitivesAndFunctions(value) {\n // BigInt cannot be serialized by JSON.stringify(), convert it to a string representation\n if (typeof value === 'bigint') {\n return '[BigInt] ' + value.toString()\n }\n // Functions cannot be serialized by JSON.stringify(). Moreover, if a faulty toJSON is present, it needs to be converted\n // so it won't prevent stringify from serializing later\n if (typeof value === 'function') {\n return '[Function] ' + value.name || 'unknown'\n }\n // JSON.stringify() does not serialize symbols.\n if (typeof value === 'symbol') {\n // symbol.description is part of ES2019+\n return '[Symbol] ' + value.description || value.toString()\n }\n\n return value\n}\n\n/**\n * Handles sanitization of object types\n *\n * LIMITATIONS\n * - If a class defines a toStringTag Symbol, it will fall in the catch-all method and prevent enumeration of properties.\n * To avoid this, a toJSON method can be defined.\n * - IE11 does not return a distinct type for objects such as Map, WeakMap, ... These objects will pass through and their\n * properties enumerated if any.\n *\n */\nfunction sanitizeObjects(value) {\n try {\n // Handle events - Keep a simple implementation to avoid breaking changes\n if (value instanceof Event) {\n return {\n isTrusted: value.isTrusted\n }\n }\n\n // Handle all remaining object types in a generic way\n var result = Object.prototype.toString.call(value)\n var match = result.match(/\\[object (.*)\\]/)\n if (match && match[1]) {\n return '[' + match[1] + ']'\n }\n } catch {\n // If the previous serialization attempts failed, and we cannot convert using\n // Object.prototype.toString, declare the value unserializable\n }\n return '[Unserializable]'\n}\n\n/**\n * Checks if a toJSON function exists and tries to execute it\n *\n */\nfunction tryToApplyToJSON(value) {\n var object = value\n if (object && typeof object.toJSON === 'function') {\n try {\n return object.toJSON()\n } catch {\n // If toJSON fails, we continue by trying to serialize the value manually\n }\n }\n\n return value\n}\n\n/**\n * Helper function to display the warning when the accumulated character count is over the limit\n */\nfunction warnOverCharacterLimit(maxCharacterCount, changeType, source) {\n display.warn(\n 'The data provided has been ' +\n changeType +\n ' as it is over the limit of ' +\n maxCharacterCount +\n ' characters:',\n source\n )\n}\n"],"mappings":"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"}
|
|
@@ -7,15 +7,14 @@ export function createContextManager(customerDataType, computeBytesCountImpl) {
|
|
|
7
7
|
if (typeof computeBytesCountImpl === 'undefined') {
|
|
8
8
|
computeBytesCountImpl = computeBytesCount;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
10
|
var context = {};
|
|
12
11
|
var bytesCountCache;
|
|
13
|
-
var alreadyWarned = false;
|
|
14
|
-
// Especially useful if the user call context APIs synchronously multiple times in a row
|
|
12
|
+
var alreadyWarned = false;
|
|
15
13
|
|
|
14
|
+
// Throttle the bytes computation to minimize the impact on performance.
|
|
15
|
+
// Especially useful if the user call context APIs synchronously multiple times in a row
|
|
16
16
|
var computeBytesCountThrottled = throttle(function (context) {
|
|
17
17
|
bytesCountCache = computeBytesCountImpl(jsonStringify(context));
|
|
18
|
-
|
|
19
18
|
if (!alreadyWarned) {
|
|
20
19
|
alreadyWarned = warnIfCustomerDataLimitReached(bytesCountCache, customerDataType);
|
|
21
20
|
}
|
|
@@ -24,24 +23,20 @@ export function createContextManager(customerDataType, computeBytesCountImpl) {
|
|
|
24
23
|
getBytesCount: function getBytesCount() {
|
|
25
24
|
return bytesCountCache;
|
|
26
25
|
},
|
|
27
|
-
|
|
28
26
|
/** @deprecated use getContext instead */
|
|
29
27
|
get: function get() {
|
|
30
28
|
return context;
|
|
31
29
|
},
|
|
32
|
-
|
|
33
30
|
/** @deprecated use setContextProperty instead */
|
|
34
31
|
add: function add(key, value) {
|
|
35
32
|
context[key] = value;
|
|
36
33
|
computeBytesCountThrottled(context);
|
|
37
34
|
},
|
|
38
|
-
|
|
39
35
|
/** @deprecated renamed to removeContextProperty */
|
|
40
36
|
remove: function remove(key) {
|
|
41
37
|
delete context[key];
|
|
42
38
|
computeBytesCountThrottled(context);
|
|
43
39
|
},
|
|
44
|
-
|
|
45
40
|
/** @deprecated use setContext instead */
|
|
46
41
|
set: function set(newContext) {
|
|
47
42
|
context = newContext;
|
|
@@ -67,4 +62,5 @@ export function createContextManager(customerDataType, computeBytesCountImpl) {
|
|
|
67
62
|
bytesCountCache = 0;
|
|
68
63
|
}
|
|
69
64
|
};
|
|
70
|
-
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=contextManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contextManager.js","names":["computeBytesCount","deepClone","throttle","jsonStringify","warnIfCustomerDataLimitReached","BYTES_COMPUTATION_THROTTLING_DELAY","createContextManager","customerDataType","computeBytesCountImpl","context","bytesCountCache","alreadyWarned","computeBytesCountThrottled","throttled","getBytesCount","get","add","key","value","remove","set","newContext","getContext","setContext","setContextProperty","property","removeContextProperty","clearContext"],"sources":["../../../src/helper/serialisation/contextManager.js"],"sourcesContent":["import { computeBytesCount } from '../byteUtils'\nimport { deepClone, throttle } from '../tools'\nimport { jsonStringify } from './jsonStringify'\nimport { warnIfCustomerDataLimitReached } from './heavyCustomerDataWarning'\n\nexport var BYTES_COMPUTATION_THROTTLING_DELAY = 200\n\nexport function createContextManager(customerDataType, computeBytesCountImpl) {\n if (typeof computeBytesCountImpl === 'undefined') {\n computeBytesCountImpl = computeBytesCount\n }\n var context = {}\n var bytesCountCache\n var alreadyWarned = false\n\n // Throttle the bytes computation to minimize the impact on performance.\n // Especially useful if the user call context APIs synchronously multiple times in a row\n var computeBytesCountThrottled = throttle(function (context) {\n bytesCountCache = computeBytesCountImpl(jsonStringify(context))\n if (!alreadyWarned) {\n alreadyWarned = warnIfCustomerDataLimitReached(\n bytesCountCache,\n customerDataType\n )\n }\n }, BYTES_COMPUTATION_THROTTLING_DELAY).throttled\n\n return {\n getBytesCount: function () {\n return bytesCountCache\n },\n /** @deprecated use getContext instead */\n get: function () {\n return context\n },\n\n /** @deprecated use setContextProperty instead */\n add: function (key, value) {\n context[key] = value\n computeBytesCountThrottled(context)\n },\n\n /** @deprecated renamed to removeContextProperty */\n remove: function (key) {\n delete context[key]\n computeBytesCountThrottled(context)\n },\n\n /** @deprecated use setContext instead */\n set: function (newContext) {\n context = newContext\n computeBytesCountThrottled(context)\n },\n\n getContext: function () {\n return deepClone(context)\n },\n\n setContext: function (newContext) {\n context = deepClone(newContext)\n computeBytesCountThrottled(context)\n },\n\n setContextProperty: function (key, property) {\n context[key] = deepClone(property)\n computeBytesCountThrottled(context)\n },\n\n removeContextProperty: function (key) {\n delete context[key]\n computeBytesCountThrottled(context)\n },\n\n clearContext: function () {\n context = {}\n bytesCountCache = 0\n }\n }\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,cAAc;AAChD,SAASC,SAAS,EAAEC,QAAQ,QAAQ,UAAU;AAC9C,SAASC,aAAa,QAAQ,iBAAiB;AAC/C,SAASC,8BAA8B,QAAQ,4BAA4B;AAE3E,OAAO,IAAIC,kCAAkC,GAAG,GAAG;AAEnD,OAAO,SAASC,oBAAoBA,CAACC,gBAAgB,EAAEC,qBAAqB,EAAE;EAC5E,IAAI,OAAOA,qBAAqB,KAAK,WAAW,EAAE;IAChDA,qBAAqB,GAAGR,iBAAiB;EAC3C;EACA,IAAIS,OAAO,GAAG,CAAC,CAAC;EAChB,IAAIC,eAAe;EACnB,IAAIC,aAAa,GAAG,KAAK;;EAEzB;EACA;EACA,IAAIC,0BAA0B,GAAGV,QAAQ,CAAC,UAAUO,OAAO,EAAE;IAC3DC,eAAe,GAAGF,qBAAqB,CAACL,aAAa,CAACM,OAAO,CAAC,CAAC;IAC/D,IAAI,CAACE,aAAa,EAAE;MAClBA,aAAa,GAAGP,8BAA8B,CAC5CM,eAAe,EACfH,gBACF,CAAC;IACH;EACF,CAAC,EAAEF,kCAAkC,CAAC,CAACQ,SAAS;EAEhD,OAAO;IACLC,aAAa,EAAE,SAAAA,cAAA,EAAY;MACzB,OAAOJ,eAAe;IACxB,CAAC;IACD;IACAK,GAAG,EAAE,SAAAA,IAAA,EAAY;MACf,OAAON,OAAO;IAChB,CAAC;IAED;IACAO,GAAG,EAAE,SAAAA,IAAUC,GAAG,EAAEC,KAAK,EAAE;MACzBT,OAAO,CAACQ,GAAG,CAAC,GAAGC,KAAK;MACpBN,0BAA0B,CAACH,OAAO,CAAC;IACrC,CAAC;IAED;IACAU,MAAM,EAAE,SAAAA,OAAUF,GAAG,EAAE;MACrB,OAAOR,OAAO,CAACQ,GAAG,CAAC;MACnBL,0BAA0B,CAACH,OAAO,CAAC;IACrC,CAAC;IAED;IACAW,GAAG,EAAE,SAAAA,IAAUC,UAAU,EAAE;MACzBZ,OAAO,GAAGY,UAAU;MACpBT,0BAA0B,CAACH,OAAO,CAAC;IACrC,CAAC;IAEDa,UAAU,EAAE,SAAAA,WAAA,EAAY;MACtB,OAAOrB,SAAS,CAACQ,OAAO,CAAC;IAC3B,CAAC;IAEDc,UAAU,EAAE,SAAAA,WAAUF,UAAU,EAAE;MAChCZ,OAAO,GAAGR,SAAS,CAACoB,UAAU,CAAC;MAC/BT,0BAA0B,CAACH,OAAO,CAAC;IACrC,CAAC;IAEDe,kBAAkB,EAAE,SAAAA,mBAAUP,GAAG,EAAEQ,QAAQ,EAAE;MAC3ChB,OAAO,CAACQ,GAAG,CAAC,GAAGhB,SAAS,CAACwB,QAAQ,CAAC;MAClCb,0BAA0B,CAACH,OAAO,CAAC;IACrC,CAAC;IAEDiB,qBAAqB,EAAE,SAAAA,sBAAUT,GAAG,EAAE;MACpC,OAAOR,OAAO,CAACQ,GAAG,CAAC;MACnBL,0BAA0B,CAACH,OAAO,CAAC;IACrC,CAAC;IAEDkB,YAAY,EAAE,SAAAA,aAAA,EAAY;MACxBlB,OAAO,GAAG,CAAC,CAAC;MACZC,eAAe,GAAG,CAAC;IACrB;EACF,CAAC;AACH"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ONE_KIBI_BYTE } from '../byteUtils';
|
|
2
|
-
import { display } from '../display';
|
|
2
|
+
import { display } from '../display';
|
|
3
|
+
|
|
4
|
+
// RUM and logs batch bytes limit is 16KB
|
|
3
5
|
// ensure that we leave room for other event attributes and maintain a decent amount of event per batch
|
|
4
6
|
// (3KB (customer data) + 1KB (other attributes)) * 4 (events per batch) = 16KB
|
|
5
|
-
|
|
6
7
|
export var CUSTOMER_DATA_BYTES_LIMIT = 3 * ONE_KIBI_BYTE;
|
|
7
8
|
export var CustomerDataType = {
|
|
8
9
|
FeatureFlag: 'feature flag evaluation',
|
|
@@ -15,6 +16,6 @@ export function warnIfCustomerDataLimitReached(bytesCount, customerDataType) {
|
|
|
15
16
|
display.warn('The ' + customerDataType + 'data is over ' + CUSTOMER_DATA_BYTES_LIMIT / ONE_KIBI_BYTE + " KiB. On low connectivity, the SDK has the potential to exhaust the user's upload bandwidth.");
|
|
16
17
|
return true;
|
|
17
18
|
}
|
|
18
|
-
|
|
19
19
|
return false;
|
|
20
|
-
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=heavyCustomerDataWarning.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heavyCustomerDataWarning.js","names":["ONE_KIBI_BYTE","display","CUSTOMER_DATA_BYTES_LIMIT","CustomerDataType","FeatureFlag","User","GlobalContext","LoggerContext","warnIfCustomerDataLimitReached","bytesCount","customerDataType","warn"],"sources":["../../../src/helper/serialisation/heavyCustomerDataWarning.js"],"sourcesContent":["import { ONE_KIBI_BYTE } from '../byteUtils'\nimport { display } from '../display'\n\n// RUM and logs batch bytes limit is 16KB\n// ensure that we leave room for other event attributes and maintain a decent amount of event per batch\n// (3KB (customer data) + 1KB (other attributes)) * 4 (events per batch) = 16KB\nexport var CUSTOMER_DATA_BYTES_LIMIT = 3 * ONE_KIBI_BYTE\n\nexport var CustomerDataType = {\n FeatureFlag: 'feature flag evaluation',\n User: 'user',\n GlobalContext: 'global context',\n LoggerContext: 'logger context'\n}\n\nexport function warnIfCustomerDataLimitReached(bytesCount, customerDataType) {\n if (bytesCount > CUSTOMER_DATA_BYTES_LIMIT) {\n display.warn(\n 'The ' +\n customerDataType +\n 'data is over ' +\n CUSTOMER_DATA_BYTES_LIMIT / ONE_KIBI_BYTE +\n \" KiB. On low connectivity, the SDK has the potential to exhaust the user's upload bandwidth.\"\n )\n return true\n }\n return false\n}\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,cAAc;AAC5C,SAASC,OAAO,QAAQ,YAAY;;AAEpC;AACA;AACA;AACA,OAAO,IAAIC,yBAAyB,GAAG,CAAC,GAAGF,aAAa;AAExD,OAAO,IAAIG,gBAAgB,GAAG;EAC5BC,WAAW,EAAE,yBAAyB;EACtCC,IAAI,EAAE,MAAM;EACZC,aAAa,EAAE,gBAAgB;EAC/BC,aAAa,EAAE;AACjB,CAAC;AAED,OAAO,SAASC,8BAA8BA,CAACC,UAAU,EAAEC,gBAAgB,EAAE;EAC3E,IAAID,UAAU,GAAGP,yBAAyB,EAAE;IAC1CD,OAAO,CAACU,IAAI,CACV,MAAM,GACJD,gBAAgB,GAChB,eAAe,GACfR,yBAAyB,GAAGF,aAAa,GACzC,8FACJ,CAAC;IACD,OAAO,IAAI;EACb;EACA,OAAO,KAAK;AACd"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
|
2
|
-
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
3
2
|
import { noop } from '../tools';
|
|
3
|
+
|
|
4
4
|
/**
|
|
5
5
|
* Custom implementation of JSON.stringify that ignores some toJSON methods. We need to do that
|
|
6
6
|
* because some sites badly override toJSON on certain objects. Removing all toJSON methods from
|
|
@@ -9,19 +9,17 @@ import { noop } from '../tools';
|
|
|
9
9
|
*
|
|
10
10
|
* Note: this still assumes that JSON.stringify is correct.
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
12
|
export function jsonStringify(value, replacer, space) {
|
|
14
13
|
if (_typeof(value) !== 'object' || value === null) {
|
|
15
14
|
return JSON.stringify(value);
|
|
16
|
-
}
|
|
17
|
-
// subclasses.
|
|
18
|
-
|
|
15
|
+
}
|
|
19
16
|
|
|
17
|
+
// Note: The order matter here. We need to detach toJSON methods on parent classes before their
|
|
18
|
+
// subclasses.
|
|
20
19
|
var restoreObjectPrototypeToJson = detachToJsonMethod(Object.prototype);
|
|
21
20
|
var restoreArrayPrototypeToJson = detachToJsonMethod(Array.prototype);
|
|
22
21
|
var restoreValuePrototypeToJson = detachToJsonMethod(Object.getPrototypeOf(value));
|
|
23
22
|
var restoreValueToJson = detachToJsonMethod(value);
|
|
24
|
-
|
|
25
23
|
try {
|
|
26
24
|
return JSON.stringify(value, replacer, space);
|
|
27
25
|
} catch (_unused) {
|
|
@@ -36,13 +34,12 @@ export function jsonStringify(value, replacer, space) {
|
|
|
36
34
|
export function detachToJsonMethod(value) {
|
|
37
35
|
var object = value;
|
|
38
36
|
var objectToJson = object.toJSON;
|
|
39
|
-
|
|
40
37
|
if (objectToJson) {
|
|
41
38
|
delete object.toJSON;
|
|
42
39
|
return function () {
|
|
43
40
|
object.toJSON = objectToJson;
|
|
44
41
|
};
|
|
45
42
|
}
|
|
46
|
-
|
|
47
43
|
return noop;
|
|
48
|
-
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=jsonStringify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonStringify.js","names":["noop","jsonStringify","value","replacer","space","_typeof","JSON","stringify","restoreObjectPrototypeToJson","detachToJsonMethod","Object","prototype","restoreArrayPrototypeToJson","Array","restoreValuePrototypeToJson","getPrototypeOf","restoreValueToJson","_unused","object","objectToJson","toJSON"],"sources":["../../../src/helper/serialisation/jsonStringify.js"],"sourcesContent":["import { noop } from '../tools'\n\n/**\n * Custom implementation of JSON.stringify that ignores some toJSON methods. We need to do that\n * because some sites badly override toJSON on certain objects. Removing all toJSON methods from\n * nested values would be too costly, so we just detach them from the root value, and native classes\n * used to build JSON values (Array and Object).\n *\n * Note: this still assumes that JSON.stringify is correct.\n */\nexport function jsonStringify(value, replacer, space) {\n if (typeof value !== 'object' || value === null) {\n return JSON.stringify(value)\n }\n\n // Note: The order matter here. We need to detach toJSON methods on parent classes before their\n // subclasses.\n var restoreObjectPrototypeToJson = detachToJsonMethod(Object.prototype)\n var restoreArrayPrototypeToJson = detachToJsonMethod(Array.prototype)\n var restoreValuePrototypeToJson = detachToJsonMethod(\n Object.getPrototypeOf(value)\n )\n var restoreValueToJson = detachToJsonMethod(value)\n\n try {\n return JSON.stringify(value, replacer, space)\n } catch {\n return '<error: unable to serialize object>'\n } finally {\n restoreObjectPrototypeToJson()\n restoreArrayPrototypeToJson()\n restoreValuePrototypeToJson()\n restoreValueToJson()\n }\n}\n\nexport function detachToJsonMethod(value) {\n const object = value\n const objectToJson = object.toJSON\n if (objectToJson) {\n delete object.toJSON\n return () => {\n object.toJSON = objectToJson\n }\n }\n return noop\n}\n"],"mappings":";AAAA,SAASA,IAAI,QAAQ,UAAU;;AAE/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAACC,KAAK,EAAEC,QAAQ,EAAEC,KAAK,EAAE;EACpD,IAAIC,OAAA,CAAOH,KAAK,MAAK,QAAQ,IAAIA,KAAK,KAAK,IAAI,EAAE;IAC/C,OAAOI,IAAI,CAACC,SAAS,CAACL,KAAK,CAAC;EAC9B;;EAEA;EACA;EACA,IAAIM,4BAA4B,GAAGC,kBAAkB,CAACC,MAAM,CAACC,SAAS,CAAC;EACvE,IAAIC,2BAA2B,GAAGH,kBAAkB,CAACI,KAAK,CAACF,SAAS,CAAC;EACrE,IAAIG,2BAA2B,GAAGL,kBAAkB,CAClDC,MAAM,CAACK,cAAc,CAACb,KAAK,CAC7B,CAAC;EACD,IAAIc,kBAAkB,GAAGP,kBAAkB,CAACP,KAAK,CAAC;EAElD,IAAI;IACF,OAAOI,IAAI,CAACC,SAAS,CAACL,KAAK,EAAEC,QAAQ,EAAEC,KAAK,CAAC;EAC/C,CAAC,CAAC,OAAAa,OAAA,EAAM;IACN,OAAO,qCAAqC;EAC9C,CAAC,SAAS;IACRT,4BAA4B,CAAC,CAAC;IAC9BI,2BAA2B,CAAC,CAAC;IAC7BE,2BAA2B,CAAC,CAAC;IAC7BE,kBAAkB,CAAC,CAAC;EACtB;AACF;AAEA,OAAO,SAASP,kBAAkBA,CAACP,KAAK,EAAE;EACxC,IAAMgB,MAAM,GAAGhB,KAAK;EACpB,IAAMiB,YAAY,GAAGD,MAAM,CAACE,MAAM;EAClC,IAAID,YAAY,EAAE;IAChB,OAAOD,MAAM,CAACE,MAAM;IACpB,OAAO,YAAM;MACXF,MAAM,CAACE,MAAM,GAAGD,YAAY;IAC9B,CAAC;EACH;EACA,OAAOnB,IAAI;AACb"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
|
2
|
-
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
3
2
|
import { jsonStringify } from './jsonStringify';
|
|
4
3
|
import { isString } from '../tools';
|
|
5
4
|
export function escapeRowData(str) {
|
|
@@ -8,7 +7,6 @@ export function escapeRowData(str) {
|
|
|
8
7
|
} else if (!isString(str)) {
|
|
9
8
|
return str;
|
|
10
9
|
}
|
|
11
|
-
|
|
12
10
|
var reg = /[\s=,"]/g;
|
|
13
11
|
return String(str).replace(reg, function (word) {
|
|
14
12
|
return '\\' + word;
|
|
@@ -32,4 +30,5 @@ export function escapeRowField(value) {
|
|
|
32
30
|
} else {
|
|
33
31
|
return value;
|
|
34
32
|
}
|
|
35
|
-
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=rowData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rowData.js","names":["jsonStringify","isString","escapeRowData","str","_typeof","reg","String","replace","word","escapeJsonValue","value","escapeFieldValueStr","escapeRowField"],"sources":["../../../src/helper/serialisation/rowData.js"],"sourcesContent":["import { jsonStringify } from './jsonStringify'\nimport { isString } from '../tools'\nexport function escapeRowData(str) {\n if (typeof str === 'object' && str) {\n str = jsonStringify(str)\n } else if (!isString(str)) {\n return str\n }\n var reg = /[\\s=,\"]/g\n return String(str).replace(reg, function (word) {\n return '\\\\' + word\n })\n}\n\nexport function escapeJsonValue(value) {\n if (isString(value)) {\n return value\n } else {\n return jsonStringify(value)\n }\n}\n\nexport function escapeFieldValueStr(str) {\n return '\"' + str.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"') + '\"'\n}\nexport function escapeRowField(value) {\n if (typeof value === 'object' && value) {\n return escapeFieldValueStr(jsonStringify(value))\n } else if (isString(value)) {\n return escapeFieldValueStr(value)\n } else {\n return value\n }\n}\n"],"mappings":";AAAA,SAASA,aAAa,QAAQ,iBAAiB;AAC/C,SAASC,QAAQ,QAAQ,UAAU;AACnC,OAAO,SAASC,aAAaA,CAACC,GAAG,EAAE;EACjC,IAAIC,OAAA,CAAOD,GAAG,MAAK,QAAQ,IAAIA,GAAG,EAAE;IAClCA,GAAG,GAAGH,aAAa,CAACG,GAAG,CAAC;EAC1B,CAAC,MAAM,IAAI,CAACF,QAAQ,CAACE,GAAG,CAAC,EAAE;IACzB,OAAOA,GAAG;EACZ;EACA,IAAIE,GAAG,GAAG,UAAU;EACpB,OAAOC,MAAM,CAACH,GAAG,CAAC,CAACI,OAAO,CAACF,GAAG,EAAE,UAAUG,IAAI,EAAE;IAC9C,OAAO,IAAI,GAAGA,IAAI;EACpB,CAAC,CAAC;AACJ;AAEA,OAAO,SAASC,eAAeA,CAACC,KAAK,EAAE;EACrC,IAAIT,QAAQ,CAACS,KAAK,CAAC,EAAE;IACnB,OAAOA,KAAK;EACd,CAAC,MAAM;IACL,OAAOV,aAAa,CAACU,KAAK,CAAC;EAC7B;AACF;AAEA,OAAO,SAASC,mBAAmBA,CAACR,GAAG,EAAE;EACvC,OAAO,GAAG,GAAGA,GAAG,CAACI,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAACA,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,GAAG;AACpE;AACA,OAAO,SAASK,cAAcA,CAACF,KAAK,EAAE;EACpC,IAAIN,OAAA,CAAOM,KAAK,MAAK,QAAQ,IAAIA,KAAK,EAAE;IACtC,OAAOC,mBAAmB,CAACX,aAAa,CAACU,KAAK,CAAC,CAAC;EAClD,CAAC,MAAM,IAAIT,QAAQ,CAACS,KAAK,CAAC,EAAE;IAC1B,OAAOC,mBAAmB,CAACD,KAAK,CAAC;EACnC,CAAC,MAAM;IACL,OAAOA,KAAK;EACd;AACF"}
|
package/esm/helper/timer.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timer.js","names":["getZoneJsOriginalValue","getGlobalObject","monitor","setTimeout","callback","delay","clearTimeout","timeoutId","setInterval","window","clearInterval"],"sources":["../../src/helper/timer.js"],"sourcesContent":["import { getZoneJsOriginalValue } from './getZoneJsOriginalValue'\nimport { getGlobalObject } from '../init'\nimport { monitor } from './monitor'\nexport function setTimeout(callback, delay) {\n return getZoneJsOriginalValue(getGlobalObject(), 'setTimeout')(\n monitor(callback),\n delay\n )\n}\n\nexport function clearTimeout(timeoutId) {\n getZoneJsOriginalValue(getGlobalObject(), 'clearTimeout')(timeoutId)\n}\n\nexport function setInterval(callback, delay) {\n return getZoneJsOriginalValue(window, 'setInterval')(monitor(callback), delay)\n}\n\nexport function clearInterval(timeoutId) {\n getZoneJsOriginalValue(window, 'clearInterval')(timeoutId)\n}\n"],"mappings":"AAAA,SAASA,sBAAsB,QAAQ,0BAA0B;AACjE,SAASC,eAAe,QAAQ,SAAS;AACzC,SAASC,OAAO,QAAQ,WAAW;AACnC,OAAO,SAASC,UAAUA,CAACC,QAAQ,EAAEC,KAAK,EAAE;EAC1C,OAAOL,sBAAsB,CAACC,eAAe,CAAC,CAAC,EAAE,YAAY,CAAC,CAC5DC,OAAO,CAACE,QAAQ,CAAC,EACjBC,KACF,CAAC;AACH;AAEA,OAAO,SAASC,YAAYA,CAACC,SAAS,EAAE;EACtCP,sBAAsB,CAACC,eAAe,CAAC,CAAC,EAAE,cAAc,CAAC,CAACM,SAAS,CAAC;AACtE;AAEA,OAAO,SAASC,WAAWA,CAACJ,QAAQ,EAAEC,KAAK,EAAE;EAC3C,OAAOL,sBAAsB,CAACS,MAAM,EAAE,aAAa,CAAC,CAACP,OAAO,CAACE,QAAQ,CAAC,EAAEC,KAAK,CAAC;AAChF;AAEA,OAAO,SAASK,aAAaA,CAACH,SAAS,EAAE;EACvCP,sBAAsB,CAACS,MAAM,EAAE,eAAe,CAAC,CAACF,SAAS,CAAC;AAC5D"}
|