@storepecker/storefront-core 2.7.0 → 2.9.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/api/index.cjs +90 -46
- package/dist/api/index.d.cts +95 -6
- package/dist/api/index.d.ts +95 -6
- package/dist/api/index.js +3 -3
- package/dist/buy-now-B1dkx82V.d.cts +197 -0
- package/dist/buy-now-BgKd5p4J.d.ts +197 -0
- package/dist/checkout/index.cjs +78 -31
- package/dist/checkout/index.d.cts +47 -9
- package/dist/checkout/index.d.ts +47 -9
- package/dist/checkout/index.js +64 -18
- package/dist/{chunk-GTV42PDK.cjs → chunk-57UU7IJ2.cjs} +1 -0
- package/dist/{chunk-IWYO22XV.cjs → chunk-CIBMO44U.cjs} +26 -31
- package/dist/{chunk-5BT3MH4A.cjs → chunk-ETXIP5XE.cjs} +3 -3
- package/dist/{chunk-RNGQUWQW.cjs → chunk-H6FJYRO3.cjs} +49 -1
- package/dist/{chunk-CHRTGR3G.js → chunk-KCLVR6G5.js} +39 -2
- package/dist/{chunk-LCMJYFHC.cjs → chunk-NQZ5GUOG.cjs} +0 -1
- package/dist/{chunk-4C4NTH6O.js → chunk-OOFYY6GR.js} +1 -0
- package/dist/{chunk-6QHEH5XE.js → chunk-SU5LVRZD.js} +9 -14
- package/dist/{chunk-KWYFA2LJ.cjs → chunk-TFWTQTWE.cjs} +37 -19
- package/dist/{chunk-H32TICAM.js → chunk-TH7OAMGC.js} +0 -1
- package/dist/{chunk-5JD6MRVS.js → chunk-UWW5YIHL.js} +35 -17
- package/dist/{chunk-TY5NK7NW.js → chunk-YMZZCVZ2.js} +1 -1
- package/dist/components/digital-product-download-modal.d.cts +1 -1
- package/dist/components/digital-product-download-modal.d.ts +1 -1
- package/dist/components/index.d.cts +2 -2
- package/dist/components/index.d.ts +2 -2
- package/dist/components/theme-data-initializer.d.cts +2 -2
- package/dist/components/theme-data-initializer.d.ts +2 -2
- package/dist/hooks/index.cjs +564 -29
- package/dist/hooks/index.d.cts +179 -2
- package/dist/hooks/index.d.ts +179 -2
- package/dist/hooks/index.js +541 -10
- package/dist/middleware/index.cjs +3 -3
- package/dist/middleware/index.js +1 -1
- package/dist/models/index.d.cts +2 -1
- package/dist/models/index.d.ts +2 -1
- package/dist/{orders-9_scVq_M.d.cts → orders-COKWr7K7.d.cts} +1 -0
- package/dist/{orders-C1XZr8tx.d.ts → orders-Cp8qNCrl.d.ts} +1 -0
- package/dist/{pixelEvents-D0sH22Er.d.ts → pixelEvents-2Tb-_fRP.d.ts} +2 -1
- package/dist/{pixelEvents-uiPHbiAQ.d.cts → pixelEvents-BJNH06rS.d.cts} +2 -1
- package/dist/store/index.cjs +9 -9
- package/dist/store/index.d.cts +9 -4
- package/dist/store/index.d.ts +9 -4
- package/dist/store/index.js +4 -4
- package/dist/utils/index.cjs +7 -7
- package/dist/utils/index.d.cts +4 -3
- package/dist/utils/index.d.ts +4 -3
- package/dist/utils/index.js +2 -2
- package/package.json +1 -1
package/dist/hooks/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { getUserDetails } from '../chunk-WYXT5AAG.js';
|
|
2
2
|
import { findMatchingVariant, findSimilarVariant, isVariantCombinationAvailable, isColorVariantType } from '../chunk-HEFA67WK.js';
|
|
3
|
-
import { useCartStore, useAuthStore } from '../chunk-
|
|
4
|
-
import { getCart, getProductList, getProductDetail, getWishlist, notifyProductStock, getProductCategories, getCategories } from '../chunk-
|
|
5
|
-
import { cart_default } from '../chunk-
|
|
6
|
-
import { processPayment, fetchAvailableCoupons, applyCheckoutCoupon, removeCheckoutCoupon } from '../chunk-
|
|
3
|
+
import { useCartStore, useAuthStore } from '../chunk-SU5LVRZD.js';
|
|
4
|
+
import { getCart, getProductList, getProductDetail, getWishlist, notifyProductStock, getProductCategories, getCategories } from '../chunk-YMZZCVZ2.js';
|
|
5
|
+
import { cart_default } from '../chunk-TH7OAMGC.js';
|
|
6
|
+
import { processPayment, fetchAvailableCoupons, applyCheckoutCoupon, removeCheckoutCoupon } from '../chunk-UWW5YIHL.js';
|
|
7
7
|
import { applyCoupon, removeCoupon, getCoupons, getAppliedCoupon } from '../chunk-7M5CVYZJ.js';
|
|
8
8
|
import '../chunk-WFDKKOO7.js';
|
|
9
|
-
import { getOrders, placeOrder } from '../chunk-
|
|
9
|
+
import { getOrders, placeOrder, buyNowPreview, placeGuestBuyNowOrder, placeBuyNowOrder, publicCheckoutPreview, placePublicOrder } from '../chunk-KCLVR6G5.js';
|
|
10
10
|
export { useAddressForm } from '../chunk-ICKTXS6B.js';
|
|
11
11
|
import { getAddresses } from '../chunk-ZGMLOLTC.js';
|
|
12
12
|
import '../chunk-OSM73ETC.js';
|
|
@@ -354,7 +354,8 @@ function useCheckoutPayment(options) {
|
|
|
354
354
|
const order = response.data;
|
|
355
355
|
setOrderSummary(order);
|
|
356
356
|
processPayment(order, paymentMethod, callbacks);
|
|
357
|
-
} catch {
|
|
357
|
+
} catch (error) {
|
|
358
|
+
if (options.onPlaceOrderError?.(error) === true) return;
|
|
358
359
|
setShowFailureModal(true);
|
|
359
360
|
} finally {
|
|
360
361
|
setIsPlacingOrder(false);
|
|
@@ -373,6 +374,530 @@ function useCheckoutPayment(options) {
|
|
|
373
374
|
placeAndPay
|
|
374
375
|
};
|
|
375
376
|
}
|
|
377
|
+
var BUY_NOW_PAYLOAD_KEY = "____bn_pl_";
|
|
378
|
+
var DEBOUNCE_MS = 300;
|
|
379
|
+
function messageForPreviewError(code, fallback, isPreorder) {
|
|
380
|
+
switch (code) {
|
|
381
|
+
case "FEATURE_NOT_AVAILABLE":
|
|
382
|
+
return isPreorder ? "Pre Order isn't available for this store." : "Buy Now isn't available for this store.";
|
|
383
|
+
case "PUBLIC_CHECKOUT_DISABLED":
|
|
384
|
+
return "Guest checkout isn't available for this store. Please log in to continue.";
|
|
385
|
+
case "VARIANT_NOT_FOUND":
|
|
386
|
+
return "This product is no longer available.";
|
|
387
|
+
case "VARIANT_UNAVAILABLE":
|
|
388
|
+
return "This product is currently unavailable.";
|
|
389
|
+
case "INVALID_QUANTITY":
|
|
390
|
+
return "Please choose a valid quantity.";
|
|
391
|
+
case "ADDRESS_NOT_FOUND":
|
|
392
|
+
return "The selected address could not be found. Please pick another.";
|
|
393
|
+
default:
|
|
394
|
+
return fallback || "We couldn't load this item. Please try again.";
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
function readStashedItem() {
|
|
398
|
+
if (typeof window === "undefined") return null;
|
|
399
|
+
try {
|
|
400
|
+
const raw = window.sessionStorage.getItem(BUY_NOW_PAYLOAD_KEY);
|
|
401
|
+
if (!raw) return null;
|
|
402
|
+
const parsed = JSON.parse(raw);
|
|
403
|
+
if (!parsed?.variant_id) return null;
|
|
404
|
+
return { ...parsed, quantity: parsed.quantity || 1 };
|
|
405
|
+
} catch {
|
|
406
|
+
return null;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
function useBuyNow(isAuthenticated = true) {
|
|
410
|
+
const [item, setItem] = useState(null);
|
|
411
|
+
const [quantity, setQuantityState] = useState(1);
|
|
412
|
+
const [couponCodes, setCouponCodes] = useState(void 0);
|
|
413
|
+
const [addressId, setAddressIdState] = useState(void 0);
|
|
414
|
+
const [guestAddress, setGuestAddress] = useState(void 0);
|
|
415
|
+
const [shippingOptionId, setShippingOptionIdState] = useState(void 0);
|
|
416
|
+
const [preview, setPreview] = useState(null);
|
|
417
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
418
|
+
const [isRefreshing, setIsRefreshing] = useState(false);
|
|
419
|
+
const [placingOrder, setPlacingOrder] = useState(false);
|
|
420
|
+
const [notFound, setNotFound] = useState(false);
|
|
421
|
+
const [error, setError] = useState(null);
|
|
422
|
+
const [refreshNonce, setRefreshNonce] = useState(0);
|
|
423
|
+
const debounceRef = useRef();
|
|
424
|
+
const stateRef = useRef({ quantity, couponCodes, addressId, guestAddress, shippingOptionId, preview });
|
|
425
|
+
stateRef.current = { quantity, couponCodes, addressId, guestAddress, shippingOptionId, preview };
|
|
426
|
+
useEffect(() => {
|
|
427
|
+
const stashed = readStashedItem();
|
|
428
|
+
if (!stashed) {
|
|
429
|
+
setNotFound(true);
|
|
430
|
+
setIsLoading(false);
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
setItem(stashed);
|
|
434
|
+
setQuantityState(stashed.quantity || 1);
|
|
435
|
+
}, []);
|
|
436
|
+
const runPreview = useCallback(async (current) => {
|
|
437
|
+
const { quantity: quantity2, couponCodes: couponCodes2, addressId: addressId2, guestAddress: guestAddress2, shippingOptionId: shippingOptionId2 } = stateRef.current;
|
|
438
|
+
const payload = {
|
|
439
|
+
variant_id: current.variant_id,
|
|
440
|
+
quantity: quantity2,
|
|
441
|
+
customization_inputs: current.customization_inputs
|
|
442
|
+
};
|
|
443
|
+
if (couponCodes2 !== void 0) payload.coupon_codes = couponCodes2;
|
|
444
|
+
if (addressId2 !== void 0) payload.address_id = addressId2;
|
|
445
|
+
if (guestAddress2 !== void 0) payload.address = guestAddress2;
|
|
446
|
+
if (shippingOptionId2 !== void 0) payload.shipping_option_id = shippingOptionId2;
|
|
447
|
+
setIsRefreshing(true);
|
|
448
|
+
try {
|
|
449
|
+
const response = await buyNowPreview(payload);
|
|
450
|
+
if (response.data) {
|
|
451
|
+
setPreview(response.data);
|
|
452
|
+
setError(null);
|
|
453
|
+
}
|
|
454
|
+
} catch (err) {
|
|
455
|
+
const data = err?.response?.data;
|
|
456
|
+
setError({
|
|
457
|
+
code: data?.error_code || "INTERNAL_ERROR",
|
|
458
|
+
message: messageForPreviewError(data?.error_code, data?.error, current.is_preorder)
|
|
459
|
+
});
|
|
460
|
+
} finally {
|
|
461
|
+
setIsLoading(false);
|
|
462
|
+
setIsRefreshing(false);
|
|
463
|
+
}
|
|
464
|
+
}, []);
|
|
465
|
+
useEffect(() => {
|
|
466
|
+
if (!item) return;
|
|
467
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
468
|
+
debounceRef.current = setTimeout(() => runPreview(item), DEBOUNCE_MS);
|
|
469
|
+
return () => {
|
|
470
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
471
|
+
};
|
|
472
|
+
}, [item, quantity, couponCodes, addressId, guestAddress, shippingOptionId, refreshNonce, runPreview]);
|
|
473
|
+
const refresh = useCallback(() => {
|
|
474
|
+
setRefreshNonce((n) => n + 1);
|
|
475
|
+
}, []);
|
|
476
|
+
const clearItem = useCallback(() => {
|
|
477
|
+
try {
|
|
478
|
+
window.sessionStorage.removeItem(BUY_NOW_PAYLOAD_KEY);
|
|
479
|
+
} catch {
|
|
480
|
+
}
|
|
481
|
+
}, []);
|
|
482
|
+
const setQuantity = useCallback((value) => {
|
|
483
|
+
setQuantityState(Math.max(1, value));
|
|
484
|
+
}, []);
|
|
485
|
+
const setAddressId = useCallback((id) => {
|
|
486
|
+
setAddressIdState(id);
|
|
487
|
+
setShippingOptionIdState(void 0);
|
|
488
|
+
}, []);
|
|
489
|
+
const setShippingOptionId = useCallback((id) => {
|
|
490
|
+
setShippingOptionIdState(id);
|
|
491
|
+
}, []);
|
|
492
|
+
const applyCoupon2 = useCallback((code) => {
|
|
493
|
+
setCouponCodes([code]);
|
|
494
|
+
}, []);
|
|
495
|
+
const removeCoupon2 = useCallback(() => {
|
|
496
|
+
setCouponCodes([]);
|
|
497
|
+
}, []);
|
|
498
|
+
const placeOrder2 = useCallback(
|
|
499
|
+
async ({
|
|
500
|
+
isCod,
|
|
501
|
+
phonepeRedirectUrl,
|
|
502
|
+
stripeRedirectUrl,
|
|
503
|
+
tabbyRedirectUrl,
|
|
504
|
+
guest
|
|
505
|
+
}) => {
|
|
506
|
+
if (!item) return;
|
|
507
|
+
const effectiveShippingId = shippingOptionId ?? stateRef.current.preview?.selected_shipping_option_id ?? void 0;
|
|
508
|
+
setPlacingOrder(true);
|
|
509
|
+
try {
|
|
510
|
+
if (!isAuthenticated) {
|
|
511
|
+
if (!guest) throw new Error("MISSING_ADDRESS");
|
|
512
|
+
const payload2 = {
|
|
513
|
+
cart_items: { [item.variant_id]: quantity },
|
|
514
|
+
is_buy_now: true,
|
|
515
|
+
is_cod: !!isCod,
|
|
516
|
+
email: guest.email,
|
|
517
|
+
phone: guest.phone,
|
|
518
|
+
country_code: guest.country_code,
|
|
519
|
+
address: guest.address
|
|
520
|
+
};
|
|
521
|
+
if (couponCodes !== void 0) payload2.coupon_codes = couponCodes;
|
|
522
|
+
if (effectiveShippingId !== void 0 && effectiveShippingId !== null)
|
|
523
|
+
payload2.shipping_option_id = effectiveShippingId;
|
|
524
|
+
if (phonepeRedirectUrl) payload2.phonepe_redirect_url = phonepeRedirectUrl;
|
|
525
|
+
if (stripeRedirectUrl) payload2.stripe_redirect_url = stripeRedirectUrl;
|
|
526
|
+
if (tabbyRedirectUrl) payload2.tabby_redirect_url = tabbyRedirectUrl;
|
|
527
|
+
const response2 = await placeGuestBuyNowOrder(payload2);
|
|
528
|
+
return response2.data;
|
|
529
|
+
}
|
|
530
|
+
if (addressId === void 0) throw new Error("MISSING_ADDRESS");
|
|
531
|
+
const payload = {
|
|
532
|
+
variant_id: item.variant_id,
|
|
533
|
+
quantity,
|
|
534
|
+
address_id: addressId,
|
|
535
|
+
customization_inputs: item.customization_inputs,
|
|
536
|
+
is_cod: !!isCod
|
|
537
|
+
};
|
|
538
|
+
if (couponCodes !== void 0) payload.coupon_codes = couponCodes;
|
|
539
|
+
if (effectiveShippingId !== void 0 && effectiveShippingId !== null)
|
|
540
|
+
payload.shipping_option_id = effectiveShippingId;
|
|
541
|
+
if (phonepeRedirectUrl) payload.phonepe_redirect_url = phonepeRedirectUrl;
|
|
542
|
+
if (stripeRedirectUrl) payload.stripe_redirect_url = stripeRedirectUrl;
|
|
543
|
+
if (tabbyRedirectUrl) payload.tabby_redirect_url = tabbyRedirectUrl;
|
|
544
|
+
const response = await placeBuyNowOrder(payload);
|
|
545
|
+
return response.data;
|
|
546
|
+
} finally {
|
|
547
|
+
setPlacingOrder(false);
|
|
548
|
+
}
|
|
549
|
+
},
|
|
550
|
+
[item, quantity, addressId, couponCodes, shippingOptionId, isAuthenticated]
|
|
551
|
+
);
|
|
552
|
+
return {
|
|
553
|
+
// data
|
|
554
|
+
item,
|
|
555
|
+
preview,
|
|
556
|
+
quantity,
|
|
557
|
+
couponCodes,
|
|
558
|
+
addressId,
|
|
559
|
+
guestAddress,
|
|
560
|
+
shippingOptionId,
|
|
561
|
+
// status
|
|
562
|
+
isLoading,
|
|
563
|
+
isRefreshing,
|
|
564
|
+
placingOrder,
|
|
565
|
+
notFound,
|
|
566
|
+
error,
|
|
567
|
+
missingItems: preview?.missing_items ?? {},
|
|
568
|
+
appliedCoupon: preview?.applied_coupons && Object.keys(preview.applied_coupons).length > 0 ? preview.applied_coupons : null,
|
|
569
|
+
// actions
|
|
570
|
+
setQuantity,
|
|
571
|
+
setAddressId,
|
|
572
|
+
setShippingOptionId,
|
|
573
|
+
applyCoupon: applyCoupon2,
|
|
574
|
+
removeCoupon: removeCoupon2,
|
|
575
|
+
setGuestAddress,
|
|
576
|
+
refresh,
|
|
577
|
+
clearItem,
|
|
578
|
+
placeOrder: placeOrder2
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
function useInlineCheckoutPayment(options) {
|
|
582
|
+
const [orderSummary, setOrderSummary] = useState(null);
|
|
583
|
+
const [isPlacingOrder, setIsPlacingOrder] = useState(false);
|
|
584
|
+
const [isConfirmingPayment, setIsConfirmingPayment] = useState(false);
|
|
585
|
+
const [showSuccessModal, setShowSuccessModal] = useState(false);
|
|
586
|
+
const [showFailureModal, setShowFailureModal] = useState(false);
|
|
587
|
+
const isPublic = !options.isAuthenticated;
|
|
588
|
+
const callbacks = {
|
|
589
|
+
onSuccess: (order) => {
|
|
590
|
+
setOrderSummary(order);
|
|
591
|
+
setShowSuccessModal(true);
|
|
592
|
+
options.onClearItem?.();
|
|
593
|
+
options.onSuccess?.(order);
|
|
594
|
+
},
|
|
595
|
+
onFailure: (order) => {
|
|
596
|
+
setOrderSummary(order);
|
|
597
|
+
setShowFailureModal(true);
|
|
598
|
+
options.onFailure?.(order);
|
|
599
|
+
},
|
|
600
|
+
onRedirect: options.onRedirect,
|
|
601
|
+
onStripeModalOpen: options.onStripeModalOpen,
|
|
602
|
+
onCartReset: () => {
|
|
603
|
+
},
|
|
604
|
+
onPaymentStart: () => setIsConfirmingPayment(true),
|
|
605
|
+
onPaymentEnd: () => setIsConfirmingPayment(false)
|
|
606
|
+
};
|
|
607
|
+
const placeAndPay = useCallback(
|
|
608
|
+
async (paymentMethod) => {
|
|
609
|
+
try {
|
|
610
|
+
setIsPlacingOrder(true);
|
|
611
|
+
const isCod = paymentMethod === "cod";
|
|
612
|
+
const guest = isPublic ? options.getGuestContact?.() : void 0;
|
|
613
|
+
if (isPublic && !guest) {
|
|
614
|
+
setShowFailureModal(true);
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
const order = await options.placeOrder({
|
|
618
|
+
isCod,
|
|
619
|
+
phonepeRedirectUrl: options.phonepeRedirectUrl,
|
|
620
|
+
stripeRedirectUrl: options.stripeRedirectUrl,
|
|
621
|
+
tabbyRedirectUrl: options.tabbyRedirectUrl,
|
|
622
|
+
guest
|
|
623
|
+
});
|
|
624
|
+
if (!order) {
|
|
625
|
+
setShowFailureModal(true);
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
setOrderSummary(order);
|
|
629
|
+
processPayment(order, paymentMethod, callbacks, { isPublic });
|
|
630
|
+
} catch (error) {
|
|
631
|
+
if (options.onPlaceOrderError?.(error) === true) return;
|
|
632
|
+
setShowFailureModal(true);
|
|
633
|
+
} finally {
|
|
634
|
+
setIsPlacingOrder(false);
|
|
635
|
+
}
|
|
636
|
+
},
|
|
637
|
+
[
|
|
638
|
+
isPublic,
|
|
639
|
+
options.placeOrder,
|
|
640
|
+
options.getGuestContact,
|
|
641
|
+
options.phonepeRedirectUrl,
|
|
642
|
+
options.stripeRedirectUrl,
|
|
643
|
+
options.tabbyRedirectUrl
|
|
644
|
+
]
|
|
645
|
+
);
|
|
646
|
+
return {
|
|
647
|
+
orderSummary,
|
|
648
|
+
isPlacingOrder,
|
|
649
|
+
isConfirmingPayment,
|
|
650
|
+
showSuccessModal,
|
|
651
|
+
showFailureModal,
|
|
652
|
+
setShowSuccessModal,
|
|
653
|
+
setShowFailureModal,
|
|
654
|
+
placeAndPay
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
var DEBOUNCE_MS2 = 400;
|
|
658
|
+
function messageForPreviewError2(code, fallback) {
|
|
659
|
+
switch (code) {
|
|
660
|
+
case "PUBLIC_CHECKOUT_DISABLED":
|
|
661
|
+
return "Guest checkout isn't available for this store. Please log in to continue.";
|
|
662
|
+
case "INVALID_QUANTITY":
|
|
663
|
+
return "One of the items has an invalid quantity. Please review your cart.";
|
|
664
|
+
case "ADDRESS_NOT_FOUND":
|
|
665
|
+
return "The selected address could not be found. Please pick another.";
|
|
666
|
+
case "PREORDER_DIRECT_ONLY":
|
|
667
|
+
return "A pre-order product is in your cart. Please remove it and purchase it directly with Pre Order.";
|
|
668
|
+
default:
|
|
669
|
+
return fallback || "We couldn't price your cart. Please try again.";
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
function readCartItems(cart) {
|
|
673
|
+
if (!cart?.products_quantity) return {};
|
|
674
|
+
return Object.entries(cart.products_quantity).reduce(
|
|
675
|
+
(acc, [id, qty]) => {
|
|
676
|
+
const variantId = Number(id);
|
|
677
|
+
const quantity = Number(qty);
|
|
678
|
+
if (variantId && quantity > 0) acc[variantId] = quantity;
|
|
679
|
+
return acc;
|
|
680
|
+
},
|
|
681
|
+
{}
|
|
682
|
+
);
|
|
683
|
+
}
|
|
684
|
+
function usePublicCheckout() {
|
|
685
|
+
const [cartItems, setCartItems] = useState({});
|
|
686
|
+
const [couponCodes, setCouponCodes] = useState(void 0);
|
|
687
|
+
const [guestAddress, setGuestAddressState] = useState(void 0);
|
|
688
|
+
const [shippingOptionId, setShippingOptionIdState] = useState(
|
|
689
|
+
void 0
|
|
690
|
+
);
|
|
691
|
+
const [isCod, setIsCodState] = useState(false);
|
|
692
|
+
const [preview, setPreview] = useState(null);
|
|
693
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
694
|
+
const [isRefreshing, setIsRefreshing] = useState(false);
|
|
695
|
+
const [placingOrder, setPlacingOrder] = useState(false);
|
|
696
|
+
const [isEmpty, setIsEmpty] = useState(false);
|
|
697
|
+
const [error, setError] = useState(null);
|
|
698
|
+
const [refreshNonce, setRefreshNonce] = useState(0);
|
|
699
|
+
const debounceRef = useRef();
|
|
700
|
+
const stateRef = useRef({
|
|
701
|
+
cartItems,
|
|
702
|
+
couponCodes,
|
|
703
|
+
guestAddress,
|
|
704
|
+
shippingOptionId,
|
|
705
|
+
isCod,
|
|
706
|
+
preview
|
|
707
|
+
});
|
|
708
|
+
stateRef.current = {
|
|
709
|
+
cartItems,
|
|
710
|
+
couponCodes,
|
|
711
|
+
guestAddress,
|
|
712
|
+
shippingOptionId,
|
|
713
|
+
isCod,
|
|
714
|
+
preview
|
|
715
|
+
};
|
|
716
|
+
useEffect(() => {
|
|
717
|
+
const cart = cart_default.get();
|
|
718
|
+
const items = readCartItems(cart);
|
|
719
|
+
if (Object.keys(items).length === 0) {
|
|
720
|
+
setIsEmpty(true);
|
|
721
|
+
setIsLoading(false);
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
724
|
+
setCartItems(items);
|
|
725
|
+
}, []);
|
|
726
|
+
const pruneStaleItems = useCallback(
|
|
727
|
+
(priced) => {
|
|
728
|
+
const missing = priced.missing_items || {};
|
|
729
|
+
const missingIds = Object.keys(missing).map(Number);
|
|
730
|
+
if (missingIds.length === 0) return;
|
|
731
|
+
const pricedIds = new Set((priced.product_variants || []).map((v) => v.id));
|
|
732
|
+
const droppedIds = missingIds.filter((id) => !pricedIds.has(id));
|
|
733
|
+
if (droppedIds.length === 0) return;
|
|
734
|
+
const cart = cart_default.get();
|
|
735
|
+
if (cart) {
|
|
736
|
+
droppedIds.forEach((id) => {
|
|
737
|
+
const variant = cart.product_variants?.find((v) => v.id === id);
|
|
738
|
+
if (variant) cart_default.remove(variant);
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
setCartItems((prev) => {
|
|
742
|
+
const next = { ...prev };
|
|
743
|
+
droppedIds.forEach((id) => delete next[id]);
|
|
744
|
+
return next;
|
|
745
|
+
});
|
|
746
|
+
},
|
|
747
|
+
[]
|
|
748
|
+
);
|
|
749
|
+
const runPreview = useCallback(async () => {
|
|
750
|
+
const {
|
|
751
|
+
cartItems: cartItems2,
|
|
752
|
+
couponCodes: couponCodes2,
|
|
753
|
+
guestAddress: guestAddress2,
|
|
754
|
+
shippingOptionId: shippingOptionId2,
|
|
755
|
+
isCod: isCod2
|
|
756
|
+
} = stateRef.current;
|
|
757
|
+
if (Object.keys(cartItems2).length === 0) {
|
|
758
|
+
setIsEmpty(true);
|
|
759
|
+
setIsLoading(false);
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
762
|
+
const payload = {
|
|
763
|
+
cart_items: cartItems2,
|
|
764
|
+
is_cod: isCod2
|
|
765
|
+
};
|
|
766
|
+
if (couponCodes2 !== void 0) payload.coupon_codes = couponCodes2;
|
|
767
|
+
if (guestAddress2 !== void 0) payload.address = guestAddress2;
|
|
768
|
+
if (shippingOptionId2 !== void 0) payload.shipping_option_id = shippingOptionId2;
|
|
769
|
+
setIsRefreshing(true);
|
|
770
|
+
try {
|
|
771
|
+
const response = await publicCheckoutPreview(payload);
|
|
772
|
+
if (response.data) {
|
|
773
|
+
setPreview(response.data);
|
|
774
|
+
setError(null);
|
|
775
|
+
pruneStaleItems(response.data);
|
|
776
|
+
}
|
|
777
|
+
} catch (err) {
|
|
778
|
+
const data = err?.response?.data;
|
|
779
|
+
const code = data?.error_code;
|
|
780
|
+
if (code === "CART_EMPTY") {
|
|
781
|
+
cart_default.clear();
|
|
782
|
+
setCartItems({});
|
|
783
|
+
setIsEmpty(true);
|
|
784
|
+
setPreview(null);
|
|
785
|
+
setError(null);
|
|
786
|
+
return;
|
|
787
|
+
}
|
|
788
|
+
setError({
|
|
789
|
+
code: code || "INTERNAL_ERROR",
|
|
790
|
+
message: messageForPreviewError2(code, data?.error)
|
|
791
|
+
});
|
|
792
|
+
} finally {
|
|
793
|
+
setIsLoading(false);
|
|
794
|
+
setIsRefreshing(false);
|
|
795
|
+
}
|
|
796
|
+
}, [pruneStaleItems]);
|
|
797
|
+
useEffect(() => {
|
|
798
|
+
if (isEmpty) return;
|
|
799
|
+
if (Object.keys(cartItems).length === 0) return;
|
|
800
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
801
|
+
debounceRef.current = setTimeout(runPreview, DEBOUNCE_MS2);
|
|
802
|
+
return () => {
|
|
803
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
804
|
+
};
|
|
805
|
+
}, [
|
|
806
|
+
cartItems,
|
|
807
|
+
couponCodes,
|
|
808
|
+
guestAddress,
|
|
809
|
+
shippingOptionId,
|
|
810
|
+
isCod,
|
|
811
|
+
refreshNonce,
|
|
812
|
+
isEmpty,
|
|
813
|
+
runPreview
|
|
814
|
+
]);
|
|
815
|
+
const refresh = useCallback(() => setRefreshNonce((n) => n + 1), []);
|
|
816
|
+
const setGuestAddress = useCallback((address) => {
|
|
817
|
+
const prev = stateRef.current.guestAddress;
|
|
818
|
+
const unchanged = prev?.country_obj === address?.country_obj && prev?.state_obj === address?.state_obj && prev?.pincode === address?.pincode;
|
|
819
|
+
if (unchanged) return;
|
|
820
|
+
const destinationChanged = prev?.country_obj !== address?.country_obj || prev?.state_obj !== address?.state_obj;
|
|
821
|
+
setGuestAddressState(address);
|
|
822
|
+
if (destinationChanged) setShippingOptionIdState(void 0);
|
|
823
|
+
}, []);
|
|
824
|
+
const setShippingOptionId = useCallback((id) => {
|
|
825
|
+
setShippingOptionIdState(id);
|
|
826
|
+
}, []);
|
|
827
|
+
const setIsCod = useCallback((value) => setIsCodState(value), []);
|
|
828
|
+
const applyCoupon2 = useCallback((code) => setCouponCodes([code]), []);
|
|
829
|
+
const removeCoupon2 = useCallback(() => setCouponCodes([]), []);
|
|
830
|
+
const clearCart = useCallback(() => {
|
|
831
|
+
cart_default.clear();
|
|
832
|
+
setCartItems({});
|
|
833
|
+
setIsEmpty(true);
|
|
834
|
+
}, []);
|
|
835
|
+
const placeOrder2 = useCallback(
|
|
836
|
+
async ({
|
|
837
|
+
isCod: isCodArg,
|
|
838
|
+
phonepeRedirectUrl,
|
|
839
|
+
stripeRedirectUrl,
|
|
840
|
+
tabbyRedirectUrl,
|
|
841
|
+
guest
|
|
842
|
+
}) => {
|
|
843
|
+
if (!guest) throw new Error("MISSING_ADDRESS");
|
|
844
|
+
const items = stateRef.current.cartItems;
|
|
845
|
+
if (Object.keys(items).length === 0) throw new Error("CART_EMPTY");
|
|
846
|
+
setPlacingOrder(true);
|
|
847
|
+
try {
|
|
848
|
+
const payload = {
|
|
849
|
+
cart_items: items,
|
|
850
|
+
is_cod: !!isCodArg,
|
|
851
|
+
email: guest.email,
|
|
852
|
+
phone: guest.phone,
|
|
853
|
+
country_code: guest.country_code,
|
|
854
|
+
address: guest.address
|
|
855
|
+
};
|
|
856
|
+
if (couponCodes !== void 0) payload.coupon_codes = couponCodes;
|
|
857
|
+
const effectiveShippingId = shippingOptionId ?? stateRef.current.preview?.selected_shipping_option_id ?? void 0;
|
|
858
|
+
if (effectiveShippingId !== void 0 && effectiveShippingId !== null) {
|
|
859
|
+
payload.shipping_option_id = effectiveShippingId;
|
|
860
|
+
}
|
|
861
|
+
if (phonepeRedirectUrl) payload.phonepe_redirect_url = phonepeRedirectUrl;
|
|
862
|
+
if (stripeRedirectUrl) payload.stripe_redirect_url = stripeRedirectUrl;
|
|
863
|
+
if (tabbyRedirectUrl) payload.tabby_redirect_url = tabbyRedirectUrl;
|
|
864
|
+
const response = await placePublicOrder(payload);
|
|
865
|
+
return response.data;
|
|
866
|
+
} finally {
|
|
867
|
+
setPlacingOrder(false);
|
|
868
|
+
}
|
|
869
|
+
},
|
|
870
|
+
[couponCodes, shippingOptionId]
|
|
871
|
+
);
|
|
872
|
+
return {
|
|
873
|
+
// data
|
|
874
|
+
preview,
|
|
875
|
+
cartItems,
|
|
876
|
+
couponCodes,
|
|
877
|
+
guestAddress,
|
|
878
|
+
shippingOptionId,
|
|
879
|
+
isCod,
|
|
880
|
+
isCodEnabled: !!preview?.is_cod_enabled,
|
|
881
|
+
codAmount: Number(preview?.cod_amount || 0),
|
|
882
|
+
// status
|
|
883
|
+
isLoading,
|
|
884
|
+
isRefreshing,
|
|
885
|
+
placingOrder,
|
|
886
|
+
isEmpty,
|
|
887
|
+
error,
|
|
888
|
+
missingItems: preview?.missing_items ?? {},
|
|
889
|
+
appliedCoupon: preview?.applied_coupons && Object.keys(preview.applied_coupons).length > 0 ? preview.applied_coupons : null,
|
|
890
|
+
// actions
|
|
891
|
+
setGuestAddress,
|
|
892
|
+
setShippingOptionId,
|
|
893
|
+
setIsCod,
|
|
894
|
+
applyCoupon: applyCoupon2,
|
|
895
|
+
removeCoupon: removeCoupon2,
|
|
896
|
+
refresh,
|
|
897
|
+
clearCart,
|
|
898
|
+
placeOrder: placeOrder2
|
|
899
|
+
};
|
|
900
|
+
}
|
|
376
901
|
function useCheckoutCoupon(options) {
|
|
377
902
|
const [availableCoupons, setAvailableCoupons] = useState([]);
|
|
378
903
|
const [appliedCoupon, setAppliedCoupon] = useState(null);
|
|
@@ -506,7 +1031,7 @@ function useVariantSelector(options) {
|
|
|
506
1031
|
};
|
|
507
1032
|
}
|
|
508
1033
|
function useShopCheckout(options) {
|
|
509
|
-
const { product, onNavigateToCart, onToast } = options;
|
|
1034
|
+
const { product, onNavigateToCart, onToast, onPreorderRejected } = options;
|
|
510
1035
|
const { addToCart, setCart } = useCartStore();
|
|
511
1036
|
const isUserAuthenticated = useAuthStore((s) => s.isAuthenticated);
|
|
512
1037
|
const [isWishlisted, setIsWishlisted] = useState(product.is_wishlisted);
|
|
@@ -541,7 +1066,12 @@ function useShopCheckout(options) {
|
|
|
541
1066
|
await addToCart([{ variant_id: product.id, quantity }]);
|
|
542
1067
|
setIsAddedToCart(true);
|
|
543
1068
|
} catch (error) {
|
|
544
|
-
|
|
1069
|
+
const code = error?.response?.data?.error_code;
|
|
1070
|
+
if (code === "PREORDER_DIRECT_ONLY" && onPreorderRejected) {
|
|
1071
|
+
onPreorderRejected();
|
|
1072
|
+
} else {
|
|
1073
|
+
console.log(error);
|
|
1074
|
+
}
|
|
545
1075
|
} finally {
|
|
546
1076
|
setLoading(false);
|
|
547
1077
|
}
|
|
@@ -560,7 +1090,8 @@ function useShopCheckout(options) {
|
|
|
560
1090
|
quantity,
|
|
561
1091
|
addToCart,
|
|
562
1092
|
setCart,
|
|
563
|
-
onNavigateToCart
|
|
1093
|
+
onNavigateToCart,
|
|
1094
|
+
onPreorderRejected
|
|
564
1095
|
]);
|
|
565
1096
|
const handleCustomizationSubmit = useCallback(
|
|
566
1097
|
async (data) => {
|
|
@@ -766,4 +1297,4 @@ function useCoupon(options = {}) {
|
|
|
766
1297
|
};
|
|
767
1298
|
}
|
|
768
1299
|
|
|
769
|
-
export { useAddress, useCart, useCheckoutCoupon, useCheckoutPayment, useCoupon, useGetProductCategories, useGetProductDetails, useGetProducts, useOrders, useProductDetailModal, useServiceFormModal, useShopCheckout, useUserDetails, useVariantSelector, useWishlist };
|
|
1300
|
+
export { BUY_NOW_PAYLOAD_KEY, useAddress, useBuyNow, useCart, useCheckoutCoupon, useCheckoutPayment, useCoupon, useGetProductCategories, useGetProductDetails, useGetProducts, useInlineCheckoutPayment, useOrders, useProductDetailModal, usePublicCheckout, useServiceFormModal, useShopCheckout, useUserDetails, useVariantSelector, useWishlist };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunk57UU7IJ2_cjs = require('../chunk-57UU7IJ2.cjs');
|
|
4
4
|
var chunkNE3ZHELZ_cjs = require('../chunk-NE3ZHELZ.cjs');
|
|
5
5
|
var server = require('next/server');
|
|
6
6
|
var jwtDecode = require('jwt-decode');
|
|
@@ -18,13 +18,13 @@ function middleware(request) {
|
|
|
18
18
|
);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
if (
|
|
21
|
+
if (chunk57UU7IJ2_cjs.protectedRoutes.includes(request.nextUrl.pathname) && !token) {
|
|
22
22
|
const response = server.NextResponse.redirect(
|
|
23
23
|
new URL(`/login?referer=${request.nextUrl.pathname}`, request.url)
|
|
24
24
|
);
|
|
25
25
|
return response;
|
|
26
26
|
}
|
|
27
|
-
if (
|
|
27
|
+
if (chunk57UU7IJ2_cjs.authRoutes.includes(request.nextUrl.pathname) && token) {
|
|
28
28
|
return server.NextResponse.redirect(
|
|
29
29
|
new URL(`/?referer=${request.nextUrl.pathname}`, request.url)
|
|
30
30
|
);
|
package/dist/middleware/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { protectedRoutes, authRoutes } from '../chunk-
|
|
1
|
+
import { protectedRoutes, authRoutes } from '../chunk-OOFYY6GR.js';
|
|
2
2
|
import { USER_CRED_TOKEN } from '../chunk-BQ256JKN.js';
|
|
3
3
|
import { NextResponse } from 'next/server';
|
|
4
4
|
import { jwtDecode } from 'jwt-decode';
|
package/dist/models/index.d.cts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { A as Address } from '../address-DwBZHzbI.cjs';
|
|
2
2
|
export { A as Analytics, B as Blog, a as Booking, b as BookingDetails, I as Instagram, R as Review } from '../instagram-D4JUT4ZU.cjs';
|
|
3
|
+
export { B as BuyNow, C as Checkout, P as PublicCheckout } from '../buy-now-B1dkx82V.cjs';
|
|
3
4
|
export { A as ApplicableTarget, C as Cart, a as CartState, b as Category, c as Coupon, d as CouponResponse, e as CouponStatus, f as Coupons, D as DiscountType, U as User, V as ValueType } from '../cart-CyN2JQTw.cjs';
|
|
4
5
|
export { A as CollectionAttributes, C as CollectionResponse, s as singleCollection } from '../collections-8YdINtUf.cjs';
|
|
5
|
-
export { O as Order } from '../orders-
|
|
6
|
+
export { O as Order } from '../orders-COKWr7K7.cjs';
|
|
6
7
|
export { D as Data, P as PaymentInstrument, a as PhonePe } from '../phonepe-dWMLZel6.cjs';
|
|
7
8
|
export { A as Attributes, B as BaseProduct, a as BookingService, b as BookingServiceDate, c as Brand, C as CustomField, O as OperatingHours, P as Photos, d as Product, e as ProductAttribute, f as ProductDetail, S as SpecialHours, T as TimeSlot, W as WishlistState } from '../product-CZtFWhxO.cjs';
|
|
8
9
|
export { W as Wishlist } from '../wishlist-Cx9Vrszq.cjs';
|
package/dist/models/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { A as Address } from '../address-DwBZHzbI.js';
|
|
2
2
|
export { A as Analytics, B as Blog, a as Booking, b as BookingDetails, I as Instagram, R as Review } from '../instagram-CqJBZ-0X.js';
|
|
3
|
+
export { B as BuyNow, C as Checkout, P as PublicCheckout } from '../buy-now-BgKd5p4J.js';
|
|
3
4
|
export { A as ApplicableTarget, C as Cart, a as CartState, b as Category, c as Coupon, d as CouponResponse, e as CouponStatus, f as Coupons, D as DiscountType, U as User, V as ValueType } from '../cart-BGIsIZdM.js';
|
|
4
5
|
export { A as CollectionAttributes, C as CollectionResponse, s as singleCollection } from '../collections-ycrA2cPL.js';
|
|
5
|
-
export { O as Order } from '../orders-
|
|
6
|
+
export { O as Order } from '../orders-Cp8qNCrl.js';
|
|
6
7
|
export { D as Data, P as PaymentInstrument, a as PhonePe } from '../phonepe-dWMLZel6.js';
|
|
7
8
|
export { A as Attributes, B as BaseProduct, a as BookingService, b as BookingServiceDate, c as Brand, C as CustomField, O as OperatingHours, P as Photos, d as Product, e as ProductAttribute, f as ProductDetail, S as SpecialHours, T as TimeSlot, W as WishlistState } from '../product-CZtFWhxO.js';
|
|
8
9
|
export { W as Wishlist } from '../wishlist-CRNbfFIx.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { b as Category$1, C as Cart } from './cart-BGIsIZdM.js';
|
|
2
2
|
import { C as CollectionResponse } from './collections-ycrA2cPL.js';
|
|
3
|
-
import { O as Order } from './orders-
|
|
3
|
+
import { O as Order } from './orders-Cp8qNCrl.js';
|
|
4
4
|
import { f as ProductDetail, d as Product } from './product-CZtFWhxO.js';
|
|
5
5
|
|
|
6
6
|
interface PageProps {
|
|
@@ -93,6 +93,7 @@ type PageHeaderProps = Pick<PagePropsFull, "navbar" | "logo" | "store_name" | "s
|
|
|
93
93
|
popup_message_text: string;
|
|
94
94
|
popup_thank_you_message: string;
|
|
95
95
|
public_checkout_enabled: boolean;
|
|
96
|
+
buy_now_enabled: boolean;
|
|
96
97
|
booking_success_message: string;
|
|
97
98
|
order_success_message: string;
|
|
98
99
|
};
|