@nivaro/react 0.3.8 → 0.3.10
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/components/fields/FileField.js +20 -19
- package/dist/full.css +1 -1
- package/dist/hooks/replayUploadQueue.js +107 -93
- package/dist/hooks/useNivaroForm.js +129 -126
- package/dist/hooks/useSessionRecorder.js +103 -101
- package/dist/index.d.ts +115 -2
- package/dist/index.js +466 -447
- package/dist/shared/components/CollectionBrowserView.js +1058 -1059
- package/dist/shared/components/ConformanceView.js +36 -35
- package/dist/shared/components/DataTable.js +230 -223
- package/dist/shared/components/ForceReloadBanner.js +58 -34
- package/dist/shared/components/ItemEditForm.js +3687 -3580
- package/dist/shared/components/JsonMapEditor.js +18 -17
- package/dist/shared/components/MatrixEditor.js +8 -7
- package/dist/shared/components/MyWorkView.js +32 -31
- package/dist/shared/components/PageRenderer.js +146 -145
- package/dist/shared/components/QueryTable.js +49 -49
- package/dist/shared/components/RecordGridEditor.js +76 -75
- package/dist/shared/components/ai/AiMemorySuggestions.js +15 -14
- package/dist/shared/components/ai/AskPanel.js +55 -54
- package/dist/shared/components/bulk/BulkActionButtons.js +30 -29
- package/dist/shared/components/bulk/PushBulkButtons.js +57 -56
- package/dist/shared/components/chat/ChatPanel.js +288 -287
- package/dist/shared/components/chat/SlashCommands.js +30 -29
- package/dist/shared/components/chat/chat-outbox.js +76 -75
- package/dist/shared/components/help-videos/recorder/useLeaveWarning.js +6 -5
- package/dist/shared/components/integrations/console/SignalCard.js +124 -123
- package/dist/shared/components/integrations/console/SnoozeMenu.js +24 -23
- package/dist/shared/components/item-edit/CloneDialog.js +85 -78
- package/dist/shared/components/item-edit/InlineTableField.js +301 -300
- package/dist/shared/components/item-edit/MembershipSetField.js +24 -23
- package/dist/shared/components/item-edit/QuickCreateButton.js +8 -7
- package/dist/shared/components/item-edit/RecordLiveSync.js +101 -100
- package/dist/shared/components/item-edit/staged-links.js +86 -0
- package/dist/shared/components/layout-editor/LayoutEditor.js +275 -274
- package/dist/shared/components/layout-editor/editors/cascade-rule-row.js +18 -17
- package/dist/shared/components/layout-editor/inspector/HelpTab.js +37 -36
- package/dist/shared/components/layout-editor/matrix/FieldStateMatrix.js +50 -49
- package/dist/shared/components/panels/CommentPanel.js +237 -236
- package/dist/shared/components/profile/AiMemoryCard.js +15 -14
- package/dist/shared/components/profile/PersonAdminTools.js +70 -67
- package/dist/shared/components/profile/usePersonPresence.js +42 -37
- package/dist/shared/components/queue/QueueItemSheet.js +36 -35
- package/dist/shared/components/queue/QueueWorklist.js +597 -598
- package/dist/shared/lib/client-version.js +63 -0
- package/dist/shared/lib/force-reload.js +36 -0
- package/dist/shared/lib/load-error.js +11 -10
- package/dist/shared/lib/presence-live.js +73 -0
- package/dist/shared/lib/presence-state.js +39 -31
- package/dist/shared/lib/record-outbox.js +76 -75
- package/dist/shared/lib/request-gate.js +120 -102
- package/dist/shared/lib/rum.js +45 -36
- package/dist/shared/lib/safe-error.js +39 -0
- package/dist/shared/lib/server-clock.js +11 -7
- package/dist/shared/lib/signed-out.js +114 -0
- package/dist/shared/lib/socket-realtime.js +19 -17
- package/dist/shared/lib/unsaved-work.js +62 -0
- package/dist/shared/lib/use-online-users.js +11 -10
- package/dist/shared/lib/worker-socket.js +89 -79
- package/package.json +1 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const c = "nvr-tab-id", f = Date.now();
|
|
2
|
+
let y = null, g = null, n = null;
|
|
3
|
+
function i() {
|
|
4
|
+
try {
|
|
5
|
+
const t = new Uint8Array(8);
|
|
6
|
+
return crypto.getRandomValues(t), Array.from(t, (e) => e.toString(36).padStart(2, "0")).join("").slice(0, 12);
|
|
7
|
+
} catch {
|
|
8
|
+
return `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 8)}`;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function S(t, e = 60) {
|
|
12
|
+
if (typeof t != "string") return null;
|
|
13
|
+
const r = t.trim().replace(/[^\w.+@-]/g, "");
|
|
14
|
+
return r ? r.slice(0, e) : null;
|
|
15
|
+
}
|
|
16
|
+
function b() {
|
|
17
|
+
if (n) return n;
|
|
18
|
+
try {
|
|
19
|
+
const t = typeof sessionStorage < "u" ? sessionStorage.getItem(c) : null;
|
|
20
|
+
n = S(t, 24) ?? i(), t !== n && typeof sessionStorage < "u" && sessionStorage.setItem(c, n);
|
|
21
|
+
} catch {
|
|
22
|
+
n = i();
|
|
23
|
+
}
|
|
24
|
+
return n;
|
|
25
|
+
}
|
|
26
|
+
function h() {
|
|
27
|
+
const t = p();
|
|
28
|
+
return t.length ? { ...l(), obeyed: t } : l();
|
|
29
|
+
}
|
|
30
|
+
function l() {
|
|
31
|
+
return { build: y, api: g, tab: b(), loaded: f };
|
|
32
|
+
}
|
|
33
|
+
const u = "nvr-fr-obeyed", m = 30;
|
|
34
|
+
function s() {
|
|
35
|
+
try {
|
|
36
|
+
const t = typeof sessionStorage < "u" ? sessionStorage.getItem(u) : null, e = t ? JSON.parse(t) : null;
|
|
37
|
+
return e && typeof e == "object" && !Array.isArray(e) ? e : {};
|
|
38
|
+
} catch {
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function p() {
|
|
43
|
+
return Object.keys(s());
|
|
44
|
+
}
|
|
45
|
+
function A(t) {
|
|
46
|
+
return Number(s()[t]) || 0;
|
|
47
|
+
}
|
|
48
|
+
function I(t) {
|
|
49
|
+
try {
|
|
50
|
+
const e = s(), r = Number(e[t]) || 0;
|
|
51
|
+
delete e[t];
|
|
52
|
+
const o = { ...e, [t]: r + 1 }, a = Object.keys(o);
|
|
53
|
+
for (const d of a.slice(0, Math.max(0, a.length - m))) delete o[d];
|
|
54
|
+
sessionStorage.setItem(u, JSON.stringify(o));
|
|
55
|
+
} catch {
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
h as clientVersion,
|
|
60
|
+
I as markReloadFor,
|
|
61
|
+
p as obeyedReloads,
|
|
62
|
+
A as reloadCountFor
|
|
63
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { reloadCountFor as c, clientVersion as d } from "./client-version.js";
|
|
2
|
+
import { serverClockOffset as m } from "./server-clock.js";
|
|
3
|
+
const a = 2, f = /^v?(\d+(?:\.\d+){0,3})(?:[-+][\w.+-]*)?$/i;
|
|
4
|
+
function l(r) {
|
|
5
|
+
return !!r && r !== "dev" && !r.startsWith("0.0.0");
|
|
6
|
+
}
|
|
7
|
+
function p(r, t) {
|
|
8
|
+
const n = f.exec(r.trim()), e = f.exec(t.trim());
|
|
9
|
+
if (!n || !e) return null;
|
|
10
|
+
const o = n[1].split(".").map(Number), s = e[1].split(".").map(Number);
|
|
11
|
+
for (let u = 0; u < Math.max(o.length, s.length); u++) {
|
|
12
|
+
const i = (o[u] ?? 0) - (s[u] ?? 0);
|
|
13
|
+
if (i !== 0) return i < 0 ? -1 : 1;
|
|
14
|
+
}
|
|
15
|
+
return 0;
|
|
16
|
+
}
|
|
17
|
+
function b(r, t, n, e) {
|
|
18
|
+
if (!l(r) || !l(t)) return !1;
|
|
19
|
+
const o = p(r, t);
|
|
20
|
+
return o != null ? o < 0 : r !== t && n != null && n < e;
|
|
21
|
+
}
|
|
22
|
+
function y(r, t, n = c) {
|
|
23
|
+
const e = typeof r.id == "string" && r.id ? r.id : null;
|
|
24
|
+
return e ? r.reason === "min-build" ? n(e) >= a ? !1 : typeof r.min_build == "string" && typeof r.set_at == "number" ? b(t.build, r.min_build, t.loaded, r.set_at) : !0 : n(e) >= 1 ? !1 : r.reason === "sticky" && typeof r.issued_at == "number" ? t.loaded < r.issued_at : !0 : !0;
|
|
25
|
+
}
|
|
26
|
+
function g() {
|
|
27
|
+
const r = d();
|
|
28
|
+
return { build: r.build, loaded: r.loaded + m() };
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
a as MIN_BUILD_RELOADS,
|
|
32
|
+
b as buildBelow,
|
|
33
|
+
p as compareBuilds,
|
|
34
|
+
y as shouldObeyForceReload,
|
|
35
|
+
g as thisTabForReload
|
|
36
|
+
};
|
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
import { isCodeError as u, SOMETHING_WENT_WRONG as a } from "./safe-error.js";
|
|
2
|
+
function l(e) {
|
|
2
3
|
var r;
|
|
3
4
|
const t = e, n = (t == null ? void 0 : t.status) ?? ((r = t == null ? void 0 : t.response) == null ? void 0 : r.status);
|
|
4
5
|
return typeof n == "number" ? n : null;
|
|
5
6
|
}
|
|
6
|
-
function
|
|
7
|
-
const n =
|
|
7
|
+
function c(e, t = "this") {
|
|
8
|
+
const n = l(e);
|
|
8
9
|
if (n == null) {
|
|
9
10
|
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.` :
|
|
11
|
+
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.` : /network|failed to fetch|load failed/i.test(r) ? "Can’t reach the server. Check the connection." : u(e) ? a : `Couldn’t load ${t}.`;
|
|
11
12
|
}
|
|
12
13
|
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
|
}
|
|
14
|
-
const
|
|
15
|
-
function
|
|
15
|
+
const d = /^(service unavailable|internal server error|bad gateway|gateway timeout|not found|forbidden|unauthorized)$/i;
|
|
16
|
+
function g(e) {
|
|
16
17
|
var o, i, s;
|
|
17
18
|
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
19
|
if (typeof n != "string") return null;
|
|
19
20
|
const r = n.trim();
|
|
20
|
-
return !r ||
|
|
21
|
+
return !r || d.test(r) ? null : r.length > 200 ? `${r.slice(0, 197)}…` : r;
|
|
21
22
|
}
|
|
22
23
|
export {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
l as loadErrorStatus,
|
|
25
|
+
c as loadErrorText,
|
|
26
|
+
g as serverErrorText
|
|
26
27
|
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { useQueryClient as _ } from "@tanstack/react-query";
|
|
2
|
+
import { useEffect as w } from "react";
|
|
3
|
+
import { useItemEditAuth as S } from "../context.js";
|
|
4
|
+
import { LIVE_WINDOW_EVENT as m } from "./live.js";
|
|
5
|
+
import { useLiveRefetchInterval as I } from "./live-queries.js";
|
|
6
|
+
import { presenceChangeTouches as P } from "./presence-state.js";
|
|
7
|
+
import { useOptionalRealtime as N } from "./realtime.js";
|
|
8
|
+
const v = ["presence-online"], A = 1e3, E = 1e4, C = 2e3, L = 6e4, s = /* @__PURE__ */ new WeakMap(), l = { now: () => Date.now(), random: () => Math.random() };
|
|
9
|
+
function d(n, e) {
|
|
10
|
+
e.timer && clearTimeout(e.timer), e.timer = null, e.lastRefreshAt = l.now(), n.invalidateQueries({ queryKey: [...v] }, { cancelRefetch: !1 });
|
|
11
|
+
}
|
|
12
|
+
function M(n, e = l.random()) {
|
|
13
|
+
return n >= E ? A : E - Math.max(0, n) + e * C;
|
|
14
|
+
}
|
|
15
|
+
function p(n, e, o) {
|
|
16
|
+
const r = o;
|
|
17
|
+
if (e.selfId && (r == null ? void 0 : r.many) !== !0 && P(o, e.selfId)) {
|
|
18
|
+
d(n, e);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (e.timer) return;
|
|
22
|
+
const t = l.now() - e.lastRefreshAt;
|
|
23
|
+
e.timer = setTimeout(() => d(n, e), M(t));
|
|
24
|
+
}
|
|
25
|
+
function W(n, e, o) {
|
|
26
|
+
var a;
|
|
27
|
+
let r = s.get(n);
|
|
28
|
+
if (!r) {
|
|
29
|
+
const i = {
|
|
30
|
+
refs: 0,
|
|
31
|
+
adapter: null,
|
|
32
|
+
offAdapter: null,
|
|
33
|
+
offWindow: () => {
|
|
34
|
+
},
|
|
35
|
+
timer: null,
|
|
36
|
+
lastRefreshAt: 0,
|
|
37
|
+
selfId: null
|
|
38
|
+
}, u = (R) => {
|
|
39
|
+
const f = R.detail;
|
|
40
|
+
(f == null ? void 0 : f.event) === "presence:changed" && p(n, i, f.payload);
|
|
41
|
+
};
|
|
42
|
+
typeof window < "u" && (window.addEventListener(m, u), i.offWindow = () => window.removeEventListener(m, u)), r = i, s.set(n, r);
|
|
43
|
+
}
|
|
44
|
+
const t = r;
|
|
45
|
+
t.refs++, o && (t.selfId = String(o)), e && t.adapter !== e && ((a = t.offAdapter) == null || a.call(t), t.adapter = e, t.offAdapter = e.on("presence:changed", (i) => p(n, t, i)));
|
|
46
|
+
let c = !1;
|
|
47
|
+
return () => {
|
|
48
|
+
var i;
|
|
49
|
+
c || (c = !0, t.refs--, !(t.refs > 0) && ((i = t.offAdapter) == null || i.call(t), t.offWindow(), t.timer && clearTimeout(t.timer), s.delete(n)));
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function O(n = !0) {
|
|
53
|
+
const e = _(), o = N(), { userId: r } = S();
|
|
54
|
+
w(() => {
|
|
55
|
+
if (n)
|
|
56
|
+
return W(e, o, r || null);
|
|
57
|
+
}, [e, o, n, r]);
|
|
58
|
+
}
|
|
59
|
+
function K(n, e = !0) {
|
|
60
|
+
return O(e), I(e ? n : !1, { safetyMs: L });
|
|
61
|
+
}
|
|
62
|
+
export {
|
|
63
|
+
E as PRESENCE_MIN_REFRESH_GAP_MS,
|
|
64
|
+
v as PRESENCE_ONLINE_KEY,
|
|
65
|
+
L as PRESENCE_POLL_BACKSTOP_MS,
|
|
66
|
+
C as PRESENCE_REFRESH_JITTER_MS,
|
|
67
|
+
A as PRESENCE_REFRESH_WINDOW_MS,
|
|
68
|
+
W as acquirePresenceListener,
|
|
69
|
+
l as presenceLiveClock,
|
|
70
|
+
M as presenceRefreshDelay,
|
|
71
|
+
O as usePresenceOnlineLive,
|
|
72
|
+
K as usePresenceOnlinePoll
|
|
73
|
+
};
|
|
@@ -1,49 +1,57 @@
|
|
|
1
|
-
function
|
|
2
|
-
const
|
|
3
|
-
return
|
|
1
|
+
function m(t) {
|
|
2
|
+
const n = Math.max(0, Math.floor(t.minutes)), e = n >= 60 ? `${Math.floor(n / 60)}h ${n % 60}m` : `${n}m`;
|
|
3
|
+
return t.label ? `stuck on ${t.label} for ${e}` : `stuck for ${e}`;
|
|
4
4
|
}
|
|
5
|
-
function
|
|
6
|
-
if (!
|
|
7
|
-
const
|
|
8
|
-
if (
|
|
9
|
-
const e = /* @__PURE__ */ new Set(["records", "collections", "p"]), o =
|
|
10
|
-
return o.length === 0 ? "Home" : o.map((
|
|
5
|
+
function $(t) {
|
|
6
|
+
if (!t) return null;
|
|
7
|
+
const n = t.split("?")[0].split("/").filter(Boolean);
|
|
8
|
+
if (n.length === 0) return "Home";
|
|
9
|
+
const e = /* @__PURE__ */ new Set(["records", "collections", "p"]), o = n.filter((r) => !e.has(r));
|
|
10
|
+
return o.length === 0 ? "Home" : o.map((r, s) => s === 0 ? r.replace(/[-_]/g, " ").replace(/\b\w/g, (l) => l.toUpperCase()) : r).join(" › ");
|
|
11
11
|
}
|
|
12
12
|
const a = /* @__PURE__ */ new Set(["API", "admin"]);
|
|
13
|
-
function d(
|
|
14
|
-
if (!
|
|
15
|
-
const
|
|
16
|
-
let s = null;
|
|
17
|
-
c && c[2] !== "new" && o && (s = o(c[1], encodeURIComponent(c[2])));
|
|
18
|
-
const i = (e == null ? void 0 : e.replace(/\/$/, "")) ?? "";
|
|
13
|
+
function d(t, n, e, o, r) {
|
|
14
|
+
if (!t || !t.startsWith("/") || t.startsWith("//") || /[\\\s]/.test(t)) return null;
|
|
15
|
+
const s = t.split("#")[0], l = /^\/(?:records|collections)\/([A-Za-z0-9_]+)\/([^/?#]+)/.exec(s);
|
|
19
16
|
let u = null;
|
|
17
|
+
l && l[2] !== "new" && o && (u = o(l[1], encodeURIComponent(l[2])));
|
|
18
|
+
const i = (e == null ? void 0 : e.replace(/\/$/, "")) ?? "";
|
|
19
|
+
let c = null;
|
|
20
20
|
try {
|
|
21
|
-
|
|
21
|
+
c = i && r ? new URL(i, r).origin : null;
|
|
22
22
|
} catch {
|
|
23
|
-
|
|
23
|
+
c = null;
|
|
24
24
|
}
|
|
25
|
-
const f = !!
|
|
26
|
-
return
|
|
25
|
+
const f = !!c && c === r;
|
|
26
|
+
return u || (n && a.has(n) ? u = f ? s : i ? `${i}${s}` : null : u = f ? null : s), p(u, r, c);
|
|
27
27
|
}
|
|
28
|
-
function p(
|
|
29
|
-
if (!
|
|
28
|
+
function p(t, n, e) {
|
|
29
|
+
if (!t || !n) return null;
|
|
30
30
|
try {
|
|
31
|
-
const o = new URL(
|
|
32
|
-
return o.protocol !== "http:" && o.protocol !== "https:" ? null : o.origin ===
|
|
31
|
+
const o = new URL(t, n);
|
|
32
|
+
return o.protocol !== "http:" && o.protocol !== "https:" ? null : o.origin === n || o.origin === e ? t : null;
|
|
33
33
|
} catch {
|
|
34
34
|
return null;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
function
|
|
38
|
-
return /^https?:\/\//i.test(
|
|
37
|
+
function g(t, n) {
|
|
38
|
+
return /^https?:\/\//i.test(t) ? t : `${typeof window > "u" ? "" : window.location.origin}${t}`;
|
|
39
|
+
}
|
|
40
|
+
function h(t) {
|
|
41
|
+
return t.online ? t.away ? "away" : (t.idle_minutes ?? 0) >= 5 ? "idle" : "online" : "offline";
|
|
39
42
|
}
|
|
40
|
-
function
|
|
41
|
-
|
|
43
|
+
function y(t, n) {
|
|
44
|
+
if (!n) return !1;
|
|
45
|
+
const e = t ?? {};
|
|
46
|
+
if (e.many === !0) return !0;
|
|
47
|
+
const o = String(n).toUpperCase();
|
|
48
|
+
return Array.isArray(e.user_ids) && e.user_ids.some((r) => String(r).toUpperCase() === o) ? !0 : String(e.user_id ?? "").toUpperCase() === o;
|
|
42
49
|
}
|
|
43
50
|
export {
|
|
44
|
-
|
|
51
|
+
g as fullHref,
|
|
52
|
+
y as presenceChangeTouches,
|
|
45
53
|
d as presencePlaceHref,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
h as presenceWord,
|
|
55
|
+
$ as prettyPagePath,
|
|
56
|
+
m as stuckText
|
|
49
57
|
};
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import { clearChatOutbox as z } from "../components/chat/chat-outbox.js";
|
|
2
2
|
import { get as C, patch as G } from "./commands.js";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { userErrorMessage as H } from "./safe-error.js";
|
|
4
|
+
const Z = "nivaro-record-outbox", k = "entries", Q = 1, tt = 10080 * 60 * 1e3, P = 8e3;
|
|
5
|
+
function et(t) {
|
|
5
6
|
return t ? `${typeof location < "u" ? location.host : ""}|${t}` : null;
|
|
6
7
|
}
|
|
7
|
-
function
|
|
8
|
+
function nt(t) {
|
|
8
9
|
return t.slice(t.lastIndexOf("|") + 1);
|
|
9
10
|
}
|
|
10
11
|
function p(t, e, n) {
|
|
11
12
|
return `${t}|${e}|${String(n)}`;
|
|
12
13
|
}
|
|
13
|
-
let
|
|
14
|
+
let ot = !1;
|
|
14
15
|
const O = /* @__PURE__ */ new Map();
|
|
15
|
-
function
|
|
16
|
+
function rt() {
|
|
16
17
|
return new Promise((t) => {
|
|
17
18
|
try {
|
|
18
|
-
if (
|
|
19
|
-
const e = indexedDB.open(
|
|
19
|
+
if (ot || typeof indexedDB > "u") return t(null);
|
|
20
|
+
const e = indexedDB.open(Z, Q);
|
|
20
21
|
e.onupgradeneeded = () => {
|
|
21
22
|
const n = e.result;
|
|
22
23
|
n.objectStoreNames.contains(k) || n.createObjectStore(k, { keyPath: "id" });
|
|
@@ -27,7 +28,7 @@ function ot() {
|
|
|
27
28
|
});
|
|
28
29
|
}
|
|
29
30
|
async function g(t, e) {
|
|
30
|
-
const n = await
|
|
31
|
+
const n = await rt();
|
|
31
32
|
return n ? new Promise((r) => {
|
|
32
33
|
try {
|
|
33
34
|
const o = n.transaction(k, t), i = e(o.objectStore(k));
|
|
@@ -49,16 +50,16 @@ async function x(t) {
|
|
|
49
50
|
const e = await g("readonly", (n) => n.get(t));
|
|
50
51
|
return e.ok ? e.value ?? null : O.get(t) ?? null;
|
|
51
52
|
}
|
|
52
|
-
async function
|
|
53
|
+
async function M() {
|
|
53
54
|
const t = await g("readonly", (e) => e.getAll());
|
|
54
55
|
return t.ok ? t.value ?? [] : [...O.values()];
|
|
55
56
|
}
|
|
56
57
|
function W(t) {
|
|
57
58
|
return JSON.parse(JSON.stringify(t ?? null));
|
|
58
59
|
}
|
|
59
|
-
let l = null,
|
|
60
|
+
let l = null, it = !1, j = null, w = null, a = [];
|
|
60
61
|
const D = /* @__PURE__ */ new Set(), I = /* @__PURE__ */ new Set(), N = /* @__PURE__ */ new Set();
|
|
61
|
-
let S = null, A = !1,
|
|
62
|
+
let S = null, A = !1, m = null;
|
|
62
63
|
function d() {
|
|
63
64
|
for (const t of D) t();
|
|
64
65
|
}
|
|
@@ -71,37 +72,37 @@ function R(t) {
|
|
|
71
72
|
}
|
|
72
73
|
function y() {
|
|
73
74
|
try {
|
|
74
|
-
|
|
75
|
+
m == null || m.postMessage({ type: "changed" });
|
|
75
76
|
} catch {
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
function K(t, e) {
|
|
79
80
|
const n = new Date(t.created_at).getTime();
|
|
80
|
-
return !Number.isFinite(n) || e - n >
|
|
81
|
+
return !Number.isFinite(n) || e - n > tt;
|
|
81
82
|
}
|
|
82
|
-
async function
|
|
83
|
-
const e =
|
|
83
|
+
async function st(t) {
|
|
84
|
+
const e = B();
|
|
84
85
|
if (!e) return t();
|
|
85
86
|
await e.request("nvr-record-outbox:sweep", {}, t).catch(() => {
|
|
86
87
|
});
|
|
87
88
|
}
|
|
88
89
|
async function V() {
|
|
89
90
|
const t = l;
|
|
90
|
-
t && await
|
|
91
|
+
t && await st(async () => {
|
|
91
92
|
const e = Date.now();
|
|
92
|
-
for (const n of await
|
|
93
|
+
for (const n of await M()) {
|
|
93
94
|
if (!n || n.owner !== t || !K(n, e)) continue;
|
|
94
95
|
const r = await x(n.id);
|
|
95
96
|
r && (await v(n.id), a = a.filter((o) => o.id !== n.id), d(), y(), l === t && R({ type: "expired", entry: r }));
|
|
96
97
|
}
|
|
97
98
|
});
|
|
98
99
|
}
|
|
99
|
-
async function
|
|
100
|
-
for (const e of await
|
|
100
|
+
async function at(t) {
|
|
101
|
+
for (const e of await M()) e && e.owner !== t && await v(e.id);
|
|
101
102
|
}
|
|
102
103
|
async function $() {
|
|
103
104
|
if (!l) return;
|
|
104
|
-
const t = l, e = await
|
|
105
|
+
const t = l, e = await M(), n = Date.now(), r = [];
|
|
105
106
|
let o = !1;
|
|
106
107
|
for (const i of e)
|
|
107
108
|
if (!(!i || i.owner !== t)) {
|
|
@@ -113,31 +114,31 @@ async function $() {
|
|
|
113
114
|
}
|
|
114
115
|
l === t && (a = r, d(), o && await V());
|
|
115
116
|
}
|
|
116
|
-
function
|
|
117
|
+
function bt(t, e, n) {
|
|
117
118
|
j = t, n && (w = n);
|
|
118
|
-
const r =
|
|
119
|
+
const r = et(e);
|
|
119
120
|
if (!(!r || r === l)) {
|
|
120
|
-
if (l = r, a = [], d(), typeof BroadcastChannel < "u" && !
|
|
121
|
+
if (l = r, a = [], d(), typeof BroadcastChannel < "u" && !m)
|
|
121
122
|
try {
|
|
122
|
-
|
|
123
|
+
m = new BroadcastChannel("nvr-record-outbox"), m.onmessage = () => void $();
|
|
123
124
|
} catch {
|
|
124
|
-
|
|
125
|
+
m = null;
|
|
125
126
|
}
|
|
126
|
-
!A && typeof window < "u" && (A = !0, window.addEventListener("online", () => b(0))),
|
|
127
|
+
!A && typeof window < "u" && (A = !0, window.addEventListener("online", () => b(0))), at(r).then(() => (y(), $())).then(() => {
|
|
127
128
|
a.some((o) => o.status === "queued") && b(1e3);
|
|
128
129
|
});
|
|
129
130
|
}
|
|
130
131
|
}
|
|
131
|
-
function
|
|
132
|
+
function pt() {
|
|
132
133
|
return a;
|
|
133
134
|
}
|
|
134
|
-
function
|
|
135
|
+
function Ot(t) {
|
|
135
136
|
return D.add(t), () => D.delete(t);
|
|
136
137
|
}
|
|
137
|
-
function
|
|
138
|
+
function gt(t) {
|
|
138
139
|
return I.add(t), () => I.delete(t);
|
|
139
140
|
}
|
|
140
|
-
function
|
|
141
|
+
function vt(t) {
|
|
141
142
|
return N.add(t), () => N.delete(t);
|
|
142
143
|
}
|
|
143
144
|
function F(t) {
|
|
@@ -145,7 +146,7 @@ function F(t) {
|
|
|
145
146
|
const e = t, n = (e == null ? void 0 : e.status) ?? ((r = e == null ? void 0 : e.response) == null ? void 0 : r.status);
|
|
146
147
|
return n == null ? !(e != null && e.response) : n === 0 || n === 502 || n === 503 || n === 504;
|
|
147
148
|
}
|
|
148
|
-
function
|
|
149
|
+
function ct(t) {
|
|
149
150
|
const e = t == null ? void 0 : t.response, n = (e == null ? void 0 : e.data) ?? e;
|
|
150
151
|
return (n == null ? void 0 : n.code) !== "MIDAIR_COLLISION" || !Array.isArray(n.conflicts) ? null : { conflicts: n.conflicts, latest: Number(n.latest_revision) || 0 };
|
|
151
152
|
}
|
|
@@ -158,9 +159,9 @@ function L(t, e) {
|
|
|
158
159
|
return !1;
|
|
159
160
|
}
|
|
160
161
|
}
|
|
161
|
-
async function
|
|
162
|
+
async function xt(t) {
|
|
162
163
|
const e = l;
|
|
163
|
-
if (!e ||
|
|
164
|
+
if (!e || it) return null;
|
|
164
165
|
const n = {};
|
|
165
166
|
for (const [f, Y] of Object.entries(t.payload)) f.startsWith("_") || (n[f] = Y);
|
|
166
167
|
if (Object.keys(n).length === 0) return null;
|
|
@@ -185,7 +186,7 @@ async function gt(t) {
|
|
|
185
186
|
});
|
|
186
187
|
return l !== e ? null : (a = [...a.filter((f) => f.id !== r), q], d(), await T(q), y(), b(P), q);
|
|
187
188
|
}
|
|
188
|
-
async function
|
|
189
|
+
async function St(t, e, n) {
|
|
189
190
|
if (!l) return;
|
|
190
191
|
const r = p(l, t, e), o = a.find((s) => s.id === r) ?? await x(r);
|
|
191
192
|
if (!o || o.owner !== l) return;
|
|
@@ -204,26 +205,26 @@ async function vt(t, e, n) {
|
|
|
204
205
|
}
|
|
205
206
|
y();
|
|
206
207
|
}
|
|
207
|
-
async function
|
|
208
|
+
async function kt(t, e) {
|
|
208
209
|
if (!l) return;
|
|
209
210
|
const n = p(l, t, e);
|
|
210
211
|
a = a.filter((r) => r.id !== n), d(), await v(n), y();
|
|
211
212
|
}
|
|
212
|
-
async function
|
|
213
|
+
async function _t() {
|
|
213
214
|
z(), a = [], O.clear(), d(), await g("readwrite", (t) => t.clear()), y();
|
|
214
215
|
}
|
|
215
|
-
async function
|
|
216
|
+
async function h(t, e) {
|
|
216
217
|
const n = a.find((o) => o.id === t) ?? await x(t);
|
|
217
218
|
if (!n) return null;
|
|
218
219
|
const r = { ...n, ...e };
|
|
219
220
|
return a = a.some((o) => o.id === t) ? a.map((o) => o.id === t ? r : o) : a, d(), await T(r), y(), r;
|
|
220
221
|
}
|
|
221
|
-
function
|
|
222
|
+
function B() {
|
|
222
223
|
const t = globalThis.navigator;
|
|
223
224
|
return (t == null ? void 0 : t.locks) ?? null;
|
|
224
225
|
}
|
|
225
226
|
const _ = /* @__PURE__ */ new Set();
|
|
226
|
-
function
|
|
227
|
+
function Rt(t, e) {
|
|
227
228
|
if (!l) return () => {
|
|
228
229
|
};
|
|
229
230
|
const n = p(l, t, e);
|
|
@@ -232,15 +233,15 @@ function kt(t, e) {
|
|
|
232
233
|
};
|
|
233
234
|
const o = new Promise((c) => {
|
|
234
235
|
r = c;
|
|
235
|
-
}), i =
|
|
236
|
+
}), i = B();
|
|
236
237
|
return i && i.request(`nvr-record-outbox:${n}`, {}, () => o).catch(() => {
|
|
237
238
|
}), () => {
|
|
238
239
|
_.delete(n), r();
|
|
239
240
|
};
|
|
240
241
|
}
|
|
241
|
-
async function
|
|
242
|
+
async function lt(t, e) {
|
|
242
243
|
if (_.has(t)) return;
|
|
243
|
-
const n =
|
|
244
|
+
const n = B();
|
|
244
245
|
if (!n) return e();
|
|
245
246
|
await n.request(`nvr-record-outbox:${t}`, { ifAvailable: !0 }, async (r) => {
|
|
246
247
|
r && await e();
|
|
@@ -250,25 +251,25 @@ async function ct(t, e) {
|
|
|
250
251
|
let E = !1;
|
|
251
252
|
function b(t) {
|
|
252
253
|
S && clearTimeout(S), S = setTimeout(() => {
|
|
253
|
-
S = null,
|
|
254
|
+
S = null, ft();
|
|
254
255
|
}, t);
|
|
255
256
|
}
|
|
256
|
-
async function
|
|
257
|
+
async function ut(t, e) {
|
|
257
258
|
var n;
|
|
258
259
|
try {
|
|
259
260
|
const r = await t.request(C("/auth/me")), o = (n = r == null ? void 0 : r.data) == null ? void 0 : n.id;
|
|
260
|
-
return !!o && String(o).toLowerCase() ===
|
|
261
|
+
return !!o && String(o).toLowerCase() === nt(e).toLowerCase();
|
|
261
262
|
} catch (r) {
|
|
262
263
|
return F(r) ? null : !1;
|
|
263
264
|
}
|
|
264
265
|
}
|
|
265
|
-
async function
|
|
266
|
+
async function ft() {
|
|
266
267
|
if (E || !j || !l || (await V(), !a.some((r) => r.status === "queued"))) return;
|
|
267
268
|
E = !0;
|
|
268
269
|
const t = j, e = l;
|
|
269
270
|
let n = !1;
|
|
270
271
|
try {
|
|
271
|
-
const r = await
|
|
272
|
+
const r = await ut(t, e);
|
|
272
273
|
if (r === null) {
|
|
273
274
|
n = !0;
|
|
274
275
|
return;
|
|
@@ -278,20 +279,20 @@ async function ut() {
|
|
|
278
279
|
const o = a.filter((i) => i.status === "queued" && !_.has(i.id));
|
|
279
280
|
for (const i of o) {
|
|
280
281
|
if (l !== e) return;
|
|
281
|
-
if (await
|
|
282
|
+
if (await lt(i.id, async () => {
|
|
282
283
|
const c = await x(i.id);
|
|
283
284
|
if (!c || c.owner !== e || c.status !== "queued") {
|
|
284
285
|
await $();
|
|
285
286
|
return;
|
|
286
287
|
}
|
|
287
|
-
await
|
|
288
|
+
await yt(t, c) === "offline" && (n = !0);
|
|
288
289
|
}), n) break;
|
|
289
290
|
}
|
|
290
291
|
} finally {
|
|
291
292
|
E = !1, n && b(P);
|
|
292
293
|
}
|
|
293
294
|
}
|
|
294
|
-
async function
|
|
295
|
+
async function dt(t, e) {
|
|
295
296
|
const n = Object.keys(e.payload), r = await t.request(
|
|
296
297
|
C(`/items/${e.collection}/${encodeURIComponent(e.item)}`, { fields: n.join(",") })
|
|
297
298
|
), o = (r == null ? void 0 : r.data) ?? {}, i = [];
|
|
@@ -307,13 +308,13 @@ async function ft(t, e) {
|
|
|
307
308
|
});
|
|
308
309
|
return { conflicts: i, latest: c == null ? null : Number(c) || null };
|
|
309
310
|
}
|
|
310
|
-
async function
|
|
311
|
+
async function yt(t, e) {
|
|
311
312
|
var n, r;
|
|
312
|
-
await
|
|
313
|
+
await h(e.id, { status: "sending" });
|
|
313
314
|
try {
|
|
314
315
|
let o = e.base_revision;
|
|
315
316
|
if (o == null) {
|
|
316
|
-
const c = await
|
|
317
|
+
const c = await dt(t, e);
|
|
317
318
|
if (c.conflicts.length > 0) return J(e, c.conflicts, c.latest ?? 0);
|
|
318
319
|
o = c.latest;
|
|
319
320
|
}
|
|
@@ -321,11 +322,11 @@ async function dt(t, e) {
|
|
|
321
322
|
return o != null && (i._base_revision = o), e.change_reason && (i._change_reason = e.change_reason), await t.request(G(`/items/${e.collection}/${encodeURIComponent(e.item)}`, i)), U(e);
|
|
322
323
|
} catch (o) {
|
|
323
324
|
if (F(o))
|
|
324
|
-
return await
|
|
325
|
-
const i =
|
|
325
|
+
return await h(e.id, { status: "queued", error: "Waiting for a connection" }), "offline";
|
|
326
|
+
const i = ct(o);
|
|
326
327
|
if (i)
|
|
327
328
|
return i.conflicts.every((u) => L(u.current_value, e.payload[u.field])) ? U(e) : J(e, i.conflicts, i.latest);
|
|
328
|
-
const c = ((n = o == null ? void 0 : o.response) == null ? void 0 : n.message) ?? ((r = o == null ? void 0 : o.response) == null ? void 0 : r.error) ?? (o
|
|
329
|
+
const c = ((n = o == null ? void 0 : o.response) == null ? void 0 : n.message) ?? ((r = o == null ? void 0 : o.response) == null ? void 0 : r.error) ?? H(o, "Could not save"), s = await h(e.id, { status: "failed", error: c });
|
|
329
330
|
return s && R({ type: "failed", entry: s }), "failed";
|
|
330
331
|
}
|
|
331
332
|
}
|
|
@@ -333,7 +334,7 @@ async function U(t) {
|
|
|
333
334
|
return a = a.filter((e) => e.id !== t.id), d(), await v(t.id), y(), R({ type: "replayed", entry: t }), w == null || w.invalidateQueries({ queryKey: ["item", t.collection] }), w == null || w.invalidateQueries({ queryKey: ["collision-base", t.collection] }), "done";
|
|
334
335
|
}
|
|
335
336
|
async function J(t, e, n) {
|
|
336
|
-
const r = await
|
|
337
|
+
const r = await h(t.id, {
|
|
337
338
|
status: "conflict",
|
|
338
339
|
conflicts: W(e),
|
|
339
340
|
latest_revision: n,
|
|
@@ -341,32 +342,32 @@ async function J(t, e, n) {
|
|
|
341
342
|
});
|
|
342
343
|
return r && R({ type: "conflict", entry: r }), "conflict";
|
|
343
344
|
}
|
|
344
|
-
async function
|
|
345
|
-
l && (await
|
|
345
|
+
async function qt(t, e) {
|
|
346
|
+
l && (await h(p(l, t, e), {
|
|
346
347
|
status: "queued",
|
|
347
348
|
error: null,
|
|
348
349
|
conflicts: null
|
|
349
350
|
}), b(0));
|
|
350
351
|
}
|
|
351
352
|
export {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
353
|
+
tt as RECORD_OUTBOX_TTL_MS,
|
|
354
|
+
bt as bindRecordOutbox,
|
|
355
|
+
dt as checkUnknownBase,
|
|
356
|
+
Rt as claimRecordOutbox,
|
|
357
|
+
_t as clearRecordOutbox,
|
|
358
|
+
kt as discardRecordOutbox,
|
|
359
|
+
xt as enqueueRecordSave,
|
|
360
|
+
pt as getRecordOutbox,
|
|
360
361
|
F as isOfflineSaveError,
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
362
|
+
ct as midairCollisionOf,
|
|
363
|
+
gt as onRecordOutboxEvent,
|
|
364
|
+
vt as onRecordOutboxRetry,
|
|
364
365
|
p as outboxEntryId,
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
366
|
+
et as outboxOwner,
|
|
367
|
+
ft as replayRecordOutbox,
|
|
368
|
+
qt as retryRecordOutbox,
|
|
368
369
|
b as scheduleReplay,
|
|
369
|
-
|
|
370
|
-
|
|
370
|
+
St as settleRecordOutbox,
|
|
371
|
+
Ot as subscribeRecordOutbox,
|
|
371
372
|
V as sweepExpiredRecordOutbox
|
|
372
373
|
};
|