onroute-policy-engine 2.16.0 → 2.17.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.
@@ -1,5 +1,6 @@
1
1
  export declare enum PolicyFacts {
2
2
  AllowedVehicles = "allowedVehicles",
3
+ AxleCalcResults = "axleCalcResults",
3
4
  AxleCalcViolations = "axleCalcViolations",
4
5
  ConfigurationIsValid = "configurationIsValid",
5
6
  DaysBetween = "daysBetween",
@@ -4,6 +4,7 @@ exports.CostFacts = exports.PolicyFacts = void 0;
4
4
  var PolicyFacts;
5
5
  (function (PolicyFacts) {
6
6
  PolicyFacts["AllowedVehicles"] = "allowedVehicles";
7
+ PolicyFacts["AxleCalcResults"] = "axleCalcResults";
7
8
  PolicyFacts["AxleCalcViolations"] = "axleCalcViolations";
8
9
  PolicyFacts["ConfigurationIsValid"] = "configurationIsValid";
9
10
  PolicyFacts["DaysBetween"] = "daysBetween";
@@ -9,6 +9,25 @@ const quarterOfYear_1 = __importDefault(require("dayjs/plugin/quarterOfYear"));
9
9
  const enum_1 = require("onroute-policy-engine/enum");
10
10
  const policy_check_helper_1 = require("./policy-check.helper");
11
11
  dayjs_1.default.extend(quarterOfYear_1.default);
12
+ const AXLE_CALC_RESULTS_FACT = 'axleCalcResults';
13
+ const getAxleCalculationInputs = async (policy, almanac) => {
14
+ var _a, _b;
15
+ const vehicleDetails = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, enum_1.PermitAppInfo.VehicleDetails);
16
+ const vehicleConfigurationData = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, enum_1.PermitAppInfo.VehicleConfiguration);
17
+ const vehicleConfiguration = policy.getSimplifiedVehicleConfiguration(vehicleDetails, vehicleConfigurationData);
18
+ const powerUnitAxleConfiguration = (_a = vehicleConfigurationData === null || vehicleConfigurationData === void 0 ? void 0 : vehicleConfigurationData.axleConfiguration) !== null && _a !== void 0 ? _a : [];
19
+ const trailers = (_b = vehicleConfigurationData === null || vehicleConfigurationData === void 0 ? void 0 : vehicleConfigurationData.trailers) !== null && _b !== void 0 ? _b : [];
20
+ const hasNestedTrailerAxleConfiguration = trailers.some((trailer) => Array.isArray(trailer.axleConfiguration) &&
21
+ trailer.axleConfiguration.length > 0);
22
+ const axleConfiguration = hasNestedTrailerAxleConfiguration
23
+ ? policy.combineAxleConfigurations(powerUnitAxleConfiguration, trailers)
24
+ : powerUnitAxleConfiguration;
25
+ return {
26
+ vehicleConfiguration,
27
+ axleConfiguration,
28
+ licensedGVW: vehicleDetails.licensedGVW || 0,
29
+ };
30
+ };
12
31
  /**
13
32
  * Adds runtime facts for the validation. For example, adds the
14
33
  * validation date for comparison against startDate of the permit.
@@ -112,8 +131,7 @@ function addRuntimeFacts(engine, policy) {
112
131
  * weight by summing the weights of the individual axle units.
113
132
  */
114
133
  engine.addFact(enum_1.PolicyFacts.GrossVehicleCombinationWeight, async function (params, almanac) {
115
- // Retrieve the axle configuration from permit data
116
- const axleConfiguration = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, enum_1.PermitAppInfo.AxleConfiguration);
134
+ const { axleConfiguration } = await getAxleCalculationInputs(policy, almanac);
117
135
  return axleConfiguration.reduce((w, curr) => w + curr.axleUnitWeight, 0);
118
136
  });
119
137
  /**
@@ -122,10 +140,7 @@ function addRuntimeFacts(engine, policy) {
122
140
  * Returns true if all policy check results are 'pass', false otherwise.
123
141
  */
124
142
  engine.addFact(enum_1.PolicyFacts.PolicyCheckPassed.toString(), async function (params, almanac) {
125
- // Retrieve the complete vehicle configuration (power unit + trailers)
126
- const vehicleConfiguration = await almanac.factValue(enum_1.PolicyFacts.VehicleConfiguration);
127
- // Retrieve the axle configuration from permit data
128
- const axleConfiguration = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, enum_1.PermitAppInfo.AxleConfiguration);
143
+ const { vehicleConfiguration, axleConfiguration } = await getAxleCalculationInputs(policy, almanac);
129
144
  // Get the specific policy check ID from parameters
130
145
  const policyCheckId = params.policyId;
131
146
  // Look up the policy check function from the policy check map
@@ -144,19 +159,20 @@ function addRuntimeFacts(engine, policy) {
144
159
  return policyCheckResults.every((r) => r.result === enum_1.PolicyCheckResultType.Pass);
145
160
  });
