@utk09/ui-observability 0.8.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/README.md +75 -48
  3. package/dist/batch-DEK4bv9N.js +31 -0
  4. package/dist/batch-DEK4bv9N.js.map +1 -0
  5. package/dist/batch-DEVFs28i.cjs +2 -0
  6. package/dist/batch-DEVFs28i.cjs.map +1 -0
  7. package/dist/bus/bus.d.ts +46 -12
  8. package/dist/bus/links.d.ts +6 -3
  9. package/dist/bus-DNFvTkif.cjs +2 -0
  10. package/dist/bus-DNFvTkif.cjs.map +1 -0
  11. package/dist/{bus-DPDrlUBY.js → bus-HVQ8E72V.js} +128 -71
  12. package/dist/bus-HVQ8E72V.js.map +1 -0
  13. package/dist/capture/interactions.d.ts +7 -6
  14. package/dist/capture/network.d.ts +23 -9
  15. package/dist/capture/types.d.ts +3 -3
  16. package/dist/console-C9Y639mn.js +82 -0
  17. package/dist/console-C9Y639mn.js.map +1 -0
  18. package/dist/console-DssDxq1B.cjs +2 -0
  19. package/dist/console-DssDxq1B.cjs.map +1 -0
  20. package/dist/constants-N99w84xy.js +117 -0
  21. package/dist/constants-N99w84xy.js.map +1 -0
  22. package/dist/constants-X86IDwkC.cjs +2 -0
  23. package/dist/constants-X86IDwkC.cjs.map +1 -0
  24. package/dist/constants.d.ts +36 -18
  25. package/dist/core/diagnostics.d.ts +2 -2
  26. package/dist/core/drops.d.ts +29 -0
  27. package/dist/core/hold-buffer.d.ts +27 -0
  28. package/dist/core/journey.d.ts +16 -4
  29. package/dist/core/logger.d.ts +6 -2
  30. package/dist/core/pipeline.d.ts +20 -16
  31. package/dist/core/record.d.ts +11 -6
  32. package/dist/core/remote-sampling.d.ts +1 -1
  33. package/dist/core/runtime.d.ts +87 -23
  34. package/dist/core/sender.d.ts +19 -11
  35. package/dist/deadline-5_PecIl5.js +26 -0
  36. package/dist/deadline-5_PecIl5.js.map +1 -0
  37. package/dist/deadline-XSnm95pg.cjs +2 -0
  38. package/dist/deadline-XSnm95pg.cjs.map +1 -0
  39. package/dist/error-like-Ywo5uRHo.js +19 -0
  40. package/dist/error-like-Ywo5uRHo.js.map +1 -0
  41. package/dist/error-like-gGRx2s36.cjs +2 -0
  42. package/dist/error-like-gGRx2s36.cjs.map +1 -0
  43. package/dist/errors-BTWuVnHZ.cjs +3 -0
  44. package/dist/errors-BTWuVnHZ.cjs.map +1 -0
  45. package/dist/{errors-Dnc-X4Ec.js → errors-CQusIGWJ.js} +39 -20
  46. package/dist/errors-CQusIGWJ.js.map +1 -0
  47. package/dist/global-scope-BN-Io_yv.cjs.map +1 -1
  48. package/dist/global-scope-dp2jADRl.js.map +1 -1
  49. package/dist/identity-B1GDS1Tb.cjs +2 -0
  50. package/dist/identity-B1GDS1Tb.cjs.map +1 -0
  51. package/dist/identity-D4DPjTM9.js +88 -0
  52. package/dist/identity-D4DPjTM9.js.map +1 -0
  53. package/dist/index.cjs +1 -1
  54. package/dist/index.cjs.map +1 -1
  55. package/dist/index.d.ts +12 -4
  56. package/dist/index.js +720 -446
  57. package/dist/index.js.map +1 -1
  58. package/dist/{indexeddb-storage-uD4oaRMc.js → indexeddb-storage-B8SGUzSV.js} +88 -59
  59. package/dist/indexeddb-storage-B8SGUzSV.js.map +1 -0
  60. package/dist/indexeddb-storage-ukzC82dm.cjs +2 -0
  61. package/dist/indexeddb-storage-ukzC82dm.cjs.map +1 -0
  62. package/dist/interactions-CcxrVzpg.cjs +2 -0
  63. package/dist/interactions-CcxrVzpg.cjs.map +1 -0
  64. package/dist/{interactions-igKTAJvj.js → interactions-CnjfQgw3.js} +22 -19
  65. package/dist/interactions-CnjfQgw3.js.map +1 -0
  66. package/dist/journey-DjvDzHyp.js +163 -0
  67. package/dist/journey-DjvDzHyp.js.map +1 -0
  68. package/dist/journey-DxlfdFJV.cjs +2 -0
  69. package/dist/journey-DxlfdFJV.cjs.map +1 -0
  70. package/dist/{library-request-Br_T09Bn.cjs → library-request-BZ1ekVtl.cjs} +2 -2
  71. package/dist/{library-request-Br_T09Bn.cjs.map → library-request-BZ1ekVtl.cjs.map} +1 -1
  72. package/dist/{library-request-Dt0fXhcn.js → library-request-C8kc5YWv.js} +2 -2
  73. package/dist/{library-request-Dt0fXhcn.js.map → library-request-C8kc5YWv.js.map} +1 -1
  74. package/dist/{long-frames-DahhqM6u.cjs → long-frames-BGik_Yhy.cjs} +2 -2
  75. package/dist/{long-frames-DahhqM6u.cjs.map → long-frames-BGik_Yhy.cjs.map} +1 -1
  76. package/dist/{long-frames-6pnjWSSR.js → long-frames-CZk3XOkH.js} +3 -3
  77. package/dist/{long-frames-6pnjWSSR.js.map → long-frames-CZk3XOkH.js.map} +1 -1
  78. package/dist/models/batch.d.ts +15 -1
  79. package/dist/models/bus.d.ts +7 -4
  80. package/dist/models/config.d.ts +189 -12
  81. package/dist/models/drop.d.ts +39 -0
  82. package/dist/models/log-record.d.ts +12 -6
  83. package/dist/models/storage.d.ts +15 -3
  84. package/dist/network-51iicpLl.js +174 -0
  85. package/dist/network-51iicpLl.js.map +1 -0
  86. package/dist/network-jBbjyAJP.cjs +2 -0
  87. package/dist/network-jBbjyAJP.cjs.map +1 -0
  88. package/dist/patch-BX8KrPCT.cjs +2 -0
  89. package/dist/patch-BX8KrPCT.cjs.map +1 -0
  90. package/dist/patch-CCWfuEY7.js +9 -0
  91. package/dist/patch-CCWfuEY7.js.map +1 -0
  92. package/dist/platform-Cjts-8k8.js +48 -0
  93. package/dist/platform-Cjts-8k8.js.map +1 -0
  94. package/dist/{platform-D_XkVIF6.cjs → platform-DW3GFIUE.cjs} +2 -2
  95. package/dist/platform-DW3GFIUE.cjs.map +1 -0
  96. package/dist/{remote-rules-rJJZKVG8.cjs → remote-rules-ByS34k4e.cjs} +2 -2
  97. package/dist/remote-rules-ByS34k4e.cjs.map +1 -0
  98. package/dist/{remote-rules-5UA23alm.js → remote-rules-M-XZ1xbe.js} +14 -14
  99. package/dist/remote-rules-M-XZ1xbe.js.map +1 -0
  100. package/dist/sampling-BN3Oi6SV.js +63 -0
  101. package/dist/sampling-BN3Oi6SV.js.map +1 -0
  102. package/dist/sampling-b2ck5X98.cjs +2 -0
  103. package/dist/sampling-b2ck5X98.cjs.map +1 -0
  104. package/dist/sanitize-DKp5MRsa.cjs +2 -0
  105. package/dist/sanitize-DKp5MRsa.cjs.map +1 -0
  106. package/dist/sanitize-Dwj9JCkI.js +123 -0
  107. package/dist/sanitize-Dwj9JCkI.js.map +1 -0
  108. package/dist/{sender-G6v4Uqi4.js → sender-BBY0IcUo.js} +439 -322
  109. package/dist/sender-BBY0IcUo.js.map +1 -0
  110. package/dist/sender-BXoAZKum.cjs +3 -0
  111. package/dist/sender-BXoAZKum.cjs.map +1 -0
  112. package/dist/storage/emergency-queue.d.ts +5 -2
  113. package/dist/storage/eviction.d.ts +40 -0
  114. package/dist/storage/factory.d.ts +1 -1
  115. package/dist/storage/idb-driver.d.ts +7 -1
  116. package/dist/storage/indexeddb-storage.d.ts +13 -5
  117. package/dist/storage/local-storage.d.ts +27 -4
  118. package/dist/storage/memory-storage.d.ts +10 -3
  119. package/dist/{storm-BtzgLOCX.cjs → storm-CKuaBp7i.cjs} +2 -2
  120. package/dist/{storm-BtzgLOCX.cjs.map → storm-CKuaBp7i.cjs.map} +1 -1
  121. package/dist/{storm-DJkEZP_8.js → storm-DhtL2eVr.js} +2 -2
  122. package/dist/{storm-DJkEZP_8.js.map → storm-DhtL2eVr.js.map} +1 -1
  123. package/dist/transport/compression.d.ts +1 -1
  124. package/dist/transport/exit-flush.d.ts +27 -17
  125. package/dist/transport/http-transport.d.ts +61 -7
  126. package/dist/transport/retry-engine.d.ts +12 -8
  127. package/dist/transport/status-transport.d.ts +8 -3
  128. package/dist/utils/console.d.ts +5 -2
  129. package/dist/utils/error-like.d.ts +25 -0
  130. package/dist/utils/global-scope.d.ts +1 -1
  131. package/dist/utils/identity.d.ts +1 -1
  132. package/dist/utils/library-console.d.ts +1 -1
  133. package/dist/utils/library-request.d.ts +1 -1
  134. package/dist/utils/patch.d.ts +9 -0
  135. package/dist/utils/platform.d.ts +3 -3
  136. package/dist/utils/sequence.d.ts +0 -5
  137. package/dist/utils/timer.d.ts +1 -1
  138. package/dist/utils/tracing.d.ts +3 -3
  139. package/dist/utils/unref.d.ts +2 -2
  140. package/dist/{web-vitals-DHZ0yA_H.js → web-vitals-Bflr5jSA.js} +4 -2
  141. package/dist/web-vitals-Bflr5jSA.js.map +1 -0
  142. package/dist/web-vitals-DFuoTQbZ.cjs +2 -0
  143. package/dist/web-vitals-DFuoTQbZ.cjs.map +1 -0
  144. package/package.json +2 -2
  145. package/dist/bus-CUXRY0JR.cjs +0 -2
  146. package/dist/bus-CUXRY0JR.cjs.map +0 -1
  147. package/dist/bus-DPDrlUBY.js.map +0 -1
  148. package/dist/console-CNljJict.js +0 -81
  149. package/dist/console-CNljJict.js.map +0 -1
  150. package/dist/console-PKzc-FmR.cjs +0 -2
  151. package/dist/console-PKzc-FmR.cjs.map +0 -1
  152. package/dist/constants-B28fDv2F.cjs +0 -2
  153. package/dist/constants-B28fDv2F.cjs.map +0 -1
  154. package/dist/constants-Bu49bm39.js +0 -93
  155. package/dist/constants-Bu49bm39.js.map +0 -1
  156. package/dist/errors-C78ZTjet.cjs +0 -3
  157. package/dist/errors-C78ZTjet.cjs.map +0 -1
  158. package/dist/errors-Dnc-X4Ec.js.map +0 -1
  159. package/dist/indexeddb-storage-D0p3iMD0.cjs +0 -2
  160. package/dist/indexeddb-storage-D0p3iMD0.cjs.map +0 -1
  161. package/dist/indexeddb-storage-uD4oaRMc.js.map +0 -1
  162. package/dist/interactions-CsE2y_fQ.cjs +0 -2
  163. package/dist/interactions-CsE2y_fQ.cjs.map +0 -1
  164. package/dist/interactions-igKTAJvj.js.map +0 -1
  165. package/dist/network-CZ0aFUsy.cjs +0 -2
  166. package/dist/network-CZ0aFUsy.cjs.map +0 -1
  167. package/dist/network-aSNbwpue.js +0 -112
  168. package/dist/network-aSNbwpue.js.map +0 -1
  169. package/dist/platform-BwbMRwHm.js +0 -48
  170. package/dist/platform-BwbMRwHm.js.map +0 -1
  171. package/dist/platform-D_XkVIF6.cjs.map +0 -1
  172. package/dist/remote-rules-5UA23alm.js.map +0 -1
  173. package/dist/remote-rules-rJJZKVG8.cjs.map +0 -1
  174. package/dist/sampling-E4x92Nn2.cjs +0 -2
  175. package/dist/sampling-E4x92Nn2.cjs.map +0 -1
  176. package/dist/sampling-J1eahbfT.js +0 -160
  177. package/dist/sampling-J1eahbfT.js.map +0 -1
  178. package/dist/sanitize-BMhh8ghJ.cjs +0 -2
  179. package/dist/sanitize-BMhh8ghJ.cjs.map +0 -1
  180. package/dist/sanitize-UJ-4Lb0n.js +0 -114
  181. package/dist/sanitize-UJ-4Lb0n.js.map +0 -1
  182. package/dist/sender-B6ufz26f.cjs +0 -3
  183. package/dist/sender-B6ufz26f.cjs.map +0 -1
  184. package/dist/sender-G6v4Uqi4.js.map +0 -1
  185. package/dist/unref-16maCyKA.js +0 -8
  186. package/dist/unref-16maCyKA.js.map +0 -1
  187. package/dist/unref-CU9Nyz_9.cjs +0 -2
  188. package/dist/unref-CU9Nyz_9.cjs.map +0 -1
  189. package/dist/web-vitals-B2FYsEAU.cjs +0 -2
  190. package/dist/web-vitals-B2FYsEAU.cjs.map +0 -1
  191. package/dist/web-vitals-DHZ0yA_H.js.map +0 -1
