onroute-policy-engine 1.4.1 → 1.6.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 +3 -3
- package/.github/workflows/pipeline.yml +2 -2
- package/dist/helper/bridge-calculation.helper.js +15 -22
- package/dist/helper/conditions.helper.d.ts +11 -0
- package/dist/helper/conditions.helper.js +49 -0
- package/dist/policy-engine.d.ts +16 -1
- package/dist/policy-engine.js +31 -0
- package/dist/types/axle-configuration.d.ts +3 -3
- package/dist/types/index.d.ts +1 -0
- package/dist/types/permit-condition.d.ts +10 -0
- package/dist/types/permit-condition.js +2 -0
- package/dist/types/permit-type.d.ts +2 -0
- package/dist/types/policy-definition.d.ts +2 -1
- package/dist/types/vehicle-type.d.ts +2 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -16,8 +16,8 @@ jobs:
|
|
|
16
16
|
|
|
17
17
|
lint:
|
|
18
18
|
name: lint
|
|
19
|
-
if:
|
|
20
|
-
runs-on: ubuntu-
|
|
19
|
+
if: (! github.event.pull_request.draft)
|
|
20
|
+
runs-on: ubuntu-24.04 # Runs on the latest version of Ubuntu
|
|
21
21
|
steps:
|
|
22
22
|
- name: Checkout code
|
|
23
23
|
uses: actions/checkout@v4 # Checks out the code from the repository
|
|
@@ -37,7 +37,7 @@ jobs:
|
|
|
37
37
|
# https://github.com/marketplace/actions/aqua-security-trivy
|
|
38
38
|
trivy:
|
|
39
39
|
name: Trivy Security Scan
|
|
40
|
-
if:
|
|
40
|
+
if: (! github.event.pull_request.draft)
|
|
41
41
|
runs-on: ubuntu-22.04
|
|
42
42
|
timeout-minutes: 1
|
|
43
43
|
steps:
|
|
@@ -6,14 +6,14 @@ on:
|
|
|
6
6
|
workflow_dispatch:
|
|
7
7
|
jobs:
|
|
8
8
|
build:
|
|
9
|
-
runs-on: ubuntu-
|
|
9
|
+
runs-on: ubuntu-24.04
|
|
10
10
|
permissions:
|
|
11
11
|
contents: write
|
|
12
12
|
packages: write
|
|
13
13
|
steps:
|
|
14
14
|
- uses: actions/checkout@v4
|
|
15
15
|
deploy:
|
|
16
|
-
runs-on: ubuntu-
|
|
16
|
+
runs-on: ubuntu-24.04
|
|
17
17
|
permissions:
|
|
18
18
|
id-token: write # needed for provenance data generation
|
|
19
19
|
contents: write
|
|
@@ -28,42 +28,43 @@ function runBridgeFormula(axleConfig, policy) {
|
|
|
28
28
|
// Do not process once we reach the last axle unit
|
|
29
29
|
// in the configuration, as they have all been calculated
|
|
30
30
|
// by then.
|
|
31
|
-
if (index
|
|
31
|
+
if (index <= axleConfig.length) {
|
|
32
32
|
// Initialize the variables for our start axle
|
|
33
33
|
const firstAxle = index + 1;
|
|
34
34
|
let nextAxle = firstAxle + 1;
|
|
35
35
|
if (!axle.numberOfAxles || axle.numberOfAxles < 0) {
|
|
36
36
|
throw new Error(`Invalid or missing number of axles for axle unit number ${firstAxle}`);
|
|
37
37
|
}
|
|
38
|
-
if (!axle.
|
|
38
|
+
if (!axle.axleUnitWeight || axle.axleUnitWeight < 0) {
|
|
39
39
|
throw new Error(`Invalid or missing weight for axle unit number ${firstAxle}`);
|
|
40
40
|
}
|
|
41
|
-
let totalWeight = axle.
|
|
41
|
+
let totalWeight = axle.axleUnitWeight;
|
|
42
42
|
// Spread may be zero or undefined if the axle unit
|
|
43
43
|
// is a single axle. Spacing to next will be zero or
|
|
44
44
|
// undefined for the final axle unit in the configuration.
|
|
45
|
-
if (axle.numberOfAxles > 1 && (!axle.
|
|
45
|
+
if (axle.numberOfAxles > 1 && (!axle.axleSpread || axle.axleSpread < 0)) {
|
|
46
46
|
throw new Error(`Invalid or missing axle spread for axle unit number ${firstAxle}`);
|
|
47
47
|
}
|
|
48
|
-
if (axle.numberOfAxles == 1 && axle.
|
|
48
|
+
if (axle.numberOfAxles == 1 && axle.axleSpread && axle.axleSpread < 0) {
|
|
49
49
|
throw new Error(`Invalid axle spread for single axle unit, cannot be a negative number`);
|
|
50
50
|
}
|
|
51
|
-
|
|
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;
|
|
51
|
+
let wheelbase = (_a = axle.axleSpread) !== null && _a !== void 0 ? _a : 0;
|
|
55
52
|
// Now loop through all of the next axles, building up a group
|
|
56
53
|
// for each.
|
|
57
54
|
axleConfig.slice(firstAxle).forEach((axleN) => {
|
|
58
|
-
var _a
|
|
59
|
-
if (!axleN.
|
|
55
|
+
var _a;
|
|
56
|
+
if (!axleN.axleUnitWeight || axleN.axleUnitWeight < 0) {
|
|
60
57
|
throw new Error(`Invalid or missing weight for axle unit number ${nextAxle}`);
|
|
61
58
|
}
|
|
62
|
-
totalWeight += axleN.
|
|
63
|
-
if (axleN.numberOfAxles > 1 &&
|
|
59
|
+
totalWeight += axleN.axleUnitWeight;
|
|
60
|
+
if (axleN.numberOfAxles > 1 &&
|
|
61
|
+
(!axleN.axleSpread || axleN.axleSpread < 0)) {
|
|
64
62
|
throw new Error(`Invalid or missing axle spread for axle unit number ${nextAxle}`);
|
|
65
63
|
}
|
|
66
|
-
|
|
64
|
+
if (!axleN.interaxleSpacing || axleN.interaxleSpacing < 0) {
|
|
65
|
+
throw new Error(`Invalid or missing axle spacing between axle units ${firstAxle} and ${nextAxle}`);
|
|
66
|
+
}
|
|
67
|
+
wheelbase += ((_a = axleN.axleSpread) !== null && _a !== void 0 ? _a : 0) + axleN.interaxleSpacing;
|
|
67
68
|
// The magic is in the next line
|
|
68
69
|
const maxBridge = BRIDGE_MULTIPLIER * wheelbase + BRIDGE_MIN_WEIGHT;
|
|
69
70
|
// Push the axle group result to the results array, including
|
|
@@ -75,14 +76,6 @@ function runBridgeFormula(axleConfig, policy) {
|
|
|
75
76
|
actualWeight: totalWeight,
|
|
76
77
|
success: totalWeight <= maxBridge,
|
|
77
78
|
});
|
|
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
79
|
nextAxle++;
|
|
87
80
|
});
|
|
88
81
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Policy } from '../policy-engine';
|
|
2
|
+
import { ConditionForPermit } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Gets a list of conditions that are applicable for the supplied permit
|
|
5
|
+
* application. The conditions may be driven by those applicable for the
|
|
6
|
+
* permit type, or the vehicle type, or other aspects of the permit application.
|
|
7
|
+
* @param permitApp The in-progress permit application
|
|
8
|
+
* @param policy Policy object
|
|
9
|
+
* @returns Array of conditions that apply to the specific permit application
|
|
10
|
+
*/
|
|
11
|
+
export declare function getConditionsForPermitHelper(permitApp: any, policy: Policy): Array<ConditionForPermit>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getConditionsForPermitHelper = getConditionsForPermitHelper;
|
|
4
|
+
/**
|
|
5
|
+
* Gets a list of conditions that are applicable for the supplied permit
|
|
6
|
+
* application. The conditions may be driven by those applicable for the
|
|
7
|
+
* permit type, or the vehicle type, or other aspects of the permit application.
|
|
8
|
+
* @param permitApp The in-progress permit application
|
|
9
|
+
* @param policy Policy object
|
|
10
|
+
* @returns Array of conditions that apply to the specific permit application
|
|
11
|
+
*/
|
|
12
|
+
function getConditionsForPermitHelper(permitApp, policy) {
|
|
13
|
+
var _a, _b;
|
|
14
|
+
let conditionsForPermit = [];
|
|
15
|
+
if (permitApp.permitType) {
|
|
16
|
+
// Get all conditions applicable to the permit type
|
|
17
|
+
const permitType = policy.getPermitTypeDefinition(permitApp.permitType);
|
|
18
|
+
if (permitType) {
|
|
19
|
+
conditionsForPermit = conditionsForPermit.concat(expandConditions(policy, permitType.conditions));
|
|
20
|
+
}
|
|
21
|
+
// Get any conditions specific to the permitted vehicle
|
|
22
|
+
if ((_b = (_a = permitApp.permitData) === null || _a === void 0 ? void 0 : _a.vehicleDetails) === null || _b === void 0 ? void 0 : _b.vehicleSubType) {
|
|
23
|
+
const vehicle = policy.getVehicleDefinition(permitApp.permitData.vehicleDetails.vehicleSubType);
|
|
24
|
+
if (vehicle) {
|
|
25
|
+
conditionsForPermit = conditionsForPermit.concat(expandConditions(policy, vehicle.conditions));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return conditionsForPermit;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Expand a list of ConditionRequirement to include the full
|
|
33
|
+
* properties of the configured condition in the policy definition
|
|
34
|
+
* @param conditions Array of condition requirements
|
|
35
|
+
* @param policy Policy to use for condition definitions
|
|
36
|
+
* @returns Array of full ConditionForPermit object, or empty array if
|
|
37
|
+
* none found matching.
|
|
38
|
+
*/
|
|
39
|
+
function expandConditions(policy, conditions) {
|
|
40
|
+
const expandedConditions = [];
|
|
41
|
+
conditions === null || conditions === void 0 ? void 0 : conditions.forEach((c) => {
|
|
42
|
+
var _a;
|
|
43
|
+
const condition = (_a = policy.policyDefinition.conditions) === null || _a === void 0 ? void 0 : _a.find((cond) => cond.condition == c.condition);
|
|
44
|
+
if (condition) {
|
|
45
|
+
expandedConditions.push(Object.assign(Object.assign({}, condition), c));
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return expandedConditions;
|
|
49
|
+
}
|
package/dist/policy-engine.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PolicyDefinition, PermitType, Commodity, SizeDimension, AxleConfiguration, BridgeCalculationResult } from 'onroute-policy-engine/types';
|
|
1
|
+
import { PolicyDefinition, PermitType, Commodity, VehicleType, SizeDimension, AxleConfiguration, BridgeCalculationResult, ConditionForPermit } from 'onroute-policy-engine/types';
|
|
2
2
|
import { Engine } from 'json-rules-engine';
|
|
3
3
|
import { ValidationResults } from './validation-results';
|
|
4
4
|
import { SpecialAuthorizations } from './types/special-authorizations';
|
|
@@ -34,6 +34,14 @@ export declare class Policy {
|
|
|
34
34
|
* @returns Results of the validation of the permit application
|
|
35
35
|
*/
|
|
36
36
|
validate(permit: any): Promise<ValidationResults>;
|
|
37
|
+
/**
|
|
38
|
+
* Gets a list of conditions that are applicable for the supplied permit
|
|
39
|
+
* application. The conditions may be driven by those applicable for the
|
|
40
|
+
* permit type, or the vehicle type, or other aspects of the permit application.
|
|
41
|
+
* @param permit The in-progress permit application
|
|
42
|
+
* @returns Array of conditions that apply to the specific permit application
|
|
43
|
+
*/
|
|
44
|
+
getConditionsForPermit(permit: any): Array<ConditionForPermit>;
|
|
37
45
|
/**
|
|
38
46
|
* Gets a list of all configured permit types in the policy definition.
|
|
39
47
|
* @returns Map of permit type IDs to permit type names.
|
|
@@ -149,6 +157,13 @@ export declare class Policy {
|
|
|
149
157
|
* @returns PermitType definition for the supplied ID.
|
|
150
158
|
*/
|
|
151
159
|
getPermitTypeDefinition(type?: string): PermitType | null;
|
|
160
|
+
/**
|
|
161
|
+
* Gets a full VehicleType definition by ID (subType)
|
|
162
|
+
* @param subType String id (subType) of the vehicle. Can be either
|
|
163
|
+
* a trailer subtype or a power unit subtype.
|
|
164
|
+
* @returns Vehicle Type (trailer or power unit), or null if none found
|
|
165
|
+
*/
|
|
166
|
+
getVehicleDefinition(subType?: string): VehicleType | null;
|
|
152
167
|
/**
|
|
153
168
|
* Gets a full Commodity definition by ID
|
|
154
169
|
* @param type Type ID of the commodity to return.
|
package/dist/policy-engine.js
CHANGED
|
@@ -16,6 +16,7 @@ const valid_1 = __importDefault(require("semver/functions/valid"));
|
|
|
16
16
|
const lt_1 = __importDefault(require("semver/functions/lt"));
|
|
17
17
|
const major_1 = __importDefault(require("semver/functions/major"));
|
|
18
18
|
const vehicles_helper_1 = require("./helper/vehicles.helper");
|
|
19
|
+
const conditions_helper_1 = require("./helper/conditions.helper");
|
|
19
20
|
/** Class representing commercial vehicle policy. */
|
|
20
21
|
class Policy {
|
|
21
22
|
/**
|
|
@@ -79,6 +80,16 @@ class Policy {
|
|
|
79
80
|
return validationResults;
|
|
80
81
|
}
|
|
81
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Gets a list of conditions that are applicable for the supplied permit
|
|
85
|
+
* application. The conditions may be driven by those applicable for the
|
|
86
|
+
* permit type, or the vehicle type, or other aspects of the permit application.
|
|
87
|
+
* @param permit The in-progress permit application
|
|
88
|
+
* @returns Array of conditions that apply to the specific permit application
|
|
89
|
+
*/
|
|
90
|
+
getConditionsForPermit(permit) {
|
|
91
|
+
return (0, conditions_helper_1.getConditionsForPermitHelper)(permit, this);
|
|
92
|
+
}
|
|
82
93
|
/**
|
|
83
94
|
* Gets a list of all configured permit types in the policy definition.
|
|
84
95
|
* @returns Map of permit type IDs to permit type names.
|
|
@@ -677,6 +688,26 @@ class Policy {
|
|
|
677
688
|
return null;
|
|
678
689
|
}
|
|
679
690
|
}
|
|
691
|
+
/**
|
|
692
|
+
* Gets a full VehicleType definition by ID (subType)
|
|
693
|
+
* @param subType String id (subType) of the vehicle. Can be either
|
|
694
|
+
* a trailer subtype or a power unit subtype.
|
|
695
|
+
* @returns Vehicle Type (trailer or power unit), or null if none found
|
|
696
|
+
*/
|
|
697
|
+
getVehicleDefinition(subType) {
|
|
698
|
+
var _a, _b;
|
|
699
|
+
if (this.policyDefinition.vehicleTypes) {
|
|
700
|
+
const puType = (_a = this.policyDefinition.vehicleTypes.powerUnitTypes) === null || _a === void 0 ? void 0 : _a.find((pu) => pu.id == subType);
|
|
701
|
+
if (puType) {
|
|
702
|
+
return puType;
|
|
703
|
+
}
|
|
704
|
+
const trType = (_b = this.policyDefinition.vehicleTypes.trailerTypes) === null || _b === void 0 ? void 0 : _b.find((tr) => tr.id == subType);
|
|
705
|
+
if (trType) {
|
|
706
|
+
return trType;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
return null;
|
|
710
|
+
}
|
|
680
711
|
/**
|
|
681
712
|
* Gets a full Commodity definition by ID
|
|
682
713
|
* @param type Type ID of the commodity to return.
|
package/dist/types/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { DimensionModifier } from './dimension-modifier';
|
|
|
7
7
|
export { PermitFacts } from './facts';
|
|
8
8
|
export { GeographicRegion } from './geographic-region';
|
|
9
9
|
export { IdentifiedObject } from './identified-object';
|
|
10
|
+
export { PermitConditionDefinition, ConditionRequirement, ConditionForPermit, } from './permit-condition';
|
|
10
11
|
export { PermitType } from './permit-type';
|
|
11
12
|
export { PolicyDefinition } from './policy-definition';
|
|
12
13
|
export { Matrix, RangeMatrix } from './range-matrix';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type PermitConditionDefinition = {
|
|
2
|
+
description: string;
|
|
3
|
+
condition: string;
|
|
4
|
+
conditionLink: string;
|
|
5
|
+
};
|
|
6
|
+
export type ConditionRequirement = {
|
|
7
|
+
condition: string;
|
|
8
|
+
mandatory?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type ConditionForPermit = PermitConditionDefinition & ConditionRequirement;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RuleProperties } from 'json-rules-engine';
|
|
2
2
|
import { CostRule, IdentifiedObject } from 'onroute-policy-engine/types';
|
|
3
|
+
import { ConditionRequirement } from './permit-condition';
|
|
3
4
|
export type PermitType = IdentifiedObject & {
|
|
4
5
|
routingRequired: boolean;
|
|
5
6
|
weightDimensionRequired: boolean;
|
|
@@ -9,4 +10,5 @@ export type PermitType = IdentifiedObject & {
|
|
|
9
10
|
allowedCommodities?: Array<string>;
|
|
10
11
|
rules?: Array<RuleProperties>;
|
|
11
12
|
costRules?: Array<CostRule>;
|
|
13
|
+
conditions?: Array<ConditionRequirement>;
|
|
12
14
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GeographicRegion, PermitType, DefaultWeightDimensions, VehicleTypes, Commodity, SizeDimension, VehicleCategories, RangeMatrix, BridgeCalculationConstants } from 'onroute-policy-engine/types';
|
|
1
|
+
import { GeographicRegion, PermitType, DefaultWeightDimensions, VehicleTypes, Commodity, SizeDimension, VehicleCategories, RangeMatrix, BridgeCalculationConstants, PermitConditionDefinition } from 'onroute-policy-engine/types';
|
|
2
2
|
import { RuleProperties } from 'json-rules-engine';
|
|
3
3
|
export type PolicyDefinition = {
|
|
4
4
|
minPEVersion: string;
|
|
@@ -12,4 +12,5 @@ export type PolicyDefinition = {
|
|
|
12
12
|
commodities: Array<Commodity>;
|
|
13
13
|
rangeMatrices?: Array<RangeMatrix>;
|
|
14
14
|
bridgeCalculationConstants: BridgeCalculationConstants;
|
|
15
|
+
conditions?: Array<PermitConditionDefinition>;
|
|
15
16
|
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { IdentifiedObject, SizeDimension, PowerUnitWeightDimension, TrailerWeightDimension } from 'onroute-policy-engine/types';
|
|
2
|
+
import { ConditionRequirement } from './permit-condition';
|
|
2
3
|
export type VehicleType = IdentifiedObject & {
|
|
3
4
|
category: string;
|
|
4
5
|
defaultSizeDimensions?: SizeDimension;
|
|
5
6
|
ignoreForSizeDimensions?: boolean;
|
|
6
7
|
isLcv?: boolean;
|
|
8
|
+
conditions?: Array<ConditionRequirement>;
|
|
7
9
|
};
|
|
8
10
|
export type PowerUnitType = VehicleType & {
|
|
9
11
|
defaultWeightDimensions?: Array<PowerUnitWeightDimension>;
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "v1.
|
|
1
|
+
export declare const version = "v1.6.0";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED