@storepecker/storefront-core 2.2.1 → 2.3.0
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/{chunk-ZKHQPHT5.js → chunk-QBRME5AG.js} +54 -6
- package/dist/{chunk-JVSR6THX.cjs → chunk-SABICUTC.cjs} +54 -6
- package/dist/hooks/index.cjs +10 -5
- package/dist/hooks/index.d.cts +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +7 -2
- package/dist/store/index.cjs +4 -4
- package/dist/store/index.js +1 -1
- package/package.json +1 -1
|
@@ -42,8 +42,24 @@ var useCartStore = create((set) => ({
|
|
|
42
42
|
addToCart: async (items, customizationInputs, addressId) => {
|
|
43
43
|
set({ status: "loading" /* LOADING */ });
|
|
44
44
|
try {
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
if (auth_default.getUserDetails()) {
|
|
46
|
+
await addToCart(items, customizationInputs);
|
|
47
|
+
await useCartStore.getState().syncCart(addressId);
|
|
48
|
+
} else {
|
|
49
|
+
const cart = cart_default.get();
|
|
50
|
+
if (cart) {
|
|
51
|
+
items.forEach((item) => {
|
|
52
|
+
const product = cart.product_variants.find(
|
|
53
|
+
(p) => p.id === item.variant_id
|
|
54
|
+
);
|
|
55
|
+
if (product) {
|
|
56
|
+
cart_default.add(product);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const updatedCart = cart_default.get();
|
|
61
|
+
if (updatedCart) set({ cart: updatedCart });
|
|
62
|
+
}
|
|
47
63
|
} catch {
|
|
48
64
|
} finally {
|
|
49
65
|
set({ status: "idle" /* IDLE */ });
|
|
@@ -52,8 +68,26 @@ var useCartStore = create((set) => ({
|
|
|
52
68
|
removeFromCart: async (items, addressId) => {
|
|
53
69
|
set({ status: "loading" /* LOADING */ });
|
|
54
70
|
try {
|
|
55
|
-
|
|
56
|
-
|
|
71
|
+
if (auth_default.getUserDetails()) {
|
|
72
|
+
await removeFromCart(items);
|
|
73
|
+
await useCartStore.getState().syncCart(addressId);
|
|
74
|
+
} else {
|
|
75
|
+
const cart = cart_default.get();
|
|
76
|
+
if (cart) {
|
|
77
|
+
items.forEach((item) => {
|
|
78
|
+
const product = cart.product_variants.find(
|
|
79
|
+
(p) => p.id === item.variant_id
|
|
80
|
+
);
|
|
81
|
+
if (product) cart_default.remove(product);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
const updatedCart = cart_default.get();
|
|
85
|
+
if (updatedCart) {
|
|
86
|
+
set({ cart: updatedCart });
|
|
87
|
+
} else {
|
|
88
|
+
set(initialState);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
57
91
|
} catch {
|
|
58
92
|
} finally {
|
|
59
93
|
set({ status: "idle" /* IDLE */ });
|
|
@@ -62,8 +96,22 @@ var useCartStore = create((set) => ({
|
|
|
62
96
|
updateCart: async (items, addressId) => {
|
|
63
97
|
set({ status: "loading" /* LOADING */ });
|
|
64
98
|
try {
|
|
65
|
-
|
|
66
|
-
|
|
99
|
+
if (auth_default.getUserDetails()) {
|
|
100
|
+
await updateCart(items);
|
|
101
|
+
await useCartStore.getState().syncCart(addressId);
|
|
102
|
+
} else {
|
|
103
|
+
const cart = cart_default.get();
|
|
104
|
+
if (cart) {
|
|
105
|
+
items.forEach((item) => {
|
|
106
|
+
const product = cart.product_variants.find(
|
|
107
|
+
(p) => p.id === item.variant_id
|
|
108
|
+
);
|
|
109
|
+
if (product) cart_default.updateQuantity(product, item.quantity);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const updatedCart = cart_default.get();
|
|
113
|
+
if (updatedCart) set({ cart: updatedCart });
|
|
114
|
+
}
|
|
67
115
|
} catch {
|
|
68
116
|
} finally {
|
|
69
117
|
set({ status: "idle" /* IDLE */ });
|
|
@@ -44,8 +44,24 @@ var useCartStore = zustand.create((set) => ({
|
|
|
44
44
|
addToCart: async (items, customizationInputs, addressId) => {
|
|
45
45
|
set({ status: "loading" /* LOADING */ });
|
|
46
46
|
try {
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
if (chunkBBRXE57K_cjs.auth_default.getUserDetails()) {
|
|
48
|
+
await chunkA67PCF55_cjs.addToCart(items, customizationInputs);
|
|
49
|
+
await useCartStore.getState().syncCart(addressId);
|
|
50
|
+
} else {
|
|
51
|
+
const cart = chunkSMHJRNCR_cjs.cart_default.get();
|
|
52
|
+
if (cart) {
|
|
53
|
+
items.forEach((item) => {
|
|
54
|
+
const product = cart.product_variants.find(
|
|
55
|
+
(p) => p.id === item.variant_id
|
|
56
|
+
);
|
|
57
|
+
if (product) {
|
|
58
|
+
chunkSMHJRNCR_cjs.cart_default.add(product);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
const updatedCart = chunkSMHJRNCR_cjs.cart_default.get();
|
|
63
|
+
if (updatedCart) set({ cart: updatedCart });
|
|
64
|
+
}
|
|
49
65
|
} catch {
|
|
50
66
|
} finally {
|
|
51
67
|
set({ status: "idle" /* IDLE */ });
|
|
@@ -54,8 +70,26 @@ var useCartStore = zustand.create((set) => ({
|
|
|
54
70
|
removeFromCart: async (items, addressId) => {
|
|
55
71
|
set({ status: "loading" /* LOADING */ });
|
|
56
72
|
try {
|
|
57
|
-
|
|
58
|
-
|
|
73
|
+
if (chunkBBRXE57K_cjs.auth_default.getUserDetails()) {
|
|
74
|
+
await chunkA67PCF55_cjs.removeFromCart(items);
|
|
75
|
+
await useCartStore.getState().syncCart(addressId);
|
|
76
|
+
} else {
|
|
77
|
+
const cart = chunkSMHJRNCR_cjs.cart_default.get();
|
|
78
|
+
if (cart) {
|
|
79
|
+
items.forEach((item) => {
|
|
80
|
+
const product = cart.product_variants.find(
|
|
81
|
+
(p) => p.id === item.variant_id
|
|
82
|
+
);
|
|
83
|
+
if (product) chunkSMHJRNCR_cjs.cart_default.remove(product);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
const updatedCart = chunkSMHJRNCR_cjs.cart_default.get();
|
|
87
|
+
if (updatedCart) {
|
|
88
|
+
set({ cart: updatedCart });
|
|
89
|
+
} else {
|
|
90
|
+
set(initialState);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
59
93
|
} catch {
|
|
60
94
|
} finally {
|
|
61
95
|
set({ status: "idle" /* IDLE */ });
|
|
@@ -64,8 +98,22 @@ var useCartStore = zustand.create((set) => ({
|
|
|
64
98
|
updateCart: async (items, addressId) => {
|
|
65
99
|
set({ status: "loading" /* LOADING */ });
|
|
66
100
|
try {
|
|
67
|
-
|
|
68
|
-
|
|
101
|
+
if (chunkBBRXE57K_cjs.auth_default.getUserDetails()) {
|
|
102
|
+
await chunkA67PCF55_cjs.updateCart(items);
|
|
103
|
+
await useCartStore.getState().syncCart(addressId);
|
|
104
|
+
} else {
|
|
105
|
+
const cart = chunkSMHJRNCR_cjs.cart_default.get();
|
|
106
|
+
if (cart) {
|
|
107
|
+
items.forEach((item) => {
|
|
108
|
+
const product = cart.product_variants.find(
|
|
109
|
+
(p) => p.id === item.variant_id
|
|
110
|
+
);
|
|
111
|
+
if (product) chunkSMHJRNCR_cjs.cart_default.updateQuantity(product, item.quantity);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const updatedCart = chunkSMHJRNCR_cjs.cart_default.get();
|
|
115
|
+
if (updatedCart) set({ cart: updatedCart });
|
|
116
|
+
}
|
|
69
117
|
} catch {
|
|
70
118
|
} finally {
|
|
71
119
|
set({ status: "idle" /* IDLE */ });
|
package/dist/hooks/index.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var chunkKKQKHG26_cjs = require('../chunk-KKQKHG26.cjs');
|
|
4
4
|
var chunk2AHH3XBW_cjs = require('../chunk-2AHH3XBW.cjs');
|
|
5
|
-
var
|
|
5
|
+
var chunkSABICUTC_cjs = require('../chunk-SABICUTC.cjs');
|
|
6
6
|
var chunkA67PCF55_cjs = require('../chunk-A67PCF55.cjs');
|
|
7
7
|
var chunkSMHJRNCR_cjs = require('../chunk-SMHJRNCR.cjs');
|
|
8
8
|
var chunkXLQAALMU_cjs = require('../chunk-XLQAALMU.cjs');
|
|
@@ -32,6 +32,7 @@ var useAddress = () => {
|
|
|
32
32
|
setError(null);
|
|
33
33
|
} catch (err) {
|
|
34
34
|
setError(err);
|
|
35
|
+
setData([]);
|
|
35
36
|
} finally {
|
|
36
37
|
setIsLoading(false);
|
|
37
38
|
}
|
|
@@ -78,7 +79,11 @@ var useOrders = (filters) => {
|
|
|
78
79
|
const [data, setData] = react.useState(void 0);
|
|
79
80
|
const [error, setError] = react.useState(null);
|
|
80
81
|
const [isLoading, setIsLoading] = react.useState(true);
|
|
81
|
-
const queryString = new URLSearchParams(
|
|
82
|
+
const queryString = new URLSearchParams(
|
|
83
|
+
Object.fromEntries(
|
|
84
|
+
Object.entries(filters).map(([k, v]) => [k, String(v)])
|
|
85
|
+
)
|
|
86
|
+
).toString();
|
|
82
87
|
const fetchData = react.useCallback(async () => {
|
|
83
88
|
try {
|
|
84
89
|
setIsLoading(true);
|
|
@@ -314,7 +319,7 @@ function useCheckoutPayment(options) {
|
|
|
314
319
|
const [isConfirmingPayment, setIsConfirmingPayment] = react.useState(false);
|
|
315
320
|
const [showSuccessModal, setShowSuccessModal] = react.useState(false);
|
|
316
321
|
const [showFailureModal, setShowFailureModal] = react.useState(false);
|
|
317
|
-
const resetCartCount =
|
|
322
|
+
const resetCartCount = chunkSABICUTC_cjs.useCartStore((s) => s.resetCartCount);
|
|
318
323
|
const callbacks = {
|
|
319
324
|
onSuccess: (order) => {
|
|
320
325
|
setOrderSummary(order);
|
|
@@ -500,8 +505,8 @@ function useVariantSelector(options) {
|
|
|
500
505
|
}
|
|
501
506
|
function useShopCheckout(options) {
|
|
502
507
|
const { product, onNavigateToCart, onToast } = options;
|
|
503
|
-
const { addToCart, setCart } =
|
|
504
|
-
const isUserAuthenticated =
|
|
508
|
+
const { addToCart, setCart } = chunkSABICUTC_cjs.useCartStore();
|
|
509
|
+
const isUserAuthenticated = chunkSABICUTC_cjs.useAuthStore((s) => s.isAuthenticated);
|
|
505
510
|
const [isWishlisted, setIsWishlisted] = react.useState(product.is_wishlisted);
|
|
506
511
|
const [isAddedToCart, setIsAddedToCart] = react.useState(false);
|
|
507
512
|
const [loading, setLoading] = react.useState(false);
|
package/dist/hooks/index.d.cts
CHANGED
|
@@ -24,7 +24,7 @@ declare const useCart: (addressId?: number) => {
|
|
|
24
24
|
setData: React.Dispatch<React.SetStateAction<Cart.Root | undefined>>;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
declare const useOrders: (filters: Record<string,
|
|
27
|
+
declare const useOrders: (filters: Record<string, any>) => {
|
|
28
28
|
data: Order.OrderResponse | undefined;
|
|
29
29
|
error: unknown;
|
|
30
30
|
isLoading: boolean;
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ declare const useCart: (addressId?: number) => {
|
|
|
24
24
|
setData: React.Dispatch<React.SetStateAction<Cart.Root | undefined>>;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
declare const useOrders: (filters: Record<string,
|
|
27
|
+
declare const useOrders: (filters: Record<string, any>) => {
|
|
28
28
|
data: Order.OrderResponse | undefined;
|
|
29
29
|
error: unknown;
|
|
30
30
|
isLoading: boolean;
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getUserDetails } from '../chunk-C7ZJZEEN.js';
|
|
2
2
|
import { findMatchingVariant, findSimilarVariant, isVariantCombinationAvailable, isColorVariantType } from '../chunk-HEFA67WK.js';
|
|
3
|
-
import { useCartStore, useAuthStore } from '../chunk-
|
|
3
|
+
import { useCartStore, useAuthStore } from '../chunk-QBRME5AG.js';
|
|
4
4
|
import { getCart, getProductList, getProductDetail, getWishlist, notifyProductStock, getProductCategories, getCategories } from '../chunk-ERLBPVFK.js';
|
|
5
5
|
import { cart_default } from '../chunk-QAC72HKO.js';
|
|
6
6
|
import { processPayment, fetchAvailableCoupons, applyCheckoutCoupon, removeCheckoutCoupon } from '../chunk-BHOXJGIE.js';
|
|
@@ -30,6 +30,7 @@ var useAddress = () => {
|
|
|
30
30
|
setError(null);
|
|
31
31
|
} catch (err) {
|
|
32
32
|
setError(err);
|
|
33
|
+
setData([]);
|
|
33
34
|
} finally {
|
|
34
35
|
setIsLoading(false);
|
|
35
36
|
}
|
|
@@ -76,7 +77,11 @@ var useOrders = (filters) => {
|
|
|
76
77
|
const [data, setData] = useState(void 0);
|
|
77
78
|
const [error, setError] = useState(null);
|
|
78
79
|
const [isLoading, setIsLoading] = useState(true);
|
|
79
|
-
const queryString = new URLSearchParams(
|
|
80
|
+
const queryString = new URLSearchParams(
|
|
81
|
+
Object.fromEntries(
|
|
82
|
+
Object.entries(filters).map(([k, v]) => [k, String(v)])
|
|
83
|
+
)
|
|
84
|
+
).toString();
|
|
80
85
|
const fetchData = useCallback(async () => {
|
|
81
86
|
try {
|
|
82
87
|
setIsLoading(true);
|
package/dist/store/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkSABICUTC_cjs = require('../chunk-SABICUTC.cjs');
|
|
4
4
|
var chunkA67PCF55_cjs = require('../chunk-A67PCF55.cjs');
|
|
5
5
|
require('../chunk-SMHJRNCR.cjs');
|
|
6
6
|
require('../chunk-ZO2HREQL.cjs');
|
|
@@ -67,15 +67,15 @@ var useProductStore = zustand.create((set, get) => ({
|
|
|
67
67
|
|
|
68
68
|
Object.defineProperty(exports, "loginUser", {
|
|
69
69
|
enumerable: true,
|
|
70
|
-
get: function () { return
|
|
70
|
+
get: function () { return chunkSABICUTC_cjs.loginUser; }
|
|
71
71
|
});
|
|
72
72
|
Object.defineProperty(exports, "useAuthStore", {
|
|
73
73
|
enumerable: true,
|
|
74
|
-
get: function () { return
|
|
74
|
+
get: function () { return chunkSABICUTC_cjs.useAuthStore; }
|
|
75
75
|
});
|
|
76
76
|
Object.defineProperty(exports, "useCartStore", {
|
|
77
77
|
enumerable: true,
|
|
78
|
-
get: function () { return
|
|
78
|
+
get: function () { return chunkSABICUTC_cjs.useCartStore; }
|
|
79
79
|
});
|
|
80
80
|
exports.useProductStore = useProductStore;
|
|
81
81
|
exports.useWishlistStore = useWishlistStore;
|
package/dist/store/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { loginUser, useAuthStore, useCartStore } from '../chunk-
|
|
1
|
+
export { loginUser, useAuthStore, useCartStore } from '../chunk-QBRME5AG.js';
|
|
2
2
|
import { getWishlist, getProducts } from '../chunk-ERLBPVFK.js';
|
|
3
3
|
import '../chunk-QAC72HKO.js';
|
|
4
4
|
import '../chunk-JWKDXFS4.js';
|