@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.
- package/dist/OneBlinkForm.d.ts +6 -6
- package/dist/OneBlinkFormBase.js +1 -0
- package/dist/OneBlinkFormBase.js.map +1 -1
- package/dist/apps/Sentry.d.ts +7 -0
- package/dist/apps/Sentry.js +16 -0
- package/dist/apps/Sentry.js.map +1 -0
- package/dist/apps/approvals-service.d.ts +390 -0
- package/dist/apps/approvals-service.js +987 -0
- package/dist/apps/approvals-service.js.map +1 -0
- package/dist/apps/attachments-service.d.ts +49 -0
- package/dist/apps/attachments-service.js +134 -0
- package/dist/apps/attachments-service.js.map +1 -0
- package/dist/apps/auth-service.d.ts +114 -0
- package/dist/apps/auth-service.js +194 -0
- package/dist/apps/auth-service.js.map +1 -0
- package/dist/apps/auto-save-service.d.ts +82 -0
- package/dist/apps/auto-save-service.js +105 -0
- package/dist/apps/auto-save-service.js.map +1 -0
- package/dist/apps/draft-service.d.ts +148 -0
- package/dist/apps/draft-service.js +583 -0
- package/dist/apps/draft-service.js.map +1 -0
- package/dist/apps/form-service.d.ts +204 -0
- package/dist/apps/form-service.js +718 -0
- package/dist/apps/form-service.js.map +1 -0
- package/dist/apps/form-store-service.d.ts +141 -0
- package/dist/apps/form-store-service.js +114 -0
- package/dist/apps/form-store-service.js.map +1 -0
- package/dist/apps/forms-app-environment-service.d.ts +19 -0
- package/dist/apps/forms-app-environment-service.js +55 -0
- package/dist/apps/forms-app-environment-service.js.map +1 -0
- package/dist/apps/forms-app-service.d.ts +18 -0
- package/dist/apps/forms-app-service.js +53 -0
- package/dist/apps/forms-app-service.js.map +1 -0
- package/dist/apps/index.d.ts +252 -0
- package/dist/apps/index.js +254 -0
- package/dist/apps/index.js.map +1 -0
- package/dist/apps/job-service.d.ts +20 -0
- package/dist/apps/job-service.js +95 -0
- package/dist/apps/job-service.js.map +1 -0
- package/dist/apps/localisation-service.d.ts +207 -0
- package/dist/apps/localisation-service.js +321 -0
- package/dist/apps/localisation-service.js.map +1 -0
- package/dist/apps/notification-service.d.ts +83 -0
- package/dist/apps/notification-service.js +315 -0
- package/dist/apps/notification-service.js.map +1 -0
- package/dist/apps/offline-service.d.ts +18 -0
- package/dist/apps/offline-service.js +25 -0
- package/dist/apps/offline-service.js.map +1 -0
- package/dist/apps/payment-service.d.ts +110 -0
- package/dist/apps/payment-service.js +182 -0
- package/dist/apps/payment-service.js.map +1 -0
- package/dist/apps/prefill-service.d.ts +14 -0
- package/dist/apps/prefill-service.js +19 -0
- package/dist/apps/prefill-service.js.map +1 -0
- package/dist/apps/scheduled-tasks-service.d.ts +127 -0
- package/dist/apps/scheduled-tasks-service.js +240 -0
- package/dist/apps/scheduled-tasks-service.js.map +1 -0
- package/dist/apps/scheduling-service.d.ts +101 -0
- package/dist/apps/scheduling-service.js +171 -0
- package/dist/apps/scheduling-service.js.map +1 -0
- package/dist/apps/services/AWSCognitoClient.d.ts +55 -0
- package/dist/apps/services/AWSCognitoClient.js +436 -0
- package/dist/apps/services/AWSCognitoClient.js.map +1 -0
- package/dist/apps/services/api/drafts.d.ts +7 -0
- package/dist/apps/services/api/drafts.js +236 -0
- package/dist/apps/services/api/drafts.js.map +1 -0
- package/dist/apps/services/api/notifications.d.ts +3 -0
- package/dist/apps/services/api/notifications.js +60 -0
- package/dist/apps/services/api/notifications.js.map +1 -0
- package/dist/apps/services/api/payment.d.ts +23 -0
- package/dist/apps/services/api/payment.js +235 -0
- package/dist/apps/services/api/payment.js.map +1 -0
- package/dist/apps/services/api/post-submission-attachment-urls.d.ts +7 -0
- package/dist/apps/services/api/post-submission-attachment-urls.js +19 -0
- package/dist/apps/services/api/post-submission-attachment-urls.js.map +1 -0
- package/dist/apps/services/api/prefill.d.ts +1 -0
- package/dist/apps/services/api/prefill.js +70 -0
- package/dist/apps/services/api/prefill.js.map +1 -0
- package/dist/apps/services/api/receipt-id.d.ts +2 -0
- package/dist/apps/services/api/receipt-id.js +54 -0
- package/dist/apps/services/api/receipt-id.js.map +1 -0
- package/dist/apps/services/api/scheduling.d.ts +38 -0
- package/dist/apps/services/api/scheduling.js +142 -0
- package/dist/apps/services/api/scheduling.js.map +1 -0
- package/dist/apps/services/api/submissions.d.ts +18 -0
- package/dist/apps/services/api/submissions.js +166 -0
- package/dist/apps/services/api/submissions.js.map +1 -0
- package/dist/apps/services/cognito.d.ts +302 -0
- package/dist/apps/services/cognito.js +441 -0
- package/dist/apps/services/cognito.js.map +1 -0
- package/dist/apps/services/draft-data-store.d.ts +16 -0
- package/dist/apps/services/draft-data-store.js +115 -0
- package/dist/apps/services/draft-data-store.js.map +1 -0
- package/dist/apps/services/errors/oneBlinkAppsError.d.ts +35 -0
- package/dist/apps/services/errors/oneBlinkAppsError.js +32 -0
- package/dist/apps/services/errors/oneBlinkAppsError.js.map +1 -0
- package/dist/apps/services/external-id-generation.d.ts +4 -0
- package/dist/apps/services/external-id-generation.js +59 -0
- package/dist/apps/services/external-id-generation.js.map +1 -0
- package/dist/apps/services/fetch.d.ts +12 -0
- package/dist/apps/services/fetch.js +95 -0
- package/dist/apps/services/fetch.js.map +1 -0
- package/dist/apps/services/forms-key.d.ts +51 -0
- package/dist/apps/services/forms-key.js +83 -0
- package/dist/apps/services/forms-key.js.map +1 -0
- package/dist/apps/services/generate-generic-error.d.ts +3 -0
- package/dist/apps/services/generate-generic-error.js +52 -0
- package/dist/apps/services/generate-generic-error.js.map +1 -0
- package/dist/apps/services/generateOneBlinkDownloader.d.ts +2 -0
- package/dist/apps/services/generateOneBlinkDownloader.js +11 -0
- package/dist/apps/services/generateOneBlinkDownloader.js.map +1 -0
- package/dist/apps/services/generateOneBlinkUploader.d.ts +2 -0
- package/dist/apps/services/generateOneBlinkUploader.js +11 -0
- package/dist/apps/services/generateOneBlinkUploader.js.map +1 -0
- package/dist/apps/services/getDeviceInformation.d.ts +17 -0
- package/dist/apps/services/getDeviceInformation.js +38 -0
- package/dist/apps/services/getDeviceInformation.js.map +1 -0
- package/dist/apps/services/integration-elements.d.ts +383 -0
- package/dist/apps/services/integration-elements.js +761 -0
- package/dist/apps/services/integration-elements.js.map +1 -0
- package/dist/apps/services/job-prefill.d.ts +40 -0
- package/dist/apps/services/job-prefill.js +78 -0
- package/dist/apps/services/job-prefill.js.map +1 -0
- package/dist/apps/services/payment-providers/BPOINTPaymentProvider.d.ts +29 -0
- package/dist/apps/services/payment-providers/BPOINTPaymentProvider.js +59 -0
- package/dist/apps/services/payment-providers/BPOINTPaymentProvider.js.map +1 -0
- package/dist/apps/services/payment-providers/CPPayPaymentProvider.d.ts +27 -0
- package/dist/apps/services/payment-providers/CPPayPaymentProvider.js +63 -0
- package/dist/apps/services/payment-providers/CPPayPaymentProvider.js.map +1 -0
- package/dist/apps/services/payment-providers/NSWGovPayPaymentProvider.d.ts +30 -0
- package/dist/apps/services/payment-providers/NSWGovPayPaymentProvider.js +116 -0
- package/dist/apps/services/payment-providers/NSWGovPayPaymentProvider.js.map +1 -0
- package/dist/apps/services/payment-providers/WestpacQuickStreamPaymentProvider.d.ts +49 -0
- package/dist/apps/services/payment-providers/WestpacQuickStreamPaymentProvider.js +116 -0
- package/dist/apps/services/payment-providers/WestpacQuickStreamPaymentProvider.js.map +1 -0
- package/dist/apps/services/payment-providers/receipt-items.d.ts +8 -0
- package/dist/apps/services/payment-providers/receipt-items.js +58 -0
- package/dist/apps/services/payment-providers/receipt-items.js.map +1 -0
- package/dist/apps/services/pending-queue.d.ts +150 -0
- package/dist/apps/services/pending-queue.js +316 -0
- package/dist/apps/services/pending-queue.js.map +1 -0
- package/dist/apps/services/prepareSubmissionData.d.ts +2 -0
- package/dist/apps/services/prepareSubmissionData.js +113 -0
- package/dist/apps/services/prepareSubmissionData.js.map +1 -0
- package/dist/apps/services/query-string.d.ts +1 -0
- package/dist/apps/services/query-string.js +16 -0
- package/dist/apps/services/query-string.js.map +1 -0
- package/dist/apps/services/replaceInjectablesWithSubmissionValues.d.ts +3 -0
- package/dist/apps/services/replaceInjectablesWithSubmissionValues.js +18 -0
- package/dist/apps/services/replaceInjectablesWithSubmissionValues.js.map +1 -0
- package/dist/apps/services/schedulingHandlers.d.ts +36 -0
- package/dist/apps/services/schedulingHandlers.js +76 -0
- package/dist/apps/services/schedulingHandlers.js.map +1 -0
- package/dist/apps/services/server-validation.d.ts +2 -0
- package/dist/apps/services/server-validation.js +36 -0
- package/dist/apps/services/server-validation.js.map +1 -0
- package/dist/apps/services/serverRequest.d.ts +5 -0
- package/dist/apps/services/serverRequest.js +24 -0
- package/dist/apps/services/serverRequest.js.map +1 -0
- package/dist/apps/services/submit.d.ts +19 -0
- package/dist/apps/services/submit.js +219 -0
- package/dist/apps/services/submit.js.map +1 -0
- package/dist/apps/services/uploadAttachment.d.ts +52 -0
- package/dist/apps/services/uploadAttachment.js +73 -0
- package/dist/apps/services/uploadAttachment.js.map +1 -0
- package/dist/apps/services/user-token.d.ts +27 -0
- package/dist/apps/services/user-token.js +33 -0
- package/dist/apps/services/user-token.js.map +1 -0
- package/dist/apps/services/utils.d.ts +12 -0
- package/dist/apps/services/utils.js +100 -0
- package/dist/apps/services/utils.js.map +1 -0
- package/dist/apps/submission-service.d.ts +226 -0
- package/dist/apps/submission-service.js +425 -0
- package/dist/apps/submission-service.js.map +1 -0
- package/dist/apps/tenants.d.ts +29 -0
- package/dist/apps/tenants.js +127 -0
- package/dist/apps/tenants.js.map +1 -0
- package/dist/apps/types/form.d.ts +4 -0
- package/dist/apps/types/form.js +2 -0
- package/dist/apps/types/form.js.map +1 -0
- package/dist/apps/types/payments.d.ts +45 -0
- package/dist/apps/types/payments.js +2 -0
- package/dist/apps/types/payments.js.map +1 -0
- package/dist/apps/types/scheduling.d.ts +5 -0
- package/dist/apps/types/scheduling.js +2 -0
- package/dist/apps/types/scheduling.js.map +1 -0
- package/dist/apps/types/submissions.d.ts +175 -0
- package/dist/apps/types/submissions.js +2 -0
- package/dist/apps/types/submissions.js.map +1 -0
- package/dist/components/CustomAccordion.d.ts +3 -3
- package/dist/components/Lists.d.ts +4 -1
- package/dist/components/formStore/display/ElementDisplay.js +2 -2
- package/dist/components/formStore/display/ElementDisplay.js.map +1 -1
- package/dist/components/formStore/useFormStoreTableContext.d.ts +2 -2
- package/dist/components/mfa/MultiFactorAuthentication.d.ts +1 -1
- package/dist/components/renderer/LookupNotification.js +1 -1
- package/dist/components/renderer/LookupNotification.js.map +1 -1
- package/dist/form-elements/FormElementAutocomplete.js +1 -1
- package/dist/form-elements/FormElementAutocomplete.js.map +1 -1
- package/dist/hooks/attachments/useAttachment.js +1 -1
- package/dist/hooks/attachments/useAttachment.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/services/download-file.js +1 -1
- package/dist/services/download-file.js.map +1 -1
- package/dist/styles.css +208 -204
- package/package.json +43 -35
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { submissionService } from '@oneblink/sdk-core';
|
|
2
|
+
/**
|
|
3
|
+
* Get the locale (e.g. `en-AU`) for the current tenant.
|
|
4
|
+
*
|
|
5
|
+
* #### Example
|
|
6
|
+
*
|
|
7
|
+
* ```js
|
|
8
|
+
* const locale = localisationService.getLocale()
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export declare function getLocale(): "en-AU" | "en-US";
|
|
14
|
+
/**
|
|
15
|
+
* Get the distance units (e.g. `feet` & 'ft) for the current tenant.
|
|
16
|
+
*
|
|
17
|
+
* #### Example
|
|
18
|
+
*
|
|
19
|
+
* ```js
|
|
20
|
+
* const { distanceUnit, distanceUnitShortName } =
|
|
21
|
+
* localisationService.getDistanceUnits()
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
export declare function getDistanceUnits(): {
|
|
27
|
+
distanceUnit: string;
|
|
28
|
+
distanceUnitShortName: string;
|
|
29
|
+
};
|
|
30
|
+
export declare function getDateFnsFormats(): {
|
|
31
|
+
time: string;
|
|
32
|
+
shortDate: string;
|
|
33
|
+
shortYearlessDate: string;
|
|
34
|
+
longDate: string;
|
|
35
|
+
longYearlessDate: string;
|
|
36
|
+
shortDateTime: string;
|
|
37
|
+
longDateTime: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Format a `Date` as a `string` that just contains the date portion e.g.
|
|
41
|
+
* _31/01/2020_
|
|
42
|
+
*
|
|
43
|
+
* #### Example
|
|
44
|
+
*
|
|
45
|
+
* ```js
|
|
46
|
+
* const date = new Date()
|
|
47
|
+
* const text = localisationService.formatDate(date)
|
|
48
|
+
* // Display text
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @param value
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
export declare function formatDate(value: Date): string;
|
|
55
|
+
/**
|
|
56
|
+
* Format a `Date` as a `string` that just contains the date portion in a long
|
|
57
|
+
* format e.g. _Thursday, 2 January 2020_
|
|
58
|
+
*
|
|
59
|
+
* #### Example
|
|
60
|
+
*
|
|
61
|
+
* ```js
|
|
62
|
+
* const date = new Date()
|
|
63
|
+
* const text = localisationService.formatDateLong(date)
|
|
64
|
+
* // Display text
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @param value
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
70
|
+
export declare function formatDateLong(value: Date): string;
|
|
71
|
+
/**
|
|
72
|
+
* Format a `Date` as a `string` that just contains the time portion e.g. _5:31
|
|
73
|
+
* pm_
|
|
74
|
+
*
|
|
75
|
+
* #### Example
|
|
76
|
+
*
|
|
77
|
+
* ```js
|
|
78
|
+
* const date = new Date()
|
|
79
|
+
* const text = localisationService.formatTime(date)
|
|
80
|
+
* // Display text
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @param value
|
|
84
|
+
* @returns
|
|
85
|
+
*/
|
|
86
|
+
export declare function formatTime(value: Date): string;
|
|
87
|
+
/**
|
|
88
|
+
* Format a `Date` as a `string` that contains the date and time portions e.g.
|
|
89
|
+
* _31/01/2020 5:31 pm_
|
|
90
|
+
*
|
|
91
|
+
* #### Example
|
|
92
|
+
*
|
|
93
|
+
* ```js
|
|
94
|
+
* const date = new Date()
|
|
95
|
+
* const text = localisationService.formatDatetime(date)
|
|
96
|
+
* // Display text
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* @param value
|
|
100
|
+
* @returns
|
|
101
|
+
*/
|
|
102
|
+
export declare function formatDatetime(value: Date): string;
|
|
103
|
+
/**
|
|
104
|
+
* Format a `Date` as a `string` that contains the date and time portions in a
|
|
105
|
+
* long format e.g. _Thursday, 2 January 2020 5:31 pm_
|
|
106
|
+
*
|
|
107
|
+
* #### Example
|
|
108
|
+
*
|
|
109
|
+
* ```js
|
|
110
|
+
* const date = new Date()
|
|
111
|
+
* const text = localisationService.formatDatetime(date)
|
|
112
|
+
* // Display text
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @param value
|
|
116
|
+
* @returns
|
|
117
|
+
*/
|
|
118
|
+
export declare function formatDatetimeLong(value: Date): string;
|
|
119
|
+
/**
|
|
120
|
+
* Format a `number` as a `string` represented as a readable number e.g.
|
|
121
|
+
* _123,321.123_
|
|
122
|
+
*
|
|
123
|
+
* #### Example
|
|
124
|
+
*
|
|
125
|
+
* ```js
|
|
126
|
+
* const amount = 1234.4321
|
|
127
|
+
* const text = localisationService.formatCurrency(amount)
|
|
128
|
+
* // Display text
|
|
129
|
+
* ```
|
|
130
|
+
*
|
|
131
|
+
* @param value
|
|
132
|
+
* @returns
|
|
133
|
+
*/
|
|
134
|
+
export declare function formatNumber(value: number): string;
|
|
135
|
+
/**
|
|
136
|
+
* Format a `number` as a `string` represented as a currency e.g. _$123.31_
|
|
137
|
+
*
|
|
138
|
+
* #### Example
|
|
139
|
+
*
|
|
140
|
+
* ```js
|
|
141
|
+
* const amount = 123.321
|
|
142
|
+
* const text = localisationService.formatCurrency(amount)
|
|
143
|
+
* // Display text
|
|
144
|
+
* ```
|
|
145
|
+
*
|
|
146
|
+
* @param value
|
|
147
|
+
* @returns
|
|
148
|
+
*/
|
|
149
|
+
export declare function formatCurrency(value: number): string;
|
|
150
|
+
/**
|
|
151
|
+
* Generate a `Date` based a `string` while adding/subtracting a number of days.
|
|
152
|
+
* Use this function to generate a date with the correct time if only the date
|
|
153
|
+
* part is required to be formatted for display purposes. Also supports passing
|
|
154
|
+
* `'NOW'` as the value to get the current date with an offset.
|
|
155
|
+
*
|
|
156
|
+
* #### Example
|
|
157
|
+
*
|
|
158
|
+
* ```js
|
|
159
|
+
* const dateOnly = localisationService.generateDate({
|
|
160
|
+
* value: '2023-05-04',
|
|
161
|
+
* dateOnly: true,
|
|
162
|
+
* daysOffset: undefined,
|
|
163
|
+
* })
|
|
164
|
+
*
|
|
165
|
+
* const date = localisationService.generateDate({
|
|
166
|
+
* value: '2023-05-04T02:49:23.616Z',
|
|
167
|
+
* dateOnly: false,
|
|
168
|
+
* daysOffset: undefined,
|
|
169
|
+
* })
|
|
170
|
+
*
|
|
171
|
+
* const now = localisationService.generateDate({
|
|
172
|
+
* value: 'NOW',
|
|
173
|
+
* dateOnly: false,
|
|
174
|
+
* daysOffset: undefined,
|
|
175
|
+
* })
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* @param options
|
|
179
|
+
* @returns
|
|
180
|
+
*/
|
|
181
|
+
export declare function generateDate({ daysOffset, value, }: {
|
|
182
|
+
daysOffset: number | undefined;
|
|
183
|
+
value: string;
|
|
184
|
+
}): Date | undefined;
|
|
185
|
+
export declare const replaceSubmissionFormatters: submissionService.ReplaceInjectablesFormatters;
|
|
186
|
+
/**
|
|
187
|
+
* Replace the `{ELEMENT:<elementName>}` values in text after a successful form
|
|
188
|
+
* submission as well as other replaceable parameters e.g. `submissionId`. The
|
|
189
|
+
* replacements are suppose to be user friendly and for display purposes, e.g.
|
|
190
|
+
* dates should be displayed in the user's desired format and timezone.
|
|
191
|
+
*
|
|
192
|
+
* @param text
|
|
193
|
+
* @param options
|
|
194
|
+
* @returns
|
|
195
|
+
*/
|
|
196
|
+
export declare function replaceInjectablesWithSubmissionValues(text: string, options: Omit<Parameters<typeof submissionService.replaceInjectablesWithSubmissionValues>[1], keyof submissionService.ReplaceInjectablesFormatters>): ReturnType<typeof submissionService.replaceInjectablesWithSubmissionValues>;
|
|
197
|
+
/**
|
|
198
|
+
* Replace the `{ELEMENT:<elementName>}` values in text while a form is being
|
|
199
|
+
* filled out. The replacements are suppose to be user friendly and for display
|
|
200
|
+
* purposes, e.g. dates should be displayed in the user's desired format and
|
|
201
|
+
* timezone.
|
|
202
|
+
*
|
|
203
|
+
* @param text
|
|
204
|
+
* @param options
|
|
205
|
+
* @returns
|
|
206
|
+
*/
|
|
207
|
+
export declare function replaceInjectablesWithElementValues(text: string, options: Omit<Parameters<typeof submissionService.replaceInjectablesWithElementValues>[1], keyof submissionService.ReplaceInjectablesFormatters>): ReturnType<typeof submissionService.replaceInjectablesWithElementValues>;
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { submissionService } from '@oneblink/sdk-core';
|
|
2
|
+
import tenants from './tenants';
|
|
3
|
+
import parser from 'ua-parser-js';
|
|
4
|
+
import { add, parse } from 'date-fns';
|
|
5
|
+
let iosVersion;
|
|
6
|
+
const parsedUserAgent = parser(window.navigator.userAgent);
|
|
7
|
+
if (parsedUserAgent.os.name === 'iOS' &&
|
|
8
|
+
typeof parsedUserAgent.os.version === 'string') {
|
|
9
|
+
iosVersion = parseFloat(parsedUserAgent.os.version);
|
|
10
|
+
if (Number.isNaN(iosVersion)) {
|
|
11
|
+
iosVersion = undefined;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Get the locale (e.g. `en-AU`) for the current tenant.
|
|
16
|
+
*
|
|
17
|
+
* #### Example
|
|
18
|
+
*
|
|
19
|
+
* ```js
|
|
20
|
+
* const locale = localisationService.getLocale()
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
export function getLocale() {
|
|
26
|
+
return tenants.locale;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get the distance units (e.g. `feet` & 'ft) for the current tenant.
|
|
30
|
+
*
|
|
31
|
+
* #### Example
|
|
32
|
+
*
|
|
33
|
+
* ```js
|
|
34
|
+
* const { distanceUnit, distanceUnitShortName } =
|
|
35
|
+
* localisationService.getDistanceUnits()
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
export function getDistanceUnits() {
|
|
41
|
+
return {
|
|
42
|
+
distanceUnit: tenants.current.distanceUnit,
|
|
43
|
+
distanceUnitShortName: tenants.current.distanceUnitShortName,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function generateFormats({ time, shortDate, shortYearlessDate, longDate, longYearlessDate, }) {
|
|
47
|
+
return {
|
|
48
|
+
time,
|
|
49
|
+
shortDate,
|
|
50
|
+
shortYearlessDate,
|
|
51
|
+
longDate,
|
|
52
|
+
longYearlessDate,
|
|
53
|
+
shortDateTime: `${shortDate} ${time}`,
|
|
54
|
+
longDateTime: `${longDate} ${time}`,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export function getDateFnsFormats() {
|
|
58
|
+
const time = 'h:mm a';
|
|
59
|
+
switch (tenants.locale) {
|
|
60
|
+
case 'en-US': {
|
|
61
|
+
return generateFormats({
|
|
62
|
+
time,
|
|
63
|
+
shortDate: 'MM/dd/yyyy',
|
|
64
|
+
shortYearlessDate: 'MM/dd',
|
|
65
|
+
longDate: 'MMM do, yyyy',
|
|
66
|
+
longYearlessDate: 'MMM do',
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
case 'en-AU':
|
|
70
|
+
default: {
|
|
71
|
+
return generateFormats({
|
|
72
|
+
time,
|
|
73
|
+
shortDate: 'dd/MM/yyyy',
|
|
74
|
+
shortYearlessDate: 'dd/MM',
|
|
75
|
+
longDate: 'do MMM, yyyy',
|
|
76
|
+
longYearlessDate: 'do MMM',
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Format a `Date` as a `string` that just contains the date portion e.g.
|
|
83
|
+
* _31/01/2020_
|
|
84
|
+
*
|
|
85
|
+
* #### Example
|
|
86
|
+
*
|
|
87
|
+
* ```js
|
|
88
|
+
* const date = new Date()
|
|
89
|
+
* const text = localisationService.formatDate(date)
|
|
90
|
+
* // Display text
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @param value
|
|
94
|
+
* @returns
|
|
95
|
+
*/
|
|
96
|
+
export function formatDate(value) {
|
|
97
|
+
return tenants.current.intlFormats.date.format(value);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Format a `Date` as a `string` that just contains the date portion in a long
|
|
101
|
+
* format e.g. _Thursday, 2 January 2020_
|
|
102
|
+
*
|
|
103
|
+
* #### Example
|
|
104
|
+
*
|
|
105
|
+
* ```js
|
|
106
|
+
* const date = new Date()
|
|
107
|
+
* const text = localisationService.formatDateLong(date)
|
|
108
|
+
* // Display text
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* @param value
|
|
112
|
+
* @returns
|
|
113
|
+
*/
|
|
114
|
+
export function formatDateLong(value) {
|
|
115
|
+
return tenants.current.intlFormats.dateLong.format(value);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Format a `Date` as a `string` that just contains the time portion e.g. _5:31
|
|
119
|
+
* pm_
|
|
120
|
+
*
|
|
121
|
+
* #### Example
|
|
122
|
+
*
|
|
123
|
+
* ```js
|
|
124
|
+
* const date = new Date()
|
|
125
|
+
* const text = localisationService.formatTime(date)
|
|
126
|
+
* // Display text
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* @param value
|
|
130
|
+
* @returns
|
|
131
|
+
*/
|
|
132
|
+
export function formatTime(value) {
|
|
133
|
+
/*
|
|
134
|
+
* Time formatting for older iOS devices. Prevents date from repeating.
|
|
135
|
+
* Example: Last sync time: 24/11/2022 24/11/2022
|
|
136
|
+
*/
|
|
137
|
+
if (typeof iosVersion === 'number' && iosVersion < 13.0) {
|
|
138
|
+
const time = tenants.current.intlFormats.olderIOSTime.formatToParts(value);
|
|
139
|
+
const newTime = time.map((t) => t.value).join('');
|
|
140
|
+
return `${newTime}`;
|
|
141
|
+
}
|
|
142
|
+
return tenants.current.intlFormats.time.format(value);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Format a `Date` as a `string` that contains the date and time portions e.g.
|
|
146
|
+
* _31/01/2020 5:31 pm_
|
|
147
|
+
*
|
|
148
|
+
* #### Example
|
|
149
|
+
*
|
|
150
|
+
* ```js
|
|
151
|
+
* const date = new Date()
|
|
152
|
+
* const text = localisationService.formatDatetime(date)
|
|
153
|
+
* // Display text
|
|
154
|
+
* ```
|
|
155
|
+
*
|
|
156
|
+
* @param value
|
|
157
|
+
* @returns
|
|
158
|
+
*/
|
|
159
|
+
export function formatDatetime(value) {
|
|
160
|
+
return `${formatDate(value)} ${formatTime(value)}`;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Format a `Date` as a `string` that contains the date and time portions in a
|
|
164
|
+
* long format e.g. _Thursday, 2 January 2020 5:31 pm_
|
|
165
|
+
*
|
|
166
|
+
* #### Example
|
|
167
|
+
*
|
|
168
|
+
* ```js
|
|
169
|
+
* const date = new Date()
|
|
170
|
+
* const text = localisationService.formatDatetime(date)
|
|
171
|
+
* // Display text
|
|
172
|
+
* ```
|
|
173
|
+
*
|
|
174
|
+
* @param value
|
|
175
|
+
* @returns
|
|
176
|
+
*/
|
|
177
|
+
export function formatDatetimeLong(value) {
|
|
178
|
+
return `${formatDateLong(value)} ${formatTime(value)}`;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Format a `number` as a `string` represented as a readable number e.g.
|
|
182
|
+
* _123,321.123_
|
|
183
|
+
*
|
|
184
|
+
* #### Example
|
|
185
|
+
*
|
|
186
|
+
* ```js
|
|
187
|
+
* const amount = 1234.4321
|
|
188
|
+
* const text = localisationService.formatCurrency(amount)
|
|
189
|
+
* // Display text
|
|
190
|
+
* ```
|
|
191
|
+
*
|
|
192
|
+
* @param value
|
|
193
|
+
* @returns
|
|
194
|
+
*/
|
|
195
|
+
export function formatNumber(value) {
|
|
196
|
+
return tenants.current.intlFormats.number.format(value);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Format a `number` as a `string` represented as a currency e.g. _$123.31_
|
|
200
|
+
*
|
|
201
|
+
* #### Example
|
|
202
|
+
*
|
|
203
|
+
* ```js
|
|
204
|
+
* const amount = 123.321
|
|
205
|
+
* const text = localisationService.formatCurrency(amount)
|
|
206
|
+
* // Display text
|
|
207
|
+
* ```
|
|
208
|
+
*
|
|
209
|
+
* @param value
|
|
210
|
+
* @returns
|
|
211
|
+
*/
|
|
212
|
+
export function formatCurrency(value) {
|
|
213
|
+
return tenants.current.intlFormats.currency.format(value);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Generate a `Date` based a `string` while adding/subtracting a number of days.
|
|
217
|
+
* Use this function to generate a date with the correct time if only the date
|
|
218
|
+
* part is required to be formatted for display purposes. Also supports passing
|
|
219
|
+
* `'NOW'` as the value to get the current date with an offset.
|
|
220
|
+
*
|
|
221
|
+
* #### Example
|
|
222
|
+
*
|
|
223
|
+
* ```js
|
|
224
|
+
* const dateOnly = localisationService.generateDate({
|
|
225
|
+
* value: '2023-05-04',
|
|
226
|
+
* dateOnly: true,
|
|
227
|
+
* daysOffset: undefined,
|
|
228
|
+
* })
|
|
229
|
+
*
|
|
230
|
+
* const date = localisationService.generateDate({
|
|
231
|
+
* value: '2023-05-04T02:49:23.616Z',
|
|
232
|
+
* dateOnly: false,
|
|
233
|
+
* daysOffset: undefined,
|
|
234
|
+
* })
|
|
235
|
+
*
|
|
236
|
+
* const now = localisationService.generateDate({
|
|
237
|
+
* value: 'NOW',
|
|
238
|
+
* dateOnly: false,
|
|
239
|
+
* daysOffset: undefined,
|
|
240
|
+
* })
|
|
241
|
+
* ```
|
|
242
|
+
*
|
|
243
|
+
* @param options
|
|
244
|
+
* @returns
|
|
245
|
+
*/
|
|
246
|
+
export function generateDate({ daysOffset, value, }) {
|
|
247
|
+
if (value === 'NOW') {
|
|
248
|
+
const date = new Date();
|
|
249
|
+
if (daysOffset !== undefined) {
|
|
250
|
+
date.setDate(date.getDate() + daysOffset);
|
|
251
|
+
}
|
|
252
|
+
return date;
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
let date = parse(value, 'yyyy-MM-dd', new Date());
|
|
256
|
+
if (Number.isNaN(date.getTime())) {
|
|
257
|
+
date = parse(value, "yyyy-MM-dd'T'HH:mm:ss.SSSX", new Date());
|
|
258
|
+
if (!Number.isNaN(date.getTime())) {
|
|
259
|
+
return generateDateOffset({ date, daysOffset });
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
return generateDateOffset({ date, daysOffset });
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
function generateDateOffset({ date, daysOffset, }) {
|
|
268
|
+
if (daysOffset !== undefined) {
|
|
269
|
+
return add(date, { days: daysOffset });
|
|
270
|
+
}
|
|
271
|
+
return date;
|
|
272
|
+
}
|
|
273
|
+
export const replaceSubmissionFormatters = {
|
|
274
|
+
formatDate: (v) => {
|
|
275
|
+
const date = generateDate({
|
|
276
|
+
value: v,
|
|
277
|
+
daysOffset: undefined,
|
|
278
|
+
});
|
|
279
|
+
if (date) {
|
|
280
|
+
return formatDate(date);
|
|
281
|
+
}
|
|
282
|
+
return '';
|
|
283
|
+
},
|
|
284
|
+
formatDateTime: (value) => formatDatetime(new Date(value)),
|
|
285
|
+
formatTime: (value) => formatTime(new Date(value)),
|
|
286
|
+
formatCurrency: (value) => formatCurrency(value),
|
|
287
|
+
formatNumber: (value) => value.toString(),
|
|
288
|
+
};
|
|
289
|
+
/**
|
|
290
|
+
* Replace the `{ELEMENT:<elementName>}` values in text after a successful form
|
|
291
|
+
* submission as well as other replaceable parameters e.g. `submissionId`. The
|
|
292
|
+
* replacements are suppose to be user friendly and for display purposes, e.g.
|
|
293
|
+
* dates should be displayed in the user's desired format and timezone.
|
|
294
|
+
*
|
|
295
|
+
* @param text
|
|
296
|
+
* @param options
|
|
297
|
+
* @returns
|
|
298
|
+
*/
|
|
299
|
+
export function replaceInjectablesWithSubmissionValues(text, options) {
|
|
300
|
+
return submissionService.replaceInjectablesWithSubmissionValues(text, {
|
|
301
|
+
...options,
|
|
302
|
+
...replaceSubmissionFormatters,
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Replace the `{ELEMENT:<elementName>}` values in text while a form is being
|
|
307
|
+
* filled out. The replacements are suppose to be user friendly and for display
|
|
308
|
+
* purposes, e.g. dates should be displayed in the user's desired format and
|
|
309
|
+
* timezone.
|
|
310
|
+
*
|
|
311
|
+
* @param text
|
|
312
|
+
* @param options
|
|
313
|
+
* @returns
|
|
314
|
+
*/
|
|
315
|
+
export function replaceInjectablesWithElementValues(text, options) {
|
|
316
|
+
return submissionService.replaceInjectablesWithElementValues(text, {
|
|
317
|
+
...options,
|
|
318
|
+
...replaceSubmissionFormatters,
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
//# sourceMappingURL=localisation-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localisation-service.js","sourceRoot":"","sources":["../../src/apps/localisation-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,OAAO,MAAM,WAAW,CAAA;AAC/B,OAAO,MAAM,MAAM,cAAc,CAAA;AACjC,OAAO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H,MAAM,UAAU,sCAAsC,CACpD,IAAY,EACZ,OAKC;IAED,OAAO,iBAAiB,CAAC,sCAAsC,CAAC,IAAI,EAAE;QACpE,GAAG,OAAO;QACV,GAAG,2BAA2B;KAC/B,CAAC,CAAA;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,mCAAmC,CACjD,IAAY,EACZ,OAGC;IAED,OAAO,iBAAiB,CAAC,mCAAmC,CAAC,IAAI,EAAE;QACjE,GAAG,OAAO;QACV,GAAG,2BAA2B;KAC/B,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import { submissionService } from '@oneblink/sdk-core'\nimport tenants from './tenants'\nimport parser from 'ua-parser-js'\nimport { add, parse } from 'date-fns'\n\nlet iosVersion: number | undefined\nconst parsedUserAgent: parser.IResult = parser(window.navigator.userAgent)\nif (\n parsedUserAgent.os.name === 'iOS' &&\n typeof parsedUserAgent.os.version === 'string'\n) {\n iosVersion = parseFloat(parsedUserAgent.os.version)\n if (Number.isNaN(iosVersion)) {\n iosVersion = undefined\n }\n}\n\n/**\n * Get the locale (e.g. `en-AU`) for the current tenant.\n *\n * #### Example\n *\n * ```js\n * const locale = localisationService.getLocale()\n * ```\n *\n * @returns\n */\nexport function getLocale() {\n return tenants.locale\n}\n\n/**\n * Get the distance units (e.g. `feet` & 'ft) for the current tenant.\n *\n * #### Example\n *\n * ```js\n * const { distanceUnit, distanceUnitShortName } =\n * localisationService.getDistanceUnits()\n * ```\n *\n * @returns\n */\nexport function getDistanceUnits() {\n return {\n distanceUnit: tenants.current.distanceUnit,\n distanceUnitShortName: tenants.current.distanceUnitShortName,\n }\n}\n\nfunction generateFormats({\n time,\n shortDate,\n shortYearlessDate,\n longDate,\n longYearlessDate,\n}: {\n time: string\n shortDate: string\n shortYearlessDate: string\n longDate: string\n longYearlessDate: string\n}) {\n return {\n time,\n shortDate,\n shortYearlessDate,\n longDate,\n longYearlessDate,\n shortDateTime: `${shortDate} ${time}`,\n longDateTime: `${longDate} ${time}`,\n }\n}\n\nexport function getDateFnsFormats() {\n const time = 'h:mm a'\n switch (tenants.locale) {\n case 'en-US': {\n return generateFormats({\n time,\n shortDate: 'MM/dd/yyyy',\n shortYearlessDate: 'MM/dd',\n longDate: 'MMM do, yyyy',\n longYearlessDate: 'MMM do',\n })\n }\n case 'en-AU':\n default: {\n return generateFormats({\n time,\n shortDate: 'dd/MM/yyyy',\n shortYearlessDate: 'dd/MM',\n longDate: 'do MMM, yyyy',\n longYearlessDate: 'do MMM',\n })\n }\n }\n}\n\n/**\n * Format a `Date` as a `string` that just contains the date portion e.g.\n * _31/01/2020_\n *\n * #### Example\n *\n * ```js\n * const date = new Date()\n * const text = localisationService.formatDate(date)\n * // Display text\n * ```\n *\n * @param value\n * @returns\n */\nexport function formatDate(value: Date): string {\n return tenants.current.intlFormats.date.format(value)\n}\n\n/**\n * Format a `Date` as a `string` that just contains the date portion in a long\n * format e.g. _Thursday, 2 January 2020_\n *\n * #### Example\n *\n * ```js\n * const date = new Date()\n * const text = localisationService.formatDateLong(date)\n * // Display text\n * ```\n *\n * @param value\n * @returns\n */\nexport function formatDateLong(value: Date): string {\n return tenants.current.intlFormats.dateLong.format(value)\n}\n\n/**\n * Format a `Date` as a `string` that just contains the time portion e.g. _5:31\n * pm_\n *\n * #### Example\n *\n * ```js\n * const date = new Date()\n * const text = localisationService.formatTime(date)\n * // Display text\n * ```\n *\n * @param value\n * @returns\n */\nexport function formatTime(value: Date): string {\n /*\n * Time formatting for older iOS devices. Prevents date from repeating.\n * Example: Last sync time: 24/11/2022 24/11/2022\n */\n if (typeof iosVersion === 'number' && iosVersion < 13.0) {\n const time = tenants.current.intlFormats.olderIOSTime.formatToParts(value)\n const newTime = time.map((t) => t.value).join('')\n return `${newTime}`\n }\n return tenants.current.intlFormats.time.format(value)\n}\n\n/**\n * Format a `Date` as a `string` that contains the date and time portions e.g.\n * _31/01/2020 5:31 pm_\n *\n * #### Example\n *\n * ```js\n * const date = new Date()\n * const text = localisationService.formatDatetime(date)\n * // Display text\n * ```\n *\n * @param value\n * @returns\n */\nexport function formatDatetime(value: Date) {\n return `${formatDate(value)} ${formatTime(value)}`\n}\n\n/**\n * Format a `Date` as a `string` that contains the date and time portions in a\n * long format e.g. _Thursday, 2 January 2020 5:31 pm_\n *\n * #### Example\n *\n * ```js\n * const date = new Date()\n * const text = localisationService.formatDatetime(date)\n * // Display text\n * ```\n *\n * @param value\n * @returns\n */\nexport function formatDatetimeLong(value: Date) {\n return `${formatDateLong(value)} ${formatTime(value)}`\n}\n\n/**\n * Format a `number` as a `string` represented as a readable number e.g.\n * _123,321.123_\n *\n * #### Example\n *\n * ```js\n * const amount = 1234.4321\n * const text = localisationService.formatCurrency(amount)\n * // Display text\n * ```\n *\n * @param value\n * @returns\n */\nexport function formatNumber(value: number): string {\n return tenants.current.intlFormats.number.format(value)\n}\n\n/**\n * Format a `number` as a `string` represented as a currency e.g. _$123.31_\n *\n * #### Example\n *\n * ```js\n * const amount = 123.321\n * const text = localisationService.formatCurrency(amount)\n * // Display text\n * ```\n *\n * @param value\n * @returns\n */\nexport function formatCurrency(value: number): string {\n return tenants.current.intlFormats.currency.format(value)\n}\n\n/**\n * Generate a `Date` based a `string` while adding/subtracting a number of days.\n * Use this function to generate a date with the correct time if only the date\n * part is required to be formatted for display purposes. Also supports passing\n * `'NOW'` as the value to get the current date with an offset.\n *\n * #### Example\n *\n * ```js\n * const dateOnly = localisationService.generateDate({\n * value: '2023-05-04',\n * dateOnly: true,\n * daysOffset: undefined,\n * })\n *\n * const date = localisationService.generateDate({\n * value: '2023-05-04T02:49:23.616Z',\n * dateOnly: false,\n * daysOffset: undefined,\n * })\n *\n * const now = localisationService.generateDate({\n * value: 'NOW',\n * dateOnly: false,\n * daysOffset: undefined,\n * })\n * ```\n *\n * @param options\n * @returns\n */\nexport function generateDate({\n daysOffset,\n value,\n}: {\n daysOffset: number | undefined\n value: string\n}): Date | undefined {\n if (value === 'NOW') {\n const date = new Date()\n if (daysOffset !== undefined) {\n date.setDate(date.getDate() + daysOffset)\n }\n return date\n } else {\n let date = parse(value, 'yyyy-MM-dd', new Date())\n if (Number.isNaN(date.getTime())) {\n date = parse(value, \"yyyy-MM-dd'T'HH:mm:ss.SSSX\", new Date())\n if (!Number.isNaN(date.getTime())) {\n return generateDateOffset({ date, daysOffset })\n }\n } else {\n return generateDateOffset({ date, daysOffset })\n }\n }\n}\n\nfunction generateDateOffset({\n date,\n daysOffset,\n}: {\n daysOffset: number | undefined\n date: Date\n}) {\n if (daysOffset !== undefined) {\n return add(date, { days: daysOffset })\n }\n return date\n}\n\nexport const replaceSubmissionFormatters: submissionService.ReplaceInjectablesFormatters =\n {\n formatDate: (v) => {\n const date = generateDate({\n value: v,\n daysOffset: undefined,\n })\n if (date) {\n return formatDate(date)\n }\n return ''\n },\n formatDateTime: (value) => formatDatetime(new Date(value)),\n formatTime: (value) => formatTime(new Date(value)),\n formatCurrency: (value) => formatCurrency(value),\n formatNumber: (value) => value.toString(),\n }\n\n/**\n * Replace the `{ELEMENT:<elementName>}` values in text after a successful form\n * submission as well as other replaceable parameters e.g. `submissionId`. The\n * replacements are suppose to be user friendly and for display purposes, e.g.\n * dates should be displayed in the user's desired format and timezone.\n *\n * @param text\n * @param options\n * @returns\n */\nexport function replaceInjectablesWithSubmissionValues(\n text: string,\n options: Omit<\n Parameters<\n typeof submissionService.replaceInjectablesWithSubmissionValues\n >[1],\n keyof submissionService.ReplaceInjectablesFormatters\n >,\n): ReturnType<typeof submissionService.replaceInjectablesWithSubmissionValues> {\n return submissionService.replaceInjectablesWithSubmissionValues(text, {\n ...options,\n ...replaceSubmissionFormatters,\n })\n}\n\n/**\n * Replace the `{ELEMENT:<elementName>}` values in text while a form is being\n * filled out. The replacements are suppose to be user friendly and for display\n * purposes, e.g. dates should be displayed in the user's desired format and\n * timezone.\n *\n * @param text\n * @param options\n * @returns\n */\nexport function replaceInjectablesWithElementValues(\n text: string,\n options: Omit<\n Parameters<typeof submissionService.replaceInjectablesWithElementValues>[1],\n keyof submissionService.ReplaceInjectablesFormatters\n >,\n): ReturnType<typeof submissionService.replaceInjectablesWithElementValues> {\n return submissionService.replaceInjectablesWithElementValues(text, {\n ...options,\n ...replaceSubmissionFormatters,\n })\n}\n"]}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { FormsAppsTypes } from '@oneblink/types';
|
|
2
|
+
/**
|
|
3
|
+
* Check if the user is currently subscribed to notifications
|
|
4
|
+
*
|
|
5
|
+
* #### Example
|
|
6
|
+
*
|
|
7
|
+
* ```js
|
|
8
|
+
* const isSubscribed = await notificationService.isSubscribed()
|
|
9
|
+
* // Allow user to subscribe or unsubscribe
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
declare function isSubscribed(): Promise<boolean>;
|
|
15
|
+
/**
|
|
16
|
+
* Subscribe the current user to notifications
|
|
17
|
+
*
|
|
18
|
+
* #### Example
|
|
19
|
+
*
|
|
20
|
+
* ```js
|
|
21
|
+
* const formsAppId = 1
|
|
22
|
+
* const isSubscribed = await notificationService.subscribe(formsAppId)
|
|
23
|
+
* // isSubscribed will be false if user denied permission to push notifications
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @param formsAppId
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
declare function subscribe(formsAppId: number): Promise<boolean>;
|
|
30
|
+
/**
|
|
31
|
+
* Subscribe the current user to notifications
|
|
32
|
+
*
|
|
33
|
+
* #### Example
|
|
34
|
+
*
|
|
35
|
+
* ```js
|
|
36
|
+
* const formsAppId = 1
|
|
37
|
+
* await notificationService.unsubscribe(formsAppId)
|
|
38
|
+
* // isSubscribed will be false if user denied permission to push notifications
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @param formsAppId
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
declare function unsubscribe(formsAppId: number): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Get the current users email subscriptions for a single forms app.
|
|
47
|
+
*
|
|
48
|
+
* #### Example
|
|
49
|
+
*
|
|
50
|
+
* ```js
|
|
51
|
+
* const formsAppId = 1
|
|
52
|
+
* const emailSubscriptions =
|
|
53
|
+
* await approvalsService.getEmailSubscriptions(formsAppId)
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @param formsAppId
|
|
57
|
+
* @param abortSignal
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
export declare function getEmailSubscriptions(formsAppId: number, abortSignal?: AbortSignal): Promise<FormsAppsTypes.FormsAppUserSubscription['emailSubscriptions']>;
|
|
61
|
+
/**
|
|
62
|
+
* Update the current users email subscriptions for a single forms app.
|
|
63
|
+
*
|
|
64
|
+
* #### Example
|
|
65
|
+
*
|
|
66
|
+
* ```js
|
|
67
|
+
* const emailSubscriptions = {
|
|
68
|
+
* newApproval: true,
|
|
69
|
+
* clarificationReceived: true,
|
|
70
|
+
* }
|
|
71
|
+
* const savedFormsAppUserSubscription =
|
|
72
|
+
* await approvalsService.updateFormsAppUserSubscription(
|
|
73
|
+
* emailSubscriptions,
|
|
74
|
+
* )
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @param formsAppId
|
|
78
|
+
* @param emailSubscriptions
|
|
79
|
+
* @param abortSignal
|
|
80
|
+
* @returns
|
|
81
|
+
*/
|
|
82
|
+
export declare function updateEmailSubscriptions(formsAppId: number, emailSubscriptions: FormsAppsTypes.FormsAppUserSubscription['emailSubscriptions'], abortSignal?: AbortSignal): Promise<void>;
|
|
83
|
+
export { isSubscribed, subscribe, unsubscribe };
|