import { useEffect, useState } from 'react'; import { pretty, record, request, Session, tenantPath, page, RecordValue } from './api'; import { adminIntent, allowed, parseStrictJson, recipeInput, sha256 } from './safety'; const message = (e: unknown) => e instanceof Error ? e.message : 'Unbekannter Fehler'; function Result({ error, result }: { error: string | null; result: unknown }) { return <>{error &&
{error}
}{result !== null &&
{pretty(result)}
}; } export function AdminControl({ auth, path, title, permission, warning, stopped, done }: { auth: Session; path: string; title: string; permission: string; warning: string; stopped?: boolean; done?: () => void }) { const [nonce, setNonce] = useState(() => crypto.randomUUID()), [error, setError] = useState(null), [result, setResult] = useState(null), [busy, setBusy] = useState(false); return
{title}

{warning}

Erforderliches Recht: {permission}. {allowed(auth, permission) ? 'Von Sitzung angekündigt; Server prüft erneut.' : 'Unbekannt oder nicht erteilt; Aktion gesperrt.'}

{ e.preventDefault(); const form = e.currentTarget, f = new FormData(form); setError(null); setBusy(true); try { if (!allowed(auth, permission) || !auth.csrf_token) throw new Error('Berechtigung/CSRF fehlt'); const body = adminIntent(f.get('confirmed') === 'on', String(f.get('reason') ?? ''), String(f.get('nonce') ?? ''), nonce); const response = await request(path, { csrf: auth.csrf_token, body: stopped === undefined ? body : { ...body, stopped } }); setResult(response); form.reset(); setNonce(crypto.randomUUID()); done?.(); } catch (e) { setError(message(e)); } finally { setBusy(false); } }}>

Aktuelle Bestätigungskennung: {nonce}

; } export function TenantControls({ tenantId, auth }: { tenantId: string; auth: Session }) { const [status, setStatus] = useState('unknown — kein lesender Stopstatus-Endpunkt angekündigt'); return

Mitgliedschaft und Ausführungsstopp

Rollen: {auth.roles?.join(', ') || 'unknown'} · Rechte: {auth.permissions?.join(', ') || 'unknown'}

Aktueller Ausführungsstopp: {typeof status === 'string' ? status : pretty(status)}

Frontendberechtigungen sind keine Sicherheitsgrenze. Aktuelle Rechte/Tenant/CSRF/Policy prüft der Server. Anmeldemodi werden über /auth/config ermittelt; die Simulationskennzeichnung stammt ausschließlich aus der Serversitzung.

setStatus('true — zuletzt erfolgreich per UI angefordert; kein unabhängiger aktueller Lesestatus')}/> setStatus('false — zuletzt erfolgreich per UI angefordert; kein unabhängiger aktueller Lesestatus')}/>
; } async function downloadArtifact(path: string) { const r = await fetch(path, { credentials: 'same-origin', cache: 'no-store' }); if (!r.ok) { const data: unknown = await r.json().catch(() => null); throw new Error(`Artefaktabruf HTTP ${r.status}: ${data ? pretty(data) : 'keine JSON-Fehlerdetails'}`); } if (!r.headers.get('content-type')?.startsWith('application/octet-stream') || !r.body) throw new Error('Binärer Artefaktvertrag nicht erfüllt'); const reader = r.body.getReader(), chunks: Uint8Array[] = []; let size = 0; try { while (true) { const next = await reader.read(); if (next.done) break; size += next.value.length; if (size > 262144) throw new Error('Artefakt über 256 KiB'); chunks.push(next.value); } } finally { await reader.cancel(); } if (!size) throw new Error('Leeres Artefakt'); const bytes = new Uint8Array(size); let offset = 0; for (const chunk of chunks) { bytes.set(chunk, offset); offset += chunk.length; } return { size_bytes: size, computed_sha256: await sha256(bytes), server_metadata: 'not_provided — GET liefert Binärbytes, keinen JSON-Details-Endpunkt' }; } export function Catalog({ tenantId, auth }: { tenantId: string; auth: Session }) { const [cursor, setCursor] = useState(null), [list, setList] = useState(null), [error, setError] = useState(null), [revision, setRevision] = useState(0), [recipe, setRecipe] = useState('{}'), [result, setResult] = useState(null), [busy, setBusy] = useState(false), [receipts, setReceipts] = useState>({}); useEffect(() => { const controller = new AbortController(); setList(null); setError(null); request(tenantPath(tenantId, `/package-recipes${cursor ? `?cursor=${encodeURIComponent(cursor)}` : ''}`), { signal: controller.signal }).then(v => setList(page(v))).catch(e => { if (!controller.signal.aborted) setError(message(e)); }); return () => controller.abort(); }, [tenantId, cursor, revision]); const loaded = list ? page(list) : null; return

Unveränderlicher Paketkatalog und Artefakte

Exakte Paket-/Rezeptversionen, Architektur und SHA-256. Keine freie Download-URL oder LLM-URL als Installer. Import ist keine Ausführungsgenehmigung.

{loaded && <>}
Neue unveränderliche Rezeptversion importieren

POST package-recipes, Recht catalog:write. Bestehende Versionen werden nicht bearbeitet; Plattform wird nur dargestellt, soweit geliefert, nicht aus Architektur erfunden.

{ e.preventDefault(); setError(null); setResult(null); setBusy(true); try { if (!allowed(auth, 'catalog:write')) throw new Error('catalog:write unbekannt/nicht erteilt'); const input = recipeInput(parseStrictJson(recipe)); const expected = await sha256(new TextEncoder().encode(JSON.stringify(input))); const response = record(await request(tenantPath(tenantId, '/package-recipes'), { body: input, csrf: auth.csrf_token })); if (response.sha256 !== expected || JSON.stringify(recipeInput(response.recipe)) !== JSON.stringify(input)) throw new Error('Rezeptantwort stimmt nicht mit unveränderlichen Importbytes überein'); setResult(response); setRevision(v => v + 1); } catch (e) { setError(message(e)); } finally { setBusy(false); } }}>