A module for evaluating ZEN expressions and making decisions based on provided context.
ZEN Module Documentation
A module for evaluating ZEN expressions and making decisions based on provided context.
Basic Usage
import zen from 'zen';
// Evaluate a ZEN expression
const result = zen.evaluateExpression('value > 10', {{ value: 15 });
// Evaluate using a decision file (from same project)
const decision = await zen.evaluate('pricing-rules', {
orderId: '123',
total: 99.99
});
API Reference
evaluateExpression(expression, context)
Evaluates a ZEN expression with the given context.
const context = { age: 25 };
const result = zen.evaluateExpression('age >= 18', context);
// result: true
evaluateUnaryExpression(expression, context)
Evaluates a ZEN unary expression that returns a boolean.
const context = { $: 'active'};
const result = zen.evaluateUnaryExpression('"active"', context);
// result: true
evaluate(key, context, options?)
Evaluates a decision file from the same project identified by the key using provided context.
const result = await zen.evaluate('discount-rules', {
customer: { type: 'premium' },
orderTotal: 150
}, {
trace: true // Enable tracing for debugging
});
Response format:
{
result: any, // Evaluation result
performance: string, // Performance metrics
trace?: any // Trace data if enabled
}
Context Requirements (Unary)
- All context objects must contain a
$
key with the values to be evaluated - The
$
object holds the variables referenced in expressions
Options
EvaluateOptions
for the evaluate method:
{
trace?: boolean // Enable/disable evaluation tracing
}