@legalplace/prerenderx 3.8.2-nightly.0 → 3.8.2
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 +8 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +22 -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 +127 -0
- package/dist/libs/InputsInitiator.d.ts +21 -0
- package/dist/libs/InputsInitiator.js +104 -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 +78 -0
- package/dist/libs/OutputParser.d.ts +11 -0
- package/dist/libs/OutputParser.js +132 -0
- package/dist/libs/Prerender.d.ts +25 -0
- package/dist/libs/Prerender.js +116 -0
- package/dist/libs/SectionRender.d.ts +24 -0
- package/dist/libs/SectionRender.js +69 -0
- package/dist/libs/misc/FillPdfFormBase.d.ts +16 -0
- package/dist/libs/misc/FillPdfFormBase.js +70 -0
- package/dist/types/types.d.ts +17 -0
- package/dist/types/types.js +2 -0
- package/package.json +8 -7
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.8.2](https://git.legalplace.eu/legalplace/prerenderx/compare/@legalplace/prerenderx@3.8.1...@legalplace/prerenderx@3.8.2) (2026-03-16)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @legalplace/prerenderx
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## [3.8.1](https://git.legalplace.eu/legalplace/prerenderx/compare/@legalplace/prerenderx@3.8.0...@legalplace/prerenderx@3.8.1) (2026-02-03)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @legalplace/prerenderx
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
var Prerender_1 = __importDefault(require("./libs/Prerender"));
|
|
21
|
+
__exportStar(require("./types/types"), exports);
|
|
22
|
+
exports.default = Prerender_1.default;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Types } from "@legalplace/referencesparser";
|
|
2
|
+
import type ConditionsRunner from "@legalplace/conditions-runner";
|
|
3
|
+
import type InputsType from "@legalplace/types/dist/inputs";
|
|
4
|
+
import type NumAuto from "./NumAuto";
|
|
5
|
+
declare class DocumentRender {
|
|
6
|
+
references: Types.ReferencesType;
|
|
7
|
+
conditions: ConditionsRunner;
|
|
8
|
+
ovc: InputsType;
|
|
9
|
+
private NumAuto;
|
|
10
|
+
constructor(references: Types.ReferencesType, conditions: ConditionsRunner, ovc: InputsType, numauto: NumAuto);
|
|
11
|
+
renderDocument(documentName: string): string;
|
|
12
|
+
}
|
|
13
|
+
export default DocumentRender;
|
|
@@ -0,0 +1,32 @@
|
|
|
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 SectionRender_1 = __importDefault(require("./SectionRender"));
|
|
7
|
+
var DocumentRender = (function () {
|
|
8
|
+
function DocumentRender(references, conditions, ovc, numauto) {
|
|
9
|
+
this.references = references;
|
|
10
|
+
this.conditions = conditions;
|
|
11
|
+
this.ovc = ovc;
|
|
12
|
+
this.NumAuto = numauto;
|
|
13
|
+
}
|
|
14
|
+
DocumentRender.prototype.renderDocument = function (documentName) {
|
|
15
|
+
var _this = this;
|
|
16
|
+
var documentOutputs = [];
|
|
17
|
+
this.NumAuto.resetIndexes();
|
|
18
|
+
Object.keys(this.references.sections[documentName]).forEach(function (sectionId) {
|
|
19
|
+
documentOutputs.push.apply(documentOutputs, new SectionRender_1.default({
|
|
20
|
+
references: _this.references,
|
|
21
|
+
conditions: _this.conditions,
|
|
22
|
+
documentName: documentName,
|
|
23
|
+
ovc: _this.ovc,
|
|
24
|
+
currentSection: parseInt(sectionId, 10),
|
|
25
|
+
numauto: _this.NumAuto,
|
|
26
|
+
}).getOutputs());
|
|
27
|
+
});
|
|
28
|
+
return documentOutputs.join("");
|
|
29
|
+
};
|
|
30
|
+
return DocumentRender;
|
|
31
|
+
}());
|
|
32
|
+
exports.default = DocumentRender;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import FillPdfFormBase from "./misc/FillPdfFormBase";
|
|
2
|
+
type FDFType = {
|
|
3
|
+
id: string;
|
|
4
|
+
fields: Record<string, string>;
|
|
5
|
+
};
|
|
6
|
+
declare class FillPdfForm extends FillPdfFormBase {
|
|
7
|
+
fillDocument(documentName: string): FDFType;
|
|
8
|
+
private getInputValue;
|
|
9
|
+
private getBoxValue;
|
|
10
|
+
private getVariableValue;
|
|
11
|
+
private getOptionValue;
|
|
12
|
+
}
|
|
13
|
+
export default FillPdfForm;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
var FillPdfFormBase_1 = __importDefault(require("./misc/FillPdfFormBase"));
|
|
22
|
+
var FillPdfForm = (function (_super) {
|
|
23
|
+
__extends(FillPdfForm, _super);
|
|
24
|
+
function FillPdfForm() {
|
|
25
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
26
|
+
}
|
|
27
|
+
FillPdfForm.prototype.fillDocument = function (documentName) {
|
|
28
|
+
var _this = this;
|
|
29
|
+
var result = {
|
|
30
|
+
id: "",
|
|
31
|
+
fields: {},
|
|
32
|
+
};
|
|
33
|
+
var document = this.references.documents[documentName];
|
|
34
|
+
var pdf = document.pdf;
|
|
35
|
+
if (typeof pdf === "undefined")
|
|
36
|
+
return result;
|
|
37
|
+
var form = pdf.form;
|
|
38
|
+
result.id = pdf.id;
|
|
39
|
+
form.inputs.forEach(function (input) {
|
|
40
|
+
var id = "".concat(input.name);
|
|
41
|
+
result.fields[id] = _this.getInputValue(input);
|
|
42
|
+
});
|
|
43
|
+
form.boxes.forEach(function (box) {
|
|
44
|
+
var id = "".concat(box.name);
|
|
45
|
+
var value = _this.getBoxValue(box);
|
|
46
|
+
if (!(value === "" &&
|
|
47
|
+
Object.prototype.hasOwnProperty.call(result.fields, id)))
|
|
48
|
+
result.fields[id] = value;
|
|
49
|
+
});
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
FillPdfForm.prototype.getInputValue = function (input) {
|
|
53
|
+
for (var i = 0; i < input.variables.length; i += 1) {
|
|
54
|
+
var variable = input.variables[i];
|
|
55
|
+
var currentValue = this.getVariableValue(variable.id);
|
|
56
|
+
if (currentValue !== false) {
|
|
57
|
+
var dateRegex = /^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/;
|
|
58
|
+
if (variable.date && dateRegex.test(currentValue)) {
|
|
59
|
+
switch (variable.date) {
|
|
60
|
+
case "DD":
|
|
61
|
+
return currentValue.replace(dateRegex, "$1");
|
|
62
|
+
case "MM":
|
|
63
|
+
return currentValue.replace(dateRegex, "$2");
|
|
64
|
+
case "YYYY":
|
|
65
|
+
return currentValue.replace(dateRegex, "$3");
|
|
66
|
+
default:
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
var hourRegex = /^([0-9]{2}:[0-9]{2})$/;
|
|
70
|
+
if (variable.hour && hourRegex.test(currentValue)) {
|
|
71
|
+
switch (variable.hour) {
|
|
72
|
+
case "HH":
|
|
73
|
+
return currentValue.replace(hourRegex, "$1");
|
|
74
|
+
case "MM":
|
|
75
|
+
return currentValue.replace(hourRegex, "$2");
|
|
76
|
+
default:
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
var emailRegex = /^(.*)@(.*)$/;
|
|
80
|
+
if (variable.email && emailRegex.test(currentValue)) {
|
|
81
|
+
switch (variable.email) {
|
|
82
|
+
case "ADDRESS":
|
|
83
|
+
return currentValue.split("@")[0];
|
|
84
|
+
case "PROVIDER":
|
|
85
|
+
return currentValue.split("@")[1];
|
|
86
|
+
default:
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (variable.fragment &&
|
|
90
|
+
typeof variable.fragment.from === "number" &&
|
|
91
|
+
typeof variable.fragment.to === "number") {
|
|
92
|
+
var _a = variable.fragment, from = _a.from, to = _a.to;
|
|
93
|
+
return currentValue.slice(from, to);
|
|
94
|
+
}
|
|
95
|
+
return currentValue;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return "";
|
|
99
|
+
};
|
|
100
|
+
FillPdfForm.prototype.getBoxValue = function (box) {
|
|
101
|
+
for (var i = 0; i < box.options.length; i += 1) {
|
|
102
|
+
var option = box.options[i];
|
|
103
|
+
var currentValue = this.getOptionValue(option.id);
|
|
104
|
+
if (currentValue === true) {
|
|
105
|
+
if (this.references.options[option.id].meta.type === "checkbox" &&
|
|
106
|
+
box.value === "Off")
|
|
107
|
+
return "On";
|
|
108
|
+
return box.value;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return "";
|
|
112
|
+
};
|
|
113
|
+
FillPdfForm.prototype.getVariableValue = function (variableId) {
|
|
114
|
+
var _a;
|
|
115
|
+
if (this.isVariableDisplayed(variableId, 0) === false)
|
|
116
|
+
return false;
|
|
117
|
+
return (((_a = this.ovc.variables[variableId]) === null || _a === void 0 ? void 0 : _a[0]) || "").toString();
|
|
118
|
+
};
|
|
119
|
+
FillPdfForm.prototype.getOptionValue = function (optionId) {
|
|
120
|
+
var _a;
|
|
121
|
+
if (this.isOptionDisplayed(optionId, 0) === false)
|
|
122
|
+
return false;
|
|
123
|
+
return ((_a = this.ovc.options[optionId]) === null || _a === void 0 ? void 0 : _a[0]) === true;
|
|
124
|
+
};
|
|
125
|
+
return FillPdfForm;
|
|
126
|
+
}(FillPdfFormBase_1.default));
|
|
127
|
+
exports.default = FillPdfForm;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Types } from "@legalplace/referencesparser";
|
|
2
|
+
type References = Types.ReferencesType;
|
|
3
|
+
type OVC_TYPE = {
|
|
4
|
+
options: {
|
|
5
|
+
[key: string]: boolean[];
|
|
6
|
+
};
|
|
7
|
+
variables: {
|
|
8
|
+
[key: string]: (number | string)[];
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
declare class IntputsInitiator {
|
|
12
|
+
private inputs;
|
|
13
|
+
private references;
|
|
14
|
+
private ovc;
|
|
15
|
+
constructor(references: References, ovc: OVC_TYPE | null);
|
|
16
|
+
getInputs(): OVC_TYPE;
|
|
17
|
+
private setMultiples;
|
|
18
|
+
private initOptionsInputs;
|
|
19
|
+
private initVariablesInputs;
|
|
20
|
+
}
|
|
21
|
+
export default IntputsInitiator;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var IntputsInitiator = (function () {
|
|
4
|
+
function IntputsInitiator(references, ovc) {
|
|
5
|
+
this.inputs = {
|
|
6
|
+
options: {},
|
|
7
|
+
variables: {},
|
|
8
|
+
};
|
|
9
|
+
this.references = references;
|
|
10
|
+
this.ovc = ovc;
|
|
11
|
+
this.setMultiples();
|
|
12
|
+
this.initOptionsInputs();
|
|
13
|
+
this.initVariablesInputs();
|
|
14
|
+
}
|
|
15
|
+
IntputsInitiator.prototype.getInputs = function () {
|
|
16
|
+
return this.inputs;
|
|
17
|
+
};
|
|
18
|
+
IntputsInitiator.prototype.setMultiples = function () {
|
|
19
|
+
var _this = this;
|
|
20
|
+
if (this.ovc === null)
|
|
21
|
+
return;
|
|
22
|
+
Object.keys(this.ovc.options).forEach(function (id) {
|
|
23
|
+
if (_this.ovc === null)
|
|
24
|
+
return;
|
|
25
|
+
var inputs = _this.ovc.options[id];
|
|
26
|
+
if (inputs.length > 1) {
|
|
27
|
+
var parentsTree = _this.references.relations.options[id].parents;
|
|
28
|
+
var rootOptionId = parentsTree.length > 0 ? parentsTree[parentsTree.length - 1] : id;
|
|
29
|
+
if (!_this.ovc.options[rootOptionId]) {
|
|
30
|
+
var rootReference = _this.references.options[rootOptionId];
|
|
31
|
+
if (rootReference.meta.type === "static") {
|
|
32
|
+
_this.ovc.options[rootOptionId] = new Array(inputs.length).fill(true);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
IntputsInitiator.prototype.initOptionsInputs = function () {
|
|
39
|
+
var optionsIds = Object.keys(this.references.options);
|
|
40
|
+
for (var i = 0; i < optionsIds.length; i += 1) {
|
|
41
|
+
var optionId = optionsIds[i];
|
|
42
|
+
var option = this.references.options[optionId];
|
|
43
|
+
var values = [false];
|
|
44
|
+
if (this.ovc &&
|
|
45
|
+
Object.prototype.hasOwnProperty.call(this.ovc.options, optionId)) {
|
|
46
|
+
if ([
|
|
47
|
+
"static",
|
|
48
|
+
"hidden",
|
|
49
|
+
"brut-text",
|
|
50
|
+
"repeated",
|
|
51
|
+
"box",
|
|
52
|
+
"separator",
|
|
53
|
+
].includes(option.meta.type)) {
|
|
54
|
+
values = new Array(this.ovc.options[optionId].length).fill(true);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
values = this.ovc.options[optionId];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else if ([
|
|
61
|
+
"static",
|
|
62
|
+
"hidden",
|
|
63
|
+
"brut-text",
|
|
64
|
+
"repeated",
|
|
65
|
+
"box",
|
|
66
|
+
"separator",
|
|
67
|
+
].includes(option.meta.type)) {
|
|
68
|
+
values = [true];
|
|
69
|
+
}
|
|
70
|
+
this.inputs.options[optionId] = values;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
IntputsInitiator.prototype.initVariablesInputs = function () {
|
|
74
|
+
var variablesIds = Object.keys(this.references.variables);
|
|
75
|
+
for (var i = 0; i < variablesIds.length; i += 1) {
|
|
76
|
+
var variableId = variablesIds[i];
|
|
77
|
+
var values = [""];
|
|
78
|
+
if (this.ovc &&
|
|
79
|
+
Object.prototype.hasOwnProperty.call(this.ovc.variables, variableId)) {
|
|
80
|
+
values = this.ovc.variables[variableId];
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
var defaultValue = "";
|
|
84
|
+
var prefillings = this.references.variables[variableId].prefillings;
|
|
85
|
+
if (prefillings &&
|
|
86
|
+
Array.isArray(prefillings) &&
|
|
87
|
+
prefillings.length > 0) {
|
|
88
|
+
var noConditionsPrefills = prefillings.filter(function (prefill) {
|
|
89
|
+
return typeof prefill.conditions === "undefined" ||
|
|
90
|
+
Object.keys(prefill.conditions).length === 0;
|
|
91
|
+
});
|
|
92
|
+
defaultValue =
|
|
93
|
+
noConditionsPrefills.length > 0
|
|
94
|
+
? noConditionsPrefills[0].value
|
|
95
|
+
: "";
|
|
96
|
+
}
|
|
97
|
+
values = [defaultValue];
|
|
98
|
+
}
|
|
99
|
+
this.inputs.variables[variableId] = values;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
return IntputsInitiator;
|
|
103
|
+
}());
|
|
104
|
+
exports.default = IntputsInitiator;
|
|
@@ -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 type { Types } from "@legalplace/referencesparser";
|
|
2
|
+
import type ConditionsRunner from "@legalplace/conditions-runner";
|
|
3
|
+
import type InputsType from "@legalplace/types/dist/inputs";
|
|
4
|
+
import type 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: InputsType;
|
|
12
|
+
private NumAuto;
|
|
13
|
+
constructor(options: {
|
|
14
|
+
references: Types.ReferencesType;
|
|
15
|
+
conditions: ConditionsRunner;
|
|
16
|
+
ovc: InputsType;
|
|
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,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
var OutputParser_1 = require("./OutputParser");
|
|
13
|
+
var OptionRender = (function () {
|
|
14
|
+
function OptionRender(options) {
|
|
15
|
+
this.outputs = [];
|
|
16
|
+
this.references = options.references;
|
|
17
|
+
this.conditions = options.conditions;
|
|
18
|
+
this.index = options.index;
|
|
19
|
+
this.id = options.id;
|
|
20
|
+
this.ovc = options.ovc;
|
|
21
|
+
this.NumAuto = options.numauto;
|
|
22
|
+
this.renderOption();
|
|
23
|
+
}
|
|
24
|
+
OptionRender.prototype.getOutputs = function () {
|
|
25
|
+
return this.outputs;
|
|
26
|
+
};
|
|
27
|
+
OptionRender.prototype.renderOption = function () {
|
|
28
|
+
var _this = this;
|
|
29
|
+
var option = this.references.options[this.id];
|
|
30
|
+
var conditionObject = this.references.conditions.options[this.id];
|
|
31
|
+
var condition = conditionObject === undefined
|
|
32
|
+
? true
|
|
33
|
+
: this.conditions.executeCondition(conditionObject, this.id, this.index, "options");
|
|
34
|
+
if (condition === true) {
|
|
35
|
+
if (typeof option.meta.output === "string" &&
|
|
36
|
+
option.meta.output.trim().length > 0) {
|
|
37
|
+
var outputReference = this.references.outputs[this.id];
|
|
38
|
+
var autonums = [];
|
|
39
|
+
if (condition !== false) {
|
|
40
|
+
autonums = outputReference.autonums.map(function (currentAn) {
|
|
41
|
+
var fn = currentAn[0] === "numauto-pre"
|
|
42
|
+
? _this.NumAuto.getNumPre
|
|
43
|
+
: _this.NumAuto.getNum;
|
|
44
|
+
return [
|
|
45
|
+
currentAn[0],
|
|
46
|
+
currentAn[1],
|
|
47
|
+
fn(currentAn[1], currentAn[2]),
|
|
48
|
+
currentAn[2],
|
|
49
|
+
];
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
var variables = (0, OutputParser_1.getRelatedVariablesValues)(this.id, this.index, outputReference.variables, this.ovc, this.references);
|
|
53
|
+
var output = (0, OutputParser_1.parseOutputWithVariables)(option.meta.output, this.index, variables, autonums);
|
|
54
|
+
output = output.replace(/<\/([a-z]+)>([\n\s]+)</gi, "</$1><");
|
|
55
|
+
output = output.replace(/\n/g, "<br />");
|
|
56
|
+
output = output.replace(/\xA0/g, " ");
|
|
57
|
+
this.outputs.push(output);
|
|
58
|
+
}
|
|
59
|
+
this.renderChildren();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
OptionRender.prototype.renderChildren = function () {
|
|
63
|
+
var _this = this;
|
|
64
|
+
var option = this.references.options[this.id];
|
|
65
|
+
option.options.forEach(function (optionId) {
|
|
66
|
+
_this.outputs = __spreadArray(__spreadArray([], _this.outputs, true), new OptionRender({
|
|
67
|
+
references: _this.references,
|
|
68
|
+
id: optionId,
|
|
69
|
+
ovc: _this.ovc,
|
|
70
|
+
index: _this.index,
|
|
71
|
+
conditions: _this.conditions,
|
|
72
|
+
numauto: _this.NumAuto,
|
|
73
|
+
}).getOutputs(), true);
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
return OptionRender;
|
|
77
|
+
}());
|
|
78
|
+
exports.default = OptionRender;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Types } from "@legalplace/referencesparser";
|
|
2
|
+
import type InputsType from "@legalplace/types/dist/inputs";
|
|
3
|
+
type relVarsValsT = Record<string, string | number>;
|
|
4
|
+
type getRelatedVarsT = (optionId: number, index: number, variables: number[], ovc: InputsType, references: Types.ReferencesType) => relVarsValsT;
|
|
5
|
+
export declare const getRelatedVariablesValues: getRelatedVarsT;
|
|
6
|
+
type autonumsType = [string, string, number, string | null][];
|
|
7
|
+
type parseOutputT = (output: string, index: number, variables: relVarsValsT, autonums: autonumsType) => string;
|
|
8
|
+
export declare const parseOutputWithVariables: parseOutputT;
|
|
9
|
+
type TParseDocumentNameWithVariables = (text: string, ovc: InputsType, references: Types.ReferencesType, fallback?: string) => string;
|
|
10
|
+
export declare const parseDocumentNameWithVariables: TParseDocumentNameWithVariables;
|
|
11
|
+
export {};
|
|
@@ -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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
14
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
15
|
+
if (ar || !(i in from)) {
|
|
16
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
17
|
+
ar[i] = from[i];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.parseDocumentNameWithVariables = exports.parseOutputWithVariables = exports.getRelatedVariablesValues = void 0;
|
|
24
|
+
var yousign_1 = require("@legalplace/yousign");
|
|
25
|
+
var frenchNumber = function (value) {
|
|
26
|
+
var result = typeof value === "number" ? value.toString() : value;
|
|
27
|
+
if (/^([0-9]+)\.([0-9]+)$/.test(result.trim()))
|
|
28
|
+
result = result.trim().replace(".", ",");
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
var getRelatedVariablesValues = function (optionId, index, variables, ovc, references) {
|
|
32
|
+
var variablesValues = {};
|
|
33
|
+
variables.forEach(function (currentVariableId) {
|
|
34
|
+
var value = ovc.variables[currentVariableId] || [""];
|
|
35
|
+
var variableParents = references.relations.variables[currentVariableId].parents;
|
|
36
|
+
if (variableParents === undefined)
|
|
37
|
+
throw new Error("Variable ".concat(currentVariableId, " parents object does not exist"));
|
|
38
|
+
var rootVariableParentId = variableParents[variableParents.length - 1];
|
|
39
|
+
var rootVariableParentRelations = references.relations.options[rootVariableParentId];
|
|
40
|
+
if (rootVariableParentRelations === undefined)
|
|
41
|
+
throw new Error("Option ".concat(rootVariableParentId, " does not exist"));
|
|
42
|
+
if (typeof variableParents === "undefined")
|
|
43
|
+
return;
|
|
44
|
+
if (rootVariableParentRelations.children.options.includes(optionId) ||
|
|
45
|
+
rootVariableParentRelations.dependants.includes(optionId) ||
|
|
46
|
+
optionId === rootVariableParentId)
|
|
47
|
+
value = [value[index]];
|
|
48
|
+
var cleanValues = value.map(function (currentValue) {
|
|
49
|
+
if (["number", "string"].includes(typeof currentValue))
|
|
50
|
+
return frenchNumber(currentValue);
|
|
51
|
+
return "";
|
|
52
|
+
});
|
|
53
|
+
var currentVariableValue = cleanValues.length === 1 ? cleanValues[0] : cleanValues.join(", ");
|
|
54
|
+
variablesValues[currentVariableId] = currentVariableValue;
|
|
55
|
+
});
|
|
56
|
+
return variablesValues;
|
|
57
|
+
};
|
|
58
|
+
exports.getRelatedVariablesValues = getRelatedVariablesValues;
|
|
59
|
+
var parseOutputWithVariables = function (output, index, variables, autonums) {
|
|
60
|
+
var parsedOutput = "".concat(output);
|
|
61
|
+
Object.keys(variables).forEach(function (variableId) {
|
|
62
|
+
var value = variables[variableId].toString();
|
|
63
|
+
if (value.trim().length === 0) {
|
|
64
|
+
value = new Array(16).join("_");
|
|
65
|
+
}
|
|
66
|
+
value = value.replace(/\n/g, "<br />");
|
|
67
|
+
parsedOutput = parsedOutput.replace(new RegExp("\\[var:".concat(variableId, "\\]"), "g"), value);
|
|
68
|
+
});
|
|
69
|
+
parsedOutput = parsedOutput.replace(/\[\[PAGE_BREAK\]\]/gi, '<div style="page-break-after:always"></div>');
|
|
70
|
+
parsedOutput = parsedOutput.replace(/\[(E|B)_BLUR\]/gi, "");
|
|
71
|
+
parsedOutput = parsedOutput.replace(/\[signature:([0-9]+)\]/g, function (v, signatureId) {
|
|
72
|
+
return "<span data-signature=\"signature\" data-signature-id=\"".concat(signatureId, "\" data-signer-index=\"").concat(index, "\"></span>");
|
|
73
|
+
});
|
|
74
|
+
parsedOutput = parsedOutput.replace(/\[signature:date\]/g, function () { return '<span data-signature="date"></span>'; });
|
|
75
|
+
parsedOutput = parsedOutput.replace(/\[signature:date:([0-9]+)\]/g, function (v, signatureId) {
|
|
76
|
+
return "<span data-signature=\"date\" data-signature-id=\"".concat(signatureId, "\" data-signer-index=\"").concat(index, "\"></span>");
|
|
77
|
+
});
|
|
78
|
+
parsedOutput = parsedOutput.replace(/\[signature:mention:([0-9]+):(?:"|")((?:[^"&]|\\.)*?)(?:"|")\]/g, function (v, signatureId, mention) {
|
|
79
|
+
return "<span data-signature=\"mention\" data-signature-id=\"".concat(signatureId, "\" data-signer-index=\"").concat(index, "\" data-signer-mention=\"").concat(mention, "\"></span>");
|
|
80
|
+
});
|
|
81
|
+
parsedOutput = parsedOutput.replace(/\[date\]/g, function () { return '<span data-signature="date"></span>'; });
|
|
82
|
+
parsedOutput = parsedOutput.replace(new RegExp(yousign_1.yousignTagFieldRegex, "g"), function (v, paramsString) {
|
|
83
|
+
try {
|
|
84
|
+
var parsedParams = (0, yousign_1.parseYousignTag)("[yousign:".concat(paramsString.replace(/((=)")|("(;|$))/g, '$2"$4'), "]"));
|
|
85
|
+
return (0, yousign_1.convertParamsToHtmlTag)(__assign(__assign({}, parsedParams), { signerIndex: index }));
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
console.error("Failed to parse Yousign tag: ".concat(v), error);
|
|
89
|
+
return v;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
autonums.forEach(function (currentAn) {
|
|
93
|
+
if (currentAn[3] === null)
|
|
94
|
+
parsedOutput = parsedOutput.replace("[".concat(currentAn[0], ":").concat(currentAn[1], "]"), "<span class=\"".concat(currentAn[0], "\">").concat(currentAn[2], "</span>"));
|
|
95
|
+
else
|
|
96
|
+
parsedOutput = parsedOutput.replace("[".concat(currentAn[0], ":").concat(currentAn[1], "](").concat(currentAn[3], ")"), "<span class=\"".concat(currentAn[0], "\">").concat(currentAn[2], "</span>"));
|
|
97
|
+
});
|
|
98
|
+
return parsedOutput;
|
|
99
|
+
};
|
|
100
|
+
exports.parseOutputWithVariables = parseOutputWithVariables;
|
|
101
|
+
var parseDocumentNameWithVariables = function (text, ovc, references, fallback) {
|
|
102
|
+
var tagsMatch = text.match(/\[var:([0-9]+)\]/gi);
|
|
103
|
+
var variables = [];
|
|
104
|
+
if (tagsMatch !== null) {
|
|
105
|
+
var variablesTags = __spreadArray([], tagsMatch, true);
|
|
106
|
+
variables = variablesTags.map(function (current) {
|
|
107
|
+
var outputVariableMatch = current.match(/([0-9]+)/);
|
|
108
|
+
if (outputVariableMatch === null)
|
|
109
|
+
return 0;
|
|
110
|
+
return parseInt(outputVariableMatch[0], 10);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
variables = variables.filter(function (c, i) { return variables.indexOf(c) === i; });
|
|
114
|
+
variables = variables.filter(function (c) { return ovc !== undefined || references.variables[c] !== undefined; });
|
|
115
|
+
var variablesValues = {};
|
|
116
|
+
variables.forEach(function (variableId) {
|
|
117
|
+
var _a;
|
|
118
|
+
var value = ((_a = ovc.variables[variableId]) === null || _a === void 0 ? void 0 : _a[0]) || "";
|
|
119
|
+
variablesValues[variableId] = value.toString();
|
|
120
|
+
});
|
|
121
|
+
var parsedText = "".concat(text);
|
|
122
|
+
variables.forEach(function (variableId) {
|
|
123
|
+
var value = variablesValues[variableId];
|
|
124
|
+
if (value.trim().length === 0 && fallback)
|
|
125
|
+
parsedText = fallback;
|
|
126
|
+
if (parsedText === fallback && fallback)
|
|
127
|
+
return;
|
|
128
|
+
parsedText = parsedText.replace(new RegExp("\\[var:".concat(variableId, "\\]"), "gi"), value);
|
|
129
|
+
});
|
|
130
|
+
return parsedText;
|
|
131
|
+
};
|
|
132
|
+
exports.parseDocumentNameWithVariables = parseDocumentNameWithVariables;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ModelV3 } from "@legalplace/models-v3-types";
|
|
2
|
+
import type { Types } from "@legalplace/referencesparser";
|
|
3
|
+
import type OvcType from "@legalplace/types/dist/ovc";
|
|
4
|
+
import type InputsType from "@legalplace/types/dist/inputs";
|
|
5
|
+
import type { FDFType, DocumentIndex, DocumentOutputIndex, DocumentPdfFormIndex } from "../types/types";
|
|
6
|
+
declare class Prerender {
|
|
7
|
+
private references;
|
|
8
|
+
private ovc;
|
|
9
|
+
private conditions;
|
|
10
|
+
private documentRender;
|
|
11
|
+
private pdfFiller;
|
|
12
|
+
private NumAuto;
|
|
13
|
+
private documentsIndex;
|
|
14
|
+
private renderedDocuments;
|
|
15
|
+
constructor(model: ModelV3 | Types.ReferencesType, ovc: InputsType | OvcType);
|
|
16
|
+
getDocumentsIndexWithoutFdf(): DocumentIndex;
|
|
17
|
+
getDocumentsIndex(): DocumentIndex;
|
|
18
|
+
getDocument(documentNameHash: string): string | FDFType;
|
|
19
|
+
private generateDocumentNamesHash;
|
|
20
|
+
private fillPdfForms;
|
|
21
|
+
private generateAllDocuments;
|
|
22
|
+
static isPdfForm(index: DocumentOutputIndex | DocumentPdfFormIndex): index is DocumentPdfFormIndex;
|
|
23
|
+
static isOutput(index: DocumentOutputIndex | DocumentPdfFormIndex): index is DocumentOutputIndex;
|
|
24
|
+
}
|
|
25
|
+
export default Prerender;
|
|
@@ -0,0 +1,116 @@
|
|
|
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 conditions_runner_1 = __importDefault(require("@legalplace/conditions-runner"));
|
|
8
|
+
var ovc_converter_1 = __importDefault(require("@legalplace/ovc-converter"));
|
|
9
|
+
var crypto_1 = __importDefault(require("crypto"));
|
|
10
|
+
var DocumentRender_1 = __importDefault(require("./DocumentRender"));
|
|
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(model, ovc) {
|
|
17
|
+
this.documentsIndex = {};
|
|
18
|
+
this.renderedDocuments = {};
|
|
19
|
+
this.NumAuto = new NumAuto_1.default();
|
|
20
|
+
this.references = referencesparser_1.ReferencesParser.isReferences(model)
|
|
21
|
+
? model
|
|
22
|
+
: new referencesparser_1.ReferencesParser(model).getReferences();
|
|
23
|
+
this.ovc = ovc_converter_1.default.isOvc(ovc)
|
|
24
|
+
? ovc_converter_1.default.convertToOptionsVariables(ovc, this.references)
|
|
25
|
+
: ovc;
|
|
26
|
+
var inputs = new InputsInitiator_1.default(this.references, this.ovc).getInputs();
|
|
27
|
+
this.conditions = new conditions_runner_1.default(this.references, inputs);
|
|
28
|
+
this.documentRender = new DocumentRender_1.default(this.references, this.conditions, inputs, this.NumAuto);
|
|
29
|
+
this.pdfFiller = new FillPdfForm_1.default(this.references, this.conditions, inputs);
|
|
30
|
+
this.generateDocumentNamesHash();
|
|
31
|
+
}
|
|
32
|
+
Prerender.prototype.getDocumentsIndexWithoutFdf = function () {
|
|
33
|
+
return this.documentsIndex;
|
|
34
|
+
};
|
|
35
|
+
Prerender.prototype.getDocumentsIndex = function () {
|
|
36
|
+
this.generateAllDocuments();
|
|
37
|
+
this.fillPdfForms();
|
|
38
|
+
return this.documentsIndex;
|
|
39
|
+
};
|
|
40
|
+
Prerender.prototype.getDocument = function (documentNameHash) {
|
|
41
|
+
if (this.renderedDocuments[documentNameHash]) {
|
|
42
|
+
return this.renderedDocuments[documentNameHash];
|
|
43
|
+
}
|
|
44
|
+
var index = this.documentsIndex[documentNameHash];
|
|
45
|
+
this.renderedDocuments[documentNameHash] = Prerender.isPdfForm(index)
|
|
46
|
+
? this.pdfFiller.fillDocument(index.slug)
|
|
47
|
+
: this.documentRender.renderDocument(index.slug);
|
|
48
|
+
return this.renderedDocuments[documentNameHash];
|
|
49
|
+
};
|
|
50
|
+
Prerender.prototype.generateDocumentNamesHash = function () {
|
|
51
|
+
var _this = this;
|
|
52
|
+
Object.keys(this.references.documents).forEach(function (slug) {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
var document = _this.references.documents[slug];
|
|
55
|
+
var documentParams = _this.references.documents[slug].params;
|
|
56
|
+
var conditionObject = _this.references.conditions.documents[slug];
|
|
57
|
+
var condition = conditionObject === undefined
|
|
58
|
+
? true
|
|
59
|
+
: _this.conditions.executeCondition(conditionObject, 0, 0, "documents");
|
|
60
|
+
if (condition === true) {
|
|
61
|
+
var hash = crypto_1.default.createHash("sha1").update(slug).digest("hex");
|
|
62
|
+
if (typeof document.pdf === "object" &&
|
|
63
|
+
typeof document.pdf.id === "string" &&
|
|
64
|
+
typeof document.pdf.form === "object") {
|
|
65
|
+
_this.documentsIndex[hash] = {
|
|
66
|
+
name: (0, OutputParser_1.parseDocumentNameWithVariables)(document.name, _this.ovc, _this.references, document.fallbackName),
|
|
67
|
+
slug: slug,
|
|
68
|
+
form: true,
|
|
69
|
+
fdf: {
|
|
70
|
+
id: "",
|
|
71
|
+
fields: {},
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
_this.documentsIndex[hash] = {
|
|
77
|
+
name: (0, OutputParser_1.parseDocumentNameWithVariables)(document.name, _this.ovc, _this.references, document.fallbackName),
|
|
78
|
+
slug: slug,
|
|
79
|
+
pdf: ((_a = documentParams === null || documentParams === void 0 ? void 0 : documentParams.formats) === null || _a === void 0 ? void 0 : _a.pdf) !== false,
|
|
80
|
+
docx: ((_b = documentParams === null || documentParams === void 0 ? void 0 : documentParams.formats) === null || _b === void 0 ? void 0 : _b.docx) !== false,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
Prerender.prototype.fillPdfForms = function () {
|
|
87
|
+
var _this = this;
|
|
88
|
+
Object.keys(this.documentsIndex).forEach(function (documentNameHash) {
|
|
89
|
+
var index = _this.documentsIndex[documentNameHash];
|
|
90
|
+
if (Prerender.isPdfForm(index)) {
|
|
91
|
+
index.fdf = _this.getDocument(documentNameHash);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
Prerender.prototype.generateAllDocuments = function () {
|
|
96
|
+
var _this = this;
|
|
97
|
+
Object.keys(this.documentsIndex).forEach(function (documentNameHash) {
|
|
98
|
+
var index = _this.documentsIndex[documentNameHash];
|
|
99
|
+
if (Prerender.isPdfForm(index)) {
|
|
100
|
+
_this.renderedDocuments[documentNameHash] = _this.pdfFiller.fillDocument(_this.documentsIndex[documentNameHash].slug);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
_this.renderedDocuments[documentNameHash] =
|
|
104
|
+
_this.documentRender.renderDocument(_this.documentsIndex[documentNameHash].slug);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
Prerender.isPdfForm = function (index) {
|
|
109
|
+
return Object.prototype.hasOwnProperty.call(index, "form");
|
|
110
|
+
};
|
|
111
|
+
Prerender.isOutput = function (index) {
|
|
112
|
+
return !Object.prototype.hasOwnProperty.call(index, "form");
|
|
113
|
+
};
|
|
114
|
+
return Prerender;
|
|
115
|
+
}());
|
|
116
|
+
exports.default = Prerender;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Types } from "@legalplace/referencesparser";
|
|
2
|
+
import type ConditionsRunner from "@legalplace/conditions-runner";
|
|
3
|
+
import type InputsType from "@legalplace/types/dist/inputs";
|
|
4
|
+
import type 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: InputsType;
|
|
12
|
+
private NumAuto;
|
|
13
|
+
constructor(options: {
|
|
14
|
+
references: Types.ReferencesType;
|
|
15
|
+
conditions: ConditionsRunner;
|
|
16
|
+
ovc: InputsType;
|
|
17
|
+
documentName: string;
|
|
18
|
+
currentSection: number;
|
|
19
|
+
numauto: NumAuto;
|
|
20
|
+
});
|
|
21
|
+
getOutputs(): string[];
|
|
22
|
+
private renderSection;
|
|
23
|
+
}
|
|
24
|
+
export default SectionRender;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
var OptionRender_1 = __importDefault(require("./OptionRender"));
|
|
16
|
+
var SectionRender = (function () {
|
|
17
|
+
function SectionRender(options) {
|
|
18
|
+
this.outputs = [];
|
|
19
|
+
this.references = options.references;
|
|
20
|
+
this.conditions = options.conditions;
|
|
21
|
+
this.documentName = options.documentName;
|
|
22
|
+
this.currentSection = options.currentSection;
|
|
23
|
+
this.ovc = options.ovc;
|
|
24
|
+
this.NumAuto = options.numauto;
|
|
25
|
+
this.renderSection();
|
|
26
|
+
}
|
|
27
|
+
SectionRender.prototype.getOutputs = function () {
|
|
28
|
+
return this.outputs;
|
|
29
|
+
};
|
|
30
|
+
SectionRender.prototype.renderSection = function () {
|
|
31
|
+
var _this = this;
|
|
32
|
+
var section = this.references.sections[this.documentName][this.currentSection];
|
|
33
|
+
var conditionObject = this.references.conditions.sections[this.documentName][this.currentSection];
|
|
34
|
+
var condition = conditionObject === undefined
|
|
35
|
+
? true
|
|
36
|
+
: this.conditions.executeCondition(conditionObject, 0, 0, "sections");
|
|
37
|
+
if (condition === true) {
|
|
38
|
+
section.options.forEach(function (optionId) {
|
|
39
|
+
var option = _this.references.options[optionId];
|
|
40
|
+
var repeatOption = optionId;
|
|
41
|
+
if (option.meta.type === "repeated") {
|
|
42
|
+
if (option.meta.repeatOption === undefined)
|
|
43
|
+
return;
|
|
44
|
+
repeatOption =
|
|
45
|
+
typeof option.meta.repeatOption === "number"
|
|
46
|
+
? option.meta.repeatOption
|
|
47
|
+
: parseInt(option.meta.repeatOption, 10);
|
|
48
|
+
}
|
|
49
|
+
var inputs = _this.ovc.options[repeatOption] || [
|
|
50
|
+
!["radio", "checkbox"].includes(option.meta.type),
|
|
51
|
+
];
|
|
52
|
+
inputs.forEach(function (value, index) {
|
|
53
|
+
if (value !== true)
|
|
54
|
+
return;
|
|
55
|
+
_this.outputs = __spreadArray(__spreadArray([], _this.outputs, true), new OptionRender_1.default({
|
|
56
|
+
references: _this.references,
|
|
57
|
+
id: optionId,
|
|
58
|
+
ovc: _this.ovc,
|
|
59
|
+
index: index,
|
|
60
|
+
conditions: _this.conditions,
|
|
61
|
+
numauto: _this.NumAuto,
|
|
62
|
+
}).getOutputs(), true);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
return SectionRender;
|
|
68
|
+
}());
|
|
69
|
+
exports.default = SectionRender;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Types } from "@legalplace/referencesparser";
|
|
2
|
+
import type ConditionsRunner from "@legalplace/conditions-runner";
|
|
3
|
+
import type InputsType from "@legalplace/types/dist/inputs";
|
|
4
|
+
declare class FillPdfFormBase {
|
|
5
|
+
references: Types.ReferencesType;
|
|
6
|
+
conditions: ConditionsRunner;
|
|
7
|
+
ovc: InputsType;
|
|
8
|
+
constructor(references: Types.ReferencesType, conditions: ConditionsRunner, ovc: InputsType);
|
|
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;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
var FillPdfFormBase = (function () {
|
|
13
|
+
function FillPdfFormBase(references, conditions, ovc) {
|
|
14
|
+
this.references = references;
|
|
15
|
+
this.conditions = conditions;
|
|
16
|
+
this.ovc = ovc;
|
|
17
|
+
}
|
|
18
|
+
FillPdfFormBase.prototype.isVariableDisplayed = function (id, index) {
|
|
19
|
+
var _a;
|
|
20
|
+
var variableCondition = this.getVariableCondition(id, index);
|
|
21
|
+
var variableParents = ((_a = this.references.relations.variables[id]) === null || _a === void 0 ? void 0 : _a.parents) || [];
|
|
22
|
+
var parentOptionIsDisplayed = this.isOptionDisplayed(variableParents[0], index);
|
|
23
|
+
return ([variableCondition, parentOptionIsDisplayed].filter(function (c) { return c !== true; })
|
|
24
|
+
.length === 0);
|
|
25
|
+
};
|
|
26
|
+
FillPdfFormBase.prototype.isOptionDisplayed = function (id, index) {
|
|
27
|
+
var _this = this;
|
|
28
|
+
var _a;
|
|
29
|
+
var optionCondition = this.getOptionCondition(id, index);
|
|
30
|
+
var optionParents = ((_a = this.references.relations.options[id]) === null || _a === void 0 ? void 0 : _a.parents) || [];
|
|
31
|
+
var parentsConditions = optionParents.map(function (optionId) { return _this.getOptionCondition(optionId, index) !== false; });
|
|
32
|
+
var parentsInputs = optionParents.map(function (optionId) { return _this.ovc.options[optionId][index]; });
|
|
33
|
+
var parentSectionId = this.getOptionParentSection(id);
|
|
34
|
+
var parentSectionCondition = this.getSectionCondition(parentSectionId) !== false;
|
|
35
|
+
return (__spreadArray(__spreadArray([
|
|
36
|
+
optionCondition,
|
|
37
|
+
parentSectionCondition
|
|
38
|
+
], parentsConditions, true), parentsInputs, true).filter(function (c) { return c !== true; }).length === 0);
|
|
39
|
+
};
|
|
40
|
+
FillPdfFormBase.prototype.getVariableCondition = function (id, index) {
|
|
41
|
+
var conditionObject = this.references.conditions.variables[id];
|
|
42
|
+
return conditionObject === undefined
|
|
43
|
+
? true
|
|
44
|
+
: this.conditions.executeCondition(conditionObject, id, index, "variables");
|
|
45
|
+
};
|
|
46
|
+
FillPdfFormBase.prototype.getOptionCondition = function (id, index) {
|
|
47
|
+
var conditionObject = this.references.conditions.options[id];
|
|
48
|
+
return conditionObject === undefined
|
|
49
|
+
? true
|
|
50
|
+
: this.conditions.executeCondition(conditionObject, id, index, "options");
|
|
51
|
+
};
|
|
52
|
+
FillPdfFormBase.prototype.getSectionCondition = function (id) {
|
|
53
|
+
var conditionObject = this.references.conditions.sections.main[id];
|
|
54
|
+
return conditionObject === undefined
|
|
55
|
+
? true
|
|
56
|
+
: this.conditions.executeCondition(conditionObject, id, 0, "sections");
|
|
57
|
+
};
|
|
58
|
+
FillPdfFormBase.prototype.getOptionParentSection = function (id) {
|
|
59
|
+
var parents = this.references.relations.options[id].parents;
|
|
60
|
+
var rootId = parents.length > 0 ? parents[parents.length - 1] : id;
|
|
61
|
+
var sections = Object.values(this.references.sections.main);
|
|
62
|
+
for (var i = 0; i < sections.length; i += 1) {
|
|
63
|
+
if (sections[i].options.includes(rootId))
|
|
64
|
+
return sections[i].id;
|
|
65
|
+
}
|
|
66
|
+
throw new Error("Cannot find parent section for option ".concat(id, " (Root option id: ").concat(rootId, ")"));
|
|
67
|
+
};
|
|
68
|
+
return FillPdfFormBase;
|
|
69
|
+
}());
|
|
70
|
+
exports.default = FillPdfFormBase;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type DocumentOutputIndex = {
|
|
2
|
+
name: string;
|
|
3
|
+
slug: string;
|
|
4
|
+
pdf: boolean;
|
|
5
|
+
docx: boolean;
|
|
6
|
+
};
|
|
7
|
+
export type DocumentPdfFormIndex = {
|
|
8
|
+
name: string;
|
|
9
|
+
slug: string;
|
|
10
|
+
form: boolean;
|
|
11
|
+
fdf: FDFType;
|
|
12
|
+
};
|
|
13
|
+
export type DocumentIndex = Record<string, DocumentOutputIndex | DocumentPdfFormIndex>;
|
|
14
|
+
export type FDFType = {
|
|
15
|
+
id: string;
|
|
16
|
+
fields: Record<string, string>;
|
|
17
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@legalplace/prerenderx",
|
|
3
|
-
"version": "3.8.2
|
|
3
|
+
"version": "3.8.2",
|
|
4
4
|
"description": "PrerenderX",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": "https://git.legalplace.eu/legalplace/prerenderx",
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
"release": "standard-version -a --no-verify"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@legalplace/conditions-runner": "^2.
|
|
19
|
+
"@legalplace/conditions-runner": "^2.2.0",
|
|
20
20
|
"@legalplace/eslint-config-base": "^1.2.0",
|
|
21
|
-
"@legalplace/lplogic": "2.
|
|
22
|
-
"@legalplace/models-v3-types": "^5.
|
|
23
|
-
"@legalplace/ovc-converter": "^2.
|
|
21
|
+
"@legalplace/lplogic": "2.3.1",
|
|
22
|
+
"@legalplace/models-v3-types": "^5.16.0",
|
|
23
|
+
"@legalplace/ovc-converter": "^2.2.0",
|
|
24
24
|
"@legalplace/prettier-config": "^2.1.3",
|
|
25
|
-
"@legalplace/referencesparser": "^3.
|
|
25
|
+
"@legalplace/referencesparser": "^3.2.0",
|
|
26
26
|
"@legalplace/yousign": "^0.8.1",
|
|
27
27
|
"crypto": "^1.0.1",
|
|
28
28
|
"standard-version": "^9.3.1"
|
|
@@ -36,5 +36,6 @@
|
|
|
36
36
|
"redux-mock-store": "^1.5.3",
|
|
37
37
|
"ts-jest": "^24.0.2"
|
|
38
38
|
},
|
|
39
|
-
"prettier": "@legalplace/prettier-config"
|
|
39
|
+
"prettier": "@legalplace/prettier-config",
|
|
40
|
+
"gitHead": "c2ecbc53d3a74ecc7b17893b30880a85a5dc7e62"
|
|
40
41
|
}
|