Files
patrickandClaude Sonnet 5.5 77b46945f2
CI / Web-Barrierefreiheitspruefung (axe, Tastatur, Reflow, Textabstaende) (push) Canceled after 0s
CI / Web-Barrierefreiheitspruefung (axe, Tastatur, Reflow, Textabstaende) (pull_request) Canceled after 0s
CI / Core-Modul (Build/Vet/Test) (push) Successful in 40s
CI / DMS Security-Test-Gate (AC5, Merge-Gate) (push) Successful in 4s
CI / Connect Security-Test-Gate (QA-01 AC4, Merge-Gate) (push) Successful in 3s
CI / DMS-Modul Supply-Chain-Scan (govulncheck) (push) Failing after 14s
CI / Web (dms-browser) (push) Failing after 54s
CI / Web (pdf-viewer) (push) Failing after 37s
CI / Web (shl) (push) Failing after 8s
CI / Core-Modul (Build/Vet/Test) (pull_request) Successful in 36s
CI / DMS Security-Test-Gate (AC5, Merge-Gate) (pull_request) Successful in 2s
CI / Connect Security-Test-Gate (QA-01 AC4, Merge-Gate) (pull_request) Successful in 2s
CI / DMS-Modul Supply-Chain-Scan (govulncheck) (pull_request) Failing after 12s
CI / Web (dms-browser) (pull_request) Failing after 47s
CI / Web (pdf-viewer) (pull_request) Failing after 36s
CI / Web (shl) (pull_request) Failing after 7s
Core-Schnittstellen-Vertragstests / contract-tests (pull_request) Successful in 13m40s
Supply-Chain-Scan (Go) / govulncheck (pull_request) Failing after 47s
Supply-Chain-Scan (npm) / npm-audit (pull_request) Failing after 1m19s
Core-Pflichttest-Gate / pflichttest-gate (pull_request) Successful in 13m50s
RBAC-Rollenhierarchie-Pflichtgate / rbac-policy-invariant (pull_request) Successful in 13m33s
CI / DMS-Modul (Lint/Build/Test/Coverage/Artefakt) (pull_request) Canceled after 0s
CI / DMS-Modul (Lint/Build/Test/Coverage/Artefakt) (push) Canceled after 0s
workflow-cases, routing-rules: Sitzung und Bearer statt X-User-Id aus der URL
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-28 15:05:34 +01:00

108 lines
3.1 KiB
TypeScript

// Duenner Client fuer die eigenen Backend-for-Frontend-Routen unter
// app/api — kein direkter Zugriff auf die Workflow-API vom Client aus,
// gleiches Muster wie web/workflow-cases/web/workflow-approvals.
import { apiFetch } from "./http";
export class ApiError extends Error {
status: number;
constructor(message: string, status: number) {
super(message);
this.status = status;
}
}
export interface Condition {
field: string;
operator: string;
value: unknown;
}
export interface Action {
type: string;
target: string;
process_id?: string;
}
export interface Rule {
ID: string;
Name: string;
Priority: number;
Enabled: boolean;
ActiveVersion: number;
Conditions: Condition[] | null;
Actions: Action[] | null;
}
export interface AISuggestion {
category?: string;
confidence: number;
sample_size: number;
reasoning: string;
low_data: boolean;
}
export interface TestResult {
matched: boolean;
rule_id?: string;
rule_name?: string;
actions?: Action[];
ai_suggestion?: AISuggestion;
}
async function handle<T>(res: Response): Promise<T> {
const body = await res.json().catch(() => null);
if (!res.ok) {
const message = (body && typeof body === "object" && "error" in body && typeof (body as { error: unknown }).error === "string")
? (body as { error: string }).error
: "Anfrage fehlgeschlagen";
throw new ApiError(message, res.status);
}
return body as T;
}
export async function listRules(userId: string): Promise<Rule[]> {
const res = await apiFetch(`/api/routing-rules?userId=${encodeURIComponent(userId)}`, { cache: "no-store" });
return handle<Rule[]>(res);
}
export async function createRule(userId: string, input: { name: string; priority: number; conditions: Condition[]; actions: Action[] }): Promise<Rule> {
const res = await apiFetch(`/api/routing-rules?userId=${encodeURIComponent(userId)}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(input),
});
return handle<Rule>(res);
}
export async function setPriority(userId: string, id: string, priority: number): Promise<void> {
const res = await apiFetch(`/api/routing-rules/${encodeURIComponent(id)}/priority?userId=${encodeURIComponent(userId)}`, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ priority }),
});
if (!res.ok) {
await handle(res);
}
}
export async function setEnabled(userId: string, id: string, enabled: boolean): Promise<void> {
const res = await apiFetch(`/api/routing-rules/${encodeURIComponent(id)}/enabled?userId=${encodeURIComponent(userId)}`, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ enabled }),
});
if (!res.ok) {
await handle(res);
}
}
export async function testRule(userId: string, object: Record<string, unknown>, history?: string[]): Promise<TestResult> {
const res = await apiFetch(`/api/routing-rules/test?userId=${encodeURIComponent(userId)}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ object, history }),
});
return handle<TestResult>(res);
}