exframe-rules
v1.0.2
Published
exframe-rules description
Downloads
272
Readme
exframe-rules
A lightweight module to handle fetching and evaluating rules
Constructor arguments:
- db object The database object
- cacheTimeout number (optional, default 60) The time in seconds to cache the rules
evaluate() arguments:
- context object The context object
- rule object The rule object
- companyCode string
- state string
- product string
- code string
- document object The document object
Based on the 'condition' of the fetch rule, returns either the default 'onTrue' or 'onFalse' output value.
See the test/index.test.js
file for examples.
Example usage:
import { Rules } from 'exframe-rules';
const rules = new Rules(db);
const { companyCode, state, product } = document.csp;
const result = await rules.evaluate(
context,
{
companyCode,
state,
product,
code: shortRated
},
document
);