feat(sync): round trip cloud snapshots

This commit is contained in:
2026-05-16 00:01:28 -04:00
parent 06e947f43e
commit 40ab6b4874
22 changed files with 694 additions and 69 deletions
+1
View File
@@ -1,5 +1,6 @@
export interface ElyKvNamespace {
get(key: string): Promise<string | null>;
put(key: string, value: string): Promise<void>;
delete(key: string): Promise<void>;
}
+19
View File
@@ -1,4 +1,5 @@
import type { AuthContext } from "./auth.js";
import { authSessionCacheKvKey } from "./auth.js";
import type { Env } from "./bindings.js";
import {
type DeviceApprovalDocument,
@@ -227,6 +228,7 @@ export async function registerDeviceDocument(
throw new DevicePersistenceError("device_registration_missing");
}
await bindSessionDeviceContext(env, context, registration.deviceId, nowSeconds);
await refreshSessionDeviceCache(env, context, registration.deviceId);
return {
version: 1,
@@ -246,6 +248,23 @@ async function bindSessionDeviceContext(
.run();
}
async function refreshSessionDeviceCache(
env: Env,
context: AuthContext,
deviceId: string,
): Promise<void> {
await env.ELY_KV.put(
authSessionCacheKvKey(env.ELY_ENVIRONMENT, context.tokenHash),
JSON.stringify({
version: 1,
user_id: context.userId,
session_id: context.sessionId,
device_id: deviceId,
expires_at: context.expiresAt,
}),
);
}
export async function approveDeviceDocument(
request: Request,
env: Env,