bfrp-bfr-validation-engine v1.3.0
BFRP-BFR-ValidationEngine
Custom form data validation engine for BFRP-BFR application to be used with Javascript frameworks
frontend or NodeJS
server
This project was generated with yarn version 1.9.1.
Babel v7.6.4 is being used to transpile ES6+
codes, and Jest v24.9.0 with code coverage reporter istanbul/nyc (built in with Jest) to run tests.
Getting Started
Prerequisites
Node v8+ is required.
yarn
is preferred. If you prefer using npm
as your package manager, replace yarn
with npm
in the commands below.
To develop/run the Azure functions serverless API of the validation engine locally, install version 2.x of the Azure Functions Core Tools.
Install packages
Run yarn install
from project root to install all necessary packages.
Development with watch mode
Validation Engine
src/app
contains code for the actual validation engine module. src/index.js
is to run and check validation engine functionalities to speed up development
Create a directory named
mock
in the projectsrc
directory and put a file namedformData.json
with sample form data.Run the following command to run the project in development mode. The project would re-run itself when there is any changes in
.js
files insrc
directory
yarn start
Validation API - Azure Functions
validation-api
contains code for the validation engine serverless api. validation-api/ValidationEngine
contains the distribution copy of the validation engine.
From project root directory, run
yarn build
to build a production copy of the validation engine. It will also copy the code insidevalidation-api/ValidationEngine
cd validation-api
directoryCreate
local.settings.json
file with the content below. This also adds thevalidationFileNameTemplate
variable that is used to load right validation configuration file.ENV
andBFRTYPE
variables used in the previous version of the validation engine are NOT used anymore.{ "IsEncrypted": false, "Values": { "validationFileNameTemplate": "validationconfig", "blobStorageHost": "http://remotehost.url/bfr/" }, "Host": { "LocalHttpPort": 7072, "CORS": "*" } }
Run the following command to run the serverless api project locally. The project would re-run itself when there is any changes in
.js
files invalidation-api
directory
yarn install
func start
Build and Test
Testing
Run the following command to test the application based on specs specified in __test__
directory
yarn test # npm test
To run tests in watch mode to changes in the spec files, run-
yarn test:watch # npm run test:watch
To check test coverage, run-
yarn test:coverage # npm run test:coverage
Production Build
Validation Engine
Run the following command to build as ES6+
module in dist
directory.
yarn build # npm run build
Validation Azure Serverless Api
Run the following command to have the Azure Functions serverless api with latest version of the validation engine inside validation-api
directory.
yarn build
Usage
The module can then be imported to Javascript frameworks
or NodeJS
applications as
ES6+
import ValidationEngine from './path-to-module'
ES5 with Webpack or CommonJS
const ValidationEngine = require('./path-to-module')
The module can be instantiated with validation configuration as below
const valEngine = new ValidationEngine(config)
Config Data Structure
{
"VAL2260S": {
"type": "SOFT",
"logicRule": "001-Sum of main cells exceeds threshold",
"mainCells": [
"218-1"
],
"threshold": 50,
"warningFlag1": "Some warning data",
"warningFlag2": "VAL2260S: Some additional warning data",
"enabled": true
}
}
1 year ago