Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dcc-business-rules-utils

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dcc-business-rules-utils - npm Package Compare versions

Comparing version 0.5.1 to 0.5.2

2

dist/dcc-validator.d.ts

@@ -36,3 +36,3 @@ import { Rule, RuleType } from "./rule";

*/
export declare const validateDcc: (rules: Rule[], parameters: ValidationParameters, valueSets: CompressedValueSets, dccPayload: any) => boolean;
export declare const validateDcc: (rules: Rule[], parameters: ValidationParameters, valueSets: CompressedValueSets, dccPayload: unknown) => boolean;
//# sourceMappingURL=dcc-validator.d.ts.map
import { ErrorObject } from "ajv";
export declare const createJsonValidatorForSchema: (schema: any) => (json: any) => ErrorObject[];
export declare const createJsonValidatorForSchema: (schema: unknown) => (json: unknown) => ErrorObject[];
//# sourceMappingURL=json-validator.d.ts.map

@@ -11,8 +11,9 @@ "use strict";

const areEqual = (leftSet, rightSet) => leftSet.length === rightSet.length && leftSet.every((item) => rightSet.indexOf(item) > -1);
const withoutPrefix = (prefix) => (str) => str.startsWith(prefix) ? str.substring(prefix.length) : str;
const dataAccessesPrefixed = (expr, prefix) => (0, validation_1.dataAccesses)(expr)
.filter((fieldName) => fieldName.startsWith(prefix))
.map(withoutPrefix(prefix));
const validateAffectedFields = (rule) => {
const payloadPrefix = "payload.";
const actual = rule.AffectedFields;
const computed = (0, validation_1.dataAccesses)(rule.Logic)
.filter((fieldName) => fieldName.startsWith(payloadPrefix))
.map((fieldName) => fieldName.substring(payloadPrefix.length));
const computed = dataAccessesPrefixed(rule.Logic, "payload.");
return areEqual(actual, computed)

@@ -63,2 +64,12 @@ ? null

};
const supportedValueSets = [
"country-2-codes",
"disease-agent-targeted",
"covid-19-lab-test-manufacturer-and-name",
"covid-19-lab-result",
"covid-19-lab-test-type",
"vaccines-covid-19-auth-holders",
"vaccines-covid-19-names",
"sct-vaccines-covid-19", // vaccine-prophylaxis.json
];
/**

@@ -70,2 +81,10 @@ * Validates the given JSON value as a DCC business rule.

const logicValidationErrors = (0, validation_1.validateFormat)(rule.Logic);
const valueSetsAccessed = [...new Set(dataAccessesPrefixed(rule.Logic, "external.valueSets."))];
const unsupportedValueSets = valueSetsAccessed.filter((valueSet) => supportedValueSets.indexOf(valueSet) === -1);
if (unsupportedValueSets.length > 0) {
logicValidationErrors.push({
expr: rule.Logic,
message: `value set(s) not supported: ${unsupportedValueSets}`
});
}
const affectedFields = validateAffectedFields(rule);

@@ -72,0 +91,0 @@ const metaDataErrors = validateMetaData(rule);

{
"name": "dcc-business-rules-utils",
"version": "0.5.1",
"version": "0.5.2",
"description": "Various utils for working with DCC business/validation rules",

@@ -5,0 +5,0 @@ "keywords": [

@@ -89,3 +89,3 @@ import {evaluate} from "certlogic-js"

valueSets: CompressedValueSets,
dccPayload: any
dccPayload: unknown
): boolean => {

@@ -92,0 +92,0 @@

@@ -13,5 +13,5 @@ import Ajv from "ajv"

// (not exported through index.ts:)
export const createJsonValidatorForSchema = (schema: any): (json: any) => ErrorObject[] => {
const ajvSchemaValidator = ajv.compile(schema)
return (json: any): ErrorObject[] => {
export const createJsonValidatorForSchema = (schema: unknown): (json: unknown) => ErrorObject[] => {
const ajvSchemaValidator = ajv.compile(schema as any)
return (json: unknown): ErrorObject[] => {
const valid = ajvSchemaValidator(json)

@@ -18,0 +18,0 @@ return valid ? [] : ajvSchemaValidator.errors!

import {ErrorObject} from "ajv"
import {specificationVersion} from "certlogic-js"
import {CertLogicExpression, specificationVersion} from "certlogic-js"
import {dateFromString} from "certlogic-js/dist/internals"
import {dataAccesses, validateFormat, ValidationError} from "certlogic-js/dist/validation"
import {
dataAccesses,
validateFormat,
ValidationError
} from "certlogic-js/dist/validation"
import {gt} from "semver"

@@ -17,10 +21,17 @@

const withoutPrefix = (prefix: string): (str: string) => string =>
(str: string) => str.startsWith(prefix) ? str.substring(prefix.length) : str
const dataAccessesPrefixed = (expr: CertLogicExpression, prefix: string): string[] =>
dataAccesses(expr)
.filter((fieldName) => fieldName.startsWith(prefix))
.map(withoutPrefix(prefix))
export type AffectedFieldsValidationResult = null | { actual: string[], computed: string[] }
const validateAffectedFields = (rule: any): AffectedFieldsValidationResult => {
const payloadPrefix = "payload."
const actual = rule.AffectedFields
const computed = dataAccesses(rule.Logic)
.filter((fieldName) => fieldName.startsWith(payloadPrefix))
.map((fieldName) => fieldName.substring(payloadPrefix.length))
const computed = dataAccessesPrefixed(rule.Logic, "payload.")
return areEqual(actual, computed)

@@ -88,2 +99,15 @@ ? null

const supportedValueSets = [
"country-2-codes",
"disease-agent-targeted",
"covid-19-lab-test-manufacturer-and-name", // test-manf.json
"covid-19-lab-result", // test-result.json
"covid-19-lab-test-type", // test-type.json
"vaccines-covid-19-auth-holders", // vaccine-mah-manf.json
"vaccines-covid-19-names", // vaccine-medicinal-product.json
"sct-vaccines-covid-19", // vaccine-prophylaxis.json
]
/**

@@ -95,2 +119,10 @@ * Validates the given JSON value as a DCC business rule.

const logicValidationErrors = validateFormat(rule.Logic)
const valueSetsAccessed = [...new Set(dataAccessesPrefixed(rule.Logic, "external.valueSets."))]
const unsupportedValueSets = valueSetsAccessed.filter((valueSet) => supportedValueSets.indexOf(valueSet) === -1)
if (unsupportedValueSets.length > 0) {
logicValidationErrors.push({
expr: rule.Logic,
message: `value set(s) not supported: ${unsupportedValueSets}`
})
}
const affectedFields = validateAffectedFields(rule)

@@ -97,0 +129,0 @@ const metaDataErrors = validateMetaData(rule)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc