@utk09/ui-observability 0.7.0 → 0.9.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.
Files changed (180) hide show
  1. package/CHANGELOG.md +79 -1
  2. package/README.md +170 -41
  3. package/dist/bus/bus.d.ts +75 -11
  4. package/dist/bus/links.d.ts +6 -3
  5. package/dist/bus-CtJWf9QN.cjs +2 -0
  6. package/dist/bus-CtJWf9QN.cjs.map +1 -0
  7. package/dist/{bus-DfAbg_pg.js → bus-D8kH58tb.js} +176 -73
  8. package/dist/bus-D8kH58tb.js.map +1 -0
  9. package/dist/capture/console.d.ts +37 -0
  10. package/dist/capture/errors.d.ts +2 -4
  11. package/dist/capture/interactions.d.ts +7 -6
  12. package/dist/capture/long-frames.d.ts +31 -0
  13. package/dist/capture/network.d.ts +23 -9
  14. package/dist/capture/storm.d.ts +17 -0
  15. package/dist/capture/types.d.ts +5 -3
  16. package/dist/console-BpHfWstv.cjs +2 -0
  17. package/dist/console-BpHfWstv.cjs.map +1 -0
  18. package/dist/console-DjLbryED.js +82 -0
  19. package/dist/console-DjLbryED.js.map +1 -0
  20. package/dist/constants-Br3b89Wg.cjs +2 -0
  21. package/dist/constants-Br3b89Wg.cjs.map +1 -0
  22. package/dist/constants-DM94FjVX.js +96 -0
  23. package/dist/constants-DM94FjVX.js.map +1 -0
  24. package/dist/constants.d.ts +51 -10
  25. package/dist/core/breadcrumbs.d.ts +1 -1
  26. package/dist/core/diagnostics.d.ts +2 -2
  27. package/dist/core/journey.d.ts +16 -4
  28. package/dist/core/logger.d.ts +6 -2
  29. package/dist/core/pipeline.d.ts +20 -11
  30. package/dist/core/record.d.ts +14 -6
  31. package/dist/core/remote-rules.d.ts +17 -0
  32. package/dist/core/remote-sampling.d.ts +65 -0
  33. package/dist/core/runtime.d.ts +52 -18
  34. package/dist/core/sampling.d.ts +5 -2
  35. package/dist/core/sender.d.ts +18 -10
  36. package/dist/deadline-B5DINjD5.js +111 -0
  37. package/dist/deadline-B5DINjD5.js.map +1 -0
  38. package/dist/deadline-Cbg2cbUw.cjs +2 -0
  39. package/dist/deadline-Cbg2cbUw.cjs.map +1 -0
  40. package/dist/error-like-Ywo5uRHo.js +19 -0
  41. package/dist/error-like-Ywo5uRHo.js.map +1 -0
  42. package/dist/error-like-gGRx2s36.cjs +2 -0
  43. package/dist/error-like-gGRx2s36.cjs.map +1 -0
  44. package/dist/errors-CpGRhhIf.cjs +3 -0
  45. package/dist/errors-CpGRhhIf.cjs.map +1 -0
  46. package/dist/{errors-4MQyjZVj.js → errors-DH4QJS0u.js} +38 -20
  47. package/dist/errors-DH4QJS0u.js.map +1 -0
  48. package/dist/global-scope-BN-Io_yv.cjs +2 -0
  49. package/dist/global-scope-BN-Io_yv.cjs.map +1 -0
  50. package/dist/global-scope-dp2jADRl.js +19 -0
  51. package/dist/global-scope-dp2jADRl.js.map +1 -0
  52. package/dist/index.cjs +1 -1
  53. package/dist/index.cjs.map +1 -1
  54. package/dist/index.d.ts +13 -5
  55. package/dist/index.js +633 -463
  56. package/dist/index.js.map +1 -1
  57. package/dist/indexeddb-storage-DNdf1fmL.cjs +2 -0
  58. package/dist/indexeddb-storage-DNdf1fmL.cjs.map +1 -0
  59. package/dist/{indexeddb-storage-0LtUALBg.js → indexeddb-storage-n1qkFBGA.js} +17 -17
  60. package/dist/indexeddb-storage-n1qkFBGA.js.map +1 -0
  61. package/dist/interactions-31eHGwEQ.cjs +2 -0
  62. package/dist/interactions-31eHGwEQ.cjs.map +1 -0
  63. package/dist/{interactions-BaCmoGLB.js → interactions-OU94MPXs.js} +22 -19
  64. package/dist/interactions-OU94MPXs.js.map +1 -0
  65. package/dist/journey-CE2EcwHW.cjs +2 -0
  66. package/dist/journey-CE2EcwHW.cjs.map +1 -0
  67. package/dist/journey-CeJ1QoT2.js +162 -0
  68. package/dist/journey-CeJ1QoT2.js.map +1 -0
  69. package/dist/library-request-C9uJFlbq.cjs +2 -0
  70. package/dist/library-request-C9uJFlbq.cjs.map +1 -0
  71. package/dist/library-request-DvhuplAB.js +14 -0
  72. package/dist/library-request-DvhuplAB.js.map +1 -0
  73. package/dist/long-frames-B8VdA_ny.cjs +2 -0
  74. package/dist/long-frames-B8VdA_ny.cjs.map +1 -0
  75. package/dist/long-frames-C_7OutLs.js +65 -0
  76. package/dist/long-frames-C_7OutLs.js.map +1 -0
  77. package/dist/models/batch.d.ts +1 -1
  78. package/dist/models/bus.d.ts +23 -4
  79. package/dist/models/config.d.ts +132 -11
  80. package/dist/models/log-record.d.ts +12 -6
  81. package/dist/network-BAV7ipyn.cjs +2 -0
  82. package/dist/network-BAV7ipyn.cjs.map +1 -0
  83. package/dist/network-D_lloS5t.js +174 -0
  84. package/dist/network-D_lloS5t.js.map +1 -0
  85. package/dist/patch-BX8KrPCT.cjs +2 -0
  86. package/dist/patch-BX8KrPCT.cjs.map +1 -0
  87. package/dist/patch-CCWfuEY7.js +9 -0
  88. package/dist/patch-CCWfuEY7.js.map +1 -0
  89. package/dist/{platform-ByQllE_W.cjs → platform-D4wu1eIF.cjs} +2 -2
  90. package/dist/platform-D4wu1eIF.cjs.map +1 -0
  91. package/dist/{platform-YuByH8A5.js → platform-IHBZGqUe.js} +9 -9
  92. package/dist/platform-IHBZGqUe.js.map +1 -0
  93. package/dist/remote-rules-Bt1XsdEQ.js +86 -0
  94. package/dist/remote-rules-Bt1XsdEQ.js.map +1 -0
  95. package/dist/remote-rules-kuDf5gbe.cjs +2 -0
  96. package/dist/remote-rules-kuDf5gbe.cjs.map +1 -0
  97. package/dist/sampling-BI15ds9D.cjs +2 -0
  98. package/dist/sampling-BI15ds9D.cjs.map +1 -0
  99. package/dist/sampling-o0VY1mqQ.js +63 -0
  100. package/dist/sampling-o0VY1mqQ.js.map +1 -0
  101. package/dist/sanitize-B9UheVKc.js +123 -0
  102. package/dist/sanitize-B9UheVKc.js.map +1 -0
  103. package/dist/sanitize-DSIP7amZ.cjs +2 -0
  104. package/dist/sanitize-DSIP7amZ.cjs.map +1 -0
  105. package/dist/{sender-BIob8eZz.js → sender-BnNj9bOX.js} +415 -272
  106. package/dist/sender-BnNj9bOX.js.map +1 -0
  107. package/dist/sender-D0OsyB1c.cjs +3 -0
  108. package/dist/sender-D0OsyB1c.cjs.map +1 -0
  109. package/dist/storage/emergency-queue.d.ts +1 -1
  110. package/dist/storage/factory.d.ts +1 -1
  111. package/dist/storage/idb-driver.d.ts +1 -1
  112. package/dist/storage/local-storage.d.ts +3 -3
  113. package/dist/storage/memory-storage.d.ts +3 -3
  114. package/dist/storm-BTw0J6eE.js +10 -0
  115. package/dist/storm-BTw0J6eE.js.map +1 -0
  116. package/dist/storm-Y-yuBhvv.cjs +2 -0
  117. package/dist/storm-Y-yuBhvv.cjs.map +1 -0
  118. package/dist/transport/compression.d.ts +1 -1
  119. package/dist/transport/custom-transport.d.ts +20 -0
  120. package/dist/transport/errors.d.ts +2 -1
  121. package/dist/transport/exit-flush.d.ts +32 -13
  122. package/dist/transport/http-transport.d.ts +57 -25
  123. package/dist/transport/memory-transport.d.ts +30 -0
  124. package/dist/transport/retry-engine.d.ts +7 -7
  125. package/dist/transport/serializers/select.d.ts +12 -1
  126. package/dist/transport/status-transport.d.ts +74 -0
  127. package/dist/utils/console.d.ts +1 -1
  128. package/dist/utils/deadline.d.ts +7 -0
  129. package/dist/utils/error-like.d.ts +25 -0
  130. package/dist/utils/global-scope.d.ts +20 -0
  131. package/dist/utils/identity.d.ts +1 -1
  132. package/dist/utils/library-console.d.ts +11 -0
  133. package/dist/utils/library-request.d.ts +12 -0
  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-DeZzr2bx.cjs +0 -2
  146. package/dist/bus-DeZzr2bx.cjs.map +0 -1
  147. package/dist/bus-DfAbg_pg.js.map +0 -1
  148. package/dist/constants-C8nZQBmQ.js +0 -86
  149. package/dist/constants-C8nZQBmQ.js.map +0 -1
  150. package/dist/constants-IBL_jd5R.cjs +0 -2
  151. package/dist/constants-IBL_jd5R.cjs.map +0 -1
  152. package/dist/errors-4MQyjZVj.js.map +0 -1
  153. package/dist/errors-CUdShXe7.cjs +0 -3
  154. package/dist/errors-CUdShXe7.cjs.map +0 -1
  155. package/dist/indexeddb-storage-0LtUALBg.js.map +0 -1
  156. package/dist/indexeddb-storage-CcEJlq2l.cjs +0 -2
  157. package/dist/indexeddb-storage-CcEJlq2l.cjs.map +0 -1
  158. package/dist/interactions-BMNPQ3WH.cjs +0 -2
  159. package/dist/interactions-BMNPQ3WH.cjs.map +0 -1
  160. package/dist/interactions-BaCmoGLB.js.map +0 -1
  161. package/dist/network-DBNvxCE3.cjs +0 -2
  162. package/dist/network-DBNvxCE3.cjs.map +0 -1
  163. package/dist/network-jQ2t8rU4.js +0 -111
  164. package/dist/network-jQ2t8rU4.js.map +0 -1
  165. package/dist/platform-ByQllE_W.cjs.map +0 -1
  166. package/dist/platform-YuByH8A5.js.map +0 -1
  167. package/dist/sampling-CbYySsZ1.js +0 -251
  168. package/dist/sampling-CbYySsZ1.js.map +0 -1
  169. package/dist/sampling-Cs50xsZl.cjs +0 -2
  170. package/dist/sampling-Cs50xsZl.cjs.map +0 -1
  171. package/dist/sender-BIob8eZz.js.map +0 -1
  172. package/dist/sender-iOjzcueM.cjs +0 -3
  173. package/dist/sender-iOjzcueM.cjs.map +0 -1
  174. package/dist/unref-16maCyKA.js +0 -8
  175. package/dist/unref-16maCyKA.js.map +0 -1
  176. package/dist/unref-CU9Nyz_9.cjs +0 -2
  177. package/dist/unref-CU9Nyz_9.cjs.map +0 -1
  178. package/dist/web-vitals-B2FYsEAU.cjs +0 -2
  179. package/dist/web-vitals-B2FYsEAU.cjs.map +0 -1
  180. package/dist/web-vitals-DHZ0yA_H.js.map +0 -1
