@storepecker/storefront-core 2.9.1 → 2.10.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-BdIB6IuI.d.cts +42 -0
- package/dist/address-BdIB6IuI.d.ts +42 -0
- package/dist/api/index.cjs +16 -12
- package/dist/api/index.d.cts +13 -3
- package/dist/api/index.d.ts +13 -3
- package/dist/api/index.js +2 -2
- package/dist/{buy-now-BqVWXyy8.d.cts → buy-now-B_15RUVT.d.cts} +1 -1
- package/dist/{buy-now-DFdnuLjO.d.ts → buy-now-kII0KrhP.d.ts} +1 -1
- package/dist/checkout/index.cjs +108 -15
- package/dist/checkout/index.d.cts +25 -1
- package/dist/checkout/index.d.ts +25 -1
- package/dist/checkout/index.js +3 -2
- package/dist/{chunk-IG4BW3ZB.cjs → chunk-32X4SWN4.cjs} +3 -3
- 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-CBKJ3Y2I.js → chunk-EWZ7TGI7.js} +11 -1
- package/dist/{chunk-5XVHYPOC.js → chunk-FF5N7PTB.js} +1 -1
- package/dist/{chunk-XFOUNOKO.cjs → chunk-KNG4OMS5.cjs} +8 -0
- package/dist/chunk-QED6QJZC.cjs +603 -0
- 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/chunk-Y4RNRPBC.js +545 -0
- 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/index.cjs +8 -8
- package/dist/components/index.d.cts +3 -3
- package/dist/components/index.d.ts +3 -3
- 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.js +2 -2
- package/dist/components/theme-data-initializer.d.cts +1 -1
- package/dist/components/theme-data-initializer.d.ts +1 -1
- package/dist/hooks/index.cjs +644 -20
- package/dist/hooks/index.d.cts +233 -9
- package/dist/hooks/index.d.ts +233 -9
- package/dist/hooks/index.js +624 -8
- package/dist/models/index.d.cts +3 -2
- package/dist/models/index.d.ts +3 -2
- package/dist/pincode-8u7yWLpQ.d.cts +29 -0
- package/dist/pincode-8u7yWLpQ.d.ts +29 -0
- package/dist/pincode-CHM-ZD3H.d.ts +179 -0
- package/dist/pincode-Ch3bZSJz.d.cts +179 -0
- package/dist/{pixelEvents-BtEO5QAR.d.cts → pixelEvents-COqZIgTu.d.cts} +1 -0
- package/dist/{pixelEvents-LsealscG.d.ts → pixelEvents-Ds6fwS9t.d.ts} +1 -0
- package/dist/store/index.d.cts +1 -1
- package/dist/store/index.d.ts +1 -1
- 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 +58 -54
- package/dist/utils/index.d.cts +12 -3
- package/dist/utils/index.d.ts +12 -3
- package/dist/utils/index.js +3 -3
- package/package.json +1 -1
- package/dist/address-DwBZHzbI.d.cts +0 -19
- package/dist/address-DwBZHzbI.d.ts +0 -19
- package/dist/chunk-34Y7Y5FU.cjs +0 -246
- package/dist/chunk-VPTN4YXD.js +0 -232
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var chunk6LS5F4R3_cjs = require('./chunk-6LS5F4R3.cjs');
|
|
3
|
+
var chunk6APRQ2ED_cjs = require('./chunk-6APRQ2ED.cjs');
|
|
4
|
+
var chunkSGJUMI3M_cjs = require('./chunk-SGJUMI3M.cjs');
|
|
6
5
|
var chunkTB72NPRM_cjs = require('./chunk-TB72NPRM.cjs');
|
|
6
|
+
var chunkLJUGNSQQ_cjs = require('./chunk-LJUGNSQQ.cjs');
|
|
7
7
|
var react = require('react');
|
|
8
8
|
var formik = require('formik');
|
|
9
9
|
var libphonenumberJs = require('libphonenumber-js');
|
|
@@ -36,12 +36,12 @@ function useAddressForm(options = {}) {
|
|
|
36
36
|
const payload = chunkTB72NPRM_cjs.buildSubmitPayload(values, selectedCountry, states);
|
|
37
37
|
let response;
|
|
38
38
|
if (isEditing) {
|
|
39
|
-
response = await
|
|
39
|
+
response = await chunk6APRQ2ED_cjs.updateAddress({
|
|
40
40
|
...payload,
|
|
41
41
|
address_id: address.id
|
|
42
42
|
});
|
|
43
43
|
} else {
|
|
44
|
-
response = await
|
|
44
|
+
response = await chunk6APRQ2ED_cjs.addAddress(payload);
|
|
45
45
|
}
|
|
46
46
|
if (response) {
|
|
47
47
|
formik$1.resetForm();
|
|
@@ -58,7 +58,7 @@ function useAddressForm(options = {}) {
|
|
|
58
58
|
react.useEffect(() => {
|
|
59
59
|
const fetchCountries = async () => {
|
|
60
60
|
try {
|
|
61
|
-
const response = await
|
|
61
|
+
const response = await chunk6APRQ2ED_cjs.getCountries();
|
|
62
62
|
const sortedCountries = response?.data?.sort((a, b) => {
|
|
63
63
|
if (a.id === defaultCountryId) return -1;
|
|
64
64
|
if (b.id === defaultCountryId) return 1;
|
|
@@ -89,7 +89,7 @@ function useAddressForm(options = {}) {
|
|
|
89
89
|
if (!selectedCountry) return;
|
|
90
90
|
const fetchStates = async () => {
|
|
91
91
|
try {
|
|
92
|
-
const response = await
|
|
92
|
+
const response = await chunk6APRQ2ED_cjs.getSubdivisions(selectedCountry.id);
|
|
93
93
|
setStates(response.data.results);
|
|
94
94
|
} catch (error) {
|
|
95
95
|
console.error(error);
|
|
@@ -97,7 +97,7 @@ function useAddressForm(options = {}) {
|
|
|
97
97
|
};
|
|
98
98
|
const fetchAddressMeta = async () => {
|
|
99
99
|
try {
|
|
100
|
-
const response = await
|
|
100
|
+
const response = await chunkSGJUMI3M_cjs.getAddressMeta(
|
|
101
101
|
selectedCountry.tld_code
|
|
102
102
|
);
|
|
103
103
|
setAddressMeta(response);
|
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
import { getCoupons, getAppliedCoupon, applyCoupon, removeCoupon, getPincodeDetails } from './chunk-A7EI7XLU.js';
|
|
2
|
+
import { pixelEvents } from './chunk-VAU5OL72.js';
|
|
3
|
+
import { razorpayPublicOrderSuccess, razorpayOrderSuccess, publicRazorpayOrderFailure, razorpayOrderFail, publicMakeCODOrder, makeCODOrder, stripePublicOrderSuccess, stripeOrderSuccess } from './chunk-KCLVR6G5.js';
|
|
4
|
+
import { getCache, setCache } from './chunk-OSM73ETC.js';
|
|
5
|
+
import { getCloudFront } from './chunk-JQMLHRWL.js';
|
|
6
|
+
import { AxiosError } from 'axios';
|
|
7
|
+
import { isSupportedCountry, parsePhoneNumberFromString, getCountryCallingCode } from 'libphonenumber-js';
|
|
8
|
+
import * as Yup from 'yup';
|
|
9
|
+
|
|
10
|
+
// src/checkout/payment.ts
|
|
11
|
+
function openRazorpayCheckout(order, callbacks, paymentOptions) {
|
|
12
|
+
if (!order) return;
|
|
13
|
+
pixelEvents.initiateCheckout(order, "razorpay");
|
|
14
|
+
const {
|
|
15
|
+
razorpay_order_id,
|
|
16
|
+
razorpay_public_token,
|
|
17
|
+
total_amount,
|
|
18
|
+
razorpay_order_currency,
|
|
19
|
+
store_color_scheme,
|
|
20
|
+
store_logo,
|
|
21
|
+
store_name,
|
|
22
|
+
customer_name,
|
|
23
|
+
customer_phone,
|
|
24
|
+
customer_email
|
|
25
|
+
} = order;
|
|
26
|
+
const cloudFront = getCloudFront();
|
|
27
|
+
const options = {
|
|
28
|
+
key: razorpay_public_token,
|
|
29
|
+
amount: Number(total_amount) * 100,
|
|
30
|
+
currency: razorpay_order_currency,
|
|
31
|
+
name: store_name,
|
|
32
|
+
image: cloudFront ? `${cloudFront}${store_logo}` : store_logo,
|
|
33
|
+
order_id: razorpay_order_id,
|
|
34
|
+
handler: async (response) => {
|
|
35
|
+
handleRazorpaySuccess(
|
|
36
|
+
{
|
|
37
|
+
razorpay_payment_id: response.razorpay_payment_id,
|
|
38
|
+
razorpay_subscription_id: response.razorpay_subscription_id,
|
|
39
|
+
razorpay_signature: response.razorpay_signature,
|
|
40
|
+
order_id: order.id,
|
|
41
|
+
razorpay_order_id,
|
|
42
|
+
payment_id: response.razorpay_payment_id
|
|
43
|
+
},
|
|
44
|
+
order,
|
|
45
|
+
callbacks,
|
|
46
|
+
paymentOptions
|
|
47
|
+
);
|
|
48
|
+
},
|
|
49
|
+
theme: {
|
|
50
|
+
color: store_color_scheme?.primary,
|
|
51
|
+
accent: store_color_scheme?.secondary
|
|
52
|
+
},
|
|
53
|
+
prefill: {
|
|
54
|
+
name: customer_name,
|
|
55
|
+
email: customer_email?.endsWith("@test.com") ? void 0 : customer_email,
|
|
56
|
+
phone: customer_phone
|
|
57
|
+
},
|
|
58
|
+
modal: {
|
|
59
|
+
ondismiss: () => handleRazorpayFail(
|
|
60
|
+
order,
|
|
61
|
+
callbacks,
|
|
62
|
+
{
|
|
63
|
+
description: "User cancelled the payment manually",
|
|
64
|
+
reason: "user_cancelled_payment_manually"
|
|
65
|
+
},
|
|
66
|
+
{ isPublic: paymentOptions?.isPublic }
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const paymentObject = new window.Razorpay(options);
|
|
71
|
+
paymentObject.on("payment.failed", (response) => {
|
|
72
|
+
handleRazorpayFail(order, callbacks, response?.error, {
|
|
73
|
+
isPublic: paymentOptions?.isPublic
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
paymentObject.open();
|
|
77
|
+
}
|
|
78
|
+
async function handleRazorpaySuccess(data, order, callbacks, options) {
|
|
79
|
+
try {
|
|
80
|
+
callbacks.onPaymentStart?.();
|
|
81
|
+
if (options?.isPublic) {
|
|
82
|
+
await razorpayPublicOrderSuccess(data);
|
|
83
|
+
} else {
|
|
84
|
+
await razorpayOrderSuccess(data);
|
|
85
|
+
}
|
|
86
|
+
pixelEvents.purchase(order);
|
|
87
|
+
pixelEvents.checkoutCompleted(order);
|
|
88
|
+
callbacks.onCartReset();
|
|
89
|
+
callbacks.onSuccess(order);
|
|
90
|
+
} catch {
|
|
91
|
+
callbacks.onFailure(order);
|
|
92
|
+
} finally {
|
|
93
|
+
callbacks.onPaymentEnd?.();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async function handleRazorpayFail(order, callbacks, error, options) {
|
|
97
|
+
try {
|
|
98
|
+
const payload = {
|
|
99
|
+
order_id: order.id,
|
|
100
|
+
razorpay_order_id: order.razorpay_order_id,
|
|
101
|
+
error
|
|
102
|
+
};
|
|
103
|
+
options?.isPublic ? await publicRazorpayOrderFailure(payload) : await razorpayOrderFail(payload);
|
|
104
|
+
} catch {
|
|
105
|
+
}
|
|
106
|
+
callbacks.onFailure(order);
|
|
107
|
+
}
|
|
108
|
+
function handlePhonepePayment(order, callbacks) {
|
|
109
|
+
if (!order) return;
|
|
110
|
+
pixelEvents.initiateCheckout(order, "phonepe");
|
|
111
|
+
if (!order.phonepe_redirect_url) {
|
|
112
|
+
callbacks.onFailure(order);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
callbacks.onRedirect(order.phonepe_redirect_url);
|
|
116
|
+
}
|
|
117
|
+
function handleTabbyPayment(order, callbacks) {
|
|
118
|
+
if (!order) return;
|
|
119
|
+
pixelEvents.initiateCheckout(order, "tabby");
|
|
120
|
+
if (!order.tabby_redirect_url) {
|
|
121
|
+
callbacks.onFailure(order);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
callbacks.onRedirect(order.tabby_redirect_url);
|
|
125
|
+
}
|
|
126
|
+
async function handleCODPayment(order, callbacks, options) {
|
|
127
|
+
if (!order) return;
|
|
128
|
+
try {
|
|
129
|
+
callbacks.onPaymentStart?.();
|
|
130
|
+
pixelEvents.initiateCheckout(order, "cod");
|
|
131
|
+
if (options?.isPublic) {
|
|
132
|
+
await publicMakeCODOrder(order.order_number, {
|
|
133
|
+
customer_phone: order.customer_phone,
|
|
134
|
+
customer_email: order.customer_email
|
|
135
|
+
});
|
|
136
|
+
} else {
|
|
137
|
+
await makeCODOrder(order.id);
|
|
138
|
+
}
|
|
139
|
+
pixelEvents.purchase(order);
|
|
140
|
+
pixelEvents.checkoutCompleted(order);
|
|
141
|
+
callbacks.onCartReset();
|
|
142
|
+
callbacks.onSuccess(order);
|
|
143
|
+
} catch {
|
|
144
|
+
callbacks.onFailure(order);
|
|
145
|
+
} finally {
|
|
146
|
+
callbacks.onPaymentEnd?.();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function handleStripePayment(order, callbacks) {
|
|
150
|
+
if (!order) return;
|
|
151
|
+
pixelEvents.initiateCheckout(order, "stripe");
|
|
152
|
+
if (order.stripe_payment_link_url) {
|
|
153
|
+
callbacks.onRedirect(order.stripe_payment_link_url);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (order.stripe_client_secret) {
|
|
157
|
+
callbacks.onStripeModalOpen?.(order);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
callbacks.onFailure(order);
|
|
161
|
+
}
|
|
162
|
+
async function handleStripeSuccess(order, paymentIntentId, callbacks, options) {
|
|
163
|
+
try {
|
|
164
|
+
callbacks.onPaymentStart?.();
|
|
165
|
+
const stripeSuccessPayload = {
|
|
166
|
+
order_id: order.id,
|
|
167
|
+
payment_intent_id: paymentIntentId
|
|
168
|
+
};
|
|
169
|
+
if (options?.isPublic) {
|
|
170
|
+
await stripePublicOrderSuccess(stripeSuccessPayload);
|
|
171
|
+
} else {
|
|
172
|
+
await stripeOrderSuccess(stripeSuccessPayload);
|
|
173
|
+
}
|
|
174
|
+
pixelEvents.purchase(order);
|
|
175
|
+
pixelEvents.checkoutCompleted(order);
|
|
176
|
+
callbacks.onCartReset();
|
|
177
|
+
callbacks.onSuccess(order);
|
|
178
|
+
} catch {
|
|
179
|
+
callbacks.onFailure(order);
|
|
180
|
+
} finally {
|
|
181
|
+
callbacks.onPaymentEnd?.();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function processPayment(order, paymentMethod, callbacks, options) {
|
|
185
|
+
if (paymentMethod === "cod") {
|
|
186
|
+
handleCODPayment(order, callbacks, options);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (order.tabby_redirect_url) {
|
|
190
|
+
handleTabbyPayment(order, callbacks);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (order.stripe_client_secret || order.stripe_payment_link_url) {
|
|
194
|
+
handleStripePayment(order, callbacks);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (order.razorpay_public_token) {
|
|
198
|
+
openRazorpayCheckout(order, callbacks, options);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
handlePhonepePayment(order, callbacks);
|
|
202
|
+
}
|
|
203
|
+
async function fetchAvailableCoupons() {
|
|
204
|
+
const response = await getCoupons();
|
|
205
|
+
return response.data;
|
|
206
|
+
}
|
|
207
|
+
async function fetchAppliedCoupon() {
|
|
208
|
+
try {
|
|
209
|
+
const response = await getAppliedCoupon();
|
|
210
|
+
return response.data || null;
|
|
211
|
+
} catch {
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
async function applyCheckoutCoupon(code, callbacks) {
|
|
216
|
+
try {
|
|
217
|
+
const response = await applyCoupon(code);
|
|
218
|
+
if (response.data?.coupon) {
|
|
219
|
+
await callbacks.onCartRefresh();
|
|
220
|
+
return response.data.coupon;
|
|
221
|
+
}
|
|
222
|
+
throw new Error("Failed to apply coupon");
|
|
223
|
+
} catch (error) {
|
|
224
|
+
if (error instanceof AxiosError) {
|
|
225
|
+
throw new Error(error.response?.data?.detail || "Failed to apply coupon");
|
|
226
|
+
}
|
|
227
|
+
throw error;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
async function removeCheckoutCoupon(couponCode, callbacks) {
|
|
231
|
+
await removeCoupon(couponCode);
|
|
232
|
+
await callbacks.onCartRefresh();
|
|
233
|
+
}
|
|
234
|
+
function isValidNumber(input, code) {
|
|
235
|
+
if (!isSupportedCountry(code)) return false;
|
|
236
|
+
const phone = parsePhoneNumberFromString(input, code);
|
|
237
|
+
if (!phone || !phone.isValid()) return false;
|
|
238
|
+
return phone.countryCallingCode === getCountryCallingCode(code);
|
|
239
|
+
}
|
|
240
|
+
function detectForeignPhone(raw, countryCode) {
|
|
241
|
+
const value = raw.replace(/[^\d+]/g, "");
|
|
242
|
+
if (!value.startsWith("+")) return null;
|
|
243
|
+
const parsed = parsePhoneNumberFromString(value);
|
|
244
|
+
if (!parsed?.isValid() || !parsed.country) return null;
|
|
245
|
+
const selected = countryCode && isSupportedCountry(countryCode) ? getCountryCallingCode(countryCode) : "";
|
|
246
|
+
if (parsed.countryCallingCode === selected) return null;
|
|
247
|
+
return { country: parsed.country, nationalNumber: parsed.nationalNumber };
|
|
248
|
+
}
|
|
249
|
+
function sanitizePhoneInput(raw, countryCode) {
|
|
250
|
+
const value = raw.replace(/[^\d+]/g, "");
|
|
251
|
+
const callingCode = countryCode && isSupportedCountry(countryCode) ? getCountryCallingCode(countryCode) : "";
|
|
252
|
+
if (value.startsWith("+")) {
|
|
253
|
+
const parsed = parsePhoneNumberFromString(value);
|
|
254
|
+
if (parsed?.nationalNumber) {
|
|
255
|
+
if (callingCode && parsed.countryCallingCode !== callingCode) return value;
|
|
256
|
+
return parsed.nationalNumber;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
let digits = value.replace(/\D/g, "");
|
|
260
|
+
if (digits.startsWith("00")) digits = digits.slice(2);
|
|
261
|
+
if (callingCode && digits.startsWith(callingCode)) {
|
|
262
|
+
const parsed = parsePhoneNumberFromString("+" + digits);
|
|
263
|
+
if (parsed?.isValid()) return parsed.nationalNumber;
|
|
264
|
+
}
|
|
265
|
+
return digits.replace(/^0+/, "");
|
|
266
|
+
}
|
|
267
|
+
var ADDRESS_DATA_URL = "https://chromium-i18n.appspot.com/ssl-address/data";
|
|
268
|
+
var CACHE_PREFIX = "address_format_v1_";
|
|
269
|
+
var CACHE_HOURS = 24 * 7;
|
|
270
|
+
var FETCH_TIMEOUT_MS = 5e3;
|
|
271
|
+
var OVERRIDES = {
|
|
272
|
+
IN: {
|
|
273
|
+
postalRequired: true,
|
|
274
|
+
postalLabel: "PIN code",
|
|
275
|
+
postalPattern: /^[1-9]\d{5}$/,
|
|
276
|
+
postalStrict: true,
|
|
277
|
+
postalInputMode: "numeric",
|
|
278
|
+
postalMaxLength: 6,
|
|
279
|
+
line1Label: "House number, street, area",
|
|
280
|
+
line2Label: "Flat, building"
|
|
281
|
+
},
|
|
282
|
+
US: {
|
|
283
|
+
postalRequired: true,
|
|
284
|
+
postalPattern: /^\d{5}(?:[ -]\d{4})?$/,
|
|
285
|
+
postalStrict: true,
|
|
286
|
+
postalInputMode: "numeric",
|
|
287
|
+
postalMaxLength: 10,
|
|
288
|
+
line2Label: "Apt, suite"
|
|
289
|
+
},
|
|
290
|
+
CA: {
|
|
291
|
+
postalRequired: true,
|
|
292
|
+
postalPattern: /^[ABCEGHJ-NPRSTVXY]\d[ABCEGHJ-NPRSTV-Z] ?\d[ABCEGHJ-NPRSTV-Z]\d$/,
|
|
293
|
+
postalStrict: true,
|
|
294
|
+
postalMaxLength: 7,
|
|
295
|
+
postalUppercase: true,
|
|
296
|
+
regionLabel: "Province"
|
|
297
|
+
},
|
|
298
|
+
IE: {
|
|
299
|
+
postalRequired: true,
|
|
300
|
+
postalLabel: "Eircode",
|
|
301
|
+
postalPattern: /^(?:[AC-FHKNPRTV-Y]\d{2}|D6W) ?[0-9AC-FHKNPRTV-Y]{4}$/,
|
|
302
|
+
postalStrict: true,
|
|
303
|
+
postalMaxLength: 8,
|
|
304
|
+
postalUppercase: true,
|
|
305
|
+
regionLabel: "County",
|
|
306
|
+
cityLabel: "Town / city",
|
|
307
|
+
line2Label: "Apartment, building"
|
|
308
|
+
},
|
|
309
|
+
GB: {
|
|
310
|
+
postalRequired: true,
|
|
311
|
+
postalLabel: "Postcode",
|
|
312
|
+
regionLabel: "County",
|
|
313
|
+
postalMaxLength: 8,
|
|
314
|
+
postalUppercase: true,
|
|
315
|
+
cityLabel: "Town / city",
|
|
316
|
+
line2Label: "Flat, building"
|
|
317
|
+
},
|
|
318
|
+
AE: {
|
|
319
|
+
hasPostal: false,
|
|
320
|
+
cityLabel: "Area / district",
|
|
321
|
+
line2Label: "Villa / apartment"
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
var POSTAL_LABELS = {
|
|
325
|
+
pin: "PIN code",
|
|
326
|
+
zip: "ZIP code",
|
|
327
|
+
postal: "Postal code",
|
|
328
|
+
eircode: "Eircode",
|
|
329
|
+
cep: "CEP",
|
|
330
|
+
cap: "CAP"
|
|
331
|
+
};
|
|
332
|
+
var LOCALITY_LABELS = {
|
|
333
|
+
city: "City",
|
|
334
|
+
post_town: "Town / city",
|
|
335
|
+
district: "District",
|
|
336
|
+
suburb: "Suburb"
|
|
337
|
+
};
|
|
338
|
+
var sentenceCase = (value) => {
|
|
339
|
+
const words = value.replace(/_/g, " ").trim();
|
|
340
|
+
return words ? words.charAt(0).toUpperCase() + words.slice(1) : "";
|
|
341
|
+
};
|
|
342
|
+
var toRegExp = (source, flags = "i") => {
|
|
343
|
+
try {
|
|
344
|
+
return new RegExp(source, flags);
|
|
345
|
+
} catch {
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
function buildAddressFormat(countryCode, raw) {
|
|
350
|
+
const fmt = raw?.fmt ?? "";
|
|
351
|
+
const stateIndex = fmt.indexOf("%S");
|
|
352
|
+
const cityIndex = fmt.indexOf("%C");
|
|
353
|
+
const override = OVERRIDES[countryCode] ?? {};
|
|
354
|
+
const base = {
|
|
355
|
+
countryCode,
|
|
356
|
+
// GB and JP have a postcode but no `zip_name_type`, which is why keying on
|
|
357
|
+
// that field alone used to hide their postcode input.
|
|
358
|
+
hasPostal: raw ? Boolean(raw.zip || raw.zip_name_type || fmt.includes("%Z")) : true,
|
|
359
|
+
// Without metadata, don't demand a postcode: HK, QA and others have none.
|
|
360
|
+
postalRequired: !!raw,
|
|
361
|
+
postalLabel: raw?.zip_name_type && POSTAL_LABELS[raw.zip_name_type] || "Postal code",
|
|
362
|
+
postalPattern: raw?.zip ? toRegExp(`^(?:${raw.zip})$`) : null,
|
|
363
|
+
postalStrict: false,
|
|
364
|
+
postalInputMode: "text",
|
|
365
|
+
postalMaxLength: 12,
|
|
366
|
+
postalUppercase: false,
|
|
367
|
+
regionLabel: sentenceCase(raw?.state_name_type ?? "") || "State",
|
|
368
|
+
cityLabel: raw?.locality_name_type && LOCALITY_LABELS[raw.locality_name_type] || "City",
|
|
369
|
+
line1Label: "House number and street",
|
|
370
|
+
line2Label: "Apartment, suite, building",
|
|
371
|
+
stateFirst: stateIndex !== -1 && (cityIndex === -1 || stateIndex < cityIndex)
|
|
372
|
+
};
|
|
373
|
+
const format = { ...base, ...override };
|
|
374
|
+
return format.hasPostal ? format : { ...format, postalRequired: false };
|
|
375
|
+
}
|
|
376
|
+
var pickRawFields = (data) => {
|
|
377
|
+
const keys = [
|
|
378
|
+
"fmt",
|
|
379
|
+
"require",
|
|
380
|
+
"zip",
|
|
381
|
+
"zip_name_type",
|
|
382
|
+
"state_name_type",
|
|
383
|
+
"locality_name_type"
|
|
384
|
+
];
|
|
385
|
+
const picked = {};
|
|
386
|
+
keys.forEach((key) => {
|
|
387
|
+
if (typeof data[key] === "string") picked[key] = data[key];
|
|
388
|
+
});
|
|
389
|
+
return picked;
|
|
390
|
+
};
|
|
391
|
+
async function loadAddressFormat(countryCode) {
|
|
392
|
+
const cacheKey = `${CACHE_PREFIX}${countryCode}`;
|
|
393
|
+
const cached = getCache(cacheKey);
|
|
394
|
+
if (cached) return buildAddressFormat(countryCode, cached);
|
|
395
|
+
const controller = new AbortController();
|
|
396
|
+
const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
397
|
+
try {
|
|
398
|
+
const response = await fetch(`${ADDRESS_DATA_URL}/${countryCode}`, {
|
|
399
|
+
signal: controller.signal
|
|
400
|
+
});
|
|
401
|
+
if (!response.ok) throw new Error(`Address format request failed (${response.status})`);
|
|
402
|
+
const raw = pickRawFields(await response.json());
|
|
403
|
+
setCache(cacheKey, raw, { expiryHours: CACHE_HOURS });
|
|
404
|
+
return buildAddressFormat(countryCode, raw);
|
|
405
|
+
} finally {
|
|
406
|
+
clearTimeout(timeout);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
function sanitizePincode(value) {
|
|
410
|
+
return value.replace(/[^a-zA-Z0-9 ]/g, "").replace(/\s+/g, " ").trimStart();
|
|
411
|
+
}
|
|
412
|
+
function normalizePostcode(format, value) {
|
|
413
|
+
const cleaned = format.countryCode === "JP" || format.countryCode === "US" ? value.replace(/[^0-9 -]/g, "").trimStart() : sanitizePincode(value);
|
|
414
|
+
const cased = format.postalUppercase ? cleaned.toUpperCase() : cleaned;
|
|
415
|
+
return cased.slice(0, format.postalMaxLength);
|
|
416
|
+
}
|
|
417
|
+
function getPostcodeHint(format, value, message = (postal) => `This doesn't look like a usual ${postal}. Check it before you continue.`) {
|
|
418
|
+
const code = value.trim();
|
|
419
|
+
if (!format.hasPostal || format.postalStrict || !format.postalPattern || !code) return void 0;
|
|
420
|
+
return format.postalPattern.test(code) ? void 0 : message(lowerLabel(format.postalLabel));
|
|
421
|
+
}
|
|
422
|
+
var normalizeName = (value) => value.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z]/g, "");
|
|
423
|
+
var STATE_ALIASES = {
|
|
424
|
+
orissa: "odisha",
|
|
425
|
+
pondicherry: "puducherry",
|
|
426
|
+
uttaranchal: "uttarakhand",
|
|
427
|
+
nctofdelhi: "delhi",
|
|
428
|
+
newdelhi: "delhi",
|
|
429
|
+
andamanandnicobar: "andamanandnicobarislands",
|
|
430
|
+
dadraandnagarhaveli: "dadraandnagarhavelianddamananddiu",
|
|
431
|
+
damananddiu: "dadraandnagarhavelianddamananddiu",
|
|
432
|
+
jammukashmir: "jammuandkashmir"
|
|
433
|
+
};
|
|
434
|
+
function findStateByName(states, name) {
|
|
435
|
+
const wanted = normalizeName(name);
|
|
436
|
+
if (!wanted) return void 0;
|
|
437
|
+
const resolved = STATE_ALIASES[wanted] ?? wanted;
|
|
438
|
+
return states.find((s) => {
|
|
439
|
+
const candidate = normalizeName(s.name);
|
|
440
|
+
return candidate === resolved || candidate === wanted;
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
function joinAddressLines(line1, line2) {
|
|
444
|
+
return [line1.trim(), line2.trim()].filter(Boolean).join(", ");
|
|
445
|
+
}
|
|
446
|
+
var emailRule = Yup.string().trim().email().required();
|
|
447
|
+
var usableEmail = (value) => typeof value === "string" && emailRule.isValidSync(value) ? value.trim() : "";
|
|
448
|
+
var lowerLabel = (label) => /^[A-Z][a-z]/.test(label) ? label.charAt(0).toLowerCase() + label.slice(1) : label;
|
|
449
|
+
var DEFAULT_ADDRESS_SCHEMA_MESSAGES = {
|
|
450
|
+
nameRequired: "Enter your full name",
|
|
451
|
+
emailInvalid: "Enter a valid email",
|
|
452
|
+
emailRequired: "Enter your email",
|
|
453
|
+
phoneRequired: "Enter your phone number",
|
|
454
|
+
phoneInvalid: "Enter a valid phone number",
|
|
455
|
+
countryRequired: "Select a country",
|
|
456
|
+
line1Required: (label) => `Enter your ${label}`,
|
|
457
|
+
cityRequired: (label) => `Enter your ${label}`,
|
|
458
|
+
stateRequired: (label) => `Select your ${label}`,
|
|
459
|
+
postalRequired: (label) => `Enter your ${label}`,
|
|
460
|
+
postalInvalid: (label) => `Enter a valid ${label}`
|
|
461
|
+
};
|
|
462
|
+
function buildAddressSchema(format, { requireState, messages }) {
|
|
463
|
+
const m = { ...DEFAULT_ADDRESS_SCHEMA_MESSAGES, ...messages };
|
|
464
|
+
return Yup.object({
|
|
465
|
+
customer_name: Yup.string().trim().required(m.nameRequired),
|
|
466
|
+
customer_email: Yup.string().trim().email(m.emailInvalid).required(m.emailRequired),
|
|
467
|
+
customer_phone: Yup.string().required(m.phoneRequired).test("is-valid", m.phoneInvalid, function(value) {
|
|
468
|
+
const { customer_country_code } = this.parent;
|
|
469
|
+
if (!value || !customer_country_code) return false;
|
|
470
|
+
return isValidNumber(value, customer_country_code);
|
|
471
|
+
}),
|
|
472
|
+
country_obj: Yup.string().required(m.countryRequired),
|
|
473
|
+
address: Yup.string().trim().required(m.line1Required(lowerLabel(format.line1Label))),
|
|
474
|
+
address_line_2: Yup.string(),
|
|
475
|
+
city: Yup.string().trim().required(m.cityRequired(lowerLabel(format.cityLabel))),
|
|
476
|
+
state_obj: requireState ? Yup.string().required(m.stateRequired(lowerLabel(format.regionLabel))) : Yup.string().notRequired(),
|
|
477
|
+
pincode: format.hasPostal ? (format.postalRequired ? Yup.string().trim().required(m.postalRequired(lowerLabel(format.postalLabel))) : Yup.string().trim()).test("postal-format", m.postalInvalid(lowerLabel(format.postalLabel)), (value) => {
|
|
478
|
+
if (!value || !format.postalStrict || !format.postalPattern) return true;
|
|
479
|
+
return format.postalPattern.test(value.trim());
|
|
480
|
+
}) : Yup.string().notRequired()
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// src/checkout/pincode.ts
|
|
485
|
+
var INVALID_PINCODE = "INVALID_PINCODE";
|
|
486
|
+
var PINCODE_VALIDATION_UNAVAILABLE = "PINCODE_VALIDATION_UNAVAILABLE";
|
|
487
|
+
var NO_POSTAL_CODE = "N/A";
|
|
488
|
+
var PINCODE_DEBOUNCE_MS = 600;
|
|
489
|
+
var PINCODE_MIN_LENGTH = 4;
|
|
490
|
+
var UNAVAILABLE_MESSAGE = "We couldn't verify this postal code right now. Please try again.";
|
|
491
|
+
var UNKNOWN = { status: "unknown", match: null };
|
|
492
|
+
var cache = /* @__PURE__ */ new Map();
|
|
493
|
+
async function validatePincode(pincode, countryCode) {
|
|
494
|
+
const value = pincode?.trim();
|
|
495
|
+
if (!value || value === NO_POSTAL_CODE) return UNKNOWN;
|
|
496
|
+
const key = `${countryCode || ""}:${value.toUpperCase()}`;
|
|
497
|
+
const cached = cache.get(key);
|
|
498
|
+
if (cached) return cached;
|
|
499
|
+
let result;
|
|
500
|
+
try {
|
|
501
|
+
const { data } = await getPincodeDetails(value, countryCode);
|
|
502
|
+
if (data?.valid) {
|
|
503
|
+
result = {
|
|
504
|
+
status: "valid",
|
|
505
|
+
match: {
|
|
506
|
+
district: data.province || "",
|
|
507
|
+
city: data.city || "",
|
|
508
|
+
state: data.state || "",
|
|
509
|
+
state_code: data.state_code || "",
|
|
510
|
+
localities: data.localities || []
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
} else if (data?.error_code === INVALID_PINCODE) {
|
|
514
|
+
result = { status: "invalid", match: null };
|
|
515
|
+
} else {
|
|
516
|
+
return UNKNOWN;
|
|
517
|
+
}
|
|
518
|
+
} catch {
|
|
519
|
+
return UNKNOWN;
|
|
520
|
+
}
|
|
521
|
+
cache.set(key, result);
|
|
522
|
+
return result;
|
|
523
|
+
}
|
|
524
|
+
function getPincodeError(error, invalidMessage) {
|
|
525
|
+
const data = error?.response?.data;
|
|
526
|
+
if (data?.error_code === INVALID_PINCODE) return invalidMessage;
|
|
527
|
+
if (data?.error_code === PINCODE_VALIDATION_UNAVAILABLE) return data.error || data.message || UNAVAILABLE_MESSAGE;
|
|
528
|
+
return null;
|
|
529
|
+
}
|
|
530
|
+
function clearPincodeCache() {
|
|
531
|
+
cache.clear();
|
|
532
|
+
}
|
|
533
|
+
var bareSubdivisionCode = (code) => (code || "").toUpperCase().split("-").pop() || "";
|
|
534
|
+
function findSubdivision(states, match) {
|
|
535
|
+
const code = bareSubdivisionCode(match.state_code);
|
|
536
|
+
return (code ? states.find((s) => bareSubdivisionCode(s.short_code) === code) : void 0) ?? (match.state ? findStateByName(states, match.state) : void 0);
|
|
537
|
+
}
|
|
538
|
+
var NO_AREAS = [];
|
|
539
|
+
function getAreaOptions(match) {
|
|
540
|
+
const labels = (match?.localities ?? []).map((l) => (l.city || "").trim()).filter(Boolean);
|
|
541
|
+
const unique = Array.from(new Set(labels));
|
|
542
|
+
return unique.length > 1 ? unique : NO_AREAS;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
export { DEFAULT_ADDRESS_SCHEMA_MESSAGES, INVALID_PINCODE, NO_POSTAL_CODE, PINCODE_DEBOUNCE_MS, PINCODE_MIN_LENGTH, PINCODE_VALIDATION_UNAVAILABLE, applyCheckoutCoupon, buildAddressFormat, buildAddressSchema, clearPincodeCache, detectForeignPhone, fetchAppliedCoupon, fetchAvailableCoupons, findStateByName, findSubdivision, getAreaOptions, getPincodeError, getPostcodeHint, handleCODPayment, handlePhonepePayment, handleRazorpayFail, handleRazorpaySuccess, handleStripePayment, handleStripeSuccess, handleTabbyPayment, isValidNumber, joinAddressLines, loadAddressFormat, lowerLabel, normalizePostcode, openRazorpayCheckout, processPayment, removeCheckoutCoupon, sanitizePhoneInput, sanitizePincode, usableEmail, validatePincode };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkSGKLMS7W_cjs = require('../chunk-SGKLMS7W.cjs');
|
|
4
4
|
require('../chunk-V447PVRV.cjs');
|
|
5
|
-
require('../chunk-
|
|
6
|
-
require('../chunk-
|
|
7
|
-
require('../chunk-
|
|
8
|
-
require('../chunk-6LS5F4R3.cjs');
|
|
5
|
+
require('../chunk-WWJAPKRQ.cjs');
|
|
6
|
+
require('../chunk-6APRQ2ED.cjs');
|
|
7
|
+
require('../chunk-SGJUMI3M.cjs');
|
|
9
8
|
require('../chunk-BBRB475I.cjs');
|
|
10
9
|
require('../chunk-TB72NPRM.cjs');
|
|
10
|
+
require('../chunk-LJUGNSQQ.cjs');
|
|
11
11
|
require('../chunk-ECHV2JSY.cjs');
|
|
12
12
|
require('../chunk-BBRXE57K.cjs');
|
|
13
13
|
require('../chunk-NE3ZHELZ.cjs');
|
|
@@ -15,4 +15,4 @@ require('../chunk-N3CTXRFT.cjs');
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
module.exports =
|
|
18
|
+
module.exports = chunkSGKLMS7W_cjs.address_form_default;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { U as UseAddressFormOptions, u as useAddressForm } from '../useAddressForm-
|
|
1
|
+
import react__default from 'react';
|
|
2
|
+
import { U as UseAddressFormOptions, u as useAddressForm } from '../useAddressForm-wleIo78M.cjs';
|
|
3
3
|
import 'formik';
|
|
4
|
-
import '../address-
|
|
4
|
+
import '../address-BdIB6IuI.cjs';
|
|
5
5
|
|
|
6
6
|
interface AddressFormRef {
|
|
7
7
|
formik: ReturnType<typeof useAddressForm>["formik"];
|
|
@@ -13,8 +13,8 @@ interface AddressFormProps extends UseAddressFormOptions {
|
|
|
13
13
|
type: "submit";
|
|
14
14
|
disabled: boolean;
|
|
15
15
|
loading: boolean;
|
|
16
|
-
children:
|
|
17
|
-
}) =>
|
|
16
|
+
children: react__default.ReactNode;
|
|
17
|
+
}) => react__default.ReactNode;
|
|
18
18
|
/** Called when formik instance is ready (alternative to ref) */
|
|
19
19
|
onFormikReady?: (formik: ReturnType<typeof useAddressForm>["formik"]) => void;
|
|
20
20
|
/** Called when cancel is clicked */
|
|
@@ -28,6 +28,10 @@ interface AddressFormProps extends UseAddressFormOptions {
|
|
|
28
28
|
/** Submit button text. Default: "Save" */
|
|
29
29
|
submitLabel?: string;
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated Built on the deprecated `useAddressForm`. Build the form's markup
|
|
33
|
+
* in the theme on `useCountryAwareAddressForm` instead. Removed in 3.0.0.
|
|
34
|
+
*/
|
|
35
|
+
declare const AddressForm: react__default.ForwardRefExoticComponent<AddressFormProps & react__default.RefAttributes<AddressFormRef>>;
|
|
32
36
|
|
|
33
37
|
export { type AddressFormProps, type AddressFormRef, AddressForm as default };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { U as UseAddressFormOptions, u as useAddressForm } from '../useAddressForm-
|
|
1
|
+
import react__default from 'react';
|
|
2
|
+
import { U as UseAddressFormOptions, u as useAddressForm } from '../useAddressForm-fMOb5Z-a.js';
|
|
3
3
|
import 'formik';
|
|
4
|
-
import '../address-
|
|
4
|
+
import '../address-BdIB6IuI.js';
|
|
5
5
|
|
|
6
6
|
interface AddressFormRef {
|
|
7
7
|
formik: ReturnType<typeof useAddressForm>["formik"];
|
|
@@ -13,8 +13,8 @@ interface AddressFormProps extends UseAddressFormOptions {
|
|
|
13
13
|
type: "submit";
|
|
14
14
|
disabled: boolean;
|
|
15
15
|
loading: boolean;
|
|
16
|
-
children:
|
|
17
|
-
}) =>
|
|
16
|
+
children: react__default.ReactNode;
|
|
17
|
+
}) => react__default.ReactNode;
|
|
18
18
|
/** Called when formik instance is ready (alternative to ref) */
|
|
19
19
|
onFormikReady?: (formik: ReturnType<typeof useAddressForm>["formik"]) => void;
|
|
20
20
|
/** Called when cancel is clicked */
|
|
@@ -28,6 +28,10 @@ interface AddressFormProps extends UseAddressFormOptions {
|
|
|
28
28
|
/** Submit button text. Default: "Save" */
|
|
29
29
|
submitLabel?: string;
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated Built on the deprecated `useAddressForm`. Build the form's markup
|
|
33
|
+
* in the theme on `useCountryAwareAddressForm` instead. Removed in 3.0.0.
|
|
34
|
+
*/
|
|
35
|
+
declare const AddressForm: react__default.ForwardRefExoticComponent<AddressFormProps & react__default.RefAttributes<AddressFormRef>>;
|
|
32
36
|
|
|
33
37
|
export { type AddressFormProps, type AddressFormRef, AddressForm as default };
|