onroute-policy-engine 0.2.0 → 0.3.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 +68 -0
- package/.github/workflows/pipeline.yml +47 -0
- package/README.md +50 -50
- package/dist/enum/permit-app-info.d.ts +1 -1
- package/dist/enum/permit-app-info.js +1 -1
- package/dist/helper/bridge-calculation.helper.d.ts +13 -0
- package/dist/helper/bridge-calculation.helper.js +92 -0
- package/dist/helper/facts.helper.js +1 -2
- package/dist/helper/lists.helper.js +3 -4
- package/dist/helper/rules-engine.helper.js +1 -2
- package/dist/policy-engine.d.ts +9 -1
- package/dist/policy-engine.js +20 -1
- package/dist/types/axle-configuration.d.ts +8 -0
- package/dist/types/axle-configuration.js +2 -0
- package/dist/types/bridge-calculation-constants.d.ts +4 -0
- package/dist/types/bridge-calculation-constants.js +2 -0
- package/dist/types/bridge-calculation-result.d.ts +7 -0
- package/dist/types/bridge-calculation-result.js +2 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/permit-type.d.ts +1 -1
- package/dist/types/policy-definition.d.ts +2 -1
- package/package.json +77 -76
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
name: Analysis
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
types: [opened, reopened, synchronize, ready_for_review, converted_to_draft]
|
|
6
|
+
|
|
7
|
+
concurrency:
|
|
8
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
9
|
+
cancel-in-progress: true
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
validate:
|
|
13
|
+
name: Validate PR
|
|
14
|
+
if: (! github.event.pull_request.draft)
|
|
15
|
+
uses: bcgov/quickstart-openshift-helpers/.github/workflows/.pr-validate.yml@v0.8.1
|
|
16
|
+
|
|
17
|
+
lint:
|
|
18
|
+
name: lint
|
|
19
|
+
if: ${{ ! github.event.pull_request.draft }}
|
|
20
|
+
runs-on: ubuntu-latest # Runs on the latest version of Ubuntu
|
|
21
|
+
steps:
|
|
22
|
+
- name: Checkout code
|
|
23
|
+
uses: actions/checkout@v4 # Checks out the code from the repository
|
|
24
|
+
|
|
25
|
+
- name: Set up Node.js
|
|
26
|
+
uses: actions/setup-node@v4
|
|
27
|
+
with:
|
|
28
|
+
node-version: '20.x'
|
|
29
|
+
|
|
30
|
+
- name: Install dependencies
|
|
31
|
+
run: npm install # Installs project dependencies
|
|
32
|
+
|
|
33
|
+
- name: Lint code
|
|
34
|
+
run: npx eslint . --config .eslintrc.cjs # Run ESLint with the specified config
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
# https://github.com/marketplace/actions/aqua-security-trivy
|
|
38
|
+
trivy:
|
|
39
|
+
name: Trivy Security Scan
|
|
40
|
+
if: ${{ ! github.event.pull_request.draft }}
|
|
41
|
+
runs-on: ubuntu-22.04
|
|
42
|
+
timeout-minutes: 1
|
|
43
|
+
steps:
|
|
44
|
+
- uses: actions/checkout@v4
|
|
45
|
+
- name: Run Trivy vulnerability scanner in repo mode
|
|
46
|
+
uses: aquasecurity/trivy-action@0.24.0
|
|
47
|
+
with:
|
|
48
|
+
format: "sarif"
|
|
49
|
+
output: "trivy-results.sarif"
|
|
50
|
+
ignore-unfixed: true
|
|
51
|
+
scan-type: "fs"
|
|
52
|
+
scanners: "vuln,secret,config"
|
|
53
|
+
severity: "CRITICAL,HIGH"
|
|
54
|
+
|
|
55
|
+
- name: Upload Trivy scan results to GitHub Security tab
|
|
56
|
+
uses: github/codeql-action/upload-sarif@v3
|
|
57
|
+
with:
|
|
58
|
+
sarif_file: "trivy-results.sarif"
|
|
59
|
+
|
|
60
|
+
results:
|
|
61
|
+
name: Analysis Results
|
|
62
|
+
needs: [validate, lint, trivy]
|
|
63
|
+
if: always()
|
|
64
|
+
runs-on: ubuntu-22.04
|
|
65
|
+
steps:
|
|
66
|
+
- if: contains(needs.*.result, 'failure')
|
|
67
|
+
run: echo "At least one job has failed." && exit 1
|
|
68
|
+
- run: echo "Success!"
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: CI/CD Pipleine For Simple Package Publishing
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
jobs:
|
|
8
|
+
build:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
permissions:
|
|
11
|
+
contents: read
|
|
12
|
+
packages: write
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
deploy:
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
permissions:
|
|
18
|
+
id-token: write # needed for provenance data generation
|
|
19
|
+
|
|
20
|
+
steps:
|
|
21
|
+
- name: Checkout Code
|
|
22
|
+
uses: actions/checkout@v4
|
|
23
|
+
|
|
24
|
+
- name: Get Next Version
|
|
25
|
+
id: semver
|
|
26
|
+
uses: ietf-tools/semver-action@v1
|
|
27
|
+
with:
|
|
28
|
+
token: ${{ github.token }}
|
|
29
|
+
branch: main
|
|
30
|
+
|
|
31
|
+
- name: Injecting Semver Into Package.json
|
|
32
|
+
run: |
|
|
33
|
+
cat package.json | jq '. + { "version": "${{ steps.semver.outputs.next }}" }' | tee package.json
|
|
34
|
+
|
|
35
|
+
- uses: actions/setup-node@v4
|
|
36
|
+
with:
|
|
37
|
+
node-version: '20.x'
|
|
38
|
+
registry-url: 'https://registry.npmjs.org'
|
|
39
|
+
|
|
40
|
+
- run: npm ci
|
|
41
|
+
- run: tsc
|
|
42
|
+
- run: npm test
|
|
43
|
+
|
|
44
|
+
- name: Publish Package
|
|
45
|
+
run: npm publish --provenance --access public
|
|
46
|
+
env:
|
|
47
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/README.md
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
A JSON-based rules engine to validate onRouteBC permit applications against commercial vehicle policy.
|
|
2
|
-
|
|
3
|
-
## Synopsis
|
|
4
|
-
```orbc-policy-engine``` is a library designed to compare a commercial vehicle permit application against policy expressed in JSON format, and return a list of policy violations as well as other informational policy messages related to the permit.
|
|
5
|
-
|
|
6
|
-
```orbc-policy-engine``` makes use of https://github.com/CacheControl/json-rules-engine for rules engine functionality. Complex rules are modeled by extending the core ```json-rules-engine``` operators and other capabilities.
|
|
7
|
-
|
|
8
|
-
## Usage
|
|
9
|
-
```js
|
|
10
|
-
import Policy from 'orbc-policy-engine';
|
|
11
|
-
|
|
12
|
-
// Instantiate a new Policy object
|
|
13
|
-
// policyDefinition is a JSON object of type PolicyDefinition
|
|
14
|
-
const policy: Policy = new Policy(policyDefinition);
|
|
15
|
-
|
|
16
|
-
// Get list of all available permit types (ID and name)
|
|
17
|
-
const permitTypes: Map<string, string> = policy.getPermitTypes();
|
|
18
|
-
|
|
19
|
-
// Get list of all available commodities (ID and name)
|
|
20
|
-
const commodities: Map<string, string> = policy.getCommodities();
|
|
21
|
-
|
|
22
|
-
// Get list of all available power unit types
|
|
23
|
-
const powerUnits: Map<string, string> = policy.getPowerUnitTypes();
|
|
24
|
-
|
|
25
|
-
// Get list of all available trailer types
|
|
26
|
-
const trailers: Map<string, string> = policy.getTrailerTypes();
|
|
27
|
-
|
|
28
|
-
// Get list of all valid commodities for a given permit type
|
|
29
|
-
const commodities: Map<string, string> = policy.getCommodities(permitTypeId);
|
|
30
|
-
|
|
31
|
-
// Get list of all vehicle types valid to be added to a configuration,
|
|
32
|
-
// by permit type and commodity. Requires supplying the vehicles already
|
|
33
|
-
// added to the configuration, or empty array if starting from scratch
|
|
34
|
-
const allowableVehicles: Map<string, string> = policy.getNextPermittableVehicles(
|
|
35
|
-
permitTypeId,
|
|
36
|
-
commodityId,
|
|
37
|
-
currentConfiguration);
|
|
38
|
-
|
|
39
|
-
// Validate a permit application against policy
|
|
40
|
-
// permitApplication is a JSON object of type PermitApplication
|
|
41
|
-
// A PermitApplication is the standard permitData object wrapped
|
|
42
|
-
// in an object with a permitType key. For example:
|
|
43
|
-
// {
|
|
44
|
-
// permitType: 'TROS',
|
|
45
|
-
// permitData: { ... }
|
|
46
|
-
// }
|
|
47
|
-
// Note this is an async call due to the reliance on json-rules-engine
|
|
48
|
-
const results: ValidationResults = await policy.validate(permitApplication);
|
|
49
|
-
```
|
|
50
|
-
|
|
1
|
+
A JSON-based rules engine to validate onRouteBC permit applications against commercial vehicle policy.
|
|
2
|
+
|
|
3
|
+
## Synopsis
|
|
4
|
+
```orbc-policy-engine``` is a library designed to compare a commercial vehicle permit application against policy expressed in JSON format, and return a list of policy violations as well as other informational policy messages related to the permit.
|
|
5
|
+
|
|
6
|
+
```orbc-policy-engine``` makes use of https://github.com/CacheControl/json-rules-engine for rules engine functionality. Complex rules are modeled by extending the core ```json-rules-engine``` operators and other capabilities.
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
```js
|
|
10
|
+
import Policy from 'orbc-policy-engine';
|
|
11
|
+
|
|
12
|
+
// Instantiate a new Policy object
|
|
13
|
+
// policyDefinition is a JSON object of type PolicyDefinition
|
|
14
|
+
const policy: Policy = new Policy(policyDefinition);
|
|
15
|
+
|
|
16
|
+
// Get list of all available permit types (ID and name)
|
|
17
|
+
const permitTypes: Map<string, string> = policy.getPermitTypes();
|
|
18
|
+
|
|
19
|
+
// Get list of all available commodities (ID and name)
|
|
20
|
+
const commodities: Map<string, string> = policy.getCommodities();
|
|
21
|
+
|
|
22
|
+
// Get list of all available power unit types
|
|
23
|
+
const powerUnits: Map<string, string> = policy.getPowerUnitTypes();
|
|
24
|
+
|
|
25
|
+
// Get list of all available trailer types
|
|
26
|
+
const trailers: Map<string, string> = policy.getTrailerTypes();
|
|
27
|
+
|
|
28
|
+
// Get list of all valid commodities for a given permit type
|
|
29
|
+
const commodities: Map<string, string> = policy.getCommodities(permitTypeId);
|
|
30
|
+
|
|
31
|
+
// Get list of all vehicle types valid to be added to a configuration,
|
|
32
|
+
// by permit type and commodity. Requires supplying the vehicles already
|
|
33
|
+
// added to the configuration, or empty array if starting from scratch
|
|
34
|
+
const allowableVehicles: Map<string, string> = policy.getNextPermittableVehicles(
|
|
35
|
+
permitTypeId,
|
|
36
|
+
commodityId,
|
|
37
|
+
currentConfiguration);
|
|
38
|
+
|
|
39
|
+
// Validate a permit application against policy
|
|
40
|
+
// permitApplication is a JSON object of type PermitApplication
|
|
41
|
+
// A PermitApplication is the standard permitData object wrapped
|
|
42
|
+
// in an object with a permitType key. For example:
|
|
43
|
+
// {
|
|
44
|
+
// permitType: 'TROS',
|
|
45
|
+
// permitData: { ... }
|
|
46
|
+
// }
|
|
47
|
+
// Note this is an async call due to the reliance on json-rules-engine
|
|
48
|
+
const results: ValidationResults = await policy.validate(permitApplication);
|
|
49
|
+
```
|
|
50
|
+
|
|
@@ -12,5 +12,5 @@ export declare enum PermitAppInfo {
|
|
|
12
12
|
PermitDuration = "$.permitDuration",
|
|
13
13
|
PowerUnitType = "$.vehicleDetails.vehicleSubType",
|
|
14
14
|
TrailerList = "$.vehicleConfiguration.trailers",
|
|
15
|
-
Commodity = "$.permittedCommodity"
|
|
15
|
+
Commodity = "$.permittedCommodity.commodityType"
|
|
16
16
|
}
|
|
@@ -16,5 +16,5 @@ var PermitAppInfo;
|
|
|
16
16
|
PermitAppInfo["PermitDuration"] = "$.permitDuration";
|
|
17
17
|
PermitAppInfo["PowerUnitType"] = "$.vehicleDetails.vehicleSubType";
|
|
18
18
|
PermitAppInfo["TrailerList"] = "$.vehicleConfiguration.trailers";
|
|
19
|
-
PermitAppInfo["Commodity"] = "$.permittedCommodity";
|
|
19
|
+
PermitAppInfo["Commodity"] = "$.permittedCommodity.commodityType";
|
|
20
20
|
})(PermitAppInfo || (exports.PermitAppInfo = PermitAppInfo = {}));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BridgeCalculationResult, AxleConfiguration } from 'onroute-policy-engine/types';
|
|
2
|
+
import { Policy } from '../policy-engine';
|
|
3
|
+
/**
|
|
4
|
+
* Runs the bridge formula against the supplied vehicle axle configuration.
|
|
5
|
+
* Evaluates the weight against all possible axle group combinations and returns
|
|
6
|
+
* the result of each group comparison, with an indicator of whether or not the
|
|
7
|
+
* axle group failed the bridge calculation.
|
|
8
|
+
* @param axleConfig Vehicle dimensions and weights per axle
|
|
9
|
+
* @param policy Policy Enging object initialized with policy config
|
|
10
|
+
* @returns Array of BridgeCalculationResult objects, one for each
|
|
11
|
+
* axle group in the vehicle configuration
|
|
12
|
+
*/
|
|
13
|
+
export declare function runBridgeFormula(axleConfig: Array<AxleConfiguration>, policy: Policy): Array<BridgeCalculationResult>;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runBridgeFormula = runBridgeFormula;
|
|
4
|
+
/**
|
|
5
|
+
* Runs the bridge formula against the supplied vehicle axle configuration.
|
|
6
|
+
* Evaluates the weight against all possible axle group combinations and returns
|
|
7
|
+
* the result of each group comparison, with an indicator of whether or not the
|
|
8
|
+
* axle group failed the bridge calculation.
|
|
9
|
+
* @param axleConfig Vehicle dimensions and weights per axle
|
|
10
|
+
* @param policy Policy Enging object initialized with policy config
|
|
11
|
+
* @returns Array of BridgeCalculationResult objects, one for each
|
|
12
|
+
* axle group in the vehicle configuration
|
|
13
|
+
*/
|
|
14
|
+
function runBridgeFormula(axleConfig, policy) {
|
|
15
|
+
const BRIDGE_MULTIPLIER = policy.policyDefinition.bridgeCalculationConstants.multiplier;
|
|
16
|
+
const BRIDGE_MIN_WEIGHT = policy.policyDefinition.bridgeCalculationConstants.minWeight;
|
|
17
|
+
const results = [];
|
|
18
|
+
let index = 0;
|
|
19
|
+
if (!axleConfig || axleConfig.length < 2) {
|
|
20
|
+
throw new Error('Invalid axle configuration, bridge formula requires a minimum of two axle units');
|
|
21
|
+
}
|
|
22
|
+
// Loop through each axle unit in the configuration, and
|
|
23
|
+
// calculate the bridge formula for each other axle unit. The
|
|
24
|
+
// number of axle groups calculated will be the Nth triangular
|
|
25
|
+
// number, where N = (number of axle units) - 1.
|
|
26
|
+
axleConfig.forEach((axle) => {
|
|
27
|
+
var _a;
|
|
28
|
+
// Do not process once we reach the last axle unit
|
|
29
|
+
// in the configuration, as they have all been calculated
|
|
30
|
+
// by then.
|
|
31
|
+
if (index < axleConfig.length - 1) {
|
|
32
|
+
// Initialize the variables for our start axle
|
|
33
|
+
const firstAxle = index + 1;
|
|
34
|
+
let nextAxle = firstAxle + 1;
|
|
35
|
+
if (!axle.numberOfAxles || axle.numberOfAxles < 0) {
|
|
36
|
+
throw new Error(`Invalid or missing number of axles for axle unit number ${firstAxle}`);
|
|
37
|
+
}
|
|
38
|
+
if (!axle.weight || axle.weight < 0) {
|
|
39
|
+
throw new Error(`Invalid or missing weight for axle unit number ${firstAxle}`);
|
|
40
|
+
}
|
|
41
|
+
let totalWeight = axle.weight;
|
|
42
|
+
// Spread may be zero or undefined if the axle unit
|
|
43
|
+
// is a single axle. Spacing to next will be zero or
|
|
44
|
+
// undefined for the final axle unit in the configuration.
|
|
45
|
+
if (axle.numberOfAxles > 1 && (!axle.spread || axle.spread < 0)) {
|
|
46
|
+
throw new Error(`Invalid or missing axle spread for axle unit number ${firstAxle}`);
|
|
47
|
+
}
|
|
48
|
+
if (axle.numberOfAxles == 1 && axle.spread && axle.spread < 0) {
|
|
49
|
+
throw new Error(`Invalid axle spread for single axle unit, cannot be a negative number`);
|
|
50
|
+
}
|
|
51
|
+
if (!axle.spacingToNext || axle.spacingToNext < 0) {
|
|
52
|
+
throw new Error(`Invalid or missing axle spacing between axle units ${firstAxle} and ${firstAxle + 1}`);
|
|
53
|
+
}
|
|
54
|
+
let wheelbase = ((_a = axle.spread) !== null && _a !== void 0 ? _a : 0) + axle.spacingToNext;
|
|
55
|
+
// Now loop through all of the next axles, building up a group
|
|
56
|
+
// for each.
|
|
57
|
+
axleConfig.slice(firstAxle).forEach((axleN) => {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
if (!axleN.weight || axleN.weight < 0) {
|
|
60
|
+
throw new Error(`Invalid or missing weight for axle unit number ${nextAxle}`);
|
|
61
|
+
}
|
|
62
|
+
totalWeight += axleN.weight;
|
|
63
|
+
if (axleN.numberOfAxles > 1 && (!axleN.spread || axleN.spread < 0)) {
|
|
64
|
+
throw new Error(`Invalid or missing axle spread for axle unit number ${nextAxle}`);
|
|
65
|
+
}
|
|
66
|
+
wheelbase += (_a = axleN.spread) !== null && _a !== void 0 ? _a : 0;
|
|
67
|
+
// The magic is in the next line
|
|
68
|
+
const maxBridge = BRIDGE_MULTIPLIER * wheelbase + BRIDGE_MIN_WEIGHT;
|
|
69
|
+
// Push the axle group result to the results array, including
|
|
70
|
+
// a convenience success indicator.
|
|
71
|
+
results.push({
|
|
72
|
+
startAxleUnit: firstAxle,
|
|
73
|
+
endAxleUnit: nextAxle,
|
|
74
|
+
maxBridge: maxBridge,
|
|
75
|
+
actualWeight: totalWeight,
|
|
76
|
+
success: totalWeight <= maxBridge,
|
|
77
|
+
});
|
|
78
|
+
// Add the wheelbase only if this end axle unit is not the
|
|
79
|
+
// final one in the configuration
|
|
80
|
+
if (nextAxle < axleConfig.length) {
|
|
81
|
+
if (!axleN.spacingToNext || axleN.spacingToNext < 0) {
|
|
82
|
+
throw new Error(`Invalid or missing axle spacing between axle units ${nextAxle} and ${nextAxle + 1}`);
|
|
83
|
+
}
|
|
84
|
+
wheelbase += (_b = axleN.spacingToNext) !== null && _b !== void 0 ? _b : 0;
|
|
85
|
+
}
|
|
86
|
+
nextAxle++;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
index++;
|
|
90
|
+
});
|
|
91
|
+
return results;
|
|
92
|
+
}
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.addRuntimeFacts =
|
|
6
|
+
exports.addRuntimeFacts = addRuntimeFacts;
|
|
7
7
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
8
|
const enum_1 = require("onroute-policy-engine/enum");
|
|
9
9
|
/**
|
|
@@ -75,4 +75,3 @@ function addRuntimeFacts(engine, policy) {
|
|
|
75
75
|
return months * params.cost;
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
|
-
exports.addRuntimeFacts = addRuntimeFacts;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.extractIdentifiedObjects = extractIdentifiedObjects;
|
|
4
|
+
exports.intersectIdMaps = intersectIdMaps;
|
|
5
|
+
exports.getIdFromName = getIdFromName;
|
|
4
6
|
/**
|
|
5
7
|
* Extracts a map containing just the ID and name of each of the supplied
|
|
6
8
|
* identified objects.
|
|
@@ -19,7 +21,6 @@ function extractIdentifiedObjects(objects, filter) {
|
|
|
19
21
|
});
|
|
20
22
|
return objectMap;
|
|
21
23
|
}
|
|
22
|
-
exports.extractIdentifiedObjects = extractIdentifiedObjects;
|
|
23
24
|
/**
|
|
24
25
|
* Intersects two maps containing string id and string description to
|
|
25
26
|
* return a new map containing those entries common to both.
|
|
@@ -41,7 +42,6 @@ function intersectIdMaps(first, second) {
|
|
|
41
42
|
}
|
|
42
43
|
return combinedMap;
|
|
43
44
|
}
|
|
44
|
-
exports.intersectIdMaps = intersectIdMaps;
|
|
45
45
|
function getIdFromName(list, name) {
|
|
46
46
|
let id = null;
|
|
47
47
|
const identifiedObject = list.find((i) => i.name == name);
|
|
@@ -50,4 +50,3 @@ function getIdFromName(list, name) {
|
|
|
50
50
|
}
|
|
51
51
|
return id;
|
|
52
52
|
}
|
|
53
|
-
exports.getIdFromName = getIdFromName;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRulesEngines =
|
|
3
|
+
exports.getRulesEngines = getRulesEngines;
|
|
4
4
|
const json_rules_engine_1 = require("json-rules-engine");
|
|
5
5
|
const custom_operators_1 = require("../rule-operator/custom-operators");
|
|
6
6
|
const enum_1 = require("onroute-policy-engine/enum");
|
|
@@ -74,4 +74,3 @@ function getRulesEngines(policy) {
|
|
|
74
74
|
});
|
|
75
75
|
return engineMap;
|
|
76
76
|
}
|
|
77
|
-
exports.getRulesEngines = getRulesEngines;
|
package/dist/policy-engine.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PolicyDefinition, PermitType, Commodity, SizeDimension } from 'onroute-policy-engine/types';
|
|
1
|
+
import { PolicyDefinition, PermitType, Commodity, SizeDimension, AxleConfiguration, BridgeCalculationResult } from 'onroute-policy-engine/types';
|
|
2
2
|
import { Engine } from 'json-rules-engine';
|
|
3
3
|
import { ValidationResults } from './validation-results';
|
|
4
4
|
/** Class representing commercial vehicle policy. */
|
|
@@ -136,4 +136,12 @@ export declare class Policy {
|
|
|
136
136
|
* @returns Commodity definition for the supplied ID.
|
|
137
137
|
*/
|
|
138
138
|
getCommodityDefinition(type?: string): Commodity | null;
|
|
139
|
+
/**
|
|
140
|
+
* Convenience method of policy that delegates the bridge calculation
|
|
141
|
+
* to the helper method.
|
|
142
|
+
* @param axleConfig Vehicle dimensions and weights per axle
|
|
143
|
+
* @returns Array of BridgeCalculationResult objects, one for each
|
|
144
|
+
* axle group in the vehicle configuration
|
|
145
|
+
*/
|
|
146
|
+
calculateBridge(axleConfig: Array<AxleConfiguration>): Array<BridgeCalculationResult>;
|
|
139
147
|
}
|
package/dist/policy-engine.js
CHANGED
|
@@ -7,6 +7,7 @@ const validation_results_1 = require("./validation-results");
|
|
|
7
7
|
const validation_result_1 = require("./validation-result");
|
|
8
8
|
const facts_helper_1 = require("./helper/facts.helper");
|
|
9
9
|
const enum_1 = require("onroute-policy-engine/enum");
|
|
10
|
+
const bridge_calculation_helper_1 = require("./helper/bridge-calculation.helper");
|
|
10
11
|
/** Class representing commercial vehicle policy. */
|
|
11
12
|
class Policy {
|
|
12
13
|
/**
|
|
@@ -90,7 +91,7 @@ class Policy {
|
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
93
|
return false;
|
|
93
|
-
})
|
|
94
|
+
}));
|
|
94
95
|
// TODO when implementing overweight. Stub for now.
|
|
95
96
|
const commoditiesForOW = new Map();
|
|
96
97
|
if (permitType.sizeDimensionRequired &&
|
|
@@ -614,5 +615,23 @@ class Policy {
|
|
|
614
615
|
return null;
|
|
615
616
|
}
|
|
616
617
|
}
|
|
618
|
+
/**
|
|
619
|
+
* Convenience method of policy that delegates the bridge calculation
|
|
620
|
+
* to the helper method.
|
|
621
|
+
* @param axleConfig Vehicle dimensions and weights per axle
|
|
622
|
+
* @returns Array of BridgeCalculationResult objects, one for each
|
|
623
|
+
* axle group in the vehicle configuration
|
|
624
|
+
*/
|
|
625
|
+
calculateBridge(axleConfig) {
|
|
626
|
+
let bridgeResults;
|
|
627
|
+
try {
|
|
628
|
+
bridgeResults = (0, bridge_calculation_helper_1.runBridgeFormula)(axleConfig, this);
|
|
629
|
+
}
|
|
630
|
+
catch (e) {
|
|
631
|
+
console.log(`Error calculating bridge formula: ${e.message}`);
|
|
632
|
+
throw e;
|
|
633
|
+
}
|
|
634
|
+
return bridgeResults;
|
|
635
|
+
}
|
|
617
636
|
}
|
|
618
637
|
exports.Policy = Policy;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export { AxleConfiguration } from './axle-configuration';
|
|
2
|
+
export { BridgeCalculationConstants } from './bridge-calculation-constants';
|
|
3
|
+
export { BridgeCalculationResult } from './bridge-calculation-result';
|
|
1
4
|
export { Commodity, CommoditySize, CommodityWeight } from './commodity';
|
|
2
5
|
export { CostRule } from './cost-rule';
|
|
3
6
|
export { DimensionModifier } from './dimension-modifier';
|
|
@@ -5,7 +5,7 @@ export type PermitType = IdentifiedObject & {
|
|
|
5
5
|
weightDimensionRequired: boolean;
|
|
6
6
|
sizeDimensionRequired: boolean;
|
|
7
7
|
commodityRequired: boolean;
|
|
8
|
-
allowedVehicles
|
|
8
|
+
allowedVehicles?: Array<string>;
|
|
9
9
|
allowedCommodities?: Array<string>;
|
|
10
10
|
rules?: Array<RuleProperties>;
|
|
11
11
|
costRules?: Array<CostRule>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GeographicRegion, PermitType, DefaultWeightDimensions, VehicleTypes, Commodity, SizeDimension, VehicleCategories, RangeMatrix } from 'onroute-policy-engine/types';
|
|
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
|
version: string;
|
|
@@ -11,4 +11,5 @@ export type PolicyDefinition = {
|
|
|
11
11
|
vehicleTypes: VehicleTypes;
|
|
12
12
|
commodities: Array<Commodity>;
|
|
13
13
|
rangeMatrices?: Array<RangeMatrix>;
|
|
14
|
+
bridgeCalculationConstants: BridgeCalculationConstants;
|
|
14
15
|
};
|
package/package.json
CHANGED
|
@@ -1,76 +1,77 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "onroute-policy-engine",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
"
|
|
8
|
-
"./
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"build": "tsc"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
"@types/jest": "^29.5.12",
|
|
30
|
-
"@typescript-eslint/eslint-plugin": "^7.5.0",
|
|
31
|
-
"csv": "^6.3.10",
|
|
32
|
-
"eslint": "^8.57.0",
|
|
33
|
-
"eslint-config-prettier": "^9.1.0",
|
|
34
|
-
"jest": "^29.7.0",
|
|
35
|
-
"prettier": "^3.2.5",
|
|
36
|
-
"rimraf": "^5.0.7",
|
|
37
|
-
"ts-jest": "^29.1.2",
|
|
38
|
-
"typescript": "^5.4.3"
|
|
39
|
-
},
|
|
40
|
-
"dependencies": {
|
|
41
|
-
"dayjs": "^1.11.10",
|
|
42
|
-
"json-rules-engine": "^6.5.0"
|
|
43
|
-
},
|
|
44
|
-
"jest": {
|
|
45
|
-
"moduleFileExtensions": [
|
|
46
|
-
"js",
|
|
47
|
-
"json",
|
|
48
|
-
"ts"
|
|
49
|
-
],
|
|
50
|
-
"rootDir": ".",
|
|
51
|
-
"roots": [
|
|
52
|
-
"<rootDir>/src"
|
|
53
|
-
],
|
|
54
|
-
"moduleNameMapper": {
|
|
55
|
-
"^src/(.*)$": "<rootDir>/src/$1",
|
|
56
|
-
"^test/(.*)$": "<rootDir>/test/$1"
|
|
57
|
-
},
|
|
58
|
-
"testRegex": ".*\\.spec\\.ts$",
|
|
59
|
-
"transform": {
|
|
60
|
-
"^.+\\.ts$": "ts-jest"
|
|
61
|
-
},
|
|
62
|
-
"collectCoverage": true,
|
|
63
|
-
"collectCoverageFrom": [
|
|
64
|
-
"**/*.js"
|
|
65
|
-
],
|
|
66
|
-
"coverageDirectory": "./coverage",
|
|
67
|
-
"coveragePathIgnorePatterns": [
|
|
68
|
-
"/node_modules/",
|
|
69
|
-
"/src/_test/",
|
|
70
|
-
".enum.ts",
|
|
71
|
-
".interface.ts",
|
|
72
|
-
"index.ts"
|
|
73
|
-
],
|
|
74
|
-
"testEnvironment": "node"
|
|
75
|
-
}
|
|
76
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "onroute-policy-engine",
|
|
3
|
+
"description": "Policy Engine library for commercial vehicle permitting",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./dist/index.js",
|
|
7
|
+
"./types": "./dist/types/index.js",
|
|
8
|
+
"./enum": "./dist/enum/index.js"
|
|
9
|
+
},
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"private": false,
|
|
12
|
+
"scripts": {
|
|
13
|
+
"clean": "rimraf dist && rimraf -g *.tgz",
|
|
14
|
+
"test": "jest",
|
|
15
|
+
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
|
16
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
17
|
+
"build": "tsc",
|
|
18
|
+
"clean-build": "rimraf dist && rimraf -g *.tgz && tsc"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/bcgov/onroutebc-policy-engine.git"
|
|
23
|
+
},
|
|
24
|
+
"author": "John Fletcher",
|
|
25
|
+
"license": "Apache-2.0",
|
|
26
|
+
"homepage": "https://github.com/bcgov/onroutebc-policy-engine#readme",
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@iwsio/json-csv-core": "^1.1.7",
|
|
29
|
+
"@types/jest": "^29.5.12",
|
|
30
|
+
"@typescript-eslint/eslint-plugin": "^7.5.0",
|
|
31
|
+
"csv": "^6.3.10",
|
|
32
|
+
"eslint": "^8.57.0",
|
|
33
|
+
"eslint-config-prettier": "^9.1.0",
|
|
34
|
+
"jest": "^29.7.0",
|
|
35
|
+
"prettier": "^3.2.5",
|
|
36
|
+
"rimraf": "^5.0.7",
|
|
37
|
+
"ts-jest": "^29.1.2",
|
|
38
|
+
"typescript": "^5.4.3"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"dayjs": "^1.11.10",
|
|
42
|
+
"json-rules-engine": "^6.5.0"
|
|
43
|
+
},
|
|
44
|
+
"jest": {
|
|
45
|
+
"moduleFileExtensions": [
|
|
46
|
+
"js",
|
|
47
|
+
"json",
|
|
48
|
+
"ts"
|
|
49
|
+
],
|
|
50
|
+
"rootDir": ".",
|
|
51
|
+
"roots": [
|
|
52
|
+
"<rootDir>/src"
|
|
53
|
+
],
|
|
54
|
+
"moduleNameMapper": {
|
|
55
|
+
"^src/(.*)$": "<rootDir>/src/$1",
|
|
56
|
+
"^test/(.*)$": "<rootDir>/test/$1"
|
|
57
|
+
},
|
|
58
|
+
"testRegex": ".*\\.spec\\.ts$",
|
|
59
|
+
"transform": {
|
|
60
|
+
"^.+\\.ts$": "ts-jest"
|
|
61
|
+
},
|
|
62
|
+
"collectCoverage": true,
|
|
63
|
+
"collectCoverageFrom": [
|
|
64
|
+
"**/*.js"
|
|
65
|
+
],
|
|
66
|
+
"coverageDirectory": "./coverage",
|
|
67
|
+
"coveragePathIgnorePatterns": [
|
|
68
|
+
"/node_modules/",
|
|
69
|
+
"/src/_test/",
|
|
70
|
+
".enum.ts",
|
|
71
|
+
".interface.ts",
|
|
72
|
+
"index.ts"
|
|
73
|
+
],
|
|
74
|
+
"testEnvironment": "node"
|
|
75
|
+
},
|
|
76
|
+
"version": "v0.3.0"
|
|
77
|
+
}
|