ingeniuscliq-core 0.5.21 → 0.5.24
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 +10 -9
- 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 +10 -9
- 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 +10 -9
- 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 +10 -9
- 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 +10 -9
- 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 +10 -9
- package/dist/modules/CoreShipment/classes/CoreShipmentBuilder.d.ts.map +1 -1
- package/dist/modules/CoreShipment/classes/CoreShipmentBuilder.js +174 -165
- package/dist/modules/CoreShopCart/classes/CoreShopCartBuilder.d.ts +10 -19
- package/dist/modules/CoreShopCart/classes/CoreShopCartBuilder.d.ts.map +1 -1
- package/dist/modules/CoreShopCart/classes/CoreShopCartBuilder.js +159 -150
- package/package.json +1 -1
|
@@ -1,32 +1,23 @@
|
|
|
1
1
|
import { CoreShopCartBaseService } from '../services/base';
|
|
2
2
|
import { CoreShopCartStore } from '../types/CoreShopCart';
|
|
3
|
-
import {
|
|
4
|
-
export declare class CoreShopCartBuilder<T>
|
|
3
|
+
import { CoreBaseBuilder } from '../../../classes/CoreBaseBuilder';
|
|
4
|
+
export declare class CoreShopCartBuilder<T, TStore extends CoreShopCartStore<T> = CoreShopCartStore<T>> extends CoreBaseBuilder<TStore> {
|
|
5
5
|
protected shopCartService: CoreShopCartBaseService<T>;
|
|
6
|
-
protected initialState: Pick<
|
|
7
|
-
constructor(service?: CoreShopCartBaseService<T>, initialState?:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
subtotal: number;
|
|
11
|
-
total: number;
|
|
12
|
-
itemized_subtotals: any[];
|
|
13
|
-
};
|
|
14
|
-
cartItems: any[];
|
|
15
|
-
loading: boolean;
|
|
16
|
-
error: any;
|
|
17
|
-
});
|
|
18
|
-
build(): import('zustand').UseBoundStore<Omit<import('zustand').StoreApi<CoreShopCartStore<T>>, "persist"> & {
|
|
6
|
+
protected initialState: Pick<TStore, 'cart' | 'cartItems' | 'loading' | 'error'>;
|
|
7
|
+
constructor(service?: CoreShopCartBaseService<T>, initialState?: Partial<TStore>);
|
|
8
|
+
protected getBaseState(set: any, get: any): TStore;
|
|
9
|
+
build(): import('zustand').UseBoundStore<Omit<import('zustand').StoreApi<TStore>, "persist"> & {
|
|
19
10
|
persist: {
|
|
20
|
-
setOptions: (options: Partial<import('zustand/middleware').PersistOptions<
|
|
11
|
+
setOptions: (options: Partial<import('zustand/middleware').PersistOptions<TStore, {
|
|
21
12
|
cart: import('../types').CoreShopCart<T>;
|
|
22
13
|
cartItems: import('../types').CoreCartItem<T>[];
|
|
23
14
|
}>>) => void;
|
|
24
15
|
clearStorage: () => void;
|
|
25
16
|
rehydrate: () => Promise<void> | void;
|
|
26
17
|
hasHydrated: () => boolean;
|
|
27
|
-
onHydrate: (fn: (state:
|
|
28
|
-
onFinishHydration: (fn: (state:
|
|
29
|
-
getOptions: () => Partial<import('zustand/middleware').PersistOptions<
|
|
18
|
+
onHydrate: (fn: (state: TStore) => void) => () => void;
|
|
19
|
+
onFinishHydration: (fn: (state: TStore) => void) => () => void;
|
|
20
|
+
getOptions: () => Partial<import('zustand/middleware').PersistOptions<TStore, {
|
|
30
21
|
cart: import('../types').CoreShopCart<T>;
|
|
31
22
|
cartItems: import('../types').CoreCartItem<T>[];
|
|
32
23
|
}>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CoreShopCartBuilder.d.ts","sourceRoot":"","sources":["../../../../src/modules/CoreShopCart/classes/CoreShopCartBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,
|
|
1
|
+
{"version":3,"file":"CoreShopCartBuilder.d.ts","sourceRoot":"","sources":["../../../../src/modules/CoreShopCart/classes/CoreShopCartBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAEnE,qBAAa,mBAAmB,CAAC,CAAC,EAAE,MAAM,SAAS,iBAAiB,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAE,SAAQ,eAAe,CAAC,MAAM,CAAC;IAC7H,SAAS,CAAC,eAAe,EAAE,uBAAuB,CAAC,CAAC,CAAC,CAAC;IACtD,SAAS,CAAC,YAAY,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC;gBAG/E,OAAO,GAAE,uBAAuB,CAAC,CAAC,CAAoC,EACtE,YAAY,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC;IAoBhC,SAAS,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,MAAM;IAiK3C,KAAK;;;;;;;;;;;;;;;;;CAeb"}
|
|
@@ -1,168 +1,177 @@
|
|
|
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
|
-
constructor(service = new CoreShopCartBaseService(), initialState
|
|
9
|
-
|
|
10
|
-
items: [],
|
|
11
|
-
subtotal: 0,
|
|
12
|
-
total: 0,
|
|
13
|
-
itemized_subtotals: []
|
|
14
|
-
},
|
|
15
|
-
cartItems: [],
|
|
16
|
-
loading: false,
|
|
17
|
-
error: null
|
|
18
|
-
}) {
|
|
9
|
+
constructor(service = new CoreShopCartBaseService(), initialState) {
|
|
10
|
+
super();
|
|
19
11
|
this.shopCartService = service;
|
|
20
|
-
this.initialState =
|
|
12
|
+
this.initialState = {
|
|
13
|
+
cart: {
|
|
14
|
+
items: [],
|
|
15
|
+
subtotal: 0,
|
|
16
|
+
total: 0,
|
|
17
|
+
itemized_subtotals: []
|
|
18
|
+
},
|
|
19
|
+
cartItems: [],
|
|
20
|
+
loading: false,
|
|
21
|
+
error: null
|
|
22
|
+
};
|
|
23
|
+
if (initialState) {
|
|
24
|
+
this.initialState = { ...this.initialState, ...initialState };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
getBaseState(set, get) {
|
|
28
|
+
return {
|
|
29
|
+
...this.initialState,
|
|
30
|
+
// Setters
|
|
31
|
+
setLoading: (loading) => set({ loading }),
|
|
32
|
+
setError: (error) => set({ error }),
|
|
33
|
+
setCart: (cart) => set({ cart }),
|
|
34
|
+
setCartItems: (cartItems) => set({ cartItems }),
|
|
35
|
+
// Getters
|
|
36
|
+
getCartItems: () => get().cartItems,
|
|
37
|
+
getCart: () => get().cart,
|
|
38
|
+
// Add to cart
|
|
39
|
+
addToCart: async (product_id, quantity, actions) => {
|
|
40
|
+
set({ loading: true, error: null });
|
|
41
|
+
try {
|
|
42
|
+
await this.shopCartService.addToCart(product_id, quantity);
|
|
43
|
+
const response = await this.shopCartService.getCart();
|
|
44
|
+
set({
|
|
45
|
+
cart: response.data.data,
|
|
46
|
+
cartItems: response.data.data.items,
|
|
47
|
+
loading: false
|
|
48
|
+
});
|
|
49
|
+
actions?.onSuccess?.(response.data);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
set({ error: error || "Failed to add to cart", loading: false });
|
|
52
|
+
actions?.onError?.(error);
|
|
53
|
+
throw error;
|
|
54
|
+
} finally {
|
|
55
|
+
actions?.onFinish?.();
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
// Remove one unit from cart
|
|
59
|
+
removeFromCart: async (product_id, actions) => {
|
|
60
|
+
set({ loading: true, error: null });
|
|
61
|
+
try {
|
|
62
|
+
await this.shopCartService.removeFromCart(product_id);
|
|
63
|
+
const response = await this.shopCartService.getCart();
|
|
64
|
+
set({
|
|
65
|
+
cart: response.data.data,
|
|
66
|
+
cartItems: response.data.data.items,
|
|
67
|
+
loading: false
|
|
68
|
+
});
|
|
69
|
+
actions?.onSuccess?.(response.data);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
set({ error: error || "Failed to remove from cart", loading: false });
|
|
72
|
+
actions?.onError?.(error);
|
|
73
|
+
throw error;
|
|
74
|
+
} finally {
|
|
75
|
+
actions?.onFinish?.();
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
// Remove entire item from cart
|
|
79
|
+
removeItemFromCart: async (product_id, actions) => {
|
|
80
|
+
set({ loading: true, error: null });
|
|
81
|
+
try {
|
|
82
|
+
await this.shopCartService.removeItemFromCart(product_id);
|
|
83
|
+
const response = await this.shopCartService.getCart();
|
|
84
|
+
set({
|
|
85
|
+
cart: response.data.data,
|
|
86
|
+
cartItems: response.data.data.items,
|
|
87
|
+
loading: false
|
|
88
|
+
});
|
|
89
|
+
actions?.onSuccess?.(response.data);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
set({ error: error || "Failed to remove item from cart", loading: false });
|
|
92
|
+
actions?.onError?.(error);
|
|
93
|
+
throw error;
|
|
94
|
+
} finally {
|
|
95
|
+
actions?.onFinish?.();
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
// Clear cart
|
|
99
|
+
clearCart: async (actions) => {
|
|
100
|
+
set({ loading: true, error: null });
|
|
101
|
+
try {
|
|
102
|
+
await this.shopCartService.clearCart();
|
|
103
|
+
const response = await this.shopCartService.getCart();
|
|
104
|
+
set({
|
|
105
|
+
cart: response.data.data,
|
|
106
|
+
cartItems: response.data.data.items,
|
|
107
|
+
loading: false
|
|
108
|
+
});
|
|
109
|
+
actions?.onSuccess?.(response.data);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
set({ error: error || "Failed to clear cart", loading: false });
|
|
112
|
+
actions?.onError?.(error);
|
|
113
|
+
throw error;
|
|
114
|
+
} finally {
|
|
115
|
+
actions?.onFinish?.();
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
// Fetch full cart
|
|
119
|
+
fetchCart: async (actions) => {
|
|
120
|
+
set({ loading: true, error: null });
|
|
121
|
+
try {
|
|
122
|
+
const response = await this.shopCartService.getCart();
|
|
123
|
+
set({
|
|
124
|
+
cart: response.data.data,
|
|
125
|
+
cartItems: response.data.data.items,
|
|
126
|
+
loading: false
|
|
127
|
+
});
|
|
128
|
+
actions?.onSuccess?.(response.data);
|
|
129
|
+
return response.data;
|
|
130
|
+
} catch (error) {
|
|
131
|
+
set({ error: error || "Failed to fetch cart", loading: false });
|
|
132
|
+
actions?.onError?.(error);
|
|
133
|
+
throw error;
|
|
134
|
+
} finally {
|
|
135
|
+
actions?.onFinish?.();
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
// Fetch cart items only
|
|
139
|
+
fetchCartItems: async (params, actions) => {
|
|
140
|
+
const { onlyFetch } = params || {};
|
|
141
|
+
try {
|
|
142
|
+
if (!onlyFetch) {
|
|
143
|
+
set({ loading: true, error: null });
|
|
144
|
+
}
|
|
145
|
+
const response = await this.shopCartService.getCartItems();
|
|
146
|
+
if (!onlyFetch) {
|
|
147
|
+
set({ cartItems: response.data.data, loading: false });
|
|
148
|
+
}
|
|
149
|
+
actions?.onSuccess?.(response.data);
|
|
150
|
+
return response.data;
|
|
151
|
+
} catch (error) {
|
|
152
|
+
if (!onlyFetch) {
|
|
153
|
+
set({ error: error || "Failed to fetch cart items", loading: false });
|
|
154
|
+
}
|
|
155
|
+
actions?.onError?.(error);
|
|
156
|
+
throw error;
|
|
157
|
+
} finally {
|
|
158
|
+
actions?.onFinish?.();
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
// Reset
|
|
162
|
+
reset: () => set({ ...this.initialState, ...this.extendInitialState() })
|
|
163
|
+
};
|
|
21
164
|
}
|
|
22
165
|
build() {
|
|
23
166
|
return create()(
|
|
24
167
|
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
|
-
}),
|
|
168
|
+
(set, get) => this.buildStoreState(set, get),
|
|
161
169
|
{
|
|
162
170
|
name: "shop-cart-storage",
|
|
163
171
|
partialize: (state) => ({
|
|
164
172
|
cart: state.cart,
|
|
165
|
-
cartItems: state.cartItems
|
|
173
|
+
cartItems: state.cartItems,
|
|
174
|
+
...this.extendPartialize(state)
|
|
166
175
|
})
|
|
167
176
|
}
|
|
168
177
|
)
|