@oneblink/apps-react 9.0.0-beta.2 → 9.0.0-beta.3

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 (208) hide show
  1. package/dist/OneBlinkForm.d.ts +6 -6
  2. package/dist/OneBlinkFormBase.js +1 -0
  3. package/dist/OneBlinkFormBase.js.map +1 -1
  4. package/dist/apps/Sentry.d.ts +7 -0
  5. package/dist/apps/Sentry.js +16 -0
  6. package/dist/apps/Sentry.js.map +1 -0
  7. package/dist/apps/approvals-service.d.ts +390 -0
  8. package/dist/apps/approvals-service.js +987 -0
  9. package/dist/apps/approvals-service.js.map +1 -0
  10. package/dist/apps/attachments-service.d.ts +49 -0
  11. package/dist/apps/attachments-service.js +134 -0
  12. package/dist/apps/attachments-service.js.map +1 -0
  13. package/dist/apps/auth-service.d.ts +114 -0
  14. package/dist/apps/auth-service.js +194 -0
  15. package/dist/apps/auth-service.js.map +1 -0
  16. package/dist/apps/auto-save-service.d.ts +82 -0
  17. package/dist/apps/auto-save-service.js +105 -0
  18. package/dist/apps/auto-save-service.js.map +1 -0
  19. package/dist/apps/draft-service.d.ts +148 -0
  20. package/dist/apps/draft-service.js +583 -0
  21. package/dist/apps/draft-service.js.map +1 -0
  22. package/dist/apps/form-service.d.ts +204 -0
  23. package/dist/apps/form-service.js +718 -0
  24. package/dist/apps/form-service.js.map +1 -0
  25. package/dist/apps/form-store-service.d.ts +141 -0
  26. package/dist/apps/form-store-service.js +114 -0
  27. package/dist/apps/form-store-service.js.map +1 -0
  28. package/dist/apps/forms-app-environment-service.d.ts +19 -0
  29. package/dist/apps/forms-app-environment-service.js +55 -0
  30. package/dist/apps/forms-app-environment-service.js.map +1 -0
  31. package/dist/apps/forms-app-service.d.ts +18 -0
  32. package/dist/apps/forms-app-service.js +53 -0
  33. package/dist/apps/forms-app-service.js.map +1 -0
  34. package/dist/apps/index.d.ts +252 -0
  35. package/dist/apps/index.js +254 -0
  36. package/dist/apps/index.js.map +1 -0
  37. package/dist/apps/job-service.d.ts +20 -0
  38. package/dist/apps/job-service.js +95 -0
  39. package/dist/apps/job-service.js.map +1 -0
  40. package/dist/apps/localisation-service.d.ts +207 -0
  41. package/dist/apps/localisation-service.js +321 -0
  42. package/dist/apps/localisation-service.js.map +1 -0
  43. package/dist/apps/notification-service.d.ts +83 -0
  44. package/dist/apps/notification-service.js +315 -0
  45. package/dist/apps/notification-service.js.map +1 -0
  46. package/dist/apps/offline-service.d.ts +18 -0
  47. package/dist/apps/offline-service.js +25 -0
  48. package/dist/apps/offline-service.js.map +1 -0
  49. package/dist/apps/payment-service.d.ts +110 -0
  50. package/dist/apps/payment-service.js +182 -0
  51. package/dist/apps/payment-service.js.map +1 -0
  52. package/dist/apps/prefill-service.d.ts +14 -0
  53. package/dist/apps/prefill-service.js +19 -0
  54. package/dist/apps/prefill-service.js.map +1 -0
  55. package/dist/apps/scheduled-tasks-service.d.ts +127 -0
  56. package/dist/apps/scheduled-tasks-service.js +240 -0
  57. package/dist/apps/scheduled-tasks-service.js.map +1 -0
  58. package/dist/apps/scheduling-service.d.ts +101 -0
  59. package/dist/apps/scheduling-service.js +171 -0
  60. package/dist/apps/scheduling-service.js.map +1 -0
  61. package/dist/apps/services/AWSCognitoClient.d.ts +55 -0
  62. package/dist/apps/services/AWSCognitoClient.js +436 -0
  63. package/dist/apps/services/AWSCognitoClient.js.map +1 -0
  64. package/dist/apps/services/api/drafts.d.ts +7 -0
  65. package/dist/apps/services/api/drafts.js +236 -0
  66. package/dist/apps/services/api/drafts.js.map +1 -0
  67. package/dist/apps/services/api/notifications.d.ts +3 -0
  68. package/dist/apps/services/api/notifications.js +60 -0
  69. package/dist/apps/services/api/notifications.js.map +1 -0
  70. package/dist/apps/services/api/payment.d.ts +23 -0
  71. package/dist/apps/services/api/payment.js +235 -0
  72. package/dist/apps/services/api/payment.js.map +1 -0
  73. package/dist/apps/services/api/post-submission-attachment-urls.d.ts +7 -0
  74. package/dist/apps/services/api/post-submission-attachment-urls.js +19 -0
  75. package/dist/apps/services/api/post-submission-attachment-urls.js.map +1 -0
  76. package/dist/apps/services/api/prefill.d.ts +1 -0
  77. package/dist/apps/services/api/prefill.js +70 -0
  78. package/dist/apps/services/api/prefill.js.map +1 -0
  79. package/dist/apps/services/api/receipt-id.d.ts +2 -0
  80. package/dist/apps/services/api/receipt-id.js +54 -0
  81. package/dist/apps/services/api/receipt-id.js.map +1 -0
  82. package/dist/apps/services/api/scheduling.d.ts +38 -0
  83. package/dist/apps/services/api/scheduling.js +142 -0
  84. package/dist/apps/services/api/scheduling.js.map +1 -0
  85. package/dist/apps/services/api/submissions.d.ts +18 -0
  86. package/dist/apps/services/api/submissions.js +166 -0
  87. package/dist/apps/services/api/submissions.js.map +1 -0
  88. package/dist/apps/services/cognito.d.ts +302 -0
  89. package/dist/apps/services/cognito.js +441 -0
  90. package/dist/apps/services/cognito.js.map +1 -0
  91. package/dist/apps/services/draft-data-store.d.ts +16 -0
  92. package/dist/apps/services/draft-data-store.js +115 -0
  93. package/dist/apps/services/draft-data-store.js.map +1 -0
  94. package/dist/apps/services/errors/oneBlinkAppsError.d.ts +35 -0
  95. package/dist/apps/services/errors/oneBlinkAppsError.js +32 -0
  96. package/dist/apps/services/errors/oneBlinkAppsError.js.map +1 -0
  97. package/dist/apps/services/external-id-generation.d.ts +4 -0
  98. package/dist/apps/services/external-id-generation.js +59 -0
  99. package/dist/apps/services/external-id-generation.js.map +1 -0
  100. package/dist/apps/services/fetch.d.ts +12 -0
  101. package/dist/apps/services/fetch.js +95 -0
  102. package/dist/apps/services/fetch.js.map +1 -0
  103. package/dist/apps/services/forms-key.d.ts +51 -0
  104. package/dist/apps/services/forms-key.js +83 -0
  105. package/dist/apps/services/forms-key.js.map +1 -0
  106. package/dist/apps/services/generate-generic-error.d.ts +3 -0
  107. package/dist/apps/services/generate-generic-error.js +52 -0
  108. package/dist/apps/services/generate-generic-error.js.map +1 -0
  109. package/dist/apps/services/generateOneBlinkDownloader.d.ts +2 -0
  110. package/dist/apps/services/generateOneBlinkDownloader.js +11 -0
  111. package/dist/apps/services/generateOneBlinkDownloader.js.map +1 -0
  112. package/dist/apps/services/generateOneBlinkUploader.d.ts +2 -0
  113. package/dist/apps/services/generateOneBlinkUploader.js +11 -0
  114. package/dist/apps/services/generateOneBlinkUploader.js.map +1 -0
  115. package/dist/apps/services/getDeviceInformation.d.ts +17 -0
  116. package/dist/apps/services/getDeviceInformation.js +38 -0
  117. package/dist/apps/services/getDeviceInformation.js.map +1 -0
  118. package/dist/apps/services/integration-elements.d.ts +383 -0
  119. package/dist/apps/services/integration-elements.js +761 -0
  120. package/dist/apps/services/integration-elements.js.map +1 -0
  121. package/dist/apps/services/job-prefill.d.ts +40 -0
  122. package/dist/apps/services/job-prefill.js +78 -0
  123. package/dist/apps/services/job-prefill.js.map +1 -0
  124. package/dist/apps/services/payment-providers/BPOINTPaymentProvider.d.ts +29 -0
  125. package/dist/apps/services/payment-providers/BPOINTPaymentProvider.js +59 -0
  126. package/dist/apps/services/payment-providers/BPOINTPaymentProvider.js.map +1 -0
  127. package/dist/apps/services/payment-providers/CPPayPaymentProvider.d.ts +27 -0
  128. package/dist/apps/services/payment-providers/CPPayPaymentProvider.js +63 -0
  129. package/dist/apps/services/payment-providers/CPPayPaymentProvider.js.map +1 -0
  130. package/dist/apps/services/payment-providers/NSWGovPayPaymentProvider.d.ts +30 -0
  131. package/dist/apps/services/payment-providers/NSWGovPayPaymentProvider.js +116 -0
  132. package/dist/apps/services/payment-providers/NSWGovPayPaymentProvider.js.map +1 -0
  133. package/dist/apps/services/payment-providers/WestpacQuickStreamPaymentProvider.d.ts +49 -0
  134. package/dist/apps/services/payment-providers/WestpacQuickStreamPaymentProvider.js +116 -0
  135. package/dist/apps/services/payment-providers/WestpacQuickStreamPaymentProvider.js.map +1 -0
  136. package/dist/apps/services/payment-providers/receipt-items.d.ts +8 -0
  137. package/dist/apps/services/payment-providers/receipt-items.js +58 -0
  138. package/dist/apps/services/payment-providers/receipt-items.js.map +1 -0
  139. package/dist/apps/services/pending-queue.d.ts +150 -0
  140. package/dist/apps/services/pending-queue.js +316 -0
  141. package/dist/apps/services/pending-queue.js.map +1 -0
  142. package/dist/apps/services/prepareSubmissionData.d.ts +2 -0
  143. package/dist/apps/services/prepareSubmissionData.js +113 -0
  144. package/dist/apps/services/prepareSubmissionData.js.map +1 -0
  145. package/dist/apps/services/query-string.d.ts +1 -0
  146. package/dist/apps/services/query-string.js +16 -0
  147. package/dist/apps/services/query-string.js.map +1 -0
  148. package/dist/apps/services/replaceInjectablesWithSubmissionValues.d.ts +3 -0
  149. package/dist/apps/services/replaceInjectablesWithSubmissionValues.js +18 -0
  150. package/dist/apps/services/replaceInjectablesWithSubmissionValues.js.map +1 -0
  151. package/dist/apps/services/schedulingHandlers.d.ts +36 -0
  152. package/dist/apps/services/schedulingHandlers.js +76 -0
  153. package/dist/apps/services/schedulingHandlers.js.map +1 -0
  154. package/dist/apps/services/server-validation.d.ts +2 -0
  155. package/dist/apps/services/server-validation.js +36 -0
  156. package/dist/apps/services/server-validation.js.map +1 -0
  157. package/dist/apps/services/serverRequest.d.ts +5 -0
  158. package/dist/apps/services/serverRequest.js +24 -0
  159. package/dist/apps/services/serverRequest.js.map +1 -0
  160. package/dist/apps/services/submit.d.ts +19 -0
  161. package/dist/apps/services/submit.js +219 -0
  162. package/dist/apps/services/submit.js.map +1 -0
  163. package/dist/apps/services/uploadAttachment.d.ts +52 -0
  164. package/dist/apps/services/uploadAttachment.js +73 -0
  165. package/dist/apps/services/uploadAttachment.js.map +1 -0
  166. package/dist/apps/services/user-token.d.ts +27 -0
  167. package/dist/apps/services/user-token.js +33 -0
  168. package/dist/apps/services/user-token.js.map +1 -0
  169. package/dist/apps/services/utils.d.ts +12 -0
  170. package/dist/apps/services/utils.js +100 -0
  171. package/dist/apps/services/utils.js.map +1 -0
  172. package/dist/apps/submission-service.d.ts +226 -0
  173. package/dist/apps/submission-service.js +425 -0
  174. package/dist/apps/submission-service.js.map +1 -0
  175. package/dist/apps/tenants.d.ts +29 -0
  176. package/dist/apps/tenants.js +127 -0
  177. package/dist/apps/tenants.js.map +1 -0
  178. package/dist/apps/types/form.d.ts +4 -0
  179. package/dist/apps/types/form.js +2 -0
  180. package/dist/apps/types/form.js.map +1 -0
  181. package/dist/apps/types/payments.d.ts +45 -0
  182. package/dist/apps/types/payments.js +2 -0
  183. package/dist/apps/types/payments.js.map +1 -0
  184. package/dist/apps/types/scheduling.d.ts +5 -0
  185. package/dist/apps/types/scheduling.js +2 -0
  186. package/dist/apps/types/scheduling.js.map +1 -0
  187. package/dist/apps/types/submissions.d.ts +175 -0
  188. package/dist/apps/types/submissions.js +2 -0
  189. package/dist/apps/types/submissions.js.map +1 -0
  190. package/dist/components/CustomAccordion.d.ts +3 -3
  191. package/dist/components/Lists.d.ts +4 -1
  192. package/dist/components/formStore/display/ElementDisplay.js +2 -2
  193. package/dist/components/formStore/display/ElementDisplay.js.map +1 -1
  194. package/dist/components/formStore/useFormStoreTableContext.d.ts +2 -2
  195. package/dist/components/mfa/MultiFactorAuthentication.d.ts +1 -1
  196. package/dist/components/renderer/LookupNotification.js +1 -1
  197. package/dist/components/renderer/LookupNotification.js.map +1 -1
  198. package/dist/form-elements/FormElementAutocomplete.js +1 -1
  199. package/dist/form-elements/FormElementAutocomplete.js.map +1 -1
  200. package/dist/hooks/attachments/useAttachment.js +1 -1
  201. package/dist/hooks/attachments/useAttachment.js.map +1 -1
  202. package/dist/index.d.ts +1 -0
  203. package/dist/index.js +2 -0
  204. package/dist/index.js.map +1 -1
  205. package/dist/services/download-file.js +1 -1
  206. package/dist/services/download-file.js.map +1 -1
  207. package/dist/styles.css +208 -204
  208. package/package.json +42 -34
