From 990f5582b85df3b521fefb396913b873eb3d1597 Mon Sep 17 00:00:00 2001 From: Keysat Date: Sat, 9 May 2026 11:05:03 -0500 Subject: [PATCH] Typed Prisma queries, bcrypt native, CSP nonces, /api/me/import, more tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Typed Prisma queries - where: any in app/api/workouts/route.ts (GET + POST) and lib/db/workouts.ts replaced with Prisma.WorkoutWhereInput + Prisma.WorkoutCreateInput + Prisma.DateTimeFilter. Catches typos at compile time and surfaces query shape directly in tooltips. Workout import endpoint tests (tests/routes-import.test.ts) - 7 tests covering /api/workouts/import/save: 401 unauthenticated, empty workouts rejected, case-insensitive name matching against existing exercises, new-exercise creation with isCustom=true and type='other' default, explicit existingExerciseId honored over name lookup, multiple workouts per call, sequential setNumber per exercise per workout. bcryptjs -> bcrypt (native) - Roughly 10x faster than the pure-JS implementation under load — login latency drops from ~250ms to ~25ms. Hash format is fully cross-compatible with bcryptjs ($2a$ / $2b$ both verify), so existing user passwords keep working without migration. - Dockerfile builder stage adds python3 + make + g++ as a safety net for native node-gyp compilation on alpine when prebuilt binaries aren't available. - Runner stage explicitly COPYs node_modules/bcrypt so the .node binding is unambiguously present even if Next.js standalone tracing somehow misses it. - StartOS package's changeAdminCredentials.ts keeps bcryptjs (it's bundled by ncc into a single JS file and runs only on the rare admin action; native bcrypt would require shipping the .node binding through ncc which it doesn't handle gracefully). CSP nonces (middleware.ts + next.config.js) - Per-request nonce generated in middleware. Forwarded to Next via the x-nonce request header, which Next 13.4+ automatically stamps onto its inline bootstrap scripts. CSP response header includes `'nonce-${nonce}' 'strict-dynamic'`, dropping the previous `'unsafe-inline'` from script-src. - Static CSP removed from next.config.js (middleware-set headers override static ones, so keeping both was redundant). - Middleware matcher widened to all paths except static assets so the CSP applies to every page response. Existing /main + /api auth gating preserved. - style-src keeps 'unsafe-inline' — Next/Tailwind still inject critical inline