Function: loadRules()
function loadRules(
rulesTable: Record<string, Rule>,
domain: string,
organizationId: string
): Rule[];Defined in: shared/rules/engine.ts:125
Load current, active rules for a given domain and org. Returns rules sorted by priority (lower first).
Filters applied in order:
status === "active"— the row is enabled for runtime.is_current— only the latest version of the rule.- Domain / organization match.
- Wall-clock lifecycle:
rule_effective_date/rule_expiration_dateare inclusive bounds checked againstDateTime.now(). Anullon either side means open-ended. Tests can pin the clock viavi.setSystemTime(...). This is the canonical mechanism for "rule only fires during this wall-clock window" — there is no separate condition for it (the legacyTIME_WINDOWcondition type was removed in favor of these fields).
Lifecycle bound semantics — the contract UI date controls must write to:
- Both bounds compare instants, not calendar days, and both are
inclusive of the stored instant: the rule is live on
[effective, expiration]. - The comparison is against
DateTime.now()— the wall clock at evaluation time — NOT against any date carried in the evaluation context. Pricing a reservation months ahead therefore uses the rules live today, not the rules that will be live on the stay date. To gate on a context date instead, author a condition that reads it (seePRICING_SCHEDULE/RelativeDateCheckConfig.evaluation_date_fieldincondition-handlers.ts); that is a per-rule authoring choice, deliberately not folded into this filter. - No end-of-day widening and no timezone shifting happens here. A bare calendar date persisted as midnight UTC expires the rule at the start of that day, so an "Ending: On <date>" control must itself store the end of the day in the operator's timezone to mean "live through <date>".
- An unparseable bound is ignored (fails open, rule stays live)
rather than throwing — a malformed date must not take an org's whole
pricing path down. DB-sourced values round-trip through
Date.toISOString(), so this is a defensive branch, not a live one.
Parameters
| Parameter | Type |
|---|---|
rulesTable | Record<string, Rule> |
domain | string |
organizationId | string |
Returns
Rule[]