onroute-policy-engine 0.1.0 → 0.2.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.
Files changed (40) hide show
  1. package/README.md +5 -4
  2. package/dist/enum/accessory-vehicle-type.d.ts +4 -0
  3. package/dist/enum/accessory-vehicle-type.js +8 -0
  4. package/dist/enum/facts.d.ts +5 -1
  5. package/dist/enum/facts.js +4 -0
  6. package/dist/enum/index.d.ts +2 -0
  7. package/dist/enum/index.js +5 -1
  8. package/dist/enum/permit-app-info.d.ts +8 -2
  9. package/dist/enum/permit-app-info.js +8 -2
  10. package/dist/enum/validation-result-code.d.ts +2 -1
  11. package/dist/enum/validation-result-code.js +1 -0
  12. package/dist/enum/validation-result-type.d.ts +2 -1
  13. package/dist/enum/validation-result-type.js +1 -0
  14. package/dist/enum/vehicle-types.d.ts +4 -0
  15. package/dist/enum/vehicle-types.js +8 -0
  16. package/dist/helper/facts.helper.d.ts +2 -9
  17. package/dist/helper/facts.helper.js +63 -26
  18. package/dist/helper/lists.helper.d.ts +13 -0
  19. package/dist/helper/lists.helper.js +32 -1
  20. package/dist/helper/rules-engine.helper.js +32 -2
  21. package/dist/policy-engine.d.ts +82 -2
  22. package/dist/policy-engine.js +516 -6
  23. package/dist/rule-operator/custom-operators.js +5 -1
  24. package/dist/types/commodity.d.ts +10 -3
  25. package/dist/types/cost-rule.d.ts +4 -0
  26. package/dist/types/cost-rule.js +2 -0
  27. package/dist/types/index.d.ts +4 -2
  28. package/dist/types/permit-type.d.ts +2 -1
  29. package/dist/types/policy-definition.d.ts +2 -1
  30. package/dist/types/range-matrix.d.ts +9 -0
  31. package/dist/types/range-matrix.js +2 -0
  32. package/dist/types/region-size-override.d.ts +3 -3
  33. package/dist/types/self-issuable.d.ts +1 -1
  34. package/dist/types/size-dimension.d.ts +7 -7
  35. package/dist/types/vehicle-type.d.ts +1 -0
  36. package/dist/types/vehicle.d.ts +11 -5
  37. package/dist/validation-result.d.ts +1 -0
  38. package/dist/validation-results.d.ts +5 -0
  39. package/dist/validation-results.js +10 -1
  40. package/package.json +3 -3
