@storepecker/storefront-core 2.9.1 → 2.10.1
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-BdIB6IuI.d.cts +42 -0
- package/dist/address-BdIB6IuI.d.ts +42 -0
- package/dist/api/index.cjs +36 -32
- package/dist/api/index.d.cts +20 -17
- package/dist/api/index.d.ts +20 -17
- package/dist/api/index.js +4 -4
- package/dist/{buy-now-BqVWXyy8.d.cts → buy-now-CDug6LJ_.d.ts} +2 -2
- package/dist/{buy-now-DFdnuLjO.d.ts → buy-now-DrKY5_9R.d.cts} +2 -2
- package/dist/checkout/index.cjs +163 -76
- package/dist/checkout/index.d.cts +37 -26
- package/dist/checkout/index.d.ts +37 -26
- package/dist/checkout/index.js +50 -64
- package/dist/checkout-totals-CbmXM9L7.d.cts +220 -0
- package/dist/checkout-totals-DU8l-Wyb.d.ts +220 -0
- package/dist/{chunk-IG4BW3ZB.cjs → chunk-32X4SWN4.cjs} +3 -3
- package/dist/{chunk-NQZ5GUOG.cjs → chunk-3YPE6UPC.cjs} +24 -16
- package/dist/{chunk-RDUT4W3B.cjs → chunk-6APRQ2ED.cjs} +4 -1
- package/dist/{chunk-ICKTXS6B.js → chunk-6IXTFZFS.js} +3 -3
- package/dist/{chunk-7M5CVYZJ.js → chunk-A7EI7XLU.js} +8 -1
- package/dist/chunk-DZPK7GPG.js +601 -0
- package/dist/{chunk-TH7OAMGC.js → chunk-E4D4XOAE.js} +24 -16
- package/dist/{chunk-NRPK5GCJ.cjs → chunk-EFYAFXIS.cjs} +3 -3
- package/dist/{chunk-CBKJ3Y2I.js → chunk-EWZ7TGI7.js} +11 -1
- package/dist/{chunk-5XVHYPOC.js → chunk-FF5N7PTB.js} +1 -1
- package/dist/{chunk-NOT6VKXA.cjs → chunk-H6UZTS5O.cjs} +67 -23
- package/dist/{chunk-XFOUNOKO.cjs → chunk-KNG4OMS5.cjs} +8 -0
- package/dist/{chunk-ZAWZ3RB6.js → chunk-NNE42NMP.js} +1 -1
- package/dist/chunk-PN6KH5PX.cjs +661 -0
- package/dist/{chunk-QQHQTBAM.js → chunk-QSRVMOXT.js} +48 -6
- package/dist/{chunk-W6BDMNSU.js → chunk-QVO56X4E.js} +1 -1
- package/dist/{chunk-6LS5F4R3.cjs → chunk-SGJUMI3M.cjs} +11 -0
- package/dist/{chunk-YLLAP3H2.cjs → chunk-SGKLMS7W.cjs} +2 -2
- package/dist/{chunk-ZGMLOLTC.js → chunk-VRZRV2BR.js} +4 -1
- package/dist/{chunk-IVKJJLG7.cjs → chunk-WWJAPKRQ.cjs} +8 -8
- package/dist/{collections-CXgOv5_G.d.cts → collections-CKNFcE2d.d.cts} +1 -1
- package/dist/{collections-CNh2OGbl.d.ts → collections-CtRKsWVx.d.ts} +1 -1
- package/dist/components/address-form.cjs +6 -6
- package/dist/components/address-form.d.cts +10 -6
- package/dist/components/address-form.d.ts +10 -6
- package/dist/components/address-form.js +5 -5
- package/dist/components/digital-product-download-modal.d.cts +2 -2
- package/dist/components/digital-product-download-modal.d.ts +2 -2
- package/dist/components/index.cjs +8 -8
- package/dist/components/index.d.cts +6 -7
- package/dist/components/index.d.ts +6 -7
- package/dist/components/index.js +6 -6
- package/dist/components/search-dropdown.d.cts +4 -4
- package/dist/components/search-dropdown.d.ts +4 -4
- package/dist/components/share-button.cjs +3 -3
- package/dist/components/share-button.d.cts +1 -1
- package/dist/components/share-button.d.ts +1 -1
- package/dist/components/share-button.js +2 -2
- package/dist/components/theme-data-initializer.d.cts +4 -5
- package/dist/components/theme-data-initializer.d.ts +4 -5
- package/dist/hooks/index.cjs +672 -44
- package/dist/hooks/index.d.cts +239 -13
- package/dist/hooks/index.d.ts +239 -13
- package/dist/hooks/index.js +630 -11
- package/dist/{instagram-DalreBu6.d.cts → instagram-CSzrxk10.d.cts} +8 -2
- package/dist/{instagram-BADLnNQ3.d.ts → instagram-CagTLmyq.d.ts} +8 -2
- package/dist/models/index.d.cts +8 -8
- package/dist/models/index.d.ts +8 -8
- package/dist/orders-B6BmHCJN.d.ts +337 -0
- package/dist/orders-ZKP0lqRN.d.cts +337 -0
- package/dist/pincode-8u7yWLpQ.d.cts +29 -0
- package/dist/pincode-8u7yWLpQ.d.ts +29 -0
- package/dist/{pixelEvents-LsealscG.d.ts → pixelEvents-DqJ_CEEr.d.ts} +4 -4
- package/dist/{pixelEvents-BtEO5QAR.d.cts → pixelEvents-bahgVW4_.d.cts} +4 -4
- package/dist/{product-D9liEtl4.d.cts → product-D4kol-Z-.d.cts} +26 -2
- package/dist/{product-D9liEtl4.d.ts → product-D4kol-Z-.d.ts} +26 -2
- package/dist/store/index.cjs +20 -30
- package/dist/store/index.d.cts +21 -7
- package/dist/store/index.d.ts +21 -7
- package/dist/store/index.js +9 -26
- package/dist/{useAddressForm-DGbEn91-.d.cts → useAddressForm-fMOb5Z-a.d.ts} +6 -1
- package/dist/{useAddressForm-cO3Au33k.d.ts → useAddressForm-wleIo78M.d.cts} +6 -1
- package/dist/utils/index.cjs +60 -56
- package/dist/utils/index.d.cts +24 -9
- package/dist/utils/index.d.ts +24 -9
- package/dist/utils/index.js +4 -4
- package/dist/{wishlist-Cj0sQxiY.d.ts → wishlist-L3fM5-ie.d.ts} +1 -1
- package/dist/{wishlist-BakHvIFN.d.cts → wishlist-_0x0r1jt.d.cts} +1 -1
- package/package.json +1 -1
- package/dist/address-DwBZHzbI.d.cts +0 -19
- package/dist/address-DwBZHzbI.d.ts +0 -19
- package/dist/cart-DZq1ZEnE.d.ts +0 -153
- package/dist/cart-DwMFBmpC.d.cts +0 -153
- package/dist/chunk-34Y7Y5FU.cjs +0 -246
- package/dist/chunk-VPTN4YXD.js +0 -232
- package/dist/orders-B3G4CyhH.d.cts +0 -166
- package/dist/orders-Bl-Slh72.d.ts +0 -166
|
@@ -0,0 +1,661 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkKNG4OMS5_cjs = require('./chunk-KNG4OMS5.cjs');
|
|
4
|
+
var chunkNSAHGMS7_cjs = require('./chunk-NSAHGMS7.cjs');
|
|
5
|
+
var chunkH6FJYRO3_cjs = require('./chunk-H6FJYRO3.cjs');
|
|
6
|
+
var chunkLJUGNSQQ_cjs = require('./chunk-LJUGNSQQ.cjs');
|
|
7
|
+
var chunkN3CTXRFT_cjs = require('./chunk-N3CTXRFT.cjs');
|
|
8
|
+
var axios = require('axios');
|
|
9
|
+
var libphonenumberJs = require('libphonenumber-js');
|
|
10
|
+
var Yup = require('yup');
|
|
11
|
+
|
|
12
|
+
function _interopNamespace(e) {
|
|
13
|
+
if (e && e.__esModule) return e;
|
|
14
|
+
var n = Object.create(null);
|
|
15
|
+
if (e) {
|
|
16
|
+
Object.keys(e).forEach(function (k) {
|
|
17
|
+
if (k !== 'default') {
|
|
18
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
19
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return e[k]; }
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
n.default = e;
|
|
27
|
+
return Object.freeze(n);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var Yup__namespace = /*#__PURE__*/_interopNamespace(Yup);
|
|
31
|
+
|
|
32
|
+
// src/checkout/payment.ts
|
|
33
|
+
function openRazorpayCheckout(order, callbacks, paymentOptions) {
|
|
34
|
+
if (!order) return;
|
|
35
|
+
chunkNSAHGMS7_cjs.pixelEvents.initiateCheckout(order, "razorpay");
|
|
36
|
+
const {
|
|
37
|
+
razorpay_order_id,
|
|
38
|
+
razorpay_public_token,
|
|
39
|
+
total_amount,
|
|
40
|
+
razorpay_order_currency,
|
|
41
|
+
store_color_scheme,
|
|
42
|
+
store_logo,
|
|
43
|
+
store_name,
|
|
44
|
+
customer_name,
|
|
45
|
+
customer_phone,
|
|
46
|
+
customer_email
|
|
47
|
+
} = order;
|
|
48
|
+
const cloudFront = chunkN3CTXRFT_cjs.getCloudFront();
|
|
49
|
+
const options = {
|
|
50
|
+
key: razorpay_public_token,
|
|
51
|
+
amount: Number(total_amount) * 100,
|
|
52
|
+
currency: razorpay_order_currency,
|
|
53
|
+
name: store_name,
|
|
54
|
+
image: cloudFront ? `${cloudFront}${store_logo}` : store_logo,
|
|
55
|
+
order_id: razorpay_order_id,
|
|
56
|
+
handler: async (response) => {
|
|
57
|
+
handleRazorpaySuccess(
|
|
58
|
+
{
|
|
59
|
+
razorpay_payment_id: response.razorpay_payment_id,
|
|
60
|
+
razorpay_subscription_id: response.razorpay_subscription_id,
|
|
61
|
+
razorpay_signature: response.razorpay_signature,
|
|
62
|
+
order_id: order.id,
|
|
63
|
+
razorpay_order_id,
|
|
64
|
+
payment_id: response.razorpay_payment_id
|
|
65
|
+
},
|
|
66
|
+
order,
|
|
67
|
+
callbacks,
|
|
68
|
+
paymentOptions
|
|
69
|
+
);
|
|
70
|
+
},
|
|
71
|
+
theme: {
|
|
72
|
+
color: store_color_scheme?.primary,
|
|
73
|
+
accent: store_color_scheme?.secondary
|
|
74
|
+
},
|
|
75
|
+
prefill: {
|
|
76
|
+
name: customer_name,
|
|
77
|
+
email: customer_email?.endsWith("@test.com") ? void 0 : customer_email,
|
|
78
|
+
phone: customer_phone
|
|
79
|
+
},
|
|
80
|
+
modal: {
|
|
81
|
+
ondismiss: () => handleRazorpayFail(
|
|
82
|
+
order,
|
|
83
|
+
callbacks,
|
|
84
|
+
{
|
|
85
|
+
description: "User cancelled the payment manually",
|
|
86
|
+
reason: "user_cancelled_payment_manually"
|
|
87
|
+
},
|
|
88
|
+
{ isPublic: paymentOptions?.isPublic }
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const paymentObject = new window.Razorpay(options);
|
|
93
|
+
paymentObject.on("payment.failed", (response) => {
|
|
94
|
+
handleRazorpayFail(order, callbacks, response?.error, {
|
|
95
|
+
isPublic: paymentOptions?.isPublic
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
paymentObject.open();
|
|
99
|
+
}
|
|
100
|
+
async function handleRazorpaySuccess(data, order, callbacks, options) {
|
|
101
|
+
try {
|
|
102
|
+
callbacks.onPaymentStart?.();
|
|
103
|
+
if (options?.isPublic) {
|
|
104
|
+
await chunkH6FJYRO3_cjs.razorpayPublicOrderSuccess({ ...data, order_number: order.order_number });
|
|
105
|
+
} else {
|
|
106
|
+
await chunkH6FJYRO3_cjs.razorpayOrderSuccess(data);
|
|
107
|
+
}
|
|
108
|
+
chunkNSAHGMS7_cjs.pixelEvents.purchase(order);
|
|
109
|
+
chunkNSAHGMS7_cjs.pixelEvents.checkoutCompleted(order);
|
|
110
|
+
callbacks.onCartReset();
|
|
111
|
+
callbacks.onSuccess(order);
|
|
112
|
+
} catch {
|
|
113
|
+
callbacks.onFailure(order);
|
|
114
|
+
} finally {
|
|
115
|
+
callbacks.onPaymentEnd?.();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async function handleRazorpayFail(order, callbacks, error, options) {
|
|
119
|
+
try {
|
|
120
|
+
const payload = {
|
|
121
|
+
order_id: order.id,
|
|
122
|
+
razorpay_order_id: order.razorpay_order_id,
|
|
123
|
+
error
|
|
124
|
+
};
|
|
125
|
+
options?.isPublic ? await chunkH6FJYRO3_cjs.publicRazorpayOrderFailure(payload) : await chunkH6FJYRO3_cjs.razorpayOrderFail(payload);
|
|
126
|
+
} catch {
|
|
127
|
+
}
|
|
128
|
+
callbacks.onFailure(order);
|
|
129
|
+
}
|
|
130
|
+
function handlePhonepePayment(order, callbacks) {
|
|
131
|
+
if (!order) return;
|
|
132
|
+
chunkNSAHGMS7_cjs.pixelEvents.initiateCheckout(order, "phonepe");
|
|
133
|
+
if (!order.phonepe_redirect_url) {
|
|
134
|
+
callbacks.onFailure(order);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
callbacks.onRedirect(order.phonepe_redirect_url);
|
|
138
|
+
}
|
|
139
|
+
function handleTabbyPayment(order, callbacks) {
|
|
140
|
+
if (!order) return;
|
|
141
|
+
chunkNSAHGMS7_cjs.pixelEvents.initiateCheckout(order, "tabby");
|
|
142
|
+
if (!order.tabby_redirect_url) {
|
|
143
|
+
callbacks.onFailure(order);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
callbacks.onRedirect(order.tabby_redirect_url);
|
|
147
|
+
}
|
|
148
|
+
async function handleCODPayment(order, callbacks, options) {
|
|
149
|
+
if (!order) return;
|
|
150
|
+
try {
|
|
151
|
+
callbacks.onPaymentStart?.();
|
|
152
|
+
chunkNSAHGMS7_cjs.pixelEvents.initiateCheckout(order, "cod");
|
|
153
|
+
if (options?.isPublic) {
|
|
154
|
+
await chunkH6FJYRO3_cjs.publicMakeCODOrder(order.order_number, {
|
|
155
|
+
customer_phone: order.customer_phone,
|
|
156
|
+
customer_email: order.customer_email
|
|
157
|
+
});
|
|
158
|
+
} else {
|
|
159
|
+
await chunkH6FJYRO3_cjs.makeCODOrder(order.id);
|
|
160
|
+
}
|
|
161
|
+
chunkNSAHGMS7_cjs.pixelEvents.purchase(order);
|
|
162
|
+
chunkNSAHGMS7_cjs.pixelEvents.checkoutCompleted(order);
|
|
163
|
+
callbacks.onCartReset();
|
|
164
|
+
callbacks.onSuccess(order);
|
|
165
|
+
} catch {
|
|
166
|
+
callbacks.onFailure(order);
|
|
167
|
+
} finally {
|
|
168
|
+
callbacks.onPaymentEnd?.();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function handleStripePayment(order, callbacks) {
|
|
172
|
+
if (!order) return;
|
|
173
|
+
chunkNSAHGMS7_cjs.pixelEvents.initiateCheckout(order, "stripe");
|
|
174
|
+
if (order.stripe_payment_link_url) {
|
|
175
|
+
callbacks.onRedirect(order.stripe_payment_link_url);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if (order.stripe_client_secret) {
|
|
179
|
+
callbacks.onStripeModalOpen?.(order);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
callbacks.onFailure(order);
|
|
183
|
+
}
|
|
184
|
+
async function handleStripeSuccess(order, paymentIntentId, callbacks, options) {
|
|
185
|
+
try {
|
|
186
|
+
callbacks.onPaymentStart?.();
|
|
187
|
+
const stripeSuccessPayload = {
|
|
188
|
+
order_id: order.id,
|
|
189
|
+
payment_intent_id: paymentIntentId
|
|
190
|
+
};
|
|
191
|
+
if (options?.isPublic) {
|
|
192
|
+
await chunkH6FJYRO3_cjs.stripePublicOrderSuccess(stripeSuccessPayload);
|
|
193
|
+
} else {
|
|
194
|
+
await chunkH6FJYRO3_cjs.stripeOrderSuccess(stripeSuccessPayload);
|
|
195
|
+
}
|
|
196
|
+
chunkNSAHGMS7_cjs.pixelEvents.purchase(order);
|
|
197
|
+
chunkNSAHGMS7_cjs.pixelEvents.checkoutCompleted(order);
|
|
198
|
+
callbacks.onCartReset();
|
|
199
|
+
callbacks.onSuccess(order);
|
|
200
|
+
} catch {
|
|
201
|
+
callbacks.onFailure(order);
|
|
202
|
+
} finally {
|
|
203
|
+
callbacks.onPaymentEnd?.();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function processPayment(order, paymentMethod, callbacks, options) {
|
|
207
|
+
if (paymentMethod === "cod") {
|
|
208
|
+
handleCODPayment(order, callbacks, options);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (order.tabby_redirect_url) {
|
|
212
|
+
handleTabbyPayment(order, callbacks);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (order.stripe_client_secret || order.stripe_payment_link_url) {
|
|
216
|
+
handleStripePayment(order, callbacks);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (order.razorpay_public_token) {
|
|
220
|
+
openRazorpayCheckout(order, callbacks, options);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
handlePhonepePayment(order, callbacks);
|
|
224
|
+
}
|
|
225
|
+
async function fetchAvailableCoupons() {
|
|
226
|
+
const response = await chunkKNG4OMS5_cjs.getCoupons();
|
|
227
|
+
return response.data;
|
|
228
|
+
}
|
|
229
|
+
async function fetchAppliedCoupon() {
|
|
230
|
+
try {
|
|
231
|
+
const response = await chunkKNG4OMS5_cjs.getAppliedCoupon();
|
|
232
|
+
return response.data || null;
|
|
233
|
+
} catch {
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
async function applyCheckoutCoupon(code, callbacks) {
|
|
238
|
+
try {
|
|
239
|
+
const response = await chunkKNG4OMS5_cjs.applyCoupon(code);
|
|
240
|
+
if (response.data?.coupon) {
|
|
241
|
+
await callbacks.onCartRefresh();
|
|
242
|
+
return response.data.coupon;
|
|
243
|
+
}
|
|
244
|
+
throw new Error("Failed to apply coupon");
|
|
245
|
+
} catch (error) {
|
|
246
|
+
if (error instanceof axios.AxiosError) {
|
|
247
|
+
throw new Error(error.response?.data?.detail || "Failed to apply coupon");
|
|
248
|
+
}
|
|
249
|
+
throw error;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
async function removeCheckoutCoupon(couponCode, callbacks) {
|
|
253
|
+
await chunkKNG4OMS5_cjs.removeCoupon(couponCode);
|
|
254
|
+
await callbacks.onCartRefresh();
|
|
255
|
+
}
|
|
256
|
+
function isValidNumber(input, code) {
|
|
257
|
+
if (!libphonenumberJs.isSupportedCountry(code)) return false;
|
|
258
|
+
const phone = libphonenumberJs.parsePhoneNumberFromString(input, code);
|
|
259
|
+
if (!phone || !phone.isValid()) return false;
|
|
260
|
+
return phone.countryCallingCode === libphonenumberJs.getCountryCallingCode(code);
|
|
261
|
+
}
|
|
262
|
+
function detectForeignPhone(raw, countryCode) {
|
|
263
|
+
const value = raw.replace(/[^\d+]/g, "");
|
|
264
|
+
if (!value.startsWith("+")) return null;
|
|
265
|
+
const parsed = libphonenumberJs.parsePhoneNumberFromString(value);
|
|
266
|
+
if (!parsed?.isValid() || !parsed.country) return null;
|
|
267
|
+
const selected = countryCode && libphonenumberJs.isSupportedCountry(countryCode) ? libphonenumberJs.getCountryCallingCode(countryCode) : "";
|
|
268
|
+
if (parsed.countryCallingCode === selected) return null;
|
|
269
|
+
return { country: parsed.country, nationalNumber: parsed.nationalNumber };
|
|
270
|
+
}
|
|
271
|
+
function sanitizePhoneInput(raw, countryCode) {
|
|
272
|
+
const value = raw.replace(/[^\d+]/g, "");
|
|
273
|
+
const callingCode = countryCode && libphonenumberJs.isSupportedCountry(countryCode) ? libphonenumberJs.getCountryCallingCode(countryCode) : "";
|
|
274
|
+
if (value.startsWith("+")) {
|
|
275
|
+
const parsed = libphonenumberJs.parsePhoneNumberFromString(value);
|
|
276
|
+
if (parsed?.nationalNumber) {
|
|
277
|
+
if (callingCode && parsed.countryCallingCode !== callingCode) return value;
|
|
278
|
+
return parsed.nationalNumber;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
let digits = value.replace(/\D/g, "");
|
|
282
|
+
if (digits.startsWith("00")) digits = digits.slice(2);
|
|
283
|
+
if (callingCode && digits.startsWith(callingCode)) {
|
|
284
|
+
const parsed = libphonenumberJs.parsePhoneNumberFromString("+" + digits);
|
|
285
|
+
if (parsed?.isValid()) return parsed.nationalNumber;
|
|
286
|
+
}
|
|
287
|
+
return digits.replace(/^0+/, "");
|
|
288
|
+
}
|
|
289
|
+
var ADDRESS_DATA_URL = "https://chromium-i18n.appspot.com/ssl-address/data";
|
|
290
|
+
var CACHE_PREFIX = "address_format_v1_";
|
|
291
|
+
var CACHE_HOURS = 24 * 7;
|
|
292
|
+
var FETCH_TIMEOUT_MS = 5e3;
|
|
293
|
+
var OVERRIDES = {
|
|
294
|
+
IN: {
|
|
295
|
+
postalRequired: true,
|
|
296
|
+
postalLabel: "PIN code",
|
|
297
|
+
postalPattern: /^[1-9]\d{5}$/,
|
|
298
|
+
postalStrict: true,
|
|
299
|
+
postalInputMode: "numeric",
|
|
300
|
+
postalMaxLength: 6,
|
|
301
|
+
line1Label: "House number, street, area",
|
|
302
|
+
line2Label: "Flat, building"
|
|
303
|
+
},
|
|
304
|
+
US: {
|
|
305
|
+
postalRequired: true,
|
|
306
|
+
postalPattern: /^\d{5}(?:[ -]\d{4})?$/,
|
|
307
|
+
postalStrict: true,
|
|
308
|
+
postalInputMode: "numeric",
|
|
309
|
+
postalMaxLength: 10,
|
|
310
|
+
line2Label: "Apt, suite"
|
|
311
|
+
},
|
|
312
|
+
CA: {
|
|
313
|
+
postalRequired: true,
|
|
314
|
+
postalPattern: /^[ABCEGHJ-NPRSTVXY]\d[ABCEGHJ-NPRSTV-Z] ?\d[ABCEGHJ-NPRSTV-Z]\d$/,
|
|
315
|
+
postalStrict: true,
|
|
316
|
+
postalMaxLength: 7,
|
|
317
|
+
postalUppercase: true,
|
|
318
|
+
regionLabel: "Province"
|
|
319
|
+
},
|
|
320
|
+
IE: {
|
|
321
|
+
postalRequired: true,
|
|
322
|
+
postalLabel: "Eircode",
|
|
323
|
+
postalPattern: /^(?:[AC-FHKNPRTV-Y]\d{2}|D6W) ?[0-9AC-FHKNPRTV-Y]{4}$/,
|
|
324
|
+
postalStrict: true,
|
|
325
|
+
postalMaxLength: 8,
|
|
326
|
+
postalUppercase: true,
|
|
327
|
+
regionLabel: "County",
|
|
328
|
+
cityLabel: "Town / city",
|
|
329
|
+
line2Label: "Apartment, building"
|
|
330
|
+
},
|
|
331
|
+
GB: {
|
|
332
|
+
postalRequired: true,
|
|
333
|
+
postalLabel: "Postcode",
|
|
334
|
+
regionLabel: "County",
|
|
335
|
+
postalMaxLength: 8,
|
|
336
|
+
postalUppercase: true,
|
|
337
|
+
cityLabel: "Town / city",
|
|
338
|
+
line2Label: "Flat, building"
|
|
339
|
+
},
|
|
340
|
+
AE: {
|
|
341
|
+
hasPostal: false,
|
|
342
|
+
cityLabel: "Area / district",
|
|
343
|
+
line2Label: "Villa / apartment"
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
var POSTAL_LABELS = {
|
|
347
|
+
pin: "PIN code",
|
|
348
|
+
zip: "ZIP code",
|
|
349
|
+
postal: "Postal code",
|
|
350
|
+
eircode: "Eircode",
|
|
351
|
+
cep: "CEP",
|
|
352
|
+
cap: "CAP"
|
|
353
|
+
};
|
|
354
|
+
var LOCALITY_LABELS = {
|
|
355
|
+
city: "City",
|
|
356
|
+
post_town: "Town / city",
|
|
357
|
+
district: "District",
|
|
358
|
+
suburb: "Suburb"
|
|
359
|
+
};
|
|
360
|
+
var sentenceCase = (value) => {
|
|
361
|
+
const words = value.replace(/_/g, " ").trim();
|
|
362
|
+
return words ? words.charAt(0).toUpperCase() + words.slice(1) : "";
|
|
363
|
+
};
|
|
364
|
+
var toRegExp = (source, flags = "i") => {
|
|
365
|
+
try {
|
|
366
|
+
return new RegExp(source, flags);
|
|
367
|
+
} catch {
|
|
368
|
+
return null;
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
function buildAddressFormat(countryCode, raw) {
|
|
372
|
+
const fmt = raw?.fmt ?? "";
|
|
373
|
+
const stateIndex = fmt.indexOf("%S");
|
|
374
|
+
const cityIndex = fmt.indexOf("%C");
|
|
375
|
+
const override = OVERRIDES[countryCode] ?? {};
|
|
376
|
+
const base = {
|
|
377
|
+
countryCode,
|
|
378
|
+
// GB and JP have a postcode but no `zip_name_type`, which is why keying on
|
|
379
|
+
// that field alone used to hide their postcode input.
|
|
380
|
+
hasPostal: raw ? Boolean(raw.zip || raw.zip_name_type || fmt.includes("%Z")) : true,
|
|
381
|
+
// Without metadata, don't demand a postcode: HK, QA and others have none.
|
|
382
|
+
postalRequired: !!raw,
|
|
383
|
+
postalLabel: raw?.zip_name_type && POSTAL_LABELS[raw.zip_name_type] || "Postal code",
|
|
384
|
+
postalPattern: raw?.zip ? toRegExp(`^(?:${raw.zip})$`) : null,
|
|
385
|
+
postalStrict: false,
|
|
386
|
+
postalInputMode: "text",
|
|
387
|
+
postalMaxLength: 12,
|
|
388
|
+
postalUppercase: false,
|
|
389
|
+
regionLabel: sentenceCase(raw?.state_name_type ?? "") || "State",
|
|
390
|
+
cityLabel: raw?.locality_name_type && LOCALITY_LABELS[raw.locality_name_type] || "City",
|
|
391
|
+
line1Label: "House number and street",
|
|
392
|
+
line2Label: "Apartment, suite, building",
|
|
393
|
+
stateFirst: stateIndex !== -1 && (cityIndex === -1 || stateIndex < cityIndex)
|
|
394
|
+
};
|
|
395
|
+
const format = { ...base, ...override };
|
|
396
|
+
return format.hasPostal ? format : { ...format, postalRequired: false };
|
|
397
|
+
}
|
|
398
|
+
var pickRawFields = (data) => {
|
|
399
|
+
const keys = [
|
|
400
|
+
"fmt",
|
|
401
|
+
"require",
|
|
402
|
+
"zip",
|
|
403
|
+
"zip_name_type",
|
|
404
|
+
"state_name_type",
|
|
405
|
+
"locality_name_type"
|
|
406
|
+
];
|
|
407
|
+
const picked = {};
|
|
408
|
+
keys.forEach((key) => {
|
|
409
|
+
if (typeof data[key] === "string") picked[key] = data[key];
|
|
410
|
+
});
|
|
411
|
+
return picked;
|
|
412
|
+
};
|
|
413
|
+
async function loadAddressFormat(countryCode) {
|
|
414
|
+
const cacheKey = `${CACHE_PREFIX}${countryCode}`;
|
|
415
|
+
const cached = chunkLJUGNSQQ_cjs.getCache(cacheKey);
|
|
416
|
+
if (cached) return buildAddressFormat(countryCode, cached);
|
|
417
|
+
const controller = new AbortController();
|
|
418
|
+
const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
419
|
+
try {
|
|
420
|
+
const response = await fetch(`${ADDRESS_DATA_URL}/${countryCode}`, {
|
|
421
|
+
signal: controller.signal
|
|
422
|
+
});
|
|
423
|
+
if (!response.ok) throw new Error(`Address format request failed (${response.status})`);
|
|
424
|
+
const raw = pickRawFields(await response.json());
|
|
425
|
+
chunkLJUGNSQQ_cjs.setCache(cacheKey, raw, { expiryHours: CACHE_HOURS });
|
|
426
|
+
return buildAddressFormat(countryCode, raw);
|
|
427
|
+
} finally {
|
|
428
|
+
clearTimeout(timeout);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
function sanitizePincode(value) {
|
|
432
|
+
return value.replace(/[^a-zA-Z0-9 ]/g, "").replace(/\s+/g, " ").trimStart();
|
|
433
|
+
}
|
|
434
|
+
function normalizePostcode(format, value) {
|
|
435
|
+
const cleaned = format.countryCode === "JP" || format.countryCode === "US" ? value.replace(/[^0-9 -]/g, "").trimStart() : sanitizePincode(value);
|
|
436
|
+
const cased = format.postalUppercase ? cleaned.toUpperCase() : cleaned;
|
|
437
|
+
return cased.slice(0, format.postalMaxLength);
|
|
438
|
+
}
|
|
439
|
+
function getPostcodeHint(format, value, message = (postal) => `This doesn't look like a usual ${postal}. Check it before you continue.`) {
|
|
440
|
+
const code = value.trim();
|
|
441
|
+
if (!format.hasPostal || format.postalStrict || !format.postalPattern || !code) return void 0;
|
|
442
|
+
return format.postalPattern.test(code) ? void 0 : message(lowerLabel(format.postalLabel));
|
|
443
|
+
}
|
|
444
|
+
var normalizeName = (value) => value.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z]/g, "");
|
|
445
|
+
var STATE_ALIASES = {
|
|
446
|
+
orissa: "odisha",
|
|
447
|
+
pondicherry: "puducherry",
|
|
448
|
+
uttaranchal: "uttarakhand",
|
|
449
|
+
nctofdelhi: "delhi",
|
|
450
|
+
newdelhi: "delhi",
|
|
451
|
+
andamanandnicobar: "andamanandnicobarislands",
|
|
452
|
+
dadraandnagarhaveli: "dadraandnagarhavelianddamananddiu",
|
|
453
|
+
damananddiu: "dadraandnagarhavelianddamananddiu",
|
|
454
|
+
jammukashmir: "jammuandkashmir"
|
|
455
|
+
};
|
|
456
|
+
function findStateByName(states, name) {
|
|
457
|
+
const wanted = normalizeName(name);
|
|
458
|
+
if (!wanted) return void 0;
|
|
459
|
+
const resolved = STATE_ALIASES[wanted] ?? wanted;
|
|
460
|
+
return states.find((s) => {
|
|
461
|
+
const candidate = normalizeName(s.name);
|
|
462
|
+
return candidate === resolved || candidate === wanted;
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
function joinAddressLines(line1, line2) {
|
|
466
|
+
return [line1.trim(), line2.trim()].filter(Boolean).join(", ");
|
|
467
|
+
}
|
|
468
|
+
var emailRule = Yup__namespace.string().trim().email().required();
|
|
469
|
+
var usableEmail = (value) => typeof value === "string" && emailRule.isValidSync(value) ? value.trim() : "";
|
|
470
|
+
var lowerLabel = (label) => /^[A-Z][a-z]/.test(label) ? label.charAt(0).toLowerCase() + label.slice(1) : label;
|
|
471
|
+
var DEFAULT_ADDRESS_SCHEMA_MESSAGES = {
|
|
472
|
+
nameRequired: "Enter your full name",
|
|
473
|
+
emailInvalid: "Enter a valid email",
|
|
474
|
+
emailRequired: "Enter your email",
|
|
475
|
+
phoneRequired: "Enter your phone number",
|
|
476
|
+
phoneInvalid: "Enter a valid phone number",
|
|
477
|
+
countryRequired: "Select a country",
|
|
478
|
+
line1Required: (label) => `Enter your ${label}`,
|
|
479
|
+
cityRequired: (label) => `Enter your ${label}`,
|
|
480
|
+
stateRequired: (label) => `Select your ${label}`,
|
|
481
|
+
postalRequired: (label) => `Enter your ${label}`,
|
|
482
|
+
postalInvalid: (label) => `Enter a valid ${label}`
|
|
483
|
+
};
|
|
484
|
+
function buildAddressSchema(format, { requireState, messages }) {
|
|
485
|
+
const m = { ...DEFAULT_ADDRESS_SCHEMA_MESSAGES, ...messages };
|
|
486
|
+
return Yup__namespace.object({
|
|
487
|
+
customer_name: Yup__namespace.string().trim().required(m.nameRequired),
|
|
488
|
+
customer_email: Yup__namespace.string().trim().email(m.emailInvalid).required(m.emailRequired),
|
|
489
|
+
customer_phone: Yup__namespace.string().required(m.phoneRequired).test("is-valid", m.phoneInvalid, function(value) {
|
|
490
|
+
const { customer_country_code } = this.parent;
|
|
491
|
+
if (!value || !customer_country_code) return false;
|
|
492
|
+
return isValidNumber(value, customer_country_code);
|
|
493
|
+
}),
|
|
494
|
+
country_obj: Yup__namespace.string().required(m.countryRequired),
|
|
495
|
+
address: Yup__namespace.string().trim().required(m.line1Required(lowerLabel(format.line1Label))),
|
|
496
|
+
address_line_2: Yup__namespace.string(),
|
|
497
|
+
city: Yup__namespace.string().trim().required(m.cityRequired(lowerLabel(format.cityLabel))),
|
|
498
|
+
state_obj: requireState ? Yup__namespace.string().required(m.stateRequired(lowerLabel(format.regionLabel))) : Yup__namespace.string().notRequired(),
|
|
499
|
+
pincode: format.hasPostal ? (format.postalRequired ? Yup__namespace.string().trim().required(m.postalRequired(lowerLabel(format.postalLabel))) : Yup__namespace.string().trim()).test("postal-format", m.postalInvalid(lowerLabel(format.postalLabel)), (value) => {
|
|
500
|
+
if (!value || !format.postalStrict || !format.postalPattern) return true;
|
|
501
|
+
return format.postalPattern.test(value.trim());
|
|
502
|
+
}) : Yup__namespace.string().notRequired()
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
// src/checkout/pincode.ts
|
|
507
|
+
var INVALID_PINCODE = "INVALID_PINCODE";
|
|
508
|
+
var PINCODE_VALIDATION_UNAVAILABLE = "PINCODE_VALIDATION_UNAVAILABLE";
|
|
509
|
+
var NO_POSTAL_CODE = "N/A";
|
|
510
|
+
var PINCODE_DEBOUNCE_MS = 600;
|
|
511
|
+
var PINCODE_MIN_LENGTH = 4;
|
|
512
|
+
var UNAVAILABLE_MESSAGE = "We couldn't verify this postal code right now. Please try again.";
|
|
513
|
+
var UNKNOWN = { status: "unknown", match: null };
|
|
514
|
+
var cache = /* @__PURE__ */ new Map();
|
|
515
|
+
async function validatePincode(pincode, countryCode) {
|
|
516
|
+
const value = pincode?.trim();
|
|
517
|
+
if (!value || value === NO_POSTAL_CODE) return UNKNOWN;
|
|
518
|
+
const key = `${countryCode || ""}:${value.toUpperCase()}`;
|
|
519
|
+
const cached = cache.get(key);
|
|
520
|
+
if (cached) return cached;
|
|
521
|
+
let result;
|
|
522
|
+
try {
|
|
523
|
+
const { data } = await chunkKNG4OMS5_cjs.getPincodeDetails(value, countryCode);
|
|
524
|
+
if (data?.valid) {
|
|
525
|
+
result = {
|
|
526
|
+
status: "valid",
|
|
527
|
+
match: {
|
|
528
|
+
district: data.province || "",
|
|
529
|
+
city: data.city || "",
|
|
530
|
+
state: data.state || "",
|
|
531
|
+
state_code: data.state_code || "",
|
|
532
|
+
localities: data.localities || []
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
} else if (data?.error_code === INVALID_PINCODE) {
|
|
536
|
+
result = { status: "invalid", match: null };
|
|
537
|
+
} else {
|
|
538
|
+
return UNKNOWN;
|
|
539
|
+
}
|
|
540
|
+
} catch {
|
|
541
|
+
return UNKNOWN;
|
|
542
|
+
}
|
|
543
|
+
cache.set(key, result);
|
|
544
|
+
return result;
|
|
545
|
+
}
|
|
546
|
+
function getPincodeError(error, invalidMessage) {
|
|
547
|
+
const data = error?.response?.data;
|
|
548
|
+
if (data?.error_code === INVALID_PINCODE) return invalidMessage;
|
|
549
|
+
if (data?.error_code === PINCODE_VALIDATION_UNAVAILABLE) return data.error || data.message || UNAVAILABLE_MESSAGE;
|
|
550
|
+
return null;
|
|
551
|
+
}
|
|
552
|
+
function clearPincodeCache() {
|
|
553
|
+
cache.clear();
|
|
554
|
+
}
|
|
555
|
+
var bareSubdivisionCode = (code) => (code || "").toUpperCase().split("-").pop() || "";
|
|
556
|
+
function findSubdivision(states, match) {
|
|
557
|
+
const code = bareSubdivisionCode(match.state_code);
|
|
558
|
+
return (code ? states.find((s) => bareSubdivisionCode(s.short_code) === code) : void 0) ?? (match.state ? findStateByName(states, match.state) : void 0);
|
|
559
|
+
}
|
|
560
|
+
var NO_AREAS = [];
|
|
561
|
+
function getAreaOptions(match) {
|
|
562
|
+
const labels = (match?.localities ?? []).map((l) => (l.city || "").trim()).filter(Boolean);
|
|
563
|
+
const unique = Array.from(new Set(labels));
|
|
564
|
+
return unique.length > 1 ? unique : NO_AREAS;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// src/checkout/checkout-totals.ts
|
|
568
|
+
function getCustomizationPrice(input) {
|
|
569
|
+
return Number(
|
|
570
|
+
input?.effective_price ?? input?.additional_price ?? input?.customization_price ?? 0
|
|
571
|
+
) || 0;
|
|
572
|
+
}
|
|
573
|
+
function calculateCartTotals(cart, customizationOverride) {
|
|
574
|
+
var _a;
|
|
575
|
+
const variants = cart?.product_variants || [];
|
|
576
|
+
const quantityOf = (variantId) => {
|
|
577
|
+
const line = variants.find((item) => item.id === variantId);
|
|
578
|
+
return Number(line?.quantity) || Number(cart?.products_quantity?.[variantId]) || 0;
|
|
579
|
+
};
|
|
580
|
+
let subtotal = 0;
|
|
581
|
+
let discountAmount = 0;
|
|
582
|
+
let totalInclusiveTax = 0;
|
|
583
|
+
let totalExclusiveTax = 0;
|
|
584
|
+
for (const item of variants) {
|
|
585
|
+
const quantity = quantityOf(item.id);
|
|
586
|
+
const actualPrice = Number(item.actual_price);
|
|
587
|
+
const sellingPrice = Number(item.selling_price);
|
|
588
|
+
if (actualPrice > 0) {
|
|
589
|
+
subtotal += actualPrice * quantity;
|
|
590
|
+
discountAmount += (actualPrice - sellingPrice) * quantity;
|
|
591
|
+
} else {
|
|
592
|
+
subtotal += sellingPrice * quantity;
|
|
593
|
+
}
|
|
594
|
+
const tax = Number(item.total_tax_price) || 0;
|
|
595
|
+
if (item.is_tax_inclusive_price) totalInclusiveTax += tax;
|
|
596
|
+
else totalExclusiveTax += tax;
|
|
597
|
+
}
|
|
598
|
+
const groupedCustomizeInputs = {};
|
|
599
|
+
for (const input of cart?.customization_inputs || []) {
|
|
600
|
+
(groupedCustomizeInputs[_a = input.product_variant] || (groupedCustomizeInputs[_a] = [])).push(input);
|
|
601
|
+
}
|
|
602
|
+
const customizationTotalsByVariant = {};
|
|
603
|
+
for (const input of customizationOverride || cart?.customization_inputs || []) {
|
|
604
|
+
customizationTotalsByVariant[input.product_variant] = (customizationTotalsByVariant[input.product_variant] || 0) + getCustomizationPrice(input);
|
|
605
|
+
}
|
|
606
|
+
const totalCustomizationPrice = Object.entries(
|
|
607
|
+
customizationTotalsByVariant
|
|
608
|
+
).reduce(
|
|
609
|
+
(acc, [variantId, perUnit]) => acc + perUnit * quantityOf(Number(variantId)),
|
|
610
|
+
0
|
|
611
|
+
);
|
|
612
|
+
return {
|
|
613
|
+
subtotal,
|
|
614
|
+
discountAmount,
|
|
615
|
+
totalInclusiveTax,
|
|
616
|
+
totalExclusiveTax,
|
|
617
|
+
totalCustomizationPrice,
|
|
618
|
+
customizationTotalsByVariant,
|
|
619
|
+
groupedCustomizeInputs
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
exports.DEFAULT_ADDRESS_SCHEMA_MESSAGES = DEFAULT_ADDRESS_SCHEMA_MESSAGES;
|
|
624
|
+
exports.INVALID_PINCODE = INVALID_PINCODE;
|
|
625
|
+
exports.NO_POSTAL_CODE = NO_POSTAL_CODE;
|
|
626
|
+
exports.PINCODE_DEBOUNCE_MS = PINCODE_DEBOUNCE_MS;
|
|
627
|
+
exports.PINCODE_MIN_LENGTH = PINCODE_MIN_LENGTH;
|
|
628
|
+
exports.PINCODE_VALIDATION_UNAVAILABLE = PINCODE_VALIDATION_UNAVAILABLE;
|
|
629
|
+
exports.applyCheckoutCoupon = applyCheckoutCoupon;
|
|
630
|
+
exports.buildAddressFormat = buildAddressFormat;
|
|
631
|
+
exports.buildAddressSchema = buildAddressSchema;
|
|
632
|
+
exports.calculateCartTotals = calculateCartTotals;
|
|
633
|
+
exports.clearPincodeCache = clearPincodeCache;
|
|
634
|
+
exports.detectForeignPhone = detectForeignPhone;
|
|
635
|
+
exports.fetchAppliedCoupon = fetchAppliedCoupon;
|
|
636
|
+
exports.fetchAvailableCoupons = fetchAvailableCoupons;
|
|
637
|
+
exports.findStateByName = findStateByName;
|
|
638
|
+
exports.findSubdivision = findSubdivision;
|
|
639
|
+
exports.getAreaOptions = getAreaOptions;
|
|
640
|
+
exports.getCustomizationPrice = getCustomizationPrice;
|
|
641
|
+
exports.getPincodeError = getPincodeError;
|
|
642
|
+
exports.getPostcodeHint = getPostcodeHint;
|
|
643
|
+
exports.handleCODPayment = handleCODPayment;
|
|
644
|
+
exports.handlePhonepePayment = handlePhonepePayment;
|
|
645
|
+
exports.handleRazorpayFail = handleRazorpayFail;
|
|
646
|
+
exports.handleRazorpaySuccess = handleRazorpaySuccess;
|
|
647
|
+
exports.handleStripePayment = handleStripePayment;
|
|
648
|
+
exports.handleStripeSuccess = handleStripeSuccess;
|
|
649
|
+
exports.handleTabbyPayment = handleTabbyPayment;
|
|
650
|
+
exports.isValidNumber = isValidNumber;
|
|
651
|
+
exports.joinAddressLines = joinAddressLines;
|
|
652
|
+
exports.loadAddressFormat = loadAddressFormat;
|
|
653
|
+
exports.lowerLabel = lowerLabel;
|
|
654
|
+
exports.normalizePostcode = normalizePostcode;
|
|
655
|
+
exports.openRazorpayCheckout = openRazorpayCheckout;
|
|
656
|
+
exports.processPayment = processPayment;
|
|
657
|
+
exports.removeCheckoutCoupon = removeCheckoutCoupon;
|
|
658
|
+
exports.sanitizePhoneInput = sanitizePhoneInput;
|
|
659
|
+
exports.sanitizePincode = sanitizePincode;
|
|
660
|
+
exports.usableEmail = usableEmail;
|
|
661
|
+
exports.validatePincode = validatePincode;
|