@@ -1,34 +1,33 @@
1
- import { $t as e, A as t, At as n, Dt as r, Ft as i, G as a, Ht as o, I as s, J as c, K as l, O as u, Ot as d, Pt as f, Qt as ee, R as p, Ut as te, Vt as m, X as ne, Y as re, an as h, bt as g, en as _, ft as v, gt as y, ht as b, in as x, k as ie, l as ae, ln as oe, lt as se, on as S, pt as ce, q as le, qt as ue, rn as de, un as fe, ut as pe, v as C, xt as me, z as w } from "./constants-Bu49bm39.js";
2
- import { a as T, i as he, l as E, m as D, t as O } from "./sampling-J1eahbfT.js";
3
- import { o as k, t as A } from "./sanitize-UJ-4Lb0n.js";
4
- import { t as j } from "./unref-16maCyKA.js";
5
- import { n as M, t as N } from "./remote-rules-5UA23alm.js";
6
- import { n as P } from "./library-request-Dt0fXhcn.js";
7
- //#region src/models/batch.ts
8
- function F(e) {
9
- if (typeof e != "object" || !e) return !1;
10
- let t = Reflect.get(e, "id"), n = Reflect.get(e, "createdAt"), r = Reflect.get(e, "attempts"), i = Reflect.get(e, "records");
11
- return typeof t == "string" && typeof n == "number" && typeof r == "number" && Array.isArray(i);
12
- }
13
- function I(e, t) {
14
- if (e.records.length < 2) return null;
15
- let n = Math.floor(e.records.length / 2), r = (n) => ({
16
- id: E(t),
17
- records: n,
18
- createdAt: e.createdAt,
19
- attempts: e.attempts
20
- });
21
- return [r(e.records.slice(0, n)), r(e.records.slice(n))];
1
+ import { $ as e, At as t, Ct as n, Gt as r, H as i, J as a, Kt as o, Lt as s, M as c, N as l, Nt as u, Q as d, Rt as f, V as p, Wt as m, X as ee, Xt as te, Y as h, Z as g, an as ne, b as _, cn as v, d as y, dn as b, fn as re, gt as ie, j as x, jt as ae, mt as oe, nn as S, on as se, sn as ce, tn as le, vt as C, wt as w, yt as ue, z as de } from "./constants-N99w84xy.js";
2
+ import { o as fe, t as pe } from "./sampling-BN3Oi6SV.js";
3
+ import { o as me, t as T } from "./sanitize-Dwj9JCkI.js";
4
+ import { i as he } from "./identity-D4DPjTM9.js";
5
+ import { i as ge, n as _e, r as E } from "./batch-DEK4bv9N.js";
6
+ import { n as D } from "./library-request-C8kc5YWv.js";
7
+ import { n as O, r as k, t as A } from "./deadline-5_PecIl5.js";
8
+ import { n as j, t as M } from "./remote-rules-M-XZ1xbe.js";
9
+ //#region src/models/storage.ts
10
+ function N(e) {
11
+ let { maxBatches: t } = e;
12
+ return e.mode === "until-delivered" ? {
13
+ maxBatches: t,
14
+ maxAgeMs: Infinity,
15
+ maxAttempts: Infinity
16
+ } : {
17
+ maxBatches: t,
18
+ maxAgeMs: e.maxAgeMs,
19
+ maxAttempts: e.maxAttempts
20
+ };
22
21
  }
23
22
  //#endregion
24
23
  //#region src/utils/lock.ts
25
- function L(e, t, n, { skipIfBusy: r = !0 } = {}) {
24
+ function P(e, t, n, { skipIfBusy: r = !0 } = {}) {
26
25
  let i = globalThis.navigator?.locks;
27
26
  return i?.request ? t.guardAsync("storage.degraded", `The library could not get the lock ${e}.`, () => i.request(e, { ifAvailable: r }, (e) => e ? n() : Promise.resolve(void 0))) : n();
28
27
  }
29
28
  //#endregion
30
29
  //#region src/storage/keys.ts
31
- function R(e, t) {
30
+ function F(e, t) {
32
31
  let n = [];
33
32
  return t.guard("storage.unavailable", "The library could not list the localStorage keys.", () => {
34
33
  for (let t = 0; t < localStorage.length; t++) {
@@ -39,57 +38,91 @@ function R(e, t) {
39
38
  }
40
39
  //#endregion
41
40
  //#region src/storage/emergency-queue.ts
42
- function ge(e) {
41
+ function I(e) {
43
42
  let t = String(e.createdAt).padStart(14, "0");
44
43
  return `${p}${t}.${e.id}`;
45
44
  }
46
- function _e(e, t) {
45
+ function L(e, t) {
47
46
  let n = t.guard("storage.degraded", "An emergency entry is not valid JSON. The library dropped it.", () => JSON.parse(e));
48
- return n === void 0 ? null : F(n) ? n : (t.report("storage.degraded", "An emergency entry is not a batch. The library dropped it."), null);
49
- }
50
- async function ve(t, n) {
51
- let r = 0;
52
- for (let i of R(p, n)) {
53
- let a = n.guard("storage.unavailable", "The library could not read the emergency queue.", () => {
54
- let e = localStorage.getItem(i);
55
- return localStorage.removeItem(i), e;
47
+ return n === void 0 ? null : E(n) ? n : (t.report("storage.degraded", "An emergency entry is not a batch. The library dropped it."), null);
48
+ }
49
+ async function ve(e, t) {
50
+ let n = 0;
51
+ for (let r of F(p, t)) {
52
+ let i = t.guard("storage.unavailable", "The library could not read the emergency queue.", () => {
53
+ let e = localStorage.getItem(r);
54
+ return localStorage.removeItem(r), e;
56
55
  });
57
- if (!a) continue;
58
- let o = _e(a, n);
59
- if (o !== null) try {
60
- await T(t.save(o), e), r++;
56
+ if (!i) continue;
57
+ let a = L(i, t);
58
+ if (a !== null) try {
59
+ await O(e.save(a), S), n++;
61
60
  } catch (e) {
62
- n.report("storage.degraded", "The library could not recover an emergency batch.", { key: i }, e);
61
+ t.report("storage.degraded", "The library could not recover an emergency batch.", { key: r }, e);
63
62
  }
64
63
  }
65
- return r;
64
+ return n;
66
65
  }
67
- function z(e, t) {
68
- let n = `writing the emergency queue, ${String(e.records.length)} records`;
69
- t.guard("storage.quota_exceeded", n, () => {
70
- let n = R(p, t);
71
- for (let e of n.slice(0, Math.max(0, n.length - 20 + 1))) localStorage.removeItem(e);
72
- localStorage.setItem(ge(e), JSON.stringify(e));
66
+ function R(e, t, n) {
67
+ let r = `writing the emergency queue, ${String(e.records.length)} records`, i = [], a = t.guard("storage.quota_exceeded", r, () => {
68
+ let n = F(p, t);
69
+ for (let e of n.slice(0, Math.max(0, n.length - 20 + 1))) {
70
+ let n = L(String(localStorage.getItem(e)), t);
71
+ n !== null && i.push(n), localStorage.removeItem(e);
72
+ }
73
+ return localStorage.setItem(I(e), JSON.stringify(e)), !0;
74
+ });
75
+ t.guard("pipeline.crashed", "The loss report of the emergency queue failed.", () => {
76
+ if (i.length > 0) {
77
+ let e = i.flatMap((e) => e.records);
78
+ n?.("exit_queue_full", e, i.map((e) => e.id));
79
+ }
80
+ a !== !0 && n?.("quota", e.records, [e.id]);
73
81
  });
74
82
  }
75
83
  async function ye(e, t) {
76
- return await L("ui-observability.emergency", t, () => ve(e, t), { skipIfBusy: !1 }) ?? 0;
84
+ return await P("ui-observability.emergency", t, () => ve(e, t), { skipIfBusy: !1 }) ?? 0;
85
+ }
86
+ //#endregion
87
+ //#region src/storage/eviction.ts
88
+ function z(e) {
89
+ return Array.isArray(e.records) && e.records.some(_e);
90
+ }
91
+ var B = class {
92
+ howMany;
93
+ isAudit;
94
+ plain = [];
95
+ audit = [];
96
+ constructor(e, t) {
97
+ this.howMany = e, this.isAudit = t;
98
+ }
99
+ add(e) {
100
+ return this.isAudit(e) ? this.audit.length < this.howMany && this.audit.push(e) : this.plain.push(e), this.plain.length < this.howMany;
101
+ }
102
+ picked() {
103
+ return [...this.plain, ...this.audit].slice(0, this.howMany);
104
+ }
105
+ };
106
+ function V(e, t, n) {
107
+ let r = new B(t, n);
108
+ for (let t of e) if (!r.add(t)) break;
109
+ return r.picked();
77
110
  }
78
111
  //#endregion
79
112
  //#region src/storage/local-storage.ts
80
113
  function be(e) {
81
114
  let t = String(e.createdAt).padStart(14, "0");
82
- return `${C}${t}.${e.id}`;
115
+ return `${_}${t}.${e.id}`;
83
116
  }
84
117
  function xe(e) {
85
- let t = C.length, n = Number(e.slice(t, t + 14));
118
+ let t = _.length, n = Number(e.slice(t, t + 14));
86
119
  return Number.isFinite(n) ? n : null;
87
120
  }
88
121
  var Se = class {
89
122
  limits;
90
123
  diagnostics;
91
124
  onGap;
92
- name = de;
125
+ name = ne;
93
126
  constructor(e, t, n) {
94
127
  this.limits = e, this.diagnostics = t, this.onGap = n;
95
128
  }
@@ -98,7 +131,7 @@ var Se = class {
98
131
  batches: 1,
99
132
  records: e.records.length,
100
133
  reason: "quota"
101
- }));
134
+ }, [e]));
102
135
  }
103
136
  take(e) {
104
137
  let t = [];
@@ -125,20 +158,14 @@ var Se = class {
125
158
  batches: 0,
126
159
  records: 0,
127
160
  reason: "expired"
128
- }, n = (e) => {
129
- let n = this.read(e);
130
- this.removeKey(e), t.batches++, t.records += n?.records.length ?? 0;
131
- }, r = [];
161
+ }, n = [], r = [];
132
162
  for (let t of this.keys()) {
133
163
  let i = xe(t);
134
- i === null || i < e ? n(t) : r.push(t);
164
+ i === null || i < e ? n.push(t) : r.push(t);
135
165
  }
166
+ this.drop(t, "expired", [...this.entries(n)]);
136
167
  let i = r.length - this.limits.maxBatches;
137
- if (i > 0) {
138
- t.reason = "over_capacity";
139
- for (let e of r.slice(0, i)) n(e);
140
- }
141
- return this.reportGap(t), Promise.resolve(t);
168
+ return i > 0 && this.drop(t, "over_capacity", this.evictable(r, i)), Promise.resolve(t);
142
169
  }
143
170
  count() {
144
171
  return Promise.resolve(this.keys().length);
@@ -157,21 +184,36 @@ var Se = class {
157
184
  batches: 0,
158
185
  records: 0,
159
186
  reason: "quota"
187
+ }, n = Math.ceil(e.length / 4);
188
+ this.drop(t, "quota", this.evictable(e, n));
189
+ }
190
+ evictable(e, t) {
191
+ return V(this.entries(e), t, (e) => e.batch !== null && z(e.batch));
192
+ }
193
+ *entries(e) {
194
+ for (let t of e) yield {
195
+ key: t,
196
+ batch: this.read(t)
160
197
  };
161
- for (let n of e.slice(0, Math.ceil(e.length / 4))) {
162
- let e = this.read(n);
163
- this.removeKey(n), t.batches++, t.records += e?.records.length ?? 0;
164
- }
165
- this.reportGap(t);
166
198
  }
167
- reportGap(e) {
168
- e.batches !== 0 && (this.diagnostics.report("storage.evicted", `The library dropped ${String(e.batches)} stored batches (${String(e.records)} records).`, { ...e }), this.onGap?.(e));
199
+ drop(e, t, n) {
200
+ if (n.length === 0) return;
201
+ let r = [], i = 0;
202
+ for (let { key: e, batch: t } of n) this.removeKey(e), i += t?.records.length ?? 0, t && r.push(t);
203
+ e.batches += n.length, e.records += i, e.reason = t, this.reportGap({
204
+ batches: n.length,
205
+ records: i,
206
+ reason: t
207
+ }, r);
208
+ }
209
+ reportGap(e, t) {
210
+ this.diagnostics.report("storage.evicted", `The library dropped ${String(e.batches)} stored batches (${String(e.records)} records).`, { ...e }), this.onGap?.(e, t);
169
211
  }
170
212
  read(e) {
171
213
  let t = this.diagnostics.guard("storage.unavailable", "The library could not read a stored batch.", () => localStorage.getItem(e));
172
214
  if (!t) return null;
173
215
  let n = this.diagnostics.guard("storage.degraded", "A stored batch is corrupt. The library removed it.", () => JSON.parse(t));
174
- return n === void 0 ? null : F(n) ? n : (this.diagnostics.report("storage.degraded", "A stored entry is not a batch. The library dropped it."), null);
216
+ return n === void 0 ? null : E(n) ? n : (this.diagnostics.report("storage.degraded", "A stored entry is not a batch. The library dropped it."), null);
175
217
  }
176
218
  keyOf(e) {
177
219
  return this.keys().find((t) => t.endsWith(`.${e}`)) ?? null;
@@ -185,18 +227,18 @@ var Se = class {
185
227
  });
186
228
  }
187
229
  keys() {
188
- return R(C, this.diagnostics);
230
+ return F(_, this.diagnostics);
189
231
  }
190
232
  };
191
233
  //#endregion
192
234
  //#region src/storage/memory-storage.ts
193
- function B(e) {
235
+ function Ce(e) {
194
236
  return e.reduce((e, t) => e + t.records.length, 0);
195
237
  }
196
- var V = class {
238
+ var H = class {
197
239
  limits;
198
240
  onGap;
199
- name = x;
241
+ name = se;
200
242
  batches = [];
201
243
  constructor(e, t) {
202
244
  this.limits = e, this.onGap = t;
@@ -220,14 +262,22 @@ var V = class {
220
262
  records: 0,
221
263
  reason: "expired"
222
264
  }, n = this.batches.filter((t) => t.createdAt < e);
223
- this.batches = this.batches.filter((t) => t.createdAt >= e), t.batches += n.length, t.records += B(n);
265
+ this.batches = this.batches.filter((t) => t.createdAt >= e), this.report(t, "expired", n);
224
266
  let r = this.batches.length - this.limits.maxBatches;
225
267
  if (r > 0) {
226
- t.reason = "over_capacity";
227
- let e = this.batches.slice(0, r);
228
- this.batches = this.batches.slice(r), t.batches += e.length, t.records += B(e);
268
+ let e = V(this.batches, r, z);
269
+ this.batches = this.batches.filter((t) => !e.includes(t)), this.report(t, "over_capacity", e);
229
270
  }
230
- return t.batches > 0 && this.onGap?.(t), Promise.resolve(t);
271
+ return Promise.resolve(t);
272
+ }
273
+ report(e, t, n) {
274
+ if (n.length === 0) return;
275
+ let r = Ce(n);
276
+ e.batches += n.length, e.records += r, e.reason = t, this.onGap?.({
277
+ batches: n.length,
278
+ records: r,
279
+ reason: t
280
+ }, n);
231
281
  }
232
282
  count() {
233
283
  return Promise.resolve(this.batches.length);
@@ -238,9 +288,13 @@ var V = class {
238
288
  close() {
239
289
  return this.batches = [], Promise.resolve();
240
290
  }
241
- }, Ce = {
242
- name: h,
243
- save: () => Promise.resolve(),
291
+ }, we = (e) => ({
292
+ name: ce,
293
+ save: (t) => (e?.({
294
+ batches: 1,
295
+ records: t.records.length,
296
+ reason: "not_stored"
297
+ }, [t]), Promise.resolve()),
244
298
  take: () => Promise.resolve([]),
245
299
  remove: () => Promise.resolve(),
246
300
  bumpAttempts: () => Promise.resolve(),
@@ -252,31 +306,31 @@ var V = class {
252
306
  count: () => Promise.resolve(0),
253
307
  clear: () => Promise.resolve(),
254
308
  close: () => Promise.resolve()
255
- };
256
- function we(e) {
309
+ });
310
+ function Te(e) {
257
311
  return e.guard("storage.unavailable", "The library could not read indexedDB.", () => globalThis.indexedDB != null) === !0;
258
312
  }
259
- function Te(e) {
260
- return e.guard("storage.unavailable", "The library could not write a test key to localStorage.", () => (localStorage.setItem(S, "1"), localStorage.removeItem(S), !0)) === !0;
313
+ function Ee(e) {
314
+ return e.guard("storage.unavailable", "The library could not write a test key to localStorage.", () => (localStorage.setItem(v, "1"), localStorage.removeItem(v), !0)) === !0;
261
315
  }
262
- async function Ee(e, t, n, r, i) {
263
- if (e === "none") return Ce;
264
- if (e === "memory") return new V(n, i);
316
+ async function De(e, t, n, r, i) {
317
+ if (e === "none") return we(i);
318
+ if (e === "memory") return new H(n, i);
265
319
  if (e === "indexeddb" || e === "auto") {
266
- if (we(r)) {
320
+ if (Te(r)) {
267
321
  let e = await r.guardAsync("storage.unavailable", "The library could not open IndexedDB.", async () => {
268
- let { IndexedDbStorage: e } = await import("./indexeddb-storage-uD4oaRMc.js"), a = new e(t, n, r, i);
322
+ let { IndexedDbStorage: e } = await import("./indexeddb-storage-B8SGUzSV.js"), a = new e(t, n, r, i);
269
323
  return await a.open(), a;
270
324
  });
271
325
  if (e) return e;
272
326
  }
273
- if (e === "indexeddb") return r.report("storage.degraded", "IndexedDB is not available. The library uses memory storage instead."), new V(n, i);
327
+ if (e === "indexeddb") return r.report("storage.degraded", "IndexedDB is not available. The library uses memory storage instead."), new H(n, i);
274
328
  }
275
- return Te(r) ? new Se(n, r, i) : (r.report("storage.degraded", "No persistent storage is available. The library keeps undelivered records in memory only."), new V(n, i));
329
+ return Ee(r) ? new Se(n, r, i) : (r.report("storage.degraded", "No persistent storage is available. The library keeps undelivered records in memory only."), new H(n, i));
276
330
  }
277
331
  //#endregion
278
332
  //#region src/transport/errors.ts
279
- var H = class extends Error {
333
+ var U = class extends Error {
280
334
  kind;
281
335
  status;
282
336
  retryAfterMs;
@@ -285,77 +339,77 @@ var H = class extends Error {
285
339
  super(t, a === void 0 ? void 0 : { cause: a }), this.kind = e, this.status = n, this.retryAfterMs = r, this.maxBytes = i, this.name = "TransportError";
286
340
  }
287
341
  };
288
- function De(e) {
342
+ function Oe(e) {
289
343
  if (!e) return;
290
344
  let t = Number(e);
291
- if (Number.isFinite(t)) return Math.max(0, t * ce);
345
+ if (Number.isFinite(t)) return Math.max(0, t * ie);
292
346
  let n = Date.parse(e);
293
347
  return Number.isNaN(n) ? void 0 : Math.max(0, n - Date.now());
294
348
  }
295
349
  //#endregion
296
350
  //#region src/transport/serializers/ecs.ts
297
- function Oe(e) {
298
- return b.test(e) ? Number(BigInt(e) / y) : Date.now();
299
- }
300
351
  function ke(e) {
352
+ return C.test(e) ? Number(BigInt(e) / ue) : Date.now();
353
+ }
354
+ function Ae(e) {
301
355
  return typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? e : typeof e == "bigint" ? e.toString() : null;
302
356
  }
303
- function Ae(e, t, n) {
357
+ function je(e, t, n) {
304
358
  let r = e[t];
305
359
  r === void 0 ? e[t] = n : Array.isArray(r) ? r.push(n) : e[t] = [r, n];
306
360
  }
307
- function U(e, t, n, r) {
308
- let i = ke(n);
309
- if (i !== null) Ae(e, t, i);
361
+ function W(e, t, n, r) {
362
+ let i = Ae(n);
363
+ if (i !== null) je(e, t, i);
310
364
  else if (typeof n == "object" && n && !r.has(n)) {
311
- if (r.add(n), Array.isArray(n)) for (let i of n) U(e, t, i, r);
312
- else for (let [i, a] of Object.entries(n)) U(e, `${t}.${i}`, a, r);
365
+ if (r.add(n), Array.isArray(n)) for (let i of n) W(e, t, i, r);
366
+ else for (let [i, a] of Object.entries(n)) W(e, `${t}.${i}`, a, r);
313
367
  r.delete(n);
314
368
  }
315
369
  }
316
- function W(e) {
370
+ function G(e) {
317
371
  let t = Object.create(null), n = /* @__PURE__ */ new WeakSet();
318
- for (let [r, i] of Object.entries(e)) U(t, r, i, n);
372
+ for (let [r, i] of Object.entries(e)) W(t, r, i, n);
319
373
  return t;
320
374
  }
321
- var je = {
375
+ var Me = {
322
376
  name: "ecs",
323
377
  serialize(e) {
324
378
  return {
325
379
  body: `${e.map((e) => {
326
- let t = Oe(e.timeUnixNano);
380
+ let t = ke(e.timeUnixNano);
327
381
  return JSON.stringify({
328
382
  "@timestamp": new Date(t).toISOString(),
329
383
  message: e.body,
330
- log: { level: s[e.severityText] ?? e.severityText.toLowerCase() },
384
+ log: { level: de[e.severityText] ?? e.severityText.toLowerCase() },
331
385
  trace: { id: e.traceId },
332
386
  span: { id: e.spanId },
333
387
  service: {
334
- name: e.resource[f],
335
- version: e.resource[i],
336
- environment: e.resource[n]
388
+ name: e.resource[s],
389
+ version: e.resource[f],
390
+ environment: e.resource[u]
337
391
  },
338
- user_agent: { original: e.resource[d] },
392
+ user_agent: { original: e.resource[ae] },
339
393
  url: { full: e.attributes["url.full"] ?? e.attributes["page.url"] },
340
394
  labels: {
341
- ...W(e.resource),
342
- ...W(e.attributes)
395
+ ...G(e.resource),
396
+ ...G(e.attributes)
343
397
  }
344
398
  });
345
399
  }).join("\n")}\n`,
346
- contentType: ie
400
+ contentType: c
347
401
  };
348
402
  }
349
403
  };
350
404
  //#endregion
351
405
  //#region src/transport/serializers/otlp.ts
352
- function G(e) {
353
- return e == null ? null : typeof e == "string" ? { stringValue: e } : typeof e == "boolean" ? { boolValue: e } : typeof e == "number" ? Number.isInteger(e) ? { intValue: String(e) } : { doubleValue: e } : typeof e == "bigint" ? { intValue: e.toString() } : Array.isArray(e) ? { arrayValue: { values: e.map(G).filter((e) => e !== null) } } : typeof e == "object" ? { kvlistValue: { values: K(e) } } : null;
354
- }
355
406
  function K(e) {
407
+ return e == null ? null : typeof e == "string" ? { stringValue: e } : typeof e == "boolean" ? { boolValue: e } : typeof e == "number" ? Number.isSafeInteger(e) ? { intValue: String(e) } : { doubleValue: e } : typeof e == "bigint" ? { intValue: e.toString() } : Array.isArray(e) ? { arrayValue: { values: e.map(K).filter((e) => e !== null) } } : typeof e == "object" ? { kvlistValue: { values: q(e) } } : null;
408
+ }
409
+ function q(e) {
356
410
  let t = [];
357
411
  for (let [n, r] of Object.entries(e)) {
358
- let e = G(r);
412
+ let e = K(r);
359
413
  e && t.push({
360
414
  key: n,
361
415
  value: e
@@ -363,30 +417,30 @@ function K(e) {
363
417
  }
364
418
  return t;
365
419
  }
366
- var q = /* @__PURE__ */ new WeakMap();
367
- function Me(e) {
368
- let t = q.get(e);
420
+ var J = /* @__PURE__ */ new WeakMap();
421
+ function Ne(e) {
422
+ let t = J.get(e);
369
423
  if (t !== void 0) return t;
370
424
  let n = JSON.stringify(e);
371
- return q.set(e, n), n;
425
+ return J.set(e, n), n;
372
426
  }
373
- var Ne = {
374
- name: ue,
427
+ var Pe = {
428
+ name: te,
375
429
  serialize(e) {
376
430
  let t = /* @__PURE__ */ new Map();
377
431
  for (let n of e) {
378
- let e = Me(n.resource), r = t.get(e);
432
+ let e = Ne(n.resource), r = t.get(e);
379
433
  r ? r.records.push(n) : t.set(e, {
380
434
  resource: n.resource,
381
435
  records: [n]
382
436
  });
383
437
  }
384
438
  let n = [...t.values()].map((e) => ({
385
- resource: { attributes: K(e.resource) },
439
+ resource: { attributes: q(e.resource) },
386
440
  scopeLogs: [{
387
441
  scope: {
388
- name: oe,
389
- version: fe
442
+ name: b,
443
+ version: re
390
444
  },
391
445
  logRecords: e.records.map((e) => ({
392
446
  timeUnixNano: e.timeUnixNano,
@@ -397,24 +451,24 @@ var Ne = {
397
451
  traceId: e.traceId,
398
452
  spanId: e.spanId,
399
453
  flags: e.traceFlags,
400
- attributes: K(e.attributes)
454
+ attributes: q(e.attributes)
401
455
  }))
402
456
  }]
403
457
  }));
404
458
  return {
405
459
  body: JSON.stringify({ resourceLogs: n }),
406
- contentType: u
460
+ contentType: x
407
461
  };
408
462
  }
409
463
  };
410
464
  //#endregion
411
465
  //#region src/transport/serializers/select.ts
412
- function Pe(e) {
413
- return e === "otlp" ? Ne : e === "ecs" ? je : e;
466
+ function Fe(e) {
467
+ return e === "otlp" ? Pe : e === "ecs" ? Me : e;
414
468
  }
415
- function J(e, t, n, r) {
469
+ function Y(e, t, n, r) {
416
470
  try {
417
- return Pe(e).serialize(t.records);
471
+ return Fe(e).serialize(t.records);
418
472
  } catch (e) {
419
473
  n.report("transport.serialize_failed", r, { batchId: t.id }, e);
420
474
  return;
@@ -422,19 +476,21 @@ function J(e, t, n, r) {
422
476
  }
423
477
  //#endregion
424
478
  //#region src/transport/status-transport.ts
425
- var Y = class {
479
+ var X = class {
426
480
  config;
427
481
  diagnostics;
428
482
  onSampling;
483
+ onLoss;
429
484
  throttledUntil = 0;
430
- constructor(e, t, n = () => void 0) {
431
- this.config = e, this.diagnostics = t, this.onSampling = n;
485
+ constructor(e, t, n = () => void 0, r = () => void 0) {
486
+ this.config = e, this.diagnostics = t, this.onSampling = n, this.onLoss = r;
432
487
  }
433
488
  throttledForMs() {
434
489
  return Math.max(0, this.throttledUntil - Date.now());
435
490
  }
436
491
  serialize(e) {
437
- return J(this.config.serializer, e, this.diagnostics, "The serializer threw an error. The library dropped the batch.");
492
+ let t = Y(this.config.serializer, e, this.diagnostics, "The serializer threw an error. The library dropped the batch.");
493
+ return t || this.onLoss("unserializable", e.records, [e.id]), t;
438
494
  }
439
495
  accept(e) {
440
496
  this.throttledUntil = 0, this.config.sampling.remote && e != null && this.onSampling(e);
@@ -446,22 +502,22 @@ var Y = class {
446
502
  return this.diagnostics.report("transport.rejected_credentials", `The server returned ${r}.${t}`, {
447
503
  status: e,
448
504
  endpoint: this.config.endpoint
449
- }), new H("permanent", `The server rejected the batch with ${r}.`, e);
505
+ }), new U("permanent", `The server rejected the batch with ${r}.`, e);
450
506
  }
451
- if (e === 413) return new H("too_large", "The payload is too large.", e, void 0, n.maxBytes);
507
+ if (e === 413) return new U("too_large", "The payload is too large.", e, void 0, n.maxBytes);
452
508
  if (e === 429 || e === 503) {
453
- let t = e === 429;
454
- return this.throttledUntil = Date.now() + (n.retryAfterMs ?? 2e3), t && this.diagnostics.report("transport.throttled", "The server throttles the requests.", { retryAfterMs: n.retryAfterMs }), new H("throttled", t ? "The server throttles the requests." : "The service is not available.", e, n.retryAfterMs);
509
+ let t = e === 429, r = n.retryAfterMs === void 0 ? void 0 : Math.min(n.retryAfterMs, o);
510
+ return this.throttledUntil = Date.now() + (r ?? 2e3), t && this.diagnostics.report("transport.throttled", "The server throttles the requests.", { retryAfterMs: r }), new U("throttled", t ? "The server throttles the requests." : "The service is not available.", e, r);
455
511
  }
456
- return e === 408 || e >= 500 ? new H("transient", `The server returned the error ${r}.`, e) : (this.diagnostics.report("transport.dropped_permanent", `The server rejected the batch with ${r}. The library dropped it.`, {
512
+ return e === 408 || e >= 500 ? new U("transient", `The server returned the error ${r}.`, e) : (this.diagnostics.report("transport.dropped_permanent", `The server rejected the batch with ${r}. The library dropped it.`, {
457
513
  batchId: t,
458
514
  status: e
459
- }), new H("permanent", `The server rejected the batch with ${r}.`, e));
515
+ }), new U("permanent", `The server rejected the batch with ${r}.`, e));
460
516
  }
461
517
  };
462
518
  //#endregion
463
519
  //#region src/transport/custom-transport.ts
464
- function X(e, t) {
520
+ function Z(e, t) {
465
521
  return {
466
522
  body: t.body,
467
523
  contentType: t.contentType,
@@ -470,36 +526,36 @@ function X(e, t) {
470
526
  records: e.records
471
527
  };
472
528
  }
473
- function Fe(e) {
529
+ function Ie(e) {
474
530
  if (typeof e != "object" || !e) return !1;
475
531
  let t = Reflect.get(e, "status");
476
532
  return typeof t == "number" && Number.isInteger(t) && t >= 100 && t <= 599;
477
533
  }
478
- function Z(e) {
534
+ function Q(e) {
479
535
  return typeof e == "number" && Number.isFinite(e) ? Math.max(0, e) : void 0;
480
536
  }
481
- var Ie = class extends Y {
537
+ var Le = class extends X {
482
538
  async send(e) {
483
- let { transport: t } = this.config;
484
- if (!t || e.records.length === 0) return;
485
- let n = this.serialize(e);
486
- if (!n) return;
487
- let i = X(e, n), a;
539
+ let { transport: n } = this.config;
540
+ if (!n || e.records.length === 0) return;
541
+ let r = this.serialize(e);
542
+ if (!r) return;
543
+ let i = Z(e, r), a;
488
544
  try {
489
- a = await T(P(() => k(() => t(i))), r);
545
+ a = await O(D(() => me(() => n(i))), t);
490
546
  } catch (e) {
491
- let t = e instanceof he ? e : void 0;
492
- throw new H(t ? "timeout" : "transient", t?.message ?? "The custom transport failed.", void 0, void 0, void 0, e);
547
+ let t = e instanceof A ? e : void 0;
548
+ throw new U(t ? "timeout" : "transient", t?.message ?? "The custom transport failed.", void 0, void 0, void 0, e);
493
549
  }
494
- if (!Fe(a)) throw this.diagnostics.report("transport.http_error", "The custom transport returned no valid status. The library sends the batch again later.", { batchId: e.id }), new H("transient", "The custom transport returned no valid status.");
550
+ if (!Ie(a)) throw this.diagnostics.report("transport.http_error", "The custom transport returned no valid status. The library sends the batch again later.", { batchId: e.id }), new U("transient", "The custom transport returned no valid status.");
495
551
  let { status: o } = a;
496
552
  if (o >= 200 && o < 300) this.accept(a.sampling);
497
553
  else throw this.reject(o, e.id, {
498
- retryAfterMs: Z(a.retryAfterMs),
499
- maxBytes: Z(a.maxBytes)
554
+ retryAfterMs: Q(a.retryAfterMs),
555
+ maxBytes: Q(a.maxBytes)
500
556
  });
501
557
  }
502
- }, Le = class {
558
+ }, Re = class {
503
559
  deps;
504
560
  installed = !1;
505
561
  onVisibility = () => {
@@ -534,38 +590,58 @@ var Ie = class extends Y {
534
590
  });
535
591
  }
536
592
  flush(e) {
537
- let { config: t, diagnostics: n } = this.deps;
593
+ let { config: t, diagnostics: r } = this.deps;
594
+ if (e === "hidden") {
595
+ this.flushAlive();
596
+ return;
597
+ }
538
598
  if (t.transport) {
539
599
  this.flushCustom(e, t.transportOnExit);
540
600
  return;
541
601
  }
542
- let r = this.endpointUrl();
543
- if (r === null) return;
544
- let i = this.drain(e);
545
- if (!i || i.records.length === 0) return;
546
- let a = this.serialize(i, e);
547
- if (!a) return;
548
- if (A(a.body) > 6e4) {
549
- z(i, n);
602
+ let i = this.endpointUrl();
603
+ if (i === null) return;
604
+ let a = this.deps.drainForExit();
605
+ if (!a || a.records.length === 0) return;
606
+ let o = this.serialize(a, e);
607
+ if (!o) return;
608
+ if (T(o.body) > 6e4) {
609
+ R(a, r, this.deps.onLoss);
610
+ return;
611
+ }
612
+ i.searchParams.set(n, a.id), i.searchParams.set(w, e);
613
+ let s = i.toString(), c = this.deps.exitHeaders();
614
+ if (c) {
615
+ this.keepaliveFetch(s, a, o.body, e, () => {
616
+ let e = new Headers(c);
617
+ return e.set(g, o.contentType), e.set(h, a.id), e;
618
+ });
619
+ return;
620
+ }
621
+ if (t.headers) {
622
+ R(a, r, this.deps.onLoss);
550
623
  return;
551
624
  }
552
- r.searchParams.set(g, i.id), r.searchParams.set(me, e);
553
- let o = r.toString(), s = this.beacon(o, a.body);
554
- s !== "sent" && (s === "refused" ? z(i, n) : this.keepaliveFetch(o, a.body, e));
625
+ let u = this.beacon(s, o.body);
626
+ u !== "sent" && (u === "refused" ? R(a, r, this.deps.onLoss) : this.keepaliveFetch(s, a, o.body, e, () => new Headers({ [g]: l })));
627
+ }
628
+ flushAlive() {
629
+ let { diagnostics: e } = this.deps, t = "The flush of the hidden document failed.";
630
+ e.guard("pipeline.crashed", t, () => {
631
+ Promise.resolve(this.deps.flushAlive()).catch((n) => {
632
+ e.report("pipeline.crashed", t, void 0, n);
633
+ });
634
+ });
555
635
  }
556
636
  flushCustom(e, t) {
557
- let { diagnostics: n } = this.deps;
558
- if (e === "hidden" && !t) return;
559
- let r = this.drain(e);
637
+ let { diagnostics: n } = this.deps, r = this.deps.drainForExit();
560
638
  if (!r || r.records.length === 0) return;
561
639
  let i = this.serialize(r, e);
562
- i && (t === void 0 || n.guard("transport.http_error", "The transportOnExit hook threw an error.", () => P(() => t(X(r, i)))) !== !0) && z(r, n);
640
+ i && (t === void 0 || n.guard("transport.http_error", "The transportOnExit hook threw an error.", () => D(() => t(Z(r, i)))) !== !0) && R(r, n, this.deps.onLoss);
563
641
  }
564
642
  serialize(e, t) {
565
- return J(this.deps.config.serializer, e, this.deps.diagnostics, `The ${t} exit flush could not serialize its batch.`);
566
- }
567
- drain(e) {
568
- return e === "hidden" ? this.deps.drainPending() : this.deps.drainForExit();
643
+ let n = Y(this.deps.config.serializer, e, this.deps.diagnostics, `The ${t} exit flush could not serialize its batch.`);
644
+ return n || this.deps.onLoss?.("unserializable", e.records, [e.id]), n;
569
645
  }
570
646
  endpointUrl() {
571
647
  let { endpoint: e } = this.deps.config;
@@ -577,109 +653,148 @@ var Ie = class extends Y {
577
653
  return n?.sendBeacon ? n.sendBeacon(e, new Blob([t], { type: "text/plain;charset=UTF-8" })) ? "sent" : "refused" : "unavailable";
578
654
  }) ?? "unavailable";
579
655
  }
580
- keepaliveFetch(e, n, r) {
581
- let { config: i, diagnostics: a } = this.deps;
582
- a.guard("transport.http_error", "The keepalive fetch fallback failed.", () => {
583
- fetch(e, {
584
- method: "POST",
585
- body: n,
586
- headers: { [c]: t },
587
- credentials: i.credentials,
588
- keepalive: !0
589
- }).catch((e) => {
590
- a.report("transport.http_error", "The exit flush failed.", { reason: r }, e);
591
- });
592
- });
656
+ keepaliveFetch(e, t, n, r, i) {
657
+ let { config: a, diagnostics: o } = this.deps, s = () => {
658
+ R(t, o, this.deps.onLoss);
659
+ };
660
+ o.guard("transport.http_error", "The keepalive fetch failed.", () => (fetch(e, {
661
+ method: "POST",
662
+ body: n,
663
+ headers: i(),
664
+ credentials: a.credentials,
665
+ keepalive: !0
666
+ }).catch((e) => {
667
+ o.report("transport.http_error", "The exit flush failed.", { reason: r }, e), s();
668
+ }), !0)) !== !0 && s();
593
669
  }
594
670
  };
595
671
  //#endregion
596
672
  //#region src/transport/compression.ts
597
- async function Re(e) {
673
+ async function ze(e) {
598
674
  let t = globalThis.CompressionStream;
599
675
  if (t === void 0) return null;
600
- let n = new Blob([e]).stream().pipeThrough(new t(w)), r = await new Response(n).arrayBuffer();
676
+ let n = new Blob([e]).stream().pipeThrough(new t(i)), r = await new Response(n).arrayBuffer();
601
677
  return new Uint8Array(r);
602
678
  }
603
679
  //#endregion
604
680
  //#region src/transport/http-transport.ts
605
- var Q = "In a cross-origin iframe, the session cookie is a third-party cookie. The browser often blocks it. Forward the records to the platform document. As an alternative, issue the cookie with the Partitioned attribute.", ze = class extends Y {
606
- async send(e) {
607
- let { endpoint: t } = this.config;
608
- t && e.records.length !== 0 && await this.post(e, t);
609
- }
610
- async post(e, t) {
611
- let n = this.serialize(e);
612
- if (!n) return;
613
- let r = new Headers(await this.resolveHeaders());
614
- r.set(c, n.contentType), r.set(l, e.id), r.set(a, String(e.attempts));
615
- let i = await this.encodeBody(n.body);
616
- typeof i != "string" && r.set(le, w);
617
- let o = await this.dispatch(t, r, i);
618
- if (o.ok) {
619
- this.accept(o.headers.get(ne));
681
+ var Be = "In a cross-origin iframe, the session cookie is a third-party cookie. The browser often blocks it. Forward the records to the platform document. As an alternative, issue the cookie with the Partitioned attribute.", Ve = class extends X {
682
+ cachedHeaders;
683
+ async send(e, t) {
684
+ let { endpoint: n } = this.config;
685
+ n && e.records.length !== 0 && await this.post(e, n, t);
686
+ }
687
+ lastHeaders() {
688
+ let { headers: e } = this.config;
689
+ if (!e) return;
690
+ if (typeof e != "function") return e;
691
+ let t = this.cachedHeaders;
692
+ return t?.source === e && t.endpoint === this.config.endpoint ? t.headers : void 0;
693
+ }
694
+ async post(t, n, r) {
695
+ let i = this.serialize(t);
696
+ if (!i) return;
697
+ let a = await this.attempt(t, n, i, r);
698
+ if (this.rejectsCredentials(a.status) && typeof this.config.headers == "function" && (this.cachedHeaders = void 0, a = await this.attempt(t, n, i, r)), a.ok) {
699
+ this.accept(a.headers.get(e));
620
700
  return;
621
701
  }
622
- let s = o.status, u = De(o.headers.get(re)), d = s === 413 ? await this.readMaxBytes(o) : void 0;
623
- throw this.reject(s, e.id, {
624
- retryAfterMs: u,
625
- maxBytes: d,
626
- advice: Q
702
+ let o = a.status, s = Oe(a.headers.get(d)), c = o === 413 ? await this.readMaxBytes(a) : void 0;
703
+ throw this.reject(o, t.id, {
704
+ retryAfterMs: s,
705
+ maxBytes: c,
706
+ advice: Be
627
707
  });
628
708
  }
709
+ rejectsCredentials(e) {
710
+ return e === 401 || e === 403;
711
+ }
712
+ async attempt(e, n, r, o) {
713
+ let s = Date.now() + t, c = new Headers(await this.before(this.resolveHeaders(n), s));
714
+ c.set(g, r.contentType), c.set(h, e.id), c.set(a, String(e.attempts));
715
+ let l = await this.before(this.encodeBody(r.body), s);
716
+ typeof l != "string" && c.set(ee, i);
717
+ let u = this.keepalive(l);
718
+ return u && o?.(), this.dispatch(n, c, l, s, u);
719
+ }
720
+ async before(e, t) {
721
+ try {
722
+ return await O(e, Math.max(0, t - Date.now()));
723
+ } catch {
724
+ throw this.timeout();
725
+ }
726
+ }
727
+ timeout() {
728
+ let e = `The request took longer than ${String(t)} ms.`;
729
+ return this.diagnostics.report("transport.timeout", e, { endpoint: this.config.endpoint }), new U("timeout", e);
730
+ }
629
731
  async encodeBody(e) {
630
732
  let { config: t } = this;
631
- return t.compression !== "gzip" || A(e) < 1024 ? e : await this.diagnostics.guardAsync("transport.http_error", "The library could not compress the payload.", () => Re(e)) ?? e;
733
+ return t.compression !== "gzip" || T(e) < 1024 ? e : await this.diagnostics.guardAsync("transport.http_error", "The library could not compress the payload.", () => ze(e)) ?? e;
632
734
  }
633
- async dispatch(e, t, n) {
634
- let { config: i } = this, a = new AbortController(), o = setTimeout(() => {
635
- a.abort();
636
- }, r);
637
- j(o);
735
+ async dispatch(e, t, n, r, i) {
736
+ let { config: a } = this, o = new AbortController(), s = setTimeout(() => {
737
+ o.abort();
738
+ }, Math.max(0, r - Date.now()));
739
+ k(s);
638
740
  try {
639
- return await P(() => fetch(e, {
741
+ return await D(() => fetch(e, {
640
742
  method: "POST",
641
743
  headers: t,
642
744
  body: n,
643
- credentials: i.credentials,
644
- signal: a.signal,
645
- cache: "no-store"
745
+ credentials: a.credentials,
746
+ signal: o.signal,
747
+ cache: "no-store",
748
+ keepalive: i
646
749
  }));
647
750
  } catch {
648
- if (a.signal.aborted) throw new H("timeout", `The request took longer than ${String(r)} ms.`);
751
+ if (o.signal.aborted) throw this.timeout();
649
752
  let e = globalThis.navigator?.onLine;
650
- throw new H(e === !1 ? "offline" : "transient", "A network error occurred.");
753
+ throw new U(e === !1 ? "offline" : "transient", "A network error occurred.");
651
754
  } finally {
652
- clearTimeout(o);
755
+ clearTimeout(s);
653
756
  }
654
757
  }
758
+ keepalive(e) {
759
+ let t = globalThis.document?.visibilityState === "hidden", n = typeof e == "string" ? T(e) : e.byteLength;
760
+ return t && n <= 6e4;
761
+ }
655
762
  async readMaxBytes(e) {
656
763
  return this.diagnostics.guardAsync("transport.http_error", "The library could not read the body of the 413 response.", async () => {
657
764
  let t = JSON.parse(await e.text());
658
765
  return typeof t.maxBytes == "number" ? t.maxBytes : void 0;
659
766
  });
660
767
  }
661
- async resolveHeaders() {
662
- let { headers: e } = this.config;
663
- return e ? typeof e == "function" ? await this.diagnostics.guardAsync("transport.http_error", "The headers() function threw an error.", () => Promise.resolve(e())) ?? {} : e : {};
664
- }
665
- }, Be = class {
768
+ async resolveHeaders(e) {
769
+ let { headers: t } = this.config;
770
+ if (!t) return {};
771
+ if (typeof t != "function") return t;
772
+ let n = await this.diagnostics.guardAsync("transport.http_error", "The headers() function threw an error.", () => Promise.resolve(t()));
773
+ return n && (this.cachedHeaders = {
774
+ source: t,
775
+ endpoint: e,
776
+ headers: n
777
+ }), n ?? {};
778
+ }
779
+ }, He = class {
666
780
  storage;
667
781
  transport;
668
782
  diagnostics;
669
- config;
670
783
  batchesPerDrain;
784
+ onLoss;
671
785
  timer = null;
672
786
  attempt = 0;
673
787
  draining = !1;
674
788
  stopped = !1;
789
+ maxAttempts;
675
790
  onOnline = () => {
676
791
  this.attempt = 0, this.schedule(0);
677
792
  };
678
- constructor(e, t, n, r, i = 20) {
679
- this.storage = e, this.transport = t, this.diagnostics = n, this.config = r, this.batchesPerDrain = i;
793
+ constructor(e, t, n, r, i = 20, a = () => void 0) {
794
+ this.storage = e, this.transport = t, this.diagnostics = n, this.batchesPerDrain = i, this.onLoss = a, this.maxAttempts = N(r.retention).maxAttempts;
680
795
  }
681
796
  start() {
682
- this.stopped = !1, typeof addEventListener < "u" && addEventListener("online", this.onOnline), this.schedule(o);
797
+ this.stopped = !1, typeof addEventListener < "u" && addEventListener("online", this.onOnline), this.schedule(r);
683
798
  }
684
799
  nudge() {
685
800
  this.draining || this.schedule(m);
@@ -698,23 +813,23 @@ var Q = "In a cross-origin iframe, the session cookie is a third-party cookie. T
698
813
  let t = setTimeout(() => {
699
814
  this.drain();
700
815
  }, e);
701
- this.timer = t, j(t);
816
+ this.timer = t, k(t);
702
817
  }
703
- bounded(t) {
704
- return T(t, e);
818
+ bounded(e) {
819
+ return O(e, S);
705
820
  }
706
821
  clearTimer() {
707
822
  this.timer !== null && (clearTimeout(this.timer), this.timer = null);
708
823
  }
709
824
  backoffMs() {
710
- let e = Math.min(m * 2 ** this.attempt, te);
825
+ let e = Math.min(m * 2 ** this.attempt, o);
711
826
  return Math.random() * e;
712
827
  }
713
828
  async drain() {
714
829
  if (!this.draining) {
715
830
  this.draining = !0;
716
831
  try {
717
- await L("ui-observability.drain", this.diagnostics, () => this.drainLocked()) !== !0 && this.schedule(o);
832
+ await P("ui-observability.drain", this.diagnostics, () => this.drainLocked()) !== !0 && this.schedule(r);
718
833
  } finally {
719
834
  this.draining = !1;
720
835
  }
@@ -722,25 +837,25 @@ var Q = "In a cross-origin iframe, the session cookie is a third-party cookie. T
722
837
  }
723
838
  async drainLocked() {
724
839
  try {
725
- if (globalThis.navigator?.onLine === !1) return this.schedule(o), !0;
840
+ if (globalThis.navigator?.onLine === !1) return this.schedule(r), !0;
726
841
  let e = await this.bounded(this.storage.take(this.batchesPerDrain));
727
- if (e.length === 0) return this.schedule(o), !0;
842
+ if (e.length === 0) return this.schedule(r), !0;
728
843
  for (let t of e) if (this.stopped || !await this.deliver(t)) return !0;
729
- return this.schedule(e.length === this.batchesPerDrain ? 0 : o), !0;
844
+ return this.schedule(e.length === this.batchesPerDrain ? 0 : r), !0;
730
845
  } catch (e) {
731
846
  return this.diagnostics.report("storage.degraded", "The drain loop threw an error.", void 0, e), this.attempt++, this.schedule(this.backoffMs()), !0;
732
847
  }
733
848
  }
734
849
  async deliver(e) {
735
- if (e.attempts >= _.maxAttempts) return this.diagnostics.report("storage.dead_lettered", `The library dropped a batch after ${e.attempts.toString()} attempts.`, {
850
+ if (e.attempts >= this.maxAttempts) return this.diagnostics.report("storage.dead_lettered", `The library dropped a batch after ${e.attempts.toString()} attempts.`, {
736
851
  batchId: e.id,
737
852
  records: e.records.length
738
- }), await this.bounded(this.storage.remove(e.id)), !0;
853
+ }), this.onLoss("max_attempts", e.records, [e.id]), await this.bounded(this.storage.remove(e.id)), !0;
739
854
  try {
740
855
  return await this.transport.send(e), await this.bounded(this.storage.remove(e.id)), this.attempt = 0, !0;
741
856
  } catch (t) {
742
- let n = t instanceof H ? t : void 0;
743
- return n?.kind === "permanent" || n?.kind === "too_large" ? (await this.replaceStored(e, t), !0) : n?.kind === "offline" ? (this.schedule(o), !1) : n?.kind === "throttled" ? (this.attempt++, this.schedule(n.retryAfterMs ?? this.backoffMs()), !1) : (await this.bounded(this.storage.bumpAttempts(e.id, e.attempts + 1)), this.attempt++, this.schedule(n?.retryAfterMs ?? this.backoffMs()), !1);
857
+ let n = t instanceof U ? t : void 0;
858
+ return n?.kind === "permanent" || n?.kind === "too_large" ? (await this.replaceStored(e, t), !0) : n?.kind === "offline" ? (this.schedule(r), !1) : n?.kind === "throttled" ? (this.attempt++, this.schedule(n.retryAfterMs ?? this.backoffMs()), !1) : (await this.bounded(this.storage.bumpAttempts(e.id, e.attempts + 1)), this.attempt++, this.schedule(n?.retryAfterMs ?? this.backoffMs()), !1);
744
859
  }
745
860
  }
746
861
  async replaceStored(e, t) {
@@ -749,10 +864,10 @@ var Q = "In a cross-origin iframe, the session cookie is a third-party cookie. T
749
864
  for (let e of n) await this.bounded(this.storage.save(e));
750
865
  }
751
866
  toStorable(e, t) {
752
- let n = t instanceof H ? t : void 0;
753
- if (n?.kind === "permanent") return [];
867
+ let n = t instanceof U ? t : void 0;
868
+ if (n?.kind === "permanent") return this.onLoss("rejected", e.records, [e.id]), [];
754
869
  if (n?.kind !== "too_large") return [e];
755
- let r = I(e, this.diagnostics);
870
+ let r = ge(e, this.diagnostics);
756
871
  return r ? (this.diagnostics.report("transport.batch_split", "The server refused the batch because it is too large.", {
757
872
  from: e.records.length,
758
873
  to: r[0].records.length,
@@ -760,24 +875,15 @@ var Q = "In a cross-origin iframe, the session cookie is a third-party cookie. T
760
875
  }), r) : (this.diagnostics.report("transport.dropped_permanent", "One record is larger than the server limit. The library dropped it.", {
761
876
  batchId: e.id,
762
877
  bodies: e.records.map((e) => e.body)
763
- }), []);
878
+ }), this.onLoss("rejected", e.records, [e.id]), []);
764
879
  }
765
880
  };
766
881
  //#endregion
767
882
  //#region src/core/pipeline.ts
768
- function Ve(e) {
769
- return e.attributes[ae] === pe;
770
- }
771
- var He = {
772
- logs: {
773
- flushIntervalMs: se,
774
- batchSize: 100
775
- },
776
- metrics: {
777
- flushIntervalMs: v,
778
- batchSize: 500
779
- }
780
- }, $ = class {
883
+ function Ue(e) {
884
+ return e.attributes[y] === oe;
885
+ }
886
+ var $ = class {
781
887
  options;
782
888
  onFlush;
783
889
  pending = [];
@@ -801,12 +907,12 @@ var He = {
801
907
  let e = setTimeout(() => {
802
908
  this.timer = null, this.onFlush(this);
803
909
  }, this.options.flushIntervalMs);
804
- this.timer = e, j(e);
910
+ this.timer = e, k(e);
805
911
  }
806
912
  clearTimer() {
807
913
  this.timer !== null && (clearTimeout(this.timer), this.timer = null);
808
914
  }
809
- }, Ue = class {
915
+ }, We = class {
810
916
  transport;
811
917
  storage;
812
918
  retry;
@@ -814,11 +920,12 @@ var He = {
814
920
  streams;
815
921
  unconfirmed = /* @__PURE__ */ new Map();
816
922
  queue = [];
817
- ceiling = new O();
923
+ open = /* @__PURE__ */ new Set();
924
+ ceiling = new pe();
818
925
  inFlight = 0;
819
926
  pumpScheduled = !1;
820
927
  stopped = !1;
821
- constructor(e, t, n, r, i = He) {
928
+ constructor(e, t, n, r, i) {
822
929
  this.transport = e, this.storage = t, this.retry = n, this.diagnostics = r;
823
930
  let a = (e) => {
824
931
  this.claim(e);
@@ -829,7 +936,7 @@ var He = {
829
936
  };
830
937
  }
831
938
  push(e) {
832
- this.stopped || (e.observedTimeUnixNano = D(), this.route(e));
939
+ this.stopped || (e.observedTimeUnixNano = fe(), this.route(e));
833
940
  }
834
941
  drainPending() {
835
942
  return this.toBatch([...this.streams.metrics.take(), ...this.streams.logs.take()]);
@@ -842,12 +949,17 @@ var He = {
842
949
  ...this.streams.logs.take()
843
950
  ]);
844
951
  }
952
+ async flushPending() {
953
+ this.enqueue(this.stopped ? null : this.drainPending()), await Promise.all([...this.open].map((e) => e.done));
954
+ }
845
955
  destroy() {
846
956
  this.stopped = !0, this.streams.logs.stop(), this.streams.metrics.stop(), this.queue.length = 0;
957
+ for (let e of this.open) e.resolve();
958
+ this.open.clear();
847
959
  }
848
960
  toBatch(e) {
849
961
  return e.length === 0 ? null : {
850
- id: E(this.diagnostics),
962
+ id: he(this.diagnostics),
851
963
  records: e,
852
964
  createdAt: Date.now(),
853
965
  attempts: 0
@@ -855,7 +967,7 @@ var He = {
855
967
  }
856
968
  route(e) {
857
969
  try {
858
- let t = Ve(e) ? this.streams.metrics : this.streams.logs;
970
+ let t = Ue(e) ? this.streams.metrics : this.streams.logs;
859
971
  if (!this.ceiling.allow(e)) {
860
972
  this.diagnostics.count("record.dropped_by_ceiling");
861
973
  return;
@@ -866,16 +978,18 @@ var He = {
866
978
  }
867
979
  }
868
980
  claim(e) {
869
- let t = e.take(), n = {
870
- id: E(this.diagnostics),
871
- records: t,
872
- createdAt: Date.now(),
873
- attempts: 0
874
- };
875
- this.unconfirmed.set(n.id, n), this.enqueue(n);
981
+ this.enqueue(this.toBatch(e.take()));
876
982
  }
877
983
  enqueue(e) {
878
- this.queue.push(e), !this.pumpScheduled && (this.pumpScheduled = !0, queueMicrotask(() => {
984
+ if (!e) return;
985
+ let t, n = {
986
+ batch: e,
987
+ done: new Promise((e) => {
988
+ t = e;
989
+ }),
990
+ resolve: t
991
+ };
992
+ this.unconfirmed.set(e.id, e), this.open.add(n), this.queue.push(n), !this.pumpScheduled && (this.pumpScheduled = !0, queueMicrotask(() => {
879
993
  this.pumpScheduled = !1, this.pump();
880
994
  }));
881
995
  }
@@ -887,12 +1001,13 @@ var He = {
887
1001
  }
888
1002
  }
889
1003
  async run(e) {
1004
+ let { batch: t } = e;
890
1005
  try {
891
- await this.dispatch(e);
892
- } catch (t) {
893
- this.diagnostics.report("pipeline.crashed", "A dispatch rejected its promise. This must not occur.", { batchId: e.id }, t);
1006
+ await this.dispatch(t);
1007
+ } catch (e) {
1008
+ this.diagnostics.report("pipeline.crashed", "A dispatch rejected its promise. This must not occur.", { batchId: t.id }, e);
894
1009
  } finally {
895
- this.inFlight--, this.pump();
1010
+ this.inFlight--, this.open.delete(e), e.resolve(), this.pump();
896
1011
  }
897
1012
  }
898
1013
  async dispatch(e) {
@@ -907,7 +1022,9 @@ var He = {
907
1022
  return;
908
1023
  }
909
1024
  try {
910
- await this.transport.send(e);
1025
+ await this.transport.send(e, () => {
1026
+ this.unconfirmed.delete(e.id);
1027
+ });
911
1028
  } catch (t) {
912
1029
  await this.storeFailed({
913
1030
  ...e,
@@ -926,67 +1043,67 @@ var He = {
926
1043
  await this.retry.storeFailed(e, t);
927
1044
  });
928
1045
  }
929
- async store(t) {
1046
+ async store(e) {
930
1047
  await this.diagnostics.guardAsync("storage.degraded", "The library could not store an undelivered batch.", async () => {
931
- await T(this.storage.save(t), e), this.retry.nudge();
1048
+ await O(this.storage.save(e), S), this.retry.nudge();
932
1049
  });
933
1050
  }
934
- }, We = class e {
1051
+ }, Ge = class e {
935
1052
  storage;
936
- transport;
937
1053
  retry;
938
1054
  pipeline;
939
1055
  exitFlush;
940
1056
  diagnostics;
941
- constructor(e, t, n, r, i, a) {
942
- this.storage = e, this.transport = t, this.retry = n, this.pipeline = r, this.exitFlush = i, this.diagnostics = a;
1057
+ constructor(e, t, n, r, i) {
1058
+ this.storage = e, this.retry = t, this.pipeline = n, this.exitFlush = r, this.diagnostics = i;
943
1059
  }
944
1060
  static async create(t) {
945
- let { config: n, diagnostics: r } = t, i = await Ee(n.storage, ee, _, r, t.onGap), a = (e) => {
946
- let i = M(e, r);
947
- i && N(t.remote, n, i);
948
- }, o = n.transport ? new Ie(n, r, a) : new ze(n, r, a), s = new Be(i, o, r, n), c = new Ue(o, i, s, r), l = new Le({
1061
+ let { config: n, diagnostics: r } = t, i = await De(n.storage, le, N(n.retention), r, t.onGap), a = (e) => {
1062
+ let i = j(e, r);
1063
+ i && M(t.remote, n, i);
1064
+ }, { onLoss: o } = t, s = n.transport ? void 0 : new Ve(n, r, a, o), c = s ?? new Le(n, r, a, o), l = new He(i, c, r, n, 20, o), { batching: u } = n, d = new We(c, i, l, r, {
1065
+ logs: {
1066
+ flushIntervalMs: u.logFlushIntervalMs,
1067
+ batchSize: u.logBatchSize
1068
+ },
1069
+ metrics: {
1070
+ flushIntervalMs: u.metricFlushIntervalMs,
1071
+ batchSize: u.metricBatchSize
1072
+ }
1073
+ }), f = new Re({
949
1074
  config: n,
950
1075
  diagnostics: r,
951
- drainForExit: () => c.drainForExit(),
952
- drainPending: () => c.drainPending()
953
- });
954
- await ye(i, r);
955
- let u = !1;
1076
+ drainForExit: () => d.drainForExit(),
1077
+ flushAlive: () => d.flushPending(),
1078
+ exitHeaders: () => s?.lastHeaders(),
1079
+ onLoss: o
1080
+ }), p = !1;
956
1081
  try {
957
- l.install(), s.start(), u = !0;
1082
+ f.install(), l.start(), p = !0;
958
1083
  } finally {
959
- u || (l.uninstall(), s.stop());
1084
+ p || (f.uninstall(), l.stop());
960
1085
  }
961
- return new e(i, o, s, c, l, r);
1086
+ let m = new e(i, l, d, f, r);
1087
+ return m.importEmergency(), m;
962
1088
  }
963
1089
  push(e) {
964
1090
  this.pipeline.push(e);
965
1091
  }
966
1092
  async flush() {
967
- let e = this.pipeline.drainPending();
968
- if (e) try {
969
- await this.transport.send(e);
970
- } catch (t) {
971
- await this.diagnostics.guardAsync("storage.degraded", "The library could not store the batch that flush() drained.", async () => {
972
- await this.retry.storeFailed({
973
- ...e,
974
- attempts: e.attempts + 1
975
- }, t);
976
- }), this.diagnostics.report("transport.http_error", "The send from flush() failed. The library stored the batch for a retry.", {
977
- batchId: e.id,
978
- records: e.records.length
979
- }, t);
980
- }
1093
+ await this.pipeline.flushPending();
981
1094
  }
982
1095
  async queueDepth() {
983
1096
  return await this.diagnostics.guardAsync("storage.degraded", "The library could not count the batches in storage.", () => this.storage.count()) ?? 0;
984
1097
  }
985
1098
  async destroy() {
986
- this.exitFlush.flush("shutdown"), this.exitFlush.uninstall(), this.retry.stop(), this.pipeline.destroy(), await this.storage.close();
1099
+ await this.diagnostics.guardAsync("pipeline.crashed", "The flush before shutdown failed.", () => this.flush()), this.exitFlush.flush("shutdown"), this.exitFlush.uninstall(), this.retry.stop(), this.pipeline.destroy(), await this.storage.close();
1100
+ }
1101
+ async importEmergency() {
1102
+ let e = await this.diagnostics.guardAsync("storage.degraded", "The emergency import failed.", () => ye(this.storage, this.diagnostics));
1103
+ e !== void 0 && e > 0 && this.retry.nudge();
987
1104
  }
988
1105
  };
989
1106
  //#endregion
990
- export { We as Sender };
1107
+ export { Ge as Sender, z as n, B as t };
991
1108
 
992
- //# sourceMappingURL=sender-G6v4Uqi4.js.map
1109
+ //# sourceMappingURL=sender-BBY0IcUo.js.map