onroute-policy-engine 0.8.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/analysis.yml +1 -1
- package/.github/workflows/pipeline.yml +1 -1
- package/dist/helper/facts.helper.js +1 -1
- package/dist/policy-engine.js +20 -0
- package/dist/types/policy-definition.d.ts +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/eslint.config.mjs +46 -0
- package/package.json +15 -13
|
@@ -31,7 +31,7 @@ jobs:
|
|
|
31
31
|
run: npm install # Installs project dependencies
|
|
32
32
|
|
|
33
33
|
- name: Lint code
|
|
34
|
-
run: npx eslint
|
|
34
|
+
run: npx eslint "{src,apps,libs,test}/**/*.ts" # Run ESLint with the specified config
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
# https://github.com/marketplace/actions/aqua-security-trivy
|
|
@@ -56,7 +56,7 @@ function addRuntimeFacts(engine, policy) {
|
|
|
56
56
|
isValid = policy.isConfigurationValid(permitType, commodity, fullVehicleConfiguration);
|
|
57
57
|
}
|
|
58
58
|
catch (e) {
|
|
59
|
-
console.log(`Error validating vehicle configuration: '{e.message}'`);
|
|
59
|
+
console.log(`Error validating vehicle configuration: '${e.message}'`);
|
|
60
60
|
isValid = false;
|
|
61
61
|
}
|
|
62
62
|
return isValid;
|
package/dist/policy-engine.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.Policy = void 0;
|
|
4
7
|
const lists_helper_1 = require("./helper/lists.helper");
|
|
@@ -8,6 +11,10 @@ const validation_result_1 = require("./validation-result");
|
|
|
8
11
|
const facts_helper_1 = require("./helper/facts.helper");
|
|
9
12
|
const enum_1 = require("onroute-policy-engine/enum");
|
|
10
13
|
const bridge_calculation_helper_1 = require("./helper/bridge-calculation.helper");
|
|
14
|
+
const version_1 = require("./version");
|
|
15
|
+
const valid_1 = __importDefault(require("semver/functions/valid"));
|
|
16
|
+
const lt_1 = __importDefault(require("semver/functions/lt"));
|
|
17
|
+
const major_1 = __importDefault(require("semver/functions/major"));
|
|
11
18
|
/** Class representing commercial vehicle policy. */
|
|
12
19
|
class Policy {
|
|
13
20
|
/**
|
|
@@ -15,6 +22,19 @@ class Policy {
|
|
|
15
22
|
* @param definition Policy definition to validate permits against
|
|
16
23
|
*/
|
|
17
24
|
constructor(definition) {
|
|
25
|
+
// Check compatibility of the policy engine with the policy config
|
|
26
|
+
if (!(0, valid_1.default)(version_1.version)) {
|
|
27
|
+
throw new Error(`Cannot determine the version of the policy engine for compatibility: invalid semver: ${version_1.version}`);
|
|
28
|
+
}
|
|
29
|
+
else if (!(0, valid_1.default)(definition.minPEVersion)) {
|
|
30
|
+
throw new Error(`Cannot determine the minimum PE version for the configuration: invalid semver: ${definition.minPEVersion}`);
|
|
31
|
+
}
|
|
32
|
+
else if ((0, lt_1.default)(version_1.version, definition.minPEVersion)) {
|
|
33
|
+
throw new Error(`Current policy engine version is less than minimum version required for policy config: ${version_1.version} > ${definition.minPEVersion}`);
|
|
34
|
+
}
|
|
35
|
+
else if ((0, major_1.default)(version_1.version) > (0, major_1.default)(definition.minPEVersion)) {
|
|
36
|
+
throw new Error(`Current policy config minimum version is at least one major version behind policy engine: major(${definition.minPEVersion}) < major(${version_1.version}))`);
|
|
37
|
+
}
|
|
18
38
|
this.policyDefinition = definition;
|
|
19
39
|
this.rulesEngines = (0, rules_engine_helper_1.getRulesEngines)(this);
|
|
20
40
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GeographicRegion, PermitType, DefaultWeightDimensions, VehicleTypes, Commodity, SizeDimension, VehicleCategories, RangeMatrix, BridgeCalculationConstants } from 'onroute-policy-engine/types';
|
|
2
2
|
import { RuleProperties } from 'json-rules-engine';
|
|
3
3
|
export type PolicyDefinition = {
|
|
4
|
-
|
|
4
|
+
minPEVersion: string;
|
|
5
5
|
geographicRegions: Array<GeographicRegion>;
|
|
6
6
|
permitTypes: Array<PermitType>;
|
|
7
7
|
commonRules: Array<RuleProperties>;
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "
|
|
1
|
+
export declare const version = "v1.0.0";
|
package/dist/version.js
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import typescriptEslint from "@typescript-eslint/eslint-plugin";
|
|
2
|
+
import globals from "globals";
|
|
3
|
+
import tsParser from "@typescript-eslint/parser";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import js from "@eslint/js";
|
|
7
|
+
import { FlatCompat } from "@eslint/eslintrc";
|
|
8
|
+
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = path.dirname(__filename);
|
|
11
|
+
const compat = new FlatCompat({
|
|
12
|
+
baseDirectory: __dirname,
|
|
13
|
+
recommendedConfig: js.configs.recommended,
|
|
14
|
+
allConfig: js.configs.all
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export default [{
|
|
18
|
+
ignores: ["**/.eslintrc.cjs", "**/node_modules/", "**/dist/", "**/.eslintrc.cjs"],
|
|
19
|
+
}, ...compat.extends("eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"), {
|
|
20
|
+
plugins: {
|
|
21
|
+
"@typescript-eslint": typescriptEslint,
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
languageOptions: {
|
|
25
|
+
globals: {
|
|
26
|
+
...globals.node,
|
|
27
|
+
...globals.jest,
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
parser: tsParser,
|
|
31
|
+
ecmaVersion: 5,
|
|
32
|
+
sourceType: "module",
|
|
33
|
+
|
|
34
|
+
parserOptions: {
|
|
35
|
+
project: ["./tsconfig.json"],
|
|
36
|
+
tsconfigRootDir: __dirname,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
rules: {
|
|
41
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
ignores: ["node_modules/*", "dist/*"]
|
|
46
|
+
}];
|
package/package.json
CHANGED
|
@@ -38,22 +38,24 @@
|
|
|
38
38
|
"license": "Apache-2.0",
|
|
39
39
|
"homepage": "https://github.com/bcgov/onroutebc-policy-engine#readme",
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@iwsio/json-csv-core": "^1.
|
|
42
|
-
"@types/jest": "^29.5.
|
|
43
|
-
"@
|
|
44
|
-
"
|
|
45
|
-
"
|
|
41
|
+
"@iwsio/json-csv-core": "^1.2.0",
|
|
42
|
+
"@types/jest": "^29.5.14",
|
|
43
|
+
"@types/semver": "^7.5.8",
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "^8.17.0",
|
|
45
|
+
"csv": "^6.3.11",
|
|
46
|
+
"eslint": "^9.16.0",
|
|
46
47
|
"eslint-config-prettier": "^9.1.0",
|
|
48
|
+
"genversion": "^3.2.0",
|
|
47
49
|
"jest": "^29.7.0",
|
|
48
|
-
"prettier": "^3.2
|
|
49
|
-
"rimraf": "^
|
|
50
|
-
"ts-jest": "^29.
|
|
51
|
-
"typescript": "^5.
|
|
50
|
+
"prettier": "^3.4.2",
|
|
51
|
+
"rimraf": "^6.0.1",
|
|
52
|
+
"ts-jest": "^29.2.5",
|
|
53
|
+
"typescript": "^5.7.2"
|
|
52
54
|
},
|
|
53
55
|
"dependencies": {
|
|
54
|
-
"dayjs": "^1.11.
|
|
55
|
-
"
|
|
56
|
-
"
|
|
56
|
+
"dayjs": "^1.11.13",
|
|
57
|
+
"json-rules-engine": "^7.2.1",
|
|
58
|
+
"semver": "^7.6.3"
|
|
57
59
|
},
|
|
58
60
|
"jest": {
|
|
59
61
|
"moduleFileExtensions": [
|
|
@@ -87,5 +89,5 @@
|
|
|
87
89
|
],
|
|
88
90
|
"testEnvironment": "node"
|
|
89
91
|
},
|
|
90
|
-
"version": "
|
|
92
|
+
"version": "v1.0.0"
|
|
91
93
|
}
|