@burdenoff/microfe-healthybowl 2026.1015.1 → 2026.1015.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.
@@ -2,6 +2,7 @@ import "./context/HealthyBowlContext.js";
2
2
  import "../components/assistant/AIAssistantPanel.js";
3
3
  import "../components/assistant/index.js";
4
4
  import "./events/rybbit.js";
5
+ import "./offline/store.js";
5
6
  import "./HealthyBowlRoot.js";
6
7
  import "./public/PublicTracePage.js";
7
8
  import "./public/PublicSeedLotPage.js";
@@ -2,46 +2,47 @@ import { useBasePath as e } from "../hooks/useBasePath.js";
2
2
  import { useOfflineSync as t } from "./OfflineSyncProvider.js";
3
3
  import { relativeTime as n } from "./observationMeta.js";
4
4
  import { compactLabel as r } from "./headerSlot.js";
5
- import { AlertTriangle as i, CheckCircle2 as a, RefreshCw as o, Wifi as s, WifiOff as c } from "lucide-react";
6
- import { Link as l } from "react-router";
7
- import { jsx as u, jsxs as d } from "react/jsx-runtime";
5
+ import { useI18n as i } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
6
+ import { AlertTriangle as a, CheckCircle2 as o, RefreshCw as s, Wifi as c, WifiOff as l } from "lucide-react";
7
+ import { Link as u } from "react-router";
8
+ import { jsx as d, jsxs as f } from "react/jsx-runtime";
8
9
  //#region src/healthybowl/offline/OfflineStatusPill.tsx
