@legalplace/prerenderx 2.2.2 → 2.2.4

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/.gitlab-ci.yml CHANGED
@@ -13,19 +13,13 @@ variables:
13
13
 
14
14
  setup:
15
15
  stage: setup
16
- cache:
17
- key: yarn-cache-front
18
- untracked: true
19
- paths:
20
- - .yarn-cache-front
21
- policy: pull-push
22
16
  only:
23
17
  changes:
24
18
  - yarn.lock
25
19
  - package.json
26
20
  - .gitlab-ci.yml
27
21
  script:
28
- - yarn install --frozen-lockfile --check-files --silent --cache-folder .yarn-cache-front
22
+ - yarn install --frozen-lockfile --check-files --silent
29
23
  - yarn build
30
24
 
31
25
  publish:
@@ -38,4 +32,7 @@ publish:
38
32
  environment:
39
33
  name: development
40
34
  only:
41
- - master
35
+ refs:
36
+ - master
37
+ changes:
38
+ - package.json
package/.prettierrc.js ADDED
@@ -0,0 +1,10 @@
1
+ module.exports = {
2
+ printWidth: 180,
3
+ useTabs: false,
4
+ tabWidth: 2,
5
+ semi: false,
6
+ singleQuote: true,
7
+ trailingComma: 'none',
8
+ parser: 'typescript',
9
+ endOfLine: 'lf'
10
+ }
@@ -4,9 +4,6 @@
4
4
  "eslint.options": {
5
5
  "extensions": [".ts", ".js"]
6
6
  },
7
- "editor.codeActionsOnSave": {
8
- "source.fixAll.eslint": true
9
- },
10
7
  "files.autoSave": "off",
11
8
  "editor.formatOnSave": false,
12
9
  "editor.formatOnType": true,
@@ -14,4 +11,7 @@
14
11
  "eslint.packageManager": "yarn",
15
12
  "eslint.quiet": true,
16
13
  "typescript.tsdk": "node_modules/typescript/lib",
14
+ "editor.codeActionsOnSave": {
15
+ "source.fixAll.eslint": true
16
+ }
17
17
  }
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import Prerender from "./libs/Prerender";
2
- export { Prerender };
1
+ import Prerender from './libs/Prerender';
2
+ export default Prerender;
package/dist/index.js CHANGED
@@ -4,4 +4,4 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  var Prerender_1 = __importDefault(require("./libs/Prerender"));
7
- exports.Prerender = Prerender_1.default;
7
+ exports.default = Prerender_1.default;
@@ -1,6 +1,6 @@
1
- import { Types } from "@legalplace/referencesparser";
2
- import { ConditionV3 } from "@legalplace/models-v3-types";
3
- import { ConditionDataMap } from "./DataPopulator";
1
+ import { Types } from '@legalplace/referencesparser';
2
+ import { ConditionV3 } from '@legalplace/models-v3-types';
3
+ import { ConditionDataMap } from './DataPopulator';
4
4
  declare type OVC_TYPE = {
5
5
  options: {
6
6
  [key: string]: boolean[];
@@ -19,6 +19,6 @@ declare class ConditionsRunner {
19
19
  executeCondition(condition: {
20
20
  dataMap: ConditionDataMap;
21
21
  conditions: ConditionV3;
22
- }, id: number, index: number, conditionType: "options" | "optionValidator" | "variables" | "prefillers" | "variableValidator" | "sections" | "documents"): any;
22
+ }, id: number, index: number, conditionType: 'options' | 'optionValidator' | 'variables' | 'prefillers' | 'variableValidator' | 'sections' | 'documents'): any;
23
23
  }
24
24
  export default ConditionsRunner;
