CI / Web-Barrierefreiheitspruefung (axe, Tastatur, Reflow, Textabstaende) (push) Canceled after 0s
CI / DMS-Modul Supply-Chain-Scan (govulncheck) (push) Canceled after 0s
CI / Core-Modul (Build/Vet/Test) (push) Canceled after 0s
CI / DMS Security-Test-Gate (AC5, Merge-Gate) (push) Canceled after 0s
CI / Web (dms-browser) (push) Canceled after 0s
CI / Web (pdf-viewer) (push) Canceled after 0s
CI / Web (shl) (push) Canceled after 0s
Supply-Chain-Scan (Go) / govulncheck (push) Canceled after 0s
Supply-Chain-Scan (npm) / npm-audit (push) Canceled after 0s
CI / DMS-Modul (Lint/Build/Test/Coverage/Artefakt) (push) Canceled after 0s
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
63 lines
2.0 KiB
TypeScript
63 lines
2.0 KiB
TypeScript
// Duenner Client fuer API-02 (connect/internal/statusapi) — enthaelt keine
|
|
// eigene Statuslogik, nur Datenabruf. Identitaet kommt uebergangsweise (wie
|
|
// bei workflow/approvalapi vor der zentralen Core-JWT-Anbindung) aus
|
|
// Umgebungsvariablen, die als Header durchgereicht werden.
|
|
|
|
export class UnauthorizedError extends Error {}
|
|
export class ApiError extends Error {}
|
|
|
|
function apiBase(): string {
|
|
const base = process.env.NEXT_PUBLIC_CONNECT_API_URL;
|
|
if (!base) {
|
|
throw new Error("NEXT_PUBLIC_CONNECT_API_URL ist nicht gesetzt (Umgebungsvariable erforderlich)");
|
|
}
|
|
return base;
|
|
}
|
|
|
|
function identityHeaders(): Record<string, string> {
|
|
const userID = process.env.NEXT_PUBLIC_USER_ID;
|
|
const tenant = process.env.NEXT_PUBLIC_TENANT_SLUG;
|
|
const headers: Record<string, string> = {};
|
|
if (userID) headers["X-User-Id"] = userID;
|
|
if (tenant) headers["X-Tenant-Slug"] = tenant;
|
|
return headers;
|
|
}
|
|
|
|
async function req<T>(path: string, init?: RequestInit): Promise<T> {
|
|
const res = await fetch(`${apiBase()}${path}`, {
|
|
...init,
|
|
headers: {
|
|
...identityHeaders(),
|
|
...init?.headers,
|
|
},
|
|
});
|
|
if (res.status === 401) {
|
|
throw new UnauthorizedError("Anmeldung erforderlich, um den Verbindungsstatus zu sehen.");
|
|
}
|
|
if (!res.ok) {
|
|
const body = await res.json().catch(() => ({}));
|
|
throw new ApiError(body.error ?? `Anfrage fehlgeschlagen (${res.status})`);
|
|
}
|
|
return res.json().catch(() => undefined as T);
|
|
}
|
|
|
|
export type RunStatus = "running" | "succeeded" | "failed" | "retry_pending";
|
|
|
|
export interface ConnectorStatus {
|
|
job_id: string;
|
|
connector_name: string;
|
|
connector_instance_id: string;
|
|
interval_seconds: number;
|
|
next_run_at: string;
|
|
last_run_id?: string;
|
|
last_run_status?: RunStatus;
|
|
last_run_trigger?: "scheduled" | "manual";
|
|
last_run_started_at?: string;
|
|
last_run_finished_at?: string;
|
|
last_error?: string;
|
|
}
|
|
|
|
export function fetchConnectorStatus(): Promise<ConnectorStatus[]> {
|
|
return req("/connectors/status");
|
|
}
|