@legalplace/prerenderx 3.8.18-staging.2 → 3.8.19

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.
@@ -15,7 +15,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  var OptionRender_1 = __importDefault(require("./OptionRender"));
16
16
  var SectionRender = (function () {
17
17
  function SectionRender(options) {
18
- var _a;
19
18
  this.outputs = [];
20
19
  this.references = options.references;
21
20
  this.conditions = options.conditions;
@@ -23,88 +22,47 @@ var SectionRender = (function () {
23
22
  this.currentSection = options.currentSection;
24
23
  this.ovc = options.ovc;
25
24
  this.NumAuto = options.numauto;
26
- this.baseIndex = (_a = options.baseIndex) !== null && _a !== void 0 ? _a : 0;
27
25
  this.renderSection();
28
26
  }
29
27
  SectionRender.prototype.getOutputs = function () {
30
28
  return this.outputs;
31
29
  };
32
- SectionRender.prototype.getDocumentMultipleSource = function () {
33
- var _a, _b;
34
- var docMultiple = (_b = (_a = this.references.documents[this.documentName]) === null || _a === void 0 ? void 0 : _a.params) === null || _b === void 0 ? void 0 : _b.multiple;
35
- if ((docMultiple === null || docMultiple === void 0 ? void 0 : docMultiple.enabled) !== true)
36
- return undefined;
37
- return typeof docMultiple.repeatOption === "number"
38
- ? docMultiple.repeatOption
39
- : undefined;
40
- };
41
30
  SectionRender.prototype.renderSection = function () {
42
31
  var _this = this;
43
32
  var section = this.references.sections[this.documentName][this.currentSection];
44
33
  var conditionObject = this.references.conditions.sections[this.documentName][this.currentSection];
45
34
  var condition = conditionObject === undefined
46
35
  ? true
47
- : this.conditions.executeCondition(conditionObject, 0, this.baseIndex, "sections");
48
- if (condition !== true)
49
- return;
50
- var documentMultipleSource = this.getDocumentMultipleSource();
51
- section.options.forEach(function (optionId) {
52
- var option = _this.references.options[optionId];
53
- if (option.meta.type === "repeated" &&
54
- documentMultipleSource !== undefined &&
55
- option.meta.repeatOption === documentMultipleSource) {
56
- option.options.forEach(function (childId) {
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;
57
55
  _this.outputs = __spreadArray(__spreadArray([], _this.outputs, true), new OptionRender_1.default({
58
56
  references: _this.references,
59
- id: childId,
57
+ id: optionId,
60
58
  ovc: _this.ovc,
61
- index: _this.baseIndex,
59
+ index: index,
62
60
  conditions: _this.conditions,
63
61
  numauto: _this.NumAuto,
64
62
  }).getOutputs(), true);
65
63
  });
66
- return;
67
- }
68
- var repeatOption = optionId;
69
- if (option.meta.type === "repeated") {
70
- if (option.meta.repeatOption === undefined)
71
- return;
72
- repeatOption =
73
- typeof option.meta.repeatOption === "number"
74
- ? option.meta.repeatOption
75
- : parseInt(option.meta.repeatOption, 10);
76
- }
77
- var inputs = _this.ovc.options[repeatOption] || [
78
- !["radio", "checkbox"].includes(option.meta.type),
79
- ];
80
- if (documentMultipleSource !== undefined &&
81
- option.meta.type !== "repeated") {
82
- var valueAtIndex = _this.baseIndex < inputs.length ? inputs[_this.baseIndex] : inputs[0];
83
- if (valueAtIndex !== true)
84
- return;
85
- _this.outputs = __spreadArray(__spreadArray([], _this.outputs, true), new OptionRender_1.default({
86
- references: _this.references,
87
- id: optionId,
88
- ovc: _this.ovc,
89
- index: _this.baseIndex,
90
- conditions: _this.conditions,
91
- numauto: _this.NumAuto,
92
- }).getOutputs(), true);
93
- return;
94
- }
95
- inputs.forEach(function (value, index) {
96
- if (value !== true)
97
- return;
98
- _this.outputs = __spreadArray(__spreadArray([], _this.outputs, true), new OptionRender_1.default({
99
- references: _this.references,
100
- id: optionId,
101
- ovc: _this.ovc,
102
- index: index,
103
- conditions: _this.conditions,
104
- numauto: _this.NumAuto,
105
- }).getOutputs(), true);
106
64
  });
107
- });
65
+ }
108
66
  };
109
67
  return SectionRender;
110
68
  }());
@@ -6,11 +6,11 @@ declare class FillPdfFormBase {
6
6
  conditions: ConditionsRunner;
7
7
  ovc: InputsType;
8
8
  constructor(references: Types.ReferencesType, conditions: ConditionsRunner, ovc: InputsType);
9
- private readonly conditionEvaluator;
10
9
  isVariableDisplayed(id: number, index: number): boolean;
11
10
  isOptionDisplayed(id: number, index: number): boolean;
12
11
  private getVariableCondition;
13
12
  private getOptionCondition;
14
13
  private getSectionCondition;
14
+ private getOptionParentSection;
15
15
  }
16
16
  export default FillPdfFormBase;
@@ -1,25 +1,41 @@
1
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
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var referencesparser_1 = require("@legalplace/referencesparser");
4
12
  var FillPdfFormBase = (function () {
5
13
  function FillPdfFormBase(references, conditions, ovc) {
6
- var _this = this;
7
- this.conditionEvaluator = function (type, id, index) {
8
- if (type === "options")
9
- return _this.getOptionCondition(id, index);
10
- if (type === "variables")
11
- return _this.getVariableCondition(id, index);
12
- return _this.getSectionCondition(id);
13
- };
14
14
  this.references = references;
15
15
  this.conditions = conditions;
16
16
  this.ovc = ovc;
17
17
  }
18
18
  FillPdfFormBase.prototype.isVariableDisplayed = function (id, index) {
19
- return (0, referencesparser_1.isVariableDisplayed)(this.references, this.ovc, this.conditionEvaluator, 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);
20
25
  };
21
26
  FillPdfFormBase.prototype.isOptionDisplayed = function (id, index) {
22
- return (0, referencesparser_1.isOptionDisplayed)(this.references, this.ovc, this.conditionEvaluator, 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);
23
39
  };
24
40
  FillPdfFormBase.prototype.getVariableCondition = function (id, index) {
25
41
  var conditionObject = this.references.conditions.variables[id];
@@ -39,6 +55,16 @@ var FillPdfFormBase = (function () {
39
55
  ? true
40
56
  : this.conditions.executeCondition(conditionObject, id, 0, "sections");
41
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
+ };
42
68
  return FillPdfFormBase;
43
69
  }());
44
70
  exports.default = FillPdfFormBase;
@@ -1,30 +1,17 @@
1
- import type { DocumentLayoutV3 } from "@legalplace/models-v3-types";
2
1
  export type DocumentOutputIndex = {
3
2
  name: string;
4
3
  slug: string;
5
4
  pdf: boolean;
6
5
  docx: boolean;
7
- occurrenceIndex?: number;
8
6
  };
9
7
  export type DocumentPdfFormIndex = {
10
8
  name: string;
11
9
  slug: string;
12
10
  form: boolean;
13
11
  fdf: FDFType;
14
- occurrenceIndex?: number;
15
12
  };
16
13
  export type DocumentIndex = Record<string, DocumentOutputIndex | DocumentPdfFormIndex>;
17
14
  export type FDFType = {
18
15
  id: string;
19
16
  fields: Record<string, string>;
20
17
  };
21
- export type DocumentLayout = {
22
- header?: string;
23
- footer?: string;
24
- firstPageHeader?: string;
25
- firstPageFooter?: string;
26
- differentFirstPage: boolean;
27
- margins?: DocumentLayoutV3["margins"];
28
- headerDistance?: number;
29
- footerDistance?: number;
30
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legalplace/prerenderx",
3
- "version": "3.8.18-staging.2",
3
+ "version": "3.8.19",
4
4
  "description": "PrerenderX",
5
5
  "main": "dist/index.js",
6
6
  "repository": "https://git.legalplace.eu/legalplace/prerenderx",
@@ -16,25 +16,26 @@
16
16
  "release": "standard-version -a --no-verify"
17
17
  },
18
18
  "dependencies": {
19
- "@legalplace/conditions-runner": "2.2.15-staging.1",
20
- "@legalplace/eslint-config-base": "^1.2.0",
21
- "@legalplace/lplogic": "2.3.2-staging.0",
22
- "@legalplace/models-v3-types": "5.17.17-staging.1",
23
- "@legalplace/ovc-converter": "2.2.15-staging.1",
24
- "@legalplace/prettier-config": "^2.1.3",
25
- "@legalplace/referencesparser": "3.2.34-staging.1",
19
+ "@legalplace/conditions-runner": "^2.2.15",
20
+ "@legalplace/lplogic": "2.3.1",
21
+ "@legalplace/models-v3-types": "^5.17.11",
22
+ "@legalplace/ovc-converter": "^2.2.15",
23
+ "@legalplace/referencesparser": "^3.2.34",
26
24
  "@legalplace/yousign": "^0.9.13",
27
- "crypto": "^1.0.1",
28
- "standard-version": "^9.3.1"
25
+ "crypto": "^1.0.1"
29
26
  },
30
27
  "devDependencies": {
31
28
  "@babel/core": "^7.7.2",
32
29
  "@babel/preset-typescript": "^7.7.2",
33
- "@legalplace/types": "^2.22.1",
30
+ "@legalplace/eslint-config-base": "^1.2.0",
31
+ "@legalplace/prettier-config": "^2.1.3",
32
+ "@legalplace/types": "^2.22.4",
34
33
  "@types/jest": "^24.0.15",
35
34
  "jest": "^24.8.0",
36
35
  "redux-mock-store": "^1.5.3",
36
+ "standard-version": "^9.3.1",
37
37
  "ts-jest": "^24.0.2"
38
38
  },
39
- "prettier": "@legalplace/prettier-config"
39
+ "prettier": "@legalplace/prettier-config",
40
+ "gitHead": "419c4a6d077d663f332b34dc27147cc0b11d6a9f"
40
41
  }
@@ -1,9 +1,5 @@
1
+ import type { Types } from "@legalplace/referencesparser";
1
2
  import type ConditionsRunner from "@legalplace/conditions-runner";
2
- import {
3
- getSectionIdsForRole,
4
- type OutputRegionRole,
5
- type Types,
6
- } from "@legalplace/referencesparser";
7
3
  import type InputsType from "@legalplace/types/dist/inputs";
8
4
  import SectionRender from "./SectionRender";
9
5
  import type NumAuto from "./NumAuto";
@@ -29,42 +25,18 @@ class DocumentRender {
29
25
  this.NumAuto = numauto;
30
26
  }
31
27
 
32
- /**
33
- * Renders a document body. When `baseIndex` is provided (document multiple),
34
- * the index is propagated through the section/option render pipeline
35
- * so that variables referenced anywhere in the document resolve at the
36
- * correct occurrence.
37
- */
38
- public renderDocument(documentName: string, baseIndex = 0) {
39
- return this.renderRegion(documentName, "body", baseIndex);
40
- }
41
-
42
- /**
43
- * Renders a document output region (body, header, footer, first page variants).
44
- */
45
- public renderRegion(
46
- documentName: string,
47
- role: OutputRegionRole,
48
- baseIndex = 0
49
- ) {
28
+ public renderDocument(documentName: string) {
50
29
  const documentOutputs: string[] = [];
51
- if (role === "body") this.NumAuto.resetIndexes();
52
-
53
- const sectionIds = getSectionIdsForRole(
54
- this.references.sections[documentName],
55
- role
56
- );
57
-
58
- sectionIds.forEach((sectionId) => {
30
+ this.NumAuto.resetIndexes();
31
+ Object.keys(this.references.sections[documentName]).forEach((sectionId) => {
59
32
  documentOutputs.push(
60
33
  ...new SectionRender({
61
34
  references: this.references,
62
35
  conditions: this.conditions,
63
36
  documentName,
64
37
  ovc: this.ovc,
65
- currentSection: sectionId,
38
+ currentSection: parseInt(sectionId, 10),
66
39
  numauto: this.NumAuto,
67
- baseIndex,
68
40
  }).getOutputs()
69
41
  );
70
42
  });
@@ -6,13 +6,7 @@ type FDFType = {
6
6
  fields: Record<string, string>;
7
7
  };
8
8
  class FillPdfForm extends FillPdfFormBase {
9
- /**
10
- * Fills a PDF form template with values from `ovc`. When `baseIndex` is
11
- * provided (document multiple), variables and options are read at that
12
- * occurrence index instead of always reading slot 0. Each occurrence of
13
- * a multiple PDF form document yields its own filled FDF.
14
- */
15
- public fillDocument(documentName: string, baseIndex = 0) {
9
+ public fillDocument(documentName: string) {
16
10
  const result: FDFType = {
17
11
  id: "",
18
12
  fields: {},
@@ -30,13 +24,13 @@ class FillPdfForm extends FillPdfFormBase {
30
24
  // Filling inputs
31
25
  form.inputs.forEach((input) => {
32
26
  const id = `${input.name}`;
33
- result.fields[id] = this.getInputValue(input, baseIndex);
27
+ result.fields[id] = this.getInputValue(input);
34
28
  });
35
29
 
36
30
  // Filling boxes
37
31
  form.boxes.forEach((box) => {
38
32
  const id = `${box.name}`;
39
- const value = this.getBoxValue(box, baseIndex);
33
+ const value = this.getBoxValue(box);
40
34
  if (
41
35
  !(
42
36
  value === "" &&
@@ -50,14 +44,13 @@ class FillPdfForm extends FillPdfFormBase {
50
44
  }
51
45
 
52
46
  /**
53
- * Returns an input value at the given occurrence `index`.
47
+ * Returns an input value
54
48
  * @param input Input
55
- * @param index Occurrence index (defaults to 0)
56
49
  */
57
- private getInputValue(input: FDFInputsV3, index = 0): string {
50
+ private getInputValue(input: FDFInputsV3): string {
58
51
  for (let i = 0; i < input.variables.length; i += 1) {
59
52
  const variable = input.variables[i];
60
- const currentValue = this.getVariableValue(variable.id, index);
53
+ const currentValue = this.getVariableValue(variable.id);
61
54
 
62
55
  if (currentValue !== false) {
63
56
  // Date values
@@ -117,14 +110,13 @@ class FillPdfForm extends FillPdfFormBase {
117
110
  }
118
111
 
119
112
  /**
120
- * Return a box value at the given occurrence `index`.
113
+ * Return a box value
121
114
  * @param box Box
122
- * @param index Occurrence index (defaults to 0)
123
115
  */
124
- private getBoxValue(box: FDFBoxesV3, index = 0): string {
116
+ private getBoxValue(box: FDFBoxesV3): string {
125
117
  for (let i = 0; i < box.options.length; i += 1) {
126
118
  const option = box.options[i];
127
- const currentValue = this.getOptionValue(option.id, index);
119
+ const currentValue = this.getOptionValue(option.id);
128
120
 
129
121
  if (currentValue === true) {
130
122
  if (
@@ -140,34 +132,25 @@ class FillPdfForm extends FillPdfFormBase {
140
132
  }
141
133
 
142
134
  /**
143
- * Returns a variable's value at the given occurrence `index`. Falls back
144
- * to slot 0 when the requested index is missing (e.g. a non-multiple
145
- * variable inside a multiple document).
135
+ * Returns a variable's value
146
136
  */
147
- private getVariableValue(variableId: number, index = 0) {
148
- // Checking if variable is displayed at the given occurrence
149
- if (this.isVariableDisplayed(variableId, index) === false) return false;
137
+ private getVariableValue(variableId: number) {
138
+ // Checking if variable is displayed
139
+ if (this.isVariableDisplayed(variableId, 0) === false) return false;
150
140
 
151
- const variableValues = this.ovc.variables[variableId];
152
- const value =
153
- variableValues?.[index] !== undefined
154
- ? variableValues[index]
155
- : variableValues?.[0] || "";
156
-
157
- return (value ?? "").toString();
141
+ // Returning variable's value
142
+ return (this.ovc.variables[variableId]?.[0] || "").toString();
158
143
  }
159
144
 
160
145
  /**
161
- * Returns an option's boolean value at the given occurrence `index`.
146
+ * Returns a option's value
162
147
  */
163
- private getOptionValue(optionId: number, index = 0) {
164
- // Checking if option is displayed at the given occurrence
165
- if (this.isOptionDisplayed(optionId, index) === false) return false;
166
-
167
- const optionValues = this.ovc.options[optionId];
168
- return optionValues?.[index] !== undefined
169
- ? optionValues[index] === true
170
- : optionValues?.[0] === true;
148
+ private getOptionValue(optionId: number) {
149
+ // Checking if option is displayed
150
+ if (this.isOptionDisplayed(optionId, 0) === false) return false;
151
+
152
+ // Returning option's value
153
+ return this.ovc.options[optionId]?.[0] === true;
171
154
  }
172
155
  }
173
156