@legalplace/prerenderx 2.5.1 → 2.5.3
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/dist/libs/DataPopulator.js +2 -21
- package/dist/libs/OutputParser.d.ts +2 -0
- package/dist/libs/OutputParser.js +39 -1
- package/dist/libs/Prerender.js +10 -9
- package/package.json +4 -4
- package/src/libs/DataPopulator.ts +2 -19
- package/src/libs/OutputParser.ts +60 -0
- package/src/libs/Prerender.ts +10 -9
|
@@ -102,7 +102,6 @@ var DataPopulator = (function () {
|
|
|
102
102
|
}
|
|
103
103
|
};
|
|
104
104
|
DataPopulator.prototype.getVariableValues = function (variableId) {
|
|
105
|
-
var conditions = this.variableConditionValue(variableId);
|
|
106
105
|
var value = this.ovc.variables[variableId];
|
|
107
106
|
if (this.id === undefined || this.index === undefined) {
|
|
108
107
|
return value;
|
|
@@ -110,18 +109,9 @@ var DataPopulator = (function () {
|
|
|
110
109
|
var variableRootParent = this.getVariableRootParent(variableId);
|
|
111
110
|
var variableRootRelations = this.references.relations.options[variableRootParent];
|
|
112
111
|
if (variableRootRelations.children.options.includes(this.id) || variableRootRelations.dependants.includes(this.id) || this.id === variableRootParent) {
|
|
113
|
-
if (conditions !== undefined && conditions[this.index] === false)
|
|
114
|
-
return ['fAl$e'];
|
|
115
112
|
return [value[this.index]];
|
|
116
113
|
}
|
|
117
|
-
|
|
118
|
-
if (conditions === undefined)
|
|
119
|
-
return cleanValues;
|
|
120
|
-
return cleanValues.map(function (currentValue, index) {
|
|
121
|
-
if (conditions[index] === false)
|
|
122
|
-
return 'fAl$e';
|
|
123
|
-
return currentValue;
|
|
124
|
-
});
|
|
114
|
+
return this.cleanArrayFromNullValues(__spreadArrays(value));
|
|
125
115
|
};
|
|
126
116
|
DataPopulator.prototype.getVariableRootParent = function (variableId) {
|
|
127
117
|
var variableParents = this.references.relations.variables[variableId].parents;
|
|
@@ -138,7 +128,6 @@ var DataPopulator = (function () {
|
|
|
138
128
|
}
|
|
139
129
|
};
|
|
140
130
|
DataPopulator.prototype.getOptionInputs = function (optionId) {
|
|
141
|
-
var conditions = this.optionConditionValue(optionId);
|
|
142
131
|
var inputs = this.ovc.options[optionId];
|
|
143
132
|
if (this.id === undefined || this.index === undefined) {
|
|
144
133
|
return inputs;
|
|
@@ -146,17 +135,9 @@ var DataPopulator = (function () {
|
|
|
146
135
|
var optionRootParent = this.getOptionRootParent(optionId);
|
|
147
136
|
var optionRootRelations = this.references.relations.options[optionRootParent];
|
|
148
137
|
if (optionRootRelations.children.options.includes(this.id) || optionRootRelations.dependants.includes(this.id) || this.id === optionRootParent) {
|
|
149
|
-
if (conditions !== undefined && conditions[this.index] === false)
|
|
150
|
-
return [false];
|
|
151
138
|
return [inputs[this.index]];
|
|
152
139
|
}
|
|
153
|
-
|
|
154
|
-
return inputs;
|
|
155
|
-
return inputs.map(function (value, index) {
|
|
156
|
-
if (conditions[index] === false)
|
|
157
|
-
return false;
|
|
158
|
-
return value;
|
|
159
|
-
});
|
|
140
|
+
return inputs;
|
|
160
141
|
};
|
|
161
142
|
DataPopulator.prototype.getOptionRootParent = function (optionId) {
|
|
162
143
|
var optionParents = this.references.relations.options[optionId].parents;
|
|
@@ -6,4 +6,6 @@ export declare const getRelatedVariablesValues: getRelatedVarsT;
|
|
|
6
6
|
declare type autonumsType = [string, string, number, string | null][];
|
|
7
7
|
declare type parseOutputT = (output: string, index: number, variables: relVarsValsT, autonums: autonumsType) => string;
|
|
8
8
|
export declare const parseOutputWithVariables: parseOutputT;
|
|
9
|
+
declare type TParseDocumentNameWithVariables = (text: string, ovc: OVC_TYPE, references: Types.ReferencesType, fallback?: string) => string;
|
|
10
|
+
export declare const parseDocumentNameWithVariables: TParseDocumentNameWithVariables;
|
|
9
11
|
export {};
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
3
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
4
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
5
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
6
|
+
r[k] = a[j];
|
|
7
|
+
return r;
|
|
8
|
+
};
|
|
2
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseOutputWithVariables = exports.getRelatedVariablesValues = void 0;
|
|
10
|
+
exports.parseDocumentNameWithVariables = exports.parseOutputWithVariables = exports.getRelatedVariablesValues = void 0;
|
|
4
11
|
exports.getRelatedVariablesValues = function (optionId, index, variables, ovc, references) {
|
|
5
12
|
var variablesValues = {};
|
|
6
13
|
variables.forEach(function (currentVariableId) {
|
|
@@ -49,3 +56,34 @@ exports.parseOutputWithVariables = function (output, index, variables, autonums)
|
|
|
49
56
|
});
|
|
50
57
|
return parsedOutput;
|
|
51
58
|
};
|
|
59
|
+
exports.parseDocumentNameWithVariables = function (text, ovc, references, fallback) {
|
|
60
|
+
var tagsMatch = text.match(/\[var:([0-9]+)\]/gi);
|
|
61
|
+
var variables = [];
|
|
62
|
+
if (tagsMatch !== null) {
|
|
63
|
+
var variablesTags = __spreadArrays(tagsMatch);
|
|
64
|
+
variables = variablesTags.map(function (current) {
|
|
65
|
+
var outputVariableMatch = current.match(/([0-9]+)/);
|
|
66
|
+
if (outputVariableMatch === null)
|
|
67
|
+
return 0;
|
|
68
|
+
return parseInt(outputVariableMatch[0], 10);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
variables = variables.filter(function (c, i) { return variables.indexOf(c) === i; });
|
|
72
|
+
variables = variables.filter(function (c) { return ovc !== undefined || references.variables[c] !== undefined; });
|
|
73
|
+
var variablesValues = {};
|
|
74
|
+
variables.forEach(function (variableId) {
|
|
75
|
+
var _a;
|
|
76
|
+
var value = ((_a = ovc.variables[variableId]) === null || _a === void 0 ? void 0 : _a[0]) || '';
|
|
77
|
+
variablesValues[variableId] = value.toString();
|
|
78
|
+
});
|
|
79
|
+
var parsedText = "" + text;
|
|
80
|
+
variables.forEach(function (variableId) {
|
|
81
|
+
var value = variablesValues[variableId];
|
|
82
|
+
if (value.trim().length === 0 && fallback)
|
|
83
|
+
parsedText = fallback;
|
|
84
|
+
if (parsedText === fallback && fallback)
|
|
85
|
+
return;
|
|
86
|
+
parsedText = parsedText.replace(new RegExp("\\[var:" + variableId + "\\]", 'gi'), value);
|
|
87
|
+
});
|
|
88
|
+
return parsedText;
|
|
89
|
+
};
|
package/dist/libs/Prerender.js
CHANGED
|
@@ -11,6 +11,7 @@ var OvcConverter_1 = __importDefault(require("./OvcConverter"));
|
|
|
11
11
|
var NumAuto_1 = __importDefault(require("./NumAuto"));
|
|
12
12
|
var InputsInitiator_1 = __importDefault(require("./InputsInitiator"));
|
|
13
13
|
var FillPdfForm_1 = __importDefault(require("./FillPdfForm"));
|
|
14
|
+
var OutputParser_1 = require("./OutputParser");
|
|
14
15
|
var Prerender = (function () {
|
|
15
16
|
function Prerender(model, ovc) {
|
|
16
17
|
this.documentsIndex = {};
|
|
@@ -37,21 +38,21 @@ var Prerender = (function () {
|
|
|
37
38
|
};
|
|
38
39
|
Prerender.prototype.generateDocumentNamesHash = function () {
|
|
39
40
|
var _this = this;
|
|
40
|
-
Object.keys(this.model.documents).forEach(function (
|
|
41
|
+
Object.keys(this.model.documents).forEach(function (slug) {
|
|
41
42
|
var _a, _b;
|
|
42
|
-
var document = _this.model.documents[
|
|
43
|
-
var documentParams = _this.model.documents[
|
|
44
|
-
var conditionObject = _this.references.conditions.documents[
|
|
43
|
+
var document = _this.model.documents[slug];
|
|
44
|
+
var documentParams = _this.model.documents[slug].params;
|
|
45
|
+
var conditionObject = _this.references.conditions.documents[slug];
|
|
45
46
|
var condition = conditionObject === undefined ? true : _this.conditions.executeCondition(conditionObject, 0, 0, 'documents');
|
|
46
47
|
if (condition === true) {
|
|
47
48
|
var hash = crypto_1.default
|
|
48
49
|
.createHash('sha1')
|
|
49
|
-
.update(
|
|
50
|
+
.update(slug)
|
|
50
51
|
.digest('hex');
|
|
51
52
|
if (typeof document.pdf === 'object' && typeof document.pdf.id === 'string' && typeof document.pdf.form === 'object') {
|
|
52
53
|
_this.documentsIndex[hash] = {
|
|
53
|
-
name: document.name,
|
|
54
|
-
slug:
|
|
54
|
+
name: OutputParser_1.parseDocumentNameWithVariables(document.name, _this.ovc, _this.references, document.fallbackName),
|
|
55
|
+
slug: slug,
|
|
55
56
|
form: true,
|
|
56
57
|
fdf: {
|
|
57
58
|
id: '',
|
|
@@ -61,8 +62,8 @@ var Prerender = (function () {
|
|
|
61
62
|
}
|
|
62
63
|
else {
|
|
63
64
|
_this.documentsIndex[hash] = {
|
|
64
|
-
name: document.name,
|
|
65
|
-
slug:
|
|
65
|
+
name: OutputParser_1.parseDocumentNameWithVariables(document.name, _this.ovc, _this.references, document.fallbackName),
|
|
66
|
+
slug: slug,
|
|
66
67
|
pdf: ((_a = documentParams === null || documentParams === void 0 ? void 0 : documentParams.formats) === null || _a === void 0 ? void 0 : _a.pdf) === undefined ? true : documentParams.formats.pdf,
|
|
67
68
|
docx: ((_b = documentParams === null || documentParams === void 0 ? void 0 : documentParams.formats) === null || _b === void 0 ? void 0 : _b.docx) === undefined ? true : documentParams.formats.docx
|
|
68
69
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@legalplace/prerenderx",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.3",
|
|
4
4
|
"description": "PrerenderX",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": "https://git.legalplace.eu/legalplace/prerenderx",
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
"build": "tsc"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@legalplace/lplogic": "^2.1.
|
|
18
|
-
"@legalplace/models-v3-types": "^3.
|
|
19
|
-
"@legalplace/referencesparser": "^1.
|
|
17
|
+
"@legalplace/lplogic": "^2.1.6",
|
|
18
|
+
"@legalplace/models-v3-types": "^3.5.1",
|
|
19
|
+
"@legalplace/referencesparser": "^1.6.3",
|
|
20
20
|
"crypto": "^1.0.1",
|
|
21
21
|
"typescript": "3.9.3"
|
|
22
22
|
},
|
|
@@ -160,7 +160,6 @@ class DataPopulator {
|
|
|
160
160
|
* @param variableId Variable's id
|
|
161
161
|
*/
|
|
162
162
|
private getVariableValues(variableId: number): Readonly<(string | number)[]> {
|
|
163
|
-
const conditions = this.variableConditionValue(variableId)
|
|
164
163
|
const value = this.ovc.variables[variableId]
|
|
165
164
|
if (this.id === undefined || this.index === undefined) {
|
|
166
165
|
return value
|
|
@@ -170,19 +169,10 @@ class DataPopulator {
|
|
|
170
169
|
const variableRootParent = this.getVariableRootParent(variableId)
|
|
171
170
|
const variableRootRelations = this.references.relations.options[variableRootParent]
|
|
172
171
|
if (variableRootRelations.children.options.includes(this.id) || variableRootRelations.dependants.includes(this.id) || this.id === variableRootParent) {
|
|
173
|
-
// TODO: Replace fAl$e with a safer solution
|
|
174
|
-
if (conditions !== undefined && conditions[this.index] === false) return ['fAl$e']
|
|
175
172
|
return [value[this.index]]
|
|
176
173
|
}
|
|
177
174
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
if (conditions === undefined) return cleanValues
|
|
181
|
-
|
|
182
|
-
return cleanValues.map((currentValue, index) => {
|
|
183
|
-
if (conditions[index] === false) return 'fAl$e'
|
|
184
|
-
return currentValue
|
|
185
|
-
})
|
|
175
|
+
return this.cleanArrayFromNullValues([...value])
|
|
186
176
|
}
|
|
187
177
|
|
|
188
178
|
/**
|
|
@@ -221,7 +211,6 @@ class DataPopulator {
|
|
|
221
211
|
* @param optionId Option's id
|
|
222
212
|
*/
|
|
223
213
|
private getOptionInputs(optionId: number): Readonly<boolean[]> {
|
|
224
|
-
const conditions = this.optionConditionValue(optionId)
|
|
225
214
|
const inputs = this.ovc.options[optionId]
|
|
226
215
|
if (this.id === undefined || this.index === undefined) {
|
|
227
216
|
return inputs
|
|
@@ -231,16 +220,10 @@ class DataPopulator {
|
|
|
231
220
|
const optionRootParent = this.getOptionRootParent(optionId)
|
|
232
221
|
const optionRootRelations = this.references.relations.options[optionRootParent]
|
|
233
222
|
if (optionRootRelations.children.options.includes(this.id) || optionRootRelations.dependants.includes(this.id) || this.id === optionRootParent) {
|
|
234
|
-
if (conditions !== undefined && conditions[this.index] === false) return [false]
|
|
235
223
|
return [inputs[this.index]]
|
|
236
224
|
}
|
|
237
225
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
return inputs.map((value, index) => {
|
|
241
|
-
if (conditions[index] === false) return false
|
|
242
|
-
return value
|
|
243
|
-
})
|
|
226
|
+
return inputs
|
|
244
227
|
}
|
|
245
228
|
|
|
246
229
|
/**
|
package/src/libs/OutputParser.ts
CHANGED
|
@@ -87,3 +87,63 @@ export const parseOutputWithVariables: parseOutputT = (output, index, variables,
|
|
|
87
87
|
|
|
88
88
|
return parsedOutput
|
|
89
89
|
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Parses document name with variables
|
|
95
|
+
* @param text Document's name
|
|
96
|
+
*/
|
|
97
|
+
type TParseDocumentNameWithVariables = (
|
|
98
|
+
text: string,
|
|
99
|
+
ovc: OVC_TYPE,
|
|
100
|
+
references: Types.ReferencesType,
|
|
101
|
+
fallback?: string
|
|
102
|
+
) => string;
|
|
103
|
+
export const parseDocumentNameWithVariables: TParseDocumentNameWithVariables = (text, ovc, references, fallback) => {
|
|
104
|
+
/**
|
|
105
|
+
* Variables
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
// Extracting list of variables
|
|
109
|
+
const tagsMatch = text.match(/\[var:([0-9]+)\]/gi);
|
|
110
|
+
let variables: number[] = [];
|
|
111
|
+
if (tagsMatch !== null) {
|
|
112
|
+
// Tranforming tags into integer ids
|
|
113
|
+
const variablesTags: string[] = [...tagsMatch];
|
|
114
|
+
variables = variablesTags.map((current) => {
|
|
115
|
+
const outputVariableMatch = current.match(/([0-9]+)/);
|
|
116
|
+
if (outputVariableMatch === null) return 0;
|
|
117
|
+
return parseInt(outputVariableMatch[0], 10);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Removing duplicated variables
|
|
122
|
+
variables = variables.filter((c, i) => variables.indexOf(c) === i);
|
|
123
|
+
|
|
124
|
+
// Making sure all variables exist
|
|
125
|
+
variables = variables.filter(
|
|
126
|
+
(c) => ovc !== undefined || references.variables[c] !== undefined
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
// Getting values
|
|
130
|
+
const variablesValues: Record<string, string> = {};
|
|
131
|
+
variables.forEach((variableId) => {
|
|
132
|
+
const value = ovc.variables[variableId]?.[0] || ''
|
|
133
|
+
variablesValues[variableId] = value.toString();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// Inserting values
|
|
137
|
+
let parsedText = `${text}`;
|
|
138
|
+
variables.forEach((variableId) => {
|
|
139
|
+
const value: string = variablesValues[variableId];
|
|
140
|
+
if (value.trim().length === 0 && fallback) parsedText = fallback;
|
|
141
|
+
if (parsedText === fallback && fallback) return;
|
|
142
|
+
parsedText = parsedText.replace(
|
|
143
|
+
new RegExp(`\\[var:${variableId}\\]`, 'gi'),
|
|
144
|
+
value
|
|
145
|
+
);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
return parsedText;
|
|
149
|
+
};
|
package/src/libs/Prerender.ts
CHANGED
|
@@ -8,6 +8,7 @@ import OvcConverter, { OldOVC } from './OvcConverter'
|
|
|
8
8
|
import NumAuto from './NumAuto'
|
|
9
9
|
import IntputsInitiator from './InputsInitiator'
|
|
10
10
|
import FillPdfForm from './FillPdfForm'
|
|
11
|
+
import { parseDocumentNameWithVariables } from './OutputParser'
|
|
11
12
|
|
|
12
13
|
type DocumentOutputIndex = {
|
|
13
14
|
name: string
|
|
@@ -91,24 +92,24 @@ class Prerender {
|
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
private generateDocumentNamesHash() {
|
|
94
|
-
Object.keys(this.model.documents).forEach(
|
|
95
|
-
const document = this.model.documents[
|
|
96
|
-
const documentParams = this.model.documents[
|
|
97
|
-
const conditionObject = this.references.conditions.documents[
|
|
95
|
+
Object.keys(this.model.documents).forEach(slug => {
|
|
96
|
+
const document = this.model.documents[slug]
|
|
97
|
+
const documentParams = this.model.documents[slug].params
|
|
98
|
+
const conditionObject = this.references.conditions.documents[slug]
|
|
98
99
|
const condition = conditionObject === undefined ? true : this.conditions.executeCondition(conditionObject, 0, 0, 'documents')
|
|
99
100
|
|
|
100
101
|
// Rendering documents sections
|
|
101
102
|
if (condition === true) {
|
|
102
103
|
const hash = crypto
|
|
103
104
|
.createHash('sha1')
|
|
104
|
-
.update(
|
|
105
|
+
.update(slug)
|
|
105
106
|
.digest('hex')
|
|
106
107
|
|
|
107
108
|
// Referencing in index
|
|
108
109
|
if (typeof document.pdf === 'object' && typeof document.pdf.id === 'string' && typeof document.pdf.form === 'object') {
|
|
109
110
|
this.documentsIndex[hash] = {
|
|
110
|
-
name: document.name,
|
|
111
|
-
slug
|
|
111
|
+
name: parseDocumentNameWithVariables(document.name, this.ovc, this.references, document.fallbackName),
|
|
112
|
+
slug,
|
|
112
113
|
form: true,
|
|
113
114
|
fdf: {
|
|
114
115
|
id: '',
|
|
@@ -117,8 +118,8 @@ class Prerender {
|
|
|
117
118
|
}
|
|
118
119
|
} else {
|
|
119
120
|
this.documentsIndex[hash] = {
|
|
120
|
-
name: document.name,
|
|
121
|
-
slug
|
|
121
|
+
name: parseDocumentNameWithVariables(document.name, this.ovc, this.references, document.fallbackName),
|
|
122
|
+
slug,
|
|
122
123
|
pdf: documentParams?.formats?.pdf === undefined ? true : documentParams.formats.pdf,
|
|
123
124
|
docx: documentParams?.formats?.docx === undefined ? true : documentParams.formats.docx
|
|
124
125
|
}
|