@@ -13,30 +13,21 @@ var ConditionsRunner = (function () {
13
13
  ConditionsRunner.prototype.isOptionRelatedToOption = function (optionA, optionB) {
14
14
  var OptionBParents = this.references.relations.options[optionB].parents;
15
15
  var OptionBRoot = OptionBParents[OptionBParents.length - 1];
16
- var OptionBRootRelations = OptionBRoot
17
- ? this.references.relations.options[OptionBRoot]
18
- : undefined;
16
+ var OptionBRootRelations = OptionBRoot ? this.references.relations.options[OptionBRoot] : undefined;
19
17
  if (OptionBRootRelations) {
20
- if (optionA === optionB ||
21
- OptionBRootRelations.children.options.includes(optionA) ||
22
- OptionBRootRelations.dependants.includes(optionA)) {
18
+ if (optionA === optionB || OptionBRootRelations.children.options.includes(optionA) || OptionBRootRelations.dependants.includes(optionA)) {
23
19
  return true;
24
20
  }
25
21
  }
26
22
  return false;
27
23
  };
28
24
  ConditionsRunner.prototype.isVariableRelatedToOption = function (variableId, optionId) {
29
- var variableParentId = this.references.relations.variables[variableId]
30
- .parents[0];
31
- var optionParents = this.references.relations.options[variableParentId]
32
- .parents;
25
+ var variableParentId = this.references.relations.variables[variableId].parents[0];
26
+ var optionParents = this.references.relations.options[variableParentId].parents;
33
27
  var optionRoot = optionParents[optionParents.length - 1];
34
- var optionRootRelations = optionRoot
35
- ? this.references.relations.options[optionRoot]
36
- : undefined;
28
+ var optionRootRelations = optionRoot ? this.references.relations.options[optionRoot] : undefined;
37
29
  if (optionRootRelations) {
38
- if (optionRootRelations.children.options.includes(optionId) ||
39
- optionRootRelations.dependants.includes(optionId)) {
30
+ if (optionRootRelations.children.options.includes(optionId) || optionRootRelations.dependants.includes(optionId)) {
40
31
  return true;
41
32
  }
42
33
  }
@@ -47,13 +38,9 @@ var ConditionsRunner = (function () {
47
38
  var optionB = this.references.relations.variables[variableB].parents[0];
48
39
  var OptionBParents = this.references.relations.options[optionB].parents;
49
40
  var OptionBRoot = OptionBParents[OptionBParents.length - 1];
50
- var OptionBRootRelations = OptionBRoot
51
- ? this.references.relations.options[OptionBRoot]
52
- : undefined;
41
+ var OptionBRootRelations = OptionBRoot ? this.references.relations.options[OptionBRoot] : undefined;
53
42
  if (OptionBRootRelations) {
54
- if (optionA === optionB ||
55
- OptionBRootRelations.children.options.includes(optionA) ||
56
- OptionBRootRelations.dependants.includes(optionA)) {
43
+ if (optionA === optionB || OptionBRootRelations.children.options.includes(optionA) || OptionBRootRelations.dependants.includes(optionA)) {
57
44
  return true;
58
45
  }
59
46
  }
@@ -62,20 +49,16 @@ var ConditionsRunner = (function () {
62
49
  ConditionsRunner.prototype.executeCondition = function (condition, id, index, conditionType) {
63
50
  var _this = this;
64
51
  if (Array.isArray(condition))
65
- return condition.map(function (_condition) {
66
- return _this.executeCondition(_condition, id, index, conditionType);
67
- });
52
+ return condition.map(function (_condition) { return _this.executeCondition(_condition, id, index, conditionType); });
68
53
  var currentData;
69
- if (conditionType === "options" || conditionType === "optionValidator") {
54
+ if (conditionType === 'options' || conditionType === 'optionValidator') {
70
55
  currentData = new DataPopulator_1.default(this, this.references, this.ovc, condition.dataMap, id, index).getData();
71
56
  }
72
- else if (conditionType === "variables" ||
73
- conditionType === "prefillers" ||
74
- conditionType === "variableValidator") {
57
+ else if (conditionType === 'variables' || conditionType === 'prefillers' || conditionType === 'variableValidator') {
75
58
  var dataId = this.references.relations.variables[id].parents[0];
76
59
  currentData = new DataPopulator_1.default(this, this.references, this.ovc, condition.dataMap, dataId, index).getData();
77
60
  }
78
- else if (conditionType === "sections" || conditionType === "documents") {
61
+ else if (conditionType === 'sections' || conditionType === 'documents') {
79
62
  currentData = new DataPopulator_1.default(this, this.references, this.ovc, condition.dataMap, id, index).getData();
80
63
  }
81
64
  return lplogic_1.default(condition.conditions, currentData);
@@ -1,7 +1,7 @@
1
- import { Types } from "@legalplace/referencesparser";
2
- import ConditionsRunner from "./ConditionsRunner";
3
- import OVC_TYPE from "./ovc.type";
4
- import NumAuto from "./NumAuto";
1
+ import { Types } from '@legalplace/referencesparser';
2
+ import ConditionsRunner from './ConditionsRunner';
3
+ import OVC_TYPE from './ovc.type';
4
+ import NumAuto from './NumAuto';
5
5
  declare class DocumentRender {
6
6
  references: Types.ReferencesType;
7
7
  conditions: ConditionsRunner;
@@ -27,7 +27,7 @@ var DocumentRender = (function () {
27
27
  numauto: _this.NumAuto
28
28
  }).getOutputs());
29
29
  });
30
- return documentOutputs.join("");
30
+ return documentOutputs.join('');
31
31
  };
32
32
  return DocumentRender;
33
33
  }());
@@ -12,7 +12,7 @@ var NumAuto = (function () {
12
12
  _this.indexesList[index] = 0;
13
13
  }
14
14
  _this.indexesList[index] += 1;
15
- if (typeof tag === "string")
15
+ if (typeof tag === 'string')
16
16
  _this.tagsIndex[tag] = _this.indexesList[index];
17
17
  return _this.indexesList[index];
18
18
  };
@@ -1,7 +1,7 @@
1
- import { Types } from "@legalplace/referencesparser";
2
- import ConditionsRunner from "./ConditionsRunner";
3
- import OVC_TYPE from "./ovc.type";
4
- import NumAuto from "./NumAuto";
1
+ import { Types } from '@legalplace/referencesparser';
2
+ import ConditionsRunner from './ConditionsRunner';
3
+ import OVC_TYPE from './ovc.type';
4
+ import NumAuto from './NumAuto';
5
5
  declare class OptionRender {
6
6
  outputs: string[];
7
7
  references: Types.ReferencesType;
@@ -26,25 +26,15 @@ var OptionRender = (function () {
26
26
  var _this = this;
27
27
  var option = this.references.options[this.id];
28
28
  var conditionObject = this.references.conditions.options[this.id];
29
- var condition = conditionObject === undefined
30
- ? true
31
- : this.conditions.executeCondition(conditionObject, this.id, this.index, "options");
29
+ var condition = conditionObject === undefined ? true : this.conditions.executeCondition(conditionObject, this.id, this.index, 'options');
32
30
  if (condition === true) {
33
- if (typeof option.meta.output === "string" &&
34
- option.meta.output.trim().length > 0) {
31
+ if (typeof option.meta.output === 'string' && option.meta.output.trim().length > 0) {
35
32
  var outputReference = this.references.outputs[this.id];
36
33
  var autonums = [];
37
34
  if (condition !== false) {
38
35
  autonums = outputReference.autonums.map(function (currentAn) {
39
- var fn = currentAn[0] === "numauto-pre"
40
- ? _this.NumAuto.getNumPre
41
- : _this.NumAuto.getNum;
42
- return [
43
- currentAn[0],
44
- currentAn[1],
45
- fn(currentAn[1], currentAn[2]),
46
- currentAn[2]
47
- ];
36
+ var fn = currentAn[0] === 'numauto-pre' ? _this.NumAuto.getNumPre : _this.NumAuto.getNum;
37
+ return [currentAn[0], currentAn[1], fn(currentAn[1], currentAn[2]), currentAn[2]];
48
38
  });
49
39
  }
50
40
  var variables = OutputParser_1.getRelatedVariablesValues(this.id, this.index, outputReference.variables, this.ovc, this.references);
@@ -1,5 +1,5 @@
1
- import { Types } from "@legalplace/referencesparser";
2
- import OVC_TYPE from "./ovc.type";
1
+ import { Types } from '@legalplace/referencesparser';
2
+ import OVC_TYPE from './ovc.type';
3
3
  declare type relVarsValsT = Record<string, string | number>;
4
4
  declare type getRelatedVarsT = (optionId: number, index: number, variables: number[], ovc: OVC_TYPE, references: Types.ReferencesType) => relVarsValsT;
5
5
  export declare const getRelatedVariablesValues: getRelatedVarsT;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getRelatedVariablesValues = function (optionId, index, variables, ovc, references) {
4
4
  var variablesValues = {};
5
5
  variables.forEach(function (currentVariableId) {
6
- var value = ovc.variables[currentVariableId] || [""];
6
+ var value = ovc.variables[currentVariableId] || [''];
7
7
  var variableParents = references.relations.variables[currentVariableId].parents;
8
8
  if (variableParents === undefined)
9
9
  throw new Error("Variable " + currentVariableId + " parents object does not exist");
@@ -11,21 +11,18 @@ exports.getRelatedVariablesValues = function (optionId, index, variables, ovc, r
11
11
  var rootVariableParentRelations = references.relations.options[rootVariableParentId];
12
12
  if (rootVariableParentRelations === undefined)
13
13
  throw new Error("Option " + rootVariableParentId + " does not exist");
14
- if (typeof variableParents === "undefined")
14
+ if (typeof variableParents === 'undefined')
15
15
  return;
16
- if (rootVariableParentRelations.children.options.includes(optionId) ||
17
- rootVariableParentRelations.dependants.includes(optionId) ||
18
- optionId === rootVariableParentId)
16
+ if (rootVariableParentRelations.children.options.includes(optionId) || rootVariableParentRelations.dependants.includes(optionId) || optionId === rootVariableParentId)
19
17
  value = [value[index]];
20
18
  var cleanValues = value.map(function (currentValue) {
21
- if (typeof currentValue === "number")
19
+ if (typeof currentValue === 'number')
22
20
  return currentValue.toString();
23
- if (typeof currentValue === "string")
21
+ if (typeof currentValue === 'string')
24
22
  return currentValue;
25
- return "";
23
+ return '';
26
24
  });
27
- variablesValues[currentVariableId] =
28
- cleanValues.length === 1 ? cleanValues[0] : cleanValues.join(", ");
25
+ variablesValues[currentVariableId] = cleanValues.length === 1 ? cleanValues[0] : cleanValues.join(', ');
29
26
  });
30
27
  return variablesValues;
31
28
  };
@@ -34,12 +31,12 @@ exports.parseOutputWithVariables = function (output, variables, autonums) {
34
31
  Object.keys(variables).forEach(function (variableId) {
35
32
  var value = variables[variableId].toString();
36
33
  if (value.trim().length === 0) {
37
- value = new Array(16).join("_");
34
+ value = new Array(16).join('_');
38
35
  }
39
- parsedOutput = parsedOutput.replace(new RegExp("\\[var:" + variableId + "\\]", "g"), value);
36
+ parsedOutput = parsedOutput.replace(new RegExp("\\[var:" + variableId + "\\]", 'g'), value);
40
37
  });
41
38
  parsedOutput = parsedOutput.replace(/\[\[PAGE_BREAK\]\]/gi, '<div style="page-break-after:always"></div>');
42
- parsedOutput = parsedOutput.replace(/\[(E|B)_BLUR\]/gi, "");
39
+ parsedOutput = parsedOutput.replace(/\[(E|B)_BLUR\]/gi, '');
43
40
  autonums.forEach(function (currentAn) {
44
41
  if (currentAn[3] === null)
45
42
  parsedOutput = parsedOutput.replace("[" + currentAn[0] + ":" + currentAn[1] + "]", "<span class=\"" + currentAn[0] + "\">" + currentAn[2] + "</span>");
@@ -1,6 +1,6 @@
1
- import { ModelV3 } from "@legalplace/models-v3-types";
2
- import OVC_TYPE from "./ovc.type";
3
- import { OldOVC } from "./OvcConverter";
1
+ import { ModelV3 } from '@legalplace/models-v3-types';
2
+ import OVC_TYPE from './ovc.type';
3
+ import { OldOVC } from './OvcConverter';
4
4
  declare class Prerender {
5
5
  private model;
6
6
  private references;
@@ -15,9 +15,7 @@ var Prerender = (function () {
15
15
  this.documentsIndex = {};
16
16
  this.renderedDocuments = {};
17
17
  this.model = model;
18
- this.ovc = OvcConverter_1.default.isOvc(ovc)
19
- ? OvcConverter_1.default.convertToOptionsVariables(ovc)
20
- : ovc;
18
+ this.ovc = OvcConverter_1.default.isOvc(ovc) ? OvcConverter_1.default.convertToOptionsVariables(ovc) : ovc;
21
19
  this.NumAuto = new NumAuto_1.default();
22
20
  this.references = new referencesparser_1.ReferencesParser(model).getReferences();
23
21
  var inputs = new InputsInitiator_1.default(this.references, this.ovc).getInputs();
@@ -33,14 +31,12 @@ var Prerender = (function () {
33
31
  var _this = this;
34
32
  Object.keys(this.model.documents).forEach(function (documentName) {
35
33
  var conditionObject = _this.references.conditions.documents[documentName];
36
- var condition = conditionObject === undefined
37
- ? true
38
- : _this.conditions.executeCondition(conditionObject, 0, 0, "documents");
34
+ var condition = conditionObject === undefined ? true : _this.conditions.executeCondition(conditionObject, 0, 0, 'documents');
39
35
  if (condition === true) {
40
36
  var hash = crypto_1.default
41
- .createHash("sha1")
37
+ .createHash('sha1')
42
38
  .update(documentName)
43
- .digest("hex");
39
+ .digest('hex');
44
40
  _this.documentsIndex[hash] = {
45
41
  name: documentName,
46
42
  pdf: true,
@@ -1,7 +1,7 @@
1
- import { Types } from "@legalplace/referencesparser";
2
- import ConditionsRunner from "./ConditionsRunner";
3
- import OVC_TYPE from "./ovc.type";
4
- import NumAuto from "./NumAuto";
1
+ import { Types } from '@legalplace/referencesparser';
2
+ import ConditionsRunner from './ConditionsRunner';
3
+ import OVC_TYPE from './ovc.type';
4
+ import NumAuto from './NumAuto';
5
5
  declare class SectionRender {
6
6
  outputs: string[];
7
7
  references: Types.ReferencesType;
@@ -29,24 +29,17 @@ var SectionRender = (function () {
29
29
  var _this = this;
30
30
  var section = this.references.sections[this.documentName][this.currentSection];
31
31
  var conditionObject = this.references.conditions.sections[this.documentName][this.currentSection];
32
- var condition = conditionObject === undefined
33
- ? true
34
- : this.conditions.executeCondition(conditionObject, 0, 0, "sections");
32
+ var condition = conditionObject === undefined ? true : this.conditions.executeCondition(conditionObject, 0, 0, 'sections');
35
33
  if (condition === true) {
36
34
  section.options.forEach(function (optionId) {
37
35
  var option = _this.references.options[optionId];
38
36
  var repeatOption = optionId;
39
- if (option.meta.type === "repeated") {
37
+ if (option.meta.type === 'repeated') {
40
38
  if (option.meta.repeatOption === undefined)
41
39
  return;
42
- repeatOption =
43
- typeof option.meta.repeatOption === "number"
44
- ? option.meta.repeatOption
45
- : parseInt(option.meta.repeatOption, 10);
40
+ repeatOption = typeof option.meta.repeatOption === 'number' ? option.meta.repeatOption : parseInt(option.meta.repeatOption, 10);
46
41
  }
47
- var inputs = _this.ovc.options[repeatOption] || [
48
- !["radio", "checkbox"].includes(option.meta.type)
49
- ];
42
+ var inputs = _this.ovc.options[repeatOption] || [!['radio', 'checkbox'].includes(option.meta.type)];
50
43
  inputs.forEach(function (value, index) {
51
44
  if (value !== true)
52
45
  return;
package/package.json CHANGED
@@ -1,21 +1,24 @@
1
1
  {
2
2
  "name": "@legalplace/prerenderx",
3
- "version": "2.2.2",
3
+ "version": "2.2.4",
4
4
  "description": "PrerenderX",
5
5
  "main": "dist/index.js",
6
6
  "repository": "https://git.legalplace.eu/legalplace/prerenderx",
7
7
  "author": "Moncef Hammou <moncef@legalplace.fr> <moncef@legalplace.fr>",
8
8
  "license": "MIT",
9
9
  "scripts": {
10
- "lint": "npx eslint ./src/ --ext ts,js",
11
- "test": "npx jest",
12
- "build": "npx tsc"
10
+ "format": "prettier --single-quote --no-semi --trailing-comma none --write \"src/**/*.{js,ts,tsx}\"",
11
+ "lint": "tsc && eslint ./src/ --ext ts,js",
12
+ "lint:fix": "tsc && eslint 'src/**/*.{js,jsx,ts,tsx}' --fix",
13
+ "test": "jest",
14
+ "build": "tsc"
13
15
  },
14
16
  "dependencies": {
15
- "crypto": "^1.0.1",
16
17
  "@legalplace/lplogic": "^2.0.0",
17
18
  "@legalplace/models-v3-types": "^3.1.1",
18
- "@legalplace/referencesparser": "^1.2.0"
19
+ "@legalplace/referencesparser": "^1.2.0",
20
+ "crypto": "^1.0.1",
21
+ "typescript": "3.9.3"
19
22
  },
20
23
  "devDependencies": {
21
24
  "@babel/core": "^7.7.2",
@@ -33,7 +36,6 @@
33
36
  "jest": "^24.8.0",
34
37
  "prettier": "1.19.1",
35
38
  "redux-mock-store": "^1.5.3",
36
- "ts-jest": "^24.0.2",
37
- "typescript": "^3.7.2"
39
+ "ts-jest": "^24.0.2"
38
40
  }
39
41
  }
package/src/index.ts CHANGED
@@ -1,3 +1,3 @@
1
- import Prerender from "./libs/Prerender";
1
+ import Prerender from './libs/Prerender'
2
2
 
3
- export { Prerender };
3
+ export default Prerender