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>
87 lines
2.4 KiB
TypeScript
87 lines
2.4 KiB
TypeScript
// Duenner Client fuer DAT-03 (connect/internal/datevapi) — enthaelt keine
|
|
// eigene Geschaeftslogik, nur Datenabruf/-versand. Identitaet kommt
|
|
// uebergangsweise (wie bei web/connect-status) 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: {
|
|
"Content-Type": "application/json",
|
|
...identityHeaders(),
|
|
...init?.headers,
|
|
},
|
|
});
|
|
if (res.status === 401) {
|
|
throw new UnauthorizedError("Anmeldung erforderlich, um DATEV-Exporte 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 interface ExportEntry {
|
|
Amount: number;
|
|
DebitCredit: "S" | "H";
|
|
Account: string;
|
|
CounterAccount: string;
|
|
Date: string;
|
|
Text: string;
|
|
DocumentRef: string;
|
|
}
|
|
|
|
export interface TriggerExportRequest {
|
|
consultant_number: string;
|
|
client_number: string;
|
|
fiscal_year_start: string;
|
|
account_length: number;
|
|
description: string;
|
|
period_start: string;
|
|
period_end: string;
|
|
entries: ExportEntry[];
|
|
}
|
|
|
|
export interface ExportRun {
|
|
id: string;
|
|
period_start: string;
|
|
period_end: string;
|
|
entry_count: number;
|
|
retention_class: string;
|
|
created_at: string;
|
|
transfer_status?: string;
|
|
transfer_error?: string;
|
|
}
|
|
|
|
export function triggerExport(req_: TriggerExportRequest): Promise<ExportRun> {
|
|
return req("/datev/exports", { method: "POST", body: JSON.stringify(req_) });
|
|
}
|
|
|
|
export function fetchExportRuns(): Promise<ExportRun[]> {
|
|
return req("/datev/exports");
|
|
}
|