@@ -0,0 +1,236 @@
1
+ import { getRequest, HTTPError, deleteRequest } from '../fetch';
2
+ import { isLoggedIn } from '../../auth-service';
3
+ import { getDeviceInformation } from '../getDeviceInformation';
4
+ import OneBlinkAppsError from '../errors/oneBlinkAppsError';
5
+ import tenants from '../../tenants';
6
+ import { getUserToken } from '../user-token';
7
+ import Sentry from '../../Sentry';
8
+ import prepareSubmissionData from '../prepareSubmissionData';
9
+ import generateOneBlinkUploader from '../generateOneBlinkUploader';
10
+ import { OneBlinkStorageError } from '@oneblink/storage';
11
+ import generateOneBlinkDownloader from '../generateOneBlinkDownloader';
12
+ async function uploadDraftData(draftSubmission, onProgress, abortSignal) {
13
+ var _a, _b, _c, _d;
14
+ try {
15
+ const submission = await prepareSubmissionData(draftSubmission);
16
+ const oneblinkUploader = generateOneBlinkUploader();
17
+ const userToken = getUserToken();
18
+ console.log('Attempting to upload draft data');
19
+ return await oneblinkUploader.uploadFormSubmissionDraft({
20
+ submission,
21
+ definition: draftSubmission.definition,
22
+ device: getDeviceInformation(),
23
+ userToken: userToken || undefined,
24
+ previousFormSubmissionApprovalId: draftSubmission.previousFormSubmissionApprovalId,
25
+ jobId: draftSubmission.jobId,
26
+ formsAppId: draftSubmission.formsAppId,
27
+ externalId: draftSubmission.externalId,
28
+ taskId: (_a = draftSubmission.taskCompletion) === null || _a === void 0 ? void 0 : _a.task.taskId,
29
+ taskActionId: (_b = draftSubmission.taskCompletion) === null || _b === void 0 ? void 0 : _b.taskAction.taskActionId,
30
+ taskGroupInstanceId: (_d = (_c = draftSubmission.taskCompletion) === null || _c === void 0 ? void 0 : _c.taskGroupInstance) === null || _d === void 0 ? void 0 : _d.taskGroupInstanceId,
31
+ formSubmissionDraftId: draftSubmission.formSubmissionDraftId,
32
+ createdAt: draftSubmission.createdAt,
33
+ title: draftSubmission.title,
34
+ lastElementUpdated: draftSubmission.lastElementUpdated,
35
+ sectionState: draftSubmission.sectionState,
36
+ previousElapsedDurationSeconds: draftSubmission.previousElapsedDurationSeconds,
37
+ onProgress,
38
+ abortSignal,
39
+ });
40
+ }
41
+ catch (error) {
42
+ console.warn('Error occurred while attempting to upload draft data', error);
43
+ Sentry.captureException(error);
44
+ if (error instanceof OneBlinkStorageError) {
45
+ switch (error.httpStatusCode) {
46
+ case 401: {
47
+ throw new OneBlinkAppsError('You cannot save drafts until you have logged in. Please login and try again.', {
48
+ originalError: error,
49
+ requiresLogin: true,
50
+ httpStatusCode: error.httpStatusCode,
51
+ });
52
+ }
53
+ case 403: {
54
+ throw new OneBlinkAppsError('You do not have access to drafts for this application. Please contact your administrator to gain the correct level of access.', {
55
+ originalError: error,
56
+ requiresAccessRequest: true,
57
+ httpStatusCode: error.httpStatusCode,
58
+ });
59
+ }
60
+ case 400:
61
+ case 404: {
62
+ throw new OneBlinkAppsError('We could not find the application your attempting upload a draft for. Please contact your administrator to ensure your application configuration has been completed successfully.', {
63
+ originalError: error,
64
+ title: 'Unknown Application',
65
+ httpStatusCode: error.httpStatusCode,
66
+ });
67
+ }
68
+ }
69
+ }
70
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
71
+ originalError: error instanceof Error ? error : undefined,
72
+ });
73
+ }
74
+ }
75
+ async function getFormSubmissionDrafts(formsAppId, abortSignal) {
76
+ if (!isLoggedIn()) {
77
+ console.log('Could not retrieve drafts from API as the current user is not logged in.');
78
+ return [];
79
+ }
80
+ const url = new URL('/form-submission-drafts', tenants.current.apiOrigin);
81
+ url.searchParams.append('formsAppId', formsAppId.toString());
82
+ url.searchParams.append('isSubmitted', 'false');
83
+ console.log('Attempting to retrieve drafts from API', url.href);
84
+ try {
85
+ const { formSubmissionDrafts } = await getRequest(url.href, abortSignal);
86
+ return formSubmissionDrafts;
87
+ }
88
+ catch (err) {
89
+ console.warn('Error occurred while attempting to retrieve drafts from API', err);
90
+ if (err instanceof OneBlinkAppsError) {
91
+ throw err;
92
+ }
93
+ const error = err;
94
+ switch (error.status) {
95
+ case 401: {
96
+ throw new OneBlinkAppsError('You cannot retrieve your drafts until you have logged in. Please login and try again.', {
97
+ originalError: error,
98
+ httpStatusCode: error.status,
99
+ requiresLogin: true,
100
+ });
101
+ }
102
+ case 403: {
103
+ throw new OneBlinkAppsError('You do not have access to drafts for this application. Please contact your administrator to gain the correct level of access.', {
104
+ originalError: error,
105
+ httpStatusCode: error.status,
106
+ requiresAccessRequest: true,
107
+ });
108
+ }
109
+ case 400:
110
+ case 404: {
111
+ throw new OneBlinkAppsError('We could not find the application your attempting retrieve drafts for. Please contact your administrator to ensure your application configuration has been completed successfully.', {
112
+ originalError: error,
113
+ title: 'Error Syncing Drafts',
114
+ httpStatusCode: error.status,
115
+ });
116
+ }
117
+ default: {
118
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
119
+ originalError: error,
120
+ });
121
+ }
122
+ }
123
+ }
124
+ }
125
+ async function downloadDraftData(formSubmissionDraftVersionId, abortSignal) {
126
+ try {
127
+ console.log('Attempting to download draft form data:', {
128
+ formSubmissionDraftVersionId,
129
+ });
130
+ const oneblinkDownloader = generateOneBlinkDownloader();
131
+ const data = await oneblinkDownloader.downloadDraftSubmission({
132
+ formSubmissionDraftVersionId,
133
+ abortSignal,
134
+ });
135
+ if (!data) {
136
+ throw new OneBlinkAppsError("Data has been removed based on your administrator's draft data retention policy.", {
137
+ title: 'Draft Data Unavailable',
138
+ });
139
+ }
140
+ return data;
141
+ }
142
+ catch (error) {
143
+ console.error('Error occurred while attempting to download draft data', error);
144
+ if (error instanceof OneBlinkAppsError) {
145
+ throw error;
146
+ }
147
+ Sentry.captureException(error);
148
+ if (error instanceof OneBlinkStorageError) {
149
+ switch (error.httpStatusCode) {
150
+ case 400: {
151
+ throw new OneBlinkAppsError(error.message, {
152
+ originalError: error,
153
+ title: 'Invalid Request',
154
+ httpStatusCode: error.httpStatusCode,
155
+ });
156
+ }
157
+ case 401: {
158
+ throw new OneBlinkAppsError('You cannot retrieve draft data until you have logged in. Please login and try again.', {
159
+ originalError: error,
160
+ httpStatusCode: error.httpStatusCode,
161
+ requiresLogin: true,
162
+ });
163
+ }
164
+ case 403: {
165
+ throw new OneBlinkAppsError('You do not have access to drafts for this application. Please contact your administrator to gain the correct level of access.', {
166
+ originalError: error,
167
+ httpStatusCode: error.httpStatusCode,
168
+ requiresAccessRequest: true,
169
+ });
170
+ }
171
+ case 404: {
172
+ throw new OneBlinkAppsError('We could not find the draft your attempting retrieve. Please contact your administrator to ensure your application configuration has been completed successfully.', {
173
+ originalError: error,
174
+ title: 'Unknown Draft',
175
+ httpStatusCode: error.httpStatusCode,
176
+ });
177
+ }
178
+ }
179
+ }
180
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
181
+ title: 'Unexpected Error',
182
+ originalError: error instanceof Error ? error : undefined,
183
+ httpStatusCode: error instanceof OneBlinkStorageError
184
+ ? error.httpStatusCode
185
+ : undefined,
186
+ });
187
+ }
188
+ }
189
+ async function deleteFormSubmissionDraft(formSubmissionDraftId, abortSignal) {
190
+ const url = `${tenants.current.apiOrigin}/form-submission-drafts/${formSubmissionDraftId}`;
191
+ console.log('Attempting to delete form submission draft remotely', url);
192
+ try {
193
+ await deleteRequest(url, abortSignal);
194
+ }
195
+ catch (error) {
196
+ console.warn('Error occurred while attempting to delete a draft from API', error);
197
+ if (error instanceof OneBlinkAppsError) {
198
+ throw error;
199
+ }
200
+ Sentry.captureException(error);
201
+ if (error instanceof HTTPError) {
202
+ switch (error.status) {
203
+ case 401: {
204
+ throw new OneBlinkAppsError('You cannot delete drafts until you have logged in. Please login and try again.', {
205
+ originalError: error,
206
+ httpStatusCode: error.status,
207
+ requiresLogin: true,
208
+ });
209
+ }
210
+ case 403: {
211
+ throw new OneBlinkAppsError('You do not have access to drafts for this application. Please contact your administrator to gain the correct level of access.', {
212
+ originalError: error,
213
+ httpStatusCode: error.status,
214
+ requiresAccessRequest: true,
215
+ });
216
+ }
217
+ case 400: {
218
+ throw new OneBlinkAppsError(error.message, {
219
+ originalError: error,
220
+ title: 'Invalid Request',
221
+ httpStatusCode: error.status,
222
+ });
223
+ }
224
+ case 404: {
225
+ console.warn('Remote draft does not exist, we will assume it has already been deleted.', formSubmissionDraftId, error);
226
+ return;
227
+ }
228
+ }
229
+ }
230
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
231
+ originalError: error,
232
+ });
233
+ }
234
+ }
235
+ export { uploadDraftData, getFormSubmissionDrafts, downloadDraftData, deleteFormSubmissionDraft, };
236
+ //# sourceMappingURL=drafts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drafts.js","sourceRoot":"","sources":["../../../../src/apps/services/api/drafts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,iBAAiB,MAAM,6BAA6B,CAAA;AAC3D,OAAO,OAAO,MAAM,eAAe,CAAA;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,MAAM,MAAM,cAAc,CAAA;AACjC,OAAO,qBAAqB,MAAM,0BAA0B,CAAA;AAE5D,OAAO,wBAAwB,MAAM,6BAA6B,CAAA;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,0BAA0B,MAAM,+BAA+B,CAAA;AAEtE,KAAK,UAAU,eAAe,CAC5B,eAAgC,EAChC,UAA6B,EAC7B,WAAyB;;IAEzB,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,MAAM,qBAAqB,CAAC,eAAe,CAAC,CAAA;QAC/D,MAAM,gBAAgB,GAAG,wBAAwB,EAAE,CAAA;QACnD,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;QAChC,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAA;QAC9C,OAAO,MAAM,gBAAgB,CAAC,yBAAyB,CAAC;YACtD,UAAU;YACV,UAAU,EAAE,eAAe,CAAC,UAAU;YACtC,MAAM,EAAE,oBAAoB,EAAE;YAC9B,SAAS,EAAE,SAAS,IAAI,SAAS;Y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,CAAC,CAAC,CAAC;oBACT,MAAM,IAAI,iBAAiB,CACzB,+HAA+H,EAC/H;wBACE,aAAa,EAAE,KAAK;wBACpB,cAAc,EAAE,KAAK,CAAC,MAAM;wBAC5B,qBAAqB,EAAE,IAAI;qBAC5B,CACF,CAAA;gBACH,CAAC;gBACD,KAAK,GAAG,CAAC,CAAC,CAAC;oBACT,MAAM,IAAI,iBAAiB,CAAC,KAAK,CAAC,OAAO,EAAE;wBACzC,aAAa,EAAE,KAAK;wBACpB,KAAK,EAAE,iBAAiB;wBACxB,cAAc,EAAE,KAAK,CAAC,MAAM;qBAC7B,CAAC,CAAA;gBACJ,CAAC;gBACD,KAAK,GAAG,CAAC,CAAC,CAAC;oBACT,OAAO,CAAC,IAAI,CACV,0EAA0E,EAC1E,qBAAqB,EACrB,KAAK,CACN,CAAA;oBACD,OAAM;gBACR,CAAC;YACH,CAAC;QACH,CAAC;QAED,MAAM,IAAI,iBAAiB,CACzB,gFAAgF,EAChF;YACE,aAAa,EAAE,KAAc;SAC9B,CACF,CAAA;IACH,CAAC;AACH,CAAC;AAED,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,iBAAiB,EACjB,yBAAyB,GAC1B,CAAA","sourcesContent":["import { SubmissionTypes } from '@oneblink/types'\nimport { getRequest, HTTPError, deleteRequest } from '../fetch'\nimport { isLoggedIn } from '../../auth-service'\nimport { getDeviceInformation } from '../getDeviceInformation'\nimport OneBlinkAppsError from '../errors/oneBlinkAppsError'\nimport tenants from '../../tenants'\nimport { getUserToken } from '../user-token'\nimport Sentry from '../../Sentry'\nimport prepareSubmissionData from '../prepareSubmissionData'\nimport { DraftSubmission, ProgressListener } from '../../types/submissions'\nimport generateOneBlinkUploader from '../generateOneBlinkUploader'\nimport { OneBlinkStorageError } from '@oneblink/storage'\nimport generateOneBlinkDownloader from '../generateOneBlinkDownloader'\n\nasync function uploadDraftData(\n draftSubmission: DraftSubmission,\n onProgress?: ProgressListener,\n abortSignal?: AbortSignal,\n) {\n try {\n const submission = await prepareSubmissionData(draftSubmission)\n const oneblinkUploader = generateOneBlinkUploader()\n const userToken = getUserToken()\n console.log('Attempting to upload draft data')\n return await oneblinkUploader.uploadFormSubmissionDraft({\n submission,\n definition: draftSubmission.definition,\n device: getDeviceInformation(),\n userToken: userToken || undefined,\n previousFormSubmissionApprovalId:\n draftSubmission.previousFormSubmissionApprovalId,\n jobId: draftSubmission.jobId,\n formsAppId: draftSubmission.formsAppId,\n externalId: draftSubmission.externalId,\n taskId: draftSubmission.taskCompletion?.task.taskId,\n taskActionId: draftSubmission.taskCompletion?.taskAction.taskActionId,\n taskGroupInstanceId:\n draftSubmission.taskCompletion?.taskGroupInstance?.taskGroupInstanceId,\n formSubmissionDraftId: draftSubmission.formSubmissionDraftId,\n createdAt: draftSubmission.createdAt,\n title: draftSubmission.title,\n lastElementUpdated: draftSubmission.lastElementUpdated,\n sectionState: draftSubmission.sectionState,\n previousElapsedDurationSeconds:\n draftSubmission.previousElapsedDurationSeconds,\n onProgress,\n abortSignal,\n })\n } catch (error) {\n console.warn('Error occurred while attempting to upload draft data', error)\n Sentry.captureException(error)\n if (error instanceof OneBlinkStorageError) {\n switch (error.httpStatusCode) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot save drafts until you have logged in. 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 drafts for this application. 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(\n 'We could not find the application your attempting upload a draft for. Please contact your administrator to ensure your application configuration has been completed successfully.',\n {\n originalError: error,\n title: 'Unknown Application',\n httpStatusCode: error.httpStatusCode,\n },\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 },\n )\n }\n}\n\nasync function getFormSubmissionDrafts(\n formsAppId: number,\n abortSignal?: AbortSignal,\n): Promise<SubmissionTypes.FormSubmissionDraft[]> {\n if (!isLoggedIn()) {\n console.log(\n 'Could not retrieve drafts from API as the current user is not logged in.',\n )\n return []\n }\n\n const url = new URL('/form-submission-drafts', tenants.current.apiOrigin)\n url.searchParams.append('formsAppId', formsAppId.toString())\n url.searchParams.append('isSubmitted', 'false')\n console.log('Attempting to retrieve drafts from API', url.href)\n\n try {\n const { formSubmissionDrafts } = await getRequest<{\n formSubmissionDrafts: SubmissionTypes.FormSubmissionDraft[]\n }>(url.href, abortSignal)\n return formSubmissionDrafts\n } catch (err) {\n console.warn(\n 'Error occurred while attempting to retrieve drafts from API',\n err,\n )\n if (err instanceof OneBlinkAppsError) {\n throw err\n }\n\n const error = err as HTTPError\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot retrieve your drafts until you have logged in. Please login and try again.',\n {\n originalError: error,\n httpStatusCode: error.status,\n requiresLogin: true,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to drafts for this application. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n httpStatusCode: error.status,\n requiresAccessRequest: true,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(\n 'We could not find the application your attempting retrieve drafts for. Please contact your administrator to ensure your application configuration has been completed successfully.',\n {\n originalError: error,\n title: 'Error Syncing Drafts',\n httpStatusCode: error.status,\n },\n )\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n },\n )\n }\n }\n }\n}\n\nasync function downloadDraftData(\n formSubmissionDraftVersionId: string,\n abortSignal?: AbortSignal,\n) {\n try {\n console.log('Attempting to download draft form data:', {\n formSubmissionDraftVersionId,\n })\n const oneblinkDownloader = generateOneBlinkDownloader()\n const data = await oneblinkDownloader.downloadDraftSubmission({\n formSubmissionDraftVersionId,\n abortSignal,\n })\n if (!data) {\n throw new OneBlinkAppsError(\n \"Data has been removed based on your administrator's draft data retention policy.\",\n {\n title: 'Draft Data Unavailable',\n },\n )\n }\n return data\n } catch (error) {\n console.error(\n 'Error occurred while attempting to download draft data',\n error,\n )\n\n if (error instanceof OneBlinkAppsError) {\n throw error\n }\n\n Sentry.captureException(error)\n\n if (error instanceof OneBlinkStorageError) {\n switch (error.httpStatusCode) {\n case 400: {\n throw new OneBlinkAppsError(error.message, {\n originalError: error,\n title: 'Invalid Request',\n httpStatusCode: error.httpStatusCode,\n })\n }\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot retrieve draft data until you have logged in. Please login and try again.',\n {\n originalError: error,\n httpStatusCode: error.httpStatusCode,\n requiresLogin: true,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to drafts for this application. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n httpStatusCode: error.httpStatusCode,\n requiresAccessRequest: true,\n },\n )\n }\n case 404: {\n throw new OneBlinkAppsError(\n 'We could not find the draft your attempting retrieve. Please contact your administrator to ensure your application configuration has been completed successfully.',\n {\n originalError: error,\n title: 'Unknown Draft',\n httpStatusCode: error.httpStatusCode,\n },\n )\n }\n }\n }\n\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n title: 'Unexpected Error',\n originalError: error instanceof Error ? error : undefined,\n httpStatusCode:\n error instanceof OneBlinkStorageError\n ? error.httpStatusCode\n : undefined,\n },\n )\n }\n}\n\nasync function deleteFormSubmissionDraft(\n formSubmissionDraftId: string,\n abortSignal?: AbortSignal,\n) {\n const url = `${tenants.current.apiOrigin}/form-submission-drafts/${formSubmissionDraftId}`\n console.log('Attempting to delete form submission draft remotely', url)\n try {\n await deleteRequest(url, abortSignal)\n } catch (error) {\n console.warn(\n 'Error occurred while attempting to delete a draft from API',\n error,\n )\n if (error instanceof OneBlinkAppsError) {\n throw error\n }\n\n Sentry.captureException(error)\n\n if (error instanceof HTTPError) {\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot delete drafts until you have logged in. Please login and try again.',\n {\n originalError: error,\n httpStatusCode: error.status,\n requiresLogin: true,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to drafts for this application. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n httpStatusCode: error.status,\n requiresAccessRequest: true,\n },\n )\n }\n case 400: {\n throw new OneBlinkAppsError(error.message, {\n originalError: error,\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n case 404: {\n console.warn(\n 'Remote draft does not exist, we will assume it has already been deleted.',\n formSubmissionDraftId,\n error,\n )\n return\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 as Error,\n },\n )\n }\n}\n\nexport {\n uploadDraftData,\n getFormSubmissionDrafts,\n downloadDraftData,\n deleteFormSubmissionDraft,\n}\n"]}
@@ -0,0 +1,3 @@
1
+ declare function createNotificationsSubscription(formsAppId: number, subscription: PushSubscription): Promise<void>;
2
+ declare function deleteNotificationsSubscription(formsAppId: number, subscription: PushSubscription): Promise<void>;
3
+ export { createNotificationsSubscription, deleteNotificationsSubscription };
@@ -0,0 +1,60 @@
1
+ import { postRequest } from '../fetch';
2
+ import OneBlinkAppsError from '../errors/oneBlinkAppsError';
3
+ import tenants from '../../tenants';
4
+ import { isOffline } from '../../offline-service';
5
+ import Sentry from '../../Sentry';
6
+ const subscriptionErrorHandler = (error) => {
7
+ Sentry.captureException(error);
8
+ console.warn('Error POSTing notifications subscription', error);
9
+ if (isOffline()) {
10
+ throw new OneBlinkAppsError('You are currently offline, please connect to the internet and try again.', {
11
+ originalError: error,
12
+ isOffline: true,
13
+ });
14
+ }
15
+ switch (error.status) {
16
+ case 401: {
17
+ throw new OneBlinkAppsError('You cannot subscribe to notifications until you logged in. Please login and try again.', {
18
+ originalError: error,
19
+ httpStatusCode: error.status,
20
+ requiresLogin: true,
21
+ });
22
+ }
23
+ case 403: {
24
+ throw new OneBlinkAppsError('You do not have access to subscribe to notifications in the app. Please contact your administrator to gain the correct level of access.', {
25
+ originalError: error,
26
+ httpStatusCode: error.status,
27
+ requiresAccessRequest: true,
28
+ });
29
+ }
30
+ case 400:
31
+ case 404: {
32
+ throw new OneBlinkAppsError('We could not find your account. Please contact your administrator to ensure your account has been completed successfully.', {
33
+ originalError: error,
34
+ httpStatusCode: error.status,
35
+ });
36
+ }
37
+ default: {
38
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
39
+ originalError: error,
40
+ httpStatusCode: error.status,
41
+ });
42
+ }
43
+ }
44
+ };
45
+ async function createNotificationsSubscription(formsAppId, subscription) {
46
+ const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/notifications/subscribe`;
47
+ console.log('Attempting to create notifications subscription', url);
48
+ await postRequest(url, {
49
+ subscription,
50
+ }).catch(subscriptionErrorHandler);
51
+ }
52
+ async function deleteNotificationsSubscription(formsAppId, subscription) {
53
+ const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/notifications/unsubscribe`;
54
+ console.log('Attempting to delete notifications subscription', url);
55
+ await postRequest(url, {
56
+ subscription,
57
+ }).catch(subscriptionErrorHandler);
58
+ }
59
+ export { createNotificationsSubscription, deleteNotificationsSubscription };
60
+ //# sourceMappingURL=notifications.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notifications.js","sourceRoot":"","sources":["../../../../src/apps/services/api/notifications.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,WAAW,EAAE,MAAM,UAAU,CAAA;AACjD,OAAO,iBAAiB,MAAM,6BAA6B,CAAA;AAC3D,OAAO,OAAO,MAAM,eAAe,CAAA;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,MAAM,MAAM,cAAc,CAAA;AAEjC,MAAM,wBAAwB,GAAG,CAAC,KAAgB,EAAE,EAAE;IAC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,CAAA;IAC3F,OAAO,CAAC,GAAG,CAAC,iDAAiD,EAAE,GAAG,CAAC,CAAA;IACnE,MAAM,WAAW,CAAC,GAAG,EAAE;QACrB,YAAY;KACb,CAAC,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAA;AACpC,CAAC;AAED,KAAK,UAAU,+BAA+B,CAC5C,UAAkB,EAClB,YAA8B;IAE9B,MAAM,GAAG,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,eAAe,UAAU,4BAA4B,CAAA;IAC7F,OAAO,CAAC,GAAG,CAAC,iDAAiD,EAAE,GAAG,CAAC,CAAA;IACnE,MAAM,WAAW,CAAC,GAAG,EAAE;QACrB,YAAY;KACb,CAAC,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAA;AACpC,CAAC;AAED,OAAO,EAAE,+BAA+B,EAAE,+BAA+B,EAAE,CAAA","sourcesContent":["import { HTTPError, postRequest } from '../fetch'\nimport OneBlinkAppsError from '../errors/oneBlinkAppsError'\nimport tenants from '../../tenants'\nimport { isOffline } from '../../offline-service'\nimport Sentry from '../../Sentry'\n\nconst subscriptionErrorHandler = (error: HTTPError) => {\n Sentry.captureException(error)\n console.warn('Error POSTing notifications subscription', error)\n if (isOffline()) {\n throw new OneBlinkAppsError(\n 'You are currently offline, please connect to the internet and try again.',\n {\n originalError: error,\n isOffline: true,\n },\n )\n }\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot subscribe to notifications until you logged in. Please login and try again.',\n {\n originalError: error,\n httpStatusCode: error.status,\n requiresLogin: true,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to subscribe to notifications in the app. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n httpStatusCode: error.status,\n requiresAccessRequest: true,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(\n 'We could not find your account. Please contact your administrator to ensure your account has been completed successfully.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n}\n\nasync function createNotificationsSubscription(\n formsAppId: number,\n subscription: PushSubscription,\n): Promise<void> {\n const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/notifications/subscribe`\n console.log('Attempting to create notifications subscription', url)\n await postRequest(url, {\n subscription,\n }).catch(subscriptionErrorHandler)\n}\n\nasync function deleteNotificationsSubscription(\n formsAppId: number,\n subscription: PushSubscription,\n): Promise<void> {\n const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/notifications/unsubscribe`\n console.log('Attempting to delete notifications subscription', url)\n await postRequest(url, {\n subscription,\n }).catch(subscriptionErrorHandler)\n}\n\nexport { createNotificationsSubscription, deleteNotificationsSubscription }\n"]}
@@ -0,0 +1,23 @@
1
+ import { SubmissionEventTypes, SubmissionTypes } from '@oneblink/types';
2
+ import { BasePaymentConfigurationPayload, PaymentProvider } from '../../types/payments';
3
+ import { NewFormSubmission } from '../../submission-service';
4
+ declare function getCustomFormPaymentConfiguration<T>(path: string, { integrationEnvironmentId, }: {
5
+ integrationEnvironmentId: string;
6
+ }, abortSignal?: AbortSignal): Promise<T>;
7
+ declare function completeWestpacQuickStreamTransaction(formId: number, payload: {
8
+ formSubmissionPaymentId: string;
9
+ singleUseTokenId: string;
10
+ integrationEnvironmentId: string;
11
+ customerReferenceNumber: string;
12
+ principalAmount: number;
13
+ recaptcha: NonNullable<NewFormSubmission['recaptchas']>[number];
14
+ }, abortSignal?: AbortSignal): Promise<{
15
+ formSubmissionPayment: SubmissionTypes.FormSubmissionPayment;
16
+ }>;
17
+ declare function cancelWestpacQuickStreamPayment(formId: number, formSubmissionPaymentId: string, abortSignal?: AbortSignal): Promise<void>;
18
+ declare function generatePaymentConfiguration(paymentProvider: PaymentProvider<SubmissionEventTypes.FormPaymentEvent>, basePayload: BasePaymentConfigurationPayload): Promise<{
19
+ hostedFormUrl: string;
20
+ }>;
21
+ declare const verifyPaymentTransaction: <T>(path: string, payload: unknown) => Promise<T>;
22
+ declare const acknowledgeCPPayTransaction: (formId: number, payload: unknown) => Promise<void>;
23
+ export { generatePaymentConfiguration, acknowledgeCPPayTransaction, verifyPaymentTransaction, getCustomFormPaymentConfiguration, completeWestpacQuickStreamTransaction, cancelWestpacQuickStreamPayment, };
@@ -0,0 +1,235 @@
1
+ import { deleteRequest, getRequest, postRequest } from '../fetch';
2
+ import OneBlinkAppsError from '../errors/oneBlinkAppsError';
3
+ import tenants from '../../tenants';
4
+ import Sentry from '../../Sentry';
5
+ import { isOffline } from '../../offline-service';
6
+ async function getCustomFormPaymentConfiguration(path, { integrationEnvironmentId, }, abortSignal) {
7
+ const url = new URL(path, tenants.current.apiOrigin);
8
+ url.searchParams.append('integrationEnvironmentId', integrationEnvironmentId);
9
+ console.log('Attempting to get payment configuration', url.href);
10
+ try {
11
+ return await getRequest(url.href, abortSignal);
12
+ }
13
+ catch (err) {
14
+ const error = err;
15
+ Sentry.captureException(error);
16
+ console.warn('Error occurred while attempting to retrieve configuration for payment', error);
17
+ switch (error.status) {
18
+ case 401: {
19
+ throw new OneBlinkAppsError('You cannot retrieve payment configuration until you have logged in. Please login and try again.', {
20
+ originalError: error,
21
+ httpStatusCode: error.status,
22
+ requiresLogin: true,
23
+ });
24
+ }
25
+ case 403: {
26
+ throw new OneBlinkAppsError('You do not have access retrieve payment configuration. Please contact your administrator to gain the correct level of access.', {
27
+ originalError: error,
28
+ httpStatusCode: error.status,
29
+ requiresAccessRequest: true,
30
+ });
31
+ }
32
+ case 400:
33
+ case 404: {
34
+ throw new OneBlinkAppsError('We could not find the payment configuration. Please contact your administrator to ensure your application configuration has been completed successfully.', {
35
+ originalError: error,
36
+ httpStatusCode: error.status,
37
+ });
38
+ }
39
+ default: {
40
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
41
+ originalError: error,
42
+ httpStatusCode: error.status,
43
+ });
44
+ }
45
+ }
46
+ }
47
+ }
48
+ async function completeWestpacQuickStreamTransaction(formId, payload, abortSignal) {
49
+ const url = `${tenants.current.apiOrigin}/forms/${formId}/westpac-quick-stream-transaction`;
50
+ console.log('Attempting to complete Westpac QuickStream transaction', url);
51
+ try {
52
+ return await postRequest(url, payload, abortSignal);
53
+ }
54
+ catch (err) {
55
+ const error = err;
56
+ Sentry.captureException(error);
57
+ console.warn('Error occurred while attempting to generate configuration for payment', error);
58
+ switch (error.status) {
59
+ case 401: {
60
+ throw new OneBlinkAppsError('You cannot complete transactions until you have logged in. Please login and try again.', {
61
+ originalError: error,
62
+ httpStatusCode: error.status,
63
+ requiresLogin: true,
64
+ });
65
+ }
66
+ case 403: {
67
+ throw new OneBlinkAppsError('You do not have access complete transactions. Please contact your administrator to gain the correct level of access.', {
68
+ originalError: error,
69
+ httpStatusCode: error.status,
70
+ requiresAccessRequest: true,
71
+ });
72
+ }
73
+ case 400:
74
+ case 404: {
75
+ throw new OneBlinkAppsError('We could not find the configuration required to complete a transaction. Please contact your administrator to ensure your application configuration has been completed successfully.', {
76
+ originalError: error,
77
+ httpStatusCode: error.status,
78
+ });
79
+ }
80
+ default: {
81
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
82
+ originalError: error,
83
+ httpStatusCode: error.status,
84
+ });
85
+ }
86
+ }
87
+ }
88
+ }
89
+ async function cancelWestpacQuickStreamPayment(formId, formSubmissionPaymentId, abortSignal) {
90
+ try {
91
+ const url = `${tenants.current.apiOrigin}/forms/${formId}/westpac-quick-stream-payment/${formSubmissionPaymentId}`;
92
+ console.log('Attempting to cancel Westpac QuickStream payment', url);
93
+ return await deleteRequest(url, abortSignal);
94
+ }
95
+ catch (error) {
96
+ Sentry.captureException(error);
97
+ const httpError = error;
98
+ if (isOffline()) {
99
+ throw new OneBlinkAppsError('You are currently offline, please connect to the internet to continue', {
100
+ originalError: httpError,
101
+ isOffline: true,
102
+ });
103
+ }
104
+ switch (httpError.status) {
105
+ case 400:
106
+ case 404: {
107
+ throw new OneBlinkAppsError('We could not find the form you are looking for. Please contact support if the problem persists.', {
108
+ originalError: httpError,
109
+ title: 'Unknown Form',
110
+ httpStatusCode: httpError.status,
111
+ });
112
+ }
113
+ default: {
114
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
115
+ originalError: httpError,
116
+ httpStatusCode: httpError.status,
117
+ });
118
+ }
119
+ }
120
+ }
121
+ }
122
+ function generatePaymentConfiguration(paymentProvider, basePayload) {
123
+ const { path, payload } = paymentProvider.preparePaymentConfiguration(basePayload);
124
+ const url = `${tenants.current.apiOrigin}${path}`;
125
+ console.log('Attempting to generate payment configuration', url);
126
+ return postRequest(url, payload).catch((error) => {
127
+ Sentry.captureException(error);
128
+ console.warn('Error occurred while attempting to generate configuration for payment', error);
129
+ switch (error.status) {
130
+ case 401: {
131
+ throw new OneBlinkAppsError('You cannot make payments until you have logged in. Please login and try again.', {
132
+ originalError: error,
133
+ httpStatusCode: error.status,
134
+ requiresLogin: true,
135
+ });
136
+ }
137
+ case 403: {
138
+ throw new OneBlinkAppsError('You do not have access make payments. Please contact your administrator to gain the correct level of access.', {
139
+ originalError: error,
140
+ httpStatusCode: error.status,
141
+ requiresAccessRequest: true,
142
+ });
143
+ }
144
+ case 400:
145
+ case 404: {
146
+ throw new OneBlinkAppsError('We could not find the configuration required to make a payment. Please contact your administrator to ensure your application configuration has been completed successfully.', {
147
+ originalError: error,
148
+ httpStatusCode: error.status,
149
+ });
150
+ }
151
+ default: {
152
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
153
+ originalError: error,
154
+ httpStatusCode: error.status,
155
+ });
156
+ }
157
+ }
158
+ });
159
+ }
160
+ const verifyPaymentTransaction = (path, payload) => {
161
+ const url = `${tenants.current.apiOrigin}${path}`;
162
+ console.log('Attempting to verify payment transaction', url);
163
+ return postRequest(url, payload).catch((error) => {
164
+ Sentry.captureException(error);
165
+ console.warn('Error occurred while attempting to verify a transaction', error);
166
+ switch (error.status) {
167
+ case 401: {
168
+ throw new OneBlinkAppsError('You cannot verify a transaction until you have logged in. Please login and try again.', {
169
+ originalError: error,
170
+ httpStatusCode: error.status,
171
+ requiresLogin: true,
172
+ });
173
+ }
174
+ case 403: {
175
+ throw new OneBlinkAppsError('You do not have access to verify your transactions. Please contact your administrator to gain the correct level of access.', {
176
+ originalError: error,
177
+ httpStatusCode: error.status,
178
+ requiresAccessRequest: true,
179
+ });
180
+ }
181
+ case 400:
182
+ case 404: {
183
+ throw new OneBlinkAppsError('We could not find the configuration required to verify your transaction. Please contact your administrator to ensure your application configuration has been completed successfully.', {
184
+ originalError: error,
185
+ httpStatusCode: error.status,
186
+ });
187
+ }
188
+ default: {
189
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
190
+ originalError: error,
191
+ httpStatusCode: error.status,
192
+ });
193
+ }
194
+ }
195
+ });
196
+ };
197
+ const acknowledgeCPPayTransaction = async (formId, payload) => {
198
+ const url = `${tenants.current.apiOrigin}/forms/${formId}/cp-pay-acknowledge`;
199
+ console.log('Attempting to acknowledge CP Pay transaction', url);
200
+ await postRequest(url, payload).catch((error) => {
201
+ Sentry.captureException(error);
202
+ console.warn('Error occurred while attempting to acknowledge a CP Pay transaction', error);
203
+ switch (error.status) {
204
+ case 401: {
205
+ throw new OneBlinkAppsError('You cannot acknowledge a transaction until you have logged in. Please login and try again.', {
206
+ originalError: error,
207
+ httpStatusCode: error.status,
208
+ requiresLogin: true,
209
+ });
210
+ }
211
+ case 403: {
212
+ throw new OneBlinkAppsError('You do not have access to acknowledge your transactions. Please contact your administrator to gain the correct level of access.', {
213
+ originalError: error,
214
+ httpStatusCode: error.status,
215
+ requiresAccessRequest: true,
216
+ });
217
+ }
218
+ case 400:
219
+ case 404: {
220
+ throw new OneBlinkAppsError('We could not find the configuration required to acknowledge your transaction. Please contact your administrator to ensure your application configuration has been completed successfully.', {
221
+ originalError: error,
222
+ httpStatusCode: error.status,
223
+ });
224
+ }
225
+ default: {
226
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
227
+ originalError: error,
228
+ httpStatusCode: error.status,
229
+ });
230
+ }
231
+ }
232
+ });
233
+ };
234
+ export { generatePaymentConfiguration, acknowledgeCPPayTransaction, verifyPaymentTransaction, getCustomFormPaymentConfiguration, completeWestpacQuickStreamTransaction, cancelWestpacQuickStreamPayment, };
235
+ //# sourceMappingURL=payment.js.map