1.3.0 • Published 1 year ago

bfrp-bfr-validation-engine v1.3.0

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

Build Status

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

  1. Create a directory named mock in the project src directory and put a file named formData.json with sample form data.

  2. 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 in src 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.

  1. From project root directory, run yarn build to build a production copy of the validation engine. It will also copy the code inside validation-api/ValidationEngine

  2. cd validation-api directory

  3. Create local.settings.json file with the content below. This also adds the validationFileNameTemplate variable that is used to load right validation configuration file. ENV and BFRTYPE 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": "*"
     }
    }
  4. 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 in validation-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.3.0

1 year ago