@oneblink/apps-react 12.0.0 → 13.0.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 (173) hide show
  1. package/dist/OneBlinkAutoSaveForm.d.ts +5 -2
  2. package/dist/OneBlinkAutoSaveForm.js.map +1 -1
  3. package/dist/OneBlinkForm.d.ts +12 -62
  4. package/dist/OneBlinkForm.js +5 -2
  5. package/dist/OneBlinkForm.js.map +1 -1
  6. package/dist/OneBlinkFormBase.js +10 -4
  7. package/dist/OneBlinkFormBase.js.map +1 -1
  8. package/dist/OneBlinkReadOnlyForm.d.ts +0 -2
  9. package/dist/OneBlinkReadOnlyForm.js +1 -40
  10. package/dist/OneBlinkReadOnlyForm.js.map +1 -1
  11. package/dist/apps/services/api/submissions.d.ts +18 -2
  12. package/dist/apps/services/api/submissions.js +40 -4
  13. package/dist/apps/services/api/submissions.js.map +1 -1
  14. package/dist/apps/services/errors/oneBlinkAppsError.d.ts +8 -0
  15. package/dist/apps/services/errors/oneBlinkAppsError.js +1 -0
  16. package/dist/apps/services/errors/oneBlinkAppsError.js.map +1 -1
  17. package/dist/apps/submission-service.d.ts +6 -2
  18. package/dist/apps/submission-service.js +2 -2
  19. package/dist/apps/submission-service.js.map +1 -1
  20. package/dist/components/ArcGISWebMap.d.ts +2 -1
  21. package/dist/components/ArcGISWebMap.js +12 -4
  22. package/dist/components/ArcGISWebMap.js.map +1 -1
  23. package/dist/components/renderer/LookupButton.js +7 -5
  24. package/dist/components/renderer/LookupButton.js.map +1 -1
  25. package/dist/components/renderer/LookupNotification.js +28 -10
  26. package/dist/components/renderer/LookupNotification.js.map +1 -1
  27. package/dist/components/renderer/OneBlinkFormElements.d.ts +16 -1
  28. package/dist/components/renderer/OneBlinkFormElements.js +83 -39
  29. package/dist/components/renderer/OneBlinkFormElements.js.map +1 -1
  30. package/dist/components/renderer/ReverseGeocode.js +13 -1
  31. package/dist/components/renderer/ReverseGeocode.js.map +1 -1
  32. package/dist/components/renderer/attachments/DropdownMenu.d.ts +1 -2
  33. package/dist/components/renderer/attachments/DropdownMenu.js +4 -10
  34. package/dist/components/renderer/attachments/DropdownMenu.js.map +1 -1
  35. package/dist/components/renderer/attachments/FileCard.d.ts +2 -1
  36. package/dist/components/renderer/attachments/FileCard.js +2 -2
  37. package/dist/components/renderer/attachments/FileCard.js.map +1 -1
  38. package/dist/form-elements/FormElementABN.d.ts +2 -1
  39. package/dist/form-elements/FormElementABN.js +3 -3
  40. package/dist/form-elements/FormElementABN.js.map +1 -1
  41. package/dist/form-elements/FormElementAPINSWLiquorLicence.d.ts +2 -1
  42. package/dist/form-elements/FormElementAPINSWLiquorLicence.js +2 -2
  43. package/dist/form-elements/FormElementAPINSWLiquorLicence.js.map +1 -1
  44. package/dist/form-elements/FormElementArcGISWebMap.d.ts +2 -1
  45. package/dist/form-elements/FormElementArcGISWebMap.js +5 -5
  46. package/dist/form-elements/FormElementArcGISWebMap.js.map +1 -1
  47. package/dist/form-elements/FormElementAutocomplete.d.ts +1 -0
  48. package/dist/form-elements/FormElementAutocomplete.js +4 -4
  49. package/dist/form-elements/FormElementAutocomplete.js.map +1 -1
  50. package/dist/form-elements/FormElementBSB.d.ts +2 -1
  51. package/dist/form-elements/FormElementBSB.js +3 -3
  52. package/dist/form-elements/FormElementBSB.js.map +1 -1
  53. package/dist/form-elements/FormElementBarcodeScanner.d.ts +2 -1
  54. package/dist/form-elements/FormElementBarcodeScanner.js +2 -2
  55. package/dist/form-elements/FormElementBarcodeScanner.js.map +1 -1
  56. package/dist/form-elements/FormElementBoolean.d.ts +2 -1
  57. package/dist/form-elements/FormElementBoolean.js +3 -3
  58. package/dist/form-elements/FormElementBoolean.js.map +1 -1
  59. package/dist/form-elements/FormElementCamera.d.ts +2 -1
  60. package/dist/form-elements/FormElementCamera.js +4 -4
  61. package/dist/form-elements/FormElementCamera.js.map +1 -1
  62. package/dist/form-elements/FormElementCheckBoxes.d.ts +2 -1
  63. package/dist/form-elements/FormElementCheckBoxes.js +4 -4
  64. package/dist/form-elements/FormElementCheckBoxes.js.map +1 -1
  65. package/dist/form-elements/FormElementCivicaNameRecord.js +1 -1
  66. package/dist/form-elements/FormElementCivicaNameRecord.js.map +1 -1
  67. package/dist/form-elements/FormElementCivicaStreetName.d.ts +2 -1
  68. package/dist/form-elements/FormElementCivicaStreetName.js +2 -2
  69. package/dist/form-elements/FormElementCivicaStreetName.js.map +1 -1
  70. package/dist/form-elements/FormElementCompliance.d.ts +2 -1
  71. package/dist/form-elements/FormElementCompliance.js +5 -12
  72. package/dist/form-elements/FormElementCompliance.js.map +1 -1
  73. package/dist/form-elements/FormElementDate.d.ts +2 -1
  74. package/dist/form-elements/FormElementDate.js +3 -3
  75. package/dist/form-elements/FormElementDate.js.map +1 -1
  76. package/dist/form-elements/FormElementDateTime.d.ts +2 -1
  77. package/dist/form-elements/FormElementDateTime.js +3 -3
  78. package/dist/form-elements/FormElementDateTime.js.map +1 -1
  79. package/dist/form-elements/FormElementEmail.d.ts +2 -1
  80. package/dist/form-elements/FormElementEmail.js +2 -2
  81. package/dist/form-elements/FormElementEmail.js.map +1 -1
  82. package/dist/form-elements/FormElementFile.d.ts +1 -0
  83. package/dist/form-elements/FormElementFile.js +2 -2
  84. package/dist/form-elements/FormElementFile.js.map +1 -1
  85. package/dist/form-elements/FormElementFiles.d.ts +2 -1
  86. package/dist/form-elements/FormElementFiles.js +4 -4
  87. package/dist/form-elements/FormElementFiles.js.map +1 -1
  88. package/dist/form-elements/FormElementForm.d.ts +21 -1
  89. package/dist/form-elements/FormElementForm.js +5 -12
  90. package/dist/form-elements/FormElementForm.js.map +1 -1
  91. package/dist/form-elements/FormElementFreshdeskDependentField.js +1 -1
  92. package/dist/form-elements/FormElementFreshdeskDependentField.js.map +1 -1
  93. package/dist/form-elements/FormElementGeoscapeAddress.d.ts +2 -1
  94. package/dist/form-elements/FormElementGeoscapeAddress.js +2 -2
  95. package/dist/form-elements/FormElementGeoscapeAddress.js.map +1 -1
  96. package/dist/form-elements/FormElementGoogleAddress.d.ts +2 -1
  97. package/dist/form-elements/FormElementGoogleAddress.js +2 -2
  98. package/dist/form-elements/FormElementGoogleAddress.js.map +1 -1
  99. package/dist/form-elements/FormElementLocation.d.ts +2 -1
  100. package/dist/form-elements/FormElementLocation.js +3 -3
  101. package/dist/form-elements/FormElementLocation.js.map +1 -1
  102. package/dist/form-elements/FormElementLookupButton.d.ts +2 -1
  103. package/dist/form-elements/FormElementLookupButton.js +5 -2
  104. package/dist/form-elements/FormElementLookupButton.js.map +1 -1
  105. package/dist/form-elements/FormElementNumber.d.ts +2 -1
  106. package/dist/form-elements/FormElementNumber.js +4 -4
  107. package/dist/form-elements/FormElementNumber.js.map +1 -1
  108. package/dist/form-elements/FormElementPointAddress.d.ts +2 -1
  109. package/dist/form-elements/FormElementPointAddress.js +2 -2
  110. package/dist/form-elements/FormElementPointAddress.js.map +1 -1
  111. package/dist/form-elements/FormElementPointAddressV3.d.ts +2 -1
  112. package/dist/form-elements/FormElementPointAddressV3.js +2 -2
  113. package/dist/form-elements/FormElementPointAddressV3.js.map +1 -1
  114. package/dist/form-elements/FormElementPointCadastralParcel.d.ts +2 -1
  115. package/dist/form-elements/FormElementPointCadastralParcel.js +3 -3
  116. package/dist/form-elements/FormElementPointCadastralParcel.js.map +1 -1
  117. package/dist/form-elements/FormElementRadio.d.ts +2 -1
  118. package/dist/form-elements/FormElementRadio.js +3 -3
  119. package/dist/form-elements/FormElementRadio.js.map +1 -1
  120. package/dist/form-elements/FormElementRepeatableSet.d.ts +13 -1
  121. package/dist/form-elements/FormElementRepeatableSet.js +10 -10
  122. package/dist/form-elements/FormElementRepeatableSet.js.map +1 -1
  123. package/dist/form-elements/FormElementSection.d.ts +7 -1
  124. package/dist/form-elements/FormElementSection.js +2 -2
  125. package/dist/form-elements/FormElementSection.js.map +1 -1
  126. package/dist/form-elements/FormElementSelect.d.ts +2 -1
  127. package/dist/form-elements/FormElementSelect.js +4 -4
  128. package/dist/form-elements/FormElementSelect.js.map +1 -1
  129. package/dist/form-elements/FormElementSignature.d.ts +2 -1
  130. package/dist/form-elements/FormElementSignature.js +9 -9
  131. package/dist/form-elements/FormElementSignature.js.map +1 -1
  132. package/dist/form-elements/FormElementTelephone.d.ts +2 -1
  133. package/dist/form-elements/FormElementTelephone.js +2 -2
  134. package/dist/form-elements/FormElementTelephone.js.map +1 -1
  135. package/dist/form-elements/FormElementText.d.ts +2 -1
  136. package/dist/form-elements/FormElementText.js +2 -2
  137. package/dist/form-elements/FormElementText.js.map +1 -1
  138. package/dist/form-elements/FormElementTextarea.d.ts +2 -1
  139. package/dist/form-elements/FormElementTextarea.js +3 -3
  140. package/dist/form-elements/FormElementTextarea.js.map +1 -1
  141. package/dist/form-elements/FormElementTime.d.ts +2 -1
  142. package/dist/form-elements/FormElementTime.js +3 -3
  143. package/dist/form-elements/FormElementTime.js.map +1 -1
  144. package/dist/form-elements/OptionButton.d.ts +1 -1
  145. package/dist/form-elements/OptionButton.js +2 -2
  146. package/dist/form-elements/OptionButton.js.map +1 -1
  147. package/dist/hooks/useDynamicOptionsLoaderState.js +5 -1
  148. package/dist/hooks/useDynamicOptionsLoaderState.js.map +1 -1
  149. package/dist/hooks/useFormValidation.d.ts +1 -1
  150. package/dist/hooks/useFormValidation.js +20 -8
  151. package/dist/hooks/useFormValidation.js.map +1 -1
  152. package/dist/hooks/useLookupNotification.d.ts +22 -2
  153. package/dist/hooks/useLookupNotification.js +2 -1
  154. package/dist/hooks/useLookupNotification.js.map +1 -1
  155. package/dist/index.d.ts +1 -1
  156. package/dist/index.js.map +1 -1
  157. package/dist/services/form-validation/extensions.d.ts +2 -1
  158. package/dist/services/form-validation/extensions.js +2 -1
  159. package/dist/services/form-validation/extensions.js.map +1 -1
  160. package/dist/services/form-validation/validateSubmission.d.ts +2 -1
  161. package/dist/services/form-validation/validateSubmission.js +38 -12
  162. package/dist/services/form-validation/validateSubmission.js.map +1 -1
  163. package/dist/services/generateCivicaNameRecordElements.js +0 -13
  164. package/dist/services/generateCivicaNameRecordElements.js.map +1 -1
  165. package/dist/services/generateFreshdeskDependentFieldElements.js +0 -3
  166. package/dist/services/generateFreshdeskDependentFieldElements.js.map +1 -1
  167. package/dist/services/isElementReadOnlyForAudience.d.ts +20 -0
  168. package/dist/services/isElementReadOnlyForAudience.js +46 -0
  169. package/dist/services/isElementReadOnlyForAudience.js.map +1 -0
  170. package/dist/services/resolveFormElementReadOnly.d.ts +10 -0
  171. package/dist/services/resolveFormElementReadOnly.js +17 -0
  172. package/dist/services/resolveFormElementReadOnly.js.map +1 -0
  173. package/package.json +2 -2