146
161
  /**
147
- * Add runtime fact to return an array of all messages that result from
148
- * all combined policy checks for axle calculation. This is used in
149
- * permit validation, returned in the details param for that rule for
150
- * overweight permit types.
162
+ * Add runtime fact to return the complete runAxleCalculation result. This
163
+ * is the structured ASW validation detail exposed by validate().
164
+ */
165
+ engine.addFact(AXLE_CALC_RESULTS_FACT, async function (params, almanac) {
166
+ const { vehicleConfiguration, axleConfiguration, licensedGVW } = await getAxleCalculationInputs(policy, almanac);
167
+ return policy.runAxleCalculation(vehicleConfiguration, axleConfiguration, licensedGVW);
168
+ });
169
+ /**
170
+ * Add runtime fact to return messages from failed axle calculation checks.
171
+ * This keeps the generic validation violation as the gating signal while
172
+ * axleCalcResults carries the structured ASW detail.
151
173
  */
152
174
  engine.addFact(enum_1.PolicyFacts.AxleCalcViolations, async function (params, almanac) {
153
- // Retrieve the complete vehicle configuration (power unit + trailers)
154
- const vehicleConfiguration = await almanac.factValue(enum_1.PolicyFacts.VehicleConfiguration);
155
- // Retrieve the axle configuration from permit data
156
- const axleConfiguration = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, enum_1.PermitAppInfo.AxleConfiguration);
157
- // Retrieve licensed GVW from permit data
158
- const vehicleDetails = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, enum_1.PermitAppInfo.VehicleDetails);
159
- const results = policy.runAxleCalculation(vehicleConfiguration, axleConfiguration, vehicleDetails.licensedGVW || 0);
175
+ const results = await almanac.factValue(AXLE_CALC_RESULTS_FACT);
160
176
  const violations = results.results.filter((r) => r.result === enum_1.PolicyCheckResultType.Fail);
161
177
  return violations.map((v) => v.message);
162
178
  });
@@ -60,7 +60,7 @@ class Policy {
60
60
  * @returns Results of the validation of the permit application
61
61
  */
62
62
  async validate(permit) {
63
- var _a, _b;
63
+ var _a, _b, _c, _d;
64
64
  const engine = this.rulesEngines.get(permit.permitType);
65
65
  if (!engine) {
66
66
  // If the permit type being validated has no configuration in the
@@ -78,13 +78,19 @@ class Policy {
78
78
  const engineResult = await engine.run(permit);
79
79
  // Wrap the json-rules-engine result in a ValidationResult object
80
80
  const validationResults = new validation_results_1.ValidationResults(engineResult);
81
+ const shouldIncludeAxleCalculationResults = permit.permitType === 'STOW' &&
82
+ ((_b = (_a = permit.permitData) === null || _a === void 0 ? void 0 : _a.vehicleConfiguration) === null || _b === void 0 ? void 0 : _b.axleConfiguration);
83
+ if (shouldIncludeAxleCalculationResults) {
84
+ validationResults.axleCalculationResults =
85
+ await engineResult.almanac.factValue('axleCalcResults');
86
+ }
81
87
  // Include an informational message if the client is an LCV carrier
82
- if ((_a = this.specialAuthorizations) === null || _a === void 0 ? void 0 : _a.isLcvAllowed) {
88
+ if ((_c = this.specialAuthorizations) === null || _c === void 0 ? void 0 : _c.isLcvAllowed) {
83
89
  validationResults.information.push(new validation_result_1.ValidationResult(enum_1.ValidationResultType.Information, enum_1.ValidationResultCode.IsLcvCarrier, `Policy validation allowing long combination vehicle permitting for client '${this.specialAuthorizations.companyId}'`));
84
90
  }
85
91
  // Include an informational message and adjust the cost if the client
86
92
  // has a no fee flag set.
87
- if ((_b = this.specialAuthorizations) === null || _b === void 0 ? void 0 : _b.noFeeType) {
93
+ if ((_d = this.specialAuthorizations) === null || _d === void 0 ? void 0 : _d.noFeeType) {
88
94
  const originalPermitCost = validationResults === null || validationResults === void 0 ? void 0 : validationResults.cost.reduce((accumulator, { cost }) => accumulator + (cost !== null && cost !== void 0 ? cost : 0), 0);
89
95
  // Clear the cost array and replace with zero cost
90
96
  validationResults.cost.length = 0;
@@ -1,5 +1,6 @@
1
1
  import { EngineResult } from 'json-rules-engine';
2
2
  import { ValidationResult } from './validation-result';
3
+ import { AxleCalcResults } from './types/axle-calculation-results';
3
4
  /** Represents the results of a permit application validation against policy */
4
5
  export declare class ValidationResults {
5
6
  /** Array of policy violations found during validation. */
@@ -23,6 +24,12 @@ export declare class ValidationResults {
23
24
  * one cost message, all should be summed to get the total permit cost.
24
25
  */
25
26
  cost: Array<ValidationResult>;
27
+ /**
28
+ * Structured axle-spacing-and-weights policy-check results. This mirrors
29
+ * runAxleCalculation() so consumers can highlight ASW fields while
30
+ * violations remains the coarse validation-gating signal.
31
+ */
32
+ axleCalculationResults?: AxleCalcResults;
26
33
  /**
27
34
  * Creates a new ValidationResults from the json-rules-engine result.
28
35
  * Populates the violations, requirements, warnings, and messages arrays
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "v2.16.0";
1
+ export declare const version = "v2.17.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 = 'v2.16.0';
5
+ exports.version = 'v2.17.0';
package/package.json CHANGED
@@ -91,5 +91,5 @@
91
91
  ],
92
92
  "testEnvironment": "node"
93
93
  },
94
- "version": "v2.16.0"
94
+ "version": "v2.17.0"
95
95
  }