feat: warm-up deps — ts-reset, web-vitals, RHF devtool, query-broadcast

Four low-risk adds before the Zod 4 / drizzle-zod headliner:

- @total-typescript/ts-reset: tightens TS stdlib types globally (JSON.parse
  → unknown, fetch().json() → unknown, .filter(Boolean) narrows, Set
  literals respect typed Set targets). Caught 179 latent type errors;
  fixed all production sites (8 files) and added `any` cast escape hatch
  in test files (ESLint exemption scoped to tests/).
- web-vitals + /api/v1/internal/vitals endpoint + WebVitalsReporter
  client component: establishes Core Web Vitals baseline (LCP/INP/CLS/
  FCP/TTFB) via navigator.sendBeacon. Required before optimisation work.
- @hookform/devtools + FormDevtool wrapper: dev-only RHF state inspector,
  lazy-loaded via next/dynamic so the chunk is excluded from prod
  bundles entirely.
- @tanstack/query-broadcast-client-experimental: cross-tab cache sync
  via BroadcastChannel — wired in query-provider.tsx, 1-liner.

Audit doc updated with sections 35 + 36 (PDF stack overhaul + comprehensive
second-pass package sweep) covering ~20 package adoption candidates and
4-5 deprecation candidates.

Verified: tsc clean, vitest 1293/1293 pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-12 18:16:18 +02:00
parent 82049eea92
commit d3960af340
38 changed files with 1590 additions and 119 deletions

View File

@@ -35,7 +35,7 @@ async function seedReservation(portId: string) {
ctx,
{ id: berth.id },
);
return (await res.json()).data as { id: string; berthId: string };
return ((await res.json()) as any).data as { id: string; berthId: string };
}
describe('GET /api/v1/berth-reservations', () => {
@@ -51,7 +51,7 @@ describe('GET /api/v1/berth-reservations', () => {
);
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
const ids = (body.data as Array<{ id: string }>).map((r) => r.id).sort();
expect(ids).toEqual([r1.id, r2.id].sort());
expect(body.pagination).toMatchObject({ page: 1, total: 2 });
@@ -70,7 +70,7 @@ describe('GET /api/v1/berth-reservations', () => {
);
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
const ids = (body.data as Array<{ id: string }>).map((r) => r.id);
expect(ids).not.toContain(reservationInB.id);
});
@@ -88,7 +88,7 @@ describe('GET /api/v1/berth-reservations', () => {
);
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data).toHaveLength(2);
expect(body.pagination).toMatchObject({
page: 1,

View File

@@ -19,7 +19,7 @@ describe('POST /api/v1/companies', () => {
});
const res = await createHandler(req, ctx, {});
expect(res.status).toBe(201);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data.name).toBe(name);
expect(body.data.portId).toBe(port.id);
expect(body.data.status).toBe('active');
@@ -88,7 +88,7 @@ describe('GET /api/v1/companies', () => {
);
const res = await listHandler(req, ctx, {});
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data.some((c: { name: string }) => c.name === 'ListedCo')).toBe(true);
expect(body.pagination.page).toBe(1);
expect(body.pagination.pageSize).toBe(20);
@@ -115,7 +115,7 @@ describe('GET /api/v1/companies', () => {
);
const res = await listHandler(req, ctx, {});
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data.every((c: { status: string }) => c.status === 'dissolved')).toBe(true);
expect(body.data.some((c: { name: string }) => c.name === 'DissolvedCo')).toBe(true);
expect(body.data.some((c: { name: string }) => c.name === 'ActiveCo')).toBe(false);
@@ -133,7 +133,7 @@ describe('GET /api/v1/companies/[id]', () => {
const req = makeMockRequest('GET', `http://localhost/api/v1/companies/${company.id}`);
const res = await getHandler(req, ctx, { id: company.id });
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data.id).toBe(company.id);
expect(body.data.name).toBe('DetailCo');
});
@@ -162,7 +162,7 @@ describe('PATCH /api/v1/companies/[id]', () => {
});
const res = await patchHandler(req, ctx, { id: company.id });
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data.name).toBe('AfterCo');
expect(body.data.notes).toBe('updated notes');
});
@@ -211,7 +211,7 @@ describe('GET /api/v1/companies/autocomplete', () => {
);
const res = await autocompleteHandler(req, ctx, {});
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data.length).toBeGreaterThanOrEqual(1);
expect(body.data.every((c: { name: string }) => c.name.includes('AutoCompleteCoMatch'))).toBe(
true,
@@ -224,7 +224,7 @@ describe('GET /api/v1/companies/autocomplete', () => {
const req = makeMockRequest('GET', 'http://localhost/api/v1/companies/autocomplete');
const res = await autocompleteHandler(req, ctx, {});
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data).toEqual([]);
});
});

