()
| 16 | const accountClient = require('./support/account-api-client') |
| 17 | |
| 18 | async function start () { |
| 19 | /** |
| 20 | * Setup a new engine |
| 21 | */ |
| 22 | const engine = new Engine() |
| 23 | |
| 24 | /** |
| 25 | * Rule for identifying microsoft employees that have been terminated. |
| 26 | * - Demonstrates re-using a same fact with different parameters |
| 27 | * - Demonstrates calling a base fact, which serves to load data once and reuse later |
| 28 | */ |
| 29 | const microsoftRule = { |
| 30 | conditions: { |
| 31 | all: [{ |
| 32 | fact: 'account-information', |
| 33 | operator: 'equal', |
| 34 | value: 'microsoft', |
| 35 | path: '$.company' |
| 36 | }, { |
| 37 | fact: 'account-information', |
| 38 | operator: 'equal', |
| 39 | value: 'terminated', |
| 40 | path: '$.status' |
| 41 | }] |
| 42 | }, |
| 43 | event: { type: 'microsoft-terminated-employees' } |
| 44 | } |
| 45 | engine.addRule(microsoftRule) |
| 46 | |
| 47 | /** |
| 48 | * Rule for identifying accounts older than 5 years |
| 49 | * - Demonstrates calling a base fact, also shared by the account-information-field fact |
| 50 | * - Demonstrates performing computations on data retrieved by base fact |
| 51 | */ |
| 52 | const tenureRule = { |
| 53 | conditions: { |
| 54 | all: [{ |
| 55 | fact: 'employee-tenure', |
| 56 | operator: 'greaterThanInclusive', |
| 57 | value: 5, |
| 58 | params: { |
| 59 | unit: 'years' |
| 60 | } |
| 61 | }] |
| 62 | }, |
| 63 | event: { type: 'five-year-tenure' } |
| 64 | } |
| 65 | engine.addRule(tenureRule) |
| 66 | |
| 67 | /** |
| 68 | * Register listeners with the engine for rule success and failure |
| 69 | */ |
| 70 | let facts |
| 71 | engine |
| 72 | .on('success', event => { |
| 73 | console.log(facts.accountId + ' DID '.green + 'meet conditions for the ' + event.type.underline + ' rule.') |
| 74 | }) |
| 75 | .on('failure', event => { |
no test coverage detected
searching dependent graphs…