@arbidocs/react 0.5.84 → 0.5.85
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/README.md +31 -0
- package/dist/index.cjs +1705 -148
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +264 -1
- package/dist/index.d.ts +264 -1
- package/dist/index.js +1688 -152
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -176,8 +176,8 @@ function useStartTaskQuery() {
|
|
|
176
176
|
};
|
|
177
177
|
const lookUpThread = async (messageId, attempts, known) => {
|
|
178
178
|
let conversationId;
|
|
179
|
-
for (let
|
|
180
|
-
if (
|
|
179
|
+
for (let attempt2 = 0; attempt2 < attempts && !conversationId; attempt2 += 1) {
|
|
180
|
+
if (attempt2 > 0) await new Promise((r) => setTimeout(r, THREAD_LOOKUP_DELAY_MS));
|
|
181
181
|
try {
|
|
182
182
|
conversationId = await threadOf(messageId, known);
|
|
183
183
|
} catch (error) {
|
|
@@ -1797,9 +1797,9 @@ function useWorkspaceProcessing(workspaceId) {
|
|
|
1797
1797
|
}, []);
|
|
1798
1798
|
React.useEffect(() => {
|
|
1799
1799
|
if (!workspaceId) return;
|
|
1800
|
-
const
|
|
1800
|
+
const store3 = chunkQ6U7ALNV_cjs.useArbiWsStore.getState();
|
|
1801
1801
|
const documents2 = chunkQ6U7ALNV_cjs.getCachedDocuments(queryClient, workspaceId) ?? [];
|
|
1802
|
-
|
|
1802
|
+
store3.settleTasks(documents2);
|
|
1803
1803
|
const listed = new Set(documents2.map((d) => d.external_id));
|
|
1804
1804
|
const now = Date.now();
|
|
1805
1805
|
for (const task of Object.values(chunkQ6U7ALNV_cjs.useArbiWsStore.getState().tasks)) {
|
|
@@ -1809,7 +1809,7 @@ function useWorkspaceProcessing(workspaceId) {
|
|
|
1809
1809
|
const age = since == null ? null : now - since;
|
|
1810
1810
|
const stale = age != null && age > STALE_TASK_MS;
|
|
1811
1811
|
const orphan = documents2.length > 0 && !listed.has(task.doc_ext_id) && age != null && age > ORPHAN_TASK_MS;
|
|
1812
|
-
if (stale || orphan)
|
|
1812
|
+
if (stale || orphan) store3.clearTask(task.doc_ext_id);
|
|
1813
1813
|
}
|
|
1814
1814
|
}, [workspaceId, queryClient]);
|
|
1815
1815
|
React.useEffect(() => {
|
|
@@ -1854,25 +1854,25 @@ function useWorkspaceProcessing(workspaceId) {
|
|
|
1854
1854
|
}, [workspaceId, snapshot]);
|
|
1855
1855
|
}
|
|
1856
1856
|
function applyOptimisticDocumentEdit(qc, updates) {
|
|
1857
|
-
const byId = new Map(updates.map((
|
|
1857
|
+
const byId = new Map(updates.map((update2) => [update2.external_id, update2]));
|
|
1858
1858
|
const previous = [];
|
|
1859
1859
|
chunkQ6U7ALNV_cjs.patchDocuments(qc, (old) => {
|
|
1860
1860
|
let changed = false;
|
|
1861
1861
|
const next = old.map((doc) => {
|
|
1862
|
-
const
|
|
1863
|
-
if (!
|
|
1862
|
+
const update2 = byId.get(doc.external_id);
|
|
1863
|
+
if (!update2) return doc;
|
|
1864
1864
|
changed = true;
|
|
1865
1865
|
previous.push(doc);
|
|
1866
|
-
return { ...doc, ...
|
|
1866
|
+
return { ...doc, ...update2 };
|
|
1867
1867
|
});
|
|
1868
1868
|
return changed ? next : old;
|
|
1869
1869
|
});
|
|
1870
|
-
const previousOwn = updates.map((
|
|
1870
|
+
const previousOwn = updates.map((update2) => {
|
|
1871
1871
|
const own = qc.getQueryData(
|
|
1872
|
-
chunkU4PWVSCT_cjs.arbiQueryKeys.document(
|
|
1872
|
+
chunkU4PWVSCT_cjs.arbiQueryKeys.document(update2.external_id)
|
|
1873
1873
|
);
|
|
1874
|
-
if (own) chunkQ6U7ALNV_cjs.setCachedDocument(qc, { ...own, ...
|
|
1875
|
-
return [
|
|
1874
|
+
if (own) chunkQ6U7ALNV_cjs.setCachedDocument(qc, { ...own, ...update2 });
|
|
1875
|
+
return [update2.external_id, own];
|
|
1876
1876
|
});
|
|
1877
1877
|
return { optimistic: true, previous, previousOwn };
|
|
1878
1878
|
}
|
|
@@ -2202,11 +2202,11 @@ function useUpdateDocTag() {
|
|
|
2202
2202
|
);
|
|
2203
2203
|
}
|
|
2204
2204
|
function queueProcessing(documents2) {
|
|
2205
|
-
const
|
|
2206
|
-
const previous = documents2.map(({ docId }) => [docId,
|
|
2205
|
+
const store3 = chunkQ6U7ALNV_cjs.useArbiWsStore.getState();
|
|
2206
|
+
const previous = documents2.map(({ docId }) => [docId, store3.tasks[docId]]);
|
|
2207
2207
|
const now = Date.now();
|
|
2208
2208
|
for (const doc of documents2)
|
|
2209
|
-
|
|
2209
|
+
store3.putTask({
|
|
2210
2210
|
doc_ext_id: doc.docId,
|
|
2211
2211
|
workspace_ext_id: doc.workspaceId,
|
|
2212
2212
|
file_name: doc.fileName,
|
|
@@ -3983,14 +3983,14 @@ function watchPendingDocIds(queryClient) {
|
|
|
3983
3983
|
if (watched.has(queryClient)) return;
|
|
3984
3984
|
watched.add(queryClient);
|
|
3985
3985
|
const cache = queryClient.getMutationCache();
|
|
3986
|
-
const
|
|
3986
|
+
const update2 = () => {
|
|
3987
3987
|
const ids = new Set(
|
|
3988
3988
|
cache.findAll({ predicate: PENDING_SYNC_PREDICATE }).flatMap((m) => docIdsFromVariables(kindOf(m.options.mutationKey), m.state.variables))
|
|
3989
3989
|
);
|
|
3990
3990
|
if (!sameSet(usePendingDocIds.getState().ids, ids)) usePendingDocIds.setState({ ids });
|
|
3991
3991
|
};
|
|
3992
|
-
|
|
3993
|
-
cache.subscribe(
|
|
3992
|
+
update2();
|
|
3993
|
+
cache.subscribe(update2);
|
|
3994
3994
|
}
|
|
3995
3995
|
function useDocumentPendingSync(docId) {
|
|
3996
3996
|
const queryClient = reactQuery.useQueryClient();
|
|
@@ -4029,23 +4029,23 @@ function promisify(request) {
|
|
|
4029
4029
|
request.onerror = () => reject(request.error);
|
|
4030
4030
|
});
|
|
4031
4031
|
}
|
|
4032
|
-
async function withStore(mode,
|
|
4032
|
+
async function withStore(mode, run2) {
|
|
4033
4033
|
const db = await openDB();
|
|
4034
|
-
const
|
|
4035
|
-
return promisify(
|
|
4034
|
+
const store3 = db.transaction(STORE, mode).objectStore(STORE);
|
|
4035
|
+
return promisify(run2(store3));
|
|
4036
4036
|
}
|
|
4037
4037
|
async function putOfflineDocument(record) {
|
|
4038
|
-
await withStore("readwrite", (
|
|
4038
|
+
await withStore("readwrite", (store3) => store3.put(record));
|
|
4039
4039
|
}
|
|
4040
4040
|
async function getOfflineDocument(docExtId) {
|
|
4041
|
-
const record = await withStore("readonly", (
|
|
4041
|
+
const record = await withStore("readonly", (store3) => store3.get(docExtId));
|
|
4042
4042
|
return record;
|
|
4043
4043
|
}
|
|
4044
4044
|
async function deleteOfflineDocument(docExtId) {
|
|
4045
|
-
await withStore("readwrite", (
|
|
4045
|
+
await withStore("readwrite", (store3) => store3.delete(docExtId));
|
|
4046
4046
|
}
|
|
4047
4047
|
async function listOfflineDocumentIds() {
|
|
4048
|
-
const keys = await withStore("readonly", (
|
|
4048
|
+
const keys = await withStore("readonly", (store3) => store3.getAllKeys());
|
|
4049
4049
|
return keys;
|
|
4050
4050
|
}
|
|
4051
4051
|
async function requestPersistentStorage() {
|
|
@@ -5420,7 +5420,7 @@ function useAttachRun(conversationId, responseId) {
|
|
|
5420
5420
|
if (!conversationId || !responseId) return;
|
|
5421
5421
|
let disposed = false;
|
|
5422
5422
|
let controller = new AbortController();
|
|
5423
|
-
let
|
|
5423
|
+
let retryTimer2;
|
|
5424
5424
|
let reconnects = 0;
|
|
5425
5425
|
const runStartedAt = session.getState().messageTimers[`${conversationId}:${responseId}`]?.startTime;
|
|
5426
5426
|
session.setConversationGenerating(conversationId, true, null);
|
|
@@ -5445,7 +5445,7 @@ function useAttachRun(conversationId, responseId) {
|
|
|
5445
5445
|
if (isMessageRunning(queryClient, conversationId, responseId) && reconnects < MAX_RECONNECTS) {
|
|
5446
5446
|
reconnects += 1;
|
|
5447
5447
|
markLoading();
|
|
5448
|
-
|
|
5448
|
+
retryTimer2 = setTimeout(connect, RECONNECT_DELAY_MS);
|
|
5449
5449
|
return;
|
|
5450
5450
|
}
|
|
5451
5451
|
settle(false);
|
|
@@ -5531,7 +5531,7 @@ function useAttachRun(conversationId, responseId) {
|
|
|
5531
5531
|
const stop = () => {
|
|
5532
5532
|
if (disposed) return;
|
|
5533
5533
|
disposed = true;
|
|
5534
|
-
clearTimeout(
|
|
5534
|
+
clearTimeout(retryTimer2);
|
|
5535
5535
|
window.removeEventListener("online", reconnectWhenOnline);
|
|
5536
5536
|
controller.abort();
|
|
5537
5537
|
settle(true);
|
|
@@ -5540,7 +5540,7 @@ function useAttachRun(conversationId, responseId) {
|
|
|
5540
5540
|
return () => {
|
|
5541
5541
|
unregister();
|
|
5542
5542
|
disposed = true;
|
|
5543
|
-
clearTimeout(
|
|
5543
|
+
clearTimeout(retryTimer2);
|
|
5544
5544
|
window.removeEventListener("online", reconnectWhenOnline);
|
|
5545
5545
|
controller.abort();
|
|
5546
5546
|
settle(false);
|
|
@@ -6342,20 +6342,20 @@ function useConversationSettings() {
|
|
|
6342
6342
|
React.useEffect(() => {
|
|
6343
6343
|
if (isFullConfig(activeConfig)) session.setChatModelName(resolveConfigModel(activeConfig));
|
|
6344
6344
|
}, [activeConfig, configToLoad]);
|
|
6345
|
-
const
|
|
6346
|
-
const pending =
|
|
6345
|
+
const update2 = useUpdateConversation();
|
|
6346
|
+
const pending = update2.isPending ? update2.variables?.patch : void 0;
|
|
6347
6347
|
const saveTitle = React.useCallback(() => {
|
|
6348
6348
|
const trimmed = title.trim();
|
|
6349
6349
|
if (!conversationId || !isOwner || !trimmed || trimmed.length > TITLE_MAX) return;
|
|
6350
6350
|
if (trimmed === conversation?.title) return;
|
|
6351
|
-
|
|
6352
|
-
}, [conversationId, isOwner, title, conversation?.title,
|
|
6351
|
+
update2.mutate({ conversationId, patch: { title: trimmed } });
|
|
6352
|
+
}, [conversationId, isOwner, title, conversation?.title, update2]);
|
|
6353
6353
|
const setShared = React.useCallback(
|
|
6354
6354
|
(shared) => {
|
|
6355
6355
|
if (!conversationId || !isOwner || isShared === shared) return;
|
|
6356
|
-
|
|
6356
|
+
update2.mutate({ conversationId, patch: { shared } });
|
|
6357
6357
|
},
|
|
6358
|
-
[conversationId, isOwner, isShared,
|
|
6358
|
+
[conversationId, isOwner, isShared, update2]
|
|
6359
6359
|
);
|
|
6360
6360
|
const share = React.useCallback(() => setShared(true), [setShared]);
|
|
6361
6361
|
const unshare = React.useCallback(() => setShared(false), [setShared]);
|
|
@@ -6783,7 +6783,7 @@ function useOnlineSync() {
|
|
|
6783
6783
|
reactQuery.onlineManager.setOnline(computeOnline(wsStatus, signedIn2, workOffline, wsEverConnected.current));
|
|
6784
6784
|
}, [wsStatus, signedIn2, workOffline]);
|
|
6785
6785
|
React.useEffect(() => {
|
|
6786
|
-
const
|
|
6786
|
+
const update2 = () => reactQuery.onlineManager.setOnline(
|
|
6787
6787
|
computeOnline(
|
|
6788
6788
|
chunkQ6U7ALNV_cjs.useArbiWsStore.getState().status,
|
|
6789
6789
|
signedInRef.current,
|
|
@@ -6791,11 +6791,11 @@ function useOnlineSync() {
|
|
|
6791
6791
|
wsEverConnected.current
|
|
6792
6792
|
)
|
|
6793
6793
|
);
|
|
6794
|
-
window.addEventListener("online",
|
|
6795
|
-
window.addEventListener("offline",
|
|
6794
|
+
window.addEventListener("online", update2);
|
|
6795
|
+
window.addEventListener("offline", update2);
|
|
6796
6796
|
return () => {
|
|
6797
|
-
window.removeEventListener("online",
|
|
6798
|
-
window.removeEventListener("offline",
|
|
6797
|
+
window.removeEventListener("online", update2);
|
|
6798
|
+
window.removeEventListener("offline", update2);
|
|
6799
6799
|
};
|
|
6800
6800
|
}, [session]);
|
|
6801
6801
|
}
|
|
@@ -6815,8 +6815,8 @@ function useReconnect() {
|
|
|
6815
6815
|
// src/websocket/reconnect.ts
|
|
6816
6816
|
var INITIAL_RECONNECT_DELAY_MS = 1e3;
|
|
6817
6817
|
var MAX_RECONNECT_DELAY_MS = 3e4;
|
|
6818
|
-
function nextReconnectDelay(
|
|
6819
|
-
return Math.min(INITIAL_RECONNECT_DELAY_MS * 2 ** Math.max(0,
|
|
6818
|
+
function nextReconnectDelay(attempt2) {
|
|
6819
|
+
return Math.min(INITIAL_RECONNECT_DELAY_MS * 2 ** Math.max(0, attempt2), MAX_RECONNECT_DELAY_MS);
|
|
6820
6820
|
}
|
|
6821
6821
|
function resolveSocketBaseUrl(configured, origin) {
|
|
6822
6822
|
return /^https?:\/\//.test(configured) || !origin ? configured : origin;
|
|
@@ -7101,13 +7101,13 @@ function useUpdateMailMessage() {
|
|
|
7101
7101
|
mutationFn: ({
|
|
7102
7102
|
accountId,
|
|
7103
7103
|
messageId,
|
|
7104
|
-
update
|
|
7104
|
+
update: update2
|
|
7105
7105
|
}) => mailJson(
|
|
7106
7106
|
client.fetch,
|
|
7107
7107
|
`${accountPath(accountId)}/messages/${encodeURIComponent(messageId)}`,
|
|
7108
7108
|
{
|
|
7109
7109
|
method: "PATCH",
|
|
7110
|
-
body: JSON.stringify(
|
|
7110
|
+
body: JSON.stringify(update2)
|
|
7111
7111
|
}
|
|
7112
7112
|
)
|
|
7113
7113
|
});
|
|
@@ -7429,15 +7429,15 @@ function ArbiWebSocketProvider({
|
|
|
7429
7429
|
}
|
|
7430
7430
|
}
|
|
7431
7431
|
};
|
|
7432
|
-
let
|
|
7433
|
-
let
|
|
7432
|
+
let retryTimer2 = null;
|
|
7433
|
+
let attempt2 = 0;
|
|
7434
7434
|
const scheduleRestart = () => {
|
|
7435
|
-
if (cancelled || evicted ||
|
|
7435
|
+
if (cancelled || evicted || retryTimer2) return;
|
|
7436
7436
|
setStatus("disconnected");
|
|
7437
|
-
const delay = nextReconnectDelay(
|
|
7438
|
-
|
|
7439
|
-
|
|
7440
|
-
|
|
7437
|
+
const delay = nextReconnectDelay(attempt2);
|
|
7438
|
+
attempt2 += 1;
|
|
7439
|
+
retryTimer2 = setTimeout(() => {
|
|
7440
|
+
retryTimer2 = null;
|
|
7441
7441
|
void start();
|
|
7442
7442
|
}, delay);
|
|
7443
7443
|
};
|
|
@@ -7468,7 +7468,7 @@ function ArbiWebSocketProvider({
|
|
|
7468
7468
|
onMessage,
|
|
7469
7469
|
onReconnecting: () => setStatus("reconnecting"),
|
|
7470
7470
|
onReconnected: () => {
|
|
7471
|
-
|
|
7471
|
+
attempt2 = 0;
|
|
7472
7472
|
setStatus("connected");
|
|
7473
7473
|
},
|
|
7474
7474
|
// Evicted (a newer session of the same user, or the server took this connection over for a
|
|
@@ -7490,7 +7490,7 @@ function ArbiWebSocketProvider({
|
|
|
7490
7490
|
return;
|
|
7491
7491
|
}
|
|
7492
7492
|
conn = c;
|
|
7493
|
-
|
|
7493
|
+
attempt2 = 0;
|
|
7494
7494
|
setStatus("connected");
|
|
7495
7495
|
} catch {
|
|
7496
7496
|
if (!info.signal.aborted) scheduleRestart();
|
|
@@ -7500,7 +7500,7 @@ function ArbiWebSocketProvider({
|
|
|
7500
7500
|
void start();
|
|
7501
7501
|
return () => {
|
|
7502
7502
|
cancelled = true;
|
|
7503
|
-
if (
|
|
7503
|
+
if (retryTimer2) clearTimeout(retryTimer2);
|
|
7504
7504
|
conn?.close();
|
|
7505
7505
|
reset();
|
|
7506
7506
|
};
|
|
@@ -7575,10 +7575,10 @@ function createWorkspaceSwitch({
|
|
|
7575
7575
|
queryClient
|
|
7576
7576
|
}) {
|
|
7577
7577
|
const switchWorkspace = (target) => {
|
|
7578
|
-
const
|
|
7579
|
-
switching.add(
|
|
7580
|
-
void
|
|
7581
|
-
return
|
|
7578
|
+
const run2 = runSwitch(target);
|
|
7579
|
+
switching.add(run2);
|
|
7580
|
+
void run2.finally(() => switching.delete(run2));
|
|
7581
|
+
return run2;
|
|
7582
7582
|
};
|
|
7583
7583
|
const runSwitch = async (target) => {
|
|
7584
7584
|
const { workspaceId: previousId, workspaceStatus } = session.getState();
|
|
@@ -8245,7 +8245,7 @@ function useFactsSearch(options = {}) {
|
|
|
8245
8245
|
const workspaceId = options.workspaceId ?? (arbi.hasWorkspace ? arbi.getWorkspaceId() : null);
|
|
8246
8246
|
const [kept, setKept] = chunk2Y2WOIHH_cjs.useTransientView(FACTS_SEARCH_VIEW, EMPTY2);
|
|
8247
8247
|
const searchFacts = useSearchFacts(workspaceId);
|
|
8248
|
-
const
|
|
8248
|
+
const run2 = React.useRef(0);
|
|
8249
8249
|
const foreign = !!kept.workspaceId && !!workspaceId && kept.workspaceId !== workspaceId;
|
|
8250
8250
|
const state = foreign ? EMPTY2 : kept;
|
|
8251
8251
|
const patch = React.useCallback(
|
|
@@ -8260,18 +8260,18 @@ function useFactsSearch(options = {}) {
|
|
|
8260
8260
|
const search = React.useCallback(async () => {
|
|
8261
8261
|
const q = query.trim();
|
|
8262
8262
|
if (!q) return;
|
|
8263
|
-
const mine = ++
|
|
8263
|
+
const mine = ++run2.current;
|
|
8264
8264
|
try {
|
|
8265
8265
|
const res = await searchFacts.mutateAsync({ query: q, search_mode: mode, limit });
|
|
8266
|
-
if (
|
|
8266
|
+
if (run2.current !== mine) return;
|
|
8267
8267
|
patch({ hits: res.facts, lastQuery: q });
|
|
8268
8268
|
} catch (error) {
|
|
8269
|
-
if (
|
|
8269
|
+
if (run2.current !== mine) return;
|
|
8270
8270
|
throw error;
|
|
8271
8271
|
}
|
|
8272
8272
|
}, [query, searchFacts, mode, limit, patch]);
|
|
8273
8273
|
const clear = React.useCallback(() => {
|
|
8274
|
-
|
|
8274
|
+
run2.current++;
|
|
8275
8275
|
patch({ query: "", hits: null });
|
|
8276
8276
|
}, [patch]);
|
|
8277
8277
|
return {
|
|
@@ -8489,26 +8489,26 @@ var DEFAULT_LIMIT = 50;
|
|
|
8489
8489
|
var pad = (n) => String(n).padStart(2, "0");
|
|
8490
8490
|
function asDay(value) {
|
|
8491
8491
|
if (typeof value !== "string" || value.length < 10) return null;
|
|
8492
|
-
const
|
|
8493
|
-
return Number.isNaN(
|
|
8492
|
+
const day2 = /* @__PURE__ */ new Date(`${value.slice(0, 10)}T00:00:00Z`);
|
|
8493
|
+
return Number.isNaN(day2.getTime()) ? null : day2;
|
|
8494
8494
|
}
|
|
8495
|
-
function isoWeek(
|
|
8496
|
-
const d = new Date(
|
|
8495
|
+
function isoWeek(day2) {
|
|
8496
|
+
const d = new Date(day2);
|
|
8497
8497
|
const weekday = d.getUTCDay() || 7;
|
|
8498
8498
|
d.setUTCDate(d.getUTCDate() + 4 - weekday);
|
|
8499
8499
|
const yearStart = Date.UTC(d.getUTCFullYear(), 0, 1);
|
|
8500
8500
|
return [d.getUTCFullYear(), Math.ceil(((d.getTime() - yearStart) / 864e5 + 1) / 7)];
|
|
8501
8501
|
}
|
|
8502
|
-
function bucketOf(value,
|
|
8503
|
-
const
|
|
8504
|
-
if (!
|
|
8505
|
-
const y =
|
|
8506
|
-
const m =
|
|
8507
|
-
switch (
|
|
8502
|
+
function bucketOf(value, bucket2) {
|
|
8503
|
+
const day2 = asDay(value);
|
|
8504
|
+
if (!day2) return null;
|
|
8505
|
+
const y = day2.getUTCFullYear();
|
|
8506
|
+
const m = day2.getUTCMonth() + 1;
|
|
8507
|
+
switch (bucket2) {
|
|
8508
8508
|
case "day":
|
|
8509
|
-
return `${y}-${pad(m)}-${pad(
|
|
8509
|
+
return `${y}-${pad(m)}-${pad(day2.getUTCDate())}`;
|
|
8510
8510
|
case "week": {
|
|
8511
|
-
const [wy, w] = isoWeek(
|
|
8511
|
+
const [wy, w] = isoWeek(day2);
|
|
8512
8512
|
return `${wy}-W${pad(w)}`;
|
|
8513
8513
|
}
|
|
8514
8514
|
case "quarter":
|
|
@@ -8519,12 +8519,12 @@ function bucketOf(value, bucket) {
|
|
|
8519
8519
|
return `${y}-${pad(m)}`;
|
|
8520
8520
|
}
|
|
8521
8521
|
}
|
|
8522
|
-
function bucketStart(key,
|
|
8522
|
+
function bucketStart(key, bucket2) {
|
|
8523
8523
|
const parts = key.match(/^(\d{4})(?:-(W|Q)?(\d{1,2}))?(?:-(\d{2}))?$/);
|
|
8524
8524
|
if (!parts) return null;
|
|
8525
8525
|
const year = Number(parts[1]);
|
|
8526
8526
|
const n = Number(parts[3] ?? 1);
|
|
8527
|
-
switch (
|
|
8527
|
+
switch (bucket2) {
|
|
8528
8528
|
case "day":
|
|
8529
8529
|
return asDay(key);
|
|
8530
8530
|
case "week": {
|
|
@@ -8541,32 +8541,32 @@ function bucketStart(key, bucket) {
|
|
|
8541
8541
|
return new Date(Date.UTC(year, n - 1, 1));
|
|
8542
8542
|
}
|
|
8543
8543
|
}
|
|
8544
|
-
function nextBucket(
|
|
8545
|
-
const d = new Date(
|
|
8546
|
-
if (
|
|
8547
|
-
else if (
|
|
8548
|
-
else if (
|
|
8549
|
-
else if (
|
|
8544
|
+
function nextBucket(day2, bucket2) {
|
|
8545
|
+
const d = new Date(day2);
|
|
8546
|
+
if (bucket2 === "day") d.setUTCDate(d.getUTCDate() + 1);
|
|
8547
|
+
else if (bucket2 === "week") d.setUTCDate(d.getUTCDate() + 7);
|
|
8548
|
+
else if (bucket2 === "month") d.setUTCMonth(d.getUTCMonth() + 1);
|
|
8549
|
+
else if (bucket2 === "quarter") d.setUTCMonth(d.getUTCMonth() + 3);
|
|
8550
8550
|
else d.setUTCFullYear(d.getUTCFullYear() + 1);
|
|
8551
8551
|
return d;
|
|
8552
8552
|
}
|
|
8553
|
-
function bucketRange(first, last,
|
|
8554
|
-
const start = bucketStart(first,
|
|
8555
|
-
const end = bucketStart(last,
|
|
8553
|
+
function bucketRange(first, last, bucket2, max = 500) {
|
|
8554
|
+
const start = bucketStart(first, bucket2);
|
|
8555
|
+
const end = bucketStart(last, bucket2);
|
|
8556
8556
|
if (!start || !end || start > end) return null;
|
|
8557
8557
|
const keys = [];
|
|
8558
|
-
for (let d = start; d <= end && keys.length <= max; d = nextBucket(d,
|
|
8559
|
-
keys.push(bucketOf(d.toISOString(),
|
|
8558
|
+
for (let d = start; d <= end && keys.length <= max; d = nextBucket(d, bucket2)) {
|
|
8559
|
+
keys.push(bucketOf(d.toISOString(), bucket2));
|
|
8560
8560
|
}
|
|
8561
8561
|
return keys.length > max ? null : keys;
|
|
8562
8562
|
}
|
|
8563
8563
|
var isEmpty = (value) => value === null || value === void 0 || value === "" || Array.isArray(value) && !value.length;
|
|
8564
|
-
function groupKeys(value, field,
|
|
8564
|
+
function groupKeys(value, field, bucket2) {
|
|
8565
8565
|
if (isEmpty(value)) return [""];
|
|
8566
8566
|
if (Array.isArray(value)) {
|
|
8567
|
-
return [...new Set(value.map((v) => groupKeys(v, field,
|
|
8567
|
+
return [...new Set(value.map((v) => groupKeys(v, field, bucket2)[0]))];
|
|
8568
8568
|
}
|
|
8569
|
-
if (field.type === "date") return [bucketOf(value,
|
|
8569
|
+
if (field.type === "date") return [bucketOf(value, bucket2) ?? ""];
|
|
8570
8570
|
if (typeof value === "boolean") return [value ? "Yes" : "No"];
|
|
8571
8571
|
return [String(value)];
|
|
8572
8572
|
}
|
|
@@ -8661,7 +8661,7 @@ function aggregateDataset(dataset, query) {
|
|
|
8661
8661
|
const split = query.splitBy ? byId.get(query.splitBy) : void 0;
|
|
8662
8662
|
const op = query.measure?.op ?? "count";
|
|
8663
8663
|
const valueField = query.measure?.field ? byId.get(query.measure.field) : void 0;
|
|
8664
|
-
const
|
|
8664
|
+
const bucket2 = query.bucket ?? "month";
|
|
8665
8665
|
const fields = aggregateFields(dataset.fields, query);
|
|
8666
8666
|
if (op !== "count" && valueField?.type !== "number") {
|
|
8667
8667
|
throw new Error(`${op} needs a number field`);
|
|
@@ -8669,8 +8669,8 @@ function aggregateDataset(dataset, query) {
|
|
|
8669
8669
|
const rows = filterRows(dataset.rows, dataset.fields, query.filters);
|
|
8670
8670
|
const cells = /* @__PURE__ */ new Map();
|
|
8671
8671
|
for (const row of rows) {
|
|
8672
|
-
const groups = group ? groupKeys(row[group.id], group,
|
|
8673
|
-
const splits = split ? groupKeys(row[split.id], split,
|
|
8672
|
+
const groups = group ? groupKeys(row[group.id], group, bucket2) : ["All"];
|
|
8673
|
+
const splits = split ? groupKeys(row[split.id], split, bucket2) : [""];
|
|
8674
8674
|
const value = valueField ? row[valueField.id] ?? null : 1;
|
|
8675
8675
|
for (const g of groups) {
|
|
8676
8676
|
const bySplit = cells.get(g) ?? /* @__PURE__ */ new Map();
|
|
@@ -8716,12 +8716,12 @@ function aggregateDataset(dataset, query) {
|
|
|
8716
8716
|
}
|
|
8717
8717
|
return { fields, rows: out, totalRows: rows.length, truncated: keys.length > limit };
|
|
8718
8718
|
}
|
|
8719
|
-
function fillTimeGaps(dataset,
|
|
8719
|
+
function fillTimeGaps(dataset, bucket2) {
|
|
8720
8720
|
const keyId = AGGREGATE_FIELDS.key;
|
|
8721
8721
|
const keys = [...new Set(dataset.rows.map((r) => String(r[keyId] ?? "")))].filter(Boolean);
|
|
8722
8722
|
if (keys.length < 2) return dataset;
|
|
8723
8723
|
const sorted = [...keys].sort();
|
|
8724
|
-
const range = bucketRange(sorted[0], sorted[sorted.length - 1],
|
|
8724
|
+
const range = bucketRange(sorted[0], sorted[sorted.length - 1], bucket2);
|
|
8725
8725
|
if (!range || range.length === keys.length) return dataset;
|
|
8726
8726
|
const hasSeries = dataset.fields.some((f) => f.id === AGGREGATE_FIELDS.series);
|
|
8727
8727
|
const seriesLabels = hasSeries ? [...new Set(dataset.rows.map((r) => String(r[AGGREGATE_FIELDS.series])))] : [null];
|
|
@@ -9263,8 +9263,8 @@ var DEFAULT_USAGE_SOURCE_LABELS = {
|
|
|
9263
9263
|
var monthsBackOf = (params) => String(params.period ?? "0") === "1" ? 1 : 0;
|
|
9264
9264
|
function usageRows(usage, project, modelLabel = (g) => MODEL_GROUP_LABELS[g] ?? g) {
|
|
9265
9265
|
return (usage.daily ?? []).flatMap(
|
|
9266
|
-
(
|
|
9267
|
-
day:
|
|
9266
|
+
(day2) => Object.entries(day2.model_groups ?? {}).map(([group, mg]) => ({
|
|
9267
|
+
day: day2.date,
|
|
9268
9268
|
project,
|
|
9269
9269
|
model: modelLabel(group),
|
|
9270
9270
|
spend: mg.spend ?? 0,
|
|
@@ -9528,18 +9528,18 @@ function useDashboardStore() {
|
|
|
9528
9528
|
const { dashboards } = chunkVGMMK5OM_cjs.useArbiHost();
|
|
9529
9529
|
return (dashboards?.useStore ?? useDatabaseDashboardStore)();
|
|
9530
9530
|
}
|
|
9531
|
-
function useSavedDashboards(
|
|
9531
|
+
function useSavedDashboards(store3) {
|
|
9532
9532
|
return reactQuery.useQuery({
|
|
9533
|
-
queryKey: chunkU4PWVSCT_cjs.arbiQueryKeys.dashboards(
|
|
9534
|
-
queryFn: () =>
|
|
9535
|
-
enabled:
|
|
9533
|
+
queryKey: chunkU4PWVSCT_cjs.arbiQueryKeys.dashboards(store3.scope ?? ""),
|
|
9534
|
+
queryFn: () => store3.list(),
|
|
9535
|
+
enabled: store3.scope !== null
|
|
9536
9536
|
});
|
|
9537
9537
|
}
|
|
9538
|
-
function useSaveDashboard(
|
|
9538
|
+
function useSaveDashboard(store3) {
|
|
9539
9539
|
const queryClient = reactQuery.useQueryClient();
|
|
9540
|
-
const key = chunkU4PWVSCT_cjs.arbiQueryKeys.dashboards(
|
|
9540
|
+
const key = chunkU4PWVSCT_cjs.arbiQueryKeys.dashboards(store3.scope ?? "");
|
|
9541
9541
|
return reactQuery.useMutation({
|
|
9542
|
-
mutationFn: (dashboard) =>
|
|
9542
|
+
mutationFn: (dashboard) => store3.save(dashboard),
|
|
9543
9543
|
onSuccess: (saved) => {
|
|
9544
9544
|
queryClient.setQueryData(
|
|
9545
9545
|
key,
|
|
@@ -9549,11 +9549,11 @@ function useSaveDashboard(store) {
|
|
|
9549
9549
|
}
|
|
9550
9550
|
});
|
|
9551
9551
|
}
|
|
9552
|
-
function useDeleteDashboard(
|
|
9552
|
+
function useDeleteDashboard(store3) {
|
|
9553
9553
|
const queryClient = reactQuery.useQueryClient();
|
|
9554
|
-
const key = chunkU4PWVSCT_cjs.arbiQueryKeys.dashboards(
|
|
9554
|
+
const key = chunkU4PWVSCT_cjs.arbiQueryKeys.dashboards(store3.scope ?? "");
|
|
9555
9555
|
return reactQuery.useMutation({
|
|
9556
|
-
mutationFn: (id) =>
|
|
9556
|
+
mutationFn: (id) => store3.remove(id),
|
|
9557
9557
|
onSuccess: (_void, id) => {
|
|
9558
9558
|
queryClient.setQueryData(key, (old = []) => old.filter((d) => d.id !== id));
|
|
9559
9559
|
void queryClient.invalidateQueries({ queryKey: chunkU4PWVSCT_cjs.arbiQueryKeys.databaseRows() });
|
|
@@ -9656,8 +9656,8 @@ function isClientError(error) {
|
|
|
9656
9656
|
}
|
|
9657
9657
|
return false;
|
|
9658
9658
|
}
|
|
9659
|
-
function retryDelay(
|
|
9660
|
-
return Math.min(1e3 * 2 **
|
|
9659
|
+
function retryDelay(attempt2) {
|
|
9660
|
+
return Math.min(1e3 * 2 ** attempt2, 3e4) + Math.random() * 500;
|
|
9661
9661
|
}
|
|
9662
9662
|
function shouldRetryQuery(failureCount, error) {
|
|
9663
9663
|
return failureCount < 2 && !isClientError(error) && !client.isAbortError(error);
|
|
@@ -9698,6 +9698,14 @@ function createArbiQueryClient({
|
|
|
9698
9698
|
});
|
|
9699
9699
|
return { queryClient, persistOptions: persist ? createArbiQueryPersistOptions() : null };
|
|
9700
9700
|
}
|
|
9701
|
+
|
|
9702
|
+
// src/offline-store/network.ts
|
|
9703
|
+
function isNetworkFailure(error) {
|
|
9704
|
+
return error instanceof TypeError && /fetch|network|load failed|internet/i.test(error.message);
|
|
9705
|
+
}
|
|
9706
|
+
function isBrowserOffline() {
|
|
9707
|
+
return typeof navigator !== "undefined" && navigator.onLine === false;
|
|
9708
|
+
}
|
|
9701
9709
|
function useFilteredProjects(filters, options) {
|
|
9702
9710
|
const arbi = chunkVGMMK5OM_cjs.useArbi();
|
|
9703
9711
|
return reactQuery.useQuery({
|
|
@@ -10915,7 +10923,7 @@ function useIdentityVerificationFlow(api, {
|
|
|
10915
10923
|
React.useEffect(() => {
|
|
10916
10924
|
if (status && lastVerified.current === void 0) lastVerified.current = status.verified;
|
|
10917
10925
|
}, [status]);
|
|
10918
|
-
const
|
|
10926
|
+
const run2 = React.useCallback(
|
|
10919
10927
|
async (kind, fallback, fn) => {
|
|
10920
10928
|
setBusy(kind);
|
|
10921
10929
|
setProblem(null);
|
|
@@ -10936,7 +10944,7 @@ function useIdentityVerificationFlow(api, {
|
|
|
10936
10944
|
const startVerifyRef = React.useRef(async () => {
|
|
10937
10945
|
});
|
|
10938
10946
|
const refresh = React.useCallback(async () => {
|
|
10939
|
-
const next = await
|
|
10947
|
+
const next = await run2(
|
|
10940
10948
|
"refresh",
|
|
10941
10949
|
"Could not read the verification result",
|
|
10942
10950
|
() => apiRef.current.refresh()
|
|
@@ -10948,7 +10956,7 @@ function useIdentityVerificationFlow(api, {
|
|
|
10948
10956
|
const nextStep = next.state === "declined" ? "result" : identityStepFor(next);
|
|
10949
10957
|
if (nextStep === "verify" && isOpenRef.current) void startVerifyRef.current();
|
|
10950
10958
|
else setStep(nextStep);
|
|
10951
|
-
}, [
|
|
10959
|
+
}, [run2, apply]);
|
|
10952
10960
|
const refreshedOnLoad = React.useRef(false);
|
|
10953
10961
|
React.useEffect(() => {
|
|
10954
10962
|
if (refreshedOnLoad.current || !status) return;
|
|
@@ -10958,7 +10966,7 @@ function useIdentityVerificationFlow(api, {
|
|
|
10958
10966
|
const startVerify = React.useCallback(async () => {
|
|
10959
10967
|
setStep("verify");
|
|
10960
10968
|
setEmbedFailed(false);
|
|
10961
|
-
const url = await
|
|
10969
|
+
const url = await run2(
|
|
10962
10970
|
"start",
|
|
10963
10971
|
"Could not start identity verification",
|
|
10964
10972
|
() => apiRef.current.startSession()
|
|
@@ -10968,7 +10976,7 @@ function useIdentityVerificationFlow(api, {
|
|
|
10968
10976
|
return;
|
|
10969
10977
|
}
|
|
10970
10978
|
setStep("pay");
|
|
10971
|
-
}, [
|
|
10979
|
+
}, [run2]);
|
|
10972
10980
|
startVerifyRef.current = startVerify;
|
|
10973
10981
|
React.useEffect(() => {
|
|
10974
10982
|
if (!isOpen || step !== "verify" || !sessionUrl || !container || embedFailed) return;
|
|
@@ -11023,7 +11031,7 @@ function useIdentityVerificationFlow(api, {
|
|
|
11023
11031
|
}, []);
|
|
11024
11032
|
closeRef.current = close;
|
|
11025
11033
|
const pay = React.useCallback(async () => {
|
|
11026
|
-
const result = await
|
|
11034
|
+
const result = await run2(
|
|
11027
11035
|
"pay",
|
|
11028
11036
|
"Payment could not be completed",
|
|
11029
11037
|
() => apiRef.current.purchase()
|
|
@@ -11036,10 +11044,10 @@ function useIdentityVerificationFlow(api, {
|
|
|
11036
11044
|
setPaymentUrl(null);
|
|
11037
11045
|
void query.refetch();
|
|
11038
11046
|
void startVerify();
|
|
11039
|
-
}, [
|
|
11047
|
+
}, [run2, query, startVerify]);
|
|
11040
11048
|
const acceptName = React.useCallback(async () => {
|
|
11041
11049
|
const offered = status;
|
|
11042
|
-
const next = await
|
|
11050
|
+
const next = await run2(
|
|
11043
11051
|
"accept",
|
|
11044
11052
|
"Could not change your name",
|
|
11045
11053
|
() => apiRef.current.acceptName()
|
|
@@ -11052,15 +11060,15 @@ function useIdentityVerificationFlow(api, {
|
|
|
11052
11060
|
familyName: offered.document_family_name ?? null
|
|
11053
11061
|
});
|
|
11054
11062
|
}
|
|
11055
|
-
}, [
|
|
11063
|
+
}, [run2, apply, status, onNameAccepted]);
|
|
11056
11064
|
const remove = React.useCallback(async () => {
|
|
11057
|
-
const next = await
|
|
11065
|
+
const next = await run2(
|
|
11058
11066
|
"remove",
|
|
11059
11067
|
"Could not remove the verification",
|
|
11060
11068
|
() => apiRef.current.remove()
|
|
11061
11069
|
);
|
|
11062
11070
|
if (next) apply(next);
|
|
11063
|
-
}, [
|
|
11071
|
+
}, [run2, apply]);
|
|
11064
11072
|
const price = React.useMemo(() => status ? formatPrice(status) : null, [status, formatPrice]);
|
|
11065
11073
|
return {
|
|
11066
11074
|
status,
|
|
@@ -11115,6 +11123,1191 @@ async function downloadRecoveryFile(params) {
|
|
|
11115
11123
|
});
|
|
11116
11124
|
chunkTAVS54EN_cjs.downloadBlob(new Blob([file.html], { type: "text/html" }), file.filename);
|
|
11117
11125
|
}
|
|
11126
|
+
var OfflineMailLockedError = class extends Error {
|
|
11127
|
+
constructor() {
|
|
11128
|
+
super("Sign in to open the mail saved on this device");
|
|
11129
|
+
this.name = "OfflineMailLockedError";
|
|
11130
|
+
}
|
|
11131
|
+
};
|
|
11132
|
+
var sealer = client.createOfflineSealer("arbi-offline-mail-v1", {
|
|
11133
|
+
locked: () => new OfflineMailLockedError()
|
|
11134
|
+
});
|
|
11135
|
+
var forgetOfflineMailKeys = sealer.forget;
|
|
11136
|
+
var sealBytes = sealer.sealBytes;
|
|
11137
|
+
var openBytes = sealer.openBytes;
|
|
11138
|
+
var sealJson = sealer.sealJson;
|
|
11139
|
+
var openJson = sealer.openJson;
|
|
11140
|
+
var blind = sealer.blind;
|
|
11141
|
+
|
|
11142
|
+
// src/offline-store/store.ts
|
|
11143
|
+
var DB_VERSION2 = 1;
|
|
11144
|
+
var RECORDS = "records";
|
|
11145
|
+
var META = "meta";
|
|
11146
|
+
function promisify2(request) {
|
|
11147
|
+
return new Promise((resolve, reject) => {
|
|
11148
|
+
request.onsuccess = () => resolve(request.result);
|
|
11149
|
+
request.onerror = () => reject(request.error);
|
|
11150
|
+
});
|
|
11151
|
+
}
|
|
11152
|
+
function createRecordStore(dbName) {
|
|
11153
|
+
let dbPromise = null;
|
|
11154
|
+
function openDB2() {
|
|
11155
|
+
if (dbPromise) return dbPromise;
|
|
11156
|
+
dbPromise = new Promise((resolve, reject) => {
|
|
11157
|
+
const request = indexedDB.open(dbName, DB_VERSION2);
|
|
11158
|
+
request.onerror = () => {
|
|
11159
|
+
dbPromise = null;
|
|
11160
|
+
reject(request.error);
|
|
11161
|
+
};
|
|
11162
|
+
request.onsuccess = () => {
|
|
11163
|
+
const db = request.result;
|
|
11164
|
+
db.onversionchange = () => {
|
|
11165
|
+
db.close();
|
|
11166
|
+
dbPromise = null;
|
|
11167
|
+
};
|
|
11168
|
+
resolve(db);
|
|
11169
|
+
};
|
|
11170
|
+
request.onupgradeneeded = () => {
|
|
11171
|
+
const db = request.result;
|
|
11172
|
+
if (!db.objectStoreNames.contains(RECORDS)) {
|
|
11173
|
+
const records = db.createObjectStore(RECORDS, { keyPath: "key" });
|
|
11174
|
+
records.createIndex("bucket", "bucket");
|
|
11175
|
+
records.createIndex("kind", "kind");
|
|
11176
|
+
}
|
|
11177
|
+
if (!db.objectStoreNames.contains(META)) db.createObjectStore(META, { keyPath: "key" });
|
|
11178
|
+
};
|
|
11179
|
+
});
|
|
11180
|
+
return dbPromise;
|
|
11181
|
+
}
|
|
11182
|
+
async function run2(store3, mode, fn) {
|
|
11183
|
+
const db = await openDB2();
|
|
11184
|
+
return promisify2(fn(db.transaction(store3, mode).objectStore(store3)));
|
|
11185
|
+
}
|
|
11186
|
+
async function scan(pick) {
|
|
11187
|
+
const db = await openDB2();
|
|
11188
|
+
const store3 = db.transaction(RECORDS, "readonly").objectStore(RECORDS);
|
|
11189
|
+
return new Promise((resolve, reject) => {
|
|
11190
|
+
const out = [];
|
|
11191
|
+
const cursor = store3.openCursor();
|
|
11192
|
+
cursor.onerror = () => reject(cursor.error);
|
|
11193
|
+
cursor.onsuccess = () => {
|
|
11194
|
+
const c = cursor.result;
|
|
11195
|
+
if (!c) return resolve(out);
|
|
11196
|
+
out.push(pick(c.value));
|
|
11197
|
+
c.continue();
|
|
11198
|
+
};
|
|
11199
|
+
});
|
|
11200
|
+
}
|
|
11201
|
+
const self = {
|
|
11202
|
+
dbName,
|
|
11203
|
+
async putRecord(record) {
|
|
11204
|
+
await run2(RECORDS, "readwrite", (s) => s.put(record));
|
|
11205
|
+
},
|
|
11206
|
+
async getRecord(key) {
|
|
11207
|
+
return await run2(RECORDS, "readonly", (s) => s.get(key));
|
|
11208
|
+
},
|
|
11209
|
+
async hasRecord(key) {
|
|
11210
|
+
return await run2(RECORDS, "readonly", (s) => s.count(key)) > 0;
|
|
11211
|
+
},
|
|
11212
|
+
async deleteRecords(keys) {
|
|
11213
|
+
if (keys.length === 0) return;
|
|
11214
|
+
const db = await openDB2();
|
|
11215
|
+
const tx = db.transaction(RECORDS, "readwrite");
|
|
11216
|
+
const store3 = tx.objectStore(RECORDS);
|
|
11217
|
+
for (const key of keys) store3.delete(key);
|
|
11218
|
+
await new Promise((resolve, reject) => {
|
|
11219
|
+
tx.oncomplete = () => resolve();
|
|
11220
|
+
tx.onerror = () => reject(tx.error);
|
|
11221
|
+
tx.onabort = () => reject(tx.error);
|
|
11222
|
+
});
|
|
11223
|
+
},
|
|
11224
|
+
async recordsInBucket(bucket2) {
|
|
11225
|
+
return await run2(
|
|
11226
|
+
RECORDS,
|
|
11227
|
+
"readonly",
|
|
11228
|
+
(s) => s.index("bucket").getAll(bucket2)
|
|
11229
|
+
);
|
|
11230
|
+
},
|
|
11231
|
+
async recordsOfKind(kind) {
|
|
11232
|
+
return await run2(
|
|
11233
|
+
RECORDS,
|
|
11234
|
+
"readonly",
|
|
11235
|
+
(s) => s.index("kind").getAll(kind)
|
|
11236
|
+
);
|
|
11237
|
+
},
|
|
11238
|
+
allRecordSizes() {
|
|
11239
|
+
return scan(({ key, kind, size }) => ({ key, kind, size }));
|
|
11240
|
+
},
|
|
11241
|
+
allRecordAccess() {
|
|
11242
|
+
return scan(({ key, kind, lastAccess }) => ({ key, kind, lastAccess }));
|
|
11243
|
+
},
|
|
11244
|
+
async touchRecord(key) {
|
|
11245
|
+
const record = await self.getRecord(key);
|
|
11246
|
+
if (record) await self.putRecord({ ...record, lastAccess: Date.now() });
|
|
11247
|
+
},
|
|
11248
|
+
async getMeta(key) {
|
|
11249
|
+
const row = await run2(META, "readonly", (s) => s.get(key));
|
|
11250
|
+
return row?.value;
|
|
11251
|
+
},
|
|
11252
|
+
async setMeta(key, value) {
|
|
11253
|
+
await run2(META, "readwrite", (s) => s.put({ key, value }));
|
|
11254
|
+
},
|
|
11255
|
+
async deleteDatabase() {
|
|
11256
|
+
const db = await dbPromise?.catch(() => null);
|
|
11257
|
+
db?.close();
|
|
11258
|
+
dbPromise = null;
|
|
11259
|
+
await new Promise((resolve, reject) => {
|
|
11260
|
+
const request = indexedDB.deleteDatabase(dbName);
|
|
11261
|
+
request.onsuccess = () => resolve();
|
|
11262
|
+
request.onerror = () => reject(request.error);
|
|
11263
|
+
request.onblocked = () => {
|
|
11264
|
+
};
|
|
11265
|
+
});
|
|
11266
|
+
}
|
|
11267
|
+
};
|
|
11268
|
+
return self;
|
|
11269
|
+
}
|
|
11270
|
+
|
|
11271
|
+
// src/mail/offline/store.ts
|
|
11272
|
+
var OFFLINE_MAIL_DB = "arbi-offline-mail";
|
|
11273
|
+
var store = createRecordStore(OFFLINE_MAIL_DB);
|
|
11274
|
+
var putRecord = store.putRecord;
|
|
11275
|
+
var getRecord = store.getRecord;
|
|
11276
|
+
var hasRecord = store.hasRecord;
|
|
11277
|
+
var deleteRecords = store.deleteRecords;
|
|
11278
|
+
var recordsInBucket = store.recordsInBucket;
|
|
11279
|
+
var recordsOfKind = store.recordsOfKind;
|
|
11280
|
+
var allRecordSizes = store.allRecordSizes;
|
|
11281
|
+
var touchRecord = store.touchRecord;
|
|
11282
|
+
var getMeta = store.getMeta;
|
|
11283
|
+
var setMeta = store.setMeta;
|
|
11284
|
+
var deleteOfflineMailDatabase = store.deleteDatabase;
|
|
11285
|
+
|
|
11286
|
+
// src/mail/offline/mailbox.ts
|
|
11287
|
+
var keyOf = {
|
|
11288
|
+
accounts: () => blind("accounts"),
|
|
11289
|
+
policy: () => blind("policy"),
|
|
11290
|
+
folders: (accountId) => blind("folders", accountId),
|
|
11291
|
+
header: (accountId, folderId, messageId) => blind("header", accountId, folderId, messageId),
|
|
11292
|
+
body: (accountId, messageId) => blind("body", accountId, messageId),
|
|
11293
|
+
attachment: (accountId, messageId, attachmentId) => blind("attachment", accountId, messageId, attachmentId)
|
|
11294
|
+
};
|
|
11295
|
+
var bucketOf2 = {
|
|
11296
|
+
global: () => blind("bucket", "global"),
|
|
11297
|
+
folder: (accountId, folderId) => blind("bucket", "folder", accountId, folderId),
|
|
11298
|
+
account: (accountId) => blind("bucket", "account", accountId)
|
|
11299
|
+
};
|
|
11300
|
+
async function put(kind, key, bucket2, data, sortAt = Date.now()) {
|
|
11301
|
+
const now = Date.now();
|
|
11302
|
+
await putRecord({ key, kind, bucket: bucket2, sortAt, size: data.byteLength, lastAccess: now, data });
|
|
11303
|
+
}
|
|
11304
|
+
async function readJson(record) {
|
|
11305
|
+
if (!record) return void 0;
|
|
11306
|
+
try {
|
|
11307
|
+
return await openJson(record.data);
|
|
11308
|
+
} catch {
|
|
11309
|
+
return void 0;
|
|
11310
|
+
}
|
|
11311
|
+
}
|
|
11312
|
+
var receivedAt = (m) => m.received_at ? Date.parse(m.received_at) || 0 : 0;
|
|
11313
|
+
async function saveAccounts(accounts) {
|
|
11314
|
+
await put("accounts", await keyOf.accounts(), await bucketOf2.global(), await sealJson(accounts));
|
|
11315
|
+
}
|
|
11316
|
+
async function loadAccounts() {
|
|
11317
|
+
return readJson(await getRecord(await keyOf.accounts()));
|
|
11318
|
+
}
|
|
11319
|
+
async function savePolicy(policy) {
|
|
11320
|
+
await put("policy", await keyOf.policy(), await bucketOf2.global(), await sealJson(policy));
|
|
11321
|
+
}
|
|
11322
|
+
async function loadPolicy() {
|
|
11323
|
+
return readJson(await getRecord(await keyOf.policy()));
|
|
11324
|
+
}
|
|
11325
|
+
async function saveFolders(accountId, folders) {
|
|
11326
|
+
await put(
|
|
11327
|
+
"folders",
|
|
11328
|
+
await keyOf.folders(accountId),
|
|
11329
|
+
await bucketOf2.account(accountId),
|
|
11330
|
+
await sealJson(folders)
|
|
11331
|
+
);
|
|
11332
|
+
}
|
|
11333
|
+
async function loadFolders(accountId) {
|
|
11334
|
+
return readJson(await getRecord(await keyOf.folders(accountId)));
|
|
11335
|
+
}
|
|
11336
|
+
function toHeader(message) {
|
|
11337
|
+
return {
|
|
11338
|
+
...message,
|
|
11339
|
+
text: "",
|
|
11340
|
+
html: void 0,
|
|
11341
|
+
delivery: void 0,
|
|
11342
|
+
attachments: message.attachments.map((a) => ({ ...a, content_base64: null }))
|
|
11343
|
+
};
|
|
11344
|
+
}
|
|
11345
|
+
async function saveHeader(accountId, folderId, message) {
|
|
11346
|
+
await put(
|
|
11347
|
+
"header",
|
|
11348
|
+
await keyOf.header(accountId, folderId, message.id),
|
|
11349
|
+
await bucketOf2.folder(accountId, folderId),
|
|
11350
|
+
await sealJson(toHeader(message)),
|
|
11351
|
+
receivedAt(message)
|
|
11352
|
+
);
|
|
11353
|
+
}
|
|
11354
|
+
async function loadHeaders(accountId, folderId) {
|
|
11355
|
+
const records = await recordsInBucket(await bucketOf2.folder(accountId, folderId));
|
|
11356
|
+
const out = [];
|
|
11357
|
+
for (const record of records) {
|
|
11358
|
+
if (record.kind !== "header") continue;
|
|
11359
|
+
const message = await readJson(record);
|
|
11360
|
+
if (message) out.push({ key: record.key, sortAt: record.sortAt, message });
|
|
11361
|
+
}
|
|
11362
|
+
return out.sort((a, b) => b.sortAt - a.sortAt);
|
|
11363
|
+
}
|
|
11364
|
+
async function hasFolder(accountId) {
|
|
11365
|
+
return hasRecord(await keyOf.folders(accountId));
|
|
11366
|
+
}
|
|
11367
|
+
async function saveBody(accountId, message) {
|
|
11368
|
+
const stripped = {
|
|
11369
|
+
...message,
|
|
11370
|
+
attachments: message.attachments.map((a) => ({ ...a, content_base64: null }))
|
|
11371
|
+
};
|
|
11372
|
+
await put(
|
|
11373
|
+
"body",
|
|
11374
|
+
await keyOf.body(accountId, message.id),
|
|
11375
|
+
await bucketOf2.account(accountId),
|
|
11376
|
+
await sealJson(stripped),
|
|
11377
|
+
receivedAt(message)
|
|
11378
|
+
);
|
|
11379
|
+
}
|
|
11380
|
+
async function hasBody(accountId, messageId) {
|
|
11381
|
+
return hasRecord(await keyOf.body(accountId, messageId));
|
|
11382
|
+
}
|
|
11383
|
+
async function loadBody(accountId, messageId) {
|
|
11384
|
+
return readJson(await getRecord(await keyOf.body(accountId, messageId)));
|
|
11385
|
+
}
|
|
11386
|
+
async function saveAttachment(accountId, messageId, attachmentId, bytes) {
|
|
11387
|
+
await put(
|
|
11388
|
+
"attachment",
|
|
11389
|
+
await keyOf.attachment(accountId, messageId, attachmentId),
|
|
11390
|
+
await bucketOf2.account(accountId),
|
|
11391
|
+
await sealBytes(bytes)
|
|
11392
|
+
);
|
|
11393
|
+
}
|
|
11394
|
+
async function hasAttachment(accountId, messageId, attachmentId) {
|
|
11395
|
+
return hasRecord(await keyOf.attachment(accountId, messageId, attachmentId));
|
|
11396
|
+
}
|
|
11397
|
+
async function loadAttachment(accountId, messageId, attachmentId) {
|
|
11398
|
+
const key = await keyOf.attachment(accountId, messageId, attachmentId);
|
|
11399
|
+
const record = await getRecord(key);
|
|
11400
|
+
if (!record) return void 0;
|
|
11401
|
+
try {
|
|
11402
|
+
const bytes = await openBytes(record.data);
|
|
11403
|
+
void touchRecord(key);
|
|
11404
|
+
return bytes;
|
|
11405
|
+
} catch {
|
|
11406
|
+
return void 0;
|
|
11407
|
+
}
|
|
11408
|
+
}
|
|
11409
|
+
async function removeKeys(keys) {
|
|
11410
|
+
await deleteRecords(keys);
|
|
11411
|
+
}
|
|
11412
|
+
function bodyText(body) {
|
|
11413
|
+
const html = body.text ? "" : (body.html ?? "").replace(/<[^>]*>/g, " ");
|
|
11414
|
+
return `${body.text} ${html} ${body.attachments.map((a) => a.name).join(" ")}`;
|
|
11415
|
+
}
|
|
11416
|
+
var folded = (value) => value.toLocaleLowerCase().normalize("NFKD");
|
|
11417
|
+
async function searchFolder(accountId, folderId, query) {
|
|
11418
|
+
const words = folded(query).split(/\s+/).filter(Boolean);
|
|
11419
|
+
const headers = await loadHeaders(accountId, folderId);
|
|
11420
|
+
if (words.length === 0) return headers.map((h) => h.message);
|
|
11421
|
+
const out = [];
|
|
11422
|
+
for (const { message } of headers) {
|
|
11423
|
+
const people = [...message.sender, ...message.to, ...message.cc].map((p) => `${p.name ?? ""} ${p.email}`).join(" ");
|
|
11424
|
+
let haystack = folded(`${message.subject} ${people} ${message.preview}`);
|
|
11425
|
+
if (!words.every((w) => haystack.includes(w))) {
|
|
11426
|
+
const body = await loadBody(accountId, message.id);
|
|
11427
|
+
if (body) haystack += " " + folded(bodyText(body));
|
|
11428
|
+
}
|
|
11429
|
+
if (words.every((w) => haystack.includes(w))) out.push(message);
|
|
11430
|
+
}
|
|
11431
|
+
return out;
|
|
11432
|
+
}
|
|
11433
|
+
|
|
11434
|
+
// src/mail/offline/settings.ts
|
|
11435
|
+
var DEFAULT_OFFLINE_MAIL_SETTINGS = {
|
|
11436
|
+
enabled: false,
|
|
11437
|
+
scope: "90d",
|
|
11438
|
+
attachmentCapMb: 25,
|
|
11439
|
+
quotaMb: 1024
|
|
11440
|
+
};
|
|
11441
|
+
var SCOPE_DAYS = {
|
|
11442
|
+
"30d": 30,
|
|
11443
|
+
"90d": 90,
|
|
11444
|
+
"365d": 365,
|
|
11445
|
+
all: null
|
|
11446
|
+
};
|
|
11447
|
+
var STORAGE_PREFIX = "arbi-offline-mail-settings:";
|
|
11448
|
+
function getOfflineMailSettings(userExtId) {
|
|
11449
|
+
if (!userExtId) return DEFAULT_OFFLINE_MAIL_SETTINGS;
|
|
11450
|
+
const key = STORAGE_PREFIX + userExtId;
|
|
11451
|
+
try {
|
|
11452
|
+
const raw = localStorage.getItem(key);
|
|
11453
|
+
return raw ? { ...DEFAULT_OFFLINE_MAIL_SETTINGS, ...JSON.parse(raw) } : DEFAULT_OFFLINE_MAIL_SETTINGS;
|
|
11454
|
+
} catch {
|
|
11455
|
+
return DEFAULT_OFFLINE_MAIL_SETTINGS;
|
|
11456
|
+
}
|
|
11457
|
+
}
|
|
11458
|
+
function setOfflineMailSettings(userExtId, patch) {
|
|
11459
|
+
const next = { ...getOfflineMailSettings(userExtId), ...patch };
|
|
11460
|
+
if (userExtId) {
|
|
11461
|
+
try {
|
|
11462
|
+
localStorage.setItem(STORAGE_PREFIX + userExtId, JSON.stringify(next));
|
|
11463
|
+
} catch {
|
|
11464
|
+
}
|
|
11465
|
+
}
|
|
11466
|
+
notifyOfflineMailChange("settings");
|
|
11467
|
+
return next;
|
|
11468
|
+
}
|
|
11469
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
11470
|
+
var CHANNEL = "arbi-offline-mail";
|
|
11471
|
+
var channel = null;
|
|
11472
|
+
function getChannel() {
|
|
11473
|
+
if (channel || typeof BroadcastChannel === "undefined") return channel;
|
|
11474
|
+
channel = new BroadcastChannel(CHANNEL);
|
|
11475
|
+
channel.onmessage = (event) => {
|
|
11476
|
+
for (const listener of listeners) listener(event.data);
|
|
11477
|
+
};
|
|
11478
|
+
return channel;
|
|
11479
|
+
}
|
|
11480
|
+
function notifyOfflineMailChange(change) {
|
|
11481
|
+
for (const listener of listeners) listener(change);
|
|
11482
|
+
try {
|
|
11483
|
+
getChannel()?.postMessage(change);
|
|
11484
|
+
} catch {
|
|
11485
|
+
}
|
|
11486
|
+
}
|
|
11487
|
+
function onOfflineMailChange(listener) {
|
|
11488
|
+
getChannel();
|
|
11489
|
+
listeners.add(listener);
|
|
11490
|
+
return () => listeners.delete(listener);
|
|
11491
|
+
}
|
|
11492
|
+
|
|
11493
|
+
// src/mail/offline/drafts.ts
|
|
11494
|
+
var keyFor = (id) => blind("draft", id);
|
|
11495
|
+
async function saveLocalDraft(accountId, compose, id = crypto.randomUUID()) {
|
|
11496
|
+
const draft = { id, accountId, compose, updatedAt: Date.now() };
|
|
11497
|
+
await putRecord({
|
|
11498
|
+
key: await keyFor(id),
|
|
11499
|
+
kind: "draft",
|
|
11500
|
+
bucket: await blind("bucket", "drafts", accountId),
|
|
11501
|
+
sortAt: draft.updatedAt,
|
|
11502
|
+
size: 0,
|
|
11503
|
+
lastAccess: draft.updatedAt,
|
|
11504
|
+
data: await sealJson(draft)
|
|
11505
|
+
});
|
|
11506
|
+
notifyOfflineMailChange("drafts");
|
|
11507
|
+
return draft;
|
|
11508
|
+
}
|
|
11509
|
+
async function listLocalDrafts(accountId) {
|
|
11510
|
+
const drafts = [];
|
|
11511
|
+
for (const record of await recordsOfKind("draft")) {
|
|
11512
|
+
try {
|
|
11513
|
+
const draft = await openJson(record.data);
|
|
11514
|
+
if (!accountId || draft.accountId === accountId) drafts.push(draft);
|
|
11515
|
+
} catch {
|
|
11516
|
+
}
|
|
11517
|
+
}
|
|
11518
|
+
return drafts.sort((a, b) => b.updatedAt - a.updatedAt);
|
|
11519
|
+
}
|
|
11520
|
+
async function deleteLocalDraft(id) {
|
|
11521
|
+
await deleteRecords([await keyFor(id)]);
|
|
11522
|
+
notifyOfflineMailChange("drafts");
|
|
11523
|
+
}
|
|
11524
|
+
async function syncLocalDrafts(save) {
|
|
11525
|
+
let uploaded = 0;
|
|
11526
|
+
for (const draft of await listLocalDrafts()) {
|
|
11527
|
+
if (draft.error) continue;
|
|
11528
|
+
try {
|
|
11529
|
+
await save(draft);
|
|
11530
|
+
await deleteLocalDraft(draft.id);
|
|
11531
|
+
uploaded++;
|
|
11532
|
+
} catch (error) {
|
|
11533
|
+
const status = error.status;
|
|
11534
|
+
if (isNetworkFailure(error) || status === void 0 || status === 401 || status >= 500) break;
|
|
11535
|
+
await putRecord({
|
|
11536
|
+
key: await keyFor(draft.id),
|
|
11537
|
+
kind: "draft",
|
|
11538
|
+
bucket: await blind("bucket", "drafts", draft.accountId),
|
|
11539
|
+
sortAt: draft.updatedAt,
|
|
11540
|
+
size: 0,
|
|
11541
|
+
lastAccess: Date.now(),
|
|
11542
|
+
data: await sealJson({
|
|
11543
|
+
...draft,
|
|
11544
|
+
error: error instanceof Error ? error.message : "The server refused this draft"
|
|
11545
|
+
})
|
|
11546
|
+
});
|
|
11547
|
+
notifyOfflineMailChange("drafts");
|
|
11548
|
+
}
|
|
11549
|
+
}
|
|
11550
|
+
return uploaded;
|
|
11551
|
+
}
|
|
11552
|
+
|
|
11553
|
+
// src/mail/offline/outbox.ts
|
|
11554
|
+
var bucket = () => blind("bucket", "outbox");
|
|
11555
|
+
var keyFor2 = (id) => blind("outbox", id);
|
|
11556
|
+
function outboxProblem(compose) {
|
|
11557
|
+
const missing = compose.attachments.find((a) => a.content_base64 == null);
|
|
11558
|
+
if (missing)
|
|
11559
|
+
return `${missing.name} isn't saved on this device, so it can't be sent offline. Remove it or send once you're back online.`;
|
|
11560
|
+
return null;
|
|
11561
|
+
}
|
|
11562
|
+
var seqCounter = 0;
|
|
11563
|
+
async function write(item) {
|
|
11564
|
+
await putRecord({
|
|
11565
|
+
key: await keyFor2(item.id),
|
|
11566
|
+
kind: "outbox",
|
|
11567
|
+
bucket: await bucket(),
|
|
11568
|
+
sortAt: item.seq,
|
|
11569
|
+
size: 0,
|
|
11570
|
+
lastAccess: Date.now(),
|
|
11571
|
+
data: await sealJson(item)
|
|
11572
|
+
});
|
|
11573
|
+
}
|
|
11574
|
+
async function listOutbox() {
|
|
11575
|
+
const records = await recordsInBucket(await bucket());
|
|
11576
|
+
const items = [];
|
|
11577
|
+
for (const record of records) {
|
|
11578
|
+
try {
|
|
11579
|
+
items.push(await openJson(record.data));
|
|
11580
|
+
} catch {
|
|
11581
|
+
}
|
|
11582
|
+
}
|
|
11583
|
+
return items.sort((a, b) => a.seq - b.seq);
|
|
11584
|
+
}
|
|
11585
|
+
async function enqueueOutbox(input) {
|
|
11586
|
+
const problem = outboxProblem(input.compose);
|
|
11587
|
+
if (problem) throw new Error(problem);
|
|
11588
|
+
const now = Date.now();
|
|
11589
|
+
seqCounter = Math.max(seqCounter + 1, now * 1e3);
|
|
11590
|
+
const item = {
|
|
11591
|
+
id: crypto.randomUUID(),
|
|
11592
|
+
requestId: input.requestId,
|
|
11593
|
+
account: input.account,
|
|
11594
|
+
compose: input.compose,
|
|
11595
|
+
secure: input.secure,
|
|
11596
|
+
securePayload: input.securePayload,
|
|
11597
|
+
status: "queued",
|
|
11598
|
+
attempts: 0,
|
|
11599
|
+
createdAt: now,
|
|
11600
|
+
seq: seqCounter
|
|
11601
|
+
};
|
|
11602
|
+
await write(item);
|
|
11603
|
+
notifyOfflineMailChange("outbox");
|
|
11604
|
+
return item;
|
|
11605
|
+
}
|
|
11606
|
+
async function update(item, patch) {
|
|
11607
|
+
const next = { ...item, ...patch };
|
|
11608
|
+
await write(next);
|
|
11609
|
+
notifyOfflineMailChange("outbox");
|
|
11610
|
+
return next;
|
|
11611
|
+
}
|
|
11612
|
+
async function deleteOutboxItem(id) {
|
|
11613
|
+
await deleteRecords([await keyFor2(id)]);
|
|
11614
|
+
notifyOfflineMailChange("outbox");
|
|
11615
|
+
}
|
|
11616
|
+
async function retryOutboxItem(id) {
|
|
11617
|
+
const item = (await listOutbox()).find((i) => i.id === id);
|
|
11618
|
+
if (item && item.status === "failed")
|
|
11619
|
+
await update(item, { status: "queued", error: void 0, inDoubt: item.inDoubt });
|
|
11620
|
+
}
|
|
11621
|
+
var IN_DOUBT_MESSAGE = "The mail server didn't confirm this message. It may already have been sent: check Sent before sending it again.";
|
|
11622
|
+
function classify(error) {
|
|
11623
|
+
if (isNetworkFailure(error)) return { kind: "offline" };
|
|
11624
|
+
const status = error?.status;
|
|
11625
|
+
const detail = error instanceof Error ? error.message : "The message could not be sent";
|
|
11626
|
+
if (status === void 0) return { kind: "failed", error: detail, inDoubt: false };
|
|
11627
|
+
if (status === 409) return { kind: "failed", error: IN_DOUBT_MESSAGE, inDoubt: true };
|
|
11628
|
+
if (status >= 500) return { kind: "failed", error: IN_DOUBT_MESSAGE, inDoubt: true };
|
|
11629
|
+
return { kind: "failed", error: detail, inDoubt: false };
|
|
11630
|
+
}
|
|
11631
|
+
async function prepared(item, sender) {
|
|
11632
|
+
if (!item.secure || item.securePayload !== void 0) return item;
|
|
11633
|
+
return update(item, { securePayload: await sender.prepareSecure(item) });
|
|
11634
|
+
}
|
|
11635
|
+
async function attempt(item, sender) {
|
|
11636
|
+
try {
|
|
11637
|
+
const result = await sender.send(item);
|
|
11638
|
+
return { kind: "sent", serverId: result?.id };
|
|
11639
|
+
} catch (error) {
|
|
11640
|
+
const outcome = classify(error);
|
|
11641
|
+
if (error.status === 401) {
|
|
11642
|
+
try {
|
|
11643
|
+
await sender.unlock(item.account);
|
|
11644
|
+
const result = await sender.send(item);
|
|
11645
|
+
return { kind: "sent", serverId: result?.id };
|
|
11646
|
+
} catch (retryError) {
|
|
11647
|
+
return classify(retryError);
|
|
11648
|
+
}
|
|
11649
|
+
}
|
|
11650
|
+
return outcome;
|
|
11651
|
+
}
|
|
11652
|
+
}
|
|
11653
|
+
async function flushOutboxOnce(sender, isOnline) {
|
|
11654
|
+
const result = { sent: 0, failed: 0, interrupted: false };
|
|
11655
|
+
const unlocked2 = /* @__PURE__ */ new Set();
|
|
11656
|
+
for (; ; ) {
|
|
11657
|
+
if (!isOnline()) {
|
|
11658
|
+
result.interrupted = true;
|
|
11659
|
+
break;
|
|
11660
|
+
}
|
|
11661
|
+
const next = (await listOutbox()).find((i) => i.status === "queued" || i.status === "sending");
|
|
11662
|
+
if (!next) break;
|
|
11663
|
+
let item = await update(next, { status: "sending", attempts: next.attempts + 1 });
|
|
11664
|
+
try {
|
|
11665
|
+
item = await prepared(item, sender);
|
|
11666
|
+
} catch (error) {
|
|
11667
|
+
const message = error instanceof Error ? error.message : "Could not encrypt the message";
|
|
11668
|
+
await update(item, { status: "failed", error: message });
|
|
11669
|
+
result.failed++;
|
|
11670
|
+
continue;
|
|
11671
|
+
}
|
|
11672
|
+
if (!unlocked2.has(item.account.id)) {
|
|
11673
|
+
await sender.unlock(item.account).catch(() => {
|
|
11674
|
+
});
|
|
11675
|
+
unlocked2.add(item.account.id);
|
|
11676
|
+
}
|
|
11677
|
+
const outcome = await attempt(item, sender);
|
|
11678
|
+
if (outcome.kind === "sent") {
|
|
11679
|
+
item = await update(item, {
|
|
11680
|
+
status: "sent",
|
|
11681
|
+
sentAt: Date.now(),
|
|
11682
|
+
error: void 0,
|
|
11683
|
+
inDoubt: false
|
|
11684
|
+
});
|
|
11685
|
+
result.sent++;
|
|
11686
|
+
} else if (outcome.kind === "offline") {
|
|
11687
|
+
await update(item, { status: "queued" });
|
|
11688
|
+
result.interrupted = true;
|
|
11689
|
+
break;
|
|
11690
|
+
} else {
|
|
11691
|
+
await update(item, {
|
|
11692
|
+
status: "failed",
|
|
11693
|
+
error: outcome.error,
|
|
11694
|
+
inDoubt: item.inDoubt || outcome.inDoubt
|
|
11695
|
+
});
|
|
11696
|
+
result.failed++;
|
|
11697
|
+
}
|
|
11698
|
+
}
|
|
11699
|
+
return result;
|
|
11700
|
+
}
|
|
11701
|
+
async function purgeSentOutbox(olderThanMs = 0) {
|
|
11702
|
+
const cutoff = Date.now() - olderThanMs;
|
|
11703
|
+
const done = (await listOutbox()).filter((i) => i.status === "sent" && (i.sentAt ?? 0) <= cutoff);
|
|
11704
|
+
if (done.length === 0) return;
|
|
11705
|
+
await deleteRecords(await Promise.all(done.map((i) => keyFor2(i.id))));
|
|
11706
|
+
notifyOfflineMailChange("outbox");
|
|
11707
|
+
}
|
|
11708
|
+
var STATUS_KEY = "status";
|
|
11709
|
+
var FULL_SYNC_EVERY_MS = 60 * 60 * 1e3;
|
|
11710
|
+
var MAX_PAGES = 200;
|
|
11711
|
+
async function getOfflineMailStatus() {
|
|
11712
|
+
return await getMeta(STATUS_KEY) ?? { messages: 0, bytes: 0, skipped: [] };
|
|
11713
|
+
}
|
|
11714
|
+
var MB = 1024 * 1024;
|
|
11715
|
+
var time = (m) => m.received_at ? Date.parse(m.received_at) || 0 : 0;
|
|
11716
|
+
var sameHeader = (a, b) => JSON.stringify(toHeader(a)) === JSON.stringify(toHeader(b));
|
|
11717
|
+
var Budget = class {
|
|
11718
|
+
constructor(used, quota) {
|
|
11719
|
+
this.used = used;
|
|
11720
|
+
this.quota = quota;
|
|
11721
|
+
}
|
|
11722
|
+
used;
|
|
11723
|
+
quota;
|
|
11724
|
+
get full() {
|
|
11725
|
+
return this.used >= this.quota;
|
|
11726
|
+
}
|
|
11727
|
+
take(bytes) {
|
|
11728
|
+
this.used += bytes;
|
|
11729
|
+
}
|
|
11730
|
+
};
|
|
11731
|
+
async function saveMessageContent(transport, account, header, settings, budget) {
|
|
11732
|
+
const message = await transport.message(account, header.id);
|
|
11733
|
+
await saveBody(account.id, message);
|
|
11734
|
+
budget.take((message.text?.length ?? 0) + (message.html?.length ?? 0));
|
|
11735
|
+
let attachmentBytes = 0;
|
|
11736
|
+
for (const attachment of message.attachments) {
|
|
11737
|
+
if (budget.full) return;
|
|
11738
|
+
if (attachmentBytes + attachment.size > settings.attachmentCapMb * MB) continue;
|
|
11739
|
+
if (await hasAttachment(account.id, message.id, attachment.id)) continue;
|
|
11740
|
+
const bytes = attachment.content_base64 ? Uint8Array.from(atob(attachment.content_base64), (c) => c.charCodeAt(0)) : await transport.attachment(account, message.id, attachment.id);
|
|
11741
|
+
await saveAttachment(account.id, message.id, attachment.id, bytes);
|
|
11742
|
+
attachmentBytes += bytes.byteLength;
|
|
11743
|
+
budget.take(bytes.byteLength);
|
|
11744
|
+
}
|
|
11745
|
+
}
|
|
11746
|
+
async function syncFolder(transport, account, folder, settings, windowStart, full, budget) {
|
|
11747
|
+
const saved = new Map(
|
|
11748
|
+
(await loadHeaders(account.id, folder.id)).map((h) => [h.message.id, h])
|
|
11749
|
+
);
|
|
11750
|
+
const seen = /* @__PURE__ */ new Set();
|
|
11751
|
+
let oldestSeen = Infinity;
|
|
11752
|
+
let cursor = null;
|
|
11753
|
+
let reachedEnd = false;
|
|
11754
|
+
for (let page = 0; page < MAX_PAGES; page++) {
|
|
11755
|
+
const result = await transport.messages(account, folder.id, cursor);
|
|
11756
|
+
let anythingNew = false;
|
|
11757
|
+
let outOfScope = false;
|
|
11758
|
+
for (const message of result.messages) {
|
|
11759
|
+
const at = time(message);
|
|
11760
|
+
if (at && at < windowStart) {
|
|
11761
|
+
outOfScope = true;
|
|
11762
|
+
break;
|
|
11763
|
+
}
|
|
11764
|
+
seen.add(message.id);
|
|
11765
|
+
if (at) oldestSeen = Math.min(oldestSeen, at);
|
|
11766
|
+
const previous = saved.get(message.id)?.message;
|
|
11767
|
+
if (!previous || !sameHeader(previous, message)) {
|
|
11768
|
+
await saveHeader(account.id, folder.id, message);
|
|
11769
|
+
anythingNew = true;
|
|
11770
|
+
}
|
|
11771
|
+
if (!budget.full && !await hasBody(account.id, message.id)) {
|
|
11772
|
+
try {
|
|
11773
|
+
await saveMessageContent(transport, account, message, settings, budget);
|
|
11774
|
+
anythingNew = true;
|
|
11775
|
+
} catch (error) {
|
|
11776
|
+
client.logger.warn("[offline-mail] could not save a message body", error);
|
|
11777
|
+
}
|
|
11778
|
+
}
|
|
11779
|
+
}
|
|
11780
|
+
cursor = result.next_cursor ?? null;
|
|
11781
|
+
if (outOfScope || !cursor) {
|
|
11782
|
+
reachedEnd = true;
|
|
11783
|
+
break;
|
|
11784
|
+
}
|
|
11785
|
+
if (!full && !anythingNew) break;
|
|
11786
|
+
}
|
|
11787
|
+
const stale = [...saved.values()].filter(
|
|
11788
|
+
(h) => !seen.has(h.message.id) && (reachedEnd || h.sortAt >= oldestSeen)
|
|
11789
|
+
);
|
|
11790
|
+
await removeKeys(stale.map((h) => h.key));
|
|
11791
|
+
}
|
|
11792
|
+
async function collectGarbage(accounts) {
|
|
11793
|
+
for (const account of accounts) {
|
|
11794
|
+
const folders = await loadFolders(account.id) ?? [];
|
|
11795
|
+
const expected = /* @__PURE__ */ new Set([await keyOf.folders(account.id)]);
|
|
11796
|
+
for (const folder of folders) {
|
|
11797
|
+
for (const { message } of await loadHeaders(account.id, folder.id)) {
|
|
11798
|
+
expected.add(await keyOf.body(account.id, message.id));
|
|
11799
|
+
for (const attachment of message.attachments)
|
|
11800
|
+
expected.add(await keyOf.attachment(account.id, message.id, attachment.id));
|
|
11801
|
+
}
|
|
11802
|
+
}
|
|
11803
|
+
const orphans = (await recordsInBucket(await bucketOf2.account(account.id))).filter((r) => (r.kind === "body" || r.kind === "attachment") && !expected.has(r.key)).map((r) => r.key);
|
|
11804
|
+
await removeKeys(orphans);
|
|
11805
|
+
}
|
|
11806
|
+
}
|
|
11807
|
+
async function forgetAccount(accountId) {
|
|
11808
|
+
for (const folder of await loadFolders(accountId) ?? []) {
|
|
11809
|
+
const records2 = await recordsInBucket(await bucketOf2.folder(accountId, folder.id));
|
|
11810
|
+
await removeKeys(records2.map((r) => r.key));
|
|
11811
|
+
}
|
|
11812
|
+
const records = await recordsInBucket(await bucketOf2.account(accountId));
|
|
11813
|
+
await removeKeys(records.filter((r) => r.kind !== "draft").map((r) => r.key));
|
|
11814
|
+
}
|
|
11815
|
+
async function enforceQuota(quotaBytes) {
|
|
11816
|
+
let used = (await allRecordSizes()).reduce((n, r) => n + r.size, 0);
|
|
11817
|
+
if (used <= quotaBytes) return used;
|
|
11818
|
+
for (const kind of ["attachment", "body"]) {
|
|
11819
|
+
const records = (await recordsOfKind(kind)).sort(
|
|
11820
|
+
(a, b) => kind === "attachment" ? a.lastAccess - b.lastAccess : a.sortAt - b.sortAt
|
|
11821
|
+
);
|
|
11822
|
+
const evict = [];
|
|
11823
|
+
for (const record of records) {
|
|
11824
|
+
if (used <= quotaBytes) break;
|
|
11825
|
+
evict.push(record.key);
|
|
11826
|
+
used -= record.size;
|
|
11827
|
+
}
|
|
11828
|
+
await removeKeys(evict);
|
|
11829
|
+
if (used <= quotaBytes) break;
|
|
11830
|
+
}
|
|
11831
|
+
return used;
|
|
11832
|
+
}
|
|
11833
|
+
async function syncMailbox(transport, settings, options = {}) {
|
|
11834
|
+
const now = options.now ?? Date.now();
|
|
11835
|
+
const previous = await getOfflineMailStatus();
|
|
11836
|
+
const full = options.full || !previous.lastFullSyncAt || now - previous.lastFullSyncAt > FULL_SYNC_EVERY_MS;
|
|
11837
|
+
const days = SCOPE_DAYS[settings.scope];
|
|
11838
|
+
const windowStart = days === null ? 0 : now - days * 24 * 60 * 60 * 1e3;
|
|
11839
|
+
const quota = settings.quotaMb * MB;
|
|
11840
|
+
const skipped = [];
|
|
11841
|
+
let error;
|
|
11842
|
+
try {
|
|
11843
|
+
await savePolicy(await transport.policy());
|
|
11844
|
+
const accounts = await transport.accounts();
|
|
11845
|
+
const before = await loadAccounts() ?? [];
|
|
11846
|
+
await saveAccounts(accounts);
|
|
11847
|
+
for (const gone of before.filter((b) => !accounts.some((a) => a.id === b.id)))
|
|
11848
|
+
await forgetAccount(gone.id);
|
|
11849
|
+
const budget = new Budget(
|
|
11850
|
+
(await allRecordSizes()).reduce((n, r) => n + r.size, 0),
|
|
11851
|
+
quota
|
|
11852
|
+
);
|
|
11853
|
+
for (const account of accounts) {
|
|
11854
|
+
if (account.needs_reconsent) {
|
|
11855
|
+
skipped.push(account.email);
|
|
11856
|
+
continue;
|
|
11857
|
+
}
|
|
11858
|
+
try {
|
|
11859
|
+
await transport.unlock(account);
|
|
11860
|
+
const folders = await transport.folders(account);
|
|
11861
|
+
const oldFolders = await loadFolders(account.id) ?? [];
|
|
11862
|
+
await saveFolders(account.id, folders);
|
|
11863
|
+
for (const gone of oldFolders.filter((o) => !folders.some((f) => f.id === o.id))) {
|
|
11864
|
+
const records = await recordsInBucket(await bucketOf2.folder(account.id, gone.id));
|
|
11865
|
+
await removeKeys(records.map((r) => r.key));
|
|
11866
|
+
}
|
|
11867
|
+
for (const folder of folders)
|
|
11868
|
+
await syncFolder(transport, account, folder, settings, windowStart, full, budget);
|
|
11869
|
+
notifyOfflineMailChange("mailbox");
|
|
11870
|
+
} catch (accountError) {
|
|
11871
|
+
if (accountError.status === void 0) throw accountError;
|
|
11872
|
+
client.logger.warn("[offline-mail] account sync failed", accountError);
|
|
11873
|
+
skipped.push(account.email);
|
|
11874
|
+
}
|
|
11875
|
+
}
|
|
11876
|
+
if (full) await collectGarbage(accounts);
|
|
11877
|
+
} catch (syncError) {
|
|
11878
|
+
error = syncError.status === void 0 ? "The connection dropped during sync. It will continue when you are back online." : syncError instanceof Error ? syncError.message : "Sync failed";
|
|
11879
|
+
}
|
|
11880
|
+
const bytes = await enforceQuota(quota);
|
|
11881
|
+
const messages = (await recordsOfKind("header")).length;
|
|
11882
|
+
const status = {
|
|
11883
|
+
lastSyncedAt: error ? previous.lastSyncedAt : now,
|
|
11884
|
+
lastFullSyncAt: !error && full ? now : previous.lastFullSyncAt,
|
|
11885
|
+
messages,
|
|
11886
|
+
bytes,
|
|
11887
|
+
error,
|
|
11888
|
+
skipped
|
|
11889
|
+
};
|
|
11890
|
+
await setMeta(STATUS_KEY, status);
|
|
11891
|
+
notifyOfflineMailChange("status");
|
|
11892
|
+
return status;
|
|
11893
|
+
}
|
|
11894
|
+
|
|
11895
|
+
// src/mail/offline/live.ts
|
|
11896
|
+
var OUTBOX_FOLDER = "outbox";
|
|
11897
|
+
function sessionUser(arbi) {
|
|
11898
|
+
return arbi.session?.getState().user?.external_id ?? null;
|
|
11899
|
+
}
|
|
11900
|
+
function hasLiveSession(arbi) {
|
|
11901
|
+
return !!arbi.session?.getState().serverSessionKey;
|
|
11902
|
+
}
|
|
11903
|
+
function canReachMail(arbi) {
|
|
11904
|
+
return reactQuery.onlineManager.isOnline() && hasLiveSession(arbi);
|
|
11905
|
+
}
|
|
11906
|
+
var unlocked = { nativeUnlocked: true };
|
|
11907
|
+
function mailCall(arbi, path, init = {}) {
|
|
11908
|
+
return mailJson((p, i) => arbi.mail.fetch(p, i, unlocked), path, init);
|
|
11909
|
+
}
|
|
11910
|
+
function liveTransport(arbi) {
|
|
11911
|
+
const unlock = async (account) => {
|
|
11912
|
+
if (!hasLiveSession(arbi))
|
|
11913
|
+
throw Object.assign(new Error("Sign in to unlock your mailbox"), { status: 401 });
|
|
11914
|
+
await arbi.mail.unlockAccount(account);
|
|
11915
|
+
};
|
|
11916
|
+
return {
|
|
11917
|
+
policy: () => mailCall(arbi, "/policy"),
|
|
11918
|
+
accounts: () => mailCall(arbi, "/accounts"),
|
|
11919
|
+
unlock,
|
|
11920
|
+
folders: (account) => mailCall(arbi, `${accountPath(account.id)}/folders`),
|
|
11921
|
+
messages: (account, folderId, cursor) => mailCall(
|
|
11922
|
+
arbi,
|
|
11923
|
+
`${accountPath(account.id)}/messages?${new URLSearchParams({
|
|
11924
|
+
folder_id: folderId,
|
|
11925
|
+
q: "",
|
|
11926
|
+
limit: "100",
|
|
11927
|
+
...cursor ? { cursor } : {}
|
|
11928
|
+
})}`
|
|
11929
|
+
),
|
|
11930
|
+
message: async (account, messageId) => {
|
|
11931
|
+
const path = `${accountPath(account.id)}/messages/${encodeURIComponent(messageId)}`;
|
|
11932
|
+
try {
|
|
11933
|
+
return await mailCall(arbi, path);
|
|
11934
|
+
} catch (error) {
|
|
11935
|
+
if (error.status !== 401 || account.provider !== "native")
|
|
11936
|
+
throw error;
|
|
11937
|
+
if (hasLiveSession(arbi)) await arbi.mail.unlockNative();
|
|
11938
|
+
return mailCall(arbi, path);
|
|
11939
|
+
}
|
|
11940
|
+
},
|
|
11941
|
+
attachment: async (account, messageId, attachmentId) => {
|
|
11942
|
+
const response = await arbi.mail.fetch(
|
|
11943
|
+
`${accountPath(account.id)}/messages/${encodeURIComponent(messageId)}/attachments/${encodeURIComponent(attachmentId)}`,
|
|
11944
|
+
{},
|
|
11945
|
+
unlocked
|
|
11946
|
+
);
|
|
11947
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
11948
|
+
}
|
|
11949
|
+
};
|
|
11950
|
+
}
|
|
11951
|
+
function liveSender(arbi) {
|
|
11952
|
+
const transport = liveTransport(arbi);
|
|
11953
|
+
return {
|
|
11954
|
+
prepareSecure: async (item) => {
|
|
11955
|
+
if (item.account.provider !== "native")
|
|
11956
|
+
throw new Error("Choose your native inbox to send securely");
|
|
11957
|
+
return arbi.secureMail.prepare(item.compose, item.account, item.requestId);
|
|
11958
|
+
},
|
|
11959
|
+
unlock: async (account) => {
|
|
11960
|
+
if (account.provider !== "native") await transport.unlock(account);
|
|
11961
|
+
},
|
|
11962
|
+
send: (item) => item.secure ? mailJson((p, i) => arbi.mail.fetch(p, i), "/secure/send", {
|
|
11963
|
+
method: "POST",
|
|
11964
|
+
body: JSON.stringify(item.securePayload)
|
|
11965
|
+
}) : mailJson(
|
|
11966
|
+
(p, i) => arbi.mail.fetch(p, i),
|
|
11967
|
+
`${accountPath(item.account.id)}/send`,
|
|
11968
|
+
{
|
|
11969
|
+
method: "POST",
|
|
11970
|
+
body: JSON.stringify({ ...item.compose, request_id: item.requestId })
|
|
11971
|
+
}
|
|
11972
|
+
)
|
|
11973
|
+
};
|
|
11974
|
+
}
|
|
11975
|
+
var localLocks = /* @__PURE__ */ new Set();
|
|
11976
|
+
async function exclusive(name, fn) {
|
|
11977
|
+
if (typeof navigator !== "undefined" && navigator.locks?.request) {
|
|
11978
|
+
return navigator.locks.request(name, { ifAvailable: true }, async (lock) => {
|
|
11979
|
+
if (!lock) return false;
|
|
11980
|
+
await fn();
|
|
11981
|
+
return true;
|
|
11982
|
+
});
|
|
11983
|
+
}
|
|
11984
|
+
if (localLocks.has(name)) return false;
|
|
11985
|
+
localLocks.add(name);
|
|
11986
|
+
try {
|
|
11987
|
+
await fn();
|
|
11988
|
+
return true;
|
|
11989
|
+
} finally {
|
|
11990
|
+
localLocks.delete(name);
|
|
11991
|
+
}
|
|
11992
|
+
}
|
|
11993
|
+
var retryTimer = null;
|
|
11994
|
+
async function flushOutbox(context) {
|
|
11995
|
+
const { arbi, queryClient, openOutbox } = context;
|
|
11996
|
+
if (!canReachMail(arbi)) return;
|
|
11997
|
+
const ran = await exclusive("arbi-mail-outbox", async () => {
|
|
11998
|
+
const result = await flushOutboxOnce(liveSender(arbi), () => reactQuery.onlineManager.isOnline());
|
|
11999
|
+
if (result.sent > 0) void queryClient.invalidateQueries({ queryKey: chunkU4PWVSCT_cjs.mailQueryKeys.all() });
|
|
12000
|
+
const remaining = (await listOutbox()).filter((i) => i.status !== "sent");
|
|
12001
|
+
if (result.failed > 0) {
|
|
12002
|
+
chunkDZUBZ45Y_cjs.notify.error(
|
|
12003
|
+
result.failed === 1 ? "A message in your Outbox couldn't be sent" : `${result.failed} messages in your Outbox couldn't be sent`,
|
|
12004
|
+
{
|
|
12005
|
+
description: "Open the Outbox to see why, then retry, edit or delete it.",
|
|
12006
|
+
...openOutbox && { action: { label: "Open Outbox", onClick: openOutbox } }
|
|
12007
|
+
}
|
|
12008
|
+
);
|
|
12009
|
+
} else if (result.sent > 0 && remaining.length === 0) {
|
|
12010
|
+
chunkDZUBZ45Y_cjs.notify.success(
|
|
12011
|
+
result.sent === 1 ? "Your Outbox message was sent" : `${result.sent} Outbox messages sent`
|
|
12012
|
+
);
|
|
12013
|
+
}
|
|
12014
|
+
setTimeout(() => void purgeSentOutbox(3e4), 31e3);
|
|
12015
|
+
});
|
|
12016
|
+
if (!ran) {
|
|
12017
|
+
if (retryTimer) clearTimeout(retryTimer);
|
|
12018
|
+
retryTimer = setTimeout(() => void flushOutbox(context), 3e3);
|
|
12019
|
+
}
|
|
12020
|
+
}
|
|
12021
|
+
async function uploadOfflineDrafts({
|
|
12022
|
+
arbi,
|
|
12023
|
+
queryClient
|
|
12024
|
+
}) {
|
|
12025
|
+
if (!canReachMail(arbi)) return;
|
|
12026
|
+
await exclusive("arbi-mail-drafts", async () => {
|
|
12027
|
+
const uploaded = await syncLocalDrafts(
|
|
12028
|
+
({ accountId, compose }) => mailJson(
|
|
12029
|
+
(p, i) => arbi.mail.fetch(p, i),
|
|
12030
|
+
`${accountPath(accountId)}/drafts`,
|
|
12031
|
+
{
|
|
12032
|
+
method: "POST",
|
|
12033
|
+
body: JSON.stringify(compose)
|
|
12034
|
+
}
|
|
12035
|
+
)
|
|
12036
|
+
);
|
|
12037
|
+
if (uploaded > 0) {
|
|
12038
|
+
void queryClient.invalidateQueries({ queryKey: chunkU4PWVSCT_cjs.mailQueryKeys.allMessages() });
|
|
12039
|
+
chunkDZUBZ45Y_cjs.notify.success(
|
|
12040
|
+
uploaded === 1 ? "Your offline draft was saved to Drafts" : `${uploaded} offline drafts were saved to Drafts`
|
|
12041
|
+
);
|
|
12042
|
+
}
|
|
12043
|
+
});
|
|
12044
|
+
}
|
|
12045
|
+
var syncing = false;
|
|
12046
|
+
function isMailSyncRunning() {
|
|
12047
|
+
return syncing;
|
|
12048
|
+
}
|
|
12049
|
+
async function syncOfflineMailbox({ arbi }, options = {}) {
|
|
12050
|
+
const settings = getOfflineMailSettings(sessionUser(arbi));
|
|
12051
|
+
if (!settings.enabled || !canReachMail(arbi)) return;
|
|
12052
|
+
await exclusive("arbi-mail-sync", async () => {
|
|
12053
|
+
syncing = true;
|
|
12054
|
+
notifyOfflineMailChange("status");
|
|
12055
|
+
try {
|
|
12056
|
+
await syncMailbox(liveTransport(arbi), settings, options);
|
|
12057
|
+
} catch (error) {
|
|
12058
|
+
client.logger.error("[offline-mail] sync failed", error);
|
|
12059
|
+
} finally {
|
|
12060
|
+
syncing = false;
|
|
12061
|
+
notifyOfflineMailChange("status");
|
|
12062
|
+
}
|
|
12063
|
+
});
|
|
12064
|
+
}
|
|
12065
|
+
|
|
12066
|
+
// src/mail/offline/reads.ts
|
|
12067
|
+
var NOT_SAVED_HINT = 'Turn on "Keep my mailbox available offline" in Mail settings to read mail without a connection.';
|
|
12068
|
+
async function onlineFirst(online, offline, unavailable) {
|
|
12069
|
+
if (reactQuery.onlineManager.isOnline()) {
|
|
12070
|
+
try {
|
|
12071
|
+
return await online();
|
|
12072
|
+
} catch (error) {
|
|
12073
|
+
if (!isNetworkFailure(error)) throw error;
|
|
12074
|
+
}
|
|
12075
|
+
}
|
|
12076
|
+
const saved = await offline().catch(() => void 0);
|
|
12077
|
+
if (saved !== void 0) return saved;
|
|
12078
|
+
throw new MailOfflineUnavailableError(unavailable);
|
|
12079
|
+
}
|
|
12080
|
+
function offlineMailReads(getArbi, { keepsMail = () => true } = {}) {
|
|
12081
|
+
const call = (path) => mailJson((p, i) => getArbi().mail.fetch(p, i), path);
|
|
12082
|
+
const storeEnabled = () => getOfflineMailSettings(sessionUser(getArbi())).enabled;
|
|
12083
|
+
const remember = (write2) => {
|
|
12084
|
+
if (!keepsMail()) return;
|
|
12085
|
+
write2().catch((error) => client.logger.warn("[offline-mail] could not save for offline use", error));
|
|
12086
|
+
};
|
|
12087
|
+
return {
|
|
12088
|
+
getPolicy: () => onlineFirst(
|
|
12089
|
+
async () => {
|
|
12090
|
+
const policy = await call("/policy");
|
|
12091
|
+
remember(() => savePolicy(policy));
|
|
12092
|
+
return policy;
|
|
12093
|
+
},
|
|
12094
|
+
loadPolicy,
|
|
12095
|
+
"You're offline. Mail opens here once you've used it online on this device."
|
|
12096
|
+
),
|
|
12097
|
+
listAccounts: () => onlineFirst(
|
|
12098
|
+
async () => {
|
|
12099
|
+
const accounts = await call("/accounts");
|
|
12100
|
+
remember(() => saveAccounts(accounts));
|
|
12101
|
+
return accounts;
|
|
12102
|
+
},
|
|
12103
|
+
loadAccounts,
|
|
12104
|
+
"You're offline. Your mail accounts appear here once you've opened Mail online on this device."
|
|
12105
|
+
),
|
|
12106
|
+
listFolders: (account) => onlineFirst(
|
|
12107
|
+
async () => {
|
|
12108
|
+
const folders = await call(`${accountPath(account.id)}/folders`);
|
|
12109
|
+
if (storeEnabled()) remember(() => saveFolders(account.id, folders));
|
|
12110
|
+
return folders;
|
|
12111
|
+
},
|
|
12112
|
+
() => loadFolders(account.id),
|
|
12113
|
+
`You're offline and this mailbox isn't saved on this device. ${NOT_SAVED_HINT}`
|
|
12114
|
+
),
|
|
12115
|
+
listMessages: (account, folderId, query, cursor) => onlineFirst(
|
|
12116
|
+
async () => {
|
|
12117
|
+
const page = await call(
|
|
12118
|
+
`${accountPath(account.id)}/messages?${new URLSearchParams({ folder_id: folderId, q: query, ...cursor ? { cursor } : {} })}`
|
|
12119
|
+
);
|
|
12120
|
+
if (storeEnabled() && !query)
|
|
12121
|
+
remember(async () => {
|
|
12122
|
+
for (const message of page.messages) await saveHeader(account.id, folderId, message);
|
|
12123
|
+
});
|
|
12124
|
+
return page;
|
|
12125
|
+
},
|
|
12126
|
+
async () => {
|
|
12127
|
+
if (!await hasFolder(account.id)) return void 0;
|
|
12128
|
+
return { messages: await searchFolder(account.id, folderId, query), fromDevice: true };
|
|
12129
|
+
},
|
|
12130
|
+
`You're offline and this folder isn't saved on this device. ${NOT_SAVED_HINT}`
|
|
12131
|
+
),
|
|
12132
|
+
getMessage: (account, messageId) => onlineFirst(
|
|
12133
|
+
async () => {
|
|
12134
|
+
const message = await call(
|
|
12135
|
+
`${accountPath(account.id)}/messages/${encodeURIComponent(messageId)}`
|
|
12136
|
+
);
|
|
12137
|
+
if (storeEnabled()) remember(() => saveBody(account.id, message));
|
|
12138
|
+
return message;
|
|
12139
|
+
},
|
|
12140
|
+
() => loadBody(account.id, messageId),
|
|
12141
|
+
storeEnabled() ? "You're offline and this message hasn't been saved on this device yet." : `You're offline. ${NOT_SAVED_HINT}`
|
|
12142
|
+
)
|
|
12143
|
+
};
|
|
12144
|
+
}
|
|
12145
|
+
|
|
12146
|
+
// src/mail/offline/wipe.ts
|
|
12147
|
+
var OWNER_KEY2 = "owner";
|
|
12148
|
+
async function wipeOfflineMail() {
|
|
12149
|
+
forgetOfflineMailKeys();
|
|
12150
|
+
await deleteOfflineMailDatabase();
|
|
12151
|
+
notifyOfflineMailChange("wiped");
|
|
12152
|
+
}
|
|
12153
|
+
async function claimOfflineMail(userExtId) {
|
|
12154
|
+
const owner = await getMeta(OWNER_KEY2);
|
|
12155
|
+
if (owner && owner !== userExtId) await wipeOfflineMail();
|
|
12156
|
+
await setMeta(OWNER_KEY2, userExtId);
|
|
12157
|
+
}
|
|
12158
|
+
|
|
12159
|
+
// src/mail/offline/runtime.ts
|
|
12160
|
+
var SYNC_INTERVAL_MS = 5 * 60 * 1e3;
|
|
12161
|
+
var NEW_MAIL_DEBOUNCE_MS = 5e3;
|
|
12162
|
+
function useOfflineMailRuntime({ openOutbox } = {}) {
|
|
12163
|
+
const { user, status, serverSessionKey } = chunk2Y2WOIHH_cjs.useArbiSession();
|
|
12164
|
+
const userExtId = user?.external_id;
|
|
12165
|
+
const authenticated = status === "signed-in";
|
|
12166
|
+
const mailEnabled = chunkLUDIYWT7_cjs.useFeature("mail");
|
|
12167
|
+
const entitled = chunkLUDIYWT7_cjs.useIsEntitled("mail");
|
|
12168
|
+
const hasSession = !!serverSessionKey;
|
|
12169
|
+
const active = authenticated && mailEnabled && entitled && !!userExtId;
|
|
12170
|
+
const queryClient = reactQuery.useQueryClient();
|
|
12171
|
+
const arbi = chunkVGMMK5OM_cjs.useArbi();
|
|
12172
|
+
const latest = React.useRef({ arbi, queryClient, openOutbox });
|
|
12173
|
+
latest.current = { arbi, queryClient, openOutbox };
|
|
12174
|
+
React.useEffect(() => {
|
|
12175
|
+
if (!active || !userExtId) return;
|
|
12176
|
+
claimOfflineMail(userExtId).catch(
|
|
12177
|
+
(error) => client.logger.warn("[offline-mail] could not bind the store", error)
|
|
12178
|
+
);
|
|
12179
|
+
}, [active, userExtId]);
|
|
12180
|
+
React.useEffect(() => {
|
|
12181
|
+
if (!active || !hasSession) return;
|
|
12182
|
+
const context = () => latest.current;
|
|
12183
|
+
const catchUp = async () => {
|
|
12184
|
+
await flushOutbox(context());
|
|
12185
|
+
await uploadOfflineDrafts(context());
|
|
12186
|
+
await syncOfflineMailbox(context());
|
|
12187
|
+
};
|
|
12188
|
+
const run2 = () => {
|
|
12189
|
+
catchUp().catch((error) => client.logger.warn("[offline-mail] catch-up failed", error));
|
|
12190
|
+
};
|
|
12191
|
+
run2();
|
|
12192
|
+
let wasOnline = reactQuery.onlineManager.isOnline();
|
|
12193
|
+
const offOnline = reactQuery.onlineManager.subscribe((online) => {
|
|
12194
|
+
if (online && !wasOnline) run2();
|
|
12195
|
+
wasOnline = online;
|
|
12196
|
+
});
|
|
12197
|
+
const interval = setInterval(() => {
|
|
12198
|
+
if (document.visibilityState === "visible") void syncOfflineMailbox(context());
|
|
12199
|
+
}, SYNC_INTERVAL_MS);
|
|
12200
|
+
const enabled = () => getOfflineMailSettings(sessionUser(context().arbi)).enabled;
|
|
12201
|
+
let newMailTimer = null;
|
|
12202
|
+
const offCache = queryClient.getQueryCache().subscribe((event) => {
|
|
12203
|
+
if (event.type !== "updated" || event.action.type !== "invalidate") return;
|
|
12204
|
+
if (!chunkU4PWVSCT_cjs.isUnderQueryKey(event.query.queryKey, chunkU4PWVSCT_cjs.mailQueryKeys.all()) || !enabled()) return;
|
|
12205
|
+
if (newMailTimer) clearTimeout(newMailTimer);
|
|
12206
|
+
newMailTimer = setTimeout(() => void syncOfflineMailbox(context()), NEW_MAIL_DEBOUNCE_MS);
|
|
12207
|
+
});
|
|
12208
|
+
const offSettings = onOfflineMailChange((change) => {
|
|
12209
|
+
if (change === "settings" && enabled()) void syncOfflineMailbox(context(), { full: true });
|
|
12210
|
+
if (change === "outbox") void flushOutbox(context());
|
|
12211
|
+
if (change === "drafts") void uploadOfflineDrafts(context());
|
|
12212
|
+
});
|
|
12213
|
+
return () => {
|
|
12214
|
+
offOnline();
|
|
12215
|
+
clearInterval(interval);
|
|
12216
|
+
if (newMailTimer) clearTimeout(newMailTimer);
|
|
12217
|
+
offCache();
|
|
12218
|
+
offSettings();
|
|
12219
|
+
};
|
|
12220
|
+
}, [active, hasSession, queryClient]);
|
|
12221
|
+
}
|
|
12222
|
+
function useStoreValue(load, initial, changes) {
|
|
12223
|
+
const [value, setValue] = React.useState(initial);
|
|
12224
|
+
const key = changes.join(",");
|
|
12225
|
+
React.useEffect(() => {
|
|
12226
|
+
let alive = true;
|
|
12227
|
+
const read = () => load().then((next) => alive && setValue(next)).catch((error) => client.logger.warn("[offline-mail] read failed", error));
|
|
12228
|
+
void read();
|
|
12229
|
+
const off = onOfflineMailChange((change) => {
|
|
12230
|
+
if (change === "wiped") setValue(initial);
|
|
12231
|
+
if (change === "wiped" || key.split(",").includes(change)) void read();
|
|
12232
|
+
});
|
|
12233
|
+
return () => {
|
|
12234
|
+
alive = false;
|
|
12235
|
+
off();
|
|
12236
|
+
};
|
|
12237
|
+
}, [key, load, initial]);
|
|
12238
|
+
return value;
|
|
12239
|
+
}
|
|
12240
|
+
function useOfflineMailSettings() {
|
|
12241
|
+
const userExtId = chunk2Y2WOIHH_cjs.useArbiSession().user?.external_id;
|
|
12242
|
+
const subscribe = React.useCallback(
|
|
12243
|
+
(onChange) => onOfflineMailChange((change) => {
|
|
12244
|
+
if (change === "settings") onChange();
|
|
12245
|
+
}),
|
|
12246
|
+
[]
|
|
12247
|
+
);
|
|
12248
|
+
const raw = React.useSyncExternalStore(
|
|
12249
|
+
subscribe,
|
|
12250
|
+
() => JSON.stringify([userExtId, getOfflineMailSettings(userExtId)])
|
|
12251
|
+
);
|
|
12252
|
+
const settings = React.useMemo(() => JSON.parse(raw)[1], [raw]);
|
|
12253
|
+
const update2 = React.useCallback(
|
|
12254
|
+
(patch) => void setOfflineMailSettings(userExtId, patch),
|
|
12255
|
+
[userExtId]
|
|
12256
|
+
);
|
|
12257
|
+
return [settings, update2];
|
|
12258
|
+
}
|
|
12259
|
+
var EMPTY_STATUS = { messages: 0, bytes: 0, skipped: [] };
|
|
12260
|
+
function useOfflineMailStatus() {
|
|
12261
|
+
const status = useStoreValue(getOfflineMailStatus, EMPTY_STATUS, ["status", "mailbox"]);
|
|
12262
|
+
const [syncing2, setSyncing] = React.useState(isMailSyncRunning);
|
|
12263
|
+
React.useEffect(
|
|
12264
|
+
() => onOfflineMailChange((change) => {
|
|
12265
|
+
if (change === "status") setSyncing(isMailSyncRunning());
|
|
12266
|
+
}),
|
|
12267
|
+
[]
|
|
12268
|
+
);
|
|
12269
|
+
return { ...status, syncing: syncing2 };
|
|
12270
|
+
}
|
|
12271
|
+
var NO_ITEMS = [];
|
|
12272
|
+
function useOutbox(enabled = true) {
|
|
12273
|
+
const load = React.useCallback(() => enabled ? listOutbox() : Promise.resolve(NO_ITEMS), [enabled]);
|
|
12274
|
+
return useStoreValue(load, NO_ITEMS, ["outbox"]);
|
|
12275
|
+
}
|
|
12276
|
+
var NO_DRAFTS = [];
|
|
12277
|
+
function useLocalDrafts(accountId) {
|
|
12278
|
+
const load = React.useCallback(
|
|
12279
|
+
() => accountId ? listLocalDrafts(accountId) : Promise.resolve(NO_DRAFTS),
|
|
12280
|
+
[accountId]
|
|
12281
|
+
);
|
|
12282
|
+
return useStoreValue(load, NO_DRAFTS, ["drafts"]);
|
|
12283
|
+
}
|
|
12284
|
+
function useFlushOutbox() {
|
|
12285
|
+
const arbi = chunkVGMMK5OM_cjs.useArbi();
|
|
12286
|
+
const queryClient = reactQuery.useQueryClient();
|
|
12287
|
+
return React.useCallback(() => flushOutbox({ arbi, queryClient }), [arbi, queryClient]);
|
|
12288
|
+
}
|
|
12289
|
+
function useSyncOfflineMailbox() {
|
|
12290
|
+
const arbi = chunkVGMMK5OM_cjs.useArbi();
|
|
12291
|
+
return React.useCallback((options) => syncOfflineMailbox({ arbi }, options), [arbi]);
|
|
12292
|
+
}
|
|
12293
|
+
|
|
12294
|
+
// src/mail/offline/confirm-sign-out.ts
|
|
12295
|
+
async function confirmLosingOfflineMail(confirm) {
|
|
12296
|
+
const [outbox, drafts] = await Promise.all([
|
|
12297
|
+
listOutbox().catch(() => []),
|
|
12298
|
+
listLocalDrafts().catch(() => [])
|
|
12299
|
+
]);
|
|
12300
|
+
const unsent = outbox.filter((item) => item.status !== "sent").length;
|
|
12301
|
+
if (unsent === 0 && drafts.length === 0) return true;
|
|
12302
|
+
const parts = [
|
|
12303
|
+
unsent > 0 ? `${unsent} unsent ${unsent === 1 ? "message" : "messages"} in your Outbox` : "",
|
|
12304
|
+
drafts.length > 0 ? `${drafts.length} ${drafts.length === 1 ? "draft" : "drafts"} saved only on this device` : ""
|
|
12305
|
+
].filter(Boolean);
|
|
12306
|
+
return confirm({
|
|
12307
|
+
message: `You have ${parts.join(" and ")}. Signing out deletes ${unsent + drafts.length === 1 ? "it" : "them"} from this device. Reconnect first to send and save them.`,
|
|
12308
|
+
title: "Sign out and delete unsent mail?"
|
|
12309
|
+
});
|
|
12310
|
+
}
|
|
11118
12311
|
function useConnectorMutation(mutationFn) {
|
|
11119
12312
|
const qc = reactQuery.useQueryClient();
|
|
11120
12313
|
return reactQuery.useMutation({
|
|
@@ -11582,9 +12775,9 @@ function useDeleteCalendar() {
|
|
|
11582
12775
|
function useCreateEvent() {
|
|
11583
12776
|
const arbi = chunkVGMMK5OM_cjs.useArbi();
|
|
11584
12777
|
const qc = reactQuery.useQueryClient();
|
|
11585
|
-
const { write, networkMode } = useOfflineWrite();
|
|
12778
|
+
const { write: write2, networkMode } = useOfflineWrite();
|
|
11586
12779
|
return reactQuery.useMutation({
|
|
11587
|
-
mutationFn: (body) =>
|
|
12780
|
+
mutationFn: (body) => write2({ kind: "create", body }, () => arbi.calendar.createEvent(body)),
|
|
11588
12781
|
networkMode,
|
|
11589
12782
|
onSuccess: () => {
|
|
11590
12783
|
void invalidateCalendarEvents(qc);
|
|
@@ -11594,9 +12787,9 @@ function useCreateEvent() {
|
|
|
11594
12787
|
function useUpdateEvent() {
|
|
11595
12788
|
const arbi = chunkVGMMK5OM_cjs.useArbi();
|
|
11596
12789
|
const qc = reactQuery.useQueryClient();
|
|
11597
|
-
const { write, networkMode } = useOfflineWrite();
|
|
12790
|
+
const { write: write2, networkMode } = useOfflineWrite();
|
|
11598
12791
|
return reactQuery.useMutation({
|
|
11599
|
-
mutationFn: ({ target, body }) =>
|
|
12792
|
+
mutationFn: ({ target, body }) => write2({ kind: "update", target, body }, () => arbi.calendar.updateEvent(target, body)),
|
|
11600
12793
|
networkMode,
|
|
11601
12794
|
onSuccess: () => {
|
|
11602
12795
|
void invalidateCalendarEvents(qc);
|
|
@@ -11606,9 +12799,9 @@ function useUpdateEvent() {
|
|
|
11606
12799
|
function useDeleteEvent() {
|
|
11607
12800
|
const arbi = chunkVGMMK5OM_cjs.useArbi();
|
|
11608
12801
|
const qc = reactQuery.useQueryClient();
|
|
11609
|
-
const { write, networkMode } = useOfflineWrite();
|
|
12802
|
+
const { write: write2, networkMode } = useOfflineWrite();
|
|
11610
12803
|
return reactQuery.useMutation({
|
|
11611
|
-
mutationFn: (target) =>
|
|
12804
|
+
mutationFn: (target) => write2({ kind: "delete", target }, () => arbi.calendar.deleteEvent(target)),
|
|
11612
12805
|
networkMode,
|
|
11613
12806
|
onSuccess: () => {
|
|
11614
12807
|
void invalidateCalendarEvents(qc);
|
|
@@ -11628,9 +12821,9 @@ function useMoveEvent() {
|
|
|
11628
12821
|
function useRespondToEvent() {
|
|
11629
12822
|
const arbi = chunkVGMMK5OM_cjs.useArbi();
|
|
11630
12823
|
const qc = reactQuery.useQueryClient();
|
|
11631
|
-
const { write, networkMode } = useOfflineWrite();
|
|
12824
|
+
const { write: write2, networkMode } = useOfflineWrite();
|
|
11632
12825
|
return reactQuery.useMutation({
|
|
11633
|
-
mutationFn: (params) =>
|
|
12826
|
+
mutationFn: (params) => write2({ kind: "respond", params }, () => arbi.calendar.respond(params)),
|
|
11634
12827
|
networkMode,
|
|
11635
12828
|
onSuccess: () => {
|
|
11636
12829
|
void invalidateCalendarEvents(qc);
|
|
@@ -11870,7 +13063,7 @@ function useSyncAccountsOnOpen(enabled = true) {
|
|
|
11870
13063
|
const arbi = chunkVGMMK5OM_cjs.useArbi();
|
|
11871
13064
|
const { data: accounts } = useCalendarAccounts(enabled);
|
|
11872
13065
|
const qc = reactQuery.useQueryClient();
|
|
11873
|
-
const [
|
|
13066
|
+
const [syncing2, setSyncing] = React.useState(false);
|
|
11874
13067
|
React.useEffect(() => {
|
|
11875
13068
|
if (!enabled || !accounts?.length) return;
|
|
11876
13069
|
const due = accounts.filter((a) => !syncedThisSession.has(a.id));
|
|
@@ -11882,7 +13075,7 @@ function useSyncAccountsOnOpen(enabled = true) {
|
|
|
11882
13075
|
void invalidateAccounts(qc);
|
|
11883
13076
|
});
|
|
11884
13077
|
}, [enabled, accounts, arbi, qc]);
|
|
11885
|
-
return { syncing };
|
|
13078
|
+
return { syncing: syncing2 };
|
|
11886
13079
|
}
|
|
11887
13080
|
function useBookingPages(enabled = true) {
|
|
11888
13081
|
const arbi = chunkVGMMK5OM_cjs.useArbi();
|
|
@@ -11910,6 +13103,349 @@ function useDeleteBookingPage() {
|
|
|
11910
13103
|
onSuccess: () => qc.invalidateQueries({ queryKey: chunkU4PWVSCT_cjs.calendarQueryKeys.bookingPages() })
|
|
11911
13104
|
});
|
|
11912
13105
|
}
|
|
13106
|
+
|
|
13107
|
+
// src/offline-store/wipe.ts
|
|
13108
|
+
async function wipeStore(sealer3, store3) {
|
|
13109
|
+
sealer3.forget();
|
|
13110
|
+
await store3.deleteDatabase();
|
|
13111
|
+
}
|
|
13112
|
+
|
|
13113
|
+
// src/calendar/offline/outbox.ts
|
|
13114
|
+
var OFFLINE_CALENDAR_DB = "arbi-offline-calendar";
|
|
13115
|
+
var CACHE_LIMIT = 200;
|
|
13116
|
+
var OfflineCalendarLockedError = class extends Error {
|
|
13117
|
+
constructor() {
|
|
13118
|
+
super("Sign in to open the calendar saved on this device");
|
|
13119
|
+
this.name = "OfflineCalendarLockedError";
|
|
13120
|
+
}
|
|
13121
|
+
};
|
|
13122
|
+
var store2 = createRecordStore(OFFLINE_CALENDAR_DB);
|
|
13123
|
+
var sealer2 = client.createOfflineSealer("arbi-offline-calendar-v1", {
|
|
13124
|
+
locked: () => new OfflineCalendarLockedError()
|
|
13125
|
+
});
|
|
13126
|
+
function isCalendarOffline() {
|
|
13127
|
+
return isBrowserOffline();
|
|
13128
|
+
}
|
|
13129
|
+
function isCalendarNetworkError(error) {
|
|
13130
|
+
if (isNetworkFailure(error)) return true;
|
|
13131
|
+
const status = error?.status;
|
|
13132
|
+
return typeof status !== "number" && isBrowserOffline();
|
|
13133
|
+
}
|
|
13134
|
+
var cacheBucket = () => sealer2.blind("bucket", "cache");
|
|
13135
|
+
var cacheKey = (key) => sealer2.blind("cache", key);
|
|
13136
|
+
async function writeCalendarCache(key, data) {
|
|
13137
|
+
const sealed = await sealer2.sealJson({ key, data });
|
|
13138
|
+
const now = Date.now();
|
|
13139
|
+
await store2.putRecord({
|
|
13140
|
+
key: await cacheKey(key),
|
|
13141
|
+
kind: "cache",
|
|
13142
|
+
bucket: await cacheBucket(),
|
|
13143
|
+
sortAt: now,
|
|
13144
|
+
size: sealed.length,
|
|
13145
|
+
lastAccess: now,
|
|
13146
|
+
data: sealed
|
|
13147
|
+
});
|
|
13148
|
+
await evictCache();
|
|
13149
|
+
}
|
|
13150
|
+
async function readCalendarCache(key) {
|
|
13151
|
+
try {
|
|
13152
|
+
const blindKey = await cacheKey(key);
|
|
13153
|
+
const record = await store2.getRecord(blindKey);
|
|
13154
|
+
if (!record) return null;
|
|
13155
|
+
const opened = await sealer2.openJson(record.data);
|
|
13156
|
+
if (opened.key !== key) return null;
|
|
13157
|
+
await store2.putRecord({ ...record, lastAccess: Date.now() });
|
|
13158
|
+
return opened.data;
|
|
13159
|
+
} catch {
|
|
13160
|
+
return null;
|
|
13161
|
+
}
|
|
13162
|
+
}
|
|
13163
|
+
async function evictCache() {
|
|
13164
|
+
const rows = (await store2.allRecordAccess()).filter((r) => r.kind === "cache");
|
|
13165
|
+
if (rows.length <= CACHE_LIMIT) return;
|
|
13166
|
+
rows.sort((a, b) => a.lastAccess - b.lastAccess);
|
|
13167
|
+
await store2.deleteRecords(rows.slice(0, rows.length - CACHE_LIMIT).map((r) => r.key));
|
|
13168
|
+
}
|
|
13169
|
+
var outboxBucket = () => sealer2.blind("bucket", "outbox");
|
|
13170
|
+
var outboxKey = (requestId) => sealer2.blind("outbox", requestId);
|
|
13171
|
+
var seqCounter2 = 0;
|
|
13172
|
+
async function writeItem(item) {
|
|
13173
|
+
const sealed = await sealer2.sealJson(item);
|
|
13174
|
+
await store2.putRecord({
|
|
13175
|
+
key: await outboxKey(item.requestId),
|
|
13176
|
+
kind: "outbox",
|
|
13177
|
+
bucket: await outboxBucket(),
|
|
13178
|
+
sortAt: item.seq,
|
|
13179
|
+
size: sealed.length,
|
|
13180
|
+
lastAccess: Date.now(),
|
|
13181
|
+
data: sealed
|
|
13182
|
+
});
|
|
13183
|
+
}
|
|
13184
|
+
async function readItems() {
|
|
13185
|
+
const records = await store2.recordsInBucket(await outboxBucket());
|
|
13186
|
+
const items = [];
|
|
13187
|
+
for (const record of records) {
|
|
13188
|
+
try {
|
|
13189
|
+
items.push(await sealer2.openJson(record.data));
|
|
13190
|
+
} catch {
|
|
13191
|
+
}
|
|
13192
|
+
}
|
|
13193
|
+
return items.sort((a, b) => a.seq - b.seq);
|
|
13194
|
+
}
|
|
13195
|
+
function newRequestId() {
|
|
13196
|
+
return typeof crypto !== "undefined" && "randomUUID" in crypto ? crypto.randomUUID() : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
13197
|
+
}
|
|
13198
|
+
async function enqueueCalendarWrite(op) {
|
|
13199
|
+
const now = Date.now();
|
|
13200
|
+
seqCounter2 = Math.max(seqCounter2 + 1, now * 1e3);
|
|
13201
|
+
const item = {
|
|
13202
|
+
requestId: newRequestId(),
|
|
13203
|
+
op,
|
|
13204
|
+
state: "queued",
|
|
13205
|
+
attempts: 0,
|
|
13206
|
+
createdAt: now,
|
|
13207
|
+
seq: seqCounter2
|
|
13208
|
+
};
|
|
13209
|
+
await writeItem(item);
|
|
13210
|
+
notify2("enqueued");
|
|
13211
|
+
return { requestId: item.requestId };
|
|
13212
|
+
}
|
|
13213
|
+
async function listCalendarOutbox() {
|
|
13214
|
+
try {
|
|
13215
|
+
return (await readItems()).map(({ requestId, op, state, inDoubt, error }) => ({
|
|
13216
|
+
requestId,
|
|
13217
|
+
op,
|
|
13218
|
+
state,
|
|
13219
|
+
inDoubt,
|
|
13220
|
+
error
|
|
13221
|
+
}));
|
|
13222
|
+
} catch {
|
|
13223
|
+
return [];
|
|
13224
|
+
}
|
|
13225
|
+
}
|
|
13226
|
+
function classify2(error) {
|
|
13227
|
+
if (isCalendarNetworkError(error)) return "offline";
|
|
13228
|
+
const status = error?.status;
|
|
13229
|
+
if (typeof status === "number" && status >= 500) return "retry";
|
|
13230
|
+
return "failed";
|
|
13231
|
+
}
|
|
13232
|
+
function run(exec, item) {
|
|
13233
|
+
const op = item.op;
|
|
13234
|
+
switch (op.kind) {
|
|
13235
|
+
case "create":
|
|
13236
|
+
return exec.create(op.body, item.requestId);
|
|
13237
|
+
case "update":
|
|
13238
|
+
return exec.update(op.target, op.body, item.requestId);
|
|
13239
|
+
case "delete":
|
|
13240
|
+
return exec.delete(op.target, item.requestId);
|
|
13241
|
+
case "respond":
|
|
13242
|
+
return exec.respond(op.params, item.requestId);
|
|
13243
|
+
}
|
|
13244
|
+
}
|
|
13245
|
+
var replaying = null;
|
|
13246
|
+
function replayCalendarOutbox(exec) {
|
|
13247
|
+
if (replaying) return replaying;
|
|
13248
|
+
const locks = typeof navigator !== "undefined" ? navigator.locks : void 0;
|
|
13249
|
+
const run2 = locks?.request ? locks.request(
|
|
13250
|
+
"arbi-calendar-outbox-replay",
|
|
13251
|
+
() => replayOnce(exec)
|
|
13252
|
+
) : replayOnce(exec);
|
|
13253
|
+
const current = run2.finally(() => {
|
|
13254
|
+
replaying = null;
|
|
13255
|
+
});
|
|
13256
|
+
replaying = current;
|
|
13257
|
+
return current;
|
|
13258
|
+
}
|
|
13259
|
+
async function replayOnce(exec) {
|
|
13260
|
+
const result = { sent: 0, failed: 0, inDoubt: 0 };
|
|
13261
|
+
for (const queued of await readItems()) {
|
|
13262
|
+
if (queued.state !== "queued" && queued.state !== "sending") continue;
|
|
13263
|
+
if (isCalendarOffline()) break;
|
|
13264
|
+
let item = {
|
|
13265
|
+
...queued,
|
|
13266
|
+
inDoubt: queued.inDoubt || queued.state === "sending"
|
|
13267
|
+
};
|
|
13268
|
+
if (item.op.kind === "create" && item.inDoubt && exec.findCreated) {
|
|
13269
|
+
let found = false;
|
|
13270
|
+
try {
|
|
13271
|
+
found = await exec.findCreated(item.requestId, item.op.body);
|
|
13272
|
+
} catch (error) {
|
|
13273
|
+
if (classify2(error) === "offline") break;
|
|
13274
|
+
}
|
|
13275
|
+
if (found) {
|
|
13276
|
+
await store2.deleteRecords([await outboxKey(item.requestId)]);
|
|
13277
|
+
result.sent++;
|
|
13278
|
+
continue;
|
|
13279
|
+
}
|
|
13280
|
+
}
|
|
13281
|
+
item = { ...item, state: "sending", attempts: item.attempts + 1 };
|
|
13282
|
+
await writeItem(item);
|
|
13283
|
+
let outcome;
|
|
13284
|
+
let message;
|
|
13285
|
+
try {
|
|
13286
|
+
await run(exec, item);
|
|
13287
|
+
outcome = "sent";
|
|
13288
|
+
} catch (error) {
|
|
13289
|
+
outcome = classify2(error);
|
|
13290
|
+
message = error instanceof Error ? error.message : "The change could not be saved";
|
|
13291
|
+
}
|
|
13292
|
+
if (outcome === "sent") {
|
|
13293
|
+
await store2.deleteRecords([await outboxKey(item.requestId)]);
|
|
13294
|
+
result.sent++;
|
|
13295
|
+
continue;
|
|
13296
|
+
}
|
|
13297
|
+
if (outcome === "failed") {
|
|
13298
|
+
await writeItem({ ...item, state: "failed", error: message });
|
|
13299
|
+
result.failed++;
|
|
13300
|
+
continue;
|
|
13301
|
+
}
|
|
13302
|
+
const inDoubt = item.inDoubt || item.op.kind === "create";
|
|
13303
|
+
await writeItem({ ...item, state: "queued", inDoubt, error: message });
|
|
13304
|
+
if (inDoubt) result.inDoubt++;
|
|
13305
|
+
if (outcome === "offline") break;
|
|
13306
|
+
}
|
|
13307
|
+
notify2();
|
|
13308
|
+
return result;
|
|
13309
|
+
}
|
|
13310
|
+
var listeners2 = /* @__PURE__ */ new Set();
|
|
13311
|
+
function notify2(change = "changed") {
|
|
13312
|
+
for (const l of listeners2) l(change);
|
|
13313
|
+
}
|
|
13314
|
+
function onCalendarOutboxChange(listener) {
|
|
13315
|
+
listeners2.add(listener);
|
|
13316
|
+
return () => listeners2.delete(listener);
|
|
13317
|
+
}
|
|
13318
|
+
async function wipeCalendarOffline() {
|
|
13319
|
+
await wipeStore(sealer2, store2);
|
|
13320
|
+
notify2();
|
|
13321
|
+
}
|
|
13322
|
+
async function claimCalendarOffline(userExtId) {
|
|
13323
|
+
const owner = await store2.getMeta("owner");
|
|
13324
|
+
if (owner && owner !== userExtId) await wipeCalendarOffline();
|
|
13325
|
+
await store2.setMeta("owner", userExtId);
|
|
13326
|
+
}
|
|
13327
|
+
|
|
13328
|
+
// src/calendar/offline/support.ts
|
|
13329
|
+
var calendarOfflineSupport = {
|
|
13330
|
+
async read(key, fetch2) {
|
|
13331
|
+
const cacheKey2 = JSON.stringify(key);
|
|
13332
|
+
if (!isCalendarOffline()) {
|
|
13333
|
+
try {
|
|
13334
|
+
const data = await fetch2();
|
|
13335
|
+
void writeCalendarCache(cacheKey2, data).catch(() => {
|
|
13336
|
+
});
|
|
13337
|
+
return data;
|
|
13338
|
+
} catch (err) {
|
|
13339
|
+
if (!isCalendarNetworkError(err)) throw err;
|
|
13340
|
+
}
|
|
13341
|
+
}
|
|
13342
|
+
const cached = await readCalendarCache(cacheKey2).catch(
|
|
13343
|
+
() => null
|
|
13344
|
+
);
|
|
13345
|
+
if (cached != null) return cached;
|
|
13346
|
+
throw new browser.ArbiApiError("You are offline and this view is not saved on this device");
|
|
13347
|
+
},
|
|
13348
|
+
async write(op, send) {
|
|
13349
|
+
if (!isCalendarOffline()) return send();
|
|
13350
|
+
const { requestId } = await enqueueCalendarWrite(op);
|
|
13351
|
+
return { queued: true, requestId };
|
|
13352
|
+
},
|
|
13353
|
+
pending: listCalendarOutbox,
|
|
13354
|
+
subscribe: (listener) => onCalendarOutboxChange(() => listener())
|
|
13355
|
+
};
|
|
13356
|
+
var day = (date, offset) => {
|
|
13357
|
+
const t = /* @__PURE__ */ new Date(`${date}T00:00:00Z`);
|
|
13358
|
+
t.setUTCDate(t.getUTCDate() + offset);
|
|
13359
|
+
return t.toISOString();
|
|
13360
|
+
};
|
|
13361
|
+
var calendarOutboxExecutor = (arbi) => ({
|
|
13362
|
+
create: (body) => arbi.calendar.createEvent(body),
|
|
13363
|
+
update: (target, body) => arbi.calendar.updateEvent(target, body),
|
|
13364
|
+
delete: (target) => arbi.calendar.deleteEvent(target),
|
|
13365
|
+
respond: (params) => arbi.calendar.respond(params),
|
|
13366
|
+
/** No server dedupe: an in-doubt create counts as made if an event with its title and start exists. */
|
|
13367
|
+
async findCreated(_requestId, body) {
|
|
13368
|
+
const { title, start } = body;
|
|
13369
|
+
const date = (start?.date_time ?? start?.date ?? "").slice(0, 10);
|
|
13370
|
+
if (!title || !/^\d{4}-\d{2}-\d{2}$/.test(date)) return false;
|
|
13371
|
+
const events = await arbi.calendar.listEvents({
|
|
13372
|
+
start: day(date, -1),
|
|
13373
|
+
end: day(date, 2)
|
|
13374
|
+
});
|
|
13375
|
+
return events.some(
|
|
13376
|
+
(e) => e.title === title && (start?.date_time ? (e.start.date_time ?? "").slice(0, 16) === start.date_time.slice(0, 16) : e.start.date === start?.date)
|
|
13377
|
+
);
|
|
13378
|
+
}
|
|
13379
|
+
});
|
|
13380
|
+
var SYNC_CHANNEL = "arbi-calendar-outbox";
|
|
13381
|
+
function refreshCalendarQueries(queryClient) {
|
|
13382
|
+
void queryClient.invalidateQueries({ queryKey: chunkU4PWVSCT_cjs.calendarQueryKeys.all() });
|
|
13383
|
+
}
|
|
13384
|
+
async function replay(arbi, queryClient) {
|
|
13385
|
+
const result = await replayCalendarOutbox(calendarOutboxExecutor(arbi));
|
|
13386
|
+
if (result.sent || result.failed) {
|
|
13387
|
+
refreshCalendarQueries(queryClient);
|
|
13388
|
+
try {
|
|
13389
|
+
const channel2 = new BroadcastChannel(SYNC_CHANNEL);
|
|
13390
|
+
channel2.postMessage("synced");
|
|
13391
|
+
channel2.close();
|
|
13392
|
+
} catch {
|
|
13393
|
+
}
|
|
13394
|
+
}
|
|
13395
|
+
if (result.failed)
|
|
13396
|
+
chunkDZUBZ45Y_cjs.notify.error(
|
|
13397
|
+
result.failed === 1 ? "A calendar change made offline could not be saved" : `${result.failed} calendar changes made offline could not be saved`
|
|
13398
|
+
);
|
|
13399
|
+
}
|
|
13400
|
+
function useCalendarOfflineRuntime() {
|
|
13401
|
+
const { status, serverSessionKey, user } = chunk2Y2WOIHH_cjs.useArbiSession();
|
|
13402
|
+
const userExtId = user?.external_id;
|
|
13403
|
+
const authenticated = status === "signed-in";
|
|
13404
|
+
const hasSession = !!serverSessionKey;
|
|
13405
|
+
const arbi = chunkVGMMK5OM_cjs.useArbi();
|
|
13406
|
+
const ready = authenticated && hasSession && arbi.isLoggedIn;
|
|
13407
|
+
const queryClient = reactQuery.useQueryClient();
|
|
13408
|
+
React.useEffect(() => {
|
|
13409
|
+
if (!authenticated || !userExtId) return;
|
|
13410
|
+
claimCalendarOffline(userExtId).catch(
|
|
13411
|
+
(error) => client.logger.warn("[offline-calendar] could not bind the store", error)
|
|
13412
|
+
);
|
|
13413
|
+
}, [authenticated, userExtId]);
|
|
13414
|
+
React.useEffect(() => {
|
|
13415
|
+
if (!ready) return;
|
|
13416
|
+
const run2 = () => {
|
|
13417
|
+
if (!reactQuery.onlineManager.isOnline()) return;
|
|
13418
|
+
replay(arbi, queryClient).catch(
|
|
13419
|
+
(error) => client.logger.warn("[offline-calendar] replay failed", error)
|
|
13420
|
+
);
|
|
13421
|
+
};
|
|
13422
|
+
run2();
|
|
13423
|
+
let wasOnline = reactQuery.onlineManager.isOnline();
|
|
13424
|
+
const offOnline = reactQuery.onlineManager.subscribe((online) => {
|
|
13425
|
+
if (online && !wasOnline) run2();
|
|
13426
|
+
wasOnline = online;
|
|
13427
|
+
});
|
|
13428
|
+
let queued = null;
|
|
13429
|
+
const offOutbox = onCalendarOutboxChange((change) => {
|
|
13430
|
+
if (change !== "enqueued") return;
|
|
13431
|
+
if (queued) clearTimeout(queued);
|
|
13432
|
+
queued = setTimeout(run2, 2e3);
|
|
13433
|
+
});
|
|
13434
|
+
let channel2 = null;
|
|
13435
|
+
try {
|
|
13436
|
+
channel2 = new BroadcastChannel(SYNC_CHANNEL);
|
|
13437
|
+
channel2.onmessage = () => refreshCalendarQueries(queryClient);
|
|
13438
|
+
} catch {
|
|
13439
|
+
channel2 = null;
|
|
13440
|
+
}
|
|
13441
|
+
return () => {
|
|
13442
|
+
channel2?.close();
|
|
13443
|
+
offOnline();
|
|
13444
|
+
offOutbox();
|
|
13445
|
+
if (queued) clearTimeout(queued);
|
|
13446
|
+
};
|
|
13447
|
+
}, [ready, arbi, queryClient]);
|
|
13448
|
+
}
|
|
11913
13449
|
function useWorkspaceDocs(workspaceId) {
|
|
11914
13450
|
const { data: docs = [], isLoading, isError } = chunkQ6U7ALNV_cjs.useDocuments(workspaceId);
|
|
11915
13451
|
const docIds = React.useMemo(
|
|
@@ -11938,7 +13474,7 @@ function useAiTask() {
|
|
|
11938
13474
|
artifactsRef.current = /* @__PURE__ */ new Map();
|
|
11939
13475
|
bufferRef.current = "";
|
|
11940
13476
|
}, []);
|
|
11941
|
-
const
|
|
13477
|
+
const run2 = React.useCallback(
|
|
11942
13478
|
async (question, docIds, opts) => {
|
|
11943
13479
|
setStatus("running");
|
|
11944
13480
|
setText("");
|
|
@@ -12006,7 +13542,7 @@ function useAiTask() {
|
|
|
12006
13542
|
error,
|
|
12007
13543
|
responseId,
|
|
12008
13544
|
artifacts,
|
|
12009
|
-
run,
|
|
13545
|
+
run: run2,
|
|
12010
13546
|
reset,
|
|
12011
13547
|
isRunning: status === "running",
|
|
12012
13548
|
isDone: status === "done"
|
|
@@ -12444,13 +13980,13 @@ function useSemanticSearch(docIds = [], options = {}) {
|
|
|
12444
13980
|
chunkAXKHDLBB_cjs.clearSearchSession(void 0, session);
|
|
12445
13981
|
return;
|
|
12446
13982
|
}
|
|
12447
|
-
const
|
|
13983
|
+
const run2 = session.getState().run + 1;
|
|
12448
13984
|
const searched = workspaceId ?? session.getState().workspaceId ?? void 0;
|
|
12449
13985
|
session.setState((s) => ({
|
|
12450
13986
|
query: trimmed,
|
|
12451
13987
|
status: "running",
|
|
12452
13988
|
error: null,
|
|
12453
|
-
run,
|
|
13989
|
+
run: run2,
|
|
12454
13990
|
workspaceId: workspaceId ?? s.workspaceId
|
|
12455
13991
|
}));
|
|
12456
13992
|
try {
|
|
@@ -12460,10 +13996,10 @@ function useSemanticSearch(docIds = [], options = {}) {
|
|
|
12460
13996
|
...model ? { model } : {},
|
|
12461
13997
|
...searched ? { workspaceId: searched } : {}
|
|
12462
13998
|
});
|
|
12463
|
-
if (session.getState().run !==
|
|
13999
|
+
if (session.getState().run !== run2) return;
|
|
12464
14000
|
session.setState({ results: browser.searchChunks(result), searched: true, status: "done" });
|
|
12465
14001
|
} catch (error) {
|
|
12466
|
-
if (session.getState().run !==
|
|
14002
|
+
if (session.getState().run !== run2) return;
|
|
12467
14003
|
session.setState({
|
|
12468
14004
|
status: "error",
|
|
12469
14005
|
error: error instanceof Error ? error.message : "Search failed"
|
|
@@ -12666,7 +14202,7 @@ var CitationRendererComponent = ({
|
|
|
12666
14202
|
useCitationState,
|
|
12667
14203
|
onCloseCitation,
|
|
12668
14204
|
onDismissCitation,
|
|
12669
|
-
notify:
|
|
14205
|
+
notify: notify3,
|
|
12670
14206
|
docTitles
|
|
12671
14207
|
}) => {
|
|
12672
14208
|
const chunkMap = React.useMemo(() => {
|
|
@@ -12710,7 +14246,7 @@ var CitationRendererComponent = ({
|
|
|
12710
14246
|
useCitationState,
|
|
12711
14247
|
onCloseCitation,
|
|
12712
14248
|
onDismissCitation,
|
|
12713
|
-
notify:
|
|
14249
|
+
notify: notify3
|
|
12714
14250
|
}),
|
|
12715
14251
|
[
|
|
12716
14252
|
citations,
|
|
@@ -12723,7 +14259,7 @@ var CitationRendererComponent = ({
|
|
|
12723
14259
|
useCitationState,
|
|
12724
14260
|
onCloseCitation,
|
|
12725
14261
|
onDismissCitation,
|
|
12726
|
-
|
|
14262
|
+
notify3
|
|
12727
14263
|
]
|
|
12728
14264
|
);
|
|
12729
14265
|
return /* @__PURE__ */ jsxRuntime.jsx(CitationAnchorContext.Provider, { value: anchorContext, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: chunkS6A6FSG7_cjs.cn("citation-container", className), "data-testid": "citation-renderer", children: renderMarkdown({
|
|
@@ -12782,7 +14318,7 @@ var CitationPopover = ({
|
|
|
12782
14318
|
useCitationState,
|
|
12783
14319
|
onCloseCitation,
|
|
12784
14320
|
onDismissCitation,
|
|
12785
|
-
notify:
|
|
14321
|
+
notify: notify3,
|
|
12786
14322
|
children
|
|
12787
14323
|
}) => {
|
|
12788
14324
|
const { activeCitationKey, viewingPassageId, isOnConversationPage } = useCitationState();
|
|
@@ -12856,11 +14392,11 @@ var CitationPopover = ({
|
|
|
12856
14392
|
const source = [firstTitle, firstPage != null ? `p.${firstPage}` : null].filter(Boolean).join(", ");
|
|
12857
14393
|
try {
|
|
12858
14394
|
await navigator.clipboard.writeText(source ? `\u201C${firstText}\u201D (${source})` : firstText);
|
|
12859
|
-
|
|
14395
|
+
notify3?.("Citation copied", "success");
|
|
12860
14396
|
} catch {
|
|
12861
|
-
|
|
14397
|
+
notify3?.("Could not copy the citation", "error");
|
|
12862
14398
|
}
|
|
12863
|
-
}, [firstText, firstTitle, firstPage,
|
|
14399
|
+
}, [firstText, firstTitle, firstPage, notify3]);
|
|
12864
14400
|
const items = isStreaming || chunks.length === 0 ? [] : [
|
|
12865
14401
|
{
|
|
12866
14402
|
id: "open",
|
|
@@ -14573,12 +16109,12 @@ function annotateThread(messages, accessors, runWindowMs = RUN_WINDOW_MS) {
|
|
|
14573
16109
|
return messages.map((message, i) => {
|
|
14574
16110
|
const next = messages[i + 1];
|
|
14575
16111
|
const prev = messages[i - 1];
|
|
14576
|
-
const
|
|
14577
|
-
const continuesIntoNext = !!next && senderId(next) === senderId(message) && dayKey(createdAt(next)) ===
|
|
16112
|
+
const day2 = dayKey(createdAt(message));
|
|
16113
|
+
const continuesIntoNext = !!next && senderId(next) === senderId(message) && dayKey(createdAt(next)) === day2 && Date.parse(createdAt(next)) - Date.parse(createdAt(message)) < runWindowMs;
|
|
14578
16114
|
return {
|
|
14579
16115
|
message,
|
|
14580
16116
|
isLastOfRun: !continuesIntoNext,
|
|
14581
|
-
isFirstOfDay: !prev || dayKey(createdAt(prev)) !==
|
|
16117
|
+
isFirstOfDay: !prev || dayKey(createdAt(prev)) !== day2
|
|
14582
16118
|
};
|
|
14583
16119
|
});
|
|
14584
16120
|
}
|
|
@@ -17639,6 +19175,7 @@ exports.MIN_NARRATION_DWELL_MS = MIN_NARRATION_DWELL_MS;
|
|
|
17639
19175
|
exports.MODEL_GROUP_LABELS = MODEL_GROUP_LABELS;
|
|
17640
19176
|
exports.MailOfflineUnavailableError = MailOfflineUnavailableError;
|
|
17641
19177
|
exports.MessageArtifactCard = MessageArtifactCard;
|
|
19178
|
+
exports.OUTBOX_FOLDER = OUTBOX_FOLDER;
|
|
17642
19179
|
exports.PENDING_SYNC_PREDICATE = PENDING_SYNC_PREDICATE;
|
|
17643
19180
|
exports.POLL_EVERY_MS = POLL_EVERY_MS;
|
|
17644
19181
|
exports.PhotoCapture = PhotoCapture;
|
|
@@ -17693,6 +19230,7 @@ exports.cachedAssistantMode = cachedAssistantMode;
|
|
|
17693
19230
|
exports.cachedMentionCandidates = cachedMentionCandidates;
|
|
17694
19231
|
exports.cachedQuotaUsedUp = cachedQuotaUsedUp;
|
|
17695
19232
|
exports.calendarNotificationMeta = calendarNotificationMeta;
|
|
19233
|
+
exports.calendarOfflineSupport = calendarOfflineSupport;
|
|
17696
19234
|
exports.callNotificationMeta = callNotificationMeta;
|
|
17697
19235
|
exports.captureFrameAsBlob = captureFrameAsBlob;
|
|
17698
19236
|
exports.claimOfflineQueue = claimOfflineQueue;
|
|
@@ -17701,6 +19239,7 @@ exports.clearUserInputRequest = clearUserInputRequest;
|
|
|
17701
19239
|
exports.commitFinalMessage = commitFinalMessage;
|
|
17702
19240
|
exports.completeQueuedUserMessageByContent = completeQueuedUserMessageByContent;
|
|
17703
19241
|
exports.computeOnline = computeOnline;
|
|
19242
|
+
exports.confirmLosingOfflineMail = confirmLosingOfflineMail;
|
|
17704
19243
|
exports.connectOAuthCalendarAccount = connectOAuthCalendarAccount;
|
|
17705
19244
|
exports.connectorErrorStatus = connectorErrorStatus;
|
|
17706
19245
|
exports.connectorReturnTo = connectorReturnTo;
|
|
@@ -17721,6 +19260,8 @@ exports.cropImage = cropImage;
|
|
|
17721
19260
|
exports.dayKey = dayKey;
|
|
17722
19261
|
exports.defaultMailAlias = defaultMailAlias;
|
|
17723
19262
|
exports.defineRowsSource = defineRowsSource;
|
|
19263
|
+
exports.deleteLocalDraft = deleteLocalDraft;
|
|
19264
|
+
exports.deleteOutboxItem = deleteOutboxItem;
|
|
17724
19265
|
exports.deploymentUserMeta = deploymentUserMeta;
|
|
17725
19266
|
exports.describeActivity = describeActivity;
|
|
17726
19267
|
exports.describeCalendarNotification = describeCalendarNotification;
|
|
@@ -17732,6 +19273,7 @@ exports.documentActivityPhrase = documentActivityPhrase;
|
|
|
17732
19273
|
exports.documentDisplayName = documentDisplayName;
|
|
17733
19274
|
exports.docxMentionMeta = docxMentionMeta;
|
|
17734
19275
|
exports.downloadRecoveryFile = downloadRecoveryFile;
|
|
19276
|
+
exports.enqueueOutbox = enqueueOutbox;
|
|
17735
19277
|
exports.ensureAssistantMessageLoading = ensureAssistantMessageLoading;
|
|
17736
19278
|
exports.extractZipFile = extractZipFile;
|
|
17737
19279
|
exports.fallbackFileName = fallbackFileName;
|
|
@@ -17769,6 +19311,7 @@ exports.isDeploymentAdmin = isDeploymentAdmin;
|
|
|
17769
19311
|
exports.isDeploymentUserNotification = isDeploymentUserNotification;
|
|
17770
19312
|
exports.isFullConfig = isFullConfig;
|
|
17771
19313
|
exports.isMessageRunning = isMessageRunning;
|
|
19314
|
+
exports.isNetworkFailure = isNetworkFailure;
|
|
17772
19315
|
exports.isNotificationRow = isNotificationRow;
|
|
17773
19316
|
exports.isOrphanedUserMessage = isOrphanedUserMessage;
|
|
17774
19317
|
exports.isQueuedCalendarWrite = isQueuedCalendarWrite;
|
|
@@ -17782,6 +19325,7 @@ exports.isWorkspaceArchivedError = isWorkspaceArchivedError;
|
|
|
17782
19325
|
exports.isWorkspaceNotificationType = isWorkspaceNotificationType;
|
|
17783
19326
|
exports.isZipFile = isZipFile;
|
|
17784
19327
|
exports.loadOfflineDocument = loadOfflineDocument;
|
|
19328
|
+
exports.loadOfflineMailAttachment = loadAttachment;
|
|
17785
19329
|
exports.mailDraftIdFromContent = mailDraftIdFromContent;
|
|
17786
19330
|
exports.mailJson = mailJson;
|
|
17787
19331
|
exports.markMessageAsFailed = markMessageAsFailed;
|
|
@@ -17790,6 +19334,7 @@ exports.migrateLegacyThreadDocuments = migrateLegacyThreadDocuments;
|
|
|
17790
19334
|
exports.mountDiditVerification = mountDiditVerification;
|
|
17791
19335
|
exports.nextAliasSuggestion = nextAliasSuggestion;
|
|
17792
19336
|
exports.notificationUserName = notificationUserName;
|
|
19337
|
+
exports.offlineMailReads = offlineMailReads;
|
|
17793
19338
|
exports.openAccessRequest = openAccessRequest;
|
|
17794
19339
|
exports.parseActivityContent = parseActivityContent;
|
|
17795
19340
|
exports.parseDashboardSpec = parseDashboardSpec;
|
|
@@ -17812,8 +19357,10 @@ exports.resetMessageContent = resetMessageContent;
|
|
|
17812
19357
|
exports.resolveActiveWorkspace = resolveActiveWorkspace;
|
|
17813
19358
|
exports.resolveConfigModel = resolveConfigModel;
|
|
17814
19359
|
exports.resolveReplyTarget = resolveReplyTarget;
|
|
19360
|
+
exports.retryOutboxItem = retryOutboxItem;
|
|
17815
19361
|
exports.rollbackOptimisticDocumentEdit = rollbackOptimisticDocumentEdit;
|
|
17816
19362
|
exports.safePortalUrl = safePortalUrl;
|
|
19363
|
+
exports.saveLocalDraft = saveLocalDraft;
|
|
17817
19364
|
exports.serializeDashboardSpec = serializeDashboardSpec;
|
|
17818
19365
|
exports.serverNotificationBellEntry = serverNotificationBellEntry;
|
|
17819
19366
|
exports.setMessageContent = setMessageContent;
|
|
@@ -17876,6 +19423,7 @@ exports.useCalendarEvent = useCalendarEvent;
|
|
|
17876
19423
|
exports.useCalendarEventByUid = useCalendarEventByUid;
|
|
17877
19424
|
exports.useCalendarEvents = useCalendarEvents;
|
|
17878
19425
|
exports.useCalendarInvitations = useCalendarInvitations;
|
|
19426
|
+
exports.useCalendarOfflineRuntime = useCalendarOfflineRuntime;
|
|
17879
19427
|
exports.useCalendarOutbox = useCalendarOutbox;
|
|
17880
19428
|
exports.useCalendarOverlays = useCalendarOverlays;
|
|
17881
19429
|
exports.useCalendarSettings = useCalendarSettings;
|
|
@@ -17996,6 +19544,7 @@ exports.useFetchCalendarEvent = useFetchCalendarEvent;
|
|
|
17996
19544
|
exports.useFilteredProjects = useFilteredProjects;
|
|
17997
19545
|
exports.useFinaliseTranslation = useFinaliseTranslation;
|
|
17998
19546
|
exports.useFindTime = useFindTime;
|
|
19547
|
+
exports.useFlushOutbox = useFlushOutbox;
|
|
17999
19548
|
exports.useFollowThread = useFollowThread;
|
|
18000
19549
|
exports.useFreeBusy = useFreeBusy;
|
|
18001
19550
|
exports.useGenerateAgentAvatar = useGenerateAgentAvatar;
|
|
@@ -18019,6 +19568,7 @@ exports.useIsWorkspaceOwner = useIsWorkspaceOwner;
|
|
|
18019
19568
|
exports.useKeepDocumentsOffline = useKeepDocumentsOffline;
|
|
18020
19569
|
exports.useLinkContact = useLinkContact;
|
|
18021
19570
|
exports.useLinkMentions = useLinkMentions;
|
|
19571
|
+
exports.useLocalDrafts = useLocalDrafts;
|
|
18022
19572
|
exports.useMailAccounts = useMailAccounts;
|
|
18023
19573
|
exports.useMailAttachmentText = useMailAttachmentText;
|
|
18024
19574
|
exports.useMailCache = useMailCache;
|
|
@@ -18049,8 +19599,12 @@ exports.useNotificationPreferences = useNotificationPreferences;
|
|
|
18049
19599
|
exports.useNotifications = useNotifications;
|
|
18050
19600
|
exports.useNotifyConversation = useNotifyConversation;
|
|
18051
19601
|
exports.useOfflineDocumentIds = useOfflineDocumentIds;
|
|
19602
|
+
exports.useOfflineMailRuntime = useOfflineMailRuntime;
|
|
19603
|
+
exports.useOfflineMailSettings = useOfflineMailSettings;
|
|
19604
|
+
exports.useOfflineMailStatus = useOfflineMailStatus;
|
|
18052
19605
|
exports.useOpenSelectedWorkspace = useOpenSelectedWorkspace;
|
|
18053
19606
|
exports.useOpenViewerDocumentId = useOpenViewerDocumentId;
|
|
19607
|
+
exports.useOutbox = useOutbox;
|
|
18054
19608
|
exports.usePanelDataset = usePanelDataset;
|
|
18055
19609
|
exports.usePassageQuotes = usePassageQuotes;
|
|
18056
19610
|
exports.usePasswordChange = usePasswordChange;
|
|
@@ -18135,6 +19689,7 @@ exports.useSupportTickets = useSupportTickets;
|
|
|
18135
19689
|
exports.useSwitchWorkspace = useSwitchWorkspace;
|
|
18136
19690
|
exports.useSyncAccountsOnOpen = useSyncAccountsOnOpen;
|
|
18137
19691
|
exports.useSyncCalendarAccount = useSyncCalendarAccount;
|
|
19692
|
+
exports.useSyncOfflineMailbox = useSyncOfflineMailbox;
|
|
18138
19693
|
exports.useTerminateSession = useTerminateSession;
|
|
18139
19694
|
exports.useThinkingContent = useThinkingContent;
|
|
18140
19695
|
exports.useThreadDocument = useThreadDocument;
|
|
@@ -18185,7 +19740,9 @@ exports.userDisplayName = userDisplayName;
|
|
|
18185
19740
|
exports.userInitials = userInitials;
|
|
18186
19741
|
exports.viewsOfTable = viewsOfTable;
|
|
18187
19742
|
exports.waitForResponseId = waitForResponseId;
|
|
19743
|
+
exports.wipeCalendarOffline = wipeCalendarOffline;
|
|
18188
19744
|
exports.wipeOfflineDocuments = wipeOfflineDocuments;
|
|
19745
|
+
exports.wipeOfflineMail = wipeOfflineMail;
|
|
18189
19746
|
exports.withRelativePath = withRelativePath;
|
|
18190
19747
|
exports.workflowStepOf = workflowStepOf;
|
|
18191
19748
|
exports.workspaceHouseTemplateId = workspaceHouseTemplateId;
|