LIC-04: dev-server fuer adminapi + next.js lizenz-modul-verwaltungsoberflaeche

This commit is contained in:
sysops
2026-08-27 23:40:05 +02:00
parent eed73eca8f
commit 0620baa993
7 changed files with 379 additions and 0 deletions
+63
View File
@@ -0,0 +1,63 @@
// Duenner Client fuer das LIC-04-Backend-API (internal/adminapi) — enthaelt
// keinerlei eigene Lizenz-/Flag-Logik, nur Datenabruf und -weitergabe.
export type FlagOverview = {
key: string;
enabled: boolean;
licensed: boolean;
deny_grund?: string;
};
export type UsageOverview = {
metric: string;
value: number;
limit: number;
status: "ok" | "warning" | "exceeded";
};
export type Overview = {
plan: string;
modules: string[];
issued_at: string;
valid_until: string;
expired: boolean;
flags: FlagOverview[];
usage: UsageOverview[];
};
function apiBase(): string {
const base = process.env.NEXT_PUBLIC_ADMIN_API_URL;
if (!base) {
throw new Error(
"NEXT_PUBLIC_ADMIN_API_URL ist nicht gesetzt (Umgebungsvariable erforderlich)"
);
}
return base;
}
export async function fetchOverview(tenantId: string): Promise<Overview> {
const res = await fetch(
`${apiBase()}/admin/overview?tenant=${encodeURIComponent(tenantId)}`,
{ cache: "no-store" }
);
if (!res.ok) {
const body = await res.json().catch(() => ({}));
throw new Error(body.error || `Anfrage fehlgeschlagen (${res.status})`);
}
return res.json();
}
export async function toggleFlag(
tenantId: string,
key: string,
enabled: boolean
): Promise<void> {
const res = await fetch(`${apiBase()}/admin/flags/toggle`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ tenant: tenantId, key, enabled }),
});
if (!res.ok) {
const body = await res.json().catch(() => ({}));
throw new Error(body.error || `Umschalten fehlgeschlagen (${res.status})`);
}
}