@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,131 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkCFF632IQ_cjs = require('./chunk-CFF632IQ.cjs');
|
|
4
|
+
var chunkUXLUE3HW_cjs = require('./chunk-UXLUE3HW.cjs');
|
|
5
|
+
var chunkGQTO5ZE2_cjs = require('./chunk-GQTO5ZE2.cjs');
|
|
6
|
+
|
|
7
|
+
// src/api/cart.ts
|
|
8
|
+
async function getCart(url, addressId) {
|
|
9
|
+
const localCart = chunkCFF632IQ_cjs.cart_default.get();
|
|
10
|
+
return chunkGQTO5ZE2_cjs.auth_default.getUserDetails() ? (await chunkUXLUE3HW_cjs.http_service_default.get(url, { params: { address_id: addressId } })).data : localCart || {
|
|
11
|
+
product_variants: [],
|
|
12
|
+
total_amount: 0,
|
|
13
|
+
total_quantity: 0,
|
|
14
|
+
products_quantity: {},
|
|
15
|
+
cart_count: 0,
|
|
16
|
+
missing_items: [],
|
|
17
|
+
customization_inputs: [],
|
|
18
|
+
total_coupon_discount: 0,
|
|
19
|
+
variant_discounts: {},
|
|
20
|
+
total_shipping: 0,
|
|
21
|
+
total_tax_amount: 0
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
async function addToCart(product, customizationInputs) {
|
|
25
|
+
return chunkUXLUE3HW_cjs.http_service_default.post("/customer/cart/", {
|
|
26
|
+
action: "add",
|
|
27
|
+
cart_items: product,
|
|
28
|
+
customization_inputs: customizationInputs
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async function removeFromCart(product) {
|
|
32
|
+
return chunkUXLUE3HW_cjs.http_service_default.post("/customer/cart/", {
|
|
33
|
+
action: "remove",
|
|
34
|
+
cart_items: product
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
async function updateCart(product) {
|
|
38
|
+
return chunkUXLUE3HW_cjs.http_service_default.post("/customer/cart/", {
|
|
39
|
+
action: "update",
|
|
40
|
+
cart_items: product
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/api/product.ts
|
|
45
|
+
async function getProductList(url, filter) {
|
|
46
|
+
const response = await chunkUXLUE3HW_cjs.http_service_default.get(url, {
|
|
47
|
+
params: filter
|
|
48
|
+
});
|
|
49
|
+
return response.data;
|
|
50
|
+
}
|
|
51
|
+
async function getProducts(filter) {
|
|
52
|
+
return chunkUXLUE3HW_cjs.http_service_default.get("/inventory/products/", {
|
|
53
|
+
params: { ...filter }
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
async function getProductDetail(url, slug) {
|
|
57
|
+
const response = await chunkUXLUE3HW_cjs.http_service_default.get(url, {
|
|
58
|
+
params: { variant_slug: slug }
|
|
59
|
+
});
|
|
60
|
+
return response.data;
|
|
61
|
+
}
|
|
62
|
+
async function getProductCategories(url) {
|
|
63
|
+
return await chunkUXLUE3HW_cjs.http_service_default.get(url);
|
|
64
|
+
}
|
|
65
|
+
async function getDigitalProductDownloadLink(variantId) {
|
|
66
|
+
return chunkUXLUE3HW_cjs.http_service_default.get("/inventory/digital_product/download/", {
|
|
67
|
+
params: { variant_id: variantId }
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async function updateDigitalProductDownloadLinkCount(variantId, downloadLink) {
|
|
71
|
+
return chunkUXLUE3HW_cjs.http_service_default.post("/inventory/digital_product/download/", {
|
|
72
|
+
variant_id: variantId,
|
|
73
|
+
download_link: downloadLink
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
async function getCategories(responseType = "flat") {
|
|
77
|
+
return await chunkUXLUE3HW_cjs.http_service_default.get("/inventory/categories/", {
|
|
78
|
+
params: { response_structure: responseType }
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
async function getProductDetailBySlug(url, slug) {
|
|
82
|
+
const response = await chunkUXLUE3HW_cjs.http_service_default.get(url, {
|
|
83
|
+
params: { variant_slug: slug }
|
|
84
|
+
});
|
|
85
|
+
const product = response.data;
|
|
86
|
+
const variantAttributes = product.variants.map((variant) => ({
|
|
87
|
+
...variant.attributes,
|
|
88
|
+
slug: variant.slug
|
|
89
|
+
}));
|
|
90
|
+
variantAttributes.push({
|
|
91
|
+
...product.attributes,
|
|
92
|
+
slug: product.slug
|
|
93
|
+
});
|
|
94
|
+
product.variantAttributes = variantAttributes;
|
|
95
|
+
return product;
|
|
96
|
+
}
|
|
97
|
+
async function notifyProductStock(userDetails) {
|
|
98
|
+
return chunkUXLUE3HW_cjs.http_service_default.post("/utils/customer/notify-me/", userDetails);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/api/wishlist.ts
|
|
102
|
+
async function getWishlist(url) {
|
|
103
|
+
const response = await chunkUXLUE3HW_cjs.http_service_default.get(url);
|
|
104
|
+
return response.data;
|
|
105
|
+
}
|
|
106
|
+
async function addWishlist(productDetails) {
|
|
107
|
+
return chunkUXLUE3HW_cjs.http_service_default.post("/customer/wishlist/", productDetails);
|
|
108
|
+
}
|
|
109
|
+
async function removeFromWishlist(product_variants) {
|
|
110
|
+
return chunkUXLUE3HW_cjs.http_service_default.post("/customer/wishlist/", {
|
|
111
|
+
action: "remove",
|
|
112
|
+
product_variants
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
exports.addToCart = addToCart;
|
|
117
|
+
exports.addWishlist = addWishlist;
|
|
118
|
+
exports.getCart = getCart;
|
|
119
|
+
exports.getCategories = getCategories;
|
|
120
|
+
exports.getDigitalProductDownloadLink = getDigitalProductDownloadLink;
|
|
121
|
+
exports.getProductCategories = getProductCategories;
|
|
122
|
+
exports.getProductDetail = getProductDetail;
|
|
123
|
+
exports.getProductDetailBySlug = getProductDetailBySlug;
|
|
124
|
+
exports.getProductList = getProductList;
|
|
125
|
+
exports.getProducts = getProducts;
|
|
126
|
+
exports.getWishlist = getWishlist;
|
|
127
|
+
exports.notifyProductStock = notifyProductStock;
|
|
128
|
+
exports.removeFromCart = removeFromCart;
|
|
129
|
+
exports.removeFromWishlist = removeFromWishlist;
|
|
130
|
+
exports.updateCart = updateCart;
|
|
131
|
+
exports.updateDigitalProductDownloadLinkCount = updateDigitalProductDownloadLinkCount;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { updateAddress, addAddress, getCountries, getSubdivisions } from './chunk-LBGIUNM6.js';
|
|
2
|
+
import { getCache, getAddressMeta } from './chunk-YUPBTD4M.js';
|
|
3
|
+
import { addressFormInitialValues, IP_API_CACHE_KEY, addressValidationSchema, buildSubmitPayload } from './chunk-CSISWBZZ.js';
|
|
4
|
+
import { useState, useEffect, useMemo, useCallback } from 'react';
|
|
5
|
+
import { useFormik } from 'formik';
|
|
6
|
+
import { isSupportedCountry, getCountryCallingCode } from 'libphonenumber-js';
|
|
7
|
+
|
|
8
|
+
var defaultInitialValues = {
|
|
9
|
+
...addressFormInitialValues,
|
|
10
|
+
is_default: false,
|
|
11
|
+
country_obj: "IN"
|
|
12
|
+
};
|
|
13
|
+
function useAddressForm(options = {}) {
|
|
14
|
+
const {
|
|
15
|
+
address,
|
|
16
|
+
onSuccess,
|
|
17
|
+
onError,
|
|
18
|
+
locationCacheKey = IP_API_CACHE_KEY,
|
|
19
|
+
defaultCountryId = 105
|
|
20
|
+
} = options;
|
|
21
|
+
const isEditing = !!address;
|
|
22
|
+
const [countries, setCountries] = useState([]);
|
|
23
|
+
const [states, setStates] = useState([]);
|
|
24
|
+
const [selectedCountry, setSelectedCountry] = useState(null);
|
|
25
|
+
const [addressMeta, setAddressMeta] = useState(null);
|
|
26
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
27
|
+
const formik = useFormik({
|
|
28
|
+
initialValues: defaultInitialValues,
|
|
29
|
+
validationSchema: addressValidationSchema,
|
|
30
|
+
onSubmit: async (values) => {
|
|
31
|
+
try {
|
|
32
|
+
setIsSubmitting(true);
|
|
33
|
+
const payload = buildSubmitPayload(values, selectedCountry, states);
|
|
34
|
+
let response;
|
|
35
|
+
if (isEditing) {
|
|
36
|
+
response = await updateAddress({
|
|
37
|
+
...payload,
|
|
38
|
+
address_id: address.id
|
|
39
|
+
});
|
|
40
|
+
} else {
|
|
41
|
+
response = await addAddress(payload);
|
|
42
|
+
}
|
|
43
|
+
if (response) {
|
|
44
|
+
formik.resetForm();
|
|
45
|
+
onSuccess?.(response.data, isEditing);
|
|
46
|
+
}
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error(error);
|
|
49
|
+
onError?.(error);
|
|
50
|
+
} finally {
|
|
51
|
+
setIsSubmitting(false);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
const fetchCountries = async () => {
|
|
57
|
+
try {
|
|
58
|
+
const response = await getCountries();
|
|
59
|
+
const sortedCountries = response?.data?.sort((a, b) => {
|
|
60
|
+
if (a.id === defaultCountryId) return -1;
|
|
61
|
+
if (b.id === defaultCountryId) return 1;
|
|
62
|
+
return 0;
|
|
63
|
+
});
|
|
64
|
+
setCountries(sortedCountries);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error(error);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
fetchCountries();
|
|
70
|
+
}, [defaultCountryId]);
|
|
71
|
+
const supportedCountries = useMemo(
|
|
72
|
+
() => countries?.filter((c) => isSupportedCountry(c.tld_code)) ?? [],
|
|
73
|
+
[countries]
|
|
74
|
+
);
|
|
75
|
+
const countryCodeOptions = useMemo(() => {
|
|
76
|
+
return supportedCountries?.map((c) => {
|
|
77
|
+
const callingCode = getCountryCallingCode(c?.tld_code);
|
|
78
|
+
return {
|
|
79
|
+
value: c.tld_code,
|
|
80
|
+
label: `${c.name} (+${callingCode})`,
|
|
81
|
+
country: c
|
|
82
|
+
};
|
|
83
|
+
}) ?? [];
|
|
84
|
+
}, [supportedCountries]);
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
if (!selectedCountry) return;
|
|
87
|
+
const fetchStates = async () => {
|
|
88
|
+
try {
|
|
89
|
+
const response = await getSubdivisions(selectedCountry.id);
|
|
90
|
+
setStates(response.data.results);
|
|
91
|
+
} catch (error) {
|
|
92
|
+
console.error(error);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const fetchAddressMeta = async () => {
|
|
96
|
+
try {
|
|
97
|
+
const response = await getAddressMeta(
|
|
98
|
+
selectedCountry.tld_code
|
|
99
|
+
);
|
|
100
|
+
setAddressMeta(response);
|
|
101
|
+
if (!response?.hasPostal) {
|
|
102
|
+
formik.setFieldValue("pincode", "N/A");
|
|
103
|
+
} else {
|
|
104
|
+
if (formik.values.pincode === "N/A") {
|
|
105
|
+
formik.setFieldValue("pincode", "");
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
} catch (error) {
|
|
109
|
+
console.error(error);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
fetchStates();
|
|
113
|
+
fetchAddressMeta();
|
|
114
|
+
}, [selectedCountry]);
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
if (countries.length > 0 && formik.values.customer_country_code && !selectedCountry) {
|
|
117
|
+
const found = countries.find(
|
|
118
|
+
(c) => c.tld_code === formik.values.customer_country_code
|
|
119
|
+
);
|
|
120
|
+
if (found) {
|
|
121
|
+
setSelectedCountry(found);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}, [countries, formik.values.customer_country_code]);
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
if (supportedCountries.length === 0) return;
|
|
127
|
+
if (address) {
|
|
128
|
+
const addressValues = { ...address };
|
|
129
|
+
if (addressValues.country_obj) {
|
|
130
|
+
const foundCountry = supportedCountries.find(
|
|
131
|
+
(c) => c.id === Number(addressValues.country_obj)
|
|
132
|
+
);
|
|
133
|
+
if (foundCountry) {
|
|
134
|
+
setSelectedCountry(foundCountry);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (addressValues?.customer_country_code) {
|
|
138
|
+
const foundCountry = supportedCountries.find(
|
|
139
|
+
(c) => getCountryCallingCode(c.tld_code) === addressValues.customer_country_code.slice(1)
|
|
140
|
+
);
|
|
141
|
+
if (foundCountry) {
|
|
142
|
+
addressValues.customer_country_code = foundCountry.tld_code;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
formik.setValues(addressValues);
|
|
146
|
+
} else {
|
|
147
|
+
const locationData = getCache(locationCacheKey);
|
|
148
|
+
if (locationData) {
|
|
149
|
+
const { country_code = "IN" } = locationData;
|
|
150
|
+
const foundCountry = supportedCountries.find(
|
|
151
|
+
(c) => c.tld_code === country_code
|
|
152
|
+
);
|
|
153
|
+
if (foundCountry) {
|
|
154
|
+
setSelectedCountry(foundCountry);
|
|
155
|
+
}
|
|
156
|
+
formik.setValues({
|
|
157
|
+
...defaultInitialValues,
|
|
158
|
+
customer_country_code: country_code,
|
|
159
|
+
country_obj: country_code
|
|
160
|
+
});
|
|
161
|
+
} else {
|
|
162
|
+
formik.setValues(defaultInitialValues);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}, [address, supportedCountries]);
|
|
166
|
+
const handlePhoneCountryChange = useCallback(
|
|
167
|
+
(value) => {
|
|
168
|
+
formik.setFieldValue("customer_country_code", value);
|
|
169
|
+
},
|
|
170
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
171
|
+
[]
|
|
172
|
+
);
|
|
173
|
+
const handleCountryCodeChange = useCallback(
|
|
174
|
+
(value) => {
|
|
175
|
+
const country = supportedCountries.find(
|
|
176
|
+
(c) => c.tld_code === value
|
|
177
|
+
);
|
|
178
|
+
if (country) {
|
|
179
|
+
setSelectedCountry(country);
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
[supportedCountries]
|
|
183
|
+
);
|
|
184
|
+
const handleStateChange = useCallback(
|
|
185
|
+
(e) => {
|
|
186
|
+
formik.setFieldValue("state_obj", e.target.value);
|
|
187
|
+
},
|
|
188
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
189
|
+
[]
|
|
190
|
+
);
|
|
191
|
+
const handlePhoneChange = useCallback(
|
|
192
|
+
(e) => {
|
|
193
|
+
const cleaned = e.target.value.trim().replace(/^0+/, "");
|
|
194
|
+
formik.setFieldValue("customer_phone", cleaned);
|
|
195
|
+
},
|
|
196
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
197
|
+
[]
|
|
198
|
+
);
|
|
199
|
+
return {
|
|
200
|
+
formik,
|
|
201
|
+
countries,
|
|
202
|
+
supportedCountries,
|
|
203
|
+
states,
|
|
204
|
+
selectedCountry,
|
|
205
|
+
countryCodeOptions,
|
|
206
|
+
addressMeta,
|
|
207
|
+
handlePhoneCountryChange,
|
|
208
|
+
handleCountryCodeChange,
|
|
209
|
+
handleStateChange,
|
|
210
|
+
handlePhoneChange,
|
|
211
|
+
isSubmitting,
|
|
212
|
+
isEditing
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export { useAddressForm };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkGQTO5ZE2_cjs = require('./chunk-GQTO5ZE2.cjs');
|
|
4
|
+
var chunkN3CTXRFT_cjs = require('./chunk-N3CTXRFT.cjs');
|
|
5
|
+
var axios = require('axios');
|
|
6
|
+
var typescriptCookie = require('typescript-cookie');
|
|
7
|
+
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var axios__default = /*#__PURE__*/_interopDefault(axios);
|
|
11
|
+
|
|
12
|
+
var _instance = null;
|
|
13
|
+
function createInstance() {
|
|
14
|
+
const baseURL = chunkN3CTXRFT_cjs.getPublicApiEndpoint();
|
|
15
|
+
if (!baseURL) {
|
|
16
|
+
throw new Error("Missing API endpoint. Call initConfig() first.");
|
|
17
|
+
}
|
|
18
|
+
axios__default.default.defaults.withCredentials = true;
|
|
19
|
+
const instance = axios__default.default.create({
|
|
20
|
+
baseURL,
|
|
21
|
+
withCredentials: true
|
|
22
|
+
});
|
|
23
|
+
const onRequestSuccess = (config) => {
|
|
24
|
+
const csrftoken = typescriptCookie.getCookie("csrftoken");
|
|
25
|
+
const token = chunkGQTO5ZE2_cjs.auth_default.getAccessToken();
|
|
26
|
+
config.headers["X-CSRFToken"] = csrftoken;
|
|
27
|
+
if (token) config.headers["Authorization"] = `Bearer ${token}`;
|
|
28
|
+
const storeId = chunkN3CTXRFT_cjs.getStoreId();
|
|
29
|
+
if (storeId) config.headers[""] = `Store ${storeId}`;
|
|
30
|
+
return config;
|
|
31
|
+
};
|
|
32
|
+
const onRequestFail = (error) => {
|
|
33
|
+
return Promise.reject(error);
|
|
34
|
+
};
|
|
35
|
+
instance.interceptors.request.use(onRequestSuccess, onRequestFail);
|
|
36
|
+
const onResponseSuccess = (response) => {
|
|
37
|
+
return response;
|
|
38
|
+
};
|
|
39
|
+
const onResponseFail = (error) => {
|
|
40
|
+
if (error && !error.response) ; else {
|
|
41
|
+
const status = error.response?.status;
|
|
42
|
+
if (status === 401) {
|
|
43
|
+
error.response?.data?.detail;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return Promise.reject(error);
|
|
47
|
+
};
|
|
48
|
+
instance.interceptors.response.use(onResponseSuccess, onResponseFail);
|
|
49
|
+
return instance;
|
|
50
|
+
}
|
|
51
|
+
function getHttpService() {
|
|
52
|
+
if (!_instance) {
|
|
53
|
+
_instance = createInstance();
|
|
54
|
+
}
|
|
55
|
+
return _instance;
|
|
56
|
+
}
|
|
57
|
+
function resetHttpService() {
|
|
58
|
+
_instance = null;
|
|
59
|
+
}
|
|
60
|
+
var httpService = new Proxy({}, {
|
|
61
|
+
get(_target, prop) {
|
|
62
|
+
return getHttpService()[prop];
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
var http_service_default = httpService;
|
|
66
|
+
|
|
67
|
+
exports.getHttpService = getHttpService;
|
|
68
|
+
exports.http_service_default = http_service_default;
|
|
69
|
+
exports.resetHttpService = resetHttpService;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// src/utils/pixelEvents.ts
|
|
2
|
+
var pixelEvents = {
|
|
3
|
+
/**
|
|
4
|
+
* Track when a user views a product
|
|
5
|
+
*/
|
|
6
|
+
productView: (product) => {
|
|
7
|
+
if (!window.fbq) return;
|
|
8
|
+
try {
|
|
9
|
+
window.fbq("track", "product_viewed", {
|
|
10
|
+
content_slug: product.slug,
|
|
11
|
+
content_name: product.name,
|
|
12
|
+
content_type: "product",
|
|
13
|
+
currency: window.currency_code || "INR",
|
|
14
|
+
price: Number(product.selling_price),
|
|
15
|
+
attributes: product.attributes,
|
|
16
|
+
value: Number(product.selling_price)
|
|
17
|
+
});
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error("Facebook Pixel ViewContent Event Error:", error);
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
/**
|
|
23
|
+
* Track when a product is added to cart
|
|
24
|
+
*/
|
|
25
|
+
addToCart: (product, quantity = 1) => {
|
|
26
|
+
if (!window.fbq) return;
|
|
27
|
+
try {
|
|
28
|
+
window.fbq("track", "product_added_to_cart", {
|
|
29
|
+
content_slug: product.slug,
|
|
30
|
+
content_name: product.name,
|
|
31
|
+
content_type: "product",
|
|
32
|
+
price: Number(product.selling_price) * quantity,
|
|
33
|
+
num_items: quantity,
|
|
34
|
+
attributes: product.attributes
|
|
35
|
+
});
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.error("Facebook Pixel AddToCart Event Error:", error);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
removeFromCart: (product) => {
|
|
41
|
+
if (!window.fbq) return;
|
|
42
|
+
try {
|
|
43
|
+
window.fbq("track", "product_removed_from_cart", {
|
|
44
|
+
content_slug: product.slug,
|
|
45
|
+
content_name: product.name,
|
|
46
|
+
content_type: "product",
|
|
47
|
+
price: Number(product.selling_price),
|
|
48
|
+
attributes: product.attributes
|
|
49
|
+
});
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error("Facebook Pixel RemoveFromCart Event Error:", error);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
/**
|
|
55
|
+
* Track when a product is added to wishlist
|
|
56
|
+
*/
|
|
57
|
+
addToWishlist: (product) => {
|
|
58
|
+
if (!window.fbq) return;
|
|
59
|
+
try {
|
|
60
|
+
window.fbq("track", "product_added_to_wishlist", {
|
|
61
|
+
content_slug: product.slug,
|
|
62
|
+
content_name: product.name,
|
|
63
|
+
content_type: "product",
|
|
64
|
+
price: Number(product.selling_price),
|
|
65
|
+
attributes: product.attributes
|
|
66
|
+
});
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error("Facebook Pixel AddToWishlist Event Error:", error);
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
/**
|
|
72
|
+
* Track when user initiates checkout
|
|
73
|
+
*/
|
|
74
|
+
initiateCheckout: (orderSummary, paymentMethod) => {
|
|
75
|
+
if (!window.fbq) return;
|
|
76
|
+
try {
|
|
77
|
+
window.fbq("track", "checkout_started", {
|
|
78
|
+
order_number: orderSummary.order_number,
|
|
79
|
+
content_type: "product",
|
|
80
|
+
currency: window.currency_code || "INR",
|
|
81
|
+
price: orderSummary.total_amount,
|
|
82
|
+
value: orderSummary.total_amount,
|
|
83
|
+
num_items: orderSummary.purchased_products.length,
|
|
84
|
+
contents: orderSummary.purchased_products.map((item) => ({
|
|
85
|
+
name: item.product_variant_name,
|
|
86
|
+
quantity: item.quantity,
|
|
87
|
+
item_price: Number(item.total_price),
|
|
88
|
+
sku: item.product_variant_sku
|
|
89
|
+
})),
|
|
90
|
+
payment_method: paymentMethod
|
|
91
|
+
});
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.error("Facebook Pixel InitiateCheckout Event Error:", error);
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
/**
|
|
97
|
+
* Track successful purchases
|
|
98
|
+
*/
|
|
99
|
+
purchase: (orderSummary) => {
|
|
100
|
+
if (!window.fbq) return;
|
|
101
|
+
try {
|
|
102
|
+
window.fbq("track", "purchase", {
|
|
103
|
+
content_ids: [orderSummary.order_number],
|
|
104
|
+
order_number: orderSummary.order_number,
|
|
105
|
+
content_type: "product",
|
|
106
|
+
currency: window.currency_code || "INR",
|
|
107
|
+
price: orderSummary.total_amount,
|
|
108
|
+
value: orderSummary.total_amount,
|
|
109
|
+
num_items: orderSummary.purchased_products.length,
|
|
110
|
+
contents: orderSummary.purchased_products.map((item) => ({
|
|
111
|
+
name: item.product_variant_name,
|
|
112
|
+
quantity: item.quantity,
|
|
113
|
+
item_price: Number(item.total_price),
|
|
114
|
+
sku: item.product_variant_sku
|
|
115
|
+
}))
|
|
116
|
+
});
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.error("Facebook Pixel Purchase Event Error:", error);
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
/**
|
|
122
|
+
* Track search events
|
|
123
|
+
*/
|
|
124
|
+
search: (searchTerm, resultCount) => {
|
|
125
|
+
if (!window.fbq) return;
|
|
126
|
+
try {
|
|
127
|
+
window.fbq("track", "search_submitted", {
|
|
128
|
+
search_string: searchTerm,
|
|
129
|
+
content_type: "product",
|
|
130
|
+
success: resultCount > 0,
|
|
131
|
+
num_results: resultCount
|
|
132
|
+
});
|
|
133
|
+
} catch (error) {
|
|
134
|
+
console.error("Facebook Pixel Search Event Error:", error);
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
/**
|
|
138
|
+
* Track when a user views their cart
|
|
139
|
+
*/
|
|
140
|
+
cartView: (cart) => {
|
|
141
|
+
if (!window.fbq) return;
|
|
142
|
+
try {
|
|
143
|
+
window.fbq("track", "cart_viewed", {
|
|
144
|
+
content_type: "cart",
|
|
145
|
+
value: cart.total_amount,
|
|
146
|
+
number_of_products: cart.total_quantity
|
|
147
|
+
});
|
|
148
|
+
} catch (error) {
|
|
149
|
+
console.error("Facebook Pixel Cart View Event Error:", error);
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
/**
|
|
153
|
+
* Track when a user completes a checkout
|
|
154
|
+
*/
|
|
155
|
+
checkoutCompleted: (orderSummary) => {
|
|
156
|
+
if (!window.fbq) return;
|
|
157
|
+
try {
|
|
158
|
+
window.fbq("track", "checkout_completed", {
|
|
159
|
+
content_ids: [orderSummary.order_number],
|
|
160
|
+
order_number: orderSummary.order_number,
|
|
161
|
+
content_type: "product",
|
|
162
|
+
currency: "INR",
|
|
163
|
+
value: orderSummary.total_amount,
|
|
164
|
+
num_items: orderSummary.purchased_products.length,
|
|
165
|
+
contents: orderSummary.purchased_products.map((item) => ({
|
|
166
|
+
name: item.product_variant_name,
|
|
167
|
+
quantity: item.quantity,
|
|
168
|
+
item_price: Number(item.total_price),
|
|
169
|
+
sku: item.product_variant_sku
|
|
170
|
+
}))
|
|
171
|
+
});
|
|
172
|
+
} catch (error) {
|
|
173
|
+
console.error("Facebook Pixel Checkout Completed Event Error:", error);
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
addressInfoSubmitted: () => {
|
|
177
|
+
if (!window.fbq) return;
|
|
178
|
+
try {
|
|
179
|
+
window.fbq("track", "checkout_address_info_submitted", {
|
|
180
|
+
content_type: "address"
|
|
181
|
+
});
|
|
182
|
+
} catch (error) {
|
|
183
|
+
console.error(
|
|
184
|
+
"Facebook Pixel Address Info Submitted Event Error:",
|
|
185
|
+
error
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
checkoutStarted: (cart) => {
|
|
190
|
+
if (!window.fbq) return;
|
|
191
|
+
try {
|
|
192
|
+
window.fbq("track", "checkout_started", {
|
|
193
|
+
value: cart.total_amount,
|
|
194
|
+
number_of_products: cart.total_quantity
|
|
195
|
+
});
|
|
196
|
+
} catch (error) {
|
|
197
|
+
console.error("Facebook Pixel Checkout Started Event Error:", error);
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
pageViewed: () => {
|
|
201
|
+
if (!window.fbq) return;
|
|
202
|
+
try {
|
|
203
|
+
window.fbq("track", "page_viewed");
|
|
204
|
+
} catch (error) {
|
|
205
|
+
console.error("Facebook Pixel Page Viewed Event Error:", error);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
export { pixelEvents };
|