@codemem/server 0.49.0-beta.5 → 0.49.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +58 -34
- package/dist/index.js.map +1 -1
- package/dist/routes/device-rename.d.ts +7 -7
- package/dist/routes/device-rename.d.ts.map +1 -1
- package/dist/routes/sync.d.ts.map +1 -1
- package/package.json +2 -2
- package/static/app.js +2 -2
- package/static/app.js.br +0 -0
- package/static/app.js.gz +0 -0
- package/static/index.html +1 -1
package/dist/index.js
CHANGED
|
@@ -8855,10 +8855,25 @@ function teamSetupRoutes(options) {
|
|
|
8855
8855
|
/**
|
|
8856
8856
|
* Sync routes — status, peers, actors, attempts, pairing, mutations.
|
|
8857
8857
|
*/
|
|
8858
|
-
function
|
|
8858
|
+
async function refreshManualSyncAuthorization(store, options) {
|
|
8859
|
+
if (options.refreshFailed) return;
|
|
8860
|
+
const refreshed = await refreshConfiguredScopeMembershipCache(store.db, options.config, {
|
|
8861
|
+
keysDir: syncKeysDir(),
|
|
8862
|
+
dbPath: store.dbPath,
|
|
8863
|
+
onlyIfStale: true
|
|
8864
|
+
}).catch((error) => {
|
|
8865
|
+
options.refreshFailed = true;
|
|
8866
|
+
throw error;
|
|
8867
|
+
});
|
|
8868
|
+
options.refreshFailed = refreshed.status !== "refreshed" && refreshed.status !== "skipped";
|
|
8869
|
+
}
|
|
8870
|
+
async function manualSyncReachability(store, peerId, options) {
|
|
8871
|
+
const { resolver } = options;
|
|
8872
|
+
if (!resolver) return void 0;
|
|
8859
8873
|
let route;
|
|
8860
8874
|
try {
|
|
8861
|
-
|
|
8875
|
+
await refreshManualSyncAuthorization(store, options);
|
|
8876
|
+
route = resolver.forPeer(store.db, peerId);
|
|
8862
8877
|
} catch {
|
|
8863
8878
|
return;
|
|
8864
8879
|
}
|
|
@@ -8870,14 +8885,52 @@ function manualSyncReachability(resolver, store, peerId) {
|
|
|
8870
8885
|
deadlineMs: void 0
|
|
8871
8886
|
};
|
|
8872
8887
|
}
|
|
8873
|
-
function runManualSyncPass(store, peerId,
|
|
8888
|
+
async function runManualSyncPass(store, peerId, options) {
|
|
8874
8889
|
return runSyncPass(store.db, peerId, {
|
|
8875
8890
|
keysDir: syncKeysDir(),
|
|
8876
8891
|
dbPath: store.dbPath,
|
|
8877
8892
|
scanner: store.scanner,
|
|
8878
|
-
reachability: manualSyncReachability(
|
|
8893
|
+
reachability: await manualSyncReachability(store, peerId, options)
|
|
8879
8894
|
});
|
|
8880
8895
|
}
|
|
8896
|
+
function manualSyncHandler(getStore, options) {
|
|
8897
|
+
return async (c) => {
|
|
8898
|
+
const store = getStore();
|
|
8899
|
+
let body = {};
|
|
8900
|
+
try {
|
|
8901
|
+
body = await c.req.json();
|
|
8902
|
+
} catch {
|
|
8903
|
+
body = {};
|
|
8904
|
+
}
|
|
8905
|
+
const config = readCoordinatorSyncConfig();
|
|
8906
|
+
if (!config.syncEnabled) return c.json({ error: "sync_disabled" }, 403);
|
|
8907
|
+
const address = typeof body.address === "string" && body.address.trim() ? body.address.trim() : null;
|
|
8908
|
+
const requestedPeerId = typeof body.peer_device_id === "string" && body.peer_device_id.trim() ? body.peer_device_id.trim() : null;
|
|
8909
|
+
let peerIds;
|
|
8910
|
+
if (address) {
|
|
8911
|
+
const peerId = findPeerDeviceIdForAddress(store, address);
|
|
8912
|
+
if (!peerId) return c.json({ error: "unknown peer address" }, 404);
|
|
8913
|
+
peerIds = [peerId];
|
|
8914
|
+
} else if (requestedPeerId) peerIds = store.db.prepare("SELECT peer_device_id FROM sync_peers WHERE peer_device_id = ?").all(requestedPeerId).map((row) => String(row.peer_device_id ?? "").trim()).filter(Boolean);
|
|
8915
|
+
else peerIds = store.db.prepare("SELECT peer_device_id FROM sync_peers").all().map((row) => String(row.peer_device_id ?? "").trim()).filter(Boolean);
|
|
8916
|
+
const items = [];
|
|
8917
|
+
const manualSyncOptions = {
|
|
8918
|
+
resolver: options.syncReachability,
|
|
8919
|
+
config,
|
|
8920
|
+
refreshFailed: false
|
|
8921
|
+
};
|
|
8922
|
+
for (const peerId of peerIds) {
|
|
8923
|
+
const result = await runManualSyncPass(store, peerId, manualSyncOptions);
|
|
8924
|
+
items.push({
|
|
8925
|
+
peer_device_id: peerId,
|
|
8926
|
+
...result,
|
|
8927
|
+
skippedOut: void 0,
|
|
8928
|
+
skipped_out: safeSkippedSyncDetail(result.skippedOut)
|
|
8929
|
+
});
|
|
8930
|
+
}
|
|
8931
|
+
return c.json({ items });
|
|
8932
|
+
};
|
|
8933
|
+
}
|
|
8881
8934
|
function safeSkippedSyncDetail(detail) {
|
|
8882
8935
|
if (!detail) return null;
|
|
8883
8936
|
return {
|
|
@@ -12950,36 +13003,7 @@ function syncRoutes(getStore, getSyncRuntimeStatus, options = {}) {
|
|
|
12950
13003
|
return c.json({ ok: true });
|
|
12951
13004
|
}
|
|
12952
13005
|
});
|
|
12953
|
-
app.post("/api/sync/run",
|
|
12954
|
-
const store = getStore();
|
|
12955
|
-
let body = {};
|
|
12956
|
-
try {
|
|
12957
|
-
body = await c.req.json();
|
|
12958
|
-
} catch {
|
|
12959
|
-
body = {};
|
|
12960
|
-
}
|
|
12961
|
-
if (!readCoordinatorSyncConfig().syncEnabled) return c.json({ error: "sync_disabled" }, 403);
|
|
12962
|
-
const address = typeof body.address === "string" && body.address.trim() ? body.address.trim() : null;
|
|
12963
|
-
const requestedPeerId = typeof body.peer_device_id === "string" && body.peer_device_id.trim() ? body.peer_device_id.trim() : null;
|
|
12964
|
-
let peerIds;
|
|
12965
|
-
if (address) {
|
|
12966
|
-
const peerId = findPeerDeviceIdForAddress(store, address);
|
|
12967
|
-
if (!peerId) return c.json({ error: "unknown peer address" }, 404);
|
|
12968
|
-
peerIds = [peerId];
|
|
12969
|
-
} else if (requestedPeerId) peerIds = store.db.prepare("SELECT peer_device_id FROM sync_peers WHERE peer_device_id = ?").all(requestedPeerId).map((row) => String(row.peer_device_id ?? "").trim()).filter(Boolean);
|
|
12970
|
-
else peerIds = store.db.prepare("SELECT peer_device_id FROM sync_peers").all().map((row) => String(row.peer_device_id ?? "").trim()).filter(Boolean);
|
|
12971
|
-
const items = [];
|
|
12972
|
-
for (const peerId of peerIds) {
|
|
12973
|
-
const result = await runManualSyncPass(store, peerId, options.syncReachability);
|
|
12974
|
-
items.push({
|
|
12975
|
-
peer_device_id: peerId,
|
|
12976
|
-
...result,
|
|
12977
|
-
skippedOut: void 0,
|
|
12978
|
-
skipped_out: safeSkippedSyncDetail(result.skippedOut)
|
|
12979
|
-
});
|
|
12980
|
-
}
|
|
12981
|
-
return c.json({ items });
|
|
12982
|
-
});
|
|
13006
|
+
app.post("/api/sync/run", manualSyncHandler(getStore, options));
|
|
12983
13007
|
app.post("/api/sync/peers/scope", async (c) => {
|
|
12984
13008
|
const store = getStore();
|
|
12985
13009
|
let body;
|