@storepecker/storefront-core 1.2.0 → 2.0.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/api/index.cjs +76 -75
- package/dist/api/index.d.cts +4 -3
- package/dist/api/index.d.ts +4 -3
- package/dist/api/index.js +9 -8
- package/dist/{booking-B21s0inO.d.cts → booking-B39Ilxhg.d.ts} +1 -1
- package/dist/{booking-CegE1cje.d.ts → booking-Dk-BoHUB.d.cts} +1 -1
- package/dist/cart-BY8D8w-s.d.cts +90 -0
- package/dist/cart-GuhgeBBt.d.ts +90 -0
- package/dist/checkout/index.cjs +38 -37
- package/dist/checkout/index.d.cts +2 -1
- package/dist/checkout/index.d.ts +2 -1
- package/dist/checkout/index.js +6 -5
- package/dist/{chunk-34KV265H.cjs → chunk-26A3EBZI.cjs} +20 -20
- package/dist/chunk-2AHH3XBW.cjs +47 -0
- package/dist/{chunk-K5B62JZO.cjs → chunk-47XTPPII.cjs} +4 -4
- package/dist/chunk-4C4NTH6O.js +41 -0
- package/dist/{chunk-UM24VDYB.js → chunk-7R2V4C7Q.js} +2 -2
- package/dist/{chunk-CSISWBZZ.js → chunk-B7FOXIZN.js} +1 -1
- package/dist/chunk-BBRB475I.cjs +43 -0
- package/dist/chunk-BBRXE57K.cjs +50 -0
- package/dist/{chunk-QCQCFYYR.js → chunk-BHOXJGIE.js} +1 -1
- package/dist/chunk-BQ256JKN.js +39 -0
- package/dist/{chunk-7UH6REGV.js → chunk-C7ZJZEEN.js} +1 -1
- package/dist/{chunk-A6IO3HIN.cjs → chunk-FMHR5ABF.cjs} +28 -28
- package/dist/{chunk-JHGXIIBZ.cjs → chunk-G3R7ZVAG.cjs} +7 -7
- package/dist/{chunk-4MJMNIAB.js → chunk-GHABOHLA.js} +1 -1
- package/dist/chunk-GTV42PDK.cjs +46 -0
- package/dist/chunk-HEFA67WK.js +42 -0
- package/dist/chunk-HSF2D56O.js +40 -0
- package/dist/{chunk-GB3HW6DM.js → chunk-JWKDXFS4.js} +1 -1
- package/dist/{chunk-KWKHHRRJ.cjs → chunk-KKQKHG26.cjs} +3 -3
- package/dist/{chunk-QM73PI5L.cjs → chunk-N3ZCCKXV.cjs} +10 -10
- package/dist/{chunk-GQTO5ZE2.cjs → chunk-NE3ZHELZ.cjs} +0 -46
- package/dist/chunk-PWYWNRVO.cjs +150 -0
- package/dist/{chunk-E7WPE3PV.js → chunk-QAC72HKO.js} +1 -1
- package/dist/{chunk-CFF632IQ.cjs → chunk-SMHJRNCR.cjs} +4 -4
- package/dist/chunk-UOFTDL4D.js +146 -0
- package/dist/chunk-WEMNXIRS.js +47 -0
- package/dist/{chunk-LC5ZAUKL.cjs → chunk-XLQAALMU.cjs} +10 -10
- package/dist/{chunk-Z7LHRD3V.js → chunk-Y6NFUWTH.js} +3 -3
- package/dist/{chunk-LBGIUNM6.js → chunk-YY77CUWX.js} +1 -1
- package/dist/{chunk-UXLUE3HW.cjs → chunk-ZO2HREQL.cjs} +2 -2
- package/dist/components/index.cjs +126 -7
- package/dist/components/index.d.cts +35 -8
- package/dist/components/index.d.ts +35 -8
- package/dist/components/index.js +122 -7
- package/dist/hooks/index.cjs +368 -27
- package/dist/hooks/index.d.cts +83 -3
- package/dist/hooks/index.d.ts +83 -3
- package/dist/hooks/index.js +352 -14
- package/dist/middleware/index.cjs +47 -0
- package/dist/middleware/index.d.cts +8 -0
- package/dist/middleware/index.d.ts +8 -0
- package/dist/middleware/index.js +44 -0
- package/dist/models/index.d.cts +4 -3
- package/dist/models/index.d.ts +4 -3
- package/dist/{cart-VaCKkJ1C.d.cts → product-Dfi0ke-4.d.cts} +1 -88
- package/dist/{cart-VaCKkJ1C.d.ts → product-Dfi0ke-4.d.ts} +1 -88
- package/dist/store/index.cjs +17 -85
- package/dist/store/index.d.cts +22 -2
- package/dist/store/index.d.ts +22 -2
- package/dist/store/index.js +7 -82
- package/dist/utils/index.cjs +80 -65
- package/dist/utils/index.d.cts +54 -3
- package/dist/utils/index.d.ts +54 -3
- package/dist/utils/index.js +20 -43
- package/dist/{wishlist-FG8tgn76.d.ts → wishlist-DHOvXmJj.d.cts} +1 -1
- package/dist/{wishlist-CkAhLpbI.d.cts → wishlist-LfdFxddw.d.ts} +1 -1
- package/package.json +24 -5
- package/dist/chunk-7DQIKSGY.js +0 -40
- package/dist/chunk-FLBJKM6G.js +0 -83
- package/dist/chunk-S3WIGYDS.cjs +0 -42
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkZO2HREQL_cjs = require('./chunk-ZO2HREQL.cjs');
|
|
4
4
|
|
|
5
5
|
// src/api/coupon.ts
|
|
6
6
|
async function getCoupons() {
|
|
7
|
-
return
|
|
7
|
+
return chunkZO2HREQL_cjs.http_service_default.get("/coupon/available/");
|
|
8
8
|
}
|
|
9
9
|
async function applyCoupon(couponCode) {
|
|
10
|
-
return
|
|
10
|
+
return chunkZO2HREQL_cjs.http_service_default.post("/coupon/use/", { coupon_code: couponCode });
|
|
11
11
|
}
|
|
12
12
|
async function getAppliedCoupon() {
|
|
13
|
-
return
|
|
13
|
+
return chunkZO2HREQL_cjs.http_service_default.get("/coupon/use/");
|
|
14
14
|
}
|
|
15
15
|
async function removeCoupon(couponCode) {
|
|
16
|
-
return
|
|
16
|
+
return chunkZO2HREQL_cjs.http_service_default.delete("/coupon/use/");
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
// src/api/orders.ts
|
|
20
20
|
async function getOrders(url) {
|
|
21
|
-
const response = await
|
|
21
|
+
const response = await chunkZO2HREQL_cjs.http_service_default.get(url);
|
|
22
22
|
return response.data;
|
|
23
23
|
}
|
|
24
24
|
async function getOrderDetails(orderId) {
|
|
25
|
-
return
|
|
25
|
+
return chunkZO2HREQL_cjs.http_service_default.get("/customer/order/", {
|
|
26
26
|
params: { order_id: orderId }
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
async function getOrderDetailsByNumber(orderNumber) {
|
|
30
|
-
return
|
|
30
|
+
return chunkZO2HREQL_cjs.http_service_default.get("/customer/order/", {
|
|
31
31
|
params: { order_number: orderNumber }
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
async function getPublicOrderDetailsByNumber(orderNumber) {
|
|
35
|
-
return
|
|
35
|
+
return chunkZO2HREQL_cjs.http_service_default.get("/customer/public_order/", {
|
|
36
36
|
params: { order_number: orderNumber }
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
async function placeOrder(address_id, redirect, isCod, stripeRedirect, tabbyRedirect) {
|
|
40
|
-
return
|
|
40
|
+
return chunkZO2HREQL_cjs.http_service_default.post("/customer/order/", {
|
|
41
41
|
address_id,
|
|
42
42
|
phonepe_redirect_url: redirect,
|
|
43
43
|
is_cod: isCod,
|
|
@@ -46,7 +46,7 @@ async function placeOrder(address_id, redirect, isCod, stripeRedirect, tabbyRedi
|
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
async function publicPlaceOrder(address, redirect, orderDetails, stripeRedirect, tabbyRedirect) {
|
|
49
|
-
return
|
|
49
|
+
return chunkZO2HREQL_cjs.http_service_default.post("/customer/public_order/", {
|
|
50
50
|
address,
|
|
51
51
|
phonepe_redirect_url: redirect,
|
|
52
52
|
stripe_redirect_url: stripeRedirect,
|
|
@@ -55,30 +55,30 @@ async function publicPlaceOrder(address, redirect, orderDetails, stripeRedirect,
|
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
async function updateOrder(orderDetails) {
|
|
58
|
-
return
|
|
58
|
+
return chunkZO2HREQL_cjs.http_service_default.patch("/customer/order/", orderDetails);
|
|
59
59
|
}
|
|
60
60
|
async function razorpayPublicOrderSuccess(orderDetails) {
|
|
61
|
-
return
|
|
61
|
+
return chunkZO2HREQL_cjs.http_service_default.post("/payment/public-razorpay-order-success/", orderDetails);
|
|
62
62
|
}
|
|
63
63
|
async function razorpayOrderSuccess(orderDetails) {
|
|
64
|
-
return
|
|
64
|
+
return chunkZO2HREQL_cjs.http_service_default.post("/payment/razorpay-order-success/", orderDetails);
|
|
65
65
|
}
|
|
66
66
|
async function razorpayOrderFail(orderDetails) {
|
|
67
|
-
return
|
|
67
|
+
return chunkZO2HREQL_cjs.http_service_default.post("/payment/razorpay-order-fail/", orderDetails);
|
|
68
68
|
}
|
|
69
69
|
async function phonepePublicOrderSuccess(orderDetails) {
|
|
70
|
-
return
|
|
70
|
+
return chunkZO2HREQL_cjs.http_service_default.post("/payment/public-phonepe-order-success/", orderDetails);
|
|
71
71
|
}
|
|
72
72
|
async function phonepeOrderSuccess(orderDetails) {
|
|
73
|
-
return
|
|
73
|
+
return chunkZO2HREQL_cjs.http_service_default.post("/payment/phonepe-order-success/", orderDetails);
|
|
74
74
|
}
|
|
75
75
|
async function checkPhonepePaymentStatus(transactionId) {
|
|
76
|
-
return
|
|
76
|
+
return chunkZO2HREQL_cjs.http_service_default.get("/payment/phonepe-order-success/", {
|
|
77
77
|
params: { phonepe_transaction_id: transactionId }
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
80
|
async function getStripePaymentStatus(stripeCheckoutSessionId, order_number, payment_link_id) {
|
|
81
|
-
return
|
|
81
|
+
return chunkZO2HREQL_cjs.http_service_default.get("/payment/stripe-payment-status/", {
|
|
82
82
|
params: {
|
|
83
83
|
checkout_session_id: stripeCheckoutSessionId,
|
|
84
84
|
order_number,
|
|
@@ -87,7 +87,7 @@ async function getStripePaymentStatus(stripeCheckoutSessionId, order_number, pay
|
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
89
|
async function getStripePaymentStatusPublic(stripeCheckoutSessionId, order_number, payment_link_id) {
|
|
90
|
-
return
|
|
90
|
+
return chunkZO2HREQL_cjs.http_service_default.get("/payment/public-stripe-payment-status/", {
|
|
91
91
|
params: {
|
|
92
92
|
checkout_session_id: stripeCheckoutSessionId,
|
|
93
93
|
order_number,
|
|
@@ -96,28 +96,28 @@ async function getStripePaymentStatusPublic(stripeCheckoutSessionId, order_numbe
|
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
98
|
async function stripePublicOrderSuccess(orderDetails) {
|
|
99
|
-
return
|
|
99
|
+
return chunkZO2HREQL_cjs.http_service_default.post("/payment/public-stripe-order-success/", orderDetails);
|
|
100
100
|
}
|
|
101
101
|
async function stripeOrderSuccess(orderDetails) {
|
|
102
|
-
return
|
|
102
|
+
return chunkZO2HREQL_cjs.http_service_default.post("/payment/stripe-order-success/", orderDetails);
|
|
103
103
|
}
|
|
104
104
|
async function stripeOrderFail(orderDetails) {
|
|
105
|
-
return
|
|
105
|
+
return chunkZO2HREQL_cjs.http_service_default.post("/payment/stripe-order-fail/", orderDetails);
|
|
106
106
|
}
|
|
107
107
|
async function makeCODOrder(orderId) {
|
|
108
|
-
return
|
|
108
|
+
return chunkZO2HREQL_cjs.http_service_default.post("/customer/order_cod/", { order_id: orderId });
|
|
109
109
|
}
|
|
110
110
|
async function publicMakeCODOrder(orderNumber) {
|
|
111
|
-
return
|
|
111
|
+
return chunkZO2HREQL_cjs.http_service_default.post("/customer/public_order_cod/", { order_number: orderNumber });
|
|
112
112
|
}
|
|
113
113
|
async function updateOrderCustomization(customizationInput) {
|
|
114
|
-
return
|
|
114
|
+
return chunkZO2HREQL_cjs.http_service_default.post("/customer/product_personalize/", customizationInput);
|
|
115
115
|
}
|
|
116
116
|
async function uploadCustomizationImage(uploadForm) {
|
|
117
|
-
return
|
|
117
|
+
return chunkZO2HREQL_cjs.http_service_default.post("/utils/upload_image", uploadForm);
|
|
118
118
|
}
|
|
119
119
|
async function verifyTabbyPayment(orderNumber) {
|
|
120
|
-
return
|
|
120
|
+
return chunkZO2HREQL_cjs.http_service_default.get("/payment/tabby-payment-status/", {
|
|
121
121
|
params: { order_number: orderNumber }
|
|
122
122
|
});
|
|
123
123
|
}
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkZO2HREQL_cjs = require('./chunk-ZO2HREQL.cjs');
|
|
4
4
|
|
|
5
5
|
// src/api/address.ts
|
|
6
6
|
async function getAddresses(url) {
|
|
7
|
-
const response = await
|
|
7
|
+
const response = await chunkZO2HREQL_cjs.http_service_default.get(url);
|
|
8
8
|
return response.data;
|
|
9
9
|
}
|
|
10
10
|
async function addAddress(addressDetails) {
|
|
11
|
-
return
|
|
11
|
+
return chunkZO2HREQL_cjs.http_service_default.post("/store/customer_address/", addressDetails);
|
|
12
12
|
}
|
|
13
13
|
async function updateAddress(addressDetails) {
|
|
14
|
-
return
|
|
14
|
+
return chunkZO2HREQL_cjs.http_service_default.patch("/store/customer_address/", addressDetails);
|
|
15
15
|
}
|
|
16
16
|
async function deleteAddress(address_id) {
|
|
17
|
-
return
|
|
17
|
+
return chunkZO2HREQL_cjs.http_service_default.delete("/store/customer_address/", {
|
|
18
18
|
params: { address_id }
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
// src/api/countries.ts
|
|
23
23
|
var getCountries = async () => {
|
|
24
|
-
return
|
|
24
|
+
return chunkZO2HREQL_cjs.http_service_default.get("utils/countries/");
|
|
25
25
|
};
|
|
26
26
|
var getSubdivisions = async (countryId) => {
|
|
27
|
-
return
|
|
27
|
+
return chunkZO2HREQL_cjs.http_service_default.get(`utils/subdivisions/`, {
|
|
28
28
|
params: { country_id: countryId }
|
|
29
29
|
});
|
|
30
30
|
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/utils/routes.ts
|
|
4
|
+
var protectedRoutes = [
|
|
5
|
+
"/my/profile",
|
|
6
|
+
"/my/orders",
|
|
7
|
+
"/my/delete-account",
|
|
8
|
+
"/my/addresses",
|
|
9
|
+
"/my/dashboard"
|
|
10
|
+
];
|
|
11
|
+
var authRoutes = ["/login", "/signup"];
|
|
12
|
+
var publicRoutes = ["/about", "/"];
|
|
13
|
+
var urls = {
|
|
14
|
+
dashboard: "/my/dashboard",
|
|
15
|
+
profile: "/my/profile",
|
|
16
|
+
orders: "/my/orders",
|
|
17
|
+
orderDetail: "/my/orders/:id",
|
|
18
|
+
deleteAccount: "/my/delete-account",
|
|
19
|
+
addresses: "/my/addresses",
|
|
20
|
+
bookings: "/my/bookings",
|
|
21
|
+
login: "/login",
|
|
22
|
+
signup: "/signup",
|
|
23
|
+
about: "/about",
|
|
24
|
+
home: "/",
|
|
25
|
+
searchProducts: "/search-products",
|
|
26
|
+
shop: "/shop",
|
|
27
|
+
shopDetails: "/shop/:id",
|
|
28
|
+
cart: "/checkout/cart",
|
|
29
|
+
address: "/checkout/address",
|
|
30
|
+
payment: "/checkout/payment",
|
|
31
|
+
wishlist: "/wishlist",
|
|
32
|
+
privacyPolicy: "/privacy-policy",
|
|
33
|
+
faq: "/faq",
|
|
34
|
+
contactUs: "/contact-us",
|
|
35
|
+
services: "/services",
|
|
36
|
+
storeReview: "/store-review",
|
|
37
|
+
returnAndRefund: "/return-and-refund",
|
|
38
|
+
shippingPolicy: "/shipping-policy",
|
|
39
|
+
termsOfService: "/terms-of-service"
|
|
40
|
+
};
|
|
41
|
+
var routes_default = urls;
|
|
42
|
+
|
|
43
|
+
exports.authRoutes = authRoutes;
|
|
44
|
+
exports.protectedRoutes = protectedRoutes;
|
|
45
|
+
exports.publicRoutes = publicRoutes;
|
|
46
|
+
exports.routes_default = routes_default;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// src/utils/variant.ts
|
|
2
|
+
var findMatchingVariant = (variantAttributes, attributeKeys, newSelectedVariant) => {
|
|
3
|
+
return variantAttributes.find((attributes) => {
|
|
4
|
+
for (const key of attributeKeys) {
|
|
5
|
+
const selectedVal = newSelectedVariant?.[key]?.name?.toLowerCase();
|
|
6
|
+
const attrVal = attributes?.[key]?.name?.toLowerCase();
|
|
7
|
+
if (selectedVal !== attrVal) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return true;
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
var findSimilarVariant = (variantAttributes, variantType, variant) => {
|
|
15
|
+
return variantAttributes.find(
|
|
16
|
+
(attributes) => attributes?.[variantType]?.value?.toLowerCase() === variant.value?.toLowerCase()
|
|
17
|
+
);
|
|
18
|
+
};
|
|
19
|
+
var isVariantCombinationAvailable = (variantAttributes, attributeKeys, currentSelection, variantType, candidate) => {
|
|
20
|
+
if (variantAttributes.length === 0) return false;
|
|
21
|
+
const newSelection = {
|
|
22
|
+
...currentSelection,
|
|
23
|
+
[variantType]: candidate
|
|
24
|
+
};
|
|
25
|
+
const matched = variantAttributes.find((attributes) => {
|
|
26
|
+
for (const key of attributeKeys) {
|
|
27
|
+
const selectedVal = newSelection?.[key]?.name?.toLowerCase();
|
|
28
|
+
const attrVal = attributes?.[key]?.name?.toLowerCase();
|
|
29
|
+
if (selectedVal !== attrVal) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
});
|
|
35
|
+
return !!matched;
|
|
36
|
+
};
|
|
37
|
+
var isColorVariantType = (variantType) => {
|
|
38
|
+
const type = variantType.toLowerCase();
|
|
39
|
+
return type === "color" || type === "colors";
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export { findMatchingVariant, findSimilarVariant, isColorVariantType, isVariantCombinationAvailable };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// src/utils/date.ts
|
|
2
|
+
function timeFromNow(date) {
|
|
3
|
+
const now = /* @__PURE__ */ new Date();
|
|
4
|
+
const target = new Date(date);
|
|
5
|
+
const diffMs = target.getTime() - now.getTime();
|
|
6
|
+
const absDiffMs = Math.abs(diffMs);
|
|
7
|
+
const isFuture = diffMs > 0;
|
|
8
|
+
const seconds = Math.floor(absDiffMs / 1e3);
|
|
9
|
+
const minutes = Math.floor(seconds / 60);
|
|
10
|
+
const hours = Math.floor(minutes / 60);
|
|
11
|
+
const days = Math.floor(hours / 24);
|
|
12
|
+
const months = Math.floor(days / 30);
|
|
13
|
+
const years = Math.floor(days / 365);
|
|
14
|
+
let value;
|
|
15
|
+
let unit;
|
|
16
|
+
if (years > 0) {
|
|
17
|
+
value = years;
|
|
18
|
+
unit = years === 1 ? "year" : "years";
|
|
19
|
+
} else if (months > 0) {
|
|
20
|
+
value = months;
|
|
21
|
+
unit = months === 1 ? "month" : "months";
|
|
22
|
+
} else if (days > 0) {
|
|
23
|
+
value = days;
|
|
24
|
+
unit = days === 1 ? "day" : "days";
|
|
25
|
+
} else if (hours > 0) {
|
|
26
|
+
value = hours;
|
|
27
|
+
unit = hours === 1 ? "hour" : "hours";
|
|
28
|
+
} else if (minutes > 0) {
|
|
29
|
+
value = minutes;
|
|
30
|
+
unit = minutes === 1 ? "minute" : "minutes";
|
|
31
|
+
} else {
|
|
32
|
+
return isFuture ? "in a few seconds" : "a few seconds ago";
|
|
33
|
+
}
|
|
34
|
+
return isFuture ? `in ${value} ${unit}` : `${value} ${unit} ago`;
|
|
35
|
+
}
|
|
36
|
+
function isExpired(date) {
|
|
37
|
+
return /* @__PURE__ */ new Date() > new Date(date);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { isExpired, timeFromNow };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkZO2HREQL_cjs = require('./chunk-ZO2HREQL.cjs');
|
|
4
4
|
|
|
5
5
|
// src/api/user.ts
|
|
6
6
|
async function getUserDetails(url) {
|
|
7
|
-
const response = await
|
|
7
|
+
const response = await chunkZO2HREQL_cjs.http_service_default.get(url);
|
|
8
8
|
return response.data;
|
|
9
9
|
}
|
|
10
10
|
async function updateUserDetails(userDetails) {
|
|
11
|
-
return
|
|
11
|
+
return chunkZO2HREQL_cjs.http_service_default.patch("/users/store/profile/", { ...userDetails });
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
exports.getUserDetails = getUserDetails;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkG3R7ZVAG_cjs = require('./chunk-G3R7ZVAG.cjs');
|
|
4
4
|
var chunk4CVKE6CC_cjs = require('./chunk-4CVKE6CC.cjs');
|
|
5
|
-
var
|
|
5
|
+
var chunk47XTPPII_cjs = require('./chunk-47XTPPII.cjs');
|
|
6
6
|
var react = require('react');
|
|
7
7
|
var formik = require('formik');
|
|
8
8
|
var libphonenumberJs = require('libphonenumber-js');
|
|
9
9
|
|
|
10
10
|
var defaultInitialValues = {
|
|
11
|
-
...
|
|
11
|
+
...chunk47XTPPII_cjs.addressFormInitialValues,
|
|
12
12
|
is_default: false,
|
|
13
13
|
country_obj: "IN"
|
|
14
14
|
};
|
|
@@ -17,7 +17,7 @@ function useAddressForm(options = {}) {
|
|
|
17
17
|
address,
|
|
18
18
|
onSuccess,
|
|
19
19
|
onError,
|
|
20
|
-
locationCacheKey =
|
|
20
|
+
locationCacheKey = chunk47XTPPII_cjs.IP_API_CACHE_KEY,
|
|
21
21
|
defaultCountryId = 105
|
|
22
22
|
} = options;
|
|
23
23
|
const isEditing = !!address;
|
|
@@ -28,19 +28,19 @@ function useAddressForm(options = {}) {
|
|
|
28
28
|
const [isSubmitting, setIsSubmitting] = react.useState(false);
|
|
29
29
|
const formik$1 = formik.useFormik({
|
|
30
30
|
initialValues: defaultInitialValues,
|
|
31
|
-
validationSchema:
|
|
31
|
+
validationSchema: chunk47XTPPII_cjs.addressValidationSchema,
|
|
32
32
|
onSubmit: async (values) => {
|
|
33
33
|
try {
|
|
34
34
|
setIsSubmitting(true);
|
|
35
|
-
const payload =
|
|
35
|
+
const payload = chunk47XTPPII_cjs.buildSubmitPayload(values, selectedCountry, states);
|
|
36
36
|
let response;
|
|
37
37
|
if (isEditing) {
|
|
38
|
-
response = await
|
|
38
|
+
response = await chunkG3R7ZVAG_cjs.updateAddress({
|
|
39
39
|
...payload,
|
|
40
40
|
address_id: address.id
|
|
41
41
|
});
|
|
42
42
|
} else {
|
|
43
|
-
response = await
|
|
43
|
+
response = await chunkG3R7ZVAG_cjs.addAddress(payload);
|
|
44
44
|
}
|
|
45
45
|
if (response) {
|
|
46
46
|
formik$1.resetForm();
|
|
@@ -57,7 +57,7 @@ function useAddressForm(options = {}) {
|
|
|
57
57
|
react.useEffect(() => {
|
|
58
58
|
const fetchCountries = async () => {
|
|
59
59
|
try {
|
|
60
|
-
const response = await
|
|
60
|
+
const response = await chunkG3R7ZVAG_cjs.getCountries();
|
|
61
61
|
const sortedCountries = response?.data?.sort((a, b) => {
|
|
62
62
|
if (a.id === defaultCountryId) return -1;
|
|
63
63
|
if (b.id === defaultCountryId) return 1;
|
|
@@ -88,7 +88,7 @@ function useAddressForm(options = {}) {
|
|
|
88
88
|
if (!selectedCountry) return;
|
|
89
89
|
const fetchStates = async () => {
|
|
90
90
|
try {
|
|
91
|
-
const response = await
|
|
91
|
+
const response = await chunkG3R7ZVAG_cjs.getSubdivisions(selectedCountry.id);
|
|
92
92
|
setStates(response.data.results);
|
|
93
93
|
} catch (error) {
|
|
94
94
|
console.error(error);
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var typescriptCookie = require('typescript-cookie');
|
|
4
|
-
|
|
5
3
|
// src/utils/constants.ts
|
|
6
4
|
var SLICE_STATUS = /* @__PURE__ */ ((SLICE_STATUS2) => {
|
|
7
5
|
SLICE_STATUS2["IDLE"] = "idle";
|
|
@@ -39,48 +37,6 @@ var DEFAULT_TOAST_CONFIG = {
|
|
|
39
37
|
};
|
|
40
38
|
var ALLOWED_COUNTRIES = ["AE", "IN", "US"];
|
|
41
39
|
var ADDRESS_FORM_SESSION_KEY = "address_form_values";
|
|
42
|
-
var _onTokenChange = null;
|
|
43
|
-
function setAuthTokenChangeCallback(callback) {
|
|
44
|
-
_onTokenChange = callback;
|
|
45
|
-
}
|
|
46
|
-
var Auth = {
|
|
47
|
-
isAuthenticated: false,
|
|
48
|
-
getUserDetails() {
|
|
49
|
-
return typeof window === "undefined" ? false : typescriptCookie.getCookie(USER_CRED_TOKEN);
|
|
50
|
-
},
|
|
51
|
-
setUserDetails(data) {
|
|
52
|
-
typescriptCookie.setCookie(USER_CREDENTIALS, JSON.stringify(data), {
|
|
53
|
-
expires: 60,
|
|
54
|
-
path: "/"
|
|
55
|
-
});
|
|
56
|
-
},
|
|
57
|
-
setAccessToken(token) {
|
|
58
|
-
typescriptCookie.setCookie(USER_CRED_TOKEN, token, {
|
|
59
|
-
expires: 60,
|
|
60
|
-
path: "/"
|
|
61
|
-
});
|
|
62
|
-
_onTokenChange?.(token);
|
|
63
|
-
},
|
|
64
|
-
getAccessToken() {
|
|
65
|
-
return typescriptCookie.getCookie(USER_CRED_TOKEN);
|
|
66
|
-
},
|
|
67
|
-
setRefreshToken(token) {
|
|
68
|
-
typescriptCookie.setCookie(USER_CRED_REFRESH_TOKEN, token, {
|
|
69
|
-
expires: 60,
|
|
70
|
-
path: "/"
|
|
71
|
-
});
|
|
72
|
-
},
|
|
73
|
-
getRefreshToken() {
|
|
74
|
-
return typescriptCookie.getCookie(USER_CRED_REFRESH_TOKEN);
|
|
75
|
-
},
|
|
76
|
-
removeTokens() {
|
|
77
|
-
typescriptCookie.removeCookie(USER_CRED_TOKEN);
|
|
78
|
-
typescriptCookie.removeCookie(USER_CRED_REFRESH_TOKEN);
|
|
79
|
-
typescriptCookie.removeCookie(USER_CREDENTIALS);
|
|
80
|
-
_onTokenChange?.(void 0);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
var auth_default = Auth;
|
|
84
40
|
|
|
85
41
|
exports.ADDRESS_FORM_SESSION_KEY = ADDRESS_FORM_SESSION_KEY;
|
|
86
42
|
exports.ALLOWED_COUNTRIES = ALLOWED_COUNTRIES;
|
|
@@ -91,6 +47,4 @@ exports.USER_CART = USER_CART;
|
|
|
91
47
|
exports.USER_CREDENTIALS = USER_CREDENTIALS;
|
|
92
48
|
exports.USER_CRED_REFRESH_TOKEN = USER_CRED_REFRESH_TOKEN;
|
|
93
49
|
exports.USER_CRED_TOKEN = USER_CRED_TOKEN;
|
|
94
|
-
exports.auth_default = auth_default;
|
|
95
50
|
exports.pathNameMap = pathNameMap;
|
|
96
|
-
exports.setAuthTokenChangeCallback = setAuthTokenChangeCallback;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk26A3EBZI_cjs = require('./chunk-26A3EBZI.cjs');
|
|
4
|
+
var chunkSMHJRNCR_cjs = require('./chunk-SMHJRNCR.cjs');
|
|
5
|
+
var chunkBBRXE57K_cjs = require('./chunk-BBRXE57K.cjs');
|
|
6
|
+
var chunkNE3ZHELZ_cjs = require('./chunk-NE3ZHELZ.cjs');
|
|
7
|
+
var zustand = require('zustand');
|
|
8
|
+
var typescriptCookie = require('typescript-cookie');
|
|
9
|
+
|
|
10
|
+
var initialState = {
|
|
11
|
+
cart: null,
|
|
12
|
+
status: "idle" /* IDLE */
|
|
13
|
+
};
|
|
14
|
+
var useCartStore = zustand.create((set) => ({
|
|
15
|
+
...initialState,
|
|
16
|
+
setCart: (cart) => set({ cart, status: "idle" /* IDLE */ }),
|
|
17
|
+
resetCart: () => set(initialState),
|
|
18
|
+
resetCartCount: () => set((state) => {
|
|
19
|
+
if (!state.cart) return state;
|
|
20
|
+
return { cart: { ...state.cart, total_quantity: 0 } };
|
|
21
|
+
}),
|
|
22
|
+
syncCart: async (addressId) => {
|
|
23
|
+
set({ status: "loading" /* LOADING */ });
|
|
24
|
+
try {
|
|
25
|
+
const response = await chunk26A3EBZI_cjs.getCart("/customer/cart/", addressId);
|
|
26
|
+
if (response) {
|
|
27
|
+
set({ cart: response, status: "idle" /* IDLE */ });
|
|
28
|
+
}
|
|
29
|
+
} catch {
|
|
30
|
+
set({ status: "idle" /* IDLE */ });
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
fetchCart: async (addressId) => {
|
|
34
|
+
set({ status: "loading" /* LOADING */ });
|
|
35
|
+
try {
|
|
36
|
+
const response = await chunk26A3EBZI_cjs.getCart("/customer/cart/", addressId);
|
|
37
|
+
if (response) {
|
|
38
|
+
set({ cart: response, status: "idle" /* IDLE */ });
|
|
39
|
+
}
|
|
40
|
+
} catch {
|
|
41
|
+
set({ status: "idle" /* IDLE */ });
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
addToCart: async (items, customizationInputs, addressId) => {
|
|
45
|
+
set({ status: "loading" /* LOADING */ });
|
|
46
|
+
try {
|
|
47
|
+
await chunk26A3EBZI_cjs.addToCart(items, customizationInputs);
|
|
48
|
+
await useCartStore.getState().syncCart(addressId);
|
|
49
|
+
} catch {
|
|
50
|
+
} finally {
|
|
51
|
+
set({ status: "idle" /* IDLE */ });
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
removeFromCart: async (items, addressId) => {
|
|
55
|
+
set({ status: "loading" /* LOADING */ });
|
|
56
|
+
try {
|
|
57
|
+
await chunk26A3EBZI_cjs.removeFromCart(items);
|
|
58
|
+
await useCartStore.getState().syncCart(addressId);
|
|
59
|
+
} catch {
|
|
60
|
+
} finally {
|
|
61
|
+
set({ status: "idle" /* IDLE */ });
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
updateCart: async (items, addressId) => {
|
|
65
|
+
set({ status: "loading" /* LOADING */ });
|
|
66
|
+
try {
|
|
67
|
+
await chunk26A3EBZI_cjs.updateCart(items);
|
|
68
|
+
await useCartStore.getState().syncCart(addressId);
|
|
69
|
+
} catch {
|
|
70
|
+
} finally {
|
|
71
|
+
set({ status: "idle" /* IDLE */ });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}));
|
|
75
|
+
var getInitialState = () => ({
|
|
76
|
+
user: null,
|
|
77
|
+
status: "idle" /* IDLE */,
|
|
78
|
+
isAuthenticated: typeof window !== "undefined" ? !!typescriptCookie.getCookie(chunkNE3ZHELZ_cjs.USER_CRED_TOKEN) : false
|
|
79
|
+
});
|
|
80
|
+
var useAuthStore = zustand.create((set, get) => ({
|
|
81
|
+
...getInitialState(),
|
|
82
|
+
fetchUser: () => set({ status: "loading" /* LOADING */ }),
|
|
83
|
+
fetchUserSuccess: (user) => set({ user, status: "success" /* SUCCESS */, isAuthenticated: true }),
|
|
84
|
+
fetchUserFailure: (error) => set({ status: "failure" /* FAILURE */, isAuthenticated: false, error }),
|
|
85
|
+
setAuthenticated: () => set({ isAuthenticated: true }),
|
|
86
|
+
resetUser: () => set(getInitialState()),
|
|
87
|
+
logoutUser: () => {
|
|
88
|
+
try {
|
|
89
|
+
chunkBBRXE57K_cjs.auth_default.removeTokens();
|
|
90
|
+
set(getInitialState());
|
|
91
|
+
} catch {
|
|
92
|
+
set({ status: "failure" /* FAILURE */, isAuthenticated: false, error: "Something went wrong" });
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
loadCurrentUser: (user, referer, redirect = true, preventRefreshAfterLogin) => {
|
|
96
|
+
set({ status: "loading" /* LOADING */ });
|
|
97
|
+
setTimeout(async () => {
|
|
98
|
+
try {
|
|
99
|
+
set({ user, status: "success" /* SUCCESS */, isAuthenticated: true });
|
|
100
|
+
const localCartItems = chunkSMHJRNCR_cjs.cart_default.get();
|
|
101
|
+
if (localCartItems) {
|
|
102
|
+
await useCartStore.getState().addToCart(
|
|
103
|
+
Object.entries(localCartItems.products_quantity).map(
|
|
104
|
+
([key, value]) => ({
|
|
105
|
+
variant_id: parseInt(key),
|
|
106
|
+
quantity: value
|
|
107
|
+
})
|
|
108
|
+
)
|
|
109
|
+
);
|
|
110
|
+
chunkSMHJRNCR_cjs.cart_default.clear();
|
|
111
|
+
await useCartStore.getState().fetchCart();
|
|
112
|
+
setTimeout(() => {
|
|
113
|
+
if (!preventRefreshAfterLogin) {
|
|
114
|
+
if (redirect) {
|
|
115
|
+
window.location.href = referer;
|
|
116
|
+
} else {
|
|
117
|
+
window.location.reload();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}, 500);
|
|
121
|
+
} else {
|
|
122
|
+
if (!preventRefreshAfterLogin) {
|
|
123
|
+
if (redirect) {
|
|
124
|
+
window.location.href = referer;
|
|
125
|
+
} else {
|
|
126
|
+
window.location.reload();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
} catch {
|
|
131
|
+
localStorage.removeItem("userExists");
|
|
132
|
+
set({
|
|
133
|
+
status: "failure" /* FAILURE */,
|
|
134
|
+
isAuthenticated: false,
|
|
135
|
+
error: "Something went wrong while fetching user"
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}, 1e3);
|
|
139
|
+
}
|
|
140
|
+
}));
|
|
141
|
+
var loginUser = async (user) => {
|
|
142
|
+
const { access, refresh, ...userData } = user;
|
|
143
|
+
localStorage.setItem(chunkNE3ZHELZ_cjs.USER_CREDENTIALS, JSON.stringify(userData));
|
|
144
|
+
chunkBBRXE57K_cjs.auth_default.setAccessToken(access);
|
|
145
|
+
chunkBBRXE57K_cjs.auth_default.setRefreshToken(refresh);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
exports.loginUser = loginUser;
|
|
149
|
+
exports.useAuthStore = useAuthStore;
|
|
150
|
+
exports.useCartStore = useCartStore;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkNE3ZHELZ_cjs = require('./chunk-NE3ZHELZ.cjs');
|
|
4
4
|
|
|
5
5
|
// src/utils/cart.ts
|
|
6
6
|
var LocalCart = {
|
|
7
7
|
get() {
|
|
8
|
-
const storeData = localStorage.getItem(
|
|
8
|
+
const storeData = localStorage.getItem(chunkNE3ZHELZ_cjs.USER_CART);
|
|
9
9
|
return storeData ? JSON.parse(storeData) : null;
|
|
10
10
|
},
|
|
11
11
|
set(cart) {
|
|
12
|
-
localStorage.setItem(
|
|
12
|
+
localStorage.setItem(chunkNE3ZHELZ_cjs.USER_CART, JSON.stringify(cart));
|
|
13
13
|
},
|
|
14
14
|
add(product) {
|
|
15
15
|
const cart = this.get();
|
|
@@ -92,7 +92,7 @@ var LocalCart = {
|
|
|
92
92
|
this.set(cart);
|
|
93
93
|
},
|
|
94
94
|
clear() {
|
|
95
|
-
localStorage.removeItem(
|
|
95
|
+
localStorage.removeItem(chunkNE3ZHELZ_cjs.USER_CART);
|
|
96
96
|
}
|
|
97
97
|
};
|
|
98
98
|
var cart_default = LocalCart;
|