@@ -1,16 +1,19 @@
1
- import { $t as e, A as t, Ft as n, G as r, I as i, It as a, J as o, Jt as s, K as c, Kt as l, Lt as u, O as d, Ot as ee, Qt as te, R as f, St as p, Vt as ne, Y as re, Zt as ie, _t as m, en as h, ft as g, in as _, k as v, kt as y, l as b, lt as x, ot as S, pt as ae, q as oe, qt as C, rn as se, st as ce, ut as le, v as w, vt as ue, wt as de, xt as T, z as E } from "./constants-C8nZQBmQ.js";
2
- import { _ as D, c as O, f as k, i as A, t as j } from "./sampling-CbYySsZ1.js";
3
- import { t as M } from "./unref-16maCyKA.js";
1
+ import { A as e, At as t, B as n, Ct as r, Gt as i, J as a, Kt as o, Lt as s, M as c, Nt as l, Q as u, R as d, Rt as f, V as p, Wt as m, X as h, Xt as ee, Y as te, Z as ne, b as g, cn as re, d as _, fn as v, ft as y, gt as b, ht as x, j as S, jt as C, ln as w, nn as T, on as ie, pn as ae, pt as oe, q as se, rn as E, sn as ce, tn as le, vt as ue, wt as de, yt as fe } from "./constants-DM94FjVX.js";
2
+ import { o as pe, t as me } from "./sampling-o0VY1mqQ.js";
3
+ import { o as he, t as D } from "./sanitize-B9UheVKc.js";
4
+ import { n as O, r as k, s as A, t as j } from "./deadline-B5DINjD5.js";
5
+ import { n as M, t as N } from "./remote-rules-Bt1XsdEQ.js";
6
+ import { n as P } from "./library-request-DvhuplAB.js";
4
7
  //#region src/models/batch.ts