@@ -1,10 +1,10 @@
1
- import { DimensionModifier, RegionSizeOverride } from 'onroute-policy-engine/types';
2
- export type SizeDimension = {
3
- frontProjection: number;
4
- rearProjection: number;
5
- width: number;
6
- height: number;
7
- length: number;
1
+ import { DimensionModifier, RegionSizeOverride, SelfIssuable } from 'onroute-policy-engine/types';
2
+ export type SizeDimension = SelfIssuable & {
3
+ fp?: number;
4
+ rp?: number;
5
+ w?: number;
6
+ h?: number;
7
+ l?: number;
8
8
  modifiers?: Array<DimensionModifier>;
9
9
  regions?: Array<RegionSizeOverride>;
10
10
  };
@@ -2,6 +2,7 @@ import { IdentifiedObject, SizeDimension, PowerUnitWeightDimension, TrailerWeigh
2
2
  export type VehicleType = IdentifiedObject & {
3
3
  category: string;
4
4
  defaultSizeDimensions?: SizeDimension;
5
+ ignoreForSizeDimensions?: boolean;
5
6
  };
6
7
  export type PowerUnitType = VehicleType & {
7
8
  defaultWeightDimensions?: Array<PowerUnitWeightDimension>;
@@ -1,12 +1,18 @@
1
- import { SizeDimension, PowerUnitWeightDimension, TrailerWeightDimension } from 'onroute-policy-engine/types';
2
- export type Vehicle = {
1
+ import { SelfIssuable, SizeDimension, PowerUnitWeightDimension, TrailerWeightDimension } from 'onroute-policy-engine/types';
2
+ export type Vehicle = SelfIssuable & {
3
3
  type: string;
4
- canFollow: Array<string>;
4
+ };
5
+ export type VehicleSizeConfiguration = Vehicle & {
6
+ trailers: Array<TrailerSize>;
7
+ };
8
+ export type TrailerSize = Vehicle & {
5
9
  sizeDimensions?: Array<SizeDimension>;
10
+ jeep: boolean;
11
+ booster: boolean;
6
12
  };
7
- export type PowerUnit = Vehicle & {
13
+ export type PowerUnitWeight = Vehicle & {
8
14
  weightDimensions?: Array<PowerUnitWeightDimension>;
9
15
  };
10
- export type Trailer = Vehicle & {
16
+ export type TrailerWeight = Vehicle & {
11
17
  weightDimensions?: Array<TrailerWeightDimension>;
12
18
  };
@@ -16,4 +16,5 @@ export declare class ValidationResult {
16
16
  code: string;
17
17
  message: string;
18
18
  fieldReference?: string;
19
+ cost?: number;
19
20
  }
@@ -18,6 +18,11 @@ export declare class ValidationResults {
18
18
  * permit.
19
19
  */
20
20
  information: Array<ValidationResult>;
21
+ /**
22
+ * Array of cost messages, based on cost rules. If there are more than
23
+ * one cost message, all should be summed to get the total permit cost.
24
+ */
25
+ cost: Array<ValidationResult>;
21
26
  /**
22
27
  * Creates a new ValidationResults from the json-rules-engine result.
23
28
  * Populates the violations, requirements, warnings, and messages arrays
@@ -29,14 +29,20 @@ class ValidationResults {
29
29
  * permit.
30
30
  */
31
31
  this.information = [];
32
+ /**
33
+ * Array of cost messages, based on cost rules. If there are more than
34
+ * one cost message, all should be summed to get the total permit cost.
35
+ */
36
+ this.cost = [];
32
37
  if (engineResult) {
33
38
  engineResult.events.forEach((e) => {
34
- var _a, _b, _c, _d, _e, _f;
39
+ var _a, _b, _c, _d, _e, _f, _g;
35
40
  const message = (_b = (_a = e.params) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : `Unknown message: params=${JSON.stringify(e.params)}`;
36
41
  const code = (_d = (_c = e.params) === null || _c === void 0 ? void 0 : _c.code) !== null && _d !== void 0 ? _d : validation_result_code_1.ValidationResultCode.GeneralResult;
37
42
  const type = (_e = e.type) !== null && _e !== void 0 ? _e : validation_result_type_1.ValidationResultType.Violation.toString();
38
43
  const result = new validation_result_1.ValidationResult(type, code, message);
39
44
  result.fieldReference = (_f = e.params) === null || _f === void 0 ? void 0 : _f.fieldReference;
45
+ result.cost = (_g = e.params) === null || _g === void 0 ? void 0 : _g.cost;
40
46
  switch (type) {
41
47
  case validation_result_type_1.ValidationResultType.Violation:
42
48
  this.violations.push(result);
@@ -50,6 +56,9 @@ class ValidationResults {
50
56
  case validation_result_type_1.ValidationResultType.Information:
51
57
  this.information.push(result);
52
58
  break;
59
+ case validation_result_type_1.ValidationResultType.Cost:
60
+ this.cost.push(result);
61
+ break;
53
62
  default:
54
63
  // Treat any unknown validation event as a violation since
55
64
  // it is an unexpected scenario.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onroute-policy-engine",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Policy Engine library for commercial vehicle permitting",
5
5
  "main": "dist/index.js",
6
6
  "exports": {
@@ -24,10 +24,11 @@
24
24
  },
25
25
  "author": "John Fletcher",
26
26
  "license": "Apache-2.0",
27
- "homepage": "https://github.com/bcgov/onroutebc#readme",
27
+ "homepage": "https://github.com/bcgov/onroutebc#readme",
28
28
  "devDependencies": {
29
29
  "@types/jest": "^29.5.12",
30
30
  "@typescript-eslint/eslint-plugin": "^7.5.0",
31
+ "csv": "^6.3.10",
31
32
  "eslint": "^8.57.0",
32
33
  "eslint-config-prettier": "^9.1.0",
33
34
  "jest": "^29.7.0",
@@ -38,7 +39,6 @@
38
39
  },
39
40
  "dependencies": {
40
41
  "dayjs": "^1.11.10",
41
- "flattie": "^1.1.1",
42
42
  "json-rules-engine": "^6.5.0"
43
43
  },
44
44
  "jest": {