GPT-5 finding
API contract divergence between /activity server page and /api/activity endpoint serialization
mediumapi-contractmedium
- apps/web/app/activity/page.tsx
- apps/web/app/api/activity/route.ts
The server page normalizes Dates to ISO strings before passing to the client, but the API route returns the raw query result and relies on JSON serialization. This duplication risks future drift (e.g., additional fields, BigInt counts) and type mismatches. The client casts the polled response to FleetActivityJson without validation, so any drift can cause runtime errors.
Recommendation
Create a shared serializer that converts loadFleetActivity() results into FleetActivityJson (e.g., normalize lastSweepAt/lastReceiptAt/events.ts to strings and ensure numeric windows). Use it in both the server page and /api/activity route. Optionally validate the response shape on the client with a schema (e.g., zod) before setData.