fix(api,lib): consent before reuse, tighter inputs and caches that tell on themselves

Per-status texts check AI consent before the unchanged-data refresh can
re-stamp them, the comprehensive fingerprint folds in the comparison
baseline and generation language so toggling either regenerates once,
and profile, threshold and source-priority writes evict the analytics,
targets and derived caches they feed. CSV export neutralises spreadsheet
formula prefixes on free-text cells while numeric columns stay typed,
the derived batch validates its type token against the measurement enum
and carries a per-user rate limit, and a dose synced from the phone app
counts as the interactive write it is. Background cache refresh
failures log a structured event instead of vanishing, the warm queue
runs visit-triggered jobs alongside the nightly walk, the formatter
memo evicts one entry instead of flushing wholesale with its option
objects frozen, the targets cold build bounds its fan-out, and time in
bed unions every writer's envelope while stages stay with the richest
recorder.
This commit is contained in:
Marc-André Bombeck committed 2026-06-11 23:20:38 +02:00
1 parent 95f21bfa4d
commit f790e14edd
40 files changed
+1141 -287

No files matched your search

+10
View File
@@ -19,6 +19,7 @@ import { annotate } from "@/lib/logging/context";
import { prisma } from "@/lib/db";
import { auditLog } from "@/lib/auth/audit";
import { checkRateLimit } from "@/lib/rate-limit";
import { invalidateUserProfile } from "@/lib/cache/invalidate";
import {
getAllEffectiveRanges,
type ThresholdOverridesJson,
@@ -99,6 +100,11 @@ export const PUT = apiHandler(async (request: NextRequest) => {
data: { thresholdsJson: merged },
});
// Threshold overrides feed the targets grid's effective ranges and the
// analytics snapshot — drop the cached payloads so the next read
// reflects the new bands instead of serving the pre-edit grid.
invalidateUserProfile(user.id);
await auditLog("thresholds.update", {
userId: user.id,
ipAddress: getClientIp(request),
@@ -142,6 +148,10 @@ export const DELETE = apiHandler(async (request: NextRequest) => {
},
});
// A reset changes the effective ranges back to the defaults — same
// eviction as the PUT above.
invalidateUserProfile(user.id);
await auditLog("thresholds.reset", {
userId: user.id,
ipAddress: getClientIp(request),