@timum/timum_pdk 1.0.2

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/.eslintignore ADDED
@@ -0,0 +1,5 @@
1
+ build
2
+ public
3
+ node_modules
4
+ .vscode
5
+ .git
package/.eslintrc ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "settings": {
3
+ "react": {"version":"detect"}
4
+ },
5
+ "extends": [
6
+ "eslint:recommended",
7
+ "plugin:prettier/recommended",
8
+ "plugin:react/recommended",
9
+ "plugin:storybook/recommended"
10
+ ],
11
+ "env": {
12
+ "browser": true,
13
+ "es2022": true,
14
+ "node": true
15
+ },
16
+ "parserOptions": {
17
+ "sourceType": "module"
18
+ },
19
+ "rules": {
20
+ "prettier/prettier": [
21
+ "error",
22
+ {
23
+ "singleQuote": true,
24
+ "endOfLine": "auto"
25
+ }
26
+ ],
27
+ "no-console": "off",
28
+ "react/prop-types": 0
29
+ }
30
+ }
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # README #
2
+
3
+ This repo contains publicly available timum endpoints.
4
+
5
+ It uses Redux, Redux Toolkit and RTKQ.
6
+ Here is how to add it to your store:
7
+
8
+ ````
9
+ import { timumApiSlice } from '@timum/timum_pdk';
10
+
11
+ export default configureStore({
12
+ reducer: {
13
+ [timumApiSlice.reducerPath]: timumApiSlice.reducer,
14
+ },
15
+ middleware: (getDefaultMiddleware) =>
16
+ getDefaultMiddleware().concat(timumApiSlice.middleware)
17
+ });
18
+ ````
19
+
20
+
21
+
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@timum/timum_pdk",
3
+ "version": "1.0.2",
4
+ "dependencies": {
5
+ "@reduxjs/toolkit": "^1.8.0",
6
+ "np": "^7.6.2",
7
+ "react": "^18.2.0",
8
+ "react-dom": "^18.2.0",
9
+ "react-redux": "^8.0.2",
10
+ "reactjs-localstorage": "^1.0.1"
11
+ },
12
+ "scripts": {
13
+ "lint": "eslint .",
14
+ "lint:fix": "eslint --fix .",
15
+ "prepublishOnly": "npm login",
16
+ "postbuild": "np --no-publish --no-yarn",
17
+ "build": "webpack --mode=production",
18
+ "devBuild": "webpack --mode=development",
19
+ "test": "echo \"No tests yet\""
20
+ },
21
+ "browserslist": {
22
+ "production": [
23
+ ">0.2%",
24
+ "not dead",
25
+ "not op_mini all"
26
+ ],
27
+ "development": [
28
+ "last 1 chrome version",
29
+ "last 1 firefox version",
30
+ "last 1 safari version"
31
+ ]
32
+ },
33
+ "devDependencies": {
34
+ "eslint": "^8.17.0",
35
+ "eslint-config-prettier": "^8.5.0",
36
+ "eslint-plugin-prettier": "^4.0.0",
37
+ "eslint-plugin-react": "^7.30.0",
38
+ "webpack": "^5.70.0",
39
+ "webpack-cli": "^4.10.0"
40
+ }
41
+ }
package/src/index.js ADDED
@@ -0,0 +1,180 @@
1
+ import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
2
+
3
+ import { reactLocalStorage } from 'reactjs-localstorage';
4
+
5
+ export const getTimumApiHost = () => {
6
+ return reactLocalStorage.get('timumApiHost', 'www.timum.de');
7
+ };
8
+
9
+ // we do it this way so that the base url can be determined dynamically
10
+ export const getBaseUrl = () => {
11
+ return getTimumApiHost() + '/rest/1';
12
+ };
13
+
14
+ export const constructUrl = (url, plain) => {
15
+ if (!url.includes('?')) {
16
+ url = `${url}?X-DISABLE-COOKIES=true`;
17
+ } else {
18
+ url = `${url}&X-DISABLE-COOKIES=true`;
19
+ }
20
+
21
+ if (plain) {
22
+ return `${getTimumApiHost()}${url}`;
23
+ } else {
24
+ return `${getBaseUrl()}${url}`;
25
+ }
26
+ };
27
+
28
+ export const timumApiSlice = createApi({
29
+ reducerPath: 'timumApi',
30
+ baseQuery: fetchBaseQuery({
31
+ baseUrl: undefined,
32
+ credentials: 'include',
33
+ }),
34
+ tagTypes: ['Timeslot', 'Product', 'Account', 'Provider', 'User'],
35
+ endpoints: (builder) => ({
36
+ // ##########################################
37
+ // # ConsumerAPI v2
38
+ // ##########################################
39
+
40
+ upcomingBookables: builder.query({
41
+ query: (props) => ({
42
+ url: constructUrl(`/resources/${props.resourceId}/upcoming_bookables`),
43
+ }),
44
+ providesTags: (/* result = [], error, arg */) => [
45
+ 'Timeslot'
46
+ ],
47
+ }),
48
+
49
+ activeProducts: builder.query({
50
+ query: (props) => ({
51
+ url: constructUrl(`/resources/${props.resourceId}/active_products`),
52
+ }),
53
+ providesTags: (/* result = [], error, arg */) => [
54
+ 'Product'
55
+ ],
56
+ }),
57
+
58
+ createAppointmentWithConsumer: builder.mutation({
59
+ query: (props) => ({
60
+ url: constructUrl(
61
+ `/resources/${props.resourceId}/create_appointment_with_consumer`
62
+ ),
63
+ method: 'post',
64
+ body: props.body,
65
+ }),
66
+ invalidatesTags: (/* result, error, arg */) => [{ type: 'Timeslot' }],
67
+ }),
68
+
69
+ // ##########################################
70
+ // # CRM API requests (general api)
71
+ // ##########################################
72
+
73
+ getAccount: builder.query({
74
+ query: (props) => ({
75
+ url: constructUrl(
76
+ `/crms/${props.platform}/account/${props.accountReference}`
77
+ ),
78
+ }),
79
+ providesTags: (/* result = [], error, arg */) => [
80
+ 'Account'
81
+ ],
82
+ }),
83
+
84
+ createAccount: builder.mutation({
85
+ query: (props) => {
86
+ return {
87
+ url: constructUrl(`/crms/${props.platform}/account`),
88
+ method: 'post',
89
+ body: JSON.stringify(props.accountData),
90
+ };
91
+ },
92
+ invalidatesTags: (/* result, error, arg */) => [{ type: 'Account' }],
93
+ }),
94
+
95
+ getProviders: builder.query({
96
+ query: (props) => ({
97
+ url: constructUrl(
98
+ `/crms/${props.platform}/account/${props.accountReference}/providers`
99
+ ),
100
+ }),
101
+ providesTags: (/* result = [], error, arg */) => [
102
+ 'Product'
103
+ ],
104
+ }),
105
+
106
+ getProvider: builder.query({
107
+ query: (props) => ({
108
+ url: constructUrl(
109
+ `/crms/${props.platform}/provider/${props.providerReference}`
110
+ ),
111
+ }),
112
+ }),
113
+
114
+ createProvider: builder.mutation({
115
+ query: (props) => ({
116
+ url: constructUrl(`/crms/${props.platform}/provider`),
117
+ method: 'post',
118
+ body: JSON.stringify(
119
+ (() => ({
120
+ user: props.userData ?? {},
121
+ provider: props.providerData ?? {},
122
+ address: props.addressData ?? null,
123
+ account: props.account ?? null,
124
+ sendEmail: props.sendEmail ?? false,
125
+ }))()
126
+ ),
127
+ }),
128
+ invalidatesTags: (/* result, error, arg */) => [{ type: 'Provider' }],
129
+ }),
130
+
131
+ // loginUserViaApi: builder.query({
132
+ // query: (props) => ({
133
+ // url: constructUrl(`/crms/${props.platform}/user/loginWithJwt`),
134
+ // }),
135
+ // async onQueryStarted(props, { dispatch, queryFulfilled }) {
136
+ // const { data /* , meta */ } = await queryFulfilled;
137
+ // if (data) {
138
+ // dispatch(timumClientAuthorised({ auth2: data.auth2 }));
139
+ // }
140
+ // },
141
+ // }),
142
+ getUser: builder.query({
143
+ query: (props) => ({
144
+ url: constructUrl(
145
+ `/crms/${props.platform}/user/${props.userReference}`
146
+ ),
147
+ }),
148
+ }),
149
+
150
+ createUser: builder.mutation({
151
+ query: (props) => ({
152
+ url: constructUrl(`/crms/${props.platform}/user`),
153
+ method: 'post',
154
+ body: JSON.stringify(props.userData),
155
+ }),
156
+ invalidatesTags: (/* result, error, arg */) => [{ type: 'User' }],
157
+ }),
158
+ }),
159
+ });
160
+
161
+ export const {
162
+ // ##########################################
163
+ // # ConsumerAPI v2
164
+ // ##########################################
165
+
166
+ useUpcomingBookablesQuery,
167
+ useActiveProductsQuery,
168
+ useCreateAppointmentWithConsumerMutation,
169
+
170
+ // ##########################################
171
+ // # CRM API requests (general api)
172
+ // ##########################################
173
+ useCreateAccountMutation,
174
+ useGetAccountQuery,
175
+ useGetProvidersQuery,
176
+ useCreateProviderMutation,
177
+ // useLoginUserViaApiQuery,
178
+ useCreateUserMutation,
179
+ useGetUserQuery,
180
+ } = timumApiSlice;
@@ -0,0 +1,11 @@
1
+ const path = require('path');
2
+
3
+ module.exports = {
4
+ entry: './src/index.js',
5
+ output: {
6
+ path: path.resolve(__dirname, 'dist'),
7
+ library: {
8
+ type: 'commonjs-static'
9
+ },
10
+ },
11
+ };