@oneblink/apps-react 9.0.0-beta.1 → 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 +43 -35
@@ -0,0 +1,761 @@
1
+ import { add } from 'date-fns';
2
+ import OneBlinkAppsError from '../services/errors/oneBlinkAppsError';
3
+ import { isOffline } from '../offline-service';
4
+ import { deleteRequest, fetchJSON, getRequest, postRequest, searchRequest, putRequest, } from '../services/fetch';
5
+ import tenants from '../tenants';
6
+ import Sentry from '../Sentry';
7
+ import generateGenericError from './generate-generic-error';
8
+ /**
9
+ * Search for geoscape addresses based on a partial address.
10
+ *
11
+ * #### Example
12
+ *
13
+ * ```js
14
+ * const formId = 1
15
+ * const result = await formService.searchGeoscapeAddresses(formId, {
16
+ * query: '123 N',
17
+ * maxNumberOfResults: 10
18
+ * stateTerritory: 'NSW'
19
+ * })
20
+ * ```
21
+ *
22
+ * @param formId
23
+ * @param queryParams
24
+ * @param abortSignal
25
+ * @returns
26
+ */
27
+ export async function searchGeoscapeAddresses(formId, queryParams, abortSignal) {
28
+ try {
29
+ return await searchRequest(`${tenants.current.apiOrigin}/forms/${formId}/geoscape/addresses`, queryParams, abortSignal);
30
+ }
31
+ catch (err) {
32
+ throw generateGenericError(err, abortSignal);
33
+ }
34
+ }
35
+ /**
36
+ * Get the details for a single geoscape address based on the Id of a geoscape
37
+ * address resource.
38
+ *
39
+ * #### Example
40
+ *
41
+ * ```js
42
+ * const formId = 1
43
+ * const addressId = 'ABC123'
44
+ * const result = await formService.getGeoscapeAddress(formId, addressId)
45
+ * ```
46
+ *
47
+ * @param formId
48
+ * @param addressId
49
+ * @param abortSignal
50
+ * @returns
51
+ */
52
+ export async function getGeoscapeAddress(formId, addressId, abortSignal) {
53
+ try {
54
+ return await getRequest(`${tenants.current.apiOrigin}/forms/${formId}/geoscape/addresses/${addressId}`, abortSignal);
55
+ }
56
+ catch (err) {
57
+ throw generateGenericError(err, abortSignal);
58
+ }
59
+ }
60
+ /**
61
+ * Get a geoscape address from a latitude and longitude
62
+ *
63
+ * #### Example
64
+ *
65
+ * ```js
66
+ * const lat = 41.9475427
67
+ * const lng = -87.6562292
68
+ * const formId = 1
69
+ * const result = await formService.getGeoscapeReverseGeocoding({
70
+ * lat,
71
+ * lng,
72
+ * formId,
73
+ * })
74
+ * ```
75
+ *
76
+ * @param options
77
+ * @returns
78
+ */
79
+ export async function getGeoscapeReverseGeocoding({ formId, lat, lng, abortSignal, }) {
80
+ try {
81
+ const urlParams = new URLSearchParams({
82
+ lat: lat.toString(),
83
+ lng: lng.toString(),
84
+ });
85
+ return await getRequest(`${tenants.current.apiOrigin}/forms/${formId}/geoscape/reverse-geocode?${urlParams.toString()}`, abortSignal);
86
+ }
87
+ catch (err) {
88
+ if (!(abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted)) {
89
+ Sentry.captureException(err);
90
+ }
91
+ const error = err;
92
+ if (isOffline()) {
93
+ throw new OneBlinkAppsError('You are currently offline, please connect to the internet and try again', {
94
+ originalError: error,
95
+ isOffline: true,
96
+ });
97
+ }
98
+ switch (error.status) {
99
+ case 401: {
100
+ throw new OneBlinkAppsError('Please login and try again.', {
101
+ originalError: error,
102
+ requiresLogin: true,
103
+ httpStatusCode: error.status,
104
+ });
105
+ }
106
+ case 403: {
107
+ throw new OneBlinkAppsError('You do not have access to this application. Please contact your administrator to gain the correct level of access.', {
108
+ originalError: error,
109
+ requiresAccessRequest: true,
110
+ httpStatusCode: error.status,
111
+ });
112
+ }
113
+ case 400:
114
+ case 404: {
115
+ throw new OneBlinkAppsError(`Could not find address from ${lat},${lng}.`, {
116
+ originalError: error,
117
+ title: 'Address not found',
118
+ httpStatusCode: error.status,
119
+ });
120
+ }
121
+ default: {
122
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
123
+ originalError: error,
124
+ httpStatusCode: error.status,
125
+ });
126
+ }
127
+ }
128
+ }
129
+ }
130
+ /**
131
+ * Search for Point addresses based on a partial address.
132
+ *
133
+ * #### Example
134
+ *
135
+ * ```js
136
+ * const formId = 1
137
+ * const result = await formService.searchPointAddresses(formId, {
138
+ * address: '123 N',
139
+ * maxNumberOfResults: 10
140
+ * stateTerritory: 'NSW'
141
+ * })
142
+ * ```
143
+ *
144
+ * @param formId
145
+ * @param queryParams
146
+ * @param abortSignal
147
+ * @returns
148
+ */
149
+ export async function searchPointAddresses(formId, queryParams, abortSignal) {
150
+ try {
151
+ return await searchRequest(`${tenants.current.apiOrigin}/forms/${formId}/point/addresses`, queryParams, abortSignal);
152
+ }
153
+ catch (err) {
154
+ throw generateGenericError(err, abortSignal);
155
+ }
156
+ }
157
+ /**
158
+ * Get the details for a single Point address based on the Id of a Point address
159
+ * resource.
160
+ *
161
+ * #### Example
162
+ *
163
+ * ```js
164
+ * const formId = 1
165
+ * const addressId = 'ABC123'
166
+ * const result = await formService.getPointAddress(formId, addressId)
167
+ * ```
168
+ *
169
+ * @param formId
170
+ * @param addressId
171
+ * @param abortSignal
172
+ * @returns
173
+ */
174
+ export async function getPointAddress(formId, addressId, abortSignal) {
175
+ try {
176
+ return await getRequest(`${tenants.current.apiOrigin}/forms/${formId}/point/addresses/${addressId}`, abortSignal);
177
+ }
178
+ catch (err) {
179
+ throw generateGenericError(err, abortSignal);
180
+ }
181
+ }
182
+ /**
183
+ * Get the details for a single NSW Point Cadastral Parcel record.
184
+ *
185
+ * #### Example
186
+ *
187
+ * ```js
188
+ * const formId = 1
189
+ * const parcelId = '1/234567'
190
+ * const result = await formService.getPointCadastralParcel(
191
+ * formId,
192
+ * addressId,
193
+ * )
194
+ * ```
195
+ *
196
+ * @param formId
197
+ * @param parcelId
198
+ * @param abortSignal
199
+ * @returns
200
+ */
201
+ export async function getPointCadastralParcel(formId, parcelId, abortSignal) {
202
+ try {
203
+ const urlSearchParams = new URLSearchParams([['parcelId', parcelId]]);
204
+ return await getRequest(`${tenants.current.apiOrigin}/forms/${formId}/point/cadastral-parcels?${urlSearchParams.toString()}`, abortSignal);
205
+ }
206
+ catch (err) {
207
+ throw generateGenericError(err, abortSignal);
208
+ }
209
+ }
210
+ /**
211
+ * Search for Point addresses v3 based on a partial address.
212
+ *
213
+ * #### Example
214
+ *
215
+ * -
216
+ *
217
+ * Const formId = 1 const result = await
218
+ * formService.searchPointV3Addresses(formId, { address: '123 N', maxResults: 10
219
+ * stateFilter: 'NSW' })
220
+ *
221
+ * @param formId
222
+ * @param queryParams
223
+ * @param abortSignal
224
+ * @returns
225
+ */
226
+ export async function searchPointV3Addresses(formId, queryParams, abortSignal) {
227
+ try {
228
+ return await searchRequest(`${tenants.current.apiOrigin}/forms/${formId}/point/v3/addresses`, queryParams, abortSignal);
229
+ }
230
+ catch (err) {
231
+ throw generateGenericError(err, abortSignal);
232
+ }
233
+ }
234
+ /**
235
+ * Get the details for a single Point address based on the Id of a Point address
236
+ * resource.
237
+ *
238
+ * #### Example
239
+ *
240
+ * ```js
241
+ * const formId = 1
242
+ * const result = await formService.getPointV3Address(formId, {
243
+ * addressId: 'ABC123',
244
+ * 'Accept-Crs': '<https://www.opengis.net/def/crs/EPSG/0/7844>',
245
+ * })
246
+ * ```
247
+ *
248
+ * @param formId
249
+ * @param queryParams
250
+ * @param abortSignal
251
+ * @returns
252
+ */
253
+ export async function getPointV3Address(formId, queryParams, abortSignal) {
254
+ try {
255
+ return await searchRequest(`${tenants.current.apiOrigin}/forms/${formId}/point/v3/address`, queryParams, abortSignal);
256
+ }
257
+ catch (err) {
258
+ throw generateGenericError(err, abortSignal);
259
+ }
260
+ }
261
+ /**
262
+ * Search for street names in Civica
263
+ *
264
+ * #### Example
265
+ *
266
+ * ```js
267
+ * const formId = 1
268
+ * const queryParams = {
269
+ * search: '1 Station ',
270
+ * top: 10,
271
+ * }
272
+ * const result = await formService.searchCivicaStreetNames(
273
+ * formId,
274
+ * queryParams,
275
+ * )
276
+ * ```
277
+ *
278
+ * @param formId
279
+ * @param queryParams
280
+ * @param abortSignal
281
+ * @returns
282
+ */
283
+ export async function searchCivicaStreetNames(formId, queryParams, abortSignal) {
284
+ try {
285
+ return await searchRequest(`${tenants.current.apiOrigin}/forms/${formId}/civica/streetregister/streetnames`, queryParams, abortSignal);
286
+ }
287
+ catch (err) {
288
+ throw generateGenericError(err, abortSignal);
289
+ }
290
+ }
291
+ /**
292
+ * Get titles codes from Civica name register
293
+ *
294
+ * #### Example
295
+ *
296
+ * ```js
297
+ * const formId = 1
298
+ * const results = await formService.getCivicaTitleCodes(formId)
299
+ * ```
300
+ *
301
+ * @param formId
302
+ * @param abortSignal
303
+ * @returns
304
+ */
305
+ export async function getCivicaTitleCodes(formId, abortSignal) {
306
+ try {
307
+ return await getRequest(`${tenants.current.apiOrigin}/forms/${formId}/civica/nameregister/titlecodes`, abortSignal);
308
+ }
309
+ catch (err) {
310
+ throw generateGenericError(err, abortSignal);
311
+ }
312
+ }
313
+ /**
314
+ * Get BSB record based on a BSB number codes from Civica name register
315
+ *
316
+ * #### Example
317
+ *
318
+ * ```js
319
+ * const formId = 1
320
+ * const bsb = '123-321'
321
+ * const results = await formService.getBSBRecord(formId, bsb)
322
+ * ```
323
+ *
324
+ * @param formId
325
+ * @param bsb
326
+ * @param abortSignal
327
+ * @returns
328
+ */
329
+ export async function getBSBRecord(formId, bsb, abortSignal) {
330
+ try {
331
+ return await getRequest(`${tenants.current.apiOrigin}/forms/${formId}/bsb-records/${bsb}`, abortSignal);
332
+ }
333
+ catch (err) {
334
+ if (!(abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted)) {
335
+ Sentry.captureException(err);
336
+ }
337
+ const error = err;
338
+ if (isOffline()) {
339
+ throw new OneBlinkAppsError('You are currently offline, please connect to the internet and try again', {
340
+ originalError: error,
341
+ isOffline: true,
342
+ });
343
+ }
344
+ switch (error.status) {
345
+ case 401: {
346
+ throw new OneBlinkAppsError('Please login and try again.', {
347
+ originalError: error,
348
+ requiresLogin: true,
349
+ httpStatusCode: error.status,
350
+ });
351
+ }
352
+ case 403: {
353
+ throw new OneBlinkAppsError('You do not have access to this application. Please contact your administrator to gain the correct level of access.', {
354
+ originalError: error,
355
+ requiresAccessRequest: true,
356
+ httpStatusCode: error.status,
357
+ });
358
+ }
359
+ case 400:
360
+ case 404: {
361
+ throw new OneBlinkAppsError('The BSB number you have entered does not exist.', {
362
+ originalError: error,
363
+ title: 'Unknown BSB Number',
364
+ httpStatusCode: error.status,
365
+ });
366
+ }
367
+ default: {
368
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
369
+ originalError: error,
370
+ httpStatusCode: error.status,
371
+ });
372
+ }
373
+ }
374
+ }
375
+ }
376
+ const API_NSW_LIQUOR_LICENCE_TOKEN_KEY = 'API_NSW_LIQUOR_LICENCE_TOKEN';
377
+ function getAPINSWLiquorLicenceTokenFromStorage() {
378
+ const localStorageValue = localStorage.getItem(API_NSW_LIQUOR_LICENCE_TOKEN_KEY);
379
+ if (localStorageValue) {
380
+ try {
381
+ return JSON.parse(localStorageValue);
382
+ }
383
+ catch {
384
+ // ignore JSON parse error
385
+ }
386
+ }
387
+ }
388
+ async function getAPINSWLiquorLicenceToken(formId, abortSignal) {
389
+ const liquorLicenceAccessTokenResponse = getAPINSWLiquorLicenceTokenFromStorage();
390
+ if (liquorLicenceAccessTokenResponse) {
391
+ const now = new Date();
392
+ const issuedAt = new Date(parseInt(liquorLicenceAccessTokenResponse.issued_at));
393
+ const expiresAt = add(issuedAt, {
394
+ seconds: parseInt(liquorLicenceAccessTokenResponse.expires_in),
395
+ });
396
+ if (expiresAt > now) {
397
+ return liquorLicenceAccessTokenResponse;
398
+ }
399
+ }
400
+ const result = await postRequest(`${tenants.current.apiOrigin}/forms/${formId}/api-nsw/liquor/access-token`, abortSignal);
401
+ localStorage.setItem(API_NSW_LIQUOR_LICENCE_TOKEN_KEY, JSON.stringify(result));
402
+ return result;
403
+ }
404
+ /**
405
+ * Search for API.NSW Liquor licences based on a partial text search.
406
+ *
407
+ * #### Example
408
+ *
409
+ * ```js
410
+ * const result = await formService.searchAPINSWLiquorLicences({
411
+ * formId: 1,
412
+ * search: 'SMITH',
413
+ * })
414
+ * ```
415
+ *
416
+ * @param options
417
+ * @param abortSignal
418
+ * @returns
419
+ */
420
+ export async function searchAPINSWLiquorLicences({ formId, searchText, }, abortSignal) {
421
+ try {
422
+ const apiNSWLiquorLicenceToken = await getAPINSWLiquorLicenceToken(formId, abortSignal);
423
+ return await fetchJSON(`https://api.onegov.nsw.gov.au/liquorregister/v1/browse?searchText=${searchText}`, {
424
+ method: 'GET',
425
+ headers: {
426
+ Accept: 'application/json',
427
+ apikey: apiNSWLiquorLicenceToken.client_id,
428
+ Authorization: `Bearer ${apiNSWLiquorLicenceToken.access_token}`,
429
+ },
430
+ signal: abortSignal,
431
+ });
432
+ }
433
+ catch (err) {
434
+ throw generateGenericError(err, abortSignal);
435
+ }
436
+ }
437
+ /**
438
+ * Get the details for a single API.NSW Liquor licence based on the licenceID.
439
+ *
440
+ * #### Example
441
+ *
442
+ * ```js
443
+ * const formId = 1
444
+ * const licenceId = '1-RL22KV'
445
+ * const result = await formService.getAPINSWLiquorLicence(
446
+ * formId,
447
+ * licenceId,
448
+ * )
449
+ * ```
450
+ *
451
+ * @param formId
452
+ * @param licenceId
453
+ * @param abortSignal
454
+ * @returns
455
+ */
456
+ export async function getAPINSWLiquorLicence(formId, licenceId, abortSignal) {
457
+ try {
458
+ const apiNSWLiquorLicenceToken = await getAPINSWLiquorLicenceToken(formId, abortSignal);
459
+ return await fetchJSON(`https://api.onegov.nsw.gov.au/liquorregister/v1/details?licenceid=${licenceId}`, {
460
+ method: 'GET',
461
+ headers: {
462
+ Accept: 'application/json',
463
+ apikey: apiNSWLiquorLicenceToken.client_id,
464
+ Authorization: `Bearer ${apiNSWLiquorLicenceToken.access_token}`,
465
+ },
466
+ signal: abortSignal,
467
+ });
468
+ }
469
+ catch (err) {
470
+ throw generateGenericError(err, abortSignal);
471
+ }
472
+ }
473
+ function generateCPHCMSStorageKey(formId) {
474
+ return `CP_HCMS_TOKEN_FORM_${formId}`;
475
+ }
476
+ function getCPHCMSTokenFromStorage(formId) {
477
+ const itemKey = generateCPHCMSStorageKey(formId);
478
+ const localStorageValue = localStorage.getItem(itemKey);
479
+ if (localStorageValue) {
480
+ try {
481
+ return JSON.parse(localStorageValue);
482
+ }
483
+ catch {
484
+ // ignore JSON parse error
485
+ }
486
+ }
487
+ }
488
+ async function getCPHCMSToken({ formsAppId, formId }, abortSignal) {
489
+ const CPHCMSTokenResponse = getCPHCMSTokenFromStorage(formId);
490
+ if (CPHCMSTokenResponse) {
491
+ const now = new Date();
492
+ const expiresAt = new Date(CPHCMSTokenResponse.auth.expires_at);
493
+ if (expiresAt > now) {
494
+ return CPHCMSTokenResponse;
495
+ }
496
+ }
497
+ const result = await postRequest(`${tenants.current.apiOrigin}/forms-apps/${formsAppId}/forms/${formId}/cp-hcms-authentication`, abortSignal);
498
+ const itemKey = generateCPHCMSStorageKey(formId);
499
+ localStorage.setItem(itemKey, JSON.stringify(result));
500
+ return result;
501
+ }
502
+ /**
503
+ * Change the status of a CivicPlus HCMS content item to published.
504
+ *
505
+ * @param options
506
+ * @returns
507
+ */
508
+ export async function publishHCMSContentItem({ formsAppId, formId, contentId, abortSignal, }) {
509
+ try {
510
+ const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/forms/${formId}/cp-hcms-content/${contentId}/publish`;
511
+ return await putRequest(url, undefined, abortSignal);
512
+ }
513
+ catch (err) {
514
+ if (!(abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted)) {
515
+ Sentry.captureException(err);
516
+ }
517
+ const error = err;
518
+ if (isOffline()) {
519
+ throw new OneBlinkAppsError('You are currently offline, please connect to the internet and try again', {
520
+ originalError: error,
521
+ isOffline: true,
522
+ });
523
+ }
524
+ switch (error.status) {
525
+ case 401: {
526
+ throw new OneBlinkAppsError('Please login and try again.', {
527
+ originalError: error,
528
+ requiresLogin: true,
529
+ httpStatusCode: error.status,
530
+ });
531
+ }
532
+ case 403: {
533
+ throw new OneBlinkAppsError('You do not have access to this application. Please contact your administrator to gain the correct level of access.', {
534
+ originalError: error,
535
+ requiresAccessRequest: true,
536
+ httpStatusCode: error.status,
537
+ });
538
+ }
539
+ case 400: {
540
+ throw new OneBlinkAppsError(error.message, {
541
+ originalError: error,
542
+ title: 'Invalid Request',
543
+ httpStatusCode: error.status,
544
+ });
545
+ }
546
+ case 404: {
547
+ throw new OneBlinkAppsError(error.message, {
548
+ originalError: error,
549
+ title: 'Unknown Application',
550
+ httpStatusCode: error.status,
551
+ });
552
+ }
553
+ default: {
554
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
555
+ originalError: error,
556
+ httpStatusCode: error.status,
557
+ });
558
+ }
559
+ }
560
+ }
561
+ }
562
+ /**
563
+ * Change the status of a CivicPlus HCMS content item to draft.
564
+ *
565
+ * @param options
566
+ * @returns
567
+ */
568
+ export async function draftHCMSContentItem({ formsAppId, formId, contentId, abortSignal, }) {
569
+ try {
570
+ const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/forms/${formId}/cp-hcms-content/${contentId}/draft`;
571
+ return await putRequest(url, undefined, abortSignal);
572
+ }
573
+ catch (err) {
574
+ if (!(abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted)) {
575
+ Sentry.captureException(err);
576
+ }
577
+ const error = err;
578
+ if (isOffline()) {
579
+ throw new OneBlinkAppsError('You are currently offline, please connect to the internet and try again', {
580
+ originalError: error,
581
+ isOffline: true,
582
+ });
583
+ }
584
+ switch (error.status) {
585
+ case 401: {
586
+ throw new OneBlinkAppsError('Please login and try again.', {
587
+ originalError: error,
588
+ requiresLogin: true,
589
+ httpStatusCode: error.status,
590
+ });
591
+ }
592
+ case 403: {
593
+ throw new OneBlinkAppsError('You do not have access to this application. Please contact your administrator to gain the correct level of access.', {
594
+ originalError: error,
595
+ requiresAccessRequest: true,
596
+ httpStatusCode: error.status,
597
+ });
598
+ }
599
+ case 400: {
600
+ throw new OneBlinkAppsError(error.message, {
601
+ originalError: error,
602
+ title: 'Invalid Request',
603
+ httpStatusCode: error.status,
604
+ });
605
+ }
606
+ case 404: {
607
+ throw new OneBlinkAppsError(error.message, {
608
+ originalError: error,
609
+ title: 'Unknown Application',
610
+ httpStatusCode: error.status,
611
+ });
612
+ }
613
+ default: {
614
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
615
+ originalError: error,
616
+ httpStatusCode: error.status,
617
+ });
618
+ }
619
+ }
620
+ }
621
+ }
622
+ /**
623
+ * Search CivicPlus HCMS content items.
624
+ *
625
+ * @param options
626
+ * @returns
627
+ */
628
+ export async function searchCivicPlusHCMSContentItems({ formsAppId, formId, $top, $skip, $search, $filter, $orderby, abortSignal, }) {
629
+ try {
630
+ const { auth: { access_token }, appName, baseUrl, contentTypeName, } = await getCPHCMSToken({ formsAppId, formId }, abortSignal);
631
+ const url = new URL(`/api/content/${appName}/${contentTypeName}`, baseUrl);
632
+ if (typeof $top === 'number')
633
+ url.searchParams.append('$top', $top.toString());
634
+ if (typeof $skip === 'number')
635
+ url.searchParams.append('$skip', $skip.toString());
636
+ if ($search)
637
+ url.searchParams.append('$search', $search);
638
+ if ($filter)
639
+ url.searchParams.append('$filter', $filter);
640
+ if ($orderby)
641
+ url.searchParams.append('$orderby', $orderby);
642
+ return await fetchJSON(url.href, {
643
+ signal: abortSignal,
644
+ headers: {
645
+ 'Content-Type': 'application/json',
646
+ Authorization: `Bearer ${access_token}`,
647
+ 'X-Flatten': 'true',
648
+ 'X-Unpublished': 'true',
649
+ },
650
+ });
651
+ }
652
+ catch (err) {
653
+ if (!(abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted)) {
654
+ Sentry.captureException(err);
655
+ }
656
+ const error = err;
657
+ if (isOffline()) {
658
+ throw new OneBlinkAppsError('You are currently offline, please connect to the internet and try again', {
659
+ originalError: error,
660
+ isOffline: true,
661
+ });
662
+ }
663
+ switch (error.status) {
664
+ case 401: {
665
+ throw new OneBlinkAppsError('Please login and try again.', {
666
+ originalError: error,
667
+ requiresLogin: true,
668
+ httpStatusCode: error.status,
669
+ });
670
+ }
671
+ case 403: {
672
+ throw new OneBlinkAppsError('You do not have access to this application. Please contact your administrator to gain the correct level of access.', {
673
+ originalError: error,
674
+ requiresAccessRequest: true,
675
+ httpStatusCode: error.status,
676
+ });
677
+ }
678
+ case 400: {
679
+ throw new OneBlinkAppsError(error.message, {
680
+ originalError: error,
681
+ title: 'Invalid Request',
682
+ httpStatusCode: error.status,
683
+ });
684
+ }
685
+ case 404: {
686
+ throw new OneBlinkAppsError(error.message, {
687
+ originalError: error,
688
+ title: 'Unknown Application',
689
+ httpStatusCode: error.status,
690
+ });
691
+ }
692
+ default: {
693
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
694
+ originalError: error,
695
+ httpStatusCode: error.status,
696
+ });
697
+ }
698
+ }
699
+ }
700
+ }
701
+ /**
702
+ * Delete CivicPlus HCMS content item.
703
+ *
704
+ * @param options
705
+ * @returns
706
+ */
707
+ export async function deleteCivicPlusHCMSContentItem({ formsAppId, formId, contentId, abortSignal, }) {
708
+ try {
709
+ const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/forms/${formId}/cp-hcms-content/${contentId}`;
710
+ return await deleteRequest(url, abortSignal);
711
+ }
712
+ catch (err) {
713
+ if (!(abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted)) {
714
+ Sentry.captureException(err);
715
+ }
716
+ const error = err;
717
+ if (isOffline()) {
718
+ throw new OneBlinkAppsError('You are currently offline, please connect to the internet and try again', {
719
+ originalError: error,
720
+ isOffline: true,
721
+ });
722
+ }
723
+ switch (error.status) {
724
+ case 401: {
725
+ throw new OneBlinkAppsError('Please login and try again.', {
726
+ originalError: error,
727
+ requiresLogin: true,
728
+ httpStatusCode: error.status,
729
+ });
730
+ }
731
+ case 403: {
732
+ throw new OneBlinkAppsError('You do not have access to this application. Please contact your administrator to gain the correct level of access.', {
733
+ originalError: error,
734
+ requiresAccessRequest: true,
735
+ httpStatusCode: error.status,
736
+ });
737
+ }
738
+ case 400: {
739
+ throw new OneBlinkAppsError(error.message, {
740
+ originalError: error,
741
+ title: 'Invalid Request',
742
+ httpStatusCode: error.status,
743
+ });
744
+ }
745
+ case 404: {
746
+ throw new OneBlinkAppsError(error.message, {
747
+ originalError: error,
748
+ title: 'Unknown Application',
749
+ httpStatusCode: error.status,
750
+ });
751
+ }
752
+ default: {
753
+ throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.', {
754
+ originalError: error,
755
+ httpStatusCode: error.status,
756
+ });
757
+ }
758
+ }
759
+ }
760
+ }
761
+ //# sourceMappingURL=integration-elements.js.map