@storepecker/storefront-core 2.3.0 → 2.3.2
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 +78 -74
- package/dist/api/index.d.cts +7 -2
- package/dist/api/index.d.ts +7 -2
- package/dist/api/index.js +6 -6
- package/dist/{cart-XumsY-y0.d.cts → cart-B13IUuwP.d.cts} +3 -0
- package/dist/{cart-CfsntcpS.d.ts → cart-DOy6dICN.d.ts} +3 -0
- package/dist/checkout/index.cjs +40 -36
- package/dist/checkout/index.d.cts +7 -2
- package/dist/checkout/index.d.ts +7 -2
- package/dist/checkout/index.js +4 -4
- package/dist/{chunk-BHOXJGIE.js → chunk-27MTKBJL.js} +1 -1
- package/dist/chunk-3SYYP3XV.js +121 -0
- package/dist/{chunk-XLQAALMU.cjs → chunk-65Z7I5UP.cjs} +10 -10
- package/dist/{chunk-FMHR5ABF.cjs → chunk-CV6DWPYF.cjs} +28 -28
- package/dist/chunk-ECHV2JSY.cjs +130 -0
- package/dist/{chunk-B7FOXIZN.js → chunk-ELP23UGF.js} +27 -2
- package/dist/{chunk-7R2V4C7Q.js → chunk-ILVGYHNI.js} +2 -2
- package/dist/{chunk-N3ZCCKXV.cjs → chunk-JCOOINQF.cjs} +10 -10
- package/dist/{chunk-SABICUTC.cjs → chunk-NKJ4DF4D.cjs} +6 -6
- package/dist/{chunk-G3R7ZVAG.cjs → chunk-RDUT4W3B.cjs} +7 -7
- package/dist/{chunk-47XTPPII.cjs → chunk-TB72NPRM.cjs} +27 -1
- package/dist/{chunk-ERLBPVFK.js → chunk-U25T7M6S.js} +3 -2
- package/dist/{chunk-QBRME5AG.js → chunk-VJCAOV74.js} +1 -1
- package/dist/{chunk-GHABOHLA.js → chunk-VWFZZFZL.js} +1 -1
- package/dist/{chunk-C7ZJZEEN.js → chunk-WYXT5AAG.js} +1 -1
- package/dist/{chunk-A67PCF55.cjs → chunk-Y2CPMT34.cjs} +19 -18
- package/dist/{chunk-KKQKHG26.cjs → chunk-Y46EHRJQ.cjs} +3 -3
- package/dist/{chunk-YY77CUWX.js → chunk-ZGMLOLTC.js} +1 -1
- package/dist/components/index.cjs +5 -5
- package/dist/components/index.js +4 -4
- package/dist/hooks/index.cjs +32 -32
- package/dist/hooks/index.d.cts +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +9 -9
- package/dist/models/index.d.cts +1 -1
- package/dist/models/index.d.ts +1 -1
- package/dist/store/index.cjs +8 -8
- package/dist/store/index.d.cts +1 -1
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.js +3 -3
- package/dist/utils/index.d.cts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/package.json +1 -1
- package/dist/chunk-JWKDXFS4.js +0 -61
- package/dist/chunk-ZO2HREQL.cjs +0 -69
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkBBRXE57K_cjs = require('./chunk-BBRXE57K.cjs');
|
|
4
|
+
var chunkN3CTXRFT_cjs = require('./chunk-N3CTXRFT.cjs');
|
|
5
|
+
var axios = require('axios');
|
|
6
|
+
var typescriptCookie = require('typescript-cookie');
|
|
7
|
+
var jwtDecode = require('jwt-decode');
|
|
8
|
+
|
|
9
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
|
|
11
|
+
var axios__default = /*#__PURE__*/_interopDefault(axios);
|
|
12
|
+
|
|
13
|
+
var _instance = null;
|
|
14
|
+
var _isRefreshing = false;
|
|
15
|
+
var _refreshQueue = [];
|
|
16
|
+
var _onSessionExpired = null;
|
|
17
|
+
function setSessionExpiredCallback(cb) {
|
|
18
|
+
_onSessionExpired = cb;
|
|
19
|
+
}
|
|
20
|
+
function isTokenExpiringSoon(token) {
|
|
21
|
+
try {
|
|
22
|
+
const decoded = jwtDecode.jwtDecode(token);
|
|
23
|
+
if (!decoded?.exp) return false;
|
|
24
|
+
const expiresAt = decoded.exp * 1e3;
|
|
25
|
+
return Date.now() > expiresAt - 6e4;
|
|
26
|
+
} catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function refreshAccessToken(instance) {
|
|
31
|
+
const refresh = chunkBBRXE57K_cjs.auth_default.getRefreshToken();
|
|
32
|
+
if (!refresh) return null;
|
|
33
|
+
try {
|
|
34
|
+
const response = await instance.post("/api/token/refresh/", { refresh });
|
|
35
|
+
const { access, refresh: newRefresh } = response.data;
|
|
36
|
+
chunkBBRXE57K_cjs.auth_default.setAccessToken(access);
|
|
37
|
+
chunkBBRXE57K_cjs.auth_default.setRefreshToken(newRefresh);
|
|
38
|
+
return access;
|
|
39
|
+
} catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function queuedRefresh(instance) {
|
|
44
|
+
if (_isRefreshing) {
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
_refreshQueue.push({ resolve, reject });
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
_isRefreshing = true;
|
|
50
|
+
return refreshAccessToken(instance).then((token) => {
|
|
51
|
+
_isRefreshing = false;
|
|
52
|
+
if (token) {
|
|
53
|
+
_refreshQueue.forEach((req) => req.resolve(token));
|
|
54
|
+
} else {
|
|
55
|
+
chunkBBRXE57K_cjs.auth_default.removeTokens();
|
|
56
|
+
_onSessionExpired?.();
|
|
57
|
+
_refreshQueue.forEach(
|
|
58
|
+
(req) => req.reject(new Error("Session expired"))
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
_refreshQueue = [];
|
|
62
|
+
return token;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function createInstance() {
|
|
66
|
+
const baseURL = chunkN3CTXRFT_cjs.getPublicApiEndpoint();
|
|
67
|
+
if (!baseURL) {
|
|
68
|
+
throw new Error("Missing API endpoint. Call initConfig() first.");
|
|
69
|
+
}
|
|
70
|
+
axios__default.default.defaults.withCredentials = true;
|
|
71
|
+
const instance = axios__default.default.create({
|
|
72
|
+
baseURL,
|
|
73
|
+
withCredentials: true
|
|
74
|
+
});
|
|
75
|
+
const onRequestSuccess = async (config) => {
|
|
76
|
+
const csrftoken = typescriptCookie.getCookie("csrftoken");
|
|
77
|
+
let token = chunkBBRXE57K_cjs.auth_default.getAccessToken();
|
|
78
|
+
if (token && isTokenExpiringSoon(token) && !config.url?.includes("/api/token/refresh/")) {
|
|
79
|
+
const newToken = await queuedRefresh(instance);
|
|
80
|
+
if (newToken) token = newToken;
|
|
81
|
+
}
|
|
82
|
+
config.headers["X-CSRFToken"] = csrftoken;
|
|
83
|
+
if (token) config.headers["Authorization"] = `Bearer ${token}`;
|
|
84
|
+
const storeId = chunkN3CTXRFT_cjs.getStoreId();
|
|
85
|
+
if (storeId) config.headers[""] = `Store ${storeId}`;
|
|
86
|
+
return config;
|
|
87
|
+
};
|
|
88
|
+
const onRequestFail = (error) => {
|
|
89
|
+
return Promise.reject(error);
|
|
90
|
+
};
|
|
91
|
+
instance.interceptors.request.use(onRequestSuccess, onRequestFail);
|
|
92
|
+
const onResponseSuccess = (response) => {
|
|
93
|
+
return response;
|
|
94
|
+
};
|
|
95
|
+
const onResponseFail = async (error) => {
|
|
96
|
+
const originalRequest = error.config;
|
|
97
|
+
if (error.response?.status === 401 && originalRequest && !originalRequest.url?.includes("/api/token/refresh/") && !originalRequest._retried) {
|
|
98
|
+
originalRequest._retried = true;
|
|
99
|
+
const newToken = await queuedRefresh(instance);
|
|
100
|
+
if (newToken) {
|
|
101
|
+
originalRequest.headers["Authorization"] = `Bearer ${newToken}`;
|
|
102
|
+
return instance(originalRequest);
|
|
103
|
+
}
|
|
104
|
+
return Promise.reject(error);
|
|
105
|
+
}
|
|
106
|
+
return Promise.reject(error);
|
|
107
|
+
};
|
|
108
|
+
instance.interceptors.response.use(onResponseSuccess, onResponseFail);
|
|
109
|
+
return instance;
|
|
110
|
+
}
|
|
111
|
+
function getHttpService() {
|
|
112
|
+
if (!_instance) {
|
|
113
|
+
_instance = createInstance();
|
|
114
|
+
}
|
|
115
|
+
return _instance;
|
|
116
|
+
}
|
|
117
|
+
function resetHttpService() {
|
|
118
|
+
_instance = null;
|
|
119
|
+
}
|
|
120
|
+
var httpService = new Proxy({}, {
|
|
121
|
+
get(_target, prop) {
|
|
122
|
+
return getHttpService()[prop];
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
var http_service_default = httpService;
|
|
126
|
+
|
|
127
|
+
exports.getHttpService = getHttpService;
|
|
128
|
+
exports.http_service_default = http_service_default;
|
|
129
|
+
exports.resetHttpService = resetHttpService;
|
|
130
|
+
exports.setSessionExpiredCallback = setSessionExpiredCallback;
|
|
@@ -15,10 +15,30 @@ var addressFormInitialValues = {
|
|
|
15
15
|
city: "",
|
|
16
16
|
customer_email: ""
|
|
17
17
|
};
|
|
18
|
+
function sanitizePhoneNumber(input, countryCode) {
|
|
19
|
+
let cleaned = input.trim().replace(/\s+/g, "");
|
|
20
|
+
try {
|
|
21
|
+
const callingCode = getCountryCallingCode(countryCode);
|
|
22
|
+
const prefix = `+${callingCode}`;
|
|
23
|
+
if (cleaned.startsWith(prefix)) {
|
|
24
|
+
cleaned = cleaned.slice(prefix.length);
|
|
25
|
+
} else if (cleaned.startsWith(callingCode)) {
|
|
26
|
+
cleaned = cleaned.slice(callingCode.length);
|
|
27
|
+
}
|
|
28
|
+
} catch {
|
|
29
|
+
if (cleaned.startsWith("+")) {
|
|
30
|
+
cleaned = cleaned.replace(/^\+\d{1,4}/, "");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
cleaned = cleaned.replace(/^0+/, "");
|
|
34
|
+
return cleaned;
|
|
35
|
+
}
|
|
18
36
|
function isValidPhoneNumber(input, countryCode) {
|
|
19
37
|
if (!input) return false;
|
|
20
38
|
const phone = parsePhoneNumberFromString(input, countryCode);
|
|
21
|
-
|
|
39
|
+
if (!phone?.isValid()) return false;
|
|
40
|
+
if (phone.country && phone.country !== countryCode) return false;
|
|
41
|
+
return true;
|
|
22
42
|
}
|
|
23
43
|
var addressValidationSchema = Yup.object({
|
|
24
44
|
customer_phone: Yup.string().required("Phone number required").test("is-valid", "Please enter a valid number", function(value) {
|
|
@@ -109,8 +129,13 @@ function buildSubmitPayload(values, country, states) {
|
|
|
109
129
|
customerCountryCode = values.customer_country_code;
|
|
110
130
|
}
|
|
111
131
|
}
|
|
132
|
+
const cleanPhone = sanitizePhoneNumber(
|
|
133
|
+
values.customer_phone,
|
|
134
|
+
values.customer_country_code
|
|
135
|
+
);
|
|
112
136
|
return {
|
|
113
137
|
...formValues,
|
|
138
|
+
customer_phone: cleanPhone,
|
|
114
139
|
country: country?.name || "india",
|
|
115
140
|
country_obj: country?.id || 105,
|
|
116
141
|
customer_country_code: customerCountryCode,
|
|
@@ -118,4 +143,4 @@ function buildSubmitPayload(values, country, states) {
|
|
|
118
143
|
};
|
|
119
144
|
}
|
|
120
145
|
|
|
121
|
-
export { IP_API_CACHE_KEY, addressFormInitialValues, addressValidationSchema, buildAddressPayload, buildSubmitPayload, clearAddressFormSession, decodeAddress, encodeAddress, isValidPhoneNumber, loadAddressFormFromSession, parseEditAddress, saveAddressFormToSession };
|
|
146
|
+
export { IP_API_CACHE_KEY, addressFormInitialValues, addressValidationSchema, buildAddressPayload, buildSubmitPayload, clearAddressFormSession, decodeAddress, encodeAddress, isValidPhoneNumber, loadAddressFormFromSession, parseEditAddress, sanitizePhoneNumber, saveAddressFormToSession };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { updateAddress, addAddress, getCountries, getSubdivisions } from './chunk-
|
|
1
|
+
import { updateAddress, addAddress, getCountries, getSubdivisions } from './chunk-ZGMLOLTC.js';
|
|
2
2
|
import { getCache, getAddressMeta } from './chunk-YUPBTD4M.js';
|
|
3
|
-
import { addressFormInitialValues, IP_API_CACHE_KEY, addressValidationSchema, buildSubmitPayload } from './chunk-
|
|
3
|
+
import { addressFormInitialValues, IP_API_CACHE_KEY, addressValidationSchema, buildSubmitPayload } from './chunk-ELP23UGF.js';
|
|
4
4
|
import { useState, useEffect, useMemo, useCallback } from 'react';
|
|
5
5
|
import { useFormik } from 'formik';
|
|
6
6
|
import { isSupportedCountry, getCountryCallingCode } from 'libphonenumber-js';
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkRDUT4W3B_cjs = require('./chunk-RDUT4W3B.cjs');
|
|
4
4
|
var chunk4CVKE6CC_cjs = require('./chunk-4CVKE6CC.cjs');
|
|
5
|
-
var
|
|
5
|
+
var chunkTB72NPRM_cjs = require('./chunk-TB72NPRM.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
|
+
...chunkTB72NPRM_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 = chunkTB72NPRM_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: chunkTB72NPRM_cjs.addressValidationSchema,
|
|
32
32
|
onSubmit: async (values) => {
|
|
33
33
|
try {
|
|
34
34
|
setIsSubmitting(true);
|
|
35
|
-
const payload =
|
|
35
|
+
const payload = chunkTB72NPRM_cjs.buildSubmitPayload(values, selectedCountry, states);
|
|
36
36
|
let response;
|
|
37
37
|
if (isEditing) {
|
|
38
|
-
response = await
|
|
38
|
+
response = await chunkRDUT4W3B_cjs.updateAddress({
|
|
39
39
|
...payload,
|
|
40
40
|
address_id: address.id
|
|
41
41
|
});
|
|
42
42
|
} else {
|
|
43
|
-
response = await
|
|
43
|
+
response = await chunkRDUT4W3B_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 chunkRDUT4W3B_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 chunkRDUT4W3B_cjs.getSubdivisions(selectedCountry.id);
|
|
92
92
|
setStates(response.data.results);
|
|
93
93
|
} catch (error) {
|
|
94
94
|
console.error(error);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkY2CPMT34_cjs = require('./chunk-Y2CPMT34.cjs');
|
|
4
4
|
var chunkSMHJRNCR_cjs = require('./chunk-SMHJRNCR.cjs');
|
|
5
5
|
var chunkBBRXE57K_cjs = require('./chunk-BBRXE57K.cjs');
|
|
6
6
|
var chunkNE3ZHELZ_cjs = require('./chunk-NE3ZHELZ.cjs');
|
|
@@ -22,7 +22,7 @@ var useCartStore = zustand.create((set) => ({
|
|
|
22
22
|
syncCart: async (addressId) => {
|
|
23
23
|
set({ status: "loading" /* LOADING */ });
|
|
24
24
|
try {
|
|
25
|
-
const response = await
|
|
25
|
+
const response = await chunkY2CPMT34_cjs.getCart("/customer/cart/", addressId);
|
|
26
26
|
if (response) {
|
|
27
27
|
set({ cart: response, status: "idle" /* IDLE */ });
|
|
28
28
|
}
|
|
@@ -33,7 +33,7 @@ var useCartStore = zustand.create((set) => ({
|
|
|
33
33
|
fetchCart: async (addressId) => {
|
|
34
34
|
set({ status: "loading" /* LOADING */ });
|
|
35
35
|
try {
|
|
36
|
-
const response = await
|
|
36
|
+
const response = await chunkY2CPMT34_cjs.getCart("/customer/cart/", addressId);
|
|
37
37
|
if (response) {
|
|
38
38
|
set({ cart: response, status: "idle" /* IDLE */ });
|
|
39
39
|
}
|
|
@@ -45,7 +45,7 @@ var useCartStore = zustand.create((set) => ({
|
|
|
45
45
|
set({ status: "loading" /* LOADING */ });
|
|
46
46
|
try {
|
|
47
47
|
if (chunkBBRXE57K_cjs.auth_default.getUserDetails()) {
|
|
48
|
-
await
|
|
48
|
+
await chunkY2CPMT34_cjs.addToCart(items, customizationInputs);
|
|
49
49
|
await useCartStore.getState().syncCart(addressId);
|
|
50
50
|
} else {
|
|
51
51
|
const cart = chunkSMHJRNCR_cjs.cart_default.get();
|
|
@@ -71,7 +71,7 @@ var useCartStore = zustand.create((set) => ({
|
|
|
71
71
|
set({ status: "loading" /* LOADING */ });
|
|
72
72
|
try {
|
|
73
73
|
if (chunkBBRXE57K_cjs.auth_default.getUserDetails()) {
|
|
74
|
-
await
|
|
74
|
+
await chunkY2CPMT34_cjs.removeFromCart(items);
|
|
75
75
|
await useCartStore.getState().syncCart(addressId);
|
|
76
76
|
} else {
|
|
77
77
|
const cart = chunkSMHJRNCR_cjs.cart_default.get();
|
|
@@ -99,7 +99,7 @@ var useCartStore = zustand.create((set) => ({
|
|
|
99
99
|
set({ status: "loading" /* LOADING */ });
|
|
100
100
|
try {
|
|
101
101
|
if (chunkBBRXE57K_cjs.auth_default.getUserDetails()) {
|
|
102
|
-
await
|
|
102
|
+
await chunkY2CPMT34_cjs.updateCart(items);
|
|
103
103
|
await useCartStore.getState().syncCart(addressId);
|
|
104
104
|
} else {
|
|
105
105
|
const cart = chunkSMHJRNCR_cjs.cart_default.get();
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkECHV2JSY_cjs = require('./chunk-ECHV2JSY.cjs');
|
|
4
4
|
|
|
5
5
|
// src/api/address.ts
|
|
6
6
|
async function getAddresses(url) {
|
|
7
|
-
const response = await
|
|
7
|
+
const response = await chunkECHV2JSY_cjs.http_service_default.get(url);
|
|
8
8
|
return response.data;
|
|
9
9
|
}
|
|
10
10
|
async function addAddress(addressDetails) {
|
|
11
|
-
return
|
|
11
|
+
return chunkECHV2JSY_cjs.http_service_default.post("/store/customer_address/", addressDetails);
|
|
12
12
|
}
|
|
13
13
|
async function updateAddress(addressDetails) {
|
|
14
|
-
return
|
|
14
|
+
return chunkECHV2JSY_cjs.http_service_default.patch("/store/customer_address/", addressDetails);
|
|
15
15
|
}
|
|
16
16
|
async function deleteAddress(address_id) {
|
|
17
|
-
return
|
|
17
|
+
return chunkECHV2JSY_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 chunkECHV2JSY_cjs.http_service_default.get("utils/countries/");
|
|
25
25
|
};
|
|
26
26
|
var getSubdivisions = async (countryId) => {
|
|
27
|
-
return
|
|
27
|
+
return chunkECHV2JSY_cjs.http_service_default.get(`utils/subdivisions/`, {
|
|
28
28
|
params: { country_id: countryId }
|
|
29
29
|
});
|
|
30
30
|
};
|
|
@@ -37,10 +37,30 @@ var addressFormInitialValues = {
|
|
|
37
37
|
city: "",
|
|
38
38
|
customer_email: ""
|
|
39
39
|
};
|
|
40
|
+
function sanitizePhoneNumber(input, countryCode) {
|
|
41
|
+
let cleaned = input.trim().replace(/\s+/g, "");
|
|
42
|
+
try {
|
|
43
|
+
const callingCode = libphonenumberJs.getCountryCallingCode(countryCode);
|
|
44
|
+
const prefix = `+${callingCode}`;
|
|
45
|
+
if (cleaned.startsWith(prefix)) {
|
|
46
|
+
cleaned = cleaned.slice(prefix.length);
|
|
47
|
+
} else if (cleaned.startsWith(callingCode)) {
|
|
48
|
+
cleaned = cleaned.slice(callingCode.length);
|
|
49
|
+
}
|
|
50
|
+
} catch {
|
|
51
|
+
if (cleaned.startsWith("+")) {
|
|
52
|
+
cleaned = cleaned.replace(/^\+\d{1,4}/, "");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
cleaned = cleaned.replace(/^0+/, "");
|
|
56
|
+
return cleaned;
|
|
57
|
+
}
|
|
40
58
|
function isValidPhoneNumber(input, countryCode) {
|
|
41
59
|
if (!input) return false;
|
|
42
60
|
const phone = libphonenumberJs.parsePhoneNumberFromString(input, countryCode);
|
|
43
|
-
|
|
61
|
+
if (!phone?.isValid()) return false;
|
|
62
|
+
if (phone.country && phone.country !== countryCode) return false;
|
|
63
|
+
return true;
|
|
44
64
|
}
|
|
45
65
|
var addressValidationSchema = Yup__namespace.object({
|
|
46
66
|
customer_phone: Yup__namespace.string().required("Phone number required").test("is-valid", "Please enter a valid number", function(value) {
|
|
@@ -131,8 +151,13 @@ function buildSubmitPayload(values, country, states) {
|
|
|
131
151
|
customerCountryCode = values.customer_country_code;
|
|
132
152
|
}
|
|
133
153
|
}
|
|
154
|
+
const cleanPhone = sanitizePhoneNumber(
|
|
155
|
+
values.customer_phone,
|
|
156
|
+
values.customer_country_code
|
|
157
|
+
);
|
|
134
158
|
return {
|
|
135
159
|
...formValues,
|
|
160
|
+
customer_phone: cleanPhone,
|
|
136
161
|
country: country?.name || "india",
|
|
137
162
|
country_obj: country?.id || 105,
|
|
138
163
|
customer_country_code: customerCountryCode,
|
|
@@ -151,4 +176,5 @@ exports.encodeAddress = encodeAddress;
|
|
|
151
176
|
exports.isValidPhoneNumber = isValidPhoneNumber;
|
|
152
177
|
exports.loadAddressFormFromSession = loadAddressFormFromSession;
|
|
153
178
|
exports.parseEditAddress = parseEditAddress;
|
|
179
|
+
exports.sanitizePhoneNumber = sanitizePhoneNumber;
|
|
154
180
|
exports.saveAddressFormToSession = saveAddressFormToSession;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cart_default } from './chunk-QAC72HKO.js';
|
|
2
|
-
import { http_service_default } from './chunk-
|
|
2
|
+
import { http_service_default } from './chunk-3SYYP3XV.js';
|
|
3
3
|
import { auth_default } from './chunk-WEMNXIRS.js';
|
|
4
4
|
|
|
5
5
|
// src/api/cart.ts
|
|
@@ -11,7 +11,8 @@ async function getCart(url, addressId) {
|
|
|
11
11
|
total_quantity: 0,
|
|
12
12
|
products_quantity: {},
|
|
13
13
|
cart_count: 0,
|
|
14
|
-
missing_items:
|
|
14
|
+
missing_items: {},
|
|
15
|
+
missing_cart_items: {},
|
|
15
16
|
customization_inputs: [],
|
|
16
17
|
total_coupon_discount: 0,
|
|
17
18
|
variant_discounts: {},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { updateCart, removeFromCart, addToCart, getCart } from './chunk-
|
|
1
|
+
import { updateCart, removeFromCart, addToCart, getCart } from './chunk-U25T7M6S.js';
|
|
2
2
|
import { cart_default } from './chunk-QAC72HKO.js';
|
|
3
3
|
import { auth_default } from './chunk-WEMNXIRS.js';
|
|
4
4
|
import { USER_CRED_TOKEN, USER_CREDENTIALS } from './chunk-BQ256JKN.js';
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunkSMHJRNCR_cjs = require('./chunk-SMHJRNCR.cjs');
|
|
4
|
-
var
|
|
4
|
+
var chunkECHV2JSY_cjs = require('./chunk-ECHV2JSY.cjs');
|
|
5
5
|
var chunkBBRXE57K_cjs = require('./chunk-BBRXE57K.cjs');
|
|
6
6
|
|
|
7
7
|
// src/api/cart.ts
|
|
8
8
|
async function getCart(url, addressId) {
|
|
9
9
|
const localCart = chunkSMHJRNCR_cjs.cart_default.get();
|
|
10
|
-
return chunkBBRXE57K_cjs.auth_default.getUserDetails() ? (await
|
|
10
|
+
return chunkBBRXE57K_cjs.auth_default.getUserDetails() ? (await chunkECHV2JSY_cjs.http_service_default.get(url, { params: { address_id: addressId } })).data : localCart || {
|
|
11
11
|
product_variants: [],
|
|
12
12
|
total_amount: 0,
|
|
13
13
|
total_quantity: 0,
|
|
14
14
|
products_quantity: {},
|
|
15
15
|
cart_count: 0,
|
|
16
|
-
missing_items:
|
|
16
|
+
missing_items: {},
|
|
17
|
+
missing_cart_items: {},
|
|
17
18
|
customization_inputs: [],
|
|
18
19
|
total_coupon_discount: 0,
|
|
19
20
|
variant_discounts: {},
|
|
@@ -23,20 +24,20 @@ async function getCart(url, addressId) {
|
|
|
23
24
|
};
|
|
24
25
|
}
|
|
25
26
|
async function addToCart(product, customizationInputs) {
|
|
26
|
-
return
|
|
27
|
+
return chunkECHV2JSY_cjs.http_service_default.post("/customer/cart/", {
|
|
27
28
|
action: "add",
|
|
28
29
|
cart_items: product,
|
|
29
30
|
customization_inputs: customizationInputs
|
|
30
31
|
});
|
|
31
32
|
}
|
|
32
33
|
async function removeFromCart(product) {
|
|
33
|
-
return
|
|
34
|
+
return chunkECHV2JSY_cjs.http_service_default.post("/customer/cart/", {
|
|
34
35
|
action: "remove",
|
|
35
36
|
cart_items: product
|
|
36
37
|
});
|
|
37
38
|
}
|
|
38
39
|
async function updateCart(product) {
|
|
39
|
-
return
|
|
40
|
+
return chunkECHV2JSY_cjs.http_service_default.post("/customer/cart/", {
|
|
40
41
|
action: "update",
|
|
41
42
|
cart_items: product
|
|
42
43
|
});
|
|
@@ -44,43 +45,43 @@ async function updateCart(product) {
|
|
|
44
45
|
|
|
45
46
|
// src/api/product.ts
|
|
46
47
|
async function getProductList(url, filter) {
|
|
47
|
-
const response = await
|
|
48
|
+
const response = await chunkECHV2JSY_cjs.http_service_default.get(url, {
|
|
48
49
|
params: filter
|
|
49
50
|
});
|
|
50
51
|
return response.data;
|
|
51
52
|
}
|
|
52
53
|
async function getProducts(filter) {
|
|
53
|
-
return
|
|
54
|
+
return chunkECHV2JSY_cjs.http_service_default.get("/inventory/products/", {
|
|
54
55
|
params: { ...filter }
|
|
55
56
|
});
|
|
56
57
|
}
|
|
57
58
|
async function getProductDetail(url, slug) {
|
|
58
|
-
const response = await
|
|
59
|
+
const response = await chunkECHV2JSY_cjs.http_service_default.get(url, {
|
|
59
60
|
params: { variant_slug: slug }
|
|
60
61
|
});
|
|
61
62
|
return response.data;
|
|
62
63
|
}
|
|
63
64
|
async function getProductCategories(url) {
|
|
64
|
-
return await
|
|
65
|
+
return await chunkECHV2JSY_cjs.http_service_default.get(url);
|
|
65
66
|
}
|
|
66
67
|
async function getDigitalProductDownloadLink(variantId) {
|
|
67
|
-
return
|
|
68
|
+
return chunkECHV2JSY_cjs.http_service_default.get("/inventory/digital_product/download/", {
|
|
68
69
|
params: { variant_id: variantId }
|
|
69
70
|
});
|
|
70
71
|
}
|
|
71
72
|
async function updateDigitalProductDownloadLinkCount(variantId, downloadLink) {
|
|
72
|
-
return
|
|
73
|
+
return chunkECHV2JSY_cjs.http_service_default.post("/inventory/digital_product/download/", {
|
|
73
74
|
variant_id: variantId,
|
|
74
75
|
download_link: downloadLink
|
|
75
76
|
});
|
|
76
77
|
}
|
|
77
78
|
async function getCategories(responseType = "flat") {
|
|
78
|
-
return await
|
|
79
|
+
return await chunkECHV2JSY_cjs.http_service_default.get("/inventory/categories/", {
|
|
79
80
|
params: { response_structure: responseType }
|
|
80
81
|
});
|
|
81
82
|
}
|
|
82
83
|
async function getProductDetailBySlug(url, slug) {
|
|
83
|
-
const response = await
|
|
84
|
+
const response = await chunkECHV2JSY_cjs.http_service_default.get(url, {
|
|
84
85
|
params: { variant_slug: slug }
|
|
85
86
|
});
|
|
86
87
|
const product = response.data;
|
|
@@ -96,18 +97,18 @@ async function getProductDetailBySlug(url, slug) {
|
|
|
96
97
|
return product;
|
|
97
98
|
}
|
|
98
99
|
async function notifyProductStock(userDetails) {
|
|
99
|
-
return
|
|
100
|
+
return chunkECHV2JSY_cjs.http_service_default.post("/utils/customer/notify-me/", userDetails);
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
// src/api/wishlist.ts
|
|
103
104
|
async function getWishlist(url) {
|
|
104
|
-
return await
|
|
105
|
+
return await chunkECHV2JSY_cjs.http_service_default.get(url);
|
|
105
106
|
}
|
|
106
107
|
async function addWishlist(productDetails) {
|
|
107
|
-
return
|
|
108
|
+
return chunkECHV2JSY_cjs.http_service_default.post("/customer/wishlist/", productDetails);
|
|
108
109
|
}
|
|
109
110
|
async function removeFromWishlist(product_variants) {
|
|
110
|
-
return
|
|
111
|
+
return chunkECHV2JSY_cjs.http_service_default.post("/customer/wishlist/", {
|
|
111
112
|
action: "remove",
|
|
112
113
|
product_variants
|
|
113
114
|
});
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkECHV2JSY_cjs = require('./chunk-ECHV2JSY.cjs');
|
|
4
4
|
|
|
5
5
|
// src/api/user.ts
|
|
6
6
|
async function getUserDetails(url) {
|
|
7
|
-
const response = await
|
|
7
|
+
const response = await chunkECHV2JSY_cjs.http_service_default.get(url);
|
|
8
8
|
return response.data;
|
|
9
9
|
}
|
|
10
10
|
async function updateUserDetails(userDetails) {
|
|
11
|
-
return
|
|
11
|
+
return chunkECHV2JSY_cjs.http_service_default.patch("/users/store/profile/", { ...userDetails });
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
exports.getUserDetails = getUserDetails;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunkBBRB475I_cjs = require('../chunk-BBRB475I.cjs');
|
|
4
|
-
var
|
|
5
|
-
require('../chunk-
|
|
4
|
+
var chunkJCOOINQF_cjs = require('../chunk-JCOOINQF.cjs');
|
|
5
|
+
require('../chunk-RDUT4W3B.cjs');
|
|
6
6
|
var chunk4CVKE6CC_cjs = require('../chunk-4CVKE6CC.cjs');
|
|
7
|
-
require('../chunk-
|
|
8
|
-
require('../chunk-
|
|
7
|
+
require('../chunk-TB72NPRM.cjs');
|
|
8
|
+
require('../chunk-ECHV2JSY.cjs');
|
|
9
9
|
require('../chunk-BBRXE57K.cjs');
|
|
10
10
|
require('../chunk-NE3ZHELZ.cjs');
|
|
11
11
|
require('../chunk-N3CTXRFT.cjs');
|
|
@@ -343,7 +343,7 @@ var AddressForm = react.forwardRef(
|
|
|
343
343
|
handlePhoneChange,
|
|
344
344
|
isSubmitting,
|
|
345
345
|
isEditing
|
|
346
|
-
} =
|
|
346
|
+
} = chunkJCOOINQF_cjs.useAddressForm({
|
|
347
347
|
address,
|
|
348
348
|
onSuccess,
|
|
349
349
|
onError,
|
package/dist/components/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { timeFromNow, isExpired } from '../chunk-HSF2D56O.js';
|
|
2
|
-
import { useAddressForm } from '../chunk-
|
|
3
|
-
import '../chunk-
|
|
2
|
+
import { useAddressForm } from '../chunk-ILVGYHNI.js';
|
|
3
|
+
import '../chunk-ZGMLOLTC.js';
|
|
4
4
|
import { shareLink, convertToCurrency } from '../chunk-YUPBTD4M.js';
|
|
5
|
-
import '../chunk-
|
|
6
|
-
import '../chunk-
|
|
5
|
+
import '../chunk-ELP23UGF.js';
|
|
6
|
+
import '../chunk-3SYYP3XV.js';
|
|
7
7
|
import '../chunk-WEMNXIRS.js';
|
|
8
8
|
import '../chunk-BQ256JKN.js';
|
|
9
9
|
import '../chunk-JQMLHRWL.js';
|