L7 Offline & PWA: Outbox-Kern, IndexedDB-Store, Sync-Engine und Bundle-Logik

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-14 17:19:43 +02:00
co-authored by Claude Opus 5
parent d5c1221ab5
commit 9f73cdae49
13 changed files with 2081 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
/** Device-side ids (moved from src/lib/field/client-ops.ts, which re-exports them). */
/** RFC 4122 v4 id; falls back to getRandomValues outside secure contexts. */
export function newClientId(): string {
const c = globalThis.crypto;
if (typeof c?.randomUUID === "function") return c.randomUUID();
const b = new Uint8Array(16);
c.getRandomValues(b);
b[6] = (b[6] & 0x0f) | 0x40;
b[8] = (b[8] & 0x3f) | 0x80;
const h = [...b].map((x) => x.toString(16).padStart(2, "0")).join("");
return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`;
}
const DEVICE_KEY = "craftvia.field.deviceId";
export function deviceId(): string {
try {
let id = localStorage.getItem(DEVICE_KEY);
if (!id) {
id = newClientId();
localStorage.setItem(DEVICE_KEY, id);
}
return id;
} catch {
return "unknown-device";
}
}