@oneblink/apps-react 4.4.0 → 4.5.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 (105) hide show
  1. package/dist/OneBlinkAutoSaveForm.js +2 -2
  2. package/dist/OneBlinkAutoSaveForm.js.map +1 -1
  3. package/dist/OneBlinkForm.js +2 -2
  4. package/dist/OneBlinkForm.js.map +1 -1
  5. package/dist/OneBlinkFormBase.d.ts +3 -2
  6. package/dist/OneBlinkFormBase.js +36 -23
  7. package/dist/OneBlinkFormBase.js.map +1 -1
  8. package/dist/OneBlinkReadOnlyForm.js +2 -2
  9. package/dist/OneBlinkReadOnlyForm.js.map +1 -1
  10. package/dist/components/renderer/LookupNotification.js +59 -13
  11. package/dist/components/renderer/LookupNotification.js.map +1 -1
  12. package/dist/components/renderer/OneBlinkFormElements.d.ts +2 -2
  13. package/dist/components/renderer/OneBlinkFormElements.js.map +1 -1
  14. package/dist/components/renderer/PageFormElements.d.ts +2 -2
  15. package/dist/components/renderer/PageFormElements.js +3 -1
  16. package/dist/components/renderer/PageFormElements.js.map +1 -1
  17. package/dist/components/renderer/ToggleAllCheckbox.js +6 -2
  18. package/dist/components/renderer/ToggleAllCheckbox.js.map +1 -1
  19. package/dist/form-elements/FormElementABN.js +6 -2
  20. package/dist/form-elements/FormElementABN.js.map +1 -1
  21. package/dist/form-elements/FormElementAutocomplete.js +3 -1
  22. package/dist/form-elements/FormElementAutocomplete.js.map +1 -1
  23. package/dist/form-elements/FormElementBSB.js +12 -4
  24. package/dist/form-elements/FormElementBSB.js.map +1 -1
  25. package/dist/form-elements/FormElementBarcodeScanner.js +6 -2
  26. package/dist/form-elements/FormElementBarcodeScanner.js.map +1 -1
  27. package/dist/form-elements/FormElementBoolean.js +3 -1
  28. package/dist/form-elements/FormElementBoolean.js.map +1 -1
  29. package/dist/form-elements/FormElementCalculation.js +6 -2
  30. package/dist/form-elements/FormElementCalculation.js.map +1 -1
  31. package/dist/form-elements/FormElementCamera.js +25 -11
  32. package/dist/form-elements/FormElementCamera.js.map +1 -1
  33. package/dist/form-elements/FormElementCaptcha.js +3 -1
  34. package/dist/form-elements/FormElementCaptcha.js.map +1 -1
  35. package/dist/form-elements/FormElementCheckBoxes.js +14 -12
  36. package/dist/form-elements/FormElementCheckBoxes.js.map +1 -1
  37. package/dist/form-elements/FormElementCivicaStreetName.js +3 -1
  38. package/dist/form-elements/FormElementCivicaStreetName.js.map +1 -1
  39. package/dist/form-elements/FormElementCompliance.js +57 -49
  40. package/dist/form-elements/FormElementCompliance.js.map +1 -1
  41. package/dist/form-elements/FormElementDate.js +3 -1
  42. package/dist/form-elements/FormElementDate.js.map +1 -1
  43. package/dist/form-elements/FormElementDateTime.js +3 -1
  44. package/dist/form-elements/FormElementDateTime.js.map +1 -1
  45. package/dist/form-elements/FormElementEmail.js +3 -1
  46. package/dist/form-elements/FormElementEmail.js.map +1 -1
  47. package/dist/form-elements/FormElementForm.d.ts +2 -2
  48. package/dist/form-elements/FormElementForm.js +30 -8
  49. package/dist/form-elements/FormElementForm.js.map +1 -1
  50. package/dist/form-elements/FormElementGeoscapeAddress.js +6 -2
  51. package/dist/form-elements/FormElementGeoscapeAddress.js.map +1 -1
  52. package/dist/form-elements/FormElementLocation.js +6 -2
  53. package/dist/form-elements/FormElementLocation.js.map +1 -1
  54. package/dist/form-elements/FormElementNumber.js +3 -1
  55. package/dist/form-elements/FormElementNumber.js.map +1 -1
  56. package/dist/form-elements/FormElementPointAddress.js +2 -2
  57. package/dist/form-elements/FormElementPointAddress.js.map +1 -1
  58. package/dist/form-elements/FormElementRadio.js +6 -2
  59. package/dist/form-elements/FormElementRadio.js.map +1 -1
  60. package/dist/form-elements/FormElementRepeatableSet.d.ts +2 -2
  61. package/dist/form-elements/FormElementRepeatableSet.js +95 -28
  62. package/dist/form-elements/FormElementRepeatableSet.js.map +1 -1
  63. package/dist/form-elements/FormElementSection.js +5 -1
  64. package/dist/form-elements/FormElementSection.js.map +1 -1
  65. package/dist/form-elements/FormElementSelect.js +6 -2
  66. package/dist/form-elements/FormElementSelect.js.map +1 -1
  67. package/dist/form-elements/FormElementSignature.js +16 -8
  68. package/dist/form-elements/FormElementSignature.js.map +1 -1
  69. package/dist/form-elements/FormElementSummary.js +6 -2
  70. package/dist/form-elements/FormElementSummary.js.map +1 -1
  71. package/dist/form-elements/FormElementTelephone.js +3 -1
  72. package/dist/form-elements/FormElementTelephone.js.map +1 -1
  73. package/dist/form-elements/FormElementText.js +3 -1
  74. package/dist/form-elements/FormElementText.js.map +1 -1
  75. package/dist/form-elements/FormElementTextarea.js +3 -1
  76. package/dist/form-elements/FormElementTextarea.js.map +1 -1
  77. package/dist/form-elements/FormElementTime.js +3 -1
  78. package/dist/form-elements/FormElementTime.js.map +1 -1
  79. package/dist/hooks/attachments/useAttachments.js +30 -24
  80. package/dist/hooks/attachments/useAttachments.js.map +1 -1
  81. package/dist/hooks/useFormElementOptions.js +6 -2
  82. package/dist/hooks/useFormElementOptions.js.map +1 -1
  83. package/dist/hooks/useFormSubmissionAutoSaveState.d.ts +2 -0
  84. package/dist/hooks/useFormSubmissionAutoSaveState.js +2 -1
  85. package/dist/hooks/useFormSubmissionAutoSaveState.js.map +1 -1
  86. package/dist/hooks/useFormSubmissionState.d.ts +5 -6
  87. package/dist/hooks/useFormSubmissionState.js +1 -0
  88. package/dist/hooks/useFormSubmissionState.js.map +1 -1
  89. package/dist/hooks/useFormValidation.d.ts +2 -4
  90. package/dist/hooks/useFormValidation.js +4 -20
  91. package/dist/hooks/useFormValidation.js.map +1 -1
  92. package/dist/hooks/useLookups.js +1 -0
  93. package/dist/hooks/useLookups.js.map +1 -1
  94. package/dist/hooks/useToggleComplianceChildren.d.ts +3 -1
  95. package/dist/hooks/useToggleComplianceChildren.js +1 -1
  96. package/dist/hooks/useToggleComplianceChildren.js.map +1 -1
  97. package/dist/services/form-validation.d.ts +3 -3
  98. package/dist/services/form-validation.js +54 -27
  99. package/dist/services/form-validation.js.map +1 -1
  100. package/dist/types/form.d.ts +15 -1
  101. package/dist/types/form.js.map +1 -1
  102. package/package.json +2 -2
  103. package/dist/hooks/useExecutedLookupCallback.d.ts +0 -12
  104. package/dist/hooks/useExecutedLookupCallback.js +0 -16
  105. package/dist/hooks/useExecutedLookupCallback.js.map +0 -1
@@ -28,32 +28,16 @@ function stripFormElementsWithoutName(formElements) {
28
28
  }, []);
29
29
  }
30
30
  export default function useFormValidation(pages) {
31
- const [elementIdsWithLookupsExecuted, setElementIdsWithLookupsExecuted] = React.useState([]);
32
- const executedLookup = React.useCallback((element) => {
33
- setElementIdsWithLookupsExecuted((currentElementIdsWithLookupsExecuted) => {
34
- if (currentElementIdsWithLookupsExecuted.includes(element.id)) {
35
- return currentElementIdsWithLookupsExecuted;
36
- }
37
- return [...currentElementIdsWithLookupsExecuted, element.id];
38
- });
39
- }, []);
40
- const executeLookupFailed = React.useCallback((element) => {
41
- setElementIdsWithLookupsExecuted((currentElementIdsWithLookupsExecuted) => {
42
- return currentElementIdsWithLookupsExecuted.filter((elementId) => elementId !== element.id);
43
- });
44
- }, []);
45
31
  const formElementsWithoutName = React.useMemo(() => {
46
32
  return stripFormElementsWithoutName(pages);
47
33
  }, [pages]);
48
34
  const validationSchema = React.useMemo(() => {
49
- return generateValidationSchema(formElementsWithoutName, elementIdsWithLookupsExecuted);
50
- }, [formElementsWithoutName, elementIdsWithLookupsExecuted]);
51
- const handleValidate = React.useCallback((submission, formElementsConditionallyShown) => {
52
- return validateSubmission(validationSchema, submission, formElementsConditionallyShown);
35
+ return generateValidationSchema(formElementsWithoutName);
36
+ }, [formElementsWithoutName]);
37
+ const handleValidate = React.useCallback((submission, formElementsConditionallyShown, executedLookups) => {
38
+ return validateSubmission(validationSchema, submission, formElementsConditionallyShown, executedLookups);
53
39
  }, [validationSchema]);
54
40
  return {
55
- executedLookup,
56
- executeLookupFailed,
57
41
  validate: handleValidate,
58
42
  };
59
43
  }
