onroute-policy-engine 1.5.0 → 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.
@@ -16,8 +16,8 @@ jobs:
16
16
 
17
17
  lint:
18
18
  name: lint
19
- if: ${{ ! github.event.pull_request.draft }}
20
- runs-on: ubuntu-latest # Runs on the latest version of 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: ${{ ! github.event.pull_request.draft }}
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-latest
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-latest
16
+ runs-on: ubuntu-24.04
17
17
  permissions:
18
18
  id-token: write # needed for provenance data generation
19
19
  contents: write
@@ -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
+ }
@@ -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.
@@ -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.
@@ -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;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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.5.0";
1
+ export declare const version = "v1.6.0";
package/dist/version.js CHANGED
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
4
  // Generated by genversion.
5
- exports.version = 'v1.5.0';
5
+ exports.version = 'v1.6.0';
package/package.json CHANGED
@@ -89,5 +89,5 @@
89
89
  ],
90
90
  "testEnvironment": "node"
91
91
  },
92
- "version": "v1.5.0"
92
+ "version": "v1.6.0"
93
93
  }