@oneblink/sdk-core 0.3.6-beta.3 → 0.4.0-beta.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.
Files changed (60) hide show
  1. package/README.md +2 -8
  2. package/dist/abnService.d.ts +53 -0
  3. package/dist/abnService.js +53 -0
  4. package/dist/abnService.js.map +1 -1
  5. package/dist/conditionalLogicService/conditionallyShowElement.js +9 -19
  6. package/dist/conditionalLogicService/conditionallyShowElement.js.map +1 -1
  7. package/dist/conditionalLogicService/conditionallyShowOption.js +3 -3
  8. package/dist/conditionalLogicService/conditionallyShowOption.js.map +1 -1
  9. package/dist/conditionalLogicService/evaluateConditionalOptionsPredicate.d.ts +6 -0
  10. package/dist/conditionalLogicService/evaluateConditionalOptionsPredicate.js +26 -0
  11. package/dist/conditionalLogicService/evaluateConditionalOptionsPredicate.js.map +1 -0
  12. package/dist/conditionalLogicService/evaluateConditionalPredicate.d.ts +6 -0
  13. package/dist/conditionalLogicService/evaluateConditionalPredicate.js +114 -0
  14. package/dist/conditionalLogicService/evaluateConditionalPredicate.js.map +1 -0
  15. package/dist/conditionalLogicService/generateFormElementsConditionallyShown.d.ts +111 -9
  16. package/dist/conditionalLogicService/generateFormElementsConditionallyShown.js +95 -4
  17. package/dist/conditionalLogicService/generateFormElementsConditionallyShown.js.map +1 -1
  18. package/dist/conditionalLogicService.d.ts +71 -0
  19. package/dist/conditionalLogicService.js +106 -0
  20. package/dist/conditionalLogicService.js.map +1 -0
  21. package/dist/fileUploadService.d.ts +14 -0
  22. package/dist/fileUploadService.js +14 -0
  23. package/dist/fileUploadService.js.map +1 -1
  24. package/dist/formElementsService.d.ts +83 -4
  25. package/dist/formElementsService.js +83 -15
  26. package/dist/formElementsService.js.map +1 -1
  27. package/dist/index.d.ts +85 -4
  28. package/dist/index.js +91 -9
  29. package/dist/index.js.map +1 -1
  30. package/dist/paymentService.d.ts +19 -0
  31. package/dist/{paymentAmountValidation.js → paymentService.js} +20 -6
  32. package/dist/paymentService.js.map +1 -0
  33. package/dist/replaceCustomValues.d.ts +98 -3
  34. package/dist/replaceCustomValues.js +98 -2
  35. package/dist/replaceCustomValues.js.map +1 -1
  36. package/dist/schedulingService.d.ts +19 -0
  37. package/dist/schedulingService.js +33 -0
  38. package/dist/schedulingService.js.map +1 -0
  39. package/dist/submissionService.d.ts +22 -0
  40. package/dist/submissionService.js +52 -0
  41. package/dist/submissionService.js.map +1 -0
  42. package/dist/typeCastService.d.ts +1 -1
  43. package/dist/typeCastService.js.map +1 -1
  44. package/dist/typedoc.d.ts +2 -0
  45. package/dist/typedoc.js +19 -0
  46. package/dist/typedoc.js.map +1 -0
  47. package/dist/types/index.d.ts +0 -14
  48. package/dist/types/index.js.map +1 -1
  49. package/dist/userService.d.ts +35 -0
  50. package/dist/userService.js +35 -0
  51. package/dist/userService.js.map +1 -1
  52. package/package.json +15 -12
  53. package/dist/conditionalLogicService/evaluationService.d.ts +0 -19
  54. package/dist/conditionalLogicService/evaluationService.js +0 -139
  55. package/dist/conditionalLogicService/evaluationService.js.map +0 -1
  56. package/dist/conditionalLogicService/index.d.ts +0 -2
  57. package/dist/conditionalLogicService/index.js +0 -13
  58. package/dist/conditionalLogicService/index.js.map +0 -1
  59. package/dist/paymentAmountValidation.d.ts +0 -7
  60. package/dist/paymentAmountValidation.js.map +0 -1
package/README.md CHANGED
@@ -2,12 +2,6 @@
2
2
 
3
3
  OneBlink SDK for JavaScript (works in Browsers and NodeJS).
4
4
 
5
- ## Installation
5
+ ## Documentation
6
6
 
