@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,987 @@
1
+ import OneBlinkAppsError from './services/errors/oneBlinkAppsError';
2
+ import { isOffline } from './offline-service';
3
+ import { deleteRequest, getRequest, putRequest, searchRequest, postRequest, } from './services/fetch';
4
+ import tenants from './tenants';
5
+ import Sentry from './Sentry';
6
+ /**
7
+ * Get an Object containing FormSubmissionApprovals assigned to the current user
8
+ * and the Form definitions in those approvals.
9
+ *
10
+ * #### Example
11
+ *
12
+ * ```js
13
+ * const formsAppId = 1
14
+ * const {
15
+ * formSubmissionApprovals,
16
+ * formApprovalFlowInstances,
17
+ * forms,
18
+ * formSubmissionMeta,
19
+ * } = await approvalsService.getFormSubmissionApprovals(formAppId)
20
+ * ```
21
+ *
22
+ * @param formsAppId
23
+ * @param abortSignal
24
+ * @returns
25
+ */
26
+ export async function getFormSubmissionApprovals(formsAppId, abortSignal) {
27
+ try {
28
+ return await getRequest(`${tenants.current.apiOrigin}/forms-apps/${formsAppId}/my-approvals`, abortSignal);
29
+ }
30
+ catch (err) {
31
+ Sentry.captureException(err);
32
+ console.error('Error retrieving form submission approvals', err);
33
+ const error = err;
34
+ if (isOffline()) {
35
+ throw new OneBlinkAppsError('You are currently offline and do not have a local copy of this app available, please connect to the internet and try again', {
36
+ originalError: error,
37
+ isOffline: true,
38
+ });
39
+ }
40
+ switch (error.status) {
41
+ case 401: {
42
+ throw new OneBlinkAppsError('You cannot view your pending approvals without first logging in. Please login and try again.', {
43
+ originalError: error,
44
+ requiresLogin: true,
45
+ httpStatusCode: error.status,
46
+ });
47
+ }
48
+ case 403: {
49
+ throw new OneBlinkAppsError('You do not have access to this application. Please contact your administrator to gain the correct level of access.', {
50
+ originalError: error,
51
+ requiresAccessRequest: true,
52
+ httpStatusCode: error.status,
53
+ });
54
+ }
55
+ case 400:
56
+ case 404: {
57
+ throw new OneBlinkAppsError(error.message, {
58
+ title: 'Invalid Request',
59
+ httpStatusCode: error.status,
60
+ });
61
+ }
62
+ default: {
63
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
64
+ originalError: error,
65
+ httpStatusCode: error.status,
66
+ });
67
+ }
68
+ }
69
+ }
70
+ }
71
+ /**
72
+ * Get a single FormSubmissionApproval belonging to the given id.
73
+ *
74
+ * #### Example
75
+ *
76
+ * ```js
77
+ * const formSubmissionApprovalId = 'd27966cc-128d-48a2-b681-6ad52012e113'
78
+ * const {
79
+ * formSubmissionApproval,
80
+ * formApprovalFlowInstance,
81
+ * formSubmissionMeta,
82
+ * form,
83
+ * history,
84
+ * } = await approvalsService.getFormSubmissionApproval(
85
+ * formSubmissionApprovalId,
86
+ * )
87
+ * ```
88
+ *
89
+ * @param formSubmissionApprovalId
90
+ * @param abortSignal
91
+ * @returns
92
+ */
93
+ export async function getFormSubmissionApproval(formSubmissionApprovalId, abortSignal) {
94
+ try {
95
+ const result = await getRequest(`${tenants.current.apiOrigin}/form-submission-approvals/${formSubmissionApprovalId}`, abortSignal);
96
+ return result;
97
+ }
98
+ catch (err) {
99
+ Sentry.captureException(err);
100
+ console.error('Error retrieving form submission approval', err);
101
+ const error = err;
102
+ if (isOffline()) {
103
+ throw new OneBlinkAppsError('You are currently offline and do not have a local copy of this app available, please connect to the internet and try again', {
104
+ originalError: error,
105
+ isOffline: true,
106
+ });
107
+ }
108
+ switch (error.status) {
109
+ case 401: {
110
+ throw new OneBlinkAppsError('You cannot action this pending submission without first logging in. Please login and try again.', {
111
+ originalError: error,
112
+ requiresLogin: true,
113
+ httpStatusCode: error.status,
114
+ });
115
+ }
116
+ case 403: {
117
+ throw new OneBlinkAppsError('You do not have access to this application. Please contact your administrator to gain the correct level of access.', {
118
+ originalError: error,
119
+ requiresAccessRequest: true,
120
+ httpStatusCode: error.status,
121
+ });
122
+ }
123
+ case 400:
124
+ case 404: {
125
+ throw new OneBlinkAppsError(error.message, {
126
+ title: 'Invalid Request',
127
+ httpStatusCode: error.status,
128
+ });
129
+ }
130
+ default: {
131
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
132
+ originalError: error,
133
+ httpStatusCode: error.status,
134
+ });
135
+ }
136
+ }
137
+ }
138
+ }
139
+ /**
140
+ * Update a single FormSubmissionApproval assigned to the current user.
141
+ *
142
+ * #### Example
143
+ *
144
+ * ```js
145
+ * const formSubmissionApproval = {
146
+ * id: 'd27966cc-128d-48a2-b681-6ad52012e113',
147
+ * status: 'APPROVED',
148
+ * username: 'email@example.com',
149
+ * formApprovalFlowInstanceId: 1,
150
+ * notificationEmailAddress: 'email@example.com',
151
+ * notes: 'Great work!!!',
152
+ * internalNotes: 'It was not really that great...',
153
+ * cannedResponseKey: 'my_canned_response_key',
154
+ * createdAt: '2021-02-21T22:57:56.257Z',
155
+ * updatedAt: '2021-02-21T22:57:56.257Z',
156
+ * }
157
+ * const updatedFormSubmissionApproval =
158
+ * await approvalsService.updateFormSubmissionApproval(
159
+ * formSubmissionApproval,
160
+ * )
161
+ * ```
162
+ *
163
+ * @param formSubmissionApproval
164
+ * @param abortSignal
165
+ * @returns
166
+ */
167
+ export async function updateFormSubmissionApproval(formSubmissionApproval, abortSignal) {
168
+ try {
169
+ return await putRequest(`${tenants.current.apiOrigin}/form-submission-approvals/${formSubmissionApproval.id}`, formSubmissionApproval, abortSignal);
170
+ }
171
+ catch (err) {
172
+ Sentry.captureException(err);
173
+ console.error('Error updating form submission approval', err);
174
+ const error = err;
175
+ if (isOffline()) {
176
+ throw new OneBlinkAppsError('You are currently offline, please connect to the internet and try again', {
177
+ originalError: error,
178
+ isOffline: true,
179
+ });
180
+ }
181
+ switch (error.status) {
182
+ case 401: {
183
+ throw new OneBlinkAppsError('You cannot action this pending submission without first logging in. Please login and try again.', {
184
+ originalError: error,
185
+ requiresLogin: true,
186
+ httpStatusCode: error.status,
187
+ });
188
+ }
189
+ case 403: {
190
+ throw new OneBlinkAppsError('You do not have access to this application. Please contact your administrator to gain the correct level of access.', {
191
+ originalError: error,
192
+ requiresAccessRequest: true,
193
+ httpStatusCode: error.status,
194
+ });
195
+ }
196
+ case 400:
197
+ case 404:
198
+ case 409: {
199
+ throw new OneBlinkAppsError(error.message, {
200
+ title: 'Invalid Request',
201
+ httpStatusCode: error.status,
202
+ });
203
+ }
204
+ default: {
205
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
206
+ originalError: error,
207
+ httpStatusCode: error.status,
208
+ });
209
+ }
210
+ }
211
+ }
212
+ }
213
+ /**
214
+ * @deprecated Use "reopenFormApprovalFlowInstance()" instead
215
+ * @internal
216
+ */
217
+ export const reopenFormSubmissionApproval = reopenFormApprovalFlowInstance;
218
+ /**
219
+ * As an administrator, reopen a submission that has been approved or denied.
220
+ *
221
+ * #### Example
222
+ *
223
+ * ```js
224
+ * await approvalsService.reopenFormApprovalFlowInstance({
225
+ * formApprovalFlowInstanceId: 1,
226
+ * notificationEmailAddress: 'email@example.com',
227
+ * notes: 'Great work!!!',
228
+ * internalNotes: 'It was not really that great...',
229
+ * cannedResponseKey: 'my_canned_response_key',
230
+ * })
231
+ * ```
232
+ *
233
+ * @param options
234
+ * @param abortSignal
235
+ * @returns
236
+ */
237
+ export async function reopenFormApprovalFlowInstance({ formApprovalFlowInstanceId, ...payload }, abortSignal) {
238
+ console.log('Reopening form approval flow instance', {
239
+ formApprovalFlowInstanceId,
240
+ ...payload,
241
+ });
242
+ try {
243
+ return await postRequest(`${tenants.current.apiOrigin}/form-approval-flow-instances/${formApprovalFlowInstanceId}/reopen`, payload, abortSignal);
244
+ }
245
+ catch (err) {
246
+ console.error('Error reopening form approval flow instance', err);
247
+ Sentry.captureException(err);
248
+ const error = err;
249
+ if (isOffline()) {
250
+ throw new OneBlinkAppsError('You are currently offline, please connect to the internet and try again', {
251
+ originalError: error,
252
+ isOffline: true,
253
+ });
254
+ }
255
+ switch (error.status) {
256
+ case 401: {
257
+ throw new OneBlinkAppsError('You cannot reopen this approval without first logging in. Please login and try again.', {
258
+ originalError: error,
259
+ requiresLogin: true,
260
+ httpStatusCode: error.status,
261
+ });
262
+ }
263
+ case 403: {
264
+ throw new OneBlinkAppsError('You do not have access to this approval. Please contact your administrator to gain the correct level of access.', {
265
+ originalError: error,
266
+ requiresAccessRequest: true,
267
+ httpStatusCode: error.status,
268
+ });
269
+ }
270
+ case 400:
271
+ case 404:
272
+ case 409: {
273
+ throw new OneBlinkAppsError(error.message, {
274
+ title: 'Invalid Request',
275
+ httpStatusCode: error.status,
276
+ });
277
+ }
278
+ default: {
279
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
280
+ originalError: error,
281
+ httpStatusCode: error.status,
282
+ });
283
+ }
284
+ }
285
+ }
286
+ }
287
+ /**
288
+ * As an administrator, close a submission that has been approved.
289
+ *
290
+ * #### Example
291
+ *
292
+ * ```js
293
+ * await approvalsService.closeFormApprovalFlowInstance({
294
+ * formApprovalFlowInstanceId: 1,
295
+ * notificationEmailAddress: ['email@example.com'],
296
+ * notes: 'Great work!!!',
297
+ * internalNotes: 'It was not really that great...',
298
+ * cannedResponseKey: 'my_canned_response_key',
299
+ * })
300
+ * ```
301
+ *
302
+ * @param options
303
+ * @param abortSignal
304
+ * @returns
305
+ */
306
+ export async function closeFormApprovalFlowInstance({ formApprovalFlowInstanceId, ...payload }, abortSignal) {
307
+ console.log('Closing form approval flow instance', {
308
+ formApprovalFlowInstanceId,
309
+ ...payload,
310
+ });
311
+ try {
312
+ return await postRequest(`${tenants.current.apiOrigin}/form-approval-flow-instances/${formApprovalFlowInstanceId}/close`, payload, abortSignal);
313
+ }
314
+ catch (err) {
315
+ console.log('Error closing form approval flow instance', err);
316
+ Sentry.captureException(err);
317
+ const error = err;
318
+ if (isOffline()) {
319
+ throw new OneBlinkAppsError('You are currently offline, please connect to the internet and try again', {
320
+ originalError: error,
321
+ isOffline: true,
322
+ });
323
+ }
324
+ switch (error.status) {
325
+ case 401: {
326
+ throw new OneBlinkAppsError('You cannot close this approval without first logging in. Please login and try again.', {
327
+ originalError: error,
328
+ requiresLogin: true,
329
+ httpStatusCode: error.status,
330
+ });
331
+ }
332
+ case 403: {
333
+ throw new OneBlinkAppsError('You do not have access to this approval. Please contact your administrator to gain the correct level of access.', {
334
+ originalError: error,
335
+ requiresAccessRequest: true,
336
+ httpStatusCode: error.status,
337
+ });
338
+ }
339
+ case 400:
340
+ case 404:
341
+ case 409: {
342
+ throw new OneBlinkAppsError(error.message, {
343
+ title: 'Invalid Request',
344
+ httpStatusCode: error.status,
345
+ });
346
+ }
347
+ default: {
348
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
349
+ originalError: error,
350
+ httpStatusCode: error.status,
351
+ });
352
+ }
353
+ }
354
+ }
355
+ }
356
+ export async function getFormApprovalFlows(formsAppId, abortSignal) {
357
+ try {
358
+ return await getRequest(`${tenants.current.apiOrigin}/forms-apps/${formsAppId}/form-approval-flows`, abortSignal);
359
+ }
360
+ catch (err) {
361
+ Sentry.captureException(err);
362
+ console.error('Error retrieving form approval flows', err);
363
+ const error = err;
364
+ if (isOffline()) {
365
+ throw new OneBlinkAppsError('You are currently offline, please connect to the internet and try again', {
366
+ originalError: error,
367
+ isOffline: true,
368
+ });
369
+ }
370
+ switch (error.status) {
371
+ case 401: {
372
+ throw new OneBlinkAppsError('You cannot access form approval flows without first logging in. Please login and try again.', {
373
+ originalError: error,
374
+ requiresLogin: true,
375
+ httpStatusCode: error.status,
376
+ });
377
+ }
378
+ case 403: {
379
+ throw new OneBlinkAppsError('You do not have access to this application. Please contact your administrator to gain the correct level of access.', {
380
+ originalError: error,
381
+ requiresAccessRequest: true,
382
+ httpStatusCode: error.status,
383
+ });
384
+ }
385
+ case 400:
386
+ case 404: {
387
+ throw new OneBlinkAppsError(error.message, {
388
+ title: 'Invalid Request',
389
+ httpStatusCode: error.status,
390
+ });
391
+ }
392
+ default: {
393
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
394
+ originalError: error,
395
+ httpStatusCode: error.status,
396
+ });
397
+ }
398
+ }
399
+ }
400
+ }
401
+ /**
402
+ * Get an Object containing approvals for the app regardless of approval groups
403
+ * and meta for paging. Must be an Approvals Administrator.
404
+ *
405
+ * #### Example
406
+ *
407
+ * ```js
408
+ * const formsAppId = 1
409
+ * const limit = 50
410
+ * const offset = 0
411
+ * const { approvals, meta } =
412
+ * await approvalsService.getFormSubmissionAdministrationApprovals({
413
+ * formAppId,
414
+ * limit,
415
+ * offset,
416
+ * })
417
+ * ```
418
+ *
419
+ * @param options
420
+ * @param abortSignal
421
+ * @returns
422
+ */
423
+ export async function getFormSubmissionAdministrationApprovals({ formsAppId, ...rest }, abortSignal) {
424
+ try {
425
+ return await searchRequest(`${tenants.current.apiOrigin}/forms-apps/${formsAppId}/approvals`, {
426
+ ...rest,
427
+ }, abortSignal);
428
+ }
429
+ catch (err) {
430
+ Sentry.captureException(err);
431
+ console.error('Error retrieving administrator form submission approvals', err);
432
+ const error = err;
433
+ if (isOffline()) {
434
+ throw new OneBlinkAppsError('You are currently offline and do not have a local copy of this app available, please connect to the internet and try again', {
435
+ originalError: error,
436
+ isOffline: true,
437
+ });
438
+ }
439
+ switch (error.status) {
440
+ case 401: {
441
+ throw new OneBlinkAppsError('You cannot view approvals without first logging in. Please login and try again.', {
442
+ originalError: error,
443
+ requiresLogin: true,
444
+ httpStatusCode: error.status,
445
+ });
446
+ }
447
+ case 403: {
448
+ throw new OneBlinkAppsError('You do not have access to this application. Please contact your administrator to gain the correct level of access.', {
449
+ originalError: error,
450
+ requiresAccessRequest: true,
451
+ httpStatusCode: error.status,
452
+ });
453
+ }
454
+ case 400:
455
+ case 404: {
456
+ throw new OneBlinkAppsError(error.message, {
457
+ title: 'Invalid Request',
458
+ httpStatusCode: error.status,
459
+ });
460
+ }
461
+ default: {
462
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
463
+ originalError: error,
464
+ httpStatusCode: error.status,
465
+ });
466
+ }
467
+ }
468
+ }
469
+ }
470
+ /**
471
+ * Get an array containing usernames that have updated approvals in the within
472
+ * the formsAppId associated with the passed `formsAppId`. Must be an Approvals
473
+ * Administrator.
474
+ *
475
+ * #### Example
476
+ *
477
+ * ```js
478
+ * const formsAppId = 1
479
+ * const { usernames } =
480
+ * await approvalsService.getFormApprovalUsernames(formsAppId)
481
+ * ```
482
+ *
483
+ * @param formsAppId
484
+ * @param abortSignal
485
+ * @returns
486
+ */
487
+ export async function getFormApprovalUsernames(formsAppId, abortSignal) {
488
+ try {
489
+ return await getRequest(`${tenants.current.apiOrigin}/forms-apps/${formsAppId}/approvals/usernames`, abortSignal);
490
+ }
491
+ catch (err) {
492
+ Sentry.captureException(err);
493
+ console.error('Error retrieving form approval usernames', err);
494
+ const error = err;
495
+ if (isOffline()) {
496
+ throw new OneBlinkAppsError('You are currently offline, please connect to the internet and try again', {
497
+ originalError: error,
498
+ isOffline: true,
499
+ });
500
+ }
501
+ switch (error.status) {
502
+ case 401: {
503
+ throw new OneBlinkAppsError('You cannot access form approval usernames without first logging in. Please login and try again.', {
504
+ originalError: error,
505
+ requiresLogin: true,
506
+ httpStatusCode: error.status,
507
+ });
508
+ }
509
+ case 403: {
510
+ throw new OneBlinkAppsError('You do not have access to this application. Please contact your administrator to gain the correct level of access.', {
511
+ originalError: error,
512
+ requiresAccessRequest: true,
513
+ httpStatusCode: error.status,
514
+ });
515
+ }
516
+ case 400:
517
+ case 404: {
518
+ throw new OneBlinkAppsError(error.message, {
519
+ title: 'Invalid Request',
520
+ httpStatusCode: error.status,
521
+ });
522
+ }
523
+ default: {
524
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
525
+ originalError: error,
526
+ httpStatusCode: error.status,
527
+ });
528
+ }
529
+ }
530
+ }
531
+ }
532
+ /**
533
+ * Create an additional note for a form submission approval.
534
+ *
535
+ * #### Example
536
+ *
537
+ * ```js
538
+ * const formSubmissionApprovalId = 'd96ff812-f263-4a66-868d-e259a1fe4157'
539
+ * const newFormSubmissionApprovalNote = {
540
+ * note: 'this is my note',
541
+ * }
542
+ * const createdFormSubmissionApprovalNote =
543
+ * await approvalsService.createApprovalAdditionalNote({
544
+ * formSubmissionApprovalId,
545
+ * newFormSubmissionApprovalNote,
546
+ * })
547
+ * ```
548
+ *
549
+ * @param options
550
+ * @returns
551
+ */
552
+ export async function createApprovalAdditionalNote({ formSubmissionApprovalId, newFormSubmissionApprovalNote, abortSignal, }) {
553
+ try {
554
+ return await postRequest(`${tenants.current.apiOrigin}/form-submission-approvals/${formSubmissionApprovalId}/additional-notes`, newFormSubmissionApprovalNote, abortSignal);
555
+ }
556
+ catch (err) {
557
+ console.error('Error creating form submission approval note', err);
558
+ if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
559
+ throw err;
560
+ }
561
+ Sentry.captureException(err);
562
+ const error = err;
563
+ if (isOffline()) {
564
+ throw new OneBlinkAppsError('You are currently offline, please connect to the internet and try again', {
565
+ originalError: error,
566
+ isOffline: true,
567
+ });
568
+ }
569
+ switch (error.status) {
570
+ case 401: {
571
+ throw new OneBlinkAppsError('You cannot create additional notes without first logging in. Please login and try again.', {
572
+ originalError: error,
573
+ requiresLogin: true,
574
+ httpStatusCode: error.status,
575
+ });
576
+ }
577
+ case 403: {
578
+ throw new OneBlinkAppsError('You do not have access to this application. Please contact your administrator to gain the correct level of access.', {
579
+ originalError: error,
580
+ requiresAccessRequest: true,
581
+ httpStatusCode: error.status,
582
+ });
583
+ }
584
+ case 400:
585
+ case 404: {
586
+ throw new OneBlinkAppsError(error.message, {
587
+ title: 'Invalid Request',
588
+ httpStatusCode: error.status,
589
+ });
590
+ }
591
+ default: {
592
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
593
+ originalError: error,
594
+ httpStatusCode: error.status,
595
+ });
596
+ }
597
+ }
598
+ }
599
+ }
600
+ /**
601
+ * Update an additional note for a form submission approval.
602
+ *
603
+ * #### Example
604
+ *
605
+ * ```js
606
+ * const formSubmissionApprovalId = 'd96ff812-f263-4a66-868d-e259a1fe4157'
607
+ * const formSubmissionApprovalNote = {
608
+ * id: '1e84dee3-0dc0-4abe-b2cf-d15d62fd9d0b',
609
+ * note: 'this is my note',
610
+ * createdAt: '2022-06-24T03:16:34.696Z',
611
+ * createdBy: {
612
+ * username: 'user@domain.com',
613
+ * },
614
+ * updatedAt: '2022-06-24T03:16:34.696Z',
615
+ * lastUpdatedBy: {
616
+ * username: 'user@domain.com',
617
+ * },
618
+ * }
619
+ * const updatedFormSubmissionApprovalNote =
620
+ * await approvalsService.updateApprovalAdditionalNote({
621
+ * formSubmissionApprovalId,
622
+ * formSubmissionApprovalNote,
623
+ * })
624
+ * ```
625
+ *
626
+ * @param options
627
+ * @returns
628
+ */
629
+ export async function updateApprovalAdditionalNote({ formSubmissionApprovalId, formSubmissionApprovalNote, abortSignal, }) {
630
+ try {
631
+ return await putRequest(`${tenants.current.apiOrigin}/form-submission-approvals/${formSubmissionApprovalId}/additional-notes/${formSubmissionApprovalNote.id}`, formSubmissionApprovalNote, abortSignal);
632
+ }
633
+ catch (err) {
634
+ console.error('Error updating form submission approval note', err);
635
+ if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
636
+ throw err;
637
+ }
638
+ Sentry.captureException(err);
639
+ const error = err;
640
+ if (isOffline()) {
641
+ throw new OneBlinkAppsError('You are currently offline, please connect to the internet and try again', {
642
+ originalError: error,
643
+ isOffline: true,
644
+ });
645
+ }
646
+ switch (error.status) {
647
+ case 401: {
648
+ throw new OneBlinkAppsError('You cannot update additional notes without first logging in. Please login and try again.', {
649
+ originalError: error,
650
+ requiresLogin: true,
651
+ httpStatusCode: error.status,
652
+ });
653
+ }
654
+ case 403: {
655
+ throw new OneBlinkAppsError('You do not have access to this application. Please contact your administrator to gain the correct level of access.', {
656
+ originalError: error,
657
+ requiresAccessRequest: true,
658
+ httpStatusCode: error.status,
659
+ });
660
+ }
661
+ case 400:
662
+ case 404: {
663
+ throw new OneBlinkAppsError(error.message, {
664
+ title: 'Invalid Request',
665
+ httpStatusCode: error.status,
666
+ });
667
+ }
668
+ default: {
669
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
670
+ originalError: error,
671
+ httpStatusCode: error.status,
672
+ });
673
+ }
674
+ }
675
+ }
676
+ }
677
+ /**
678
+ * Delete an additional note for a form submission approval.
679
+ *
680
+ * #### Example
681
+ *
682
+ * ```js
683
+ * const formSubmissionApprovalId = 'd96ff812-f263-4a66-868d-e259a1fe4157'
684
+ * const formSubmissionApprovalNoteId = '1e84dee3-0dc0-4abe-b2cf-d15d62fd9d0b',
685
+ * const updatedFormSubmissionApprovalNote =
686
+ * await approvalsService.deleteApprovalAdditionalNote({
687
+ * formSubmissionApprovalId,
688
+ * formSubmissionApprovalNoteId,
689
+ * })
690
+ * ```
691
+ *
692
+ * @param options
693
+ * @returns
694
+ */
695
+ export async function deleteApprovalAdditionalNote({ formSubmissionApprovalId, formSubmissionApprovalNoteId, abortSignal, }) {
696
+ try {
697
+ return await deleteRequest(`${tenants.current.apiOrigin}/form-submission-approvals/${formSubmissionApprovalId}/additional-notes/${formSubmissionApprovalNoteId}`, abortSignal);
698
+ }
699
+ catch (err) {
700
+ console.error('Error updating form submission approval note', err);
701
+ if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
702
+ throw err;
703
+ }
704
+ Sentry.captureException(err);
705
+ const error = err;
706
+ if (isOffline()) {
707
+ throw new OneBlinkAppsError('You are currently offline, please connect to the internet and try again', {
708
+ originalError: error,
709
+ isOffline: true,
710
+ });
711
+ }
712
+ switch (error.status) {
713
+ case 401: {
714
+ throw new OneBlinkAppsError('You cannot delete additional notes without first logging in. Please login and try again.', {
715
+ originalError: error,
716
+ requiresLogin: true,
717
+ httpStatusCode: error.status,
718
+ });
719
+ }
720
+ case 403: {
721
+ throw new OneBlinkAppsError('You do not have access to this application. Please contact your administrator to gain the correct level of access.', {
722
+ originalError: error,
723
+ requiresAccessRequest: true,
724
+ httpStatusCode: error.status,
725
+ });
726
+ }
727
+ case 400:
728
+ case 404: {
729
+ throw new OneBlinkAppsError(error.message, {
730
+ title: 'Invalid Request',
731
+ httpStatusCode: error.status,
732
+ });
733
+ }
734
+ default: {
735
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
736
+ originalError: error,
737
+ httpStatusCode: error.status,
738
+ });
739
+ }
740
+ }
741
+ }
742
+ }
743
+ /**
744
+ * Get the status of a single FormSubmissionApproval for the given id.
745
+ *
746
+ * #### Example
747
+ *
748
+ * ```js
749
+ * const formSubmissionApprovalId = 'd27966cc-128d-48a2-b681-6ad52012e113'
750
+ * const { status } =
751
+ * await approvalsService.getFormSubmissionApprovalStatus(
752
+ * formSubmissionApprovalId,
753
+ * )
754
+ * ```
755
+ *
756
+ * @param formSubmissionApprovalId
757
+ * @param abortSignal
758
+ * @returns
759
+ */
760
+ export async function getFormSubmissionApprovalStatus(formSubmissionApprovalId, abortSignal) {
761
+ try {
762
+ const result = await getRequest(`${tenants.current.apiOrigin}/form-submission-approvals/${formSubmissionApprovalId}/status`, abortSignal);
763
+ return result;
764
+ }
765
+ catch (err) {
766
+ Sentry.captureException(err);
767
+ console.error('Error retrieving form submission approval status', err);
768
+ const error = err;
769
+ if (isOffline()) {
770
+ throw new OneBlinkAppsError('You are currently offline and do not have a local copy of this app available, please connect to the internet and try again', {
771
+ originalError: error,
772
+ isOffline: true,
773
+ });
774
+ }
775
+ switch (error.status) {
776
+ case 401: {
777
+ throw new OneBlinkAppsError('You cannot action this pending submission without first logging in. Please login and try again.', {
778
+ originalError: error,
779
+ requiresLogin: true,
780
+ httpStatusCode: error.status,
781
+ });
782
+ }
783
+ case 403: {
784
+ throw new OneBlinkAppsError('You do not have access to this application. Please contact your administrator to gain the correct level of access.', {
785
+ originalError: error,
786
+ requiresAccessRequest: true,
787
+ httpStatusCode: error.status,
788
+ });
789
+ }
790
+ case 400:
791
+ case 404: {
792
+ throw new OneBlinkAppsError(error.message, {
793
+ title: 'Invalid Request',
794
+ httpStatusCode: error.status,
795
+ });
796
+ }
797
+ default: {
798
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
799
+ originalError: error,
800
+ httpStatusCode: error.status,
801
+ });
802
+ }
803
+ }
804
+ }
805
+ }
806
+ const possibleStatuses = [
807
+ {
808
+ label: 'Awaiting Approval',
809
+ value: 'PENDING',
810
+ },
811
+ {
812
+ label: 'Approved',
813
+ value: 'APPROVED',
814
+ },
815
+ {
816
+ label: 'Clarification Requested',
817
+ value: 'CLARIFICATION_REQUIRED',
818
+ },
819
+ {
820
+ label: 'Clarification Received',
821
+ value: 'CLARIFICATION_RECEIVED',
822
+ },
823
+ {
824
+ label: 'Denied',
825
+ value: 'CLOSED',
826
+ },
827
+ ];
828
+ function findLatestFormSubmissionApproval(flowInstanceNode, formSubmissionApprovals) {
829
+ return formSubmissionApprovals.reduce((lastUpdatedFormSubmissionApproval, formSubmissionApproval) => {
830
+ if (formSubmissionApproval.stepLabel === flowInstanceNode.label &&
831
+ (!lastUpdatedFormSubmissionApproval ||
832
+ lastUpdatedFormSubmissionApproval.updatedAt <
833
+ formSubmissionApproval.updatedAt)) {
834
+ return formSubmissionApproval;
835
+ }
836
+ return lastUpdatedFormSubmissionApproval;
837
+ }, undefined);
838
+ }
839
+ function getFormApprovalFlowInstanceNodes(steps) {
840
+ return steps.reduce((memo, step) => {
841
+ switch (step.type) {
842
+ case 'CONCURRENT': {
843
+ const parentStepLabelsId = step.nodes
844
+ .map(({ label }) => label)
845
+ .join('_');
846
+ for (const node of step.nodes) {
847
+ const index = step.nodes.indexOf(node);
848
+ memo.push({
849
+ ...node,
850
+ parentStepLabelsId,
851
+ isConcurrentWithPrevious: index !== 0,
852
+ isConcurrentWithNext: index < step.nodes.length - 1,
853
+ });
854
+ }
855
+ break;
856
+ }
857
+ case 'STANDARD':
858
+ default: {
859
+ memo.push({
860
+ ...step,
861
+ isConcurrentWithPrevious: false,
862
+ isConcurrentWithNext: false,
863
+ parentStepLabelsId: step.label,
864
+ });
865
+ break;
866
+ }
867
+ }
868
+ return memo;
869
+ }, []);
870
+ }
871
+ /**
872
+ * Inputs a form approval flow instance and set of form submission approvals and
873
+ * returns a flattened array of nodes/steps with inlcuded metadata.
874
+ *
875
+ * #### Example
876
+ *
877
+ * ```js
878
+ * const formApprovalFlowInstance = {
879
+ * steps: [
880
+ * {
881
+ * type: 'STANDARD',
882
+ * group: 'oneblink:administrator',
883
+ * isSkipped: false,
884
+ * label: 'Manager Approval',
885
+ * approvalFormId: '1234',
886
+ * },
887
+ * {
888
+ * type: 'CONCURRENT',
889
+ * nodes: [
890
+ * {
891
+ * label: 'HR Review',
892
+ * group: 'oneblink:administrator',
893
+ * isSkipped: false,
894
+ * approvalFormId: '1234',
895
+ * },
896
+ * {
897
+ * label: 'Finance Review',
898
+ * group: 'oneblink:administrator',
899
+ * isSkipped: false,
900
+ * approvalFormId: '1234',
901
+ * },
902
+ * ],
903
+ * },
904
+ * ],
905
+ * }
906
+ *
907
+ * const formSubmissionApprovals = [
908
+ * {
909
+ * id: 'approval1',
910
+ * stepLabel: 'Manager Approval',
911
+ * status: 'APPROVED',
912
+ * createdAt: '2024-03-20T10:00:00Z',
913
+ * updatedAt: '2024-03-20T10:00:00Z',
914
+ * updatedBy: 'fake@fake.com',
915
+ * group: 'oneblink:administrator',
916
+ * approvalFormId: '1234',
917
+ * },
918
+ * ]
919
+ *
920
+ * const nodesWithMeta = getFlowInstanceNodesWithMeta(
921
+ * formApprovalFlowInstance,
922
+ * formSubmissionApprovals,
923
+ * )
924
+ * ```
925
+ *
926
+ * @param formApprovalFlowInstance
927
+ * @param formSubmissionApprovals
928
+ * @returns ApprovalTypes.FlowInstanceNodeWithMeta[]
929
+ */
930
+ export function getFlowInstanceNodesWithMeta(formApprovalFlowInstance, formSubmissionApprovals) {
931
+ const formApprovalFlowInstanceNodes = getFormApprovalFlowInstanceNodes(formApprovalFlowInstance.steps);
932
+ let isDenied = false;
933
+ let isClarificationRequired = false;
934
+ return formApprovalFlowInstanceNodes.map((step) => {
935
+ const associatedApproval = findLatestFormSubmissionApproval(step, formSubmissionApprovals);
936
+ const status = possibleStatuses.find(({ value }) => value === (associatedApproval === null || associatedApproval === void 0 ? void 0 : associatedApproval.status));
937
+ let isDeniedInConcurrentStep = false;
938
+ let isClarificationRequiredInConcurrentStep = false;
939
+ if ((status === null || status === void 0 ? void 0 : status.value) === 'PENDING') {
940
+ const siblingNodes = formApprovalFlowInstanceNodes.filter(({ parentStepLabelsId, label }) => parentStepLabelsId === step.parentStepLabelsId &&
941
+ label !== step.label);
942
+ for (const siblingNode of siblingNodes) {
943
+ const formSubmissionApproval = findLatestFormSubmissionApproval(siblingNode, formSubmissionApprovals);
944
+ if ((formSubmissionApproval === null || formSubmissionApproval === void 0 ? void 0 : formSubmissionApproval.status) === 'CLOSED') {
945
+ isDeniedInConcurrentStep = true;
946
+ }
947
+ if ((formSubmissionApproval === null || formSubmissionApproval === void 0 ? void 0 : formSubmissionApproval.status) === 'CLARIFICATION_REQUIRED') {
948
+ isClarificationRequiredInConcurrentStep = true;
949
+ }
950
+ }
951
+ }
952
+ const isAfterDeniedStep = isDenied;
953
+ if ((status === null || status === void 0 ? void 0 : status.value) === 'CLOSED') {
954
+ isDenied = true;
955
+ }
956
+ const isAfterClarificationRequiredStep = isClarificationRequired;
957
+ if ((status === null || status === void 0 ? void 0 : status.value) === 'CLARIFICATION_REQUIRED') {
958
+ isClarificationRequired = true;
959
+ }
960
+ let description = 'Awaiting previous approvals';
961
+ if (step.isSkipped) {
962
+ description = 'Skipped based on form submission';
963
+ }
964
+ else if (status) {
965
+ const updatedByText = (associatedApproval === null || associatedApproval === void 0 ? void 0 : associatedApproval.updatedBy)
966
+ ? ` by ${associatedApproval.updatedBy}`
967
+ : '';
968
+ description = `${status.label}${updatedByText}`;
969
+ }
970
+ else if (isAfterDeniedStep) {
971
+ description = 'Denied in a previous step';
972
+ }
973
+ else if (isAfterClarificationRequiredStep) {
974
+ description = 'Sent for clarification in a previous step';
975
+ }
976
+ return {
977
+ ...step,
978
+ status,
979
+ isDeniedInConcurrentStep,
980
+ isAfterDeniedStep,
981
+ isClarificationRequiredInConcurrentStep,
982
+ isAfterClarificationRequiredStep,
983
+ description,
984
+ };
985
+ });
986
+ }
987
+ //# sourceMappingURL=approvals-service.js.map