onroute-policy-engine 0.5.0 → 0.7.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/dist/enum/facts.d.ts +6 -3
- package/dist/enum/facts.js +9 -5
- package/dist/enum/index.d.ts +1 -1
- package/dist/enum/index.js +2 -1
- package/dist/enum/permit-app-info.d.ts +2 -1
- package/dist/enum/permit-app-info.js +1 -0
- package/dist/helper/facts.helper.js +73 -3
- package/package.json +1 -1
|
@@ -63,6 +63,6 @@ jobs:
|
|
|
63
63
|
if: always()
|
|
64
64
|
runs-on: ubuntu-22.04
|
|
65
65
|
steps:
|
|
66
|
-
- if: contains(needs.*.result, 'failure')
|
|
66
|
+
- if: contains(needs.*.result, 'failure')||contains(needs.*.result, 'canceled')
|
|
67
67
|
run: echo "At least one job has failed." && exit 1
|
|
68
68
|
- run: echo "Success!"
|
package/dist/enum/facts.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
export declare enum PolicyFacts {
|
|
2
2
|
AllowedVehicles = "allowedVehicles",
|
|
3
|
-
ConditionalFixedCost = "conditionalFixedCost",
|
|
4
3
|
DaysInPermitYear = "daysInPermitYear",
|
|
5
4
|
EndOfPermitQuarter = "endOfPermitQuarter",
|
|
6
5
|
ValidationDate = "validationDate",
|
|
6
|
+
ConfigurationIsValid = "configurationIsValid"
|
|
7
|
+
}
|
|
8
|
+
export declare enum CostFacts {
|
|
9
|
+
ConditionalFixedCost = "conditionalFixedCost",
|
|
7
10
|
FixedCost = "fixedCost",
|
|
8
11
|
CostPerMonth = "costPerMonth",
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
CostPerKilometre = "costPerKilometre",
|
|
13
|
+
RangeMatrixCostLookup = "rangeMatrixCostLookup"
|
|
11
14
|
}
|
package/dist/enum/facts.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PolicyFacts = void 0;
|
|
3
|
+
exports.CostFacts = exports.PolicyFacts = void 0;
|
|
4
4
|
var PolicyFacts;
|
|
5
5
|
(function (PolicyFacts) {
|
|
6
6
|
PolicyFacts["AllowedVehicles"] = "allowedVehicles";
|
|
7
|
-
PolicyFacts["ConditionalFixedCost"] = "conditionalFixedCost";
|
|
8
7
|
PolicyFacts["DaysInPermitYear"] = "daysInPermitYear";
|
|
9
8
|
PolicyFacts["EndOfPermitQuarter"] = "endOfPermitQuarter";
|
|
10
9
|
PolicyFacts["ValidationDate"] = "validationDate";
|
|
11
|
-
PolicyFacts["FixedCost"] = "fixedCost";
|
|
12
|
-
PolicyFacts["CostPerMonth"] = "costPerMonth";
|
|
13
|
-
PolicyFacts["RangeMatrixCostLookup"] = "rangeMatrixCostLookup";
|
|
14
10
|
PolicyFacts["ConfigurationIsValid"] = "configurationIsValid";
|
|
15
11
|
})(PolicyFacts || (exports.PolicyFacts = PolicyFacts = {}));
|
|
12
|
+
var CostFacts;
|
|
13
|
+
(function (CostFacts) {
|
|
14
|
+
CostFacts["ConditionalFixedCost"] = "conditionalFixedCost";
|
|
15
|
+
CostFacts["FixedCost"] = "fixedCost";
|
|
16
|
+
CostFacts["CostPerMonth"] = "costPerMonth";
|
|
17
|
+
CostFacts["CostPerKilometre"] = "costPerKilometre";
|
|
18
|
+
CostFacts["RangeMatrixCostLookup"] = "rangeMatrixCostLookup";
|
|
19
|
+
})(CostFacts || (exports.CostFacts = CostFacts = {}));
|
package/dist/enum/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { AccessoryVehicleType } from './accessory-vehicle-type';
|
|
2
|
-
export { PolicyFacts } from './facts';
|
|
2
|
+
export { PolicyFacts, CostFacts } from './facts';
|
|
3
3
|
export { PermitAppInfo } from './permit-app-info';
|
|
4
4
|
export { RelativePosition } from './relative-position';
|
|
5
5
|
export { ValidationResultCode } from './validation-result-code';
|
package/dist/enum/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VehicleTypes = exports.ValidationResultType = exports.ValidationResultCode = exports.RelativePosition = exports.PermitAppInfo = exports.PolicyFacts = exports.AccessoryVehicleType = void 0;
|
|
3
|
+
exports.VehicleTypes = exports.ValidationResultType = exports.ValidationResultCode = exports.RelativePosition = exports.PermitAppInfo = exports.CostFacts = exports.PolicyFacts = exports.AccessoryVehicleType = void 0;
|
|
4
4
|
var accessory_vehicle_type_1 = require("./accessory-vehicle-type");
|
|
5
5
|
Object.defineProperty(exports, "AccessoryVehicleType", { enumerable: true, get: function () { return accessory_vehicle_type_1.AccessoryVehicleType; } });
|
|
6
6
|
var facts_1 = require("./facts");
|
|
7
7
|
Object.defineProperty(exports, "PolicyFacts", { enumerable: true, get: function () { return facts_1.PolicyFacts; } });
|
|
8
|
+
Object.defineProperty(exports, "CostFacts", { enumerable: true, get: function () { return facts_1.CostFacts; } });
|
|
8
9
|
var permit_app_info_1 = require("./permit-app-info");
|
|
9
10
|
Object.defineProperty(exports, "PermitAppInfo", { enumerable: true, get: function () { return permit_app_info_1.PermitAppInfo; } });
|
|
10
11
|
var relative_position_1 = require("./relative-position");
|
|
@@ -12,5 +12,6 @@ export declare enum PermitAppInfo {
|
|
|
12
12
|
PermitDuration = "$.permitDuration",
|
|
13
13
|
PowerUnitType = "$.vehicleDetails.vehicleSubType",
|
|
14
14
|
TrailerList = "$.vehicleConfiguration.trailers",
|
|
15
|
-
Commodity = "$.permittedCommodity.commodityType"
|
|
15
|
+
Commodity = "$.permittedCommodity.commodityType",
|
|
16
|
+
TotalDistance = "$.permittedRoute.manualRoute.totalDistance"
|
|
16
17
|
}
|
|
@@ -17,4 +17,5 @@ var PermitAppInfo;
|
|
|
17
17
|
PermitAppInfo["PowerUnitType"] = "$.vehicleDetails.vehicleSubType";
|
|
18
18
|
PermitAppInfo["TrailerList"] = "$.vehicleConfiguration.trailers";
|
|
19
19
|
PermitAppInfo["Commodity"] = "$.permittedCommodity.commodityType";
|
|
20
|
+
PermitAppInfo["TotalDistance"] = "$.permittedRoute.manualRoute.totalDistance";
|
|
20
21
|
})(PermitAppInfo || (exports.PermitAppInfo = PermitAppInfo = {}));
|
|
@@ -65,7 +65,7 @@ function addRuntimeFacts(engine, policy) {
|
|
|
65
65
|
* Add runtime fact for a fixed permit cost, the cost supplied
|
|
66
66
|
* as a parameter.
|
|
67
67
|
*/
|
|
68
|
-
engine.addFact(enum_1.
|
|
68
|
+
engine.addFact(enum_1.CostFacts.FixedCost.toString(), async function (params) {
|
|
69
69
|
return params.cost;
|
|
70
70
|
});
|
|
71
71
|
/**
|
|
@@ -73,7 +73,7 @@ function addRuntimeFacts(engine, policy) {
|
|
|
73
73
|
* cost rule applied only when the fact and value supplied as parameters
|
|
74
74
|
* match.
|
|
75
75
|
*/
|
|
76
|
-
engine.addFact(enum_1.
|
|
76
|
+
engine.addFact(enum_1.CostFacts.ConditionalFixedCost.toString(), async function (params, almanac) {
|
|
77
77
|
const conditionValue = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, params.fact);
|
|
78
78
|
if (conditionValue && conditionValue === params.value) {
|
|
79
79
|
return params.cost;
|
|
@@ -87,7 +87,7 @@ function addRuntimeFacts(engine, policy) {
|
|
|
87
87
|
* policy as a 30 day period or portion thereof, except in the
|
|
88
88
|
* case of a full year in which case it is 12 months.
|
|
89
89
|
*/
|
|
90
|
-
engine.addFact(enum_1.
|
|
90
|
+
engine.addFact(enum_1.CostFacts.CostPerMonth.toString(), async function (params, almanac) {
|
|
91
91
|
const duration = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, enum_1.PermitAppInfo.PermitDuration);
|
|
92
92
|
const daysInPermitYear = await almanac.factValue(enum_1.PolicyFacts.DaysInPermitYear.toString());
|
|
93
93
|
let months = Math.floor(duration / 30);
|
|
@@ -101,4 +101,74 @@ function addRuntimeFacts(engine, policy) {
|
|
|
101
101
|
}
|
|
102
102
|
return months * params.cost;
|
|
103
103
|
});
|
|
104
|
+
/**
|
|
105
|
+
* Add runtime fact for cost per kilometre driven in the applicant's
|
|
106
|
+
* permitted route. Accepts an optional parameter minValue which
|
|
107
|
+
* specifies the minimum value for the permit if the kilometre cost
|
|
108
|
+
* is less than that value.
|
|
109
|
+
*/
|
|
110
|
+
engine.addFact(enum_1.CostFacts.CostPerKilometre.toString(), async function (params, almanac) {
|
|
111
|
+
const distance = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, enum_1.PermitAppInfo.TotalDistance);
|
|
112
|
+
let cost = distance * params.cost;
|
|
113
|
+
if (typeof params.minValue === 'number') {
|
|
114
|
+
cost = Math.max(cost, params.minValue);
|
|
115
|
+
}
|
|
116
|
+
return cost;
|
|
117
|
+
});
|
|
118
|
+
/**
|
|
119
|
+
* Add runtime fact to look up the permit cost from a matrix of
|
|
120
|
+
* value ranges configured in policy json. This is most commonly
|
|
121
|
+
* used for a permit cost that is based on the vehicle weight.
|
|
122
|
+
*/
|
|
123
|
+
engine.addFact(enum_1.CostFacts.RangeMatrixCostLookup.toString(), async function (params, almanac) {
|
|
124
|
+
var _a, _b;
|
|
125
|
+
// Get the parameter from the permit application whose
|
|
126
|
+
// value will be used to select the correct range matrix key
|
|
127
|
+
const rangeLookupKey = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, params.rangeLookupKey);
|
|
128
|
+
// Initialize cost to zero, if we are unable to find
|
|
129
|
+
// a matching value or matrix for whatever reason, the
|
|
130
|
+
// cost will default to zero (no matrix applicable)
|
|
131
|
+
let cost = 0;
|
|
132
|
+
// Get the ID of the matrix to look up
|
|
133
|
+
const matrixRef = (_a = params.matrixMap) === null || _a === void 0 ? void 0 : _a.find((r) => r.key === rangeLookupKey);
|
|
134
|
+
if (matrixRef) {
|
|
135
|
+
// If a matrix ID was returned, retrieve the matrix from the
|
|
136
|
+
// policy configuration that we need to use for cost lookup
|
|
137
|
+
// (for example, the 'annualFeeIndustrial' matrix)
|
|
138
|
+
const matrix = (_b = policy.policyDefinition.rangeMatrices) === null || _b === void 0 ? void 0 : _b.find((m) => m.id === matrixRef.value);
|
|
139
|
+
if (matrix) {
|
|
140
|
+
// if the matrix exists in policy configuration
|
|
141
|
+
// Retrieve the numeric value for the matrix lookup
|
|
142
|
+
// (for example, may be loaded GVW)
|
|
143
|
+
const matrixFactValue = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, params.matrixFactValue);
|
|
144
|
+
// Look up the correct entry in the matrix, where the lookup
|
|
145
|
+
// value falls within the min/max range
|
|
146
|
+
const matrixMatch = matrix.matrix.find((m) => {
|
|
147
|
+
let min = m.min;
|
|
148
|
+
if (typeof min !== 'number') {
|
|
149
|
+
min = Number.MIN_SAFE_INTEGER;
|
|
150
|
+
}
|
|
151
|
+
let max = m.max;
|
|
152
|
+
if (typeof max !== 'number') {
|
|
153
|
+
max = Number.MAX_SAFE_INTEGER;
|
|
154
|
+
}
|
|
155
|
+
return matrixFactValue >= min && matrixFactValue <= max;
|
|
156
|
+
});
|
|
157
|
+
if (matrixMatch) {
|
|
158
|
+
// If we got a hit from the matrix
|
|
159
|
+
cost = matrixMatch.value;
|
|
160
|
+
// If the cost rule includes a divisor, apply it here. A divisor
|
|
161
|
+
// may be used if, for example, the value from the lookup matrix
|
|
162
|
+
// is an annual fee but the permit is just a month or quarter.
|
|
163
|
+
if (typeof params.divisor === 'number' && params.divisor > 0) {
|
|
164
|
+
cost = Math.round(cost / params.divisor);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
console.log(`No range matrix with id ${matrixRef} found in the policy configuration`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return cost;
|
|
173
|
+
});
|
|
104
174
|
}
|
package/package.json
CHANGED