@@ -60,6 +60,13 @@ const handleError = (error) => {
60
60
  case 404: {
61
61
  return getNotFoundError(error);
62
62
  }
63
+ case 409: {
64
+ return new OneBlinkAppsError(error.message, {
65
+ originalError: error,
66
+ httpStatusCode: error.httpStatusCode,
67
+ conflict: error.conflict,
68
+ });
69
+ }
63
70
  default: {
64
71
  return getDefaultError(error);
65
72
  }
@@ -101,24 +108,53 @@ completionTimestamp, onProgress, abortSignal) {
101
108
  throw handleError(error);
102
109
  }
103
110
  }
104
- export async function downloadFormSubmission({ formId, submissionId, abortSignal, }) {
111
+ export async function uploadFormSubmissionEdit({ submission, definition, submissionId, context, editedS3ObjectVersionId, onProgress, abortSignal, }) {
112
+ try {
113
+ const oneblinkUploader = generateOneBlinkUploader();
114
+ return await oneblinkUploader.uploadFormSubmissionEdit({
115
+ submission,
116
+ definition,
117
+ device: getDeviceInformation(),
118
+ completionTimestamp: new Date().toISOString(),
119
+ submissionId,
120
+ context,
121
+ editedS3ObjectVersionId,
122
+ onProgress,
123
+ abortSignal,
124
+ });
125
+ }
126
+ catch (error) {
127
+ throw handleError(error);
128
+ }
129
+ }
130
+ export async function downloadFormSubmission({ formId, submissionId, abortSignal, versionId, }) {
105
131
  try {
106
132
  console.log('Attempting to download form submission data:', {
107
133
  formId,
108
134
  submissionId,
135
+ versionId,
109
136
  });
110
137
  const oneblinkDownloader = generateOneBlinkDownloader();
111
- const submissionData = await oneblinkDownloader.downloadSubmission({
138
+ const result = await oneblinkDownloader.downloadSubmission({
112
139
  formId,
113
140
  submissionId,
114
141
  abortSignal,
142
+ versionId,
115
143
  });
116
- if (!submissionData) {
144
+ if (!result) {
117
145
  throw new OneBlinkAppsError("This submission has been removed based on your administrator's retention policy.", {
118
146
  title: 'Submission Data Unavailable',
119
147
  });
120
148
  }
121
- return submissionData;
149
+ if (!result.versionId) {
150
+ throw new OneBlinkAppsError('The submission version could not be determined. Please reload and try again.', {
151
+ title: 'Submission Version Unavailable',
152
+ });
153
+ }
154
+ return {
155
+ data: result.data,
156
+ versionId: result.versionId,
157
+ };
122
158
  }
123
159
  catch (error) {
124
160
  console.error('Error retrieving form submission data', error);
@@ -1 +1 @@
1
- {"version":3,"file":"submissions.js","sourceRoot":"","sources":["../../../../src/apps/services/api/submissions.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,6BAA6B,CAAA;AAC3D,OAAO,MAAM,MAAM,cAAc,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAE9D,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,wBAAwB,MAAM,6BAA6B,CAAA;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,0BAA0B,MAAM,+BAA+B,CAAA;AAEtE,MAAM,kBAAkB,GAAG,CAAC,KAA2B,EAAE,EAAE;IACzD,OAAO,IAAI,iBAAiB,CAAC,KAAK,CAAC,OAAO,EAAE;QAC1C,KAAK,EAAE,oBAAoB;QAC3B,cAAc,EAAE,KAAK,CAAC,cAAc;KACrC,CAAC,CAAA;AACJ,CAAC,CAAA;AACD,MAAM,uBAAuB,GAAG,CAAC,KAA2B,EAAE,EAAE;IAC9D,OAAO,IAAI,iBAAiB,CAC1B,8FAA8F,E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B,CACF,CAAA;QACH,CAAC;QAED,IAAI,KAAK,YAAY,oBAAoB,EAAE,CAAC;YAC1C,QAAQ,KAAK,CAAC,cAAc,EAAE,CAAC;gBAC7B,KAAK,GAAG,CAAC,CAAC,CAAC;oBACT,MAAM,IAAI,iBAAiB,CACzB,gGAAgG,EAChG;wBACE,aAAa,EAAE,KAAK;wBACpB,aAAa,EAAE,IAAI;wBACnB,cAAc,EAAE,KAAK,CAAC,cAAc;qBACrC,CACF,CAAA;gBACH,CAAC;gBACD,KAAK,GAAG,CAAC,CAAC,CAAC;oBACT,MAAM,IAAI,iBAAiB,CACzB,mHAAmH,EACnH;wBACE,aAAa,EAAE,KAAK;wBACpB,qBAAqB,EAAE,IAAI;wBAC3B,cAAc,EAAE,KAAK,CAAC,cAAc;qBACrC,CACF,CAAA;gBACH,CAAC;gBACD,KAAK,GAAG,CAAC;gBACT,KAAK,GAAG,CAAC,CAAC,CAAC;oBACT,MAAM,IAAI,iBAAiB,CAAC,KAAK,CAAC,OAAO,EAAE;wBACzC,KAAK,EAAE,iBAAiB;wBACxB,cAAc,EAAE,KAAK,CAAC,cAAc;qBACrC,CAAC,CAAA;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;QAED,MAAM,IAAI,iBAAiB,CACzB,gFAAgF,EAChF;YACE,aAAa,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;YACzD,cAAc,EACZ,KAAK,YAAY,oBAAoB;gBACnC,CAAC,CAAC,KAAK,CAAC,cAAc;gBACtB,CAAC,CAAC,SAAS;SAChB,CACF,CAAA;IACH,CAAC;AACH,CAAC","sourcesContent":["import OneBlinkAppsError from '../errors/oneBlinkAppsError'\nimport Sentry from '../../Sentry'\nimport { isOffline } from '../../offline-service'\nimport { getDeviceInformation } from '../getDeviceInformation'\nimport { FormSubmission, ProgressListener } from '../../types/submissions'\nimport { getUserToken } from '../user-token'\nimport generateOneBlinkUploader from '../generateOneBlinkUploader'\nimport { OneBlinkStorageError } from '@oneblink/storage'\nimport generateOneBlinkDownloader from '../generateOneBlinkDownloader'\n\nconst getBadRequestError = (error: OneBlinkStorageError) => {\n return new OneBlinkAppsError(error.message, {\n title: 'Invalid Submission',\n httpStatusCode: error.httpStatusCode,\n })\n}\nconst getUnauthenticatedError = (error: OneBlinkStorageError) => {\n return new OneBlinkAppsError(\n 'The form you are attempting to complete requires authentication. Please login and try again.',\n {\n requiresLogin: true,\n originalError: error,\n httpStatusCode: error.httpStatusCode,\n },\n )\n}\nconst getUnauthorisedError = (error: OneBlinkStorageError) => {\n return new OneBlinkAppsError(\n 'You do not have access to complete this form. Please contact your administrator to gain the correct level of access.',\n {\n requiresAccessRequest: true,\n originalError: error,\n httpStatusCode: error.httpStatusCode,\n },\n )\n}\nconst getNotFoundError = (error: OneBlinkStorageError) => {\n return new OneBlinkAppsError(\n 'We could not find the form you are looking for. Please contact your administrator to ensure your form configuration has been completed successfully.',\n {\n title: 'Unknown Form',\n originalError: error,\n httpStatusCode: error.httpStatusCode,\n },\n )\n}\nconst getDefaultError = (error: OneBlinkStorageError) => {\n return new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.httpStatusCode,\n },\n )\n}\n\nconst handleError = (error: OneBlinkStorageError) => {\n if (/Failed to fetch/.test((error as Error).message)) {\n throw new OneBlinkAppsError(\n 'We encountered a network related issue. Please ensure you are connected to the internet before trying again. If the problem persists, contact your administrator.',\n {\n title: 'Connectivity Issues',\n originalError: error as Error,\n isOffline: true,\n },\n )\n }\n switch (error.httpStatusCode) {\n case 400: {\n return getBadRequestError(error)\n }\n case 401: {\n return getUnauthenticatedError(error)\n }\n case 403: {\n return getUnauthorisedError(error)\n }\n case 404: {\n return getNotFoundError(error)\n }\n default: {\n return getDefaultError(error)\n }\n }\n}\n\nexport async function uploadFormSubmission(\n formSubmission: FormSubmission,\n /**\n * The date and time (in ISO format) the form was completed I.e. when the user\n * clicked the submit button\n */\n completionTimestamp: string,\n onProgress?: ProgressListener,\n abortSignal?: AbortSignal,\n) {\n try {\n const oneblinkUploader = generateOneBlinkUploader()\n\n const userToken = getUserToken()\n\n console.log('Uploading submission')\n return await oneblinkUploader.uploadSubmission({\n completionTimestamp,\n submission: formSubmission.submission,\n definition: formSubmission.definition,\n device: getDeviceInformation(),\n userToken: userToken || undefined,\n previousFormSubmissionApprovalId:\n formSubmission.previousFormSubmissionApprovalId,\n jobId: formSubmission.jobId || undefined,\n formsAppId: formSubmission.formsAppId,\n externalId: formSubmission.externalId || undefined,\n taskId: formSubmission.taskCompletion?.task.taskId || undefined,\n taskActionId: formSubmission.taskCompletion?.taskAction.taskActionId,\n taskGroupInstanceId:\n formSubmission.taskCompletion?.taskGroupInstance?.taskGroupInstanceId,\n taskCompletionTimestamp: formSubmission.taskCompletion?.completedAt,\n taskIsAdhoc: formSubmission.taskCompletion?.isAdhoc,\n recaptchas: formSubmission.recaptchas,\n onProgress,\n abortSignal,\n formSubmissionDraftId: formSubmission.formSubmissionDraftId,\n })\n } catch (error) {\n throw handleError(error as OneBlinkStorageError)\n }\n}\n\nexport async function downloadFormSubmission({\n formId,\n submissionId,\n abortSignal,\n}: {\n formId: number\n submissionId: string\n abortSignal?: AbortSignal\n}) {\n try {\n console.log('Attempting to download form submission data:', {\n formId,\n submissionId,\n })\n const oneblinkDownloader = generateOneBlinkDownloader()\n const submissionData = await oneblinkDownloader.downloadSubmission({\n formId,\n submissionId,\n abortSignal,\n })\n if (!submissionData) {\n throw new OneBlinkAppsError(\n \"This submission has been removed based on your administrator's retention policy.\",\n {\n title: 'Submission Data Unavailable',\n },\n )\n }\n return submissionData\n } catch (error) {\n console.error('Error retrieving form submission data', error)\n\n if (error instanceof OneBlinkAppsError) {\n throw error\n }\n\n Sentry.captureException(error)\n\n if (isOffline()) {\n throw new OneBlinkAppsError(\n 'You are currently offline, please connect to the internet and try again',\n {\n originalError: error instanceof Error ? error : undefined,\n isOffline: true,\n },\n )\n }\n\n if (error instanceof OneBlinkStorageError) {\n switch (error.httpStatusCode) {\n case 401: {\n throw new OneBlinkAppsError(\n 'The submission you are attempting to view requires authentication. Please login and try again.',\n {\n originalError: error,\n requiresLogin: true,\n httpStatusCode: error.httpStatusCode,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to submission data. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.httpStatusCode,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.httpStatusCode,\n })\n }\n }\n }\n\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error instanceof Error ? error : undefined,\n httpStatusCode:\n error instanceof OneBlinkStorageError\n ? error.httpStatusCode\n : undefined,\n },\n )\n }\n}\n"]}
1
+ {"version":3,"file":"submissions.js","sourceRoot":"","sources":["../../../../src/apps/services/api/submissions.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,6BAA6B,CAAA;AAC3D,OAAO,MAAM,MAAM,cAAc,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAE9D,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,wBAAwB,MAAM,6BAA6B,CAAA;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,0BAA0B,MAAM,+BAA+B,CAAA;AAGtE,MAAM,kBAAkB,GAAG,CAAC,KAA2B,EAAE,EAAE;IACzD,OAAO,IAAI,iBAAiB,CAAC,KAAK,CAAC,OAAO,EAAE;QAC1C,KAAK,EAAE,oBAAoB;QAC3B,cAAc,EAAE,KAAK,CAAC,cAAc;KACrC,CAAC,CAAA;AACJ,CAAC,CAAA;AACD,MAAM,uBA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C,CAAC,CAAC;oBACT,MAAM,IAAI,iBAAiB,CACzB,gGAAgG,EAChG;wBACE,aAAa,EAAE,KAAK;wBACpB,aAAa,EAAE,IAAI;wBACnB,cAAc,EAAE,KAAK,CAAC,cAAc;qBACrC,CACF,CAAA;gBACH,CAAC;gBACD,KAAK,GAAG,CAAC,CAAC,CAAC;oBACT,MAAM,IAAI,iBAAiB,CACzB,mHAAmH,EACnH;wBACE,aAAa,EAAE,KAAK;wBACpB,qBAAqB,EAAE,IAAI;wBAC3B,cAAc,EAAE,KAAK,CAAC,cAAc;qBACrC,CACF,CAAA;gBACH,CAAC;gBACD,KAAK,GAAG,CAAC;gBACT,KAAK,GAAG,CAAC,CAAC,CAAC;oBACT,MAAM,IAAI,iBAAiB,CAAC,KAAK,CAAC,OAAO,EAAE;wBACzC,KAAK,EAAE,iBAAiB;wBACxB,cAAc,EAAE,KAAK,CAAC,cAAc;qBACrC,CAAC,CAAA;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;QAED,MAAM,IAAI,iBAAiB,CACzB,gFAAgF,EAChF;YACE,aAAa,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;YACzD,cAAc,EACZ,KAAK,YAAY,oBAAoB;gBACnC,CAAC,CAAC,KAAK,CAAC,cAAc;gBACtB,CAAC,CAAC,SAAS;SAChB,CACF,CAAA;IACH,CAAC;AACH,CAAC","sourcesContent":["import OneBlinkAppsError from '../errors/oneBlinkAppsError'\nimport Sentry from '../../Sentry'\nimport { isOffline } from '../../offline-service'\nimport { getDeviceInformation } from '../getDeviceInformation'\nimport { FormSubmission, ProgressListener } from '../../types/submissions'\nimport { getUserToken } from '../user-token'\nimport generateOneBlinkUploader from '../generateOneBlinkUploader'\nimport { OneBlinkStorageError } from '@oneblink/storage'\nimport generateOneBlinkDownloader from '../generateOneBlinkDownloader'\nimport { FormTypes, SubmissionTypes } from '@oneblink/types'\n\nconst getBadRequestError = (error: OneBlinkStorageError) => {\n return new OneBlinkAppsError(error.message, {\n title: 'Invalid Submission',\n httpStatusCode: error.httpStatusCode,\n })\n}\nconst getUnauthenticatedError = (error: OneBlinkStorageError) => {\n return new OneBlinkAppsError(\n 'The form you are attempting to complete requires authentication. Please login and try again.',\n {\n requiresLogin: true,\n originalError: error,\n httpStatusCode: error.httpStatusCode,\n },\n )\n}\nconst getUnauthorisedError = (error: OneBlinkStorageError) => {\n return new OneBlinkAppsError(\n 'You do not have access to complete this form. Please contact your administrator to gain the correct level of access.',\n {\n requiresAccessRequest: true,\n originalError: error,\n httpStatusCode: error.httpStatusCode,\n },\n )\n}\nconst getNotFoundError = (error: OneBlinkStorageError) => {\n return new OneBlinkAppsError(\n 'We could not find the form you are looking for. Please contact your administrator to ensure your form configuration has been completed successfully.',\n {\n title: 'Unknown Form',\n originalError: error,\n httpStatusCode: error.httpStatusCode,\n },\n )\n}\nconst getDefaultError = (error: OneBlinkStorageError) => {\n return new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.httpStatusCode,\n },\n )\n}\n\nconst handleError = (error: OneBlinkStorageError) => {\n if (/Failed to fetch/.test((error as Error).message)) {\n throw new OneBlinkAppsError(\n 'We encountered a network related issue. Please ensure you are connected to the internet before trying again. If the problem persists, contact your administrator.',\n {\n title: 'Connectivity Issues',\n originalError: error as Error,\n isOffline: true,\n },\n )\n }\n switch (error.httpStatusCode) {\n case 400: {\n return getBadRequestError(error)\n }\n case 401: {\n return getUnauthenticatedError(error)\n }\n case 403: {\n return getUnauthorisedError(error)\n }\n case 404: {\n return getNotFoundError(error)\n }\n case 409: {\n return new OneBlinkAppsError(error.message, {\n originalError: error,\n httpStatusCode: error.httpStatusCode,\n conflict: error.conflict,\n })\n }\n default: {\n return getDefaultError(error)\n }\n }\n}\n\nexport async function uploadFormSubmission(\n formSubmission: FormSubmission,\n /**\n * The date and time (in ISO format) the form was completed I.e. when the user\n * clicked the submit button\n */\n completionTimestamp: string,\n onProgress?: ProgressListener,\n abortSignal?: AbortSignal,\n) {\n try {\n const oneblinkUploader = generateOneBlinkUploader()\n\n const userToken = getUserToken()\n\n console.log('Uploading submission')\n return await oneblinkUploader.uploadSubmission({\n completionTimestamp,\n submission: formSubmission.submission,\n definition: formSubmission.definition,\n device: getDeviceInformation(),\n userToken: userToken || undefined,\n previousFormSubmissionApprovalId:\n formSubmission.previousFormSubmissionApprovalId,\n jobId: formSubmission.jobId || undefined,\n formsAppId: formSubmission.formsAppId,\n externalId: formSubmission.externalId || undefined,\n taskId: formSubmission.taskCompletion?.task.taskId || undefined,\n taskActionId: formSubmission.taskCompletion?.taskAction.taskActionId,\n taskGroupInstanceId:\n formSubmission.taskCompletion?.taskGroupInstance?.taskGroupInstanceId,\n taskCompletionTimestamp: formSubmission.taskCompletion?.completedAt,\n taskIsAdhoc: formSubmission.taskCompletion?.isAdhoc,\n recaptchas: formSubmission.recaptchas,\n onProgress,\n abortSignal,\n formSubmissionDraftId: formSubmission.formSubmissionDraftId,\n })\n } catch (error) {\n throw handleError(error as OneBlinkStorageError)\n }\n}\n\nexport async function uploadFormSubmissionEdit({\n submission,\n definition,\n submissionId,\n context,\n editedS3ObjectVersionId,\n onProgress,\n abortSignal,\n}: {\n submission: SubmissionTypes.NewS3SubmissionData['submission']\n definition: FormTypes.Form\n submissionId: string\n context: SubmissionTypes.FormSubmissionMetaEditContext\n editedS3ObjectVersionId: string\n onProgress?: ProgressListener\n abortSignal?: AbortSignal\n}) {\n try {\n const oneblinkUploader = generateOneBlinkUploader()\n return await oneblinkUploader.uploadFormSubmissionEdit({\n submission,\n definition,\n device: getDeviceInformation(),\n completionTimestamp: new Date().toISOString(),\n submissionId,\n context,\n editedS3ObjectVersionId,\n onProgress,\n abortSignal,\n })\n } catch (error) {\n throw handleError(error as OneBlinkStorageError)\n }\n}\n\nexport async function downloadFormSubmission({\n formId,\n submissionId,\n abortSignal,\n versionId,\n}: {\n formId: number\n submissionId: string\n abortSignal?: AbortSignal\n versionId?: string\n}) {\n try {\n console.log('Attempting to download form submission data:', {\n formId,\n submissionId,\n versionId,\n })\n const oneblinkDownloader = generateOneBlinkDownloader()\n const result = await oneblinkDownloader.downloadSubmission({\n formId,\n submissionId,\n abortSignal,\n versionId,\n })\n if (!result) {\n throw new OneBlinkAppsError(\n \"This submission has been removed based on your administrator's retention policy.\",\n {\n title: 'Submission Data Unavailable',\n },\n )\n }\n if (!result.versionId) {\n throw new OneBlinkAppsError(\n 'The submission version could not be determined. Please reload and try again.',\n {\n title: 'Submission Version Unavailable',\n },\n )\n }\n return {\n data: result.data,\n versionId: result.versionId,\n }\n } catch (error) {\n console.error('Error retrieving form submission data', error)\n\n if (error instanceof OneBlinkAppsError) {\n throw error\n }\n\n Sentry.captureException(error)\n\n if (isOffline()) {\n throw new OneBlinkAppsError(\n 'You are currently offline, please connect to the internet and try again',\n {\n originalError: error instanceof Error ? error : undefined,\n isOffline: true,\n },\n )\n }\n\n if (error instanceof OneBlinkStorageError) {\n switch (error.httpStatusCode) {\n case 401: {\n throw new OneBlinkAppsError(\n 'The submission you are attempting to view requires authentication. Please login and try again.',\n {\n originalError: error,\n requiresLogin: true,\n httpStatusCode: error.httpStatusCode,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to submission data. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.httpStatusCode,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.httpStatusCode,\n })\n }\n }\n }\n\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error instanceof Error ? error : undefined,\n httpStatusCode:\n error instanceof OneBlinkStorageError\n ? error.httpStatusCode\n : undefined,\n },\n )\n }\n}\n"]}
@@ -12,6 +12,10 @@ export default class OneBlinkAppsError extends Error {
12
12
  httpStatusCode?: number;
13
13
  /** The original error that was thrown */
14
14
  originalError?: Error;
15
+ /**
16
+ * Machine-readable conflict from the API error payload, when present.
17
+ */
18
+ conflict?: string;
15
19
  /**
16
20
  * Used to create an instance of the `OneBlinkAppsError` class.
17
21
  *
@@ -31,5 +35,9 @@ export default class OneBlinkAppsError extends Error {
31
35
  httpStatusCode?: number;
32
36
  /** The original error that was thrown */
33
37
  originalError?: Error;
38
+ /**
39
+ * Machine-readable conflict from the API error payload, when present.
40
+ */
41
+ conflict?: string;
34
42
  });
35
43
  }
@@ -27,6 +27,7 @@ export default class OneBlinkAppsError extends Error {
27
27
  this.requiresLogin = options.requiresLogin || false;
28
28
  this.originalError = options.originalError;
29
29
  this.httpStatusCode = options.httpStatusCode;
30
+ this.conflict = options.conflict;
30
31
  }
31
32
  }
32
33
  //# sourceMappingURL=oneBlinkAppsError.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"oneBlinkAppsError.js","sourceRoot":"","sources":["../../../../src/apps/services/errors/oneBlinkAppsError.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,KAAK;IAclD;;;;;OAKG;IACH,YACE,OAAe,EACf,UAaI,EAAE;QAEN,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAA;QAE/B,IAAI,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;QACzB,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,IAAI,OAAO,CAAC,qBAAqB,EAAE,CAAC;gBAClC,KAAK,GAAG,eAAe,CAAA;YACzB,CAAC;iBAAM,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;gBACjC,KAAK,GAAG,gBAAgB,CAAA;YAC1B,CAAC;iBAAM,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;gBAC7B,KAAK,GAAG,SAAS,CAAA;YACnB,CAAC;QACH,CAAC;QAED,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,KAAK,CAAA;QAC3C,IAAI,CAAC,qBAAqB,GAAG,OAAO,CAAC,qBAAqB,IAAI,KAAK,CAAA;QACnE,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,KAAK,CAAA;QACnD,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAA;QAC1C,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAA;IAC9C,CAAC;CACF","sourcesContent":["/** An error class that extends `Error` */\nexport default class OneBlinkAppsError extends Error {\n /** The title of the error */\n title?: string\n /** Whether the application state is offline */\n isOffline: boolean\n /** Whether the attempted action required access */\n requiresAccessRequest: boolean\n /** Whether the attempted action required login */\n requiresLogin: boolean\n /** The http status code associated with the error */\n httpStatusCode?: number\n /** The original error that was thrown */\n originalError?: Error\n\n /**\n * Used to create an instance of the `OneBlinkAppsError` class.\n *\n * @param message The message associated with the error\n * @param options The options associated with the error\n */\n constructor(\n message: string,\n options: {\n /** The title of the error */\n title?: string\n /** Whether the application state is offline */\n isOffline?: boolean\n /** Whether the attempted action required access */\n requiresAccessRequest?: boolean\n /** Whether the attempted action required login */\n requiresLogin?: boolean\n /** The http status code associated with the error */\n httpStatusCode?: number\n /** The original error that was thrown */\n originalError?: Error\n } = {},\n ) {\n super(message)\n this.name = 'OneBlinkAppsError'\n\n let title = options.title\n if (!title) {\n if (options.requiresAccessRequest) {\n title = 'Access Denied'\n } else if (options.requiresLogin) {\n title = 'Login Required'\n } else if (options.isOffline) {\n title = 'Offline'\n }\n }\n\n this.title = title\n this.isOffline = options.isOffline || false\n this.requiresAccessRequest = options.requiresAccessRequest || false\n this.requiresLogin = options.requiresLogin || false\n this.originalError = options.originalError\n this.httpStatusCode = options.httpStatusCode\n }\n}\n"]}
1
+ {"version":3,"file":"oneBlinkAppsError.js","sourceRoot":"","sources":["../../../../src/apps/services/errors/oneBlinkAppsError.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,KAAK;IAkBlD;;;;;OAKG;IACH,YACE,OAAe,EACf,UAiBI,EAAE;QAEN,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAA;QAE/B,IAAI,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;QACzB,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,IAAI,OAAO,CAAC,qBAAqB,EAAE,CAAC;gBAClC,KAAK,GAAG,eAAe,CAAA;YACzB,CAAC;iBAAM,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;gBACjC,KAAK,GAAG,gBAAgB,CAAA;YAC1B,CAAC;iBAAM,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;gBAC7B,KAAK,GAAG,SAAS,CAAA;YACnB,CAAC;QACH,CAAC;QAED,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,KAAK,CAAA;QAC3C,IAAI,CAAC,qBAAqB,GAAG,OAAO,CAAC,qBAAqB,IAAI,KAAK,CAAA;QACnE,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,KAAK,CAAA;QACnD,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAA;QAC1C,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAA;QAC5C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAA;IAClC,CAAC;CACF","sourcesContent":["/** An error class that extends `Error` */\nexport default class OneBlinkAppsError extends Error {\n /** The title of the error */\n title?: string\n /** Whether the application state is offline */\n isOffline: boolean\n /** Whether the attempted action required access */\n requiresAccessRequest: boolean\n /** Whether the attempted action required login */\n requiresLogin: boolean\n /** The http status code associated with the error */\n httpStatusCode?: number\n /** The original error that was thrown */\n originalError?: Error\n /**\n * Machine-readable conflict from the API error payload, when present.\n */\n conflict?: string\n\n /**\n * Used to create an instance of the `OneBlinkAppsError` class.\n *\n * @param message The message associated with the error\n * @param options The options associated with the error\n */\n constructor(\n message: string,\n options: {\n /** The title of the error */\n title?: string\n /** Whether the application state is offline */\n isOffline?: boolean\n /** Whether the attempted action required access */\n requiresAccessRequest?: boolean\n /** Whether the attempted action required login */\n requiresLogin?: boolean\n /** The http status code associated with the error */\n httpStatusCode?: number\n /** The original error that was thrown */\n originalError?: Error\n /**\n * Machine-readable conflict from the API error payload, when present.\n */\n conflict?: string\n } = {},\n ) {\n super(message)\n this.name = 'OneBlinkAppsError'\n\n let title = options.title\n if (!title) {\n if (options.requiresAccessRequest) {\n title = 'Access Denied'\n } else if (options.requiresLogin) {\n title = 'Login Required'\n } else if (options.isOffline) {\n title = 'Offline'\n }\n }\n\n this.title = title\n this.isOffline = options.isOffline || false\n this.requiresAccessRequest = options.requiresAccessRequest || false\n this.requiresLogin = options.requiresLogin || false\n this.originalError = options.originalError\n this.httpStatusCode = options.httpStatusCode\n this.conflict = options.conflict\n }\n}\n"]}
@@ -2,6 +2,7 @@ import { registerPendingQueueListener, getPendingQueueSubmissions, cancelEditing
2
2
  import { FormTypes, SubmissionTypes } from '@oneblink/types';
3
3
  import { SubmissionParams, ProgressListener, ProgressListenerEvent } from './services/submit';
4
4
  import { PendingFormSubmission, FormSubmission, FormSubmissionResult, BaseFormSubmission, NewDraftSubmission, NewFormSubmission, DraftSubmission, DraftSubmissionInput } from './types/submissions';
5
+ import { uploadFormSubmissionEdit } from './services/api/submissions';
5
6
  import getPostSubmissionAttachments from './services/api/post-submission-attachment-urls';
6
7
  /**
7
8
  * Force processing the pending queue. This must be called to process the
@@ -222,5 +223,8 @@ declare function getSubmissionData({ formId, submissionId, abortSignal, }: {
222
223
  formId: number;
223
224
  submissionId: string;
224
225
  abortSignal?: AbortSignal;
225
- }): Promise<SubmissionTypes.S3SubmissionData>;
226
- export { submit, executePostSubmissionAction, executeCancelAction, goBackOrCloseWindow, getPendingQueueSubmissions, deletePendingQueueSubmission, editPendingQueueSubmission, cancelEditingPendingQueueSubmission, registerPendingQueueListener, processPendingQueue, BaseFormSubmission, NewDraftSubmission, NewFormSubmission, DraftSubmissionInput, DraftSubmission, FormSubmission, FormSubmissionResult, PendingFormSubmission, SubmissionParams, registerPendingQueueAttachmentProgressListener, registerPendingQueueProgressListener, ProgressListener, ProgressListenerEvent, PendingQueueListener, PendingQueueAction, getSubmissionData, getPostSubmissionAttachments, };
226
+ }): Promise<{
227
+ data: SubmissionTypes.S3SubmissionData;
228
+ versionId: string;
229
+ }>;
230
+ export { submit, executePostSubmissionAction, executeCancelAction, goBackOrCloseWindow, getPendingQueueSubmissions, deletePendingQueueSubmission, editPendingQueueSubmission, cancelEditingPendingQueueSubmission, registerPendingQueueListener, processPendingQueue, BaseFormSubmission, NewDraftSubmission, NewFormSubmission, DraftSubmissionInput, DraftSubmission, FormSubmission, FormSubmissionResult, PendingFormSubmission, SubmissionParams, registerPendingQueueAttachmentProgressListener, registerPendingQueueProgressListener, ProgressListener, ProgressListenerEvent, PendingQueueListener, PendingQueueAction, getSubmissionData, uploadFormSubmissionEdit, getPostSubmissionAttachments, };
@@ -6,7 +6,7 @@ import Sentry from './Sentry';
6
6
  import prepareSubmissionData from './services/prepareSubmissionData';
7
7
  import submitForm from './services/submit';
8
8
  import { deleteAutoSaveData } from './auto-save-service';
9
- import { downloadFormSubmission } from './services/api/submissions';
9
+ import { downloadFormSubmission, uploadFormSubmissionEdit, } from './services/api/submissions';
10
10
  import { getSubmissionAttachmentDetails } from './attachments-service';
11
11
  import getPostSubmissionAttachments from './services/api/post-submission-attachment-urls';
12
12
  let _isProcessingPendingQueue = false;
@@ -421,5 +421,5 @@ async function getSubmissionData({ formId, submissionId, abortSignal, }) {
421
421
  abortSignal,
422
422
  });
423
423
  }
424
- export { submit, executePostSubmissionAction, executeCancelAction, goBackOrCloseWindow, getPendingQueueSubmissions, deletePendingQueueSubmission, editPendingQueueSubmission, cancelEditingPendingQueueSubmission, registerPendingQueueListener, processPendingQueue, registerPendingQueueAttachmentProgressListener, registerPendingQueueProgressListener, getSubmissionData, getPostSubmissionAttachments, };
424
+ export { submit, executePostSubmissionAction, executeCancelAction, goBackOrCloseWindow, getPendingQueueSubmissions, deletePendingQueueSubmission, editPendingQueueSubmission, cancelEditingPendingQueueSubmission, registerPendingQueueListener, processPendingQueue, registerPendingQueueAttachmentProgressListener, registerPendingQueueProgressListener, getSubmissionData, uploadFormSubmissionEdit, getPostSubmissionAttachments, };
425
425
  //# sourceMappingURL=submission-service.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"submission-service.js","sourceRoot":"","sources":["../../src/apps/submission-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC1D,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,4BAA4B,EAC5B,mCAAmC,EACnC,4BAA4B,EAC5B,0BAA0B,EAC1B,8CAA8C,EAC9C,oCAAoC,EACpC,oCAAoC,EACpC,4BAA4B,GAG7B,MAAM,0BAA0B,CAAA;AACjC,OAAO,sCAAsC,MAAM,mDAAmD,CAAA;AAEtG,OAAO,MAAM,MAAM,UAAU,CAAA;AAC7B,OAAO,qBAAqB,MAAM,kCAAkC,CAAA;AACpE,OAAO,UAIN,MAAM,mBAAmB,CAAA;AAW1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AACnE,OAAO,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,4BAA4B,MAAM,gDAAgD,CAAA;AAEzF,IAAI,yBAAyB,GAAG,KAAK,CAAA;AAErC;;;;;;;;;;;GAWG;AACH,KAAK,UAAU,mBAAmB,CAAC,EACjC,6BAA6B,EA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CAAC,EAC/B,MAAM,EACN,YAAY,EACZ,WAAW,GAKZ;IACC,OAAO,MAAM,sBAAsB,CAAC;QAClC,MAAM;QACN,YAAY;QACZ,WAAW;KACZ,CAAC,CAAA;AACJ,CAAC;AAED,OAAO,EACL,MAAM,EACN,2BAA2B,EAC3B,mBAAmB,EACnB,mBAAmB,EACnB,0BAA0B,EAC1B,4BAA4B,EAC5B,0BAA0B,EAC1B,mCAAmC,EACnC,4BAA4B,EAC5B,mBAAmB,EAUnB,8CAA8C,EAC9C,oCAAoC,EAKpC,iBAAiB,EACjB,4BAA4B,GAC7B,CAAA","sourcesContent":["import { isOffline } from './offline-service'\nimport { getFormsKeyId, isLoggedIn } from './auth-service'\nimport {\n registerPendingQueueListener,\n getPendingQueueSubmissions,\n updatePendingQueueSubmission,\n cancelEditingPendingQueueSubmission,\n deletePendingQueueSubmission,\n editPendingQueueSubmission,\n registerPendingQueueAttachmentProgressListener,\n registerPendingQueueProgressListener,\n executePendingQueueProgressListeners,\n removePendingQueueSubmission,\n PendingQueueListener,\n PendingQueueAction,\n} from './services/pending-queue'\nimport replaceInjectablesWithSubmissionValues from './services/replaceInjectablesWithSubmissionValues'\nimport { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport Sentry from './Sentry'\nimport prepareSubmissionData from './services/prepareSubmissionData'\nimport submitForm, {\n SubmissionParams,\n ProgressListener,\n ProgressListenerEvent,\n} from './services/submit'\nimport {\n PendingFormSubmission,\n FormSubmission,\n FormSubmissionResult,\n BaseFormSubmission,\n NewDraftSubmission,\n NewFormSubmission,\n DraftSubmission,\n DraftSubmissionInput,\n} from './types/submissions'\nimport { deleteAutoSaveData } from './auto-save-service'\nimport { downloadFormSubmission } from './services/api/submissions'\nimport { getSubmissionAttachmentDetails } from './attachments-service'\nimport getPostSubmissionAttachments from './services/api/post-submission-attachment-urls'\n\nlet _isProcessingPendingQueue = false\n\n/**\n * Force processing the pending queue. This must be called to process the\n * pending queue and is best used when the application comes back online.\n *\n * ### Example\n *\n * ```js\n * await submissionService.processPendingQueue()\n * ```\n *\n * @returns\n */\nasync function processPendingQueue({\n shouldRunExternalIdGeneration,\n shouldRunServerValidation,\n}: {\n shouldRunExternalIdGeneration: boolean\n shouldRunServerValidation: boolean\n}): Promise<void> {\n if (_isProcessingPendingQueue) {\n return\n }\n _isProcessingPendingQueue = true\n\n console.log('Checking pending queue for submissions.')\n const pendingQueueSubmissions = await getPendingQueueSubmissions()\n\n console.log(\n `Found ${pendingQueueSubmissions.length} submission(s) in the pending queue.`,\n )\n for (const pendingQueueSubmission of pendingQueueSubmissions) {\n if (isOffline()) {\n console.log(\n 'Application is offline, leaving submission in the pending queue:',\n pendingQueueSubmission,\n )\n continue\n }\n\n if (pendingQueueSubmission.isEditing) {\n console.log(\n 'submission is being edited, leaving submission in the pending queue:',\n pendingQueueSubmission,\n )\n continue\n }\n\n if (\n pendingQueueSubmission.definition.isAuthenticated &&\n !isLoggedIn() &&\n !getFormsKeyId()\n ) {\n console.log(\n 'Authentication is required for this form but the user does not have a valid token, leaving submission in the pending queue:',\n pendingQueueSubmission,\n )\n continue\n }\n\n try {\n console.log(\n 'Attempting to process submission from pending queue:',\n pendingQueueSubmission,\n )\n\n pendingQueueSubmission.isSubmitting = true\n pendingQueueSubmission.error = undefined\n await updatePendingQueueSubmission(\n pendingQueueSubmission.pendingTimestamp,\n pendingQueueSubmission,\n 'SUBMIT_STARTED',\n )\n\n const preparedSubmission = await prepareSubmissionData(\n pendingQueueSubmission,\n )\n pendingQueueSubmission.submission = {\n ...preparedSubmission,\n }\n const attachments = getSubmissionAttachmentDetails(\n pendingQueueSubmission.definition.elements,\n pendingQueueSubmission.submission,\n )\n const failedAttachments = attachments.filter(\n (attachment) => attachment.value.type === 'ERROR',\n )\n if (failedAttachments.length) {\n throw new Error(\n `Failed to upload ${failedAttachments.length} attachment${\n failedAttachments.length > 1 ? 's' : ''\n }.`,\n )\n }\n await submitWithCompletionTimestamp({\n isPendingQueueEnabled: true,\n formSubmission: pendingQueueSubmission,\n onProgress: (event) => {\n executePendingQueueProgressListeners({\n ...event,\n pendingTimestamp: pendingQueueSubmission.pendingTimestamp,\n })\n },\n shouldRunExternalIdGeneration,\n shouldRunServerValidation,\n paymentFormUrl: undefined,\n paymentReceiptUrl: undefined,\n completionTimestamp: pendingQueueSubmission.pendingTimestamp,\n })\n\n await removePendingQueueSubmission(\n pendingQueueSubmission.pendingTimestamp,\n 'SUBMIT_SUCCEEDED',\n )\n\n console.log(\n 'Successfully processed submission from the pending queue',\n pendingQueueSubmission,\n )\n } catch (error) {\n Sentry.captureException(error)\n console.error('Error processing submission from the pending queue', error)\n pendingQueueSubmission.isSubmitting = false\n if ((error as Error).message) {\n pendingQueueSubmission.error = (error as Error).message\n } else {\n pendingQueueSubmission.error =\n 'An unknown error has occurred, which has prevented your Form from submitting. Please try again, or contact your Administrator if the problem persists.'\n }\n await updatePendingQueueSubmission(\n pendingQueueSubmission.pendingTimestamp,\n pendingQueueSubmission,\n 'SUBMIT_FAILED',\n )\n }\n }\n\n console.log(\n 'Finished attempting to processing submissions in the pending queue.',\n )\n _isProcessingPendingQueue = false\n}\n\n/**\n * Submit a FormSubmission. Offline submissions will be added to a pending queue\n * and be processed using the `processPendingQueue()` function. FormSubmissions\n * with payment submission events will return the FormSubmissionResult with a\n * `payment` property set, this should be used to redirect the user to the\n * payment URL. Will also handle cleaning up auto save data (if the\n * `autoSaveKey` property is passed), locally stored drafts and prefill data.\n *\n * ### Example\n *\n * ```js\n * const formSubmission = {\n * formsAppId: 1,\n * submission: {\n * form: 'data',\n * goes: 'here',\n * },\n * definition: OneBlinkForm,\n * captchaTokens: [],\n * formSubmissionDraftId: '2974602c-2c5b-4b46-b086-87ee9b2aa233',\n * jobId: 'bb37d1da-9cda-4950-a36a-22f58b25de3a',\n * preFillFormDataId: '7763f828-4aaf-49dc-9c1b-e2eeea8fa990',\n * externalId: 'external-id-set-by-developer',\n * }\n *\n * // Pass paymentReceiptUrl if submission may require a payment\n * const paymentReceiptUrl = `${window.location.origin}/payment-receipt`\n *\n * // Pass schedulingBookingUrlConfiguration if submission utilise scheduling\n * const schedulingBookingUrlConfiguration = {\n * schedulingBookingUrl: 'https://my-website.com/booking',\n * schedulingRescheduleUrl: 'https://my-website.com/reschedule',\n * schedulingCancelUrl: 'https://my-website.com/cancel',\n * }\n * const submissionResult = await submissionService.submit({\n * formSubmission,\n * paymentReceiptUrl,\n * schedulingBookingUrlConfiguration,\n * })\n *\n * if (submissionResult.scheduling) {\n * // Redirect user to booking form\n * window.location.href = submissionResult.scheduling.bookingUrl\n * return\n * }\n *\n * if (submissionResult.payment) {\n * // Redirect user to payment form\n * window.location.href = submissionResult.payment.hostedFormUrl\n * return\n * }\n *\n * if (submissionResult.isOffline) {\n * if (submissionResult.isInPendingQueue) {\n * // Display message to user that the submission\n * // has been added to the pending queue\n * } else {\n * // Display message to user that this submission can\n * // not be processed while offline (most likely because it requires a payment)\n * }\n * return\n * }\n *\n * // submissionResult.submissionId and submissionResult.submissionTimestamp\n * // will be set if the submission was successful\n * ```\n *\n * @param params\n * @returns\n */\nasync function submit(\n params: SubmissionParams & {\n autoSaveKey?: string\n },\n): Promise<FormSubmissionResult> {\n return await submitWithCompletionTimestamp({\n ...params,\n completionTimestamp: new Date().toISOString(),\n })\n}\n\nasync function submitWithCompletionTimestamp({\n autoSaveKey,\n ...params\n}: SubmissionParams & {\n autoSaveKey?: string\n completionTimestamp: string\n}): Promise<FormSubmissionResult> {\n const formSubmissionResult = await submitForm(params)\n if (typeof autoSaveKey === 'string') {\n try {\n await deleteAutoSaveData(params.formSubmission.definition.id, autoSaveKey)\n } catch (error) {\n console.warn('Error removing auto save data: ', error)\n Sentry.captureException(error)\n }\n }\n return formSubmissionResult\n}\n\nasync function closeWindow(): Promise<void> {\n // @ts-expect-error\n if (window.cordova && window.cordova.plugins.exit) {\n // @ts-expect-error\n window.cordova.plugins.exit()\n return\n }\n\n window.close()\n\n // If the browser has not closed after timeout,\n // we throw an error to display to the user\n return new Promise((resolve, reject) => {\n setTimeout(() => {\n console.log('Could not close as window was not opened using JavaScript')\n reject(\n new Error(\n 'We were unable to close your browser, could you please close it manually for us?',\n ),\n )\n }, 500)\n })\n}\n\n/**\n * Go back in the browser history or attempts to close the browser tab if there\n * is no history.\n *\n * ### Example\n *\n * ```js\n * try {\n * await submissionService.goBackOrCloseWindow()\n * } catch (error) {\n * // Handle error while closing browser tab.\n * // Display message to user to close it manually\n * }\n * ```\n *\n * @returns\n */\nasync function goBackOrCloseWindow(): Promise<void> {\n if (window.history.length <= 1) {\n return closeWindow()\n } else {\n window.history.back()\n }\n}\n\n/**\n * Action to cancel completing a form, currently goes back in the browser\n * history or attempts to close the browser tab if there is no history.\n *\n * ### Example\n *\n * ```js\n * const options = {\n * definition: OneBlinkForm,\n * externalId: 'external-id-set-by-developer',\n * }\n * // Only used for relative URLs\n * const pushRelativePath = (path) => {\n * window.location.href = path\n * }\n * // Only used for aboslute URLS\n * const replaceAbsolutePath = window.location.replace\n *\n * try {\n * await submissionService.executeCancelAction(options, {\n * onRedirectToRelativeUrl: pushRelativePath,\n * onRedirectToAbsoluteUrl: replaceAbsolutePath,\n * })\n * } catch (error) {\n * // Handle error while closing browser tab.\n * // Display message to user to close it manually\n * }\n * ```\n *\n * @param options\n * @param redirectConfig\n */\nasync function executeCancelAction(\n formSubmissionResultOptions: {\n definition: FormTypes.Form\n externalId: string | null\n taskCompletion?: FormSubmissionResult['taskCompletion']\n },\n {\n onRedirectToRelativeUrl,\n onRedirectToAbsoluteUrl,\n }: {\n onRedirectToRelativeUrl: (url: string) => void\n onRedirectToAbsoluteUrl: (url: string) => void\n },\n): Promise<void> {\n const formSubmissionResult: FormSubmissionResult = {\n ...formSubmissionResultOptions,\n formsAppId: NaN,\n formSubmissionDraftId: undefined,\n jobId: undefined,\n externalId: undefined,\n preFillFormDataId: null,\n recaptchas: [],\n submission: {},\n isInPendingQueue: false,\n isOffline: false,\n payment: null,\n scheduling: null,\n submissionId: null,\n submissionTimestamp: null,\n isUploadingAttachments: false,\n }\n\n let cancelAction = formSubmissionResult.definition.cancelAction\n let cancelRedirectUrl = formSubmissionResult.definition.cancelRedirectUrl\n\n if (formSubmissionResult.taskCompletion) {\n cancelAction = 'URL'\n cancelRedirectUrl = formSubmissionResult.taskCompletion.redirectUrl\n }\n\n await executeAction(formSubmissionResult, {\n action: cancelAction,\n redirectUrl: cancelRedirectUrl,\n onRedirectToRelativeUrl,\n onRedirectToAbsoluteUrl,\n })\n}\n\n/**\n * Execute the post submission action for a form after a successful form\n * submission.\n *\n * ### Example\n *\n * ```js\n * const formSubmissionResult = {\n * submissionId: '89c6e98e-f56f-45fc-84fe-c4fc62331d34',\n * submissionTimestamp: '2020-07-29T01:03:26.573Z'\n * formsAppId: 1,\n * submission: {\n * form: 'data',\n * goes: 'here'\n * },\n * definition: OneBlinkForm,\n * payment: {\n * hostedFormUrl: 'https://payment.com/transaction'\n * },\n * formSubmissionDraftId: '2974602c-2c5b-4b46-b086-87ee9b2aa233',\n * jobId: 'bb37d1da-9cda-4950-a36a-22f58b25de3a',\n * preFillFormDataId: '7763f828-4aaf-49dc-9c1b-e2eeea8fa990',\n * externalId: 'external-id-set-by-developer',\n * }\n * // Only used for relative URLs\n * const pushRelativePath = (path) => {\n * window.location.href = path\n * }\n * // Only used for aboslute URLS\n * const replaceAbsolutePath = window.location.replace\n *\n * try {\n * await submissionService.executePostSubmissionAction(formSubmissionResult, {\n * onRedirectToRelativeUrl: pushRelativePath,\n * onRedirectToAbsoluteUrl: replaceAbsolutePath,\n * })\n * } catch (error) {\n * // Handle error while closing browser tab.\n * // Display message to user to close it manually\n * }\n * ```\n *\n * @param submissionResult\n * @param redirectConfig\n */\nasync function executePostSubmissionAction(\n submissionResult: FormSubmissionResult,\n {\n onRedirectToRelativeUrl,\n onRedirectToAbsoluteUrl,\n }: {\n onRedirectToRelativeUrl: (url: string) => void\n onRedirectToAbsoluteUrl: (url: string) => void\n },\n): Promise<void> {\n console.log('Attempting to run post submission action')\n let postSubmissionAction = submissionResult.definition.postSubmissionAction\n let redirectUrl = submissionResult.definition.redirectUrl\n\n if (submissionResult.scheduling) {\n postSubmissionAction = 'URL'\n redirectUrl = submissionResult.scheduling.bookingUrl\n } else if (submissionResult.payment) {\n postSubmissionAction = 'URL'\n redirectUrl = submissionResult.payment.hostedFormUrl\n } else if (submissionResult.taskCompletion) {\n postSubmissionAction = 'URL'\n redirectUrl = submissionResult.taskCompletion.redirectUrl\n }\n\n await executeAction(submissionResult, {\n action: postSubmissionAction,\n redirectUrl,\n onRedirectToRelativeUrl,\n onRedirectToAbsoluteUrl,\n })\n}\n\nasync function executeAction(\n submissionResult: FormSubmissionResult,\n {\n action,\n redirectUrl,\n onRedirectToRelativeUrl,\n onRedirectToAbsoluteUrl,\n }: {\n action: FormTypes.FormPostSubmissionAction\n redirectUrl: string | undefined\n onRedirectToRelativeUrl: (url: string) => void\n onRedirectToAbsoluteUrl: (url: string) => void\n },\n): Promise<void> {\n switch (action) {\n case 'CLOSE':\n return closeWindow()\n case 'FORMS_LIBRARY': {\n if (window.location.pathname === '/') {\n onRedirectToAbsoluteUrl(window.location.origin)\n } else {\n onRedirectToRelativeUrl('/')\n }\n break\n }\n case 'URL': {\n const newUrl = replaceInjectablesWithSubmissionValues(\n redirectUrl || '/',\n submissionResult,\n ).text\n // Relative URLs can be navigated to internally\n if (newUrl[0] === '/') {\n onRedirectToRelativeUrl(newUrl)\n return\n }\n\n onRedirectToAbsoluteUrl(newUrl)\n\n // If we are in cordova land, we will navigate\n // back to the home screen after redirect\n if (window.cordova) {\n // Wait a couple of seconds to ensure the browser has\n // been opened before navigating away from form.\n setTimeout(() => {\n onRedirectToRelativeUrl('/')\n }, 2000)\n }\n break\n }\n case 'BACK':\n default: {\n // if there's no post submission action for some reason, use prev. logic...\n return goBackOrCloseWindow()\n }\n }\n}\n\n/**\n * Retrieve submission data for a known formId and submissionId\n *\n * #### Example\n *\n * ```js\n * const formId = 1\n * const submissionId = 'fba95b9d-5a9c-463d-ab68-867f431e4120'\n * const credentials = await formSubmissionService.getSubmissionData({\n * formId,\n * submissionId,\n * })\n * ```\n *\n * @param formId\n * @param submissionId\n * @param abortSignal\n * @returns\n */\nasync function getSubmissionData({\n formId,\n submissionId,\n abortSignal,\n}: {\n formId: number\n submissionId: string\n abortSignal?: AbortSignal\n}): Promise<SubmissionTypes.S3SubmissionData> {\n return await downloadFormSubmission({\n formId,\n submissionId,\n abortSignal,\n })\n}\n\nexport {\n submit,\n executePostSubmissionAction,\n executeCancelAction,\n goBackOrCloseWindow,\n getPendingQueueSubmissions,\n deletePendingQueueSubmission,\n editPendingQueueSubmission,\n cancelEditingPendingQueueSubmission,\n registerPendingQueueListener,\n processPendingQueue,\n BaseFormSubmission,\n NewDraftSubmission,\n NewFormSubmission,\n DraftSubmissionInput,\n DraftSubmission,\n FormSubmission,\n FormSubmissionResult,\n PendingFormSubmission,\n SubmissionParams,\n registerPendingQueueAttachmentProgressListener,\n registerPendingQueueProgressListener,\n ProgressListener,\n ProgressListenerEvent,\n PendingQueueListener,\n PendingQueueAction,\n getSubmissionData,\n getPostSubmissionAttachments,\n}\n"]}
1
+ {"version":3,"file":"submission-service.js","sourceRoot":"","sources":["../../src/apps/submission-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC1D,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,4BAA4B,EAC5B,mCAAmC,EACnC,4BAA4B,EAC5B,0BAA0B,EAC1B,8CAA8C,EAC9C,oCAAoC,EACpC,oCAAoC,EACpC,4BAA4B,GAG7B,MAAM,0BAA0B,CAAA;AACjC,OAAO,sCAAsC,MAAM,mDAAmD,CAAA;AAEtG,OAAO,MAAM,MAAM,UAAU,CAAA;AAC7B,OAAO,qBAAqB,MAAM,kCAAkC,CAAA;AACpE,OAAO,UAIN,MAAM,mB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AgD;gBAChD,UAAU,CAAC,GAAG,EAAE;oBACd,uBAAuB,CAAC,GAAG,CAAC,CAAA;gBAC9B,CAAC,EAAE,IAAI,CAAC,CAAA;YACV,CAAC;YACD,MAAK;QACP,CAAC;QACD,KAAK,MAAM,CAAC;QACZ,OAAO,CAAC,CAAC,CAAC;YACR,2EAA2E;YAC3E,OAAO,mBAAmB,EAAE,CAAA;QAC9B,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,KAAK,UAAU,iBAAiB,CAAC,EAC/B,MAAM,EACN,YAAY,EACZ,WAAW,GAKZ;IAIC,OAAO,MAAM,sBAAsB,CAAC;QAClC,MAAM;QACN,YAAY;QACZ,WAAW;KACZ,CAAC,CAAA;AACJ,CAAC;AAED,OAAO,EACL,MAAM,EACN,2BAA2B,EAC3B,mBAAmB,EACnB,mBAAmB,EACnB,0BAA0B,EAC1B,4BAA4B,EAC5B,0BAA0B,EAC1B,mCAAmC,EACnC,4BAA4B,EAC5B,mBAAmB,EAUnB,8CAA8C,EAC9C,oCAAoC,EAKpC,iBAAiB,EACjB,wBAAwB,EACxB,4BAA4B,GAC7B,CAAA","sourcesContent":["import { isOffline } from './offline-service'\nimport { getFormsKeyId, isLoggedIn } from './auth-service'\nimport {\n registerPendingQueueListener,\n getPendingQueueSubmissions,\n updatePendingQueueSubmission,\n cancelEditingPendingQueueSubmission,\n deletePendingQueueSubmission,\n editPendingQueueSubmission,\n registerPendingQueueAttachmentProgressListener,\n registerPendingQueueProgressListener,\n executePendingQueueProgressListeners,\n removePendingQueueSubmission,\n PendingQueueListener,\n PendingQueueAction,\n} from './services/pending-queue'\nimport replaceInjectablesWithSubmissionValues from './services/replaceInjectablesWithSubmissionValues'\nimport { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport Sentry from './Sentry'\nimport prepareSubmissionData from './services/prepareSubmissionData'\nimport submitForm, {\n SubmissionParams,\n ProgressListener,\n ProgressListenerEvent,\n} from './services/submit'\nimport {\n PendingFormSubmission,\n FormSubmission,\n FormSubmissionResult,\n BaseFormSubmission,\n NewDraftSubmission,\n NewFormSubmission,\n DraftSubmission,\n DraftSubmissionInput,\n} from './types/submissions'\nimport { deleteAutoSaveData } from './auto-save-service'\nimport {\n downloadFormSubmission,\n uploadFormSubmissionEdit,\n} from './services/api/submissions'\nimport { getSubmissionAttachmentDetails } from './attachments-service'\nimport getPostSubmissionAttachments from './services/api/post-submission-attachment-urls'\n\nlet _isProcessingPendingQueue = false\n\n/**\n * Force processing the pending queue. This must be called to process the\n * pending queue and is best used when the application comes back online.\n *\n * ### Example\n *\n * ```js\n * await submissionService.processPendingQueue()\n * ```\n *\n * @returns\n */\nasync function processPendingQueue({\n shouldRunExternalIdGeneration,\n shouldRunServerValidation,\n}: {\n shouldRunExternalIdGeneration: boolean\n shouldRunServerValidation: boolean\n}): Promise<void> {\n if (_isProcessingPendingQueue) {\n return\n }\n _isProcessingPendingQueue = true\n\n console.log('Checking pending queue for submissions.')\n const pendingQueueSubmissions = await getPendingQueueSubmissions()\n\n console.log(\n `Found ${pendingQueueSubmissions.length} submission(s) in the pending queue.`,\n )\n for (const pendingQueueSubmission of pendingQueueSubmissions) {\n if (isOffline()) {\n console.log(\n 'Application is offline, leaving submission in the pending queue:',\n pendingQueueSubmission,\n )\n continue\n }\n\n if (pendingQueueSubmission.isEditing) {\n console.log(\n 'submission is being edited, leaving submission in the pending queue:',\n pendingQueueSubmission,\n )\n continue\n }\n\n if (\n pendingQueueSubmission.definition.isAuthenticated &&\n !isLoggedIn() &&\n !getFormsKeyId()\n ) {\n console.log(\n 'Authentication is required for this form but the user does not have a valid token, leaving submission in the pending queue:',\n pendingQueueSubmission,\n )\n continue\n }\n\n try {\n console.log(\n 'Attempting to process submission from pending queue:',\n pendingQueueSubmission,\n )\n\n pendingQueueSubmission.isSubmitting = true\n pendingQueueSubmission.error = undefined\n await updatePendingQueueSubmission(\n pendingQueueSubmission.pendingTimestamp,\n pendingQueueSubmission,\n 'SUBMIT_STARTED',\n )\n\n const preparedSubmission = await prepareSubmissionData(\n pendingQueueSubmission,\n )\n pendingQueueSubmission.submission = {\n ...preparedSubmission,\n }\n const attachments = getSubmissionAttachmentDetails(\n pendingQueueSubmission.definition.elements,\n pendingQueueSubmission.submission,\n )\n const failedAttachments = attachments.filter(\n (attachment) => attachment.value.type === 'ERROR',\n )\n if (failedAttachments.length) {\n throw new Error(\n `Failed to upload ${failedAttachments.length} attachment${\n failedAttachments.length > 1 ? 's' : ''\n }.`,\n )\n }\n await submitWithCompletionTimestamp({\n isPendingQueueEnabled: true,\n formSubmission: pendingQueueSubmission,\n onProgress: (event) => {\n executePendingQueueProgressListeners({\n ...event,\n pendingTimestamp: pendingQueueSubmission.pendingTimestamp,\n })\n },\n shouldRunExternalIdGeneration,\n shouldRunServerValidation,\n paymentFormUrl: undefined,\n paymentReceiptUrl: undefined,\n completionTimestamp: pendingQueueSubmission.pendingTimestamp,\n })\n\n await removePendingQueueSubmission(\n pendingQueueSubmission.pendingTimestamp,\n 'SUBMIT_SUCCEEDED',\n )\n\n console.log(\n 'Successfully processed submission from the pending queue',\n pendingQueueSubmission,\n )\n } catch (error) {\n Sentry.captureException(error)\n console.error('Error processing submission from the pending queue', error)\n pendingQueueSubmission.isSubmitting = false\n if ((error as Error).message) {\n pendingQueueSubmission.error = (error as Error).message\n } else {\n pendingQueueSubmission.error =\n 'An unknown error has occurred, which has prevented your Form from submitting. Please try again, or contact your Administrator if the problem persists.'\n }\n await updatePendingQueueSubmission(\n pendingQueueSubmission.pendingTimestamp,\n pendingQueueSubmission,\n 'SUBMIT_FAILED',\n )\n }\n }\n\n console.log(\n 'Finished attempting to processing submissions in the pending queue.',\n )\n _isProcessingPendingQueue = false\n}\n\n/**\n * Submit a FormSubmission. Offline submissions will be added to a pending queue\n * and be processed using the `processPendingQueue()` function. FormSubmissions\n * with payment submission events will return the FormSubmissionResult with a\n * `payment` property set, this should be used to redirect the user to the\n * payment URL. Will also handle cleaning up auto save data (if the\n * `autoSaveKey` property is passed), locally stored drafts and prefill data.\n *\n * ### Example\n *\n * ```js\n * const formSubmission = {\n * formsAppId: 1,\n * submission: {\n * form: 'data',\n * goes: 'here',\n * },\n * definition: OneBlinkForm,\n * captchaTokens: [],\n * formSubmissionDraftId: '2974602c-2c5b-4b46-b086-87ee9b2aa233',\n * jobId: 'bb37d1da-9cda-4950-a36a-22f58b25de3a',\n * preFillFormDataId: '7763f828-4aaf-49dc-9c1b-e2eeea8fa990',\n * externalId: 'external-id-set-by-developer',\n * }\n *\n * // Pass paymentReceiptUrl if submission may require a payment\n * const paymentReceiptUrl = `${window.location.origin}/payment-receipt`\n *\n * // Pass schedulingBookingUrlConfiguration if submission utilise scheduling\n * const schedulingBookingUrlConfiguration = {\n * schedulingBookingUrl: 'https://my-website.com/booking',\n * schedulingRescheduleUrl: 'https://my-website.com/reschedule',\n * schedulingCancelUrl: 'https://my-website.com/cancel',\n * }\n * const submissionResult = await submissionService.submit({\n * formSubmission,\n * paymentReceiptUrl,\n * schedulingBookingUrlConfiguration,\n * })\n *\n * if (submissionResult.scheduling) {\n * // Redirect user to booking form\n * window.location.href = submissionResult.scheduling.bookingUrl\n * return\n * }\n *\n * if (submissionResult.payment) {\n * // Redirect user to payment form\n * window.location.href = submissionResult.payment.hostedFormUrl\n * return\n * }\n *\n * if (submissionResult.isOffline) {\n * if (submissionResult.isInPendingQueue) {\n * // Display message to user that the submission\n * // has been added to the pending queue\n * } else {\n * // Display message to user that this submission can\n * // not be processed while offline (most likely because it requires a payment)\n * }\n * return\n * }\n *\n * // submissionResult.submissionId and submissionResult.submissionTimestamp\n * // will be set if the submission was successful\n * ```\n *\n * @param params\n * @returns\n */\nasync function submit(\n params: SubmissionParams & {\n autoSaveKey?: string\n },\n): Promise<FormSubmissionResult> {\n return await submitWithCompletionTimestamp({\n ...params,\n completionTimestamp: new Date().toISOString(),\n })\n}\n\nasync function submitWithCompletionTimestamp({\n autoSaveKey,\n ...params\n}: SubmissionParams & {\n autoSaveKey?: string\n completionTimestamp: string\n}): Promise<FormSubmissionResult> {\n const formSubmissionResult = await submitForm(params)\n if (typeof autoSaveKey === 'string') {\n try {\n await deleteAutoSaveData(params.formSubmission.definition.id, autoSaveKey)\n } catch (error) {\n console.warn('Error removing auto save data: ', error)\n Sentry.captureException(error)\n }\n }\n return formSubmissionResult\n}\n\nasync function closeWindow(): Promise<void> {\n // @ts-expect-error\n if (window.cordova && window.cordova.plugins.exit) {\n // @ts-expect-error\n window.cordova.plugins.exit()\n return\n }\n\n window.close()\n\n // If the browser has not closed after timeout,\n // we throw an error to display to the user\n return new Promise((resolve, reject) => {\n setTimeout(() => {\n console.log('Could not close as window was not opened using JavaScript')\n reject(\n new Error(\n 'We were unable to close your browser, could you please close it manually for us?',\n ),\n )\n }, 500)\n })\n}\n\n/**\n * Go back in the browser history or attempts to close the browser tab if there\n * is no history.\n *\n * ### Example\n *\n * ```js\n * try {\n * await submissionService.goBackOrCloseWindow()\n * } catch (error) {\n * // Handle error while closing browser tab.\n * // Display message to user to close it manually\n * }\n * ```\n *\n * @returns\n */\nasync function goBackOrCloseWindow(): Promise<void> {\n if (window.history.length <= 1) {\n return closeWindow()\n } else {\n window.history.back()\n }\n}\n\n/**\n * Action to cancel completing a form, currently goes back in the browser\n * history or attempts to close the browser tab if there is no history.\n *\n * ### Example\n *\n * ```js\n * const options = {\n * definition: OneBlinkForm,\n * externalId: 'external-id-set-by-developer',\n * }\n * // Only used for relative URLs\n * const pushRelativePath = (path) => {\n * window.location.href = path\n * }\n * // Only used for aboslute URLS\n * const replaceAbsolutePath = window.location.replace\n *\n * try {\n * await submissionService.executeCancelAction(options, {\n * onRedirectToRelativeUrl: pushRelativePath,\n * onRedirectToAbsoluteUrl: replaceAbsolutePath,\n * })\n * } catch (error) {\n * // Handle error while closing browser tab.\n * // Display message to user to close it manually\n * }\n * ```\n *\n * @param options\n * @param redirectConfig\n */\nasync function executeCancelAction(\n formSubmissionResultOptions: {\n definition: FormTypes.Form\n externalId: string | null\n taskCompletion?: FormSubmissionResult['taskCompletion']\n },\n {\n onRedirectToRelativeUrl,\n onRedirectToAbsoluteUrl,\n }: {\n onRedirectToRelativeUrl: (url: string) => void\n onRedirectToAbsoluteUrl: (url: string) => void\n },\n): Promise<void> {\n const formSubmissionResult: FormSubmissionResult = {\n ...formSubmissionResultOptions,\n formsAppId: NaN,\n formSubmissionDraftId: undefined,\n jobId: undefined,\n externalId: undefined,\n preFillFormDataId: null,\n recaptchas: [],\n submission: {},\n isInPendingQueue: false,\n isOffline: false,\n payment: null,\n scheduling: null,\n submissionId: null,\n submissionTimestamp: null,\n isUploadingAttachments: false,\n }\n\n let cancelAction = formSubmissionResult.definition.cancelAction\n let cancelRedirectUrl = formSubmissionResult.definition.cancelRedirectUrl\n\n if (formSubmissionResult.taskCompletion) {\n cancelAction = 'URL'\n cancelRedirectUrl = formSubmissionResult.taskCompletion.redirectUrl\n }\n\n await executeAction(formSubmissionResult, {\n action: cancelAction,\n redirectUrl: cancelRedirectUrl,\n onRedirectToRelativeUrl,\n onRedirectToAbsoluteUrl,\n })\n}\n\n/**\n * Execute the post submission action for a form after a successful form\n * submission.\n *\n * ### Example\n *\n * ```js\n * const formSubmissionResult = {\n * submissionId: '89c6e98e-f56f-45fc-84fe-c4fc62331d34',\n * submissionTimestamp: '2020-07-29T01:03:26.573Z'\n * formsAppId: 1,\n * submission: {\n * form: 'data',\n * goes: 'here'\n * },\n * definition: OneBlinkForm,\n * payment: {\n * hostedFormUrl: 'https://payment.com/transaction'\n * },\n * formSubmissionDraftId: '2974602c-2c5b-4b46-b086-87ee9b2aa233',\n * jobId: 'bb37d1da-9cda-4950-a36a-22f58b25de3a',\n * preFillFormDataId: '7763f828-4aaf-49dc-9c1b-e2eeea8fa990',\n * externalId: 'external-id-set-by-developer',\n * }\n * // Only used for relative URLs\n * const pushRelativePath = (path) => {\n * window.location.href = path\n * }\n * // Only used for aboslute URLS\n * const replaceAbsolutePath = window.location.replace\n *\n * try {\n * await submissionService.executePostSubmissionAction(formSubmissionResult, {\n * onRedirectToRelativeUrl: pushRelativePath,\n * onRedirectToAbsoluteUrl: replaceAbsolutePath,\n * })\n * } catch (error) {\n * // Handle error while closing browser tab.\n * // Display message to user to close it manually\n * }\n * ```\n *\n * @param submissionResult\n * @param redirectConfig\n */\nasync function executePostSubmissionAction(\n submissionResult: FormSubmissionResult,\n {\n onRedirectToRelativeUrl,\n onRedirectToAbsoluteUrl,\n }: {\n onRedirectToRelativeUrl: (url: string) => void\n onRedirectToAbsoluteUrl: (url: string) => void\n },\n): Promise<void> {\n console.log('Attempting to run post submission action')\n let postSubmissionAction = submissionResult.definition.postSubmissionAction\n let redirectUrl = submissionResult.definition.redirectUrl\n\n if (submissionResult.scheduling) {\n postSubmissionAction = 'URL'\n redirectUrl = submissionResult.scheduling.bookingUrl\n } else if (submissionResult.payment) {\n postSubmissionAction = 'URL'\n redirectUrl = submissionResult.payment.hostedFormUrl\n } else if (submissionResult.taskCompletion) {\n postSubmissionAction = 'URL'\n redirectUrl = submissionResult.taskCompletion.redirectUrl\n }\n\n await executeAction(submissionResult, {\n action: postSubmissionAction,\n redirectUrl,\n onRedirectToRelativeUrl,\n onRedirectToAbsoluteUrl,\n })\n}\n\nasync function executeAction(\n submissionResult: FormSubmissionResult,\n {\n action,\n redirectUrl,\n onRedirectToRelativeUrl,\n onRedirectToAbsoluteUrl,\n }: {\n action: FormTypes.FormPostSubmissionAction\n redirectUrl: string | undefined\n onRedirectToRelativeUrl: (url: string) => void\n onRedirectToAbsoluteUrl: (url: string) => void\n },\n): Promise<void> {\n switch (action) {\n case 'CLOSE':\n return closeWindow()\n case 'FORMS_LIBRARY': {\n if (window.location.pathname === '/') {\n onRedirectToAbsoluteUrl(window.location.origin)\n } else {\n onRedirectToRelativeUrl('/')\n }\n break\n }\n case 'URL': {\n const newUrl = replaceInjectablesWithSubmissionValues(\n redirectUrl || '/',\n submissionResult,\n ).text\n // Relative URLs can be navigated to internally\n if (newUrl[0] === '/') {\n onRedirectToRelativeUrl(newUrl)\n return\n }\n\n onRedirectToAbsoluteUrl(newUrl)\n\n // If we are in cordova land, we will navigate\n // back to the home screen after redirect\n if (window.cordova) {\n // Wait a couple of seconds to ensure the browser has\n // been opened before navigating away from form.\n setTimeout(() => {\n onRedirectToRelativeUrl('/')\n }, 2000)\n }\n break\n }\n case 'BACK':\n default: {\n // if there's no post submission action for some reason, use prev. logic...\n return goBackOrCloseWindow()\n }\n }\n}\n\n/**\n * Retrieve submission data for a known formId and submissionId\n *\n * #### Example\n *\n * ```js\n * const formId = 1\n * const submissionId = 'fba95b9d-5a9c-463d-ab68-867f431e4120'\n * const credentials = await formSubmissionService.getSubmissionData({\n * formId,\n * submissionId,\n * })\n * ```\n *\n * @param formId\n * @param submissionId\n * @param abortSignal\n * @returns\n */\nasync function getSubmissionData({\n formId,\n submissionId,\n abortSignal,\n}: {\n formId: number\n submissionId: string\n abortSignal?: AbortSignal\n}): Promise<{\n data: SubmissionTypes.S3SubmissionData\n versionId: string\n}> {\n return await downloadFormSubmission({\n formId,\n submissionId,\n abortSignal,\n })\n}\n\nexport {\n submit,\n executePostSubmissionAction,\n executeCancelAction,\n goBackOrCloseWindow,\n getPendingQueueSubmissions,\n deletePendingQueueSubmission,\n editPendingQueueSubmission,\n cancelEditingPendingQueueSubmission,\n registerPendingQueueListener,\n processPendingQueue,\n BaseFormSubmission,\n NewDraftSubmission,\n NewFormSubmission,\n DraftSubmissionInput,\n DraftSubmission,\n FormSubmission,\n FormSubmissionResult,\n PendingFormSubmission,\n SubmissionParams,\n registerPendingQueueAttachmentProgressListener,\n registerPendingQueueProgressListener,\n ProgressListener,\n ProgressListenerEvent,\n PendingQueueListener,\n PendingQueueAction,\n getSubmissionData,\n uploadFormSubmissionEdit,\n getPostSubmissionAttachments,\n}\n"]}
@@ -5,6 +5,7 @@ import { FormElementValueChangeHandler } from '../types/form';
5
5
  import '@arcgis/core/assets/esri/themes/light/main.css';
6
6
  type Props = {
7
7
  element: FormTypes.ArcGISWebMapElement;
8
+ readOnly: boolean;
8
9
  id: string;
9
10
  value: ArcGISWebMapElementValue | undefined;
10
11
  onChange: FormElementValueChangeHandler<ArcGISWebMapElementValue>;
@@ -14,6 +15,6 @@ type Props = {
14
15
  dataUrl: string;
15
16
  }>) | null>;
16
17
  };
17
- declare function FormElementArcGISWebMap({ element, id, value, onChange, takeScreenShotRef, automatedSnapshotFileName, ...props }: Props): import("react/jsx-runtime").JSX.Element;
18
+ declare function FormElementArcGISWebMap({ element, readOnly, id, value, onChange, takeScreenShotRef, automatedSnapshotFileName, ...props }: Props): import("react/jsx-runtime").JSX.Element;
18
19
  declare const _default: React.MemoExoticComponent<typeof FormElementArcGISWebMap>;
19
20
  export default _default;
@@ -40,7 +40,7 @@ function DrawingOptionsList({ options, sketchTool, onClose, sketchToolType, setS
40
40
  setSelectedGraphicAttributes({ value, label, description });
41
41
  }, children: label }, id))) })] }));
