@oneblink/sdk-core 0.3.6-beta.2 → 0.4.0-beta.1

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 (57) 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 +86 -4
  28. package/dist/index.js +95 -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/types/index.d.ts +0 -14
  45. package/dist/types/index.js.map +1 -1
  46. package/dist/userService.d.ts +35 -0
  47. package/dist/userService.js +35 -0
  48. package/dist/userService.js.map +1 -1
  49. package/package.json +15 -12
  50. package/dist/conditionalLogicService/evaluationService.d.ts +0 -19
  51. package/dist/conditionalLogicService/evaluationService.js +0 -139
  52. package/dist/conditionalLogicService/evaluationService.js.map +0 -1
  53. package/dist/conditionalLogicService/index.d.ts +0 -2
  54. package/dist/conditionalLogicService/index.js +0 -13
  55. package/dist/conditionalLogicService/index.js.map +0 -1
  56. package/dist/paymentAmountValidation.d.ts +0 -7
  57. package/dist/paymentAmountValidation.js.map +0 -1
@@ -3,6 +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
+ exports.generateFormElementsConditionallyShown = void 0;
6
7
  const formElementsService_1 = require("../formElementsService");
7
8
  const conditionallyShowElement_1 = __importDefault(require("./conditionallyShowElement"));
8
9
  const conditionallyShowOption_1 = __importDefault(require("./conditionallyShowOption"));
@@ -25,7 +26,7 @@ const handleConditionallyShowOption = (formElementsCtrl, element, option, errorC
25
26
  return false;
26
27
  }
27
28
  };
