Files
nexarch/web/datev-export/lib/api.ts
rootandClaude Sonnet 5 a465bb6dab
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) Canceled after 0s
CI / DMS Security-Test-Gate (AC5, Merge-Gate) (push) Canceled after 0s
CI / Core-Modul (Build/Vet/Test) (pull_request) Canceled after 0s
CI / DMS Security-Test-Gate (AC5, Merge-Gate) (pull_request) Canceled after 0s
CI / DMS-Modul Supply-Chain-Scan (govulncheck) (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 Supply-Chain-Scan (govulncheck) (pull_request) Canceled after 0s
CI / Web (dms-browser) (pull_request) Canceled after 0s
CI / Web (pdf-viewer) (pull_request) Canceled after 0s
CI / Web (shl) (pull_request) Canceled after 0s
Core-Schnittstellen-Vertragstests / contract-tests (pull_request) Canceled after 0s
Supply-Chain-Scan (Go) / govulncheck (pull_request) Canceled after 0s
Supply-Chain-Scan (npm) / npm-audit (pull_request) Canceled after 0s
Core-Pflichttest-Gate / pflichttest-gate (pull_request) Canceled after 0s
RBAC-Rollenhierarchie-Pflichtgate / rbac-policy-invariant (pull_request) Canceled after 0s
CI / DMS-Modul (Lint/Build/Test/Coverage/Artefakt) (push) Canceled after 0s
CI / DMS-Modul (Lint/Build/Test/Coverage/Artefakt) (pull_request) Canceled after 0s
DAT-03: 03 datev export oberflaeche protokoll
Backend: additive List()/ListForTenant()-Methoden fuer DAT-01/DAT-02
(kein Aenderungen an bestehendem Code), neues Paket datevapi (POST/GET
/datev/exports), gleiches Auth-Muster wie statusapi (API-02).
Frontend: web/datev-export (Next.js/React/TS + @nexarch/shl) mit
Formular (Zeitraum-Auswahl) und Protokolltabelle, fehlgeschlagene
Uebertragung farblich/textlich klar erkennbar.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-26 11:40:20 +00:00

84 lines
2.3 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.
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: {
"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");
}