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
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { create } from 'zustand';
|
|
2
2
|
import { persist } from '../../../node_modules/zustand/esm/middleware.js';
|
|
3
3
|
import { CoreShopCartBaseService } from '../services/base.js';
|
|
4
|
+
import { CoreBaseBuilder } from '../../../classes/CoreBaseBuilder.js';
|
|
4
5
|
|
|
5
|
-
class CoreShopCartBuilder {
|
|
6
|
+
class CoreShopCartBuilder extends CoreBaseBuilder {
|
|
6
7
|
shopCartService;
|
|
7
8
|
initialState;
|
|
8
9
|
constructor(service = new CoreShopCartBaseService(), initialState = {
|
|
@@ -16,153 +17,158 @@ class CoreShopCartBuilder {
|
|
|
16
17
|
loading: false,
|
|
17
18
|
error: null
|
|
18
19
|
}) {
|
|
20
|
+
super();
|
|
19
21
|
this.shopCartService = service;
|
|
20
22
|
this.initialState = initialState;
|
|
21
23
|
}
|
|
24
|
+
getBaseState(set, get) {
|
|
25
|
+
return {
|
|
26
|
+
...this.initialState,
|
|
27
|
+
// Setters
|
|
28
|
+
setLoading: (loading) => set({ loading }),
|
|
29
|
+
setError: (error) => set({ error }),
|
|
30
|
+
setCart: (cart) => set({ cart }),
|
|
31
|
+
setCartItems: (cartItems) => set({ cartItems }),
|
|
32
|
+
// Getters
|
|
33
|
+
getCartItems: () => get().cartItems,
|
|
34
|
+
getCart: () => get().cart,
|
|
35
|
+
// Add to cart
|
|
36
|
+
addToCart: async (product_id, quantity, actions) => {
|
|
37
|
+
set({ loading: true, error: null });
|
|
38
|
+
try {
|
|
39
|
+
await this.shopCartService.addToCart(product_id, quantity);
|
|
40
|
+
const response = await this.shopCartService.getCart();
|
|
41
|
+
set({
|
|
42
|
+
cart: response.data.data,
|
|
43
|
+
cartItems: response.data.data.items,
|
|
44
|
+
loading: false
|
|
45
|
+
});
|
|
46
|
+
actions?.onSuccess?.(response.data);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
set({ error: error || "Failed to add to cart", loading: false });
|
|
49
|
+
actions?.onError?.(error);
|
|
50
|
+
throw error;
|
|
51
|
+
} finally {
|
|
52
|
+
actions?.onFinish?.();
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
// Remove one unit from cart
|
|
56
|
+
removeFromCart: async (product_id, actions) => {
|
|
57
|
+
set({ loading: true, error: null });
|
|
58
|
+
try {
|
|
59
|
+
await this.shopCartService.removeFromCart(product_id);
|
|
60
|
+
const response = await this.shopCartService.getCart();
|
|
61
|
+
set({
|
|
62
|
+
cart: response.data.data,
|
|
63
|
+
cartItems: response.data.data.items,
|
|
64
|
+
loading: false
|
|
65
|
+
});
|
|
66
|
+
actions?.onSuccess?.(response.data);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
set({ error: error || "Failed to remove from cart", loading: false });
|
|
69
|
+
actions?.onError?.(error);
|
|
70
|
+
throw error;
|
|
71
|
+
} finally {
|
|
72
|
+
actions?.onFinish?.();
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
// Remove entire item from cart
|
|
76
|
+
removeItemFromCart: async (product_id, actions) => {
|
|
77
|
+
set({ loading: true, error: null });
|
|
78
|
+
try {
|
|
79
|
+
await this.shopCartService.removeItemFromCart(product_id);
|
|
80
|
+
const response = await this.shopCartService.getCart();
|
|
81
|
+
set({
|
|
82
|
+
cart: response.data.data,
|
|
83
|
+
cartItems: response.data.data.items,
|
|
84
|
+
loading: false
|
|
85
|
+
});
|
|
86
|
+
actions?.onSuccess?.(response.data);
|
|
87
|
+
} catch (error) {
|
|
88
|
+
set({ error: error || "Failed to remove item from cart", loading: false });
|
|
89
|
+
actions?.onError?.(error);
|
|
90
|
+
throw error;
|
|
91
|
+
} finally {
|
|
92
|
+
actions?.onFinish?.();
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
// Clear cart
|
|
96
|
+
clearCart: async (actions) => {
|
|
97
|
+
set({ loading: true, error: null });
|
|
98
|
+
try {
|
|
99
|
+
await this.shopCartService.clearCart();
|
|
100
|
+
const response = await this.shopCartService.getCart();
|
|
101
|
+
set({
|
|
102
|
+
cart: response.data.data,
|
|
103
|
+
cartItems: response.data.data.items,
|
|
104
|
+
loading: false
|
|
105
|
+
});
|
|
106
|
+
actions?.onSuccess?.(response.data);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
set({ error: error || "Failed to clear cart", loading: false });
|
|
109
|
+
actions?.onError?.(error);
|
|
110
|
+
throw error;
|
|
111
|
+
} finally {
|
|
112
|
+
actions?.onFinish?.();
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
// Fetch full cart
|
|
116
|
+
fetchCart: async (actions) => {
|
|
117
|
+
set({ loading: true, error: null });
|
|
118
|
+
try {
|
|
119
|
+
const response = await this.shopCartService.getCart();
|
|
120
|
+
set({
|
|
121
|
+
cart: response.data.data,
|
|
122
|
+
cartItems: response.data.data.items,
|
|
123
|
+
loading: false
|
|
124
|
+
});
|
|
125
|
+
actions?.onSuccess?.(response.data);
|
|
126
|
+
return response.data;
|
|
127
|
+
} catch (error) {
|
|
128
|
+
set({ error: error || "Failed to fetch cart", loading: false });
|
|
129
|
+
actions?.onError?.(error);
|
|
130
|
+
throw error;
|
|
131
|
+
} finally {
|
|
132
|
+
actions?.onFinish?.();
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
// Fetch cart items only
|
|
136
|
+
fetchCartItems: async (params, actions) => {
|
|
137
|
+
const { onlyFetch } = params || {};
|
|
138
|
+
try {
|
|
139
|
+
if (!onlyFetch) {
|
|
140
|
+
set({ loading: true, error: null });
|
|
141
|
+
}
|
|
142
|
+
const response = await this.shopCartService.getCartItems();
|
|
143
|
+
if (!onlyFetch) {
|
|
144
|
+
set({ cartItems: response.data.data, loading: false });
|
|
145
|
+
}
|
|
146
|
+
actions?.onSuccess?.(response.data);
|
|
147
|
+
return response.data;
|
|
148
|
+
} catch (error) {
|
|
149
|
+
if (!onlyFetch) {
|
|
150
|
+
set({ error: error || "Failed to fetch cart items", loading: false });
|
|
151
|
+
}
|
|
152
|
+
actions?.onError?.(error);
|
|
153
|
+
throw error;
|
|
154
|
+
} finally {
|
|
155
|
+
actions?.onFinish?.();
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
// Reset
|
|
159
|
+
reset: () => set({ ...this.initialState, ...this.extendInitialState() })
|
|
160
|
+
};
|
|
161
|
+
}
|
|
22
162
|
build() {
|
|
23
163
|
return create()(
|
|
24
164
|
persist(
|
|
25
|
-
(set, get) => (
|
|
26
|
-
...this.initialState,
|
|
27
|
-
// Setters
|
|
28
|
-
setLoading: (loading) => set({ loading }),
|
|
29
|
-
setError: (error) => set({ error }),
|
|
30
|
-
setCart: (cart) => set({ cart }),
|
|
31
|
-
setCartItems: (cartItems) => set({ cartItems }),
|
|
32
|
-
// Getters
|
|
33
|
-
getCartItems: () => get().cartItems,
|
|
34
|
-
getCart: () => get().cart,
|
|
35
|
-
// Add to cart
|
|
36
|
-
addToCart: async (product_id, quantity, actions) => {
|
|
37
|
-
set({ loading: true, error: null });
|
|
38
|
-
try {
|
|
39
|
-
await this.shopCartService.addToCart(product_id, quantity);
|
|
40
|
-
const response = await this.shopCartService.getCart();
|
|
41
|
-
set({
|
|
42
|
-
cart: response.data.data,
|
|
43
|
-
cartItems: response.data.data.items,
|
|
44
|
-
loading: false
|
|
45
|
-
});
|
|
46
|
-
actions?.onSuccess?.(response.data);
|
|
47
|
-
} catch (error) {
|
|
48
|
-
set({ error: error || "Failed to add to cart", loading: false });
|
|
49
|
-
actions?.onError?.(error);
|
|
50
|
-
throw error;
|
|
51
|
-
} finally {
|
|
52
|
-
actions?.onFinish?.();
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
// Remove one unit from cart
|
|
56
|
-
removeFromCart: async (product_id, actions) => {
|
|
57
|
-
set({ loading: true, error: null });
|
|
58
|
-
try {
|
|
59
|
-
await this.shopCartService.removeFromCart(product_id);
|
|
60
|
-
const response = await this.shopCartService.getCart();
|
|
61
|
-
set({
|
|
62
|
-
cart: response.data.data,
|
|
63
|
-
cartItems: response.data.data.items,
|
|
64
|
-
loading: false
|
|
65
|
-
});
|
|
66
|
-
actions?.onSuccess?.(response.data);
|
|
67
|
-
} catch (error) {
|
|
68
|
-
set({ error: error || "Failed to remove from cart", loading: false });
|
|
69
|
-
actions?.onError?.(error);
|
|
70
|
-
throw error;
|
|
71
|
-
} finally {
|
|
72
|
-
actions?.onFinish?.();
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
// Remove entire item from cart
|
|
76
|
-
removeItemFromCart: async (product_id, actions) => {
|
|
77
|
-
set({ loading: true, error: null });
|
|
78
|
-
try {
|
|
79
|
-
await this.shopCartService.removeItemFromCart(product_id);
|
|
80
|
-
const response = await this.shopCartService.getCart();
|
|
81
|
-
set({
|
|
82
|
-
cart: response.data.data,
|
|
83
|
-
cartItems: response.data.data.items,
|
|
84
|
-
loading: false
|
|
85
|
-
});
|
|
86
|
-
actions?.onSuccess?.(response.data);
|
|
87
|
-
} catch (error) {
|
|
88
|
-
set({ error: error || "Failed to remove item from cart", loading: false });
|
|
89
|
-
actions?.onError?.(error);
|
|
90
|
-
throw error;
|
|
91
|
-
} finally {
|
|
92
|
-
actions?.onFinish?.();
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
// Clear cart
|
|
96
|
-
clearCart: async (actions) => {
|
|
97
|
-
set({ loading: true, error: null });
|
|
98
|
-
try {
|
|
99
|
-
await this.shopCartService.clearCart();
|
|
100
|
-
const response = await this.shopCartService.getCart();
|
|
101
|
-
set({
|
|
102
|
-
cart: response.data.data,
|
|
103
|
-
cartItems: response.data.data.items,
|
|
104
|
-
loading: false
|
|
105
|
-
});
|
|
106
|
-
actions?.onSuccess?.(response.data);
|
|
107
|
-
} catch (error) {
|
|
108
|
-
set({ error: error || "Failed to clear cart", loading: false });
|
|
109
|
-
actions?.onError?.(error);
|
|
110
|
-
throw error;
|
|
111
|
-
} finally {
|
|
112
|
-
actions?.onFinish?.();
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
// Fetch full cart
|
|
116
|
-
fetchCart: async (actions) => {
|
|
117
|
-
set({ loading: true, error: null });
|
|
118
|
-
try {
|
|
119
|
-
const response = await this.shopCartService.getCart();
|
|
120
|
-
set({
|
|
121
|
-
cart: response.data.data,
|
|
122
|
-
cartItems: response.data.data.items,
|
|
123
|
-
loading: false
|
|
124
|
-
});
|
|
125
|
-
actions?.onSuccess?.(response.data);
|
|
126
|
-
return response.data;
|
|
127
|
-
} catch (error) {
|
|
128
|
-
set({ error: error || "Failed to fetch cart", loading: false });
|
|
129
|
-
actions?.onError?.(error);
|
|
130
|
-
throw error;
|
|
131
|
-
} finally {
|
|
132
|
-
actions?.onFinish?.();
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
// Fetch cart items only
|
|
136
|
-
fetchCartItems: async (params, actions) => {
|
|
137
|
-
const { onlyFetch } = params || {};
|
|
138
|
-
try {
|
|
139
|
-
if (!onlyFetch) {
|
|
140
|
-
set({ loading: true, error: null });
|
|
141
|
-
}
|
|
142
|
-
const response = await this.shopCartService.getCartItems();
|
|
143
|
-
if (!onlyFetch) {
|
|
144
|
-
set({ cartItems: response.data.data, loading: false });
|
|
145
|
-
}
|
|
146
|
-
actions?.onSuccess?.(response.data);
|
|
147
|
-
return response.data;
|
|
148
|
-
} catch (error) {
|
|
149
|
-
if (!onlyFetch) {
|
|
150
|
-
set({ error: error || "Failed to fetch cart items", loading: false });
|
|
151
|
-
}
|
|
152
|
-
actions?.onError?.(error);
|
|
153
|
-
throw error;
|
|
154
|
-
} finally {
|
|
155
|
-
actions?.onFinish?.();
|
|
156
|
-
}
|
|
157
|
-
},
|
|
158
|
-
// Reset
|
|
159
|
-
reset: () => set(this.initialState)
|
|
160
|
-
}),
|
|
165
|
+
(set, get) => this.buildStoreState(set, get),
|
|
161
166
|
{
|
|
162
167
|
name: "shop-cart-storage",
|
|
163
168
|
partialize: (state) => ({
|
|
164
169
|
cart: state.cart,
|
|
165
|
-
cartItems: state.cartItems
|
|
170
|
+
cartItems: state.cartItems,
|
|
171
|
+
...this.extendPartialize(state)
|
|
166
172
|
})
|
|
167
173
|
}
|
|
168
174
|
)
|