Class: RuleService
Defined in: server/rules/rule-service.ts:33
Extends
Constructors
Constructor
new RuleService(deps: RulesFeatureDeps): RuleService;Defined in: server/rules/base-rules-service.ts:4
Parameters
| Parameter | Type |
|---|---|
deps | RulesFeatureDeps |
Returns
RuleService
Inherited from
Properties
deps
protected readonly deps: RulesFeatureDeps;Defined in: server/rules/base-rules-service.ts:4
Inherited from
Accessors
actorId
Get Signature
get protected actorId(): string | null;Defined in: server/rules/base-rules-service.ts:6
Returns
string | null
Inherited from
Methods
create()
create(input: {
conditionLogic?: ConditionLogicNode;
description?: string | null;
domain: string;
domainConfig: Record<string, unknown>;
effectiveEnd?: Date | null;
effectiveStart?: Date;
id?: string;
identifier: string;
module?: string | null;
name: string;
organizationId: string;
priority: number;
rateTierId?: string | null;
ruleEffectiveDate?: Date | null;
ruleExpirationDate?: Date | null;
scheduleConditionId?: string | null;
scopes: {
scope_type: string;
scope_value: string[];
}[];
status?: "active" | "inactive" | "archived";
}): Promise<RuleRecordWithVersion>;Defined in: server/rules/rule-service.ts:74
Parameters
| Parameter | Type | Description |
|---|---|---|
input | { conditionLogic?: ConditionLogicNode; description?: string | null; domain: string; domainConfig: Record<string, unknown>; effectiveEnd?: Date | null; effectiveStart?: Date; id?: string; identifier: string; module?: string | null; name: string; organizationId: string; priority: number; rateTierId?: string | null; ruleEffectiveDate?: Date | null; ruleExpirationDate?: Date | null; scheduleConditionId?: string | null; scopes: { scope_type: string; scope_value: string[]; }[]; status?: "active" | "inactive" | "archived"; } | - |
input.conditionLogic? | ConditionLogicNode | - |
input.description? | string | null | - |
input.domain | string | - |
input.domainConfig | Record<string, unknown> | - |
input.effectiveEnd? | Date | null | - |
input.effectiveStart? | Date | - |
input.id? | string | - |
input.identifier | string | - |
input.module? | string | null | - |
input.name | string | - |
input.organizationId | string | - |
input.priority | number | - |
input.rateTierId? | string | null | Pricing-matrix cell wiring (PLA-136). Present in the schema only so RuleService.create has something concrete to reject at runtime — a caller that supplies either field gets a clear error directing them to PricingMatrixService.setCellPrice instead. These fields are only ever constructed by that service via its own internal repository access (bypassing RuleService), never through this public schema. |
input.ruleEffectiveDate? | Date | null | - |
input.ruleExpirationDate? | Date | null | - |
input.scheduleConditionId? | string | null | - |
input.scopes | { scope_type: string; scope_value: string[]; }[] | - |
input.status? | "active" | "inactive" | "archived" | - |
Returns
Promise<RuleRecordWithVersion>
createVersion()
createVersion(id: string, input: {
changeReason?: string | null;
conditionLogic?: ConditionLogicNode;
description?: string | null;
domainConfig?: Record<string, unknown>;
effectiveEnd?: Date | null;
effectiveStart?: Date;
module?: string | null;
name?: string;
priority?: number;
rateTierId?: string | null;
ruleEffectiveDate?: Date | null;
ruleExpirationDate?: Date | null;
scheduleConditionId?: string | null;
scopes?: {
scope_type: string;
scope_value: string[];
}[];
}): Promise<RuleRecordWithVersion>;Defined in: server/rules/rule-service.ts:122
Append a new version. Any version-level field not supplied is copied
forward from the current version, so callers can submit a partial patch
(e.g. only priority) without losing the rest of the rule's content.
Parent-level fields (name, description, module) update the Rules
row in the same transaction.
Guards against two distinct matrix-managed-bypass shapes (PLA-136):
assertNoMatrixFields(input) rejects a caller trying to SET
rateTierId/scheduleConditionId via the patch; the check just below
additionally rejects versioning an ALREADY matrix-managed cell rule at
all, even via a patch that never mentions those fields (e.g.
{ conditionLogic, domainConfig }) — otherwise a caller could silently
overwrite a cell rule's condition_logic/domain_config/priority
through this generic surface, bypassing PricingMatrixService. setCellPrice's tier lock, schedule/org validation, and deterministic
condition_logic rebuild entirely. Mirrors how ConditionService. createVersion/softDelete check the EXISTING row's conditionType,
not just the caller-supplied patch.
Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | - |
input | { changeReason?: string | null; conditionLogic?: ConditionLogicNode; description?: string | null; domainConfig?: Record<string, unknown>; effectiveEnd?: Date | null; effectiveStart?: Date; module?: string | null; name?: string; priority?: number; rateTierId?: string | null; ruleEffectiveDate?: Date | null; ruleExpirationDate?: Date | null; scheduleConditionId?: string | null; scopes?: { scope_type: string; scope_value: string[]; }[]; } | - |
input.changeReason? | string | null | - |
input.conditionLogic? | ConditionLogicNode | - |
input.description? | string | null | - |
input.domainConfig? | Record<string, unknown> | - |
input.effectiveEnd? | Date | null | - |
input.effectiveStart? | Date | - |
input.module? | string | null | - |
input.name? | string | - |
input.priority? | number | - |
input.rateTierId? | string | null | See createRuleInputSchema's doc — same rejection applies here. |
input.ruleEffectiveDate? | Date | null | - |
input.ruleExpirationDate? | Date | null | - |
input.scheduleConditionId? | string | null | - |
input.scopes? | { scope_type: string; scope_value: string[]; }[] | - |
Returns
Promise<RuleRecordWithVersion>
getAllActiveByDomain()
getAllActiveByDomain(domain: string, organizationId: string): Promise<RuleRecordWithVersion[]>;Defined in: server/rules/rule-service.ts:55
Fetch every active, non-deleted rule for the given domain + organization, each paired with its current version. Rules without a current version are excluded (they shouldn't exist, but the CRUD path doesn't enforce it).
Parameters
| Parameter | Type |
|---|---|
domain | string |
organizationId | string |
Returns
Promise<RuleRecordWithVersion[]>
getById()
getById(id: string): Promise<RuleRecord>;Defined in: server/rules/rule-service.ts:34
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
Promise<RuleRecord>
getByIdWithCurrentVersion()
getByIdWithCurrentVersion(id: string): Promise<RuleRecordWithVersion>;Defined in: server/rules/rule-service.ts:39
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
Promise<RuleRecordWithVersion>
setStatus()
setStatus(id: string, status: "active" | "inactive" | "archived"): Promise<RuleRecordWithVersion>;Defined in: server/rules/rule-service.ts:199
Parameters
| Parameter | Type |
|---|---|
id | string |
status | "active" | "inactive" | "archived" |
Returns
Promise<RuleRecordWithVersion>
softDelete()
softDelete(id: string): Promise<RuleRecord>;Defined in: server/rules/rule-service.ts:221
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
Promise<RuleRecord>
transaction()
protected transaction<T>(fn: (deps: RulesFeatureDeps) => Promise<T>): Promise<T>;Defined in: server/rules/base-rules-service.ts:10
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fn | (deps: RulesFeatureDeps) => Promise<T> |
Returns
Promise<T>