@@ -1 +1 @@
1
- {"version":3,"file":"use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C,EAAE,OAAO,CAAC,EAAE,CAAC,CAAA;QAC9D,CAAC,CACF,CAAA;IACH,CAAC,EACD,EAAE,CACH,CAAA;IACD,MAAM,mBAAmB,GAAG,KAAK,CAAC,WAAW,CAC3C,CAAC,OAAoC,EAAE,EAAE;QACvC,gCAAgC,CAC9B,CAAC,oCAAoC,EAAE,EAAE;YACvC,OAAO,oCAAoC,CAAC,MAAM,CAChD,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,KAAK,OAAO,CAAC,EAAE,CACxC,CAAA;QACH,CAAC,CACF,CAAA;IACH,CAAC,EACD,EAAE,CACH,CAAA;IAED,MAAM,uBAAuB,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACjD,OAAO,4BAA4B,CAAC,KAAK,CAAC,CAAA;IAC5C,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;IAEX,MAAM,gBAAgB,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QAC1C,OAAO,wBAAwB,CAC7B,uBAAuB,EACvB,6BAA6B,CAC9B,CAAA;IACH,CAAC,EAAE,CAAC,uBAAuB,EAAE,6BAA6B,CAAC,CAAC,CAAA;IAE5D,MAAM,cAAc,GAAG,KAAK,CAAC,WAAW,CACtC,CACE,UAA0D,EAC1D,8BAA8D,EAC9D,EAAE;QACF,OAAO,kBAAkB,CACvB,gBAAgB,EAChB,UAAU,EACV,8BAA8B,CAC/B,CAAA;IACH,CAAC,EACD,CAAC,gBAAgB,CAAC,CACnB,CAAA;IAED,OAAO;QACL,cAAc;QACd,mBAAmB;QACnB,QAAQ,EAAE,cAAc;KACzB,CAAA;AACH,CAAC","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport * as React from 'react'\n\nimport {\n validateSubmission,\n generateValidationSchema,\n} from '../services/form-validation'\nimport { FormElementsConditionallyShown } from '../types/form'\n\nfunction stripFormElementsWithoutName(\n formElements: FormTypes.FormElement[],\n): FormTypes.FormElementWithName[] {\n return formElements.reduce<FormTypes.FormElementWithName[]>(\n (memo, formElement) => {\n switch (formElement.type) {\n case 'page':\n case 'section': {\n return [\n ...memo,\n ...stripFormElementsWithoutName(formElement.elements),\n ]\n }\n case 'infoPage':\n case 'form':\n case 'repeatableSet': {\n return [\n ...memo,\n {\n ...formElement,\n elements: stripFormElementsWithoutName(\n formElement.elements || [],\n ),\n },\n ]\n }\n default: {\n return [...memo, formElement]\n }\n }\n },\n [],\n )\n}\n\nexport default function useFormValidation(pages: FormTypes.PageElement[]) {\n const [elementIdsWithLookupsExecuted, setElementIdsWithLookupsExecuted] =\n React.useState<string[]>([])\n\n const executedLookup = React.useCallback(\n (element: FormTypes.LookupFormElement) => {\n setElementIdsWithLookupsExecuted(\n (currentElementIdsWithLookupsExecuted: string[]) => {\n if (currentElementIdsWithLookupsExecuted.includes(element.id)) {\n return currentElementIdsWithLookupsExecuted\n }\n return [...currentElementIdsWithLookupsExecuted, element.id]\n },\n )\n },\n [],\n )\n const executeLookupFailed = React.useCallback(\n (element: FormTypes.LookupFormElement) => {\n setElementIdsWithLookupsExecuted(\n (currentElementIdsWithLookupsExecuted) => {\n return currentElementIdsWithLookupsExecuted.filter(\n (elementId) => elementId !== element.id,\n )\n },\n )\n },\n [],\n )\n\n const formElementsWithoutName = React.useMemo(() => {\n return stripFormElementsWithoutName(pages)\n }, [pages])\n\n const validationSchema = React.useMemo(() => {\n return generateValidationSchema(\n formElementsWithoutName,\n elementIdsWithLookupsExecuted,\n )\n }, [formElementsWithoutName, elementIdsWithLookupsExecuted])\n\n const handleValidate = React.useCallback(\n (\n submission: SubmissionTypes.S3SubmissionData['submission'],\n formElementsConditionallyShown: FormElementsConditionallyShown,\n ) => {\n return validateSubmission(\n validationSchema,\n submission,\n formElementsConditionallyShown,\n )\n },\n [validationSchema],\n )\n\n return {\n executedLookup,\n executeLookupFailed,\n validate: handleValidate,\n }\n}\n"]}
1
+ {"version":3,"file":"useFormValidation.js","sourceRoot":"","sources":["../../src/hooks/useFormVal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D,EAC9D,eAAgC,EAChC,EAAE;QACF,OAAO,kBAAkB,CACvB,gBAAgB,EAChB,UAAU,EACV,8BAA8B,EAC9B,eAAe,CAChB,CAAA;IACH,CAAC,EACD,CAAC,gBAAgB,CAAC,CACnB,CAAA;IAED,OAAO;QACL,QAAQ,EAAE,cAAc;KACzB,CAAA;AACH,CAAC","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport * as React from 'react'\n\nimport {\n validateSubmission,\n generateValidationSchema,\n} from '../services/form-validation'\nimport { ExecutedLookups, FormElementsConditionallyShown } from '../types/form'\n\nfunction stripFormElementsWithoutName(\n formElements: FormTypes.FormElement[],\n): FormTypes.FormElementWithName[] {\n return formElements.reduce<FormTypes.FormElementWithName[]>(\n (memo, formElement) => {\n switch (formElement.type) {\n case 'page':\n case 'section': {\n return [\n ...memo,\n ...stripFormElementsWithoutName(formElement.elements),\n ]\n }\n case 'infoPage':\n case 'form':\n case 'repeatableSet': {\n return [\n ...memo,\n {\n ...formElement,\n elements: stripFormElementsWithoutName(\n formElement.elements || [],\n ),\n },\n ]\n }\n default: {\n return [...memo, formElement]\n }\n }\n },\n [],\n )\n}\n\nexport default function useFormValidation(pages: FormTypes.PageElement[]) {\n const formElementsWithoutName = React.useMemo(() => {\n return stripFormElementsWithoutName(pages)\n }, [pages])\n\n const validationSchema = React.useMemo(() => {\n return generateValidationSchema(formElementsWithoutName)\n }, [formElementsWithoutName])\n\n const handleValidate = React.useCallback(\n (\n submission: SubmissionTypes.S3SubmissionData['submission'],\n formElementsConditionallyShown: FormElementsConditionallyShown,\n executedLookups: ExecutedLookups,\n ) => {\n return validateSubmission(\n validationSchema,\n submission,\n formElementsConditionallyShown,\n executedLookups,\n )\n },\n [validationSchema],\n )\n\n return {\n validate: handleValidate,\n }\n}\n"]}
@@ -54,6 +54,7 @@ export default function useLookups(formId, setFormSubmission) {
54
54
  submission,
55
55
  definition,
56
56
  lastElementUpdated: currentFormSubmission.lastElementUpdated,
57
+ executedLookups: currentFormSubmission.executedLookups,
57
58
  };
58
59
  });
59
60
  }, [formId, setFormSubmission]);
