@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,96 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var typescriptCookie = require('typescript-cookie');
|
|
4
|
+
|
|
5
|
+
// src/utils/constants.ts
|
|
6
|
+
var SLICE_STATUS = /* @__PURE__ */ ((SLICE_STATUS2) => {
|
|
7
|
+
SLICE_STATUS2["IDLE"] = "idle";
|
|
8
|
+
SLICE_STATUS2["LOADING"] = "loading";
|
|
9
|
+
SLICE_STATUS2["SUCCESS"] = "success";
|
|
10
|
+
SLICE_STATUS2["FAILURE"] = "failure";
|
|
11
|
+
return SLICE_STATUS2;
|
|
12
|
+
})(SLICE_STATUS || {});
|
|
13
|
+
var pathNameMap = {
|
|
14
|
+
"/checkout/cart": "bag",
|
|
15
|
+
"/checkout/address": "address",
|
|
16
|
+
"/checkout/payment": "payment",
|
|
17
|
+
"/checkout/summary": "summary"
|
|
18
|
+
};
|
|
19
|
+
var USER_CREDENTIALS = "____user_cred_";
|
|
20
|
+
var USER_CART = "____user_cart_";
|
|
21
|
+
var USER_CRED_TOKEN = "____user_cst_";
|
|
22
|
+
var USER_CRED_REFRESH_TOKEN = "____user_csr_";
|
|
23
|
+
var PRODUCT_STATUSES = [
|
|
24
|
+
"confirm",
|
|
25
|
+
"packed",
|
|
26
|
+
"shipped",
|
|
27
|
+
"delivered",
|
|
28
|
+
"cancel",
|
|
29
|
+
" return",
|
|
30
|
+
"refund"
|
|
31
|
+
];
|
|
32
|
+
var DEFAULT_TOAST_CONFIG = {
|
|
33
|
+
position: "bottom-left",
|
|
34
|
+
autoClose: 3e3,
|
|
35
|
+
hideProgressBar: false,
|
|
36
|
+
closeOnClick: true,
|
|
37
|
+
theme: "light",
|
|
38
|
+
progressClassName: "bg-primary"
|
|
39
|
+
};
|
|
40
|
+
var ALLOWED_COUNTRIES = ["AE", "IN", "US"];
|
|
41
|
+
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
|
+
|
|
85
|
+
exports.ADDRESS_FORM_SESSION_KEY = ADDRESS_FORM_SESSION_KEY;
|
|
86
|
+
exports.ALLOWED_COUNTRIES = ALLOWED_COUNTRIES;
|
|
87
|
+
exports.DEFAULT_TOAST_CONFIG = DEFAULT_TOAST_CONFIG;
|
|
88
|
+
exports.PRODUCT_STATUSES = PRODUCT_STATUSES;
|
|
89
|
+
exports.SLICE_STATUS = SLICE_STATUS;
|
|
90
|
+
exports.USER_CART = USER_CART;
|
|
91
|
+
exports.USER_CREDENTIALS = USER_CREDENTIALS;
|
|
92
|
+
exports.USER_CRED_REFRESH_TOKEN = USER_CRED_REFRESH_TOKEN;
|
|
93
|
+
exports.USER_CRED_TOKEN = USER_CRED_TOKEN;
|
|
94
|
+
exports.auth_default = auth_default;
|
|
95
|
+
exports.pathNameMap = pathNameMap;
|
|
96
|
+
exports.setAuthTokenChangeCallback = setAuthTokenChangeCallback;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkUXLUE3HW_cjs = require('./chunk-UXLUE3HW.cjs');
|
|
4
|
+
|
|
5
|
+
// src/api/address.ts
|
|
6
|
+
async function getAddresses(url) {
|
|
7
|
+
const response = await chunkUXLUE3HW_cjs.http_service_default.get(url);
|
|
8
|
+
return response.data;
|
|
9
|
+
}
|
|
10
|
+
async function addAddress(addressDetails) {
|
|
11
|
+
return chunkUXLUE3HW_cjs.http_service_default.post("/store/customer_address/", addressDetails);
|
|
12
|
+
}
|
|
13
|
+
async function updateAddress(addressDetails) {
|
|
14
|
+
return chunkUXLUE3HW_cjs.http_service_default.patch("/store/customer_address/", addressDetails);
|
|
15
|
+
}
|
|
16
|
+
async function deleteAddress(address_id) {
|
|
17
|
+
return chunkUXLUE3HW_cjs.http_service_default.delete("/store/customer_address/", {
|
|
18
|
+
params: { address_id }
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/api/countries.ts
|
|
23
|
+
var getCountries = async () => {
|
|
24
|
+
return chunkUXLUE3HW_cjs.http_service_default.get("utils/countries/");
|
|
25
|
+
};
|
|
26
|
+
var getSubdivisions = async (countryId) => {
|
|
27
|
+
return chunkUXLUE3HW_cjs.http_service_default.get(`utils/subdivisions/`, {
|
|
28
|
+
params: { country_id: countryId }
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
exports.addAddress = addAddress;
|
|
33
|
+
exports.deleteAddress = deleteAddress;
|
|
34
|
+
exports.getAddresses = getAddresses;
|
|
35
|
+
exports.getCountries = getCountries;
|
|
36
|
+
exports.getSubdivisions = getSubdivisions;
|
|
37
|
+
exports.updateAddress = updateAddress;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// src/utils/config.ts
|
|
2
|
+
var _config = null;
|
|
3
|
+
function initConfig(config) {
|
|
4
|
+
_config = config;
|
|
5
|
+
}
|
|
6
|
+
function getConfig() {
|
|
7
|
+
if (!_config) {
|
|
8
|
+
throw new Error(
|
|
9
|
+
"Snapstore config not initialized. Call initConfig() in your app's entry point."
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
return _config;
|
|
13
|
+
}
|
|
14
|
+
var getPublicApiEndpoint = () => getConfig().publicApiEndpoint;
|
|
15
|
+
var getApiEndpoint = () => getConfig().apiEndpoint;
|
|
16
|
+
var getStoreId = () => getConfig().storeId || "";
|
|
17
|
+
var getSecretKey = () => getConfig().secretKey || "alohomora";
|
|
18
|
+
var getCloudFront = () => getConfig().cloudFront;
|
|
19
|
+
var getPhonePeApiEndpoint = () => getConfig().phonePeApiEndpoint;
|
|
20
|
+
|
|
21
|
+
export { getApiEndpoint, getCloudFront, getConfig, getPhonePeApiEndpoint, getPublicApiEndpoint, getSecretKey, getStoreId, initConfig };
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/utils/pixelEvents.ts
|
|
4
|
+
var pixelEvents = {
|
|
5
|
+
/**
|
|
6
|
+
* Track when a user views a product
|
|
7
|
+
*/
|
|
8
|
+
productView: (product) => {
|
|
9
|
+
if (!window.fbq) return;
|
|
10
|
+
try {
|
|
11
|
+
window.fbq("track", "product_viewed", {
|
|
12
|
+
content_slug: product.slug,
|
|
13
|
+
content_name: product.name,
|
|
14
|
+
content_type: "product",
|
|
15
|
+
currency: window.currency_code || "INR",
|
|
16
|
+
price: Number(product.selling_price),
|
|
17
|
+
attributes: product.attributes,
|
|
18
|
+
value: Number(product.selling_price)
|
|
19
|
+
});
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.error("Facebook Pixel ViewContent Event Error:", error);
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
/**
|
|
25
|
+
* Track when a product is added to cart
|
|
26
|
+
*/
|
|
27
|
+
addToCart: (product, quantity = 1) => {
|
|
28
|
+
if (!window.fbq) return;
|
|
29
|
+
try {
|
|
30
|
+
window.fbq("track", "product_added_to_cart", {
|
|
31
|
+
content_slug: product.slug,
|
|
32
|
+
content_name: product.name,
|
|
33
|
+
content_type: "product",
|
|
34
|
+
price: Number(product.selling_price) * quantity,
|
|
35
|
+
num_items: quantity,
|
|
36
|
+
attributes: product.attributes
|
|
37
|
+
});
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error("Facebook Pixel AddToCart Event Error:", error);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
removeFromCart: (product) => {
|
|
43
|
+
if (!window.fbq) return;
|
|
44
|
+
try {
|
|
45
|
+
window.fbq("track", "product_removed_from_cart", {
|
|
46
|
+
content_slug: product.slug,
|
|
47
|
+
content_name: product.name,
|
|
48
|
+
content_type: "product",
|
|
49
|
+
price: Number(product.selling_price),
|
|
50
|
+
attributes: product.attributes
|
|
51
|
+
});
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error("Facebook Pixel RemoveFromCart Event Error:", error);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
/**
|
|
57
|
+
* Track when a product is added to wishlist
|
|
58
|
+
*/
|
|
59
|
+
addToWishlist: (product) => {
|
|
60
|
+
if (!window.fbq) return;
|
|
61
|
+
try {
|
|
62
|
+
window.fbq("track", "product_added_to_wishlist", {
|
|
63
|
+
content_slug: product.slug,
|
|
64
|
+
content_name: product.name,
|
|
65
|
+
content_type: "product",
|
|
66
|
+
price: Number(product.selling_price),
|
|
67
|
+
attributes: product.attributes
|
|
68
|
+
});
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.error("Facebook Pixel AddToWishlist Event Error:", error);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
/**
|
|
74
|
+
* Track when user initiates checkout
|
|
75
|
+
*/
|
|
76
|
+
initiateCheckout: (orderSummary, paymentMethod) => {
|
|
77
|
+
if (!window.fbq) return;
|
|
78
|
+
try {
|
|
79
|
+
window.fbq("track", "checkout_started", {
|
|
80
|
+
order_number: orderSummary.order_number,
|
|
81
|
+
content_type: "product",
|
|
82
|
+
currency: window.currency_code || "INR",
|
|
83
|
+
price: orderSummary.total_amount,
|
|
84
|
+
value: orderSummary.total_amount,
|
|
85
|
+
num_items: orderSummary.purchased_products.length,
|
|
86
|
+
contents: orderSummary.purchased_products.map((item) => ({
|
|
87
|
+
name: item.product_variant_name,
|
|
88
|
+
quantity: item.quantity,
|
|
89
|
+
item_price: Number(item.total_price),
|
|
90
|
+
sku: item.product_variant_sku
|
|
91
|
+
})),
|
|
92
|
+
payment_method: paymentMethod
|
|
93
|
+
});
|
|
94
|
+
} catch (error) {
|
|
95
|
+
console.error("Facebook Pixel InitiateCheckout Event Error:", error);
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
/**
|
|
99
|
+
* Track successful purchases
|
|
100
|
+
*/
|
|
101
|
+
purchase: (orderSummary) => {
|
|
102
|
+
if (!window.fbq) return;
|
|
103
|
+
try {
|
|
104
|
+
window.fbq("track", "purchase", {
|
|
105
|
+
content_ids: [orderSummary.order_number],
|
|
106
|
+
order_number: orderSummary.order_number,
|
|
107
|
+
content_type: "product",
|
|
108
|
+
currency: window.currency_code || "INR",
|
|
109
|
+
price: orderSummary.total_amount,
|
|
110
|
+
value: orderSummary.total_amount,
|
|
111
|
+
num_items: orderSummary.purchased_products.length,
|
|
112
|
+
contents: orderSummary.purchased_products.map((item) => ({
|
|
113
|
+
name: item.product_variant_name,
|
|
114
|
+
quantity: item.quantity,
|
|
115
|
+
item_price: Number(item.total_price),
|
|
116
|
+
sku: item.product_variant_sku
|
|
117
|
+
}))
|
|
118
|
+
});
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.error("Facebook Pixel Purchase Event Error:", error);
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
/**
|
|
124
|
+
* Track search events
|
|
125
|
+
*/
|
|
126
|
+
search: (searchTerm, resultCount) => {
|
|
127
|
+
if (!window.fbq) return;
|
|
128
|
+
try {
|
|
129
|
+
window.fbq("track", "search_submitted", {
|
|
130
|
+
search_string: searchTerm,
|
|
131
|
+
content_type: "product",
|
|
132
|
+
success: resultCount > 0,
|
|
133
|
+
num_results: resultCount
|
|
134
|
+
});
|
|
135
|
+
} catch (error) {
|
|
136
|
+
console.error("Facebook Pixel Search Event Error:", error);
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
/**
|
|
140
|
+
* Track when a user views their cart
|
|
141
|
+
*/
|
|
142
|
+
cartView: (cart) => {
|
|
143
|
+
if (!window.fbq) return;
|
|
144
|
+
try {
|
|
145
|
+
window.fbq("track", "cart_viewed", {
|
|
146
|
+
content_type: "cart",
|
|
147
|
+
value: cart.total_amount,
|
|
148
|
+
number_of_products: cart.total_quantity
|
|
149
|
+
});
|
|
150
|
+
} catch (error) {
|
|
151
|
+
console.error("Facebook Pixel Cart View Event Error:", error);
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
/**
|
|
155
|
+
* Track when a user completes a checkout
|
|
156
|
+
*/
|
|
157
|
+
checkoutCompleted: (orderSummary) => {
|
|
158
|
+
if (!window.fbq) return;
|
|
159
|
+
try {
|
|
160
|
+
window.fbq("track", "checkout_completed", {
|
|
161
|
+
content_ids: [orderSummary.order_number],
|
|
162
|
+
order_number: orderSummary.order_number,
|
|
163
|
+
content_type: "product",
|
|
164
|
+
currency: "INR",
|
|
165
|
+
value: orderSummary.total_amount,
|
|
166
|
+
num_items: orderSummary.purchased_products.length,
|
|
167
|
+
contents: orderSummary.purchased_products.map((item) => ({
|
|
168
|
+
name: item.product_variant_name,
|
|
169
|
+
quantity: item.quantity,
|
|
170
|
+
item_price: Number(item.total_price),
|
|
171
|
+
sku: item.product_variant_sku
|
|
172
|
+
}))
|
|
173
|
+
});
|
|
174
|
+
} catch (error) {
|
|
175
|
+
console.error("Facebook Pixel Checkout Completed Event Error:", error);
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
addressInfoSubmitted: () => {
|
|
179
|
+
if (!window.fbq) return;
|
|
180
|
+
try {
|
|
181
|
+
window.fbq("track", "checkout_address_info_submitted", {
|
|
182
|
+
content_type: "address"
|
|
183
|
+
});
|
|
184
|
+
} catch (error) {
|
|
185
|
+
console.error(
|
|
186
|
+
"Facebook Pixel Address Info Submitted Event Error:",
|
|
187
|
+
error
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
checkoutStarted: (cart) => {
|
|
192
|
+
if (!window.fbq) return;
|
|
193
|
+
try {
|
|
194
|
+
window.fbq("track", "checkout_started", {
|
|
195
|
+
value: cart.total_amount,
|
|
196
|
+
number_of_products: cart.total_quantity
|
|
197
|
+
});
|
|
198
|
+
} catch (error) {
|
|
199
|
+
console.error("Facebook Pixel Checkout Started Event Error:", error);
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
pageViewed: () => {
|
|
203
|
+
if (!window.fbq) return;
|
|
204
|
+
try {
|
|
205
|
+
window.fbq("track", "page_viewed");
|
|
206
|
+
} catch (error) {
|
|
207
|
+
console.error("Facebook Pixel Page Viewed Event Error:", error);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
exports.pixelEvents = pixelEvents;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkGQTO5ZE2_cjs = require('./chunk-GQTO5ZE2.cjs');
|
|
4
|
+
var libphonenumberJs = require('libphonenumber-js');
|
|
5
|
+
var Yup = require('yup');
|
|
6
|
+
|
|
7
|
+
function _interopNamespace(e) {
|
|
8
|
+
if (e && e.__esModule) return e;
|
|
9
|
+
var n = Object.create(null);
|
|
10
|
+
if (e) {
|
|
11
|
+
Object.keys(e).forEach(function (k) {
|
|
12
|
+
if (k !== 'default') {
|
|
13
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return e[k]; }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
n.default = e;
|
|
22
|
+
return Object.freeze(n);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var Yup__namespace = /*#__PURE__*/_interopNamespace(Yup);
|
|
26
|
+
|
|
27
|
+
var IP_API_CACHE_KEY = "ip_geolocation_data";
|
|
28
|
+
var addressFormInitialValues = {
|
|
29
|
+
customer_phone: "",
|
|
30
|
+
customer_country_code: "IN",
|
|
31
|
+
customer_name: "",
|
|
32
|
+
pincode: "",
|
|
33
|
+
state_obj: "",
|
|
34
|
+
address: "",
|
|
35
|
+
street_name: "",
|
|
36
|
+
area: "",
|
|
37
|
+
city: "",
|
|
38
|
+
customer_email: ""
|
|
39
|
+
};
|
|
40
|
+
function isValidPhoneNumber(input, countryCode) {
|
|
41
|
+
if (!input) return false;
|
|
42
|
+
const phone = libphonenumberJs.parsePhoneNumberFromString(input, countryCode);
|
|
43
|
+
return phone?.isValid() ?? false;
|
|
44
|
+
}
|
|
45
|
+
var addressValidationSchema = Yup__namespace.object({
|
|
46
|
+
customer_phone: Yup__namespace.string().required("Phone number required").test("is-valid", "Please enter a valid number", function(value) {
|
|
47
|
+
const { customer_country_code } = this.parent;
|
|
48
|
+
if (!value) return false;
|
|
49
|
+
return isValidPhoneNumber(value, customer_country_code);
|
|
50
|
+
}),
|
|
51
|
+
customer_name: Yup__namespace.string().required("Name is required"),
|
|
52
|
+
pincode: Yup__namespace.string().when("customer_country_code", {
|
|
53
|
+
is: "AE",
|
|
54
|
+
then: (schema) => schema.optional(),
|
|
55
|
+
otherwise: (schema) => schema.required("Pincode is required")
|
|
56
|
+
}),
|
|
57
|
+
state_obj: Yup__namespace.string().required("State is required"),
|
|
58
|
+
address: Yup__namespace.string().required("Address is required"),
|
|
59
|
+
street_name: Yup__namespace.string().optional(),
|
|
60
|
+
area: Yup__namespace.string().optional(),
|
|
61
|
+
city: Yup__namespace.string().required("City/District is required"),
|
|
62
|
+
customer_email: Yup__namespace.string().email("Please enter a valid email").required("Email is required")
|
|
63
|
+
});
|
|
64
|
+
function encodeAddress(id, city) {
|
|
65
|
+
return `${btoa(id.toString())}-${btoa(city)}`;
|
|
66
|
+
}
|
|
67
|
+
function decodeAddress(encoded) {
|
|
68
|
+
const [encodedId, encodedCity] = encoded.split("-");
|
|
69
|
+
return {
|
|
70
|
+
id: Number(atob(encodedId)),
|
|
71
|
+
city: atob(encodedCity)
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function saveAddressFormToSession(values) {
|
|
75
|
+
try {
|
|
76
|
+
sessionStorage.setItem(chunkGQTO5ZE2_cjs.ADDRESS_FORM_SESSION_KEY, JSON.stringify(values));
|
|
77
|
+
} catch {
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function loadAddressFormFromSession() {
|
|
81
|
+
try {
|
|
82
|
+
const stored = sessionStorage.getItem(chunkGQTO5ZE2_cjs.ADDRESS_FORM_SESSION_KEY);
|
|
83
|
+
return stored ? JSON.parse(stored) : null;
|
|
84
|
+
} catch {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function clearAddressFormSession() {
|
|
89
|
+
try {
|
|
90
|
+
sessionStorage.removeItem(chunkGQTO5ZE2_cjs.ADDRESS_FORM_SESSION_KEY);
|
|
91
|
+
} catch {
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function buildAddressPayload(formValues, selectedCountry, states) {
|
|
95
|
+
const selectedState = states.find((s) => s.name === formValues.state_obj);
|
|
96
|
+
return {
|
|
97
|
+
customer_name: formValues.customer_name,
|
|
98
|
+
customer_phone: formValues.customer_phone,
|
|
99
|
+
customer_country_code: formValues.customer_country_code,
|
|
100
|
+
customer_email: formValues.customer_email,
|
|
101
|
+
address: formValues.address,
|
|
102
|
+
street_name: formValues.street_name,
|
|
103
|
+
area: formValues.area,
|
|
104
|
+
city: formValues.city,
|
|
105
|
+
state: selectedState?.state_code || formValues.state_obj,
|
|
106
|
+
state_obj: formValues.state_obj,
|
|
107
|
+
country: selectedCountry.short_code,
|
|
108
|
+
pincode: formValues.pincode
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function parseEditAddress(fullAddress) {
|
|
112
|
+
if (!fullAddress) return { address: "", street_name: "", area: "" };
|
|
113
|
+
const parts = fullAddress.split(",").map((s) => s.trim());
|
|
114
|
+
return {
|
|
115
|
+
address: parts[0] || "",
|
|
116
|
+
street_name: parts[1] || "",
|
|
117
|
+
area: parts[2] || ""
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function buildSubmitPayload(values, country, states) {
|
|
121
|
+
const formValues = { ...values };
|
|
122
|
+
delete formValues.customer;
|
|
123
|
+
const stateName = states.find(
|
|
124
|
+
(s) => s.id === Number(values.state_obj)
|
|
125
|
+
)?.name;
|
|
126
|
+
let customerCountryCode = "";
|
|
127
|
+
if (values.customer_country_code) {
|
|
128
|
+
try {
|
|
129
|
+
customerCountryCode = `+${libphonenumberJs.getCountryCallingCode(values.customer_country_code)}`;
|
|
130
|
+
} catch {
|
|
131
|
+
customerCountryCode = values.customer_country_code;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
...formValues,
|
|
136
|
+
country: country?.name || "india",
|
|
137
|
+
country_obj: country?.id || 105,
|
|
138
|
+
customer_country_code: customerCountryCode,
|
|
139
|
+
state: stateName || values.state_obj
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
exports.IP_API_CACHE_KEY = IP_API_CACHE_KEY;
|
|
144
|
+
exports.addressFormInitialValues = addressFormInitialValues;
|
|
145
|
+
exports.addressValidationSchema = addressValidationSchema;
|
|
146
|
+
exports.buildAddressPayload = buildAddressPayload;
|
|
147
|
+
exports.buildSubmitPayload = buildSubmitPayload;
|
|
148
|
+
exports.clearAddressFormSession = clearAddressFormSession;
|
|
149
|
+
exports.decodeAddress = decodeAddress;
|
|
150
|
+
exports.encodeAddress = encodeAddress;
|
|
151
|
+
exports.isValidPhoneNumber = isValidPhoneNumber;
|
|
152
|
+
exports.loadAddressFormFromSession = loadAddressFormFromSession;
|
|
153
|
+
exports.parseEditAddress = parseEditAddress;
|
|
154
|
+
exports.saveAddressFormToSession = saveAddressFormToSession;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkUXLUE3HW_cjs = require('./chunk-UXLUE3HW.cjs');
|
|
4
|
+
|
|
5
|
+
// src/api/user.ts
|
|
6
|
+
async function getUserDetails(url) {
|
|
7
|
+
const response = await chunkUXLUE3HW_cjs.http_service_default.get(url);
|
|
8
|
+
return response.data;
|
|
9
|
+
}
|
|
10
|
+
async function updateUserDetails(userDetails) {
|
|
11
|
+
return chunkUXLUE3HW_cjs.http_service_default.patch("/users/store/profile/", { ...userDetails });
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports.getUserDetails = getUserDetails;
|
|
15
|
+
exports.updateUserDetails = updateUserDetails;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { http_service_default } from './chunk-GB3HW6DM.js';
|
|
2
|
+
|
|
3
|
+
// src/api/address.ts
|
|
4
|
+
async function getAddresses(url) {
|
|
5
|
+
const response = await http_service_default.get(url);
|
|
6
|
+
return response.data;
|
|
7
|
+
}
|
|
8
|
+
async function addAddress(addressDetails) {
|
|
9
|
+
return http_service_default.post("/store/customer_address/", addressDetails);
|
|
10
|
+
}
|
|
11
|
+
async function updateAddress(addressDetails) {
|
|
12
|
+
return http_service_default.patch("/store/customer_address/", addressDetails);
|
|
13
|
+
}
|
|
14
|
+
async function deleteAddress(address_id) {
|
|
15
|
+
return http_service_default.delete("/store/customer_address/", {
|
|
16
|
+
params: { address_id }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// src/api/countries.ts
|
|
21
|
+
var getCountries = async () => {
|
|
22
|
+
return http_service_default.get("utils/countries/");
|
|
23
|
+
};
|
|
24
|
+
var getSubdivisions = async (countryId) => {
|
|
25
|
+
return http_service_default.get(`utils/subdivisions/`, {
|
|
26
|
+
params: { country_id: countryId }
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { addAddress, deleteAddress, getAddresses, getCountries, getSubdivisions, updateAddress };
|