exframe-schema

2.5.12 • Public • Published

exframe-schema

A module to handle building and validating document schemas based on information from the document-configuration service.

Validate a document

const { validate } = require('exframe-schema');
try {
  validate(context, configuration, document);
  // Document is valid
} catch (e) {
  // For the case where coverageLimits.dwelling is required, but missing:
  console.log(e.validationErrors[0].dataPath);
  // ./coverageLimits
  console.log(e.validationErrors[0].params);
  // { missingProperty: 'dwelling' }
  // For validation schema used to validate document
  console.log(e.validationSchema);
}

Arguments:

  • context object The context object. If the context object contains a log, debug information will be logged there. If not, debug information will not be logged.
  • configuration object Contains coverage details and form fields
    • coverageDetails object A coverageDetails object containing coverageLimits, coverageOptions and deductibles
    • formFields array A collection of formFields objects
  • document object The document to be validated

Create form fields from coverage options

const { addCoverageOptions } = require('exframe-schema');

let fields = addCoverageOptions(coverageDetails);
console.log(fields);
/*
[
  {
     path: 'coverageOptions',
     type: 'object',
     metaData: {},
     children: [ 'coverageOptions.sinkholePerilCoverage' ],
     required: [ 'coverageOptions.sinkholePerilCoverage' ],
     group: 'coverage'
  },
  {
     path: 'coverageOptions.sinkholePerilCoverage',
     type: 'object',
     displayText: 'Sinkhole Peril Coverage',
     metaData: {},
     children: [ 'coverageOptions.sinkholePerilCoverage.answer' ],
     required: [ 'coverageOptions.sinkholePerilCoverage.answer' ]
  },
  {
     path: 'coverageOptions.sinkholePerilCoverage.answer',
     type: 'boolean',
     metaData: { }
  }
];
*/

Arguments:

  • coverageDetails object A coverageDetails object containing coverageLimits, coverageOptions and deductibles
  • document object (optional) The document to be validated

Create form fields from coverage limits

const { addCoverageLimits } = require('exframe-schema');

let fields = addCoverageLimits(coverageDetails);
console.log(fields);

/*
[
  {
    path: 'coverageLimits',
    type: 'object',
    metaData: {},
    required: [ 'coverageLimits.dwelling' ],
    children: [ 'coverageLimits.dwelling' ],
    group: 'coverage'
  },
  {
    path: 'coverageLimits.dwelling',
    type: 'object',
    metaData: {},
    children: [ 'coverageLimits.dwelling.value', 'coverageLimits.dwelling.amount', 'coverageLimits.dwelling.letterDesignation' ],
    required: [ 'coverageLimits.dwelling.value' ]
  },
  {
    path: 'coverageLimits.dwelling.value',
    type: 'string',
    metaData: { }
  },
  {
    path: 'coverageLimits.dwelling.amount',
    type: 'integer',
    metaData: {},
    value: '${it.coverageLimits.dwelling.value}'
  },
  {
    path: 'coverageLimits.dwelling.letterDesignation',
    type: 'string',
    metaData: {}
  }
]
*/

fields = addCoverageLimits(coverageDetails, document);
console.log(fields);

/*
[
  {
    path: 'coverageLimits',
    type: 'object',
    metaData: {},
    required: [ 'coverageLimits.dwelling' ],
    children: [ 'coverageLimits.dwelling' ],
    group: 'coverage'
  },
  {
    path: 'coverageLimits.dwelling',
    type: 'object',
    metaData: {},
    children: [ 'coverageLimits.dwelling.value', 'coverageLimits.dwelling.amount', 'coverageLimits.dwelling.letterDesignation' ],
    required: [ 'coverageLimits.dwelling.value' ]
  },
  {
    path: 'coverageLimits.dwelling.value',
    type: 'string',
    metaData: { }
  },
  {
    path: 'coverageLimits.dwelling.amount',
    type: 'integer',
    metaData: {},
    value: 200000
  },
  {
    path: 'coverageLimits.dwelling.letterDesignation',
    type: 'string',
    metaData: {}
  }
]
*/

Arguments:

  • coverageDetails object A coverageDetails object containing coverageLimits, coverageOptions and deductibles
  • document object (optional) The document to be validated

Create form fields from deductibles

const { addDeductibles } = require('exframe-schema');

let fields = addDeductibles(coverageDetails);
console.log(fields);

/*
[
  {
    path: 'deductibles',
    type: 'object',
    metaData: {},
    children: [ 'deductibles.hurricane', 'deductibles.sinkhole' ],
    required: [ 'deductibles.hurricane' ],
    group: 'coverage'
  },
  {
    path: 'deductibles.hurricane',
    type: 'object',
    metaData: {},
    children: ['deductibles.hurricane.value', 'deductibles.hurricane.amount'],
    required: ['deductibles.hurricane.value']
  },
  {
    path: 'deductibles.hurricane.value',
    type: 'integer',
    metaData: {},
    children: [],
    required: []
  },
  {
    path: 'deductibles.hurricane.amount',
    type: 'integer',
    metaData: {},
    children: [],
    required: [],
    value: '${it.deductibles.hurricane.value}'
  },
  {
    path: 'deductibles.sinkhole',
    type: 'object',
    metaData: {},
    children: ['deductibles.sinkhole.value', 'deductibles.sinkhole.amount'],
    required: ['deductibles.sinkhole.value']
  },
  {
    path: 'deductibles.sinkhole.value',
    type: 'integer',
    metaData: {},
    children: [],
    required: []
  },
  {
    path: 'deductibles.sinkhole.amount',
    type: 'integer',
    metaData: {},
    children: [],
    required: [],
    value: '${it.deductibles.hurricane.value}'
  }
];
*/

fields = addDeductibles(coverageDetails, document);
console.log(fields);

/*
[
  {
    path: 'deductibles',
    type: 'object',
    metaData: {},
    children: [ 'deductibles.hurricane', 'deductibles.sinkhole' ],
    required: [ 'deductibles.hurricane' ],
    group: 'coverage'
  },
  {
    path: 'deductibles.hurricane',
    type: 'object',
    metaData: {},
    children: ['deductibles.hurricane.value', 'deductibles.hurricane.amount'],
    required: ['deductibles.hurricane.value']
  },
  {
    path: 'deductibles.hurricane.value',
    type: 'integer',
    metaData: {},
    children: [],
    required: []
  },
  {
    path: 'deductibles.hurricane.amount',
    type: 'integer',
    metaData: {},
    children: [],
    required: [],
    value: 10000
  },
  {
    path: 'deductibles.sinkhole',
    type: 'object',
    metaData: {},
    children: ['deductibles.sinkhole.value', 'deductibles.sinkhole.amount'],
    required: ['deductibles.sinkhole.value']
  },
  {
    path: 'deductibles.sinkhole.value',
    type: 'integer',
    metaData: {},
    children: [],
    required: []
  },
  {
    path: 'deductibles.sinkhole.amount',
    type: 'integer',
    metaData: {},
    children: [],
    required: [],
    value: 4000
  }
];
*/

Arguments:

  • coverageDetails object A coverageDetails object containing coverageLimits, coverageOptions and deductibles
  • document object (optional) The document to be validated

Readme

Keywords

none

Package Sidebar

Install

npm i exframe-schema

Weekly Downloads

11

Version

2.5.12

License

ISC

Unpacked Size

117 kB

Total Files

9

Last publish

Collaborators

  • exzeo_usa
  • exzeodevops