// Duenner Client fuer VER-04s Backend-Voraussetzung // (dms/internal/versioningapi.handleDiff) — enthaelt keine eigene // Diff-Berechnung, nur den HTTP-Aufruf. import { apiFetch, statusMessage } from "./http"; import { withCaller } from "./caller"; 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; } 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 = withCaller(`${apiBase()}/documents/${encodeURIComponent(documentID)}/diff?from=${encodeURIComponent(fromRevisionID)}&to=${encodeURIComponent(toRevisionID)}`); const res = await apiFetch(url); if (!res.ok) { if (res.status === 403) throw new Error("Zugriff verweigert: keine Berechtigung für eine der beiden Revisionen."); throw new Error(statusMessage(res, "Vergleich fehlgeschlagen")); } return res.json(); }