Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
@wizeapps/rule-engine
Advanced tools
Engine to process business rules.
GET
] /api/rule-metadata - Lists all metadata for setting rulesPOST
] /api/execute-rules - Executes rulesPOST
] /api/wizeeventregistries - Registers events/hooks for data changesDELETE
] /api/wizeeventregistries/:id - De-registers eventsnpm install --save @wizeapps/rule-engine
import wizeRuleEngine from '@wizeapps/rule-engine';
.
.
.
/*
app: koa-app returned from 'const app = createServer({});'
sequelizeSource: sequelize object returned from 'import sequelizeSource from './sources/postgresql';'
*/
wizeRuleEngine(app, sequelizeSource);
import {runRule} from '@wizeapps/rule-engine';
Example with JSON rules
const fact = {fld1: 'F1', fld2: 100};
const jsonRules = [
{
name: 'Rule 2.1: FLD1 is F1 AND FLD2 > 50',
condition: `this.fld1 === 'F1' && this.fld2 > 50`,
consequence: `const rule = Object.assign({}, R.rule()); delete rule.condition; delete rule.consequence; delete rule.on;
this.eligibility = this.eligibility || []; this.eligibility.push(rule);`
},
{
name: 'Rule 2.2: FLD2 >= 50',
condition: `this.fld2 >= 50`,
consequence: `const rule = Object.assign({}, R.rule()); delete rule.condition; delete rule.consequence; delete rule.on;
this.eligibility = this.eligibility || []; this.eligibility.push(rule);`
},
{
name: 'Rule 2.3: FLD2 > 100',
condition: `this.fld2 > 100`,
consequence: `const rule = Object.assign({}, R.rule()); delete rule.condition; delete rule.consequence; delete rule.on;
this.eligibility = this.eligibility || []; this.eligibility.push(rule);`
}
];
const result = await runRule(jsonRules, fact);
Result
{
fld1: 'F1',
fld2: 100,
result: true,
eligibility: [
{name: 'Rule 2.1: FLD1 is F1 AND FLD2 > 50'},
{name: 'Rule 2.2: FLD2 >= 50'}
],
matchPath: ['Rule 2.1: FLD1 is F1 AND FLD2 > 50', 'Rule 2.2: FLD2 >= 50']
};
Example with PMT function
const fact = {fld1: 'F1', fld2: 100};
const jsonRule = {
name: 'Rule 1',
condition: `this.fld1 === 'F1' && this.fld2 > 50`,
consequence: `const rule = Object.assign({}, R.rule()); delete rule.condition; delete rule.consequence; delete rule.on;
this.eligibility = this.eligibility || []; this.eligibility.push(rule); this.monthlyfld2 = -1* this.helper.pmt(0.05/12, 5*12,this.fld2,0,0);`
};
const result = await util.runRule(jsonRule, fact);
expect(Number(Number(result.monthlyfld2).toFixed(2))).to.equal(1.89);
Example with actual rules
const fact = {
fld1: 'F1',
InnerArray: [{
fld2: 'Field 2',
amount: 200,
}],
};
const eligibilityRules = [
{
name: 'F1 and Amount >= 200',
condition: function (R) {
const fld2Query = this.InnerArray ? this.InnerArray.find(i => i.fld2 === 'Field 2') : null;
R.when(this.fld1 === 'F1' && (fld2Query ? fld2Query.amount : 0) >= 200);
},
consequence: function (R) {
this.remarks = 'Scenario 1';
R.stop();
},
},
{
name: 'Other',
condition: function (R) {
const fld2Query = this.InnerArray ? this.InnerArray.find(i => i.fld2 === 'Field 2') : null;
R.when(fld2Query);
},
consequence: function (R) {
this.remarks = 'Other';
R.stop();
},
},
];
const result = await util.runActualRule(eligibilityRules, fact);
expect(result.remarks).to.equal('Scenario 1');
Result
{
fld1: 'F1',
InnerArray: [ { fld2: 'Field 2', amount: 200 } ],
result: true,
remarks: 'Scenario 1',
matchPath: [ 'F1 and Amount >= 200' ]
};
npm run test
MIT License
FAQs
Engine to process business rules
The npm package @wizeapps/rule-engine receives a total of 3 weekly downloads. As such, @wizeapps/rule-engine popularity was classified as not popular.
We found that @wizeapps/rule-engine demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.