Skip to content

Commit

Permalink
feat: merge mowali branch (#286)
Browse files Browse the repository at this point in the history
* Tests converted to Jest

* Added rules engine jsonpath dynamic fact

* Updated rules engine API. Added jsonpath package to dependencies. Added rules engine tests. Added Jest config. Added example rules.json.

* Updated hapi/subtext to patch vulnerability

* Updated example rules and corresponding tests to reflect real form of payer and payee

* Added switch endpoint to config to obtain payer and payee information for rules engine. Stubbed validateQuoteRequest method in relevant tests. Running rules engine in validateQuoteRequest (but not doing anything with the results yet).

* Tests converted to Jest

* Replaced coverage-check script. Added coverage threshold to jest config. Removed Istanbul config.

* Uninstalled and reinstalled jest to fix vulnerability

* Added junit + config. Added test:junit npm script. Modified circle config to call junit script. Added test results directory to gitignore.

* Modified example rules and corresponding tests to better reflect actual payer and payee facts

* Updated redirect address to redirect fsp. Made the linter happy. Added rule execution and event handling. Removed empty quote validation, replaced with rules engine execution. Removed redundant setImmediate. New test for INVALID_QUOTE_REQUEST event. Expanded INVALID_QUOTE_REQUEST unit tests.

* Manual merge from upstream

* Integrated properly the new `model/rules.js` into `model/quotes.js` and updated the `quotes.tests.js` accordingly.

* Simplified block of code that was unnecessarily using `map`.

* Forwarding event-handler-modified quote request and headers instead of originals

* Fixed tests by poorly mocking handleRuleEvents on the quotes model

* Cleaned a little bit the result of `handleRuleEvents`;
Updated unit tests in order to pass according to latest code changes.

* Deduplicated the functionality of request sending

* Removed `setImmediate` from all places that it was used.

* Use `CreateInternalServerFSPIOPError` instead of `CreateFSPIOPError`

* mowdev-3411

* added more rules

* Feature/846 async logging (#100)

* Add file logging support in docker, update dependencies

* Add back missing package after merge conflicts

* Feature/update json rules engine (#101)

* Simplified rules unit tests

* Updated json-rules-engine

* Updated code to use native json-rules-engine jsonpath syntax

* Made linter happy. Removed jsonpath dependency.

* Feature/test fx rules (#102)

* Added skeleton for fx rules unit tests

* Removed commented tests from original file

* Update fx.test.js

* added more rules and tests

* test discard

* test discard

* test discard

* stripe off accept header for PUT requests

* added package-lock.json

* added more rules

* fixed the package.json version

* fixed version number

* fixed the Object.assign

* removed rules.json

* update package-lock.json

* Attempt cache refresh

* Replace audit:check with audit

* Debug with verbose audit

* Skip vulnerability check because of network errors

* Skip vuln check step

* downgrade helm version

* temp logging

* renamed switchEndpoint to a better name

* removed config from dockerfile

* Added synchronous responses for rules engine invalid quote errors (#127)

* Added synchronous responses for rules engine invalid quote errors

* Corrected import

* Corrected error variable name

* Moved response handling out of model, into handlers

* Fixed tests

* added error code

* added swagger changes

* added error handling when there are no active accounts

* added error handling when there are no active accounts

* added error handling when there are no active accounts

* fixed error responses sync and async

* fixed the rounting problem with forex quotes

* fixed the rounting problem with forex quotes

* fixed the rounting problem with forex quotes

* removed fspiop-uri header

* removed fspiop-signature header

* added one more error code to sync errors

* added more error handling

* Updated package version

* Do not modify headers in case they are only being relayed to another DFSP.

* Do not delete `FSPIOP-Signature` header unless if `modifyHeaders` is `true`.

* Merged `master` into this branch.

* fixed the bug with createQuoteExtensions

* fixed issue with createQuoteExtension

* Revert change of the error message as it breaks tests.

* Aligned an error message with the master branch to match Postman test's assertions.

* Fixed some npm vulnerabilities and skipped the rest.

* Updated circle CI config according to master branch.

* Removed `quoteId` from error log message as it causes error due its exceeding length.

* fixed error message

* added test currencies

* resolve audit issues

* fix audit issues

* fix audit issues

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* Fixed the tests

* changed the way we add headers

* refactoring

* refactoring

* removed the hardcoded headers

* removed the hardcoded headers

* updated README

* fixed swagger

* revert sync changes

* revert sync changes

* revert sync changes

* revert sync changes

* revert sync changes

* revert sync changes

* revert sync changes

* fixed issue with createPayerParty

* fixed issue with createPayerParty

* fixed issue with eslint version

* Update src/model/quotes.js

Co-authored-by: Sam <10507686+elnyry-sam-k@users.noreply.github.com>

* Update src/model/quotes.js

Co-authored-by: Sam <10507686+elnyry-sam-k@users.noreply.github.com>

* Update src/model/quotes.js

Co-authored-by: Sam <10507686+elnyry-sam-k@users.noreply.github.com>

* Update src/model/quotes.js

Co-authored-by: Sam <10507686+elnyry-sam-k@users.noreply.github.com>

* fixed audit issue

* fixed audit issue

* bring in latest mowali version

* audit resolve

* revert package version

* removed the implementation specific payer/payee validation

* removed the implementation specific payer/payee validation

* removed comments

Co-authored-by: msk- <mattkingston@gmail.com>
Co-authored-by: Vassilis Barzokas <vassilis.barzokas@modusbox.com>
Co-authored-by: shashi165 <shashikant.hirugade@softwaregroup.com>
Co-authored-by: Lewis Daly <lewis@vesselstech.com>
Co-authored-by: Kamuela Franco <kamuela.franco@gmail.com>
Co-authored-by: Sam <10507686+elnyry-sam-k@users.noreply.github.com>
  • Loading branch information
7 people authored Feb 11, 2022
1 parent ca5dbeb commit f92299b
Show file tree
Hide file tree
Showing 19 changed files with 2,452 additions and 1,428 deletions.
113 changes: 113 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,119 @@ push a release triggering another subsequent build that also publishes a docker
- It is unknown if a race condition might occur with multiple merges with master in
quick succession, but this is a suspected edge case.


## How to use quoting-service JSON rules
### About rules.json
The rules.json file acts as a rules engine and enables you to define arbitrary rules that will accept or reject quotes. A rule is defined as an object with a title, a conditions object, and an event object. A rule specifies that if certain conditions are met, then the specified event will be generated.

The rules engine used by the quoting-service is an off-the-shelf rules engine, called json-rules-engine. For detailed information on how to write rules, see the [json-rules-engine documentation](https://github.com/CacheControl/json-rules-engine/blob/master/docs/rules.md). This page only focuses on those details that are relevant for adding support for new currencies.

### Conditions
Conditions are a combination of facts, paths, operators, and values.

Each rule's conditions must have either an all or an any operator at its root, containing an array of conditions. The all operator specifies that all conditions must be met for the rule to be applied. The any operator only requires one condition to be met for the rule to be applied.

Operators within the individual conditions can take the following values:

- `equal:` fact must equal value (string or numeric value)
- `notEqual:` fact must not equal value (string or numeric value)
- `in:` fact must be included in value (an array)
- `notIn:` fact must not be included in value (an array)
- `contains:` fact (an array) must include value
- `doesNotContain:` fact (an array) must not include value

### Events
Event objects must have a type property, and an optional params property. There are two types of events:

- `INTERCEPT_QUOTE`: Used for redirecting quote requests.
- `INVALID_QUOTE_REQUEST`: Used for validation rules. You do not have to use this type of event when adding support for new currencies.

### Configuration – an example
```
[
{
"title": "This is UGX -> ZMW transfer rule",
"conditions": {
"all": [
{
"fact": "headers",
"path": "$.fspiop-source",
"operator": "notIn",
"value":[
"DFSPUGX",
"DFSPZMW"
]
},
{
"fact": "payer",
"path": "$.accounts[?(@.ledgerAccountType == 'POSITION' && @.isActive == 1)].currency",
"operator": "equal",
"value": "UGX"
},
{
"fact": "payee",
"path": "$.accounts[?(@.ledgerAccountType == 'POSITION' && @.isActive == 1)].currency",
"operator": "equal",
"value": "ZMW"
}
]
},
"event":{
"type": "INTERCEPT_QUOTE",
"params":{
"rerouteToFsp": "DFSPUGX",
"additionalHeaders": {
"x-fspiop-sourcecurrency": "UGX",
"x-fspiop-destinationcurrency": "ZMW"
}
}
}
},
{
"title": "Payee fsp should have only one active account",
"conditions": {
"all": [
{
"any": [
{
"fact": "payload",
"path": "$.amount.currency",
"operator": "notIn",
"value": {
"fact": "payer",
"path": "$.accounts[?(@.ledgerAccountType == \"POSITION\" && @.isActive == 1)].currency"
}
},
{
"fact": "payload",
"path": "$.amount.currency",
"operator": "notIn",
"value": {
"fact": "payee",
"path": "$.accounts[?(@.ledgerAccountType == \"POSITION\" && @.isActive == 1)].currency"
}
}
]
},
{
"fact": "payee",
"path": "$.accounts[?(@.ledgerAccountType == \"POSITION\" && @.isActive == 1)]",
"operator": "isArray",
"value": true
}
]
},
"event": {
"type": "INVALID_QUOTE_REQUEST",
"params": {
"FSPIOPError": "PAYEE_ERROR",
"message": "Payee FSP has more than 1 active currency account. Switch does not support more than 1 active currency account for Forex Requests"
}
}
}
]
```
## Additional Notes

N/A
58 changes: 34 additions & 24 deletions audit-resolve.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,54 @@
{
"decisions": {
"1002401|@mojaloop/central-services-shared>widdershins>yargs>string-width>strip-ansi>ansi-regex": {
"1004854|@mojaloop/central-services-shared>widdershins>openapi-sampler>json-pointer": {
"decision": "ignore",
"madeAt": 1634736537116,
"expiresAt": 1637328532038
"madeAt": 1644325757825,
"expiresAt": 1646917672191
},
"1002401|@mojaloop/central-services-shared>widdershins>yargs>cliui>string-width>strip-ansi>ansi-regex": {
"1004869|@mojaloop/central-services-shared>widdershins>swagger2openapi>better-ajv-errors>jsonpointer": {
"decision": "ignore",
"madeAt": 1634736537116,
"expiresAt": 1637328532038
"madeAt": 1644325761263,
"expiresAt": 1646917672191
},
"1002865|@mojaloop/central-services-shared>shins>sanitize-html": {
"1004869|@mojaloop/central-services-shared>widdershins>swagger2openapi>oas-validator>better-ajv-errors>jsonpointer": {
"decision": "ignore",
"madeAt": 1634736539173,
"expiresAt": 1637328532038
"madeAt": 1644325761263,
"expiresAt": 1646917672191
},
"1002866|@mojaloop/central-services-shared>shins>sanitize-html": {
"1004946|@mojaloop/central-services-shared>widdershins>yargs>string-width>strip-ansi>ansi-regex": {
"decision": "ignore",
"madeAt": 1634736539173,
"expiresAt": 1637328532038
"madeAt": 1644325764910,
"expiresAt": 1646917672191
},
"1003019|@mojaloop/central-services-shared>widdershins>yargs>yargs-parser": {
"1004946|@mojaloop/central-services-shared>widdershins>yargs>cliui>string-width>strip-ansi>ansi-regex": {
"decision": "ignore",
"madeAt": 1634736540650,
"expiresAt": 1637328532038
"madeAt": 1644325764910,
"expiresAt": 1646917672191
},
"1004809|@mojaloop/central-services-shared>widdershins>openapi-sampler>json-pointer": {
"1005383|@mojaloop/central-services-shared>shins>sanitize-html": {
"decision": "ignore",
"madeAt": 1636987481291,
"expiresAt": 1639579470858
"madeAt": 1644325767287,
"expiresAt": 1646917672191
},
"1004812|@mojaloop/central-services-shared>widdershins>swagger2openapi>better-ajv-errors>jsonpointer": {
"1005384|@mojaloop/central-services-shared>shins>sanitize-html": {
"decision": "ignore",
"madeAt": 1636987484386,
"expiresAt": 1639579470858
"madeAt": 1644325767287,
"expiresAt": 1646917672191
},
"1004812|@mojaloop/central-services-shared>widdershins>swagger2openapi>oas-validator>better-ajv-errors>jsonpointer": {
"1005534|@mojaloop/central-services-shared>widdershins>yargs>yargs-parser": {
"decision": "ignore",
"madeAt": 1636987484386,
"expiresAt": 1639579470858
"madeAt": 1644325769863,
"expiresAt": 1646917672191
},
"1006846|@mojaloop/central-services-shared>shins>sanitize-html>postcss": {
"decision": "ignore",
"madeAt": 1644325772190,
"expiresAt": 1646917672191
},
"1006886|@mojaloop/central-services-shared>shins>markdown-it": {
"decision": "ignore",
"madeAt": 1644325774956,
"expiresAt": 1646917672191
}
},
"rules": {},
Expand Down
Loading

0 comments on commit f92299b

Please sign in to comment.