@legalplace/prerenderx 2.6.3 → 2.6.4
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/CHANGELOG.md +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -0
- package/dist/libs/ConditionsRunner.d.ts +24 -0
- package/dist/libs/ConditionsRunner.js +77 -0
- package/dist/libs/DataPopulator.d.ts +53 -0
- package/dist/libs/DataPopulator.js +175 -0
- package/dist/libs/DocumentRender.d.ts +13 -0
- package/dist/libs/DocumentRender.js +32 -0
- package/dist/libs/FillPdfForm.d.ts +13 -0
- package/dist/libs/FillPdfForm.js +121 -0
- package/dist/libs/InputsInitiator.d.ts +21 -0
- package/dist/libs/InputsInitiator.js +80 -0
- package/dist/libs/NumAuto.d.ts +8 -0
- package/dist/libs/NumAuto.js +32 -0
- package/dist/libs/OptionRender.d.ts +25 -0
- package/dist/libs/OptionRender.js +66 -0
- package/dist/libs/OutputParser.d.ts +11 -0
- package/dist/libs/OutputParser.js +93 -0
- package/dist/libs/OvcConverter.d.ts +21 -0
- package/dist/libs/OvcConverter.js +132 -0
- package/dist/libs/Prerender.d.ts +42 -0
- package/dist/libs/Prerender.js +105 -0
- package/dist/libs/SectionRender.d.ts +24 -0
- package/dist/libs/SectionRender.js +60 -0
- package/dist/libs/misc/FillPdfFormBase.d.ts +16 -0
- package/dist/libs/misc/FillPdfFormBase.js +62 -0
- package/dist/libs/ovc.type.d.ts +9 -0
- package/dist/libs/ovc.type.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var NumAuto = (function () {
|
|
4
|
+
function NumAuto() {
|
|
5
|
+
var _this = this;
|
|
6
|
+
this.indexesList = {};
|
|
7
|
+
this.tagsIndex = {};
|
|
8
|
+
this.getNum = function (index, tag) {
|
|
9
|
+
if (!Object.prototype.hasOwnProperty.call(_this.indexesList, index)) {
|
|
10
|
+
if (Object.prototype.hasOwnProperty.call(_this.tagsIndex, index))
|
|
11
|
+
return _this.tagsIndex[index];
|
|
12
|
+
_this.indexesList[index] = 0;
|
|
13
|
+
}
|
|
14
|
+
_this.indexesList[index] += 1;
|
|
15
|
+
if (typeof tag === 'string')
|
|
16
|
+
_this.tagsIndex[tag] = _this.indexesList[index];
|
|
17
|
+
return _this.indexesList[index];
|
|
18
|
+
};
|
|
19
|
+
this.getNumPre = function (index) {
|
|
20
|
+
if (!Object.prototype.hasOwnProperty.call(_this.indexesList, index)) {
|
|
21
|
+
if (Object.prototype.hasOwnProperty.call(_this.tagsIndex, index))
|
|
22
|
+
return _this.tagsIndex[index];
|
|
23
|
+
}
|
|
24
|
+
return _this.indexesList[index];
|
|
25
|
+
};
|
|
26
|
+
this.resetIndexes = function () {
|
|
27
|
+
_this.indexesList = {};
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return NumAuto;
|
|
31
|
+
}());
|
|
32
|
+
exports.default = NumAuto;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Types } from '@legalplace/referencesparser';
|
|
2
|
+
import ConditionsRunner from './ConditionsRunner';
|
|
3
|
+
import OVC_TYPE from './ovc.type';
|
|
4
|
+
import NumAuto from './NumAuto';
|
|
5
|
+
declare class OptionRender {
|
|
6
|
+
outputs: string[];
|
|
7
|
+
references: Types.ReferencesType;
|
|
8
|
+
index: number;
|
|
9
|
+
id: number;
|
|
10
|
+
conditions: ConditionsRunner;
|
|
11
|
+
ovc: OVC_TYPE;
|
|
12
|
+
private NumAuto;
|
|
13
|
+
constructor(options: {
|
|
14
|
+
references: Types.ReferencesType;
|
|
15
|
+
conditions: ConditionsRunner;
|
|
16
|
+
ovc: OVC_TYPE;
|
|
17
|
+
index: number;
|
|
18
|
+
id: number;
|
|
19
|
+
numauto: NumAuto;
|
|
20
|
+
});
|
|
21
|
+
getOutputs(): string[];
|
|
22
|
+
private renderOption;
|
|
23
|
+
private renderChildren;
|
|
24
|
+
}
|
|
25
|
+
export default OptionRender;
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
var OutputParser_1 = require("./OutputParser");
|
|
11
|
+
var OptionRender = (function () {
|
|
12
|
+
function OptionRender(options) {
|
|
13
|
+
this.outputs = [];
|
|
14
|
+
this.references = options.references;
|
|
15
|
+
this.conditions = options.conditions;
|
|
16
|
+
this.index = options.index;
|
|
17
|
+
this.id = options.id;
|
|
18
|
+
this.ovc = options.ovc;
|
|
19
|
+
this.NumAuto = options.numauto;
|
|
20
|
+
this.renderOption();
|
|
21
|
+
}
|
|
22
|
+
OptionRender.prototype.getOutputs = function () {
|
|
23
|
+
return this.outputs;
|
|
24
|
+
};
|
|
25
|
+
OptionRender.prototype.renderOption = function () {
|
|
26
|
+
var _this = this;
|
|
27
|
+
var option = this.references.options[this.id];
|
|
28
|
+
var conditionObject = this.references.conditions.options[this.id];
|
|
29
|
+
var condition = conditionObject === undefined ? true : this.conditions.executeCondition(conditionObject, this.id, this.index, 'options');
|
|
30
|
+
if (condition === true) {
|
|
31
|
+
if (typeof option.meta.output === 'string' && option.meta.output.trim().length > 0) {
|
|
32
|
+
var outputReference = this.references.outputs[this.id];
|
|
33
|
+
var autonums = [];
|
|
34
|
+
if (condition !== false) {
|
|
35
|
+
autonums = outputReference.autonums.map(function (currentAn) {
|
|
36
|
+
var fn = currentAn[0] === 'numauto-pre' ? _this.NumAuto.getNumPre : _this.NumAuto.getNum;
|
|
37
|
+
return [currentAn[0], currentAn[1], fn(currentAn[1], currentAn[2]), currentAn[2]];
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
var variables = OutputParser_1.getRelatedVariablesValues(this.id, this.index, outputReference.variables, this.ovc, this.references);
|
|
41
|
+
var output = OutputParser_1.parseOutputWithVariables(option.meta.output, this.index, variables, autonums);
|
|
42
|
+
output = output.replace(/<\/([a-z]+)>([\n\s]+)</gi, '</$1><');
|
|
43
|
+
output = output.replace(/\n/g, '<br />');
|
|
44
|
+
output = output.replace(/\xA0/g, ' ');
|
|
45
|
+
this.outputs.push(output);
|
|
46
|
+
}
|
|
47
|
+
this.renderChildren();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
OptionRender.prototype.renderChildren = function () {
|
|
51
|
+
var _this = this;
|
|
52
|
+
var option = this.references.options[this.id];
|
|
53
|
+
option.options.forEach(function (optionId) {
|
|
54
|
+
_this.outputs = __spreadArrays(_this.outputs, new OptionRender({
|
|
55
|
+
references: _this.references,
|
|
56
|
+
id: optionId,
|
|
57
|
+
ovc: _this.ovc,
|
|
58
|
+
index: _this.index,
|
|
59
|
+
conditions: _this.conditions,
|
|
60
|
+
numauto: _this.NumAuto
|
|
61
|
+
}).getOutputs());
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
return OptionRender;
|
|
65
|
+
}());
|
|
66
|
+
exports.default = OptionRender;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Types } from '@legalplace/referencesparser';
|
|
2
|
+
import OVC_TYPE from './ovc.type';
|
|
3
|
+
declare type relVarsValsT = Record<string, string | number>;
|
|
4
|
+
declare type getRelatedVarsT = (optionId: number, index: number, variables: number[], ovc: OVC_TYPE, references: Types.ReferencesType) => relVarsValsT;
|
|
5
|
+
export declare const getRelatedVariablesValues: getRelatedVarsT;
|
|
6
|
+
declare type autonumsType = [string, string, number, string | null][];
|
|
7
|
+
declare type parseOutputT = (output: string, index: number, variables: relVarsValsT, autonums: autonumsType) => string;
|
|
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;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.parseDocumentNameWithVariables = exports.parseOutputWithVariables = exports.getRelatedVariablesValues = void 0;
|
|
11
|
+
var frenchNumber = function (value) {
|
|
12
|
+
var result = typeof value === 'number' ? value.toString() : value;
|
|
13
|
+
if (/^([0-9]+)\.([0-9]+)$/.test(result.trim()))
|
|
14
|
+
result = result.trim().replace('.', ',');
|
|
15
|
+
return result;
|
|
16
|
+
};
|
|
17
|
+
exports.getRelatedVariablesValues = function (optionId, index, variables, ovc, references) {
|
|
18
|
+
var variablesValues = {};
|
|
19
|
+
variables.forEach(function (currentVariableId) {
|
|
20
|
+
var value = ovc.variables[currentVariableId] || [''];
|
|
21
|
+
var variableParents = references.relations.variables[currentVariableId].parents;
|
|
22
|
+
if (variableParents === undefined)
|
|
23
|
+
throw new Error("Variable " + currentVariableId + " parents object does not exist");
|
|
24
|
+
var rootVariableParentId = variableParents[variableParents.length - 1];
|
|
25
|
+
var rootVariableParentRelations = references.relations.options[rootVariableParentId];
|
|
26
|
+
if (rootVariableParentRelations === undefined)
|
|
27
|
+
throw new Error("Option " + rootVariableParentId + " does not exist");
|
|
28
|
+
if (typeof variableParents === 'undefined')
|
|
29
|
+
return;
|
|
30
|
+
if (rootVariableParentRelations.children.options.includes(optionId) || rootVariableParentRelations.dependants.includes(optionId) || optionId === rootVariableParentId)
|
|
31
|
+
value = [value[index]];
|
|
32
|
+
var cleanValues = value.map(function (currentValue) {
|
|
33
|
+
if (['number', 'string'].includes(typeof currentValue))
|
|
34
|
+
return frenchNumber(currentValue);
|
|
35
|
+
return '';
|
|
36
|
+
});
|
|
37
|
+
var currentVariableValue = cleanValues.length === 1 ? cleanValues[0] : cleanValues.join(', ');
|
|
38
|
+
variablesValues[currentVariableId] = currentVariableValue;
|
|
39
|
+
});
|
|
40
|
+
return variablesValues;
|
|
41
|
+
};
|
|
42
|
+
exports.parseOutputWithVariables = function (output, index, variables, autonums) {
|
|
43
|
+
var parsedOutput = "" + output;
|
|
44
|
+
Object.keys(variables).forEach(function (variableId) {
|
|
45
|
+
var value = variables[variableId].toString();
|
|
46
|
+
if (value.trim().length === 0) {
|
|
47
|
+
value = new Array(16).join('_');
|
|
48
|
+
}
|
|
49
|
+
value = value.replace(/\n/g, '<br />');
|
|
50
|
+
parsedOutput = parsedOutput.replace(new RegExp("\\[var:" + variableId + "\\]", 'g'), value);
|
|
51
|
+
});
|
|
52
|
+
parsedOutput = parsedOutput.replace(/\[\[PAGE_BREAK\]\]/gi, '<div style="page-break-after:always"></div>');
|
|
53
|
+
parsedOutput = parsedOutput.replace(/\[(E|B)_BLUR\]/gi, '');
|
|
54
|
+
parsedOutput = parsedOutput.replace(/\[signature:([0-9]+)\]/g, function (v, signatureId) { return "<span data-signature-id=\"" + signatureId + "\" data-signer-index=\"" + index + "\"></span>"; });
|
|
55
|
+
autonums.forEach(function (currentAn) {
|
|
56
|
+
if (currentAn[3] === null)
|
|
57
|
+
parsedOutput = parsedOutput.replace("[" + currentAn[0] + ":" + currentAn[1] + "]", "<span class=\"" + currentAn[0] + "\">" + currentAn[2] + "</span>");
|
|
58
|
+
else
|
|
59
|
+
parsedOutput = parsedOutput.replace("[" + currentAn[0] + ":" + currentAn[1] + "](" + currentAn[3] + ")", "<span class=\"" + currentAn[0] + "\">" + currentAn[2] + "</span>");
|
|
60
|
+
});
|
|
61
|
+
return parsedOutput;
|
|
62
|
+
};
|
|
63
|
+
exports.parseDocumentNameWithVariables = function (text, ovc, references, fallback) {
|
|
64
|
+
var tagsMatch = text.match(/\[var:([0-9]+)\]/gi);
|
|
65
|
+
var variables = [];
|
|
66
|
+
if (tagsMatch !== null) {
|
|
67
|
+
var variablesTags = __spreadArrays(tagsMatch);
|
|
68
|
+
variables = variablesTags.map(function (current) {
|
|
69
|
+
var outputVariableMatch = current.match(/([0-9]+)/);
|
|
70
|
+
if (outputVariableMatch === null)
|
|
71
|
+
return 0;
|
|
72
|
+
return parseInt(outputVariableMatch[0], 10);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
variables = variables.filter(function (c, i) { return variables.indexOf(c) === i; });
|
|
76
|
+
variables = variables.filter(function (c) { return ovc !== undefined || references.variables[c] !== undefined; });
|
|
77
|
+
var variablesValues = {};
|
|
78
|
+
variables.forEach(function (variableId) {
|
|
79
|
+
var _a;
|
|
80
|
+
var value = ((_a = ovc.variables[variableId]) === null || _a === void 0 ? void 0 : _a[0]) || '';
|
|
81
|
+
variablesValues[variableId] = value.toString();
|
|
82
|
+
});
|
|
83
|
+
var parsedText = "" + text;
|
|
84
|
+
variables.forEach(function (variableId) {
|
|
85
|
+
var value = variablesValues[variableId];
|
|
86
|
+
if (value.trim().length === 0 && fallback)
|
|
87
|
+
parsedText = fallback;
|
|
88
|
+
if (parsedText === fallback && fallback)
|
|
89
|
+
return;
|
|
90
|
+
parsedText = parsedText.replace(new RegExp("\\[var:" + variableId + "\\]", 'gi'), value);
|
|
91
|
+
});
|
|
92
|
+
return parsedText;
|
|
93
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import OVC_TYPE from './ovc.type';
|
|
2
|
+
import { Types } from '@legalplace/referencesparser';
|
|
3
|
+
export interface OldOVC {
|
|
4
|
+
o: {
|
|
5
|
+
[k: string]: string | number | (string | number)[];
|
|
6
|
+
};
|
|
7
|
+
v: {
|
|
8
|
+
[k: string]: string | number | (string | number)[];
|
|
9
|
+
};
|
|
10
|
+
c: {
|
|
11
|
+
[k: string]: boolean | boolean[];
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
declare class OvcConverter {
|
|
15
|
+
convertToOptionsVariables(ovc: OldOVC, references: Types.ReferencesType): OVC_TYPE;
|
|
16
|
+
isOvc(_obj: OVC_TYPE | OldOVC): _obj is OldOVC;
|
|
17
|
+
isOptionsVariables(_obj: OVC_TYPE | OldOVC): boolean;
|
|
18
|
+
private pushStaticChildren;
|
|
19
|
+
}
|
|
20
|
+
declare const _default: OvcConverter;
|
|
21
|
+
export default _default;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
14
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
15
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
16
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
17
|
+
r[k] = a[j];
|
|
18
|
+
return r;
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
var OvcConverter = (function () {
|
|
22
|
+
function OvcConverter() {
|
|
23
|
+
}
|
|
24
|
+
OvcConverter.prototype.convertToOptionsVariables = function (ovc, references) {
|
|
25
|
+
var _this = this;
|
|
26
|
+
var inputs = {
|
|
27
|
+
options: {},
|
|
28
|
+
variables: {}
|
|
29
|
+
};
|
|
30
|
+
if (typeof ovc !== 'object')
|
|
31
|
+
return inputs;
|
|
32
|
+
if (typeof ovc.o === 'object') {
|
|
33
|
+
Object.keys(ovc.o).forEach(function (id) {
|
|
34
|
+
var currentOption = ovc.o[id];
|
|
35
|
+
if (Array.isArray(currentOption)) {
|
|
36
|
+
var occurences_1 = currentOption.length;
|
|
37
|
+
inputs.options = __assign(__assign({}, inputs.options), _this.pushStaticChildren(inputs.options, id, occurences_1, references));
|
|
38
|
+
currentOption.forEach(function (childId, index) {
|
|
39
|
+
var sanitizedId = typeof childId === 'string' && childId.split('_').length > 0
|
|
40
|
+
? childId.split('_')[0]
|
|
41
|
+
: childId;
|
|
42
|
+
if (!Object.prototype.hasOwnProperty.call(inputs.options, id)) {
|
|
43
|
+
inputs.options[id] = new Array(occurences_1).fill(false);
|
|
44
|
+
}
|
|
45
|
+
if (typeof sanitizedId === 'string' &&
|
|
46
|
+
sanitizedId.trim().length === 0) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (!Object.prototype.hasOwnProperty.call(inputs.options, sanitizedId)) {
|
|
50
|
+
inputs.options[sanitizedId] = new Array(occurences_1).fill(false);
|
|
51
|
+
}
|
|
52
|
+
inputs.options = __assign(__assign({}, inputs.options), _this.pushStaticChildren(inputs.options, sanitizedId, occurences_1, references));
|
|
53
|
+
inputs.options[sanitizedId][index] = true;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
if (typeof currentOption === 'string' &&
|
|
58
|
+
currentOption.trim().length === 0)
|
|
59
|
+
return;
|
|
60
|
+
inputs.options[currentOption] = [true];
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
if (typeof ovc.c === 'object') {
|
|
65
|
+
Object.keys(ovc.c).forEach(function (id) {
|
|
66
|
+
var currentCheckbox = ovc.c[id];
|
|
67
|
+
if (typeof id === 'string' && id.trim().length === 0)
|
|
68
|
+
return;
|
|
69
|
+
if (Array.isArray(currentCheckbox)) {
|
|
70
|
+
inputs.options[id] = currentCheckbox;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
inputs.options[id] = [currentCheckbox];
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if (typeof ovc.v === 'object') {
|
|
78
|
+
Object.keys(ovc.v).forEach(function (id) {
|
|
79
|
+
var currentVariable = ovc.v[id];
|
|
80
|
+
if (Array.isArray(currentVariable)) {
|
|
81
|
+
inputs.variables[id] = currentVariable;
|
|
82
|
+
var parentsTree = references.relations.variables[id].parents;
|
|
83
|
+
var parentOption = inputs.options["" + parentsTree[parentsTree.length - 1]];
|
|
84
|
+
if (Array.isArray(parentOption)) {
|
|
85
|
+
var occurences = parentOption.length;
|
|
86
|
+
if (currentVariable.length < occurences) {
|
|
87
|
+
inputs.variables[id] = __spreadArrays(currentVariable, Array(occurences - currentVariable.length).fill(''));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
inputs.variables[id] = [currentVariable];
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return inputs;
|
|
97
|
+
};
|
|
98
|
+
OvcConverter.prototype.isOvc = function (_obj) {
|
|
99
|
+
if (typeof _obj !== 'object' || _obj === null)
|
|
100
|
+
return false;
|
|
101
|
+
var ovcKeys = ['o', 'v', 'c'];
|
|
102
|
+
var foundKeys = Object.keys(_obj)
|
|
103
|
+
.map(function (key) { return (ovcKeys.includes(key) ? 1 : 0); })
|
|
104
|
+
.reduce(function (a, b) { return a + b; }, 0);
|
|
105
|
+
return foundKeys > 1;
|
|
106
|
+
};
|
|
107
|
+
OvcConverter.prototype.isOptionsVariables = function (_obj) {
|
|
108
|
+
if (typeof _obj !== 'object' || _obj === null)
|
|
109
|
+
return false;
|
|
110
|
+
var optionsVariablesKeys = ['options', 'variables'];
|
|
111
|
+
var foundKeys = Object.keys(_obj)
|
|
112
|
+
.map(function (key) { return (optionsVariablesKeys.includes(key) ? 1 : 0); })
|
|
113
|
+
.reduce(function (a, b) { return a + b; }, 0);
|
|
114
|
+
return foundKeys === 2;
|
|
115
|
+
};
|
|
116
|
+
OvcConverter.prototype.pushStaticChildren = function (inputOptions, id, occurences, references) {
|
|
117
|
+
var result = __assign({}, inputOptions);
|
|
118
|
+
var intId = typeof id === 'number' ? id : parseInt(id, 10);
|
|
119
|
+
var options = references.relations.options[intId].children.options;
|
|
120
|
+
var staticOptions = options.filter(function (childId) {
|
|
121
|
+
return references.options[childId].meta.type === 'static';
|
|
122
|
+
});
|
|
123
|
+
staticOptions.forEach(function (childId) {
|
|
124
|
+
if (!Object.prototype.hasOwnProperty.call(result, childId)) {
|
|
125
|
+
result[childId] = new Array(occurences).fill(false);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
return result;
|
|
129
|
+
};
|
|
130
|
+
return OvcConverter;
|
|
131
|
+
}());
|
|
132
|
+
exports.default = new OvcConverter();
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ModelV3 } from '@legalplace/models-v3-types';
|
|
2
|
+
import { Types } from '@legalplace/referencesparser';
|
|
3
|
+
import OVC_TYPE from './ovc.type';
|
|
4
|
+
import { OldOVC } from './OvcConverter';
|
|
5
|
+
declare type DocumentOutputIndex = {
|
|
6
|
+
name: string;
|
|
7
|
+
slug: string;
|
|
8
|
+
pdf: boolean;
|
|
9
|
+
docx: boolean;
|
|
10
|
+
};
|
|
11
|
+
declare type DocumentPdfFormIndex = {
|
|
12
|
+
name: string;
|
|
13
|
+
slug: string;
|
|
14
|
+
form: boolean;
|
|
15
|
+
fdf: {
|
|
16
|
+
id: string;
|
|
17
|
+
fields: Record<string, string>;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
declare type FDFType = {
|
|
21
|
+
id: string;
|
|
22
|
+
fields: Record<string, string>;
|
|
23
|
+
};
|
|
24
|
+
declare class Prerender {
|
|
25
|
+
private references;
|
|
26
|
+
private ovc;
|
|
27
|
+
private conditions;
|
|
28
|
+
private documentRender;
|
|
29
|
+
private pdfFiller;
|
|
30
|
+
private NumAuto;
|
|
31
|
+
private documentsIndex;
|
|
32
|
+
private renderedDocuments;
|
|
33
|
+
constructor(entry: ModelV3 | Types.ReferencesType, ovc: OVC_TYPE | OldOVC);
|
|
34
|
+
getDocumentsIndex(): Record<string, DocumentOutputIndex | DocumentPdfFormIndex>;
|
|
35
|
+
getDocument(documentNameHash: string): string | FDFType;
|
|
36
|
+
private generateDocumentNamesHash;
|
|
37
|
+
private fillPdfForms;
|
|
38
|
+
private generateAllDocuments;
|
|
39
|
+
static isPdfForm(index: DocumentOutputIndex | DocumentPdfFormIndex): index is DocumentPdfFormIndex;
|
|
40
|
+
static isOutput(index: DocumentOutputIndex | DocumentPdfFormIndex): index is DocumentOutputIndex;
|
|
41
|
+
}
|
|
42
|
+
export default Prerender;
|
|
@@ -0,0 +1,105 @@
|
|
|
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 referencesparser_1 = require("@legalplace/referencesparser");
|
|
7
|
+
var crypto_1 = __importDefault(require("crypto"));
|
|
8
|
+
var DocumentRender_1 = __importDefault(require("./DocumentRender"));
|
|
9
|
+
var ConditionsRunner_1 = __importDefault(require("./ConditionsRunner"));
|
|
10
|
+
var OvcConverter_1 = __importDefault(require("./OvcConverter"));
|
|
11
|
+
var NumAuto_1 = __importDefault(require("./NumAuto"));
|
|
12
|
+
var InputsInitiator_1 = __importDefault(require("./InputsInitiator"));
|
|
13
|
+
var FillPdfForm_1 = __importDefault(require("./FillPdfForm"));
|
|
14
|
+
var OutputParser_1 = require("./OutputParser");
|
|
15
|
+
var Prerender = (function () {
|
|
16
|
+
function Prerender(entry, ovc) {
|
|
17
|
+
this.documentsIndex = {};
|
|
18
|
+
this.renderedDocuments = {};
|
|
19
|
+
if (referencesparser_1.ReferencesParser.isReferences(entry)) {
|
|
20
|
+
this.references = entry;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
this.references = new referencesparser_1.ReferencesParser(entry).getReferences();
|
|
24
|
+
}
|
|
25
|
+
this.NumAuto = new NumAuto_1.default();
|
|
26
|
+
this.ovc = OvcConverter_1.default.isOvc(ovc) ? OvcConverter_1.default.convertToOptionsVariables(ovc, this.references) : ovc;
|
|
27
|
+
var inputs = new InputsInitiator_1.default(this.references, this.ovc).getInputs();
|
|
28
|
+
this.conditions = new ConditionsRunner_1.default(this.references, inputs);
|
|
29
|
+
this.documentRender = new DocumentRender_1.default(this.references, this.conditions, inputs, this.NumAuto);
|
|
30
|
+
this.pdfFiller = new FillPdfForm_1.default(this.references, this.conditions, inputs);
|
|
31
|
+
this.generateDocumentNamesHash();
|
|
32
|
+
this.generateAllDocuments();
|
|
33
|
+
this.fillPdfForms();
|
|
34
|
+
}
|
|
35
|
+
Prerender.prototype.getDocumentsIndex = function () {
|
|
36
|
+
return this.documentsIndex;
|
|
37
|
+
};
|
|
38
|
+
Prerender.prototype.getDocument = function (documentNameHash) {
|
|
39
|
+
return this.renderedDocuments[documentNameHash];
|
|
40
|
+
};
|
|
41
|
+
Prerender.prototype.generateDocumentNamesHash = function () {
|
|
42
|
+
var _this = this;
|
|
43
|
+
Object.keys(this.references.documents).forEach(function (slug) {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
var document = _this.references.documents[slug];
|
|
46
|
+
var documentParams = _this.references.documents[slug].params;
|
|
47
|
+
var conditionObject = _this.references.conditions.documents[slug];
|
|
48
|
+
var condition = conditionObject === undefined ? true : _this.conditions.executeCondition(conditionObject, 0, 0, 'documents');
|
|
49
|
+
if (condition === true) {
|
|
50
|
+
var hash = crypto_1.default
|
|
51
|
+
.createHash('sha1')
|
|
52
|
+
.update(slug)
|
|
53
|
+
.digest('hex');
|
|
54
|
+
if (typeof document.pdf === 'object' && typeof document.pdf.id === 'string' && typeof document.pdf.form === 'object') {
|
|
55
|
+
_this.documentsIndex[hash] = {
|
|
56
|
+
name: OutputParser_1.parseDocumentNameWithVariables(document.name, _this.ovc, _this.references, document.fallbackName),
|
|
57
|
+
slug: slug,
|
|
58
|
+
form: true,
|
|
59
|
+
fdf: {
|
|
60
|
+
id: '',
|
|
61
|
+
fields: {}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
_this.documentsIndex[hash] = {
|
|
67
|
+
name: OutputParser_1.parseDocumentNameWithVariables(document.name, _this.ovc, _this.references, document.fallbackName),
|
|
68
|
+
slug: slug,
|
|
69
|
+
pdf: ((_a = documentParams === null || documentParams === void 0 ? void 0 : documentParams.formats) === null || _a === void 0 ? void 0 : _a.pdf) === undefined ? true : documentParams.formats.pdf,
|
|
70
|
+
docx: ((_b = documentParams === null || documentParams === void 0 ? void 0 : documentParams.formats) === null || _b === void 0 ? void 0 : _b.docx) === undefined ? true : documentParams.formats.docx
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
Prerender.prototype.fillPdfForms = function () {
|
|
77
|
+
var _this = this;
|
|
78
|
+
Object.keys(this.documentsIndex).forEach(function (documentNameHash) {
|
|
79
|
+
var index = _this.documentsIndex[documentNameHash];
|
|
80
|
+
if (Prerender.isPdfForm(index)) {
|
|
81
|
+
index.fdf = _this.getDocument(documentNameHash);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
Prerender.prototype.generateAllDocuments = function () {
|
|
86
|
+
var _this = this;
|
|
87
|
+
Object.keys(this.documentsIndex).forEach(function (documentNameHash) {
|
|
88
|
+
var index = _this.documentsIndex[documentNameHash];
|
|
89
|
+
if (Prerender.isPdfForm(index)) {
|
|
90
|
+
_this.renderedDocuments[documentNameHash] = _this.pdfFiller.fillDocument(_this.documentsIndex[documentNameHash].slug);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
_this.renderedDocuments[documentNameHash] = _this.documentRender.renderDocument(_this.documentsIndex[documentNameHash].slug);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
Prerender.isPdfForm = function (index) {
|
|
98
|
+
return Object.prototype.hasOwnProperty.call(index, 'form');
|
|
99
|
+
};
|
|
100
|
+
Prerender.isOutput = function (index) {
|
|
101
|
+
return !Object.prototype.hasOwnProperty.call(index, 'form');
|
|
102
|
+
};
|
|
103
|
+
return Prerender;
|
|
104
|
+
}());
|
|
105
|
+
exports.default = Prerender;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Types } from '@legalplace/referencesparser';
|
|
2
|
+
import ConditionsRunner from './ConditionsRunner';
|
|
3
|
+
import OVC_TYPE from './ovc.type';
|
|
4
|
+
import NumAuto from './NumAuto';
|
|
5
|
+
declare class SectionRender {
|
|
6
|
+
outputs: string[];
|
|
7
|
+
references: Types.ReferencesType;
|
|
8
|
+
currentSection: number;
|
|
9
|
+
documentName: string;
|
|
10
|
+
conditions: ConditionsRunner;
|
|
11
|
+
ovc: OVC_TYPE;
|
|
12
|
+
private NumAuto;
|
|
13
|
+
constructor(options: {
|
|
14
|
+
references: Types.ReferencesType;
|
|
15
|
+
conditions: ConditionsRunner;
|
|
16
|
+
ovc: OVC_TYPE;
|
|
17
|
+
documentName: string;
|
|
18
|
+
currentSection: number;
|
|
19
|
+
numauto: NumAuto;
|
|
20
|
+
});
|
|
21
|
+
getOutputs(): string[];
|
|
22
|
+
private renderSection;
|
|
23
|
+
}
|
|
24
|
+
export default SectionRender;
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
};
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
var OptionRender_1 = __importDefault(require("./OptionRender"));
|
|
14
|
+
var SectionRender = (function () {
|
|
15
|
+
function SectionRender(options) {
|
|
16
|
+
this.outputs = [];
|
|
17
|
+
this.references = options.references;
|
|
18
|
+
this.conditions = options.conditions;
|
|
19
|
+
this.documentName = options.documentName;
|
|
20
|
+
this.currentSection = options.currentSection;
|
|
21
|
+
this.ovc = options.ovc;
|
|
22
|
+
this.NumAuto = options.numauto;
|
|
23
|
+
this.renderSection();
|
|
24
|
+
}
|
|
25
|
+
SectionRender.prototype.getOutputs = function () {
|
|
26
|
+
return this.outputs;
|
|
27
|
+
};
|
|
28
|
+
SectionRender.prototype.renderSection = function () {
|
|
29
|
+
var _this = this;
|
|
30
|
+
var section = this.references.sections[this.documentName][this.currentSection];
|
|
31
|
+
var conditionObject = this.references.conditions.sections[this.documentName][this.currentSection];
|
|
32
|
+
var condition = conditionObject === undefined ? true : this.conditions.executeCondition(conditionObject, 0, 0, 'sections');
|
|
33
|
+
if (condition === true) {
|
|
34
|
+
section.options.forEach(function (optionId) {
|
|
35
|
+
var option = _this.references.options[optionId];
|
|
36
|
+
var repeatOption = optionId;
|
|
37
|
+
if (option.meta.type === 'repeated') {
|
|
38
|
+
if (option.meta.repeatOption === undefined)
|
|
39
|
+
return;
|
|
40
|
+
repeatOption = typeof option.meta.repeatOption === 'number' ? option.meta.repeatOption : parseInt(option.meta.repeatOption, 10);
|
|
41
|
+
}
|
|
42
|
+
var inputs = _this.ovc.options[repeatOption] || [!['radio', 'checkbox'].includes(option.meta.type)];
|
|
43
|
+
inputs.forEach(function (value, index) {
|
|
44
|
+
if (value !== true)
|
|
45
|
+
return;
|
|
46
|
+
_this.outputs = __spreadArrays(_this.outputs, new OptionRender_1.default({
|
|
47
|
+
references: _this.references,
|
|
48
|
+
id: optionId,
|
|
49
|
+
ovc: _this.ovc,
|
|
50
|
+
index: index,
|
|
51
|
+
conditions: _this.conditions,
|
|
52
|
+
numauto: _this.NumAuto
|
|
53
|
+
}).getOutputs());
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
return SectionRender;
|
|
59
|
+
}());
|
|
60
|
+
exports.default = SectionRender;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Types } from '@legalplace/referencesparser';
|
|
2
|
+
import ConditionsRunner from '../ConditionsRunner';
|
|
3
|
+
import OVC_TYPE from '../ovc.type';
|
|
4
|
+
declare class FillPdfFormBase {
|
|
5
|
+
references: Types.ReferencesType;
|
|
6
|
+
conditions: ConditionsRunner;
|
|
7
|
+
ovc: OVC_TYPE;
|
|
8
|
+
constructor(references: Types.ReferencesType, conditions: ConditionsRunner, ovc: OVC_TYPE);
|
|
9
|
+
isVariableDisplayed(id: number, index: number): boolean;
|
|
10
|
+
isOptionDisplayed(id: number, index: number): boolean;
|
|
11
|
+
private getVariableCondition;
|
|
12
|
+
private getOptionCondition;
|
|
13
|
+
private getSectionCondition;
|
|
14
|
+
private getOptionParentSection;
|
|
15
|
+
}
|
|
16
|
+
export default FillPdfFormBase;
|