@legalplace/prerenderx 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +3 -47
- package/CHANGELOG.md +28 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +11 -0
- package/dist/libs/DocumentRender.d.ts +4 -4
- package/dist/libs/DocumentRender.js +2 -2
- package/dist/libs/FillPdfForm.d.ts +1 -1
- package/dist/libs/FillPdfForm.js +30 -24
- package/dist/libs/InputsInitiator.d.ts +1 -1
- package/dist/libs/InputsInitiator.js +35 -11
- package/dist/libs/NumAuto.js +1 -1
- package/dist/libs/OptionRender.d.ts +4 -4
- package/dist/libs/OptionRender.js +30 -18
- package/dist/libs/OutputParser.d.ts +2 -2
- package/dist/libs/OutputParser.js +34 -25
- package/dist/libs/Prerender.d.ts +8 -26
- package/dist/libs/Prerender.js +30 -23
- package/dist/libs/SectionRender.d.ts +4 -4
- package/dist/libs/SectionRender.js +22 -13
- package/dist/libs/misc/FillPdfFormBase.d.ts +3 -3
- package/dist/libs/misc/FillPdfFormBase.js +25 -17
- package/dist/types/types.d.ts +17 -0
- package/dist/types/types.js +2 -0
- package/package.json +14 -18
- package/src/index.ts +4 -2
- package/src/libs/DocumentRender.ts +27 -22
- package/src/libs/FillPdfForm.ts +72 -59
- package/src/libs/InputsInitiator.ts +91 -53
- package/src/libs/NumAuto.ts +16 -14
- package/src/libs/OptionRender.ts +85 -45
- package/src/libs/OutputParser.ts +112 -58
- package/src/libs/Prerender.ts +120 -98
- package/src/libs/SectionRender.ts +57 -38
- package/src/libs/misc/FillPdfFormBase.ts +71 -39
- package/src/types/types.ts +22 -0
- package/tsconfig.json +3 -1
- package/.gitlab-ci.yml +0 -43
- package/.prettierrc.js +0 -10
- package/.vscode/settings.json +0 -17
- package/.vscode/tasks.json +0 -24
- package/tsconfig.eslint.json +0 -12
package/src/libs/OutputParser.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { Types } from
|
|
2
|
-
import InputsType from
|
|
3
|
-
|
|
1
|
+
import type { Types } from "@legalplace/referencesparser";
|
|
2
|
+
import type InputsType from "@legalplace/types/dist/inputs";
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Parses number to correct french number format ("," instead of ".")
|
|
7
6
|
*/
|
|
8
7
|
const frenchNumber = (value: string | number) => {
|
|
9
|
-
let result = typeof value ===
|
|
8
|
+
let result = typeof value === "number" ? value.toString() : value;
|
|
10
9
|
if (/^([0-9]+)\.([0-9]+)$/.test(result.trim()))
|
|
11
|
-
result = result.trim().replace(
|
|
10
|
+
result = result.trim().replace(".", ",");
|
|
12
11
|
return result;
|
|
13
12
|
};
|
|
14
13
|
|
|
@@ -18,43 +17,67 @@ const frenchNumber = (value: string | number) => {
|
|
|
18
17
|
* @param index Occurency index
|
|
19
18
|
* @param variables Variables ids list
|
|
20
19
|
*/
|
|
21
|
-
type relVarsValsT = Record<string, string | number
|
|
22
|
-
type getRelatedVarsT = (
|
|
23
|
-
|
|
20
|
+
type relVarsValsT = Record<string, string | number>;
|
|
21
|
+
type getRelatedVarsT = (
|
|
22
|
+
optionId: number,
|
|
23
|
+
index: number,
|
|
24
|
+
variables: number[],
|
|
25
|
+
ovc: InputsType,
|
|
26
|
+
references: Types.ReferencesType
|
|
27
|
+
) => relVarsValsT;
|
|
28
|
+
export const getRelatedVariablesValues: getRelatedVarsT = (
|
|
29
|
+
optionId,
|
|
30
|
+
index,
|
|
31
|
+
variables,
|
|
32
|
+
ovc,
|
|
33
|
+
references
|
|
34
|
+
) => {
|
|
24
35
|
// Getting variables values
|
|
25
|
-
const variablesValues: Record<string, string> = {}
|
|
26
|
-
variables.forEach(currentVariableId => {
|
|
36
|
+
const variablesValues: Record<string, string> = {};
|
|
37
|
+
variables.forEach((currentVariableId) => {
|
|
27
38
|
// Getting option value
|
|
28
|
-
let value = ovc.variables[currentVariableId] || [
|
|
29
|
-
const variableParents =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
39
|
+
let value = ovc.variables[currentVariableId] || [""];
|
|
40
|
+
const variableParents =
|
|
41
|
+
references.relations.variables[currentVariableId].parents;
|
|
42
|
+
if (variableParents === undefined)
|
|
43
|
+
throw new Error(
|
|
44
|
+
`Variable ${currentVariableId} parents object does not exist`
|
|
45
|
+
);
|
|
46
|
+
const rootVariableParentId = variableParents[variableParents.length - 1];
|
|
47
|
+
const rootVariableParentRelations =
|
|
48
|
+
references.relations.options[rootVariableParentId];
|
|
49
|
+
if (rootVariableParentRelations === undefined)
|
|
50
|
+
throw new Error(`Option ${rootVariableParentId} does not exist`);
|
|
51
|
+
|
|
52
|
+
if (typeof variableParents === "undefined") return;
|
|
36
53
|
|
|
37
54
|
// Getting rootOption parent
|
|
38
55
|
|
|
39
56
|
// Checking if current option is related to the option that changed
|
|
40
|
-
if (
|
|
41
|
-
|
|
57
|
+
if (
|
|
58
|
+
rootVariableParentRelations.children.options.includes(optionId) ||
|
|
59
|
+
rootVariableParentRelations.dependants.includes(optionId) ||
|
|
60
|
+
optionId === rootVariableParentId
|
|
61
|
+
)
|
|
62
|
+
value = [value[index]];
|
|
42
63
|
|
|
43
64
|
// Making sure all values are strings
|
|
44
|
-
const cleanValues = value.map(currentValue => {
|
|
45
|
-
if ([
|
|
46
|
-
|
|
47
|
-
|
|
65
|
+
const cleanValues = value.map((currentValue) => {
|
|
66
|
+
if (["number", "string"].includes(typeof currentValue))
|
|
67
|
+
return frenchNumber(currentValue);
|
|
68
|
+
return "";
|
|
69
|
+
});
|
|
48
70
|
|
|
49
71
|
// Joining multiple variables if needed
|
|
50
|
-
const currentVariableValue =
|
|
72
|
+
const currentVariableValue =
|
|
73
|
+
cleanValues.length === 1 ? cleanValues[0] : cleanValues.join(", ");
|
|
51
74
|
|
|
52
75
|
// Setting variable value
|
|
53
|
-
variablesValues[currentVariableId] = currentVariableValue
|
|
54
|
-
})
|
|
76
|
+
variablesValues[currentVariableId] = currentVariableValue;
|
|
77
|
+
});
|
|
55
78
|
|
|
56
|
-
return variablesValues
|
|
57
|
-
}
|
|
79
|
+
return variablesValues;
|
|
80
|
+
};
|
|
58
81
|
|
|
59
82
|
/**
|
|
60
83
|
* Parses output with variables
|
|
@@ -64,53 +87,84 @@ export const getRelatedVariablesValues: getRelatedVarsT = (optionId, index, vari
|
|
|
64
87
|
* @param variables Variables values list
|
|
65
88
|
* @param autonums Autonums values
|
|
66
89
|
*/
|
|
67
|
-
type autonumsType = [string, string, number, string | null][]
|
|
68
|
-
type parseOutputT = (
|
|
69
|
-
|
|
90
|
+
type autonumsType = [string, string, number, string | null][];
|
|
91
|
+
type parseOutputT = (
|
|
92
|
+
output: string,
|
|
93
|
+
index: number,
|
|
94
|
+
variables: relVarsValsT,
|
|
95
|
+
autonums: autonumsType
|
|
96
|
+
) => string;
|
|
97
|
+
export const parseOutputWithVariables: parseOutputT = (
|
|
98
|
+
output,
|
|
99
|
+
index,
|
|
100
|
+
variables,
|
|
101
|
+
autonums
|
|
102
|
+
) => {
|
|
70
103
|
// Inserting values
|
|
71
|
-
let parsedOutput = `${output}
|
|
72
|
-
Object.keys(variables).forEach(variableId => {
|
|
73
|
-
let value: string = variables[variableId].toString()
|
|
104
|
+
let parsedOutput = `${output}`;
|
|
105
|
+
Object.keys(variables).forEach((variableId) => {
|
|
106
|
+
let value: string = variables[variableId].toString();
|
|
74
107
|
if (value.trim().length === 0) {
|
|
75
|
-
value = new Array(16).join(
|
|
108
|
+
value = new Array(16).join("_");
|
|
76
109
|
}
|
|
77
110
|
|
|
78
111
|
// Replacing linebreaks with br tags
|
|
79
|
-
value = value.replace(/\n/g,
|
|
80
|
-
parsedOutput = parsedOutput.replace(
|
|
81
|
-
|
|
112
|
+
value = value.replace(/\n/g, "<br />");
|
|
113
|
+
parsedOutput = parsedOutput.replace(
|
|
114
|
+
new RegExp(`\\[var:${variableId}\\]`, "g"),
|
|
115
|
+
value
|
|
116
|
+
);
|
|
117
|
+
});
|
|
82
118
|
|
|
83
119
|
// Inserting page breaks
|
|
84
|
-
parsedOutput = parsedOutput.replace(
|
|
120
|
+
parsedOutput = parsedOutput.replace(
|
|
121
|
+
/\[\[PAGE_BREAK\]\]/gi,
|
|
122
|
+
'<div style="page-break-after:always"></div>'
|
|
123
|
+
);
|
|
85
124
|
|
|
86
125
|
// Cleaning BLURS
|
|
87
|
-
parsedOutput = parsedOutput.replace(/\[(E|B)_BLUR\]/gi,
|
|
126
|
+
parsedOutput = parsedOutput.replace(/\[(E|B)_BLUR\]/gi, "");
|
|
88
127
|
|
|
89
128
|
// Parsing Signatures
|
|
90
|
-
parsedOutput = parsedOutput.replace(
|
|
129
|
+
parsedOutput = parsedOutput.replace(
|
|
130
|
+
/\[signature:([0-9]+)\]/g,
|
|
131
|
+
(v, signatureId) =>
|
|
132
|
+
`<span data-signature-id="${signatureId}" data-signer-index="${index}"></span>`
|
|
133
|
+
);
|
|
91
134
|
|
|
92
135
|
// Inserting autonums
|
|
93
|
-
autonums.forEach(currentAn => {
|
|
94
|
-
if (currentAn[3] === null)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
136
|
+
autonums.forEach((currentAn) => {
|
|
137
|
+
if (currentAn[3] === null)
|
|
138
|
+
parsedOutput = parsedOutput.replace(
|
|
139
|
+
`[${currentAn[0]}:${currentAn[1]}]`,
|
|
140
|
+
`<span class="${currentAn[0]}">${currentAn[2]}</span>`
|
|
141
|
+
);
|
|
142
|
+
else
|
|
143
|
+
parsedOutput = parsedOutput.replace(
|
|
144
|
+
`[${currentAn[0]}:${currentAn[1]}](${currentAn[3]})`,
|
|
145
|
+
`<span class="${currentAn[0]}">${currentAn[2]}</span>`
|
|
146
|
+
);
|
|
147
|
+
});
|
|
101
148
|
|
|
149
|
+
return parsedOutput;
|
|
150
|
+
};
|
|
102
151
|
|
|
103
152
|
/**
|
|
104
153
|
* Parses document name with variables
|
|
105
154
|
* @param text Document's name
|
|
106
155
|
*/
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
156
|
+
type TParseDocumentNameWithVariables = (
|
|
157
|
+
text: string,
|
|
158
|
+
ovc: InputsType,
|
|
159
|
+
references: Types.ReferencesType,
|
|
160
|
+
fallback?: string
|
|
112
161
|
) => string;
|
|
113
|
-
export const parseDocumentNameWithVariables: TParseDocumentNameWithVariables = (
|
|
162
|
+
export const parseDocumentNameWithVariables: TParseDocumentNameWithVariables = (
|
|
163
|
+
text,
|
|
164
|
+
ovc,
|
|
165
|
+
references,
|
|
166
|
+
fallback
|
|
167
|
+
) => {
|
|
114
168
|
/**
|
|
115
169
|
* Variables
|
|
116
170
|
*/
|
|
@@ -139,7 +193,7 @@ export const parseDocumentNameWithVariables: TParseDocumentNameWithVariables = (
|
|
|
139
193
|
// Getting values
|
|
140
194
|
const variablesValues: Record<string, string> = {};
|
|
141
195
|
variables.forEach((variableId) => {
|
|
142
|
-
const value = ovc.variables[variableId]?.[0] ||
|
|
196
|
+
const value = ovc.variables[variableId]?.[0] || "";
|
|
143
197
|
variablesValues[variableId] = value.toString();
|
|
144
198
|
});
|
|
145
199
|
|
|
@@ -150,7 +204,7 @@ export const parseDocumentNameWithVariables: TParseDocumentNameWithVariables = (
|
|
|
150
204
|
if (value.trim().length === 0 && fallback) parsedText = fallback;
|
|
151
205
|
if (parsedText === fallback && fallback) return;
|
|
152
206
|
parsedText = parsedText.replace(
|
|
153
|
-
new RegExp(`\\[var:${variableId}\\]`,
|
|
207
|
+
new RegExp(`\\[var:${variableId}\\]`, "gi"),
|
|
154
208
|
value
|
|
155
209
|
);
|
|
156
210
|
});
|
package/src/libs/Prerender.ts
CHANGED
|
@@ -1,171 +1,193 @@
|
|
|
1
|
-
import { ModelV3 } from
|
|
2
|
-
import { Types
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
type
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
type DocumentPdfFormIndex = {
|
|
21
|
-
name: string
|
|
22
|
-
slug: string
|
|
23
|
-
form: boolean
|
|
24
|
-
fdf: {
|
|
25
|
-
id: string
|
|
26
|
-
fields: Record<string, string>
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
type DocumentIndex = Record<string, DocumentOutputIndex | DocumentPdfFormIndex>
|
|
31
|
-
|
|
32
|
-
type FDFType = {
|
|
33
|
-
id: string
|
|
34
|
-
fields: Record<string, string>
|
|
35
|
-
}
|
|
1
|
+
import type { ModelV3 } from "@legalplace/models-v3-types";
|
|
2
|
+
import type { Types } from "@legalplace/referencesparser";
|
|
3
|
+
import { ReferencesParser } from "@legalplace/referencesparser";
|
|
4
|
+
import ConditionsRunner from "@legalplace/conditions-runner";
|
|
5
|
+
import OvcConverter from "@legalplace/ovc-converter";
|
|
6
|
+
import type OvcType from "@legalplace/types/dist/ovc";
|
|
7
|
+
import type InputsType from "@legalplace/types/dist/inputs";
|
|
8
|
+
import crypto from "crypto";
|
|
9
|
+
import DocumentRender from "./DocumentRender";
|
|
10
|
+
import NumAuto from "./NumAuto";
|
|
11
|
+
import IntputsInitiator from "./InputsInitiator";
|
|
12
|
+
import FillPdfForm from "./FillPdfForm";
|
|
13
|
+
import { parseDocumentNameWithVariables } from "./OutputParser";
|
|
14
|
+
import type {
|
|
15
|
+
FDFType,
|
|
16
|
+
DocumentIndex,
|
|
17
|
+
DocumentOutputIndex,
|
|
18
|
+
DocumentPdfFormIndex,
|
|
19
|
+
} from "../types/types";
|
|
36
20
|
|
|
37
21
|
class Prerender {
|
|
38
|
-
private
|
|
39
|
-
|
|
40
|
-
private references: Types.ReferencesType
|
|
41
|
-
|
|
42
|
-
private ovc: InputsType
|
|
22
|
+
private references: Types.ReferencesType;
|
|
43
23
|
|
|
44
|
-
private
|
|
24
|
+
private ovc: InputsType;
|
|
45
25
|
|
|
46
|
-
private
|
|
26
|
+
private conditions: ConditionsRunner;
|
|
47
27
|
|
|
48
|
-
private
|
|
28
|
+
private documentRender: DocumentRender;
|
|
49
29
|
|
|
50
|
-
private
|
|
30
|
+
private pdfFiller: FillPdfForm;
|
|
51
31
|
|
|
52
|
-
private
|
|
32
|
+
private NumAuto: NumAuto;
|
|
53
33
|
|
|
54
|
-
private
|
|
34
|
+
private documentsIndex: DocumentIndex = {};
|
|
55
35
|
|
|
56
|
-
|
|
57
|
-
this.model = model
|
|
36
|
+
private renderedDocuments: Record<string, string | FDFType> = {};
|
|
58
37
|
|
|
38
|
+
constructor(
|
|
39
|
+
model: ModelV3 | Types.ReferencesType,
|
|
40
|
+
ovc: InputsType | OvcType
|
|
41
|
+
) {
|
|
59
42
|
// Initiating num auto
|
|
60
|
-
this.NumAuto = new NumAuto()
|
|
43
|
+
this.NumAuto = new NumAuto();
|
|
61
44
|
|
|
62
45
|
// Parsing references
|
|
63
|
-
this.references =
|
|
46
|
+
this.references = ReferencesParser.isReferences(model)
|
|
47
|
+
? model
|
|
48
|
+
: new ReferencesParser(model).getReferences();
|
|
64
49
|
|
|
65
50
|
// Converting OVC if needed
|
|
66
|
-
this.ovc = OvcConverter.isOvc(ovc)
|
|
51
|
+
this.ovc = OvcConverter.isOvc(ovc)
|
|
52
|
+
? OvcConverter.convertToOptionsVariables(ovc, this.references)
|
|
53
|
+
: ovc;
|
|
67
54
|
|
|
68
55
|
// Initiating inputs
|
|
69
|
-
const inputs = new IntputsInitiator(this.references, this.ovc).getInputs()
|
|
56
|
+
const inputs = new IntputsInitiator(this.references, this.ovc).getInputs();
|
|
70
57
|
|
|
71
58
|
// Initiating ConditionsRunner
|
|
72
|
-
this.conditions = new ConditionsRunner(this.references, inputs)
|
|
59
|
+
this.conditions = new ConditionsRunner(this.references, inputs);
|
|
73
60
|
|
|
74
61
|
// Rendering documents
|
|
75
|
-
this.documentRender = new DocumentRender(
|
|
62
|
+
this.documentRender = new DocumentRender(
|
|
63
|
+
this.references,
|
|
64
|
+
this.conditions,
|
|
65
|
+
inputs,
|
|
66
|
+
this.NumAuto
|
|
67
|
+
);
|
|
76
68
|
|
|
77
69
|
// Filling pdf documents
|
|
78
|
-
this.pdfFiller = new FillPdfForm(this.references, this.conditions, inputs)
|
|
70
|
+
this.pdfFiller = new FillPdfForm(this.references, this.conditions, inputs);
|
|
79
71
|
|
|
80
|
-
this.generateDocumentNamesHash()
|
|
72
|
+
this.generateDocumentNamesHash();
|
|
81
73
|
}
|
|
82
74
|
|
|
83
75
|
public getDocumentsIndexWithoutFdf() {
|
|
84
|
-
return this.documentsIndex
|
|
76
|
+
return this.documentsIndex;
|
|
85
77
|
}
|
|
86
78
|
|
|
87
79
|
public getDocumentsIndex() {
|
|
88
|
-
this.generateAllDocuments()
|
|
89
|
-
this.fillPdfForms()
|
|
90
|
-
return this.documentsIndex
|
|
80
|
+
this.generateAllDocuments();
|
|
81
|
+
this.fillPdfForms();
|
|
82
|
+
return this.documentsIndex;
|
|
91
83
|
}
|
|
92
84
|
|
|
93
85
|
public getDocument(documentNameHash: string) {
|
|
94
86
|
if (this.renderedDocuments[documentNameHash]) {
|
|
95
|
-
return this.renderedDocuments[documentNameHash]
|
|
87
|
+
return this.renderedDocuments[documentNameHash];
|
|
96
88
|
}
|
|
97
89
|
|
|
98
|
-
const index = this.documentsIndex[documentNameHash]
|
|
90
|
+
const index = this.documentsIndex[documentNameHash];
|
|
99
91
|
|
|
100
|
-
this.renderedDocuments[documentNameHash] = Prerender.isPdfForm(index)
|
|
92
|
+
this.renderedDocuments[documentNameHash] = Prerender.isPdfForm(index)
|
|
93
|
+
? this.pdfFiller.fillDocument(index.slug)
|
|
94
|
+
: this.documentRender.renderDocument(index.slug);
|
|
101
95
|
|
|
102
|
-
return this.renderedDocuments[documentNameHash]
|
|
96
|
+
return this.renderedDocuments[documentNameHash];
|
|
103
97
|
}
|
|
104
98
|
|
|
105
99
|
private generateDocumentNamesHash() {
|
|
106
|
-
Object.keys(this.
|
|
107
|
-
const document = this.
|
|
108
|
-
const documentParams = this.
|
|
109
|
-
const conditionObject = this.references.conditions.documents[slug]
|
|
110
|
-
const condition =
|
|
100
|
+
Object.keys(this.references.documents).forEach((slug) => {
|
|
101
|
+
const document = this.references.documents[slug];
|
|
102
|
+
const documentParams = this.references.documents[slug].params;
|
|
103
|
+
const conditionObject = this.references.conditions.documents[slug];
|
|
104
|
+
const condition =
|
|
105
|
+
conditionObject === undefined
|
|
106
|
+
? true
|
|
107
|
+
: this.conditions.executeCondition(
|
|
108
|
+
conditionObject,
|
|
109
|
+
0,
|
|
110
|
+
0,
|
|
111
|
+
"documents"
|
|
112
|
+
);
|
|
111
113
|
|
|
112
114
|
// Rendering documents sections
|
|
113
115
|
if (condition === true) {
|
|
114
|
-
const hash = crypto
|
|
115
|
-
.createHash('sha1')
|
|
116
|
-
.update(slug)
|
|
117
|
-
.digest('hex')
|
|
116
|
+
const hash = crypto.createHash("sha1").update(slug).digest("hex");
|
|
118
117
|
|
|
119
118
|
// Referencing in index
|
|
120
|
-
if (
|
|
119
|
+
if (
|
|
120
|
+
typeof document.pdf === "object" &&
|
|
121
|
+
typeof document.pdf.id === "string" &&
|
|
122
|
+
typeof document.pdf.form === "object"
|
|
123
|
+
) {
|
|
121
124
|
this.documentsIndex[hash] = {
|
|
122
|
-
name: parseDocumentNameWithVariables(
|
|
125
|
+
name: parseDocumentNameWithVariables(
|
|
126
|
+
document.name,
|
|
127
|
+
this.ovc,
|
|
128
|
+
this.references,
|
|
129
|
+
document.fallbackName
|
|
130
|
+
),
|
|
123
131
|
slug,
|
|
124
132
|
form: true,
|
|
125
133
|
fdf: {
|
|
126
|
-
id:
|
|
127
|
-
fields: {}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
134
|
+
id: "",
|
|
135
|
+
fields: {},
|
|
136
|
+
},
|
|
137
|
+
};
|
|
130
138
|
} else {
|
|
131
139
|
this.documentsIndex[hash] = {
|
|
132
|
-
name: parseDocumentNameWithVariables(
|
|
140
|
+
name: parseDocumentNameWithVariables(
|
|
141
|
+
document.name,
|
|
142
|
+
this.ovc,
|
|
143
|
+
this.references,
|
|
144
|
+
document.fallbackName
|
|
145
|
+
),
|
|
133
146
|
slug,
|
|
134
|
-
pdf: documentParams?.formats?.pdf
|
|
135
|
-
docx: documentParams?.formats?.docx
|
|
136
|
-
}
|
|
147
|
+
pdf: documentParams?.formats?.pdf !== false,
|
|
148
|
+
docx: documentParams?.formats?.docx !== false,
|
|
149
|
+
};
|
|
137
150
|
}
|
|
138
151
|
}
|
|
139
|
-
})
|
|
152
|
+
});
|
|
140
153
|
}
|
|
141
154
|
|
|
142
155
|
private fillPdfForms() {
|
|
143
|
-
Object.keys(this.documentsIndex).forEach(documentNameHash => {
|
|
144
|
-
const index = this.documentsIndex[documentNameHash]
|
|
156
|
+
Object.keys(this.documentsIndex).forEach((documentNameHash) => {
|
|
157
|
+
const index = this.documentsIndex[documentNameHash];
|
|
145
158
|
if (Prerender.isPdfForm(index)) {
|
|
146
|
-
index.fdf = this.getDocument(documentNameHash) as FDFType
|
|
159
|
+
index.fdf = this.getDocument(documentNameHash) as FDFType;
|
|
147
160
|
}
|
|
148
|
-
})
|
|
161
|
+
});
|
|
149
162
|
}
|
|
150
163
|
|
|
151
164
|
private generateAllDocuments() {
|
|
152
|
-
Object.keys(this.documentsIndex).forEach(documentNameHash => {
|
|
153
|
-
const index = this.documentsIndex[documentNameHash]
|
|
165
|
+
Object.keys(this.documentsIndex).forEach((documentNameHash) => {
|
|
166
|
+
const index = this.documentsIndex[documentNameHash];
|
|
154
167
|
if (Prerender.isPdfForm(index)) {
|
|
155
|
-
this.renderedDocuments[documentNameHash] = this.pdfFiller.fillDocument(
|
|
168
|
+
this.renderedDocuments[documentNameHash] = this.pdfFiller.fillDocument(
|
|
169
|
+
this.documentsIndex[documentNameHash].slug
|
|
170
|
+
);
|
|
156
171
|
} else {
|
|
157
|
-
this.renderedDocuments[documentNameHash] =
|
|
172
|
+
this.renderedDocuments[documentNameHash] =
|
|
173
|
+
this.documentRender.renderDocument(
|
|
174
|
+
this.documentsIndex[documentNameHash].slug
|
|
175
|
+
);
|
|
158
176
|
}
|
|
159
|
-
})
|
|
177
|
+
});
|
|
160
178
|
}
|
|
161
179
|
|
|
162
|
-
static isPdfForm(
|
|
163
|
-
|
|
180
|
+
static isPdfForm(
|
|
181
|
+
index: DocumentOutputIndex | DocumentPdfFormIndex
|
|
182
|
+
): index is DocumentPdfFormIndex {
|
|
183
|
+
return Object.prototype.hasOwnProperty.call(index, "form");
|
|
164
184
|
}
|
|
165
185
|
|
|
166
|
-
static isOutput(
|
|
167
|
-
|
|
186
|
+
static isOutput(
|
|
187
|
+
index: DocumentOutputIndex | DocumentPdfFormIndex
|
|
188
|
+
): index is DocumentOutputIndex {
|
|
189
|
+
return !Object.prototype.hasOwnProperty.call(index, "form");
|
|
168
190
|
}
|
|
169
191
|
}
|
|
170
192
|
|
|
171
|
-
export default Prerender
|
|
193
|
+
export default Prerender;
|
|
@@ -1,61 +1,80 @@
|
|
|
1
|
-
import { Types } from
|
|
2
|
-
import ConditionsRunner from
|
|
3
|
-
import InputsType from
|
|
4
|
-
import OptionRender from
|
|
5
|
-
import NumAuto from
|
|
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 OptionRender from "./OptionRender";
|
|
5
|
+
import type NumAuto from "./NumAuto";
|
|
6
6
|
|
|
7
7
|
class SectionRender {
|
|
8
|
-
outputs: string[] = []
|
|
8
|
+
outputs: string[] = [];
|
|
9
9
|
|
|
10
|
-
references: Types.ReferencesType
|
|
10
|
+
references: Types.ReferencesType;
|
|
11
11
|
|
|
12
|
-
currentSection: number
|
|
12
|
+
currentSection: number;
|
|
13
13
|
|
|
14
|
-
documentName: string
|
|
14
|
+
documentName: string;
|
|
15
15
|
|
|
16
|
-
conditions: ConditionsRunner
|
|
16
|
+
conditions: ConditionsRunner;
|
|
17
17
|
|
|
18
|
-
ovc: InputsType
|
|
18
|
+
ovc: InputsType;
|
|
19
19
|
|
|
20
|
-
private NumAuto: NumAuto
|
|
20
|
+
private NumAuto: NumAuto;
|
|
21
21
|
|
|
22
|
-
constructor(options: {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
constructor(options: {
|
|
23
|
+
references: Types.ReferencesType;
|
|
24
|
+
conditions: ConditionsRunner;
|
|
25
|
+
ovc: InputsType;
|
|
26
|
+
documentName: string;
|
|
27
|
+
currentSection: number;
|
|
28
|
+
numauto: NumAuto;
|
|
29
|
+
}) {
|
|
30
|
+
this.references = options.references;
|
|
31
|
+
this.conditions = options.conditions;
|
|
32
|
+
this.documentName = options.documentName;
|
|
33
|
+
this.currentSection = options.currentSection;
|
|
34
|
+
this.ovc = options.ovc;
|
|
35
|
+
this.NumAuto = options.numauto;
|
|
29
36
|
|
|
30
|
-
this.renderSection()
|
|
37
|
+
this.renderSection();
|
|
31
38
|
}
|
|
32
39
|
|
|
33
40
|
getOutputs() {
|
|
34
|
-
return this.outputs
|
|
41
|
+
return this.outputs;
|
|
35
42
|
}
|
|
36
43
|
|
|
37
44
|
private renderSection() {
|
|
38
|
-
const section =
|
|
39
|
-
|
|
40
|
-
const
|
|
45
|
+
const section =
|
|
46
|
+
this.references.sections[this.documentName][this.currentSection];
|
|
47
|
+
const conditionObject =
|
|
48
|
+
this.references.conditions.sections[this.documentName][
|
|
49
|
+
this.currentSection
|
|
50
|
+
];
|
|
51
|
+
const condition =
|
|
52
|
+
conditionObject === undefined
|
|
53
|
+
? true
|
|
54
|
+
: this.conditions.executeCondition(conditionObject, 0, 0, "sections");
|
|
41
55
|
|
|
42
56
|
// Rendering documents sections
|
|
43
57
|
if (condition === true) {
|
|
44
|
-
section.options.forEach(optionId => {
|
|
45
|
-
const option = this.references.options[optionId]
|
|
46
|
-
let repeatOption = optionId
|
|
47
|
-
if (option.meta.type ===
|
|
48
|
-
if (option.meta.repeatOption === undefined) return
|
|
49
|
-
repeatOption =
|
|
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);
|
|
50
67
|
}
|
|
51
68
|
|
|
52
69
|
// Option inputs
|
|
53
|
-
const inputs = this.ovc.options[repeatOption] || [
|
|
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
|
|
54
73
|
|
|
55
74
|
// Looping through inputs
|
|
56
75
|
inputs.forEach((value, index) => {
|
|
57
76
|
// If value is false we stop here
|
|
58
|
-
if (value !== true) return
|
|
77
|
+
if (value !== true) return;
|
|
59
78
|
|
|
60
79
|
this.outputs = [
|
|
61
80
|
...this.outputs,
|
|
@@ -65,13 +84,13 @@ class SectionRender {
|
|
|
65
84
|
ovc: this.ovc,
|
|
66
85
|
index,
|
|
67
86
|
conditions: this.conditions,
|
|
68
|
-
numauto: this.NumAuto
|
|
69
|
-
}).getOutputs()
|
|
70
|
-
]
|
|
71
|
-
})
|
|
72
|
-
})
|
|
87
|
+
numauto: this.NumAuto,
|
|
88
|
+
}).getOutputs(),
|
|
89
|
+
];
|
|
90
|
+
});
|
|
91
|
+
});
|
|
73
92
|
}
|
|
74
93
|
}
|
|
75
94
|
}
|
|
76
95
|
|
|
77
|
-
export default SectionRender
|
|
96
|
+
export default SectionRender;
|