onroute-policy-engine 0.2.0 → 0.2.1

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.
@@ -0,0 +1,68 @@
1
+ name: Analysis
2
+
3
+ on:
4
+ pull_request:
5
+ types: [opened, reopened, synchronize, ready_for_review, converted_to_draft]
6
+
7
+ concurrency:
8
+ group: ${{ github.workflow }}-${{ github.ref }}
9
+ cancel-in-progress: true
10
+
11
+ jobs:
12
+ validate:
13
+ name: Validate PR
14
+ if: (! github.event.pull_request.draft)
15
+ uses: bcgov/quickstart-openshift-helpers/.github/workflows/.pr-validate.yml@v0.8.1
16
+
17
+ lint:
18
+ name: lint
19
+ if: ${{ ! github.event.pull_request.draft }}
20
+ runs-on: ubuntu-latest # Runs on the latest version of Ubuntu
21
+ steps:
22
+ - name: Checkout code
23
+ uses: actions/checkout@v4 # Checks out the code from the repository
24
+
25
+ - name: Set up Node.js
26
+ uses: actions/setup-node@v4
27
+ with:
28
+ node-version: '20.x'
29
+
30
+ - name: Install dependencies
31
+ run: npm install # Installs project dependencies
32
+
33
+ - name: Lint code
34
+ run: npx eslint . --config .eslintrc.cjs # Run ESLint with the specified config
35
+
36
+
37
+ # https://github.com/marketplace/actions/aqua-security-trivy
38
+ trivy:
39
+ name: Trivy Security Scan
40
+ if: ${{ ! github.event.pull_request.draft }}
41
+ runs-on: ubuntu-22.04
42
+ timeout-minutes: 1
43
+ steps:
44
+ - uses: actions/checkout@v4
45
+ - name: Run Trivy vulnerability scanner in repo mode
46
+ uses: aquasecurity/trivy-action@0.24.0
47
+ with:
48
+ format: "sarif"
49
+ output: "trivy-results.sarif"
50
+ ignore-unfixed: true
51
+ scan-type: "fs"
52
+ scanners: "vuln,secret,config"
53
+ severity: "CRITICAL,HIGH"
54
+
55
+ - name: Upload Trivy scan results to GitHub Security tab
56
+ uses: github/codeql-action/upload-sarif@v3
57
+ with:
58
+ sarif_file: "trivy-results.sarif"
59
+
60
+ results:
61
+ name: Analysis Results
62
+ needs: [validate, lint, trivy]
63
+ if: always()
64
+ runs-on: ubuntu-22.04
65
+ steps:
66
+ - if: contains(needs.*.result, 'failure')
67
+ run: echo "At least one job has failed." && exit 1
68
+ - run: echo "Success!"
@@ -0,0 +1,47 @@
1
+ ---
2
+ name: CI/CD Pipleine For Simple Package Publishing
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ workflow_dispatch:
7
+ jobs:
8
+ build:
9
+ runs-on: ubuntu-latest
10
+ permissions:
11
+ contents: read
12
+ packages: write
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+ deploy:
16
+ runs-on: ubuntu-latest
17
+ permissions:
18
+ id-token: write # needed for provenance data generation
19
+
20
+ steps:
21
+ - name: Checkout Code
22
+ uses: actions/checkout@v4
23
+
24
+ - name: Get Next Version
25
+ id: semver
26
+ uses: ietf-tools/semver-action@v1
27
+ with:
28
+ token: ${{ github.token }}
29
+ branch: main
30
+
31
+ - name: Injecting Semver Into Package.json
32
+ run: |
33
+ cat package.json | jq '. + { "version": "${{ steps.semver.outputs.next }}" }' | tee package.json
34
+
35
+ - uses: actions/setup-node@v4
36
+ with:
37
+ node-version: '20.x'
38
+ registry-url: 'https://registry.npmjs.org'
39
+
40
+ - run: npm ci
41
+ - run: tsc
42
+ - run: npm test
43
+
44
+ - name: Publish Package
45
+ run: npm publish --provenance --access public
46
+ env:
47
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/README.md CHANGED
@@ -1,50 +1,50 @@
1
- A JSON-based rules engine to validate onRouteBC permit applications against commercial vehicle policy.
2
-
3
- ## Synopsis
4
- ```orbc-policy-engine``` is a library designed to compare a commercial vehicle permit application against policy expressed in JSON format, and return a list of policy violations as well as other informational policy messages related to the permit.
5
-
6
- ```orbc-policy-engine``` makes use of https://github.com/CacheControl/json-rules-engine for rules engine functionality. Complex rules are modeled by extending the core ```json-rules-engine``` operators and other capabilities.
7
-
8
- ## Usage
9
- ```js
10
- import Policy from 'orbc-policy-engine';
11
-
12
- // Instantiate a new Policy object
13
- // policyDefinition is a JSON object of type PolicyDefinition
14
- const policy: Policy = new Policy(policyDefinition);
15
-
16
- // Get list of all available permit types (ID and name)
17
- const permitTypes: Map<string, string> = policy.getPermitTypes();
18
-
19
- // Get list of all available commodities (ID and name)
20
- const commodities: Map<string, string> = policy.getCommodities();
21
-
22
- // Get list of all available power unit types
23
- const powerUnits: Map<string, string> = policy.getPowerUnitTypes();
24
-
25
- // Get list of all available trailer types
26
- const trailers: Map<string, string> = policy.getTrailerTypes();
27
-
28
- // Get list of all valid commodities for a given permit type
29
- const commodities: Map<string, string> = policy.getCommodities(permitTypeId);
30
-
31
- // Get list of all vehicle types valid to be added to a configuration,
32
- // by permit type and commodity. Requires supplying the vehicles already
33
- // added to the configuration, or empty array if starting from scratch
34
- const allowableVehicles: Map<string, string> = policy.getNextPermittableVehicles(
35
- permitTypeId,
36
- commodityId,
37
- currentConfiguration);
38
-
39
- // Validate a permit application against policy
40
- // permitApplication is a JSON object of type PermitApplication
41
- // A PermitApplication is the standard permitData object wrapped
42
- // in an object with a permitType key. For example:
43
- // {
44
- // permitType: 'TROS',
45
- // permitData: { ... }
46
- // }
47
- // Note this is an async call due to the reliance on json-rules-engine
48
- const results: ValidationResults = await policy.validate(permitApplication);
49
- ```
50
-
1
+ A JSON-based rules engine to validate onRouteBC permit applications against commercial vehicle policy.
2
+
3
+ ## Synopsis
4
+ ```orbc-policy-engine``` is a library designed to compare a commercial vehicle permit application against policy expressed in JSON format, and return a list of policy violations as well as other informational policy messages related to the permit.
5
+
6
+ ```orbc-policy-engine``` makes use of https://github.com/CacheControl/json-rules-engine for rules engine functionality. Complex rules are modeled by extending the core ```json-rules-engine``` operators and other capabilities.
7
+
8
+ ## Usage
9
+ ```js
10
+ import Policy from 'orbc-policy-engine';
11
+
12
+ // Instantiate a new Policy object
13
+ // policyDefinition is a JSON object of type PolicyDefinition
14
+ const policy: Policy = new Policy(policyDefinition);
15
+
16
+ // Get list of all available permit types (ID and name)
17
+ const permitTypes: Map<string, string> = policy.getPermitTypes();
18
+
19
+ // Get list of all available commodities (ID and name)
20
+ const commodities: Map<string, string> = policy.getCommodities();
21
+
22
+ // Get list of all available power unit types
23
+ const powerUnits: Map<string, string> = policy.getPowerUnitTypes();
24
+
25
+ // Get list of all available trailer types
26
+ const trailers: Map<string, string> = policy.getTrailerTypes();
27
+
28
+ // Get list of all valid commodities for a given permit type
29
+ const commodities: Map<string, string> = policy.getCommodities(permitTypeId);
30
+
31
+ // Get list of all vehicle types valid to be added to a configuration,
32
+ // by permit type and commodity. Requires supplying the vehicles already
33
+ // added to the configuration, or empty array if starting from scratch
34
+ const allowableVehicles: Map<string, string> = policy.getNextPermittableVehicles(
35
+ permitTypeId,
36
+ commodityId,
37
+ currentConfiguration);
38
+
39
+ // Validate a permit application against policy
40
+ // permitApplication is a JSON object of type PermitApplication
41
+ // A PermitApplication is the standard permitData object wrapped
42
+ // in an object with a permitType key. For example:
43
+ // {
44
+ // permitType: 'TROS',
45
+ // permitData: { ... }
46
+ // }
47
+ // Note this is an async call due to the reliance on json-rules-engine
48
+ const results: ValidationResults = await policy.validate(permitApplication);
49
+ ```
50
+
@@ -12,5 +12,5 @@ export declare enum PermitAppInfo {
12
12
  PermitDuration = "$.permitDuration",
13
13
  PowerUnitType = "$.vehicleDetails.vehicleSubType",
14
14
  TrailerList = "$.vehicleConfiguration.trailers",
15
- Commodity = "$.permittedCommodity"
15
+ Commodity = "$.permittedCommodity.commodityType"
16
16
  }
