Files
nexarch/web/dms2-import/lib/api.ts
patrickandClaude Sonnet 5 380858ca34
CI / Web-Barrierefreiheitspruefung (axe, Tastatur, Reflow, Textabstaende) (push) Canceled after 0s
CI / Web-Barrierefreiheitspruefung (axe, Tastatur, Reflow, Textabstaende) (pull_request) Canceled after 0s
CI / DMS Security-Test-Gate (AC5, Merge-Gate) (push) 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
CI / Core-Modul (Build/Vet/Test) (push) Canceled after 0s
Supply-Chain-Scan (Go) / govulncheck (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 / 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) (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 (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
DMS2-02: 02 import assistent fuer drittsystem exporte
Import-Assistent fuer paperless-ngx-Exporte (dieses Projekts primaeres
Referenzsystem): Parser, Feld-Mapping-Vorschlag ueber ENG-04s
fieldmapping.Store, Umwandlung in DMS2-01-Bundles, Import-Lauf mit
Erfolgs-/Fehleranzahl. Mapping-Vorschau-Oberflaeche (Next.js/shl).

Echte Funde dabei behoben: fieldmapping.FieldDef hatte keine JSON-Tags
(serialisierte als NexarchField/Required statt nexarch_field/required,
API-Antwort damit fuer das Frontend unbrauchbar); die neuen BFF-Routen
lieferten ohne cache:no-store eine veraltete Antwort aus Next.js'
Fetch-Cache aus.

4/4 Akzeptanzkriterien erfuellt, alle 4 Prüfungen real durchgefuehrt
inkl. echtem Chrome/Puppeteer-Ende-zu-Ende-Test (Mapping im Browser
geaendert, Import mit geaenderter Zuordnung erfolgreich ausgefuehrt).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-26 15:57:22 +02:00

78 lines
2.3 KiB
TypeScript

// Duenner Client fuer die eigenen Backend-for-Frontend-Routen unter
// app/api — kein direkter Zugriff auf die Connect-API vom Client aus,
// gleiches Muster wie web/routing-rules/web/workflow-cases.
export class ApiError extends Error {
status: number;
constructor(message: string, status: number) {
super(message);
this.status = status;
}
}
export interface FieldDef {
nexarch_field: string;
required: boolean;
}
export interface MappingEntry {
nexarch_field: string;
external_field: string;
}
export interface PreviewResult {
document_count: number;
available_fields: string[];
suggested_mapping: MappingEntry[];
schema: FieldDef[];
}
export interface ImportResult {
run_id: string;
document_count: number;
success_count: number;
error_count: number;
errors: string[];
}
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 previewImport(userId: string, tenant: string, file: File): Promise<PreviewResult> {
const form = new FormData();
form.append("file", file);
const res = await fetch(`/api/dms2-import/preview?userId=${encodeURIComponent(userId)}&tenant=${encodeURIComponent(tenant)}`, {
method: "POST",
body: form,
});
return handle<PreviewResult>(res);
}
export async function executeImport(userId: string, tenant: string, file: File, mapping: MappingEntry[]): Promise<ImportResult> {
const form = new FormData();
form.append("file", file);
form.append("mapping", JSON.stringify(mapping));
const res = await fetch(`/api/dms2-import/execute?userId=${encodeURIComponent(userId)}&tenant=${encodeURIComponent(tenant)}`, {
method: "POST",
body: form,
});
return handle<ImportResult>(res);
}
export async function getRun(userId: string, tenant: string, runId: string): Promise<ImportResult> {
const res = await fetch(
`/api/dms2-import/runs/${encodeURIComponent(runId)}?userId=${encodeURIComponent(userId)}&tenant=${encodeURIComponent(tenant)}`,
{ cache: "no-store" }
);
return handle<ImportResult>(res);
}