View File

@@ -56,7 +56,7 @@ describe('GET /api/v1/interests/[id]/berths (listHandler)', () => {
const req = makeMockRequest('GET', `http://localhost/api/v1/interests/${interest.id}/berths`);
const res = await listHandler(req, ctx, { id: interest.id });
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data).toHaveLength(1);
expect(body.data[0].berthId).toBe(berth.id);
expect(body.data[0].mooringNumber).toBe(berth.mooringNumber);
@@ -102,7 +102,7 @@ describe('POST /api/v1/interests/[id]/berths (addHandler)', () => {
});
const res = await addHandler(req, ctx, { id: interest.id });
expect(res.status).toBe(201);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data.berthId).toBe(berth.id);
expect(body.data.isSpecificInterest).toBe(true);
});
@@ -165,7 +165,7 @@ describe('PATCH /api/v1/interests/[id]/berths/[berthId] (patchHandler)', () => {
);
const res = await patchHandler(req, ctx, { id: interest.id, berthId: berth.id });
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data.isInEoiBundle).toBe(true);
expect(body.data.isSpecificInterest).toBe(false);
});

View File

@@ -43,7 +43,7 @@ describe('GET /api/v1/companies/[id]/members', () => {
const req = makeMockRequest('GET', `http://localhost/api/v1/companies/${company.id}/members`);
const res = await listHandler(req, ctx, { id: company.id });
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
expect(Array.isArray(body.data)).toBe(true);
expect(body.data.length).toBe(2);
expect(body.data.every((m: { endDate: string | null }) => m.endDate === null)).toBe(true);
@@ -81,7 +81,7 @@ describe('GET /api/v1/companies/[id]/members', () => {
ctx,
{ id: company.id },
);
const createdBody = await createRes.json();
const createdBody = (await createRes.json()) as any;
const toEndId = createdBody.data.id as string;
const delRes = await deleteHandler(
@@ -100,7 +100,7 @@ describe('GET /api/v1/companies/[id]/members', () => {
ctx,
{ id: company.id },
);
const activeBody = await activeOnlyRes.json();
const activeBody = (await activeOnlyRes.json()) as any;
expect(activeBody.data.length).toBe(1);
// activeOnly=false.
@@ -112,7 +112,7 @@ describe('GET /api/v1/companies/[id]/members', () => {
ctx,
{ id: company.id },
);
const allBody = await allRes.json();
const allBody = (await allRes.json()) as any;
expect(allBody.data.length).toBe(2);
});
@@ -143,7 +143,7 @@ describe('POST /api/v1/companies/[id]/members', () => {
});
const res = await createHandler(req, ctx, { id: company.id });
expect(res.status).toBe(201);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data.companyId).toBe(company.id);
expect(body.data.clientId).toBe(client.id);
expect(body.data.role).toBe('director');
@@ -217,7 +217,7 @@ describe('PATCH /api/v1/companies/[id]/members/[mid]', () => {
ctx,
{ id: company.id },
);
const created = (await createRes.json()).data;
const created = ((await createRes.json()) as any).data;
const patchRes = await patchHandler(
makeMockRequest(
@@ -234,7 +234,7 @@ describe('PATCH /api/v1/companies/[id]/members/[mid]', () => {
{ id: company.id, mid: created.id },
);
expect(patchRes.status).toBe(200);
const body = await patchRes.json();
const body = (await patchRes.json()) as any;
expect(body.data.role).toBe('officer');
expect(body.data.notes).toBe('promoted');
});
@@ -257,7 +257,7 @@ describe('PATCH /api/v1/companies/[id]/members/[mid]', () => {
ctxA,
{ id: company.id },
);
const created = (await createRes.json()).data;
const created = ((await createRes.json()) as any).data;
const ctxB = makeMockCtx({ portId: portB.id, permissions: makeFullPermissions() });
const patchRes = await patchHandler(
@@ -291,7 +291,7 @@ describe('DELETE /api/v1/companies/[id]/members/[mid]', () => {
ctx,
{ id: company.id },
);
const created = (await createRes.json()).data;
const created = ((await createRes.json()) as any).data;
const before = new Date();
const delRes = await deleteHandler(
@@ -329,7 +329,7 @@ describe('DELETE /api/v1/companies/[id]/members/[mid]', () => {
ctx,
{ id: company.id },
);
const created = (await createRes.json()).data;
const created = ((await createRes.json()) as any).data;
const explicitEnd = new Date('2026-06-01T00:00:00.000Z');
const delRes = await deleteHandler(
@@ -373,7 +373,7 @@ describe('POST /api/v1/companies/[id]/members/[mid]/set-primary', () => {
ctx,
{ id: company.id },
);
const m1 = (await m1Res.json()).data;
const m1 = ((await m1Res.json()) as any).data;
// M2, M3 — not primary.
const m2Res = await createHandler(
@@ -387,7 +387,7 @@ describe('POST /api/v1/companies/[id]/members/[mid]/set-primary', () => {
ctx,
{ id: company.id },
);
const m2 = (await m2Res.json()).data;
const m2 = ((await m2Res.json()) as any).data;
const m3Res = await createHandler(
makeMockRequest('POST', `http://localhost/api/v1/companies/${company.id}/members`, {
@@ -400,7 +400,7 @@ describe('POST /api/v1/companies/[id]/members/[mid]/set-primary', () => {
ctx,
{ id: company.id },
);
const m3 = (await m3Res.json()).data;
const m3 = ((await m3Res.json()) as any).data;
// Promote M2.
const setPrimRes = await setPrimaryHandler(
@@ -412,7 +412,7 @@ describe('POST /api/v1/companies/[id]/members/[mid]/set-primary', () => {
{ id: company.id, mid: m2.id },
);
expect(setPrimRes.status).toBe(200);
const setPrimBody = await setPrimRes.json();
const setPrimBody = (await setPrimRes.json()) as any;
expect(setPrimBody.data.id).toBe(m2.id);
expect(setPrimBody.data.isPrimary).toBe(true);

View File

@@ -45,7 +45,7 @@ describe('POST /api/v1/berths/[id]/reservations', () => {
});
const res = await createReservationHandler(req, ctx, { id: berth.id });
expect(res.status).toBe(201);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data.berthId).toBe(berth.id);
expect(body.data.clientId).toBe(client.id);
expect(body.data.yachtId).toBe(yacht.id);
@@ -129,7 +129,7 @@ describe('POST /api/v1/berths/[id]/reservations', () => {
);
const res = await createReservationHandler(req, ctx, { id: urlBerth.id });
expect(res.status).toBe(201);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data.berthId).toBe(urlBerth.id);
expect(body.data.berthId).not.toBe(bodyBerth.id);
});
@@ -182,7 +182,7 @@ describe('GET /api/v1/berths/[id]/reservations', () => {
{ id: berthA.id },
);
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data.length).toBe(1);
expect(body.data[0].berthId).toBe(berthA.id);
});
@@ -213,7 +213,7 @@ describe('GET /api/v1/berth-reservations/[id]', () => {
ctx,
{ id: berth.id },
);
const reservation = (await createRes.json()).data;
const reservation = ((await createRes.json()) as any).data;
const res = await getReservationHandler(
makeMockRequest('GET', `http://localhost/api/v1/berth-reservations/${reservation.id}`),
@@ -221,7 +221,7 @@ describe('GET /api/v1/berth-reservations/[id]', () => {
{ id: reservation.id },
);
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data.id).toBe(reservation.id);
});
@@ -248,7 +248,7 @@ describe('GET /api/v1/berth-reservations/[id]', () => {
ctxA,
{ id: berth.id },
);
const reservation = (await createRes.json()).data;
const reservation = ((await createRes.json()) as any).data;
const ctxB = makeMockCtx({ portId: portB.id, permissions: makeFullPermissions() });
const res = await getReservationHandler(
@@ -285,7 +285,7 @@ describe('PATCH /api/v1/berth-reservations/[id]', () => {
ctx,
{ id: berth.id },
);
const reservation = (await createRes.json()).data;
const reservation = ((await createRes.json()) as any).data;
return { port, berth, client, yacht, ctx, reservation };
}
@@ -299,7 +299,7 @@ describe('PATCH /api/v1/berth-reservations/[id]', () => {
{ id: reservation.id },
);
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data.status).toBe('active');
});
@@ -329,7 +329,7 @@ describe('PATCH /api/v1/berth-reservations/[id]', () => {
{ id: reservation.id },
);
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data.status).toBe('ended');
expect(new Date(body.data.endDate).toISOString()).toBe(endDate.toISOString());
});
@@ -344,7 +344,7 @@ describe('PATCH /api/v1/berth-reservations/[id]', () => {
{ id: reservation.id },
);
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data.status).toBe('cancelled');
});
@@ -467,7 +467,7 @@ describe('DELETE /api/v1/berth-reservations/[id]', () => {
ctx,
{ id: berth.id },
);
const reservation = (await createRes.json()).data;
const reservation = ((await createRes.json()) as any).data;
const delRes = await deleteReservationHandler(
makeMockRequest('DELETE', `http://localhost/api/v1/berth-reservations/${reservation.id}`),

View File

@@ -42,7 +42,7 @@ describe('saved-views ownership enforcement', () => {
{ id: viewId },
);
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data.name).toBe('Renamed by owner');
});

View File

@@ -32,7 +32,7 @@ describe('GET /api/v1/yachts/[id]', () => {
const req = makeMockRequest('GET', `http://localhost/api/v1/yachts/${yacht.id}`);
const res = await getHandler(req, ctx, { id: yacht.id });
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data.id).toBe(yacht.id);
expect(body.data.name).toBe('Detail Yacht');
});
@@ -77,7 +77,7 @@ describe('PATCH /api/v1/yachts/[id]', () => {
});
const res = await patchHandler(req, ctx, { id: yacht.id });
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data.name).toBe('After');
expect(body.data.notes).toBe('updated notes');
});
@@ -184,7 +184,7 @@ describe('POST /api/v1/yachts/[id]/transfer', () => {
});
const res = await transferHandler(req, ctx, { id: yacht.id });
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data.currentOwnerType).toBe('company');
expect(body.data.currentOwnerId).toBe(company.id);
});
@@ -262,7 +262,7 @@ describe('GET /api/v1/yachts/[id]/ownership-history', () => {
);
const res = await historyHandler(req, ctxFull, { id: yacht.id });
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data).toHaveLength(2);
// Sorted DESC by startDate — newest first
const firstStart = new Date(body.data[0].startDate).getTime();
@@ -312,7 +312,7 @@ describe('GET /api/v1/yachts/autocomplete', () => {
);
const res = await autocompleteHandler(req, ctx, {});
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data.length).toBeGreaterThanOrEqual(1);
expect(body.data.every((y: { name: string }) => y.name.includes('AutoCompleteMatch'))).toBe(
true,
@@ -325,7 +325,7 @@ describe('GET /api/v1/yachts/autocomplete', () => {
const req = makeMockRequest('GET', 'http://localhost/api/v1/yachts/autocomplete');
const res = await autocompleteHandler(req, ctx, {});
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data).toEqual([]);
});
@@ -346,7 +346,7 @@ describe('GET /api/v1/yachts/autocomplete', () => {
);
const res = await autocompleteHandler(req, ctx, {});
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data).toEqual([]);
});
});

