// Duenner Client fuer VER-04s Backend-Voraussetzung // (dms/internal/versioningapi.handleDiff) — enthaelt keine eigene // Diff-Berechnung, nur den HTTP-Aufruf. function apiBase(): string { const base = process.env.NEXT_PUBLIC_VERSIONING_API_URL; if (!base) { throw new Error("NEXT_PUBLIC_VERSIONING_API_URL ist nicht gesetzt (Umgebungsvariable erforderlich)"); } return base; } function caller(): string { const c = process.env.NEXT_PUBLIC_USER_ID; if (!c) { throw new Error("NEXT_PUBLIC_USER_ID ist nicht gesetzt (Umgebungsvariable erforderlich)"); } return c; } export type DiffOp = "equal" | "insert" | "delete"; export interface DiffLine { op: DiffOp; text: string; } export interface MetadataDiffEntry { field: string; before: string; after: string; } export interface DiffResult { text: DiffLine[]; metadata: MetadataDiffEntry[]; } export async function fetchDiff(documentID: string, fromRevisionID: string, toRevisionID: string): Promise { const url = `${apiBase()}/documents/${encodeURIComponent(documentID)}/diff?caller=${encodeURIComponent(caller())}&from=${encodeURIComponent(fromRevisionID)}&to=${encodeURIComponent(toRevisionID)}`; const res = await fetch(url); if (!res.ok) { if (res.status === 403) throw new Error("Zugriff verweigert: keine Berechtigung für eine der beiden Revisionen."); throw new Error(`Vergleich fehlgeschlagen (${res.status})`); } return res.json(); }