chore(release): v1.4.49 — audit-backlog closure + server reminder suppression + diagnostic endpoint + analytics cold-path fix

Bundles the deferred v1.4.47 Mediums + Lows with the v1.4.48-deferred items
into a single release. Headline: server-side suppression of MEDICATION_REMINDER
APNs for iOS clients that own their local reminders (closes GH #206), a
push_attempts table backing /api/admin/notifications/diagnostic, and a sweep
of v1.4.48 QA forward-findings.

Performance (the user-visible win):
- /api/analytics cold-fallback path splits the heavy single-statement
  aggregate into two parallel queries. The linearly composable columns
  (count / min / max / mean) keep the full-partition scan; the windowed
  7 / 30 / 90-day avg / slope / r² columns take a 90-day outer cap so
  the planner does an index range scan on (user_id, type, measured_at)
  instead of a full-partition sequential scan. Output is bit-identical;
  cold slim slice drops from multi-second to sub-second on tenants with
  large measurement partitions.

Server-side notifications:
- GET + PATCH /api/auth/me/notification-prefs with deep-merge semantics.
  Initial category medication.clientManaged: boolean (default false). Cron
  medicationReminderJob skips dose-due APNs when the flag is true,
  emitting a medication_reminder.suppressed_client_managed wide-event
  annotation per skip.
- push_attempts table backs the diagnostic endpoint. Every APNS /
  Web-Push / Telegram / NTFY sender writes a fire-and-forget row.
  Daily 03:35 Europe/Berlin cleanup prunes rows older than 90 days.
- /api/admin/notifications/diagnostic — admin-only endpoint surfacing
  device APNs token presence (masked), channel config presence, and
  recent push attempts. Registered in OpenAPI.
- Per-channel APNs "Send test" button now fires with
  eventType: "MEDICATION_REMINDER" so the dispatcher's time-sensitive +
  priority-10 branch runs. A successful self-test now exercises the
  exact path production reminders take; an unsuccessful one points the
  user at iOS Settings → Time Sensitive Notifications rather than
  appearing to be a server-side bug.

Withings reliability:
- OAuth callback consumes the nonce atomically (delete-first with
  P2025 catch for the replay branch). The previous read-then-delete
  pattern allowed a race between two concurrent callbacks.
- ?reason=state redirect differentiated into csrf1 / replay / expired /
  cross_user so operators can tell mismatch types apart without DB
  shell access.
- connect endpoint rate-limited to 10/60s/user; row-create failures
  redirect to a consistent error surface.

Observability hardening:
- redactSensitiveFields(body) denylist helper covers password / token /
  secret / apiKey / authorization / csrfState / nonce, recursive,
  case-insensitive. Caught: /api/devices invalid_format issues were
  echoing apnsToken values verbatim into the audit log.
- sanitiseZodIssues(issues, { stripValuesFromMessage: true }) overload
  applied to 14 audit-log sites.

Migrations: 0079 (notification_prefs), 0080 (push_attempts).

Tests: 4815 → 5272 unit + integration. Workout-batch integration suite
that had been red on main since v1.4.45 (three release commits shipped
through it) now green again — updated to match v1.4.42 cross-source
dedup semantics.

Resolves PR #207.
This commit is contained in:
Marc-André Bombeck committed 2026-05-23 12:51:41 +02:00
1 parent 30ab2112db
commit f92e644154
87 files changed
+7939 -2950

No files matched your search

@@ -0,0 +1,33 @@
"use client";
import { useContext } from "react";
import { QueryClientContext } from "@tanstack/react-query";
/**
* v1.4.48 M4 — shared SSR-safety helper for hooks that delegate to
* React Query under a `<QueryClientProvider>`.
*
* A long tail of legacy presentational components (`<HeroStrip>`,
* `<SuggestedPrompts>`, `<LayoutCoachFab>`, `<InsightStatusCard>`,
* `<HealthScoreDeltaExplainer>`, …) ships with unit tests that render
* the component in isolation without wrapping it in
* `<QueryClientProvider>`. Hooks that call `useQuery` directly crash
* in that environment.
*
* `useQueryClientMounted()` returns `true` when a `QueryClientContext`
* value is present in the React tree, `false` otherwise. The branch is
* stable across the component's lifetime — the provider never
* appears and disappears between renders — so a conditional hook call
* gated on this value remains safe per the Rules of Hooks (the same
* posture the React docs document for "different environments where
* the same component renders").
*/
export function useQueryClientMounted(): boolean {
// The cast strips the generic so callers don't have to learn the
// internal `QueryClient | undefined` shape — they only need to know
// whether the context is mounted.
const ctx = useContext(
QueryClientContext as unknown as React.Context<unknown>,
);
return ctx != null;
}
+9 -11
View File
@@ -1,9 +1,7 @@
"use client";
import { useContext } from "react";
import { QueryClientContext } from "@tanstack/react-query";
import { useAuth } from "@/hooks/use-auth";
import { useQueryClientMounted } from "@/hooks/_internal/use-query-client-safe";
/**
* v1.4.47 W3 — SSR-safe accessor for the per-user "Hide Coach" toggle.
@@ -15,16 +13,16 @@ import { useAuth } from "@/hooks/use-auth";
* long-tail SSR snapshot tests (`<SuggestedPrompts>`, `<LayoutCoachFab>`,
* `<HeroStrip>` …) render the component in isolation and don't.
*
* Mirrors the defensive pattern in `useFeatureFlags()`: when no
* `QueryClientContext` is mounted we short-circuit to the "no opt-out"
* default so the legacy tests keep rendering the surface, and the gate
* stays correct for the production app where the provider is always
* mounted.
* v1.4.48 M4 — share the `<QueryClientProvider>`-mount detection with
* `useFeatureFlags()` via the `_internal/use-query-client-safe`
* helper. When no client is mounted we short-circuit to the "no
* opt-out" default; the inner hook is only invoked once the provider
* is known to be in the tree, so the conditional call is safe per the
* Rules of Hooks (the branch is stable across the component's
* lifetime).
*/
export function useDisableCoach(): boolean {
const hasClient = useContext(
QueryClientContext as unknown as React.Context<unknown>,
);
const hasClient = useQueryClientMounted();
if (!hasClient) return false;
// eslint-disable-next-line react-hooks/rules-of-hooks
return useDisableCoachInner();
+7 -4
View File
@@ -1,9 +1,9 @@
"use client";
import { useContext } from "react";
import { QueryClientContext, useQuery } from "@tanstack/react-query";
import { useQuery } from "@tanstack/react-query";
import { queryKeys } from "@/lib/query-keys";
import { useQueryClientMounted } from "@/hooks/_internal/use-query-client-safe";
/**
* v1.4.31 — Client-side accessor for the operator's assistant
@@ -77,10 +77,13 @@ async function fetchFeatureFlags(): Promise<FeatureFlagsPayload> {
* renders — so the conditional hook call is safe per the Rules of
* Hooks (same posture the React docs document for "different
* environments where the same component renders").
*
* v1.4.48 M4 — the SSR-mount probe is shared with `useDisableCoach`
* via `_internal/use-query-client-safe` so the eslint-disable line
* stays in exactly one place per consumer.
*/
export function useFeatureFlags(): AssistantFlagSet {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const hasClient = useContext(QueryClientContext as unknown as React.Context<any>);
const hasClient = useQueryClientMounted();
if (!hasClient) return DEFAULT_ASSISTANT_FLAGS;
// eslint-disable-next-line react-hooks/rules-of-hooks
return useFeatureFlagsQuery();