@nivaro/react 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/full.css +1 -1
- package/dist/hooks/useSessionRecorder.js +1 -1
- package/dist/index.d.ts +341 -0
- package/dist/index.js +764 -723
- package/dist/shared/components/ClientChaosToolbar.js +410 -0
- package/dist/shared/components/LoadErrorNote.js +49 -0
- package/dist/shared/components/PretendDown.js +258 -0
- package/dist/shared/components/ProfileView.js +54 -49
- package/dist/shared/components/QueryErrorState.js +16 -0
- package/dist/shared/components/ReportView.js +1351 -1338
- package/dist/shared/components/WidgetSlot.js +438 -418
- package/dist/shared/components/chaos/DeclareIncidentButton.js +72 -0
- package/dist/shared/components/chaos/DrillBanner.js +119 -0
- package/dist/shared/components/chaos/DrillTag.js +62 -0
- package/dist/shared/components/chaos/GameDayStrip.js +61 -0
- package/dist/shared/components/chat/huddle/HuddleAudioUi.js +95 -92
- package/dist/shared/components/chat/huddle/HuddleCallBar.js +69 -64
- package/dist/shared/components/chat/huddle/HuddlePeoplePicker.js +40 -39
- package/dist/shared/components/chat/huddle/HuddleStageTools.js +30 -27
- package/dist/shared/components/chat/huddle/huddle-dismiss.js +12 -0
- package/dist/shared/components/chat/huddle/huddle-store.js +25 -20
- package/dist/shared/components/client-chaos-gate.js +51 -0
- package/dist/shared/components/integrations/console/SignalCard.js +172 -167
- package/dist/shared/components/layout-editor/EditorTopBar.js +108 -105
- package/dist/shared/components/layout-editor/LayoutEditor.js +514 -508
- package/dist/shared/components/notifications/NotificationAnalyticsView.js +18 -10
- package/dist/shared/components/pipeline/PipelineEditorView.js +495 -479
- package/dist/shared/components/pipeline/TeamsView.js +184 -169
- package/dist/shared/lib/client-chaos.js +359 -0
- package/dist/shared/lib/load-error.js +26 -0
- package/dist/shared/lib/socket-realtime.js +31 -30
- package/dist/shared/lib/worker-socket.js +108 -89
- package/package.json +1 -1
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
const h = "x-nivaro-client-chaos", y = "nvr-client-chaos", K = 1e4, Y = 18e5, z = 50, D = {
|
|
2
|
+
flaky: { min: 5, max: 90, step: 5, initial: 30 },
|
|
3
|
+
slow: { min: 250, max: 1e4, step: 250, initial: 2e3 }
|
|
4
|
+
};
|
|
5
|
+
function Q(e) {
|
|
6
|
+
return !!(e != null && e.is_admin) && !e.masquerade;
|
|
7
|
+
}
|
|
8
|
+
let o = null, A = !1, u = null;
|
|
9
|
+
const C = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Map();
|
|
10
|
+
let k = 0;
|
|
11
|
+
function R() {
|
|
12
|
+
try {
|
|
13
|
+
return typeof sessionStorage > "u" ? null : sessionStorage;
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function M() {
|
|
19
|
+
const e = R();
|
|
20
|
+
if (e)
|
|
21
|
+
try {
|
|
22
|
+
o ? e.setItem(y, JSON.stringify(o)) : e.removeItem(y);
|
|
23
|
+
} catch {
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function P(e) {
|
|
27
|
+
const t = e;
|
|
28
|
+
return !!t && t.v === 1 && typeof t.endsAt == "number" && typeof t.startedAt == "number" && typeof t.strength == "number" && typeof t.failWrites == "number" && (t.preset === null || t.preset === "flaky" || t.preset === "api-down" || t.preset === "slow" || t.preset === "offline" || t.preset === "socket-gone");
|
|
29
|
+
}
|
|
30
|
+
function v(e) {
|
|
31
|
+
if (A) return;
|
|
32
|
+
A = !0;
|
|
33
|
+
const t = R();
|
|
34
|
+
if (t)
|
|
35
|
+
try {
|
|
36
|
+
const n = t.getItem(y);
|
|
37
|
+
if (!n) return;
|
|
38
|
+
const r = JSON.parse(n);
|
|
39
|
+
P(r) && r.endsAt > e && r.endsAt - r.startedAt <= 18e5 ? (o = r, O(e)) : t.removeItem(y);
|
|
40
|
+
} catch {
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function p() {
|
|
44
|
+
for (const e of [...C])
|
|
45
|
+
try {
|
|
46
|
+
e();
|
|
47
|
+
} catch {
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function O(e) {
|
|
51
|
+
u && clearTimeout(u), u = null, o && (u = setTimeout(
|
|
52
|
+
() => {
|
|
53
|
+
u = null, m();
|
|
54
|
+
},
|
|
55
|
+
Math.max(0, o.endsAt - e) + 5
|
|
56
|
+
));
|
|
57
|
+
}
|
|
58
|
+
function _(e = !0) {
|
|
59
|
+
u && clearTimeout(u), u = null;
|
|
60
|
+
const t = o !== null;
|
|
61
|
+
o = null, M(), t && (e ? p() : Promise.resolve().then(p));
|
|
62
|
+
}
|
|
63
|
+
function m(e = Date.now()) {
|
|
64
|
+
return v(e), o && e >= o.endsAt && _(!1), o && o.preset === null && o.failWrites <= 0 && _(!1), o;
|
|
65
|
+
}
|
|
66
|
+
function Z(e, t = Date.now()) {
|
|
67
|
+
v(t);
|
|
68
|
+
const n = Math.min(
|
|
69
|
+
18e5,
|
|
70
|
+
Math.max(1e4, Math.round(e.durationMs) || 0)
|
|
71
|
+
), r = e.preset === "flaky" || e.preset === "slow" ? D[e.preset] : null, a = r ? Math.min(r.max, Math.max(r.min, Math.round(e.strength ?? r.initial))) : 0, s = Math.min(
|
|
72
|
+
50,
|
|
73
|
+
Math.max(0, Math.floor(e.failWrites ?? 0))
|
|
74
|
+
);
|
|
75
|
+
return o = {
|
|
76
|
+
v: 1,
|
|
77
|
+
preset: e.preset,
|
|
78
|
+
strength: a,
|
|
79
|
+
failWrites: s,
|
|
80
|
+
startedAt: t,
|
|
81
|
+
endsAt: t + n
|
|
82
|
+
}, M(), O(t), p(), o;
|
|
83
|
+
}
|
|
84
|
+
function ee() {
|
|
85
|
+
v(Date.now()), _();
|
|
86
|
+
}
|
|
87
|
+
function N(e) {
|
|
88
|
+
return C.add(e), () => C.delete(e);
|
|
89
|
+
}
|
|
90
|
+
function U(e, t) {
|
|
91
|
+
const n = l.get(e);
|
|
92
|
+
!t.length && !n || (t.length ? l.set(e, t) : l.delete(e), k += 1, p());
|
|
93
|
+
}
|
|
94
|
+
const te = "nvr:pretend-down";
|
|
95
|
+
function ne(e) {
|
|
96
|
+
return l.get(e) ?? [];
|
|
97
|
+
}
|
|
98
|
+
function re(e) {
|
|
99
|
+
U(e, []);
|
|
100
|
+
}
|
|
101
|
+
function se() {
|
|
102
|
+
return k;
|
|
103
|
+
}
|
|
104
|
+
function W(e = Date.now()) {
|
|
105
|
+
var t;
|
|
106
|
+
if (((t = m(e)) == null ? void 0 : t.preset) === "socket-gone") return !0;
|
|
107
|
+
for (const n of l.values()) if (n.some((r) => r.socket)) return !0;
|
|
108
|
+
return !1;
|
|
109
|
+
}
|
|
110
|
+
function I(e = Date.now()) {
|
|
111
|
+
return m(e) !== null || l.size > 0;
|
|
112
|
+
}
|
|
113
|
+
function H(e) {
|
|
114
|
+
let t = e;
|
|
115
|
+
try {
|
|
116
|
+
t = new URL(
|
|
117
|
+
e,
|
|
118
|
+
typeof window < "u" && window.location ? window.location.href : "http://local/"
|
|
119
|
+
).pathname;
|
|
120
|
+
} catch {
|
|
121
|
+
t = e.split(/[?#]/)[0];
|
|
122
|
+
}
|
|
123
|
+
return t === "/api" ? "/" : t.startsWith("/api/") ? t.slice(4) : null;
|
|
124
|
+
}
|
|
125
|
+
const q = /^\/(chaos(\/|$)|auth\/(login|logout|callback|me)(\/|$)|issues\/client$|rum$|connection-reports$)/, $ = /^\/(issues\/client|rum|connection-reports)$/, g = /^\/(items\/batch-read|items\/[^/]+\/aggregate|users\/cards|graphql(\/|$)|widgets-internal\/[^/]+\/render|record-views\/|presence\/|page-at|field-rules\/(evaluate|explain)|custom-queries\/[^/]+\/(run|execute)|search(\/|$)|realtime\/)/;
|
|
126
|
+
function G(e, t) {
|
|
127
|
+
const n = e.toUpperCase();
|
|
128
|
+
return n === "PATCH" || n === "PUT" || n === "DELETE" ? !0 : n === "POST" && !g.test(t);
|
|
129
|
+
}
|
|
130
|
+
const X = { status: 503, statusText: "Service Unavailable" }, j = {
|
|
131
|
+
500: "Internal Server Error",
|
|
132
|
+
502: "Bad Gateway",
|
|
133
|
+
503: "Service Unavailable",
|
|
134
|
+
504: "Gateway Timeout"
|
|
135
|
+
};
|
|
136
|
+
function f(e, t, n) {
|
|
137
|
+
return Math.round(t + e() * (n - t));
|
|
138
|
+
}
|
|
139
|
+
function x(e, t = Math.random, n = Date.now()) {
|
|
140
|
+
const r = m(n);
|
|
141
|
+
if (!r && l.size === 0) return { kind: "pass", mark: null };
|
|
142
|
+
const a = H(e.url);
|
|
143
|
+
if (a === null) return { kind: "pass", mark: null };
|
|
144
|
+
const s = (r == null ? void 0 : r.preset) ?? (r ? "fail-saves" : "pretend-down");
|
|
145
|
+
if (q.test(a))
|
|
146
|
+
return { kind: "pass", mark: $.test(a) ? s : null };
|
|
147
|
+
const i = (e.method ?? "GET").toUpperCase();
|
|
148
|
+
for (const d of l.values()) {
|
|
149
|
+
const E = d.find((w) => w.patterns.some((L) => L.test(a)));
|
|
150
|
+
if (E) {
|
|
151
|
+
const w = E.status ?? 503;
|
|
152
|
+
return {
|
|
153
|
+
kind: "status",
|
|
154
|
+
delayMs: f(t, 150, 600),
|
|
155
|
+
status: w,
|
|
156
|
+
statusText: j[w] ?? "Service Unavailable",
|
|
157
|
+
body: JSON.stringify({ error: `${E.label} is unavailable` }),
|
|
158
|
+
contentType: "application/json; charset=utf-8",
|
|
159
|
+
mark: "pretend-down"
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (!r) return { kind: "pass", mark: null };
|
|
164
|
+
if (r.failWrites > 0 && G(i, a))
|
|
165
|
+
return o = { ...r, failWrites: r.failWrites - 1 }, M(), p(), {
|
|
166
|
+
kind: "status",
|
|
167
|
+
delayMs: f(t, 100, 400),
|
|
168
|
+
status: 500,
|
|
169
|
+
statusText: "Internal Server Error",
|
|
170
|
+
body: JSON.stringify({
|
|
171
|
+
statusCode: 500,
|
|
172
|
+
error: "Internal Server Error",
|
|
173
|
+
message: "Internal Server Error"
|
|
174
|
+
}),
|
|
175
|
+
contentType: "application/json; charset=utf-8",
|
|
176
|
+
mark: "fail-saves"
|
|
177
|
+
};
|
|
178
|
+
switch (r.preset) {
|
|
179
|
+
case "offline":
|
|
180
|
+
return { kind: "network", delayMs: 0, mark: s };
|
|
181
|
+
case "api-down":
|
|
182
|
+
return {
|
|
183
|
+
kind: "status",
|
|
184
|
+
delayMs: f(t, 20, 120),
|
|
185
|
+
...X,
|
|
186
|
+
body: "Service Unavailable",
|
|
187
|
+
contentType: "text/plain; charset=utf-8",
|
|
188
|
+
mark: s
|
|
189
|
+
};
|
|
190
|
+
case "slow":
|
|
191
|
+
return { kind: "delay", ms: Math.max(0, Math.round(r.strength * (0.8 + t() * 0.4))) };
|
|
192
|
+
case "flaky":
|
|
193
|
+
return t() * 100 < r.strength ? { kind: "network", delayMs: f(t, 100, 1500), mark: s } : { kind: "delay", ms: f(t, 50, 800) };
|
|
194
|
+
default:
|
|
195
|
+
return { kind: "pass", mark: null };
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function T() {
|
|
199
|
+
try {
|
|
200
|
+
return new DOMException("The user aborted a request.", "AbortError");
|
|
201
|
+
} catch {
|
|
202
|
+
const e = new Error("The user aborted a request.");
|
|
203
|
+
return e.name = "AbortError", e;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function c(e, t) {
|
|
207
|
+
return e <= 0 ? t != null && t.aborted ? Promise.reject(T()) : Promise.resolve() : new Promise((n, r) => {
|
|
208
|
+
if (t != null && t.aborted) return r(T());
|
|
209
|
+
const a = setTimeout(() => {
|
|
210
|
+
t == null || t.removeEventListener("abort", s), n();
|
|
211
|
+
}, e), s = () => {
|
|
212
|
+
clearTimeout(a), r(T());
|
|
213
|
+
};
|
|
214
|
+
t == null || t.addEventListener("abort", s, { once: !0 });
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
function F(e) {
|
|
218
|
+
return typeof e == "string" ? e : e instanceof URL ? e.href : e.url;
|
|
219
|
+
}
|
|
220
|
+
function J(e) {
|
|
221
|
+
return async (n, r) => {
|
|
222
|
+
if (!I()) return e(n, r);
|
|
223
|
+
const a = (r == null ? void 0 : r.method) ?? (typeof Request < "u" && n instanceof Request ? n.method : "GET"), s = x({ method: a, url: F(n) }), i = (r == null ? void 0 : r.signal) ?? (typeof Request < "u" && n instanceof Request ? n.signal : null);
|
|
224
|
+
switch (s.kind) {
|
|
225
|
+
case "pass": {
|
|
226
|
+
if (!s.mark) return e(n, r);
|
|
227
|
+
const d = new Headers(
|
|
228
|
+
(r == null ? void 0 : r.headers) ?? (typeof Request < "u" && n instanceof Request ? n.headers : void 0)
|
|
229
|
+
);
|
|
230
|
+
return d.set(h, s.mark), e(n, { ...r, headers: d });
|
|
231
|
+
}
|
|
232
|
+
case "delay":
|
|
233
|
+
return await c(s.ms, i), e(n, r);
|
|
234
|
+
case "network":
|
|
235
|
+
throw await c(s.delayMs, i), new TypeError("Failed to fetch");
|
|
236
|
+
case "status":
|
|
237
|
+
return await c(s.delayMs, i), new Response(s.body, {
|
|
238
|
+
status: s.status,
|
|
239
|
+
statusText: s.statusText,
|
|
240
|
+
headers: { "content-type": s.contentType, [h]: s.mark }
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
let b = !1;
|
|
246
|
+
function ae() {
|
|
247
|
+
if (b || typeof window > "u" || typeof window.fetch != "function") return;
|
|
248
|
+
b = !0, window.fetch = J(window.fetch.bind(window));
|
|
249
|
+
let e = !1;
|
|
250
|
+
const t = () => {
|
|
251
|
+
var r;
|
|
252
|
+
const n = ((r = m()) == null ? void 0 : r.preset) === "offline";
|
|
253
|
+
n !== e && (e = n, V(n));
|
|
254
|
+
};
|
|
255
|
+
N(t), t();
|
|
256
|
+
}
|
|
257
|
+
function V(e) {
|
|
258
|
+
try {
|
|
259
|
+
e ? Object.defineProperty(navigator, "onLine", { configurable: !0, get: () => !1 }) : delete navigator.onLine;
|
|
260
|
+
} catch {
|
|
261
|
+
}
|
|
262
|
+
try {
|
|
263
|
+
window.dispatchEvent(new Event(e ? "offline" : "online"));
|
|
264
|
+
} catch {
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
function B(e) {
|
|
268
|
+
const t = e.url ?? "";
|
|
269
|
+
return /^https?:\/\//i.test(t) || !e.baseURL ? t : `${e.baseURL.replace(/\/$/, "")}/${t.replace(/^\//, "")}`;
|
|
270
|
+
}
|
|
271
|
+
function oe(e) {
|
|
272
|
+
return async (t) => {
|
|
273
|
+
if (!I()) return t;
|
|
274
|
+
const n = x({ method: t.method ?? "get", url: B(t) }), r = t.signal ?? null;
|
|
275
|
+
switch (n.kind) {
|
|
276
|
+
case "pass":
|
|
277
|
+
return n.mark && t.headers && (typeof t.headers.set == "function" ? t.headers.set(h, n.mark) : t.headers[h] = n.mark), t;
|
|
278
|
+
case "delay":
|
|
279
|
+
return await c(n.ms, r), t;
|
|
280
|
+
case "network":
|
|
281
|
+
return t.adapter = async () => {
|
|
282
|
+
throw await c(n.delayMs, r), new e("Network Error", "ERR_NETWORK", t, {});
|
|
283
|
+
}, t;
|
|
284
|
+
case "status":
|
|
285
|
+
return t.adapter = async () => {
|
|
286
|
+
await c(n.delayMs, r);
|
|
287
|
+
let a = n.body;
|
|
288
|
+
if (n.contentType.startsWith("application/json"))
|
|
289
|
+
try {
|
|
290
|
+
a = JSON.parse(n.body);
|
|
291
|
+
} catch {
|
|
292
|
+
}
|
|
293
|
+
const s = {
|
|
294
|
+
data: a,
|
|
295
|
+
status: n.status,
|
|
296
|
+
statusText: n.statusText,
|
|
297
|
+
headers: { "content-type": n.contentType, [h]: n.mark },
|
|
298
|
+
config: t,
|
|
299
|
+
request: {}
|
|
300
|
+
};
|
|
301
|
+
throw new e(
|
|
302
|
+
`Request failed with status code ${n.status}`,
|
|
303
|
+
n.status >= 500 ? "ERR_BAD_RESPONSE" : "ERR_BAD_REQUEST",
|
|
304
|
+
t,
|
|
305
|
+
{},
|
|
306
|
+
s
|
|
307
|
+
);
|
|
308
|
+
}, t;
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
const S = /* @__PURE__ */ new WeakSet();
|
|
313
|
+
function ie(e) {
|
|
314
|
+
if (!e || S.has(e)) return () => {
|
|
315
|
+
};
|
|
316
|
+
S.add(e);
|
|
317
|
+
let t = !1;
|
|
318
|
+
const n = () => {
|
|
319
|
+
var s, i;
|
|
320
|
+
const a = W();
|
|
321
|
+
if (a !== t) {
|
|
322
|
+
t = a;
|
|
323
|
+
try {
|
|
324
|
+
typeof e.chaosPause == "function" ? e.chaosPause(a) : a ? (s = e.disconnect) == null || s.call(e) : (i = e.connect) == null || i.call(e);
|
|
325
|
+
} catch {
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}, r = N(n);
|
|
329
|
+
return n(), () => {
|
|
330
|
+
r(), S.delete(e);
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
export {
|
|
334
|
+
h as CLIENT_CHAOS_HEADER,
|
|
335
|
+
z as CLIENT_CHAOS_MAX_FAIL_WRITES,
|
|
336
|
+
Y as CLIENT_CHAOS_MAX_MS,
|
|
337
|
+
K as CLIENT_CHAOS_MIN_MS,
|
|
338
|
+
y as CLIENT_CHAOS_STORAGE_KEY,
|
|
339
|
+
D as CLIENT_CHAOS_STRENGTH,
|
|
340
|
+
te as PRETEND_DOWN_EVENT,
|
|
341
|
+
ie as bindClientChaosSocket,
|
|
342
|
+
Q as canUseClientChaos,
|
|
343
|
+
re as clearPretendDown,
|
|
344
|
+
I as clientChaosActive,
|
|
345
|
+
H as clientChaosApiPath,
|
|
346
|
+
oe as clientChaosAxiosInterceptor,
|
|
347
|
+
W as clientSocketGone,
|
|
348
|
+
x as decideClientChaos,
|
|
349
|
+
m as getClientChaos,
|
|
350
|
+
ne as getPretendDown,
|
|
351
|
+
ae as installClientChaosFetch,
|
|
352
|
+
G as isClientChaosWrite,
|
|
353
|
+
se as pretendDownVersion,
|
|
354
|
+
U as setPretendDown,
|
|
355
|
+
Z as startClientChaos,
|
|
356
|
+
ee as stopClientChaos,
|
|
357
|
+
N as subscribeClientChaos,
|
|
358
|
+
J as withClientChaos
|
|
359
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
function a(e) {
|
|
2
|
+
var r;
|
|
3
|
+
const t = e, n = (t == null ? void 0 : t.status) ?? ((r = t == null ? void 0 : t.response) == null ? void 0 : r.status);
|
|
4
|
+
return typeof n == "number" ? n : null;
|
|
5
|
+
}
|
|
6
|
+
function l(e, t = "this") {
|
|
7
|
+
const n = a(e);
|
|
8
|
+
if (n == null) {
|
|
9
|
+
const r = e instanceof Error ? e.message : String(e ?? "");
|
|
10
|
+
return /timed? ?out|timeout/i.test(r) || (e == null ? void 0 : e.name) === "TimeoutError" ? `Couldn’t load ${t}: it is taking too long to answer.` : e instanceof TypeError || /network|failed to fetch|load failed/i.test(r) ? "Can’t reach the server. Check the connection." : `Couldn’t load ${t}.`;
|
|
11
|
+
}
|
|
12
|
+
return n === 502 || n === 503 || n === 504 ? "The service behind this is unavailable right now." : n === 401 ? "Your sign-in has ended. Sign in again to see it." : n === 403 ? "You don’t have access to this." : n === 404 ? `${t === "this" ? "This" : t[0].toUpperCase() + t.slice(1)} no longer exists.` : n === 429 ? "Too many requests just now. Try again in a moment." : n >= 500 ? `The server hit an error loading ${t}.` : `Couldn’t load ${t}.`;
|
|
13
|
+
}
|
|
14
|
+
const u = /^(service unavailable|internal server error|bad gateway|gateway timeout|not found|forbidden|unauthorized)$/i;
|
|
15
|
+
function c(e) {
|
|
16
|
+
var o, i, s;
|
|
17
|
+
const t = e, n = ((i = (o = t == null ? void 0 : t.response) == null ? void 0 : o.data) == null ? void 0 : i.error) ?? ((s = t == null ? void 0 : t.response) == null ? void 0 : s.error);
|
|
18
|
+
if (typeof n != "string") return null;
|
|
19
|
+
const r = n.trim();
|
|
20
|
+
return !r || u.test(r) ? null : r.length > 200 ? `${r.slice(0, 197)}…` : r;
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
a as loadErrorStatus,
|
|
24
|
+
l as loadErrorText,
|
|
25
|
+
c as serverErrorText
|
|
26
|
+
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
var N = Object.defineProperty;
|
|
2
2
|
var U = (i, n, r) => n in i ? N(i, n, { enumerable: !0, configurable: !0, writable: !0, value: r }) : i[n] = r;
|
|
3
3
|
var b = (i, n, r) => U(i, typeof n != "symbol" ? n + "" : n, r);
|
|
4
|
+
import { bindClientChaosSocket as k } from "./client-chaos.js";
|
|
4
5
|
import { deliveryAckFor as L } from "./delivery-ack.js";
|
|
5
|
-
import { forgetSettledReads as
|
|
6
|
+
import { forgetSettledReads as y } from "./request-gate.js";
|
|
6
7
|
import { createRoomGapTracker as M, refetchEventsFor as W } from "./room-gaps.js";
|
|
7
8
|
const p = {
|
|
8
9
|
catchupFull: "nvr:catchup-full",
|
|
@@ -10,7 +11,7 @@ const p = {
|
|
|
10
11
|
configUpdate: "nvr:config-update",
|
|
11
12
|
forceRefresh: "nvr:force-refresh"
|
|
12
13
|
};
|
|
13
|
-
class
|
|
14
|
+
class E {
|
|
14
15
|
constructor(n, r) {
|
|
15
16
|
b(this, "refs", /* @__PURE__ */ new Map());
|
|
16
17
|
this.join = n, this.leave = r;
|
|
@@ -30,61 +31,61 @@ class F {
|
|
|
30
31
|
return [...this.refs.keys()];
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
|
-
function
|
|
34
|
+
function G(i) {
|
|
34
35
|
let n = null, r = 0, j = !1, l = null, a = { state: "live", transport: null, refreshed: null, resumed: null };
|
|
35
|
-
const
|
|
36
|
+
const T = /* @__PURE__ */ new Set(), v = (e) => {
|
|
36
37
|
var o;
|
|
37
38
|
return ((o = i.windowEvents) == null ? void 0 : o[e]) !== !1;
|
|
38
39
|
}, g = (e) => {
|
|
39
40
|
const o = { ...a, ...e };
|
|
40
41
|
if (!(o.state === a.state && o.transport === a.transport && o.refreshed === a.refreshed && o.resumed === a.resumed)) {
|
|
41
42
|
a = o;
|
|
42
|
-
for (const t of
|
|
43
|
+
for (const t of T) t(a);
|
|
43
44
|
}
|
|
44
|
-
},
|
|
45
|
+
}, R = () => {
|
|
45
46
|
var e, o, t;
|
|
46
47
|
return ((t = (o = (e = n == null ? void 0 : n.io) == null ? void 0 : e.engine) == null ? void 0 : o.transport) == null ? void 0 : t.name) ?? null;
|
|
47
|
-
},
|
|
48
|
-
l && clearTimeout(l), l = null, g({ state: "live", transport:
|
|
48
|
+
}, C = (e, o) => {
|
|
49
|
+
l && clearTimeout(l), l = null, g({ state: "live", transport: R(), refreshed: e, resumed: o });
|
|
49
50
|
}, u = (e, o) => {
|
|
50
51
|
typeof window > "u" || window.dispatchEvent(new CustomEvent(e, { detail: o }));
|
|
51
52
|
}, h = (e, o) => {
|
|
52
53
|
n != null && n.connected && n.emit(e, o);
|
|
53
|
-
},
|
|
54
|
+
}, F = (e, o) => {
|
|
54
55
|
var t;
|
|
55
56
|
for (const s of ((t = n == null ? void 0 : n.listeners) == null ? void 0 : t.call(n, e)) ?? []) s(o);
|
|
56
|
-
},
|
|
57
|
-
for (const o of W(e))
|
|
57
|
+
}, _ = (e) => {
|
|
58
|
+
for (const o of W(e)) F(o.event, o.payload);
|
|
58
59
|
u("nvr:realtime-stale", { rooms: e });
|
|
59
60
|
}, m = M({
|
|
60
61
|
request: (e) => h("catchup:room", e),
|
|
61
|
-
dispatch:
|
|
62
|
-
refetch:
|
|
63
|
-
}), q = new
|
|
62
|
+
dispatch: F,
|
|
63
|
+
refetch: _
|
|
64
|
+
}), q = new E(
|
|
64
65
|
(e) => {
|
|
65
66
|
m.reset([`collection:${e}`]), h("collection:join", { collection: e });
|
|
66
67
|
},
|
|
67
68
|
(e) => {
|
|
68
69
|
m.reset([`collection:${e}`]), h("collection:leave", { collection: e });
|
|
69
70
|
}
|
|
70
|
-
), A = new
|
|
71
|
+
), A = new E(
|
|
71
72
|
(e) => h("admin:join", { room: e }),
|
|
72
73
|
(e) => h("admin:leave", { room: e })
|
|
73
|
-
),
|
|
74
|
+
), S = new E(
|
|
74
75
|
(e) => h("ops:join", { topic: e }),
|
|
75
76
|
(e) => h("ops:leave", { topic: e })
|
|
76
77
|
), w = () => {
|
|
77
78
|
var o;
|
|
78
79
|
if (n) return n;
|
|
79
80
|
const e = typeof i.socket == "function" ? i.socket() : i.socket;
|
|
80
|
-
return n = e, j = e.connected, e.on("auth:ok", () => {
|
|
81
|
-
if (m.reset(), q.rejoinAll(), A.rejoinAll(),
|
|
81
|
+
return n = e, k(e), j = e.connected, e.on("auth:ok", () => {
|
|
82
|
+
if (m.reset(), q.rejoinAll(), A.rejoinAll(), S.rejoinAll(), j && r > 0) {
|
|
82
83
|
const t = r;
|
|
83
|
-
g({ transport:
|
|
84
|
+
g({ transport: R() }), l && clearTimeout(l), l = setTimeout(() => C(null, "unverified"), i.catchupTimeoutMs ?? 8e3), e.emit("catchup", { cursor: t });
|
|
84
85
|
} else
|
|
85
86
|
g({
|
|
86
87
|
state: "live",
|
|
87
|
-
transport:
|
|
88
|
+
transport: R(),
|
|
88
89
|
refreshed: null,
|
|
89
90
|
resumed: j && a.state === "reconnecting" ? "unverified" : null
|
|
90
91
|
});
|
|
@@ -100,7 +101,7 @@ function B(i) {
|
|
|
100
101
|
d && e.emit("rt:ack", d);
|
|
101
102
|
}), e.on("catchup:room:events", (t) => m.replayed(t)), e.on("realtime:stale", (t) => {
|
|
102
103
|
const s = Array.isArray(t == null ? void 0 : t.rooms) ? t.rooms.filter((c) => typeof c == "string") : [];
|
|
103
|
-
m.reset(s), t != null && t.all ? (v("catchupFull") && u(p.catchupFull, {}), u("nvr:realtime-stale", { rooms: s, all: !0 })) : s.length &&
|
|
104
|
+
m.reset(s), t != null && t.all ? (v("catchupFull") && u(p.catchupFull, {}), u("nvr:realtime-stale", { rooms: s, all: !0 })) : s.length && _(s);
|
|
104
105
|
}), e.on(
|
|
105
106
|
"catchup:events",
|
|
106
107
|
(t) => {
|
|
@@ -109,18 +110,18 @@ function B(i) {
|
|
|
109
110
|
c.seq > r && (r = c.seq);
|
|
110
111
|
for (const d of ((s = e.listeners) == null ? void 0 : s.call(e, c.event)) ?? []) d({ ...c.payload, _seq: c.seq });
|
|
111
112
|
}
|
|
112
|
-
|
|
113
|
+
C(null, "replayed");
|
|
113
114
|
}
|
|
114
115
|
), e.on("catchup:full", (t) => {
|
|
115
|
-
v("catchupFull") && u(p.catchupFull, {}),
|
|
116
|
+
v("catchupFull") && u(p.catchupFull, {}), C(
|
|
116
117
|
(t == null ? void 0 : t.reason) === "slow-consumer" ? "Live updates resumed. This tab fell too far behind to send each change, so the lists and records on this page were reloaded." : "Live updates resumed. The connection was gone too long to replay each change, so the lists and records on this page were reloaded.",
|
|
117
118
|
"reloaded"
|
|
118
119
|
);
|
|
119
120
|
}), e.on("access:changed", (t) => {
|
|
120
121
|
var s;
|
|
121
|
-
|
|
122
|
+
y(), (s = t == null ? void 0 : t.rooms_left) != null && s.length && v("accessChanged") && u(p.accessChanged, t);
|
|
122
123
|
}), e.on("config:update", (t) => {
|
|
123
|
-
|
|
124
|
+
y(), v("configUpdate") && u(p.configUpdate, t ?? {});
|
|
124
125
|
}), e.on("client:force-refresh", (t) => {
|
|
125
126
|
v("forceRefresh") && u(p.forceRefresh, t ?? {});
|
|
126
127
|
}), e;
|
|
@@ -151,7 +152,7 @@ function B(i) {
|
|
|
151
152
|
if (w(), e === "ops:join" || e === "ops:leave") {
|
|
152
153
|
const t = String((o == null ? void 0 : o.topic) ?? "");
|
|
153
154
|
if (!t) return;
|
|
154
|
-
e === "ops:join" ?
|
|
155
|
+
e === "ops:join" ? S.add(t) : S.remove(t);
|
|
155
156
|
return;
|
|
156
157
|
}
|
|
157
158
|
n == null || n.emit(e, o);
|
|
@@ -160,8 +161,8 @@ function B(i) {
|
|
|
160
161
|
return a;
|
|
161
162
|
},
|
|
162
163
|
onStatus(e) {
|
|
163
|
-
return w(),
|
|
164
|
-
|
|
164
|
+
return w(), T.add(e), () => {
|
|
165
|
+
T.delete(e);
|
|
165
166
|
};
|
|
166
167
|
},
|
|
167
168
|
joinWatch(e) {
|
|
@@ -172,10 +173,10 @@ function B(i) {
|
|
|
172
173
|
};
|
|
173
174
|
},
|
|
174
175
|
held() {
|
|
175
|
-
return { collections: q.keys(), watch: A.keys(), ops:
|
|
176
|
+
return { collections: q.keys(), watch: A.keys(), ops: S.keys() };
|
|
176
177
|
}
|
|
177
178
|
};
|
|
178
179
|
}
|
|
179
180
|
export {
|
|
180
|
-
|
|
181
|
+
G as createSocketRealtime
|
|
181
182
|
};
|