@legalplace/prerenderx 2.6.0 → 2.6.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 +25 -0
- package/dist/libs/OutputParser.js +8 -4
- package/dist/libs/Prerender.d.ts +3 -12
- package/dist/libs/Prerender.js +25 -22
- package/package.json +4 -2
- package/src/libs/OutputParser.ts +11 -2
- package/src/libs/Prerender.ts +27 -25
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
+
|
|
5
|
+
### [2.6.2](https://git.legalplace.eu/legalplace/prerenderx/compare/v2.2.0...v2.6.2) (2021-10-01)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* adding french numbers displaying ([ffc1c1e](https://git.legalplace.eu/legalplace/prerenderx/commit/ffc1c1e4279dbd5d6529da0394cf03998fe1d4a3))
|
|
11
|
+
* bump version ([1b94156](https://git.legalplace.eu/legalplace/prerenderx/commit/1b941562c157e4ee368ca6ced106bf5c2d1dddd3))
|
|
12
|
+
* supporting parsed references ([39d5a8d](https://git.legalplace.eu/legalplace/prerenderx/commit/39d5a8d74fc9d9fd91936ab8d2c1edb9780e5afc))
|
|
13
|
+
* supporting parsed references and rendering documents on-demand. ([17ccbeb](https://git.legalplace.eu/legalplace/prerenderx/commit/17ccbeb8fe6ef4529864df955fd83fbe4911e252))
|
|
14
|
+
* Supporting variables in documents names ([da853c0](https://git.legalplace.eu/legalplace/prerenderx/commit/da853c0a1b0325d45570543195ada5f292645bad))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* add version logging ([4815571](https://git.legalplace.eu/legalplace/prerenderx/commit/4815571df9dbb1dc2a394683fe0bb16723eae57c))
|
|
20
|
+
* adding cache support for conditions ([34866b8](https://git.legalplace.eu/legalplace/prerenderx/commit/34866b8f7fc5b7e5d2bd1ff08dd50a80010c0262))
|
|
21
|
+
* bimp version ([f3fbd55](https://git.legalplace.eu/legalplace/prerenderx/commit/f3fbd55bba169a449a282c34c85fa48f98b03be5))
|
|
22
|
+
* datapopulator issue ([b8f8532](https://git.legalplace.eu/legalplace/prerenderx/commit/b8f8532fe7b03811e364387d3168c637d7bc6976))
|
|
23
|
+
* fixing cache ([53cf0dd](https://git.legalplace.eu/legalplace/prerenderx/commit/53cf0ddd2e1cd8c6c98c86869081aa949317f0cb))
|
|
24
|
+
* handle static chil in ovc converter ([5eadfab](https://git.legalplace.eu/legalplace/prerenderx/commit/5eadfab0aa8c0885f3e4268eb56c82e56e07d7ba))
|
|
25
|
+
* handle static child in prerender ([f6e6115](https://git.legalplace.eu/legalplace/prerenderx/commit/f6e6115f9d04bd585e0e05e52871217da9e1cf1b))
|
|
@@ -8,6 +8,12 @@ var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
|
8
8
|
};
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
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
|
+
};
|
|
11
17
|
exports.getRelatedVariablesValues = function (optionId, index, variables, ovc, references) {
|
|
12
18
|
var variablesValues = {};
|
|
13
19
|
variables.forEach(function (currentVariableId) {
|
|
@@ -24,10 +30,8 @@ exports.getRelatedVariablesValues = function (optionId, index, variables, ovc, r
|
|
|
24
30
|
if (rootVariableParentRelations.children.options.includes(optionId) || rootVariableParentRelations.dependants.includes(optionId) || optionId === rootVariableParentId)
|
|
25
31
|
value = [value[index]];
|
|
26
32
|
var cleanValues = value.map(function (currentValue) {
|
|
27
|
-
if (typeof currentValue
|
|
28
|
-
return currentValue
|
|
29
|
-
if (typeof currentValue === 'string')
|
|
30
|
-
return currentValue;
|
|
33
|
+
if (['number', 'string'].includes(typeof currentValue))
|
|
34
|
+
return frenchNumber(currentValue);
|
|
31
35
|
return '';
|
|
32
36
|
});
|
|
33
37
|
var currentVariableValue = cleanValues.length === 1 ? cleanValues[0] : cleanValues.join(', ');
|
package/dist/libs/Prerender.d.ts
CHANGED
|
@@ -32,19 +32,10 @@ declare class Prerender {
|
|
|
32
32
|
private renderedDocuments;
|
|
33
33
|
constructor(entry: ModelV3 | Types.ReferencesType, ovc: OVC_TYPE | OldOVC);
|
|
34
34
|
getDocumentsIndex(): Record<string, DocumentOutputIndex | DocumentPdfFormIndex>;
|
|
35
|
-
getDocument(documentNameHash: string): string | FDFType
|
|
36
|
-
fdf: string | FDFType;
|
|
37
|
-
name: string;
|
|
38
|
-
slug: string;
|
|
39
|
-
pdf: boolean;
|
|
40
|
-
docx: boolean;
|
|
41
|
-
} | {
|
|
42
|
-
fdf: string | FDFType;
|
|
43
|
-
name: string;
|
|
44
|
-
slug: string;
|
|
45
|
-
form: boolean;
|
|
46
|
-
};
|
|
35
|
+
getDocument(documentNameHash: string): string | FDFType;
|
|
47
36
|
private generateDocumentNamesHash;
|
|
37
|
+
private fillPdfForms;
|
|
38
|
+
private generateAllDocuments;
|
|
48
39
|
static isPdfForm(index: DocumentOutputIndex | DocumentPdfFormIndex): index is DocumentPdfFormIndex;
|
|
49
40
|
static isOutput(index: DocumentOutputIndex | DocumentPdfFormIndex): index is DocumentOutputIndex;
|
|
50
41
|
}
|
package/dist/libs/Prerender.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
@@ -34,26 +23,19 @@ var Prerender = (function () {
|
|
|
34
23
|
this.references = new referencesparser_1.ReferencesParser(entry).getReferences();
|
|
35
24
|
}
|
|
36
25
|
this.NumAuto = new NumAuto_1.default();
|
|
37
|
-
this.ovc = OvcConverter_1.default.isOvc(ovc)
|
|
38
|
-
? OvcConverter_1.default.convertToOptionsVariables(ovc, this.references)
|
|
39
|
-
: ovc;
|
|
26
|
+
this.ovc = OvcConverter_1.default.isOvc(ovc) ? OvcConverter_1.default.convertToOptionsVariables(ovc, this.references) : ovc;
|
|
40
27
|
var inputs = new InputsInitiator_1.default(this.references, this.ovc).getInputs();
|
|
41
28
|
this.conditions = new ConditionsRunner_1.default(this.references, inputs);
|
|
42
29
|
this.documentRender = new DocumentRender_1.default(this.references, this.conditions, inputs, this.NumAuto);
|
|
43
30
|
this.pdfFiller = new FillPdfForm_1.default(this.references, this.conditions, inputs);
|
|
31
|
+
this.generateDocumentNamesHash();
|
|
32
|
+
this.generateAllDocuments();
|
|
33
|
+
this.fillPdfForms();
|
|
44
34
|
}
|
|
45
35
|
Prerender.prototype.getDocumentsIndex = function () {
|
|
46
|
-
this.generateDocumentNamesHash();
|
|
47
36
|
return this.documentsIndex;
|
|
48
37
|
};
|
|
49
38
|
Prerender.prototype.getDocument = function (documentNameHash) {
|
|
50
|
-
if (Prerender.isPdfForm(this.documentsIndex[documentNameHash])) {
|
|
51
|
-
if (!Object.prototype.hasOwnProperty.call(this.renderedDocuments, documentNameHash))
|
|
52
|
-
this.renderedDocuments[documentNameHash] = this.pdfFiller.fillDocument(this.documentsIndex[documentNameHash].slug);
|
|
53
|
-
return __assign(__assign({}, this.documentsIndex[documentNameHash]), { fdf: this.renderedDocuments[documentNameHash] });
|
|
54
|
-
}
|
|
55
|
-
if (!Object.prototype.hasOwnProperty.call(this.renderedDocuments, documentNameHash))
|
|
56
|
-
this.renderedDocuments[documentNameHash] = this.documentRender.renderDocument(this.documentsIndex[documentNameHash].slug);
|
|
57
39
|
return this.renderedDocuments[documentNameHash];
|
|
58
40
|
};
|
|
59
41
|
Prerender.prototype.generateDocumentNamesHash = function () {
|
|
@@ -91,6 +73,27 @@ var Prerender = (function () {
|
|
|
91
73
|
}
|
|
92
74
|
});
|
|
93
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
|
+
};
|
|
94
97
|
Prerender.isPdfForm = function (index) {
|
|
95
98
|
return Object.prototype.hasOwnProperty.call(index, 'form');
|
|
96
99
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@legalplace/prerenderx",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.2",
|
|
4
4
|
"description": "PrerenderX",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": "https://git.legalplace.eu/legalplace/prerenderx",
|
|
@@ -11,13 +11,15 @@
|
|
|
11
11
|
"lint": "tsc && eslint ./src/ --ext ts,js",
|
|
12
12
|
"lint:fix": "tsc && eslint 'src/**/*.{js,jsx,ts,tsx}' --fix",
|
|
13
13
|
"test": "jest",
|
|
14
|
-
"build": "tsc"
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"release": "standard-version -a --no-verify"
|
|
15
16
|
},
|
|
16
17
|
"dependencies": {
|
|
17
18
|
"@legalplace/lplogic": "^2.1.6",
|
|
18
19
|
"@legalplace/models-v3-types": "^3.5.1",
|
|
19
20
|
"@legalplace/referencesparser": "^1.7.0",
|
|
20
21
|
"crypto": "^1.0.1",
|
|
22
|
+
"standard-version": "^9.3.1",
|
|
21
23
|
"typescript": "3.9.3"
|
|
22
24
|
},
|
|
23
25
|
"devDependencies": {
|
package/src/libs/OutputParser.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { Types } from '@legalplace/referencesparser'
|
|
2
2
|
import OVC_TYPE from './ovc.type'
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Parses number to correct french number format ("," instead of ".")
|
|
6
|
+
*/
|
|
7
|
+
const frenchNumber = (value: string | number) => {
|
|
8
|
+
let result = typeof value === 'number' ? value.toString() : value;
|
|
9
|
+
if (/^([0-9]+)\.([0-9]+)$/.test(result.trim()))
|
|
10
|
+
result = result.trim().replace('.', ',');
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
|
|
4
14
|
/**
|
|
5
15
|
* Returns option's related variable values
|
|
6
16
|
* @param optionId Option's id
|
|
@@ -31,8 +41,7 @@ export const getRelatedVariablesValues: getRelatedVarsT = (optionId, index, vari
|
|
|
31
41
|
|
|
32
42
|
// Making sure all values are strings
|
|
33
43
|
const cleanValues = value.map(currentValue => {
|
|
34
|
-
if (typeof currentValue
|
|
35
|
-
if (typeof currentValue === 'string') return currentValue
|
|
44
|
+
if (['number', 'string'].includes(typeof currentValue)) return frenchNumber(currentValue)
|
|
36
45
|
return ''
|
|
37
46
|
})
|
|
38
47
|
|
package/src/libs/Prerender.ts
CHANGED
|
@@ -51,10 +51,9 @@ class Prerender {
|
|
|
51
51
|
private renderedDocuments: Record<string, string | FDFType> = {}
|
|
52
52
|
|
|
53
53
|
constructor(entry: ModelV3 | Types.ReferencesType, ovc: OVC_TYPE | OldOVC) {
|
|
54
|
-
|
|
55
54
|
// Initiating references
|
|
56
55
|
if (ReferencesParser.isReferences(entry)) {
|
|
57
|
-
this.references = entry
|
|
56
|
+
this.references = entry
|
|
58
57
|
} else {
|
|
59
58
|
// Parsing references
|
|
60
59
|
this.references = new ReferencesParser(entry).getReferences()
|
|
@@ -62,11 +61,9 @@ class Prerender {
|
|
|
62
61
|
|
|
63
62
|
// Initiating num auto
|
|
64
63
|
this.NumAuto = new NumAuto()
|
|
65
|
-
|
|
64
|
+
|
|
66
65
|
// Converting OVC if needed
|
|
67
|
-
this.ovc = OvcConverter.isOvc(ovc)
|
|
68
|
-
? OvcConverter.convertToOptionsVariables(ovc, this.references)
|
|
69
|
-
: ovc
|
|
66
|
+
this.ovc = OvcConverter.isOvc(ovc) ? OvcConverter.convertToOptionsVariables(ovc, this.references) : ovc
|
|
70
67
|
|
|
71
68
|
// Initiating inputs
|
|
72
69
|
const inputs = new IntputsInitiator(this.references, this.ovc).getInputs()
|
|
@@ -79,32 +76,17 @@ class Prerender {
|
|
|
79
76
|
|
|
80
77
|
// Filling pdf documents
|
|
81
78
|
this.pdfFiller = new FillPdfForm(this.references, this.conditions, inputs)
|
|
79
|
+
|
|
80
|
+
this.generateDocumentNamesHash()
|
|
81
|
+
this.generateAllDocuments()
|
|
82
|
+
this.fillPdfForms()
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
public getDocumentsIndex() {
|
|
85
|
-
// Generating documents names
|
|
86
|
-
this.generateDocumentNamesHash();
|
|
87
|
-
|
|
88
86
|
return this.documentsIndex
|
|
89
87
|
}
|
|
90
88
|
|
|
91
89
|
public getDocument(documentNameHash: string) {
|
|
92
|
-
// Handling Pdf form
|
|
93
|
-
if (Prerender.isPdfForm(this.documentsIndex[documentNameHash])) {
|
|
94
|
-
if (!Object.prototype.hasOwnProperty.call(this.renderedDocuments, documentNameHash))
|
|
95
|
-
this.renderedDocuments[documentNameHash] = this.pdfFiller.fillDocument(this.documentsIndex[documentNameHash].slug);
|
|
96
|
-
|
|
97
|
-
return {
|
|
98
|
-
...this.documentsIndex[documentNameHash],
|
|
99
|
-
fdf: this.renderedDocuments[documentNameHash]
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Avoiding regeneration if document exists before rendering it
|
|
104
|
-
if (!Object.prototype.hasOwnProperty.call(this.renderedDocuments, documentNameHash))
|
|
105
|
-
this.renderedDocuments[documentNameHash] = this.documentRender.renderDocument(this.documentsIndex[documentNameHash].slug)
|
|
106
|
-
|
|
107
|
-
// Returning rendered document
|
|
108
90
|
return this.renderedDocuments[documentNameHash]
|
|
109
91
|
}
|
|
110
92
|
|
|
@@ -145,6 +127,26 @@ class Prerender {
|
|
|
145
127
|
})
|
|
146
128
|
}
|
|
147
129
|
|
|
130
|
+
private fillPdfForms() {
|
|
131
|
+
Object.keys(this.documentsIndex).forEach(documentNameHash => {
|
|
132
|
+
const index = this.documentsIndex[documentNameHash]
|
|
133
|
+
if (Prerender.isPdfForm(index)) {
|
|
134
|
+
index.fdf = this.getDocument(documentNameHash) as FDFType
|
|
135
|
+
}
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
private generateAllDocuments() {
|
|
140
|
+
Object.keys(this.documentsIndex).forEach(documentNameHash => {
|
|
141
|
+
const index = this.documentsIndex[documentNameHash]
|
|
142
|
+
if (Prerender.isPdfForm(index)) {
|
|
143
|
+
this.renderedDocuments[documentNameHash] = this.pdfFiller.fillDocument(this.documentsIndex[documentNameHash].slug)
|
|
144
|
+
} else {
|
|
145
|
+
this.renderedDocuments[documentNameHash] = this.documentRender.renderDocument(this.documentsIndex[documentNameHash].slug)
|
|
146
|
+
}
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
|
|
148
150
|
static isPdfForm(index: DocumentOutputIndex | DocumentPdfFormIndex): index is DocumentPdfFormIndex {
|
|
149
151
|
return Object.prototype.hasOwnProperty.call(index, 'form')
|
|
150
152
|
}
|