7
- ```sh
8
- npm install @oneblink/sdk-core --save
9
- ```
10
-
11
- ## Usage
12
-
13
- - [Usage Documentation](./docs/README.md)
7
+ See the [Documentation](https://oneblink.github.io/sdk-core-js/) for more details.
@@ -1,5 +1,58 @@
1
1
  import { ABNRecord } from '@oneblink/types/typescript/misc';
2
+ /**
3
+ * Attempts to get the most relevant business name from the data returned in an
4
+ * `ABNRecord`. Will return `undefined` if a suitable name is not found.
5
+ *
6
+ * #### Example
7
+ *
8
+ * ```js
9
+ * const businessName = abnService.getBusinessNameFromABNRecord(abnRecord)
10
+ * ```
11
+ *
12
+ * @param abnRecord
13
+ * @returns
14
+ */
2
15
  export declare const getBusinessNameFromABNRecord: (abnRecord: ABNRecord) => string | undefined;
16
+ /**
17
+ * Get the most relevant business name from the data returned in an `ABNRecord`.
18
+ * Will return "Unknown Business Name" if a suitable name is not found.
19
+ *
20
+ * #### Example
21
+ *
22
+ * ```js
23
+ * const businessName =
24
+ * abnService.displayBusinessNameFromABNRecord(abnRecord)
25
+ * ```
26
+ *
27
+ * @param abnRecord
28
+ * @returns
29
+ */
3
30
  export declare const displayBusinessNameFromABNRecord: (abnRecord: ABNRecord) => string;
31
+ /**
32
+ * Attempts to get the most recent ABN number from the data returned in an
33
+ * `ABNRecord`. Will return `undefined` if an ABN is not found.
34
+ *
35
+ * #### Example
36
+ *
37
+ * ```js
38
+ * const ABN = abnService.getABNNumberFromABNRecord(abnRecord)
39
+ * ```
40
+ *
41
+ * @param abnRecord
42
+ * @returns
43
+ */
4
44
  export declare const getABNNumberFromABNRecord: (abnRecord: ABNRecord) => string | undefined;
45
+ /**
46
+ * Attempts to get the most recent ABN number from the data returned in an
47
+ * `ABNRecord`. Will return "Unknown ABN Number" if an ABN is not found.
48
+ *
49
+ * #### Example
50
+ *
51
+ * ```js
52
+ * const ABN = abnService.displayABNNumberFromABNRecord(abnRecord)
53
+ * ```
54
+ *
55
+ * @param abnRecord
56
+ * @returns
57
+ */
5
58
  export declare const displayABNNumberFromABNRecord: (abnRecord: ABNRecord) => string;
@@ -14,6 +14,19 @@ const createLegalName = ({ familyName, givenName, otherGivenName, }) => {
14
14
  legalName += `${otherGivenName}`;
15
15
  return legalName;
16
16
  };
17
+ /**
18
+ * Attempts to get the most relevant business name from the data returned in an
19
+ * `ABNRecord`. Will return `undefined` if a suitable name is not found.
20
+ *
21
+ * #### Example
22
+ *
23
+ * ```js
24
+ * const businessName = abnService.getBusinessNameFromABNRecord(abnRecord)
25
+ * ```
26
+ *
27
+ * @param abnRecord
28
+ * @returns
29
+ */
17
30
  const getBusinessNameFromABNRecord = (abnRecord) => {
18
31
  var _a, _b;
19
32
  if (abnRecord.entityType.entityTypeCode === 'IND' && abnRecord.legalName) {
@@ -34,11 +47,38 @@ const getBusinessNameFromABNRecord = (abnRecord) => {
34
47
  }
35
48
  };
36
49
  exports.getBusinessNameFromABNRecord = getBusinessNameFromABNRecord;
50
+ /**
51
+ * Get the most relevant business name from the data returned in an `ABNRecord`.
52
+ * Will return "Unknown Business Name" if a suitable name is not found.
53
+ *
54
+ * #### Example
55
+ *
56
+ * ```js
57
+ * const businessName =
58
+ * abnService.displayBusinessNameFromABNRecord(abnRecord)
59
+ * ```
60
+ *
61
+ * @param abnRecord
62
+ * @returns
63
+ */
37
64
  const displayBusinessNameFromABNRecord = (abnRecord) => {
38
65
  const businessName = (0, exports.getBusinessNameFromABNRecord)(abnRecord);
39
66
  return businessName || 'Unknown Business Name';
40
67
  };
41
68
  exports.displayBusinessNameFromABNRecord = displayBusinessNameFromABNRecord;
69
+ /**
70
+ * Attempts to get the most recent ABN number from the data returned in an
71
+ * `ABNRecord`. Will return `undefined` if an ABN is not found.
72
+ *
73
+ * #### Example
74
+ *
75
+ * ```js
76
+ * const ABN = abnService.getABNNumberFromABNRecord(abnRecord)
77
+ * ```
78
+ *
79
+ * @param abnRecord
80
+ * @returns
81
+ */
42
82
  const getABNNumberFromABNRecord = (abnRecord) => {
43
83
  if (!abnRecord.ABN)
44
84
  return;
@@ -49,6 +89,19 @@ const getABNNumberFromABNRecord = (abnRecord) => {
49
89
  return abnRecord.ABN.identifierValue;
50
90
  };
51
91
  exports.getABNNumberFromABNRecord = getABNNumberFromABNRecord;
92
+ /**
93
+ * Attempts to get the most recent ABN number from the data returned in an
94
+ * `ABNRecord`. Will return "Unknown ABN Number" if an ABN is not found.
95
+ *
96
+ * #### Example
97
+ *
98
+ * ```js
99
+ * const ABN = abnService.displayABNNumberFromABNRecord(abnRecord)
100
+ * ```
101
+ *
102
+ * @param abnRecord
103
+ * @returns
104
+ */
52
105
  const displayABNNumberFromABNRecord = (abnRecord) => {
53
106
  const abnNumber = (0, exports.getABNNumberFromABNRecord)(abnRecord);
54
107
  return abnNumber || 'Unknown ABN Number';
@@ -1 +1 @@
1
- {"version":3,"file":"abnService.js","sourceRoot":"","sources":["../src/abnService.ts"],"names":[],"mappings":";;;AAEA,MAAM,eAAe,GAAG,CAAC,EACvB,UAAU,EACV,SAAS,EACT,cAAc,GACsB,EAAE,EAAE;IACxC,IAAI,SAAS,GAAG,EAAE,CAAA;IAClB,mBAAmB;IACnB,IAAI,UAAU;QAAE,SAAS,IAAI,GAAG,UAAU,IAAI,CAAA;IAC9C,oBAAoB;IACpB,IAAI,SAAS;QAAE,SAAS,IAAI,GAAG,SAAS,GAAG,CAAA;IAC3C,qBAAqB;IACrB,IAAI,cAAc;QAAE,SAAS,IAAI,GAAG,cAAc,EAAE,CAAA;IAEpD,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AAEM,MAAM,4BAA4B,GAAG,CAC1C,SAAoB,EACA,EAAE;;IACtB,IAAI,SAAS,CAAC,UAAU,CAAC,cAAc,KAAK,KAAK,IAAI,SAAS,CAAC,SAAS,EAAE;QACxE,MAAM,SAAS,GAAG,eAAe,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;QACtD,IAAI,SAAS;YAAE,OAAO,SAAS,CAAC,IAAI,EAAE,CAAA;KACvC;IAED,IAAI,MAAA,SAAS,CAAC,QAAQ,0CAAE,gBAAgB,EAAE;QACxC,OAAO,SAAS,CAAC,QAAQ,CAAC,gBAAgB,CAAA;KAC3C;IACD,IAAI,MAAA,SAAS,CAAC,eAAe,0CAAE,gBAAgB,EAAE;QAC/C,OAAO,SAAS,CAAC,eAAe,CAAC,gBAAgB,CAAA;KAClD;IACD,IAAI,SAAS,CAAC,SAAS,EAAE;QACvB,MAAM,SAAS,GAAG,eAAe,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;QACtD,IAAI,SAAS;YAAE,OAAO,SAAS,CAAC,IAAI,EAAE,CAAA;KACvC;AACH,CAAC,CAAA;AAlBY,QAAA,4BAA4B,gCAkBxC;AAEM,MAAM,gCAAgC,GAAG,CAC9C,SAAoB,EACZ,EAAE;IACV,MAAM,YAAY,GAAG,IAAA,oCAA4B,EAAC,SAAS,CAAC,CAAA;IAC5D,OAAO,YAAY,IAAI,uBAAuB,CAAA;AAChD,CAAC,CAAA;AALY,QAAA,gCAAgC,oCAK5C;AAEM,MAAM,yBAAyB,GAAG,CACvC,SAAoB,EACA,EAAE;IACtB,IAAI,CAAC,SAAS,CAAC,GAAG;QAAE,OAAM;IAC1B,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE;QAChC,MAAM,WAAW,GAAG,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAA;QACvE,OAAO,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,eAAe,CAAA;KACpC;IACD,OAAO,SAAS,CAAC,GAAG,CAAC,eAAe,CAAA;AACtC,CAAC,CAAA;AATY,QAAA,yBAAyB,6BASrC;AACM,MAAM,6BAA6B,GAAG,CAAC,SAAoB,EAAU,EAAE;IAC5E,MAAM,SAAS,GAAG,IAAA,iCAAyB,EAAC,SAAS,CAAC,CAAA;IACtD,OAAO,SAAS,IAAI,oBAAoB,CAAA;AAC1C,CAAC,CAAA;AAHY,QAAA,6BAA6B,iCAGzC","sourcesContent":["import { ABNRecord } from '@oneblink/types/typescript/misc'\n\nconst createLegalName = ({\n familyName,\n givenName,\n otherGivenName,\n}: NonNullable<ABNRecord['legalName']>) => {\n let legalName = ''\n // Concat last name\n if (familyName) legalName += `${familyName}, `\n // Concat first name\n if (givenName) legalName += `${givenName} `\n // Concat middle name\n if (otherGivenName) legalName += `${otherGivenName}`\n\n return legalName\n}\n\nexport const getBusinessNameFromABNRecord = (\n abnRecord: ABNRecord,\n): string | undefined => {\n if (abnRecord.entityType.entityTypeCode === 'IND' && abnRecord.legalName) {\n const legalName = createLegalName(abnRecord.legalName)\n if (legalName) return legalName.trim()\n }\n\n if (abnRecord.mainName?.organisationName) {\n return abnRecord.mainName.organisationName\n }\n if (abnRecord.mainTradingName?.organisationName) {\n return abnRecord.mainTradingName.organisationName\n }\n if (abnRecord.legalName) {\n const legalName = createLegalName(abnRecord.legalName)\n if (legalName) return legalName.trim()\n }\n}\n\nexport const displayBusinessNameFromABNRecord = (\n abnRecord: ABNRecord,\n): string => {\n const businessName = getBusinessNameFromABNRecord(abnRecord)\n return businessName || 'Unknown Business Name'\n}\n\nexport const getABNNumberFromABNRecord = (\n abnRecord: ABNRecord,\n): string | undefined => {\n if (!abnRecord.ABN) return\n if (Array.isArray(abnRecord.ABN)) {\n const relevantABN = abnRecord.ABN.find((abn) => abn.isCurrentIndicator)\n return relevantABN?.identifierValue\n }\n return abnRecord.ABN.identifierValue\n}\nexport const displayABNNumberFromABNRecord = (abnRecord: ABNRecord): string => {\n const abnNumber = getABNNumberFromABNRecord(abnRecord)\n return abnNumber || 'Unknown ABN Number'\n}\n"]}
1
+ {"version":3,"file":"abnService.js","sourceRoot":"","sources":["../src/abnService.ts"],"names":[],"mappings":";;;AAEA,MAAM,eAAe,GAAG,CAAC,EACvB,UAAU,EACV,SAAS,EACT,cAAc,GACsB,EAAE,EAAE;IACxC,IAAI,SAAS,GAAG,EAAE,CAAA;IAClB,mBAAmB;IACnB,IAAI,UAAU;QAAE,SAAS,IAAI,GAAG,UAAU,IAAI,CAAA;IAC9C,oBAAoB;IACpB,IAAI,SAAS;QAAE,SAAS,IAAI,GAAG,SAAS,GAAG,CAAA;IAC3C,qBAAqB;IACrB,IAAI,cAAc;QAAE,SAAS,IAAI,GAAG,cAAc,EAAE,CAAA;IAEpD,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AAED;;;;;;;;;;;;G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C,kBAAkB,CAAC,CAAA;QACvE,OAAO,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,eAAe,CAAA;KACpC;IACD,OAAO,SAAS,CAAC,GAAG,CAAC,eAAe,CAAA;AACtC,CAAC,CAAA;AATY,QAAA,yBAAyB,6BASrC;AAED;;;;;;;;;;;;GAYG;AACI,MAAM,6BAA6B,GAAG,CAAC,SAAoB,EAAU,EAAE;IAC5E,MAAM,SAAS,GAAG,IAAA,iCAAyB,EAAC,SAAS,CAAC,CAAA;IACtD,OAAO,SAAS,IAAI,oBAAoB,CAAA;AAC1C,CAAC,CAAA;AAHY,QAAA,6BAA6B,iCAGzC","sourcesContent":["import { ABNRecord } from '@oneblink/types/typescript/misc'\n\nconst createLegalName = ({\n familyName,\n givenName,\n otherGivenName,\n}: NonNullable<ABNRecord['legalName']>) => {\n let legalName = ''\n // Concat last name\n if (familyName) legalName += `${familyName}, `\n // Concat first name\n if (givenName) legalName += `${givenName} `\n // Concat middle name\n if (otherGivenName) legalName += `${otherGivenName}`\n\n return legalName\n}\n\n/**\n * Attempts to get the most relevant business name from the data returned in an\n * `ABNRecord`. Will return `undefined` if a suitable name is not found.\n *\n * #### Example\n *\n * ```js\n * const businessName = abnService.getBusinessNameFromABNRecord(abnRecord)\n * ```\n *\n * @param abnRecord\n * @returns\n */\nexport const getBusinessNameFromABNRecord = (\n abnRecord: ABNRecord,\n): string | undefined => {\n if (abnRecord.entityType.entityTypeCode === 'IND' && abnRecord.legalName) {\n const legalName = createLegalName(abnRecord.legalName)\n if (legalName) return legalName.trim()\n }\n\n if (abnRecord.mainName?.organisationName) {\n return abnRecord.mainName.organisationName\n }\n if (abnRecord.mainTradingName?.organisationName) {\n return abnRecord.mainTradingName.organisationName\n }\n if (abnRecord.legalName) {\n const legalName = createLegalName(abnRecord.legalName)\n if (legalName) return legalName.trim()\n }\n}\n\n/**\n * Get the most relevant business name from the data returned in an `ABNRecord`.\n * Will return \"Unknown Business Name\" if a suitable name is not found.\n *\n * #### Example\n *\n * ```js\n * const businessName =\n * abnService.displayBusinessNameFromABNRecord(abnRecord)\n * ```\n *\n * @param abnRecord\n * @returns\n */\nexport const displayBusinessNameFromABNRecord = (\n abnRecord: ABNRecord,\n): string => {\n const businessName = getBusinessNameFromABNRecord(abnRecord)\n return businessName || 'Unknown Business Name'\n}\n\n/**\n * Attempts to get the most recent ABN number from the data returned in an\n * `ABNRecord`. Will return `undefined` if an ABN is not found.\n *\n * #### Example\n *\n * ```js\n * const ABN = abnService.getABNNumberFromABNRecord(abnRecord)\n * ```\n *\n * @param abnRecord\n * @returns\n */\nexport const getABNNumberFromABNRecord = (\n abnRecord: ABNRecord,\n): string | undefined => {\n if (!abnRecord.ABN) return\n if (Array.isArray(abnRecord.ABN)) {\n const relevantABN = abnRecord.ABN.find((abn) => abn.isCurrentIndicator)\n return relevantABN?.identifierValue\n }\n return abnRecord.ABN.identifierValue\n}\n\n/**\n * Attempts to get the most recent ABN number from the data returned in an\n * `ABNRecord`. Will return \"Unknown ABN Number\" if an ABN is not found.\n *\n * #### Example\n *\n * ```js\n * const ABN = abnService.displayABNNumberFromABNRecord(abnRecord)\n * ```\n *\n * @param abnRecord\n * @returns\n */\nexport const displayABNNumberFromABNRecord = (abnRecord: ABNRecord): string => {\n const abnNumber = getABNNumberFromABNRecord(abnRecord)\n return abnNumber || 'Unknown ABN Number'\n}\n"]}
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const evaluationService_1 = require("./evaluationService");
6
+ const evaluateConditionalPredicate_1 = __importDefault(require("./evaluateConditionalPredicate"));
4
7
  const getParentFormElements = (formElementsCtrl, childElement) => {
5
8
  const parentElement = formElementsCtrl.flattenedElements.find((element) => {
6
9
  return ((element.type === 'page' || element.type === 'section') &&
@@ -16,20 +19,12 @@ const getParentFormElements = (formElementsCtrl, childElement) => {
16
19
  return [];
17
20
  };
18
21
  const conditionallyShowByPredicate = (formElementsCtrl, predicate, elementsEvaluated) => {
19
- const predicateElement = formElementsCtrl.flattenedElements.find((element) => {
20
- return element.id === predicate.elementId;
22
+ const predicateElement = (0, evaluateConditionalPredicate_1.default)({
23
+ predicate,
24
+ formElementsCtrl,
21
25
  });
22
- // If we cant find the element used for the predicate,
23
- // we can check to see if the element being evaluated
24
- // is in a repeatable set and the predicate element is
25
- // in a parent list of elements.
26
26
  if (!predicateElement) {
27
- if (formElementsCtrl.parentFormElementsCtrl) {
28
- return conditionallyShowByPredicate(formElementsCtrl.parentFormElementsCtrl, predicate, elementsEvaluated);
29
- }
30
- else {
31
- return false;
32
- }
27
+ return false;
33
28
  }
34
29
  // Here we will also need to check if the predicate element
35
30
  // is on a page/section element and the page/section element
@@ -44,12 +39,7 @@ const conditionallyShowByPredicate = (formElementsCtrl, predicate, elementsEvalu
44
39
  }
45
40
  }
46
41
  // Check to see if the model has one of the valid values to show the element
47
- return (conditionallyShowElement(formElementsCtrl, predicateElement, elementsEvaluated) &&
48
- (0, evaluationService_1.evaluateConditionalPredicate)({
49
- predicate,
50
- submission: formElementsCtrl.model,
51
- predicateElement,
52
- }));
42
+ return conditionallyShowElement(formElementsCtrl, predicateElement, elementsEvaluated);
53
43
  };
54
44
  function conditionallyShowElement(formElementsCtrl, elementToEvaluate, elementsEvaluated) {
55
45
  // If the element does not have the `conditionallyShow` flag set,
@@ -1 +1 @@
1
- {"version":3,"file":"conditionallyShowElement.js","sourceRoot":"","sources":["../../src/conditionalLogicService/conditionallyShowElement.ts"],"names":[],"mappings":";;AACA,2DAAkE;AAGlE,MAAM,qBAAqB,GAAG,CAC5B,gBAAkC,EAClC,YAAmC,EACsB,EAAE;IAC3D,MAAM,aAAa,GAAG,gBAAgB,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;QACxE,OAAO,CACL,CAAC,OAAO,CAAC,IAAI,KAAK,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;QACpE,iEAAiE;QACjE,yBAAyB;QACzB,OAAO,4BAA4B,CAAC,gBAAgB,EAAE,SAAS,EAAE;YAC/D,GAAG,iBAAiB;SACrB,CAAC,CAAA;IACJ,CAAC,CAAA;IAED,IAAI,iBAAiB,CAAC,sCAAsC,EAAE;QAC5D,OAAO,2BAA2B,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAA;KAC5D;SAAM;QACL,OAAO,2BAA2B,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;KAC3D;AACH,CAAC;AAtDD,2CAsDC","sourcesContent":["import { FormTypes, ConditionTypes } from '@oneblink/types'\nimport { evaluateConditionalPredicate } from './evaluationService'\nimport { FormElementsCtrl } from '../types'\n\nconst getParentFormElements = (\n formElementsCtrl: FormElementsCtrl,\n childElement: FormTypes.FormElement,\n): Array<FormTypes.SectionElement | FormTypes.PageElement> => {\n const parentElement = formElementsCtrl.flattenedElements.find((element) => {\n return (\n (element.type === 'page' || element.type === 'section') &&\n element.elements.some(({ id }) => id === childElement.id)\n )\n })\n if (\n parentElement &&\n (parentElement.type === 'page' || parentElement.type === 'section')\n ) {\n return [\n parentElement,\n ...getParentFormElements(formElementsCtrl, parentElement),\n ]\n }\n return []\n}\n\nconst conditionallyShowByPredicate = (\n formElementsCtrl: FormElementsCtrl,\n predicate: ConditionTypes.ConditionalPredicate,\n elementsEvaluated: Array<{ id: string; label: string }>,\n): FormTypes.FormElement | boolean => {\n const predicateElement = formElementsCtrl.flattenedElements.find(\n (element: FormTypes.FormElement) => {\n return element.id === predicate.elementId\n },\n )\n\n // If we cant find the element used for the predicate,\n // we can check to see if the element being evaluated\n // is in a repeatable set and the predicate element is\n // in a parent list of elements.\n if (!predicateElement) {\n if (formElementsCtrl.parentFormElementsCtrl) {\n return conditionallyShowByPredicate(\n formElementsCtrl.parentFormElementsCtrl,\n predicate,\n elementsEvaluated,\n )\n } else {\n return false\n }\n }\n\n // Here we will also need to check if the predicate element\n // is on a page/section element and the page/section element\n // is also hidden. If it is hidden we will treat this\n // predicate element as hidden as well.\n const parentFormElements = getParentFormElements(\n formElementsCtrl,\n predicateElement,\n )\n for (const parentFormElement of parentFormElements) {\n if (\n !conditionallyShowElement(formElementsCtrl, parentFormElement, [\n ...elementsEvaluated,\n ])\n ) {\n return false\n }\n }\n\n // Check to see if the model has one of the valid values to show the element\n return (\n conditionallyShowElement(\n formElementsCtrl,\n predicateElement,\n elementsEvaluated,\n ) &&\n evaluateConditionalPredicate({\n predicate,\n submission: formElementsCtrl.model,\n predicateElement,\n })\n )\n}\n\nexport default function conditionallyShowElement(\n formElementsCtrl: FormElementsCtrl,\n elementToEvaluate: FormTypes.FormElement,\n elementsEvaluated: Array<{ id: string; label: string }>,\n): boolean {\n // If the element does not have the `conditionallyShow` flag set,\n // we can always show the element.\n if (\n !elementToEvaluate ||\n !elementToEvaluate.conditionallyShow ||\n !Array.isArray(elementToEvaluate.conditionallyShowPredicates) ||\n !elementToEvaluate.conditionallyShowPredicates.length\n ) {\n return true\n }\n const conditionallyShowPredicates =\n elementToEvaluate.conditionallyShowPredicates\n\n // Check to see if this element has already been used to evaluate\n // if the element should be shown based on parent element conditional logic\n const elementAlreadyEvaluated = elementsEvaluated.find(\n ({ id }) => id === elementToEvaluate.id,\n )\n if (elementAlreadyEvaluated) {\n throw new Error(\n `Your conditional logic has caused an infinite loop. Check the \"${elementAlreadyEvaluated.label}\" form element to ensure element A does not rely on element B if element B also relies on element A.`,\n )\n } else {\n elementsEvaluated.push({\n id: elementToEvaluate.id,\n label:\n elementToEvaluate.type === 'form' ||\n elementToEvaluate.type === 'infoPage'\n ? elementToEvaluate.name\n : elementToEvaluate.label,\n })\n }\n\n const predicateFunction = (\n predicate: ConditionTypes.ConditionalPredicate,\n ) => {\n // Spread the array of elements evaluated so that each predicate can\n // evaluate the tree without causing false positives for infinite\n // loop conditional logic\n return conditionallyShowByPredicate(formElementsCtrl, predicate, [\n ...elementsEvaluated,\n ])\n }\n\n if (elementToEvaluate.requiresAllConditionallyShowPredicates) {\n return conditionallyShowPredicates.every(predicateFunction)\n } else {\n return conditionallyShowPredicates.some(predicateFunction)\n }\n}\n"]}
1
+ {"version":3,"file":"conditionallyShowElement.js","sourceRoot":"","sources":["../../src/conditionalLogicService/conditionallyShowElement.ts"],"names":[],"mappings":";;;;;AAEA,kGAAyE;AAEzE,MAAM,qBAAqB,GAAG,CAC5B,gBAAkC,EAClC,YAAmC,EACsB,EAAE;IAC3D,MAAM,aAAa,GAAG,gBAAgB,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;QACxE,OAAO,CACL,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC;YACvD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,YAAY,CAAC,EAAE,CAAC,CAC1D,CAAA;IACH,CAAC,CAAC,CAAA;IACF,IACE,aAAa;QACb,CAAC,aAAa,CAAC,IAAI,KAAK,MAAM,IAAI,aAAa,CAAC,IAAI,KAAK,SAAS,CAAC,EACnE;QACA,OAAO;YACL,aAAa;YACb,GAAG,qBAAqB,CAAC,gBAAgB,EAAE,aAAa,CAAC;SAC1D,CAAA;KACF;IACD,OAAO,EAAE,CAAA;AACX,CAAC,CAAA;AAED,MAAM,4BAA4B,GAAG,CACnC,gBAAkC,EAClC,SAA8C,EAC9C,iBAAuD,EACtB,EAAE;IACnC,MAAM,gBAAgB,GAAG,IAAA,sCAA4B,EAAC;QACpD,SAAS;QACT,gBAAgB;KACjB,CAAC,CAAA;IAEF,IAAI,CAAC,gBAAgB,EAAE;QACrB,OAAO,KAAK,CAAA;KACb;IAED,2DAA2D;IAC3D,4DAA4D;IAC5D,qDAAqD;IACrD,uCAAuC;IACvC,MAAM,kBAAkB,GAAG,qBAAqB,CAC9C,gBAAgB,EAChB,gBAAgB,CACjB,CAAA;IACD,KAAK,MAA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F,oEAAoE;QACpE,iEAAiE;QACjE,yBAAyB;QACzB,OAAO,4BAA4B,CAAC,gBAAgB,EAAE,SAAS,EAAE;YAC/D,GAAG,iBAAiB;SACrB,CAAC,CAAA;IACJ,CAAC,CAAA;IAED,IAAI,iBAAiB,CAAC,sCAAsC,EAAE;QAC5D,OAAO,2BAA2B,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAA;KAC5D;SAAM;QACL,OAAO,2BAA2B,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;KAC3D;AACH,CAAC;AAtDD,2CAsDC","sourcesContent":["import { FormTypes, ConditionTypes } from '@oneblink/types'\nimport { FormElementsCtrl } from '../types'\nimport evaluateConditionalPredicate from './evaluateConditionalPredicate'\n\nconst getParentFormElements = (\n formElementsCtrl: FormElementsCtrl,\n childElement: FormTypes.FormElement,\n): Array<FormTypes.SectionElement | FormTypes.PageElement> => {\n const parentElement = formElementsCtrl.flattenedElements.find((element) => {\n return (\n (element.type === 'page' || element.type === 'section') &&\n element.elements.some(({ id }) => id === childElement.id)\n )\n })\n if (\n parentElement &&\n (parentElement.type === 'page' || parentElement.type === 'section')\n ) {\n return [\n parentElement,\n ...getParentFormElements(formElementsCtrl, parentElement),\n ]\n }\n return []\n}\n\nconst conditionallyShowByPredicate = (\n formElementsCtrl: FormElementsCtrl,\n predicate: ConditionTypes.ConditionalPredicate,\n elementsEvaluated: Array<{ id: string; label: string }>,\n): FormTypes.FormElement | boolean => {\n const predicateElement = evaluateConditionalPredicate({\n predicate,\n formElementsCtrl,\n })\n\n if (!predicateElement) {\n return false\n }\n\n // Here we will also need to check if the predicate element\n // is on a page/section element and the page/section element\n // is also hidden. If it is hidden we will treat this\n // predicate element as hidden as well.\n const parentFormElements = getParentFormElements(\n formElementsCtrl,\n predicateElement,\n )\n for (const parentFormElement of parentFormElements) {\n if (\n !conditionallyShowElement(formElementsCtrl, parentFormElement, [\n ...elementsEvaluated,\n ])\n ) {\n return false\n }\n }\n\n // Check to see if the model has one of the valid values to show the element\n return conditionallyShowElement(\n formElementsCtrl,\n predicateElement,\n elementsEvaluated,\n )\n}\n\nexport default function conditionallyShowElement(\n formElementsCtrl: FormElementsCtrl,\n elementToEvaluate: FormTypes.FormElement,\n elementsEvaluated: Array<{ id: string; label: string }>,\n): boolean {\n // If the element does not have the `conditionallyShow` flag set,\n // we can always show the element.\n if (\n !elementToEvaluate ||\n !elementToEvaluate.conditionallyShow ||\n !Array.isArray(elementToEvaluate.conditionallyShowPredicates) ||\n !elementToEvaluate.conditionallyShowPredicates.length\n ) {\n return true\n }\n const conditionallyShowPredicates =\n elementToEvaluate.conditionallyShowPredicates\n\n // Check to see if this element has already been used to evaluate\n // if the element should be shown based on parent element conditional logic\n const elementAlreadyEvaluated = elementsEvaluated.find(\n ({ id }) => id === elementToEvaluate.id,\n )\n if (elementAlreadyEvaluated) {\n throw new Error(\n `Your conditional logic has caused an infinite loop. Check the \"${elementAlreadyEvaluated.label}\" form element to ensure element A does not rely on element B if element B also relies on element A.`,\n )\n } else {\n elementsEvaluated.push({\n id: elementToEvaluate.id,\n label:\n elementToEvaluate.type === 'form' ||\n elementToEvaluate.type === 'infoPage'\n ? elementToEvaluate.name\n : elementToEvaluate.label,\n })\n }\n\n const predicateFunction = (\n predicate: ConditionTypes.ConditionalPredicate,\n ) => {\n // Spread the array of elements evaluated so that each predicate can\n // evaluate the tree without causing false positives for infinite\n // loop conditional logic\n return conditionallyShowByPredicate(formElementsCtrl, predicate, [\n ...elementsEvaluated,\n ])\n }\n\n if (elementToEvaluate.requiresAllConditionallyShowPredicates) {\n return conditionallyShowPredicates.every(predicateFunction)\n } else {\n return conditionallyShowPredicates.some(predicateFunction)\n }\n}\n"]}
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const evaluationService_1 = require("./evaluationService");
6
+ const evaluateConditionalOptionsPredicate_1 = __importDefault(require("./evaluateConditionalOptionsPredicate"));
7
7
  const conditionallyShowElement_1 = __importDefault(require("./conditionallyShowElement"));
8
8
  const handleAttributePredicate = (predicate, model, predicateElement) => {
9
9
  const values = model[predicateElement.name];
@@ -14,13 +14,13 @@ const handleAttributePredicate = (predicate, model, predicateElement) => {
14
14
  !values.filter((value) => typeof value !== 'undefined').length)) {
15
15
  return true;
16
16
  }
17
- return (0, evaluationService_1.evaluateConditionalOptionsPredicate)({
17
+ return (0, evaluateConditionalOptionsPredicate_1.default)({
18
18
  predicate: {
19
19
  type: 'OPTIONS',
20
20
  elementId: predicate.elementId,
21
21
  optionIds: predicate.optionIds,
22
22
  },
23
- submission: model,
23
+ predicateValue: values,
24
24
  predicateElement,
25
25
  });
26
26
  };
@@ -1 +1 @@
1
- {"version":3,"file":"conditionallyShowOption.js","sourceRoot":"","sources":["../../src/conditionalLogicService/conditionallyShowOption.ts"],"names":[],"mappings":";;;;;AACA,2DAAyE;AAGzE,0FAAiE;AAEjE,MAAM,wBAAwB,GAAG,CAC/B,SAAiD,EACjD,KAA8B,EAC9B,gBAAkD,EAClD,EAAE;IACF,MAAM,MAAM,GAAG,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAA;IAC3C,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IAExB,IACE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QACrB,CAAC,CAAC,MAAM,CAAC,MAAM;YACb,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,WAAW,CAAC,CAAC,MAAM,CAAC,EACjE;QACA,OAAO,IAAI,CAAA;KACZ;IAED,OAAO,IAAA,uDAAmC,EAAC;QACzC,SAAS,EAAE;YACT,IAAI,EAAE,SAAS;YACf,SAAS,EAAE,SAAS,CAAC,SAAS;YAC9B,SAAS,EAAE,SAAS,CAAC,SAAS;SAC/B;QACD,UAAU,EAAE,KAAK;Q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C,SAAS,EAAE,EAAE;QACZ,OAAO,sBAAsB,CAC3B,gBAAgB,EAChB,SAAS,EACT,gBAAgB,CACjB,CAAA;IACH,CAAC,CACF,CAAA;IAED,IAAI,CAAC,eAAe,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IACxC,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CACxC,kCAAkC,CAChC,gBAAgB,EAChB,SAAS,EACT,gBAAgB,CACjB,CACF,CAAA;AACH,CAAC;AA/CD,0CA+CC","sourcesContent":["import { FormTypes } from '@oneblink/types'\nimport { evaluateConditionalOptionsPredicate } from './evaluationService'\nimport { FormElementsCtrl } from '../types'\n\nimport conditionallyShowElement from './conditionallyShowElement'\n\nconst handleAttributePredicate = (\n predicate: FormTypes.ChoiceElementOptionAttribute,\n model: Record<string, unknown>,\n predicateElement: FormTypes.FormElementWithOptions,\n) => {\n const values = model[predicateElement.name]\n if (!values) return true\n\n if (\n Array.isArray(values) &&\n (!values.length ||\n !values.filter((value) => typeof value !== 'undefined').length)\n ) {\n return true\n }\n\n return evaluateConditionalOptionsPredicate({\n predicate: {\n type: 'OPTIONS',\n elementId: predicate.elementId,\n optionIds: predicate.optionIds,\n },\n submission: model,\n predicateElement,\n })\n}\n\nconst conditionallyShowOptionByPredicate = (\n formElementsCtrl: FormElementsCtrl,\n predicate: FormTypes.ChoiceElementOptionAttribute,\n elementsEvaluated: string[],\n): boolean => {\n // Validate the predicate data, if it is invalid,\n // we will always show the field\n if (\n !predicate ||\n !predicate.elementId ||\n !predicate.optionIds ||\n !predicate.optionIds.length\n ) {\n return true\n }\n\n const predicateElement = formElementsCtrl.flattenedElements.find(\n (element) => {\n return element.id === predicate.elementId\n },\n )\n\n // If we cant find the element used for the predicate,\n // we can check to see if the element being evaluated\n // is in a repeatable set and the predicate element is\n // in a parent list of elements.\n if (!predicateElement) {\n if (formElementsCtrl.parentFormElementsCtrl) {\n return conditionallyShowOptionByPredicate(\n formElementsCtrl.parentFormElementsCtrl,\n predicate,\n elementsEvaluated,\n )\n } else {\n return false\n }\n }\n\n if (\n predicateElement.type !== 'compliance' &&\n predicateElement.type !== 'select' &&\n predicateElement.type !== 'autocomplete' &&\n predicateElement.type !== 'checkboxes' &&\n predicateElement.type !== 'radio'\n ) {\n return false\n }\n\n // If the predicate element does not have any options to evaluate,\n // we will show the element.\n // Unless the predicate element has dynamic options and\n // options have not been fetched yet.\n if (!Array.isArray(predicateElement.options)) {\n return predicateElement.optionsType !== 'DYNAMIC'\n }\n\n const everyOptionIsShowing = predicate.optionIds.every((id) => {\n const predicateOption = predicateElement.options?.find((o) => o.id === id)\n if (!predicateOption) return false\n\n return conditionallyShowOption(\n { model: formElementsCtrl.model, flattenedElements: [] },\n predicateElement,\n predicateOption,\n elementsEvaluated,\n )\n })\n\n if (!everyOptionIsShowing) {\n return false\n }\n\n // Check to see if the model has one of the valid values to show the element\n return handleAttributePredicate(\n predicate,\n formElementsCtrl.model,\n predicateElement,\n )\n}\n\nconst isAttributeFilterValid = (\n formElementsCtrl: FormElementsCtrl,\n predicate: FormTypes.ChoiceElementOptionAttribute,\n elementsEvaluated: string[],\n): boolean => {\n const predicateElement = formElementsCtrl.flattenedElements.find(\n (element) => {\n return element.id === predicate.elementId\n },\n )\n\n // If we cant find the element used for the predicate,\n // we can check to see if the element being evaluated\n // is in a repeatable set and the predicate element is\n // in a parent list of elements.\n if (!predicateElement) {\n if (formElementsCtrl.parentFormElementsCtrl) {\n return isAttributeFilterValid(\n formElementsCtrl.parentFormElementsCtrl,\n predicate,\n elementsEvaluated,\n )\n } else {\n return false\n }\n }\n\n // now we have the model and predicate element, verify that the predicate element\n // is not hidden\n if (\n // Will never be a page, just making typescript happy :)\n predicateElement.type === 'page' ||\n predicateElement.type === 'section' ||\n !conditionallyShowElement(formElementsCtrl, predicateElement, [])\n ) {\n return false\n }\n\n // verify that at least one option is selected\n const values = formElementsCtrl.model[predicateElement.name]\n if (!values) return false\n // if the model value is an array, verify that it has a selection\n if (\n Array.isArray(values) &&\n (!values.length ||\n !values.filter((value) => typeof value !== 'undefined').length)\n ) {\n return false\n }\n\n return true\n}\n\nexport default function conditionallyShowOption(\n formElementsCtrl: FormElementsCtrl,\n elementToEvaluate: FormTypes.FormElementWithOptions,\n optionToEvaluate: FormTypes.ChoiceElementOption,\n optionsEvaluated: string[],\n): boolean {\n // If the element does not have the `conditionallyShow` flag set,\n // we can always show the element.\n\n if (\n !elementToEvaluate.conditionallyShowOptions ||\n !optionToEvaluate ||\n !optionToEvaluate.attributes ||\n !Array.isArray(optionToEvaluate.attributes) ||\n !optionToEvaluate.attributes.length\n ) {\n return true\n }\n\n // Check to see if this element has already been used to evaluate\n // if the element should be shown based on parent element conditional logic\n if (optionsEvaluated.some((optionId) => optionId === optionToEvaluate.id)) {\n throw new Error(\n 'Your conditional logic has caused an infinite loop. Check the following Fields to ensure element A does not rely on element B if element B also relies on element A.',\n )\n } else {\n optionsEvaluated.push(optionToEvaluate.id)\n }\n\n const validPredicates = (optionToEvaluate.attributes || []).filter(\n (predicate) => {\n return isAttributeFilterValid(\n formElementsCtrl,\n predicate,\n optionsEvaluated,\n )\n },\n )\n\n if (!validPredicates.length) return true\n return validPredicates.some((predicate) =>\n conditionallyShowOptionByPredicate(\n formElementsCtrl,\n predicate,\n optionsEvaluated,\n ),\n )\n}\n"]}
1
+ {"version":3,"file":"conditionallyShowOption.js","sourceRoot":"","sources":["../../src/conditionalLogicService/conditionallyShowOption.ts"],"names":[],"mappings":";;;;;AACA,gHAAuF;AAGvF,0FAAiE;AAEjE,MAAM,wBAAwB,GAAG,CAC/B,SAAiD,EACjD,KAA8B,EAC9B,gBAAkD,EAClD,EAAE;IACF,MAAM,MAAM,GAAG,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAA;IAC3C,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IAExB,IACE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QACrB,CAAC,CAAC,MAAM,C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C3E,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,KAAK,gBAAgB,CAAC,EAAE,CAAC,EAAE;QACzE,MAAM,IAAI,KAAK,CACb,sKAAsK,CACvK,CAAA;KACF;SAAM;QACL,gBAAgB,CAAC,IAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAA;KAC3C;IAED,MAAM,eAAe,GAAG,CAAC,gBAAgB,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,MAAM,CAChE,CAAC,SAAS,EAAE,EAAE;QACZ,OAAO,sBAAsB,CAC3B,gBAAgB,EAChB,SAAS,EACT,gBAAgB,CACjB,CAAA;IACH,CAAC,CACF,CAAA;IAED,IAAI,CAAC,eAAe,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IACxC,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CACxC,kCAAkC,CAChC,gBAAgB,EAChB,SAAS,EACT,gBAAgB,CACjB,CACF,CAAA;AACH,CAAC;AA/CD,0CA+CC","sourcesContent":["import { FormTypes } from '@oneblink/types'\nimport evaluateConditionalOptionsPredicate from './evaluateConditionalOptionsPredicate'\nimport { FormElementsCtrl } from '../types'\n\nimport conditionallyShowElement from './conditionallyShowElement'\n\nconst handleAttributePredicate = (\n predicate: FormTypes.ChoiceElementOptionAttribute,\n model: Record<string, unknown>,\n predicateElement: FormTypes.FormElementWithOptions,\n) => {\n const values = model[predicateElement.name]\n if (!values) return true\n\n if (\n Array.isArray(values) &&\n (!values.length ||\n !values.filter((value) => typeof value !== 'undefined').length)\n ) {\n return true\n }\n\n return evaluateConditionalOptionsPredicate({\n predicate: {\n type: 'OPTIONS',\n elementId: predicate.elementId,\n optionIds: predicate.optionIds,\n },\n predicateValue: values,\n predicateElement,\n })\n}\n\nconst conditionallyShowOptionByPredicate = (\n formElementsCtrl: FormElementsCtrl,\n predicate: FormTypes.ChoiceElementOptionAttribute,\n elementsEvaluated: string[],\n): boolean => {\n // Validate the predicate data, if it is invalid,\n // we will always show the field\n if (\n !predicate ||\n !predicate.elementId ||\n !predicate.optionIds ||\n !predicate.optionIds.length\n ) {\n return true\n }\n\n const predicateElement = formElementsCtrl.flattenedElements.find(\n (element) => {\n return element.id === predicate.elementId\n },\n )\n\n // If we cant find the element used for the predicate,\n // we can check to see if the element being evaluated\n // is in a repeatable set and the predicate element is\n // in a parent list of elements.\n if (!predicateElement) {\n if (formElementsCtrl.parentFormElementsCtrl) {\n return conditionallyShowOptionByPredicate(\n formElementsCtrl.parentFormElementsCtrl,\n predicate,\n elementsEvaluated,\n )\n } else {\n return false\n }\n }\n\n if (\n predicateElement.type !== 'compliance' &&\n predicateElement.type !== 'select' &&\n predicateElement.type !== 'autocomplete' &&\n predicateElement.type !== 'checkboxes' &&\n predicateElement.type !== 'radio'\n ) {\n return false\n }\n\n // If the predicate element does not have any options to evaluate,\n // we will show the element.\n // Unless the predicate element has dynamic options and\n // options have not been fetched yet.\n if (!Array.isArray(predicateElement.options)) {\n return predicateElement.optionsType !== 'DYNAMIC'\n }\n\n const everyOptionIsShowing = predicate.optionIds.every((id) => {\n const predicateOption = predicateElement.options?.find((o) => o.id === id)\n if (!predicateOption) return false\n\n return conditionallyShowOption(\n { model: formElementsCtrl.model, flattenedElements: [] },\n predicateElement,\n predicateOption,\n elementsEvaluated,\n )\n })\n\n if (!everyOptionIsShowing) {\n return false\n }\n\n // Check to see if the model has one of the valid values to show the element\n return handleAttributePredicate(\n predicate,\n formElementsCtrl.model,\n predicateElement,\n )\n}\n\nconst isAttributeFilterValid = (\n formElementsCtrl: FormElementsCtrl,\n predicate: FormTypes.ChoiceElementOptionAttribute,\n elementsEvaluated: string[],\n): boolean => {\n const predicateElement = formElementsCtrl.flattenedElements.find(\n (element) => {\n return element.id === predicate.elementId\n },\n )\n\n // If we cant find the element used for the predicate,\n // we can check to see if the element being evaluated\n // is in a repeatable set and the predicate element is\n // in a parent list of elements.\n if (!predicateElement) {\n if (formElementsCtrl.parentFormElementsCtrl) {\n return isAttributeFilterValid(\n formElementsCtrl.parentFormElementsCtrl,\n predicate,\n elementsEvaluated,\n )\n } else {\n return false\n }\n }\n\n // now we have the model and predicate element, verify that the predicate element\n // is not hidden\n if (\n // Will never be a page, just making typescript happy :)\n predicateElement.type === 'page' ||\n predicateElement.type === 'section' ||\n !conditionallyShowElement(formElementsCtrl, predicateElement, [])\n ) {\n return false\n }\n\n // verify that at least one option is selected\n const values = formElementsCtrl.model[predicateElement.name]\n if (!values) return false\n // if the model value is an array, verify that it has a selection\n if (\n Array.isArray(values) &&\n (!values.length ||\n !values.filter((value) => typeof value !== 'undefined').length)\n ) {\n return false\n }\n\n return true\n}\n\nexport default function conditionallyShowOption(\n formElementsCtrl: FormElementsCtrl,\n elementToEvaluate: FormTypes.FormElementWithOptions,\n optionToEvaluate: FormTypes.ChoiceElementOption,\n optionsEvaluated: string[],\n): boolean {\n // If the element does not have the `conditionallyShow` flag set,\n // we can always show the element.\n\n if (\n !elementToEvaluate.conditionallyShowOptions ||\n !optionToEvaluate ||\n !optionToEvaluate.attributes ||\n !Array.isArray(optionToEvaluate.attributes) ||\n !optionToEvaluate.attributes.length\n ) {\n return true\n }\n\n // Check to see if this element has already been used to evaluate\n // if the element should be shown based on parent element conditional logic\n if (optionsEvaluated.some((optionId) => optionId === optionToEvaluate.id)) {\n throw new Error(\n 'Your conditional logic has caused an infinite loop. Check the following Fields to ensure element A does not rely on element B if element B also relies on element A.',\n )\n } else {\n optionsEvaluated.push(optionToEvaluate.id)\n }\n\n const validPredicates = (optionToEvaluate.attributes || []).filter(\n (predicate) => {\n return isAttributeFilterValid(\n formElementsCtrl,\n predicate,\n optionsEvaluated,\n )\n },\n )\n\n if (!validPredicates.length) return true\n return validPredicates.some((predicate) =>\n conditionallyShowOptionByPredicate(\n formElementsCtrl,\n predicate,\n optionsEvaluated,\n ),\n )\n}\n"]}
@@ -0,0 +1,6 @@
1
+ import { FormTypes, ConditionTypes } from '@oneblink/types';
2
+ export default function evaluateConditionalOptionsPredicate({ predicate, predicateElement, predicateValue: value, }: {
3
+ predicate: ConditionTypes.ConditionalPredicateOptions;
4
+ predicateValue: unknown;
5
+ predicateElement: FormTypes.FormElementWithOptions;
6
+ }): boolean;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function evaluateConditionalOptionsPredicate({ predicate, predicateElement, predicateValue: value, }) {
4
+ return predicate.optionIds.some((optionId) => {
5
+ var _a;
6
+ const option = (_a = predicateElement.options) === null || _a === void 0 ? void 0 : _a.find((o) => o.id === optionId);
7
+ if (option) {
8
+ if (Array.isArray(value)) {
9
+ return value.some((modelValue) => {
10
+ return modelValue === option.value;
11
+ });
12
+ }
13
+ else if (predicateElement.type === 'compliance' && value) {
14
+ return option.value === value.value;
15
+ }
16
+ else {
17
+ return option.value === value;
18
+ }
19
+ }
20
+ else {
21
+ return false;
22
+ }
23
+ });
24
+ }
25
+ exports.default = evaluateConditionalOptionsPredicate;
26
+ //# sourceMappingURL=evaluateConditionalOptionsPredicate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evaluateConditionalOptionsPredicate.js","sourceRoot":"","sources":["../../src/conditionalLogicService/evaluateConditionalOptionsPredicate.ts"],"names":[],"mappings":";;AAEA,SAAwB,mCAAmC,CAAC,EAC1D,SAAS,EACT,gBAAgB,EAChB,cAAc,EAAE,KAAK,GAKtB;IACC,OAAO,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;;QAC3C,MAAM,MAAM,GAAG,MAAA,gBAAgB,CAAC,OAAO,0CAAE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAA;QACvE,IAAI,MAAM,EAAE;YACV,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBACxB,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE;oBAC/B,OAAO,UAAU,KAAK,MAAM,CAAC,KAAK,CAAA;gBACpC,CAAC,CAAC,CAAA;aACH;iBAAM,IAAI,gBAAgB,CAAC,IAAI,KAAK,YAAY,IAAI,KAAK,EAAE;gBAC1D,OAAO,MAAM,CAAC,KAAK,KAAM,KAA4B,CAAC,KAAK,CAAA;aAC5D;iBAAM;gBACL,OAAO,MAAM,CAAC,KAAK,KAAK,KAAK,CAAA;aAC9B;SACF;aAAM;YACL,OAAO,KAAK,CAAA;SACb;IACH,CAAC,CAAC,CAAA;AACJ,CAAC;AAzBD,sDAyBC","sourcesContent":["import { FormTypes, ConditionTypes } from '@oneblink/types'\n\nexport default function evaluateConditionalOptionsPredicate({\n predicate,\n predicateElement,\n predicateValue: value,\n}: {\n predicate: ConditionTypes.ConditionalPredicateOptions\n predicateValue: unknown\n predicateElement: FormTypes.FormElementWithOptions\n}): boolean {\n return predicate.optionIds.some((optionId) => {\n const option = predicateElement.options?.find((o) => o.id === optionId)\n if (option) {\n if (Array.isArray(value)) {\n return value.some((modelValue) => {\n return modelValue === option.value\n })\n } else if (predicateElement.type === 'compliance' && value) {\n return option.value === (value as { value: unknown }).value\n } else {\n return option.value === value\n }\n } else {\n return false\n }\n })\n}\n"]}
@@ -0,0 +1,6 @@
1
+ import { FormTypes, ConditionTypes } from '@oneblink/types';
2
+ import { FormElementsCtrl } from '../types';
3
+ export default function evaluateConditionalPredicate({ predicate, formElementsCtrl, }: {
4
+ predicate: ConditionTypes.ConditionalPredicate;
5
+ formElementsCtrl: FormElementsCtrl;
6
+ }): FormTypes.FormElementWithName | undefined;
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const typeCastService_1 = require("../typeCastService");
7
+ const evaluateConditionalOptionsPredicate_1 = __importDefault(require("./evaluateConditionalOptionsPredicate"));
8
+ const fnMap = {
9
+ '>': (lhs, rhs) => lhs > rhs,
10
+ '>=': (lhs, rhs) => lhs >= rhs,
11
+ '===': (lhs, rhs) => lhs === rhs,
12
+ '!==': (lhs, rhs) => lhs !== rhs,
13
+ '<=': (lhs, rhs) => lhs <= rhs,
14
+ '<': (lhs, rhs) => lhs < rhs,
15
+ };
16
+ function getElementAndValue(formElementsCtrl, elementId) {
17
+ const formElement = formElementsCtrl.flattenedElements.find((formElement) => formElement.id === elementId);
18
+ if (formElement) {
19
+ const formElementWithName = typeCastService_1.formElements.toNamedElement(formElement);
20
+ if (formElementWithName) {
21
+ return {
22
+ formElementWithName,
23
+ value: formElementsCtrl.model[formElementWithName.name],
24
+ };
25
+ }
26
+ }
27
+ else if (formElementsCtrl.parentFormElementsCtrl) {
28
+ return getElementAndValue(formElementsCtrl.parentFormElementsCtrl, elementId);
29
+ }
30
+ return {};
31
+ }
32
+ function evaluateConditionalPredicate({ predicate, formElementsCtrl, }) {
33
+ const { formElementWithName: predicateElement, value: predicateValue } = getElementAndValue(formElementsCtrl, predicate.elementId);
34
+ if (!predicateElement) {
35
+ return;
36
+ }
37
+ switch (predicate.type) {
38
+ case 'VALUE': {
39
+ return !predicate.hasValue === !predicateValue
40
+ ? predicateElement
41
+ : undefined;
42
+ }
43
+ case 'NUMERIC': {
44
+ // if the operator fn doesn't exist, hide the control
45
+ const operatorFn = fnMap[predicate.operator];
46
+ if (!operatorFn)
47
+ return undefined;
48
+ const lhs = Number.parseFloat(predicateValue);
49
+ // if left is not a number, hide the control
50
+ if (isNaN(lhs))
51
+ return undefined;
52
+ let rhsValue = NaN;
53
+ switch (predicate.compareWith) {
54
+ case 'ELEMENT': {
55
+ const { value: comparisonValue } = getElementAndValue(formElementsCtrl, predicate.value);
56
+ rhsValue =
57
+ comparisonValue === 'string'
58
+ ? Number.parseFloat(comparisonValue)
59
+ : comparisonValue;
60
+ break;
61
+ }
62
+ case 'VALUE':
63
+ default: {
64
+ rhsValue = predicate.value;
65
+ break;
66
+ }
67
+ }
68
+ const rhs = typeof rhsValue === 'string' ? Number.parseFloat(rhsValue) : rhsValue;
69
+ // if right is not a number, hide the control
70
+ if (isNaN(rhs))
71
+ return undefined;
72
+ return operatorFn(lhs, rhs) ? predicateElement : undefined;
73
+ }
74
+ case 'BETWEEN': {
75
+ const value = Number.parseFloat(predicateValue);
76
+ if (Number.isNaN(value)) {
77
+ return undefined;
78
+ }
79
+ return value >= predicate.min && value <= predicate.max
80
+ ? predicateElement
81
+ : undefined;
82
+ }
83
+ case 'OPTIONS':
84
+ default: {
85
+ if (predicateElement.type !== 'select' &&
86
+ predicateElement.type !== 'autocomplete' &&
87
+ predicateElement.type !== 'radio' &&
88
+ predicateElement.type !== 'checkboxes' &&
89
+ predicateElement.type !== 'compliance') {
90
+ return undefined;
91
+ }
92
+ // If the predicate element does not have any options to evaluate,
93
+ // we will show the element.
94
+ // Unless the predicate element has dynamic options and
95
+ // options have not been fetched yet.
96
+ if (!Array.isArray(predicateElement.options)) {
97
+ return predicateElement.optionsType !== 'DYNAMIC'
98
+ ? predicateElement
99
+ : undefined;
100
+ }
101
+ else {
102
+ return (0, evaluateConditionalOptionsPredicate_1.default)({
103
+ predicate,
104
+ predicateValue,
105
+ predicateElement,
106
+ })
107
+ ? predicateElement
108
+ : undefined;
109
+ }
110
+ }
111
+ }
112
+ }
113
+ exports.default = evaluateConditionalPredicate;
114
+ //# sourceMappingURL=evaluateConditionalPredicate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evaluateConditionalPredicate.js","sourceRoot":"","sources":["../../src/conditionalLogicService/evaluateConditionalPredicate.ts"],"names":[],"mappings":";;;;;AACA,wDAAiD;AAEjD,gHAAuF;AAEvF,MAAM,KAAK,GAAG;IACZ,GAAG,EAAE,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG;IAC5C,IAAI,EAAE,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE,CAAC,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QACD,KAAK,SAAS,CAAC,CAAC;YACd,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,cAAwB,CAAC,CAAA;YACzD,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;gBACvB,OAAO,SAAS,CAAA;aACjB;YAED,OAAO,KAAK,IAAI,SAAS,CAAC,GAAG,IAAI,KAAK,IAAI,SAAS,CAAC,GAAG;gBACrD,CAAC,CAAC,gBAAgB;gBAClB,CAAC,CAAC,SAAS,CAAA;SACd;QACD,KAAK,SAAS,CAAC;QACf,OAAO,CAAC,CAAC;YACP,IACE,gBAAgB,CAAC,IAAI,KAAK,QAAQ;gBAClC,gBAAgB,CAAC,IAAI,KAAK,cAAc;gBACxC,gBAAgB,CAAC,IAAI,KAAK,OAAO;gBACjC,gBAAgB,CAAC,IAAI,KAAK,YAAY;gBACtC,gBAAgB,CAAC,IAAI,KAAK,YAAY,EACtC;gBACA,OAAO,SAAS,CAAA;aACjB;YAED,kEAAkE;YAClE,4BAA4B;YAC5B,uDAAuD;YACvD,qCAAqC;YACrC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE;gBAC5C,OAAO,gBAAgB,CAAC,WAAW,KAAK,SAAS;oBAC/C,CAAC,CAAC,gBAAgB;oBAClB,CAAC,CAAC,SAAS,CAAA;aACd;iBAAM;gBACL,OAAO,IAAA,6CAAmC,EAAC;oBACzC,SAAS;oBACT,cAAc;oBACd,gBAAgB;iBACjB,CAAC;oBACA,CAAC,CAAC,gBAAgB;oBAClB,CAAC,CAAC,SAAS,CAAA;aACd;SACF;KACF;AACH,CAAC;AAhGD,+CAgGC","sourcesContent":["import { FormTypes, ConditionTypes } from '@oneblink/types'\nimport { formElements } from '../typeCastService'\nimport { FormElementsCtrl } from '../types'\nimport evaluateConditionalOptionsPredicate from './evaluateConditionalOptionsPredicate'\n\nconst fnMap = {\n '>': (lhs: number, rhs: number) => lhs > rhs,\n '>=': (lhs: number, rhs: number) => lhs >= rhs,\n '===': (lhs: number, rhs: number) => lhs === rhs,\n '!==': (lhs: number, rhs: number) => lhs !== rhs,\n '<=': (lhs: number, rhs: number) => lhs <= rhs,\n '<': (lhs: number, rhs: number) => lhs < rhs,\n}\n\nfunction getElementAndValue(\n formElementsCtrl: FormElementsCtrl,\n elementId: string,\n): { formElementWithName?: FormTypes.FormElementWithName; value?: unknown } {\n const formElement = formElementsCtrl.flattenedElements.find(\n (formElement) => formElement.id === elementId,\n )\n if (formElement) {\n const formElementWithName = formElements.toNamedElement(formElement)\n if (formElementWithName) {\n return {\n formElementWithName,\n value: formElementsCtrl.model[formElementWithName.name],\n }\n }\n } else if (formElementsCtrl.parentFormElementsCtrl) {\n return getElementAndValue(\n formElementsCtrl.parentFormElementsCtrl,\n elementId,\n )\n }\n return {}\n}\n\nexport default function evaluateConditionalPredicate({\n predicate,\n formElementsCtrl,\n}: {\n predicate: ConditionTypes.ConditionalPredicate\n formElementsCtrl: FormElementsCtrl\n}): FormTypes.FormElementWithName | undefined {\n const { formElementWithName: predicateElement, value: predicateValue } =\n getElementAndValue(formElementsCtrl, predicate.elementId)\n if (!predicateElement) {\n return\n }\n switch (predicate.type) {\n case 'VALUE': {\n return !predicate.hasValue === !predicateValue\n ? predicateElement\n : undefined\n }\n case 'NUMERIC': {\n // if the operator fn doesn't exist, hide the control\n const operatorFn = fnMap[predicate.operator]\n if (!operatorFn) return undefined\n\n const lhs = Number.parseFloat(predicateValue as string)\n // if left is not a number, hide the control\n if (isNaN(lhs)) return undefined\n\n let rhsValue = NaN\n switch (predicate.compareWith) {\n case 'ELEMENT': {\n const { value: comparisonValue } = getElementAndValue(\n formElementsCtrl,\n predicate.value,\n )\n rhsValue =\n comparisonValue === 'string'\n ? Number.parseFloat(comparisonValue)\n : (comparisonValue as number)\n break\n }\n case 'VALUE':\n default: {\n rhsValue = predicate.value\n break\n }\n }\n\n const rhs =\n typeof rhsValue === 'string' ? Number.parseFloat(rhsValue) : rhsValue\n\n // if right is not a number, hide the control\n if (isNaN(rhs)) return undefined\n\n return operatorFn(lhs, rhs) ? predicateElement : undefined\n }\n case 'BETWEEN': {\n const value = Number.parseFloat(predicateValue as string)\n if (Number.isNaN(value)) {\n return undefined\n }\n\n return value >= predicate.min && value <= predicate.max\n ? predicateElement\n : undefined\n }\n case 'OPTIONS':\n default: {\n if (\n predicateElement.type !== 'select' &&\n predicateElement.type !== 'autocomplete' &&\n predicateElement.type !== 'radio' &&\n predicateElement.type !== 'checkboxes' &&\n predicateElement.type !== 'compliance'\n ) {\n return undefined\n }\n\n // If the predicate element does not have any options to evaluate,\n // we will show the element.\n // Unless the predicate element has dynamic options and\n // options have not been fetched yet.\n if (!Array.isArray(predicateElement.options)) {\n return predicateElement.optionsType !== 'DYNAMIC'\n ? predicateElement\n : undefined\n } else {\n return evaluateConditionalOptionsPredicate({\n predicate,\n predicateValue,\n predicateElement,\n })\n ? predicateElement\n : undefined\n }\n }\n }\n}\n"]}
@@ -1,10 +1,112 @@
1
- import { FormTypes } from '@oneblink/types';
2
- import { FormElementsCtrl, FormElementsConditionallyShown } from '../types';
3
- declare type ErrorCallback = (error: Error) => void;
4
- declare const generateFormElementsConditionallyShown: ({ formElements, submission, parentFormElementsCtrl, errorCallback, }: {
1
+ import { FormTypes, SubmissionTypes } from '@oneblink/types';
2
+ export declare type FormElementsConditionallyShown = Record<string, FormElementConditionallyShown>;
3
+ export declare type FormElementConditionallyShown = undefined | {
4
+ type: 'formElement';
5
+ isHidden: boolean;
6
+ options?: import('@oneblink/types').FormTypes.ChoiceElementOption[];
7
+ } | {
8
+ type: 'formElements';
9
+ isHidden: boolean;
10
+ formElements: FormElementsConditionallyShown | undefined;
11
+ } | {
12
+ type: 'repeatableSet';
13
+ isHidden: boolean;
14
+ entries: Record<string, FormElementsConditionallyShown | undefined>;
15
+ };
16
+ export declare type ErrorCallback = (error: Error) => void;
17
+ export declare type FormElementsConditionallyShownParameters = {
18
+ /** Form elements to evaluate */
5
19
  formElements: FormTypes.FormElement[];
6
- submission: Record<string, unknown>;
7
- parentFormElementsCtrl?: FormElementsCtrl['parentFormElementsCtrl'];
8
- errorCallback?: ErrorCallback | undefined;
9
- }) => FormElementsConditionallyShown;
10
- export default generateFormElementsConditionallyShown;
20
+ /** Current submission data */
21
+ submission: SubmissionTypes.S3SubmissionData['submission'];
22
+ /** Optional callback for handling errors caught during the evaluation */
23
+ errorCallback?: ErrorCallback;
24
+ };
25
+ /**
26
+ * Given a form element and submission data, evaluate which elements are
27
+ * currently shown. The function also takes an optional errorCallback for
28
+ * handling errors caught during the evaluation.
29
+ *
30
+ * #### Example
31
+ *
32
+ * ```js
33
+ * const formElementsConditionallyShown =
34
+ * conditionalLogicService.generateFormElementsConditionallyShown({
35
+ * submission: {
36
+ * radio: ['hide'],
37
+ * text: 'hidden text',
38
+ * },
39
+ * formElements: [
40
+ * {
41
+ * name: 'radio',
42
+ * label: 'Radio',
43
+ * type: 'radio',
44
+ * required: false,
45
+ * id: '5ef3beb8-8ac8-4c8d-9fd3-d8197113bf54',
46
+ * conditionallyShow: false,
47
+ * options: [
48
+ * {
49
+ * id: '9a44e15a-5929-419d-825e-b3dc0a29591f',
50
+ * label: 'Show',
51
+ * value: 'show',
52
+ * },
53
+ * {
54
+ * id: 'd776ed42-072c-4bf8-9879-874b2bef85d3',
55
+ * label: 'Hide',
56
+ * value: 'Hide',
57
+ * },
58
+ * ],
59
+ * readOnly: false,
60
+ * isDataLookup: false,
61
+ * isElementLookup: false,
62
+ * buttons: false,
63
+ * optionsType: 'CUSTOM',
64
+ * conditionallyShowOptions: false,
65
+ * },
66
+ * {
67
+ * name: 'text',
68
+ * label: 'Text',
69
+ * type: 'text',
70
+ * required: false,
71
+ * id: '8fbddb41-348d-494c-904b-56a2c4361f13',
72
+ * requiresAllConditionallyShowPredicates: false,
73
+ * conditionallyShow: true,
74
+ * conditionallyShowPredicates: [
75
+ * {
76
+ * elementId: '5ef3beb8-8ac8-4c8d-9fd3-d8197113bf54',
77
+ * optionIds: ['9a44e15a-5929-419d-825e-b3dc0a29591f'],
78
+ * type: 'OPTIONS',
79
+ * },
80
+ * ],
81
+ * readOnly: false,
82
+ * isDataLookup: false,
83
+ * isElementLookup: false,
84
+ * },
85
+ * ],
86
+ * parentFormElementsCtrl: undefined,
87
+ * errorCallback: (error) => {
88
+ * //do something with the error here
89
+ * console.error(error)
90
+ * },
91
+ * })
92
+ * ```
93
+ *
94
+ * The above example returns an object like below
95
+ *
96
+ * ```json
97
+ * {
98
+ * "radio": {
99
+ * "isHidden": false,
100
+ * "type": "formElement"
101
+ * },
102
+ * "text": {
103
+ * "isHidden": true,
104
+ * "type": "formElement"
105
+ * }
106
+ * }
107
+ * ```
108
+ *
109
+ * @param parameters
110
+ * @returns
111
+ */
112
+ export declare function generateFormElementsConditionallyShown(parameters: FormElementsConditionallyShownParameters): FormElementsConditionallyShown;