9
- var f = ({ inline: f, compact: p, className: m }) => {
10
- let { buildPath: h } = e(), { online: g, syncing: _, queuedCount: v, conflictCount: y, lastSyncedAt: b, syncNow: x } = t(), S = !g, C = v > 0, w = "ok";
11
- S ? w = "offline" : (C || y > 0) && (w = "warning");
12
- let T = w === "offline" || w === "warning" ? "bg-status-warning-bgSubtle text-status-warning-text border-status-warning-border" : "bg-status-success-bgSubtle text-status-success-text border-status-success-border", E = S ? c : y > 0 ? i : C ? s : a, D;
13
- D = S ? C ? `Offline — ${v} record${v > 1 ? "s" : ""} queued` : "Offline — working locally" : _ ? "Online — syncing…" : y > 0 ? `Online — ${y} conflict${y > 1 ? "s" : ""} to review` : C ? `Online — ${v} record${v > 1 ? "s" : ""} queued` : b ? `Online — all synced · last synced ${n(b)}` : "Online — all synced";
14
- let O = /* @__PURE__ */ d("button", {
10
+ var p = ({ inline: p, compact: m, className: h }) => {
11
+ let { buildPath: g } = e(), { t: _ } = i(), { online: v, syncing: y, queuedCount: b, conflictCount: x, needsReviewCount: S, lastSyncedAt: C, storageBlocked: w, syncNow: T } = t(), E = !v, D = b > 0, O = "ok";
12
+ E ? O = "offline" : (w || D || x > 0 || S > 0) && (O = "warning");
13
+ let k = O === "offline" || O === "warning" ? "bg-status-warning-bgSubtle text-status-warning-text border-status-warning-border" : "bg-status-success-bgSubtle text-status-success-text border-status-success-border", A = w ? a : E ? l : x > 0 || S > 0 ? a : D ? c : o, j;
14
+ j = w ? _("healthybowl.offline.pill.storageBlocked", "Close other HealthyBowl tabs · offline storage is finishing an update") : E ? D ? `Offline — ${b} record${b > 1 ? "s" : ""} queued` : "Offline — working locally" : y ? "Online — syncing…" : x > 0 ? `Online — ${x} conflict${x > 1 ? "s" : ""} to review` : D ? `Online — ${b} record${b > 1 ? "s" : ""} queued` : S > 0 ? S === 1 ? _("healthybowl.offline.pill.needsReviewOne", "Online — 1 record to review") : _("healthybowl.offline.pill.needsReviewMany", "Online — {{count}} records to review", { count: S }) : C ? `Online — all synced · last synced ${n(C)}` : "Online — all synced";
15
+ let M = /* @__PURE__ */ f("button", {
15
16
  type: "button",
16
- onClick: () => void x({ manual: !0 }),
17
- disabled: _ || !g,
18
- title: g ? "Sync now" : "Reconnect to sync",
19
- className: `inline-flex shrink-0 items-center gap-1.5 rounded-lg bg-bg-surface px-2.5 py-1 text-xs font-semibold text-text-primary shadow-sm ring-1 ring-border-subtle transition hover:bg-bg-sunken disabled:cursor-not-allowed disabled:opacity-50 ${p ? "hidden lg:inline-flex" : ""}`,
20
- children: [/* @__PURE__ */ u(o, { className: `h-3.5 w-3.5 ${_ ? "animate-spin" : ""}` }), "Sync Now"]
17
+ onClick: () => void T({ manual: !0 }),
18
+ disabled: y || !v,
19
+ title: v ? "Sync now" : "Reconnect to sync",
20
+ className: `inline-flex shrink-0 items-center gap-1.5 rounded-lg bg-bg-surface px-2.5 py-1 text-xs font-semibold text-text-primary shadow-sm ring-1 ring-border-subtle transition hover:bg-bg-sunken disabled:cursor-not-allowed disabled:opacity-50 ${m ? "hidden lg:inline-flex" : ""}`,
21
+ children: [/* @__PURE__ */ d(s, { className: `h-3.5 w-3.5 ${y ? "animate-spin" : ""}` }), "Sync Now"]
21
22
  });
22
- return p ? /* @__PURE__ */ d("div", {
23
- className: `flex max-w-[13rem] items-center gap-2 rounded-full border px-3 py-1 xl:max-w-[22rem] ${T} ${m ?? ""}`,
23
+ return m ? /* @__PURE__ */ f("div", {
24
+ className: `flex max-w-[13rem] items-center gap-2 rounded-full border px-3 py-1 xl:max-w-[22rem] ${k} ${h ?? ""}`,
24
25
  role: "status",
25
26
  "aria-live": "polite",
26
- children: [/* @__PURE__ */ d(l, {
27
- to: h("field-capture/pending"),
28
- title: D,
29
- "aria-label": D,
27
+ children: [/* @__PURE__ */ f(u, {
28
+ to: g("field-capture/pending"),
29
+ title: j,
30
+ "aria-label": j,
30
31
  className: "flex min-w-0 flex-1 items-center gap-2 text-left transition hover:opacity-90",
31
- children: [/* @__PURE__ */ u(E, { className: "h-4 w-4 shrink-0" }), /* @__PURE__ */ u("span", {
32
+ children: [/* @__PURE__ */ d(A, { className: "h-4 w-4 shrink-0" }), /* @__PURE__ */ d("span", {
32
33
  className: "truncate text-xs font-medium",
33
- children: r(D)
34
+ children: r(j)
34
35
  })]
35
- }), O]
36
- }) : /* @__PURE__ */ d("div", {
37
- className: `flex items-center justify-between gap-3 rounded-xl border px-3.5 py-2 ${T} ${f ? "" : "shadow-sm"} ${m ?? ""}`,
36
+ }), M]
37
+ }) : /* @__PURE__ */ f("div", {
38
+ className: `flex items-center justify-between gap-3 rounded-xl border px-3.5 py-2 ${k} ${p ? "" : "shadow-sm"} ${h ?? ""}`,
38
39
  role: "status",
39
40
  "aria-live": "polite",
40
- children: [/* @__PURE__ */ d("span", {
41
+ children: [/* @__PURE__ */ f("span", {
41
42
  className: "flex items-center gap-2 text-sm font-medium",
42
- children: [/* @__PURE__ */ u(E, { className: "h-4 w-4 shrink-0" }), D]
43
- }), O]
43
+ children: [/* @__PURE__ */ d(A, { className: "h-4 w-4 shrink-0" }), j]
44
+ }), M]
44
45
  });
45
46
  };
46
47
  //#endregion
47
- export { f as OfflineStatusPill };
48
+ export { p as OfflineStatusPill };
@@ -2,152 +2,235 @@ import { useHealthyBowl as e } from "../context/HealthyBowlContext.js";
2
2
  import { getNetworkState as t, isCellular as n, subscribeNetwork as r } from "./network.js";
3
3
  import { useToast as i } from "../hooks/useToast.js";
4
4
  import { DEFAULT_SETTINGS as a } from "./types.js";
5
- import { deleteObservation as o, deletePendingMutation as s, getAllObservations as c, getAllPendingMutations as l, getHistory as u, getMeta as d, getObservation as ee, getPendingMutation as te, getPhotosFor as ne, loadSettings as re, saveObservation as f, savePendingMutation as ie, savePhoto as ae, saveSettings as oe, setMeta as p } from "./store.js";
6
- import { CAPTURE_DATA_META as m, CAPTURE_PHOTO_MAX_DIM as se, CAPTURE_PHOTO_QUALITY as ce, autoResolutionFor as le, conflictsToAutoResolve as h, isUsableCaptureCache as ue, shouldCompressPhotos as de, toCachedCaptureData as fe } from "./captureCache.js";
7
- import { downscaleImage as pe } from "../utils/imageDownscale.js";
8
- import { fetchFieldCaptureData as me, resolveConflict as he } from "./graphql.js";
9
- import { drainQueue as ge } from "./syncEngine.js";
10
- import { describeDrain as _e } from "./syncOutcome.js";
11
- import { createContext as g, useCallback as _, useContext as v, useEffect as y, useMemo as b, useRef as x, useState as S } from "react";
12
- import { jsx as ve } from "react/jsx-runtime";
13
- import { useSaveToFiles as ye } from "@burdenoff/fe-libs/storage";
5
+ import { claimUnattributedObservation as o, claimUnattributedPendingMutation as s, clearSyncedCache as c, deleteObservation as l, deletePendingMutation as u, discardUnattributedObservation as ee, discardUnattributedPendingMutation as te, estimateLocalUsage as ne, getAllObservations as d, getAllPendingMutations as f, getHistory as p, getObservation as re, getPendingMutation as ie, getPhotosFor as ae, getScopedMeta as m, getUnattributedObservations as h, getUnattributedPendingMutations as g, isOfflineStoreBlocked as _, loadSettings as oe, lockOfflineActor as se, saveObservation as ce, savePendingMutation as le, savePhoto as ue, saveSettings as de, setScopedMeta as fe, subscribeOfflineStoreBlocked as pe, toOfflineScope as me, unlockOfflineActor as he, updateObservation as ge } from "./store.js";
6
+ import { CAPTURE_DATA_META as _e, CAPTURE_PHOTO_MAX_DIM as ve, CAPTURE_PHOTO_QUALITY as ye, autoResolutionFor as be, conflictsToAutoResolve as xe, isUsableCaptureCache as Se, shouldCompressPhotos as Ce, toCachedCaptureData as we } from "./captureCache.js";
7
+ import { downscaleImage as Te } from "../utils/imageDownscale.js";
8
+ import { sendIfSessionCurrent as Ee } from "./sessionGuard.js";
9
+ import { fetchFieldCaptureData as De, resolveConflict as Oe } from "./graphql.js";
10
+ import { drainQueue as ke } from "./syncEngine.js";
11
+ import { describeDrain as Ae } from "./syncOutcome.js";
12
+ import { createContext as v, useCallback as y, useContext as b, useEffect as x, useMemo as S, useRef as C, useState as w } from "react";
13
+ import { jsx as je } from "react/jsx-runtime";
14
+ import { useSaveToFiles as Me } from "@burdenoff/fe-libs/storage";
14
15
  //#region src/healthybowl/offline/OfflineSyncProvider.tsx
15
- var C = g(null);
16
- function w() {
17
- let e = v(C);
16
+ var T = v(null);
17
+ function E() {
18
+ let e = b(T);
18
19
  if (!e) throw Error("useOfflineSync must be used within an OfflineSyncProvider");
19
20
  return e;
20
21
  }
21
- var T = "lastSyncedAt";
22
- function E() {
22
+ var D = "lastSyncedAt", O = "Sign in and open a workspace to save field records on this device.", k = "This record is not available in the current session.";
23
+ function A(e) {
24
+ return {
25
+ key: e,
26
+ loaded: !1,
27
+ observations: [],
28
+ pendingMutations: [],
29
+ unattributedObservations: [],
30
+ unattributedMutations: [],
31
+ history: [],
32
+ lastSyncedAt: null,
33
+ captureData: null
34
+ };
35
+ }
36
+ function Ne(e) {
37
+ return e ? JSON.stringify([e.workspaceId, e.actorId]) : "";
38
+ }
39
+ async function j(e) {
40
+ let [t, n, r, i, a] = await Promise.all([
41
+ d(e),
42
+ p(e),
43
+ f(e),
44
+ h(e),
45
+ g(e)
46
+ ]);
47
+ return {
48
+ observations: t,
49
+ history: n,
50
+ pendingMutations: r,
51
+ unattributedObservations: i,
52
+ unattributedMutations: a
53
+ };
54
+ }
55
+ function M() {
23
56
  return (/* @__PURE__ */ new Date()).toISOString();
24
57
  }
25
- function D(e) {
58
+ function N(e) {
26
59
  return `${e}-${typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.round(Math.random() * 1e9)}`}`;
27
60
  }
28
- var O = ({ children: g }) => {
29
- let { workspaceId: v } = e(), { save: w } = ye(), { toast: O } = i(), [be, xe] = S(!1), [k, Se] = S(() => t()), [A, j] = S(!1), [M, N] = S([]), [P, F] = S([]), [Ce, I] = S([]), [L, R] = S(a), [we, z] = S(null), [B, V] = S(null), [Te, H] = S(!1), U = x(L), W = x(k), G = x(!1), K = x(w), q = x(v), J = x(() => Promise.resolve());
30
- U.current = L, W.current = k, K.current = w, q.current = v;
31
- let Y = _(async () => {
32
- let [e, t, n] = await Promise.all([
33
- c(),
34
- u(),
35
- l()
36
- ]);
37
- N(e), I(t), F(n);
38
- }, []), X = _(async () => {
39
- if (!(!q.current || !W.current.online)) {
40
- H(!0);
41
- try {
42
- let e = await me({ workspaceId: q.current });
43
- e && (V(e), await p(m, fe(e, q.current, Date.now())).catch(() => void 0));
44
- } finally {
45
- H(!1);
46
- }
47
- }
61
+ var P = ({ children: f }) => {
62
+ let { workspaceId: p, currentUser: h } = e(), g = h?.id ?? "", { save: v } = Me(), { toast: b } = i(), E = S(() => me(p, g), [p, g]), P = Ne(E), [F, Pe] = w(() => t()), [Fe, I] = w(!1), [L, R] = w(a), [z, Ie] = w(() => A(P)), [Le, B] = w(!1), [Re, ze] = w(() => _());
63
+ x(() => (ze(_()), pe(ze)), []);
64
+ let V = C(L), H = C(F), U = C(!1), Be = C(v), W = C({
65
+ key: P,
66
+ generation: 0,
67
+ scope: E
68
+ });
69
+ W.current.key !== P && (W.current = {
70
+ key: P,
71
+ generation: W.current.generation + 1,
72
+ scope: E
73
+ });
74
+ let Ve = C(() => Promise.resolve());
75
+ V.current = L, H.current = F, Be.current = v, x(() => {
76
+ let e = W;
77
+ return () => {
78
+ e.current = {
79
+ ...e.current,
80
+ generation: e.current.generation + 1
81
+ };
82
+ };
48
83
  }, []);
49
- y(() => {
50
- let e = !1;
84
+ let G = y((e, t) => {
85
+ W.current.generation === e.generation && Ie((n) => ({
86
+ ...n.key === e.key ? n : A(e.key),
87
+ ...t
88
+ }));
89
+ }, []), K = y(async () => {
90
+ let e = W.current;
91
+ G(e, await j(e.scope));
92
+ }, [G]), q = y(async () => {
93
+ let e = W.current;
94
+ if (!e.scope || !H.current.online) return;
95
+ let t = e.scope;
96
+ B(!0);
97
+ try {
98
+ let n = await De({ workspaceId: t.workspaceId });
99
+ n && W.current.generation === e.generation && (G(e, { captureData: n }), await fe(t, _e, we(n, t.workspaceId, Date.now())).catch(() => void 0));
100
+ } finally {
101
+ B(!1);
102
+ }
103
+ }, [G]), He = C("");
104
+ x(() => {
105
+ let e = He.current;
106
+ He.current = g, e && e !== g && se(e);
107
+ }, [g]), x(() => {
108
+ let e = !1, t = W.current;
51
109
  return (async () => {
52
- let [t, n, r, i, a, o] = await Promise.all([
53
- c(),
54
- u(),
55
- re(),
56
- d(T),
57
- l(),
58
- d(m)
110
+ t.scope && await he(t.scope.actorId);
111
+ let [n, r, i, a] = await Promise.all([
112
+ j(t.scope),
113
+ oe(),
114
+ m(t.scope, D),
115
+ m(t.scope, _e)
59
116
  ]);
60
- e || (N(t), I(n), R(r), z(i ?? null), F(a), ue(o, q.current, Date.now()) && V(o.data), xe(!0));
117
+ e || (R(r), G(t, {
118
+ ...n,
119
+ lastSyncedAt: i ?? null,
120
+ captureData: Se(a, t.scope?.workspaceId, Date.now()) ? a.data : null,
121
+ loaded: !0
122
+ }));
61
123
  })(), () => {
62
124
  e = !0;
63
125
  };
64
- }, []), y(() => {
65
- X();
66
- }, [X, v]);
67
- let Z = _(async (e) => {
68
- if (G.current) return;
69
- let t = q.current, r = W.current;
70
- if (!(!t || !r.online) && !(!e?.manual && !U.current.syncOverMobileData && n(r))) {
71
- G.current = !0, j(!0);
72
- try {
73
- let n = await ge({
74
- workspaceId: t,
75
- saveToFiles: K.current,
76
- settings: U.current,
77
- network: r
78
- }), i = Date.now();
79
- z(i), await p(T, i), await Y(), X();
80
- let a = le(U.current.conflictHandling), o = n.conflict;
81
- if (a && n.conflict > 0) {
82
- let e = h(await c(), t), r = 0;
83
- for (let t of e) await J.current(t.clientId, a, void 0, { silent: !0 }).then(() => !0, () => !1) && (r += 1);
84
- o = Math.max(0, n.conflict - r), r > 0 && (await Y(), O({
85
- title: `${r} conflict${r > 1 ? "s" : ""} resolved`,
86
- description: a === "KEEP_MINE" ? "Your offline version was kept, as set in Offline Settings." : "The server version was kept, as set in Offline Settings.",
87
- variant: "info"
88
- }));
126
+ }, [P, G]), x(() => {
127
+ q();
128
+ }, [q, P]);
129
+ let J = y(async (e) => {
130
+ if (U.current) return;
131
+ let t = W.current, r = H.current;
132
+ if (!t.scope || !r.online) return;
133
+ let i = t.scope;
134
+ if (!e?.manual && !V.current.syncOverMobileData && n(r)) return;
135
+ let a = () => W.current.generation === t.generation;
136
+ U.current = !0, I(!0);
137
+ try {
138
+ let n = await ke({
139
+ scope: i,
140
+ isCurrent: a,
141
+ saveToFiles: Be.current,
142
+ settings: V.current,
143
+ network: r
144
+ });
145
+ if (n.aborted || !a()) return;
146
+ let o = Date.now();
147
+ G(t, { lastSyncedAt: o }), await fe(i, D, o), await K(), q();
148
+ let s = be(V.current.conflictHandling), c = n.conflict;
149
+ if (s && n.conflict > 0) {
150
+ let e = xe(await d(i), i.workspaceId), r = 0;
151
+ for (let n of e) {
152
+ if (!a()) break;
153
+ await Ve.current(n.clientId, s, void 0, {
154
+ silent: !0,
155
+ session: t
156
+ }).then(() => !0, () => !1) && (r += 1);
89
157
  }
90
- let s = _e({
91
- ...n,
92
- conflict: o
93
- }, { manual: e?.manual });
94
- s && O(s);
95
- } catch {
96
- e?.manual && O({
97
- title: "Sync failed",
98
- description: "Please try again.",
99
- variant: "error"
100
- });
101
- } finally {
102
- G.current = !1, j(!1);
158
+ if (!a()) return;
159
+ c = Math.max(0, n.conflict - r), r > 0 && (await K(), b({
160
+ title: `${r} conflict${r > 1 ? "s" : ""} resolved`,
161
+ description: s === "KEEP_MINE" ? "Your offline version was kept, as set in Offline Settings." : "The server version was kept, as set in Offline Settings.",
162
+ variant: "info"
163
+ }));
103
164
  }
165
+ let l = Ae({
166
+ ...n,
167
+ conflict: c
168
+ }, { manual: e?.manual });
169
+ l && b(l);
170
+ } catch {
171
+ e?.manual && a() && b({
172
+ title: "Sync failed",
173
+ description: "Please try again.",
174
+ variant: "error"
175
+ });
176
+ } finally {
177
+ U.current = !1, I(!1);
104
178
  }
105
179
  }, [
106
- Y,
107
- X,
108
- O
180
+ G,
181
+ K,
182
+ q,
183
+ b
109
184
  ]);
110
- y(() => {
111
- let e = W.current.online;
185
+ x(() => {
186
+ let e = H.current.online;
112
187
  return r((t) => {
113
- Se(t);
188
+ Pe(t);
114
189
  let n = !e && t.online;
115
- e = t.online, n && U.current.autoSyncOnReconnect && Z();
190
+ e = t.online, n && V.current.autoSyncOnReconnect && J();
116
191
  });
117
- }, [Z]), y(() => {
192
+ }, [J]), x(() => {
118
193
  if (!L.autoSyncOnReconnect || L.syncFrequencyMs <= 0) return;
119
194
  let e = window.setInterval(() => {
120
- W.current.online && Z();
195
+ H.current.online && J();
121
196
  }, L.syncFrequencyMs);
122
197
  return () => window.clearInterval(e);
123
198
  }, [
124
199
  L.autoSyncOnReconnect,
125
200
  L.syncFrequencyMs,
126
- Z
201
+ J
127
202
  ]);
128
- let Ee = _(async (e) => {
129
- let t = D("obs"), n = [], r = de(U.current);
130
- for (let i of e.photos ?? []) {
131
- let e = D("photo"), a = i, o = i.name || `photo-${e}.jpg`, s = i.type || "image/jpeg";
132
- if (r) try {
133
- let e = await pe(i, {
134
- maxDim: se,
135
- quality: ce,
203
+ let Ue = y(async (e) => {
204
+ let t = W.current.scope;
205
+ if (!t) throw b({
206
+ title: "Not saved",
207
+ description: O,
208
+ variant: "error"
209
+ }), Error(O);
210
+ let n = N("obs"), r = [], i = Ce(V.current);
211
+ for (let a of e.photos ?? []) {
212
+ let e = N("photo"), o = a, s = a.name || `photo-${e}.jpg`, c = a.type || "image/jpeg";
213
+ if (i) try {
214
+ let e = await Te(a, {
215
+ maxDim: ve,
216
+ quality: ye,
136
217
  encodeFallback: !1
137
218
  });
138
- e.downscaled && e.blob && (a = e.blob, o = e.filename ?? o, s = e.mimeType ?? "image/jpeg");
219
+ e.downscaled && e.blob && (o = e.blob, s = e.filename ?? s, c = e.mimeType ?? "image/jpeg");
139
220
  } catch {}
140
- await ae({
221
+ await ue({
141
222
  id: e,
142
- clientId: t,
143
- blob: a,
144
- filename: o,
145
- mimeType: s,
146
- createdAt: Date.now()
147
- }), n.push(e);
223
+ clientId: n,
224
+ blob: o,
225
+ filename: s,
226
+ mimeType: c,
227
+ createdAt: Date.now(),
228
+ workspaceId: t.workspaceId,
229
+ actorId: t.actorId
230
+ }), r.push(e);
148
231
  }
149
- let i = {
150
- clientId: t,
232
+ let a = {
233
+ clientId: n,
151
234
  observationType: e.observationType,
152
235
  fieldId: e.fieldId ?? null,
153
236
  fieldName: e.fieldName ?? null,
@@ -160,25 +243,35 @@ var O = ({ children: g }) => {
160
243
  latitude: e.latitude ?? null,
161
244
  longitude: e.longitude ?? null,
162
245
  gpsAccuracy: e.gpsAccuracy ?? null,
163
- photoLocalIds: n,
246
+ photoLocalIds: r,
164
247
  photoFileIds: [],
165
- capturedAt: E(),
166
- capturedOffline: !W.current.online,
248
+ capturedAt: M(),
249
+ capturedOffline: !H.current.online,
167
250
  status: "QUEUED",
168
251
  baseVersion: null,
169
252
  attempts: 0,
170
253
  createdAt: Date.now(),
171
254
  updatedAt: Date.now(),
172
- workspaceId: q.current
255
+ workspaceId: t.workspaceId,
256
+ actorId: t.actorId
173
257
  };
174
- return await f(i), await Y(), W.current.online && U.current.autoSyncOnReconnect && Z(), i;
175
- }, [Y, Z]), Q = _(async (e, t, n, r) => {
176
- let i = await ee(e), a = i?.serverVersion?.version ?? i?.baseVersion ?? 0;
258
+ return await ce(a), await K(), H.current.online && V.current.autoSyncOnReconnect && J(), a;
259
+ }, [
260
+ K,
261
+ J,
262
+ b
263
+ ]), We = y(async (e, t, n, r) => {
264
+ let i = r?.session ?? W.current, a = () => W.current.generation === i.generation;
177
265
  try {
178
- let o = await he({ workspaceId: q.current }, {
266
+ let o = i.scope, s = o ? await re(o, e) : void 0;
267
+ if (!o || !s) throw Error(k);
268
+ let c = s.serverVersion?.version ?? s.baseVersion ?? 0, l = await Ee({
269
+ scope: o,
270
+ isCurrent: a
271
+ }, () => Oe({ workspaceId: o.workspaceId }, {
179
272
  clientId: e,
180
273
  resolution: t,
181
- baseVersion: a,
274
+ baseVersion: c,
182
275
  fieldId: n?.fieldId,
183
276
  note: n?.note,
184
277
  severity: n?.severity,
@@ -189,23 +282,31 @@ var O = ({ children: g }) => {
189
282
  latitude: n?.latitude,
190
283
  longitude: n?.longitude,
191
284
  photoFileIds: n?.photoFileIds
192
- });
193
- i && (i.status = "SYNCED", i.serverVersion = null, i.baseVersion = o.version, i.serverId = o.id, i.syncedAt = E(), i.message = null, i.note = o.note ?? i.note, i.severity = o.severity ?? i.severity, i.updatedAt = Date.now(), await f(i)), await Y(), r?.silent || O({
285
+ }));
286
+ if (!l.sent) throw Error(k);
287
+ let u = l.result;
288
+ if (s.status = "SYNCED", s.serverVersion = null, s.baseVersion = u.version, s.serverId = u.id, s.syncedAt = M(), s.message = null, s.note = u.note ?? s.note, s.severity = u.severity ?? s.severity, s.updatedAt = Date.now(), await ge(s), !a()) return;
289
+ await K(), r?.silent || b({
194
290
  title: "Conflict resolved",
195
291
  variant: "success"
196
292
  });
197
293
  } catch (e) {
198
294
  let t = e instanceof Error ? e.message : "Could not resolve the conflict";
199
- throw r?.silent || O({
295
+ throw !r?.silent && a() && b({
200
296
  title: "Resolve failed",
201
297
  description: t,
202
298
  variant: "error"
203
299
  }), e;
204
300
  }
205
- }, [Y, O]), De = _(async (e, t) => {
206
- let n = D("scheme");
207
- if (await ie({
208
- clientId: n,
301
+ }, [K, b]), Ge = y(async (e, t) => {
302
+ let n = W.current.scope;
303
+ if (!n) return {
304
+ status: "FAILED",
305
+ message: O
306
+ };
307
+ let r = N("scheme");
308
+ if (await le({
309
+ clientId: r,
209
310
  kind: "SCHEME_APPLICATION",
210
311
  payload: e,
211
312
  label: t,
@@ -213,63 +314,79 @@ var O = ({ children: g }) => {
213
314
  attempts: 0,
214
315
  createdAt: Date.now(),
215
316
  updatedAt: Date.now(),
216
- workspaceId: q.current
217
- }), await Y(), !W.current.online) return { status: "QUEUED" };
218
- await Z();
219
- let r = await te(n);
220
- return await Y(), r?.status === "SYNCED" && r.serverId ? {
317
+ workspaceId: n.workspaceId,
318
+ actorId: n.actorId
319
+ }), await K(), !H.current.online) return { status: "QUEUED" };
320
+ await J();
321
+ let i = await ie(n, r);
322
+ return await K(), i?.status === "SYNCED" && i.serverId ? {
221
323
  status: "SYNCED",
222
- serverId: r.serverId
223
- } : r?.status === "FAILED" ? {
324
+ serverId: i.serverId
325
+ } : i?.status === "FAILED" ? {
224
326
  status: "FAILED",
225
- message: r.message ?? "The server rejected this application."
327
+ message: i.message ?? "The server rejected this application."
226
328
  } : { status: "QUEUED" };
227
- }, [Y, Z]);
228
- J.current = Q;
229
- let Oe = _(async (e) => {
230
- await s(e), await Y();
231
- }, [Y]), ke = _(async (e) => {
232
- await o(e), await Y();
233
- }, [Y]), Ae = _(async (e) => {
329
+ }, [K, J]);
330
+ Ve.current = We;
331
+ let Ke = y(async (e) => {
332
+ await u(W.current.scope, e), await K();
333
+ }, [K]), qe = y(async (e) => {
334
+ let t = await l(W.current.scope, e);
335
+ if (await K(), !t) throw Error(k);
336
+ }, [K]), Je = y(async (e, t) => {
337
+ let n = W.current, r = e === "observation" ? await o(n.scope, t) : await s(n.scope, t);
338
+ return await K(), r && H.current.online && V.current.autoSyncOnReconnect && J(), r !== null;
339
+ }, [K, J]), Ye = y(async (e, t) => {
340
+ let n = W.current.scope, r = e === "observation" ? await ee(n, t) : await te(n, t);
341
+ return await K(), r;
342
+ }, [K]), Xe = y(async (e) => {
234
343
  R((t) => {
235
344
  let n = {
236
345
  ...t,
237
346
  ...e
238
347
  };
239
- return oe(n), n;
348
+ return de(n), n;
240
349
  });
241
- }, []), $ = _((e) => ne(e), []), je = b(() => M.filter((e) => e.status === "QUEUED" || e.status === "UPLOADING" || e.status === "FAILED").length + P.filter((e) => e.status === "QUEUED" || e.status === "UPLOADING" || e.status === "FAILED").length, [M, P]), Me = b(() => M.filter((e) => e.status === "CONFLICT").length, [M]), Ne = {
242
- ready: be,
243
- online: k.online,
244
- connectionType: k.connectionType,
245
- syncing: A,
246
- lastSyncedAt: we,
247
- observations: M,
248
- pendingMutations: P,
249
- queuedCount: je,
250
- conflictCount: Me,
251
- history: Ce,
350
+ }, []), Ze = y((e) => ae(W.current.scope, e), []), Qe = y(() => ne(W.current.scope), []), $e = y(() => c(W.current.scope), []), Y = z.key === P ? z : A(P), { observations: X, pendingMutations: Z, unattributedObservations: et, unattributedMutations: Q, history: tt, lastSyncedAt: nt } = Y, $ = Y.captureData, rt = S(() => X.filter((e) => e.status === "QUEUED" || e.status === "UPLOADING" || e.status === "FAILED").length + Z.filter((e) => e.status === "QUEUED" || e.status === "UPLOADING" || e.status === "FAILED").length, [X, Z]), it = S(() => X.filter((e) => e.status === "CONFLICT").length, [X]), at = {
351
+ ready: Y.loaded,
352
+ storageBlocked: Re,
353
+ online: F.online,
354
+ connectionType: F.connectionType,
355
+ syncing: Fe,
356
+ lastSyncedAt: nt,
357
+ observations: X,
358
+ pendingMutations: Z,
359
+ unattributedObservations: et,
360
+ unattributedMutations: Q,
361
+ needsReviewCount: et.length + Q.length,
362
+ queuedCount: rt,
363
+ conflictCount: it,
364
+ history: tt,
252
365
  settings: L,
253
- fields: B?.fields ?? [],
254
- serverRecent: B?.recentObservations ?? [],
255
- stats: B?.stats ?? null,
256
- loadingCaptureData: Te,
257
- capture: Ee,
258
- queueSchemeApplication: De,
259
- discardPendingMutation: Oe,
260
- syncNow: Z,
261
- resolve: Q,
262
- remove: ke,
263
- updateSettings: Ae,
366
+ fields: $?.fields ?? [],
367
+ serverRecent: $?.recentObservations ?? [],
368
+ stats: $?.stats ?? null,
369
+ loadingCaptureData: Le,
370
+ capture: Ue,
371
+ queueSchemeApplication: Ge,
372
+ discardPendingMutation: Ke,
373
+ claimUnattributed: Je,
374
+ discardUnattributed: Ye,
375
+ estimateLocalUsage: Qe,
376
+ clearSyncedCache: $e,
377
+ syncNow: J,
378
+ resolve: We,
379
+ remove: qe,
380
+ updateSettings: Xe,
264
381
  refresh: async () => {
265
- await Y(), await X();
382
+ await K(), await q();
266
383
  },
267
- loadLocalPhotos: $
384
+ loadLocalPhotos: Ze
268
385
  };
269
- return /* @__PURE__ */ ve(C.Provider, {
270
- value: Ne,
271
- children: g
386
+ return /* @__PURE__ */ je(T.Provider, {
387
+ value: at,
388
+ children: f
272
389
  });
273
390
  };
274
391
  //#endregion
275
- export { O as OfflineSyncProvider, w as useOfflineSync };
392
+ export { P as OfflineSyncProvider, E as useOfflineSync };