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 2s
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 49s
CI / Web (pdf-viewer) (push) Failing after 37s
CI / Web (shl) (push) Failing after 8s
Supply-Chain-Scan (Go) / govulncheck (push) Failing after 42s
CI / Core-Modul (Build/Vet/Test) (pull_request) Successful in 41s
CI / DMS Security-Test-Gate (AC5, Merge-Gate) (pull_request) Successful in 3s
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 16s
CI / Web (dms-browser) (pull_request) Failing after 55s
CI / Web (pdf-viewer) (pull_request) Failing after 38s
CI / Web (shl) (pull_request) Failing after 8s
Core-Schnittstellen-Vertragstests / contract-tests (pull_request) Successful in 22m20s
Supply-Chain-Scan (Go) / govulncheck (pull_request) Failing after 1m3s
Supply-Chain-Scan (npm) / npm-audit (pull_request) Failing after 1m54s
Core-Pflichttest-Gate / pflichttest-gate (pull_request) Successful in 23m46s
RBAC-Rollenhierarchie-Pflichtgate / rbac-policy-invariant (pull_request) Successful in 23m56s
DB-Integrationstests / db-tests (pull_request) Canceled after 0s
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
connect/internal/bearerauth (wie workflow): verifiziertes Core-Token setzt
X-User-Id/X-Tenant-Slug, ohne Token nur mit NEXARCH_CONNECT_APP_ALLOW_HEADER_AUTH=1.
Mit JWKS ist NEXARCH_CONNECT_APP_TENANT_SLUG Pflicht (Mandant der Datenbank).
common auf v0.2.1 (moduleauth). Frontends nutzen createBearerClient("connect").
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
117 lines
3.4 KiB
TypeScript
117 lines
3.4 KiB
TypeScript
// Duenner Client fuer API-01 (connect/internal/connectorsetupapi) — enthaelt
|
|
// keine eigene Geschaeftslogik, nur Datenabruf/-versand. Identitaet kommt
|
|
// uebergangsweise (wie bei web/connect-status vor der zentralen
|
|
// Core-JWT-Anbindung) aus Umgebungsvariablen, die als Header durchgereicht
|
|
// werden.
|
|
|
|
import { apiFetch, bearerEnabled } from "./http";
|
|
|
|
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> {
|
|
if (bearerEnabled()) return {};
|
|
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 apiFetch(`${apiBase()}${path}`, {
|
|
...init,
|
|
headers: {
|
|
...identityHeaders(),
|
|
...(init?.body ? { "Content-Type": "application/json" } : {}),
|
|
...init?.headers,
|
|
},
|
|
});
|
|
if (res.status === 401) {
|
|
throw new UnauthorizedError("Anmeldung erforderlich, um Connectoren einzurichten.");
|
|
}
|
|
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 CredentialKind = "oauth2" | "api_key";
|
|
|
|
export interface FieldDef {
|
|
nexarch_field: string;
|
|
required: boolean;
|
|
}
|
|
|
|
export interface Entry {
|
|
nexarch_field: string;
|
|
external_field: string;
|
|
}
|
|
|
|
export interface ConnectorType {
|
|
id: string;
|
|
display_name: string;
|
|
credential_kind: CredentialKind;
|
|
schema: FieldDef[];
|
|
}
|
|
|
|
export interface Connection {
|
|
connector_type: string;
|
|
connector_type_label: string;
|
|
connector_instance_id: string;
|
|
credential_kind: CredentialKind;
|
|
masked_credential: string;
|
|
expires_at?: string;
|
|
updated_at: string;
|
|
}
|
|
|
|
export interface MappingView {
|
|
schema: FieldDef[];
|
|
fields: Entry[];
|
|
version: number;
|
|
}
|
|
|
|
export function fetchCatalog(): Promise<ConnectorType[]> {
|
|
return req("/connectors/catalog");
|
|
}
|
|
|
|
export function fetchConnections(): Promise<Connection[]> {
|
|
return req("/connectors/connections");
|
|
}
|
|
|
|
export interface SetConnectionInput {
|
|
kind: CredentialKind;
|
|
api_key?: string;
|
|
access_token?: string;
|
|
refresh_token?: string;
|
|
expires_at?: string;
|
|
}
|
|
|
|
export function setConnection(connectorType: string, instanceID: string, input: SetConnectionInput): Promise<Connection> {
|
|
return req(`/connectors/connections/${encodeURIComponent(connectorType)}/${encodeURIComponent(instanceID)}`, {
|
|
method: "PUT",
|
|
body: JSON.stringify(input),
|
|
});
|
|
}
|
|
|
|
export function fetchMapping(connectorType: string, instanceID: string): Promise<MappingView> {
|
|
return req(`/connectors/connections/${encodeURIComponent(connectorType)}/${encodeURIComponent(instanceID)}/mapping`);
|
|
}
|
|
|
|
export function saveMapping(connectorType: string, instanceID: string, fields: Entry[]): Promise<MappingView> {
|
|
return req(`/connectors/connections/${encodeURIComponent(connectorType)}/${encodeURIComponent(instanceID)}/mapping`, {
|
|
method: "PUT",
|
|
body: JSON.stringify({ fields }),
|
|
});
|
|
}
|