@utk09/ui-observability 0.12.0 → 1.0.0
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/CHANGELOG.md +420 -0
- package/README.md +72 -839
- package/dist/{batch-BjQUwjA6.js → batch-CXmPmTse.js} +4 -4
- package/dist/{batch-BjQUwjA6.js.map → batch-CXmPmTse.js.map} +1 -1
- package/dist/{batch-D5LlU4Q9.cjs → batch-mmPigCpi.cjs} +2 -2
- package/dist/{batch-D5LlU4Q9.cjs.map → batch-mmPigCpi.cjs.map} +1 -1
- package/dist/bus/bus.d.cts +331 -0
- package/dist/bus/bus.d.ts +60 -10
- package/dist/bus/links.d.cts +132 -0
- package/dist/bus/links.d.ts +18 -3
- package/dist/bus/validation.d.cts +16 -0
- package/dist/bus/validation.d.ts +10 -1
- package/dist/{bus-ecxUNTja.js → bus-C39wspFV.js} +308 -193
- package/dist/bus-C39wspFV.js.map +1 -0
- package/dist/bus-_EaOVPGq.cjs +2 -0
- package/dist/bus-_EaOVPGq.cjs.map +1 -0
- package/dist/capture/console.d.cts +37 -0
- package/dist/capture/console.d.ts +1 -1
- package/dist/capture/errors.d.cts +32 -0
- package/dist/capture/errors.d.ts +1 -1
- package/dist/capture/interactions.d.cts +48 -0
- package/dist/capture/interactions.d.ts +1 -1
- package/dist/capture/lifecycle.d.cts +20 -0
- package/dist/capture/lifecycle.d.ts +1 -1
- package/dist/capture/long-frames.d.cts +31 -0
- package/dist/capture/long-frames.d.ts +1 -1
- package/dist/capture/network.d.cts +57 -0
- package/dist/capture/network.d.ts +1 -1
- package/dist/capture/profiler-frames.d.cts +44 -0
- package/dist/capture/profiler-frames.d.ts +1 -1
- package/dist/capture/replay-buffer.d.cts +45 -0
- package/dist/capture/replay-buffer.d.ts +9 -10
- package/dist/capture/replay-upload.d.cts +79 -0
- package/dist/capture/replay-upload.d.ts +7 -2
- package/dist/capture/replay.d.cts +114 -0
- package/dist/capture/replay.d.ts +1 -1
- package/dist/capture/reports.d.cts +17 -0
- package/dist/capture/reports.d.ts +1 -1
- package/dist/capture/resource-timing.d.cts +14 -0
- package/dist/capture/resource-timing.d.ts +1 -1
- package/dist/capture/server-timing.d.cts +19 -0
- package/dist/capture/storm.d.cts +13 -0
- package/dist/capture/storm.d.ts +5 -5
- package/dist/capture/types.d.cts +128 -0
- package/dist/capture/types.d.ts +10 -9
- package/dist/capture/unclean-exit.d.cts +31 -0
- package/dist/capture/unclean-exit.d.ts +1 -1
- package/dist/capture/user-timing.d.cts +22 -0
- package/dist/capture/user-timing.d.ts +2 -2
- package/dist/capture/web-socket.d.cts +40 -0
- package/dist/capture/web-socket.d.ts +3 -3
- package/dist/capture/web-vitals.d.cts +40 -0
- package/dist/capture/web-vitals.d.ts +1 -1
- package/dist/{compression-lD9abCcO.cjs → compression-CvED_Jel.cjs} +2 -2
- package/dist/{compression-lD9abCcO.cjs.map → compression-CvED_Jel.cjs.map} +1 -1
- package/dist/{compression-AJJCMBOa.js → compression-tVtXwVjX.js} +2 -2
- package/dist/{compression-AJJCMBOa.js.map → compression-tVtXwVjX.js.map} +1 -1
- package/dist/config-DUs7uHHt.cjs +2 -0
- package/dist/config-DUs7uHHt.cjs.map +1 -0
- package/dist/config-SgQcCP1_.js +560 -0
- package/dist/config-SgQcCP1_.js.map +1 -0
- package/dist/console-BGgGnjSi.js +81 -0
- package/dist/console-BGgGnjSi.js.map +1 -0
- package/dist/console-CSZ5_Vx5.cjs +2 -0
- package/dist/console-CSZ5_Vx5.cjs.map +1 -0
- package/dist/constants-CUyd9cTZ.js +357 -0
- package/dist/constants-CUyd9cTZ.js.map +1 -0
- package/dist/constants-CqdJhTxH.cjs +2 -0
- package/dist/constants-CqdJhTxH.cjs.map +1 -0
- package/dist/constants.d.cts +751 -0
- package/dist/constants.d.ts +88 -20
- package/dist/core/breadcrumbs.d.cts +54 -0
- package/dist/core/breadcrumbs.d.ts +5 -0
- package/dist/core/config.d.cts +45 -0
- package/dist/core/config.d.ts +30 -2
- package/dist/core/context.d.cts +24 -0
- package/dist/core/context.d.ts +3 -8
- package/dist/core/debug-buffer.d.cts +34 -0
- package/dist/core/debug-buffer.d.ts +3 -3
- package/dist/core/debug-bundle.d.cts +12 -0
- package/dist/core/debug-bundle.d.ts +3 -3
- package/dist/core/deferred.d.cts +7 -0
- package/dist/core/deferred.d.ts +2 -2
- package/dist/core/diagnostics.d.cts +86 -0
- package/dist/core/diagnostics.d.ts +1 -1
- package/dist/core/drops.d.cts +39 -0
- package/dist/core/drops.d.ts +16 -6
- package/dist/core/hold-buffer.d.cts +36 -0
- package/dist/core/hold-buffer.d.ts +16 -7
- package/dist/core/journey.d.cts +148 -0
- package/dist/core/journey.d.ts +7 -7
- package/dist/core/logger.d.cts +141 -0
- package/dist/core/logger.d.ts +23 -30
- package/dist/core/measure.d.cts +30 -0
- package/dist/core/measure.d.ts +14 -3
- package/dist/core/meter.d.cts +78 -0
- package/dist/core/meter.d.ts +14 -8
- package/dist/core/pipeline.d.cts +227 -0
- package/dist/core/pipeline.d.ts +73 -10
- package/dist/core/profile-buckets.d.cts +31 -0
- package/dist/core/profiler.d.cts +218 -0
- package/dist/core/profiler.d.ts +2 -2
- package/dist/core/record.d.cts +190 -0
- package/dist/core/record.d.ts +44 -12
- package/dist/core/remote-rules.d.cts +17 -0
- package/dist/core/remote-rules.d.ts +3 -3
- package/dist/core/remote-sampling.d.cts +74 -0
- package/dist/core/remote-sampling.d.ts +3 -3
- package/dist/core/rotation.d.cts +75 -0
- package/dist/core/rotation.d.ts +75 -0
- package/dist/core/runtime.d.cts +765 -0
- package/dist/core/runtime.d.ts +245 -70
- package/dist/core/sampling.d.cts +86 -0
- package/dist/core/sampling.d.ts +5 -5
- package/dist/core/sender.d.cts +161 -0
- package/dist/core/sender.d.ts +59 -15
- package/dist/core/spans.d.cts +39 -0
- package/dist/core/spans.d.ts +1 -1
- package/dist/debug-bundle-BXIlwDKM.cjs +2 -0
- package/dist/debug-bundle-BXIlwDKM.cjs.map +1 -0
- package/dist/debug-bundle-CRpYV_ui.js +35 -0
- package/dist/debug-bundle-CRpYV_ui.js.map +1 -0
- package/dist/defineProperty-X1c4tIPD.cjs +1 -0
- package/dist/defineProperty-s2S8BXUc.js +35 -0
- package/dist/doctor.cjs +1 -1
- package/dist/doctor.cjs.map +1 -1
- package/dist/doctor.d.cts +36 -0
- package/dist/doctor.d.ts +5 -2
- package/dist/doctor.js +121 -89
- package/dist/doctor.js.map +1 -1
- package/dist/errors-BE_EZV7Q.js +86 -0
- package/dist/errors-BE_EZV7Q.js.map +1 -0
- package/dist/errors-CNPbesMs.cjs +3 -0
- package/dist/errors-CNPbesMs.cjs.map +1 -0
- package/dist/factory-CTi0Is3F.js +404 -0
- package/dist/factory-CTi0Is3F.js.map +1 -0
- package/dist/factory-hRrH32v5.cjs +2 -0
- package/dist/factory-hRrH32v5.cjs.map +1 -0
- package/dist/guards-BlYGRK4l.js +10 -0
- package/dist/guards-BlYGRK4l.js.map +1 -0
- package/dist/guards-EjG3ahFp.cjs +2 -0
- package/dist/guards-EjG3ahFp.cjs.map +1 -0
- package/dist/{identity-BrQp_5J5.js → identity-DdhKgrpk.js} +20 -24
- package/dist/identity-DdhKgrpk.js.map +1 -0
- package/dist/identity-DlWRIuwy.cjs +2 -0
- package/dist/identity-DlWRIuwy.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +300 -0
- package/dist/index.d.ts +89 -98
- package/dist/index.js +1173 -1506
- package/dist/index.js.map +1 -1
- package/dist/indexeddb-storage-CL9uqBCy.cjs +2 -0
- package/dist/indexeddb-storage-CL9uqBCy.cjs.map +1 -0
- package/dist/{indexeddb-storage-DLXQzAGh.js → indexeddb-storage-GHdl0t8A.js} +51 -47
- package/dist/indexeddb-storage-GHdl0t8A.js.map +1 -0
- package/dist/interactions-CUkzK8sR.cjs +2 -0
- package/dist/interactions-CUkzK8sR.cjs.map +1 -0
- package/dist/{interactions-B6z2I4tU.js → interactions-DiFvCosX.js} +41 -49
- package/dist/interactions-DiFvCosX.js.map +1 -0
- package/dist/journey-B4Adltjm.cjs +2 -0
- package/dist/journey-B4Adltjm.cjs.map +1 -0
- package/dist/{journey-35yCMNFo.js → journey-D2_sia57.js} +45 -48
- package/dist/journey-D2_sia57.js.map +1 -0
- package/dist/{library-console-Dl_Ly6DQ.js → library-console-Btrzt814.js} +2 -2
- package/dist/{library-console-Dl_Ly6DQ.js.map → library-console-Btrzt814.js.map} +1 -1
- package/dist/{library-console-BFWEuQsl.cjs → library-console-CPW6bvZH.cjs} +2 -2
- package/dist/{library-console-BFWEuQsl.cjs.map → library-console-CPW6bvZH.cjs.map} +1 -1
- package/dist/{library-request-nI6pvI6I.js → library-request-BJ9PLRaD.js} +2 -2
- package/dist/{library-request-nI6pvI6I.js.map → library-request-BJ9PLRaD.js.map} +1 -1
- package/dist/{library-request-Da-CHKzT.cjs → library-request-D7OvTxZV.cjs} +2 -2
- package/dist/{library-request-Da-CHKzT.cjs.map → library-request-D7OvTxZV.cjs.map} +1 -1
- package/dist/{lifecycle-CZ6RRXc6.js → lifecycle-22CUCrc9.js} +21 -29
- package/dist/lifecycle-22CUCrc9.js.map +1 -0
- package/dist/lifecycle-IaAm1mOC.cjs +2 -0
- package/dist/lifecycle-IaAm1mOC.cjs.map +1 -0
- package/dist/{log-record-DIA6McNr.js → log-record-BNiLfqtL.js} +8 -7
- package/dist/log-record-BNiLfqtL.js.map +1 -0
- package/dist/log-record-CkivuiEl.cjs +2 -0
- package/dist/log-record-CkivuiEl.cjs.map +1 -0
- package/dist/long-frames-BUUbXd-B.cjs +2 -0
- package/dist/long-frames-BUUbXd-B.cjs.map +1 -0
- package/dist/{long-frames-430_85Da.js → long-frames-DNFaRnC3.js} +18 -22
- package/dist/long-frames-DNFaRnC3.js.map +1 -0
- package/dist/models/batch.d.cts +57 -0
- package/dist/models/batch.d.ts +2 -2
- package/dist/models/bus.d.cts +158 -0
- package/dist/models/bus.d.ts +22 -2
- package/dist/models/config.d.cts +1540 -0
- package/dist/models/config.d.ts +360 -259
- package/dist/models/drop.d.cts +54 -0
- package/dist/models/drop.d.ts +16 -3
- package/dist/models/health.d.cts +148 -0
- package/dist/models/health.d.ts +108 -12
- package/dist/models/log-record.d.cts +61 -0
- package/dist/models/metric.d.cts +139 -0
- package/dist/models/metric.d.ts +13 -2
- package/dist/models/plugin.d.cts +47 -0
- package/dist/models/plugin.d.ts +3 -3
- package/dist/models/replay.d.cts +60 -0
- package/dist/models/serializer.d.cts +23 -0
- package/dist/models/serializer.d.ts +1 -1
- package/dist/models/storage.d.cts +95 -0
- package/dist/models/storage.d.ts +7 -5
- package/dist/network-CGMLQ-mA.cjs +2 -0
- package/dist/network-CGMLQ-mA.cjs.map +1 -0
- package/dist/{network-C7SkLf4v.js → network-on2zZT6H.js} +51 -51
- package/dist/network-on2zZT6H.js.map +1 -0
- package/dist/{otlp-2MCrC3kd.cjs → otlp-BENHf3g9.cjs} +2 -2
- package/dist/{otlp-2MCrC3kd.cjs.map → otlp-BENHf3g9.cjs.map} +1 -1
- package/dist/{otlp-COq033e3.js → otlp-DimfrRor.js} +12 -12
- package/dist/{otlp-COq033e3.js.map → otlp-DimfrRor.js.map} +1 -1
- package/dist/{platform-CVewe4wQ.js → platform-BaaFIPCU.js} +10 -10
- package/dist/{platform-CVewe4wQ.js.map → platform-BaaFIPCU.js.map} +1 -1
- package/dist/{platform-12uR7kBQ.cjs → platform-CfA3-7sJ.cjs} +2 -2
- package/dist/{platform-12uR7kBQ.cjs.map → platform-CfA3-7sJ.cjs.map} +1 -1
- package/dist/{profiler-BVWIOgnq.js → profiler-BAZoh7A4.js} +89 -107
- package/dist/profiler-BAZoh7A4.js.map +1 -0
- package/dist/profiler-D4tJpDRc.cjs +2 -0
- package/dist/profiler-D4tJpDRc.cjs.map +1 -0
- package/dist/profiler-frames-C4xr7KfH.cjs +2 -0
- package/dist/profiler-frames-C4xr7KfH.cjs.map +1 -0
- package/dist/{profiler-frames-CLXlT_xL.js → profiler-frames-cJMx9wNM.js} +29 -37
- package/dist/profiler-frames-cJMx9wNM.js.map +1 -0
- package/dist/remote-rules-Dz9MRAsB.js +95 -0
- package/dist/remote-rules-Dz9MRAsB.js.map +1 -0
- package/dist/remote-rules-_tY0zj5o.cjs +2 -0
- package/dist/remote-rules-_tY0zj5o.cjs.map +1 -0
- package/dist/replay-B3gFXIZd.cjs +2 -0
- package/dist/replay-B3gFXIZd.cjs.map +1 -0
- package/dist/replay-Ds-ANH34.js +310 -0
- package/dist/replay-Ds-ANH34.js.map +1 -0
- package/dist/reports-BDSe4dFH.cjs +2 -0
- package/dist/reports-BDSe4dFH.cjs.map +1 -0
- package/dist/{reports-BuXekPOS.js → reports-C-thq-bk.js} +25 -30
- package/dist/reports-C-thq-bk.js.map +1 -0
- package/dist/resource-timing-C576gFIQ.cjs +2 -0
- package/dist/resource-timing-C576gFIQ.cjs.map +1 -0
- package/dist/{resource-timing-CXGHwFRD.js → resource-timing-eUl2dNgC.js} +20 -23
- package/dist/resource-timing-eUl2dNgC.js.map +1 -0
- package/dist/response-body-YdNl-HkR.cjs +3 -0
- package/dist/response-body-YdNl-HkR.cjs.map +1 -0
- package/dist/response-body-eoSQpLiH.js +331 -0
- package/dist/response-body-eoSQpLiH.js.map +1 -0
- package/dist/rotation-Cwct4ckk.js +94 -0
- package/dist/rotation-Cwct4ckk.js.map +1 -0
- package/dist/rotation-D4qUAHAu.cjs +2 -0
- package/dist/rotation-D4qUAHAu.cjs.map +1 -0
- package/dist/sampling-BlrI8jor.js +63 -0
- package/dist/sampling-BlrI8jor.js.map +1 -0
- package/dist/sampling-mXt4dstx.cjs +2 -0
- package/dist/sampling-mXt4dstx.cjs.map +1 -0
- package/dist/{sanitize-CNmsD9r3.js → sanitize-Ba0KqU06.js} +2 -2
- package/dist/sanitize-Ba0KqU06.js.map +1 -0
- package/dist/{sanitize-ChLn97Ch.cjs → sanitize-DQyiI_KY.cjs} +2 -2
- package/dist/sanitize-DQyiI_KY.cjs.map +1 -0
- package/dist/sender-BdRuNVhF.cjs +2 -0
- package/dist/sender-BdRuNVhF.cjs.map +1 -0
- package/dist/sender-Dv8rAmpV.js +979 -0
- package/dist/sender-Dv8rAmpV.js.map +1 -0
- package/dist/storage/context-storage.d.cts +90 -0
- package/dist/storage/context-storage.d.ts +5 -5
- package/dist/storage/emergency-queue.d.cts +27 -0
- package/dist/storage/emergency-queue.d.ts +4 -4
- package/dist/storage/eviction.d.cts +40 -0
- package/dist/storage/eviction.d.ts +1 -1
- package/dist/storage/factory.d.cts +21 -0
- package/dist/storage/factory.d.ts +3 -3
- package/dist/storage/gap.d.cts +20 -0
- package/dist/storage/gap.d.ts +3 -3
- package/dist/storage/idb-driver.d.cts +93 -0
- package/dist/storage/idb-driver.d.ts +1 -1
- package/dist/storage/indexeddb-storage.d.cts +97 -0
- package/dist/storage/indexeddb-storage.d.ts +12 -4
- package/dist/storage/keys.d.cts +17 -0
- package/dist/storage/keys.d.ts +2 -2
- package/dist/storage/local-storage.d.cts +139 -0
- package/dist/storage/local-storage.d.ts +11 -4
- package/dist/storage/memory-storage.d.cts +73 -0
- package/dist/storage/memory-storage.d.ts +4 -3
- package/dist/storage/persistence.d.cts +8 -0
- package/dist/storage/persistence.d.ts +2 -2
- package/dist/storage/stored-context.d.cts +34 -0
- package/dist/storage/stored-context.d.ts +34 -0
- package/dist/stored-context-B2EzVuYm.js +51 -0
- package/dist/stored-context-B2EzVuYm.js.map +1 -0
- package/dist/stored-context-CXt7eHZL.cjs +2 -0
- package/dist/stored-context-CXt7eHZL.cjs.map +1 -0
- package/dist/storm-C-zYSdDX.cjs +2 -0
- package/dist/storm-C-zYSdDX.cjs.map +1 -0
- package/dist/storm-DjKetLKZ.js +9 -0
- package/dist/storm-DjKetLKZ.js.map +1 -0
- package/dist/transport/compression.d.cts +7 -0
- package/dist/transport/custom-transport.d.cts +22 -0
- package/dist/transport/custom-transport.d.ts +6 -5
- package/dist/transport/errors.d.cts +31 -0
- package/dist/transport/exit-flush.d.cts +135 -0
- package/dist/transport/exit-flush.d.ts +30 -13
- package/dist/transport/headers.d.cts +8 -0
- package/dist/transport/headers.d.ts +2 -2
- package/dist/transport/http-transport.d.cts +116 -0
- package/dist/transport/http-transport.d.ts +20 -8
- package/dist/transport/memory-transport.d.cts +30 -0
- package/dist/transport/memory-transport.d.ts +2 -2
- package/dist/transport/response-body.d.cts +49 -0
- package/dist/transport/response-body.d.ts +49 -0
- package/dist/transport/retry-engine.d.cts +129 -0
- package/dist/transport/retry-engine.d.ts +27 -9
- package/dist/transport/serializers/ecs.d.cts +3 -0
- package/dist/transport/serializers/ecs.d.ts +1 -1
- package/dist/transport/serializers/otlp-metrics.d.cts +3 -0
- package/dist/transport/serializers/otlp-metrics.d.ts +1 -1
- package/dist/transport/serializers/otlp-traces.d.cts +3 -0
- package/dist/transport/serializers/otlp-traces.d.ts +1 -1
- package/dist/transport/serializers/otlp.d.cts +47 -0
- package/dist/transport/serializers/otlp.d.ts +2 -2
- package/dist/transport/serializers/select.d.cts +38 -0
- package/dist/transport/serializers/select.d.ts +5 -5
- package/dist/transport/status-transport.d.cts +129 -0
- package/dist/transport/status-transport.d.ts +25 -8
- package/dist/transport/worker-client.d.cts +23 -0
- package/dist/transport/worker-client.d.ts +12 -3
- package/dist/transport/worker-entry.d.cts +5 -0
- package/dist/transport/worker-entry.d.ts +1 -1
- package/dist/transport/worker-protocol.d.cts +38 -0
- package/dist/transport/worker-protocol.d.ts +4 -2
- package/dist/transport/worker-server.d.cts +3 -0
- package/dist/transport/worker-server.d.ts +1 -1
- package/dist/transport/worker-transport.d.cts +10 -0
- package/dist/transport/worker-transport.d.ts +5 -4
- package/dist/types-BAerHgCq.js.map +1 -1
- package/dist/types-C7WNpnG1.cjs.map +1 -1
- package/dist/{unclean-exit-Cob_jyTv.js → unclean-exit-DQD1cT7c.js} +23 -30
- package/dist/unclean-exit-DQD1cT7c.js.map +1 -0
- package/dist/unclean-exit-py99ApzT.cjs +2 -0
- package/dist/unclean-exit-py99ApzT.cjs.map +1 -0
- package/dist/{user-timing-DgHubxCI.js → user-timing-BePqb1uN.js} +15 -17
- package/dist/user-timing-BePqb1uN.js.map +1 -0
- package/dist/user-timing-D6XTmpuM.cjs +2 -0
- package/dist/user-timing-D6XTmpuM.cjs.map +1 -0
- package/dist/utils/console.d.cts +36 -0
- package/dist/utils/console.d.ts +4 -4
- package/dist/utils/deadline.d.cts +14 -0
- package/dist/utils/error-like.d.cts +25 -0
- package/dist/utils/fixed-window.d.cts +25 -0
- package/dist/utils/global-scope.d.cts +20 -0
- package/dist/utils/guards.d.cts +14 -0
- package/dist/utils/guards.d.ts +8 -0
- package/dist/utils/identity.d.cts +109 -0
- package/dist/utils/identity.d.ts +3 -4
- package/dist/utils/library-console.d.cts +11 -0
- package/dist/utils/library-request.d.cts +24 -0
- package/dist/utils/lock.d.cts +24 -0
- package/dist/utils/lock.d.ts +1 -1
- package/dist/utils/openfin.d.cts +48 -0
- package/dist/utils/patch.d.cts +9 -0
- package/dist/utils/platform.d.cts +62 -0
- package/dist/utils/platform.d.ts +2 -2
- package/dist/utils/sanitize.d.cts +52 -0
- package/dist/utils/sanitize.d.ts +1 -1
- package/dist/utils/sequence.d.cts +10 -0
- package/dist/utils/tracing.d.cts +158 -0
- package/dist/utils/tracing.d.ts +11 -4
- package/dist/utils/unref.d.cts +9 -0
- package/dist/web-socket-CoIUBM3C.cjs +2 -0
- package/dist/{web-socket-DthJuSAg.js.map → web-socket-CoIUBM3C.cjs.map} +1 -1
- package/dist/{web-socket-DthJuSAg.js → web-socket-DSHgDiZ6.js} +23 -28
- package/dist/web-socket-DSHgDiZ6.js.map +1 -0
- package/dist/{web-vitals-CsGCWnUr.js → web-vitals-4pWACwaR.js} +15 -21
- package/dist/web-vitals-4pWACwaR.js.map +1 -0
- package/dist/web-vitals-__X7t4pj.cjs +2 -0
- package/dist/web-vitals-__X7t4pj.cjs.map +1 -0
- package/dist/worker-protocol-QbvqNazn.cjs +2 -0
- package/dist/worker-protocol-QbvqNazn.cjs.map +1 -0
- package/dist/{worker-protocol-B0_8rWy5.js → worker-protocol-x074Rpet.js} +14 -11
- package/dist/worker-protocol-x074Rpet.js.map +1 -0
- package/dist/worker-server-CFe4nvos.cjs +2 -0
- package/dist/worker-server-CFe4nvos.cjs.map +1 -0
- package/dist/worker-server-iUVSjH8L.js +94 -0
- package/dist/worker-server-iUVSjH8L.js.map +1 -0
- package/dist/worker-transport-CRAX-09c.cjs +2 -0
- package/dist/worker-transport-CRAX-09c.cjs.map +1 -0
- package/dist/worker-transport-Dy1KMA7t.js +190 -0
- package/dist/worker-transport-Dy1KMA7t.js.map +1 -0
- package/llms.txt +397 -0
- package/package.json +54 -46
- package/dist/bus-D_7pd7RN.cjs +0 -2
- package/dist/bus-D_7pd7RN.cjs.map +0 -1
- package/dist/bus-ecxUNTja.js.map +0 -1
- package/dist/console-CLz_PvFn.cjs +0 -2
- package/dist/console-CLz_PvFn.cjs.map +0 -1
- package/dist/console-cwgHKXvM.js +0 -82
- package/dist/console-cwgHKXvM.js.map +0 -1
- package/dist/constants-Bwl_YtQi.js +0 -349
- package/dist/constants-Bwl_YtQi.js.map +0 -1
- package/dist/constants-DakMxVB2.cjs +0 -2
- package/dist/constants-DakMxVB2.cjs.map +0 -1
- package/dist/context-storage-BjzeBSxH.cjs +0 -2
- package/dist/context-storage-BjzeBSxH.cjs.map +0 -1
- package/dist/context-storage-BzkoHzkQ.js +0 -51
- package/dist/context-storage-BzkoHzkQ.js.map +0 -1
- package/dist/debug-bundle-BOdYmCeV.js +0 -32
- package/dist/debug-bundle-BOdYmCeV.js.map +0 -1
- package/dist/debug-bundle-Ex4L_LSP.cjs +0 -2
- package/dist/debug-bundle-Ex4L_LSP.cjs.map +0 -1
- package/dist/emergency-queue-B9WZxanZ.js +0 -67
- package/dist/emergency-queue-B9WZxanZ.js.map +0 -1
- package/dist/emergency-queue-HBpL5r3V.cjs +0 -2
- package/dist/emergency-queue-HBpL5r3V.cjs.map +0 -1
- package/dist/errors-D6bwgJtO.js +0 -92
- package/dist/errors-D6bwgJtO.js.map +0 -1
- package/dist/errors-DCOCRdSi.cjs +0 -3
- package/dist/errors-DCOCRdSi.cjs.map +0 -1
- package/dist/factory-DLFDjdLv.cjs +0 -2
- package/dist/factory-DLFDjdLv.cjs.map +0 -1
- package/dist/factory-e9Qo3K0z.js +0 -276
- package/dist/factory-e9Qo3K0z.js.map +0 -1
- package/dist/guards-Cidk71ME.js +0 -7
- package/dist/guards-Cidk71ME.js.map +0 -1
- package/dist/guards-nJ70syPt.cjs +0 -2
- package/dist/guards-nJ70syPt.cjs.map +0 -1
- package/dist/identity-BlvlgjrU.cjs +0 -2
- package/dist/identity-BlvlgjrU.cjs.map +0 -1
- package/dist/identity-BrQp_5J5.js.map +0 -1
- package/dist/indexeddb-storage-CtLvZH1r.cjs +0 -2
- package/dist/indexeddb-storage-CtLvZH1r.cjs.map +0 -1
- package/dist/indexeddb-storage-DLXQzAGh.js.map +0 -1
- package/dist/interactions-B6z2I4tU.js.map +0 -1
- package/dist/interactions-P6pz08Jn.cjs +0 -2
- package/dist/interactions-P6pz08Jn.cjs.map +0 -1
- package/dist/journey-35yCMNFo.js.map +0 -1
- package/dist/journey-DAGh5h9k.cjs +0 -2
- package/dist/journey-DAGh5h9k.cjs.map +0 -1
- package/dist/keys-BHhw_0Wh.cjs +0 -2
- package/dist/keys-BHhw_0Wh.cjs.map +0 -1
- package/dist/keys-BU9j5YqW.js +0 -16
- package/dist/keys-BU9j5YqW.js.map +0 -1
- package/dist/lifecycle-BGGOcN4N.cjs +0 -2
- package/dist/lifecycle-BGGOcN4N.cjs.map +0 -1
- package/dist/lifecycle-CZ6RRXc6.js.map +0 -1
- package/dist/log-record-D7bA1RPb.cjs +0 -2
- package/dist/log-record-D7bA1RPb.cjs.map +0 -1
- package/dist/log-record-DIA6McNr.js.map +0 -1
- package/dist/long-frames-430_85Da.js.map +0 -1
- package/dist/long-frames-Dd8tsi2U.cjs +0 -2
- package/dist/long-frames-Dd8tsi2U.cjs.map +0 -1
- package/dist/models/stats.d.ts +0 -11
- package/dist/network-C7SkLf4v.js.map +0 -1
- package/dist/network-pEX3PAJv.cjs +0 -2
- package/dist/network-pEX3PAJv.cjs.map +0 -1
- package/dist/profiler-BVWIOgnq.js.map +0 -1
- package/dist/profiler-eVCknCzS.cjs +0 -2
- package/dist/profiler-eVCknCzS.cjs.map +0 -1
- package/dist/profiler-frames-CLXlT_xL.js.map +0 -1
- package/dist/profiler-frames-Dg2OebB2.cjs +0 -2
- package/dist/profiler-frames-Dg2OebB2.cjs.map +0 -1
- package/dist/remote-rules-BJGDJGwA.js +0 -98
- package/dist/remote-rules-BJGDJGwA.js.map +0 -1
- package/dist/remote-rules-CJD3ToVk.cjs +0 -2
- package/dist/remote-rules-CJD3ToVk.cjs.map +0 -1
- package/dist/replay-0zAJv9T3.js +0 -338
- package/dist/replay-0zAJv9T3.js.map +0 -1
- package/dist/replay-DomJpXqW.cjs +0 -2
- package/dist/replay-DomJpXqW.cjs.map +0 -1
- package/dist/reports-BsbqmP8h.cjs +0 -2
- package/dist/reports-BsbqmP8h.cjs.map +0 -1
- package/dist/reports-BuXekPOS.js.map +0 -1
- package/dist/resource-timing-CXGHwFRD.js.map +0 -1
- package/dist/resource-timing-DkycFGDa.cjs +0 -2
- package/dist/resource-timing-DkycFGDa.cjs.map +0 -1
- package/dist/sampling-Dd0wllyq.cjs +0 -2
- package/dist/sampling-Dd0wllyq.cjs.map +0 -1
- package/dist/sampling-UUDbi3K0.js +0 -60
- package/dist/sampling-UUDbi3K0.js.map +0 -1
- package/dist/sanitize-CNmsD9r3.js.map +0 -1
- package/dist/sanitize-ChLn97Ch.cjs.map +0 -1
- package/dist/select-CTk-K5mG.cjs +0 -3
- package/dist/select-CTk-K5mG.cjs.map +0 -1
- package/dist/select-DPv_j6wq.js +0 -270
- package/dist/select-DPv_j6wq.js.map +0 -1
- package/dist/sender-15zEsZpr.js +0 -857
- package/dist/sender-15zEsZpr.js.map +0 -1
- package/dist/sender-Bfpv9tad.cjs +0 -2
- package/dist/sender-Bfpv9tad.cjs.map +0 -1
- package/dist/storage-BA9RqRO-.cjs +0 -2
- package/dist/storage-BA9RqRO-.cjs.map +0 -1
- package/dist/storage-DZwed89z.js +0 -16
- package/dist/storage-DZwed89z.js.map +0 -1
- package/dist/storm-BTSNTIWI.js +0 -9
- package/dist/storm-BTSNTIWI.js.map +0 -1
- package/dist/storm-D0_qZOEg.cjs +0 -2
- package/dist/storm-D0_qZOEg.cjs.map +0 -1
- package/dist/unclean-exit-ClGzrc2A.cjs +0 -2
- package/dist/unclean-exit-ClGzrc2A.cjs.map +0 -1
- package/dist/unclean-exit-Cob_jyTv.js.map +0 -1
- package/dist/user-timing-CdYqx3PF.cjs +0 -2
- package/dist/user-timing-CdYqx3PF.cjs.map +0 -1
- package/dist/user-timing-DgHubxCI.js.map +0 -1
- package/dist/utils/timer.d.ts +0 -19
- package/dist/web-socket-BTuvYoJI.cjs +0 -2
- package/dist/web-socket-BTuvYoJI.cjs.map +0 -1
- package/dist/web-vitals-Ch5BpDmo.cjs +0 -2
- package/dist/web-vitals-Ch5BpDmo.cjs.map +0 -1
- package/dist/web-vitals-CsGCWnUr.js.map +0 -1
- package/dist/worker-protocol-B0_8rWy5.js.map +0 -1
- package/dist/worker-protocol-BjzFORfq.cjs +0 -2
- package/dist/worker-protocol-BjzFORfq.cjs.map +0 -1
- package/dist/worker-server-4en-Lt-3.cjs +0 -2
- package/dist/worker-server-4en-Lt-3.cjs.map +0 -1
- package/dist/worker-server-Cne9MX9I.js +0 -83
- package/dist/worker-server-Cne9MX9I.js.map +0 -1
- package/dist/worker-transport-B-GF4Aqn.cjs +0 -2
- package/dist/worker-transport-B-GF4Aqn.cjs.map +0 -1
- package/dist/worker-transport-C3SjJAEC.js +0 -200
- package/dist/worker-transport-C3SjJAEC.js.map +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./constants-CqdJhTxH.cjs"),t=require("./batch-mmPigCpi.cjs"),n=require("./factory-hRrH32v5.cjs"),r=require("./defineProperty-X1c4tIPD.cjs");function i(e){return e.error??Error(`The IndexedDB request failed.`)}function a(e){return new Promise((t,n)=>{e.onsuccess=()=>{t(e.result)},e.onerror=()=>{n(i(e))}})}var o=class{constructor(e){r.t(this,`name`,void 0),r.t(this,`connection`,null),this.name=e}async put(e){await a((await this.store(`readwrite`)).put(e))}async takeContext(e,t){let n=await this.store(`readonly`),r=IDBKeyRange.bound([e,0],[e,2**53-1]);return a(n.index(`routingContext`).getAll(r,t))}async countContext(e){return a((await this.store(`readonly`)).index(`routingContext`).count(IDBKeyRange.bound([e,0],[e,2**53-1])))}async takeOldest(t){return a((await this.store(`readonly`)).index(e.yt).getAll(null,t))}async walkOldest(t){let n=(await this.store(`readonly`)).index(e.yt).openCursor();await new Promise((e,r)=>{n.onsuccess=()=>{let r=n.result;r===null||!t(r.value)?e():r.continue()},n.onerror=()=>{r(i(n))}})}async takeBefore(t){let n=await this.store(`readonly`),r=IDBKeyRange.upperBound(t,!0);return a(n.index(e.yt).getAll(r))}async delete(e){await a((await this.store(`readwrite`)).delete(e))}async deleteMany(e){let t=await this.store(`readwrite`);await Promise.all(e.map(e=>a(t.delete(e))))}async bumpAttempts(e,t){let n=await this.store(`readwrite`),r=await a(n.get(e));r!==void 0&&await a(n.put({...r,attempts:t}))}async count(){return a((await this.store(`readonly`)).count())}async clear(){await a((await this.store(`readwrite`)).clear())}async ready(){await this.open()}async close(){let e=this.connection;e!==null&&(this.connection=null,(await e).close())}async store(t){return(await this.open()).transaction(e.bt,t).objectStore(e.bt)}open(){let t=this.connection;if(t!==null)return t;let n=new Promise((t,n)=>{let r=indexedDB.open(this.name,12),a=!1;r.onupgradeneeded=()=>{let t=r.result;t.objectStoreNames.contains(`batches`)||t.createObjectStore(e.bt,{keyPath:`id`}).createIndex(e.yt,e.yt);let n=r.transaction.objectStore(e.bt);n.indexNames.contains(`routingContext`)||n.createIndex(`routingContext`,[`routingContextId`,`createdAt`])},r.onsuccess=()=>{let e=r.result;a?e.close():(e.onversionchange=()=>{e.close(),this.connection=null},t(e))},r.onerror=()=>{n(i(r))},r.onblocked=()=>{a=!0,n(Error(`Another connection blocks the IndexedDB upgrade.`))}});return this.connection=n.catch(e=>{throw this.connection=null,e}),this.connection}},s=class{constructor(t,n,i,a){r.t(this,`limits`,void 0),r.t(this,`diagnostics`,void 0),r.t(this,`onGap`,void 0),r.t(this,`name`,e.Kn),r.t(this,`db`,void 0),this.limits=n,this.diagnostics=i,this.onGap=a,this.db=new o(t)}async open(){await this.db.ready()}async save(e){try{await this.db.put(e);let{removed:t}=await this.sweep();return!t.some(t=>t.id===e.id)}catch(r){if(r instanceof Error&&r.name===`QuotaExceededError`){this.diagnostics.report(`storage.quota_exceeded`,`IndexedDB is full. The library removes the oldest batches.`);let r=await this.diagnostics.guardAsync(`storage.degraded`,`The library could not remove old batches after a full disk.`,()=>this.evictOldest(Math.ceil(this.limits.maxBatches/4)));if(r){let e=t.n(r),i={batches:r.length,records:e,reason:`quota`};n.i(this.diagnostics,this.onGap,i,r)}let i=await this.diagnostics.guardAsync(`storage.degraded`,`The library could not write the batch after it removed old batches.`,async()=>(await this.db.put(e),!0));if(i!==!0){let t={batches:1,records:e.records.length,reason:`quota`};n.i(this.diagnostics,this.onGap,t,[e])}return i===!0}return this.diagnostics.report(`storage.degraded`,`The library could not store a batch.`,{batchId:e.id},r),this.onGap?.({batches:1,records:e.records.length,reason:`not_stored`},[e]),!1}}async takeContext(e,t){return await this.diagnostics.guardAsync(`storage.degraded`,`Could not query the context partition.`,()=>this.db.takeContext(e,Math.min(t,4294967295)))??[]}async countContext(e){return await this.diagnostics.guardAsync(`storage.degraded`,`Could not count the context partition.`,()=>this.db.countContext(e))??0}async take(e){return await this.diagnostics.guardAsync(`storage.degraded`,`The library could not read the stored batches.`,()=>this.db.takeOldest(Math.min(e,4294967295)))??[]}async remove(e){await this.diagnostics.guardAsync(`storage.degraded`,`The library could not delete a batch.`,()=>this.db.delete(e))}async bumpAttempts(e,t){await this.diagnostics.guardAsync(`storage.degraded`,`The library could not update the attempt count.`,()=>this.db.bumpAttempts(e,t))}async prune(){let{result:e}=await this.sweep();return e}async sweep(){let e={batches:0,records:0,reason:`expired`},t=[];return await this.diagnostics.guardAsync(`storage.degraded`,`The library could not prune the stored batches.`,async()=>{let n=Date.now()-this.limits.maxAgeMs,r=await this.db.takeBefore(n);r.length>0&&(await this.db.deleteMany(r.map(e=>e.id)),this.addGap(e,`expired`,r),t.push(...r));let i=await this.db.count();if(i>this.limits.maxBatches){let n=await this.evictOldest(i-this.limits.maxBatches);this.addGap(e,`over_capacity`,n),t.push(...n)}}),{result:e,removed:t}}async count(){return await this.diagnostics.guardAsync(`storage.degraded`,`The library could not count the stored batches.`,()=>this.db.count())??0}async clear(){await this.diagnostics.guardAsync(`storage.degraded`,`The library could not clear the stored batches.`,()=>this.db.clear())}async close(){await this.diagnostics.guardAsync(`storage.degraded`,`The library could not close the database.`,()=>this.db.close())}addGap(e,r,i){let a=n.r(e,r,i.length,t.n(i));n.i(this.diagnostics,this.onGap,a,i)}async evictOldest(e){let t=new n.a(e,n.o);await this.db.walkOldest(e=>t.add(e));let r=t.picked();return await this.db.deleteMany(r.map(e=>e.id)),r}};exports.IndexedDbStorage=s;
|
|
2
|
+
//# sourceMappingURL=indexeddb-storage-CL9uqBCy.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexeddb-storage-CL9uqBCy.cjs","names":["INDEXEDDB_CREATED_AT_INDEX","INDEXEDDB_STORE_NAME","STORAGE_NAME_INDEXEDDB","countRecords","addDrop","EvictionPick","hasAction","require_constants","require_batch","require_factory","require_defineProperty","failureOf","request","promisify","resolve","reject","IdbDriver","name","batch","store","range","id","limit","cursor","visit","cutoff","ids","connection","mode","existing","opening","abandoned","db","error","IndexedDbStorage","limits","diagnostics","onGap","dbName","removed","gone","evicted","records","gap","stored","attempts","result","expired","total","reason","dropped","pick","howMany","doomed"],"sources":["../src/storage/idb-driver.ts","../src/storage/indexeddb-storage.ts"],"sourcesContent":["// src/storage/idb-driver.ts\n//\n// The raw IndexedDB code for the batch store. Opens the database, wraps requests in promises\n// and reads in createdAt order. Code above this file only deals in batches and ids.\n\nimport {\n INDEXEDDB_CREATED_AT_INDEX,\n INDEXEDDB_SCHEMA_VERSION,\n INDEXEDDB_STORE_NAME,\n} from \"../constants\";\nimport type { LogBatch } from \"../models/batch\";\n\n/**\n * Returns the failure of a request that fired onerror. Some hosts leave the request's error\n * empty, so fall back to a replacement Error. Rejecting with null would fail the\n * instanceof Error test in save(), which would then report a full disk as an ordinary write\n * failure.\n * @param request The request that fired onerror.\n * @returns The failure that stopped it.\n */\nfunction failureOf(request: IDBRequest): Error {\n return request.error ?? new Error(\"The IndexedDB request failed.\");\n}\n\n/**\n * Resolves when an IndexedDB request succeeds and rejects with the request's error. The\n * request is read as IDBRequest<any>, so every caller has to name the type it expects.\n * @param request The request to await.\n * @returns The request's result.\n */\nfunction promisify<T>(request: IDBRequest): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n request.onsuccess = () => {\n resolve(request.result as T);\n };\n request.onerror = () => {\n reject(failureOf(request));\n };\n });\n}\n\n/** Wraps one IndexedDB database that holds undelivered batches by id. */\nexport class IdbDriver {\n /** The pending or completed open. Reused for every call on this database. */\n private connection: Promise<IDBDatabase> | null = null;\n\n /**\n * @param name IndexedDB database name.\n */\n constructor(private readonly name: string) {}\n\n /**\n * Writes a batch, replacing any stored batch with the same id.\n * @param batch The batch to persist.\n */\n async put(batch: LogBatch): Promise<void> {\n const store = await this.store(\"readwrite\");\n await promisify(store.put(batch));\n }\n\n /**\n * Reads one context's batches in creation order without removing them.\n * @param id Delivery context id.\n * @param limit Maximum number of batches to return.\n * @returns This context's batches, oldest first.\n */\n async takeContext(id: string, limit: number): Promise<LogBatch[]> {\n const store = await this.store(\"readonly\");\n const range = IDBKeyRange.bound([id, 0], [id, Number.MAX_SAFE_INTEGER]);\n return promisify<LogBatch[]>(store.index(\"routingContext\").getAll(range, limit));\n }\n\n /**\n * Counts one context's stored batches.\n * @param id Delivery context id.\n * @returns The number of batches in this context.\n */\n async countContext(id: string): Promise<number> {\n const store = await this.store(\"readonly\");\n return promisify<number>(\n store\n .index(\"routingContext\")\n .count(IDBKeyRange.bound([id, 0], [id, Number.MAX_SAFE_INTEGER])),\n );\n }\n\n /**\n * Reads the oldest batches by createdAt without removing them.\n * @param limit Maximum number of batches to return.\n * @returns The batches in ascending createdAt order.\n */\n async takeOldest(limit: number): Promise<LogBatch[]> {\n const store = await this.store(\"readonly\");\n return promisify<LogBatch[]>(store.index(INDEXEDDB_CREATED_AT_INDEX).getAll(null, limit));\n }\n\n /**\n * Walks the batches by createdAt, oldest first, without removing them. A cursor reads one\n * batch at a time, so the walk can stop before it has read the whole store.\n * @param visit Receives each batch. Return false to stop the walk.\n */\n async walkOldest(visit: (batch: LogBatch) => boolean): Promise<void> {\n const store = await this.store(\"readonly\");\n const request = store.index(INDEXEDDB_CREATED_AT_INDEX).openCursor();\n\n await new Promise<void>((resolve, reject) => {\n request.onsuccess = () => {\n const cursor = request.result;\n if (cursor === null || !visit(cursor.value as LogBatch)) {\n resolve();\n return;\n }\n cursor.continue();\n };\n request.onerror = () => {\n reject(failureOf(request));\n };\n });\n }\n\n /**\n * Reads every batch whose createdAt is before the cutoff.\n * @param cutoff Exclusive upper bound in epoch milliseconds.\n * @returns The batches older than the cutoff.\n */\n async takeBefore(cutoff: number): Promise<LogBatch[]> {\n const store = await this.store(\"readonly\");\n const range = IDBKeyRange.upperBound(cutoff, true);\n return promisify<LogBatch[]>(store.index(INDEXEDDB_CREATED_AT_INDEX).getAll(range));\n }\n\n /**\n * Deletes one batch. An id that isn't stored resolves without an error.\n * @param id Batch identifier.\n */\n async delete(id: string): Promise<void> {\n const store = await this.store(\"readwrite\");\n await promisify(store.delete(id));\n }\n\n /**\n * Deletes several batches in one transaction. If any delete fails, none of them are deleted.\n * @param ids Batch identifiers.\n */\n async deleteMany(ids: string[]): Promise<void> {\n const store = await this.store(\"readwrite\");\n await Promise.all(ids.map((id) => promisify(store.delete(id))));\n }\n\n /**\n * Sets a stored batch's attempt count, ignoring an id that isn't stored. A batch we already\n * delivered and deleted must not come back, so the get and the put share one transaction.\n * With two transactions, a prune in another window could delete the batch in between and\n * the put would restore it.\n * @param id Batch identifier.\n * @param attempts The new absolute attempt count.\n */\n async bumpAttempts(id: string, attempts: number): Promise<void> {\n const store = await this.store(\"readwrite\");\n const batch = await promisify<LogBatch | undefined>(store.get(id));\n if (batch === undefined) {\n return;\n }\n\n await promisify(store.put({ ...batch, attempts }));\n }\n\n /**\n * Counts the stored batches.\n * @returns Total batch count.\n */\n async count(): Promise<number> {\n const store = await this.store(\"readonly\");\n return promisify<number>(store.count());\n }\n\n /** Deletes every stored batch. */\n async clear(): Promise<void> {\n const store = await this.store(\"readwrite\");\n await promisify(store.clear());\n }\n\n /**\n * Opens the connection. A host that defines indexedDB but rejects open() fails here, which\n * lets the factory pick a different adapter.\n */\n async ready(): Promise<void> {\n await this.open();\n }\n\n /** Closes the connection, if there is one. */\n async close(): Promise<void> {\n const connection = this.connection;\n if (connection === null) {\n return;\n }\n\n this.connection = null;\n const db = await connection;\n db.close();\n }\n\n /**\n * Opens the batch store in a new transaction. A transaction is only valid until control\n * returns to the event loop, so every call takes a fresh one.\n * @param mode Transaction mode.\n * @returns The batch object store.\n */\n private async store(mode: IDBTransactionMode): Promise<IDBObjectStore> {\n const db = await this.open();\n return db.transaction(INDEXEDDB_STORE_NAME, mode).objectStore(INDEXEDDB_STORE_NAME);\n }\n\n /**\n * Opens the database once and hands the same connection to every later call. A failed\n * open isn't kept, so the next call tries again.\n * @returns The open database.\n */\n private open(): Promise<IDBDatabase> {\n const existing = this.connection;\n if (existing !== null) {\n return existing;\n }\n\n const opening = new Promise<IDBDatabase>((resolve, reject) => {\n const request = indexedDB.open(this.name, INDEXEDDB_SCHEMA_VERSION);\n let abandoned = false;\n\n request.onupgradeneeded = () => {\n const db = request.result;\n // A database from an earlier release already has the store. Creating it again would\n // throw ConstraintError and abort the upgrade.\n if (!db.objectStoreNames.contains(INDEXEDDB_STORE_NAME)) {\n const store = db.createObjectStore(INDEXEDDB_STORE_NAME, { keyPath: \"id\" });\n store.createIndex(INDEXEDDB_CREATED_AT_INDEX, INDEXEDDB_CREATED_AT_INDEX);\n }\n // IndexedDB supplies the versionchange transaction during upgradeneeded.\n // eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style\n const transaction = request.transaction as IDBTransaction;\n const store = transaction.objectStore(INDEXEDDB_STORE_NAME);\n if (!store.indexNames.contains(\"routingContext\")) {\n store.createIndex(\"routingContext\", [\"routingContextId\", \"createdAt\"]);\n }\n };\n\n request.onsuccess = () => {\n const db = request.result;\n\n if (abandoned) {\n // The blocked handler already rejected, so nothing references this connection.\n // Close it, because an open connection blocks the next upgrade.\n db.close();\n return;\n }\n\n // Another window is upgrading the schema, and its upgrade blocks until this\n // connection closes.\n db.onversionchange = () => {\n db.close();\n this.connection = null;\n };\n resolve(db);\n };\n request.onerror = () => {\n reject(failureOf(request));\n };\n request.onblocked = () => {\n // An older window still holds the previous schema version. This open won't settle\n // until that window closes, and every storage call would wait on it.\n abandoned = true;\n reject(new Error(\"Another connection blocks the IndexedDB upgrade.\"));\n };\n });\n\n this.connection = opening.catch((error: unknown) => {\n this.connection = null;\n throw error;\n });\n\n return this.connection;\n }\n}\n","// src/storage/indexeddb-storage.ts\n//\n// Stores batches in IndexedDB, indexed by creation time.\n\nimport { QUOTA_EVICTION_DIVISOR, QUOTA_EXCEEDED_ERROR, STORAGE_NAME_INDEXEDDB } from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport { countRecords, type LogBatch } from \"../models/batch\";\nimport type { GapReporter, PruneResult, StorageAdapter, StorageLimits } from \"../models/storage\";\nimport { EvictionPick, hasAction } from \"./eviction\";\nimport { addDrop, reportEviction } from \"./gap\";\nimport { IdbDriver } from \"./idb-driver\";\n\n/** What one prune did. save() reads `removed` to see whether its own batch survived. */\ninterface Sweep {\n /** The prune summary across all rules. */\n result: PruneResult;\n /** The batches the prune deleted. */\n removed: LogBatch[];\n}\n\n/** StorageAdapter that keeps batches in IndexedDB. */\nexport class IndexedDbStorage implements StorageAdapter {\n /** The storage strategy name. */\n readonly name = STORAGE_NAME_INDEXEDDB;\n\n /** Holds the IndexedDB code for the batch store. */\n private readonly db: IdbDriver;\n\n /**\n * @param dbName Database name.\n * @param limits Storage capacity and retention thresholds.\n * @param diagnostics Diagnostics reporter.\n * @param onGap Optional callback for reporting dropped records.\n */\n constructor(\n dbName: string,\n private readonly limits: StorageLimits,\n private readonly diagnostics: Diagnostics,\n private readonly onGap?: GapReporter,\n ) {\n this.db = new IdbDriver(dbName);\n }\n\n /**\n * Opens the database. Not guarded, because the factory needs the rejection to pick the\n * next adapter.\n */\n async open(): Promise<void> {\n await this.db.ready();\n }\n\n /**\n * Writes a batch to IndexedDB, then prunes the storage.\n * @param batch The batch to store.\n * @returns True if the batch is in the database after the prune, false if the write failed\n * or the prune removed the batch.\n */\n async save(batch: LogBatch): Promise<boolean> {\n try {\n await this.db.put(batch);\n const { removed } = await this.sweep();\n\n // The prune can remove the batch it just wrote, for example when every older batch holds\n // an action. A true here would promise a resend for a batch that onGap reported as lost.\n return !removed.some((gone) => gone.id === batch.id);\n } catch (error) {\n if (error instanceof Error && error.name === QUOTA_EXCEEDED_ERROR) {\n this.diagnostics.report(\n \"storage.quota_exceeded\",\n \"IndexedDB is full. The library removes the oldest batches.\",\n );\n const evicted = await this.diagnostics.guardAsync(\n \"storage.degraded\",\n \"The library could not remove old batches after a full disk.\",\n () => this.evictOldest(Math.ceil(this.limits.maxBatches / QUOTA_EVICTION_DIVISOR)),\n );\n if (evicted) {\n const records = countRecords(evicted);\n const gap: PruneResult = { batches: evicted.length, records, reason: \"quota\" };\n reportEviction(this.diagnostics, this.onGap, gap, evicted);\n }\n\n // The eviction made room for this batch, so write it again. Without the second write,\n // save() resolves, the batch is lost and no counter shows it.\n const stored = await this.diagnostics.guardAsync(\n \"storage.degraded\",\n \"The library could not write the batch after it removed old batches.\",\n async () => {\n await this.db.put(batch);\n return true;\n },\n );\n if (stored !== true) {\n const gap: PruneResult = { batches: 1, records: batch.records.length, reason: \"quota\" };\n reportEviction(this.diagnostics, this.onGap, gap, [batch]);\n }\n return stored === true;\n }\n\n this.diagnostics.report(\n \"storage.degraded\",\n \"The library could not store a batch.\",\n { batchId: batch.id },\n error,\n );\n // The diagnostic above names the failure. A storage.evicted report would count it twice.\n this.onGap?.({ batches: 1, records: batch.records.length, reason: \"not_stored\" }, [batch]);\n return false;\n }\n }\n\n /**\n * Reads one context's batches in creation order without removing them.\n * @param id Delivery context id.\n * @param limit Maximum number of batches to return.\n * @returns This context's batches, oldest first.\n */\n async takeContext(id: string, limit: number): Promise<LogBatch[]> {\n return (\n (await this.diagnostics.guardAsync(\n \"storage.degraded\",\n \"Could not query the context partition.\",\n () => this.db.takeContext(id, Math.min(limit, 0xffffffff)),\n )) ?? []\n );\n }\n\n /**\n * Counts one context's stored batches.\n * @param id Delivery context id.\n * @returns The number of batches in this context.\n */\n async countContext(id: string): Promise<number> {\n return (\n (await this.diagnostics.guardAsync(\n \"storage.degraded\",\n \"Could not count the context partition.\",\n () => this.db.countContext(id),\n )) ?? 0\n );\n }\n\n /**\n * Reads up to `limit` batches in FIFO order without deleting them.\n * @param limit Maximum number of batches to retrieve.\n * @returns The retrieved batches.\n */\n async take(limit: number): Promise<LogBatch[]> {\n const batches = await this.diagnostics.guardAsync(\n \"storage.degraded\",\n \"The library could not read the stored batches.\",\n // getAll() takes an unsigned 32-bit count. Anything larger throws and the read is empty.\n () => this.db.takeOldest(Math.min(limit, 0xffffffff)),\n );\n return batches ?? [];\n }\n\n /**\n * Deletes the batch with the given ID from IndexedDB.\n * @param id Batch identifier to delete.\n */\n async remove(id: string): Promise<void> {\n await this.diagnostics.guardAsync(\n \"storage.degraded\",\n \"The library could not delete a batch.\",\n () => this.db.delete(id),\n );\n }\n\n /**\n * Sets a stored batch's delivery attempt count.\n * @param id Batch identifier.\n * @param attempts The new absolute attempt count.\n */\n async bumpAttempts(id: string, attempts: number): Promise<void> {\n await this.diagnostics.guardAsync(\n \"storage.degraded\",\n \"The library could not update the attempt count.\",\n () => this.db.bumpAttempts(id, attempts),\n );\n }\n\n /**\n * Removes expired batches, then the oldest batches above the capacity limit.\n * @returns Prune summary metrics.\n */\n async prune(): Promise<PruneResult> {\n const { result } = await this.sweep();\n\n return result;\n }\n\n /**\n * Runs the prune and keeps the batches it deleted. A failed prune reports to diagnostics and\n * returns what it deleted before the failure.\n * @returns The prune summary and the deleted batches.\n */\n private async sweep(): Promise<Sweep> {\n const result: PruneResult = { batches: 0, records: 0, reason: \"expired\" };\n const removed: LogBatch[] = [];\n\n await this.diagnostics.guardAsync(\n \"storage.degraded\",\n \"The library could not prune the stored batches.\",\n async () => {\n const cutoff = Date.now() - this.limits.maxAgeMs;\n const expired = await this.db.takeBefore(cutoff);\n if (expired.length > 0) {\n await this.db.deleteMany(expired.map((batch) => batch.id));\n this.addGap(result, \"expired\", expired);\n removed.push(...expired);\n }\n\n const total = await this.db.count();\n if (total > this.limits.maxBatches) {\n const evicted = await this.evictOldest(total - this.limits.maxBatches);\n this.addGap(result, \"over_capacity\", evicted);\n removed.push(...evicted);\n }\n },\n );\n\n return { result, removed };\n }\n\n /**\n * Returns the number of stored batches.\n * @returns The total batch count, or 0 on failure.\n */\n async count(): Promise<number> {\n const total = await this.diagnostics.guardAsync(\n \"storage.degraded\",\n \"The library could not count the stored batches.\",\n () => this.db.count(),\n );\n return total ?? 0;\n }\n\n /** Deletes every stored batch from the database. */\n async clear(): Promise<void> {\n await this.diagnostics.guardAsync(\n \"storage.degraded\",\n \"The library could not clear the stored batches.\",\n () => this.db.clear(),\n );\n }\n\n /** Closes the active IndexedDB connection. */\n async close(): Promise<void> {\n await this.diagnostics.guardAsync(\n \"storage.degraded\",\n \"The library could not close the database.\",\n () => this.db.close(),\n );\n }\n\n /**\n * Adds dropped batches to the prune result and reports them under their own reason.\n * @param result The prune result across all rules.\n * @param reason The rule that dropped the batches.\n * @param dropped The dropped batches.\n */\n private addGap(result: PruneResult, reason: PruneResult[\"reason\"], dropped: LogBatch[]): void {\n const gap = addDrop(result, reason, dropped.length, countRecords(dropped));\n reportEviction(this.diagnostics, this.onGap, gap, dropped);\n }\n\n /**\n * Deletes the given number of stored batches. Batches without an action go first, oldest\n * first, because an action is an audit fact. Not guarded, because both callers guard it. A\n * guard here would hide the failure and report an eviction that never happened.\n * @param howMany Number of batches to evict.\n * @returns The evicted batches.\n */\n private async evictOldest(howMany: number): Promise<LogBatch[]> {\n // Only the records say whether a batch holds an action. Stop at enough plain batches.\n const pick = new EvictionPick(howMany, hasAction);\n await this.db.walkOldest((batch) => pick.add(batch));\n\n const doomed = pick.picked();\n await this.db.deleteMany(doomed.map((batch) => batch.id));\n\n return doomed;\n }\n}\n"],"mappings":"A,6JAoBA,SAASW,EAAU,EAA4B,CAC7C,OAAOC,EAAQ,OAAa,MAAM,+BAA+B,CACnE,CAQA,SAASC,EAAa,EAAiC,CACrD,OAAO,IAAI,SAAY,EAAS,IAAW,CACzC,EAAQ,cAAkB,CACxBC,EAAQF,EAAQ,MAAW,CAC7B,EACA,EAAQ,YAAgB,CACtBG,EAAOJ,EAAUC,CAAO,CAAC,CAC3B,CACF,CAAC,CACH,CAGA,IAAaI,EAAb,KAAuB,CAOrB,YAAY,EAA+B,CAAdN,EAAA,EAAA,KAAA,OAAA,IAAA,EAAA,EAL7BA,EAAA,EAAA,KAAA,aAAkD,IAAA,EAKrB,KAAA,KAAAO,CAAe,CAM5C,MAAM,IAAI,EAAgC,CAExC,MAAMJ,GAAU,MADI,KAAK,MAAM,WAAW,EAAA,CACpB,IAAIK,CAAK,CAAC,CAClC,CAQA,MAAM,YAAY,EAAY,EAAoC,CAChE,IAAMC,EAAQ,MAAM,KAAK,MAAM,UAAU,EACnCC,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ACF,CAGA,MAAM,OAAuB,CAC3B,MAAM,KAAK,YAAY,WACrB,mBACA,gDACM,KAAK,GAAG,MAAM,CACtB,CACF,CAQA,OAAe,EAAqB,EAA+B,EAA2B,CAC5F,IAAME,EAAMvC,EAAAA,EAAQ0C,EAAQG,EAAQC,EAAQ,OAAQ/C,EAAAA,EAAa+C,CAAO,CAAC,EACzEzC,EAAA,EAAe,KAAK,YAAa,KAAK,MAAOkC,EAAKO,CAAO,CAC3D,CASA,MAAc,YAAY,EAAsC,CAE9D,IAAMC,EAAO,IAAI9C,EAAAA,EAAa+C,EAAS9C,EAAAA,CAAS,EAChD,MAAM,KAAK,GAAG,WAAY,GAAU6C,EAAK,IAAIjC,CAAK,CAAC,EAEnD,IAAMmC,EAASF,EAAK,OAAO,EAG3B,OAFA,MAAM,KAAK,GAAG,WAAWE,EAAO,IAAK,GAAUnC,EAAM,EAAE,CAAC,EAEjDmC,CACT,CACF,E"}
|
|
@@ -1,37 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as r } from "./batch-
|
|
3
|
-
import { i,
|
|
1
|
+
import { Kn as e, bt as t, yt as n } from "./constants-CUyd9cTZ.js";
|
|
2
|
+
import { n as r } from "./batch-CXmPmTse.js";
|
|
3
|
+
import { a as i, i as a, o, r as s } from "./factory-CTi0Is3F.js";
|
|
4
|
+
import { t as c } from "./defineProperty-s2S8BXUc.js";
|
|
4
5
|
// src/storage/idb-driver.ts
|
|
5
|
-
function
|
|
6
|
+
function l(e) {
|
|
6
7
|
return e.error ?? /* @__PURE__ */ Error("The IndexedDB request failed.");
|
|
7
8
|
}
|
|
8
|
-
function
|
|
9
|
+
function u(e) {
|
|
9
10
|
return new Promise((t, n) => {
|
|
10
11
|
e.onsuccess = () => {
|
|
11
12
|
t(e.result);
|
|
12
13
|
}, e.onerror = () => {
|
|
13
|
-
n(
|
|
14
|
+
n(l(e));
|
|
14
15
|
};
|
|
15
16
|
});
|
|
16
17
|
}
|
|
17
|
-
var
|
|
18
|
-
name;
|
|
19
|
-
connection = null;
|
|
18
|
+
var d = class {
|
|
20
19
|
constructor(e) {
|
|
21
|
-
this.name = e;
|
|
20
|
+
c(this, "name", void 0), c(this, "connection", null), this.name = e;
|
|
22
21
|
}
|
|
23
22
|
async put(e) {
|
|
24
|
-
await
|
|
23
|
+
await u((await this.store("readwrite")).put(e));
|
|
25
24
|
}
|
|
26
25
|
async takeContext(e, t) {
|
|
27
26
|
let n = await this.store("readonly"), r = IDBKeyRange.bound([e, 0], [e, 2 ** 53 - 1]);
|
|
28
|
-
return
|
|
27
|
+
return u(n.index("routingContext").getAll(r, t));
|
|
29
28
|
}
|
|
30
29
|
async countContext(e) {
|
|
31
|
-
return
|
|
30
|
+
return u((await this.store("readonly")).index("routingContext").count(IDBKeyRange.bound([e, 0], [e, 2 ** 53 - 1])));
|
|
32
31
|
}
|
|
33
32
|
async takeOldest(e) {
|
|
34
|
-
return
|
|
33
|
+
return u((await this.store("readonly")).index(n).getAll(null, e));
|
|
35
34
|
}
|
|
36
35
|
async walkOldest(e) {
|
|
37
36
|
let t = (await this.store("readonly")).index(n).openCursor();
|
|
@@ -40,33 +39,33 @@ var u = class {
|
|
|
40
39
|
let r = t.result;
|
|
41
40
|
r === null || !e(r.value) ? n() : r.continue();
|
|
42
41
|
}, t.onerror = () => {
|
|
43
|
-
r(
|
|
42
|
+
r(l(t));
|
|
44
43
|
};
|
|
45
44
|
});
|
|
46
45
|
}
|
|
47
46
|
async takeBefore(e) {
|
|
48
47
|
let t = await this.store("readonly"), r = IDBKeyRange.upperBound(e, !0);
|
|
49
|
-
return
|
|
48
|
+
return u(t.index(n).getAll(r));
|
|
50
49
|
}
|
|
51
50
|
async delete(e) {
|
|
52
|
-
await
|
|
51
|
+
await u((await this.store("readwrite")).delete(e));
|
|
53
52
|
}
|
|
54
53
|
async deleteMany(e) {
|
|
55
54
|
let t = await this.store("readwrite");
|
|
56
|
-
await Promise.all(e.map((e) =>
|
|
55
|
+
await Promise.all(e.map((e) => u(t.delete(e))));
|
|
57
56
|
}
|
|
58
57
|
async bumpAttempts(e, t) {
|
|
59
|
-
let n = await this.store("readwrite"), r = await
|
|
60
|
-
r !== void 0 && await
|
|
58
|
+
let n = await this.store("readwrite"), r = await u(n.get(e));
|
|
59
|
+
r !== void 0 && await u(n.put({
|
|
61
60
|
...r,
|
|
62
61
|
attempts: t
|
|
63
62
|
}));
|
|
64
63
|
}
|
|
65
64
|
async count() {
|
|
66
|
-
return
|
|
65
|
+
return u((await this.store("readonly")).count());
|
|
67
66
|
}
|
|
68
67
|
async clear() {
|
|
69
|
-
await
|
|
68
|
+
await u((await this.store("readwrite")).clear());
|
|
70
69
|
}
|
|
71
70
|
async ready() {
|
|
72
71
|
await this.open();
|
|
@@ -94,7 +93,7 @@ var u = class {
|
|
|
94
93
|
t.close(), this.connection = null;
|
|
95
94
|
}, e(t));
|
|
96
95
|
}, i.onerror = () => {
|
|
97
|
-
r(
|
|
96
|
+
r(l(i));
|
|
98
97
|
}, i.onblocked = () => {
|
|
99
98
|
a = !0, r(/* @__PURE__ */ Error("Another connection blocks the IndexedDB upgrade."));
|
|
100
99
|
};
|
|
@@ -103,21 +102,18 @@ var u = class {
|
|
|
103
102
|
throw this.connection = null, e;
|
|
104
103
|
}), this.connection;
|
|
105
104
|
}
|
|
106
|
-
},
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
onGap;
|
|
110
|
-
name = e;
|
|
111
|
-
db;
|
|
112
|
-
constructor(e, t, n, r) {
|
|
113
|
-
this.limits = t, this.diagnostics = n, this.onGap = r, this.db = new u(e);
|
|
105
|
+
}, f = class {
|
|
106
|
+
constructor(t, n, r, i) {
|
|
107
|
+
c(this, "limits", void 0), c(this, "diagnostics", void 0), c(this, "onGap", void 0), c(this, "name", e), c(this, "db", void 0), this.limits = n, this.diagnostics = r, this.onGap = i, this.db = new d(t);
|
|
114
108
|
}
|
|
115
109
|
async open() {
|
|
116
110
|
await this.db.ready();
|
|
117
111
|
}
|
|
118
112
|
async save(e) {
|
|
119
113
|
try {
|
|
120
|
-
await this.db.put(e)
|
|
114
|
+
await this.db.put(e);
|
|
115
|
+
let { removed: t } = await this.sweep();
|
|
116
|
+
return !t.some((t) => t.id === e.id);
|
|
121
117
|
} catch (t) {
|
|
122
118
|
if (t instanceof Error && t.name === "QuotaExceededError") {
|
|
123
119
|
this.diagnostics.report("storage.quota_exceeded", "IndexedDB is full. The library removes the oldest batches.");
|
|
@@ -130,7 +126,8 @@ var u = class {
|
|
|
130
126
|
};
|
|
131
127
|
a(this.diagnostics, this.onGap, n, t);
|
|
132
128
|
}
|
|
133
|
-
|
|
129
|
+
let n = await this.diagnostics.guardAsync("storage.degraded", "The library could not write the batch after it removed old batches.", async () => (await this.db.put(e), !0));
|
|
130
|
+
if (n !== !0) {
|
|
134
131
|
let t = {
|
|
135
132
|
batches: 1,
|
|
136
133
|
records: e.records.length,
|
|
@@ -138,13 +135,13 @@ var u = class {
|
|
|
138
135
|
};
|
|
139
136
|
a(this.diagnostics, this.onGap, t, [e]);
|
|
140
137
|
}
|
|
141
|
-
return;
|
|
138
|
+
return n === !0;
|
|
142
139
|
}
|
|
143
|
-
this.diagnostics.report("storage.degraded", "The library could not store a batch.", { batchId: e.id }, t), this.onGap?.({
|
|
140
|
+
return this.diagnostics.report("storage.degraded", "The library could not store a batch.", { batchId: e.id }, t), this.onGap?.({
|
|
144
141
|
batches: 1,
|
|
145
142
|
records: e.records.length,
|
|
146
143
|
reason: "not_stored"
|
|
147
|
-
}, [e]);
|
|
144
|
+
}, [e]), !1;
|
|
148
145
|
}
|
|
149
146
|
}
|
|
150
147
|
async takeContext(e, t) {
|
|
@@ -163,20 +160,27 @@ var u = class {
|
|
|
163
160
|
await this.diagnostics.guardAsync("storage.degraded", "The library could not update the attempt count.", () => this.db.bumpAttempts(e, t));
|
|
164
161
|
}
|
|
165
162
|
async prune() {
|
|
163
|
+
let { result: e } = await this.sweep();
|
|
164
|
+
return e;
|
|
165
|
+
}
|
|
166
|
+
async sweep() {
|
|
166
167
|
let e = {
|
|
167
168
|
batches: 0,
|
|
168
169
|
records: 0,
|
|
169
170
|
reason: "expired"
|
|
170
|
-
};
|
|
171
|
+
}, t = [];
|
|
171
172
|
return await this.diagnostics.guardAsync("storage.degraded", "The library could not prune the stored batches.", async () => {
|
|
172
|
-
let
|
|
173
|
-
|
|
174
|
-
let
|
|
175
|
-
if (
|
|
176
|
-
let
|
|
177
|
-
this.addGap(e, "over_capacity", t);
|
|
173
|
+
let n = Date.now() - this.limits.maxAgeMs, r = await this.db.takeBefore(n);
|
|
174
|
+
r.length > 0 && (await this.db.deleteMany(r.map((e) => e.id)), this.addGap(e, "expired", r), t.push(...r));
|
|
175
|
+
let i = await this.db.count();
|
|
176
|
+
if (i > this.limits.maxBatches) {
|
|
177
|
+
let n = await this.evictOldest(i - this.limits.maxBatches);
|
|
178
|
+
this.addGap(e, "over_capacity", n), t.push(...n);
|
|
178
179
|
}
|
|
179
|
-
}),
|
|
180
|
+
}), {
|
|
181
|
+
result: e,
|
|
182
|
+
removed: t
|
|
183
|
+
};
|
|
180
184
|
}
|
|
181
185
|
async count() {
|
|
182
186
|
return await this.diagnostics.guardAsync("storage.degraded", "The library could not count the stored batches.", () => this.db.count()) ?? 0;
|
|
@@ -192,12 +196,12 @@ var u = class {
|
|
|
192
196
|
a(this.diagnostics, this.onGap, i, n);
|
|
193
197
|
}
|
|
194
198
|
async evictOldest(e) {
|
|
195
|
-
let t = new
|
|
199
|
+
let t = new i(e, o);
|
|
196
200
|
await this.db.walkOldest((e) => t.add(e));
|
|
197
201
|
let n = t.picked();
|
|
198
202
|
return await this.db.deleteMany(n.map((e) => e.id)), n;
|
|
199
203
|
}
|
|
200
204
|
};
|
|
201
|
-
export {
|
|
205
|
+
export { f as IndexedDbStorage };
|
|
202
206
|
|
|
203
|
-
//# sourceMappingURL=indexeddb-storage-
|
|
207
|
+
//# sourceMappingURL=indexeddb-storage-GHdl0t8A.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexeddb-storage-GHdl0t8A.js","names":["STORAGE_NAME_INDEXEDDB","INDEXEDDB_STORE_NAME","INDEXEDDB_CREATED_AT_INDEX","countRecords","EvictionPick","reportEviction","addDrop","_defineProperty","failureOf","request","promisify","IdbDriver","name","batch","store","range","id","limit","cursor","visit","resolve","cutoff","ids","connection","mode","existing","opening","abandoned","db","reject","error","IndexedDbStorage","limits","diagnostics","onGap","dbName","removed","gone","evicted","records","gap","stored","attempts","result","expired","total","reason","dropped","pick","howMany","hasAction","doomed"],"sources":["../src/storage/idb-driver.ts","../src/storage/indexeddb-storage.ts"],"sourcesContent":["// src/storage/idb-driver.ts\n//\n// The raw IndexedDB code for the batch store. Opens the database, wraps requests in promises\n// and reads in createdAt order. Code above this file only deals in batches and ids.\n\nimport {\n INDEXEDDB_CREATED_AT_INDEX,\n INDEXEDDB_SCHEMA_VERSION,\n INDEXEDDB_STORE_NAME,\n} from \"../constants\";\nimport type { LogBatch } from \"../models/batch\";\n\n/**\n * Returns the failure of a request that fired onerror. Some hosts leave the request's error\n * empty, so fall back to a replacement Error. Rejecting with null would fail the\n * instanceof Error test in save(), which would then report a full disk as an ordinary write\n * failure.\n * @param request The request that fired onerror.\n * @returns The failure that stopped it.\n */\nfunction failureOf(request: IDBRequest): Error {\n return request.error ?? new Error(\"The IndexedDB request failed.\");\n}\n\n/**\n * Resolves when an IndexedDB request succeeds and rejects with the request's error. The\n * request is read as IDBRequest<any>, so every caller has to name the type it expects.\n * @param request The request to await.\n * @returns The request's result.\n */\nfunction promisify<T>(request: IDBRequest): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n request.onsuccess = () => {\n resolve(request.result as T);\n };\n request.onerror = () => {\n reject(failureOf(request));\n };\n });\n}\n\n/** Wraps one IndexedDB database that holds undelivered batches by id. */\nexport class IdbDriver {\n /** The pending or completed open. Reused for every call on this database. */\n private connection: Promise<IDBDatabase> | null = null;\n\n /**\n * @param name IndexedDB database name.\n */\n constructor(private readonly name: string) {}\n\n /**\n * Writes a batch, replacing any stored batch with the same id.\n * @param batch The batch to persist.\n */\n async put(batch: LogBatch): Promise<void> {\n const store = await this.store(\"readwrite\");\n await promisify(store.put(batch));\n }\n\n /**\n * Reads one context's batches in creation order without removing them.\n * @param id Delivery context id.\n * @param limit Maximum number of batches to return.\n * @returns This context's batches, oldest first.\n */\n async takeContext(id: string, limit: number): Promise<LogBatch[]> {\n const store = await this.store(\"readonly\");\n const range = IDBKeyRange.bound([id, 0], [id, Number.MAX_SAFE_INTEGER]);\n return promisify<LogBatch[]>(store.index(\"routingContext\").getAll(range, limit));\n }\n\n /**\n * Counts one context's stored batches.\n * @param id Delivery context id.\n * @returns The number of batches in this context.\n */\n async countContext(id: string): Promise<number> {\n const store = await this.store(\"readonly\");\n return promisify<number>(\n store\n .index(\"routingContext\")\n .count(IDBKeyRange.bound([id, 0], [id, Number.MAX_SAFE_INTEGER])),\n );\n }\n\n /**\n * Reads the oldest batches by createdAt without removing them.\n * @param limit Maximum number of batches to return.\n * @returns The batches in ascending createdAt order.\n */\n async takeOldest(limit: number): Promise<LogBatch[]> {\n const store = await this.store(\"readonly\");\n return promisify<LogBatch[]>(store.index(INDEXEDDB_CREATED_AT_INDEX).getAll(null, limit));\n }\n\n /**\n * Walks the batches by createdAt, oldest first, without removing them. A cursor reads one\n * batch at a time, so the walk can stop before it has read the whole store.\n * @param visit Receives each batch. Return false to stop the walk.\n */\n async walkOldest(visit: (batch: LogBatch) => boolean): Promise<void> {\n const store = await this.store(\"readonly\");\n const request = store.index(INDEXEDDB_CREATED_AT_INDEX).openCursor();\n\n await new Promise<void>((resolve, reject) => {\n request.onsuccess = () => {\n const cursor = request.result;\n if (cursor === null || !visit(cursor.value as LogBatch)) {\n resolve();\n return;\n }\n cursor.continue();\n };\n request.onerror = () => {\n reject(failureOf(request));\n };\n });\n }\n\n /**\n * Reads every batch whose createdAt is before the cutoff.\n * @param cutoff Exclusive upper bound in epoch milliseconds.\n * @returns The batches older than the cutoff.\n */\n async takeBefore(cutoff: number): Promise<LogBatch[]> {\n const store = await this.store(\"readonly\");\n const range = IDBKeyRange.upperBound(cutoff, true);\n return promisify<LogBatch[]>(store.index(INDEXEDDB_CREATED_AT_INDEX).getAll(range));\n }\n\n /**\n * Deletes one batch. An id that isn't stored resolves without an error.\n * @param id Batch identifier.\n */\n async delete(id: string): Promise<void> {\n const store = await this.store(\"readwrite\");\n await promisify(store.delete(id));\n }\n\n /**\n * Deletes several batches in one transaction. If any delete fails, none of them are deleted.\n * @param ids Batch identifiers.\n */\n async deleteMany(ids: string[]): Promise<void> {\n const store = await this.store(\"readwrite\");\n await Promise.all(ids.map((id) => promisify(store.delete(id))));\n }\n\n /**\n * Sets a stored batch's attempt count, ignoring an id that isn't stored. A batch we already\n * delivered and deleted must not come back, so the get and the put share one transaction.\n * With two transactions, a prune in another window could delete the batch in between and\n * the put would restore it.\n * @param id Batch identifier.\n * @param attempts The new absolute attempt count.\n */\n async bumpAttempts(id: string, attempts: number): Promise<void> {\n const store = await this.store(\"readwrite\");\n const batch = await promisify<LogBatch | undefined>(store.get(id));\n if (batch === undefined) {\n return;\n }\n\n await promisify(store.put({ ...batch, attempts }));\n }\n\n /**\n * Counts the stored batches.\n * @returns Total batch count.\n */\n async count(): Promise<number> {\n const store = await this.store(\"readonly\");\n return promisify<number>(store.count());\n }\n\n /** Deletes every stored batch. */\n async clear(): Promise<void> {\n const store = await this.store(\"readwrite\");\n await promisify(store.clear());\n }\n\n /**\n * Opens the connection. A host that defines indexedDB but rejects open() fails here, which\n * lets the factory pick a different adapter.\n */\n async ready(): Promise<void> {\n await this.open();\n }\n\n /** Closes the connection, if there is one. */\n async close(): Promise<void> {\n const connection = this.connection;\n if (connection === null) {\n return;\n }\n\n this.connection = null;\n const db = await connection;\n db.close();\n }\n\n /**\n * Opens the batch store in a new transaction. A transaction is only valid until control\n * returns to the event loop, so every call takes a fresh one.\n * @param mode Transaction mode.\n * @returns The batch object store.\n */\n private async store(mode: IDBTransactionMode): Promise<IDBObjectStore> {\n const db = await this.open();\n return db.transaction(INDEXEDDB_STORE_NAME, mode).objectStore(INDEXEDDB_STORE_NAME);\n }\n\n /**\n * Opens the database once and hands the same connection to every later call. A failed\n * open isn't kept, so the next call tries again.\n * @returns The open database.\n */\n private open(): Promise<IDBDatabase> {\n const existing = this.connection;\n if (existing !== null) {\n return existing;\n }\n\n const opening = new Promise<IDBDatabase>((resolve, reject) => {\n const request = indexedDB.open(this.name, INDEXEDDB_SCHEMA_VERSION);\n let abandoned = false;\n\n request.onupgradeneeded = () => {\n const db = request.result;\n // A database from an earlier release already has the store. Creating it again would\n // throw ConstraintError and abort the upgrade.\n if (!db.objectStoreNames.contains(INDEXEDDB_STORE_NAME)) {\n const store = db.createObjectStore(INDEXEDDB_STORE_NAME, { keyPath: \"id\" });\n store.createIndex(INDEXEDDB_CREATED_AT_INDEX, INDEXEDDB_CREATED_AT_INDEX);\n }\n // IndexedDB supplies the versionchange transaction during upgradeneeded.\n // eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style\n const transaction = request.transaction as IDBTransaction;\n const store = transaction.objectStore(INDEXEDDB_STORE_NAME);\n if (!store.indexNames.contains(\"routingContext\")) {\n store.createIndex(\"routingContext\", [\"routingContextId\", \"createdAt\"]);\n }\n };\n\n request.onsuccess = () => {\n const db = request.result;\n\n if (abandoned) {\n // The blocked handler already rejected, so nothing references this connection.\n // Close it, because an open connection blocks the next upgrade.\n db.close();\n return;\n }\n\n // Another window is upgrading the schema, and its upgrade blocks until this\n // connection closes.\n db.onversionchange = () => {\n db.close();\n this.connection = null;\n };\n resolve(db);\n };\n request.onerror = () => {\n reject(failureOf(request));\n };\n request.onblocked = () => {\n // An older window still holds the previous schema version. This open won't settle\n // until that window closes, and every storage call would wait on it.\n abandoned = true;\n reject(new Error(\"Another connection blocks the IndexedDB upgrade.\"));\n };\n });\n\n this.connection = opening.catch((error: unknown) => {\n this.connection = null;\n throw error;\n });\n\n return this.connection;\n }\n}\n","// src/storage/indexeddb-storage.ts\n//\n// Stores batches in IndexedDB, indexed by creation time.\n\nimport { QUOTA_EVICTION_DIVISOR, QUOTA_EXCEEDED_ERROR, STORAGE_NAME_INDEXEDDB } from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport { countRecords, type LogBatch } from \"../models/batch\";\nimport type { GapReporter, PruneResult, StorageAdapter, StorageLimits } from \"../models/storage\";\nimport { EvictionPick, hasAction } from \"./eviction\";\nimport { addDrop, reportEviction } from \"./gap\";\nimport { IdbDriver } from \"./idb-driver\";\n\n/** What one prune did. save() reads `removed` to see whether its own batch survived. */\ninterface Sweep {\n /** The prune summary across all rules. */\n result: PruneResult;\n /** The batches the prune deleted. */\n removed: LogBatch[];\n}\n\n/** StorageAdapter that keeps batches in IndexedDB. */\nexport class IndexedDbStorage implements StorageAdapter {\n /** The storage strategy name. */\n readonly name = STORAGE_NAME_INDEXEDDB;\n\n /** Holds the IndexedDB code for the batch store. */\n private readonly db: IdbDriver;\n\n /**\n * @param dbName Database name.\n * @param limits Storage capacity and retention thresholds.\n * @param diagnostics Diagnostics reporter.\n * @param onGap Optional callback for reporting dropped records.\n */\n constructor(\n dbName: string,\n private readonly limits: StorageLimits,\n private readonly diagnostics: Diagnostics,\n private readonly onGap?: GapReporter,\n ) {\n this.db = new IdbDriver(dbName);\n }\n\n /**\n * Opens the database. Not guarded, because the factory needs the rejection to pick the\n * next adapter.\n */\n async open(): Promise<void> {\n await this.db.ready();\n }\n\n /**\n * Writes a batch to IndexedDB, then prunes the storage.\n * @param batch The batch to store.\n * @returns True if the batch is in the database after the prune, false if the write failed\n * or the prune removed the batch.\n */\n async save(batch: LogBatch): Promise<boolean> {\n try {\n await this.db.put(batch);\n const { removed } = await this.sweep();\n\n // The prune can remove the batch it just wrote, for example when every older batch holds\n // an action. A true here would promise a resend for a batch that onGap reported as lost.\n return !removed.some((gone) => gone.id === batch.id);\n } catch (error) {\n if (error instanceof Error && error.name === QUOTA_EXCEEDED_ERROR) {\n this.diagnostics.report(\n \"storage.quota_exceeded\",\n \"IndexedDB is full. The library removes the oldest batches.\",\n );\n const evicted = await this.diagnostics.guardAsync(\n \"storage.degraded\",\n \"The library could not remove old batches after a full disk.\",\n () => this.evictOldest(Math.ceil(this.limits.maxBatches / QUOTA_EVICTION_DIVISOR)),\n );\n if (evicted) {\n const records = countRecords(evicted);\n const gap: PruneResult = { batches: evicted.length, records, reason: \"quota\" };\n reportEviction(this.diagnostics, this.onGap, gap, evicted);\n }\n\n // The eviction made room for this batch, so write it again. Without the second write,\n // save() resolves, the batch is lost and no counter shows it.\n const stored = await this.diagnostics.guardAsync(\n \"storage.degraded\",\n \"The library could not write the batch after it removed old batches.\",\n async () => {\n await this.db.put(batch);\n return true;\n },\n );\n if (stored !== true) {\n const gap: PruneResult = { batches: 1, records: batch.records.length, reason: \"quota\" };\n reportEviction(this.diagnostics, this.onGap, gap, [batch]);\n }\n return stored === true;\n }\n\n this.diagnostics.report(\n \"storage.degraded\",\n \"The library could not store a batch.\",\n { batchId: batch.id },\n error,\n );\n // The diagnostic above names the failure. A storage.evicted report would count it twice.\n this.onGap?.({ batches: 1, records: batch.records.length, reason: \"not_stored\" }, [batch]);\n return false;\n }\n }\n\n /**\n * Reads one context's batches in creation order without removing them.\n * @param id Delivery context id.\n * @param limit Maximum number of batches to return.\n * @returns This context's batches, oldest first.\n */\n async takeContext(id: string, limit: number): Promise<LogBatch[]> {\n return (\n (await this.diagnostics.guardAsync(\n \"storage.degraded\",\n \"Could not query the context partition.\",\n () => this.db.takeContext(id, Math.min(limit, 0xffffffff)),\n )) ?? []\n );\n }\n\n /**\n * Counts one context's stored batches.\n * @param id Delivery context id.\n * @returns The number of batches in this context.\n */\n async countContext(id: string): Promise<number> {\n return (\n (await this.diagnostics.guardAsync(\n \"storage.degraded\",\n \"Could not count the context partition.\",\n () => this.db.countContext(id),\n )) ?? 0\n );\n }\n\n /**\n * Reads up to `limit` batches in FIFO order without deleting them.\n * @param limit Maximum number of batches to retrieve.\n * @returns The retrieved batches.\n */\n async take(limit: number): Promise<LogBatch[]> {\n const batches = await this.diagnostics.guardAsync(\n \"storage.degraded\",\n \"The library could not read the stored batches.\",\n // getAll() takes an unsigned 32-bit count. Anything larger throws and the read is empty.\n () => this.db.takeOldest(Math.min(limit, 0xffffffff)),\n );\n return batches ?? [];\n }\n\n /**\n * Deletes the batch with the given ID from IndexedDB.\n * @param id Batch identifier to delete.\n */\n async remove(id: string): Promise<void> {\n await this.diagnostics.guardAsync(\n \"storage.degraded\",\n \"The library could not delete a batch.\",\n () => this.db.delete(id),\n );\n }\n\n /**\n * Sets a stored batch's delivery attempt count.\n * @param id Batch identifier.\n * @param attempts The new absolute attempt count.\n */\n async bumpAttempts(id: string, attempts: number): Promise<void> {\n await this.diagnostics.guardAsync(\n \"storage.degraded\",\n \"The library could not update the attempt count.\",\n () => this.db.bumpAttempts(id, attempts),\n );\n }\n\n /**\n * Removes expired batches, then the oldest batches above the capacity limit.\n * @returns Prune summary metrics.\n */\n async prune(): Promise<PruneResult> {\n const { result } = await this.sweep();\n\n return result;\n }\n\n /**\n * Runs the prune and keeps the batches it deleted. A failed prune reports to diagnostics and\n * returns what it deleted before the failure.\n * @returns The prune summary and the deleted batches.\n */\n private async sweep(): Promise<Sweep> {\n const result: PruneResult = { batches: 0, records: 0, reason: \"expired\" };\n const removed: LogBatch[] = [];\n\n await this.diagnostics.guardAsync(\n \"storage.degraded\",\n \"The library could not prune the stored batches.\",\n async () => {\n const cutoff = Date.now() - this.limits.maxAgeMs;\n const expired = await this.db.takeBefore(cutoff);\n if (expired.length > 0) {\n await this.db.deleteMany(expired.map((batch) => batch.id));\n this.addGap(result, \"expired\", expired);\n removed.push(...expired);\n }\n\n const total = await this.db.count();\n if (total > this.limits.maxBatches) {\n const evicted = await this.evictOldest(total - this.limits.maxBatches);\n this.addGap(result, \"over_capacity\", evicted);\n removed.push(...evicted);\n }\n },\n );\n\n return { result, removed };\n }\n\n /**\n * Returns the number of stored batches.\n * @returns The total batch count, or 0 on failure.\n */\n async count(): Promise<number> {\n const total = await this.diagnostics.guardAsync(\n \"storage.degraded\",\n \"The library could not count the stored batches.\",\n () => this.db.count(),\n );\n return total ?? 0;\n }\n\n /** Deletes every stored batch from the database. */\n async clear(): Promise<void> {\n await this.diagnostics.guardAsync(\n \"storage.degraded\",\n \"The library could not clear the stored batches.\",\n () => this.db.clear(),\n );\n }\n\n /** Closes the active IndexedDB connection. */\n async close(): Promise<void> {\n await this.diagnostics.guardAsync(\n \"storage.degraded\",\n \"The library could not close the database.\",\n () => this.db.close(),\n );\n }\n\n /**\n * Adds dropped batches to the prune result and reports them under their own reason.\n * @param result The prune result across all rules.\n * @param reason The rule that dropped the batches.\n * @param dropped The dropped batches.\n */\n private addGap(result: PruneResult, reason: PruneResult[\"reason\"], dropped: LogBatch[]): void {\n const gap = addDrop(result, reason, dropped.length, countRecords(dropped));\n reportEviction(this.diagnostics, this.onGap, gap, dropped);\n }\n\n /**\n * Deletes the given number of stored batches. Batches without an action go first, oldest\n * first, because an action is an audit fact. Not guarded, because both callers guard it. A\n * guard here would hide the failure and report an eviction that never happened.\n * @param howMany Number of batches to evict.\n * @returns The evicted batches.\n */\n private async evictOldest(howMany: number): Promise<LogBatch[]> {\n // Only the records say whether a batch holds an action. Stop at enough plain batches.\n const pick = new EvictionPick(howMany, hasAction);\n await this.db.walkOldest((batch) => pick.add(batch));\n\n const doomed = pick.picked();\n await this.db.deleteMany(doomed.map((batch) => batch.id));\n\n return doomed;\n }\n}\n"],"mappings":";;;;;AAoBA,SAASQ,EAAU,GAA4B;CAC7C,OAAOC,EAAQ,SAAS,gBAAI,MAAM,+BAA+B;AACnE;AAQA,SAASC,EAAa,GAAiC;CACrD,OAAO,IAAI,SAAY,GAAS,MAAW;EAIzC,AAHA,EAAQ,kBAAkB;GACxB,EAAQD,EAAQ,MAAW;EAC7B,GACA,EAAQ,gBAAgB;GACtB,EAAOD,EAAUC,CAAO,CAAC;EAC3B;CACF,CAAC;AACH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AQ,iBAAiBL,CAAO,GAC5CF,EAAQ,KAAK,GAAGE,CAAO;GACzB;EACF,CACF,GAEO;GAAE;GAAQ;EAAQ;CAC3B;CAMA,MAAM,QAAyB;EAM7B,OAAO,MALa,KAAK,YAAY,WACnC,oBACA,yDACM,KAAK,GAAG,MAAM,CACtB,KACgB;CAClB;CAGA,MAAM,QAAuB;EAC3B,MAAM,KAAK,YAAY,WACrB,oBACA,yDACM,KAAK,GAAG,MAAM,CACtB;CACF;CAGA,MAAM,QAAuB;EAC3B,MAAM,KAAK,YAAY,WACrB,oBACA,mDACM,KAAK,GAAG,MAAM,CACtB;CACF;CAQA,OAAe,GAAqB,GAA+B,GAA2B;EAC5F,IAAME,IAAMlC,EAAQqC,GAAQG,GAAQC,EAAQ,QAAQ5C,EAAa4C,CAAO,CAAC;EACzE,EAAe,KAAK,aAAa,KAAK,OAAOP,GAAKO,CAAO;CAC3D;CASA,MAAc,YAAY,GAAsC;EAE9D,IAAMC,IAAO,IAAI5C,EAAa6C,GAASC,CAAS;EAChD,MAAM,KAAK,GAAG,YAAY,MAAUF,EAAK,IAAInC,CAAK,CAAC;EAEnD,IAAMsC,IAASH,EAAK,OAAO;EAG3B,OAFA,MAAM,KAAK,GAAG,WAAWG,EAAO,KAAK,MAAUtC,EAAM,EAAE,CAAC,GAEjDsC;CACT;AACF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./constants-CqdJhTxH.cjs"),t=require("./patch-BX8KrPCT.cjs"),n=require("./platform-CfA3-7sJ.cjs"),r=require("./defineProperty-X1c4tIPD.cjs");var i=`a[target="_blank"], a[download]`;function a(e){let t=e.tagName.toLowerCase(),n=e.getAttribute(`data-testid`)??e.getAttribute(`data-test-id`);if(n!==null)return`[data-testid="${n}"]`;if(e.id!==``)return`#${e.id}`;let r=e.getAttribute(`aria-label`);if(r!==null)return`${t}[aria-label="${r.slice(0,40)}"]`;let i=e.getAttribute(`class`)?.trim()??``;return i===``?t:`${t}.${i.split(/\s+/).slice(0,2).join(`.`)}`}function o(){return history}var s=class{constructor(t){r.t(this,`ctx`,void 0),r.t(this,`name`,`interactions`),r.t(this,`installed`,!1),r.t(this,`restores`,[]),r.t(this,`lastUrl`,``),r.t(this,`burst`,{target:null,times:[],reported:!1}),r.t(this,`stopDeadCheck`,void 0),r.t(this,`onClick`,t=>{if(this.ctx.isActive?.()===!1)return;let n=t.target;if(!(n instanceof Element))return;let r=this.ctx.config.capture.interactions,o=typeof r==`object`?r:{},s=o.ignoreSelector===void 0?e.vt:o.ignoreSelector;if(s&&n.closest(s))return;let c=o.actionAttribute??`data-observability-action`,l=((n.closest(`[${c}]`)?.getAttribute(c)??``)||`unknown-click`).slice(0,this.ctx.config.limits.maxBodyChars),u={};o.selector&&(u.selector=a(n)),o.text&&(u.text=n.textContent.trim().slice(0,o.maxTextChars??50)),this.ctx.tracing.rotate(`interaction`),this.ctx.breadcrumbs.push({t:Date.now(),category:`click`,message:l,data:Object.keys(u).length>0?u:void 0}),o.rageClicks&&this.countRage(n,l,o),o.deadClicks&&n.closest(`a, button, summary, input[type="button"], input[type="submit"], input[type="reset"], [role="button"], [role="link"], [role="menuitem"], [role="tab"], [${c}]`)&&!n.closest(i)&&this.watchDead(l,o)}),r.t(this,`onNavigate`,()=>{let e=this.lastUrl,t=location.href;if(e===t||(this.lastUrl=t,this.ctx.isActive?.()===!1))return;let r=this.ctx.config.capture.fullUrls,{urlTransform:i}=this.ctx.config.capture,a=n.i(e,r,i,this.ctx.diagnostics),o=n.i(t,r,i,this.ctx.diagnostics);this.ctx.tracing.rotate(`navigation`),this.ctx.breadcrumbs.push({t:Date.now(),category:`navigation`,message:`${a} -> ${o}`}),this.ctx.logger.logEvent(`NAVIGATION`,{"page.url.previous":a})}),this.ctx=t}install(){this.installed||typeof document>`u`||(this.installed=!0,this.lastUrl=location.href,this.ctx.config.capture.interactions&&addEventListener(`click`,this.onClick,!0),this.ctx.config.capture.navigation&&(this.installHistory(),addEventListener(`popstate`,this.onNavigate),addEventListener(`hashchange`,this.onNavigate)))}uninstall(){if(this.installed){this.installed=!1,removeEventListener(`click`,this.onClick,!0),removeEventListener(`popstate`,this.onNavigate),removeEventListener(`hashchange`,this.onNavigate);for(let e of this.restores.splice(0))e();this.stopDeadCheck?.(),this.burst={target:null,times:[],reported:!1}}}countRage(e,t,n){let r=Date.now(),i=n.rageClickWindowMs??1e3,a=n.rageClickCount??3,o=this.burst.target===e?this.burst.times.filter(e=>r-e<i):[],s=o.length>0&&this.burst.reported;o.push(r);let c=o.length>=a;this.burst={target:e,times:o,reported:s||c},c&&!s&&this.ctx.logger.logEvent(`ui.rage_click`,{"click.action":t,"click.count":a})}watchDead(e,t){if(this.stopDeadCheck||typeof MutationObserver>`u`)return;let n=location.href,r=!1,i=()=>{r=!0},a=new MutationObserver(i);a.observe(document,{subtree:!0,childList:!0,attributes:!0,characterData:!0}),addEventListener(`scroll`,i,{capture:!0,passive:!0});let o=()=>{clearTimeout(s),a.disconnect(),removeEventListener(`scroll`,i,!0),this.stopDeadCheck=void 0},s=setTimeout(()=>{o(),!r&&location.href===n&&this.ctx.isActive?.()!==!1&&this.ctx.logger.logEvent(`ui.dead_click`,{"click.action":e})},t.deadClickMs??1e3);this.stopDeadCheck=o}installHistory(){if(typeof history>`u`)return;let e=o(),n=this.onNavigate,r=!0,i=t.t(e,`pushState`,e=>function(...t){e.apply(this,t),r&&queueMicrotask(n)}),a=t.t(e,`replaceState`,e=>function(...t){e.apply(this,t),r&&queueMicrotask(n)});this.restores.push(()=>{r=!1,i(),a()})}};exports.InteractionCapture=s;
|
|
2
|
+
//# sourceMappingURL=interactions-CUkzK8sR.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactions-CUkzK8sR.cjs","names":["IGNORE_SELECTOR","recordedUrl","patch","require_constants","require_patch","require_platform","require_defineProperty","LEAVING_LINKS","describeElement","tag","element","testId","label","classAttribute","historyMethods","InteractionCapture","target","event","settings","options","ignore","attribute","message","data","from","to","full","fromUrl","urlTransform","toUrl","ctx","restore","now","windowMs","count","times","t","reported","reached","action","href","responded","respond","observer","stop","timer","onNavigate","active","restorePushState","args","original","restoreReplaceState"],"sources":["../src/capture/interactions.ts"],"sourcesContent":["// src/capture/interactions.ts\n//\n// Captures clicks and in-page navigations as breadcrumbs and trace boundaries. Also detects\n// rage clicks and dead clicks.\n\nimport {\n ACTION_ATTRIBUTE_DEFAULT,\n ARIA_LABEL_MAX_CHARS,\n CLICK_TEXT_MAX_CHARS,\n DEAD_CLICK_CONTROLS,\n DEAD_CLICK_MS,\n IGNORE_SELECTOR,\n RAGE_CLICK_COUNT,\n RAGE_CLICK_WINDOW_MS,\n SELECTOR_MAX_CLASSES,\n} from \"../constants\";\nimport type { InteractionOptions } from \"../models/config\";\nimport { patch } from \"../utils/patch\";\nimport { recordedUrl } from \"../utils/platform\";\nimport type { Capture, CaptureContext } from \"./types\";\n\n/** Links that open elsewhere. The page shows no response, but the click isn't dead. */\nconst LEAVING_LINKS = 'a[target=\"_blank\"], a[download]';\n\n/**\n * Builds a short CSS selector for an element. Prefers the test ID, then the ID, then the\n * aria-label, then the class names.\n * @param element Target DOM element.\n * @returns The selector.\n */\nfunction describeElement(element: Element): string {\n const tag = element.tagName.toLowerCase();\n\n const testId = element.getAttribute(\"data-testid\") ?? element.getAttribute(\"data-test-id\");\n if (testId !== null) {\n return `[data-testid=\"${testId}\"]`;\n }\n if (element.id !== \"\") {\n return `#${element.id}`;\n }\n\n const label = element.getAttribute(\"aria-label\");\n if (label !== null) {\n return `${tag}[aria-label=\"${label.slice(0, ARIA_LABEL_MAX_CHARS)}\"]`;\n }\n\n // Read the class through getAttribute. On an SVG element, `className` is an\n // SVGAnimatedString, and slicing it throws.\n const classAttribute = element.getAttribute(\"class\")?.trim() ?? \"\";\n if (classAttribute === \"\") {\n return tag;\n }\n\n const classes = classAttribute.split(/\\s+/).slice(0, SELECTOR_MAX_CLASSES).join(\".\");\n return `${tag}.${classes}`;\n}\n\n/**\n * The two History members this module replaces. They are declared as properties, not\n * methods, so the original functions stay unbound. With a bound copy, uninstall would\n * restore a different function from the one it replaced, and every install cycle would\n * stack one more bind on top of the last.\n */\ninterface HistoryMethods {\n pushState: (this: History, ...args: never[]) => void;\n replaceState: (this: History, ...args: never[]) => void;\n}\n\n/**\n * Returns the History object, typed so that its methods stay unbound.\n * @returns The global history.\n */\nfunction historyMethods(): HistoryMethods {\n return history;\n}\n\n/** Captures user clicks and single-page navigations. */\nexport class InteractionCapture implements Capture {\n /** Capture module identifier. */\n readonly name = \"interactions\";\n\n /** Prevents duplicate listener registration. */\n private installed = false;\n\n /** Restore functions for the history wrappers. */\n private readonly restores: (() => void)[] = [];\n\n /** The URL before the latest navigation. */\n private lastUrl = \"\";\n\n /** The element of the current click burst, and when each of its clicks happened. */\n private burst: { target: Element | null; times: number[]; reported: boolean } = {\n target: null,\n times: [],\n reported: false,\n };\n\n /** Stops the dead click check that is running now. */\n private stopDeadCheck: (() => void) | undefined;\n\n /**\n * @param ctx Capture context: configuration, diagnostics, logger, breadcrumbs and tracing.\n */\n constructor(private readonly ctx: CaptureContext) {}\n\n /** Registers click listeners and patches history navigation APIs. */\n install(): void {\n if (this.installed || typeof document === \"undefined\") {\n return;\n }\n this.installed = true;\n this.lastUrl = location.href;\n\n if (this.ctx.config.capture.interactions) {\n // In the capture phase we see the click before a page handler can stop propagation.\n addEventListener(\"click\", this.onClick, true);\n }\n if (this.ctx.config.capture.navigation) {\n this.installHistory();\n addEventListener(\"popstate\", this.onNavigate);\n addEventListener(\"hashchange\", this.onNavigate);\n }\n }\n\n /**\n * Removes the interaction listeners and restores every history method that still holds our\n * wrapper. A wrapper that another script wrapped again stays in place and records nothing.\n */\n uninstall(): void {\n if (!this.installed) {\n return;\n }\n this.installed = false;\n\n removeEventListener(\"click\", this.onClick, true);\n removeEventListener(\"popstate\", this.onNavigate);\n removeEventListener(\"hashchange\", this.onNavigate);\n\n for (const restore of this.restores.splice(0)) {\n restore();\n }\n\n this.stopDeadCheck?.();\n this.burst = { target: null, times: [], reported: false };\n }\n\n /** Rotates the trace context and records a click breadcrumb. */\n private readonly onClick = (event: Event): void => {\n if (this.ctx.isActive?.() === false) {\n return;\n }\n const target = event.target;\n if (!(target instanceof Element)) {\n return;\n }\n const settings = this.ctx.config.capture.interactions;\n const options = typeof settings === \"object\" ? settings : {};\n const ignore = options.ignoreSelector === undefined ? IGNORE_SELECTOR : options.ignoreSelector;\n if (ignore && target.closest(ignore)) {\n return;\n }\n // A missing or empty attribute gives \"\", and the message is then \"unknown-click\".\n const attribute = options.actionAttribute ?? ACTION_ATTRIBUTE_DEFAULT;\n const action = target.closest(`[${attribute}]`)?.getAttribute(attribute) ?? \"\";\n const message = (action || \"unknown-click\").slice(0, this.ctx.config.limits.maxBodyChars);\n const data: Record<string, unknown> = {};\n if (options.selector) {\n data.selector = describeElement(target);\n }\n if (options.text) {\n data.text = target.textContent.trim().slice(0, options.maxTextChars ?? CLICK_TEXT_MAX_CHARS);\n }\n this.ctx.tracing.rotate(\"interaction\");\n this.ctx.breadcrumbs.push({\n t: Date.now(),\n category: \"click\",\n message,\n data: Object.keys(data).length > 0 ? data : undefined,\n });\n\n if (options.rageClicks) {\n this.countRage(target, message, options);\n }\n if (\n options.deadClicks &&\n target.closest(`${DEAD_CLICK_CONTROLS}, [${attribute}]`) &&\n !target.closest(LEAVING_LINKS)\n ) {\n this.watchDead(message, options);\n }\n };\n\n /**\n * Counts the clicks on one element and records `ui.rage_click` once per burst.\n * @param target Clicked element.\n * @param action The click's action name.\n * @param options Interaction options.\n */\n private countRage(target: Element, action: string, options: InteractionOptions): void {\n const now = Date.now();\n const windowMs = options.rageClickWindowMs ?? RAGE_CLICK_WINDOW_MS;\n const count = options.rageClickCount ?? RAGE_CLICK_COUNT;\n const times =\n this.burst.target === target ? this.burst.times.filter((t) => now - t < windowMs) : [];\n // A burst only ends once no click is left in the window, so clicks that keep sliding\n // through it don't fire a second event.\n const reported = times.length > 0 && this.burst.reported;\n times.push(now);\n const reached = times.length >= count;\n this.burst = { target, times, reported: reported || reached };\n\n if (reached && !reported) {\n this.ctx.logger.logEvent(\"ui.rage_click\", { \"click.action\": action, \"click.count\": count });\n }\n }\n\n /**\n * Watches the page after a click on a control. If there's no DOM change, navigation or scroll\n * within `deadClickMs`, it records `ui.dead_click`. Only one check runs at a time.\n * @param action The click's action name.\n * @param options Interaction options.\n */\n private watchDead(action: string, options: InteractionOptions): void {\n if (this.stopDeadCheck || typeof MutationObserver === \"undefined\") {\n return;\n }\n\n const href = location.href;\n let responded = false;\n const respond = (): void => {\n responded = true;\n };\n const observer = new MutationObserver(respond);\n observer.observe(document, {\n subtree: true,\n childList: true,\n attributes: true,\n characterData: true,\n });\n addEventListener(\"scroll\", respond, { capture: true, passive: true });\n\n const stop = (): void => {\n // timer is declared after stop, but stop can only run once that line has executed.\n clearTimeout(timer);\n observer.disconnect();\n removeEventListener(\"scroll\", respond, true);\n this.stopDeadCheck = undefined;\n };\n const timer = setTimeout(() => {\n stop();\n if (!responded && location.href === href && this.ctx.isActive?.() !== false) {\n this.ctx.logger.logEvent(\"ui.dead_click\", { \"click.action\": action });\n }\n }, options.deadClickMs ?? DEAD_CLICK_MS);\n this.stopDeadCheck = stop;\n }\n\n /** On a URL change, rotates the trace context and records a breadcrumb and an event. */\n private readonly onNavigate = (): void => {\n const from = this.lastUrl;\n const to = location.href;\n if (from === to) {\n return;\n }\n this.lastUrl = to;\n if (this.ctx.isActive?.() === false) {\n return;\n }\n\n // The comparison above uses the full URL, so a query-only change still counts as a\n // navigation. The record doesn't keep the query unless you set fullUrls.\n const full = this.ctx.config.capture.fullUrls;\n const { urlTransform } = this.ctx.config.capture;\n const fromUrl = recordedUrl(from, full, urlTransform, this.ctx.diagnostics);\n const toUrl = recordedUrl(to, full, urlTransform, this.ctx.diagnostics);\n\n this.ctx.tracing.rotate(\"navigation\");\n this.ctx.breadcrumbs.push({\n t: Date.now(),\n category: \"navigation\",\n message: `${fromUrl} -> ${toUrl}`,\n });\n\n // The event carries only the previous URL, and the record builder adds the current one as\n // `page.url`. Putting the new URL in `url.full` would make a navigation look like an HTTP\n // request.\n this.ctx.logger.logEvent(\"NAVIGATION\", { \"page.url.previous\": fromUrl });\n };\n\n /** Patches History.pushState and replaceState to observe programmatic navigations. */\n private installHistory(): void {\n if (typeof history === \"undefined\") {\n return;\n }\n\n // Wrap the instance, not History.prototype. Reading from the prototype would skip a patch\n // that a router installed on the instance. patch keeps the originals unbound.\n const target = historyMethods();\n const onNavigate = this.onNavigate;\n // Uninstall clears the flag, so a wrapper that stays in place only calls the original.\n let active = true;\n\n const restorePushState = patch(\n target,\n \"pushState\",\n (original) =>\n function (this: History, ...args: never[]): void {\n original.apply(this, args);\n // Queue the handler. The browser only updates location.href after the call returns,\n // so a synchronous read would report the previous URL as the new one.\n if (active) {\n queueMicrotask(onNavigate);\n }\n },\n );\n\n const restoreReplaceState = patch(\n target,\n \"replaceState\",\n (original) =>\n function (this: History, ...args: never[]): void {\n original.apply(this, args);\n if (active) {\n queueMicrotask(onNavigate);\n }\n },\n );\n\n this.restores.push(() => {\n active = false;\n restorePushState();\n restoreReplaceState();\n });\n }\n}\n"],"mappings":"A,8JAsBA,IAAMO,EAAgB,kCAQtB,SAASC,EAAgB,EAA0B,CACjD,IAAMC,EAAMC,EAAQ,QAAQ,YAAY,EAElCC,EAASD,EAAQ,aAAa,aAAa,GAAKA,EAAQ,aAAa,cAAc,EACzF,GAAIC,IAAW,KACb,MAAO,iBAAiBA,EAAO,IAEjC,GAAID,EAAQ,KAAO,GACjB,MAAO,IAAIA,EAAQ,KAGrB,IAAME,EAAQF,EAAQ,aAAa,YAAY,EAC/C,GAAIE,IAAU,KACZ,MAAO,GAAGH,EAAI,eAAeG,EAAM,MAAM,EAAA,EAAuB,EAAE,IAKpE,IAAMC,EAAiBH,EAAQ,aAAa,OAAO,CAAC,EAAE,KAAK,GAAK,GAMhE,OALIG,IAAmB,GACdJ,EAIF,GAAGA,EAAI,GADEI,EA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EACpB,oBAAoB,SAAUD,EAAS,EAAI,EAC3C,KAAK,cAAgB,IAAA,EACvB,EACMG,EAAQ,eAAiB,CAC7BD,EAAK,EACD,CAACH,GAAa,SAAS,OAASD,GAAQ,KAAK,IAAI,WAAW,IAAM,IACpE,KAAK,IAAI,OAAO,SAAS,gBAAiB,CAAE,eAAgBD,CAAO,CAAC,CAExE,EAAGpB,EAAQ,aAAA,GAA4B,EACvC,KAAK,cAAgByB,CACvB,CAmCA,gBAA+B,CAC7B,GAAI,OAAO,QAAY,IACrB,OAKF,IAAM5B,EAASF,EAAe,EACxBgC,EAAa,KAAK,WAEpBC,EAAS,GAEPC,EAAmB9C,EAAAA,EACvBc,EACA,YACC,GACC,SAAyB,GAAGiC,EAAqB,CAC/CC,EAAS,MAAM,KAAMD,CAAI,EAGrBF,GACF,eAAeD,CAAU,CAE7B,CACJ,EAEMK,EAAsBjD,EAAAA,EAC1Bc,EACA,eACC,GACC,SAAyB,GAAGiC,EAAqB,CAC/CC,EAAS,MAAM,KAAMD,CAAI,EACrBF,GACF,eAAeD,CAAU,CAE7B,CACJ,EAEA,KAAK,SAAS,SAAW,CACvB,EAAS,GACTE,EAAiB,EACjBG,EAAoB,CACtB,CAAC,CACH,CACF,E"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import "./constants-
|
|
2
|
-
import { t
|
|
3
|
-
import { i as
|
|
1
|
+
import { vt as e } from "./constants-CUyd9cTZ.js";
|
|
2
|
+
import { t } from "./patch-UdPz1ea8.js";
|
|
3
|
+
import { i as n } from "./platform-BaaFIPCU.js";
|
|
4
|
+
import { t as r } from "./defineProperty-s2S8BXUc.js";
|
|
4
5
|
// src/capture/interactions.ts
|
|
5
|
-
var
|
|
6
|
-
function
|
|
6
|
+
var i = "a[target=\"_blank\"], a[download]";
|
|
7
|
+
function a(e) {
|
|
7
8
|
let t = e.tagName.toLowerCase(), n = e.getAttribute("data-testid") ?? e.getAttribute("data-test-id");
|
|
8
9
|
if (n !== null) return `[data-testid="${n}"]`;
|
|
9
10
|
if (e.id !== "") return `#${e.id}`;
|
|
@@ -12,23 +13,38 @@ function r(e) {
|
|
|
12
13
|
let i = e.getAttribute("class")?.trim() ?? "";
|
|
13
14
|
return i === "" ? t : `${t}.${i.split(/\s+/).slice(0, 2).join(".")}`;
|
|
14
15
|
}
|
|
15
|
-
function
|
|
16
|
+
function o() {
|
|
16
17
|
return history;
|
|
17
18
|
}
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
19
|
+
var s = class {
|
|
20
|
+
constructor(t) {
|
|
21
|
+
r(this, "ctx", void 0), r(this, "name", "interactions"), r(this, "installed", !1), r(this, "restores", []), r(this, "lastUrl", ""), r(this, "burst", {
|
|
22
|
+
target: null,
|
|
23
|
+
times: [],
|
|
24
|
+
reported: !1
|
|
25
|
+
}), r(this, "stopDeadCheck", void 0), r(this, "onClick", (t) => {
|
|
26
|
+
if (this.ctx.isActive?.() === !1) return;
|
|
27
|
+
let n = t.target;
|
|
28
|
+
if (!(n instanceof Element)) return;
|
|
29
|
+
let r = this.ctx.config.capture.interactions, o = typeof r == "object" ? r : {}, s = o.ignoreSelector === void 0 ? e : o.ignoreSelector;
|
|
30
|
+
if (s && n.closest(s)) return;
|
|
31
|
+
let c = o.actionAttribute ?? "data-observability-action", l = ((n.closest(`[${c}]`)?.getAttribute(c) ?? "") || "unknown-click").slice(0, this.ctx.config.limits.maxBodyChars), u = {};
|
|
32
|
+
o.selector && (u.selector = a(n)), o.text && (u.text = n.textContent.trim().slice(0, o.maxTextChars ?? 50)), this.ctx.tracing.rotate("interaction"), this.ctx.breadcrumbs.push({
|
|
33
|
+
t: Date.now(),
|
|
34
|
+
category: "click",
|
|
35
|
+
message: l,
|
|
36
|
+
data: Object.keys(u).length > 0 ? u : void 0
|
|
37
|
+
}), o.rageClicks && this.countRage(n, l, o), o.deadClicks && n.closest(`a, button, summary, input[type="button"], input[type="submit"], input[type="reset"], [role="button"], [role="link"], [role="menuitem"], [role="tab"], [${c}]`) && !n.closest(i) && this.watchDead(l, o);
|
|
38
|
+
}), r(this, "onNavigate", () => {
|
|
39
|
+
let e = this.lastUrl, t = location.href;
|
|
40
|
+
if (e === t || (this.lastUrl = t, this.ctx.isActive?.() === !1)) return;
|
|
41
|
+
let r = this.ctx.config.capture.fullUrls, { urlTransform: i } = this.ctx.config.capture, a = n(e, r, i, this.ctx.diagnostics), o = n(t, r, i, this.ctx.diagnostics);
|
|
42
|
+
this.ctx.tracing.rotate("navigation"), this.ctx.breadcrumbs.push({
|
|
43
|
+
t: Date.now(),
|
|
44
|
+
category: "navigation",
|
|
45
|
+
message: `${a} -> ${o}`
|
|
46
|
+
}), this.ctx.logger.logEvent("NAVIGATION", { "page.url.previous": a });
|
|
47
|
+
}), this.ctx = t;
|
|
32
48
|
}
|
|
33
49
|
install() {
|
|
34
50
|
this.installed || typeof document > "u" || (this.installed = !0, this.lastUrl = location.href, this.ctx.config.capture.interactions && addEventListener("click", this.onClick, !0), this.ctx.config.capture.navigation && (this.installHistory(), addEventListener("popstate", this.onNavigate), addEventListener("hashchange", this.onNavigate)));
|
|
@@ -44,20 +60,6 @@ var a = class {
|
|
|
44
60
|
};
|
|
45
61
|
}
|
|
46
62
|
}
|
|
47
|
-
onClick = (e) => {
|
|
48
|
-
if (this.ctx.isActive?.() === !1) return;
|
|
49
|
-
let t = e.target;
|
|
50
|
-
if (!(t instanceof Element)) return;
|
|
51
|
-
let i = this.ctx.config.capture.interactions, a = typeof i == "object" ? i : {}, o = a.ignoreSelector === void 0 ? "[data-observability-ignore]" : a.ignoreSelector;
|
|
52
|
-
if (o && t.closest(o)) return;
|
|
53
|
-
let s = a.actionAttribute ?? "data-observability-action", c = ((t.closest(`[${s}]`)?.getAttribute(s) ?? "") || "unknown-click").slice(0, this.ctx.config.limits.maxBodyChars), l = {};
|
|
54
|
-
a.selector && (l.selector = r(t)), a.text && (l.text = t.textContent.trim().slice(0, a.maxTextChars ?? 50)), this.ctx.tracing.rotate("interaction"), this.ctx.breadcrumbs.push({
|
|
55
|
-
t: Date.now(),
|
|
56
|
-
category: "click",
|
|
57
|
-
message: c,
|
|
58
|
-
data: Object.keys(l).length > 0 ? l : void 0
|
|
59
|
-
}), a.rageClicks && this.countRage(t, c, a), a.deadClicks && t.closest(`a, button, summary, input[type="button"], input[type="submit"], input[type="reset"], [role="button"], [role="link"], [role="menuitem"], [role="tab"], [${s}]`) && !t.closest(n) && this.watchDead(c, a);
|
|
60
|
-
};
|
|
61
63
|
countRage(e, t, n) {
|
|
62
64
|
let r = Date.now(), i = n.rageClickWindowMs ?? 1e3, a = n.rageClickCount ?? 3, o = this.burst.target === e ? this.burst.times.filter((e) => r - e < i) : [], s = o.length > 0 && this.burst.reported;
|
|
63
65
|
o.push(r);
|
|
@@ -92,28 +94,18 @@ var a = class {
|
|
|
92
94
|
}, t.deadClickMs ?? 1e3);
|
|
93
95
|
this.stopDeadCheck = o;
|
|
94
96
|
}
|
|
95
|
-
onNavigate = () => {
|
|
96
|
-
let e = this.lastUrl, n = location.href;
|
|
97
|
-
if (e === n || (this.lastUrl = n, this.ctx.isActive?.() === !1)) return;
|
|
98
|
-
let r = this.ctx.config.capture.fullUrls, { urlTransform: i } = this.ctx.config.capture, a = t(e, r, i, this.ctx.diagnostics), o = t(n, r, i, this.ctx.diagnostics);
|
|
99
|
-
this.ctx.tracing.rotate("navigation"), this.ctx.breadcrumbs.push({
|
|
100
|
-
t: Date.now(),
|
|
101
|
-
category: "navigation",
|
|
102
|
-
message: `${a} -> ${o}`
|
|
103
|
-
}), this.ctx.logger.logEvent("NAVIGATION", { "page.url.previous": a });
|
|
104
|
-
};
|
|
105
97
|
installHistory() {
|
|
106
98
|
if (typeof history > "u") return;
|
|
107
|
-
let
|
|
99
|
+
let e = o(), n = this.onNavigate, r = !0, i = t(e, "pushState", (e) => function(...t) {
|
|
108
100
|
e.apply(this, t), r && queueMicrotask(n);
|
|
109
|
-
}),
|
|
101
|
+
}), a = t(e, "replaceState", (e) => function(...t) {
|
|
110
102
|
e.apply(this, t), r && queueMicrotask(n);
|
|
111
103
|
});
|
|
112
104
|
this.restores.push(() => {
|
|
113
|
-
r = !1,
|
|
105
|
+
r = !1, i(), a();
|
|
114
106
|
});
|
|
115
107
|
}
|
|
116
108
|
};
|
|
117
|
-
export {
|
|
109
|
+
export { s as InteractionCapture };
|
|
118
110
|
|
|
119
|
-
//# sourceMappingURL=interactions-
|
|
111
|
+
//# sourceMappingURL=interactions-DiFvCosX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactions-DiFvCosX.js","names":["IGNORE_SELECTOR","recordedUrl","_defineProperty","LEAVING_LINKS","describeElement","tag","element","testId","label","classAttribute","historyMethods","InteractionCapture","target","event","settings","options","ignore","attribute","message","data","from","to","full","fromUrl","urlTransform","toUrl","ctx","restore","now","windowMs","count","times","t","reported","reached","action","href","responded","respond","observer","stop","timer","onNavigate","active","restorePushState","patch","args","original","restoreReplaceState"],"sources":["../src/capture/interactions.ts"],"sourcesContent":["// src/capture/interactions.ts\n//\n// Captures clicks and in-page navigations as breadcrumbs and trace boundaries. Also detects\n// rage clicks and dead clicks.\n\nimport {\n ACTION_ATTRIBUTE_DEFAULT,\n ARIA_LABEL_MAX_CHARS,\n CLICK_TEXT_MAX_CHARS,\n DEAD_CLICK_CONTROLS,\n DEAD_CLICK_MS,\n IGNORE_SELECTOR,\n RAGE_CLICK_COUNT,\n RAGE_CLICK_WINDOW_MS,\n SELECTOR_MAX_CLASSES,\n} from \"../constants\";\nimport type { InteractionOptions } from \"../models/config\";\nimport { patch } from \"../utils/patch\";\nimport { recordedUrl } from \"../utils/platform\";\nimport type { Capture, CaptureContext } from \"./types\";\n\n/** Links that open elsewhere. The page shows no response, but the click isn't dead. */\nconst LEAVING_LINKS = 'a[target=\"_blank\"], a[download]';\n\n/**\n * Builds a short CSS selector for an element. Prefers the test ID, then the ID, then the\n * aria-label, then the class names.\n * @param element Target DOM element.\n * @returns The selector.\n */\nfunction describeElement(element: Element): string {\n const tag = element.tagName.toLowerCase();\n\n const testId = element.getAttribute(\"data-testid\") ?? element.getAttribute(\"data-test-id\");\n if (testId !== null) {\n return `[data-testid=\"${testId}\"]`;\n }\n if (element.id !== \"\") {\n return `#${element.id}`;\n }\n\n const label = element.getAttribute(\"aria-label\");\n if (label !== null) {\n return `${tag}[aria-label=\"${label.slice(0, ARIA_LABEL_MAX_CHARS)}\"]`;\n }\n\n // Read the class through getAttribute. On an SVG element, `className` is an\n // SVGAnimatedString, and slicing it throws.\n const classAttribute = element.getAttribute(\"class\")?.trim() ?? \"\";\n if (classAttribute === \"\") {\n return tag;\n }\n\n const classes = classAttribute.split(/\\s+/).slice(0, SELECTOR_MAX_CLASSES).join(\".\");\n return `${tag}.${classes}`;\n}\n\n/**\n * The two History members this module replaces. They are declared as properties, not\n * methods, so the original functions stay unbound. With a bound copy, uninstall would\n * restore a different function from the one it replaced, and every install cycle would\n * stack one more bind on top of the last.\n */\ninterface HistoryMethods {\n pushState: (this: History, ...args: never[]) => void;\n replaceState: (this: History, ...args: never[]) => void;\n}\n\n/**\n * Returns the History object, typed so that its methods stay unbound.\n * @returns The global history.\n */\nfunction historyMethods(): HistoryMethods {\n return history;\n}\n\n/** Captures user clicks and single-page navigations. */\nexport class InteractionCapture implements Capture {\n /** Capture module identifier. */\n readonly name = \"interactions\";\n\n /** Prevents duplicate listener registration. */\n private installed = false;\n\n /** Restore functions for the history wrappers. */\n private readonly restores: (() => void)[] = [];\n\n /** The URL before the latest navigation. */\n private lastUrl = \"\";\n\n /** The element of the current click burst, and when each of its clicks happened. */\n private burst: { target: Element | null; times: number[]; reported: boolean } = {\n target: null,\n times: [],\n reported: false,\n };\n\n /** Stops the dead click check that is running now. */\n private stopDeadCheck: (() => void) | undefined;\n\n /**\n * @param ctx Capture context: configuration, diagnostics, logger, breadcrumbs and tracing.\n */\n constructor(private readonly ctx: CaptureContext) {}\n\n /** Registers click listeners and patches history navigation APIs. */\n install(): void {\n if (this.installed || typeof document === \"undefined\") {\n return;\n }\n this.installed = true;\n this.lastUrl = location.href;\n\n if (this.ctx.config.capture.interactions) {\n // In the capture phase we see the click before a page handler can stop propagation.\n addEventListener(\"click\", this.onClick, true);\n }\n if (this.ctx.config.capture.navigation) {\n this.installHistory();\n addEventListener(\"popstate\", this.onNavigate);\n addEventListener(\"hashchange\", this.onNavigate);\n }\n }\n\n /**\n * Removes the interaction listeners and restores every history method that still holds our\n * wrapper. A wrapper that another script wrapped again stays in place and records nothing.\n */\n uninstall(): void {\n if (!this.installed) {\n return;\n }\n this.installed = false;\n\n removeEventListener(\"click\", this.onClick, true);\n removeEventListener(\"popstate\", this.onNavigate);\n removeEventListener(\"hashchange\", this.onNavigate);\n\n for (const restore of this.restores.splice(0)) {\n restore();\n }\n\n this.stopDeadCheck?.();\n this.burst = { target: null, times: [], reported: false };\n }\n\n /** Rotates the trace context and records a click breadcrumb. */\n private readonly onClick = (event: Event): void => {\n if (this.ctx.isActive?.() === false) {\n return;\n }\n const target = event.target;\n if (!(target instanceof Element)) {\n return;\n }\n const settings = this.ctx.config.capture.interactions;\n const options = typeof settings === \"object\" ? settings : {};\n const ignore = options.ignoreSelector === undefined ? IGNORE_SELECTOR : options.ignoreSelector;\n if (ignore && target.closest(ignore)) {\n return;\n }\n // A missing or empty attribute gives \"\", and the message is then \"unknown-click\".\n const attribute = options.actionAttribute ?? ACTION_ATTRIBUTE_DEFAULT;\n const action = target.closest(`[${attribute}]`)?.getAttribute(attribute) ?? \"\";\n const message = (action || \"unknown-click\").slice(0, this.ctx.config.limits.maxBodyChars);\n const data: Record<string, unknown> = {};\n if (options.selector) {\n data.selector = describeElement(target);\n }\n if (options.text) {\n data.text = target.textContent.trim().slice(0, options.maxTextChars ?? CLICK_TEXT_MAX_CHARS);\n }\n this.ctx.tracing.rotate(\"interaction\");\n this.ctx.breadcrumbs.push({\n t: Date.now(),\n category: \"click\",\n message,\n data: Object.keys(data).length > 0 ? data : undefined,\n });\n\n if (options.rageClicks) {\n this.countRage(target, message, options);\n }\n if (\n options.deadClicks &&\n target.closest(`${DEAD_CLICK_CONTROLS}, [${attribute}]`) &&\n !target.closest(LEAVING_LINKS)\n ) {\n this.watchDead(message, options);\n }\n };\n\n /**\n * Counts the clicks on one element and records `ui.rage_click` once per burst.\n * @param target Clicked element.\n * @param action The click's action name.\n * @param options Interaction options.\n */\n private countRage(target: Element, action: string, options: InteractionOptions): void {\n const now = Date.now();\n const windowMs = options.rageClickWindowMs ?? RAGE_CLICK_WINDOW_MS;\n const count = options.rageClickCount ?? RAGE_CLICK_COUNT;\n const times =\n this.burst.target === target ? this.burst.times.filter((t) => now - t < windowMs) : [];\n // A burst only ends once no click is left in the window, so clicks that keep sliding\n // through it don't fire a second event.\n const reported = times.length > 0 && this.burst.reported;\n times.push(now);\n const reached = times.length >= count;\n this.burst = { target, times, reported: reported || reached };\n\n if (reached && !reported) {\n this.ctx.logger.logEvent(\"ui.rage_click\", { \"click.action\": action, \"click.count\": count });\n }\n }\n\n /**\n * Watches the page after a click on a control. If there's no DOM change, navigation or scroll\n * within `deadClickMs`, it records `ui.dead_click`. Only one check runs at a time.\n * @param action The click's action name.\n * @param options Interaction options.\n */\n private watchDead(action: string, options: InteractionOptions): void {\n if (this.stopDeadCheck || typeof MutationObserver === \"undefined\") {\n return;\n }\n\n const href = location.href;\n let responded = false;\n const respond = (): void => {\n responded = true;\n };\n const observer = new MutationObserver(respond);\n observer.observe(document, {\n subtree: true,\n childList: true,\n attributes: true,\n characterData: true,\n });\n addEventListener(\"scroll\", respond, { capture: true, passive: true });\n\n const stop = (): void => {\n // timer is declared after stop, but stop can only run once that line has executed.\n clearTimeout(timer);\n observer.disconnect();\n removeEventListener(\"scroll\", respond, true);\n this.stopDeadCheck = undefined;\n };\n const timer = setTimeout(() => {\n stop();\n if (!responded && location.href === href && this.ctx.isActive?.() !== false) {\n this.ctx.logger.logEvent(\"ui.dead_click\", { \"click.action\": action });\n }\n }, options.deadClickMs ?? DEAD_CLICK_MS);\n this.stopDeadCheck = stop;\n }\n\n /** On a URL change, rotates the trace context and records a breadcrumb and an event. */\n private readonly onNavigate = (): void => {\n const from = this.lastUrl;\n const to = location.href;\n if (from === to) {\n return;\n }\n this.lastUrl = to;\n if (this.ctx.isActive?.() === false) {\n return;\n }\n\n // The comparison above uses the full URL, so a query-only change still counts as a\n // navigation. The record doesn't keep the query unless you set fullUrls.\n const full = this.ctx.config.capture.fullUrls;\n const { urlTransform } = this.ctx.config.capture;\n const fromUrl = recordedUrl(from, full, urlTransform, this.ctx.diagnostics);\n const toUrl = recordedUrl(to, full, urlTransform, this.ctx.diagnostics);\n\n this.ctx.tracing.rotate(\"navigation\");\n this.ctx.breadcrumbs.push({\n t: Date.now(),\n category: \"navigation\",\n message: `${fromUrl} -> ${toUrl}`,\n });\n\n // The event carries only the previous URL, and the record builder adds the current one as\n // `page.url`. Putting the new URL in `url.full` would make a navigation look like an HTTP\n // request.\n this.ctx.logger.logEvent(\"NAVIGATION\", { \"page.url.previous\": fromUrl });\n };\n\n /** Patches History.pushState and replaceState to observe programmatic navigations. */\n private installHistory(): void {\n if (typeof history === \"undefined\") {\n return;\n }\n\n // Wrap the instance, not History.prototype. Reading from the prototype would skip a patch\n // that a router installed on the instance. patch keeps the originals unbound.\n const target = historyMethods();\n const onNavigate = this.onNavigate;\n // Uninstall clears the flag, so a wrapper that stays in place only calls the original.\n let active = true;\n\n const restorePushState = patch(\n target,\n \"pushState\",\n (original) =>\n function (this: History, ...args: never[]): void {\n original.apply(this, args);\n // Queue the handler. The browser only updates location.href after the call returns,\n // so a synchronous read would report the previous URL as the new one.\n if (active) {\n queueMicrotask(onNavigate);\n }\n },\n );\n\n const restoreReplaceState = patch(\n target,\n \"replaceState\",\n (original) =>\n function (this: History, ...args: never[]): void {\n original.apply(this, args);\n if (active) {\n queueMicrotask(onNavigate);\n }\n },\n );\n\n this.restores.push(() => {\n active = false;\n restorePushState();\n restoreReplaceState();\n });\n }\n}\n"],"mappings":";;;;;AAsBA,IAAMG,IAAgB;AAQtB,SAASC,EAAgB,GAA0B;CACjD,IAAMC,IAAMC,EAAQ,QAAQ,YAAY,GAElCC,IAASD,EAAQ,aAAa,aAAa,KAAKA,EAAQ,aAAa,cAAc;CACzF,IAAIC,MAAW,MACb,OAAO,iBAAiBA,EAAO;CAEjC,IAAID,EAAQ,OAAO,IACjB,OAAO,IAAIA,EAAQ;CAGrB,IAAME,IAAQF,EAAQ,aAAa,YAAY;CAC/C,IAAIE,MAAU,MACZ,OAAO,GAAGH,EAAI,eAAeG,EAAM,MAAM,GAAA,EAAuB,EAAE;CAKpE,IAAMC,IAAiBH,EAAQ,aAAa,OAAO,CAAC,EAAE,KAAK,KAAK;CAMhE,OALIG,MAAmB,KACdJ,IAIF,GAAGA,EAAI,GADEI,EAAe,MAAM,KAAK,CAAC,CAAC,MAAM,GAAA,CAAuB,CAAC,CAAC,KAAK,GAC/D;AACnB;AAiBA,SAASC,IAAiC;CACxC,OAAO;AACT;AAGA,IAAaC,IAAb,MAAmD;CA0BjD,YAAY,GAAsC;EAArB,AAAAT,EAAA,MAAA,OAAA,KAAA,CAAA,GAxB7BA,EAAA,MAAA,QAAgB,cAAA,GAGhBA,EAAA,MAAA,aAAoB,EAAA,GAGpBA,EAAA,MAAA,YAA4C,CAAC,CAAA,GAG7CA,EAAA,MAAA,WAAkB,EAAA,GAGlBA,EAAA,MAAA,SAAgF;GAC9E,QAAQ;GACR,OAAO,CAAC;GACR,UAAU;EACZ,CAAA,GAGAA,EAAA,MAAA,iBAAA,KAAA,CAAA,GAiDAA,EAAA,MAAA,YAA4B,MAAuB;GACjD,IAAI,KAAK,IAAI,WAAW,MAAM,IAC5B;GAEF,IAAMU,IAASC,EAAM;GACrB,IAAI,EAAED,aAAkB,UACtB;GAEF,IAAME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MAAM,MAAMD,CAAI,GACrBH,KACF,eAAeD,CAAU;EAE7B,CACJ;EAEA,KAAK,SAAS,WAAW;GAGvB,AAFA,IAAS,IACTE,EAAiB,GACjBI,EAAoB;EACtB,CAAC;CACH;AACF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./constants-CqdJhTxH.cjs"),t=require("./deadline-CUGbto-y.cjs"),n=require("./identity-DlWRIuwy.cjs"),r=require("./openfin-DtH2f7zX.cjs"),i=require("./unref-CU9Nyz_9.cjs"),a=require("./defineProperty-X1c4tIPD.cjs");var o={maxAgeMs:e.Tt,endOnOwnerClose:!1,urlParam:e.Dt};function s(e,t){let n=Reflect.get(e,t);return typeof n==`string`&&n!==``?n:void 0}function c(e,t){let n=Reflect.get(e,t);return typeof n==`number`&&Number.isFinite(n)?n:void 0}function l(e){if(typeof e!=`object`||!e)return null;let t=s(e,`id`),n=s(e,`name`),r=c(e,`startedAt`);return t===void 0||n===void 0||r===void 0?null:{id:t,name:n,startedAt:r,parentId:s(e,`parentId`),ownerContextId:s(e,`ownerContextId`)??``}}function u(e){if(typeof e!=`object`||!e)return null;let t=s(e,`i`),n=s(e,`n`),r=c(e,`s`),i=r!==void 0&&r>Date.now()+3e5;return t===void 0||n===void 0||r===void 0||i?null:{id:t,name:n,startedAt:r,parentId:void 0,ownerContextId:``}}function d(t){let n=JSON.stringify({i:t.id,n:t.name.slice(0,64),s:t.startedAt}),r=new TextEncoder().encode(n),i=``;for(let e of r)i+=String.fromCharCode(e);return btoa(i).replace(e.w,`-`).replace(e.T,`_`).replace(e.C,``)}var f=class{constructor(e,t,r,i,o=n.t){a.t(this,`options`,void 0),a.t(this,`diagnostics`,void 0),a.t(this,`contextId`,void 0),a.t(this,`onLocalChange`,void 0),a.t(this,`stores`,void 0),a.t(this,`journey`,null),a.t(this,`expiryTimer`,null),this.options=e,this.diagnostics=t,this.contextId=r,this.onLocalChange=i,this.stores=o}current(){return this.journey}async bootstrap(){let t=this.readUrlToken();if(this.journey){t&&this.removeUrlToken(),this.setJourney(this.journey);return}if(t&&this.adopt(t,`url`)){this.removeUrlToken();return}let n=this.diagnostics.guard(`storage.unavailable`,`The library could not read the persisted journey.`,()=>this.stores.session().getItem(e.Et));if(n&&this.restore(n))return;let r=await this.readOpenFinToken();r!==null&&this.adopt(r,`openfin.customData`)}start(e,t={}){let n={id:this.journeyId(t.id),name:e,startedAt:Date.now(),parentId:t.parent?this.journey?.id:void 0,ownerContextId:this.contextId};return this.setJourney(n),this.onLocalChange(n),n}journeyId(t){return t===void 0?n.i(this.diagnostics):typeof t==`string`&&e.wt.test(t)?t:(this.diagnostics.report(`config.invalid`,`startJourney() needs an id of 1 to 64 letters, digits, "_", ".", ":" or "-". The library uses a new id.`),n.i(this.diagnostics))}end(){this.journey!==null&&(this.setJourney(null),this.onLocalChange(null))}applyRemote(e){let t=this.journey;(e===null||t===null||e.id!==t.id)&&this.setJourney(e)}getToken(){let e=this.journey;if(e===null)return null;let t=d(e);return t.length>256?(this.diagnostics.report(`journey.token_too_large`,`The journey token is larger than the size limit. The library does not issue it.`,{length:t.length}),null):t}adopt(e,t,n=!1){let r=this.decodeToken(e);return r===null?!1:Date.now()-r.startedAt>this.options.maxAgeMs?(this.diagnostics.report(`journey.expired`,`The library discarded a seeded journey older than maxAgeMs.`,{source:t,name:r.name}),!1):(this.setJourney(r),this.diagnostics.report(`journey.adopted`,`The library adopted the journey "${r.name}".`,{source:t,journeyId:r.id}),n&&this.onLocalChange(r),!0)}ownerClosed(e){this.options.endOnOwnerClose&&this.journey?.ownerContextId===e&&this.end()}destroy(){this.clearTimer()}restore(e){let t=l(this.diagnostics.guard(`storage.degraded`,`The library could not parse the persisted journey.`,()=>JSON.parse(e)));return t===null?!1:Date.now()-t.startedAt>this.options.maxAgeMs?(this.diagnostics.report(`journey.expired`,`The library discarded a persisted journey older than maxAgeMs.`,{name:t.name}),this.clearStored(),!1):(this.setJourney(t),this.diagnostics.report(`journey.adopted`,`The library resumed the journey "${t.name}".`,{source:`sessionStorage`,journeyId:t.id}),!0)}decodeToken(t){return this.diagnostics.guard(`config.invalid`,`The library could not decode a seeded journey token.`,()=>{let n=t.replace(e.x,`+`).replace(e.S,`/`),r=(4-n.length%4)%4,i=`=`.repeat(r),a=Uint8Array.from(atob(n+i),e=>e.charCodeAt(0));return u(JSON.parse(new TextDecoder().decode(a)))})??null}setJourney(t){if(this.journey=t,this.clearTimer(),this.diagnostics.guard(`storage.unavailable`,`The library could not save the journey.`,()=>{t===null?this.stores.session().removeItem(e.Et):this.stores.session().setItem(e.Et,JSON.stringify(t))}),t===null)return;let n=Math.max(this.options.maxAgeMs-(Date.now()-t.startedAt),0),r=setTimeout(()=>{this.diagnostics.report(`journey.expired`,`The journey "${t.name}" reached maxAgeMs. The library ended it.`,{journeyId:t.id}),this.journey=null,this.expiryTimer=null,this.clearStored()},n);this.expiryTimer=r,i.t(r)}clearStored(){this.diagnostics.guard(`storage.unavailable`,`The library could not clear the persisted journey.`,()=>{this.stores.session().removeItem(e.Et)})}clearTimer(){this.expiryTimer!==null&&(clearTimeout(this.expiryTimer),this.expiryTimer=null)}readUrlToken(){return this.diagnostics.guard(`config.invalid`,`The library could not read the journey token from the URL.`,()=>typeof location>`u`?null:new URL(location.href).searchParams.get(this.options.urlParam))??null}removeUrlToken(){this.diagnostics.guard(`platform.api_blocked`,`The library could not remove the journey token from the URL.`,()=>{let e=new URL(location.href);e.searchParams.delete(this.options.urlParam),history.replaceState(history.state,``,e.href)})}async readOpenFinToken(){let n=r.t()?.me,i=n?.getOptions;if(i===void 0)return null;let a=(await this.diagnostics.guardAsync(`openfin.unavailable`,`The library could not read fin.me.getOptions().`,()=>t.n(i.call(n),e.Kt)))?.customData?.[e.Gt];return typeof a==`string`?a:null}};Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return o}});
|
|
2
|
+
//# sourceMappingURL=journey-B4Adltjm.cjs.map
|