From dfb6a7f29872294073ab3b01fb65db1ddc3baa07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Mon, 8 Jun 2026 20:09:09 +0200 Subject: [PATCH] fix(medications): keep dose-window defaults off the client server graph The dose-window editor pulled DOSE_WINDOW_DEFAULTS from @/lib/analytics/compliance, dragging the server-only scheduling graph (which imports node:async_hooks) into the client bundle. Turbopack rejected the client chunk; tsc does not model the boundary so the type check stayed green. Move the constant into a leaf module with no server imports and re-export it from compliance so the server path is unchanged. The client-reachable editor now imports the leaf directly. --- .../medications/scheduling/dose-window.ts | 2 +- src/lib/analytics/compliance.ts | 20 +--------- .../scheduling/dose-window-defaults.ts | 37 +++++++++++++++++++ 3 files changed, 40 insertions(+), 19 deletions(-) create mode 100644 src/lib/medications/scheduling/dose-window-defaults.ts diff --git a/src/components/medications/scheduling/dose-window.ts b/src/components/medications/scheduling/dose-window.ts index 0489a0ceb..e260a1bb3 100644 --- a/src/components/medications/scheduling/dose-window.ts +++ b/src/components/medications/scheduling/dose-window.ts @@ -20,7 +20,7 @@ * - day-scale (weekly / rolling): ±1 day on-time, +4 days late tail. */ -import { DOSE_WINDOW_DEFAULTS } from "@/lib/analytics/compliance"; +import { DOSE_WINDOW_DEFAULTS } from "@/lib/medications/scheduling/dose-window-defaults"; /** One persisted explicit window. Matches `doseWindowEntrySchema`. */ export interface DoseWindowEntry { diff --git a/src/lib/analytics/compliance.ts b/src/lib/analytics/compliance.ts index 6d6723dd4..e1acb9718 100644 --- a/src/lib/analytics/compliance.ts +++ b/src/lib/analytics/compliance.ts @@ -32,6 +32,7 @@ import { type ScheduleLike, } from "@/lib/medications/scheduling/cadence"; import { streaksFromTimeline } from "@/lib/medications/scheduling/compliance"; +import { DOSE_WINDOW_DEFAULTS } from "@/lib/medications/scheduling/dose-window-defaults"; import { normaliseDoseWindows } from "@/lib/medications/scheduling/worker-helpers"; import { reconstructDoseHistory, @@ -209,24 +210,7 @@ export function classifyIntakeTiming( * - overdue: up to target + 4 days (late-but-counts) * - missed: > target + 4 days */ -export const DOSE_WINDOW_DEFAULTS = { - /** Daily / intraday on-time half-width around the target instant (min). */ - dailyOnTimeMinutes: 60, - /** - * Daily / intraday overdue tail past the on-time window (min). A dose - * taken inside `[onTime, onTime + overdue]` still counts; beyond it the - * dose is missed. - */ - dailyOverdueMinutes: 240 - 60, - /** Weekly / rolling on-time half-width around the target day (days). */ - weeklyOnTimeDays: 1, - /** - * Weekly / rolling overdue tail past the target day (days) — the clinical - * 4-day GLP-1 rule. A shot inside `[target, target + 4d]` still counts; - * beyond it the dose is missed and the user skips to the next slot. - */ - weeklyOverdueDays: 4, -} as const; +export { DOSE_WINDOW_DEFAULTS }; /** * v1.15.9 — the derived per-dose state the medication card renders. diff --git a/src/lib/medications/scheduling/dose-window-defaults.ts b/src/lib/medications/scheduling/dose-window-defaults.ts new file mode 100644 index 000000000..3831bf840 --- /dev/null +++ b/src/lib/medications/scheduling/dose-window-defaults.ts @@ -0,0 +1,37 @@ +/** + * Default on-time / overdue window widths for the compliance engine. + * + * Kept in its own leaf module — free of any server-only import — so the + * client-side dose-window editor can read the same defaults without + * pulling the full analytics graph (and its `node:async_hooks` deps) + * into the browser bundle. `@/lib/analytics/compliance` re-exports this + * constant so existing server-side imports keep their path. + * + * DAILY / INTRADAY dose (minute-scale windows): + * - on-time: target ± 1h + * - overdue: up to target + 4h (late-but-counts) + * - missed: > target + 4h + * + * WEEKLY / ROLLING injectable (day-scale windows; the 4-day clinical rule): + * - on-time: target day ± 1 day + * - overdue: up to target + 4 days (late-but-counts) + * - missed: > target + 4 days + */ +export const DOSE_WINDOW_DEFAULTS = { + /** Daily / intraday on-time half-width around the target instant (min). */ + dailyOnTimeMinutes: 60, + /** + * Daily / intraday overdue tail past the on-time window (min). A dose + * taken inside `[onTime, onTime + overdue]` still counts; beyond it the + * dose is missed. + */ + dailyOverdueMinutes: 240 - 60, + /** Weekly / rolling on-time half-width around the target day (days). */ + weeklyOnTimeDays: 1, + /** + * Weekly / rolling overdue tail past the target day (days) — the clinical + * 4-day GLP-1 rule. A shot inside `[target, target + 4d]` still counts; + * beyond it the dose is missed and the user skips to the next slot. + */ + weeklyOverdueDays: 4, +} as const;