@ryuzaki13/react-foundation-lib 1.9.0 → 2.0.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.
@@ -5,145 +5,241 @@ import { hashString128 as r, uuidv4 as i } from "../crypto/index.js";
5
5
  import { an as a } from "../chunks/odata-service-CWkHASdw.js";
6
6
  import { createIndexedDbQueryStorage as o } from "../query-client/index.js";
7
7
  import { getSessionStorageId as s } from "../session-storage/index.js";
8
+ import { z as c } from "zod";
8
9
  //#region src/error-report/safeValue.ts
9
- var c = 4, ee = 20, l = 40;
10
- function u(e, t = 0) {
11
- if (t >= c) return { type: "truncated" };
12
- if (e === null || typeof e == "string" || typeof e == "number" || typeof e == "boolean") return e;
10
+ var ee = 4, te = 20, ne = 40, l = 4096, re = "[REDACTED]", ie = [
11
+ "apikey",
12
+ "authorization",
13
+ "cookie",
14
+ "csrf",
15
+ "password",
16
+ "passwd",
17
+ "refreshtoken",
18
+ "secret",
19
+ "sessiontoken",
20
+ "token"
21
+ ], ae = "url", u;
22
+ function oe(e) {
23
+ return e.toLowerCase().replace(/[^a-z0-9]/g, "");
24
+ }
25
+ function se(e) {
26
+ let t = oe(e);
27
+ return ie.some((e) => t.includes(e));
28
+ }
29
+ function ce(e) {
30
+ return oe(e).endsWith(ae);
31
+ }
32
+ function le(e) {
33
+ return /^(?:https?:\/\/|\/)[^\s]*[?#]/i.test(e);
34
+ }
35
+ function ue(e) {
36
+ try {
37
+ let t = new URL(e, "https://error-report.invalid"), n = t.pathname;
38
+ return t.origin === "https://error-report.invalid" ? n : `${t.origin}${n}`;
39
+ } catch {
40
+ return e.split(/[?#]/, 1)[0] ?? e;
41
+ }
42
+ }
43
+ function d(e, t = l) {
44
+ let n = e.slice(0, t);
45
+ return /\bbearer\s/i.test(n) && (n = n.replace(/\bBearer\s+[A-Za-z0-9._~+/=-]{8,}/gi, "Bearer [REDACTED]")), n.includes("@") && (n = n.replace(/[A-Z0-9._%+-]{1,254}@[A-Z0-9.-]{1,253}\.[A-Z]{2,63}/gi, "[REDACTED_EMAIL]")), n;
46
+ }
47
+ function f(e) {
48
+ return new TextEncoder().encode(e).byteLength;
49
+ }
50
+ function p(e, t) {
51
+ let n = d(e, t);
52
+ if (f(n) <= t) return n;
53
+ let r = 0, i = n.length;
54
+ for (; r < i;) {
55
+ let e = Math.ceil((r + i) / 2);
56
+ f(n.slice(0, e)) <= t ? r = e : i = e - 1;
57
+ }
58
+ let a = n.charCodeAt(r - 1), o = a >= 55296 && a <= 56319 ? r - 1 : r;
59
+ return n.slice(0, o);
60
+ }
61
+ function m(e, t, n, r) {
62
+ if (r && se(r)) return re;
63
+ if (t >= ee) return { type: "truncated" };
64
+ if (e === null || typeof e == "boolean") return e;
65
+ if (typeof e == "number") return Number.isFinite(e) ? e : { type: "non-finite-number" };
66
+ if (typeof e == "string") return d(r && ce(r) || le(e) ? ue(e) : e, n.maxStringLength);
13
67
  if (e === void 0) return { type: "undefined" };
14
- if (e instanceof Date) return e.toISOString();
15
- if (Array.isArray(e)) return e.slice(0, ee).map((e) => u(e, t + 1));
68
+ if (e instanceof Date) return Number.isNaN(e.getTime()) ? { type: "invalid-date" } : e.toISOString();
16
69
  if (typeof e == "object") {
17
- let n = Object.entries(e).slice(0, l);
18
- return Object.fromEntries(n.map(([e, n]) => [e, u(n, t + 1)]));
70
+ if (n.seen.has(e)) return { type: "circular" };
71
+ n.seen.add(e);
72
+ }
73
+ if (Array.isArray(e)) return e.slice(0, te).map((e) => m(e, t + 1, n));
74
+ if (typeof e == "object") try {
75
+ let r = Object.entries(e).sort(([e], [t]) => e.localeCompare(t)).slice(0, ne);
76
+ return Object.fromEntries(r.map(([e, r]) => [e, m(r, t + 1, n, e)]));
77
+ } catch {
78
+ return { type: "unreadable" };
19
79
  }
20
80
  return typeof e == "function" ? { type: "function" } : typeof e == "symbol" ? { type: "symbol" } : typeof e == "bigint" ? e.toString() : { type: "unknown" };
21
81
  }
22
- function d(e, t = 0) {
23
- if (t >= c) return { type: "truncated" };
82
+ function de(e, t = 0) {
83
+ return m(e, t, {
84
+ seen: /* @__PURE__ */ new WeakSet(),
85
+ maxStringLength: l
86
+ });
87
+ }
88
+ function h(e, t = 0) {
89
+ if (t >= ee) return { type: "truncated" };
24
90
  if (e === null) return { type: "null" };
25
91
  if (e === void 0) return { type: "undefined" };
26
92
  if (Array.isArray(e)) return {
27
93
  type: "array",
28
94
  length: e.length,
29
- firstItemsShape: e.slice(0, 3).map((e) => d(e, t + 1))
95
+ firstItemsShape: e.slice(0, 3).map((e) => h(e, t + 1))
30
96
  };
31
97
  if (typeof e == "object") {
32
- let n = Object.entries(e).slice(0, l);
98
+ let n = Object.entries(e).slice(0, ne);
33
99
  return {
34
100
  type: "object",
35
101
  keys: n.map(([e]) => e),
36
- shape: Object.fromEntries(n.map(([e, n]) => [e, d(n, t + 1)]))
102
+ shape: Object.fromEntries(n.map(([e, n]) => [e, h(n, t + 1)]))
37
103
  };
38
104
  }
39
105
  return { type: typeof e };
40
106
  }
41
- function f(e) {
107
+ function fe(e) {
108
+ u = e;
109
+ }
110
+ function g(e, t, n = l) {
111
+ let r = (e) => m(e, 0, {
112
+ seen: /* @__PURE__ */ new WeakSet(),
113
+ maxStringLength: n
114
+ }), i = r(e);
115
+ if (!u) return i;
116
+ try {
117
+ let e = u(i, t);
118
+ return e === void 0 ? void 0 : r(e);
119
+ } catch {
120
+ return;
121
+ }
122
+ }
123
+ function _(e, t = { scope: "context" }) {
42
124
  if (!e) return;
43
- let t = Object.entries(e).slice(0, l).map(([e, t]) => [e, u(t)]);
44
- return t.length ? Object.fromEntries(t) : void 0;
125
+ let n = g(e, t);
126
+ if (!(!n || Array.isArray(n) || typeof n != "object")) return Object.keys(n).length ? n : void 0;
45
127
  }
46
128
  //#endregion
47
129
  //#region src/error-report/breadcrumbs.ts
48
- var te = 20, ne = 80, re = 120, ie = [
130
+ var pe = 20, me = 120, he = [
49
131
  "button",
50
132
  "a",
51
133
  "input",
52
134
  "select",
53
135
  "textarea",
54
- "[role]",
55
- "[aria-label]",
56
- "[title]",
57
- "[data-ui]",
58
- "[data-action]"
59
- ].join(","), p = [];
60
- function ae() {
136
+ "[role]"
137
+ ].join(","), ge = /^[a-z0-9][a-z0-9._:/-]*$/i, v = [];
138
+ function _e() {
61
139
  return (/* @__PURE__ */ new Date()).toISOString();
62
140
  }
63
- function m(e) {
64
- p = [...p, {
141
+ function y(e) {
142
+ v = [...v, {
65
143
  ...e,
66
- utc: e.utc ?? ae()
144
+ utc: d(e.utc ?? _e(), 64),
145
+ routeId: e.routeId ? d(e.routeId.split(/[?#]/, 1)[0] ?? e.routeId, 512) : void 0,
146
+ appId: e.appId ? d(e.appId, 128) : void 0,
147
+ viewId: e.viewId ? d(e.viewId, 128) : void 0,
148
+ target: e.target ? d(e.target, 2048) : void 0,
149
+ detail: _(e.detail, {
150
+ scope: "breadcrumb-detail",
151
+ source: e.type
152
+ })
67
153
  }].slice(-80);
68
154
  }
69
- function h() {
70
- return p;
155
+ function ve() {
156
+ return v.slice();
71
157
  }
72
- function g() {
73
- p = [];
158
+ function ye() {
159
+ v = [];
74
160
  }
75
- function _(t) {
76
- return e(t, re);
161
+ function be(t) {
162
+ return e(t, me);
77
163
  }
78
- function v(e) {
164
+ function xe(e) {
165
+ let t = be(e.getAttribute("data-error-report-target"));
166
+ return t && ge.test(t) ? t : void 0;
167
+ }
168
+ function b(e, t) {
169
+ let n = be(e.getAttribute(t));
170
+ return n && ge.test(n) ? n : void 0;
171
+ }
172
+ function Se(e) {
173
+ let t = xe(e);
79
174
  return {
80
- id: _(e.id),
81
- role: _(e.getAttribute("role")),
82
- type: _(e.getAttribute("type")),
83
- title: _(e.getAttribute("title")),
84
- ariaLabel: _(e.getAttribute("aria-label")),
85
- dataUi: _(e.getAttribute("data-ui")),
86
- dataAction: _(e.getAttribute("data-action"))
175
+ role: b(e, "role"),
176
+ type: b(e, "type"),
177
+ errorReportTarget: t,
178
+ dataUi: t ? void 0 : b(e, "data-ui"),
179
+ dataAction: t ? void 0 : b(e, "data-action")
87
180
  };
88
181
  }
89
- function oe(t) {
90
- if (!(t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement || t instanceof HTMLSelectElement) && t.matches("button,a,[role],[aria-label],[title]")) return e(t.textContent, ne);
91
- }
92
- function se(e) {
182
+ function x(e) {
93
183
  return typeof CSS < "u" && typeof CSS.escape == "function" ? CSS.escape(e) : e.replace(/["\\#.[\]>~+:]/g, "\\$&");
94
184
  }
95
- function y(e) {
96
- let t = v(e), n = [e.tagName.toLowerCase()];
97
- return t.id && n.push(`#${se(t.id)}`), t.role && n.push(`[role="${t.role}"]`), t.type && n.push(`[type="${t.type}"]`), t.dataUi && n.push(`[data-ui="${t.dataUi}"]`), t.dataAction && n.push(`[data-action="${t.dataAction}"]`), n.join("");
185
+ function Ce(e) {
186
+ let t = Se(e), n = [e.tagName.toLowerCase()];
187
+ return t.role && n.push(`[role="${t.role}"]`), t.type && n.push(`[type="${t.type}"]`), t.errorReportTarget ? n.push(`[data-error-report-target="${x(t.errorReportTarget)}"]`) : (t.dataUi && n.push(`[data-ui="${x(t.dataUi)}"]`), t.dataAction && n.push(`[data-action="${x(t.dataAction)}"]`)), n.join("");
98
188
  }
99
- function b(e) {
100
- let t = v(e);
189
+ function we(e) {
190
+ let t = Se(e);
101
191
  return {
102
192
  tag: e.tagName.toLowerCase(),
103
- selector: y(e),
104
- text: oe(e),
193
+ selector: Ce(e),
105
194
  ...t
106
195
  };
107
196
  }
108
- function x(e) {
197
+ function Te(e) {
109
198
  return Object.fromEntries(Object.entries(e).filter(([, e]) => e !== void 0 && (!Array.isArray(e) || e.length > 0)));
110
199
  }
111
200
  function S(e) {
112
201
  let t = [], n = e;
113
- for (; n && n !== document.documentElement && t.length < te && (t.push(n), n !== document.body);) n = n.parentElement;
202
+ for (; n && n !== document.documentElement && t.length < pe && (t.push(n), n !== document.body);) n = n.parentElement;
114
203
  return t;
115
204
  }
116
- function C(e) {
117
- return e.closest(ie) ?? e;
205
+ function Ee(e) {
206
+ let t = S(e);
207
+ return t.find((e) => xe(e)) || (t.find((e) => e.matches(he) || b(e, "data-action") !== void 0 || b(e, "data-ui") !== void 0) ?? e);
118
208
  }
119
- function ce(e) {
120
- if (e instanceof Element) return S(C(e)).map((e) => y(e)).join(" > ");
209
+ function De(e) {
210
+ if (e instanceof Element) return S(Ee(e)).map((e) => Ce(e)).join(" > ");
121
211
  }
122
- function le(e) {
123
- let t = e.target instanceof Element ? e.target : void 0, n = t ? C(t) : void 0, r = n ? S(n).map((e) => x(b(e))) : [];
124
- return f({
212
+ function Oe(e) {
213
+ let t = e.target instanceof Element ? e.target : void 0, n = t ? Ee(t) : void 0, r = n ? S(n).map((e) => Te(we(e))) : [];
214
+ return _({
125
215
  button: e.button,
126
216
  ctrlKey: e.ctrlKey,
127
217
  shiftKey: e.shiftKey,
128
218
  altKey: e.altKey,
129
219
  clientX: e.clientX,
130
220
  clientY: e.clientY,
131
- target: n ? x(b(n)) : void 0,
221
+ target: n ? Te(we(n)) : void 0,
132
222
  chain: r
223
+ }, {
224
+ scope: "breadcrumb-detail",
225
+ source: "click"
133
226
  });
134
227
  }
135
- function w() {
228
+ function ke() {
136
229
  if (typeof window > "u") return () => void 0;
137
230
  let e = (e) => {
138
- m({
231
+ y({
139
232
  type: "click",
140
- target: ce(e.target),
141
- detail: le(e)
233
+ target: De(e.target),
234
+ detail: Oe(e)
142
235
  });
143
236
  }, t = () => {
144
- m({
237
+ y({
145
238
  type: "visibility",
146
- detail: f({ visibilityState: document.visibilityState })
239
+ detail: _({ visibilityState: document.visibilityState }, {
240
+ scope: "breadcrumb-detail",
241
+ source: "visibility"
242
+ })
147
243
  });
148
244
  };
149
245
  return window.addEventListener("click", e, !0), document.addEventListener("visibilitychange", t), () => {
@@ -151,58 +247,247 @@ function w() {
151
247
  };
152
248
  }
153
249
  //#endregion
154
- //#region src/error-report/errorInfo.ts
155
- var T = "Неизвестная ошибка";
156
- function E(e) {
157
- return t(e) ? e : T;
250
+ //#region src/error-report/payload.ts
251
+ var Ae = 1, C = 262144, w = 65536, je = 32768, Me = 256, Ne = 128, Pe = 2048;
252
+ function Fe(e) {
253
+ return new TextEncoder().encode(JSON.stringify(e)).byteLength;
254
+ }
255
+ function Ie(e) {
256
+ return d(e.split(/[?#]/, 1)[0] ?? e, Pe);
257
+ }
258
+ function T(e, t, n, r = "characters") {
259
+ let i = g(r === "bytes" ? p(e, n) : d(e, n), t, n);
260
+ if (typeof i == "string") return r === "bytes" ? p(i, n) : d(i, n);
261
+ }
262
+ function E(e, t) {
263
+ return {
264
+ name: d(e.name, 256),
265
+ message: T(e.message, {
266
+ scope: "error-message",
267
+ source: t
268
+ }, 4096) ?? "[REDACTED]",
269
+ code: e.code ? d(e.code, 128) : void 0,
270
+ stackTrace: e.stackTrace ? T(e.stackTrace, {
271
+ scope: "stack-trace",
272
+ source: t
273
+ }, w, "bytes") : void 0,
274
+ httpStatus: e.httpStatus
275
+ };
276
+ }
277
+ function Le(e) {
278
+ return {
279
+ ...e,
280
+ queryHash: d(e.queryHash, 512),
281
+ queryKey: g(e.queryKey, {
282
+ scope: "query-key",
283
+ source: e.queryHash
284
+ }) ?? { type: "redacted" },
285
+ meta: _(e.meta, {
286
+ scope: "query-meta",
287
+ source: e.queryHash
288
+ }),
289
+ dataShape: e.dataShape ? g(e.dataShape, {
290
+ scope: "query-data-shape",
291
+ source: e.queryHash
292
+ }) : void 0,
293
+ error: e.error ? E(e.error, e.queryHash) : void 0
294
+ };
295
+ }
296
+ function Re(e) {
297
+ return {
298
+ ...e,
299
+ mutationKey: e.mutationKey ? g(e.mutationKey, { scope: "mutation-key" }) : void 0,
300
+ meta: _(e.meta, { scope: "mutation-meta" }),
301
+ error: e.error ? E(e.error, "mutation") : void 0
302
+ };
303
+ }
304
+ function ze(e) {
305
+ return {
306
+ ...e,
307
+ buster: e.buster ? d(e.buster, 512) : void 0,
308
+ queryHash: e.queryHash ? d(e.queryHash, 512) : void 0,
309
+ queryKey: e.queryKey ? g(e.queryKey, {
310
+ scope: "persisted-query-key",
311
+ source: e.queryHash
312
+ }) : void 0,
313
+ error: e.error ? E(e.error, e.queryHash) : void 0
314
+ };
158
315
  }
159
316
  function D(e) {
317
+ return Fe(e);
318
+ }
319
+ function Be(e) {
320
+ return {
321
+ ...e,
322
+ reportId: d(e.reportId, 128),
323
+ sessionId: d(e.sessionId, 128),
324
+ createdUtc: d(e.createdUtc, 64),
325
+ application: d(e.application, Ne),
326
+ source: d(e.source, Me),
327
+ error: E(e.error, e.source),
328
+ environment: {
329
+ ...e.environment,
330
+ buildId: e.environment.buildId ? d(e.environment.buildId, 128) : void 0
331
+ },
332
+ client: e.client ? {
333
+ userAgent: e.client.userAgent ? d(e.client.userAgent) : void 0,
334
+ language: e.client.language ? d(e.client.language, 128) : void 0,
335
+ timeZone: e.client.timeZone ? d(e.client.timeZone, 128) : void 0
336
+ } : void 0,
337
+ location: e.location ? {
338
+ pathname: Ie(e.location.pathname),
339
+ origin: e.location.origin ? d(e.location.origin.split(/[?#]/, 1)[0] ?? e.location.origin, Pe) : void 0
340
+ } : void 0,
341
+ react: e.react?.componentStack ? { componentStack: T(e.react.componentStack, {
342
+ scope: "stack-trace",
343
+ source: "react-component-stack"
344
+ }, je, "bytes") } : void 0,
345
+ query: e.query ? Le(e.query) : void 0,
346
+ mutation: e.mutation ? Re(e.mutation) : void 0,
347
+ queryClient: e.queryClient ? {
348
+ queries: e.queryClient.queries.slice(-40).map(Le),
349
+ mutations: e.queryClient.mutations.slice(-40).map(Re)
350
+ } : void 0,
351
+ persistedQueries: e.persistedQueries?.slice(-40).map(ze),
352
+ breadcrumbs: e.breadcrumbs.slice(-80).map((e) => ({
353
+ ...e,
354
+ utc: d(e.utc, 64),
355
+ routeId: e.routeId ? d(e.routeId, 512) : void 0,
356
+ appId: e.appId ? d(e.appId, 128) : void 0,
357
+ viewId: e.viewId ? d(e.viewId, 128) : void 0,
358
+ target: e.target ? d(e.target, 2048) : void 0,
359
+ detail: _(e.detail, {
360
+ scope: "breadcrumb-detail",
361
+ source: e.type
362
+ })
363
+ })),
364
+ context: _(e.context, {
365
+ scope: "context",
366
+ source: e.source
367
+ })
368
+ };
369
+ }
370
+ function Ve(e) {
371
+ let t = Be(e), n = D(t);
372
+ if (n <= 262144) return t;
373
+ let r = [], i = {
374
+ ...t,
375
+ truncation: {
376
+ reason: "payload-size",
377
+ limitBytes: C,
378
+ originalBytes: n,
379
+ droppedSections: r
380
+ }
381
+ }, a = (e, t, n) => {
382
+ !t(i) || D(i) <= 262144 || (r.push(e), i = n(i));
383
+ };
384
+ return a("queryClient", (e) => e.queryClient !== void 0, (e) => ({
385
+ ...e,
386
+ queryClient: void 0
387
+ })), a("persistedQueries", (e) => e.persistedQueries !== void 0, (e) => ({
388
+ ...e,
389
+ persistedQueries: void 0
390
+ })), a("context", (e) => e.context !== void 0, (e) => ({
391
+ ...e,
392
+ context: void 0
393
+ })), a("query.meta", (e) => e.query?.meta !== void 0, (e) => ({
394
+ ...e,
395
+ query: e.query ? {
396
+ ...e.query,
397
+ meta: void 0
398
+ } : void 0
399
+ })), a("query.dataShape", (e) => e.query?.dataShape !== void 0, (e) => ({
400
+ ...e,
401
+ query: e.query ? {
402
+ ...e.query,
403
+ dataShape: void 0
404
+ } : void 0
405
+ })), a("mutation.meta", (e) => e.mutation?.meta !== void 0, (e) => ({
406
+ ...e,
407
+ mutation: e.mutation ? {
408
+ ...e.mutation,
409
+ meta: void 0
410
+ } : void 0
411
+ })), a("breadcrumbs:oldest", (e) => e.breadcrumbs.length > 20, (e) => ({
412
+ ...e,
413
+ breadcrumbs: e.breadcrumbs.slice(-20)
414
+ })), a("query", (e) => e.query !== void 0, (e) => ({
415
+ ...e,
416
+ query: void 0
417
+ })), a("mutation", (e) => e.mutation !== void 0, (e) => ({
418
+ ...e,
419
+ mutation: void 0
420
+ })), a("react", (e) => e.react !== void 0, (e) => ({
421
+ ...e,
422
+ react: void 0
423
+ })), a("breadcrumbs", (e) => e.breadcrumbs.length > 0, (e) => ({
424
+ ...e,
425
+ breadcrumbs: []
426
+ })), a("client", (e) => e.client !== void 0, (e) => ({
427
+ ...e,
428
+ client: void 0
429
+ })), a("viewport", (e) => e.viewport !== void 0, (e) => ({
430
+ ...e,
431
+ viewport: void 0
432
+ })), i;
433
+ }
434
+ //#endregion
435
+ //#region src/error-report/errorInfo.ts
436
+ var He = "Неизвестная ошибка";
437
+ function O(e) {
438
+ return t(e) ? d(e) : He;
439
+ }
440
+ function Ue(e) {
160
441
  let t = e.status ?? e.statusCode ?? e.httpStatus;
161
442
  return typeof t == "number" && Number.isFinite(t) ? t : void 0;
162
443
  }
163
- function ue(e) {
444
+ function We(e) {
164
445
  if (!e || typeof e != "object") return null;
165
446
  let n = e.appError;
166
447
  if (!n || typeof n != "object") return null;
167
448
  let r = n, i = t(r.message);
168
449
  return i ? {
169
450
  name: "AppError",
170
- message: i,
171
- code: t(r.code),
172
- httpStatus: D(r)
451
+ message: d(i),
452
+ code: t(r.code) ? d(String(r.code), 128) : void 0,
453
+ httpStatus: Ue(r)
173
454
  } : null;
174
455
  }
175
- function O(e) {
176
- let t = ue(e);
456
+ function k(e) {
457
+ let t = We(e);
177
458
  if (t) return t;
178
459
  if (e instanceof Error) return {
179
- name: e.name || "Error",
180
- message: E(e.message),
181
- stackTrace: e.stack
460
+ name: d(e.name || "Error", 256),
461
+ message: O(e.message),
462
+ stackTrace: e.stack ? p(e.stack, w) : void 0
182
463
  };
183
464
  if (e && typeof e == "object") {
184
465
  let t = e;
185
466
  return {
186
- name: typeof t.name == "string" ? t.name : "Error",
187
- message: E(typeof t.message == "string" ? t.message : String(e)),
188
- stackTrace: typeof t.stack == "string" ? t.stack : void 0,
189
- httpStatus: D(t)
467
+ name: d(typeof t.name == "string" ? t.name : "Error", 256),
468
+ message: O(typeof t.message == "string" ? t.message : String(e)),
469
+ stackTrace: typeof t.stack == "string" ? p(t.stack, w) : void 0,
470
+ httpStatus: Ue(t)
190
471
  };
191
472
  }
192
473
  return {
193
474
  name: "Error",
194
- message: E(typeof e == "string" ? e : String(e ?? T))
475
+ message: O(typeof e == "string" ? e : String(e ?? He))
195
476
  };
196
477
  }
197
478
  //#endregion
198
479
  //#region src/error-report/diagnostics.ts
199
- function k(e) {
200
- return f(e);
480
+ function Ge(e, t, n) {
481
+ return _(e, {
482
+ scope: t,
483
+ source: n
484
+ });
201
485
  }
202
486
  function A(e) {
487
+ let t = g(e.queryKey, { scope: "query-key" }) ?? { type: "redacted" }, i = r(n(t));
203
488
  return {
204
- queryHash: e.queryHash,
205
- queryKey: u(e.queryKey),
489
+ queryHash: i,
490
+ queryKey: t,
206
491
  status: e.state.status,
207
492
  fetchStatus: e.state.fetchStatus,
208
493
  dataUpdatedAt: e.state.dataUpdatedAt,
@@ -210,19 +495,22 @@ function A(e) {
210
495
  failureCount: e.state.fetchFailureCount,
211
496
  isInvalidated: e.state.isInvalidated,
212
497
  observersCount: e.getObserversCount(),
213
- meta: k(e.meta),
214
- dataShape: d(e.state.data),
215
- error: e.state.error ? O(e.state.error) : void 0
498
+ meta: Ge(e.meta, "query-meta", i),
499
+ dataShape: g(h(e.state.data), {
500
+ scope: "query-data-shape",
501
+ source: i
502
+ }),
503
+ error: e.state.error ? k(e.state.error) : void 0
216
504
  };
217
505
  }
218
506
  function j(e) {
219
507
  return {
220
- mutationKey: e.options.mutationKey ? u(e.options.mutationKey) : void 0,
508
+ mutationKey: e.options.mutationKey ? g(e.options.mutationKey, { scope: "mutation-key" }) : void 0,
221
509
  status: e.state.status,
222
510
  failureCount: e.state.failureCount,
223
511
  submittedAt: e.state.submittedAt,
224
- meta: k(e.meta),
225
- error: e.state.error ? O(e.state.error) : void 0
512
+ meta: Ge(e.meta, "mutation-meta"),
513
+ error: e.state.error ? k(e.state.error) : void 0
226
514
  };
227
515
  }
228
516
  function M(e) {
@@ -231,43 +519,42 @@ function M(e) {
231
519
  mutations: e.getMutationCache().getAll().slice(-40).map(j)
232
520
  };
233
521
  }
234
- function de(e, t) {
235
- let n = t.state;
522
+ function Ke(e) {
523
+ let t = e.state, i = g(e.queryKey, { scope: "persisted-query-key" }), a = i ? r(n(i)) : void 0;
236
524
  return {
237
- storageKey: e,
238
- buster: t.buster,
239
- queryHash: t.queryHash,
240
- queryKey: u(t.queryKey),
241
- status: n.status,
242
- fetchStatus: n.fetchStatus,
243
- dataUpdatedAt: n.dataUpdatedAt,
244
- errorUpdatedAt: n.errorUpdatedAt,
245
- failureCount: n.fetchFailureCount,
246
- error: n.error ? O(n.error) : void 0
525
+ buster: e.buster ? d(e.buster, 512) : void 0,
526
+ queryHash: a,
527
+ queryKey: i,
528
+ status: t.status,
529
+ fetchStatus: t.fetchStatus,
530
+ dataUpdatedAt: t.dataUpdatedAt,
531
+ errorUpdatedAt: t.errorUpdatedAt,
532
+ failureCount: t.fetchFailureCount,
533
+ error: t.error ? k(t.error) : void 0
247
534
  };
248
535
  }
249
536
  async function N() {
250
537
  let e = o();
251
538
  if (!e?.entries) return [];
252
539
  try {
253
- return (await e.entries()).slice(-40).map(([e, t]) => de(e, t));
540
+ return (await e.entries()).slice(-40).map(([, e]) => Ke(e));
254
541
  } catch {
255
542
  return [];
256
543
  }
257
544
  }
258
545
  //#endregion
259
546
  //#region src/error-report/environment.ts
260
- function P(e = {}) {
547
+ function qe(e = {}) {
261
548
  let t = e.isDev ?? __DEV__;
262
549
  return typeof window < "u" && !t;
263
550
  }
264
- function F() {
551
+ function Je() {
265
552
  return {
266
553
  mode: __DEV__ ? "development" : "production",
267
554
  buildId: typeof __APP_BUILD_ID__ == "string" ? __APP_BUILD_ID__ : void 0
268
555
  };
269
556
  }
270
- function I() {
557
+ function Ye() {
271
558
  if (!(typeof window > "u")) return {
272
559
  userAgent: window.navigator.userAgent,
273
560
  language: window.navigator.language,
@@ -275,135 +562,312 @@ function I() {
275
562
  };
276
563
  }
277
564
  //#endregion
565
+ //#region src/error-report/schema.ts
566
+ var P = c.lazy(() => c.union([
567
+ c.string().max(4096),
568
+ c.number().finite(),
569
+ c.boolean(),
570
+ c.null(),
571
+ c.array(P).max(20),
572
+ c.record(c.string(), P).refine((e) => Object.keys(e).length <= 40)
573
+ ])), F = c.record(c.string(), P).refine((e) => Object.keys(e).length <= 40), I = c.object({
574
+ name: c.string().min(1).max(256),
575
+ message: c.string().min(1).max(4096),
576
+ code: c.string().max(128).optional(),
577
+ stackTrace: c.string().refine((e) => f(e) <= 65536).optional(),
578
+ httpStatus: c.number().finite().optional()
579
+ }).strict(), Xe = c.object({
580
+ utc: c.string().min(1).max(64),
581
+ type: c.enum([
582
+ "route",
583
+ "click",
584
+ "visibility",
585
+ "query-error",
586
+ "mutation-error",
587
+ "runtime-error"
588
+ ]),
589
+ routeId: c.string().max(512).optional(),
590
+ appId: c.string().max(128).optional(),
591
+ viewId: c.string().max(128).optional(),
592
+ target: c.string().max(2048).optional(),
593
+ detail: F.optional()
594
+ }).strict(), Ze = c.object({
595
+ queryHash: c.string().max(512),
596
+ queryKey: P,
597
+ status: c.string().max(64).optional(),
598
+ fetchStatus: c.string().max(64).optional(),
599
+ dataUpdatedAt: c.number().finite().optional(),
600
+ errorUpdatedAt: c.number().finite().optional(),
601
+ failureCount: c.number().finite().optional(),
602
+ isInvalidated: c.boolean().optional(),
603
+ observersCount: c.number().finite().optional(),
604
+ meta: F.optional(),
605
+ dataShape: P.optional(),
606
+ error: I.optional()
607
+ }).strict(), Qe = c.object({
608
+ mutationKey: P.optional(),
609
+ status: c.string().max(64).optional(),
610
+ failureCount: c.number().finite().optional(),
611
+ submittedAt: c.number().finite().optional(),
612
+ meta: F.optional(),
613
+ error: I.optional()
614
+ }).strict(), $e = c.object({
615
+ buster: c.string().max(512).optional(),
616
+ queryHash: c.string().max(512).optional(),
617
+ queryKey: P.optional(),
618
+ status: c.string().max(64).optional(),
619
+ fetchStatus: c.string().max(64).optional(),
620
+ dataUpdatedAt: c.number().finite().optional(),
621
+ errorUpdatedAt: c.number().finite().optional(),
622
+ failureCount: c.number().finite().optional(),
623
+ error: I.optional()
624
+ }).strict(), et = c.object({
625
+ payloadVersion: c.literal(1),
626
+ application: c.string().min(1).max(128),
627
+ reportId: c.string().uuid(),
628
+ sessionId: c.string().uuid(),
629
+ createdUtc: c.string().min(1).max(64),
630
+ category: c.enum([
631
+ "query",
632
+ "mutation",
633
+ "runtime",
634
+ "react"
635
+ ]),
636
+ source: c.string().min(1).max(256),
637
+ error: I,
638
+ environment: c.object({
639
+ mode: c.enum(["development", "production"]),
640
+ buildId: c.string().max(128).optional()
641
+ }).strict(),
642
+ client: c.object({
643
+ userAgent: c.string().max(4096).optional(),
644
+ language: c.string().max(128).optional(),
645
+ timeZone: c.string().max(128).optional()
646
+ }).strict().optional(),
647
+ location: c.object({
648
+ pathname: c.string().max(2048),
649
+ origin: c.string().max(2048).optional()
650
+ }).strict().optional(),
651
+ viewport: c.object({
652
+ width: c.number().finite(),
653
+ height: c.number().finite(),
654
+ devicePixelRatio: c.number().finite().optional()
655
+ }).strict().optional(),
656
+ react: c.object({ componentStack: c.string().refine((e) => f(e) <= 32768).optional() }).strict().optional(),
657
+ query: Ze.optional(),
658
+ mutation: Qe.optional(),
659
+ queryClient: c.object({
660
+ queries: c.array(Ze).max(40),
661
+ mutations: c.array(Qe).max(40)
662
+ }).strict().optional(),
663
+ persistedQueries: c.array($e).max(40).optional(),
664
+ breadcrumbs: c.array(Xe).max(80),
665
+ context: F.optional(),
666
+ truncation: c.object({
667
+ reason: c.literal("payload-size"),
668
+ limitBytes: c.literal(C),
669
+ originalBytes: c.number().int().positive(),
670
+ droppedSections: c.array(c.string().max(128)).max(32)
671
+ }).strict().optional()
672
+ }).strict().refine((e) => D(e) <= C), tt = c.object({
673
+ reportId: c.string().uuid(),
674
+ sessionId: c.string().uuid(),
675
+ createdUtc: c.string().min(1).max(64),
676
+ category: c.enum([
677
+ "query",
678
+ "mutation",
679
+ "runtime",
680
+ "react"
681
+ ]),
682
+ status: c.enum([
683
+ "pending",
684
+ "sending",
685
+ "sent",
686
+ "failed"
687
+ ]),
688
+ sentUtc: c.string().min(1).max(64).optional(),
689
+ failedReason: c.string().max(4096).optional(),
690
+ payload: et
691
+ }).strict().superRefine((e, t) => {
692
+ (e.reportId !== e.payload.reportId || e.sessionId !== e.payload.sessionId || e.createdUtc !== e.payload.createdUtc || e.category !== e.payload.category) && t.addIssue({
693
+ code: "custom",
694
+ message: "Draft identity должна совпадать с payload identity."
695
+ });
696
+ });
697
+ function nt(e, t) {
698
+ try {
699
+ return new TextEncoder().encode(JSON.stringify(e)).byteLength <= t;
700
+ } catch {
701
+ return !1;
702
+ }
703
+ }
704
+ function L(e) {
705
+ if (nt(e, 262144)) try {
706
+ let t = et.safeParse(e);
707
+ return t.success ? t.data : void 0;
708
+ } catch {
709
+ return;
710
+ }
711
+ }
712
+ function R(e) {
713
+ if (nt(e, 278528)) try {
714
+ let t = tt.safeParse(e);
715
+ return t.success ? t.data : void 0;
716
+ } catch {
717
+ return;
718
+ }
719
+ }
720
+ function rt(e) {
721
+ return Array.isArray(e) ? e.flatMap((e) => {
722
+ let t = R(e);
723
+ return t ? [t] : [];
724
+ }) : [];
725
+ }
726
+ //#endregion
278
727
  //#region src/error-report/drafts.ts
279
- var L = `${__APP_ID__}.errorReport.drafts.v1`, fe = `${__APP_ID__}.errorReport.sessionId.v1`, R = B();
280
- function z() {
728
+ var it = `${__APP_ID__}.errorReport.drafts.v2`, at = `${__APP_ID__}.errorReport.sessionId.v1`, z = st();
729
+ function ot() {
281
730
  return a(/* @__PURE__ */ new Date());
282
731
  }
283
- function B() {
732
+ function st() {
284
733
  if (typeof sessionStorage > "u") return [];
285
734
  try {
286
- let e = sessionStorage.getItem(L), t = e ? JSON.parse(e) : [];
287
- return Array.isArray(t) ? t : [];
735
+ let e = sessionStorage.getItem(it);
736
+ return rt(e ? JSON.parse(e) : []);
288
737
  } catch {
289
738
  return [];
290
739
  }
291
740
  }
292
- function V(e) {
293
- if (R = e.slice(-10), !(typeof sessionStorage > "u")) try {
294
- sessionStorage.setItem(L, JSON.stringify(R));
741
+ function ct(e) {
742
+ if (z = e.slice(-10), !(typeof sessionStorage > "u")) try {
743
+ sessionStorage.setItem(it, JSON.stringify(z));
295
744
  } catch {}
296
745
  }
297
- function pe() {
746
+ function lt() {
298
747
  if (!(typeof window > "u")) return {
299
748
  pathname: window.location.pathname,
300
749
  origin: window.location.origin
301
750
  };
302
751
  }
303
- function me() {
752
+ function ut() {
304
753
  if (!(typeof window > "u")) return {
305
754
  width: window.innerWidth,
306
755
  height: window.innerHeight,
307
756
  devicePixelRatio: window.devicePixelRatio
308
757
  };
309
758
  }
310
- function H(e) {
311
- return R.find((t) => t.reportId === e);
759
+ function dt(e) {
760
+ if (!e) return;
761
+ let t = g(e, {
762
+ scope: "draft-failed-reason",
763
+ source: "delivery"
764
+ });
765
+ return typeof t == "string" ? t : void 0;
312
766
  }
313
- function he(e, t) {
314
- let n = H(e);
767
+ function ft(e) {
768
+ return z.find((t) => t.reportId === e);
769
+ }
770
+ function pt(e, t) {
771
+ let n = ft(e);
315
772
  if (!n) return;
316
- let r = {
773
+ let r = R({
317
774
  ...n,
318
- ...t
319
- };
320
- return V(R.map((t) => t.reportId === e ? r : t)), r;
775
+ ...t,
776
+ sentUtc: "sentUtc" in t ? t.sentUtc ? d(t.sentUtc, 64) : void 0 : n.sentUtc,
777
+ failedReason: "failedReason" in t ? dt(t.failedReason) : n.failedReason
778
+ });
779
+ if (r) return ct(z.map((t) => t.reportId === e ? r : t)), r;
321
780
  }
322
- function ge() {
323
- return R;
781
+ function mt() {
782
+ return z;
324
783
  }
325
- function U(e) {
326
- if (!P()) return;
327
- let t = i(), n = s(fe), r = z(), a = {
784
+ function B(e) {
785
+ if (!qe()) return;
786
+ let t = i(), n = s(at), r = ot(), a = Ve({
787
+ payloadVersion: 1,
788
+ application: __APP_ID__,
328
789
  reportId: t,
329
790
  sessionId: n,
330
791
  createdUtc: r,
331
792
  category: e.category,
332
- source: e.source,
793
+ source: d(e.source, 256),
333
794
  error: e.error,
334
- environment: F(),
335
- client: I(),
336
- location: pe(),
337
- viewport: me(),
795
+ environment: Je(),
796
+ client: Ye(),
797
+ location: lt(),
798
+ viewport: ut(),
338
799
  react: e.react,
339
800
  query: e.query,
340
801
  mutation: e.mutation,
341
802
  queryClient: e.queryClient,
342
803
  persistedQueries: e.persistedQueries,
343
- breadcrumbs: h(),
344
- context: e.context
345
- }, o = {
804
+ breadcrumbs: ve(),
805
+ context: _(e.context, {
806
+ scope: "context",
807
+ source: e.source
808
+ })
809
+ }), o = R({
346
810
  reportId: t,
347
811
  sessionId: n,
348
812
  createdUtc: r,
349
813
  category: e.category,
350
814
  status: "pending",
351
815
  payload: a
352
- };
353
- return V([...R, o]), o;
816
+ });
817
+ if (o) return ct([...z, o]), o;
354
818
  }
355
819
  //#endregion
356
820
  //#region src/error-report/runtimeDeduplication.ts
357
- var _e = 6e4, ve = 100, W = /* @__PURE__ */ new Map();
358
- function ye(e) {
821
+ var ht = 6e4, gt = 100, V = /* @__PURE__ */ new Map();
822
+ function _t(e) {
359
823
  if (e) return e.split("\n").map((e) => e.trim()).filter(Boolean);
360
824
  }
361
- function be(e) {
825
+ function vt(e) {
362
826
  return r(n({
363
827
  category: e.category,
364
828
  source: e.source,
365
829
  error: {
366
830
  ...e.error,
367
- stackTrace: ye(e.error.stackTrace)
831
+ stackTrace: _t(e.error.stackTrace)
368
832
  },
369
833
  pathname: e.pathname,
370
834
  scope: e.scope
371
835
  }));
372
836
  }
373
- function G(e, t) {
374
- let n = W.get(e);
375
- !n || t && n.capture !== t || (clearTimeout(n.expirationTimer), W.delete(e));
837
+ function H(e, t) {
838
+ let n = V.get(e);
839
+ !n || t && n.capture !== t || (clearTimeout(n.expirationTimer), V.delete(e));
376
840
  }
377
- function xe(e) {
378
- for (let [t, n] of W) e - n.capturedAt >= 6e4 && G(t, n.capture);
841
+ function yt(e) {
842
+ for (let [t, n] of V) e - n.capturedAt >= 6e4 && H(t, n.capture);
379
843
  }
380
- function Se() {
381
- let e = W.keys().next().value;
382
- e && G(e);
844
+ function bt() {
845
+ let e = V.keys().next().value;
846
+ e && H(e);
383
847
  }
384
- function Ce(e, t) {
385
- let n = Date.now(), r = be(e), i = W.get(r);
848
+ function xt(e, t) {
849
+ let n = Date.now(), r = vt(e), i = V.get(r);
386
850
  if (i && n - i.capturedAt < 6e4) return i.capture;
387
- for (xe(n); W.size >= ve;) Se();
851
+ for (yt(n); V.size >= gt;) bt();
388
852
  let a = t(), o = setTimeout(() => {
389
- G(r, a);
390
- }, _e);
391
- return W.set(r, {
853
+ H(r, a);
854
+ }, ht);
855
+ return V.set(r, {
392
856
  capturedAt: n,
393
857
  capture: a,
394
858
  expirationTimer: o
395
859
  }), a.catch(() => {
396
- G(r, a);
860
+ H(r, a);
397
861
  }), a;
398
862
  }
399
- function we() {
400
- for (let e of W.values()) clearTimeout(e.expirationTimer);
401
- W.clear();
863
+ function St() {
864
+ for (let e of V.values()) clearTimeout(e.expirationTimer);
865
+ V.clear();
402
866
  }
403
867
  //#endregion
404
868
  //#region src/error-report/transport.ts
405
- var K = 6e4, Te = 100, Ee = 250, q, J = /* @__PURE__ */ new WeakSet(), Y = /* @__PURE__ */ new WeakSet(), X = /* @__PURE__ */ new Map();
406
- function De(e) {
869
+ var Ct = 6e4, wt = 100, Tt = 250, U, Et = /* @__PURE__ */ new WeakSet(), Dt = /* @__PURE__ */ new WeakSet(), W = /* @__PURE__ */ new Map();
870
+ function Ot(e) {
407
871
  return [
408
872
  e.source,
409
873
  e.method,
@@ -412,85 +876,103 @@ function De(e) {
412
876
  e.responseUrl
413
877
  ].filter(Boolean).join("|");
414
878
  }
415
- function Z(e) {
416
- let t = Date.now(), n = De(e);
417
- for (let [e, n] of X) (t - n > K || X.size > Te) && X.delete(e);
418
- let r = X.get(n);
419
- return r && t - r < K ? !0 : (X.set(n, t), !1);
879
+ function kt(e) {
880
+ let t = Date.now(), n = Ot(e);
881
+ for (let [e, n] of W) (t - n > Ct || W.size > wt) && W.delete(e);
882
+ let r = W.get(n);
883
+ return r && t - r < Ct ? !0 : (W.set(n, t), !1);
420
884
  }
421
- function Oe(e) {
422
- q = e, X.clear();
885
+ function At(e) {
886
+ U = e, W.clear();
423
887
  }
424
- function ke(e) {
425
- return e instanceof Error && J.has(e);
888
+ function jt(e) {
889
+ return e instanceof Error && Et.has(e);
426
890
  }
427
- function Q(e) {
428
- e instanceof Error && Y.add(e);
891
+ function G(e) {
892
+ e instanceof Error && Dt.add(e);
429
893
  }
430
- function Ae(e, t) {
431
- J.add(e), setTimeout(() => {
432
- if (!Y.has(e) && q && !Z(t)) try {
433
- let n = q(e, t);
894
+ function Mt(e, t) {
895
+ Et.add(e), setTimeout(() => {
896
+ if (!Dt.has(e) && U && !kt(t)) try {
897
+ let n = U(e, t);
434
898
  Promise.resolve(n).catch(() => void 0);
435
899
  } catch {}
436
- }, Ee);
900
+ }, Tt);
437
901
  }
438
902
  //#endregion
439
903
  //#region src/error-report/capture.ts
440
- async function je(e, t, n, r) {
441
- Q(e);
904
+ async function Nt(e, t, n, r) {
905
+ G(e);
442
906
  let i = r?.source ?? "query";
443
- m({
907
+ y({
444
908
  type: "query-error",
445
- detail: f({
446
- queryHash: t.queryHash,
909
+ detail: _({
447
910
  queryKey: r?.queryKey ?? t.queryKey,
448
911
  ...r?.detail
912
+ }, {
913
+ scope: "breadcrumb-detail",
914
+ source: i
449
915
  })
450
916
  });
451
917
  let [a, o] = await Promise.all([N(), Promise.resolve(M(n))]);
452
- return U({
918
+ return B({
453
919
  category: "query",
454
920
  source: i,
455
- error: r?.errorInfo ?? O(e),
921
+ error: r?.errorInfo ?? k(e),
456
922
  query: A(t),
457
923
  queryClient: o,
458
924
  persistedQueries: a,
459
- context: f(r?.detail)
925
+ context: _(r?.detail, {
926
+ scope: "context",
927
+ source: i
928
+ })
460
929
  });
461
930
  }
462
- async function Me(e, t, n, r = {}) {
463
- Q(e);
931
+ async function Pt(e, t, n, r = {}) {
932
+ G(e);
464
933
  let i = r.source ?? "mutation";
465
- m({
934
+ y({
466
935
  type: "mutation-error",
467
- detail: f({
936
+ detail: _({
468
937
  mutationKey: t.options.mutationKey,
469
938
  ...r.detail
939
+ }, {
940
+ scope: "breadcrumb-detail",
941
+ source: i
470
942
  })
471
943
  });
472
944
  let [a, o] = await Promise.all([N(), Promise.resolve(M(n))]);
473
- return U({
945
+ return B({
474
946
  category: "mutation",
475
947
  source: i,
476
- error: r.errorInfo ?? O(e),
948
+ error: r.errorInfo ?? k(e),
477
949
  mutation: j(t),
478
950
  queryClient: o,
479
- persistedQueries: a
951
+ persistedQueries: a,
952
+ context: _(r.detail, {
953
+ scope: "context",
954
+ source: i
955
+ })
480
956
  });
481
957
  }
482
- function Ne(e, t = {}, n) {
483
- let r = t.category ?? "runtime", i = t.source ?? t.category ?? "runtime", a = t.errorInfo ?? O(e), o = f(t.detail), s = async () => {
484
- m({
958
+ function Ft(e, t = {}, n) {
959
+ let r = t.category ?? "runtime", i = t.source ?? t.category ?? "runtime", a = t.errorInfo ?? k(e), o = _(t.detail, {
960
+ scope: "context",
961
+ source: i
962
+ }), s = async () => {
963
+ y({
485
964
  type: "runtime-error",
486
- detail: f({
965
+ detail: _({
487
966
  category: r,
488
967
  source: i,
489
968
  ...t.detail
969
+ }, {
970
+ scope: "breadcrumb-detail",
971
+ source: i
490
972
  })
491
973
  });
492
974
  let [e, s] = n ? await Promise.all([N(), Promise.resolve(M(n))]) : [void 0, void 0];
493
- return U({
975
+ return B({
494
976
  category: r,
495
977
  source: i,
496
978
  error: a,
@@ -500,7 +982,7 @@ function Ne(e, t = {}, n) {
500
982
  context: o
501
983
  });
502
984
  };
503
- return typeof window > "u" ? s() : Ce({
985
+ return typeof window > "u" ? s() : xt({
504
986
  category: r,
505
987
  source: i,
506
988
  error: a,
@@ -512,17 +994,248 @@ function Ne(e, t = {}, n) {
512
994
  }, s);
513
995
  }
514
996
  //#endregion
997
+ //#region src/error-report/queueContract.ts
998
+ var It = 1, Lt = 50, Rt = 6048e5, zt = 3e4, Bt = /* @__PURE__ */ new Set([
999
+ "http",
1000
+ "network",
1001
+ "timeout",
1002
+ "unknown"
1003
+ ]);
1004
+ function K(e) {
1005
+ return typeof e == "object" && !!e && !Array.isArray(e);
1006
+ }
1007
+ function q(e) {
1008
+ return typeof e == "string" && e.length <= 64 && Number.isFinite(Date.parse(e));
1009
+ }
1010
+ function Vt(e) {
1011
+ return typeof e == "number" && Number.isSafeInteger(e) && e >= 0;
1012
+ }
1013
+ function Ht(e) {
1014
+ if (e !== void 0 && !(!K(e) || !q(e.utc) || typeof e.kind != "string") && Bt.has(e.kind) && !(e.httpStatus !== void 0 && (typeof e.httpStatus != "number" || !Number.isInteger(e.httpStatus) || e.httpStatus < 100 || e.httpStatus > 599))) return {
1015
+ utc: e.utc,
1016
+ kind: e.kind,
1017
+ httpStatus: e.httpStatus
1018
+ };
1019
+ }
1020
+ function Ut(e) {
1021
+ if (e !== void 0 && !(!K(e) || typeof e.ownerId != "string" || e.ownerId.length === 0 || e.ownerId.length > 128) && q(e.expiresUtc)) return {
1022
+ ownerId: e.ownerId,
1023
+ expiresUtc: e.expiresUtc
1024
+ };
1025
+ }
1026
+ function Wt(e) {
1027
+ if (!K(e) || e.queueVersion !== 1 || typeof e.reportId != "string" || !q(e.enqueuedUtc) || !q(e.expiresUtc) || !q(e.nextAttemptUtc) || !Vt(e.attemptCount)) return;
1028
+ let t = L(e.payload);
1029
+ if (!t || t.reportId !== e.reportId) return;
1030
+ let n = Ut(e.lease);
1031
+ if (e.lease !== void 0 && !n) return;
1032
+ let r = Ht(e.lastFailure);
1033
+ if (!(e.lastFailure !== void 0 && !r)) return {
1034
+ queueVersion: 1,
1035
+ reportId: e.reportId,
1036
+ enqueuedUtc: e.enqueuedUtc,
1037
+ expiresUtc: e.expiresUtc,
1038
+ nextAttemptUtc: e.nextAttemptUtc,
1039
+ attemptCount: e.attemptCount,
1040
+ payload: t,
1041
+ lease: n,
1042
+ lastFailure: r
1043
+ };
1044
+ }
1045
+ function J(e, t) {
1046
+ if (!Array.isArray(e)) return [];
1047
+ let n = /* @__PURE__ */ new Set(), r = [];
1048
+ for (let i of e) {
1049
+ let e = Wt(i);
1050
+ if (!(!e || Date.parse(e.expiresUtc) <= t || n.has(e.reportId)) && (n.add(e.reportId), r.push(e), r.length === 50)) break;
1051
+ }
1052
+ return r;
1053
+ }
1054
+ //#endregion
1055
+ //#region src/error-report/queue.ts
1056
+ var Y = "queue.v1", Gt = "records";
1057
+ function X(e) {
1058
+ return new Date(e).toISOString();
1059
+ }
1060
+ function Z(e) {
1061
+ let t = e.trim();
1062
+ if (t.length === 0 || t.length > 128) throw Error("Error report lease owner должен содержать от 1 до 128 символов");
1063
+ return t;
1064
+ }
1065
+ function Kt(e, t) {
1066
+ return Date.parse(e.nextAttemptUtc) - Date.parse(t.nextAttemptUtc) || Date.parse(e.enqueuedUtc) - Date.parse(t.enqueuedUtc);
1067
+ }
1068
+ function Q(e, t, n) {
1069
+ let r = e.findIndex((e) => e.reportId === t);
1070
+ return r < 0 ? {
1071
+ index: r,
1072
+ result: "missing"
1073
+ } : e[r]?.lease?.ownerId === n ? {
1074
+ index: r,
1075
+ result: "updated"
1076
+ } : {
1077
+ index: r,
1078
+ result: "lease-mismatch"
1079
+ };
1080
+ }
1081
+ function qt(e = {}) {
1082
+ let t = e.storage ?? o({
1083
+ dbName: e.dbName ?? `${__APP_ID__}.error-report.queue.v1`,
1084
+ storeName: Gt,
1085
+ indexedDB: e.indexedDB
1086
+ });
1087
+ if (!t) return;
1088
+ let n = t;
1089
+ function r(e, t) {
1090
+ return n.updateItem(Y, (n) => {
1091
+ let r = t(J(n, e));
1092
+ return {
1093
+ action: "set",
1094
+ value: r.records,
1095
+ result: r.result
1096
+ };
1097
+ });
1098
+ }
1099
+ return {
1100
+ enqueue: async (e, t = /* @__PURE__ */ new Date()) => {
1101
+ let n = L(e);
1102
+ if (!n) return { status: "invalid-payload" };
1103
+ let i = t.getTime();
1104
+ return Number.isFinite(i) ? r(i, (e) => {
1105
+ if (e.some((e) => e.reportId === n.reportId)) return {
1106
+ records: e,
1107
+ result: { status: "duplicate" }
1108
+ };
1109
+ let t;
1110
+ if (e.length >= 50) {
1111
+ let n = e.map((e, t) => ({
1112
+ record: e,
1113
+ index: t
1114
+ })).filter(({ record: e }) => e.lease === void 0).sort((e, t) => Date.parse(e.record.enqueuedUtc) - Date.parse(t.record.enqueuedUtc))[0]?.index;
1115
+ if (n === void 0) return {
1116
+ records: e,
1117
+ result: { status: "capacity-exceeded" }
1118
+ };
1119
+ t = e[n]?.reportId, e.splice(n, 1);
1120
+ }
1121
+ let r = X(i);
1122
+ return e.push({
1123
+ queueVersion: 1,
1124
+ reportId: n.reportId,
1125
+ enqueuedUtc: r,
1126
+ expiresUtc: X(i + Rt),
1127
+ nextAttemptUtc: r,
1128
+ attemptCount: 0,
1129
+ payload: n
1130
+ }), {
1131
+ records: e,
1132
+ result: t ? {
1133
+ status: "enqueued",
1134
+ evictedReportId: t
1135
+ } : { status: "enqueued" }
1136
+ };
1137
+ }) : { status: "invalid-payload" };
1138
+ },
1139
+ leaseNext: async ({ ownerId: e, now: t = /* @__PURE__ */ new Date(), leaseDurationMs: n = zt }) => {
1140
+ let i = Z(e), a = t.getTime();
1141
+ if (!Number.isFinite(a) || !Number.isFinite(n) || n <= 0) throw Error("Error report lease требует валидное время и положительную длительность");
1142
+ return r(a, (e) => {
1143
+ let t = e.filter((e) => Date.parse(e.nextAttemptUtc) <= a && (e.lease === void 0 || Date.parse(e.lease.expiresUtc) <= a)).sort(Kt)[0];
1144
+ if (!t) return {
1145
+ records: e,
1146
+ result: void 0
1147
+ };
1148
+ let r = {
1149
+ ...t,
1150
+ attemptCount: t.attemptCount + 1,
1151
+ lease: {
1152
+ ownerId: i,
1153
+ expiresUtc: X(a + n)
1154
+ }
1155
+ };
1156
+ return {
1157
+ records: e.map((e) => e.reportId === t.reportId ? r : e),
1158
+ result: r
1159
+ };
1160
+ });
1161
+ },
1162
+ acknowledge: async (e, t) => {
1163
+ let n = Z(t);
1164
+ return r(Date.now(), (t) => {
1165
+ let r = Q(t, e, n);
1166
+ return r.result === "updated" ? (t.splice(r.index, 1), {
1167
+ records: t,
1168
+ result: "updated"
1169
+ }) : {
1170
+ records: t,
1171
+ result: r.result
1172
+ };
1173
+ });
1174
+ },
1175
+ reschedule: async (e, t, n) => {
1176
+ let i = Z(t), a = Date.parse(n.nextAttemptUtc), o = Date.parse(n.failure.utc);
1177
+ if (!Number.isFinite(a) || !Number.isFinite(o)) throw Error("Error report retry требует валидные UTC timestamps");
1178
+ return r(o, (t) => {
1179
+ let r = Q(t, e, i);
1180
+ if (r.result !== "updated") return {
1181
+ records: t,
1182
+ result: r.result
1183
+ };
1184
+ let a = t[r.index];
1185
+ return a ? (t[r.index] = {
1186
+ ...a,
1187
+ nextAttemptUtc: n.nextAttemptUtc,
1188
+ lease: void 0,
1189
+ lastFailure: n.failure
1190
+ }, {
1191
+ records: t,
1192
+ result: "updated"
1193
+ }) : {
1194
+ records: t,
1195
+ result: "missing"
1196
+ };
1197
+ });
1198
+ },
1199
+ discard: async (e, t) => {
1200
+ let n = Z(t);
1201
+ return r(Date.now(), (t) => {
1202
+ let r = Q(t, e, n);
1203
+ return r.result === "updated" ? (t.splice(r.index, 1), {
1204
+ records: t,
1205
+ result: "updated"
1206
+ }) : {
1207
+ records: t,
1208
+ result: r.result
1209
+ };
1210
+ });
1211
+ },
1212
+ getRecords: async (e = /* @__PURE__ */ new Date()) => {
1213
+ let t = e.getTime();
1214
+ return Number.isFinite(t) ? J(await n.getItem(Y), t).sort(Kt) : [];
1215
+ },
1216
+ getNextWakeUtc: async (e = /* @__PURE__ */ new Date()) => {
1217
+ let t = e.getTime();
1218
+ if (!Number.isFinite(t)) return;
1219
+ let r = J(await n.getItem(Y), t).reduce((e, t) => {
1220
+ let n = Math.max(Date.parse(t.nextAttemptUtc), t.lease ? Date.parse(t.lease.expiresUtc) : 0);
1221
+ return e === void 0 || n < e ? n : e;
1222
+ }, void 0);
1223
+ return r === void 0 ? void 0 : X(r);
1224
+ }
1225
+ };
1226
+ }
1227
+ //#endregion
515
1228
  //#region src/error-report/runtime.ts
516
1229
  var $;
517
- function Pe(e) {
518
- $ = e, we();
1230
+ function Jt(e) {
1231
+ $ = e, St();
519
1232
  }
520
- async function Fe(e, t = {}) {
1233
+ async function Yt(e, t = {}) {
521
1234
  if ($) try {
522
1235
  await $(e, t);
523
1236
  } catch {}
524
1237
  }
525
1238
  //#endregion
526
- export { m as addErrorReportBreadcrumb, U as captureErrorReportDraft, Me as captureMutationErrorReport, je as captureQueryErrorReport, Ne as captureRuntimeErrorReport, g as clearErrorReportBreadcrumbs, j as collectMutationDiagnostics, N as collectPersistedQueryDiagnostics, M as collectQueryClientDiagnostics, A as collectQueryDiagnostics, d as createDataShape, u as createDiagnosticValue, O as createErrorInfo, h as getErrorReportBreadcrumbs, I as getErrorReportClientEnvironment, H as getErrorReportDraft, ge as getErrorReportDrafts, F as getErrorReportEnvironment, w as installErrorReportBrowserBreadcrumbs, P as isErrorReportingEnabled, ke as isTransportErrorReportScheduled, Fe as reportRuntimeError, Ae as reportTransportError, f as sanitizeDetail, Pe as setErrorReportRuntimeErrorReporter, Oe as setErrorReportTransportErrorReporter, Q as suppressTransportErrorReport, he as updateErrorReportDraft };
1239
+ export { C as ERROR_REPORT_PAYLOAD_MAX_BYTES, Ae as ERROR_REPORT_PAYLOAD_VERSION, zt as ERROR_REPORT_QUEUE_LEASE_MS, Lt as ERROR_REPORT_QUEUE_MAX_ITEMS, Rt as ERROR_REPORT_QUEUE_TTL_MS, It as ERROR_REPORT_QUEUE_VERSION, w as ERROR_REPORT_STACK_TRACE_MAX_BYTES, y as addErrorReportBreadcrumb, B as captureErrorReportDraft, Pt as captureMutationErrorReport, Nt as captureQueryErrorReport, Ft as captureRuntimeErrorReport, ye as clearErrorReportBreadcrumbs, j as collectMutationDiagnostics, N as collectPersistedQueryDiagnostics, M as collectQueryClientDiagnostics, A as collectQueryDiagnostics, h as createDataShape, de as createDiagnosticValue, k as createErrorInfo, qt as createErrorReportQueue, ve as getErrorReportBreadcrumbs, Ye as getErrorReportClientEnvironment, ft as getErrorReportDraft, mt as getErrorReportDrafts, Je as getErrorReportEnvironment, D as getErrorReportPayloadSize, f as getUtf8TextSize, ke as installErrorReportBrowserBreadcrumbs, qe as isErrorReportingEnabled, jt as isTransportErrorReportScheduled, Ve as limitErrorReportPayload, J as normalizeErrorReportQueueRecords, R as parseErrorReportDraft, rt as parseErrorReportDrafts, L as parseErrorReportPayload, Wt as parseErrorReportQueueRecord, Yt as reportRuntimeError, Mt as reportTransportError, _ as sanitizeDetail, d as sanitizeDiagnosticText, p as sanitizeDiagnosticTextBytes, g as sanitizeErrorReportValue, Jt as setErrorReportRuntimeErrorReporter, fe as setErrorReportSanitizer, At as setErrorReportTransportErrorReporter, G as suppressTransportErrorReport, pt as updateErrorReportDraft };
527
1240
 
528
1241
  //# sourceMappingURL=index.js.map