@legalplace/prerenderx 3.8.24-staging.0 → 3.8.24
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/libs/DocumentRender.d.ts +2 -3
- package/dist/libs/DocumentRender.js +4 -13
- package/dist/libs/FillPdfForm.d.ts +1 -1
- package/dist/libs/FillPdfForm.js +15 -25
- package/dist/libs/OptionRender.d.ts +0 -4
- package/dist/libs/OptionRender.js +29 -125
- package/dist/libs/OutputParser.d.ts +1 -1
- package/dist/libs/OutputParser.js +6 -18
- package/dist/libs/Prerender.d.ts +2 -5
- package/dist/libs/Prerender.js +27 -100
- package/dist/libs/SectionRender.d.ts +0 -3
- package/dist/libs/SectionRender.js +22 -64
- package/dist/libs/misc/FillPdfFormBase.d.ts +1 -1
- package/dist/libs/misc/FillPdfFormBase.js +37 -11
- package/dist/types/types.d.ts +0 -13
- package/package.json +10 -9
- package/src/libs/DocumentRender.ts +5 -33
- package/src/libs/FillPdfForm.ts +22 -39
- package/src/libs/OptionRender.ts +63 -218
- package/src/libs/OutputParser.ts +9 -40
- package/src/libs/Prerender.ts +38 -157
- package/src/libs/SectionRender.ts +28 -111
- package/src/libs/misc/FillPdfFormBase.ts +67 -34
- package/src/types/types.ts +0 -27
- package/.yalc/@legalplace/models-v3-types/.eslintrc +0 -3
- package/.yalc/@legalplace/models-v3-types/.gitlab-ci.yml +0 -30
- package/.yalc/@legalplace/models-v3-types/CHANGELOG.md +0 -1503
- package/.yalc/@legalplace/models-v3-types/README +0 -6
- package/.yalc/@legalplace/models-v3-types/index.ts +0 -915
- package/.yalc/@legalplace/models-v3-types/package.json +0 -16
- package/.yalc/@legalplace/models-v3-types/schema.json +0 -2918
- package/.yalc/@legalplace/models-v3-types/tsconfig.json +0 -22
- package/.yalc/@legalplace/models-v3-types/yalc.sig +0 -1
- package/dist/libs/outputTableRendering.d.ts +0 -16
- package/dist/libs/outputTableRendering.js +0 -130
- package/dist/libs/regionHelpers.d.ts +0 -5
- package/dist/libs/regionHelpers.js +0 -22
- package/dist/libs/tableOutputExpansion.d.ts +0 -20
- package/dist/libs/tableOutputExpansion.js +0 -68
- package/src/libs/tableOutputExpansion.ts +0 -145
- package/tests/Prerender.documentMultiple.test.ts +0 -276
- package/tests/Prerender.repeated.test.ts +0 -115
- package/yalc.lock +0 -10
|
@@ -17,13 +17,6 @@ class SectionRender {
|
|
|
17
17
|
|
|
18
18
|
ovc: InputsType;
|
|
19
19
|
|
|
20
|
-
/**
|
|
21
|
-
* Occurrence index injected by the parent DocumentRender when the document
|
|
22
|
-
* is multiple (`params.multiple.enabled === true`). For non-multiple
|
|
23
|
-
* documents this is always 0.
|
|
24
|
-
*/
|
|
25
|
-
baseIndex: number;
|
|
26
|
-
|
|
27
20
|
private NumAuto: NumAuto;
|
|
28
21
|
|
|
29
22
|
constructor(options: {
|
|
@@ -33,7 +26,6 @@ class SectionRender {
|
|
|
33
26
|
documentName: string;
|
|
34
27
|
currentSection: number;
|
|
35
28
|
numauto: NumAuto;
|
|
36
|
-
baseIndex?: number;
|
|
37
29
|
}) {
|
|
38
30
|
this.references = options.references;
|
|
39
31
|
this.conditions = options.conditions;
|
|
@@ -41,7 +33,6 @@ class SectionRender {
|
|
|
41
33
|
this.currentSection = options.currentSection;
|
|
42
34
|
this.ovc = options.ovc;
|
|
43
35
|
this.NumAuto = options.numauto;
|
|
44
|
-
this.baseIndex = options.baseIndex ?? 0;
|
|
45
36
|
|
|
46
37
|
this.renderSection();
|
|
47
38
|
}
|
|
@@ -50,19 +41,6 @@ class SectionRender {
|
|
|
50
41
|
return this.outputs;
|
|
51
42
|
}
|
|
52
43
|
|
|
53
|
-
/**
|
|
54
|
-
* Returns the multiple source option id for the current document if any.
|
|
55
|
-
* Returns `undefined` for non-multiple documents.
|
|
56
|
-
*/
|
|
57
|
-
private getDocumentMultipleSource(): number | undefined {
|
|
58
|
-
const docMultiple =
|
|
59
|
-
this.references.documents[this.documentName]?.params?.multiple;
|
|
60
|
-
if (docMultiple?.enabled !== true) return undefined;
|
|
61
|
-
return typeof docMultiple.repeatOption === "number"
|
|
62
|
-
? docMultiple.repeatOption
|
|
63
|
-
: undefined;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
44
|
private renderSection() {
|
|
67
45
|
const section =
|
|
68
46
|
this.references.sections[this.documentName][this.currentSection];
|
|
@@ -73,106 +51,45 @@ class SectionRender {
|
|
|
73
51
|
const condition =
|
|
74
52
|
conditionObject === undefined
|
|
75
53
|
? true
|
|
76
|
-
: this.conditions.executeCondition(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
54
|
+
: this.conditions.executeCondition(conditionObject, 0, 0, "sections");
|
|
55
|
+
|
|
56
|
+
// Rendering documents sections
|
|
57
|
+
if (condition === true) {
|
|
58
|
+
section.options.forEach((optionId) => {
|
|
59
|
+
const option = this.references.options[optionId];
|
|
60
|
+
let repeatOption = optionId;
|
|
61
|
+
if (option.meta.type === "repeated") {
|
|
62
|
+
if (option.meta.repeatOption === undefined) return;
|
|
63
|
+
repeatOption =
|
|
64
|
+
typeof option.meta.repeatOption === "number"
|
|
65
|
+
? option.meta.repeatOption
|
|
66
|
+
: parseInt(option.meta.repeatOption, 10);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Option inputs
|
|
70
|
+
const inputs = this.ovc.options[repeatOption] || [
|
|
71
|
+
!["radio", "checkbox"].includes(option.meta.type),
|
|
72
|
+
]; // Falling back on a single value array if option doesn't exist in ovc
|
|
73
|
+
|
|
74
|
+
// Looping through inputs
|
|
75
|
+
inputs.forEach((value, index) => {
|
|
76
|
+
// If value is false we stop here
|
|
77
|
+
if (value !== true) return;
|
|
78
|
+
|
|
101
79
|
this.outputs = [
|
|
102
80
|
...this.outputs,
|
|
103
81
|
...new OptionRender({
|
|
104
82
|
references: this.references,
|
|
105
|
-
id:
|
|
83
|
+
id: optionId,
|
|
106
84
|
ovc: this.ovc,
|
|
107
|
-
index
|
|
85
|
+
index,
|
|
108
86
|
conditions: this.conditions,
|
|
109
87
|
numauto: this.NumAuto,
|
|
110
88
|
}).getOutputs(),
|
|
111
89
|
];
|
|
112
90
|
});
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
let repeatOption = optionId;
|
|
117
|
-
if (option.meta.type === "repeated") {
|
|
118
|
-
if (option.meta.repeatOption === undefined) return;
|
|
119
|
-
repeatOption =
|
|
120
|
-
typeof option.meta.repeatOption === "number"
|
|
121
|
-
? option.meta.repeatOption
|
|
122
|
-
: parseInt(option.meta.repeatOption, 10);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// Option inputs
|
|
126
|
-
const inputs = this.ovc.options[repeatOption] || [
|
|
127
|
-
!["radio", "checkbox"].includes(option.meta.type),
|
|
128
|
-
]; // Falling back on a single value array if option doesn't exist in ovc
|
|
129
|
-
|
|
130
|
-
// Inside a multiple document, every non-`repeated` root option is
|
|
131
|
-
// rendered at the document's occurrence index instead of looping
|
|
132
|
-
// through every input slot. We pick the value at `baseIndex` (or
|
|
133
|
-
// fall back to slot 0 for non-multiplied options whose inputs are
|
|
134
|
-
// a single-element array).
|
|
135
|
-
if (
|
|
136
|
-
documentMultipleSource !== undefined &&
|
|
137
|
-
option.meta.type !== "repeated"
|
|
138
|
-
) {
|
|
139
|
-
const valueAtIndex =
|
|
140
|
-
this.baseIndex < inputs.length ? inputs[this.baseIndex] : inputs[0];
|
|
141
|
-
if (valueAtIndex !== true) return;
|
|
142
|
-
|
|
143
|
-
this.outputs = [
|
|
144
|
-
...this.outputs,
|
|
145
|
-
...new OptionRender({
|
|
146
|
-
references: this.references,
|
|
147
|
-
id: optionId,
|
|
148
|
-
ovc: this.ovc,
|
|
149
|
-
index: this.baseIndex,
|
|
150
|
-
conditions: this.conditions,
|
|
151
|
-
numauto: this.NumAuto,
|
|
152
|
-
}).getOutputs(),
|
|
153
|
-
];
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Looping through inputs (default behaviour, also used for `repeated`
|
|
158
|
-
// wrappers whose source differs from the document multiple source).
|
|
159
|
-
inputs.forEach((value, index) => {
|
|
160
|
-
// If value is false we stop here
|
|
161
|
-
if (value !== true) return;
|
|
162
|
-
|
|
163
|
-
this.outputs = [
|
|
164
|
-
...this.outputs,
|
|
165
|
-
...new OptionRender({
|
|
166
|
-
references: this.references,
|
|
167
|
-
id: optionId,
|
|
168
|
-
ovc: this.ovc,
|
|
169
|
-
index,
|
|
170
|
-
conditions: this.conditions,
|
|
171
|
-
numauto: this.NumAuto,
|
|
172
|
-
}).getOutputs(),
|
|
173
|
-
];
|
|
174
91
|
});
|
|
175
|
-
}
|
|
92
|
+
}
|
|
176
93
|
}
|
|
177
94
|
}
|
|
178
95
|
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import type { Types } from "@legalplace/referencesparser";
|
|
2
2
|
import type ConditionsRunner from "@legalplace/conditions-runner";
|
|
3
3
|
import type InputsType from "@legalplace/types/dist/inputs";
|
|
4
|
-
import {
|
|
5
|
-
isOptionDisplayed as sharedIsOptionDisplayed,
|
|
6
|
-
isVariableDisplayed as sharedIsVariableDisplayed,
|
|
7
|
-
type ConditionEvaluator,
|
|
8
|
-
} from "@legalplace/referencesparser";
|
|
9
4
|
|
|
10
5
|
class FillPdfFormBase {
|
|
11
6
|
references: Types.ReferencesType;
|
|
@@ -25,46 +20,59 @@ class FillPdfFormBase {
|
|
|
25
20
|
}
|
|
26
21
|
|
|
27
22
|
/**
|
|
28
|
-
*
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
type,
|
|
32
|
-
id,
|
|
33
|
-
index
|
|
34
|
-
) => {
|
|
35
|
-
if (type === "options") return this.getOptionCondition(id, index);
|
|
36
|
-
if (type === "variables") return this.getVariableCondition(id, index);
|
|
37
|
-
return this.getSectionCondition(id);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Checks whether a variable is displayed at a given index.
|
|
23
|
+
* Checks whether a variable is displayed at a given index
|
|
24
|
+
* @param id Variable's ID
|
|
25
|
+
* @param index Index
|
|
42
26
|
*/
|
|
43
27
|
isVariableDisplayed(id: number, index: number) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
this.
|
|
48
|
-
|
|
28
|
+
// Getting variable's conditions & executing it if any
|
|
29
|
+
const variableCondition = this.getVariableCondition(id, index);
|
|
30
|
+
const variableParents =
|
|
31
|
+
this.references.relations.variables[id]?.parents || [];
|
|
32
|
+
const parentOptionIsDisplayed = this.isOptionDisplayed(
|
|
33
|
+
variableParents[0],
|
|
49
34
|
index
|
|
50
35
|
);
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
[variableCondition, parentOptionIsDisplayed].filter((c) => c !== true)
|
|
39
|
+
.length === 0
|
|
40
|
+
);
|
|
51
41
|
}
|
|
52
42
|
|
|
53
43
|
/**
|
|
54
|
-
* Checks whether an option is displayed at a given index
|
|
44
|
+
* Checks whether an option is displayed at a given index
|
|
45
|
+
* @param id Option's ID
|
|
46
|
+
* @param index Index
|
|
55
47
|
*/
|
|
56
48
|
isOptionDisplayed(id: number, index: number) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
49
|
+
// Getting variable's conditions & executing it if any
|
|
50
|
+
const optionCondition = this.getOptionCondition(id, index);
|
|
51
|
+
const optionParents = this.references.relations.options[id]?.parents || [];
|
|
52
|
+
const parentsConditions = optionParents.map(
|
|
53
|
+
(optionId) => this.getOptionCondition(optionId, index) !== false
|
|
54
|
+
);
|
|
55
|
+
const parentsInputs = optionParents.map(
|
|
56
|
+
(optionId) => this.ovc.options[optionId][index]
|
|
57
|
+
);
|
|
58
|
+
const parentSectionId = this.getOptionParentSection(id);
|
|
59
|
+
const parentSectionCondition =
|
|
60
|
+
this.getSectionCondition(parentSectionId) !== false;
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
[
|
|
64
|
+
optionCondition,
|
|
65
|
+
parentSectionCondition,
|
|
66
|
+
...parentsConditions,
|
|
67
|
+
...parentsInputs,
|
|
68
|
+
].filter((c) => c !== true).length === 0
|
|
63
69
|
);
|
|
64
70
|
}
|
|
65
71
|
|
|
66
72
|
/**
|
|
67
|
-
* Returns a variable's conditions
|
|
73
|
+
* Returns a variable's conditions
|
|
74
|
+
* @param id Variable's id
|
|
75
|
+
* @param index Variable's index
|
|
68
76
|
*/
|
|
69
77
|
private getVariableCondition(id: number, index: number) {
|
|
70
78
|
const conditionObject = this.references.conditions.variables[id];
|
|
@@ -79,7 +87,9 @@ class FillPdfFormBase {
|
|
|
79
87
|
}
|
|
80
88
|
|
|
81
89
|
/**
|
|
82
|
-
* Returns an option's conditions
|
|
90
|
+
* Returns an option's conditions
|
|
91
|
+
* @param id Option's id
|
|
92
|
+
* @param index Option's index
|
|
83
93
|
*/
|
|
84
94
|
private getOptionCondition(id: number, index: number) {
|
|
85
95
|
const conditionObject = this.references.conditions.options[id];
|
|
@@ -89,7 +99,8 @@ class FillPdfFormBase {
|
|
|
89
99
|
}
|
|
90
100
|
|
|
91
101
|
/**
|
|
92
|
-
* Returns a section's conditions
|
|
102
|
+
* Returns a section's conditions
|
|
103
|
+
* @param id Section's id
|
|
93
104
|
*/
|
|
94
105
|
private getSectionCondition(id: number) {
|
|
95
106
|
const conditionObject = this.references.conditions.sections.main[id];
|
|
@@ -97,6 +108,28 @@ class FillPdfFormBase {
|
|
|
97
108
|
? true
|
|
98
109
|
: this.conditions.executeCondition(conditionObject, id, 0, "sections");
|
|
99
110
|
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Returns option's parent section
|
|
114
|
+
* @param id Option's id
|
|
115
|
+
*/
|
|
116
|
+
private getOptionParentSection(id: number) {
|
|
117
|
+
const { parents } = this.references.relations.options[id];
|
|
118
|
+
|
|
119
|
+
// Getting root option id
|
|
120
|
+
const rootId = parents.length > 0 ? parents[parents.length - 1] : id;
|
|
121
|
+
|
|
122
|
+
// Looking for section
|
|
123
|
+
const sections = Object.values(this.references.sections.main);
|
|
124
|
+
|
|
125
|
+
for (let i = 0; i < sections.length; i += 1) {
|
|
126
|
+
if (sections[i].options.includes(rootId)) return sections[i].id;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
throw new Error(
|
|
130
|
+
`Cannot find parent section for option ${id} (Root option id: ${rootId})`
|
|
131
|
+
);
|
|
132
|
+
}
|
|
100
133
|
}
|
|
101
134
|
|
|
102
135
|
export default FillPdfFormBase;
|
package/src/types/types.ts
CHANGED
|
@@ -1,27 +1,14 @@
|
|
|
1
|
-
import type { DocumentLayoutV3 } from "@legalplace/models-v3-types";
|
|
2
|
-
|
|
3
1
|
export type DocumentOutputIndex = {
|
|
4
2
|
name: string;
|
|
5
3
|
slug: string;
|
|
6
4
|
pdf: boolean;
|
|
7
5
|
docx: boolean;
|
|
8
|
-
/**
|
|
9
|
-
* Occurrence index of the document when the document is multiple
|
|
10
|
-
* (`params.multiple.enabled === true`). `undefined` for non-multiple
|
|
11
|
-
* documents (treated as 0 internally).
|
|
12
|
-
*/
|
|
13
|
-
occurrenceIndex?: number;
|
|
14
6
|
};
|
|
15
|
-
|
|
16
7
|
export type DocumentPdfFormIndex = {
|
|
17
8
|
name: string;
|
|
18
9
|
slug: string;
|
|
19
10
|
form: boolean;
|
|
20
11
|
fdf: FDFType;
|
|
21
|
-
/**
|
|
22
|
-
* Occurrence index of the document when the document is multiple.
|
|
23
|
-
*/
|
|
24
|
-
occurrenceIndex?: number;
|
|
25
12
|
};
|
|
26
13
|
|
|
27
14
|
export type DocumentIndex = Record<
|
|
@@ -33,17 +20,3 @@ export type FDFType = {
|
|
|
33
20
|
id: string;
|
|
34
21
|
fields: Record<string, string>;
|
|
35
22
|
};
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Rendered header/footer regions and page layout for DOCX generation.
|
|
39
|
-
*/
|
|
40
|
-
export type DocumentLayout = {
|
|
41
|
-
header?: string;
|
|
42
|
-
footer?: string;
|
|
43
|
-
firstPageHeader?: string;
|
|
44
|
-
firstPageFooter?: string;
|
|
45
|
-
differentFirstPage: boolean;
|
|
46
|
-
margins?: DocumentLayoutV3["margins"];
|
|
47
|
-
headerDistance?: number;
|
|
48
|
-
footerDistance?: number;
|
|
49
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
image: node:24-alpine
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
stages:
|
|
5
|
-
- deploy
|
|
6
|
-
|
|
7
|
-
before_script:
|
|
8
|
-
- export PATH=$PATH:./node_modules/.bin/
|
|
9
|
-
|
|
10
|
-
variables:
|
|
11
|
-
DOCKER_DRIVER: overlay2
|
|
12
|
-
|
|
13
|
-
publish:
|
|
14
|
-
image: node:24-alpine
|
|
15
|
-
stage: deploy
|
|
16
|
-
id_tokens:
|
|
17
|
-
NPM_ID_TOKEN:
|
|
18
|
-
aud: "npm:registry.npmjs.org"
|
|
19
|
-
except:
|
|
20
|
-
variables:
|
|
21
|
-
- $CI_COMMIT_MESSAGE =~ /skip-publishFi/
|
|
22
|
-
script:
|
|
23
|
-
- npm install -g npm@latest
|
|
24
|
-
- echo "//registry.npmjs.org/:_authToken=${NPM_ID_TOKEN}" > ~/.npmrc
|
|
25
|
-
- npm publish
|
|
26
|
-
- echo "PUBLISHED SUCCESSFULLY"
|
|
27
|
-
environment:
|
|
28
|
-
name: development
|
|
29
|
-
only:
|
|
30
|
-
- master
|