@@ -16,5 +16,5 @@ var PermitAppInfo;
16
16
  PermitAppInfo["PermitDuration"] = "$.permitDuration";
17
17
  PermitAppInfo["PowerUnitType"] = "$.vehicleDetails.vehicleSubType";
18
18
  PermitAppInfo["TrailerList"] = "$.vehicleConfiguration.trailers";
19
- PermitAppInfo["Commodity"] = "$.permittedCommodity";
19
+ PermitAppInfo["Commodity"] = "$.permittedCommodity.commodityType";
20
20
  })(PermitAppInfo || (exports.PermitAppInfo = PermitAppInfo = {}));
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.addRuntimeFacts = void 0;
6
+ exports.addRuntimeFacts = addRuntimeFacts;
7
7
  const dayjs_1 = __importDefault(require("dayjs"));
8
8
  const enum_1 = require("onroute-policy-engine/enum");
9
9
  /**
@@ -75,4 +75,3 @@ function addRuntimeFacts(engine, policy) {
75
75
  return months * params.cost;
76
76
  });
77
77
  }
78
- exports.addRuntimeFacts = addRuntimeFacts;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getIdFromName = exports.intersectIdMaps = exports.extractIdentifiedObjects = void 0;
3
+ exports.extractIdentifiedObjects = extractIdentifiedObjects;
4
+ exports.intersectIdMaps = intersectIdMaps;
5
+ exports.getIdFromName = getIdFromName;
4
6
  /**
5
7
  * Extracts a map containing just the ID and name of each of the supplied
6
8
  * identified objects.
@@ -19,7 +21,6 @@ function extractIdentifiedObjects(objects, filter) {
19
21
  });
20
22
  return objectMap;
21
23
  }
22
- exports.extractIdentifiedObjects = extractIdentifiedObjects;
23
24
  /**
24
25
  * Intersects two maps containing string id and string description to
25
26
  * return a new map containing those entries common to both.
@@ -41,7 +42,6 @@ function intersectIdMaps(first, second) {
41
42
  }
42
43
  return combinedMap;
43
44
  }
44
- exports.intersectIdMaps = intersectIdMaps;
45
45
  function getIdFromName(list, name) {
46
46
  let id = null;
47
47
  const identifiedObject = list.find((i) => i.name == name);
@@ -50,4 +50,3 @@ function getIdFromName(list, name) {
50
50
  }
51
51
  return id;
52
52
  }
53
- exports.getIdFromName = getIdFromName;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRulesEngines = void 0;
3
+ exports.getRulesEngines = getRulesEngines;
4
4
  const json_rules_engine_1 = require("json-rules-engine");
5
5
  const custom_operators_1 = require("../rule-operator/custom-operators");
6
6
  const enum_1 = require("onroute-policy-engine/enum");
@@ -74,4 +74,3 @@ function getRulesEngines(policy) {
74
74
  });
75
75
  return engineMap;
76
76
  }
77
- exports.getRulesEngines = getRulesEngines;
@@ -90,7 +90,7 @@ class Policy {
90
90
  }
91
91
  }
92
92
  return false;
93
- }), permitType.allowedCommodities);
93
+ }));
94
94
  // TODO when implementing overweight. Stub for now.
95
95
  const commoditiesForOW = new Map();
96
96
  if (permitType.sizeDimensionRequired &&
@@ -5,7 +5,7 @@ export type PermitType = IdentifiedObject & {
5
5
  weightDimensionRequired: boolean;
6
6
  sizeDimensionRequired: boolean;
7
7
  commodityRequired: boolean;
8
- allowedVehicles: Array<string>;
8
+ allowedVehicles?: Array<string>;
9
9
  allowedCommodities?: Array<string>;
10
10
  rules?: Array<RuleProperties>;
11
11
  costRules?: Array<CostRule>;
package/package.json CHANGED
@@ -1,76 +1,77 @@
1
- {
2
- "name": "onroute-policy-engine",
3
- "version": "0.2.0",
4
- "description": "Policy Engine library for commercial vehicle permitting",
5
- "main": "dist/index.js",
6
- "exports": {
7
- ".": "./dist/index.js",
8
- "./types": "./dist/types/index.js",
9
- "./enum": "./dist/enum/index.js"
10
- },
11
- "types": "dist/index.d.ts",
12
- "private": false,
13
- "scripts": {
14
- "clean": "rimraf dist && rimraf -g *.tgz",
15
- "test": "jest",
16
- "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
17
- "format": "prettier --write \"src/**/*.ts\"",
18
- "build": "tsc",
19
- "clean-build": "rimraf dist && rimraf -g *.tgz && tsc"
20
- },
21
- "repository": {
22
- "type": "git",
23
- "url": "git+https://github.com/bcgov/onroutebc.git"
24
- },
25
- "author": "John Fletcher",
26
- "license": "Apache-2.0",
27
- "homepage": "https://github.com/bcgov/onroutebc#readme",
28
- "devDependencies": {
29
- "@types/jest": "^29.5.12",
30
- "@typescript-eslint/eslint-plugin": "^7.5.0",
31
- "csv": "^6.3.10",
32
- "eslint": "^8.57.0",
33
- "eslint-config-prettier": "^9.1.0",
34
- "jest": "^29.7.0",
35
- "prettier": "^3.2.5",
36
- "rimraf": "^5.0.7",
37
- "ts-jest": "^29.1.2",
38
- "typescript": "^5.4.3"
39
- },
40
- "dependencies": {
41
- "dayjs": "^1.11.10",
42
- "json-rules-engine": "^6.5.0"
43
- },
44
- "jest": {
45
- "moduleFileExtensions": [
46
- "js",
47
- "json",
48
- "ts"
49
- ],
50
- "rootDir": ".",
51
- "roots": [
52
- "<rootDir>/src"
53
- ],
54
- "moduleNameMapper": {
55
- "^src/(.*)$": "<rootDir>/src/$1",
56
- "^test/(.*)$": "<rootDir>/test/$1"
57
- },
58
- "testRegex": ".*\\.spec\\.ts$",
59
- "transform": {
60
- "^.+\\.ts$": "ts-jest"
61
- },
62
- "collectCoverage": true,
63
- "collectCoverageFrom": [
64
- "**/*.js"
65
- ],
66
- "coverageDirectory": "./coverage",
67
- "coveragePathIgnorePatterns": [
68
- "/node_modules/",
69
- "/src/_test/",
70
- ".enum.ts",
71
- ".interface.ts",
72
- "index.ts"
73
- ],
74
- "testEnvironment": "node"
75
- }
76
- }
1
+ {
2
+ "name": "onroute-policy-engine",
3
+ "description": "Policy Engine library for commercial vehicle permitting",
4
+ "main": "dist/index.js",
5
+ "exports": {
6
+ ".": "./dist/index.js",
7
+ "./types": "./dist/types/index.js",
8
+ "./enum": "./dist/enum/index.js"
9
+ },
10
+ "types": "dist/index.d.ts",
11
+ "private": false,
12
+ "scripts": {
13
+ "clean": "rimraf dist && rimraf -g *.tgz",
14
+ "test": "jest",
15
+ "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
16
+ "format": "prettier --write \"src/**/*.ts\"",
17
+ "build": "tsc",
18
+ "clean-build": "rimraf dist && rimraf -g *.tgz && tsc"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/bcgov/onroutebc-policy-engine.git"
23
+ },
24
+ "author": "John Fletcher",
25
+ "license": "Apache-2.0",
26
+ "homepage": "https://github.com/bcgov/onroutebc-policy-engine#readme",
27
+ "devDependencies": {
28
+ "@iwsio/json-csv-core": "^1.1.7",
29
+ "@types/jest": "^29.5.12",
30
+ "@typescript-eslint/eslint-plugin": "^7.5.0",
31
+ "csv": "^6.3.10",
32
+ "eslint": "^8.57.0",
33
+ "eslint-config-prettier": "^9.1.0",
34
+ "jest": "^29.7.0",
35
+ "prettier": "^3.2.5",
36
+ "rimraf": "^5.0.7",
37
+ "ts-jest": "^29.1.2",
38
+ "typescript": "^5.4.3"
39
+ },
40
+ "dependencies": {
41
+ "dayjs": "^1.11.10",
42
+ "json-rules-engine": "^6.5.0"
43
+ },
44
+ "jest": {
45
+ "moduleFileExtensions": [
46
+ "js",
47
+ "json",
48
+ "ts"
49
+ ],
50
+ "rootDir": ".",
51
+ "roots": [
52
+ "<rootDir>/src"
53
+ ],
54
+ "moduleNameMapper": {
55
+ "^src/(.*)$": "<rootDir>/src/$1",
56
+ "^test/(.*)$": "<rootDir>/test/$1"
57
+ },
58
+ "testRegex": ".*\\.spec\\.ts$",
59
+ "transform": {
60
+ "^.+\\.ts$": "ts-jest"
61
+ },
62
+ "collectCoverage": true,
63
+ "collectCoverageFrom": [
64
+ "**/*.js"
65
+ ],
66
+ "coverageDirectory": "./coverage",
67
+ "coveragePathIgnorePatterns": [
68
+ "/node_modules/",
69
+ "/src/_test/",
70
+ ".enum.ts",
71
+ ".interface.ts",
72
+ "index.ts"
73
+ ],
74
+ "testEnvironment": "node"
75
+ },
76
+ "version": "v0.2.1"
77
+ }