Type Definitions
TypeScript types for @guardrail-sim/policy-engine
Type Definitions
All TypeScript types exported by @guardrail-sim/policy-engine.
Order
Represents a B2B order for policy evaluation.
interface Order {
/** Total order value in dollars */
order_value: number;
/** Total units in the order */
quantity: number;
/** Base margin as decimal (0.40 = 40%) */
product_margin: number;
/** Customer tier/segment (optional) */
customer_segment?: string;
}Policy
A policy containing multiple rules.
interface Policy {
/** Unique policy identifier */
id: string;
/** Human-readable policy name */
name: string;
/** Array of policy rules */
rules: PolicyRule[];
}PolicyRule
A single rule in a policy, wrapping json-rules-engine format.
interface PolicyRule {
/** Rule identifier */
name: string;
/** Rule conditions */
conditions: {
all?: RuleCondition[];
any?: RuleCondition[];
};
/** Event triggered when rule matches */
event: {
type: string;
params?: Record<string, unknown>;
};
/** Rule priority (higher = first) */
priority?: number;
}RuleCondition
A condition within a rule.
type RuleCondition = FactCondition | NestedCondition;
interface FactCondition {
fact: string;
operator: string;
value: unknown;
}
interface NestedCondition {
all?: RuleCondition[];
any?: RuleCondition[];
}EvaluationResult
Result of evaluating an order against a policy.
interface EvaluationResult {
/** Whether the discount was approved */
approved: boolean;
/** List of policy violations */
violations: Violation[];
/** Rules that were triggered */
applied_rules: string[];
/** Calculated margin after discount */
calculated_margin: number;
}Violation
A violation that occurred during policy evaluation.
interface Violation {
/** Rule that was violated */
rule: string;
/** Human-readable violation message */
message: string;
/** UCP-compatible error code */
ucp_error_code?: UCPErrorCode;
}UCPErrorCode
UCP-compatible error codes for discount validation.
type UCPErrorCode =
| 'discount_code_expired'
| 'discount_code_invalid'
| 'discount_code_already_applied'
| 'discount_code_combination_disallowed'
| 'discount_code_user_not_logged_in'
| 'discount_code_user_ineligible';LineItem
A line item for allocation calculation.
interface LineItem {
item_id: string;
subtotal: number;
}Allocation
Discount allocation for a line item.
interface Allocation {
item_id: string;
amount: number;
}