@@ -1 +1 @@
1
- {"version":3,"file":"useLookups.js","sourceRoot":"","sources":["../../src/hooks/useLookups.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAExD,OAAO,mBAAmB,MAAM,mCAAmC,CAAA;AAInE,MAAM,CAAC,OAAO,UAAU,UAAU,CAChC,MAAc,EACd,iBAAoC;IAEpC,MAAM,uBAAuB,GAAG,KAAK,CAAC,WAAW,CAC/C,CACE,OAAoC,EACpC,iBAA0C,EAC1C,gBAAiE,EACjE,EAAE;QACF,MAAM,eAAe,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACpD,GAAG,CAAC;YACJ,mBAAmB,EAAE,OAAO,CAAC,EAAE;SAChC,CAAC,CAAC,CAAA;QACH,iBAAiB,CAAC,CAAC,qBAAqB,EAAE,EAAE;YAC1C,MAAM,UAAU,GAAmB;gBACjC,GAAG,qBAAqB,CAAC,UAAU;gBACnC,WAAW,EAAE,IAAI;aAClB,CAAA;YACD,IAAI,CAAC,qBAAqB,CAAC,UAAU,CAAC,WAAW,EAAE;gBACjD,UAAU,CAAC,QAAQ,GAAG;oBACpB;wBACE,EAAE,EAAE,MAAM,CAAC,QAAQ,EAAE;wBACrB,IAAI,EAAE,MAAM;wBACZ,KAAK,EAAE,QAAQ;wBACf,QAAQ,EAAE,qBAAqB,CAAC,UAAU,CAAC,QAAQ;wBACnD,iBAAiB,EAAE,KAAK;wBACxB,sCAAsC,EAAE,KAAK;qBAC9C;oBACD,GAAG,eAAe;iBACnB,CAAA;aACF;iBAAM;gBACL,MAAM,WAAW,GACf,qBAAqB,CAAC,UAAU,CAAC,QAAQ,CAAC,SAAS,CACjD,CAAC,WAAkC,EAAE,EAAE;oBACrC,IAAI,WAAW,CAAC,IAAI,KAAK,MAAM,EAAE;wBAC/B,OAAO,mBAAmB,CAAC,eAAe,CACxC,WAAW,CAAC,QAAQ,EACpB,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,OAAO,CAAC,EAAE,CAC7B,CAAA;qBACF;gBACH,CAAC,CACF,CAAA;gBACH,IAAI,WAAW,KAAK,CAAC,CAAC,EAAE;oBACtB,OAAO,qBAAqB,CAAA;iBAC7B;gBACD,UAAU,CAAC,QAAQ;oBACjB,qBAAqB,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,CAC9C,CACE,mBAA4C,EAC5C,WAAkC,EAClC,KAAa,EACb,EAAE;wBACF,uFAAuF;wBACvF,IAAI,WAAW,CAAC,mBAAmB,KAAK,OAAO,CAAC,EAAE,EAAE;4BAClD,mBAAmB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;yBACtC;wBACD,IAAI,KAAK,KAAK,WAAW,EAAE;4BACzB,mBAAmB,CAAC,IAAI,CAAC,GAAG,eAAe,CAAC,CAAA;yBAC7C;wBACD,OAAO,mBAAmB,CAAA;oBAC5B,CAAC,EACD,EAAE,CACH,CAAA;aACJ;YAED,MAAM,UAAU,GAAG,mBAAmB,CAAC,UAAU,CAAC,QAAQ,EAAE;gBAC1D,GAAG,qBAAqB,CAAC,UAAU;gBACnC,GAAG,gBAAgB;aACpB,CAAC,CAAA;YACF,OAAO;gBACL,UAAU;gBACV,UAAU;gBACV,kBAAkB,EAAE,qBAAqB,CAAC,kBAAkB;aAC7D,CAAA;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,EACD,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAC5B,CAAA;IAED,OAAO;QACL,uBAAuB;KACxB,CAAA;AACH,CAAC","sourcesContent":["import * as React from 'react'\nimport { formElementsService } from '@oneblink/sdk-core'\n\nimport generateDefaultData from '../services/generate-default-data'\nimport { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport { SetFormSubmission } from '../types/form'\n\nexport default function useLookups(\n formId: number,\n setFormSubmission: SetFormSubmission,\n) {\n const handlePagesLookupResult = React.useCallback(\n (\n element: FormTypes.LookupFormElement,\n elementLookupData: FormTypes.PageElement[],\n dataLookupResult?: SubmissionTypes.S3SubmissionData['submission'],\n ) => {\n const newPageElements = elementLookupData.map((e) => ({\n ...e,\n injectedByElementId: element.id,\n }))\n setFormSubmission((currentFormSubmission) => {\n const definition: FormTypes.Form = {\n ...currentFormSubmission.definition,\n isMultiPage: true,\n }\n if (!currentFormSubmission.definition.isMultiPage) {\n definition.elements = [\n {\n id: formId.toString(),\n type: 'page',\n label: 'Page 1',\n elements: currentFormSubmission.definition.elements,\n conditionallyShow: false,\n requiresAllConditionallyShowPredicates: false,\n },\n ...newPageElements,\n ]\n } else {\n const indexOfPage =\n currentFormSubmission.definition.elements.findIndex(\n (pageElement: FormTypes.FormElement) => {\n if (pageElement.type === 'page') {\n return formElementsService.findFormElement(\n pageElement.elements,\n (el) => el.id === element.id,\n )\n }\n },\n )\n if (indexOfPage === -1) {\n return currentFormSubmission\n }\n definition.elements =\n currentFormSubmission.definition.elements.reduce(\n (\n partialPageElements: FormTypes.FormElement[],\n pageElement: FormTypes.FormElement,\n index: number,\n ) => {\n // @ts-expect-error Sorry typescript, we need to add a property you don't approve of :(\n if (pageElement.injectedByElementId !== element.id) {\n partialPageElements.push(pageElement)\n }\n if (index === indexOfPage) {\n partialPageElements.push(...newPageElements)\n }\n return partialPageElements\n },\n [],\n )\n }\n\n const submission = generateDefaultData(definition.elements, {\n ...currentFormSubmission.submission,\n ...dataLookupResult,\n })\n return {\n submission,\n definition,\n lastElementUpdated: currentFormSubmission.lastElementUpdated,\n }\n })\n },\n [formId, setFormSubmission],\n )\n\n return {\n handlePagesLookupResult,\n }\n}\n"]}
1
+ {"version":3,"file":"useLookups.js","sourceRoot":"","sources":["../../src/hooks/useLookups.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;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ACH,CAAC,CACF,CAAA;gBACH,IAAI,WAAW,KAAK,CAAC,CAAC,EAAE;oBACtB,OAAO,qBAAqB,CAAA;iBAC7B;gBACD,UAAU,CAAC,QAAQ;oBACjB,qBAAqB,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,CAC9C,CACE,mBAA4C,EAC5C,WAAkC,EAClC,KAAa,EACb,EAAE;wBACF,uFAAuF;wBACvF,IAAI,WAAW,CAAC,mBAAmB,KAAK,OAAO,CAAC,EAAE,EAAE;4BAClD,mBAAmB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;yBACtC;wBACD,IAAI,KAAK,KAAK,WAAW,EAAE;4BACzB,mBAAmB,CAAC,IAAI,CAAC,GAAG,eAAe,CAAC,CAAA;yBAC7C;wBACD,OAAO,mBAAmB,CAAA;oBAC5B,CAAC,EACD,EAAE,CACH,CAAA;aACJ;YAED,MAAM,UAAU,GAAG,mBAAmB,CAAC,UAAU,CAAC,QAAQ,EAAE;gBAC1D,GAAG,qBAAqB,CAAC,UAAU;gBACnC,GAAG,gBAAgB;aACpB,CAAC,CAAA;YACF,OAAO;gBACL,UAAU;gBACV,UAAU;gBACV,kBAAkB,EAAE,qBAAqB,CAAC,kBAAkB;gBAC5D,eAAe,EAAE,qBAAqB,CAAC,eAAe;aACvD,CAAA;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,EACD,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAC5B,CAAA;IAED,OAAO;QACL,uBAAuB;KACxB,CAAA;AACH,CAAC","sourcesContent":["import * as React from 'react'\nimport { formElementsService } from '@oneblink/sdk-core'\n\nimport generateDefaultData from '../services/generate-default-data'\nimport { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport { SetFormSubmission } from '../types/form'\n\nexport default function useLookups(\n formId: number,\n setFormSubmission: SetFormSubmission,\n) {\n const handlePagesLookupResult = React.useCallback(\n (\n element: FormTypes.LookupFormElement,\n elementLookupData: FormTypes.PageElement[],\n dataLookupResult?: SubmissionTypes.S3SubmissionData['submission'],\n ) => {\n const newPageElements = elementLookupData.map((e) => ({\n ...e,\n injectedByElementId: element.id,\n }))\n setFormSubmission((currentFormSubmission) => {\n const definition: FormTypes.Form = {\n ...currentFormSubmission.definition,\n isMultiPage: true,\n }\n if (!currentFormSubmission.definition.isMultiPage) {\n definition.elements = [\n {\n id: formId.toString(),\n type: 'page',\n label: 'Page 1',\n elements: currentFormSubmission.definition.elements,\n conditionallyShow: false,\n requiresAllConditionallyShowPredicates: false,\n },\n ...newPageElements,\n ]\n } else {\n const indexOfPage =\n currentFormSubmission.definition.elements.findIndex(\n (pageElement: FormTypes.FormElement) => {\n if (pageElement.type === 'page') {\n return formElementsService.findFormElement(\n pageElement.elements,\n (el) => el.id === element.id,\n )\n }\n },\n )\n if (indexOfPage === -1) {\n return currentFormSubmission\n }\n definition.elements =\n currentFormSubmission.definition.elements.reduce(\n (\n partialPageElements: FormTypes.FormElement[],\n pageElement: FormTypes.FormElement,\n index: number,\n ) => {\n // @ts-expect-error Sorry typescript, we need to add a property you don't approve of :(\n if (pageElement.injectedByElementId !== element.id) {\n partialPageElements.push(pageElement)\n }\n if (index === indexOfPage) {\n partialPageElements.push(...newPageElements)\n }\n return partialPageElements\n },\n [],\n )\n }\n\n const submission = generateDefaultData(definition.elements, {\n ...currentFormSubmission.submission,\n ...dataLookupResult,\n })\n return {\n submission,\n definition,\n lastElementUpdated: currentFormSubmission.lastElementUpdated,\n executedLookups: currentFormSubmission.executedLookups,\n }\n })\n },\n [formId, setFormSubmission],\n )\n\n return {\n handlePagesLookupResult,\n }\n}\n"]}
@@ -1,3 +1,5 @@
1
1
  import { FormTypes } from '@oneblink/types';
2
- declare const useToggleComplianceChildren: (element: FormTypes.ComplianceElement, initialState: boolean, onToggleOff: (element: FormTypes.ComplianceElement, newValue: undefined) => void) => [isShowing: boolean, handleToggle: () => void];
2
+ declare const useToggleComplianceChildren: (element: FormTypes.ComplianceElement, initialState: boolean, onToggleOff: (element: FormTypes.ComplianceElement, options: {
3
+ value: undefined;
4
+ }) => void) => [isShowing: boolean, handleToggle: () => void];
3
5
  export default useToggleComplianceChildren;
@@ -4,7 +4,7 @@ const useToggleComplianceChildren = (element, initialState, onToggleOff) => {
4
4
  const [isShowing, , , toggleIsShowing] = useBooleanState(initialState);
5
5
  const handleToggle = React.useCallback(() => {
6
6
  if (isShowing) {
7
- onToggleOff(element, undefined);
7
+ onToggleOff(element, { value: undefined });
8
8
  }
9
9
  toggleIsShowing();
10
10
  }, [element, isShowing, onToggleOff, toggleIsShowing]);
@@ -1 +1 @@
1
- {"version":3,"file":"useToggleComplianceChildren.js","sourceRoot":"","sources":["../../src/hooks/useToggleComplianceChildren.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,eAAe,MAAM,0BAA0B,CAAA;AACtD,MAAM,2BAA2B,GAAG,CAClC,OAAoC,EACpC,YAAqB,EACrB,WAGS,EACuC,EAAE;IAClD,MAAM,CAAC,SAAS,EAAE,AAAD,EAAG,AAAD,EAAG,eAAe,CAAC,GAAG,eAAe,CAAC,YAAY,CAAC,CAAA;IAEtE,MAAM,YAAY,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE;QAC1C,IAAI,SAAS,EAAE;YACb,WAAW,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;SAChC;QACD,eAAe,EAAE,CAAA;IACnB,CAAC,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC,CAAA;IAEtD,OAAO,CAAC,SAAS,EAAE,YAAY,CAAC,CAAA;AAClC,CAAC,CAAA;AAED,eAAe,2BAA2B,CAAA","sourcesContent":["import { FormTypes } from '@oneblink/types'\nimport * as React from 'react'\nimport useBooleanState from '../hooks/useBooleanState'\nconst useToggleComplianceChildren = (\n element: FormTypes.ComplianceElement,\n initialState: boolean,\n onToggleOff: (\n element: FormTypes.ComplianceElement,\n newValue: undefined,\n ) => void,\n): [isShowing: boolean, handleToggle: () => void] => {\n const [isShowing, , , toggleIsShowing] = useBooleanState(initialState)\n\n const handleToggle = React.useCallback(() => {\n if (isShowing) {\n onToggleOff(element, undefined)\n }\n toggleIsShowing()\n }, [element, isShowing, onToggleOff, toggleIsShowing])\n\n return [isShowing, handleToggle]\n}\n\nexport default useToggleComplianceChildren\n"]}
1
+ {"version":3,"file":"useToggleComplianceChildren.js","sourceRoot":"","sources":["../../src/hooks/useToggleComplianceChildren.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,eAAe,MAAM,0BAA0B,CAAA;AACtD,MAAM,2BAA2B,GAAG,CAClC,OAAoC,EACpC,YAAqB,EACrB,WAGS,EACuC,EAAE;IAClD,MAAM,CAAC,SAAS,EAAE,AAAD,EAAG,AAAD,EAAG,eAAe,CAAC,GAAG,eAAe,CAAC,YAAY,CAAC,CAAA;IAEtE,MAAM,YAAY,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE;QAC1C,IAAI,SAAS,EAAE;YACb,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAA;SAC3C;QACD,eAAe,EAAE,CAAA;IACnB,CAAC,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC,CAAA;IAEtD,OAAO,CAAC,SAAS,EAAE,YAAY,CAAC,CAAA;AAClC,CAAC,CAAA;AAED,eAAe,2BAA2B,CAAA","sourcesContent":["import { FormTypes } from '@oneblink/types'\nimport * as React from 'react'\nimport useBooleanState from '../hooks/useBooleanState'\nconst useToggleComplianceChildren = (\n element: FormTypes.ComplianceElement,\n initialState: boolean,\n onToggleOff: (\n element: FormTypes.ComplianceElement,\n options: { value: undefined },\n ) => void,\n): [isShowing: boolean, handleToggle: () => void] => {\n const [isShowing, , , toggleIsShowing] = useBooleanState(initialState)\n\n const handleToggle = React.useCallback(() => {\n if (isShowing) {\n onToggleOff(element, { value: undefined })\n }\n toggleIsShowing()\n }, [element, isShowing, onToggleOff, toggleIsShowing])\n\n return [isShowing, handleToggle]\n}\n\nexport default useToggleComplianceChildren\n"]}
@@ -1,9 +1,9 @@
1
1
  import { FormTypes, SubmissionTypes } from '@oneblink/types';
2
- import { FormElementsConditionallyShown, FormElementsValidation } from '../types/form';
2
+ import { ExecutedLookupValue, FormElementsConditionallyShown, FormElementsValidation } from '../types/form';
3
3
  export declare const lookupValidationMessage = "Lookup is required";
4
4
  type ValidateJSSchema = Record<string, unknown>;
5
- export declare function generateValidationSchema(elements: FormTypes.FormElementWithName[], elementIdsWithLookupsExecuted: string[]): ValidateJSSchema;
6
- export declare function validateSubmission(schema: ValidateJSSchema, submission: SubmissionTypes.S3SubmissionData['submission'] | undefined, formElementsConditionallyShown: FormElementsConditionallyShown | undefined): FormElementsValidation | undefined;
5
+ export declare function generateValidationSchema(elements: FormTypes.FormElementWithName[]): ValidateJSSchema;
6
+ export declare function validateSubmission(schema: ValidateJSSchema, submission: SubmissionTypes.S3SubmissionData['submission'] | undefined, formElementsConditionallyShown: FormElementsConditionallyShown | undefined, executedLookups: ExecutedLookupValue): FormElementsValidation | undefined;
7
7
  export declare function checkFileNameIsValid(formElement: FormTypes.FilesElement, fileName: string): boolean;
8
8
  export declare function checkFileNameExtensionIsValid(formElement: FormTypes.FilesElement, fileName: string): boolean;
9
9
  export declare function checkSectionValidity(element: FormTypes.PageElement | FormTypes.SectionElement, formElementsValidation: FormElementsValidation | undefined): boolean;
@@ -22,12 +22,12 @@ validate.extend(validate.validators.datetime, {
22
22
  return options.format(dateValue);
23
23
  },
24
24
  });
25
- validate.validators.entries = function (value, { setSchema, entrySchema: { schema: entrySchema, formElementConditionallyShown }, }) {
25
+ validate.validators.entries = function (value, { setSchema, entrySchema: { schema: entrySchema, formElementConditionallyShown, executedLookups, }, }) {
26
26
  const entries = Array.isArray(value) ? value : [];
27
27
  const entryErrors = entries.reduce((errorsByIndex, entry, index) => {
28
28
  const entryValidation = validateSubmission(entrySchema, entry, (formElementConditionallyShown === null || formElementConditionallyShown === void 0 ? void 0 : formElementConditionallyShown.type) === 'repeatableSet'
29
29
  ? formElementConditionallyShown.entries[index.toString()]
30
- : undefined);
30
+ : undefined, Array.isArray(executedLookups) ? executedLookups[index] : {});
31
31
  if (entryValidation) {
32
32
  errorsByIndex[index] = entryValidation;
33
33
  }
@@ -43,10 +43,10 @@ validate.validators.entries = function (value, { setSchema, entrySchema: { schem
43
43
  entries: entryErrors,
44
44
  };
45
45
  };
46
- validate.validators.nestedElements = function (value, { schema, formElementConditionallyShown }) {
46
+ validate.validators.nestedElements = function (value, { schema, formElementConditionallyShown, executedLookups, }) {
47
47
  const errors = validateSubmission(schema, value, (formElementConditionallyShown === null || formElementConditionallyShown === void 0 ? void 0 : formElementConditionallyShown.type) === 'formElements'
48
48
  ? formElementConditionallyShown.formElements
49
- : undefined);
49
+ : undefined, typeof executedLookups !== 'boolean' ? executedLookups : {});
50
50
  if (!errors) {
51
51
  return;
52
52
  }
@@ -87,7 +87,7 @@ validate.validators.attachments = function (value) {
87
87
  return validateAttachments(value === null || value === void 0 ? void 0 : value.files);
88
88
  };
89
89
  // Extend validator for lookups
90
- validate.validators.lookups = function (value, { elementIdsWithLookupsExecuted, formElement, }) {
90
+ validate.validators.lookups = function (value, { executedLookups, formElement, }) {
91
91
  if (!formElement.isDataLookup && !formElement.isElementLookup) {
92
92
  return;
93
93
  }
@@ -95,7 +95,8 @@ validate.validators.lookups = function (value, { elementIdsWithLookupsExecuted,
95
95
  if (formElement && !formElement.required) {
96
96
  return;
97
97
  }
98
- if (elementIdsWithLookupsExecuted.includes(formElement.id)) {
98
+ const elementExecutedLookups = executedLookups === null || executedLookups === void 0 ? void 0 : executedLookups[formElement.name];
99
+ if (elementExecutedLookups === true) {
99
100
  return;
100
101
  }
101
102
  return lookupValidationMessage;
@@ -150,7 +151,7 @@ function getCleanRepeatableSetConfiguration(setEntries, elements, submission, fo
150
151
  return getRepeatableSetEntriesConfiguration(setEntries, elements, model);
151
152
  }
152
153
  }
153
- export function generateValidationSchema(elements, elementIdsWithLookupsExecuted) {
154
+ export function generateValidationSchema(elements) {
154
155
  return elements.reduce((partialSchema, formElement) => {
155
156
  switch (formElement.type) {
156
157
  // Elements that do not need to be validated
@@ -162,7 +163,7 @@ export function generateValidationSchema(elements, elementIdsWithLookupsExecuted
162
163
  return partialSchema;
163
164
  }
164
165
  }
165
- const constraint = (value, submission, propertyName, { formElementsConditionallyShown }) => {
166
+ const constraint = (value, submission, propertyName, { formElementsConditionallyShown, executedLookups }) => {
166
167
  var _a;
167
168
  // If the element is current hidden, we do not need to apply validation
168
169
  const formElementConditionallyShown = formElementsConditionallyShown === null || formElementsConditionallyShown === void 0 ? void 0 : formElementsConditionallyShown[formElement.name];
@@ -192,7 +193,7 @@ export function generateValidationSchema(elements, elementIdsWithLookupsExecuted
192
193
  presence: presence(formElement, 'Please select a location'),
193
194
  lookups: {
194
195
  formElement,
195
- elementIdsWithLookupsExecuted,
196
+ executedLookups,
196
197
  },
197
198
  };
198
199
  }
@@ -201,7 +202,7 @@ export function generateValidationSchema(elements, elementIdsWithLookupsExecuted
201
202
  presence: presence(formElement, 'Required'),
202
203
  lookups: {
203
204
  formElement,
204
- elementIdsWithLookupsExecuted,
205
+ executedLookups,
205
206
  },
206
207
  attachments: true,
207
208
  };
@@ -221,7 +222,7 @@ export function generateValidationSchema(elements, elementIdsWithLookupsExecuted
221
222
  : undefined,
222
223
  lookups: {
223
224
  formElement,
224
- elementIdsWithLookupsExecuted,
225
+ executedLookups,
225
226
  },
226
227
  };
227
228
  }
@@ -236,7 +237,7 @@ export function generateValidationSchema(elements, elementIdsWithLookupsExecuted
236
237
  presence: presence(formElement, 'Required'),
237
238
  lookups: {
238
239
  formElement,
239
- elementIdsWithLookupsExecuted,
240
+ executedLookups,
240
241
  },
241
242
  };
242
243
  }
@@ -245,7 +246,7 @@ export function generateValidationSchema(elements, elementIdsWithLookupsExecuted
245
246
  isTrue: formElement.required && 'Required',
246
247
  lookups: {
247
248
  formElement,
248
- elementIdsWithLookupsExecuted,
249
+ executedLookups,
249
250
  },
250
251
  };
251
252
  }
@@ -254,7 +255,7 @@ export function generateValidationSchema(elements, elementIdsWithLookupsExecuted
254
255
  presence: presence(formElement, 'Please enter a BSB number'),
255
256
  lookups: {
256
257
  formElement,
257
- elementIdsWithLookupsExecuted,
258
+ executedLookups,
258
259
  },
259
260
  format: {
260
261
  pattern: /\d{3}-\d{3}/,
@@ -267,7 +268,7 @@ export function generateValidationSchema(elements, elementIdsWithLookupsExecuted
267
268
  presence: presence(formElement, 'Please scan a barcode or enter a value'),
268
269
  lookups: {
269
270
  formElement,
270
- elementIdsWithLookupsExecuted,
271
+ executedLookups,
271
272
  },
272
273
  format: getCustomRegexFormatConfig(formElement),
273
274
  };
@@ -278,7 +279,7 @@ export function generateValidationSchema(elements, elementIdsWithLookupsExecuted
278
279
  presence: presence(formElement, 'Please enter a value'),
279
280
  lookups: {
280
281
  formElement,
281
- elementIdsWithLookupsExecuted,
282
+ executedLookups,
282
283
  },
283
284
  length: {
284
285
  minimum: formElement.minLength,
@@ -294,7 +295,7 @@ export function generateValidationSchema(elements, elementIdsWithLookupsExecuted
294
295
  presence: presence(formElement, 'Please enter a phone number'),
295
296
  lookups: {
296
297
  formElement,
297
- elementIdsWithLookupsExecuted,
298
+ executedLookups,
298
299
  },
299
300
  format: getCustomRegexFormatConfig(formElement),
300
301
  };
@@ -307,7 +308,7 @@ export function generateValidationSchema(elements, elementIdsWithLookupsExecuted
307
308
  },
308
309
  lookups: {
309
310
  formElement,
310
- elementIdsWithLookupsExecuted,
311
+ executedLookups,
311
312
  },
312
313
  format: getCustomRegexFormatConfig(formElement),
313
314
  };
@@ -317,7 +318,7 @@ export function generateValidationSchema(elements, elementIdsWithLookupsExecuted
317
318
  presence: presence(formElement, 'Please select a time'),
318
319
  lookups: {
319
320
  formElement,
320
- elementIdsWithLookupsExecuted,
321
+ executedLookups,
321
322
  },
322
323
  };
323
324
  }
@@ -352,7 +353,7 @@ export function generateValidationSchema(elements, elementIdsWithLookupsExecuted
352
353
  },
353
354
  lookups: {
354
355
  formElement,
355
- elementIdsWithLookupsExecuted,
356
+ executedLookups,
356
357
  },
357
358
  };
358
359
  }
@@ -387,7 +388,7 @@ export function generateValidationSchema(elements, elementIdsWithLookupsExecuted
387
388
  },
388
389
  lookups: {
389
390
  formElement,
390
- elementIdsWithLookupsExecuted,
391
+ executedLookups,
391
392
  },
392
393
  };
393
394
  }
@@ -412,7 +413,7 @@ export function generateValidationSchema(elements, elementIdsWithLookupsExecuted
412
413
  },
413
414
  lookups: {
414
415
  formElement,
415
- elementIdsWithLookupsExecuted,
416
+ executedLookups,
416
417
  },
417
418
  numberRegex: getCustomRegexFormatConfig(formElement),
418
419
  };
@@ -446,6 +447,12 @@ export function generateValidationSchema(elements, elementIdsWithLookupsExecuted
446
447
  case 'repeatableSet': {
447
448
  const minSetEntries = getCleanRepeatableSetConfiguration(formElement.minSetEntries, elements, submission, formElementsConditionallyShown);
448
449
  const maxSetEntries = getCleanRepeatableSetConfiguration(formElement.maxSetEntries, elements, submission, formElementsConditionallyShown);
450
+ const repeatableSetExecutedLookups = executedLookups !== undefined &&
451
+ typeof executedLookups !== 'boolean' &&
452
+ !Array.isArray(executedLookups) &&
453
+ Array.isArray(executedLookups[formElement.name])
454
+ ? executedLookups[formElement.name]
455
+ : [];
449
456
  return {
450
457
  entries: {
451
458
  setSchema: {
@@ -462,28 +469,41 @@ export function generateValidationSchema(elements, elementIdsWithLookupsExecuted
462
469
  },
463
470
  },
464
471
  entrySchema: {
465
- schema: generateValidationSchema(formElement.elements, elementIdsWithLookupsExecuted),
472
+ schema: generateValidationSchema(formElement.elements),
466
473
  formElementConditionallyShown: formElementsConditionallyShown === null || formElementsConditionallyShown === void 0 ? void 0 : formElementsConditionallyShown[formElement.name],
474
+ executedLookups: repeatableSetExecutedLookups,
467
475
  },
468
476
  },
469
477
  };
470
478
  }
471
479
  case 'civicaNameRecord': {
472
480
  const nestedElements = generateCivicaNameRecordElements(formElement, []);
481
+ const nestedExecutedLookups = executedLookups !== undefined &&
482
+ typeof executedLookups !== 'boolean' &&
483
+ !Array.isArray(executedLookups)
484
+ ? executedLookups[formElement.name]
485
+ : {};
473
486
  return {
474
487
  nestedElements: {
475
- schema: generateValidationSchema(nestedElements, elementIdsWithLookupsExecuted),
488
+ schema: generateValidationSchema(nestedElements),
476
489
  formElementConditionallyShown: formElementsConditionallyShown === null || formElementsConditionallyShown === void 0 ? void 0 : formElementsConditionallyShown[formElement.name],
490
+ executedLookups: nestedExecutedLookups,
477
491
  },
478
492
  };
479
493
  }
480
494
  case 'infoPage':
481
495
  case 'form': {
482
496
  if (formElement.elements) {
497
+ const nestedExecutedLookups = executedLookups !== undefined &&
498
+ typeof executedLookups !== 'boolean' &&
499
+ !Array.isArray(executedLookups)
500
+ ? executedLookups[formElement.name]
501
+ : {};
483
502
  return {
484
503
  nestedElements: {
485
- schema: generateValidationSchema(formElement.elements, elementIdsWithLookupsExecuted),
504
+ schema: generateValidationSchema(formElement.elements),
486
505
  formElementConditionallyShown: formElementsConditionallyShown === null || formElementsConditionallyShown === void 0 ? void 0 : formElementsConditionallyShown[formElement.name],
506
+ executedLookups: nestedExecutedLookups,
487
507
  },
488
508
  };
489
509
  }
@@ -491,10 +511,16 @@ export function generateValidationSchema(elements, elementIdsWithLookupsExecuted
491
511
  }
492
512
  case 'freshdeskDependentField': {
493
513
  const nestedElements = generateFreshdeskDependentFieldElements(formElement);
514
+ const nestedExecutedLookups = executedLookups !== undefined &&
515
+ typeof executedLookups !== 'boolean' &&
516
+ !Array.isArray(executedLookups)
517
+ ? executedLookups[formElement.name]
518
+ : {};
494
519
  return {
495
520
  nestedElements: {
496
- schema: generateValidationSchema(nestedElements, elementIdsWithLookupsExecuted),
521
+ schema: generateValidationSchema(nestedElements),
497
522
  formElementConditionallyShown: formElementsConditionallyShown === null || formElementsConditionallyShown === void 0 ? void 0 : formElementsConditionallyShown[formElement.name],
523
+ executedLookups: nestedExecutedLookups,
498
524
  },
499
525
  };
500
526
  }
@@ -507,11 +533,12 @@ export function generateValidationSchema(elements, elementIdsWithLookupsExecuted
507
533
  return partialSchema;
508
534
  }, {});
509
535
  }
510
- export function validateSubmission(schema, submission, formElementsConditionallyShown) {
536
+ export function validateSubmission(schema, submission, formElementsConditionallyShown, executedLookups) {
511
537
  const errorsAsArray = validate(submission, schema, {
512
538
  format: 'grouped',
513
539
  fullMessages: false,
514
540
  formElementsConditionallyShown,
541
+ executedLookups,
515
542
  });
516
543
  if (!errorsAsArray || validate.isEmpty(errorsAsArray)) {
517
544
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"form-validation.js","sourceRoot":"","sources":["../../src/services/form-validation.ts"],"names":[],"mappings":"AAAA,OAAO,QAAmC,MAAM,aAAa,CAAA;AAC7D,OAAO,EAAsB,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAIxE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,gCAAgC,MAAM,oCAAoC,CAAA;AAMjF,OAAO,uCAAuC,MAAM,2CAA2C,CAAA;AAC/F,OAAO,wBAAwB,MAAM,4BAA4B,CAAA;AACjE,OAAO,yBAEN,MAAM,6BAA6B,CAAA;AACpC,OAAO,oCAAoC,MAAM,wCAAwC,CAAA;AAOzF,MAAM,CAAC,MAAM,uBAAuB,GAAG,oBAAoB,CAAA;AAC3D,8CAA8C;AAC9C,6DAA6D;AAC7D,kDAAkD;AAClD,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,QAAQ,EAAE;IAC5C,uEAAuE;IACvE,qBAAqB;IACrB,KAAK,EAAE,UAAU,KAAa;QAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IAC1B,CAAC;IACD,4BAA4B;IAC5B,MAAM,EAAE,UACN,KAAa,EACb,OAA2C;QAE3C,MAAM,SAAS,GAAG,I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n } from 'validate.js'\nimport { attachmentsService, localisationService } from '@oneblink/apps'\nimport { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport { FormElementBinaryStorageValue } from '../types/attachments'\nimport { Value as FormElementComplianceValue } from '../form-elements/FormElementCompliance'\nimport { parseDateValue } from './generate-default-data'\nimport generateCivicaNameRecordElements from './generateCivicaNameRecordElements'\nimport {\n FormElementConditionallyShown,\n FormElementsConditionallyShown,\n FormElementsValidation,\n} from '../types/form'\nimport generateFreshdeskDependentFieldElements from './generateFreshdeskDependentFieldElements'\nimport cleanFormSubmissionModel from './cleanFormSubmissionModel'\nimport getDateRangeConfiguration, {\n DateRangeConfigurationOptions,\n} from './getDateRangeConfiguration'\nimport getRepeatableSetEntriesConfiguration from './getRepeatableSetEntriesConfiguration'\n\ntype NestedValidateJSSchema = {\n schema: ValidateJSSchema\n formElementConditionallyShown: FormElementConditionallyShown | undefined\n}\n\nexport const lookupValidationMessage = 'Lookup is required'\n// https://validatejs.org/#validators-datetime\n// Before using it we must add the parse and format functions\n// Here is a sample implementation using moment.js\nvalidate.extend(validate.validators.datetime, {\n // The value is guaranteed not to be null or undefined but otherwise it\n // could be anything.\n parse: function (value: string) {\n return Date.parse(value)\n },\n // Input is a unix timestamp\n format: function (\n value: string,\n options: { format: (date: Date) => string },\n ) {\n const dateValue = new Date(value)\n return options.format(dateValue)\n },\n})\n\nvalidate.validators.entries = function (\n value: unknown,\n {\n setSchema,\n entrySchema: { schema: entrySchema, formElementConditionallyShown },\n }: {\n setSchema: ValidateJSSchema\n entrySchema: NestedValidateJSSchema\n },\n) {\n const entries = Array.isArray(value) ? value : []\n\n const entryErrors = entries.reduce((errorsByIndex, entry, index) => {\n const entryValidation = validateSubmission(\n entrySchema,\n entry,\n formElementConditionallyShown?.type === 'repeatableSet'\n ? formElementConditionallyShown.entries[index.toString()]\n : undefined,\n )\n if (entryValidation) {\n errorsByIndex[index] = entryValidation\n }\n return errorsByIndex\n }, {})\n\n const setErrorMessages = validate.single(value, setSchema)\n\n if (!setErrorMessages && validate.isEmpty(entryErrors)) {\n return\n }\n\n return {\n type: 'repeatableSet',\n set: setErrorMessages && setErrorMessages[0],\n entries: entryErrors,\n }\n}\n\nvalidate.validators.nestedElements = function (\n value: SubmissionTypes.S3SubmissionData['submission'] | undefined,\n { schema, formElementConditionallyShown }: NestedValidateJSSchema,\n) {\n const errors = validateSubmission(\n schema,\n value,\n formElementConditionallyShown?.type === 'formElements'\n ? formElementConditionallyShown.formElements\n : undefined,\n )\n if (!errors) {\n return\n }\n return {\n type: 'formElements',\n formElements: errors,\n }\n}\n\nfunction getInvalidAttachment(value: FormElementBinaryStorageValue) {\n if (\n value &&\n typeof value === 'object' &&\n value.type &&\n value.type === 'ERROR'\n ) {\n return value\n }\n}\nfunction validateAttachments(\n value: FormElementBinaryStorageValue[] | undefined,\n) {\n const invalidAttachmentNames = value?.reduce(\n (invalidAttachmentNames: string[], att) => {\n const attachmentName = getInvalidAttachment(att)?.fileName\n if (attachmentName) {\n invalidAttachmentNames.push(attachmentName)\n }\n return invalidAttachmentNames\n },\n [],\n )\n if (invalidAttachmentNames?.length) {\n return `${invalidAttachmentNames.join(', ')} could not be uploaded.`\n }\n}\nvalidate.validators.attachment = function (\n value: FormElementBinaryStorageValue,\n) {\n return getInvalidAttachment(value)?.errorMessage\n}\nvalidate.validators.attachments = function (\n value:\n | FormElementBinaryStorageValue[]\n | FormElementComplianceValue\n | undefined,\n) {\n if (Array.isArray(value)) {\n return validateAttachments(value)\n }\n return validateAttachments(\n value?.files as FormElementBinaryStorageValue[] | undefined,\n )\n}\n\n// Extend validator for lookups\nvalidate.validators.lookups = function (\n value: unknown,\n {\n elementIdsWithLookupsExecuted,\n formElement,\n }: {\n formElement: FormTypes.LookupFormElement & FormTypes.FormElementRequired\n elementIdsWithLookupsExecuted: string[]\n },\n) {\n if (!formElement.isDataLookup && !formElement.isElementLookup) {\n return\n }\n\n // Lookups must only be executed on required form elements\n if (formElement && !formElement.required) {\n return\n }\n\n if (elementIdsWithLookupsExecuted.includes(formElement.id)) {\n return\n }\n\n return lookupValidationMessage\n}\n\nvalidate.validators.numberRegex = function (value: unknown, format: unknown) {\n if (!format) {\n return\n }\n if (typeof value === 'number' && !Number.isNaN(value)) {\n value = value.toString()\n }\n const errorMessages = validate.single(value, { format })\n return errorMessages && errorMessages[0]\n}\n\nvalidate.validators.isTrue = function (value: unknown, message?: string) {\n if (!value) {\n return message || 'Must be set to true'\n }\n}\n\nvalidate.validators.needsExtension = function (\n value: attachmentsService.Attachment[] | undefined,\n formElement: FormTypes.FilesElement,\n) {\n const isValid =\n !Array.isArray(value) ||\n value.every((file) => {\n return checkFileNameExtensionIsValid(formElement, file.fileName)\n })\n if (!isValid) return 'All files must have extensions'\n}\n\nfunction getCustomRegexFormatConfig<DefaultValue>(\n formElement: FormTypes.FormElementWithInput<DefaultValue>,\n) {\n return formElement.regexPattern\n ? {\n pattern: formElement.regexPattern,\n flags: formElement.regexFlags,\n message: formElement.regexMessage,\n }\n : undefined\n}\n\ntype ValidateJSSchema = Record<string, unknown>\n\nconst presence = (\n { required, requiredMessage }: FormTypes.FormElementRequired,\n message: string,\n) => (required ? { message: requiredMessage || message } : false)\n\nconst escapeElementName = (elementName: string) => {\n const escapedName = elementName.replace(/\\./g, '\\\\.')\n return escapedName\n}\n\nfunction getCleanDateRangeConfiguration(\n options: DateRangeConfigurationOptions,\n elements: FormTypes.FormElement[],\n submission: SubmissionTypes.S3SubmissionData['submission'] | undefined,\n formElementsConditionallyShown: FormElementsConditionallyShown | undefined,\n): ReturnType<typeof getDateRangeConfiguration> {\n if (options.referenceFormElementId && submission) {\n const { model } = cleanFormSubmissionModel(\n submission,\n elements,\n formElementsConditionallyShown,\n true,\n )\n return getDateRangeConfiguration(options, elements, model)\n }\n return [options.date, options.daysOffset]\n}\n\nfunction getCleanRepeatableSetConfiguration(\n setEntries: FormTypes.RepeatableSetElement['minSetEntries'],\n elements: FormTypes.FormElement[],\n submission: SubmissionTypes.S3SubmissionData['submission'] | undefined,\n formElementsConditionallyShown: FormElementsConditionallyShown | undefined,\n) {\n if (submission) {\n const { model } = cleanFormSubmissionModel(\n submission,\n elements,\n formElementsConditionallyShown,\n true,\n )\n return getRepeatableSetEntriesConfiguration(setEntries, elements, model)\n }\n}\n\nexport function generateValidationSchema(\n elements: FormTypes.FormElementWithName[],\n elementIdsWithLookupsExecuted: string[],\n): ValidateJSSchema {\n return elements.reduce<ValidateJSSchema>((partialSchema, formElement) => {\n switch (formElement.type) {\n // Elements that do not need to be validated\n case 'summary':\n case 'calculation':\n case 'image':\n case 'html':\n case 'heading': {\n return partialSchema\n }\n }\n\n const constraint: ValidatorConstraintFn<\n SubmissionTypes.S3SubmissionData['submission']\n > = (\n value,\n submission,\n propertyName,\n { formElementsConditionallyShown },\n ) => {\n // If the element is current hidden, we do not need to apply validation\n const formElementConditionallyShown =\n formElementsConditionallyShown?.[formElement.name]\n if (formElementConditionallyShown?.isHidden) {\n return\n }\n\n switch (formElement.type) {\n case 'draw': {\n return {\n attachment: true,\n presence: presence(formElement, 'A saved signature is required'),\n }\n }\n case 'camera': {\n return {\n attachment: true,\n presence: presence(formElement, 'A photo is required'),\n }\n }\n case 'captcha': {\n return {\n presence: presence(\n { ...formElement, required: true },\n 'Please complete the CAPTCHA successfully',\n ),\n }\n }\n case 'location': {\n return {\n presence: presence(formElement, 'Please select a location'),\n lookups: {\n formElement,\n elementIdsWithLookupsExecuted,\n },\n }\n }\n case 'compliance': {\n return {\n presence: presence(formElement, 'Required'),\n lookups: {\n formElement,\n elementIdsWithLookupsExecuted,\n },\n attachments: true,\n }\n }\n case 'checkboxes': {\n const requiredAllDefaultMessage = 'All options are required'\n return {\n presence: presence(\n {\n ...formElement,\n required: formElement.required || !!formElement.requiredAll,\n },\n formElement.requiredAll ? requiredAllDefaultMessage : 'Required',\n ),\n length: formElement.requiredAll\n ? {\n is: formElement.options?.length,\n message:\n formElement.requiredMessage || requiredAllDefaultMessage,\n }\n : undefined,\n lookups: {\n formElement,\n elementIdsWithLookupsExecuted,\n },\n }\n }\n case 'abn':\n case 'geoscapeAddress':\n case 'pointAddress':\n case 'civicaStreetName':\n case 'autocomplete':\n case 'radio':\n case 'select': {\n return {\n presence: presence(formElement, 'Required'),\n lookups: {\n formElement,\n elementIdsWithLookupsExecuted,\n },\n }\n }\n case 'boolean': {\n return {\n isTrue: formElement.required && 'Required',\n lookups: {\n formElement,\n elementIdsWithLookupsExecuted,\n },\n }\n }\n case 'bsb': {\n return {\n presence: presence(formElement, 'Please enter a BSB number'),\n lookups: {\n formElement,\n elementIdsWithLookupsExecuted,\n },\n format: {\n pattern: /\\d{3}-\\d{3}/,\n message: 'Please enter a valid BSB number',\n },\n }\n }\n case 'barcodeScanner': {\n return {\n presence: presence(\n formElement,\n 'Please scan a barcode or enter a value',\n ),\n lookups: {\n formElement,\n elementIdsWithLookupsExecuted,\n },\n format: getCustomRegexFormatConfig(formElement),\n }\n }\n case 'text':\n case 'textarea': {\n return {\n presence: presence(formElement, 'Please enter a value'),\n lookups: {\n formElement,\n elementIdsWithLookupsExecuted,\n },\n length: {\n minimum: formElement.minLength,\n tooShort:\n 'Please enter a value with at least %{count} character(s)',\n maximum: formElement.maxLength,\n tooLong:\n 'Please enter a value with %{count} character(s) or less',\n },\n format: getCustomRegexFormatConfig(formElement),\n }\n }\n case 'telephone': {\n return {\n presence: presence(formElement, 'Please enter a phone number'),\n lookups: {\n formElement,\n elementIdsWithLookupsExecuted,\n },\n format: getCustomRegexFormatConfig(formElement),\n }\n }\n case 'email': {\n return {\n presence: presence(formElement, 'Please enter an email address'),\n email: {\n message: 'Please enter a valid email for this field',\n },\n lookups: {\n formElement,\n elementIdsWithLookupsExecuted,\n },\n format: getCustomRegexFormatConfig(formElement),\n }\n }\n case 'time': {\n return {\n presence: presence(formElement, 'Please select a time'),\n lookups: {\n formElement,\n elementIdsWithLookupsExecuted,\n },\n }\n }\n case 'date': {\n const [fromDate, fromDateDaysOffset] = getCleanDateRangeConfiguration(\n {\n date: formElement.fromDate,\n daysOffset: formElement.fromDateDaysOffset,\n referenceFormElementId: formElement.fromDateElementId,\n },\n elements,\n submission,\n formElementsConditionallyShown,\n )\n const [toDate, toDateDaysOffset] = getCleanDateRangeConfiguration(\n {\n date: formElement.toDate,\n daysOffset: formElement.toDateDaysOffset,\n referenceFormElementId: formElement.toDateElementId,\n },\n elements,\n submission,\n formElementsConditionallyShown,\n )\n return {\n presence: presence(formElement, 'Please select a date'),\n date: {\n format: (v: Date) => localisationService.formatDate(v),\n earliest: parseDateValue({\n dateOnly: true,\n daysOffset: fromDateDaysOffset,\n value: fromDate,\n }),\n latest: parseDateValue({\n dateOnly: true,\n daysOffset: toDateDaysOffset,\n value: toDate,\n }),\n notValid: 'Please select a valid date',\n tooEarly: 'Date cannot be before %{date}',\n tooLate: 'Date cannot be after %{date}',\n },\n lookups: {\n formElement,\n elementIdsWithLookupsExecuted,\n },\n }\n }\n case 'datetime': {\n const [fromDate, fromDateDaysOffset] = getCleanDateRangeConfiguration(\n {\n date: formElement.fromDate,\n daysOffset: formElement.fromDateDaysOffset,\n referenceFormElementId: formElement.fromDateElementId,\n },\n elements,\n submission,\n formElementsConditionallyShown,\n )\n const [toDate, toDateDaysOffset] = getCleanDateRangeConfiguration(\n {\n date: formElement.toDate,\n daysOffset: formElement.toDateDaysOffset,\n referenceFormElementId: formElement.toDateElementId,\n },\n elements,\n submission,\n formElementsConditionallyShown,\n )\n return {\n presence: presence(formElement, 'Please select a date and time'),\n datetime: {\n format: (v: Date) => localisationService.formatDatetime(v),\n earliest: parseDateValue({\n dateOnly: false,\n daysOffset: fromDateDaysOffset,\n value: fromDate,\n }),\n latest: parseDateValue({\n dateOnly: false,\n daysOffset: toDateDaysOffset,\n value: toDate,\n }),\n notValid: 'Please select a valid date and time',\n tooEarly: 'Date and time cannot be before %{date}',\n tooLate: 'Date and time cannot be after %{date}',\n },\n lookups: {\n formElement,\n elementIdsWithLookupsExecuted,\n },\n }\n }\n case 'number': {\n let minErrorMessage =\n 'Please enter a number greater than or equal to %{count}'\n let maxErrorMessage =\n 'Please enter a number less than or equal to %{count}'\n if (\n typeof formElement.minNumber === 'number' &&\n typeof formElement.maxNumber === 'number'\n ) {\n minErrorMessage =\n maxErrorMessage = `Please enter a number between ${formElement.minNumber} and ${formElement.maxNumber}`\n }\n\n return {\n type: 'number',\n presence: presence(formElement, 'Please enter a number'),\n numericality: {\n greaterThanOrEqualTo: formElement.minNumber,\n notGreaterThanOrEqualTo: minErrorMessage,\n lessThanOrEqualTo: formElement.maxNumber,\n notLessThanOrEqualTo: maxErrorMessage,\n onlyInteger: formElement.isInteger,\n notInteger: 'Please enter a whole number',\n },\n lookups: {\n formElement,\n elementIdsWithLookupsExecuted,\n },\n numberRegex: getCustomRegexFormatConfig(formElement),\n }\n }\n case 'files': {\n return {\n presence: formElement.minEntries\n ? {\n message: `Please upload at least ${\n formElement.minEntries\n } file${formElement.minEntries === 1 ? '' : 's'}`,\n }\n : false,\n length: {\n minimum: formElement.minEntries,\n maximum: formElement.maxEntries,\n tooLong: 'Cannot upload more than %{count} file(s)',\n tooShort: 'Please upload at least %{count} file(s)',\n },\n type: {\n type: (files: attachmentsService.Attachment[] | undefined) => {\n return (\n !Array.isArray(files) ||\n files.every((file) => {\n return checkFileNameIsValid(formElement, file.fileName)\n })\n )\n },\n message: `Only the following file types are accepted: ${(\n formElement.restrictedFileTypes || []\n ).join(', ')}`,\n },\n needsExtension: formElement,\n attachments: true,\n }\n }\n case 'repeatableSet': {\n const minSetEntries = getCleanRepeatableSetConfiguration(\n formElement.minSetEntries,\n elements,\n submission,\n formElementsConditionallyShown,\n )\n const maxSetEntries = getCleanRepeatableSetConfiguration(\n formElement.maxSetEntries,\n elements,\n submission,\n formElementsConditionallyShown,\n )\n return {\n entries: {\n setSchema: {\n presence: minSetEntries\n ? {\n message: `Must have at least ${minSetEntries} ${\n minSetEntries === 1 ? 'entry' : 'entries'\n }`,\n }\n : false,\n length: {\n minimum: minSetEntries,\n maximum: maxSetEntries,\n tooLong: 'Cannot have more than %{count} entry/entries',\n tooShort: 'Must have at least %{count} entry/entries',\n },\n },\n entrySchema: {\n schema: generateValidationSchema(\n formElement.elements as FormTypes.FormElementWithName[],\n elementIdsWithLookupsExecuted,\n ),\n formElementConditionallyShown:\n formElementsConditionallyShown?.[formElement.name],\n },\n },\n }\n }\n case 'civicaNameRecord': {\n const nestedElements = generateCivicaNameRecordElements(\n formElement,\n [],\n )\n return {\n nestedElements: {\n schema: generateValidationSchema(\n nestedElements as FormTypes.FormElementWithName[],\n elementIdsWithLookupsExecuted,\n ),\n formElementConditionallyShown:\n formElementsConditionallyShown?.[formElement.name],\n },\n }\n }\n case 'infoPage':\n case 'form': {\n if (formElement.elements) {\n return {\n nestedElements: {\n schema: generateValidationSchema(\n formElement.elements as FormTypes.FormElementWithName[],\n elementIdsWithLookupsExecuted,\n ),\n formElementConditionallyShown:\n formElementsConditionallyShown?.[formElement.name],\n },\n }\n }\n break\n }\n case 'freshdeskDependentField': {\n const nestedElements =\n generateFreshdeskDependentFieldElements(formElement)\n return {\n nestedElements: {\n schema: generateValidationSchema(\n nestedElements as FormTypes.FormElementWithName[],\n elementIdsWithLookupsExecuted,\n ),\n formElementConditionallyShown:\n formElementsConditionallyShown?.[formElement.name],\n },\n }\n }\n default: {\n console.info('Unsupported form element with validation', formElement)\n }\n }\n }\n partialSchema[escapeElementName(formElement.name)] = constraint\n return partialSchema\n }, {})\n}\n\nexport function validateSubmission(\n schema: ValidateJSSchema,\n submission: SubmissionTypes.S3SubmissionData['submission'] | undefined,\n formElementsConditionallyShown: FormElementsConditionallyShown | undefined,\n): FormElementsValidation | undefined {\n const errorsAsArray = validate(submission, schema, {\n format: 'grouped',\n fullMessages: false,\n formElementsConditionallyShown,\n })\n if (!errorsAsArray || validate.isEmpty(errorsAsArray)) {\n return\n }\n\n const errors = Object.keys(errorsAsArray || {}).reduce(\n (messagesByFormElementName: FormElementsValidation, key) => {\n const validationMessage = errorsAsArray[key][0]\n if (validationMessage) {\n messagesByFormElementName[key.replace(/\\\\./g, '.')] = validationMessage\n }\n return messagesByFormElementName\n },\n {},\n )\n if (validate.isEmpty(errors)) {\n return\n }\n\n return errors\n}\n\nexport function checkFileNameIsValid(\n formElement: FormTypes.FilesElement,\n fileName: string,\n) {\n const extension = fileName.split('.').pop()\n return (\n !formElement.restrictedFileTypes ||\n formElement.restrictedFileTypes.some(\n (fileType) => fileType.toLowerCase() === extension?.toLowerCase(),\n )\n )\n}\n\nexport function checkFileNameExtensionIsValid(\n formElement: FormTypes.FilesElement,\n fileName: string,\n) {\n return (\n formElement.allowExtensionlessAttachments || fileName.split('.').length >= 2\n )\n}\n\nexport function checkSectionValidity(\n element: FormTypes.PageElement | FormTypes.SectionElement,\n formElementsValidation: FormElementsValidation | undefined,\n): boolean {\n // If everything is valid, no need to check elements\n if (!formElementsValidation) {\n return false\n }\n\n // If there is no elements on the page that are invalid, we will treat as valid\n return element.elements.some((formElement) => {\n switch (formElement.type) {\n case 'page':\n case 'section': {\n return checkSectionValidity(formElement, formElementsValidation)\n }\n default: {\n return formElementsValidation[formElement.name]\n }\n }\n })\n}\n"]}
1
+ {"version":3,"file":"form-validation.js","sourceRoot":"","sources":["../../src/services/form-validation.ts"],"names":[],"mappings":"AAAA,OAAO,QAAmC,MAAM,aAAa,CAAA;AAC7D,OAAO,EAAsB,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAIxE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,gCAAgC,MAAM,oCAAoC,CAAA;AAQjF,OAAO,uCAAuC,MAAM,2CAA2C,CAAA;AAC/F,OAAO,wBAAwB,MAAM,4BAA4B,CAAA;AACjE,OAAO,yBAEN,MAAM,6BAA6B,CAAA;AACpC,OAAO,oCAAoC,MAAM,wCAAwC,CAAA;AAQzF,MAAM,CAAC,MAAM,uBAAuB,GAAG,oBAAoB,CAAA;AAC3D,8CAA8C;AAC9C,6DAA6D;AAC7D,kDAAkD;A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,KAAK,MAAM,CAAC;YACZ,KAAK,SAAS,CAAC,CAAC;gBACd,OAAO,oBAAoB,CAAC,WAAW,EAAE,sBAAsB,CAAC,CAAA;aACjE;YACD,OAAO,CAAC,CAAC;gBACP,OAAO,sBAAsB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;aAChD;SACF;IACH,CAAC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import validate, { ValidatorConstraintFn } from 'validate.js'\nimport { attachmentsService, localisationService } from '@oneblink/apps'\nimport { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport { FormElementBinaryStorageValue } from '../types/attachments'\nimport { Value as FormElementComplianceValue } from '../form-elements/FormElementCompliance'\nimport { parseDateValue } from './generate-default-data'\nimport generateCivicaNameRecordElements from './generateCivicaNameRecordElements'\nimport {\n ExecutedLookups,\n ExecutedLookupValue,\n FormElementConditionallyShown,\n FormElementsConditionallyShown,\n FormElementsValidation,\n} from '../types/form'\nimport generateFreshdeskDependentFieldElements from './generateFreshdeskDependentFieldElements'\nimport cleanFormSubmissionModel from './cleanFormSubmissionModel'\nimport getDateRangeConfiguration, {\n DateRangeConfigurationOptions,\n} from './getDateRangeConfiguration'\nimport getRepeatableSetEntriesConfiguration from './getRepeatableSetEntriesConfiguration'\n\ntype NestedValidateJSSchema = {\n schema: ValidateJSSchema\n formElementConditionallyShown: FormElementConditionallyShown | undefined\n executedLookups: ExecutedLookupValue\n}\n\nexport const lookupValidationMessage = 'Lookup is required'\n// https://validatejs.org/#validators-datetime\n// Before using it we must add the parse and format functions\n// Here is a sample implementation using moment.js\nvalidate.extend(validate.validators.datetime, {\n // The value is guaranteed not to be null or undefined but otherwise it\n // could be anything.\n parse: function (value: string) {\n return Date.parse(value)\n },\n // Input is a unix timestamp\n format: function (\n value: string,\n options: { format: (date: Date) => string },\n ) {\n const dateValue = new Date(value)\n return options.format(dateValue)\n },\n})\n\nvalidate.validators.entries = function (\n value: unknown,\n {\n setSchema,\n entrySchema: {\n schema: entrySchema,\n formElementConditionallyShown,\n executedLookups,\n },\n }: {\n setSchema: ValidateJSSchema\n entrySchema: NestedValidateJSSchema\n },\n) {\n const entries = Array.isArray(value) ? value : []\n\n const entryErrors = entries.reduce((errorsByIndex, entry, index) => {\n const entryValidation = validateSubmission(\n entrySchema,\n entry,\n formElementConditionallyShown?.type === 'repeatableSet'\n ? formElementConditionallyShown.entries[index.toString()]\n : undefined,\n Array.isArray(executedLookups) ? executedLookups[index] : {},\n )\n if (entryValidation) {\n errorsByIndex[index] = entryValidation\n }\n return errorsByIndex\n }, {})\n\n const setErrorMessages = validate.single(value, setSchema)\n\n if (!setErrorMessages && validate.isEmpty(entryErrors)) {\n return\n }\n\n return {\n type: 'repeatableSet',\n set: setErrorMessages && setErrorMessages[0],\n entries: entryErrors,\n }\n}\n\nvalidate.validators.nestedElements = function (\n value: SubmissionTypes.S3SubmissionData['submission'] | undefined,\n {\n schema,\n formElementConditionallyShown,\n executedLookups,\n }: NestedValidateJSSchema,\n) {\n const errors = validateSubmission(\n schema,\n value,\n formElementConditionallyShown?.type === 'formElements'\n ? formElementConditionallyShown.formElements\n : undefined,\n typeof executedLookups !== 'boolean' ? executedLookups : {},\n )\n if (!errors) {\n return\n }\n return {\n type: 'formElements',\n formElements: errors,\n }\n}\n\nfunction getInvalidAttachment(value: FormElementBinaryStorageValue) {\n if (\n value &&\n typeof value === 'object' &&\n value.type &&\n value.type === 'ERROR'\n ) {\n return value\n }\n}\nfunction validateAttachments(\n value: FormElementBinaryStorageValue[] | undefined,\n) {\n const invalidAttachmentNames = value?.reduce(\n (invalidAttachmentNames: string[], att) => {\n const attachmentName = getInvalidAttachment(att)?.fileName\n if (attachmentName) {\n invalidAttachmentNames.push(attachmentName)\n }\n return invalidAttachmentNames\n },\n [],\n )\n if (invalidAttachmentNames?.length) {\n return `${invalidAttachmentNames.join(', ')} could not be uploaded.`\n }\n}\nvalidate.validators.attachment = function (\n value: FormElementBinaryStorageValue,\n) {\n return getInvalidAttachment(value)?.errorMessage\n}\nvalidate.validators.attachments = function (\n value:\n | FormElementBinaryStorageValue[]\n | FormElementComplianceValue\n | undefined,\n) {\n if (Array.isArray(value)) {\n return validateAttachments(value)\n }\n return validateAttachments(\n value?.files as FormElementBinaryStorageValue[] | undefined,\n )\n}\n\n// Extend validator for lookups\nvalidate.validators.lookups = function (\n value: unknown,\n {\n executedLookups,\n formElement,\n }: {\n formElement: FormTypes.LookupFormElement & FormTypes.FormElementRequired\n executedLookups: ExecutedLookups\n },\n) {\n if (!formElement.isDataLookup && !formElement.isElementLookup) {\n return\n }\n\n // Lookups must only be executed on required form elements\n if (formElement && !formElement.required) {\n return\n }\n\n const elementExecutedLookups = executedLookups?.[formElement.name]\n if (elementExecutedLookups === true) {\n return\n }\n\n return lookupValidationMessage\n}\n\nvalidate.validators.numberRegex = function (value: unknown, format: unknown) {\n if (!format) {\n return\n }\n if (typeof value === 'number' && !Number.isNaN(value)) {\n value = value.toString()\n }\n const errorMessages = validate.single(value, { format })\n return errorMessages && errorMessages[0]\n}\n\nvalidate.validators.isTrue = function (value: unknown, message?: string) {\n if (!value) {\n return message || 'Must be set to true'\n }\n}\n\nvalidate.validators.needsExtension = function (\n value: attachmentsService.Attachment[] | undefined,\n formElement: FormTypes.FilesElement,\n) {\n const isValid =\n !Array.isArray(value) ||\n value.every((file) => {\n return checkFileNameExtensionIsValid(formElement, file.fileName)\n })\n if (!isValid) return 'All files must have extensions'\n}\n\nfunction getCustomRegexFormatConfig<DefaultValue>(\n formElement: FormTypes.FormElementWithInput<DefaultValue>,\n) {\n return formElement.regexPattern\n ? {\n pattern: formElement.regexPattern,\n flags: formElement.regexFlags,\n message: formElement.regexMessage,\n }\n : undefined\n}\n\ntype ValidateJSSchema = Record<string, unknown>\n\nconst presence = (\n { required, requiredMessage }: FormTypes.FormElementRequired,\n message: string,\n) => (required ? { message: requiredMessage || message } : false)\n\nconst escapeElementName = (elementName: string) => {\n const escapedName = elementName.replace(/\\./g, '\\\\.')\n return escapedName\n}\n\nfunction getCleanDateRangeConfiguration(\n options: DateRangeConfigurationOptions,\n elements: FormTypes.FormElement[],\n submission: SubmissionTypes.S3SubmissionData['submission'] | undefined,\n formElementsConditionallyShown: FormElementsConditionallyShown | undefined,\n): ReturnType<typeof getDateRangeConfiguration> {\n if (options.referenceFormElementId && submission) {\n const { model } = cleanFormSubmissionModel(\n submission,\n elements,\n formElementsConditionallyShown,\n true,\n )\n return getDateRangeConfiguration(options, elements, model)\n }\n return [options.date, options.daysOffset]\n}\n\nfunction getCleanRepeatableSetConfiguration(\n setEntries: FormTypes.RepeatableSetElement['minSetEntries'],\n elements: FormTypes.FormElement[],\n submission: SubmissionTypes.S3SubmissionData['submission'] | undefined,\n formElementsConditionallyShown: FormElementsConditionallyShown | undefined,\n) {\n if (submission) {\n const { model } = cleanFormSubmissionModel(\n submission,\n elements,\n formElementsConditionallyShown,\n true,\n )\n return getRepeatableSetEntriesConfiguration(setEntries, elements, model)\n }\n}\n\nexport function generateValidationSchema(\n elements: FormTypes.FormElementWithName[],\n): ValidateJSSchema {\n return elements.reduce<ValidateJSSchema>((partialSchema, formElement) => {\n switch (formElement.type) {\n // Elements that do not need to be validated\n case 'summary':\n case 'calculation':\n case 'image':\n case 'html':\n case 'heading': {\n return partialSchema\n }\n }\n\n const constraint: ValidatorConstraintFn<\n SubmissionTypes.S3SubmissionData['submission']\n > = (\n value,\n submission,\n propertyName,\n { formElementsConditionallyShown, executedLookups },\n ) => {\n // If the element is current hidden, we do not need to apply validation\n const formElementConditionallyShown =\n formElementsConditionallyShown?.[formElement.name]\n if (formElementConditionallyShown?.isHidden) {\n return\n }\n\n switch (formElement.type) {\n case 'draw': {\n return {\n attachment: true,\n presence: presence(formElement, 'A saved signature is required'),\n }\n }\n case 'camera': {\n return {\n attachment: true,\n presence: presence(formElement, 'A photo is required'),\n }\n }\n case 'captcha': {\n return {\n presence: presence(\n { ...formElement, required: true },\n 'Please complete the CAPTCHA successfully',\n ),\n }\n }\n case 'location': {\n return {\n presence: presence(formElement, 'Please select a location'),\n lookups: {\n formElement,\n executedLookups,\n },\n }\n }\n case 'compliance': {\n return {\n presence: presence(formElement, 'Required'),\n lookups: {\n formElement,\n executedLookups,\n },\n attachments: true,\n }\n }\n case 'checkboxes': {\n const requiredAllDefaultMessage = 'All options are required'\n return {\n presence: presence(\n {\n ...formElement,\n required: formElement.required || !!formElement.requiredAll,\n },\n formElement.requiredAll ? requiredAllDefaultMessage : 'Required',\n ),\n length: formElement.requiredAll\n ? {\n is: formElement.options?.length,\n message:\n formElement.requiredMessage || requiredAllDefaultMessage,\n }\n : undefined,\n lookups: {\n formElement,\n executedLookups,\n },\n }\n }\n case 'abn':\n case 'geoscapeAddress':\n case 'pointAddress':\n case 'civicaStreetName':\n case 'autocomplete':\n case 'radio':\n case 'select': {\n return {\n presence: presence(formElement, 'Required'),\n lookups: {\n formElement,\n executedLookups,\n },\n }\n }\n case 'boolean': {\n return {\n isTrue: formElement.required && 'Required',\n lookups: {\n formElement,\n executedLookups,\n },\n }\n }\n case 'bsb': {\n return {\n presence: presence(formElement, 'Please enter a BSB number'),\n lookups: {\n formElement,\n executedLookups,\n },\n format: {\n pattern: /\\d{3}-\\d{3}/,\n message: 'Please enter a valid BSB number',\n },\n }\n }\n case 'barcodeScanner': {\n return {\n presence: presence(\n formElement,\n 'Please scan a barcode or enter a value',\n ),\n lookups: {\n formElement,\n executedLookups,\n },\n format: getCustomRegexFormatConfig(formElement),\n }\n }\n case 'text':\n case 'textarea': {\n return {\n presence: presence(formElement, 'Please enter a value'),\n lookups: {\n formElement,\n executedLookups,\n },\n length: {\n minimum: formElement.minLength,\n tooShort:\n 'Please enter a value with at least %{count} character(s)',\n maximum: formElement.maxLength,\n tooLong:\n 'Please enter a value with %{count} character(s) or less',\n },\n format: getCustomRegexFormatConfig(formElement),\n }\n }\n case 'telephone': {\n return {\n presence: presence(formElement, 'Please enter a phone number'),\n lookups: {\n formElement,\n executedLookups,\n },\n format: getCustomRegexFormatConfig(formElement),\n }\n }\n case 'email': {\n return {\n presence: presence(formElement, 'Please enter an email address'),\n email: {\n message: 'Please enter a valid email for this field',\n },\n lookups: {\n formElement,\n executedLookups,\n },\n format: getCustomRegexFormatConfig(formElement),\n }\n }\n case 'time': {\n return {\n presence: presence(formElement, 'Please select a time'),\n lookups: {\n formElement,\n executedLookups,\n },\n }\n }\n case 'date': {\n const [fromDate, fromDateDaysOffset] = getCleanDateRangeConfiguration(\n {\n date: formElement.fromDate,\n daysOffset: formElement.fromDateDaysOffset,\n referenceFormElementId: formElement.fromDateElementId,\n },\n elements,\n submission,\n formElementsConditionallyShown,\n )\n const [toDate, toDateDaysOffset] = getCleanDateRangeConfiguration(\n {\n date: formElement.toDate,\n daysOffset: formElement.toDateDaysOffset,\n referenceFormElementId: formElement.toDateElementId,\n },\n elements,\n submission,\n formElementsConditionallyShown,\n )\n return {\n presence: presence(formElement, 'Please select a date'),\n date: {\n format: (v: Date) => localisationService.formatDate(v),\n earliest: parseDateValue({\n dateOnly: true,\n daysOffset: fromDateDaysOffset,\n value: fromDate,\n }),\n latest: parseDateValue({\n dateOnly: true,\n daysOffset: toDateDaysOffset,\n value: toDate,\n }),\n notValid: 'Please select a valid date',\n tooEarly: 'Date cannot be before %{date}',\n tooLate: 'Date cannot be after %{date}',\n },\n lookups: {\n formElement,\n executedLookups,\n },\n }\n }\n case 'datetime': {\n const [fromDate, fromDateDaysOffset] = getCleanDateRangeConfiguration(\n {\n date: formElement.fromDate,\n daysOffset: formElement.fromDateDaysOffset,\n referenceFormElementId: formElement.fromDateElementId,\n },\n elements,\n submission,\n formElementsConditionallyShown,\n )\n const [toDate, toDateDaysOffset] = getCleanDateRangeConfiguration(\n {\n date: formElement.toDate,\n daysOffset: formElement.toDateDaysOffset,\n referenceFormElementId: formElement.toDateElementId,\n },\n elements,\n submission,\n formElementsConditionallyShown,\n )\n return {\n presence: presence(formElement, 'Please select a date and time'),\n datetime: {\n format: (v: Date) => localisationService.formatDatetime(v),\n earliest: parseDateValue({\n dateOnly: false,\n daysOffset: fromDateDaysOffset,\n value: fromDate,\n }),\n latest: parseDateValue({\n dateOnly: false,\n daysOffset: toDateDaysOffset,\n value: toDate,\n }),\n notValid: 'Please select a valid date and time',\n tooEarly: 'Date and time cannot be before %{date}',\n tooLate: 'Date and time cannot be after %{date}',\n },\n lookups: {\n formElement,\n executedLookups,\n },\n }\n }\n case 'number': {\n let minErrorMessage =\n 'Please enter a number greater than or equal to %{count}'\n let maxErrorMessage =\n 'Please enter a number less than or equal to %{count}'\n if (\n typeof formElement.minNumber === 'number' &&\n typeof formElement.maxNumber === 'number'\n ) {\n minErrorMessage =\n maxErrorMessage = `Please enter a number between ${formElement.minNumber} and ${formElement.maxNumber}`\n }\n\n return {\n type: 'number',\n presence: presence(formElement, 'Please enter a number'),\n numericality: {\n greaterThanOrEqualTo: formElement.minNumber,\n notGreaterThanOrEqualTo: minErrorMessage,\n lessThanOrEqualTo: formElement.maxNumber,\n notLessThanOrEqualTo: maxErrorMessage,\n onlyInteger: formElement.isInteger,\n notInteger: 'Please enter a whole number',\n },\n lookups: {\n formElement,\n executedLookups,\n },\n numberRegex: getCustomRegexFormatConfig(formElement),\n }\n }\n case 'files': {\n return {\n presence: formElement.minEntries\n ? {\n message: `Please upload at least ${\n formElement.minEntries\n } file${formElement.minEntries === 1 ? '' : 's'}`,\n }\n : false,\n length: {\n minimum: formElement.minEntries,\n maximum: formElement.maxEntries,\n tooLong: 'Cannot upload more than %{count} file(s)',\n tooShort: 'Please upload at least %{count} file(s)',\n },\n type: {\n type: (files: attachmentsService.Attachment[] | undefined) => {\n return (\n !Array.isArray(files) ||\n files.every((file) => {\n return checkFileNameIsValid(formElement, file.fileName)\n })\n )\n },\n message: `Only the following file types are accepted: ${(\n formElement.restrictedFileTypes || []\n ).join(', ')}`,\n },\n needsExtension: formElement,\n attachments: true,\n }\n }\n case 'repeatableSet': {\n const minSetEntries = getCleanRepeatableSetConfiguration(\n formElement.minSetEntries,\n elements,\n submission,\n formElementsConditionallyShown,\n )\n const maxSetEntries = getCleanRepeatableSetConfiguration(\n formElement.maxSetEntries,\n elements,\n submission,\n formElementsConditionallyShown,\n )\n\n const repeatableSetExecutedLookups =\n executedLookups !== undefined &&\n typeof executedLookups !== 'boolean' &&\n !Array.isArray(executedLookups) &&\n Array.isArray(executedLookups[formElement.name])\n ? executedLookups[formElement.name]\n : []\n\n return {\n entries: {\n setSchema: {\n presence: minSetEntries\n ? {\n message: `Must have at least ${minSetEntries} ${\n minSetEntries === 1 ? 'entry' : 'entries'\n }`,\n }\n : false,\n length: {\n minimum: minSetEntries,\n maximum: maxSetEntries,\n tooLong: 'Cannot have more than %{count} entry/entries',\n tooShort: 'Must have at least %{count} entry/entries',\n },\n },\n entrySchema: {\n schema: generateValidationSchema(\n formElement.elements as FormTypes.FormElementWithName[],\n ),\n formElementConditionallyShown:\n formElementsConditionallyShown?.[formElement.name],\n executedLookups: repeatableSetExecutedLookups,\n },\n },\n }\n }\n case 'civicaNameRecord': {\n const nestedElements = generateCivicaNameRecordElements(\n formElement,\n [],\n )\n const nestedExecutedLookups =\n executedLookups !== undefined &&\n typeof executedLookups !== 'boolean' &&\n !Array.isArray(executedLookups)\n ? executedLookups[formElement.name]\n : {}\n return {\n nestedElements: {\n schema: generateValidationSchema(\n nestedElements as FormTypes.FormElementWithName[],\n ),\n formElementConditionallyShown:\n formElementsConditionallyShown?.[formElement.name],\n executedLookups: nestedExecutedLookups,\n },\n }\n }\n case 'infoPage':\n case 'form': {\n if (formElement.elements) {\n const nestedExecutedLookups =\n executedLookups !== undefined &&\n typeof executedLookups !== 'boolean' &&\n !Array.isArray(executedLookups)\n ? executedLookups[formElement.name]\n : {}\n return {\n nestedElements: {\n schema: generateValidationSchema(\n formElement.elements as FormTypes.FormElementWithName[],\n ),\n formElementConditionallyShown:\n formElementsConditionallyShown?.[formElement.name],\n executedLookups: nestedExecutedLookups,\n },\n }\n }\n break\n }\n case 'freshdeskDependentField': {\n const nestedElements =\n generateFreshdeskDependentFieldElements(formElement)\n const nestedExecutedLookups =\n executedLookups !== undefined &&\n typeof executedLookups !== 'boolean' &&\n !Array.isArray(executedLookups)\n ? executedLookups[formElement.name]\n : {}\n return {\n nestedElements: {\n schema: generateValidationSchema(\n nestedElements as FormTypes.FormElementWithName[],\n ),\n formElementConditionallyShown:\n formElementsConditionallyShown?.[formElement.name],\n executedLookups: nestedExecutedLookups,\n },\n }\n }\n default: {\n console.info('Unsupported form element with validation', formElement)\n }\n }\n }\n partialSchema[escapeElementName(formElement.name)] = constraint\n return partialSchema\n }, {})\n}\n\nexport function validateSubmission(\n schema: ValidateJSSchema,\n submission: SubmissionTypes.S3SubmissionData['submission'] | undefined,\n formElementsConditionallyShown: FormElementsConditionallyShown | undefined,\n executedLookups: ExecutedLookupValue,\n): FormElementsValidation | undefined {\n const errorsAsArray = validate(submission, schema, {\n format: 'grouped',\n fullMessages: false,\n formElementsConditionallyShown,\n executedLookups,\n })\n if (!errorsAsArray || validate.isEmpty(errorsAsArray)) {\n return\n }\n\n const errors = Object.keys(errorsAsArray || {}).reduce(\n (messagesByFormElementName: FormElementsValidation, key) => {\n const validationMessage = errorsAsArray[key][0]\n if (validationMessage) {\n messagesByFormElementName[key.replace(/\\\\./g, '.')] = validationMessage\n }\n return messagesByFormElementName\n },\n {},\n )\n if (validate.isEmpty(errors)) {\n return\n }\n\n return errors\n}\n\nexport function checkFileNameIsValid(\n formElement: FormTypes.FilesElement,\n fileName: string,\n) {\n const extension = fileName.split('.').pop()\n return (\n !formElement.restrictedFileTypes ||\n formElement.restrictedFileTypes.some(\n (fileType) => fileType.toLowerCase() === extension?.toLowerCase(),\n )\n )\n}\n\nexport function checkFileNameExtensionIsValid(\n formElement: FormTypes.FilesElement,\n fileName: string,\n) {\n return (\n formElement.allowExtensionlessAttachments || fileName.split('.').length >= 2\n )\n}\n\nexport function checkSectionValidity(\n element: FormTypes.PageElement | FormTypes.SectionElement,\n formElementsValidation: FormElementsValidation | undefined,\n): boolean {\n // If everything is valid, no need to check elements\n if (!formElementsValidation) {\n return false\n }\n\n // If there is no elements on the page that are invalid, we will treat as valid\n return element.elements.some((formElement) => {\n switch (formElement.type) {\n case 'page':\n case 'section': {\n return checkSectionValidity(formElement, formElementsValidation)\n }\n default: {\n return formElementsValidation[formElement.name]\n }\n }\n })\n}\n"]}