@timum/timum_pdk 2.2.0 → 2.2.1

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/src/timumPdk.js CHANGED
@@ -1,378 +1,372 @@
1
- import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
2
-
3
- import failsaveStorage from "./util/failSafeLocalStorage";
4
-
5
- let host = undefined;
6
- export const setTimumApiHost = (url) => {
7
- host = url;
8
- };
9
-
10
- export const getTimumApiHost = () => {
11
- if (host) {
12
- return host;
13
- } else {
14
- return failsaveStorage.get("timumApiHost", "https://www.timum.de");
15
- }
16
- };
17
-
18
- // we do it this way so that the base url can be determined dynamically
19
- export const getBaseUrl = () => {
20
- return getTimumApiHost() + "/rest/1";
21
- };
22
-
23
- export const constructUrl = (url, props, plain) => {
24
- if (props.params) {
25
- for (const [paramName, paramValue] of Object.entries(props.params)) {
26
- if (Array.isArray(paramValue)) {
27
- for (let el of paramValue) {
28
- if (!url.includes("?")) {
29
- url = `${url}?${paramName}=${el}`;
30
- } else {
31
- url = `${url}&${paramName}=${el}`;
32
- }
33
- }
34
-
35
- } else {
36
- if (!url.includes("?")) {
37
- url = `${url}?${paramName}=${paramValue}`;
38
- } else {
39
- url = `${url}&${paramName}=${paramValue}`;
40
- }
41
- }
42
- }
43
- }
44
-
45
- if (!url.includes("?")) {
46
- url = `${url}?X-DISABLE-COOKIES=true`;
47
- } else {
48
- url = `${url}&X-DISABLE-COOKIES=true`;
49
- }
50
-
51
- if (plain) {
52
- return `${getTimumApiHost()}${url}`;
53
- } else {
54
- return `${getBaseUrl()}${url}`;
55
- }
56
- };
57
-
58
- export const timumApiSlice = createApi({
59
- reducerPath: "timumApi",
60
- baseQuery: fetchBaseQuery({
61
- baseUrl: undefined,
62
- credentials: "include",
63
- }),
64
- tagTypes: [
65
- "Timeslot",
66
- "Product",
67
- "Account",
68
- "Provider",
69
- "User",
70
- "IdentifiedCustomer",
71
- ],
72
- endpoints: (builder) => ({
73
- // ##########################################
74
- // # ConsumerAPI v2
75
- // ##########################################
76
-
77
- upcomingBookables: builder.query({
78
- query: (props) => ({
79
- url: constructUrl(
80
- `/resources/${props.channelOrResourceId}/upcoming_bookables`,
81
- props
82
- ),
83
- headers: props.headers,
84
- }),
85
- providesTags: (/* result = [], error, arg */) => ["Timeslot"],
86
- }),
87
-
88
- specificBookables: builder.query({
89
- query: (props) => ({
90
- url: constructUrl(
91
- `/bookables/specific_bookables`,
92
- props
93
- ),
94
- headers: props.headers,
95
- method: "post",
96
- body: props.body,
97
- }),
98
- providesTags: (/* result = [], error, arg */) => ["Timeslot"],
99
- }),
100
-
101
- activeProducts: builder.query({
102
- query: (props) => ({
103
- url: constructUrl(
104
- `/resources/${props.channelOrResourceId}/active_products`,
105
- props
106
- ),
107
- headers: props.headers,
108
- }),
109
- providesTags: (/* result = [], error, arg */) => ["Product"],
110
- }),
111
-
112
- specificProducts: builder.query({
113
- query: (props) => ({
114
- url: constructUrl(
115
- `/products/specific_products`,
116
- props
117
- ),
118
- headers: props.headers,
119
- method: "post",
120
- body: props.body,
121
- }),
122
- providesTags: (/* result = [], error, arg */) => ["Product"],
123
- }),
124
-
125
- createAppointmentWithConsumer: builder.mutation({
126
- query: (props) => ({
127
- url: constructUrl(
128
- `/resources/${props.channelOrResourceId}/create_appointment_with_consumer`,
129
- props
130
- ),
131
- method: "post",
132
- body: props.body,
133
- headers: props.headers,
134
- }),
135
- invalidatesTags: (result, error, arg) => {
136
- const invalidatedTags = [{ type: "Timeslot" }];
137
-
138
- if (arg.shouldInvalidateCustomerIdentification) {
139
- invalidatedTags.push({ type: "IdentifiedCustomer" });
140
- }
141
-
142
- return invalidatedTags;
143
- },
144
- }),
145
-
146
- removeCustomerFromAppointment: builder.mutation({
147
- query: (props) => ({
148
- url: constructUrl(
149
- `/customers/${props.customersId}/appointments/${props.appointmentId}`,
150
- props
151
- ),
152
- method: "delete",
153
- headers: props.headers,
154
- }),
155
- invalidatesTags: (/* result, error, arg */) => [{ type: "Timeslot" }],
156
- }),
157
-
158
- authenticate: builder.query({
159
- query: (props) => {
160
- return {
161
- url: constructUrl(`/auth/cookieless/login`, props, true),
162
- headers: props.headers,
163
- method: "post",
164
- body: props.body,
165
- };
166
- },
167
- }),
168
-
169
- /**
170
- * Returns an object with the following makeup:
171
- * {
172
- * contact: {
173
- * name,
174
- * email,
175
- * mobile,
176
- * phone
177
- * },
178
- * resource: {
179
- * name,
180
- * description,
181
- * msgHelpText
182
- * },
183
- * provider: {
184
- * name
185
- * }
186
- * }
187
- */
188
- publicData: builder.query({
189
- query: (props) => ({
190
- url: constructUrl(
191
- `/resources/${props.channelOrResourceId}/public_data`,
192
- props
193
- ),
194
- headers: props.headers,
195
- }),
196
- }),
197
-
198
- identifyCustomer: builder.query({
199
- query: (props) => ({
200
- url: constructUrl(
201
- `/crms/${props.crmSlug}/resources/${props.channelOrResourceId}/customers/${props.personId}/identify`,
202
- props
203
- ),
204
- headers: props.headers,
205
- }),
206
- providesTags: "IdentifiedCustomer", //
207
- keepUnusedDataFor: 9999999, // once identified it's not going to change
208
- }),
209
-
210
- /**
211
- * body contain:
212
- * resource_id*,
213
- * product_id*,
214
- * provider_id,
215
- * timeslotUuid (if available)
216
- * from* (ISO format),
217
- * to* (ISO format)
218
- * -> * marks those which are required.
219
- */
220
- reserveAppoinment: builder.mutation({
221
- query: (props) => ({
222
- url: constructUrl(
223
- `/resources/${props.channelOrResourceId}/reserve_appointment`,
224
- props
225
- ),
226
- method: "post",
227
- body: props.body,
228
- headers: props.headers,
229
- }),
230
- }),
231
-
232
- /**
233
- * body must contain:
234
- * placeholder_id (id created for ephemeral customer during call to),
235
- * appointment_id
236
- */
237
- revokeAppointmentReservation: builder.mutation({
238
- query: (props) => ({
239
- url: constructUrl(
240
- `/resources/${props.channelOrResourceId}/revoke_reservation`,
241
- props
242
- ),
243
- method: "post",
244
- body: props.body,
245
- headers: props.headers,
246
- }),
247
- }),
248
-
249
- // ##########################################
250
- // # CRM API requests (general api)
251
- // ##########################################
252
-
253
- getAccount: builder.query({
254
- query: (props) => ({
255
- url: constructUrl(
256
- `/crms/${props.platform}/account/${props.accountReference}`,
257
- props
258
- ),
259
- }),
260
- providesTags: (/* result = [], error, arg */) => ["Account"],
261
- }),
262
-
263
- createAccount: builder.mutation({
264
- query: (props) => {
265
- return {
266
- url: constructUrl(`/crms/${props.platform}/account`, props),
267
- method: "post",
268
- body: JSON.stringify(props.accountData),
269
- };
270
- },
271
- invalidatesTags: (/* result, error, arg */) => [{ type: "Account" }],
272
- }),
273
-
274
- getProviders: builder.query({
275
- query: (props) => ({
276
- url: constructUrl(
277
- `/crms/${props.platform}/account/${props.accountReference}/providers`,
278
- props
279
- ),
280
- }),
281
- providesTags: (/* result = [], error, arg */) => ["Product"],
282
- }),
283
-
284
- getProvider: builder.query({
285
- query: (props) => ({
286
- url: constructUrl(
287
- `/crms/${props.platform}/provider/${props.providerReference}`,
288
- props
289
- ),
290
- }),
291
- }),
292
-
293
- createProvider: builder.mutation({
294
- query: (props) => ({
295
- url: constructUrl(`/crms/${props.platform}/provider`, props),
296
- method: "post",
297
- body: JSON.stringify(
298
- (() => ({
299
- user: props.userData ?? {},
300
- provider: props.providerData ?? {},
301
- address: props.addressData ?? null,
302
- account: props.account ?? null,
303
- sendEmail: props.sendEmail ?? false,
304
- }))()
305
- ),
306
- }),
307
- invalidatesTags: (/* result, error, arg */) => [{ type: "Provider" }],
308
- }),
309
-
310
- // loginUserViaApi: builder.query({
311
- // query: (props) => ({
312
- // url: constructUrl(`/crms/${props.platform}/user/loginWithJwt`),
313
- // }),
314
- // async onQueryStarted(props, { dispatch, queryFulfilled }) {
315
- // const { data /* , meta */ } = await queryFulfilled;
316
- // if (data) {
317
- // dispatch(timumClientAuthorised({ auth2: data.auth2 }));
318
- // }
319
- // },
320
- // }),
321
- getUser: builder.query({
322
- query: (props) => ({
323
- url: constructUrl(
324
- `/crms/${props.platform}/user/${props.userReference}`,
325
- props
326
- ),
327
- }),
328
- }),
329
-
330
- createUser: builder.mutation({
331
- query: (props) => ({
332
- url: constructUrl(`/crms/${props.platform}/user`, props),
333
- method: "post",
334
- body: JSON.stringify(props.userData),
335
- }),
336
- invalidatesTags: (/* result, error, arg */) => [{ type: "User" }],
337
- }),
338
- }),
339
- });
340
-
341
- export const {
342
- // ##########################################
343
- // # ConsumerAPI v2
344
- // ##########################################
345
-
346
- useUpcomingBookablesQuery,
347
- useLazyUpcomingBookablesQuery,
348
- useSpecificBookablesQuery,
349
- useLazySpecificBookablesQuery,
350
- useActiveProductsQuery,
351
- useLazyActiveProductsQuery,
352
- useSpecificProductsQuery,
353
- useLazySpecificProductsQuery,
354
- useCreateAppointmentWithConsumerMutation,
355
- useIdentifyCustomerQuery,
356
- useLazyIdentifyCustomerQuery,
357
- usePublicDataQuery,
358
- useLazyPublicDataQuery,
359
- useReserveAppoinmentMutation,
360
- useRevokeAppointmentReservationMutation,
361
- useRemoveCustomerFromAppointmentMutation,
362
- useAuthenticateQuery,
363
- useLazyAuthenticateQuery,
364
-
365
- // ##########################################
366
- // # CRM API requests (general api)
367
- // ##########################################
368
- useCreateAccountMutation,
369
- useGetAccountQuery,
370
- useLazyGetAccountQuery,
371
- useGetProvidersQuery,
372
- useLazyGetProvidersQuery,
373
- useCreateProviderMutation,
374
- // useLoginUserViaApiQuery,
375
- useCreateUserMutation,
376
- useGetUserQuery,
377
- useLazyGetUserQuery,
378
- } = timumApiSlice;
1
+ import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
2
+
3
+ import failsaveStorage from './util/failSafeLocalStorage';
4
+
5
+ let host = undefined;
6
+ export const setTimumApiHost = (url) => {
7
+ host = url;
8
+ };
9
+
10
+ export const getTimumApiHost = () => {
11
+ if (host) {
12
+ return host;
13
+ } else {
14
+ return failsaveStorage.get('timumApiHost', 'https://www.timum.de');
15
+ }
16
+ };
17
+
18
+ // we do it this way so that the base url can be determined dynamically
19
+ export const getBaseUrl = () => {
20
+ return getTimumApiHost() + '/rest/1';
21
+ };
22
+
23
+ export const constructUrl = (url, props, plain) => {
24
+ if (props.params) {
25
+ for (const [paramName, paramValue] of Object.entries(props.params)) {
26
+ if (Array.isArray(paramValue)) {
27
+ for (let el of paramValue) {
28
+ if (!url.includes('?')) {
29
+ url = `${url}?${paramName}=${el}`;
30
+ } else {
31
+ url = `${url}&${paramName}=${el}`;
32
+ }
33
+ }
34
+ } else {
35
+ if (!url.includes('?')) {
36
+ url = `${url}?${paramName}=${paramValue}`;
37
+ } else {
38
+ url = `${url}&${paramName}=${paramValue}`;
39
+ }
40
+ }
41
+ }
42
+ }
43
+
44
+ if (!url.includes('?')) {
45
+ url = `${url}?X-DISABLE-COOKIES=true`;
46
+ } else {
47
+ url = `${url}&X-DISABLE-COOKIES=true`;
48
+ }
49
+
50
+ if (plain) {
51
+ return `${getTimumApiHost()}${url}`;
52
+ } else {
53
+ return `${getBaseUrl()}${url}`;
54
+ }
55
+ };
56
+
57
+ export const timumApiSlice = createApi({
58
+ reducerPath: 'timumApi',
59
+ baseQuery: fetchBaseQuery({
60
+ baseUrl: undefined,
61
+ credentials: 'include',
62
+ }),
63
+ tagTypes: [
64
+ 'Timeslot',
65
+ 'Product',
66
+ 'Account',
67
+ 'Provider',
68
+ 'User',
69
+ 'IdentifiedCustomer',
70
+ ],
71
+ endpoints: (builder) => ({
72
+ // ##########################################
73
+ // # ConsumerAPI v2
74
+ // ##########################################
75
+
76
+ upcomingBookables: builder.query({
77
+ query: (props) => ({
78
+ url: constructUrl(
79
+ `/resources/${props.channelOrResourceId}/upcoming_bookables`,
80
+ props,
81
+ ),
82
+ method: 'post',
83
+ headers: props.headers,
84
+ }),
85
+ providesTags: (/* result = [], error, arg */) => ['Timeslot'],
86
+ }),
87
+
88
+ specificBookables: builder.query({
89
+ query: (props) => ({
90
+ url: constructUrl(`/bookables/specific_bookables`, props),
91
+ headers: props.headers,
92
+ method: 'post',
93
+ body: props.body,
94
+ }),
95
+ providesTags: (/* result = [], error, arg */) => ['Timeslot'],
96
+ }),
97
+
98
+ activeProducts: builder.query({
99
+ query: (props) => ({
100
+ url: constructUrl(
101
+ `/resources/${props.channelOrResourceId}/active_products`,
102
+ props,
103
+ ),
104
+ headers: props.headers,
105
+ }),
106
+ providesTags: (/* result = [], error, arg */) => ['Product'],
107
+ }),
108
+
109
+ specificProducts: builder.query({
110
+ query: (props) => ({
111
+ url: constructUrl(`/products/specific_products`, props),
112
+ headers: props.headers,
113
+ method: 'post',
114
+ body: props.body,
115
+ }),
116
+ providesTags: (/* result = [], error, arg */) => ['Product'],
117
+ }),
118
+
119
+ createAppointmentWithConsumer: builder.mutation({
120
+ query: (props) => ({
121
+ url: constructUrl(
122
+ `/resources/${props.channelOrResourceId}/create_appointment_with_consumer`,
123
+ props,
124
+ ),
125
+ method: 'post',
126
+ body: props.body,
127
+ headers: props.headers,
128
+ }),
129
+ invalidatesTags: (result, error, arg) => {
130
+ const invalidatedTags = [{ type: 'Timeslot' }];
131
+
132
+ if (arg.shouldInvalidateCustomerIdentification) {
133
+ invalidatedTags.push({ type: 'IdentifiedCustomer' });
134
+ }
135
+
136
+ return invalidatedTags;
137
+ },
138
+ }),
139
+
140
+ removeCustomerFromAppointment: builder.mutation({
141
+ query: (props) => ({
142
+ url: constructUrl(
143
+ `/customers/${props.customersId}/appointments/${props.appointmentId}`,
144
+ props,
145
+ ),
146
+ method: 'delete',
147
+ headers: props.headers,
148
+ }),
149
+ invalidatesTags: (/* result, error, arg */) => [{ type: 'Timeslot' }],
150
+ }),
151
+
152
+ authenticate: builder.query({
153
+ query: (props) => {
154
+ return {
155
+ url: constructUrl(`/auth/cookieless/login`, props, true),
156
+ headers: props.headers,
157
+ method: 'post',
158
+ body: props.body,
159
+ };
160
+ },
161
+ }),
162
+
163
+ /**
164
+ * Returns an object with the following makeup:
165
+ * {
166
+ * contact: {
167
+ * name,
168
+ * email,
169
+ * mobile,
170
+ * phone
171
+ * },
172
+ * resource: {
173
+ * name,
174
+ * description,
175
+ * msgHelpText
176
+ * },
177
+ * provider: {
178
+ * name
179
+ * }
180
+ * }
181
+ */
182
+ publicData: builder.query({
183
+ query: (props) => ({
184
+ url: constructUrl(
185
+ `/resources/${props.channelOrResourceId}/public_data`,
186
+ props,
187
+ ),
188
+ headers: props.headers,
189
+ }),
190
+ }),
191
+
192
+ identifyCustomer: builder.query({
193
+ query: (props) => ({
194
+ url: constructUrl(
195
+ `/crms/${props.crmSlug}/resources/${props.channelOrResourceId}/customers/${props.personId}/identify`,
196
+ props,
197
+ ),
198
+ headers: props.headers,
199
+ }),
200
+ providesTags: 'IdentifiedCustomer', //
201
+ keepUnusedDataFor: 9999999, // once identified it's not going to change
202
+ }),
203
+
204
+ /**
205
+ * body contain:
206
+ * resource_id*,
207
+ * product_id*,
208
+ * provider_id,
209
+ * timeslotUuid (if available)
210
+ * from* (ISO format),
211
+ * to* (ISO format)
212
+ * -> * marks those which are required.
213
+ */
214
+ reserveAppoinment: builder.mutation({
215
+ query: (props) => ({
216
+ url: constructUrl(
217
+ `/resources/${props.channelOrResourceId}/reserve_appointment`,
218
+ props,
219
+ ),
220
+ method: 'post',
221
+ body: props.body,
222
+ headers: props.headers,
223
+ }),
224
+ }),
225
+
226
+ /**
227
+ * body must contain:
228
+ * placeholder_id (id created for ephemeral customer during call to),
229
+ * appointment_id
230
+ */
231
+ revokeAppointmentReservation: builder.mutation({
232
+ query: (props) => ({
233
+ url: constructUrl(
234
+ `/resources/${props.channelOrResourceId}/revoke_reservation`,
235
+ props,
236
+ ),
237
+ method: 'post',
238
+ body: props.body,
239
+ headers: props.headers,
240
+ }),
241
+ }),
242
+
243
+ // ##########################################
244
+ // # CRM API requests (general api)
245
+ // ##########################################
246
+
247
+ getAccount: builder.query({
248
+ query: (props) => ({
249
+ url: constructUrl(
250
+ `/crms/${props.platform}/account/${props.accountReference}`,
251
+ props,
252
+ ),
253
+ }),
254
+ providesTags: (/* result = [], error, arg */) => ['Account'],
255
+ }),
256
+
257
+ createAccount: builder.mutation({
258
+ query: (props) => {
259
+ return {
260
+ url: constructUrl(`/crms/${props.platform}/account`, props),
261
+ method: 'post',
262
+ body: JSON.stringify(props.accountData),
263
+ };
264
+ },
265
+ invalidatesTags: (/* result, error, arg */) => [{ type: 'Account' }],
266
+ }),
267
+
268
+ getProviders: builder.query({
269
+ query: (props) => ({
270
+ url: constructUrl(
271
+ `/crms/${props.platform}/account/${props.accountReference}/providers`,
272
+ props,
273
+ ),
274
+ }),
275
+ providesTags: (/* result = [], error, arg */) => ['Product'],
276
+ }),
277
+
278
+ getProvider: builder.query({
279
+ query: (props) => ({
280
+ url: constructUrl(
281
+ `/crms/${props.platform}/provider/${props.providerReference}`,
282
+ props,
283
+ ),
284
+ }),
285
+ }),
286
+
287
+ createProvider: builder.mutation({
288
+ query: (props) => ({
289
+ url: constructUrl(`/crms/${props.platform}/provider`, props),
290
+ method: 'post',
291
+ body: JSON.stringify(
292
+ (() => ({
293
+ user: props.userData ?? {},
294
+ provider: props.providerData ?? {},
295
+ address: props.addressData ?? null,
296
+ account: props.account ?? null,
297
+ sendEmail: props.sendEmail ?? false,
298
+ }))(),
299
+ ),
300
+ }),
301
+ invalidatesTags: (/* result, error, arg */) => [{ type: 'Provider' }],
302
+ }),
303
+
304
+ // loginUserViaApi: builder.query({
305
+ // query: (props) => ({
306
+ // url: constructUrl(`/crms/${props.platform}/user/loginWithJwt`),
307
+ // }),
308
+ // async onQueryStarted(props, { dispatch, queryFulfilled }) {
309
+ // const { data /* , meta */ } = await queryFulfilled;
310
+ // if (data) {
311
+ // dispatch(timumClientAuthorised({ auth2: data.auth2 }));
312
+ // }
313
+ // },
314
+ // }),
315
+ getUser: builder.query({
316
+ query: (props) => ({
317
+ url: constructUrl(
318
+ `/crms/${props.platform}/user/${props.userReference}`,
319
+ props,
320
+ ),
321
+ }),
322
+ }),
323
+
324
+ createUser: builder.mutation({
325
+ query: (props) => ({
326
+ url: constructUrl(`/crms/${props.platform}/user`, props),
327
+ method: 'post',
328
+ body: JSON.stringify(props.userData),
329
+ }),
330
+ invalidatesTags: (/* result, error, arg */) => [{ type: 'User' }],
331
+ }),
332
+ }),
333
+ });
334
+
335
+ export const {
336
+ // ##########################################
337
+ // # ConsumerAPI v2
338
+ // ##########################################
339
+
340
+ useUpcomingBookablesQuery,
341
+ useLazyUpcomingBookablesQuery,
342
+ useSpecificBookablesQuery,
343
+ useLazySpecificBookablesQuery,
344
+ useActiveProductsQuery,
345
+ useLazyActiveProductsQuery,
346
+ useSpecificProductsQuery,
347
+ useLazySpecificProductsQuery,
348
+ useCreateAppointmentWithConsumerMutation,
349
+ useIdentifyCustomerQuery,
350
+ useLazyIdentifyCustomerQuery,
351
+ usePublicDataQuery,
352
+ useLazyPublicDataQuery,
353
+ useReserveAppoinmentMutation,
354
+ useRevokeAppointmentReservationMutation,
355
+ useRemoveCustomerFromAppointmentMutation,
356
+ useAuthenticateQuery,
357
+ useLazyAuthenticateQuery,
358
+
359
+ // ##########################################
360
+ // # CRM API requests (general api)
361
+ // ##########################################
362
+ useCreateAccountMutation,
363
+ useGetAccountQuery,
364
+ useLazyGetAccountQuery,
365
+ useGetProvidersQuery,
366
+ useLazyGetProvidersQuery,
367
+ useCreateProviderMutation,
368
+ // useLoginUserViaApiQuery,
369
+ useCreateUserMutation,
370
+ useGetUserQuery,
371
+ useLazyGetUserQuery,
372
+ } = timumApiSlice;