@storepecker/storefront-core 1.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/address-DQEZzyUG.d.cts +19 -0
- package/dist/address-DQEZzyUG.d.ts +19 -0
- package/dist/api/index.cjs +367 -0
- package/dist/api/index.d.cts +127 -0
- package/dist/api/index.d.ts +127 -0
- package/dist/api/index.js +131 -0
- package/dist/booking-ClX-dhX7.d.ts +131 -0
- package/dist/booking-Drl7-IL7.d.cts +131 -0
- package/dist/cart-DVrn8hD0.d.cts +367 -0
- package/dist/cart-DVrn8hD0.d.ts +367 -0
- package/dist/checkout/index.cjs +228 -0
- package/dist/checkout/index.d.cts +251 -0
- package/dist/checkout/index.d.ts +251 -0
- package/dist/checkout/index.js +122 -0
- package/dist/chunk-4CVKE6CC.cjs +312 -0
- package/dist/chunk-4MJMNIAB.js +123 -0
- package/dist/chunk-57ZBPAXU.js +114 -0
- package/dist/chunk-7MQOVWLW.js +40 -0
- package/dist/chunk-7UH6REGV.js +12 -0
- package/dist/chunk-A6IO3HIN.cjs +151 -0
- package/dist/chunk-CFF632IQ.cjs +100 -0
- package/dist/chunk-CSISWBZZ.js +121 -0
- package/dist/chunk-E7WPE3PV.js +98 -0
- package/dist/chunk-FLBJKM6G.js +83 -0
- package/dist/chunk-GB3HW6DM.js +61 -0
- package/dist/chunk-GH75WUO2.cjs +42 -0
- package/dist/chunk-GQTO5ZE2.cjs +96 -0
- package/dist/chunk-JHGXIIBZ.cjs +37 -0
- package/dist/chunk-JQMLHRWL.js +21 -0
- package/dist/chunk-K44JZ5NL.cjs +212 -0
- package/dist/chunk-K5B62JZO.cjs +154 -0
- package/dist/chunk-KWKHHRRJ.cjs +15 -0
- package/dist/chunk-LBGIUNM6.js +30 -0
- package/dist/chunk-LC5ZAUKL.cjs +220 -0
- package/dist/chunk-N3CTXRFT.cjs +30 -0
- package/dist/chunk-QCQCFYYR.js +206 -0
- package/dist/chunk-QM73PI5L.cjs +218 -0
- package/dist/chunk-RCXQJ6XC.cjs +131 -0
- package/dist/chunk-UM24VDYB.js +216 -0
- package/dist/chunk-UXLUE3HW.cjs +69 -0
- package/dist/chunk-WFDKKOO7.js +210 -0
- package/dist/chunk-YUPBTD4M.js +289 -0
- package/dist/components/index.cjs +576 -0
- package/dist/components/index.css +329 -0
- package/dist/components/index.d.cts +58 -0
- package/dist/components/index.d.ts +58 -0
- package/dist/components/index.js +569 -0
- package/dist/coupons-C7iJ-1cy.d.cts +37 -0
- package/dist/coupons-CnfTKL1i.d.ts +37 -0
- package/dist/hooks/index.cjs +381 -0
- package/dist/hooks/index.d.cts +123 -0
- package/dist/hooks/index.d.ts +123 -0
- package/dist/hooks/index.js +364 -0
- package/dist/index-DTyIuLuI.d.cts +18 -0
- package/dist/index-DTyIuLuI.d.ts +18 -0
- package/dist/index.cjs +14 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/models/index.cjs +2 -0
- package/dist/models/index.d.cts +53 -0
- package/dist/models/index.d.ts +53 -0
- package/dist/models/index.js +1 -0
- package/dist/orders-CkUzv5Xh.d.ts +159 -0
- package/dist/orders-D0oC9ugD.d.cts +159 -0
- package/dist/phonepe-D7vn-9SR.d.cts +27 -0
- package/dist/phonepe-D7vn-9SR.d.ts +27 -0
- package/dist/store/index.cjs +149 -0
- package/dist/store/index.d.cts +46 -0
- package/dist/store/index.d.ts +46 -0
- package/dist/store/index.js +141 -0
- package/dist/useAddressForm-C-Uzug4d.d.ts +42 -0
- package/dist/useAddressForm-DgkCP1nG.d.cts +42 -0
- package/dist/utils/index.cjs +535 -0
- package/dist/utils/index.d.cts +507 -0
- package/dist/utils/index.d.ts +507 -0
- package/dist/utils/index.js +342 -0
- package/dist/wishlist-BzhnCAQD.d.ts +41 -0
- package/dist/wishlist-CBCZD66Y.d.cts +41 -0
- package/package.json +134 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkUXLUE3HW_cjs = require('./chunk-UXLUE3HW.cjs');
|
|
4
|
+
|
|
5
|
+
// src/api/coupon.ts
|
|
6
|
+
async function getCoupons() {
|
|
7
|
+
return chunkUXLUE3HW_cjs.http_service_default.get("/coupon/available/");
|
|
8
|
+
}
|
|
9
|
+
async function applyCoupon(couponCode) {
|
|
10
|
+
return chunkUXLUE3HW_cjs.http_service_default.post("/coupon/use/", { coupon_code: couponCode });
|
|
11
|
+
}
|
|
12
|
+
async function getAppliedCoupon() {
|
|
13
|
+
return chunkUXLUE3HW_cjs.http_service_default.get("/coupon/use/");
|
|
14
|
+
}
|
|
15
|
+
async function removeCoupon(couponCode) {
|
|
16
|
+
return chunkUXLUE3HW_cjs.http_service_default.delete("/coupon/use/");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/api/orders.ts
|
|
20
|
+
async function getOrders(url) {
|
|
21
|
+
const response = await chunkUXLUE3HW_cjs.http_service_default.get(url);
|
|
22
|
+
return response.data;
|
|
23
|
+
}
|
|
24
|
+
async function getOrderDetails(orderId) {
|
|
25
|
+
return chunkUXLUE3HW_cjs.http_service_default.get("/customer/order/", {
|
|
26
|
+
params: { order_id: orderId }
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async function getOrderDetailsByNumber(orderNumber) {
|
|
30
|
+
return chunkUXLUE3HW_cjs.http_service_default.get("/customer/order/", {
|
|
31
|
+
params: { order_number: orderNumber }
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async function getPublicOrderDetailsByNumber(orderNumber) {
|
|
35
|
+
return chunkUXLUE3HW_cjs.http_service_default.get("/customer/public_order/", {
|
|
36
|
+
params: { order_number: orderNumber }
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
async function placeOrder(address_id, redirect, isCod, stripeRedirect, tabbyRedirect) {
|
|
40
|
+
return chunkUXLUE3HW_cjs.http_service_default.post("/customer/order/", {
|
|
41
|
+
address_id,
|
|
42
|
+
phonepe_redirect_url: redirect,
|
|
43
|
+
is_cod: isCod,
|
|
44
|
+
stripe_redirect_url: stripeRedirect,
|
|
45
|
+
tabby_redirect_url: tabbyRedirect
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async function publicPlaceOrder(address, redirect, orderDetails, stripeRedirect, tabbyRedirect) {
|
|
49
|
+
return chunkUXLUE3HW_cjs.http_service_default.post("/customer/public_order/", {
|
|
50
|
+
address,
|
|
51
|
+
phonepe_redirect_url: redirect,
|
|
52
|
+
stripe_redirect_url: stripeRedirect,
|
|
53
|
+
tabby_redirect_url: tabbyRedirect,
|
|
54
|
+
...orderDetails
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
async function updateOrder(orderDetails) {
|
|
58
|
+
return chunkUXLUE3HW_cjs.http_service_default.patch("/customer/order/", orderDetails);
|
|
59
|
+
}
|
|
60
|
+
async function razorpayPublicOrderSuccess(orderDetails) {
|
|
61
|
+
return chunkUXLUE3HW_cjs.http_service_default.post("/payment/public-razorpay-order-success/", orderDetails);
|
|
62
|
+
}
|
|
63
|
+
async function razorpayOrderSuccess(orderDetails) {
|
|
64
|
+
return chunkUXLUE3HW_cjs.http_service_default.post("/payment/razorpay-order-success/", orderDetails);
|
|
65
|
+
}
|
|
66
|
+
async function razorpayOrderFail(orderDetails) {
|
|
67
|
+
return chunkUXLUE3HW_cjs.http_service_default.post("/payment/razorpay-order-fail/", orderDetails);
|
|
68
|
+
}
|
|
69
|
+
async function phonepePublicOrderSuccess(orderDetails) {
|
|
70
|
+
return chunkUXLUE3HW_cjs.http_service_default.post("/payment/public-phonepe-order-success/", orderDetails);
|
|
71
|
+
}
|
|
72
|
+
async function phonepeOrderSuccess(orderDetails) {
|
|
73
|
+
return chunkUXLUE3HW_cjs.http_service_default.post("/payment/phonepe-order-success/", orderDetails);
|
|
74
|
+
}
|
|
75
|
+
async function checkPhonepePaymentStatus(transactionId) {
|
|
76
|
+
return chunkUXLUE3HW_cjs.http_service_default.get("/payment/phonepe-order-success/", {
|
|
77
|
+
params: { phonepe_transaction_id: transactionId }
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
async function getStripePaymentStatus(stripeCheckoutSessionId, order_number, payment_link_id) {
|
|
81
|
+
return chunkUXLUE3HW_cjs.http_service_default.get("/payment/stripe-payment-status/", {
|
|
82
|
+
params: {
|
|
83
|
+
checkout_session_id: stripeCheckoutSessionId,
|
|
84
|
+
order_number,
|
|
85
|
+
payment_link_id
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
async function getStripePaymentStatusPublic(stripeCheckoutSessionId, order_number, payment_link_id) {
|
|
90
|
+
return chunkUXLUE3HW_cjs.http_service_default.get("/payment/public-stripe-payment-status/", {
|
|
91
|
+
params: {
|
|
92
|
+
checkout_session_id: stripeCheckoutSessionId,
|
|
93
|
+
order_number,
|
|
94
|
+
payment_link_id
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
async function stripePublicOrderSuccess(orderDetails) {
|
|
99
|
+
return chunkUXLUE3HW_cjs.http_service_default.post("/payment/public-stripe-order-success/", orderDetails);
|
|
100
|
+
}
|
|
101
|
+
async function stripeOrderSuccess(orderDetails) {
|
|
102
|
+
return chunkUXLUE3HW_cjs.http_service_default.post("/payment/stripe-order-success/", orderDetails);
|
|
103
|
+
}
|
|
104
|
+
async function stripeOrderFail(orderDetails) {
|
|
105
|
+
return chunkUXLUE3HW_cjs.http_service_default.post("/payment/stripe-order-fail/", orderDetails);
|
|
106
|
+
}
|
|
107
|
+
async function makeCODOrder(orderId) {
|
|
108
|
+
return chunkUXLUE3HW_cjs.http_service_default.post("/customer/order_cod/", { order_id: orderId });
|
|
109
|
+
}
|
|
110
|
+
async function publicMakeCODOrder(orderNumber) {
|
|
111
|
+
return chunkUXLUE3HW_cjs.http_service_default.post("/customer/public_order_cod/", { order_number: orderNumber });
|
|
112
|
+
}
|
|
113
|
+
async function updateOrderCustomization(customizationInput) {
|
|
114
|
+
return chunkUXLUE3HW_cjs.http_service_default.post("/customer/product_personalize/", customizationInput);
|
|
115
|
+
}
|
|
116
|
+
async function uploadCustomizationImage(uploadForm) {
|
|
117
|
+
return chunkUXLUE3HW_cjs.http_service_default.post("/utils/upload_image", uploadForm);
|
|
118
|
+
}
|
|
119
|
+
async function verifyTabbyPayment(orderNumber) {
|
|
120
|
+
return chunkUXLUE3HW_cjs.http_service_default.get("/payment/tabby-payment-status/", {
|
|
121
|
+
params: { order_number: orderNumber }
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
exports.applyCoupon = applyCoupon;
|
|
126
|
+
exports.checkPhonepePaymentStatus = checkPhonepePaymentStatus;
|
|
127
|
+
exports.getAppliedCoupon = getAppliedCoupon;
|
|
128
|
+
exports.getCoupons = getCoupons;
|
|
129
|
+
exports.getOrderDetails = getOrderDetails;
|
|
130
|
+
exports.getOrderDetailsByNumber = getOrderDetailsByNumber;
|
|
131
|
+
exports.getOrders = getOrders;
|
|
132
|
+
exports.getPublicOrderDetailsByNumber = getPublicOrderDetailsByNumber;
|
|
133
|
+
exports.getStripePaymentStatus = getStripePaymentStatus;
|
|
134
|
+
exports.getStripePaymentStatusPublic = getStripePaymentStatusPublic;
|
|
135
|
+
exports.makeCODOrder = makeCODOrder;
|
|
136
|
+
exports.phonepeOrderSuccess = phonepeOrderSuccess;
|
|
137
|
+
exports.phonepePublicOrderSuccess = phonepePublicOrderSuccess;
|
|
138
|
+
exports.placeOrder = placeOrder;
|
|
139
|
+
exports.publicMakeCODOrder = publicMakeCODOrder;
|
|
140
|
+
exports.publicPlaceOrder = publicPlaceOrder;
|
|
141
|
+
exports.razorpayOrderFail = razorpayOrderFail;
|
|
142
|
+
exports.razorpayOrderSuccess = razorpayOrderSuccess;
|
|
143
|
+
exports.razorpayPublicOrderSuccess = razorpayPublicOrderSuccess;
|
|
144
|
+
exports.removeCoupon = removeCoupon;
|
|
145
|
+
exports.stripeOrderFail = stripeOrderFail;
|
|
146
|
+
exports.stripeOrderSuccess = stripeOrderSuccess;
|
|
147
|
+
exports.stripePublicOrderSuccess = stripePublicOrderSuccess;
|
|
148
|
+
exports.updateOrder = updateOrder;
|
|
149
|
+
exports.updateOrderCustomization = updateOrderCustomization;
|
|
150
|
+
exports.uploadCustomizationImage = uploadCustomizationImage;
|
|
151
|
+
exports.verifyTabbyPayment = verifyTabbyPayment;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkGQTO5ZE2_cjs = require('./chunk-GQTO5ZE2.cjs');
|
|
4
|
+
|
|
5
|
+
// src/utils/cart.ts
|
|
6
|
+
var LocalCart = {
|
|
7
|
+
get() {
|
|
8
|
+
const storeData = localStorage.getItem(chunkGQTO5ZE2_cjs.USER_CART);
|
|
9
|
+
return storeData ? JSON.parse(storeData) : null;
|
|
10
|
+
},
|
|
11
|
+
set(cart) {
|
|
12
|
+
localStorage.setItem(chunkGQTO5ZE2_cjs.USER_CART, JSON.stringify(cart));
|
|
13
|
+
},
|
|
14
|
+
add(product) {
|
|
15
|
+
const cart = this.get();
|
|
16
|
+
if (!cart) {
|
|
17
|
+
this.set({
|
|
18
|
+
product_variants: [product],
|
|
19
|
+
products_quantity: { [product.id]: 1 },
|
|
20
|
+
total_quantity: 1,
|
|
21
|
+
cart_count: 1,
|
|
22
|
+
total_amount: product.selling_price,
|
|
23
|
+
variant_discounts: {}
|
|
24
|
+
});
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const newCart = cart.product_variants || [];
|
|
28
|
+
const existingProduct = newCart.find((prod) => prod.id === product.id);
|
|
29
|
+
if (existingProduct) {
|
|
30
|
+
cart.products_quantity = {
|
|
31
|
+
...cart.products_quantity,
|
|
32
|
+
[product.id]: (Number(cart.products_quantity[product.id]) || 0) + 1
|
|
33
|
+
};
|
|
34
|
+
cart.total_quantity = Number(cart.total_quantity) + 1;
|
|
35
|
+
cart.cart_count = Number(cart.cart_count) + 1;
|
|
36
|
+
cart.total_amount = Number(cart.total_amount) + Number(product.selling_price);
|
|
37
|
+
this.set(cart);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
newCart.push(product);
|
|
41
|
+
cart.products_quantity = {
|
|
42
|
+
...cart.products_quantity,
|
|
43
|
+
[product.id]: (cart.products_quantity[product.id] || 0) + 1
|
|
44
|
+
};
|
|
45
|
+
cart.product_variants = newCart;
|
|
46
|
+
cart.total_quantity = Number(cart.total_quantity) + 1;
|
|
47
|
+
cart.cart_count = Number(cart.cart_count) + 1;
|
|
48
|
+
cart.total_amount = Number(cart.total_amount) + Number(product.selling_price);
|
|
49
|
+
this.set(cart);
|
|
50
|
+
},
|
|
51
|
+
remove(product) {
|
|
52
|
+
const cart = this.get();
|
|
53
|
+
if (!cart) return;
|
|
54
|
+
const newCart = cart.product_variants?.filter(
|
|
55
|
+
(prod) => prod.id !== product.id
|
|
56
|
+
);
|
|
57
|
+
const quantity = cart.products_quantity[product.id] || 0;
|
|
58
|
+
cart.cart_count = (cart.cart_count || 0) - quantity;
|
|
59
|
+
cart.products_quantity = {
|
|
60
|
+
...cart.products_quantity
|
|
61
|
+
};
|
|
62
|
+
if (cart.products_quantity[product.id]) {
|
|
63
|
+
delete cart.products_quantity[product.id];
|
|
64
|
+
}
|
|
65
|
+
cart.product_variants = newCart;
|
|
66
|
+
const currentTotalAmount = Number(cart.total_amount) || 0;
|
|
67
|
+
const itemPrice = Number(product.selling_price) || 0;
|
|
68
|
+
const itemTotalPrice = itemPrice * quantity;
|
|
69
|
+
cart.total_quantity = Math.max(
|
|
70
|
+
0,
|
|
71
|
+
(Number(cart.total_quantity) || 0) - quantity
|
|
72
|
+
);
|
|
73
|
+
cart.total_amount = Math.max(0, currentTotalAmount - itemTotalPrice);
|
|
74
|
+
this.set(cart);
|
|
75
|
+
},
|
|
76
|
+
updateQuantity(product, quantity) {
|
|
77
|
+
const cart = this.get();
|
|
78
|
+
if (!cart) return;
|
|
79
|
+
cart.products_quantity = {
|
|
80
|
+
...cart.products_quantity,
|
|
81
|
+
[product.id]: quantity
|
|
82
|
+
};
|
|
83
|
+
cart.total_quantity = Object.values(cart.products_quantity).reduce(
|
|
84
|
+
(acc, curr) => acc + curr,
|
|
85
|
+
0
|
|
86
|
+
);
|
|
87
|
+
cart.total_amount = cart.product_variants.reduce(
|
|
88
|
+
(acc, curr) => acc + Number(curr.selling_price) * Number(cart.products_quantity[curr.id]),
|
|
89
|
+
0
|
|
90
|
+
);
|
|
91
|
+
Number(cart.total_amount) + Number(product.selling_price) * quantity;
|
|
92
|
+
this.set(cart);
|
|
93
|
+
},
|
|
94
|
+
clear() {
|
|
95
|
+
localStorage.removeItem(chunkGQTO5ZE2_cjs.USER_CART);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
var cart_default = LocalCart;
|
|
99
|
+
|
|
100
|
+
exports.cart_default = cart_default;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { ADDRESS_FORM_SESSION_KEY } from './chunk-FLBJKM6G.js';
|
|
2
|
+
import { parsePhoneNumberFromString, getCountryCallingCode } from 'libphonenumber-js';
|
|
3
|
+
import * as Yup from 'yup';
|
|
4
|
+
|
|
5
|
+
var IP_API_CACHE_KEY = "ip_geolocation_data";
|
|
6
|
+
var addressFormInitialValues = {
|
|
7
|
+
customer_phone: "",
|
|
8
|
+
customer_country_code: "IN",
|
|
9
|
+
customer_name: "",
|
|
10
|
+
pincode: "",
|
|
11
|
+
state_obj: "",
|
|
12
|
+
address: "",
|
|
13
|
+
street_name: "",
|
|
14
|
+
area: "",
|
|
15
|
+
city: "",
|
|
16
|
+
customer_email: ""
|
|
17
|
+
};
|
|
18
|
+
function isValidPhoneNumber(input, countryCode) {
|
|
19
|
+
if (!input) return false;
|
|
20
|
+
const phone = parsePhoneNumberFromString(input, countryCode);
|
|
21
|
+
return phone?.isValid() ?? false;
|
|
22
|
+
}
|
|
23
|
+
var addressValidationSchema = Yup.object({
|
|
24
|
+
customer_phone: Yup.string().required("Phone number required").test("is-valid", "Please enter a valid number", function(value) {
|
|
25
|
+
const { customer_country_code } = this.parent;
|
|
26
|
+
if (!value) return false;
|
|
27
|
+
return isValidPhoneNumber(value, customer_country_code);
|
|
28
|
+
}),
|
|
29
|
+
customer_name: Yup.string().required("Name is required"),
|
|
30
|
+
pincode: Yup.string().when("customer_country_code", {
|
|
31
|
+
is: "AE",
|
|
32
|
+
then: (schema) => schema.optional(),
|
|
33
|
+
otherwise: (schema) => schema.required("Pincode is required")
|
|
34
|
+
}),
|
|
35
|
+
state_obj: Yup.string().required("State is required"),
|
|
36
|
+
address: Yup.string().required("Address is required"),
|
|
37
|
+
street_name: Yup.string().optional(),
|
|
38
|
+
area: Yup.string().optional(),
|
|
39
|
+
city: Yup.string().required("City/District is required"),
|
|
40
|
+
customer_email: Yup.string().email("Please enter a valid email").required("Email is required")
|
|
41
|
+
});
|
|
42
|
+
function encodeAddress(id, city) {
|
|
43
|
+
return `${btoa(id.toString())}-${btoa(city)}`;
|
|
44
|
+
}
|
|
45
|
+
function decodeAddress(encoded) {
|
|
46
|
+
const [encodedId, encodedCity] = encoded.split("-");
|
|
47
|
+
return {
|
|
48
|
+
id: Number(atob(encodedId)),
|
|
49
|
+
city: atob(encodedCity)
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function saveAddressFormToSession(values) {
|
|
53
|
+
try {
|
|
54
|
+
sessionStorage.setItem(ADDRESS_FORM_SESSION_KEY, JSON.stringify(values));
|
|
55
|
+
} catch {
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function loadAddressFormFromSession() {
|
|
59
|
+
try {
|
|
60
|
+
const stored = sessionStorage.getItem(ADDRESS_FORM_SESSION_KEY);
|
|
61
|
+
return stored ? JSON.parse(stored) : null;
|
|
62
|
+
} catch {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function clearAddressFormSession() {
|
|
67
|
+
try {
|
|
68
|
+
sessionStorage.removeItem(ADDRESS_FORM_SESSION_KEY);
|
|
69
|
+
} catch {
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function buildAddressPayload(formValues, selectedCountry, states) {
|
|
73
|
+
const selectedState = states.find((s) => s.name === formValues.state_obj);
|
|
74
|
+
return {
|
|
75
|
+
customer_name: formValues.customer_name,
|
|
76
|
+
customer_phone: formValues.customer_phone,
|
|
77
|
+
customer_country_code: formValues.customer_country_code,
|
|
78
|
+
customer_email: formValues.customer_email,
|
|
79
|
+
address: formValues.address,
|
|
80
|
+
street_name: formValues.street_name,
|
|
81
|
+
area: formValues.area,
|
|
82
|
+
city: formValues.city,
|
|
83
|
+
state: selectedState?.state_code || formValues.state_obj,
|
|
84
|
+
state_obj: formValues.state_obj,
|
|
85
|
+
country: selectedCountry.short_code,
|
|
86
|
+
pincode: formValues.pincode
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function parseEditAddress(fullAddress) {
|
|
90
|
+
if (!fullAddress) return { address: "", street_name: "", area: "" };
|
|
91
|
+
const parts = fullAddress.split(",").map((s) => s.trim());
|
|
92
|
+
return {
|
|
93
|
+
address: parts[0] || "",
|
|
94
|
+
street_name: parts[1] || "",
|
|
95
|
+
area: parts[2] || ""
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function buildSubmitPayload(values, country, states) {
|
|
99
|
+
const formValues = { ...values };
|
|
100
|
+
delete formValues.customer;
|
|
101
|
+
const stateName = states.find(
|
|
102
|
+
(s) => s.id === Number(values.state_obj)
|
|
103
|
+
)?.name;
|
|
104
|
+
let customerCountryCode = "";
|
|
105
|
+
if (values.customer_country_code) {
|
|
106
|
+
try {
|
|
107
|
+
customerCountryCode = `+${getCountryCallingCode(values.customer_country_code)}`;
|
|
108
|
+
} catch {
|
|
109
|
+
customerCountryCode = values.customer_country_code;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
...formValues,
|
|
114
|
+
country: country?.name || "india",
|
|
115
|
+
country_obj: country?.id || 105,
|
|
116
|
+
customer_country_code: customerCountryCode,
|
|
117
|
+
state: stateName || values.state_obj
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export { IP_API_CACHE_KEY, addressFormInitialValues, addressValidationSchema, buildAddressPayload, buildSubmitPayload, clearAddressFormSession, decodeAddress, encodeAddress, isValidPhoneNumber, loadAddressFormFromSession, parseEditAddress, saveAddressFormToSession };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { USER_CART } from './chunk-FLBJKM6G.js';
|
|
2
|
+
|
|
3
|
+
// src/utils/cart.ts
|
|
4
|
+
var LocalCart = {
|
|
5
|
+
get() {
|
|
6
|
+
const storeData = localStorage.getItem(USER_CART);
|
|
7
|
+
return storeData ? JSON.parse(storeData) : null;
|
|
8
|
+
},
|
|
9
|
+
set(cart) {
|
|
10
|
+
localStorage.setItem(USER_CART, JSON.stringify(cart));
|
|
11
|
+
},
|
|
12
|
+
add(product) {
|
|
13
|
+
const cart = this.get();
|
|
14
|
+
if (!cart) {
|
|
15
|
+
this.set({
|
|
16
|
+
product_variants: [product],
|
|
17
|
+
products_quantity: { [product.id]: 1 },
|
|
18
|
+
total_quantity: 1,
|
|
19
|
+
cart_count: 1,
|
|
20
|
+
total_amount: product.selling_price,
|
|
21
|
+
variant_discounts: {}
|
|
22
|
+
});
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const newCart = cart.product_variants || [];
|
|
26
|
+
const existingProduct = newCart.find((prod) => prod.id === product.id);
|
|
27
|
+
if (existingProduct) {
|
|
28
|
+
cart.products_quantity = {
|
|
29
|
+
...cart.products_quantity,
|
|
30
|
+
[product.id]: (Number(cart.products_quantity[product.id]) || 0) + 1
|
|
31
|
+
};
|
|
32
|
+
cart.total_quantity = Number(cart.total_quantity) + 1;
|
|
33
|
+
cart.cart_count = Number(cart.cart_count) + 1;
|
|
34
|
+
cart.total_amount = Number(cart.total_amount) + Number(product.selling_price);
|
|
35
|
+
this.set(cart);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
newCart.push(product);
|
|
39
|
+
cart.products_quantity = {
|
|
40
|
+
...cart.products_quantity,
|
|
41
|
+
[product.id]: (cart.products_quantity[product.id] || 0) + 1
|
|
42
|
+
};
|
|
43
|
+
cart.product_variants = newCart;
|
|
44
|
+
cart.total_quantity = Number(cart.total_quantity) + 1;
|
|
45
|
+
cart.cart_count = Number(cart.cart_count) + 1;
|
|
46
|
+
cart.total_amount = Number(cart.total_amount) + Number(product.selling_price);
|
|
47
|
+
this.set(cart);
|
|
48
|
+
},
|
|
49
|
+
remove(product) {
|
|
50
|
+
const cart = this.get();
|
|
51
|
+
if (!cart) return;
|
|
52
|
+
const newCart = cart.product_variants?.filter(
|
|
53
|
+
(prod) => prod.id !== product.id
|
|
54
|
+
);
|
|
55
|
+
const quantity = cart.products_quantity[product.id] || 0;
|
|
56
|
+
cart.cart_count = (cart.cart_count || 0) - quantity;
|
|
57
|
+
cart.products_quantity = {
|
|
58
|
+
...cart.products_quantity
|
|
59
|
+
};
|
|
60
|
+
if (cart.products_quantity[product.id]) {
|
|
61
|
+
delete cart.products_quantity[product.id];
|
|
62
|
+
}
|
|
63
|
+
cart.product_variants = newCart;
|
|
64
|
+
const currentTotalAmount = Number(cart.total_amount) || 0;
|
|
65
|
+
const itemPrice = Number(product.selling_price) || 0;
|
|
66
|
+
const itemTotalPrice = itemPrice * quantity;
|
|
67
|
+
cart.total_quantity = Math.max(
|
|
68
|
+
0,
|
|
69
|
+
(Number(cart.total_quantity) || 0) - quantity
|
|
70
|
+
);
|
|
71
|
+
cart.total_amount = Math.max(0, currentTotalAmount - itemTotalPrice);
|
|
72
|
+
this.set(cart);
|
|
73
|
+
},
|
|
74
|
+
updateQuantity(product, quantity) {
|
|
75
|
+
const cart = this.get();
|
|
76
|
+
if (!cart) return;
|
|
77
|
+
cart.products_quantity = {
|
|
78
|
+
...cart.products_quantity,
|
|
79
|
+
[product.id]: quantity
|
|
80
|
+
};
|
|
81
|
+
cart.total_quantity = Object.values(cart.products_quantity).reduce(
|
|
82
|
+
(acc, curr) => acc + curr,
|
|
83
|
+
0
|
|
84
|
+
);
|
|
85
|
+
cart.total_amount = cart.product_variants.reduce(
|
|
86
|
+
(acc, curr) => acc + Number(curr.selling_price) * Number(cart.products_quantity[curr.id]),
|
|
87
|
+
0
|
|
88
|
+
);
|
|
89
|
+
Number(cart.total_amount) + Number(product.selling_price) * quantity;
|
|
90
|
+
this.set(cart);
|
|
91
|
+
},
|
|
92
|
+
clear() {
|
|
93
|
+
localStorage.removeItem(USER_CART);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
var cart_default = LocalCart;
|
|
97
|
+
|
|
98
|
+
export { cart_default };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { removeCookie, getCookie, setCookie } from 'typescript-cookie';
|
|
2
|
+
|
|
3
|
+
// src/utils/constants.ts
|
|
4
|
+
var SLICE_STATUS = /* @__PURE__ */ ((SLICE_STATUS2) => {
|
|
5
|
+
SLICE_STATUS2["IDLE"] = "idle";
|
|
6
|
+
SLICE_STATUS2["LOADING"] = "loading";
|
|
7
|
+
SLICE_STATUS2["SUCCESS"] = "success";
|
|
8
|
+
SLICE_STATUS2["FAILURE"] = "failure";
|
|
9
|
+
return SLICE_STATUS2;
|
|
10
|
+
})(SLICE_STATUS || {});
|
|
11
|
+
var pathNameMap = {
|
|
12
|
+
"/checkout/cart": "bag",
|
|
13
|
+
"/checkout/address": "address",
|
|
14
|
+
"/checkout/payment": "payment",
|
|
15
|
+
"/checkout/summary": "summary"
|
|
16
|
+
};
|
|
17
|
+
var USER_CREDENTIALS = "____user_cred_";
|
|
18
|
+
var USER_CART = "____user_cart_";
|
|
19
|
+
var USER_CRED_TOKEN = "____user_cst_";
|
|
20
|
+
var USER_CRED_REFRESH_TOKEN = "____user_csr_";
|
|
21
|
+
var PRODUCT_STATUSES = [
|
|
22
|
+
"confirm",
|
|
23
|
+
"packed",
|
|
24
|
+
"shipped",
|
|
25
|
+
"delivered",
|
|
26
|
+
"cancel",
|
|
27
|
+
" return",
|
|
28
|
+
"refund"
|
|
29
|
+
];
|
|
30
|
+
var DEFAULT_TOAST_CONFIG = {
|
|
31
|
+
position: "bottom-left",
|
|
32
|
+
autoClose: 3e3,
|
|
33
|
+
hideProgressBar: false,
|
|
34
|
+
closeOnClick: true,
|
|
35
|
+
theme: "light",
|
|
36
|
+
progressClassName: "bg-primary"
|
|
37
|
+
};
|
|
38
|
+
var ALLOWED_COUNTRIES = ["AE", "IN", "US"];
|
|
39
|
+
var ADDRESS_FORM_SESSION_KEY = "address_form_values";
|
|
40
|
+
var _onTokenChange = null;
|
|
41
|
+
function setAuthTokenChangeCallback(callback) {
|
|
42
|
+
_onTokenChange = callback;
|
|
43
|
+
}
|
|
44
|
+
var Auth = {
|
|
45
|
+
isAuthenticated: false,
|
|
46
|
+
getUserDetails() {
|
|
47
|
+
return typeof window === "undefined" ? false : getCookie(USER_CRED_TOKEN);
|
|
48
|
+
},
|
|
49
|
+
setUserDetails(data) {
|
|
50
|
+
setCookie(USER_CREDENTIALS, JSON.stringify(data), {
|
|
51
|
+
expires: 60,
|
|
52
|
+
path: "/"
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
setAccessToken(token) {
|
|
56
|
+
setCookie(USER_CRED_TOKEN, token, {
|
|
57
|
+
expires: 60,
|
|
58
|
+
path: "/"
|
|
59
|
+
});
|
|
60
|
+
_onTokenChange?.(token);
|
|
61
|
+
},
|
|
62
|
+
getAccessToken() {
|
|
63
|
+
return getCookie(USER_CRED_TOKEN);
|
|
64
|
+
},
|
|
65
|
+
setRefreshToken(token) {
|
|
66
|
+
setCookie(USER_CRED_REFRESH_TOKEN, token, {
|
|
67
|
+
expires: 60,
|
|
68
|
+
path: "/"
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
getRefreshToken() {
|
|
72
|
+
return getCookie(USER_CRED_REFRESH_TOKEN);
|
|
73
|
+
},
|
|
74
|
+
removeTokens() {
|
|
75
|
+
removeCookie(USER_CRED_TOKEN);
|
|
76
|
+
removeCookie(USER_CRED_REFRESH_TOKEN);
|
|
77
|
+
removeCookie(USER_CREDENTIALS);
|
|
78
|
+
_onTokenChange?.(void 0);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
var auth_default = Auth;
|
|
82
|
+
|
|
83
|
+
export { ADDRESS_FORM_SESSION_KEY, ALLOWED_COUNTRIES, DEFAULT_TOAST_CONFIG, PRODUCT_STATUSES, SLICE_STATUS, USER_CART, USER_CREDENTIALS, USER_CRED_REFRESH_TOKEN, USER_CRED_TOKEN, auth_default, pathNameMap, setAuthTokenChangeCallback };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { auth_default } from './chunk-FLBJKM6G.js';
|
|
2
|
+
import { getPublicApiEndpoint, getStoreId } from './chunk-JQMLHRWL.js';
|
|
3
|
+
import axios from 'axios';
|
|
4
|
+
import { getCookie } from 'typescript-cookie';
|
|
5
|
+
|
|
6
|
+
var _instance = null;
|
|
7
|
+
function createInstance() {
|
|
8
|
+
const baseURL = getPublicApiEndpoint();
|
|
9
|
+
if (!baseURL) {
|
|
10
|
+
throw new Error("Missing API endpoint. Call initConfig() first.");
|
|
11
|
+
}
|
|
12
|
+
axios.defaults.withCredentials = true;
|
|
13
|
+
const instance = axios.create({
|
|
14
|
+
baseURL,
|
|
15
|
+
withCredentials: true
|
|
16
|
+
});
|
|
17
|
+
const onRequestSuccess = (config) => {
|
|
18
|
+
const csrftoken = getCookie("csrftoken");
|
|
19
|
+
const token = auth_default.getAccessToken();
|
|
20
|
+
config.headers["X-CSRFToken"] = csrftoken;
|
|
21
|
+
if (token) config.headers["Authorization"] = `Bearer ${token}`;
|
|
22
|
+
const storeId = getStoreId();
|
|
23
|
+
if (storeId) config.headers[""] = `Store ${storeId}`;
|
|
24
|
+
return config;
|
|
25
|
+
};
|
|
26
|
+
const onRequestFail = (error) => {
|
|
27
|
+
return Promise.reject(error);
|
|
28
|
+
};
|
|
29
|
+
instance.interceptors.request.use(onRequestSuccess, onRequestFail);
|
|
30
|
+
const onResponseSuccess = (response) => {
|
|
31
|
+
return response;
|
|
32
|
+
};
|
|
33
|
+
const onResponseFail = (error) => {
|
|
34
|
+
if (error && !error.response) ; else {
|
|
35
|
+
const status = error.response?.status;
|
|
36
|
+
if (status === 401) {
|
|
37
|
+
error.response?.data?.detail;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return Promise.reject(error);
|
|
41
|
+
};
|
|
42
|
+
instance.interceptors.response.use(onResponseSuccess, onResponseFail);
|
|
43
|
+
return instance;
|
|
44
|
+
}
|
|
45
|
+
function getHttpService() {
|
|
46
|
+
if (!_instance) {
|
|
47
|
+
_instance = createInstance();
|
|
48
|
+
}
|
|
49
|
+
return _instance;
|
|
50
|
+
}
|
|
51
|
+
function resetHttpService() {
|
|
52
|
+
_instance = null;
|
|
53
|
+
}
|
|
54
|
+
var httpService = new Proxy({}, {
|
|
55
|
+
get(_target, prop) {
|
|
56
|
+
return getHttpService()[prop];
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
var http_service_default = httpService;
|
|
60
|
+
|
|
61
|
+
export { getHttpService, http_service_default, resetHttpService };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkRCXQJ6XC_cjs = require('./chunk-RCXQJ6XC.cjs');
|
|
4
|
+
var zustand = require('zustand');
|
|
5
|
+
|
|
6
|
+
var initialState = {
|
|
7
|
+
cart: null,
|
|
8
|
+
status: "idle" /* IDLE */
|
|
9
|
+
};
|
|
10
|
+
var useCartStore = zustand.create((set) => ({
|
|
11
|
+
...initialState,
|
|
12
|
+
setCart: (cart) => set({ cart, status: "idle" /* IDLE */ }),
|
|
13
|
+
resetCart: () => set(initialState),
|
|
14
|
+
resetCartCount: () => set((state) => {
|
|
15
|
+
if (!state.cart) return state;
|
|
16
|
+
return { cart: { ...state.cart, total_quantity: 0 } };
|
|
17
|
+
}),
|
|
18
|
+
syncCart: async () => {
|
|
19
|
+
set({ status: "loading" /* LOADING */ });
|
|
20
|
+
try {
|
|
21
|
+
const response = await chunkRCXQJ6XC_cjs.getCart("/customer/cart/");
|
|
22
|
+
if (response) {
|
|
23
|
+
set({ cart: response, status: "idle" /* IDLE */ });
|
|
24
|
+
}
|
|
25
|
+
} catch {
|
|
26
|
+
set({ status: "idle" /* IDLE */ });
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
fetchCart: async (addressId) => {
|
|
30
|
+
set({ status: "loading" /* LOADING */ });
|
|
31
|
+
try {
|
|
32
|
+
const response = await chunkRCXQJ6XC_cjs.getCart("/customer/cart/", addressId);
|
|
33
|
+
if (response) {
|
|
34
|
+
set({ cart: response, status: "idle" /* IDLE */ });
|
|
35
|
+
}
|
|
36
|
+
} catch {
|
|
37
|
+
set({ status: "idle" /* IDLE */ });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
exports.useCartStore = useCartStore;
|