5
- function N(e) {
8
+ function F(e) {
6
9
  if (typeof e != "object" || !e) return !1;
7
10
  let t = Reflect.get(e, "id"), n = Reflect.get(e, "createdAt"), r = Reflect.get(e, "attempts"), i = Reflect.get(e, "records");
8
11
  return typeof t == "string" && typeof n == "number" && typeof r == "number" && Array.isArray(i);
9
12
  }
10
- function P(e, t) {
13
+ function I(e, t) {
11
14
  if (e.records.length < 2) return null;
12
15
  let n = Math.floor(e.records.length / 2), r = (n) => ({
13
- id: O(t),
16
+ id: A(t),
14
17
  records: n,
15
18
  createdAt: e.createdAt,
16
19
  attempts: e.attempts
@@ -19,13 +22,13 @@ function P(e, t) {
19
22
  }
20
23
  //#endregion
21
24
  //#region src/utils/lock.ts
22
- function F(e, t, n, { skipIfBusy: r = !0 } = {}) {
25
+ function L(e, t, n, { skipIfBusy: r = !0 } = {}) {
23
26
  let i = globalThis.navigator?.locks;
24
27
  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();
25
28
  }
26
29
  //#endregion
27
30
  //#region src/storage/keys.ts
28
- function I(e, t) {
31
+ function R(e, t) {
29
32
  let n = [];
30
33
  return t.guard("storage.unavailable", "The library could not list the localStorage keys.", () => {
31
34
  for (let t = 0; t < localStorage.length; t++) {
@@ -36,53 +39,53 @@ function I(e, t) {
36
39
  }
37
40
  //#endregion
38
41
  //#region src/storage/emergency-queue.ts
39
- function L(e) {
42
+ function ge(e) {
40
43
  let t = String(e.createdAt).padStart(14, "0");
41
- return `${f}${t}.${e.id}`;
44
+ return `${n}${t}.${e.id}`;
42
45
  }
43
- function R(e, t) {
46
+ function _e(e, t) {
44
47
  let n = t.guard("storage.degraded", "An emergency entry is not valid JSON. The library dropped it.", () => JSON.parse(e));
45
- return n === void 0 ? null : N(n) ? n : (t.report("storage.degraded", "An emergency entry is not a batch. The library dropped it."), null);
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);
46
49
  }
47
- async function z(e, t) {
48
- let n = 0;
49
- for (let r of I(f, t)) {
50
- let i = t.guard("storage.unavailable", "The library could not read the emergency queue.", () => {
51
- let e = localStorage.getItem(r);
52
- return localStorage.removeItem(r), e;
50
+ async function ve(e, t) {
51
+ let r = 0;
52
+ for (let i of R(n, t)) {
53
+ let n = t.guard("storage.unavailable", "The library could not read the emergency queue.", () => {
54
+ let e = localStorage.getItem(i);
55
+ return localStorage.removeItem(i), e;
53
56
  });
54
- if (!i) continue;
55
- let a = R(i, t);
57
+ if (!n) continue;
58
+ let a = _e(n, t);
56
59
  if (a !== null) try {
57
- await A(e.save(a), C), n++;
60
+ await O(e.save(a), T), r++;
58
61
  } catch (e) {
59
- t.report("storage.degraded", "The library could not recover an emergency batch.", { key: r }, e);
62
+ t.report("storage.degraded", "The library could not recover an emergency batch.", { key: i }, e);
60
63
  }
61
64
  }
62
- return n;
65
+ return r;
63
66
  }
64
- function B(e, t) {
65
- let n = `writing the emergency queue, ${String(e.records.length)} records`;
66
- t.guard("storage.quota_exceeded", n, () => {
67
- let n = I(f, t);
68
- for (let e of n.slice(0, Math.max(0, n.length - 20 + 1))) localStorage.removeItem(e);
69
- localStorage.setItem(L(e), JSON.stringify(e));
67
+ function z(e, t) {
68
+ let r = `writing the emergency queue, ${String(e.records.length)} records`;
69
+ t.guard("storage.quota_exceeded", r, () => {
70
+ let r = R(n, t);
71
+ for (let e of r.slice(0, Math.max(0, r.length - 20 + 1))) localStorage.removeItem(e);
72
+ localStorage.setItem(ge(e), JSON.stringify(e));
70
73
  });
71
74
  }
72
- async function V(e, t) {
73
- return await F("ui-observability.emergency", t, () => z(e, t), { skipIfBusy: !1 }) ?? 0;
75
+ async function ye(e, t) {
76
+ return await L("ui-observability.emergency", t, () => ve(e, t), { skipIfBusy: !1 }) ?? 0;
74
77
  }
75
78
  //#endregion
76
79
  //#region src/storage/local-storage.ts
77
- function H(e) {
80
+ function be(e) {
78
81
  let t = String(e.createdAt).padStart(14, "0");
79
- return `${w}${t}.${e.id}`;
82
+ return `${g}${t}.${e.id}`;
80
83
  }
81
- function fe(e) {
82
- let t = w.length, n = Number(e.slice(t, t + 14));
84
+ function xe(e) {
85
+ let t = g.length, n = Number(e.slice(t, t + 14));
83
86
  return Number.isFinite(n) ? n : null;
84
87
  }
85
- var pe = class {
88
+ var Se = class {
86
89
  limits;
87
90
  diagnostics;
88
91
  onGap;
@@ -127,7 +130,7 @@ var pe = class {
127
130
  this.removeKey(e), t.batches++, t.records += n?.records.length ?? 0;
128
131
  }, r = [];
129
132
  for (let t of this.keys()) {
130
- let i = fe(t);
133
+ let i = xe(t);
131
134
  i === null || i < e ? n(t) : r.push(t);
132
135
  }
133
136
  let i = r.length - this.limits.maxBatches;
@@ -147,7 +150,7 @@ var pe = class {
147
150
  return Promise.resolve();
148
151
  }
149
152
  write(e, t) {
150
- return this.diagnostics.guard("storage.quota_exceeded", t, () => (localStorage.setItem(H(e), JSON.stringify(e)), !0)) === !0;
153
+ return this.diagnostics.guard("storage.quota_exceeded", t, () => (localStorage.setItem(be(e), JSON.stringify(e)), !0)) === !0;
151
154
  }
152
155
  evictForQuota() {
153
156
  let e = this.keys(), t = {
@@ -168,7 +171,7 @@ var pe = class {
168
171
  let t = this.diagnostics.guard("storage.unavailable", "The library could not read a stored batch.", () => localStorage.getItem(e));
169
172
  if (!t) return null;
170
173
  let n = this.diagnostics.guard("storage.degraded", "A stored batch is corrupt. The library removed it.", () => JSON.parse(t));
171
- return n === void 0 ? null : N(n) ? n : (this.diagnostics.report("storage.degraded", "A stored entry is not a batch. The library dropped it."), null);
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);
172
175
  }
173
176
  keyOf(e) {
174
177
  return this.keys().find((t) => t.endsWith(`.${e}`)) ?? null;
@@ -182,18 +185,18 @@ var pe = class {
182
185
  });
183
186
  }
184
187
  keys() {
185
- return I(w, this.diagnostics);
188
+ return R(g, this.diagnostics);
186
189
  }
187
190
  };
188
191
  //#endregion
189
192
  //#region src/storage/memory-storage.ts
190
- function U(e) {
193
+ function B(e) {
191
194
  return e.reduce((e, t) => e + t.records.length, 0);
192
195
  }
193
- var W = class {
196
+ var V = class {
194
197
  limits;
195
198
  onGap;
196
- name = te;
199
+ name = ce;
197
200
  batches = [];
198
201
  constructor(e, t) {
199
202
  this.limits = e, this.onGap = t;
@@ -217,12 +220,12 @@ var W = class {
217
220
  records: 0,
218
221
  reason: "expired"
219
222
  }, n = this.batches.filter((t) => t.createdAt < e);
220
- this.batches = this.batches.filter((t) => t.createdAt >= e), t.batches += n.length, t.records += U(n);
223
+ this.batches = this.batches.filter((t) => t.createdAt >= e), t.batches += n.length, t.records += B(n);
221
224
  let r = this.batches.length - this.limits.maxBatches;
222
225
  if (r > 0) {
223
226
  t.reason = "over_capacity";
224
227
  let e = this.batches.slice(0, r);
225
- this.batches = this.batches.slice(r), t.batches += e.length, t.records += U(e);
228
+ this.batches = this.batches.slice(r), t.batches += e.length, t.records += B(e);
226
229
  }
227
230
  return t.batches > 0 && this.onGap?.(t), Promise.resolve(t);
228
231
  }
@@ -235,8 +238,8 @@ var W = class {
235
238
  close() {
236
239
  return this.batches = [], Promise.resolve();
237
240
  }
238
- }, me = {
239
- name: e,
241
+ }, Ce = {
242
+ name: re,
240
243
  save: () => Promise.resolve(),
241
244
  take: () => Promise.resolve([]),
242
245
  remove: () => Promise.resolve(),
@@ -250,91 +253,109 @@ var W = class {
250
253
  clear: () => Promise.resolve(),
251
254
  close: () => Promise.resolve()
252
255
  };
253
- function he(e) {
256
+ function we(e) {
254
257
  return e.guard("storage.unavailable", "The library could not read indexedDB.", () => globalThis.indexedDB != null) === !0;
255
258
  }
256
- function ge(e) {
257
- return e.guard("storage.unavailable", "The library could not write a test key to localStorage.", () => (localStorage.setItem(h, "1"), localStorage.removeItem(h), !0)) === !0;
259
+ function Te(e) {
260
+ return e.guard("storage.unavailable", "The library could not write a test key to localStorage.", () => (localStorage.setItem(w, "1"), localStorage.removeItem(w), !0)) === !0;
258
261
  }
259
- async function _e(e, t, n, r, i) {
260
- if (e === "none") return me;
261
- if (e === "memory") return new W(n, i);
262
+ async function Ee(e, t, n, r, i) {
263
+ if (e === "none") return Ce;
264
+ if (e === "memory") return new V(n, i);
262
265
  if (e === "indexeddb" || e === "auto") {
263
- if (he(r)) {
266
+ if (we(r)) {
264
267
  let e = await r.guardAsync("storage.unavailable", "The library could not open IndexedDB.", async () => {
265
- let { IndexedDbStorage: e } = await import("./indexeddb-storage-0LtUALBg.js"), a = new e(t, n, r, i);
268
+ let { IndexedDbStorage: e } = await import("./indexeddb-storage-n1qkFBGA.js"), a = new e(t, n, r, i);
266
269
  return await a.open(), a;
267
270
  });
268
271
  if (e) return e;
269
272
  }
270
- if (e === "indexeddb") return r.report("storage.degraded", "IndexedDB is not available. The library uses memory storage instead."), new W(n, i);
273
+ if (e === "indexeddb") return r.report("storage.degraded", "IndexedDB is not available. The library uses memory storage instead."), new V(n, i);
274
+ }
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));
276
+ }
277
+ //#endregion
278
+ //#region src/transport/errors.ts
279
+ var H = class extends Error {
280
+ kind;
281
+ status;
282
+ retryAfterMs;
283
+ maxBytes;
284
+ constructor(e, t, n, r, i, a) {
285
+ super(t, a === void 0 ? void 0 : { cause: a }), this.kind = e, this.status = n, this.retryAfterMs = r, this.maxBytes = i, this.name = "TransportError";
271
286
  }
272
- return ge(r) ? new pe(n, r, i) : (r.report("storage.degraded", "No persistent storage is available. The library keeps undelivered records in memory only."), new W(n, i));
287
+ };
288
+ function De(e) {
289
+ if (!e) return;
290
+ let t = Number(e);
291
+ if (Number.isFinite(t)) return Math.max(0, t * b);
292
+ let n = Date.parse(e);
293
+ return Number.isNaN(n) ? void 0 : Math.max(0, n - Date.now());
273
294
  }
274
295
  //#endregion
275
296
  //#region src/transport/serializers/ecs.ts
276
- function ve(e) {
277
- return g.test(e) ? Number(BigInt(e) / ae) : Date.now();
297
+ function Oe(e) {
298
+ return ue.test(e) ? Number(BigInt(e) / fe) : Date.now();
278
299
  }
279
- function ye(e) {
300
+ function ke(e) {
280
301
  return typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? e : typeof e == "bigint" ? e.toString() : null;
281
302
  }
282
- function be(e, t, n) {
303
+ function Ae(e, t, n) {
283
304
  let r = e[t];
284
305
  r === void 0 ? e[t] = n : Array.isArray(r) ? r.push(n) : e[t] = [r, n];
285
306
  }
286
- function G(e, t, n, r) {
287
- let i = ye(n);
288
- if (i !== null) be(e, t, i);
307
+ function U(e, t, n, r) {
308
+ let i = ke(n);
309
+ if (i !== null) Ae(e, t, i);
289
310
  else if (typeof n == "object" && n && !r.has(n)) {
290
- if (r.add(n), Array.isArray(n)) for (let i of n) G(e, t, i, r);
291
- else for (let [i, a] of Object.entries(n)) G(e, `${t}.${i}`, a, r);
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);
292
313
  r.delete(n);
293
314
  }
294
315
  }
295
- function K(e) {
316
+ function W(e) {
296
317
  let t = Object.create(null), n = /* @__PURE__ */ new WeakSet();
297
- for (let [r, i] of Object.entries(e)) G(t, r, i, n);
318
+ for (let [r, i] of Object.entries(e)) U(t, r, i, n);
298
319
  return t;
299
320
  }
300
- var xe = {
321
+ var je = {
301
322
  name: "ecs",
302
323
  serialize(e) {
303
324
  return {
304
325
  body: `${e.map((e) => {
305
- let t = ve(e.timeUnixNano);
326
+ let t = Oe(e.timeUnixNano);
306
327
  return JSON.stringify({
307
328
  "@timestamp": new Date(t).toISOString(),
308
329
  message: e.body,
309
- log: { level: i[e.severityText] ?? e.severityText.toLowerCase() },
330
+ log: { level: d[e.severityText] ?? e.severityText.toLowerCase() },
310
331
  trace: { id: e.traceId },
311
332
  span: { id: e.spanId },
312
333
  service: {
313
- name: e.resource[ee],
314
- version: e.resource[y],
315
- environment: e.resource[de]
334
+ name: e.resource[s],
335
+ version: e.resource[f],
336
+ environment: e.resource[l]
316
337
  },
317
- user_agent: { original: e.resource[p] },
338
+ user_agent: { original: e.resource[C] },
318
339
  url: { full: e.attributes["url.full"] ?? e.attributes["page.url"] },
319
340
  labels: {
320
- ...K(e.resource),
321
- ...K(e.attributes)
341
+ ...W(e.resource),
342
+ ...W(e.attributes)
322
343
  }
323
344
  });
324
345
  }).join("\n")}\n`,
325
- contentType: v
346
+ contentType: S
326
347
  };
327
348
  }
328
349
  };
329
350
  //#endregion
330
351
  //#region src/transport/serializers/otlp.ts
331
- function q(e) {
332
- 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(q).filter((e) => e !== null) } } : typeof e == "object" ? { kvlistValue: { values: J(e) } } : null;
352
+ function G(e) {
353
+ 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(G).filter((e) => e !== null) } } : typeof e == "object" ? { kvlistValue: { values: K(e) } } : null;
333
354
  }
334
- function J(e) {
355
+ function K(e) {
335
356
  let t = [];
336
357
  for (let [n, r] of Object.entries(e)) {
337
- let e = q(r);
358
+ let e = G(r);
338
359
  e && t.push({
339
360
  key: n,
340
361
  value: e
@@ -342,30 +363,30 @@ function J(e) {
342
363
  }
343
364
  return t;
344
365
  }
345
- var Y = /* @__PURE__ */ new WeakMap();
346
- function Se(e) {
347
- let t = Y.get(e);
366
+ var q = /* @__PURE__ */ new WeakMap();
367
+ function Me(e) {
368
+ let t = q.get(e);
348
369
  if (t !== void 0) return t;
349
370
  let n = JSON.stringify(e);
350
- return Y.set(e, n), n;
371
+ return q.set(e, n), n;
351
372
  }
352
- var Ce = {
353
- name: ne,
354
- serialize(e) {
355
- let t = /* @__PURE__ */ new Map();
356
- for (let n of e) {
357
- let e = Se(n.resource), r = t.get(e);
358
- r ? r.records.push(n) : t.set(e, {
359
- resource: n.resource,
360
- records: [n]
373
+ var Ne = {
374
+ name: ee,
375
+ serialize(t) {
376
+ let n = /* @__PURE__ */ new Map();
377
+ for (let e of t) {
378
+ let t = Me(e.resource), r = n.get(t);
379
+ r ? r.records.push(e) : n.set(t, {
380
+ resource: e.resource,
381
+ records: [e]
361
382
  });
362
383
  }
363
- let n = [...t.values()].map((e) => ({
364
- resource: { attributes: J(e.resource) },
384
+ let r = [...n.values()].map((e) => ({
385
+ resource: { attributes: K(e.resource) },
365
386
  scopeLogs: [{
366
387
  scope: {
367
- name: se,
368
- version: _
388
+ name: v,
389
+ version: ae
369
390
  },
370
391
  logRecords: e.records.map((e) => ({
371
392
  timeUnixNano: e.timeUnixNano,
@@ -376,24 +397,109 @@ var Ce = {
376
397
  traceId: e.traceId,
377
398
  spanId: e.spanId,
378
399
  flags: e.traceFlags,
379
- attributes: J(e.attributes)
400
+ attributes: K(e.attributes)
380
401
  }))
381
402
  }]
382
403
  }));
383
404
  return {
384
- body: JSON.stringify({ resourceLogs: n }),
385
- contentType: d
405
+ body: JSON.stringify({ resourceLogs: r }),
406
+ contentType: e
386
407
  };
387
408
  }
388
409
  };
389
410
  //#endregion
390
411
  //#region src/transport/serializers/select.ts
391
- function X(e) {
392
- return e === "otlp" ? Ce : e === "ecs" ? xe : e;
412
+ function Pe(e) {
413
+ return e === "otlp" ? Ne : e === "ecs" ? je : e;
414
+ }
415
+ function J(e, t, n, r) {
416
+ try {
417
+ return Pe(e).serialize(t.records);
418
+ } catch (e) {
419
+ n.report("transport.serialize_failed", r, { batchId: t.id }, e);
420
+ return;
421
+ }
393
422
  }
394
423
  //#endregion
395
- //#region src/transport/exit-flush.ts
396
- var we = class {
424
+ //#region src/transport/status-transport.ts
425
+ var Y = class {
426
+ config;
427
+ diagnostics;
428
+ onSampling;
429
+ throttledUntil = 0;
430
+ constructor(e, t, n = () => void 0) {
431
+ this.config = e, this.diagnostics = t, this.onSampling = n;
432
+ }
433
+ throttledForMs() {
434
+ return Math.max(0, this.throttledUntil - Date.now());
435
+ }
436
+ serialize(e) {
437
+ return J(this.config.serializer, e, this.diagnostics, "The serializer threw an error. The library dropped the batch.");
438
+ }
439
+ accept(e) {
440
+ this.throttledUntil = 0, this.config.sampling.remote && e != null && this.onSampling(e);
441
+ }
442
+ reject(e, t, n) {
443
+ let r = String(e);
444
+ if (e === 401 || e === 403) {
445
+ let t = n.advice === void 0 ? "" : ` ${n.advice}`;
446
+ return this.diagnostics.report("transport.rejected_credentials", `The server returned ${r}.${t}`, {
447
+ status: e,
448
+ endpoint: this.config.endpoint
449
+ }), new H("permanent", `The server rejected the batch with ${r}.`, e);
450
+ }
451
+ if (e === 413) return new H("too_large", "The payload is too large.", e, void 0, n.maxBytes);
452
+ if (e === 429 || e === 503) {
453
+ let t = e === 429, r = n.retryAfterMs === void 0 ? void 0 : Math.min(n.retryAfterMs, o);
454
+ return this.throttledUntil = Date.now() + (r ?? 2e3), t && this.diagnostics.report("transport.throttled", "The server throttles the requests.", { retryAfterMs: r }), new H("throttled", t ? "The server throttles the requests." : "The service is not available.", e, r);
455
+ }
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.`, {
457
+ batchId: t,
458
+ status: e
459
+ }), new H("permanent", `The server rejected the batch with ${r}.`, e));
460
+ }
461
+ };
462
+ //#endregion
463
+ //#region src/transport/custom-transport.ts
464
+ function X(e, t) {
465
+ return {
466
+ body: t.body,
467
+ contentType: t.contentType,
468
+ batchId: e.id,
469
+ attempt: e.attempts,
470
+ records: e.records
471
+ };
472
+ }
473
+ function Fe(e) {
474
+ if (typeof e != "object" || !e) return !1;
475
+ let t = Reflect.get(e, "status");
476
+ return typeof t == "number" && Number.isInteger(t) && t >= 100 && t <= 599;
477
+ }
478
+ function Z(e) {
479
+ return typeof e == "number" && Number.isFinite(e) ? Math.max(0, e) : void 0;
480
+ }
481
+ var Ie = class extends Y {
482
+ async send(e) {
483
+ let { transport: n } = this.config;
484
+ if (!n || e.records.length === 0) return;
485
+ let r = this.serialize(e);
486
+ if (!r) return;
487
+ let i = X(e, r), a;
488
+ try {
489
+ a = await O(P(() => he(() => n(i))), t);
490
+ } catch (e) {
491
+ let t = e instanceof j ? e : void 0;
492
+ throw new H(t ? "timeout" : "transient", t?.message ?? "The custom transport failed.", void 0, void 0, void 0, e);
493
+ }
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.");
495
+ let { status: o } = a;
496
+ if (o >= 200 && o < 300) this.accept(a.sampling);
497
+ else throw this.reject(o, e.id, {
498
+ retryAfterMs: Z(a.retryAfterMs),
499
+ maxBytes: Z(a.maxBytes)
500
+ });
501
+ }
502
+ }, Le = class {
397
503
  deps;
398
504
  installed = !1;
399
505
  onVisibility = () => {
@@ -428,147 +534,173 @@ var we = class {
428
534
  });
429
535
  }
430
536
  flush(e) {
431
- let { diagnostics: t } = this.deps, n = this.endpointUrl();
432
- if (n === null) return;
433
- let r = this.drain(e);
434
- if (!r || r.records.length === 0) return;
435
- let i = t.guard("transport.serialize_failed", `The ${e} exit flush could not serialize its batch.`, () => X(this.deps.config.serializer).serialize(r.records));
436
- if (!i) return;
437
- if (k(i.body) > 6e4) {
438
- B(r, t);
537
+ let { config: t, diagnostics: n } = this.deps;
538
+ if (e === "hidden") {
539
+ this.flushAlive();
540
+ return;
541
+ }
542
+ if (t.transport) {
543
+ this.flushCustom(e, t.transportOnExit);
544
+ return;
545
+ }
546
+ let i = this.endpointUrl();
547
+ if (i === null) return;
548
+ let o = this.deps.drainForExit();
549
+ if (!o || o.records.length === 0) return;
550
+ let s = this.serialize(o, e);
551
+ if (!s) return;
552
+ if (D(s.body) > 6e4) {
553
+ z(o, n);
554
+ return;
555
+ }
556
+ i.searchParams.set(r, o.id), i.searchParams.set(de, e);
557
+ let l = i.toString(), u = this.deps.exitHeaders();
558
+ if (u) {
559
+ this.keepaliveFetch(l, s.body, e, () => {
560
+ let e = new Headers(u);
561
+ return e.set(h, s.contentType), e.set(a, o.id), e;
562
+ });
563
+ return;
564
+ }
565
+ if (t.headers) {
566
+ z(o, n);
439
567
  return;
440
568
  }
441
- n.searchParams.set(m, r.id), n.searchParams.set(ue, e);
442
- let a = n.toString(), o = this.beacon(a, i.body);
443
- o !== "sent" && (o === "refused" ? B(r, t) : this.keepaliveFetch(a, i.body, e));
569
+ let d = this.beacon(l, s.body);
570
+ d !== "sent" && (d === "refused" ? z(o, n) : this.keepaliveFetch(l, s.body, e, () => new Headers({ [h]: c })));
571
+ }
572
+ flushAlive() {
573
+ let { diagnostics: e } = this.deps, t = "The flush of the hidden document failed.";
574
+ e.guard("pipeline.crashed", t, () => {
575
+ Promise.resolve(this.deps.flushAlive()).catch((n) => {
576
+ e.report("pipeline.crashed", t, void 0, n);
577
+ });
578
+ });
579
+ }
580
+ flushCustom(e, t) {
581
+ let { diagnostics: n } = this.deps, r = this.deps.drainForExit();
582
+ if (!r || r.records.length === 0) return;
583
+ let i = this.serialize(r, e);
584
+ i && (t === void 0 || n.guard("transport.http_error", "The transportOnExit hook threw an error.", () => P(() => t(X(r, i)))) !== !0) && z(r, n);
444
585
  }
445
- drain(e) {
446
- return e === "hidden" ? this.deps.drainPending() : this.deps.drainForExit();
586
+ serialize(e, t) {
587
+ return J(this.deps.config.serializer, e, this.deps.diagnostics, `The ${t} exit flush could not serialize its batch.`);
447
588
  }
448
589
  endpointUrl() {
449
590
  let { endpoint: e } = this.deps.config;
450
591
  return e ? this.deps.diagnostics.guard("config.invalid", `The exit flush cannot use the endpoint ${e}.`, () => new URL(e)) ?? null : null;
451
592
  }
452
593
  beacon(e, t) {
453
- return this.deps.diagnostics.guard("transport.http_error", "sendBeacon", () => {
594
+ return this.deps.diagnostics.guard("transport.http_error", "The sendBeacon call failed.", () => {
454
595
  let n = globalThis.navigator;
455
596
  return n?.sendBeacon ? n.sendBeacon(e, new Blob([t], { type: "text/plain;charset=UTF-8" })) ? "sent" : "refused" : "unavailable";
456
597
  }) ?? "unavailable";
457
598
  }
458
- keepaliveFetch(e, n, r) {
599
+ keepaliveFetch(e, t, n, r) {
459
600
  let { config: i, diagnostics: a } = this.deps;
460
- a.guard("transport.http_error", "The keepalive fetch fallback failed.", () => {
601
+ a.guard("transport.http_error", "The keepalive fetch failed.", () => {
461
602
  fetch(e, {
462
603
  method: "POST",
463
- body: n,
464
- headers: { [o]: t },
604
+ body: t,
605
+ headers: r(),
465
606
  credentials: i.credentials,
466
607
  keepalive: !0
467
608
  }).catch((e) => {
468
- a.report("transport.http_error", "The exit flush failed.", { reason: r }, e);
609
+ a.report("transport.http_error", "The exit flush failed.", { reason: n }, e);
469
610
  });
470
611
  });
471
612
  }
472
613
  };
473
614
  //#endregion
474
615
  //#region src/transport/compression.ts
475
- async function Te(e) {
616
+ async function Re(e) {
476
617
  let t = globalThis.CompressionStream;
477
618
  if (t === void 0) return null;
478
- let n = new Blob([e]).stream().pipeThrough(new t(E)), r = await new Response(n).arrayBuffer();
619
+ let n = new Blob([e]).stream().pipeThrough(new t(p)), r = await new Response(n).arrayBuffer();
479
620
  return new Uint8Array(r);
480
621
  }
481
622
  //#endregion
482
- //#region src/transport/errors.ts
483
- var Z = class extends Error {
484
- kind;
485
- status;
486
- retryAfterMs;
487
- maxBytes;
488
- constructor(e, t, n, r, i) {
489
- super(t), this.kind = e, this.status = n, this.retryAfterMs = r, this.maxBytes = i, this.name = "TransportError";
490
- }
491
- };
492
- function Ee(e) {
493
- if (!e) return;
494
- let t = Number(e);
495
- if (Number.isFinite(t)) return Math.max(0, t * le);
496
- let n = Date.parse(e);
497
- return Number.isNaN(n) ? void 0 : Math.max(0, n - Date.now());
498
- }
499
- //#endregion
500
623
  //#region src/transport/http-transport.ts
501
- var Q = class {
502
- config;
503
- diagnostics;
504
- throttledUntil = 0;
505
- constructor(e, t) {
506
- this.config = e, this.diagnostics = t;
624
+ 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 {
625
+ cachedHeaders;
626
+ async send(e, t) {
627
+ let { endpoint: n } = this.config;
628
+ n && e.records.length !== 0 && await this.post(e, n, t);
507
629
  }
508
- async send(e) {
509
- let { endpoint: t } = this.config;
510
- t && e.records.length !== 0 && await this.post(e, t);
630
+ lastHeaders() {
631
+ let { headers: e } = this.config;
632
+ if (!e) return;
633
+ if (typeof e != "function") return e;
634
+ let t = this.cachedHeaders;
635
+ return t?.source === e && t.endpoint === this.config.endpoint ? t.headers : void 0;
636
+ }
637
+ async post(e, t, n) {
638
+ let r = this.serialize(e);
639
+ if (!r) return;
640
+ let i = await this.attempt(e, t, r, n);
641
+ if (this.rejectsCredentials(i.status) && typeof this.config.headers == "function" && (this.cachedHeaders = void 0, i = await this.attempt(e, t, r, n)), i.ok) {
642
+ this.accept(i.headers.get(u));
643
+ return;
644
+ }
645
+ let a = i.status, o = De(i.headers.get(ne)), s = a === 413 ? await this.readMaxBytes(i) : void 0;
646
+ throw this.reject(a, e.id, {
647
+ retryAfterMs: o,
648
+ maxBytes: s,
649
+ advice: Q
650
+ });
511
651
  }
512
- throttledForMs() {
513
- return Math.max(0, this.throttledUntil - Date.now());
652
+ rejectsCredentials(e) {
653
+ return e === 401 || e === 403;
654
+ }
655
+ async attempt(e, n, r, i) {
656
+ let o = Date.now() + t, s = new Headers(await this.before(this.resolveHeaders(n), o));
657
+ s.set(h, r.contentType), s.set(a, e.id), s.set(se, String(e.attempts));
658
+ let c = await this.before(this.encodeBody(r.body), o);
659
+ typeof c != "string" && s.set(te, p);
660
+ let l = this.keepalive(c);
661
+ return l && i?.(), this.dispatch(n, s, c, o, l);
514
662
  }
515
- async post(e, t) {
516
- let { config: n } = this, i;
663
+ async before(e, t) {
517
664
  try {
518
- i = X(n.serializer).serialize(e.records);
519
- } catch (t) {
520
- this.diagnostics.report("transport.serialize_failed", "The serializer threw an error. The library dropped the batch.", { batchId: e.id }, t);
521
- return;
665
+ return await O(e, Math.max(0, t - Date.now()));
666
+ } catch {
667
+ throw this.timeout();
522
668
  }
523
- let a = new Headers(await this.resolveHeaders());
524
- a.set(o, i.contentType), a.set(c, e.id), a.set(r, String(e.attempts));
525
- let s = await this.encodeBody(i.body);
526
- typeof s != "string" && a.set(oe, E);
527
- let l = await this.dispatch(t, a, s);
528
- if (l.ok) this.throttledUntil = 0;
529
- else throw await this.classify(l, e.id);
669
+ }
670
+ timeout() {
671
+ let e = `The request took longer than ${String(t)} ms.`;
672
+ return this.diagnostics.report("transport.timeout", e, { endpoint: this.config.endpoint }), new H("timeout", e);
530
673
  }
531
674
  async encodeBody(e) {
532
675
  let { config: t } = this;
533
- return t.compression !== "gzip" || k(e) < 1024 ? e : await this.diagnostics.guardAsync("transport.http_error", "The library could not compress the payload.", () => Te(e)) ?? e;
676
+ return t.compression !== "gzip" || D(e) < 1024 ? e : await this.diagnostics.guardAsync("transport.http_error", "The library could not compress the payload.", () => Re(e)) ?? e;
534
677
  }
535
- async dispatch(e, t, n) {
536
- let { config: r } = this, i = new AbortController(), a = setTimeout(() => {
537
- i.abort();
538
- }, T);
539
- M(a);
678
+ async dispatch(e, t, n, r, i) {
679
+ let { config: a } = this, o = new AbortController(), s = setTimeout(() => {
680
+ o.abort();
681
+ }, Math.max(0, r - Date.now()));
682
+ k(s);
540
683
  try {
541
- return await fetch(e, {
684
+ return await P(() => fetch(e, {
542
685
  method: "POST",
543
686
  headers: t,
544
687
  body: n,
545
- credentials: r.credentials,
546
- signal: i.signal,
547
- cache: "no-store"
548
- });
688
+ credentials: a.credentials,
689
+ signal: o.signal,
690
+ cache: "no-store",
691
+ keepalive: i
692
+ }));
549
693
  } catch {
550
- if (i.signal.aborted) throw new Z("timeout", `The request took longer than ${String(T)} ms.`);
694
+ if (o.signal.aborted) throw this.timeout();
551
695
  let e = globalThis.navigator?.onLine;
552
- throw new Z(e === !1 ? "offline" : "transient", "A network error occurred.");
696
+ throw new H(e === !1 ? "offline" : "transient", "A network error occurred.");
553
697
  } finally {
554
- clearTimeout(a);
698
+ clearTimeout(s);
555
699
  }
556
700
  }
557
- async classify(e, t) {
558
- let n = e.status, r = Ee(e.headers.get(re));
559
- if (n === 401 || n === 403) return this.diagnostics.report("transport.rejected_credentials", `The server returned ${String(n)}. 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.`, {
560
- status: n,
561
- endpoint: this.config.endpoint
562
- }), new Z("permanent", `The server rejected the batch with ${String(n)}.`, n);
563
- if (n === 413) return new Z("too_large", "The payload is too large.", n, void 0, await this.readMaxBytes(e));
564
- if (n === 429 || n === 503) {
565
- let e = n === 429;
566
- return this.throttledUntil = Date.now() + (r ?? 2e3), e && this.diagnostics.report("transport.throttled", "The server throttles the requests.", { retryAfterMs: r }), new Z("throttled", e ? "The server throttles the requests." : "The service is not available.", n, r);
567
- }
568
- return n === 408 || n >= 500 ? new Z("transient", `The server returned the error ${String(n)}.`, n) : (this.diagnostics.report("transport.dropped_permanent", `The server rejected the batch with ${String(n)}. The library dropped it.`, {
569
- batchId: t,
570
- status: n
571
- }), new Z("permanent", `The server rejected the batch with ${String(n)}.`, n));
701
+ keepalive(e) {
702
+ let t = globalThis.document?.visibilityState === "hidden", n = typeof e == "string" ? D(e) : e.byteLength;
703
+ return t && n <= 6e4;
572
704
  }
573
705
  async readMaxBytes(e) {
574
706
  return this.diagnostics.guardAsync("transport.http_error", "The library could not read the body of the 413 response.", async () => {
@@ -576,11 +708,18 @@ var Q = class {
576
708
  return typeof t.maxBytes == "number" ? t.maxBytes : void 0;
577
709
  });
578
710
  }
579
- async resolveHeaders() {
580
- let { headers: e } = this.config;
581
- return e ? typeof e == "function" ? await this.diagnostics.guardAsync("transport.http_error", "The headers() function threw an error.", () => Promise.resolve(e())) ?? {} : e : {};
582
- }
583
- }, De = class {
711
+ async resolveHeaders(e) {
712
+ let { headers: t } = this.config;
713
+ if (!t) return {};
714
+ if (typeof t != "function") return t;
715
+ let n = await this.diagnostics.guardAsync("transport.http_error", "The headers() function threw an error.", () => Promise.resolve(t()));
716
+ return n && (this.cachedHeaders = {
717
+ source: t,
718
+ endpoint: e,
719
+ headers: n
720
+ }), n ?? {};
721
+ }
722
+ }, Be = class {
584
723
  storage;
585
724
  transport;
586
725
  diagnostics;
@@ -597,10 +736,10 @@ var Q = class {
597
736
  this.storage = e, this.transport = t, this.diagnostics = n, this.config = r, this.batchesPerDrain = i;
598
737
  }
599
738
  start() {
600
- this.stopped = !1, typeof addEventListener < "u" && addEventListener("online", this.onOnline), this.schedule(a);
739
+ this.stopped = !1, typeof addEventListener < "u" && addEventListener("online", this.onOnline), this.schedule(i);
601
740
  }
602
741
  nudge() {
603
- this.draining || this.schedule(n);
742
+ this.draining || this.schedule(m);
604
743
  }
605
744
  async storeFailed(e, t) {
606
745
  let n = this.toStorable(e, t);
@@ -616,23 +755,23 @@ var Q = class {
616
755
  let t = setTimeout(() => {
617
756
  this.drain();
618
757
  }, e);
619
- this.timer = t, M(t);
758
+ this.timer = t, k(t);
620
759
  }
621
760
  bounded(e) {
622
- return A(e, C);
761
+ return O(e, T);
623
762
  }
624
763
  clearTimer() {
625
764
  this.timer !== null && (clearTimeout(this.timer), this.timer = null);
626
765
  }
627
766
  backoffMs() {
628
- let e = Math.min(n * 2 ** this.attempt, u);
767
+ let e = Math.min(m * 2 ** this.attempt, o);
629
768
  return Math.random() * e;
630
769
  }
631
770
  async drain() {
632
771
  if (!this.draining) {
633
772
  this.draining = !0;
634
773
  try {
635
- await F("ui-observability.drain", this.diagnostics, () => this.drainLocked()) !== !0 && this.schedule(a);
774
+ await L("ui-observability.drain", this.diagnostics, () => this.drainLocked()) !== !0 && this.schedule(i);
636
775
  } finally {
637
776
  this.draining = !1;
638
777
  }
@@ -640,25 +779,25 @@ var Q = class {
640
779
  }
641
780
  async drainLocked() {
642
781
  try {
643
- if (globalThis.navigator?.onLine === !1) return this.schedule(a), !0;
782
+ if (globalThis.navigator?.onLine === !1) return this.schedule(i), !0;
644
783
  let e = await this.bounded(this.storage.take(this.batchesPerDrain));
645
- if (e.length === 0) return this.schedule(a), !0;
784
+ if (e.length === 0) return this.schedule(i), !0;
646
785
  for (let t of e) if (this.stopped || !await this.deliver(t)) return !0;
647
- return this.schedule(e.length === this.batchesPerDrain ? 0 : a), !0;
786
+ return this.schedule(e.length === this.batchesPerDrain ? 0 : i), !0;
648
787
  } catch (e) {
649
788
  return this.diagnostics.report("storage.degraded", "The drain loop threw an error.", void 0, e), this.attempt++, this.schedule(this.backoffMs()), !0;
650
789
  }
651
790
  }
652
791
  async deliver(e) {
653
- if (e.attempts >= s.maxAttempts) return this.diagnostics.report("storage.dead_lettered", `The library dropped a batch after ${e.attempts.toString()} attempts.`, {
792
+ if (e.attempts >= E.maxAttempts) return this.diagnostics.report("storage.dead_lettered", `The library dropped a batch after ${e.attempts.toString()} attempts.`, {
654
793
  batchId: e.id,
655
794
  records: e.records.length
656
795
  }), await this.bounded(this.storage.remove(e.id)), !0;
657
796
  try {
658
797
  return await this.transport.send(e), await this.bounded(this.storage.remove(e.id)), this.attempt = 0, !0;
659
798
  } catch (t) {
660
- let n = t instanceof Z ? t : void 0;
661
- return n?.kind === "permanent" || n?.kind === "too_large" ? (await this.replaceStored(e, t), !0) : n?.kind === "offline" ? (this.schedule(a), !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);
799
+ let n = t instanceof H ? t : void 0;
800
+ return n?.kind === "permanent" || n?.kind === "too_large" ? (await this.replaceStored(e, t), !0) : n?.kind === "offline" ? (this.schedule(i), !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);
662
801
  }
663
802
  }
664
803
  async replaceStored(e, t) {
@@ -667,10 +806,10 @@ var Q = class {
667
806
  for (let e of n) await this.bounded(this.storage.save(e));
668
807
  }
669
808
  toStorable(e, t) {
670
- let n = t instanceof Z ? t : void 0;
809
+ let n = t instanceof H ? t : void 0;
671
810
  if (n?.kind === "permanent") return [];
672
811
  if (n?.kind !== "too_large") return [e];
673
- let r = P(e, this.diagnostics);
812
+ let r = I(e, this.diagnostics);
674
813
  return r ? (this.diagnostics.report("transport.batch_split", "The server refused the batch because it is too large.", {
675
814
  from: e.records.length,
676
815
  to: r[0].records.length,
@@ -683,12 +822,12 @@ var Q = class {
683
822
  };
684
823
  //#endregion
685
824
  //#region src/core/pipeline.ts
686
- function Oe(e) {
687
- return e.attributes[b] === ce;
825
+ function Ve(e) {
826
+ return e.attributes[_] === oe;
688
827
  }
689
- var ke = {
828
+ var He = {
690
829
  logs: {
691
- flushIntervalMs: S,
830
+ flushIntervalMs: y,
692
831
  batchSize: 100
693
832
  },
694
833
  metrics: {
@@ -719,12 +858,12 @@ var ke = {
719
858
  let e = setTimeout(() => {
720
859
  this.timer = null, this.onFlush(this);
721
860
  }, this.options.flushIntervalMs);
722
- this.timer = e, M(e);
861
+ this.timer = e, k(e);
723
862
  }
724
863
  clearTimer() {
725
864
  this.timer !== null && (clearTimeout(this.timer), this.timer = null);
726
865
  }
727
- }, Ae = class {
866
+ }, Ue = class {
728
867
  transport;
729
868
  storage;
730
869
  retry;
@@ -732,11 +871,12 @@ var ke = {
732
871
  streams;
733
872
  unconfirmed = /* @__PURE__ */ new Map();
734
873
  queue = [];
735
- ceiling = new j();
874
+ open = /* @__PURE__ */ new Set();
875
+ ceiling = new me();
736
876
  inFlight = 0;
737
877
  pumpScheduled = !1;
738
878
  stopped = !1;
739
- constructor(e, t, n, r, i = ke) {
879
+ constructor(e, t, n, r, i = He) {
740
880
  this.transport = e, this.storage = t, this.retry = n, this.diagnostics = r;
741
881
  let a = (e) => {
742
882
  this.claim(e);
@@ -747,7 +887,7 @@ var ke = {
747
887
  };
748
888
  }
749
889
  push(e) {
750
- this.stopped || (e.observedTimeUnixNano = D(), this.route(e));
890
+ this.stopped || (e.observedTimeUnixNano = pe(), this.route(e));
751
891
  }
752
892
  drainPending() {
753
893
  return this.toBatch([...this.streams.metrics.take(), ...this.streams.logs.take()]);
@@ -760,12 +900,17 @@ var ke = {
760
900
  ...this.streams.logs.take()
761
901
  ]);
762
902
  }
903
+ async flushPending() {
904
+ this.enqueue(this.stopped ? null : this.drainPending()), await Promise.all([...this.open].map((e) => e.done));
905
+ }
763
906
  destroy() {
764
907
  this.stopped = !0, this.streams.logs.stop(), this.streams.metrics.stop(), this.queue.length = 0;
908
+ for (let e of this.open) e.resolve();
909
+ this.open.clear();
765
910
  }
766
911
  toBatch(e) {
767
912
  return e.length === 0 ? null : {
768
- id: O(this.diagnostics),
913
+ id: A(this.diagnostics),
769
914
  records: e,
770
915
  createdAt: Date.now(),
771
916
  attempts: 0
@@ -773,7 +918,7 @@ var ke = {
773
918
  }
774
919
  route(e) {
775
920
  try {
776
- let t = Oe(e) ? this.streams.metrics : this.streams.logs;
921
+ let t = Ve(e) ? this.streams.metrics : this.streams.logs;
777
922
  if (!this.ceiling.allow(e)) {
778
923
  this.diagnostics.count("record.dropped_by_ceiling");
779
924
  return;
@@ -784,16 +929,18 @@ var ke = {
784
929
  }
785
930
  }
786
931
  claim(e) {
787
- let t = e.take(), n = {
788
- id: O(this.diagnostics),
789
- records: t,
790
- createdAt: Date.now(),
791
- attempts: 0
792
- };
793
- this.unconfirmed.set(n.id, n), this.enqueue(n);
932
+ this.enqueue(this.toBatch(e.take()));
794
933
  }
795
934
  enqueue(e) {
796
- this.queue.push(e), !this.pumpScheduled && (this.pumpScheduled = !0, queueMicrotask(() => {
935
+ if (!e) return;
936
+ let t, n = {
937
+ batch: e,
938
+ done: new Promise((e) => {
939
+ t = e;
940
+ }),
941
+ resolve: t
942
+ };
943
+ this.unconfirmed.set(e.id, e), this.open.add(n), this.queue.push(n), !this.pumpScheduled && (this.pumpScheduled = !0, queueMicrotask(() => {
797
944
  this.pumpScheduled = !1, this.pump();
798
945
  }));
799
946
  }
@@ -805,12 +952,13 @@ var ke = {
805
952
  }
806
953
  }
807
954
  async run(e) {
955
+ let { batch: t } = e;
808
956
  try {
809
- await this.dispatch(e);
810
- } catch (t) {
811
- this.diagnostics.report("pipeline.crashed", "A dispatch rejected its promise. This must not occur.", { batchId: e.id }, t);
957
+ await this.dispatch(t);
958
+ } catch (e) {
959
+ this.diagnostics.report("pipeline.crashed", "A dispatch rejected its promise. This must not occur.", { batchId: t.id }, e);
812
960
  } finally {
813
- this.inFlight--, this.pump();
961
+ this.inFlight--, this.open.delete(e), e.resolve(), this.pump();
814
962
  }
815
963
  }
816
964
  async dispatch(e) {
@@ -825,7 +973,9 @@ var ke = {
825
973
  return;
826
974
  }
827
975
  try {
828
- await this.transport.send(e);
976
+ await this.transport.send(e, () => {
977
+ this.unconfirmed.delete(e.id);
978
+ });
829
979
  } catch (t) {
830
980
  await this.storeFailed({
831
981
  ...e,
@@ -846,62 +996,55 @@ var ke = {
846
996
  }
847
997
  async store(e) {
848
998
  await this.diagnostics.guardAsync("storage.degraded", "The library could not store an undelivered batch.", async () => {
849
- await A(this.storage.save(e), C), this.retry.nudge();
999
+ await O(this.storage.save(e), T), this.retry.nudge();
850
1000
  });
851
1001
  }
852
- }, je = class e {
1002
+ }, We = class e {
853
1003
  storage;
854
- transport;
855
1004
  retry;
856
1005
  pipeline;
857
1006
  exitFlush;
858
1007
  diagnostics;
859
- constructor(e, t, n, r, i, a) {
860
- this.storage = e, this.transport = t, this.retry = n, this.pipeline = r, this.exitFlush = i, this.diagnostics = a;
1008
+ constructor(e, t, n, r, i) {
1009
+ this.storage = e, this.retry = t, this.pipeline = n, this.exitFlush = r, this.diagnostics = i;
861
1010
  }
862
1011
  static async create(t) {
863
- let { config: n, diagnostics: r } = t, i = await _e(n.storage, l, s, r, t.onGap), a = new Q(n, r), o = new De(i, a, r, n), c = new Ae(a, i, o, r), u = new we({
1012
+ let { config: n, diagnostics: r } = t, i = await Ee(n.storage, le, E, r, t.onGap), a = (e) => {
1013
+ let i = M(e, r);
1014
+ i && N(t.remote, n, i);
1015
+ }, o = n.transport ? void 0 : new ze(n, r, a), s = o ?? new Ie(n, r, a), c = new Be(i, s, r, n), l = new Ue(s, i, c, r), u = new Le({
864
1016
  config: n,
865
1017
  diagnostics: r,
866
- drainForExit: () => c.drainForExit(),
867
- drainPending: () => c.drainPending()
868
- });
869
- await V(i, r);
870
- let d = !1;
1018
+ drainForExit: () => l.drainForExit(),
1019
+ flushAlive: () => l.flushPending(),
1020
+ exitHeaders: () => o?.lastHeaders()
1021
+ }), d = !1;
871
1022
  try {
872
- u.install(), o.start(), d = !0;
1023
+ u.install(), c.start(), d = !0;
873
1024
  } finally {
874
- d || (u.uninstall(), o.stop());
1025
+ d || (u.uninstall(), c.stop());
875
1026
  }
876
- return new e(i, a, o, c, u, r);
1027
+ let f = new e(i, c, l, u, r);
1028
+ return f.importEmergency(), f;
877
1029
  }
878
1030
  push(e) {
879
1031
  this.pipeline.push(e);
880
1032
  }
881
1033
  async flush() {
882
- let e = this.pipeline.drainPending();
883
- if (e) try {
884
- await this.transport.send(e);
885
- } catch (t) {
886
- await this.diagnostics.guardAsync("storage.degraded", "The library could not store the batch that flush() drained.", async () => {
887
- await this.retry.storeFailed({
888
- ...e,
889
- attempts: e.attempts + 1
890
- }, t);
891
- }), this.diagnostics.report("transport.http_error", "The send from flush() failed. The library stored the batch for a retry.", {
892
- batchId: e.id,
893
- records: e.records.length
894
- }, t);
895
- }
1034
+ await this.pipeline.flushPending();
896
1035
  }
897
1036
  async queueDepth() {
898
1037
  return await this.diagnostics.guardAsync("storage.degraded", "The library could not count the batches in storage.", () => this.storage.count()) ?? 0;
899
1038
  }
900
1039
  async destroy() {
901
- this.exitFlush.flush("shutdown"), this.exitFlush.uninstall(), this.retry.stop(), this.pipeline.destroy(), await this.storage.close();
1040
+ 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();
1041
+ }
1042
+ async importEmergency() {
1043
+ let e = await this.diagnostics.guardAsync("storage.degraded", "The emergency import failed.", () => ye(this.storage, this.diagnostics));
1044
+ e !== void 0 && e > 0 && this.retry.nudge();
902
1045
  }
903
1046
  };
904
1047
  //#endregion
905
- export { je as Sender };
1048
+ export { We as Sender };
906
1049
 
907
- //# sourceMappingURL=sender-BIob8eZz.js.map
1050
+ //# sourceMappingURL=sender-BnNj9bOX.js.map