42
42
  }
43
- function FormElementArcGISWebMap({ element, id, value, onChange, takeScreenShotRef, automatedSnapshotFileName, ...props }) {
43
+ function FormElementArcGISWebMap({ element, readOnly, id, value, onChange, takeScreenShotRef, automatedSnapshotFileName, ...props }) {
44
44
  var _a, _b;
45
45
  const ref = React.useRef(null);
46
46
  const layerPanelRef = React.useRef(null);
@@ -202,7 +202,7 @@ function FormElementArcGISWebMap({ element, id, value, onChange, takeScreenShotR
202
202
  }, []);
203
203
  React.useEffect(() => {
204
204
  var _a, _b, _c, _d, _e, _f;
205
- if (element.readOnly)
205
+ if (readOnly)
206
206
  return;
207
207
  // event listeners for drawing tool creates/updates/deletes
208
208
  // these need to be removed and recreated when the submission value changes
@@ -321,6 +321,7 @@ function FormElementArcGISWebMap({ element, id, value, onChange, takeScreenShotR
321
321
  updateDrawingInputSubmissionValue,
322
322
  updateMapViewSubmissionValue,
323
323
  element,
324
+ readOnly,
324
325
  selectedGraphicAttributes,
325
326
  addMeasurementLabels,
326
327
  clearMeasurementLabels,
@@ -449,7 +450,7 @@ function FormElementArcGISWebMap({ element, id, value, onChange, takeScreenShotR
449
450
  view.ui.add(mapGalleryPanelRef.current, 'top-left');
450
451
  let drawingLayerId;
451
452
  let measurementLayerId;
452
- if (!element.readOnly && ((_a = element.allowedDrawingTools) === null || _a === void 0 ? void 0 : _a.length)) {
453
+ if (!readOnly && ((_a = element.allowedDrawingTools) === null || _a === void 0 ? void 0 : _a.length)) {
453
454
  drawingLayerId = uuid();
454
455
  const drawingLayer = new GraphicsLayer({
455
456
  id: drawingLayerId,
@@ -550,7 +551,14 @@ function FormElementArcGISWebMap({ element, id, value, onChange, takeScreenShotR
550
551
  setIsLoading(true);
551
552
  loadMap();
552
553
  }
553
- }, [drawingOptionsContainerId, element, isLoading, takeScreenShotRef, value]);
554
+ }, [
555
+ drawingOptionsContainerId,
556
+ element,
557
+ isLoading,
558
+ readOnly,
559
+ takeScreenShotRef,
560
+ value,
561
+ ]);
554
562
  React.useEffect(() => {
555
563
  if (!isLoading) {
556
564
  if (isPageVisible) {