Kaizen
Browse modulesRulesrules/sharedFunctions

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:

  1. status === "active" — the row is enabled for runtime.
  2. is_current — only the latest version of the rule.
  3. Domain / organization match.
  4. Wall-clock lifecycle: rule_effective_date / rule_expiration_date are inclusive bounds checked against DateTime.now(). A null on either side means open-ended. Tests can pin the clock via vi.setSystemTime(...). This is the canonical mechanism for "rule only fires during this wall-clock window" — there is no separate condition for it (the legacy TIME_WINDOW condition 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 (see PRICING_SCHEDULE / RelativeDateCheckConfig.evaluation_date_field in condition-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

ParameterType
rulesTableRecord<string, Rule>
domainstring
organizationIdstring

Returns

Rule[]

On this page