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.
This commit is contained in:
Marc-André Bombeck committed 2026-06-08 20:09:09 +02:00
1 parent 82d4081ac5
commit dfb6a7f298
3 files changed
+40 -19

No files matched your search

@@ -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 {
+2 -18
View File
@@ -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.
@@ -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;