@legalplace/lplogic 2.0.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/.eslintrc +52 -0
- package/.gitlab-ci.yml +28 -0
- package/.vscode/settings.json +23 -0
- package/.vscode/tasks.json +24 -0
- package/README.md +149 -0
- package/dist/LpLogic.d.ts +3 -0
- package/dist/LpLogic.js +102 -0
- package/dist/Parser.d.ts +12 -0
- package/dist/Parser.js +90 -0
- package/dist/definitions/model-v1-schema.d.ts +152 -0
- package/dist/definitions/model-v1-schema.js +2 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +9 -0
- package/dist/schemas/condition-v1-schema.d.ts +45 -0
- package/dist/schemas/condition-v1-schema.js +67 -0
- package/dist/schemas/model-v1-schema.d.ts +510 -0
- package/dist/schemas/model-v1-schema.js +543 -0
- package/jest.config.js +13 -0
- package/package.json +37 -0
- package/tests/LpLogic.test.ts +90 -0
- package/tests/Parser.test.ts +40 -0
- package/tests/References.test.ts +26 -0
- package/tests/misc/expected-model-v3.json +19891 -0
- package/tests/misc/refs-model-v3.json +642 -0
- package/tests/misc/unparsed-model-v3.json +1 -0
- package/tsconfig.json +26 -0
- package/yarn.lock +5050 -0
package/.eslintrc
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"browser": true,
|
|
4
|
+
"commonjs": true,
|
|
5
|
+
"es6": true,
|
|
6
|
+
"jest": true,
|
|
7
|
+
"node": true
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
"extends": [
|
|
11
|
+
"airbnb-base",
|
|
12
|
+
"plugin:prettier/recommended"
|
|
13
|
+
],
|
|
14
|
+
|
|
15
|
+
"parser": "@typescript-eslint/parser",
|
|
16
|
+
"parserOptions": {
|
|
17
|
+
"project": "./tsconfig.json"
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
"plugins": [
|
|
21
|
+
"prettier", "@typescript-eslint"
|
|
22
|
+
],
|
|
23
|
+
|
|
24
|
+
"rules": {
|
|
25
|
+
"prettier/prettier": ["error"],
|
|
26
|
+
"no-unused-vars": "off",
|
|
27
|
+
"@typescript-eslint/no-unused-vars": ["error", {
|
|
28
|
+
"vars": "all",
|
|
29
|
+
"args": "after-used",
|
|
30
|
+
"ignoreRestSiblings": false
|
|
31
|
+
}],
|
|
32
|
+
"import/no-extraneous-dependencies": ["error", {
|
|
33
|
+
"devDependencies": ["**/*.test.ts", "**/*.spec.ts"]
|
|
34
|
+
}],
|
|
35
|
+
"no-continue": 0,
|
|
36
|
+
"class-methods-use-this": 0,
|
|
37
|
+
"no-underscore-dangle": 0,
|
|
38
|
+
"import/prefer-default-export": "warn",
|
|
39
|
+
"camelcase": "error",
|
|
40
|
+
"no-undef": 0,
|
|
41
|
+
"no-dupe-class-members": "off"
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
"settings": {
|
|
46
|
+
"import/resolver": {
|
|
47
|
+
"node": {
|
|
48
|
+
"extensions": [".js", ".jsx", ".ts", ".tsx"]
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
package/.gitlab-ci.yml
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
image: node:11-alpine
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
stages:
|
|
5
|
+
- deploy
|
|
6
|
+
|
|
7
|
+
before_script:
|
|
8
|
+
- export PATH=$PATH:./node_modules/.bin/
|
|
9
|
+
|
|
10
|
+
variables:
|
|
11
|
+
DOCKER_DRIVER: overlay2
|
|
12
|
+
|
|
13
|
+
publish:
|
|
14
|
+
image: node:11-alpine
|
|
15
|
+
stage: deploy
|
|
16
|
+
except:
|
|
17
|
+
variables:
|
|
18
|
+
- $CI_COMMIT_MESSAGE =~ /skip-publish/
|
|
19
|
+
script:
|
|
20
|
+
- echo -e "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
|
|
21
|
+
- yarn install
|
|
22
|
+
- yarn build
|
|
23
|
+
- npm publish
|
|
24
|
+
- echo "PUBLISHED SUCCESSFULLY"
|
|
25
|
+
environment:
|
|
26
|
+
name: development
|
|
27
|
+
only:
|
|
28
|
+
- master
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"eslint.enable": true,
|
|
3
|
+
"editor.tabSize": 2,
|
|
4
|
+
"eslint.validate": [
|
|
5
|
+
"javascript",
|
|
6
|
+
{
|
|
7
|
+
"autoFix": true,
|
|
8
|
+
"language": "typescript"
|
|
9
|
+
}
|
|
10
|
+
],
|
|
11
|
+
"eslint.options": {
|
|
12
|
+
"extensions": [".ts", ".js"]
|
|
13
|
+
},
|
|
14
|
+
"files.autoSave": "onFocusChange",
|
|
15
|
+
"editor.formatOnSave": false,
|
|
16
|
+
"editor.formatOnType": true,
|
|
17
|
+
"prettier.singleQuote": true,
|
|
18
|
+
"eslint.packageManager": "yarn",
|
|
19
|
+
"eslint.quiet": true,
|
|
20
|
+
"editor.codeActionsOnSave": {
|
|
21
|
+
"source.fixAll.eslint": true
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
|
3
|
+
// for the documentation about the tasks.json format
|
|
4
|
+
"version": "2.0.0",
|
|
5
|
+
"tasks": [
|
|
6
|
+
{
|
|
7
|
+
"type": "npm",
|
|
8
|
+
"script": "lint",
|
|
9
|
+
"problemMatcher": [
|
|
10
|
+
"$eslint-stylish",
|
|
11
|
+
"$tsc"
|
|
12
|
+
]
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"type": "typescript",
|
|
16
|
+
"tsconfig": "tsconfig.json",
|
|
17
|
+
"option": "watch",
|
|
18
|
+
"problemMatcher": [
|
|
19
|
+
"$tsc-watch"
|
|
20
|
+
],
|
|
21
|
+
"group": "build"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
package/README.md
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# LpLogic
|
|
2
|
+
|
|
3
|
+
LpLogic
|
|
4
|
+
|
|
5
|
+
# Setup
|
|
6
|
+
```
|
|
7
|
+
npm install --save git+ssh://git@git.legalplace.eu:legalplace/lplogic.git
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
# Libraries
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## LpLogic
|
|
14
|
+
An extension of JsonLogic supporting LegalPlace's conditions operators:
|
|
15
|
+
* selected : Returns true only if the tested input is `true` or an array containing only `true` value
|
|
16
|
+
* not-selected : Returns true only if the tested input is `false` or an array containing only `false` value
|
|
17
|
+
* has-one : Returns true only if the tested input is an array with a length === 1
|
|
18
|
+
* at-least-one : Returns true only if the tested input is an array containing at least one value as `true`
|
|
19
|
+
* has-many : Returns true only if the tested input is an array with a length > 1
|
|
20
|
+
* contains : Returns true only if the input is equal to the conditon's value input or the input is an array with all its values equal to the conditon's value
|
|
21
|
+
* does-not-contain : Returns true only if the input is not equal to the conditon's value or the input is an array with all its values not equal to the conditon's value
|
|
22
|
+
|
|
23
|
+
### Usage
|
|
24
|
+
```javascript
|
|
25
|
+
import LpLogic from "lplogic"
|
|
26
|
+
|
|
27
|
+
// Returns true
|
|
28
|
+
LpLogic({"selected":[{"var":"o.1"}]}, {"o":{"1":true}})
|
|
29
|
+
LpLogic({"selected":[{"var":"o.1"}]}, {"o":{"1":[true, true]}})
|
|
30
|
+
|
|
31
|
+
// Returns false
|
|
32
|
+
LpLogic({"selected":[{"var":"o.1"}]}, {"o":{"1":false}})
|
|
33
|
+
LpLogic({"selected":[{"var":"o.1"}]}, {"o":{"1":[true, false]}})
|
|
34
|
+
|
|
35
|
+
// Returns true
|
|
36
|
+
LpLogic({"not-selected":[{"var":"o.1"}]}, {"o":{"1":false}})
|
|
37
|
+
LpLogic({"not-selected":[{"var":"o.1"}]}, {"o":{"1":[false, false]}})
|
|
38
|
+
|
|
39
|
+
// Returns false
|
|
40
|
+
LpLogic({"not-selected":[{"var":"o.1"}]}, {"o":{"1":true}})
|
|
41
|
+
LpLogic({"not-selected":[{"var":"o.1"}]}, {"o":{"1":[true, false]}})
|
|
42
|
+
|
|
43
|
+
// Returns true
|
|
44
|
+
LpLogic({"has-one":[{"var":"o.1"}]}, {"o":{"1":[true]}})
|
|
45
|
+
|
|
46
|
+
// Returns false
|
|
47
|
+
LpLogic({"has-one":[{"var":"o.1"}]}, {"o":{"1":[true, true]}})
|
|
48
|
+
|
|
49
|
+
// Returns true
|
|
50
|
+
LpLogic({"has-many":[{"var":"o.1"}]}, {"o":{"1":[true, true]}})
|
|
51
|
+
|
|
52
|
+
// Returns false
|
|
53
|
+
LpLogic({"has-many":[{"var":"o.1"}]}, {"o":{"1":[true]}})
|
|
54
|
+
|
|
55
|
+
// Returns true
|
|
56
|
+
LpLogic({"at-least-one":[{"var":"o.1"}]}, {"o":{"1":[false, false, true]}})
|
|
57
|
+
|
|
58
|
+
// Returns false
|
|
59
|
+
LpLogic({"at-least-one":[{"var":"o.1"}]}, {"o":{"1":[false, false, false]}})
|
|
60
|
+
|
|
61
|
+
// Returns true
|
|
62
|
+
LpLogic({"contains":[{"var":"v.1"}, "Hello"]}, {"v":{"1":"Hello"}})
|
|
63
|
+
LpLogic({"contains":[{"var":"v.1"}, "Hello"]}, {"v":{"1":["Hello","Hello"]}})
|
|
64
|
+
|
|
65
|
+
// Returns false
|
|
66
|
+
LpLogic({"contains":[{"var":"v.1"}, "Hello"]}, {"v":{"1":"Bye"}})
|
|
67
|
+
LpLogic({"contains":[{"var":"v.1"}, "Hello"]}, {"v":{"1":["Hello","Bye"]}})
|
|
68
|
+
|
|
69
|
+
// Returns true
|
|
70
|
+
LpLogic({"does-not-contain":[{"var":"v.1"}, "Hello"]}, {"v":{"1":"Bye"}})
|
|
71
|
+
LpLogic({"does-not-contain":[{"var":"v.1"}, "Hello"]}, {"v":{"1":["Bye","Bye"]}})
|
|
72
|
+
|
|
73
|
+
// Returns false
|
|
74
|
+
LpLogic({"does-not-contain":[{"var":"v.1"}, "Hello"]}, {"v":{"1":"Hello"}})
|
|
75
|
+
LpLogic({"does-not-contain":[{"var":"v.1"}, "Hello"]}, {"v":{"1":["Hello","Bye"]}})
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
## Parser
|
|
81
|
+
Parsing ConditionV1 objects to LpLogic object
|
|
82
|
+
|
|
83
|
+
### Usage
|
|
84
|
+
```js
|
|
85
|
+
import { Parser, References } from "lplogic"
|
|
86
|
+
|
|
87
|
+
let model = {
|
|
88
|
+
documents: {
|
|
89
|
+
"main": {
|
|
90
|
+
sections: [{
|
|
91
|
+
"id": 1,
|
|
92
|
+
"label": "It's 3 am",
|
|
93
|
+
"options": [1,2]
|
|
94
|
+
}]
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
options: {
|
|
98
|
+
"1": {
|
|
99
|
+
meta: {
|
|
100
|
+
id: 1,
|
|
101
|
+
type: "checkbox",
|
|
102
|
+
label: "Check me to see Option 2",
|
|
103
|
+
conditional: false
|
|
104
|
+
},
|
|
105
|
+
children:[],
|
|
106
|
+
variables: []
|
|
107
|
+
},
|
|
108
|
+
"2": {
|
|
109
|
+
meta: {
|
|
110
|
+
id: 2,
|
|
111
|
+
type: "checkbox",
|
|
112
|
+
label: "Hey ! it's option 2",
|
|
113
|
+
conditional: true,
|
|
114
|
+
compiledConditions: [{
|
|
115
|
+
c: "selected",
|
|
116
|
+
o: 1
|
|
117
|
+
}]
|
|
118
|
+
},
|
|
119
|
+
children:[],
|
|
120
|
+
variables: []
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
},
|
|
124
|
+
variables: {}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Setting References before starting to parse
|
|
128
|
+
let sections = model.documents.main.sections
|
|
129
|
+
let options = model.options
|
|
130
|
+
let variables = model.variables
|
|
131
|
+
References.setRefs(sections, options, variables);
|
|
132
|
+
|
|
133
|
+
// Parsing conditions on Option 2
|
|
134
|
+
let conditions = new Parser( options["2"].meta.compiledConditions ).getLogic()
|
|
135
|
+
```
|
|
136
|
+
In this example, the variable `conditions` should be equal to
|
|
137
|
+
```json
|
|
138
|
+
{"selected":[{"var":"o.1"}]}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
# MISC
|
|
142
|
+
## Running tests
|
|
143
|
+
```
|
|
144
|
+
npm test
|
|
145
|
+
```
|
|
146
|
+
### Building
|
|
147
|
+
```
|
|
148
|
+
npm run build
|
|
149
|
+
```
|
package/dist/LpLogic.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var json_logic_js_1 = __importDefault(require("@legalplace/json-logic-js"));
|
|
7
|
+
json_logic_js_1.default.add_operation("=", function (value, comparator) {
|
|
8
|
+
if (!Array.isArray(value)) {
|
|
9
|
+
return value === comparator;
|
|
10
|
+
}
|
|
11
|
+
var filter = value.filter(function (_value) { return _value === comparator; });
|
|
12
|
+
return value.length === filter.length;
|
|
13
|
+
});
|
|
14
|
+
json_logic_js_1.default.add_operation("<>", function (value, comparator) {
|
|
15
|
+
if (!Array.isArray(value)) {
|
|
16
|
+
return value !== comparator;
|
|
17
|
+
}
|
|
18
|
+
var filter = value.filter(function (_value) { return _value !== comparator; });
|
|
19
|
+
return value.length === filter.length;
|
|
20
|
+
});
|
|
21
|
+
json_logic_js_1.default.add_operation("==", function (value, comparator) {
|
|
22
|
+
if (!Array.isArray(value)) {
|
|
23
|
+
return value === comparator;
|
|
24
|
+
}
|
|
25
|
+
var filter = value.filter(function (_value) { return _value === comparator; });
|
|
26
|
+
return value.length === filter.length;
|
|
27
|
+
});
|
|
28
|
+
json_logic_js_1.default.add_operation(">=", function (value, c) {
|
|
29
|
+
var comparator = typeof c === "number" ? c : parseFloat(c);
|
|
30
|
+
if (!Array.isArray(value)) {
|
|
31
|
+
return value >= comparator;
|
|
32
|
+
}
|
|
33
|
+
var filter = value.filter(function (_value) { return _value >= comparator; });
|
|
34
|
+
return value.length === filter.length;
|
|
35
|
+
});
|
|
36
|
+
json_logic_js_1.default.add_operation("<=", function (value, c) {
|
|
37
|
+
var comparator = typeof c === "number" ? c : parseFloat(c);
|
|
38
|
+
if (!Array.isArray(value)) {
|
|
39
|
+
return value >= comparator;
|
|
40
|
+
}
|
|
41
|
+
var filter = value.filter(function (_value) { return _value <= comparator; });
|
|
42
|
+
return value.length === filter.length;
|
|
43
|
+
});
|
|
44
|
+
json_logic_js_1.default.add_operation(">", function (value, c) {
|
|
45
|
+
var comparator = typeof c === "number" ? c : parseFloat(c);
|
|
46
|
+
if (!Array.isArray(value)) {
|
|
47
|
+
return value > comparator;
|
|
48
|
+
}
|
|
49
|
+
var filter = value.filter(function (_value) { return _value > comparator; });
|
|
50
|
+
return value.length === filter.length;
|
|
51
|
+
});
|
|
52
|
+
json_logic_js_1.default.add_operation("<", function (value, c) {
|
|
53
|
+
var comparator = typeof c === "number" ? c : parseFloat(c);
|
|
54
|
+
if (!Array.isArray(value)) {
|
|
55
|
+
return value < comparator;
|
|
56
|
+
}
|
|
57
|
+
var filter = value.filter(function (_value) { return _value < comparator; });
|
|
58
|
+
return value.length === filter.length;
|
|
59
|
+
});
|
|
60
|
+
json_logic_js_1.default.add_operation("selected", function (value) {
|
|
61
|
+
if (!Array.isArray(value)) {
|
|
62
|
+
return value === true;
|
|
63
|
+
}
|
|
64
|
+
var filter = value.filter(function (_value) { return _value === true; });
|
|
65
|
+
return value.length === filter.length;
|
|
66
|
+
});
|
|
67
|
+
json_logic_js_1.default.add_operation("not-selected", function (value) {
|
|
68
|
+
if (!Array.isArray(value)) {
|
|
69
|
+
return value !== true;
|
|
70
|
+
}
|
|
71
|
+
var filter = value.filter(function (_value) { return _value !== true; });
|
|
72
|
+
return value.length === filter.length;
|
|
73
|
+
});
|
|
74
|
+
json_logic_js_1.default.add_operation("has-one", function (value) {
|
|
75
|
+
if (!Array.isArray(value))
|
|
76
|
+
return true;
|
|
77
|
+
return value.length === 1;
|
|
78
|
+
});
|
|
79
|
+
json_logic_js_1.default.add_operation("at-least-one", function (value) {
|
|
80
|
+
if (!Array.isArray(value))
|
|
81
|
+
return false;
|
|
82
|
+
return value.includes(true);
|
|
83
|
+
});
|
|
84
|
+
json_logic_js_1.default.add_operation("has-many", function (value) {
|
|
85
|
+
if (!Array.isArray(value))
|
|
86
|
+
return false;
|
|
87
|
+
return value.length > 1;
|
|
88
|
+
});
|
|
89
|
+
json_logic_js_1.default.add_operation("contains", function (value, comparator) {
|
|
90
|
+
if (!Array.isArray(value))
|
|
91
|
+
return value === comparator;
|
|
92
|
+
var filter = value.filter(function (_value) { return _value === comparator; });
|
|
93
|
+
return value.length === filter.length;
|
|
94
|
+
});
|
|
95
|
+
json_logic_js_1.default.add_operation("does-not-contain", function (value, comparator) {
|
|
96
|
+
if (!Array.isArray(value))
|
|
97
|
+
return value !== comparator;
|
|
98
|
+
var filter = value.filter(function (_value) { return _value !== comparator; });
|
|
99
|
+
return value.length === filter.length;
|
|
100
|
+
});
|
|
101
|
+
var LpLogic = json_logic_js_1.default.apply;
|
|
102
|
+
exports.default = LpLogic;
|
package/dist/Parser.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ConditionV3 } from "@legalplace/models-v3-types";
|
|
2
|
+
import { CompiledConditionV1, ConditionV1Single } from "./definitions/model-v1-schema";
|
|
3
|
+
declare class Parser {
|
|
4
|
+
id: number | undefined;
|
|
5
|
+
logic: ConditionV3;
|
|
6
|
+
constructor(conditions: CompiledConditionV1, id?: number);
|
|
7
|
+
getLogic(): ConditionV3;
|
|
8
|
+
validateCondition(condition: ConditionV1Single): void;
|
|
9
|
+
convertConditions(conditions: CompiledConditionV1): ConditionV3;
|
|
10
|
+
convertSingleCondition(condition: ConditionV1Single): ConditionV3;
|
|
11
|
+
}
|
|
12
|
+
export default Parser;
|
package/dist/Parser.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var jsonschema_1 = require("jsonschema");
|
|
7
|
+
var condition_v1_schema_1 = __importDefault(require("./schemas/condition-v1-schema"));
|
|
8
|
+
var Parser = (function () {
|
|
9
|
+
function Parser(conditions, id) {
|
|
10
|
+
this.id = id;
|
|
11
|
+
this.logic = this.convertConditions(conditions);
|
|
12
|
+
}
|
|
13
|
+
Parser.prototype.getLogic = function () {
|
|
14
|
+
return this.logic;
|
|
15
|
+
};
|
|
16
|
+
Parser.prototype.validateCondition = function (condition) {
|
|
17
|
+
var result = jsonschema_1.validate(condition, condition_v1_schema_1.default);
|
|
18
|
+
if (result.errors.length > 0) {
|
|
19
|
+
throw new Error(JSON.stringify(condition) + " is not a valid condition");
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
Parser.prototype.convertConditions = function (conditions) {
|
|
23
|
+
var _this = this;
|
|
24
|
+
var operator;
|
|
25
|
+
if (Array.isArray(conditions) && conditions.length === 0)
|
|
26
|
+
return {};
|
|
27
|
+
for (var index = 0; index < conditions.length; index += 1) {
|
|
28
|
+
var value = conditions[index];
|
|
29
|
+
if (typeof value.t === "string" && value.t && index > 0) {
|
|
30
|
+
if (operator === undefined && typeof value.t === "string") {
|
|
31
|
+
operator = value.t;
|
|
32
|
+
}
|
|
33
|
+
else if (value.t !== operator) {
|
|
34
|
+
throw new Error("Conditions object is not valid, " + operator + " is not equal to " + value.t + " at index " + index + " in " + JSON.stringify(conditions));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
var logicConditions = [];
|
|
39
|
+
conditions.forEach(function (value) {
|
|
40
|
+
var currentCondition = {};
|
|
41
|
+
if (typeof value.condition_array === "object") {
|
|
42
|
+
currentCondition = _this.convertConditions(value.condition_array);
|
|
43
|
+
}
|
|
44
|
+
else if (typeof value === "object") {
|
|
45
|
+
currentCondition = _this.convertSingleCondition(value);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
throw new Error("Invalid condition");
|
|
49
|
+
}
|
|
50
|
+
logicConditions.push(currentCondition);
|
|
51
|
+
});
|
|
52
|
+
var logic = {};
|
|
53
|
+
if (operator !== undefined) {
|
|
54
|
+
logic[operator] = logicConditions;
|
|
55
|
+
}
|
|
56
|
+
else if (logicConditions.length === 1) {
|
|
57
|
+
logic = logicConditions[0];
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
throw new Error("Invalid condition " + conditions);
|
|
61
|
+
}
|
|
62
|
+
return logic;
|
|
63
|
+
};
|
|
64
|
+
Parser.prototype.convertSingleCondition = function (condition) {
|
|
65
|
+
this.validateCondition(condition);
|
|
66
|
+
if (condition.c === undefined)
|
|
67
|
+
throw new Error("Invalid condition");
|
|
68
|
+
var operation = condition.c;
|
|
69
|
+
var rule = {};
|
|
70
|
+
var dataReference;
|
|
71
|
+
if (condition.o !== false && condition.o !== undefined) {
|
|
72
|
+
dataReference = {
|
|
73
|
+
var: "o." + condition.o
|
|
74
|
+
};
|
|
75
|
+
rule[operation] = [dataReference];
|
|
76
|
+
}
|
|
77
|
+
else if (condition.v !== false && condition.v !== undefined) {
|
|
78
|
+
dataReference = {
|
|
79
|
+
var: "v." + condition.v
|
|
80
|
+
};
|
|
81
|
+
rule[operation] = [dataReference, condition.value];
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
throw new Error("Invalid condition " + condition);
|
|
85
|
+
}
|
|
86
|
+
return rule;
|
|
87
|
+
};
|
|
88
|
+
return Parser;
|
|
89
|
+
}());
|
|
90
|
+
exports.default = Parser;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
export declare type ConditionV1Single = {
|
|
2
|
+
c?: "selected" | "not-selected" | "has-one" | "at-least-one" | "has-many" | "contains" | "does-not-contain" | "=" | ">" | "<" | "!=" | ">=" | "<=" | "<>";
|
|
3
|
+
o?: false | number | string;
|
|
4
|
+
p?: string | number;
|
|
5
|
+
v?: string | number | false;
|
|
6
|
+
value?: string | number;
|
|
7
|
+
l?: false | (string | number)[];
|
|
8
|
+
m?: boolean;
|
|
9
|
+
t?: "and" | "or";
|
|
10
|
+
};
|
|
11
|
+
export declare type ConditionV1Array = {
|
|
12
|
+
condition_array?: ConditionV1Compose[];
|
|
13
|
+
};
|
|
14
|
+
declare type ConditionV1Compose = ConditionV1Array & ConditionV1Single;
|
|
15
|
+
export declare type CompiledConditionV1 = ConditionV1Compose[];
|
|
16
|
+
export interface ModelV1 {
|
|
17
|
+
contract_name: string;
|
|
18
|
+
sections: SectionV1[];
|
|
19
|
+
params?: {
|
|
20
|
+
sivAttributes?: {
|
|
21
|
+
[k: string]: any;
|
|
22
|
+
};
|
|
23
|
+
hasSivAttributes?: boolean;
|
|
24
|
+
is_two_steps?: boolean;
|
|
25
|
+
proIdnType?: "PRO" | "IND" | "COND";
|
|
26
|
+
disableAutoDefault?: boolean;
|
|
27
|
+
varsExtraction?: VarExtractionV1[];
|
|
28
|
+
disableCompagnon?: boolean;
|
|
29
|
+
fullWidth?: boolean;
|
|
30
|
+
disableDownloadPopup?: boolean;
|
|
31
|
+
disableDownload?: boolean;
|
|
32
|
+
disablePreview?: boolean;
|
|
33
|
+
noAttachements?: boolean;
|
|
34
|
+
isTwoSteps?: boolean;
|
|
35
|
+
};
|
|
36
|
+
options_ids?: (number | string)[];
|
|
37
|
+
variables_id?: {
|
|
38
|
+
[k: string]: any;
|
|
39
|
+
}[];
|
|
40
|
+
pro?: {
|
|
41
|
+
meta?: {
|
|
42
|
+
conditions?: CompiledConditionV1[];
|
|
43
|
+
compiledConditions?: CompiledConditionV1[];
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
[k: string]: any;
|
|
47
|
+
}
|
|
48
|
+
export interface SectionV1 {
|
|
49
|
+
id: string | number;
|
|
50
|
+
label: string;
|
|
51
|
+
options: OptionV1[];
|
|
52
|
+
grantLevel: "admin" | "manager" | "user" | "guest";
|
|
53
|
+
tags: string;
|
|
54
|
+
[k: string]: any;
|
|
55
|
+
}
|
|
56
|
+
export interface OptionV1 {
|
|
57
|
+
meta: {
|
|
58
|
+
[k: string]: any;
|
|
59
|
+
id: string | number;
|
|
60
|
+
label: string;
|
|
61
|
+
fallbackLabel?: string;
|
|
62
|
+
optionStyle?: "" | "half" | "full";
|
|
63
|
+
unvalidMessage?: string;
|
|
64
|
+
termsheetLabel?: string;
|
|
65
|
+
hideTermsheet?: boolean;
|
|
66
|
+
boxType?: "warning" | "error" | "info" | "light";
|
|
67
|
+
boxTitle?: string;
|
|
68
|
+
boxCollapsable?: boolean;
|
|
69
|
+
boxAggregatable?: boolean;
|
|
70
|
+
type: "static" | "radio" | "checkbox" | "hidden" | "brut-text" | "repeated" | "box" | "separator";
|
|
71
|
+
multiple?: boolean;
|
|
72
|
+
output?: string;
|
|
73
|
+
outputRender?: string;
|
|
74
|
+
default?: string | number;
|
|
75
|
+
parentMultiple?: boolean;
|
|
76
|
+
step_two_only?: boolean;
|
|
77
|
+
conditions?: CompiledConditionV1[];
|
|
78
|
+
compiledConditions?: CompiledConditionV1[];
|
|
79
|
+
warning?: string;
|
|
80
|
+
helper?: string;
|
|
81
|
+
multipletext?: string;
|
|
82
|
+
parent_section?: number | string;
|
|
83
|
+
multipleIncrtText?: string;
|
|
84
|
+
content?: string;
|
|
85
|
+
repeatOption?: number | string;
|
|
86
|
+
multipleIncrt?: number | string;
|
|
87
|
+
zonetendue?: boolean;
|
|
88
|
+
mandatory?: boolean;
|
|
89
|
+
};
|
|
90
|
+
children: OptionV1[];
|
|
91
|
+
variables: VariableV1[];
|
|
92
|
+
[k: string]: any;
|
|
93
|
+
}
|
|
94
|
+
export interface VariableV1 {
|
|
95
|
+
id: number;
|
|
96
|
+
grantLevel?: "ADMIN" | "MANAGER" | "USER" | "GUEST";
|
|
97
|
+
label: string;
|
|
98
|
+
termsheetLabel?: string;
|
|
99
|
+
type: "text" | "date" | "list" | "textarea" | "number" | "eval" | "advancedmask" | "hour" | "email" | "mask";
|
|
100
|
+
value?: string | any[];
|
|
101
|
+
suffix?: string;
|
|
102
|
+
parentMultiple?: boolean;
|
|
103
|
+
phsize?: string | number | null;
|
|
104
|
+
warning?: string;
|
|
105
|
+
helper?: string;
|
|
106
|
+
list?: any[];
|
|
107
|
+
autocomplete?: string;
|
|
108
|
+
advancedmask?: string;
|
|
109
|
+
maskph?: string;
|
|
110
|
+
mask?: string;
|
|
111
|
+
prefillings?: PrefillingV1[];
|
|
112
|
+
placeholder?: string;
|
|
113
|
+
eval_decimal?: number | string;
|
|
114
|
+
evaluation?: string;
|
|
115
|
+
round?: 0 | 1 | 2 | "0" | "1" | "2";
|
|
116
|
+
longInput?: boolean;
|
|
117
|
+
textarea_size?: "l" | "m" | "p" | "s";
|
|
118
|
+
textarea_height?: number | string;
|
|
119
|
+
mandatory?: boolean;
|
|
120
|
+
step_two_only?: boolean;
|
|
121
|
+
conditional?: boolean;
|
|
122
|
+
compiledConditions?: CompiledConditionV1 | false;
|
|
123
|
+
inputSize?: "half" | "full";
|
|
124
|
+
validator?: CompiledConditionV1 | false;
|
|
125
|
+
unvalidMessage?: string;
|
|
126
|
+
hidden?: boolean;
|
|
127
|
+
tags?: string;
|
|
128
|
+
hideTermsheet?: boolean;
|
|
129
|
+
}
|
|
130
|
+
export interface PrefillingV1 {
|
|
131
|
+
text?: string;
|
|
132
|
+
conditions?: CompiledConditionV1[];
|
|
133
|
+
compiledConditions?: CompiledConditionV1[];
|
|
134
|
+
}
|
|
135
|
+
export interface VarExtractionV1 {
|
|
136
|
+
type?: "variable" | "option";
|
|
137
|
+
index?: number | string;
|
|
138
|
+
id?: number | string;
|
|
139
|
+
parent_id?: number | string | boolean;
|
|
140
|
+
extractions?: {
|
|
141
|
+
sendinblue?: {
|
|
142
|
+
[k: string]: any;
|
|
143
|
+
};
|
|
144
|
+
mixpanel?: {
|
|
145
|
+
[k: string]: any;
|
|
146
|
+
};
|
|
147
|
+
slack?: {
|
|
148
|
+
[k: string]: any;
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
export {};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var LpLogic_1 = __importDefault(require("./LpLogic"));
|
|
7
|
+
var Parser_1 = __importDefault(require("./Parser"));
|
|
8
|
+
exports.Parser = Parser_1.default;
|
|
9
|
+
exports.default = LpLogic_1.default;
|