feat: platform backbone and field capture complete (checkpoint)

Platform backbone (plan 2026-10-13-plattform-rueckgrat), all tasks reviewed:
- webhooks with delivery table, retries and stable delivery id
- calendar handlers; a finished task removes its Outlook event
- tasks, automations, inspections, varroa, treatments, feedings,
  harvests, colonies, wintering, stock and bottling record domain events
  in the same transaction; legacy post-commit calls removed
- row locks through one helper (lockRowForUpdate, lockRowsForShare,
  lockRowsForUpdate)
- job framework with JobRun, cli exit codes, cleanup, task templates,
  daily evaluation, hourly app-backup and the rekey job
- system API and page "Verwaltung > System" with retry
- @nestjs/schedule removed, guard tests against in-process schedulers

Field capture T3 (plan 2026-10-13-t3-erfassung-am-stand), all tasks reviewed:
- inspection photo offline without metadata
- bulk capture for treatments, feedings and varroa (backend + frontend)
- offline stand mode with service worker, offline pages and packs
- offline session, cold start and logout on shared devices

Docs: ARCHITECTURE.md assumptions and sections updated, TASKS.md.
Gates: backend lint, typecheck, 1770 unit, 420 e2e, build, no schema
drift; frontend lint, typecheck, 913 tests, build. Not rolled out.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
Nick SzaunigandClaude Opus 5.5 committed 2026-10-14 11:36:38 +02:00
1 parent c01a38835a
commit cdd30cf3ee
288 files changed
+39165 -2853

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
import { apiFetch } from "@/lib/auth/api-client";
import type {
FailedDomainEventView,
FailedWebhookDeliveryView,
JobName,
JobRunView,
SystemOverview,
} from "./types";
export function fetchSystemOverview(): Promise<SystemOverview> {
return apiFetch<SystemOverview>("/system/overview");
}
export function fetchJobRuns(job?: JobName): Promise<JobRunView[]> {
const query = job ? `?job=${encodeURIComponent(job)}` : "";
return apiFetch<JobRunView[]>(`/system/job-runs${query}`);
}
export function fetchFailedDomainEvents(): Promise<FailedDomainEventView[]> {
return apiFetch<FailedDomainEventView[]>("/system/domain-events/failed");
}
export function retryDomainEvent(id: string): Promise<void> {
return apiFetch<void>(`/system/domain-events/${encodeURIComponent(id)}/retry`, {
method: "POST",
});
}
export function fetchFailedWebhookDeliveries(): Promise<FailedWebhookDeliveryView[]> {
return apiFetch<FailedWebhookDeliveryView[]>("/system/webhook-deliveries/failed");
}
export function retryWebhookDelivery(id: string): Promise<void> {
return apiFetch<void>(`/system/webhook-deliveries/${encodeURIComponent(id)}/retry`, {
method: "POST",
});
}
@@ -0,0 +1,43 @@
import { describe, expect, it } from "vitest";
import {
DOMAIN_EVENT_LABELS,
JOB_LABELS,
JOB_RUN_STATUS_LABELS,
QUEUE_STALE_WARNING_SECONDS,
WEBHOOK_DELIVERY_STATUS_LABELS,
attemptsLabel,
formatAge,
} from "./labels";
import { JOB_NAMES } from "./types";
describe("system labels", () => {
it("labels every job", () => {
expect(JOB_NAMES.every((job) => JOB_LABELS[job].length > 0)).toBe(true);
expect(JOB_LABELS.cleanup).toBe("Aufräumen");
});
it("labels the run and delivery states", () => {
expect(JOB_RUN_STATUS_LABELS.FAILED).toBe("Fehlgeschlagen");
expect(WEBHOOK_DELIVERY_STATUS_LABELS.DELIVERED).toBe("Zugestellt");
expect(WEBHOOK_DELIVERY_STATUS_LABELS.PENDING).toBe("Offen");
expect(DOMAIN_EVENT_LABELS.InspectionRecorded).toBe("Durchsicht erfasst");
});
it("warns after ten minutes", () => {
expect(QUEUE_STALE_WARNING_SECONDS).toBe(600);
});
it("pluralises attempts", () => {
expect(attemptsLabel(1)).toBe("1 Versuch");
expect(attemptsLabel(0)).toBe("0 Versuche");
expect(attemptsLabel(8)).toBe("8 Versuche");
});
it("formats ages in German", () => {
expect(formatAge(5)).toBe("vor wenigen Sekunden");
expect(formatAge(180)).toBe("vor 3 Min.");
expect(formatAge(7300)).toBe("vor 2 Std.");
expect(formatAge(2 * 86400 + 10)).toBe("vor 2 Tagen");
expect(formatAge(86400)).toBe("vor 1 Tag");
});
});
+77
View File
@@ -0,0 +1,77 @@
import type { WebhookDeliveryStatus } from "@/lib/webhooks/types";
import type { JobName, JobRunStatus } from "./types";
/** Same wording as JOB_LABELS_DE in the backend. */
export const JOB_LABELS: Record<JobName, string> = {
"daily-evaluation": "Tägliche Auswertung",
"task-templates": "Aufgaben aus Vorlagen",
cleanup: "Aufräumen",
"app-backup": "App-Backup",
rekey: "Schlüssel umstellen",
};
export const JOB_RUN_STATUS_LABELS: Record<JobRunStatus, string> = {
RUNNING: "Läuft",
SUCCEEDED: "Erfolgreich",
FAILED: "Fehlgeschlagen",
} as const;
export const WEBHOOK_DELIVERY_STATUS_LABELS: Record<WebhookDeliveryStatus, string> = {
PENDING: "Offen",
PROCESSING: "Wird zugestellt",
DELIVERED: "Zugestellt",
FAILED: "Fehlgeschlagen",
};
export const DOMAIN_EVENT_LABELS: Record<string, string> = {
InspectionRecorded: "Durchsicht erfasst",
InspectionCorrected: "Durchsicht korrigiert",
VarroaMeasured: "Varroamessung erfasst",
VarroaCorrected: "Varroamessung korrigiert",
TreatmentRecorded: "Behandlung erfasst",
TreatmentCorrected: "Behandlung korrigiert",
FeedingRecorded: "Fütterung erfasst",
FeedingCorrected: "Fütterung korrigiert",
HarvestRecorded: "Ernte erfasst",
HarvestCorrected: "Ernte korrigiert",
ColonyStatusChanged: "Volksstatus geändert",
ColonyEnded: "Volk beendet",
BatchBottled: "Charge abgefüllt",
BottlingCorrected: "Abfüllung korrigiert",
StockChanged: "Bestand geändert",
TaskCreated: "Aufgabe angelegt",
TaskUpdated: "Aufgabe geändert",
TaskCompleted: "Aufgabe erledigt",
WithdrawalEnded: "Wartezeit beendet",
TaskDue: "Aufgabe fällig",
QueenAged: "Königin gealtert",
VarroaMeasurementDue: "Varroamessung fällig",
InspectionOverdue: "Durchsicht überfällig",
};
/** The oldest open event is this old (seconds) before the worker counts as stuck. */
export const QUEUE_STALE_WARNING_SECONDS = 600;
const SECONDS_PER_MINUTE = 60;
const SECONDS_PER_HOUR = 3600;
const SECONDS_PER_DAY = 86400;
/** "vor 3 Min." / "vor 2 Std." / "vor 2 Tagen". */
export function formatAge(seconds: number): string {
if (seconds < SECONDS_PER_MINUTE) {
return "vor wenigen Sekunden";
}
if (seconds < SECONDS_PER_HOUR) {
return `vor ${Math.floor(seconds / SECONDS_PER_MINUTE)} Min.`;
}
if (seconds < SECONDS_PER_DAY) {
return `vor ${Math.floor(seconds / SECONDS_PER_HOUR)} Std.`;
}
const days = Math.floor(seconds / SECONDS_PER_DAY);
return days === 1 ? "vor 1 Tag" : `vor ${days} Tagen`;
}
/** "1 Versuch" / "8 Versuche". */
export function attemptsLabel(attempts: number): string {
return attempts === 1 ? "1 Versuch" : `${attempts} Versuche`;
}
+54
View File
@@ -0,0 +1,54 @@
export const JOB_NAMES = [
"daily-evaluation",
"task-templates",
"cleanup",
"app-backup",
"rekey",
] as const;
export type JobName = (typeof JOB_NAMES)[number];
export type JobRunStatus = "RUNNING" | "SUCCEEDED" | "FAILED";
export interface JobRunView {
id: string;
job: JobName;
status: JobRunStatus;
startedAt: string;
finishedAt: string | null;
error: string | null;
result: Record<string, number | string | boolean | null> | null;
}
export interface SystemOverview {
jobs: { job: JobName; lastRun: JobRunView | null }[];
domainEvents: {
pending: number;
processing: number;
failed: number;
oldestPendingAgeSeconds: number | null;
};
webhookDeliveries: { pending: number; failed: number };
}
export interface FailedDomainEventView {
id: string;
type: string;
aggregateType: string;
aggregateId: string;
occurredAt: string;
attempts: number;
lastError: string | null;
failedHandlers: { handler: string; lastError: string | null }[];
}
export interface FailedWebhookDeliveryView {
id: string;
subscriptionId: string;
targetHost: string;
event: string;
attempts: number;
lastStatusCode: number | null;
lastError: string | null;
createdAt: string;
}