Expose sync reset API

This commit is contained in:
2026-05-08 19:10:04 -04:00
parent e9f8b1eb43
commit ed44db3034
9 changed files with 597 additions and 1 deletions
+40
View File
@@ -8,6 +8,11 @@ import {
SyncPushRequestError,
syncPushDocument,
} from "./sync_push.js";
import {
SyncResetPersistenceError,
SyncResetRequestError,
syncResetDocument,
} from "./sync_reset.js";
import {
SyncSnapshotConflictError,
SyncSnapshotNotFoundError,
@@ -35,6 +40,9 @@ export async function handleSyncRoute(
if (url.pathname === "/api/sync/status") {
return handleSyncStatus(request, env);
}
if (url.pathname === "/api/sync/reset") {
return handleSyncReset(request, env);
}
return null;
}
@@ -180,3 +188,35 @@ function handleSyncStatus(request: Request, env: Env): Promise<Response> {
},
);
}
function handleSyncReset(request: Request, env: Env): Promise<Response> {
return withApprovedDeviceApiControls(
request,
env,
"sync.reset",
["POST"],
async (context) => {
try {
return jsonResponse(await syncResetDocument(request, env, context), 200, {
"Cache-Control": "no-store",
});
} catch (error) {
if (error instanceof SyncResetRequestError) {
return jsonResponse(
{ error: "invalid_sync_reset" },
400,
{ "Cache-Control": "no-store" },
);
}
if (error instanceof SyncResetPersistenceError) {
return jsonResponse(
{ error: "sync_reset_failed" },
500,
{ "Cache-Control": "no-store" },
);
}
throw error;
}
},
);
}