28
- const generateFormElementsConditionallyShown = ({ formElements, submission, parentFormElementsCtrl, errorCallback, }) => {
29
+ const generateFormElementsConditionallyShownWithParent = ({ formElements, submission, parentFormElementsCtrl, errorCallback, }) => {
29
30
  const formElementsCtrl = {
30
31
  flattenedElements: (0, formElementsService_1.flattenFormElements)(formElements),
31
32
  model: submission,
@@ -75,7 +76,7 @@ const generateFormElementsConditionallyShown = ({ formElements, submission, pare
75
76
  formElementsConditionallyShown[element.name] = {
76
77
  type: 'formElements',
77
78
  isHidden: !handleConditionallyShowElement(formElementsCtrl, element, errorCallback),
78
- formElements: generateFormElementsConditionallyShown({
79
+ formElements: generateFormElementsConditionallyShownWithParent({
79
80
  formElements: element.elements || [],
80
81
  submission: nestedModel || {},
81
82
  parentFormElementsCtrl: formElementsCtrl,
@@ -93,7 +94,7 @@ const generateFormElementsConditionallyShown = ({ formElements, submission, pare
93
94
  isHidden: !handleConditionallyShowElement(formElementsCtrl, element, errorCallback),
94
95
  entries: (entries || []).reduce((result, entry, index) => {
95
96
  result[index.toString()] =
96
- generateFormElementsConditionallyShown({
97
+ generateFormElementsConditionallyShownWithParent({
97
98
  formElements: element.elements,
98
99
  submission: entry,
99
100
  parentFormElementsCtrl: formElementsCtrl,
@@ -134,5 +135,95 @@ const generateFormElementsConditionallyShown = ({ formElements, submission, pare
134
135
  return formElementsConditionallyShown;
135
136
  }, {});
136
137
  };
137
- exports.default = generateFormElementsConditionallyShown;
138
+ /**
139
+ * Given a form element and submission data, evaluate which elements are
140
+ * currently shown. The function also takes an optional errorCallback for
141
+ * handling errors caught during the evaluation.
142
+ *
143
+ * #### Example
144
+ *
145
+ * ```js
146
+ * const formElementsConditionallyShown =
147
+ * conditionalLogicService.generateFormElementsConditionallyShown({
148
+ * submission: {
149
+ * radio: ['hide'],
150
+ * text: 'hidden text',
151
+ * },
152
+ * formElements: [
153
+ * {
154
+ * name: 'radio',
155
+ * label: 'Radio',
156
+ * type: 'radio',
157
+ * required: false,
158
+ * id: '5ef3beb8-8ac8-4c8d-9fd3-d8197113bf54',
159
+ * conditionallyShow: false,
160
+ * options: [
161
+ * {
162
+ * id: '9a44e15a-5929-419d-825e-b3dc0a29591f',
163
+ * label: 'Show',
164
+ * value: 'show',
165
+ * },
166
+ * {
167
+ * id: 'd776ed42-072c-4bf8-9879-874b2bef85d3',
168
+ * label: 'Hide',
169
+ * value: 'Hide',
170
+ * },
171
+ * ],
172
+ * readOnly: false,
173
+ * isDataLookup: false,
174
+ * isElementLookup: false,
175
+ * buttons: false,
176
+ * optionsType: 'CUSTOM',
177
+ * conditionallyShowOptions: false,
178
+ * },
179
+ * {
180
+ * name: 'text',
181
+ * label: 'Text',
182
+ * type: 'text',
183
+ * required: false,
184
+ * id: '8fbddb41-348d-494c-904b-56a2c4361f13',
185
+ * requiresAllConditionallyShowPredicates: false,
186
+ * conditionallyShow: true,
187
+ * conditionallyShowPredicates: [
188
+ * {
189
+ * elementId: '5ef3beb8-8ac8-4c8d-9fd3-d8197113bf54',
190
+ * optionIds: ['9a44e15a-5929-419d-825e-b3dc0a29591f'],
191
+ * type: 'OPTIONS',
192
+ * },
193
+ * ],
194
+ * readOnly: false,
195
+ * isDataLookup: false,
196
+ * isElementLookup: false,
197
+ * },
198
+ * ],
199
+ * parentFormElementsCtrl: undefined,
200
+ * errorCallback: (error) => {
201
+ * //do something with the error here
202
+ * console.error(error)
203
+ * },
204
+ * })
205
+ * ```
206
+ *
207
+ * The above example returns an object like below
208
+ *
209
+ * ```json
210
+ * {
211
+ * "radio": {
212
+ * "isHidden": false,
213
+ * "type": "formElement"
214
+ * },
215
+ * "text": {
216
+ * "isHidden": true,
217
+ * "type": "formElement"
218
+ * }
219
+ * }
220
+ * ```
221
+ *
222
+ * @param parameters
223
+ * @returns
224
+ */
225
+ function generateFormElementsConditionallyShown(parameters) {
226
+ return generateFormElementsConditionallyShownWithParent(parameters);
227
+ }
228
+ exports.generateFormElementsConditionallyShown = generateFormElementsConditionallyShown;
138
229
  //# sourceMappingURL=generateFormElementsConditionallyShown.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generateFormElementsConditionallyShown.js","sourceRoot":"","sources":["../../src/conditionalLog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AAK,OAAO,CAAC;wBACb,KAAK,YAAY,CAAC;wBAClB,KAAK,QAAQ,CAAC,CAAC;4BACb,IACE,OAAO,CAAC,wBAAwB;gCAChC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,EAC9B;gCACA,6BAA6B,CAAC,OAAO;oCACnC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAChC,6BAA6B,CAC3B,gBAAgB,EAChB,OAAO,EACP,MAAM,EACN,aAAa,CACd,CACF,CAAA;6BACJ;4BACD,MAAK;yBACN;qBACF;iBACF;gBAED,8BAA8B,CAAC,OAAO,CAAC,IAAI,CAAC;oBAC1C,6BAA6B,CAAA;aAChC;SACF;QAED,OAAO,8BAA8B,CAAA;IACvC,CAAC,EACD,EAAE,CACH,CAAA;AACH,CAAC,CAAA;AAED,kBAAe,sCAAsC,CAAA","sourcesContent":["import { FormTypes } from '@oneblink/types'\nimport {\n FormElementsCtrl,\n FormElementsConditionallyShown,\n FormElementConditionallyShown,\n} from '../types'\nimport { flattenFormElements } from '../formElementsService'\nimport conditionallyShowElement from './conditionallyShowElement'\nimport conditionallyShowOption from './conditionallyShowOption'\n\ntype ErrorCallback = (error: Error) => void\n\nconst handleConditionallyShowElement = (\n formElementsCtrl: FormElementsCtrl,\n element: FormTypes.FormElement,\n errorCallback?: ErrorCallback,\n) => {\n try {\n return conditionallyShowElement(formElementsCtrl, element, [])\n } catch (error) {\n console.warn('Error while checking if element is conditional shown', error)\n errorCallback && errorCallback(error as Error)\n return false\n }\n}\n\nconst handleConditionallyShowOption = (\n formElementsCtrl: FormElementsCtrl,\n element: FormTypes.FormElementWithOptions,\n option: FormTypes.ChoiceElementOption,\n errorCallback?: ErrorCallback,\n) => {\n try {\n return conditionallyShowOption(formElementsCtrl, element, option, [])\n } catch (error) {\n errorCallback && errorCallback(error as Error)\n return false\n }\n}\n\nconst generateFormElementsConditionallyShown = ({\n formElements,\n submission,\n parentFormElementsCtrl,\n errorCallback,\n}: {\n formElements: FormTypes.FormElement[]\n submission: Record<string, unknown>\n parentFormElementsCtrl?: FormElementsCtrl['parentFormElementsCtrl']\n errorCallback?: ErrorCallback\n}): FormElementsConditionallyShown => {\n const formElementsCtrl = {\n flattenedElements: flattenFormElements(formElements),\n model: submission,\n parentFormElementsCtrl,\n }\n return formElementsCtrl.flattenedElements.reduce<FormElementsConditionallyShown>(\n (formElementsConditionallyShown, element) => {\n switch (element.type) {\n case 'section':\n case 'page': {\n const formElementConditionallyShown =\n formElementsConditionallyShown[element.id]\n const isHidden = formElementConditionallyShown\n ? formElementConditionallyShown.isHidden\n : !handleConditionallyShowElement(\n formElementsCtrl,\n element,\n errorCallback,\n )\n\n formElementsConditionallyShown[element.id] = {\n type: 'formElement',\n isHidden,\n }\n\n // If the parent element is hidden, hide all the child elements\n if (isHidden) {\n element.elements.forEach((childElement) => {\n switch (childElement.type) {\n case 'section':\n case 'page': {\n formElementsConditionallyShown[childElement.id] = {\n type: 'formElement',\n isHidden: true,\n }\n break\n }\n default: {\n formElementsConditionallyShown[childElement.name] = {\n type: 'formElement',\n isHidden: true,\n }\n }\n }\n })\n }\n break\n }\n case 'infoPage':\n case 'form': {\n if (formElementsConditionallyShown[element.name]) {\n break\n }\n const nestedModel = submission[element.name] as\n | Record<string, unknown>\n | undefined\n formElementsConditionallyShown[element.name] = {\n type: 'formElements',\n isHidden: !handleConditionallyShowElement(\n formElementsCtrl,\n element,\n errorCallback,\n ),\n formElements: generateFormElementsConditionallyShown({\n formElements: element.elements || [],\n submission: nestedModel || {},\n parentFormElementsCtrl: formElementsCtrl,\n }),\n }\n break\n }\n case 'repeatableSet': {\n if (formElementsConditionallyShown[element.name]) {\n break\n }\n const entries = formElementsCtrl.model[element.name] as\n | Array<Record<string, unknown>>\n | undefined\n formElementsConditionallyShown[element.name] = {\n type: 'repeatableSet',\n isHidden: !handleConditionallyShowElement(\n formElementsCtrl,\n element,\n errorCallback,\n ),\n entries: (entries || []).reduce(\n (\n result: Record<\n string,\n FormElementsConditionallyShown | undefined\n >,\n entry,\n index,\n ) => {\n result[index.toString()] =\n generateFormElementsConditionallyShown({\n formElements: element.elements,\n submission: entry,\n parentFormElementsCtrl: formElementsCtrl,\n })\n return result\n },\n {},\n ),\n }\n break\n }\n default: {\n if (formElementsConditionallyShown[element.name]) {\n break\n }\n const formElementConditionallyShown: FormElementConditionallyShown = {\n type: 'formElement',\n isHidden: !handleConditionallyShowElement(\n formElementsCtrl,\n element,\n errorCallback,\n ),\n }\n\n if (!formElementConditionallyShown.isHidden) {\n switch (element.type) {\n case 'compliance':\n case 'autocomplete':\n case 'radio':\n case 'checkboxes':\n case 'select': {\n if (\n element.conditionallyShowOptions &&\n Array.isArray(element.options)\n ) {\n formElementConditionallyShown.options =\n element.options.filter((option) =>\n handleConditionallyShowOption(\n formElementsCtrl,\n element,\n option,\n errorCallback,\n ),\n )\n }\n break\n }\n }\n }\n\n formElementsConditionallyShown[element.name] =\n formElementConditionallyShown\n }\n }\n\n return formElementsConditionallyShown\n },\n {},\n )\n}\n\nexport default generateFormElementsConditionallyShown\n"]}
1
+ {"version":3,"file":"generateFormElementsConditionallyShown.js","sourceRoot":"","sources":["../../src/conditionalLogicService/generateFormElementsConditionallyShown.ts"],"names":[],"mappings":";;;;;;AAEA,gEAA4D;AAC5D,0FAAiE;AACjE,wFAA+D;AA2B/D,MAAM,8BAA8B,GAAG,CACrC,gBAAkC,EAClC,OAA8B,EAC9B,aAA6B,EAC7B,EAAE;IACF,IAAI;QACF,OAAO,IAAA,kCAAwB,EAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE,CAAC,CAAA;KAC/D;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,IAAI,CAAC,sDAAsD,EAAE,KAAK,CAAC,CAAA;QAC3E,aAAa,IAAI,aAAa,CAAC,KAAc,CAAC,CAAA;QAC9C,OAAO,KAAK,CAAA;KACb;AACH,CAAC,CAAA;AAED,MAAM,6BAA6B,GAAG,CAC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B,CAAA;IACvC,CAAC,EACD,EAAE,CACH,CAAA;AACH,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsFG;AACH,SAAgB,sCAAsC,CACpD,UAAoD;IAEpD,OAAO,gDAAgD,CAAC,UAAU,CAAC,CAAA;AACrE,CAAC;AAJD,wFAIC","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport { FormElementsCtrl } from '../types'\nimport { flattenFormElements } from '../formElementsService'\nimport conditionallyShowElement from './conditionallyShowElement'\nimport conditionallyShowOption from './conditionallyShowOption'\n\nexport type FormElementsConditionallyShown = Record<\n string,\n FormElementConditionallyShown\n>\n\nexport type FormElementConditionallyShown =\n | undefined\n | {\n type: 'formElement'\n isHidden: boolean\n options?: import('@oneblink/types').FormTypes.ChoiceElementOption[]\n }\n | {\n type: 'formElements'\n isHidden: boolean\n formElements: FormElementsConditionallyShown | undefined\n }\n | {\n type: 'repeatableSet'\n isHidden: boolean\n entries: Record<string, FormElementsConditionallyShown | undefined>\n }\n\nexport type ErrorCallback = (error: Error) => void\n\nconst handleConditionallyShowElement = (\n formElementsCtrl: FormElementsCtrl,\n element: FormTypes.FormElement,\n errorCallback?: ErrorCallback,\n) => {\n try {\n return conditionallyShowElement(formElementsCtrl, element, [])\n } catch (error) {\n console.warn('Error while checking if element is conditional shown', error)\n errorCallback && errorCallback(error as Error)\n return false\n }\n}\n\nconst handleConditionallyShowOption = (\n formElementsCtrl: FormElementsCtrl,\n element: FormTypes.FormElementWithOptions,\n option: FormTypes.ChoiceElementOption,\n errorCallback?: ErrorCallback,\n) => {\n try {\n return conditionallyShowOption(formElementsCtrl, element, option, [])\n } catch (error) {\n errorCallback && errorCallback(error as Error)\n return false\n }\n}\n\nexport type FormElementsConditionallyShownParameters = {\n /** Form elements to evaluate */\n formElements: FormTypes.FormElement[]\n /** Current submission data */\n submission: SubmissionTypes.S3SubmissionData['submission']\n /** Optional callback for handling errors caught during the evaluation */\n errorCallback?: ErrorCallback\n}\n\nconst generateFormElementsConditionallyShownWithParent = ({\n formElements,\n submission,\n parentFormElementsCtrl,\n errorCallback,\n}: FormElementsConditionallyShownParameters & {\n parentFormElementsCtrl?: FormElementsCtrl['parentFormElementsCtrl']\n}): FormElementsConditionallyShown => {\n const formElementsCtrl = {\n flattenedElements: flattenFormElements(formElements),\n model: submission,\n parentFormElementsCtrl,\n }\n return formElementsCtrl.flattenedElements.reduce<FormElementsConditionallyShown>(\n (formElementsConditionallyShown, element) => {\n switch (element.type) {\n case 'section':\n case 'page': {\n const formElementConditionallyShown =\n formElementsConditionallyShown[element.id]\n const isHidden = formElementConditionallyShown\n ? formElementConditionallyShown.isHidden\n : !handleConditionallyShowElement(\n formElementsCtrl,\n element,\n errorCallback,\n )\n\n formElementsConditionallyShown[element.id] = {\n type: 'formElement',\n isHidden,\n }\n\n // If the parent element is hidden, hide all the child elements\n if (isHidden) {\n element.elements.forEach((childElement) => {\n switch (childElement.type) {\n case 'section':\n case 'page': {\n formElementsConditionallyShown[childElement.id] = {\n type: 'formElement',\n isHidden: true,\n }\n break\n }\n default: {\n formElementsConditionallyShown[childElement.name] = {\n type: 'formElement',\n isHidden: true,\n }\n }\n }\n })\n }\n break\n }\n case 'infoPage':\n case 'form': {\n if (formElementsConditionallyShown[element.name]) {\n break\n }\n const nestedModel = submission[element.name] as\n | Record<string, unknown>\n | undefined\n formElementsConditionallyShown[element.name] = {\n type: 'formElements',\n isHidden: !handleConditionallyShowElement(\n formElementsCtrl,\n element,\n errorCallback,\n ),\n formElements: generateFormElementsConditionallyShownWithParent({\n formElements: element.elements || [],\n submission: nestedModel || {},\n parentFormElementsCtrl: formElementsCtrl,\n }),\n }\n break\n }\n case 'repeatableSet': {\n if (formElementsConditionallyShown[element.name]) {\n break\n }\n const entries = formElementsCtrl.model[element.name] as\n | Array<Record<string, unknown>>\n | undefined\n formElementsConditionallyShown[element.name] = {\n type: 'repeatableSet',\n isHidden: !handleConditionallyShowElement(\n formElementsCtrl,\n element,\n errorCallback,\n ),\n entries: (entries || []).reduce(\n (\n result: Record<\n string,\n FormElementsConditionallyShown | undefined\n >,\n entry,\n index,\n ) => {\n result[index.toString()] =\n generateFormElementsConditionallyShownWithParent({\n formElements: element.elements,\n submission: entry,\n parentFormElementsCtrl: formElementsCtrl,\n })\n return result\n },\n {},\n ),\n }\n break\n }\n default: {\n if (formElementsConditionallyShown[element.name]) {\n break\n }\n const formElementConditionallyShown: FormElementConditionallyShown = {\n type: 'formElement',\n isHidden: !handleConditionallyShowElement(\n formElementsCtrl,\n element,\n errorCallback,\n ),\n }\n\n if (!formElementConditionallyShown.isHidden) {\n switch (element.type) {\n case 'compliance':\n case 'autocomplete':\n case 'radio':\n case 'checkboxes':\n case 'select': {\n if (\n element.conditionallyShowOptions &&\n Array.isArray(element.options)\n ) {\n formElementConditionallyShown.options =\n element.options.filter((option) =>\n handleConditionallyShowOption(\n formElementsCtrl,\n element,\n option,\n errorCallback,\n ),\n )\n }\n break\n }\n }\n }\n\n formElementsConditionallyShown[element.name] =\n formElementConditionallyShown\n }\n }\n\n return formElementsConditionallyShown\n },\n {},\n )\n}\n\n/**\n * Given a form element and submission data, evaluate which elements are\n * currently shown. The function also takes an optional errorCallback for\n * handling errors caught during the evaluation.\n *\n * #### Example\n *\n * ```js\n * const formElementsConditionallyShown =\n * conditionalLogicService.generateFormElementsConditionallyShown({\n * submission: {\n * radio: ['hide'],\n * text: 'hidden text',\n * },\n * formElements: [\n * {\n * name: 'radio',\n * label: 'Radio',\n * type: 'radio',\n * required: false,\n * id: '5ef3beb8-8ac8-4c8d-9fd3-d8197113bf54',\n * conditionallyShow: false,\n * options: [\n * {\n * id: '9a44e15a-5929-419d-825e-b3dc0a29591f',\n * label: 'Show',\n * value: 'show',\n * },\n * {\n * id: 'd776ed42-072c-4bf8-9879-874b2bef85d3',\n * label: 'Hide',\n * value: 'Hide',\n * },\n * ],\n * readOnly: false,\n * isDataLookup: false,\n * isElementLookup: false,\n * buttons: false,\n * optionsType: 'CUSTOM',\n * conditionallyShowOptions: false,\n * },\n * {\n * name: 'text',\n * label: 'Text',\n * type: 'text',\n * required: false,\n * id: '8fbddb41-348d-494c-904b-56a2c4361f13',\n * requiresAllConditionallyShowPredicates: false,\n * conditionallyShow: true,\n * conditionallyShowPredicates: [\n * {\n * elementId: '5ef3beb8-8ac8-4c8d-9fd3-d8197113bf54',\n * optionIds: ['9a44e15a-5929-419d-825e-b3dc0a29591f'],\n * type: 'OPTIONS',\n * },\n * ],\n * readOnly: false,\n * isDataLookup: false,\n * isElementLookup: false,\n * },\n * ],\n * parentFormElementsCtrl: undefined,\n * errorCallback: (error) => {\n * //do something with the error here\n * console.error(error)\n * },\n * })\n * ```\n *\n * The above example returns an object like below\n *\n * ```json\n * {\n * \"radio\": {\n * \"isHidden\": false,\n * \"type\": \"formElement\"\n * },\n * \"text\": {\n * \"isHidden\": true,\n * \"type\": \"formElement\"\n * }\n * }\n * ```\n *\n * @param parameters\n * @returns\n */\nexport function generateFormElementsConditionallyShown(\n parameters: FormElementsConditionallyShownParameters,\n): FormElementsConditionallyShown {\n return generateFormElementsConditionallyShownWithParent(parameters)\n}\n"]}
@@ -0,0 +1,71 @@
1
+ import { ConditionTypes, FormTypes, SubmissionTypes } from '@oneblink/types';
2
+ export * from './conditionalLogicService/generateFormElementsConditionallyShown';
3
+ /**
4
+ * Given a set of form elements and submission data, evaluate if predicates are
5
+ * met or not.
6
+ *
7
+ * #### Example
8
+ *
9
+ * ```js
10
+ * const evaluation = conditionalLogicService.evaluateConditionalPredicates(
11
+ * {
12
+ * isConditional: true,
13
+ * requiresAllConditionalPredicates: false,
14
+ * conditionalPredicates: [
15
+ * {
16
+ * type: 'OPTIONS',
17
+ * elementId: '3534abe4-b0b5-4ffa-a216-49c223ab6f95',
18
+ * optionIds: ['9ce633dd-22d6-4e0e-a9e0-1aa62d435e72'],
19
+ * },
20
+ * ],
21
+ * submission: {
22
+ * checkboxes: ['a'],
23
+ * },
24
+ * formElements: [
25
+ * {
26
+ * name: 'checkboxes',
27
+ * label: 'Checkboxes',
28
+ * type: 'checkboxes',
29
+ * required: false,
30
+ * id: '3534abe4-b0b5-4ffa-a216-49c223ab6f95',
31
+ * options: [
32
+ * {
33
+ * id: '9ce633dd-22d6-4e0e-a9e0-1aa62d435e72',
34
+ * label: 'First',
35
+ * value: 'a',
36
+ * },
37
+ * {
38
+ * id: '5850b32c-3833-4498-a072-47fcc8122242',
39
+ * label: 'Second',
40
+ * value: 'b',
41
+ * },
42
+ * {
43
+ * id: 'ab363e9f-a63f-4923-ba0d-47892fc26a93',
44
+ * label: 'Third',
45
+ * value: 'c',
46
+ * },
47
+ * ],
48
+ * readOnly: false,
49
+ * buttons: false,
50
+ * optionsType: 'CUSTOM',
51
+ * conditionallyShowOptions: false,
52
+ * isDataLookup: false,
53
+ * isElementLookup: false,
54
+ * conditionallyShow: false,
55
+ * requiresAllConditionallyShowPredicates: false,
56
+ * },
57
+ * ],
58
+ * },
59
+ * )
60
+ * ```
61
+ *
62
+ * @param options
63
+ * @returns
64
+ */
65
+ export declare function evaluateConditionalPredicates({ isConditional, requiresAllConditionalPredicates, conditionalPredicates, formElements, submission, }: {
66
+ isConditional: boolean;
67
+ requiresAllConditionalPredicates: boolean;
68
+ conditionalPredicates: ConditionTypes.ConditionalPredicate[];
69
+ formElements: FormTypes.FormElement[];
70
+ submission: SubmissionTypes.S3SubmissionData['submission'];
71
+ }): boolean;
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.evaluateConditionalPredicates = void 0;
21
+ const evaluateConditionalPredicate_1 = __importDefault(require("./conditionalLogicService/evaluateConditionalPredicate"));
22
+ const formElementsService_1 = require("./formElementsService");
23
+ __exportStar(require("./conditionalLogicService/generateFormElementsConditionallyShown"), exports);
24
+ /**
25
+ * Given a set of form elements and submission data, evaluate if predicates are
26
+ * met or not.
27
+ *
28
+ * #### Example
29
+ *
30
+ * ```js
31
+ * const evaluation = conditionalLogicService.evaluateConditionalPredicates(
32
+ * {
33
+ * isConditional: true,
34
+ * requiresAllConditionalPredicates: false,
35
+ * conditionalPredicates: [
36
+ * {
37
+ * type: 'OPTIONS',
38
+ * elementId: '3534abe4-b0b5-4ffa-a216-49c223ab6f95',
39
+ * optionIds: ['9ce633dd-22d6-4e0e-a9e0-1aa62d435e72'],
40
+ * },
41
+ * ],
42
+ * submission: {
43
+ * checkboxes: ['a'],
44
+ * },
45
+ * formElements: [
46
+ * {
47
+ * name: 'checkboxes',
48
+ * label: 'Checkboxes',
49
+ * type: 'checkboxes',
50
+ * required: false,
51
+ * id: '3534abe4-b0b5-4ffa-a216-49c223ab6f95',
52
+ * options: [
53
+ * {
54
+ * id: '9ce633dd-22d6-4e0e-a9e0-1aa62d435e72',
55
+ * label: 'First',
56
+ * value: 'a',
57
+ * },
58
+ * {
59
+ * id: '5850b32c-3833-4498-a072-47fcc8122242',
60
+ * label: 'Second',
61
+ * value: 'b',
62
+ * },
63
+ * {
64
+ * id: 'ab363e9f-a63f-4923-ba0d-47892fc26a93',
65
+ * label: 'Third',
66
+ * value: 'c',
67
+ * },
68
+ * ],
69
+ * readOnly: false,
70
+ * buttons: false,
71
+ * optionsType: 'CUSTOM',
72
+ * conditionallyShowOptions: false,
73
+ * isDataLookup: false,
74
+ * isElementLookup: false,
75
+ * conditionallyShow: false,
76
+ * requiresAllConditionallyShowPredicates: false,
77
+ * },
78
+ * ],
79
+ * },
80
+ * )
81
+ * ```
82
+ *
83
+ * @param options
84
+ * @returns
85
+ */
86
+ function evaluateConditionalPredicates({ isConditional, requiresAllConditionalPredicates, conditionalPredicates, formElements, submission, }) {
87
+ if (!isConditional || !conditionalPredicates.length) {
88
+ return true;
89
+ }
90
+ const formElementsCtrl = {
91
+ flattenedElements: (0, formElementsService_1.flattenFormElements)(formElements),
92
+ model: submission,
93
+ };
94
+ const predicateFn = (predicate) => (0, evaluateConditionalPredicate_1.default)({
95
+ predicate,
96
+ formElementsCtrl,
97
+ });
98
+ if (requiresAllConditionalPredicates) {
99
+ return conditionalPredicates.every(predicateFn);
100
+ }
101
+ else {
102
+ return conditionalPredicates.some(predicateFn);
103
+ }
104
+ }
105
+ exports.evaluateConditionalPredicates = evaluateConditionalPredicates;
106
+ //# sourceMappingURL=conditionalLogicService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conditionalLogicService.js","sourceRoot":"","sources":["../src/conditionalLogicService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,0HAAiG;AACjG,+DAA2D;AAG3D,mGAAgF;AAEhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,SAAgB,6BAA6B,CAAC,EAC5C,aAAa,EACb,gCAAgC,EAChC,qBAAqB,EACrB,YAAY,EACZ,UAAU,GAOX;IACC,IAAI,CAAC,aAAa,IAAI,CAAC,qBAAqB,CAAC,MAAM,EAAE;QACnD,OAAO,IAAI,CAAA;KACZ;IACD,MAAM,gBAAgB,GAAG;QACvB,iBAAiB,EAAE,IAAA,yCAAmB,EAAC,YAAY,CAAC;QACpD,KAAK,EAAE,UAAU;KAClB,CAAA;IAED,MAAM,WAAW,GAAG,CAAC,SAA8C,EAAE,EAAE,CACrE,IAAA,sCAA4B,EAAC;QAC3B,SAAS;QACT,gBAAgB;KACjB,CAAC,CAAA;IACJ,IAAI,gCAAgC,EAAE;QACpC,OAAO,qBAAqB,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;KAChD;SAAM;QACL,OAAO,qBAAqB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;KAC/C;AACH,CAAC;AA/BD,sEA+BC","sourcesContent":["import evaluateConditionalPredicate from './conditionalLogicService/evaluateConditionalPredicate'\nimport { flattenFormElements } from './formElementsService'\nimport { ConditionTypes, FormTypes, SubmissionTypes } from '@oneblink/types'\n\nexport * from './conditionalLogicService/generateFormElementsConditionallyShown'\n\n/**\n * Given a set of form elements and submission data, evaluate if predicates are\n * met or not.\n *\n * #### Example\n *\n * ```js\n * const evaluation = conditionalLogicService.evaluateConditionalPredicates(\n * {\n * isConditional: true,\n * requiresAllConditionalPredicates: false,\n * conditionalPredicates: [\n * {\n * type: 'OPTIONS',\n * elementId: '3534abe4-b0b5-4ffa-a216-49c223ab6f95',\n * optionIds: ['9ce633dd-22d6-4e0e-a9e0-1aa62d435e72'],\n * },\n * ],\n * submission: {\n * checkboxes: ['a'],\n * },\n * formElements: [\n * {\n * name: 'checkboxes',\n * label: 'Checkboxes',\n * type: 'checkboxes',\n * required: false,\n * id: '3534abe4-b0b5-4ffa-a216-49c223ab6f95',\n * options: [\n * {\n * id: '9ce633dd-22d6-4e0e-a9e0-1aa62d435e72',\n * label: 'First',\n * value: 'a',\n * },\n * {\n * id: '5850b32c-3833-4498-a072-47fcc8122242',\n * label: 'Second',\n * value: 'b',\n * },\n * {\n * id: 'ab363e9f-a63f-4923-ba0d-47892fc26a93',\n * label: 'Third',\n * value: 'c',\n * },\n * ],\n * readOnly: false,\n * buttons: false,\n * optionsType: 'CUSTOM',\n * conditionallyShowOptions: false,\n * isDataLookup: false,\n * isElementLookup: false,\n * conditionallyShow: false,\n * requiresAllConditionallyShowPredicates: false,\n * },\n * ],\n * },\n * )\n * ```\n *\n * @param options\n * @returns\n */\nexport function evaluateConditionalPredicates({\n isConditional,\n requiresAllConditionalPredicates,\n conditionalPredicates,\n formElements,\n submission,\n}: {\n isConditional: boolean\n requiresAllConditionalPredicates: boolean\n conditionalPredicates: ConditionTypes.ConditionalPredicate[]\n formElements: FormTypes.FormElement[]\n submission: SubmissionTypes.S3SubmissionData['submission']\n}): boolean {\n if (!isConditional || !conditionalPredicates.length) {\n return true\n }\n const formElementsCtrl = {\n flattenedElements: flattenFormElements(formElements),\n model: submission,\n }\n\n const predicateFn = (predicate: ConditionTypes.ConditionalPredicate) =>\n evaluateConditionalPredicate({\n predicate,\n formElementsCtrl,\n })\n if (requiresAllConditionalPredicates) {\n return conditionalPredicates.every(predicateFn)\n } else {\n return conditionalPredicates.some(predicateFn)\n }\n}\n"]}
@@ -1 +1,15 @@
1
+ /**
2
+ * Attempts to get the content disposition for the header by compiling a string
3
+ * of UTF-8 formatting based on the file name.
4
+ *
5
+ * #### Example
6
+ *
7
+ * ```js
8
+ * const contentDisposition =
9
+ * fileUploadService.getContentDisposition(fileName)
10
+ * ```
11
+ *
12
+ * @param filename The name of the file being uploaded
13
+ * @returns
14
+ */
1
15
  export declare function getContentDisposition(filename: string): string;
@@ -1,6 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getContentDisposition = void 0;
4
+ /**
5
+ * Attempts to get the content disposition for the header by compiling a string
6
+ * of UTF-8 formatting based on the file name.
7
+ *
8
+ * #### Example
9
+ *
10
+ * ```js
11
+ * const contentDisposition =
12
+ * fileUploadService.getContentDisposition(fileName)
13
+ * ```
14
+ *
15
+ * @param filename The name of the file being uploaded
16
+ * @returns
17
+ */
4
18
  function getContentDisposition(filename) {
5
19
  return `attachment; filename*=UTF-8''${encodeURIComponent(filename)}`;
6
20
  }
@@ -1 +1 @@
1
- {"version":3,"file":"fileUploadService.js","sourceRoot":"","sources":["../src/fileUploadService.ts"],"names":[],"mappings":";;;AAAA,SAAgB,qBAAqB,CAAC,QAAgB;IACpD,OAAO,gCAAgC,kBAAkB,CAAC,QAAQ,CAAC,EAAE,CAAA;AACvE,CAAC;AAFD,sDAEC","sourcesContent":["export function getContentDisposition(filename: string): string {\n return `attachment; filename*=UTF-8''${encodeURIComponent(filename)}`\n}\n"]}
1
+ {"version":3,"file":"fileUploadService.js","sourceRoot":"","sources":["../src/fileUploadService.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;GAaG;AACH,SAAgB,qBAAqB,CAAC,QAAgB;IACpD,OAAO,gCAAgC,kBAAkB,CAAC,QAAQ,CAAC,EAAE,CAAA;AACvE,CAAC;AAFD,sDAEC","sourcesContent":["/**\n * Attempts to get the content disposition for the header by compiling a string\n * of UTF-8 formatting based on the file name.\n *\n * #### Example\n *\n * ```js\n * const contentDisposition =\n * fileUploadService.getContentDisposition(fileName)\n * ```\n *\n * @param filename The name of the file being uploaded\n * @returns\n */\nexport function getContentDisposition(filename: string): string {\n return `attachment; filename*=UTF-8''${encodeURIComponent(filename)}`\n}\n"]}
@@ -1,10 +1,89 @@
1
1
  import { FormTypes } from '@oneblink/types';
2
+ /**
3
+ * Iterate over all form elements, also iterating over nested form element (e.g.
4
+ * page elements).
5
+ *
6
+ * #### Example
7
+ *
8
+ * ```js
9
+ * formElementsService.forEachFormElement(form.elements, (formElement) => {
10
+ * // do something with formElement
11
+ * })
12
+ * ```
13
+ *
14
+ * @param elements The form elements to iterate over
15
+ * @param forEach Function to execute on each form element
16
+ */
2
17
  declare function forEachFormElement(elements: FormTypes.FormElement[], forEach: (element: FormTypes.FormElement, elements: FormTypes.FormElement[]) => void): void;
18
+ /**
19
+ * Iterate over all form elements that have options (e.g. `'select'` type
20
+ * elements), also iterating over nested form element (e.g. page elements).
21
+ *
22
+ * #### Example
23
+ *
24
+ * ```js
25
+ * formElementsService.forEachFormElementWithOptions(
26
+ * form.elements,
27
+ * (formElementWithOptions) => {
28
+ * // do something with formElementWithOptions
29
+ * },
30
+ * )
31
+ * ```
32
+ *
33
+ * @param elements The form elements to iterate over
34
+ * @param forEach Function to execute on each form element with options
35
+ */
3
36
  declare function forEachFormElementWithOptions(elements: FormTypes.FormElement[], forEach: (elementWithOptions: FormTypes.FormElementWithOptions, elements: FormTypes.FormElement[]) => void): void;
37
+ /**
38
+ * Iterate over all form elements and return an element that matches a
39
+ * predicate, also iterating over nested form element (e.g. page elements). Will
40
+ * return `undefined` if no matching element is found.
41
+ *
42
+ * #### Example
43
+ *
44
+ * ```js
45
+ * const formElement = formElementsService.findFormElement(
46
+ * form.elements,
47
+ * (formElement) => {
48
+ * return formElement.id === '123-abc'
49
+ * },
50
+ * )
51
+ * ```
52
+ *
53
+ * @param elements The form elements to iterate over
54
+ * @param predicate Predicate function to execute on each form element
55
+ * @param parentElements
56
+ * @returns
57
+ */
4
58
  declare function findFormElement(elements: FormTypes.FormElement[], predicate: (element: FormTypes.FormElement, elements: FormTypes.FormElement[]) => boolean, parentElements?: FormTypes.FormElement[]): FormTypes.FormElement | void;
59
+ /**
60
+ * Parse unknown data as valid options for a forms element. This will always
61
+ * return an Array of valid options.
62
+ *
63
+ * #### Example
64
+ *
65
+ * ```js
66
+ * const options = formElementsService.parseFormElementOptionsSet(data)
67
+ * // "options" are valid for a form element
68
+ * ```
69
+ *
70
+ * @param data
71
+ * @returns
72
+ */
5
73
  declare function parseFormElementOptionsSet(data: unknown): FormTypes.ChoiceElementOption[];
74
+ /**
75
+ * Takes the nested definition structure and returns all form elements as 1d array.
76
+ *
77
+ * #### Example
78
+ *
79
+ * ```js
80
+ * const flattenedElements = formElementsService.flattenFormElements(
81
+ * form.elements,
82
+ * )
83
+ * ```
84
+ *
85
+ * @param elements
86
+ * @returns
87
+ */
6
88
  declare function flattenFormElements(elements: FormTypes.FormElement[]): FormTypes.FormElement[];
7
- declare function getRootElementValueById(formElementId: string, formElements: FormTypes.FormElement[], submission: {
8
- readonly [key: string]: unknown;
9
- }): unknown;
10
- export { getRootElementValueById, forEachFormElement, forEachFormElementWithOptions, findFormElement, parseFormElementOptionsSet, flattenFormElements, };
89
+ export { forEachFormElement, forEachFormElementWithOptions, findFormElement, parseFormElementOptionsSet, flattenFormElements, };
@@ -1,6 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.flattenFormElements = exports.parseFormElementOptionsSet = exports.findFormElement = exports.forEachFormElementWithOptions = exports.forEachFormElement = exports.getRootElementValueById = void 0;
3
+ exports.flattenFormElements = exports.parseFormElementOptionsSet = exports.findFormElement = exports.forEachFormElementWithOptions = exports.forEachFormElement = void 0;
4
+ /**
5
+ * Iterate over all form elements, also iterating over nested form element (e.g.
6
+ * page elements).
7
+ *
8
+ * #### Example
9
+ *
10
+ * ```js
11
+ * formElementsService.forEachFormElement(form.elements, (formElement) => {
12
+ * // do something with formElement
13
+ * })
14
+ * ```
15
+ *
16
+ * @param elements The form elements to iterate over
17
+ * @param forEach Function to execute on each form element
18
+ */
4
19
  function forEachFormElement(elements, forEach) {
5
20
  findFormElement(elements, (formElement, parentElements) => {
6
21
  forEach(formElement, parentElements);
@@ -8,6 +23,24 @@ function forEachFormElement(elements, forEach) {
8
23
  });
9
24
  }
10
25
  exports.forEachFormElement = forEachFormElement;
26
+ /**
27
+ * Iterate over all form elements that have options (e.g. `'select'` type
28
+ * elements), also iterating over nested form element (e.g. page elements).
29
+ *
30
+ * #### Example
31
+ *
32
+ * ```js
33
+ * formElementsService.forEachFormElementWithOptions(
34
+ * form.elements,
35
+ * (formElementWithOptions) => {
36
+ * // do something with formElementWithOptions
37
+ * },
38
+ * )
39
+ * ```
40
+ *
41
+ * @param elements The form elements to iterate over
42
+ * @param forEach Function to execute on each form element with options
43
+ */
11
44
  function forEachFormElementWithOptions(elements, forEach) {
12
45
  findFormElement(elements, (formElement, parentElements) => {
13
46
  if (formElement.type === 'select' ||
@@ -21,6 +54,27 @@ function forEachFormElementWithOptions(elements, forEach) {
21
54
  });
22
55
  }
23
56
  exports.forEachFormElementWithOptions = forEachFormElementWithOptions;
57
+ /**
58
+ * Iterate over all form elements and return an element that matches a
59
+ * predicate, also iterating over nested form element (e.g. page elements). Will
60
+ * return `undefined` if no matching element is found.
61
+ *
62
+ * #### Example
63
+ *
64
+ * ```js
65
+ * const formElement = formElementsService.findFormElement(
66
+ * form.elements,
67
+ * (formElement) => {
68
+ * return formElement.id === '123-abc'
69
+ * },
70
+ * )
71
+ * ```
72
+ *
73
+ * @param elements The form elements to iterate over
74
+ * @param predicate Predicate function to execute on each form element
75
+ * @param parentElements
76
+ * @returns
77
+ */
24
78
  function findFormElement(elements, predicate, parentElements = []) {
25
79
  for (const element of elements) {
26
80
  if (predicate(element, parentElements)) {
@@ -43,6 +97,20 @@ function findFormElement(elements, predicate, parentElements = []) {
43
97
  }
44
98
  }
45
99
  exports.findFormElement = findFormElement;
100
+ /**
101
+ * Parse unknown data as valid options for a forms element. This will always
102
+ * return an Array of valid options.
103
+ *
104
+ * #### Example
105
+ *
106
+ * ```js
107
+ * const options = formElementsService.parseFormElementOptionsSet(data)
108
+ * // "options" are valid for a form element
109
+ * ```
110
+ *
111
+ * @param data
112
+ * @returns
113
+ */
46
114
  function parseFormElementOptionsSet(data) {
47
115
  if (!Array.isArray(data)) {
48
116
  return [];
@@ -79,6 +147,20 @@ function parseFormElementOptionsSet(data) {
79
147
  }, []);
80
148
  }
81
149
  exports.parseFormElementOptionsSet = parseFormElementOptionsSet;
150
+ /**
151
+ * Takes the nested definition structure and returns all form elements as 1d array.
152
+ *
153
+ * #### Example
154
+ *
155
+ * ```js
156
+ * const flattenedElements = formElementsService.flattenFormElements(
157
+ * form.elements,
158
+ * )
159
+ * ```
160
+ *
161
+ * @param elements
162
+ * @returns
163
+ */
82
164
  function flattenFormElements(elements) {
83
165
  return elements.reduce((flattenedElements, element) => {
84
166
  flattenedElements.push(element);
@@ -92,18 +174,4 @@ function flattenFormElements(elements) {
92
174
  }, []);
93
175
  }
94
176
  exports.flattenFormElements = flattenFormElements;
95
- function getRootElementValueById(formElementId, formElements, submission) {
96
- for (const formElement of formElements) {
97
- if (formElement.type === 'page' || formElement.type === 'section') {
98
- const value = getRootElementValueById(formElementId, formElement.elements, submission);
99
- if (value !== undefined) {
100
- return value;
101
- }
102
- }
103
- else if (formElement.id === formElementId) {
104
- return submission[formElement.name];
105
- }
106
- }
107
- }
108
- exports.getRootElementValueById = getRootElementValueById;
109
177
  //# sourceMappingURL=formElementsService.js.map