ingeniuscliq-core 0.5.21 → 0.5.22
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/classes/CoreBaseBuilder.d.ts +67 -0
- package/dist/classes/CoreBaseBuilder.d.ts.map +1 -0
- package/dist/classes/CoreBaseBuilder.js +65 -0
- package/dist/classes/index.d.ts +1 -0
- package/dist/classes/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/modules/CoreAuth/classes/CoreAuthBuilder.d.ts +3 -2
- package/dist/modules/CoreAuth/classes/CoreAuthBuilder.d.ts.map +1 -1
- package/dist/modules/CoreAuth/classes/CoreAuthBuilder.js +153 -147
- package/dist/modules/CoreCustomization/classes/CoreCustomizationBuilder.d.ts +3 -2
- package/dist/modules/CoreCustomization/classes/CoreCustomizationBuilder.d.ts.map +1 -1
- package/dist/modules/CoreCustomization/classes/CoreCustomizationBuilder.js +66 -60
- package/dist/modules/CoreOrder/classes/CoreOrderBuilder.d.ts +3 -2
- package/dist/modules/CoreOrder/classes/CoreOrderBuilder.d.ts.map +1 -1
- package/dist/modules/CoreOrder/classes/CoreOrderBuilder.js +95 -89
- package/dist/modules/CorePayForm/classes/CorePayFormBuilder.d.ts +3 -2
- package/dist/modules/CorePayForm/classes/CorePayFormBuilder.d.ts.map +1 -1
- package/dist/modules/CorePayForm/classes/CorePayFormBuilder.js +50 -44
- package/dist/modules/CoreProduct/classes/CoreProductBuilder.d.ts +3 -2
- package/dist/modules/CoreProduct/classes/CoreProductBuilder.d.ts.map +1 -1
- package/dist/modules/CoreProduct/classes/CoreProductBuilder.js +119 -113
- package/dist/modules/CoreShipment/classes/CoreShipmentBuilder.d.ts +3 -2
- package/dist/modules/CoreShipment/classes/CoreShipmentBuilder.d.ts.map +1 -1
- package/dist/modules/CoreShipment/classes/CoreShipmentBuilder.js +170 -164
- package/dist/modules/CoreShopCart/classes/CoreShopCartBuilder.d.ts +3 -2
- package/dist/modules/CoreShopCart/classes/CoreShopCartBuilder.d.ts.map +1 -1
- package/dist/modules/CoreShopCart/classes/CoreShopCartBuilder.js +144 -138
- package/package.json +1 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { CoreBuilder } from './CoreBuilder';
|
|
2
|
+
/**
|
|
3
|
+
* Base builder class with extensibility hooks
|
|
4
|
+
* Provides a pattern for extending store state and actions without duplicating code
|
|
5
|
+
* @template TStore - The type of the store state that will be built
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class CoreBaseBuilder<TStore> implements CoreBuilder {
|
|
8
|
+
abstract build(): any;
|
|
9
|
+
/**
|
|
10
|
+
* Hook method to get the base store state
|
|
11
|
+
* Implement this in child classes to define the core state and actions
|
|
12
|
+
* @param set - Zustand set function
|
|
13
|
+
* @param get - Zustand get function
|
|
14
|
+
* @returns Object with base state and actions
|
|
15
|
+
*/
|
|
16
|
+
protected abstract getBaseState(set: any, get: any): TStore;
|
|
17
|
+
/**
|
|
18
|
+
* Hook method to allow extending initial state
|
|
19
|
+
* Override this in child classes to add custom properties to the store state
|
|
20
|
+
* @returns Object with additional state properties
|
|
21
|
+
* @example
|
|
22
|
+
* protected extendInitialState() {
|
|
23
|
+
* return {
|
|
24
|
+
* customProp: 'default value',
|
|
25
|
+
* anotherProp: 0
|
|
26
|
+
* };
|
|
27
|
+
* }
|
|
28
|
+
*/
|
|
29
|
+
protected extendInitialState(): Partial<TStore>;
|
|
30
|
+
/**
|
|
31
|
+
* Hook method to allow extending store actions
|
|
32
|
+
* Override this in child classes to add custom methods to the store
|
|
33
|
+
* @param set - Zustand set function
|
|
34
|
+
* @param get - Zustand get function
|
|
35
|
+
* @returns Object with additional actions/methods
|
|
36
|
+
* @example
|
|
37
|
+
* protected extendActions(set: any, get: any) {
|
|
38
|
+
* return {
|
|
39
|
+
* setCustomProp: (value: string) => set({ customProp: value }),
|
|
40
|
+
* getCustomProp: () => get().customProp
|
|
41
|
+
* };
|
|
42
|
+
* }
|
|
43
|
+
*/
|
|
44
|
+
protected extendActions(set: any, get: any): Partial<TStore>;
|
|
45
|
+
/**
|
|
46
|
+
* Hook method to allow extending partialize storage
|
|
47
|
+
* Override this in child classes to persist custom properties
|
|
48
|
+
* @param state - Current store state
|
|
49
|
+
* @returns Object with properties to persist
|
|
50
|
+
* @example
|
|
51
|
+
* protected extendPartialize(state: any) {
|
|
52
|
+
* return {
|
|
53
|
+
* customProp: state.customProp
|
|
54
|
+
* };
|
|
55
|
+
* }
|
|
56
|
+
*/
|
|
57
|
+
protected extendPartialize(state: TStore): Record<string, any>;
|
|
58
|
+
/**
|
|
59
|
+
* Combines base state with extended state and actions
|
|
60
|
+
* This method should be called inside the store creation function
|
|
61
|
+
* @param set - Zustand set function
|
|
62
|
+
* @param get - Zustand get function
|
|
63
|
+
* @returns Complete store state with base + extended properties
|
|
64
|
+
*/
|
|
65
|
+
protected buildStoreState(set: any, get: any): TStore;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=CoreBaseBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoreBaseBuilder.d.ts","sourceRoot":"","sources":["../../src/classes/CoreBaseBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C;;;;GAIG;AACH,8BAAsB,eAAe,CAAC,MAAM,CAAE,YAAW,WAAW;IAChE,QAAQ,CAAC,KAAK,IAAI,GAAG;IAErB;;;;;;OAMG;IACH,SAAS,CAAC,QAAQ,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,MAAM;IAE3D;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI/C;;;;;;;;;;;;;OAaG;IACH,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAI5D;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAI9D;;;;;;OAMG;IACH,SAAS,CAAC,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,MAAM;CAOxD"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
class CoreBaseBuilder {
|
|
2
|
+
/**
|
|
3
|
+
* Hook method to allow extending initial state
|
|
4
|
+
* Override this in child classes to add custom properties to the store state
|
|
5
|
+
* @returns Object with additional state properties
|
|
6
|
+
* @example
|
|
7
|
+
* protected extendInitialState() {
|
|
8
|
+
* return {
|
|
9
|
+
* customProp: 'default value',
|
|
10
|
+
* anotherProp: 0
|
|
11
|
+
* };
|
|
12
|
+
* }
|
|
13
|
+
*/
|
|
14
|
+
extendInitialState() {
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Hook method to allow extending store actions
|
|
19
|
+
* Override this in child classes to add custom methods to the store
|
|
20
|
+
* @param set - Zustand set function
|
|
21
|
+
* @param get - Zustand get function
|
|
22
|
+
* @returns Object with additional actions/methods
|
|
23
|
+
* @example
|
|
24
|
+
* protected extendActions(set: any, get: any) {
|
|
25
|
+
* return {
|
|
26
|
+
* setCustomProp: (value: string) => set({ customProp: value }),
|
|
27
|
+
* getCustomProp: () => get().customProp
|
|
28
|
+
* };
|
|
29
|
+
* }
|
|
30
|
+
*/
|
|
31
|
+
extendActions(set, get) {
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Hook method to allow extending partialize storage
|
|
36
|
+
* Override this in child classes to persist custom properties
|
|
37
|
+
* @param state - Current store state
|
|
38
|
+
* @returns Object with properties to persist
|
|
39
|
+
* @example
|
|
40
|
+
* protected extendPartialize(state: any) {
|
|
41
|
+
* return {
|
|
42
|
+
* customProp: state.customProp
|
|
43
|
+
* };
|
|
44
|
+
* }
|
|
45
|
+
*/
|
|
46
|
+
extendPartialize(state) {
|
|
47
|
+
return {};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Combines base state with extended state and actions
|
|
51
|
+
* This method should be called inside the store creation function
|
|
52
|
+
* @param set - Zustand set function
|
|
53
|
+
* @param get - Zustand get function
|
|
54
|
+
* @returns Complete store state with base + extended properties
|
|
55
|
+
*/
|
|
56
|
+
buildStoreState(set, get) {
|
|
57
|
+
return {
|
|
58
|
+
...this.getBaseState(set, get),
|
|
59
|
+
...this.extendInitialState(),
|
|
60
|
+
...this.extendActions(set, get)
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { CoreBaseBuilder };
|
package/dist/classes/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/classes/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/classes/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { CoreBuilder } from './classes/CoreBuilder.js';
|
|
2
|
+
export { CoreBaseBuilder } from './classes/CoreBaseBuilder.js';
|
|
2
3
|
export { api, ensureCsrfToken, initAxiosConfigs } from './helpers/axiosGlobal.js';
|
|
3
4
|
export { capitalizeFirstLetter } from './helpers/strings.js';
|
|
4
5
|
export { getImageUrlByTenant } from './helpers/image.js';
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { CoreAuthBaseService } from '../services/base';
|
|
2
2
|
import { CoreUser, CoreAuthStore } from '../types/CoreAuth';
|
|
3
|
-
import {
|
|
4
|
-
export declare class CoreAuthBuilder<T extends CoreUser>
|
|
3
|
+
import { CoreBaseBuilder } from '../../../classes/CoreBaseBuilder';
|
|
4
|
+
export declare class CoreAuthBuilder<T extends CoreUser> extends CoreBaseBuilder<CoreAuthStore<T>> {
|
|
5
5
|
protected authService: CoreAuthBaseService<T>;
|
|
6
6
|
protected initialState: Pick<CoreAuthStore<T>, "user" | "isAuthenticated" | "loading" | "error">;
|
|
7
7
|
constructor(authService?: CoreAuthBaseService<T>, initialState?: Partial<CoreAuthStore<T>>);
|
|
8
|
+
protected getBaseState(set: any, get: any): CoreAuthStore<T>;
|
|
8
9
|
build(): import('zustand').UseBoundStore<Omit<import('zustand').StoreApi<CoreAuthStore<T>>, "persist"> & {
|
|
9
10
|
persist: {
|
|
10
11
|
setOptions: (options: Partial<import('zustand/middleware').PersistOptions<CoreAuthStore<T>, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CoreAuthBuilder.d.ts","sourceRoot":"","sources":["../../../../src/modules/CoreAuth/classes/CoreAuthBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAiD,MAAM,mBAAmB,CAAC;AAEhH,OAAO,
|
|
1
|
+
{"version":3,"file":"CoreAuthBuilder.d.ts","sourceRoot":"","sources":["../../../../src/modules/CoreAuth/classes/CoreAuthBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAiD,MAAM,mBAAmB,CAAC;AAEhH,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAEnE,qBAAa,eAAe,CAAC,CAAC,SAAS,QAAQ,CAAE,SAAQ,eAAe,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IACxF,SAAS,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAC;IAC9C,SAAS,CAAC,YAAY,EAKjB,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC;gBAG5E,WAAW,GAAE,mBAAmB,CAAC,CAAC,CAAgC,EAClE,YAAY,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAS1C,SAAS,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,aAAa,CAAC,CAAC,CAAC;IA8KrD,KAAK;;;;;;;;;;;;;;;;;CAeb"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { create } from 'zustand';
|
|
2
2
|
import { persist } from '../../../node_modules/zustand/esm/middleware.js';
|
|
3
3
|
import { CoreAuthBaseService } from '../services/base.js';
|
|
4
|
+
import { CoreBaseBuilder } from '../../../classes/CoreBaseBuilder.js';
|
|
4
5
|
|
|
5
|
-
class CoreAuthBuilder {
|
|
6
|
+
class CoreAuthBuilder extends CoreBaseBuilder {
|
|
6
7
|
authService;
|
|
7
8
|
initialState = {
|
|
8
9
|
user: null,
|
|
@@ -11,164 +12,169 @@ class CoreAuthBuilder {
|
|
|
11
12
|
error: null
|
|
12
13
|
};
|
|
13
14
|
constructor(authService = new CoreAuthBaseService(), initialState) {
|
|
15
|
+
super();
|
|
14
16
|
this.authService = authService;
|
|
15
17
|
if (initialState) {
|
|
16
18
|
this.initialState = { ...this.initialState, ...initialState };
|
|
17
19
|
}
|
|
18
20
|
}
|
|
21
|
+
getBaseState(set, get) {
|
|
22
|
+
return {
|
|
23
|
+
...this.initialState,
|
|
24
|
+
// Setters
|
|
25
|
+
setUser: (user) => {
|
|
26
|
+
set({
|
|
27
|
+
user,
|
|
28
|
+
isAuthenticated: user !== null
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
setLoading: (loading) => set({ loading }),
|
|
32
|
+
setError: (error) => set({ error }),
|
|
33
|
+
// Getters
|
|
34
|
+
getUser: async () => {
|
|
35
|
+
try {
|
|
36
|
+
set({ loading: true, error: null });
|
|
37
|
+
const response = await this.authService.getUser();
|
|
38
|
+
const userData = response.data.data.user;
|
|
39
|
+
set({
|
|
40
|
+
user: userData,
|
|
41
|
+
isAuthenticated: true,
|
|
42
|
+
loading: false
|
|
43
|
+
});
|
|
44
|
+
return response.data;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
set({
|
|
47
|
+
user: null,
|
|
48
|
+
isAuthenticated: false,
|
|
49
|
+
loading: false,
|
|
50
|
+
error
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
// Actions
|
|
55
|
+
login: async (credentials, actions) => {
|
|
56
|
+
const { onSuccess = () => {
|
|
57
|
+
}, onError = () => {
|
|
58
|
+
}, onFinish = () => {
|
|
59
|
+
} } = actions || {};
|
|
60
|
+
try {
|
|
61
|
+
set({ loading: true, error: null });
|
|
62
|
+
const response = await this.authService.login(credentials);
|
|
63
|
+
await get().getUser();
|
|
64
|
+
onSuccess(response);
|
|
65
|
+
return response.data;
|
|
66
|
+
} catch (error) {
|
|
67
|
+
set({
|
|
68
|
+
user: null,
|
|
69
|
+
isAuthenticated: false,
|
|
70
|
+
loading: false,
|
|
71
|
+
error
|
|
72
|
+
});
|
|
73
|
+
onError(error);
|
|
74
|
+
} finally {
|
|
75
|
+
onFinish();
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
register: async (credentials, actions) => {
|
|
79
|
+
const { onSuccess = () => {
|
|
80
|
+
}, onError = () => {
|
|
81
|
+
}, onFinish = () => {
|
|
82
|
+
} } = actions || {};
|
|
83
|
+
try {
|
|
84
|
+
set({ loading: true, error: null });
|
|
85
|
+
const response = await this.authService.register(credentials);
|
|
86
|
+
await get().getUser();
|
|
87
|
+
onSuccess(response);
|
|
88
|
+
return response.data;
|
|
89
|
+
} catch (error) {
|
|
90
|
+
set({
|
|
91
|
+
user: null,
|
|
92
|
+
isAuthenticated: false,
|
|
93
|
+
loading: false,
|
|
94
|
+
error
|
|
95
|
+
});
|
|
96
|
+
onError(error);
|
|
97
|
+
} finally {
|
|
98
|
+
onFinish();
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
logout: async (actions) => {
|
|
102
|
+
const { onSuccess = () => {
|
|
103
|
+
}, onError = () => {
|
|
104
|
+
}, onFinish = () => {
|
|
105
|
+
} } = actions || {};
|
|
106
|
+
try {
|
|
107
|
+
set({ loading: true, error: null });
|
|
108
|
+
await this.authService.logout();
|
|
109
|
+
set({
|
|
110
|
+
user: null,
|
|
111
|
+
isAuthenticated: false,
|
|
112
|
+
loading: false,
|
|
113
|
+
error: null
|
|
114
|
+
});
|
|
115
|
+
onSuccess(null);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
set({ loading: false, error });
|
|
118
|
+
onError(error);
|
|
119
|
+
} finally {
|
|
120
|
+
onFinish();
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
updateUser: async (userId, updateUserData, actions) => {
|
|
124
|
+
const { onSuccess = () => {
|
|
125
|
+
}, onError = () => {
|
|
126
|
+
}, onFinish = () => {
|
|
127
|
+
} } = actions || {};
|
|
128
|
+
try {
|
|
129
|
+
set({ loading: true, error: null });
|
|
130
|
+
const response = await this.authService.updateUser(userId, updateUserData);
|
|
131
|
+
await get().getUser();
|
|
132
|
+
onSuccess(response);
|
|
133
|
+
return response.data;
|
|
134
|
+
} catch (error) {
|
|
135
|
+
set({ loading: false, error });
|
|
136
|
+
onError(error);
|
|
137
|
+
} finally {
|
|
138
|
+
onFinish();
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
deleteUser: async (userId, actions) => {
|
|
142
|
+
const { onSuccess = () => {
|
|
143
|
+
}, onError = () => {
|
|
144
|
+
}, onFinish = () => {
|
|
145
|
+
} } = actions || {};
|
|
146
|
+
try {
|
|
147
|
+
set({ loading: true, error: null });
|
|
148
|
+
const response = await this.authService.deleteUser(userId);
|
|
149
|
+
set({
|
|
150
|
+
user: null,
|
|
151
|
+
isAuthenticated: false,
|
|
152
|
+
loading: false,
|
|
153
|
+
error: null
|
|
154
|
+
});
|
|
155
|
+
onSuccess(response);
|
|
156
|
+
return response.data;
|
|
157
|
+
} catch (error) {
|
|
158
|
+
set({ loading: false, error });
|
|
159
|
+
onError(error);
|
|
160
|
+
} finally {
|
|
161
|
+
onFinish();
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
// Reset
|
|
165
|
+
reset: () => set({ ...this.initialState, ...this.extendInitialState() })
|
|
166
|
+
};
|
|
167
|
+
}
|
|
19
168
|
build() {
|
|
20
169
|
return create()(
|
|
21
170
|
persist(
|
|
22
|
-
(set, get) => (
|
|
23
|
-
...this.initialState,
|
|
24
|
-
// Setters
|
|
25
|
-
setUser: (user) => {
|
|
26
|
-
set({
|
|
27
|
-
user,
|
|
28
|
-
isAuthenticated: user !== null
|
|
29
|
-
});
|
|
30
|
-
},
|
|
31
|
-
setLoading: (loading) => set({ loading }),
|
|
32
|
-
setError: (error) => set({ error }),
|
|
33
|
-
// Getters
|
|
34
|
-
getUser: async () => {
|
|
35
|
-
try {
|
|
36
|
-
set({ loading: true, error: null });
|
|
37
|
-
const response = await this.authService.getUser();
|
|
38
|
-
const userData = response.data.data.user;
|
|
39
|
-
set({
|
|
40
|
-
user: userData,
|
|
41
|
-
isAuthenticated: true,
|
|
42
|
-
loading: false
|
|
43
|
-
});
|
|
44
|
-
return response.data;
|
|
45
|
-
} catch (error) {
|
|
46
|
-
set({
|
|
47
|
-
user: null,
|
|
48
|
-
isAuthenticated: false,
|
|
49
|
-
loading: false,
|
|
50
|
-
error
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
// Actions
|
|
55
|
-
login: async (credentials, actions) => {
|
|
56
|
-
const { onSuccess = () => {
|
|
57
|
-
}, onError = () => {
|
|
58
|
-
}, onFinish = () => {
|
|
59
|
-
} } = actions || {};
|
|
60
|
-
try {
|
|
61
|
-
set({ loading: true, error: null });
|
|
62
|
-
const response = await this.authService.login(credentials);
|
|
63
|
-
await get().getUser();
|
|
64
|
-
onSuccess(response);
|
|
65
|
-
return response.data;
|
|
66
|
-
} catch (error) {
|
|
67
|
-
set({
|
|
68
|
-
user: null,
|
|
69
|
-
isAuthenticated: false,
|
|
70
|
-
loading: false,
|
|
71
|
-
error
|
|
72
|
-
});
|
|
73
|
-
onError(error);
|
|
74
|
-
} finally {
|
|
75
|
-
onFinish();
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
register: async (credentials, actions) => {
|
|
79
|
-
const { onSuccess = () => {
|
|
80
|
-
}, onError = () => {
|
|
81
|
-
}, onFinish = () => {
|
|
82
|
-
} } = actions || {};
|
|
83
|
-
try {
|
|
84
|
-
set({ loading: true, error: null });
|
|
85
|
-
const response = await this.authService.register(credentials);
|
|
86
|
-
await get().getUser();
|
|
87
|
-
onSuccess(response);
|
|
88
|
-
return response.data;
|
|
89
|
-
} catch (error) {
|
|
90
|
-
set({
|
|
91
|
-
user: null,
|
|
92
|
-
isAuthenticated: false,
|
|
93
|
-
loading: false,
|
|
94
|
-
error
|
|
95
|
-
});
|
|
96
|
-
onError(error);
|
|
97
|
-
} finally {
|
|
98
|
-
onFinish();
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
logout: async (actions) => {
|
|
102
|
-
const { onSuccess = () => {
|
|
103
|
-
}, onError = () => {
|
|
104
|
-
}, onFinish = () => {
|
|
105
|
-
} } = actions || {};
|
|
106
|
-
try {
|
|
107
|
-
set({ loading: true, error: null });
|
|
108
|
-
await this.authService.logout();
|
|
109
|
-
set({
|
|
110
|
-
user: null,
|
|
111
|
-
isAuthenticated: false,
|
|
112
|
-
loading: false,
|
|
113
|
-
error: null
|
|
114
|
-
});
|
|
115
|
-
onSuccess(null);
|
|
116
|
-
} catch (error) {
|
|
117
|
-
set({ loading: false, error });
|
|
118
|
-
onError(error);
|
|
119
|
-
} finally {
|
|
120
|
-
onFinish();
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
updateUser: async (userId, updateUserData, actions) => {
|
|
124
|
-
const { onSuccess = () => {
|
|
125
|
-
}, onError = () => {
|
|
126
|
-
}, onFinish = () => {
|
|
127
|
-
} } = actions || {};
|
|
128
|
-
try {
|
|
129
|
-
set({ loading: true, error: null });
|
|
130
|
-
const response = await this.authService.updateUser(userId, updateUserData);
|
|
131
|
-
await get().getUser();
|
|
132
|
-
onSuccess(response);
|
|
133
|
-
return response.data;
|
|
134
|
-
} catch (error) {
|
|
135
|
-
set({ loading: false, error });
|
|
136
|
-
onError(error);
|
|
137
|
-
} finally {
|
|
138
|
-
onFinish();
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
|
-
deleteUser: async (userId, actions) => {
|
|
142
|
-
const { onSuccess = () => {
|
|
143
|
-
}, onError = () => {
|
|
144
|
-
}, onFinish = () => {
|
|
145
|
-
} } = actions || {};
|
|
146
|
-
try {
|
|
147
|
-
set({ loading: true, error: null });
|
|
148
|
-
const response = await this.authService.deleteUser(userId);
|
|
149
|
-
set({
|
|
150
|
-
user: null,
|
|
151
|
-
isAuthenticated: false,
|
|
152
|
-
loading: false,
|
|
153
|
-
error: null
|
|
154
|
-
});
|
|
155
|
-
onSuccess(response);
|
|
156
|
-
return response.data;
|
|
157
|
-
} catch (error) {
|
|
158
|
-
set({ loading: false, error });
|
|
159
|
-
onError(error);
|
|
160
|
-
} finally {
|
|
161
|
-
onFinish();
|
|
162
|
-
}
|
|
163
|
-
},
|
|
164
|
-
// Reset
|
|
165
|
-
reset: () => set(this.initialState)
|
|
166
|
-
}),
|
|
171
|
+
(set, get) => this.buildStoreState(set, get),
|
|
167
172
|
{
|
|
168
173
|
name: "auth-storage",
|
|
169
174
|
partialize: (state) => ({
|
|
170
175
|
user: state.user,
|
|
171
|
-
isAuthenticated: state.isAuthenticated
|
|
176
|
+
isAuthenticated: state.isAuthenticated,
|
|
177
|
+
...this.extendPartialize(state)
|
|
172
178
|
})
|
|
173
179
|
}
|
|
174
180
|
)
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { CoreCustomizationBaseService } from '../services/base';
|
|
2
2
|
import { CoreCustomizationStore } from '../types/CoreCustomization';
|
|
3
|
-
import {
|
|
4
|
-
export declare class CoreCustomizationBuilder
|
|
3
|
+
import { CoreBaseBuilder } from '../../../classes/CoreBaseBuilder';
|
|
4
|
+
export declare class CoreCustomizationBuilder extends CoreBaseBuilder<CoreCustomizationStore> {
|
|
5
5
|
protected customizationService: CoreCustomizationBaseService;
|
|
6
6
|
protected initialState: Pick<CoreCustomizationStore, "template" | "components" | "styles" | "settings" | "loading" | "error">;
|
|
7
7
|
constructor(service?: CoreCustomizationBaseService, initialState?: Partial<CoreCustomizationStore>);
|
|
8
|
+
protected getBaseState(set: any, _get: any): CoreCustomizationStore;
|
|
8
9
|
build(): import('zustand').UseBoundStore<Omit<import('zustand').StoreApi<CoreCustomizationStore>, "persist"> & {
|
|
9
10
|
persist: {
|
|
10
11
|
setOptions: (options: Partial<import('zustand/middleware').PersistOptions<CoreCustomizationStore, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CoreCustomizationBuilder.d.ts","sourceRoot":"","sources":["../../../../src/modules/CoreCustomization/classes/CoreCustomizationBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"CoreCustomizationBuilder.d.ts","sourceRoot":"","sources":["../../../../src/modules/CoreCustomization/classes/CoreCustomizationBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAEnE,qBAAa,wBAAyB,SAAQ,eAAe,CAAC,sBAAsB,CAAC;IACnF,SAAS,CAAC,oBAAoB,EAAE,4BAA4B,CAAC;IAC7D,SAAS,CAAC,YAAY,EAOjB,IAAI,CAAC,sBAAsB,EAAE,UAAU,GAAG,YAAY,GAAG,QAAQ,GAAG,UAAU,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC;gBAGzG,OAAO,GAAE,4BAAiE,EAC1E,YAAY,CAAC,EAAE,OAAO,CAAC,sBAAsB,CAAC;IAShD,SAAS,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,GAAG,sBAAsB;IA4E5D,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiBb"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { create } from 'zustand';
|
|
2
2
|
import { persist } from '../../../node_modules/zustand/esm/middleware.js';
|
|
3
3
|
import { CoreCustomizationBaseService } from '../services/base.js';
|
|
4
|
+
import { CoreBaseBuilder } from '../../../classes/CoreBaseBuilder.js';
|
|
4
5
|
|
|
5
|
-
class CoreCustomizationBuilder {
|
|
6
|
+
class CoreCustomizationBuilder extends CoreBaseBuilder {
|
|
6
7
|
customizationService;
|
|
7
8
|
initialState = {
|
|
8
9
|
template: null,
|
|
@@ -13,79 +14,84 @@ class CoreCustomizationBuilder {
|
|
|
13
14
|
error: null
|
|
14
15
|
};
|
|
15
16
|
constructor(service = new CoreCustomizationBaseService(), initialState) {
|
|
17
|
+
super();
|
|
16
18
|
this.customizationService = service;
|
|
17
19
|
if (initialState) {
|
|
18
20
|
this.initialState = { ...this.initialState, ...initialState };
|
|
19
21
|
}
|
|
20
22
|
}
|
|
23
|
+
getBaseState(set, _get) {
|
|
24
|
+
return {
|
|
25
|
+
...this.initialState,
|
|
26
|
+
// Setters
|
|
27
|
+
setLoading: (loading) => set({ loading }),
|
|
28
|
+
setError: (error) => set({ error }),
|
|
29
|
+
setTemplate: (template) => set({ template }),
|
|
30
|
+
setComponents: (components) => set({ components }),
|
|
31
|
+
setStyles: (styles) => set({ styles }),
|
|
32
|
+
setSettings: (settings) => set({ settings }),
|
|
33
|
+
// Actions
|
|
34
|
+
fetchTemplate: async (params) => {
|
|
35
|
+
const { onlyFetch } = params || {};
|
|
36
|
+
try {
|
|
37
|
+
if (!onlyFetch) {
|
|
38
|
+
set({ loading: true, error: null });
|
|
39
|
+
}
|
|
40
|
+
const response = await this.customizationService.fetchTemplate();
|
|
41
|
+
const template = response.data.data;
|
|
42
|
+
if (!onlyFetch) {
|
|
43
|
+
set({
|
|
44
|
+
template: template.template || null,
|
|
45
|
+
styles: template.styles || null,
|
|
46
|
+
loading: false
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return template;
|
|
50
|
+
} catch (error) {
|
|
51
|
+
if (!onlyFetch) {
|
|
52
|
+
set({ loading: false, error });
|
|
53
|
+
}
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
fetchSettings: async (params) => {
|
|
58
|
+
const { onlyFetch } = params || {};
|
|
59
|
+
try {
|
|
60
|
+
if (!onlyFetch) {
|
|
61
|
+
set({ loading: true, error: null });
|
|
62
|
+
}
|
|
63
|
+
const response = await this.customizationService.fetchSettings();
|
|
64
|
+
const settings = response.data.data.configuration;
|
|
65
|
+
if (!onlyFetch) {
|
|
66
|
+
set({
|
|
67
|
+
settings,
|
|
68
|
+
loading: false
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return settings;
|
|
72
|
+
} catch (error) {
|
|
73
|
+
if (!onlyFetch) {
|
|
74
|
+
set({ loading: false, error });
|
|
75
|
+
}
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
// Reset
|
|
80
|
+
reset: () => set({ ...this.initialState, ...this.extendInitialState() })
|
|
81
|
+
};
|
|
82
|
+
}
|
|
21
83
|
build() {
|
|
22
84
|
return create()(
|
|
23
85
|
persist(
|
|
24
|
-
(set) => (
|
|
25
|
-
...this.initialState,
|
|
26
|
-
// Setters
|
|
27
|
-
setLoading: (loading) => set({ loading }),
|
|
28
|
-
setError: (error) => set({ error }),
|
|
29
|
-
setTemplate: (template) => set({ template }),
|
|
30
|
-
setComponents: (components) => set({ components }),
|
|
31
|
-
setStyles: (styles) => set({ styles }),
|
|
32
|
-
setSettings: (settings) => set({ settings }),
|
|
33
|
-
// Actions
|
|
34
|
-
fetchTemplate: async (params) => {
|
|
35
|
-
const { onlyFetch } = params || {};
|
|
36
|
-
try {
|
|
37
|
-
if (!onlyFetch) {
|
|
38
|
-
set({ loading: true, error: null });
|
|
39
|
-
}
|
|
40
|
-
const response = await this.customizationService.fetchTemplate();
|
|
41
|
-
const template = response.data.data;
|
|
42
|
-
if (!onlyFetch) {
|
|
43
|
-
set({
|
|
44
|
-
template: template.template || null,
|
|
45
|
-
styles: template.styles || null,
|
|
46
|
-
loading: false
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
return template;
|
|
50
|
-
} catch (error) {
|
|
51
|
-
if (!onlyFetch) {
|
|
52
|
-
set({ loading: false, error });
|
|
53
|
-
}
|
|
54
|
-
throw error;
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
fetchSettings: async (params) => {
|
|
58
|
-
const { onlyFetch } = params || {};
|
|
59
|
-
try {
|
|
60
|
-
if (!onlyFetch) {
|
|
61
|
-
set({ loading: true, error: null });
|
|
62
|
-
}
|
|
63
|
-
const response = await this.customizationService.fetchSettings();
|
|
64
|
-
const settings = response.data.data.configuration;
|
|
65
|
-
if (!onlyFetch) {
|
|
66
|
-
set({
|
|
67
|
-
settings,
|
|
68
|
-
loading: false
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
return settings;
|
|
72
|
-
} catch (error) {
|
|
73
|
-
if (!onlyFetch) {
|
|
74
|
-
set({ loading: false, error });
|
|
75
|
-
}
|
|
76
|
-
throw error;
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
// Reset
|
|
80
|
-
reset: () => set(this.initialState)
|
|
81
|
-
}),
|
|
86
|
+
(set, get) => this.buildStoreState(set, get),
|
|
82
87
|
{
|
|
83
88
|
name: "customization-storage",
|
|
84
89
|
partialize: (state) => ({
|
|
85
90
|
template: state.template,
|
|
86
91
|
components: state.components,
|
|
87
92
|
styles: state.styles,
|
|
88
|
-
settings: state.settings
|
|
93
|
+
settings: state.settings,
|
|
94
|
+
...this.extendPartialize(state)
|
|
89
95
|
})
|
|
90
96
|
}
|
|
91
97
|
)
|