View File

@@ -22,7 +22,7 @@ describe('POST /api/v1/yachts (createHandler)', () => {
});
const res = await createHandler(req, ctx, {});
expect(res.status).toBe(201);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data.name).toBe('Sea Breeze');
expect(body.data.currentOwnerId).toBe(client.id);
});
@@ -63,7 +63,7 @@ describe('GET /api/v1/yachts (listHandler)', () => {
const req = makeMockRequest('GET', 'http://localhost/api/v1/yachts?page=1&limit=20&order=desc');
const res = await listHandler(req, ctx, {});
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.data.some((y: { name: string }) => y.name === 'Listed')).toBe(true);
expect(body.pagination.page).toBe(1);
expect(body.pagination.pageSize).toBe(20);

View File

@@ -32,7 +32,7 @@ async function callHandler(
const req = makeMockRequest('GET', url.toString());
const res = await getMatchCandidatesHandler(req, ctx);
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
return body.data as MatchData[];
}

View File

@@ -7,7 +7,7 @@ describe('GET /api/health (liveness)', () => {
it('returns 200 + status=ok regardless of downstream dependency state', async () => {
const res = await healthGet();
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.status).toBe('ok');
expect(body.timestamp).toMatch(/^\d{4}-\d{2}-\d{2}T/);
});
@@ -25,7 +25,7 @@ describe('GET /api/ready (readiness)', () => {
// active port is configured for, via getStorageBackend().head().
const res = await readyGet();
expect(res.status).toBe(200);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.status).toBe('ready');
expect(body.checks).toEqual({
postgres: 'ok',

View File

@@ -59,7 +59,7 @@ describe('POST /api/public/interests — trio creation', () => {
});
const res = await POST(req);
expect(res.status).toBe(201);
const body = await res.json();
const body = (await res.json()) as any;
const interestId: string = body.data.id;
const [interest] = await db.select().from(interests).where(eq(interests.id, interestId));
@@ -116,7 +116,7 @@ describe('POST /api/public/interests — trio creation', () => {
});
const res = await POST(req);
expect(res.status).toBe(201);
const body = await res.json();
const body = (await res.json()) as any;
const interestId: string = body.data.id;
const [interest] = await db.select().from(interests).where(eq(interests.id, interestId));
@@ -179,7 +179,7 @@ describe('POST /api/public/interests — trio creation', () => {
);
const firstRes = await POST(firstReq);
expect(firstRes.status).toBe(201);
const firstBody = await firstRes.json();
const firstBody = (await firstRes.json()) as any;
const [firstInterest] = await db
.select()
@@ -204,7 +204,7 @@ describe('POST /api/public/interests — trio creation', () => {
);
const secondRes = await POST(secondReq);
expect(secondRes.status).toBe(201);
const secondBody = await secondRes.json();
const secondBody = (await secondRes.json()) as any;
const [secondInterest] = await db
.select()
@@ -248,7 +248,7 @@ describe('POST /api/public/interests — trio creation', () => {
);
const firstRes = await POST(firstReq);
expect(firstRes.status).toBe(201);
const firstBody = await firstRes.json();
const firstBody = (await firstRes.json()) as any;
const [firstInterest] = await db
.select()
.from(interests)
@@ -277,7 +277,7 @@ describe('POST /api/public/interests — trio creation', () => {
);
const secondRes = await POST(secondReq);
expect(secondRes.status).toBe(201);
const secondBody = await secondRes.json();
const secondBody = (await secondRes.json()) as any;
const [secondInterest] = await db
.select()
.from(interests)

View File

@@ -117,7 +117,7 @@ describe('GET /api/storage/[token]', () => {
);
const res = await callRoute(badToken);
expect(res.status).toBe(403);
const body = await res.json();
const body = (await res.json()) as any;
expect(body.error).toMatch(/Invalid|expired/i);
});
@@ -154,7 +154,7 @@ describe('GET /api/storage/[token]', () => {
const second = await callRoute(token);
expect(second.status).toBe(403);
const body = await second.json();
const body = (await second.json()) as any;
expect(body.error).toMatch(/already used/i);
});
});