@anker-in/lib 1.1.0 → 1.1.2-beta.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/.turbo/turbo-build.log +10 -6
- package/.turbo/turbo-test.log +1 -1
- package/dist/cart/context/index.d.ts +47 -0
- package/dist/cart/context/index.d.ts.map +1 -0
- package/dist/cart/hooks/basic/useAddToCart.d.ts +30 -0
- package/dist/cart/hooks/basic/useAddToCart.d.ts.map +1 -0
- package/dist/cart/hooks/basic/useApplyCartCodes.d.ts +11 -0
- package/dist/cart/hooks/basic/useApplyCartCodes.d.ts.map +1 -0
- package/dist/cart/hooks/basic/useCreateCart.d.ts +7 -0
- package/dist/cart/hooks/basic/useCreateCart.d.ts.map +1 -0
- package/dist/cart/hooks/basic/useRemoveCartCodes.d.ts +11 -0
- package/dist/cart/hooks/basic/useRemoveCartCodes.d.ts.map +1 -0
- package/dist/cart/hooks/basic/useRemoveCartLines.d.ts +11 -0
- package/dist/cart/hooks/basic/useRemoveCartLines.d.ts.map +1 -0
- package/dist/cart/hooks/basic/useUpdateCartAttributes.d.ts +8 -0
- package/dist/cart/hooks/basic/useUpdateCartAttributes.d.ts.map +1 -0
- package/dist/cart/hooks/basic/useUpdateCartBuyerIdentity.d.ts +8 -0
- package/dist/cart/hooks/basic/useUpdateCartBuyerIdentity.d.ts.map +1 -0
- package/dist/cart/hooks/basic/useUpdateCartLines.d.ts +8 -0
- package/dist/cart/hooks/basic/useUpdateCartLines.d.ts.map +1 -0
- package/dist/cart/hooks/feature/useCalcAutoFreeGift.d.ts +10 -0
- package/dist/cart/hooks/feature/useCalcAutoFreeGift.d.ts.map +1 -0
- package/dist/cart/hooks/feature/useCalcOrderDiscount.d.ts +21 -0
- package/dist/cart/hooks/feature/useCalcOrderDiscount.d.ts.map +1 -0
- package/dist/cart/hooks/feature/useCartAttributes.d.ts +10 -0
- package/dist/cart/hooks/feature/useCartAttributes.d.ts.map +1 -0
- package/dist/cart/hooks/feature/useCartItemQuantityLimit.d.ts +19 -0
- package/dist/cart/hooks/feature/useCartItemQuantityLimit.d.ts.map +1 -0
- package/dist/cart/hooks/feature/useScriptAutoFreeGift.d.ts +37 -0
- package/dist/cart/hooks/feature/useScriptAutoFreeGift.d.ts.map +1 -0
- package/dist/cart/hooks/feature/useUpdateLineCodeAmountAttributes.d.ts +9 -0
- package/dist/cart/hooks/feature/useUpdateLineCodeAmountAttributes.d.ts.map +1 -0
- package/dist/cart/track/gtm.d.ts +26 -0
- package/dist/cart/track/gtm.d.ts.map +1 -0
- package/dist/cart/types/autoFreeGift.d.ts +135 -0
- package/dist/cart/types/autoFreeGift.d.ts.map +1 -0
- package/dist/cart/types/orderDiscount.d.ts +35 -0
- package/dist/cart/types/orderDiscount.d.ts.map +1 -0
- package/dist/cart/types/priceDiscount.d.ts +20 -0
- package/dist/cart/types/priceDiscount.d.ts.map +1 -0
- package/dist/cart/utils/autoFreeGift.d.ts +21 -0
- package/dist/cart/utils/autoFreeGift.d.ts.map +1 -0
- package/dist/cjs/cart/context/index.d.ts +47 -0
- package/dist/cjs/cart/context/index.d.ts.map +1 -0
- package/dist/cjs/cart/context/index.js +2 -0
- package/dist/cjs/cart/context/index.js.map +7 -0
- package/dist/cjs/cart/hooks/basic/useAddToCart.d.ts +30 -0
- package/dist/cjs/cart/hooks/basic/useAddToCart.d.ts.map +1 -0
- package/dist/cjs/cart/hooks/basic/useAddToCart.js +2 -0
- package/dist/cjs/cart/hooks/basic/useAddToCart.js.map +7 -0
- package/dist/cjs/cart/hooks/basic/useApplyCartCodes.d.ts +11 -0
- package/dist/cjs/cart/hooks/basic/useApplyCartCodes.d.ts.map +1 -0
- package/dist/cjs/cart/hooks/basic/useApplyCartCodes.js +2 -0
- package/dist/cjs/cart/hooks/basic/useApplyCartCodes.js.map +7 -0
- package/dist/cjs/cart/hooks/basic/useBuyNow.d.ts +1 -1
- package/dist/cjs/cart/hooks/basic/useBuyNow.d.ts.map +1 -1
- package/dist/cjs/cart/hooks/basic/useBuyNow.js +1 -1
- package/dist/cjs/cart/hooks/basic/useBuyNow.js.map +3 -3
- package/dist/cjs/cart/hooks/basic/useCreateCart.d.ts +7 -0
- package/dist/cjs/cart/hooks/basic/useCreateCart.d.ts.map +1 -0
- package/dist/cjs/cart/hooks/basic/useCreateCart.js +2 -0
- package/dist/cjs/cart/hooks/basic/useCreateCart.js.map +7 -0
- package/dist/cjs/cart/hooks/basic/useRemoveCartCodes.d.ts +11 -0
- package/dist/cjs/cart/hooks/basic/useRemoveCartCodes.d.ts.map +1 -0
- package/dist/cjs/cart/hooks/basic/useRemoveCartCodes.js +2 -0
- package/dist/cjs/cart/hooks/basic/useRemoveCartCodes.js.map +7 -0
- package/dist/cjs/cart/hooks/basic/useRemoveCartLines.d.ts +11 -0
- package/dist/cjs/cart/hooks/basic/useRemoveCartLines.d.ts.map +1 -0
- package/dist/cjs/cart/hooks/basic/useRemoveCartLines.js +2 -0
- package/dist/cjs/cart/hooks/basic/useRemoveCartLines.js.map +7 -0
- package/dist/cjs/cart/hooks/basic/useUpdateCartAttributes.d.ts +8 -0
- package/dist/cjs/cart/hooks/basic/useUpdateCartAttributes.d.ts.map +1 -0
- package/dist/cjs/cart/hooks/basic/useUpdateCartAttributes.js +2 -0
- package/dist/cjs/cart/hooks/basic/useUpdateCartAttributes.js.map +7 -0
- package/dist/cjs/cart/hooks/basic/useUpdateCartBuyerIdentity.d.ts +8 -0
- package/dist/cjs/cart/hooks/basic/useUpdateCartBuyerIdentity.d.ts.map +1 -0
- package/dist/cjs/cart/hooks/basic/useUpdateCartBuyerIdentity.js +2 -0
- package/dist/cjs/cart/hooks/basic/useUpdateCartBuyerIdentity.js.map +7 -0
- package/dist/cjs/cart/hooks/basic/useUpdateCartLines.d.ts +8 -0
- package/dist/cjs/cart/hooks/basic/useUpdateCartLines.d.ts.map +1 -0
- package/dist/cjs/cart/hooks/basic/useUpdateCartLines.js +2 -0
- package/dist/cjs/cart/hooks/basic/useUpdateCartLines.js.map +7 -0
- package/dist/cjs/cart/hooks/feature/useCalcAutoFreeGift.d.ts +10 -0
- package/dist/cjs/cart/hooks/feature/useCalcAutoFreeGift.d.ts.map +1 -0
- package/dist/cjs/cart/hooks/feature/useCalcAutoFreeGift.js +2 -0
- package/dist/cjs/cart/hooks/feature/useCalcAutoFreeGift.js.map +7 -0
- package/dist/cjs/cart/hooks/feature/useCalcOrderDiscount.d.ts +21 -0
- package/dist/cjs/cart/hooks/feature/useCalcOrderDiscount.d.ts.map +1 -0
- package/dist/cjs/cart/hooks/feature/useCalcOrderDiscount.js +2 -0
- package/dist/cjs/cart/hooks/feature/useCalcOrderDiscount.js.map +7 -0
- package/dist/cjs/cart/hooks/feature/useCartAttributes.d.ts +10 -0
- package/dist/cjs/cart/hooks/feature/useCartAttributes.d.ts.map +1 -0
- package/dist/cjs/cart/hooks/feature/useCartAttributes.js +2 -0
- package/dist/cjs/cart/hooks/feature/useCartAttributes.js.map +7 -0
- package/dist/cjs/cart/hooks/feature/useCartItemQuantityLimit.d.ts +19 -0
- package/dist/cjs/cart/hooks/feature/useCartItemQuantityLimit.d.ts.map +1 -0
- package/dist/cjs/cart/hooks/feature/useCartItemQuantityLimit.js +2 -0
- package/dist/cjs/cart/hooks/feature/useCartItemQuantityLimit.js.map +7 -0
- package/dist/cjs/cart/hooks/feature/useScriptAutoFreeGift.d.ts +37 -0
- package/dist/cjs/cart/hooks/feature/useScriptAutoFreeGift.d.ts.map +1 -0
- package/dist/cjs/cart/hooks/feature/useScriptAutoFreeGift.js +2 -0
- package/dist/cjs/cart/hooks/feature/useScriptAutoFreeGift.js.map +7 -0
- package/dist/cjs/cart/hooks/feature/useUpdateLineCodeAmountAttributes.d.ts +9 -0
- package/dist/cjs/cart/hooks/feature/useUpdateLineCodeAmountAttributes.d.ts.map +1 -0
- package/dist/cjs/cart/hooks/feature/useUpdateLineCodeAmountAttributes.js +2 -0
- package/dist/cjs/cart/hooks/feature/useUpdateLineCodeAmountAttributes.js.map +7 -0
- package/dist/cjs/cart/track/fbq.d.ts +2 -9
- package/dist/cjs/cart/track/fbq.d.ts.map +1 -1
- package/dist/cjs/cart/track/fbq.js +1 -1
- package/dist/cjs/cart/track/fbq.js.map +3 -3
- package/dist/cjs/cart/track/gtm.d.ts +26 -0
- package/dist/cjs/cart/track/gtm.d.ts.map +1 -0
- package/dist/cjs/cart/track/gtm.js +2 -0
- package/dist/cjs/cart/track/gtm.js.map +7 -0
- package/dist/cjs/cart/types/autoFreeGift.d.ts +135 -0
- package/dist/cjs/cart/types/autoFreeGift.d.ts.map +1 -0
- package/dist/cjs/cart/types/autoFreeGift.js +2 -0
- package/dist/cjs/cart/types/autoFreeGift.js.map +7 -0
- package/dist/cjs/cart/types/index.d.ts +1 -0
- package/dist/cjs/cart/types/index.d.ts.map +1 -1
- package/dist/cjs/cart/types/index.js +1 -1
- package/dist/cjs/cart/types/index.js.map +1 -1
- package/dist/cjs/cart/types/orderDiscount.d.ts +35 -0
- package/dist/cjs/cart/types/orderDiscount.d.ts.map +1 -0
- package/dist/cjs/cart/types/orderDiscount.js +2 -0
- package/dist/cjs/cart/types/orderDiscount.js.map +7 -0
- package/dist/cjs/cart/types/priceDiscount.d.ts +20 -0
- package/dist/cjs/cart/types/priceDiscount.d.ts.map +1 -0
- package/dist/cjs/cart/types/priceDiscount.js +2 -0
- package/dist/cjs/cart/types/priceDiscount.js.map +7 -0
- package/dist/cjs/cart/utils/autoFreeGift.d.ts +21 -0
- package/dist/cjs/cart/utils/autoFreeGift.d.ts.map +1 -0
- package/dist/cjs/cart/utils/autoFreeGift.js +2 -0
- package/dist/cjs/cart/utils/autoFreeGift.js.map +7 -0
- package/dist/cjs/cart/utils/index.d.ts +1 -0
- package/dist/cjs/cart/utils/index.d.ts.map +1 -1
- package/dist/cjs/cart/utils/index.js +1 -1
- package/dist/cjs/cart/utils/index.js.map +3 -3
- package/dist/cjs/constants.d.ts +2 -0
- package/dist/cjs/constants.d.ts.map +1 -0
- package/dist/cjs/constants.js +2 -0
- package/dist/cjs/constants.js.map +7 -0
- package/dist/cjs/context/index.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/registration/hooks/index.d.ts +1 -0
- package/dist/cjs/registration/hooks/index.d.ts.map +1 -1
- package/dist/cjs/registration/hooks/index.js +1 -1
- package/dist/cjs/registration/hooks/index.js.map +2 -2
- package/dist/cjs/registration/hooks/useEmailValidation.d.ts.map +1 -1
- package/dist/cjs/registration/hooks/useEmailValidation.js +1 -1
- package/dist/cjs/registration/hooks/useEmailValidation.js.map +3 -3
- package/dist/cjs/registration/hooks/useSendEmailValidation.d.ts.map +1 -1
- package/dist/cjs/registration/hooks/useSendEmailValidation.js +1 -1
- package/dist/cjs/registration/hooks/useSendEmailValidation.js.map +3 -3
- package/dist/cjs/registration/hooks/useSubscriptions.d.ts +15 -0
- package/dist/cjs/registration/hooks/useSubscriptions.d.ts.map +1 -0
- package/dist/cjs/registration/hooks/useSubscriptions.js +2 -0
- package/dist/cjs/registration/hooks/useSubscriptions.js.map +7 -0
- package/dist/cjs/registration/index.d.ts +0 -1
- package/dist/cjs/registration/index.d.ts.map +1 -1
- package/dist/cjs/registration/index.js +1 -1
- package/dist/cjs/registration/index.js.map +2 -2
- package/dist/cjs/shopify/fetchers/index.d.ts +2 -0
- package/dist/cjs/shopify/fetchers/index.d.ts.map +1 -1
- package/dist/cjs/shopify/fetchers/index.js +1 -1
- package/dist/cjs/shopify/fetchers/index.js.map +3 -3
- package/dist/esm/cart/context/index.d.ts +47 -0
- package/dist/esm/cart/context/index.d.ts.map +1 -0
- package/dist/esm/cart/context/index.js +2 -0
- package/dist/esm/cart/context/index.js.map +7 -0
- package/dist/esm/cart/hooks/basic/useAddToCart.d.ts +30 -0
- package/dist/esm/cart/hooks/basic/useAddToCart.d.ts.map +1 -0
- package/dist/esm/cart/hooks/basic/useAddToCart.js +2 -0
- package/dist/esm/cart/hooks/basic/useAddToCart.js.map +7 -0
- package/dist/esm/cart/hooks/basic/useApplyCartCodes.d.ts +11 -0
- package/dist/esm/cart/hooks/basic/useApplyCartCodes.d.ts.map +1 -0
- package/dist/esm/cart/hooks/basic/useApplyCartCodes.js +2 -0
- package/dist/esm/cart/hooks/basic/useApplyCartCodes.js.map +7 -0
- package/dist/esm/cart/hooks/basic/useBuyNow.d.ts +1 -1
- package/dist/esm/cart/hooks/basic/useBuyNow.d.ts.map +1 -1
- package/dist/esm/cart/hooks/basic/useBuyNow.js +1 -1
- package/dist/esm/cart/hooks/basic/useBuyNow.js.map +3 -3
- package/dist/esm/cart/hooks/basic/useCreateCart.d.ts +7 -0
- package/dist/esm/cart/hooks/basic/useCreateCart.d.ts.map +1 -0
- package/dist/esm/cart/hooks/basic/useCreateCart.js +2 -0
- package/dist/esm/cart/hooks/basic/useCreateCart.js.map +7 -0
- package/dist/esm/cart/hooks/basic/useRemoveCartCodes.d.ts +11 -0
- package/dist/esm/cart/hooks/basic/useRemoveCartCodes.d.ts.map +1 -0
- package/dist/esm/cart/hooks/basic/useRemoveCartCodes.js +2 -0
- package/dist/esm/cart/hooks/basic/useRemoveCartCodes.js.map +7 -0
- package/dist/esm/cart/hooks/basic/useRemoveCartLines.d.ts +11 -0
- package/dist/esm/cart/hooks/basic/useRemoveCartLines.d.ts.map +1 -0
- package/dist/esm/cart/hooks/basic/useRemoveCartLines.js +2 -0
- package/dist/esm/cart/hooks/basic/useRemoveCartLines.js.map +7 -0
- package/dist/esm/cart/hooks/basic/useUpdateCartAttributes.d.ts +8 -0
- package/dist/esm/cart/hooks/basic/useUpdateCartAttributes.d.ts.map +1 -0
- package/dist/esm/cart/hooks/basic/useUpdateCartAttributes.js +2 -0
- package/dist/esm/cart/hooks/basic/useUpdateCartAttributes.js.map +7 -0
- package/dist/esm/cart/hooks/basic/useUpdateCartBuyerIdentity.d.ts +8 -0
- package/dist/esm/cart/hooks/basic/useUpdateCartBuyerIdentity.d.ts.map +1 -0
- package/dist/esm/cart/hooks/basic/useUpdateCartBuyerIdentity.js +2 -0
- package/dist/esm/cart/hooks/basic/useUpdateCartBuyerIdentity.js.map +7 -0
- package/dist/esm/cart/hooks/basic/useUpdateCartLines.d.ts +8 -0
- package/dist/esm/cart/hooks/basic/useUpdateCartLines.d.ts.map +1 -0
- package/dist/esm/cart/hooks/basic/useUpdateCartLines.js +2 -0
- package/dist/esm/cart/hooks/basic/useUpdateCartLines.js.map +7 -0
- package/dist/esm/cart/hooks/feature/useCalcAutoFreeGift.d.ts +10 -0
- package/dist/esm/cart/hooks/feature/useCalcAutoFreeGift.d.ts.map +1 -0
- package/dist/esm/cart/hooks/feature/useCalcAutoFreeGift.js +2 -0
- package/dist/esm/cart/hooks/feature/useCalcAutoFreeGift.js.map +7 -0
- package/dist/esm/cart/hooks/feature/useCalcOrderDiscount.d.ts +21 -0
- package/dist/esm/cart/hooks/feature/useCalcOrderDiscount.d.ts.map +1 -0
- package/dist/esm/cart/hooks/feature/useCalcOrderDiscount.js +2 -0
- package/dist/esm/cart/hooks/feature/useCalcOrderDiscount.js.map +7 -0
- package/dist/esm/cart/hooks/feature/useCartAttributes.d.ts +10 -0
- package/dist/esm/cart/hooks/feature/useCartAttributes.d.ts.map +1 -0
- package/dist/esm/cart/hooks/feature/useCartAttributes.js +2 -0
- package/dist/esm/cart/hooks/feature/useCartAttributes.js.map +7 -0
- package/dist/esm/cart/hooks/feature/useCartItemQuantityLimit.d.ts +19 -0
- package/dist/esm/cart/hooks/feature/useCartItemQuantityLimit.d.ts.map +1 -0
- package/dist/esm/cart/hooks/feature/useCartItemQuantityLimit.js +2 -0
- package/dist/esm/cart/hooks/feature/useCartItemQuantityLimit.js.map +7 -0
- package/dist/esm/cart/hooks/feature/useScriptAutoFreeGift.d.ts +37 -0
- package/dist/esm/cart/hooks/feature/useScriptAutoFreeGift.d.ts.map +1 -0
- package/dist/esm/cart/hooks/feature/useScriptAutoFreeGift.js +2 -0
- package/dist/esm/cart/hooks/feature/useScriptAutoFreeGift.js.map +7 -0
- package/dist/esm/cart/hooks/feature/useUpdateLineCodeAmountAttributes.d.ts +9 -0
- package/dist/esm/cart/hooks/feature/useUpdateLineCodeAmountAttributes.d.ts.map +1 -0
- package/dist/esm/cart/hooks/feature/useUpdateLineCodeAmountAttributes.js +2 -0
- package/dist/esm/cart/hooks/feature/useUpdateLineCodeAmountAttributes.js.map +7 -0
- package/dist/esm/cart/track/fbq.d.ts +2 -9
- package/dist/esm/cart/track/fbq.d.ts.map +1 -1
- package/dist/esm/cart/track/fbq.js +1 -1
- package/dist/esm/cart/track/fbq.js.map +3 -3
- package/dist/esm/cart/track/gtm.d.ts +26 -0
- package/dist/esm/cart/track/gtm.d.ts.map +1 -0
- package/dist/esm/cart/track/gtm.js +2 -0
- package/dist/esm/cart/track/gtm.js.map +7 -0
- package/dist/esm/cart/types/autoFreeGift.d.ts +135 -0
- package/dist/esm/cart/types/autoFreeGift.d.ts.map +1 -0
- package/dist/esm/cart/types/autoFreeGift.js +2 -0
- package/dist/esm/cart/types/autoFreeGift.js.map +7 -0
- package/dist/esm/cart/types/index.d.ts +1 -0
- package/dist/esm/cart/types/index.d.ts.map +1 -1
- package/dist/esm/cart/types/orderDiscount.d.ts +35 -0
- package/dist/esm/cart/types/orderDiscount.d.ts.map +1 -0
- package/dist/esm/cart/types/orderDiscount.js +2 -0
- package/dist/esm/cart/types/orderDiscount.js.map +7 -0
- package/dist/esm/cart/types/priceDiscount.d.ts +20 -0
- package/dist/esm/cart/types/priceDiscount.d.ts.map +1 -0
- package/dist/esm/cart/types/priceDiscount.js +2 -0
- package/dist/esm/cart/types/priceDiscount.js.map +7 -0
- package/dist/esm/cart/utils/autoFreeGift.d.ts +21 -0
- package/dist/esm/cart/utils/autoFreeGift.d.ts.map +1 -0
- package/dist/esm/cart/utils/autoFreeGift.js +2 -0
- package/dist/esm/cart/utils/autoFreeGift.js.map +7 -0
- package/dist/esm/cart/utils/index.d.ts +1 -0
- package/dist/esm/cart/utils/index.d.ts.map +1 -1
- package/dist/esm/cart/utils/index.js +1 -1
- package/dist/esm/cart/utils/index.js.map +3 -3
- package/dist/esm/constants.d.ts +2 -0
- package/dist/esm/constants.d.ts.map +1 -0
- package/dist/esm/constants.js +2 -0
- package/dist/esm/constants.js.map +7 -0
- package/dist/esm/context/index.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/registration/hooks/index.d.ts +1 -0
- package/dist/esm/registration/hooks/index.d.ts.map +1 -1
- package/dist/esm/registration/hooks/index.js +1 -1
- package/dist/esm/registration/hooks/index.js.map +2 -2
- package/dist/esm/registration/hooks/useEmailValidation.d.ts.map +1 -1
- package/dist/esm/registration/hooks/useEmailValidation.js +1 -1
- package/dist/esm/registration/hooks/useEmailValidation.js.map +3 -3
- package/dist/esm/registration/hooks/useSendEmailValidation.d.ts.map +1 -1
- package/dist/esm/registration/hooks/useSendEmailValidation.js +1 -1
- package/dist/esm/registration/hooks/useSendEmailValidation.js.map +2 -2
- package/dist/esm/registration/hooks/useSubscriptions.d.ts +15 -0
- package/dist/esm/registration/hooks/useSubscriptions.d.ts.map +1 -0
- package/dist/esm/registration/hooks/useSubscriptions.js +2 -0
- package/dist/esm/registration/hooks/useSubscriptions.js.map +7 -0
- package/dist/esm/registration/index.d.ts +0 -1
- package/dist/esm/registration/index.d.ts.map +1 -1
- package/dist/esm/registration/index.js +1 -1
- package/dist/esm/registration/index.js.map +2 -2
- package/dist/esm/shopify/fetchers/index.d.ts +2 -0
- package/dist/esm/shopify/fetchers/index.d.ts.map +1 -1
- package/dist/esm/shopify/fetchers/index.js +1 -1
- package/dist/esm/shopify/fetchers/index.js.map +3 -3
- package/dist/registration/hooks/index.d.ts +4 -0
- package/dist/registration/hooks/index.d.ts.map +1 -0
- package/dist/registration/hooks/useEmailValidation.d.ts +17 -0
- package/dist/registration/hooks/useEmailValidation.d.ts.map +1 -0
- package/dist/registration/hooks/useSendEmailValidation.d.ts +9 -0
- package/dist/registration/hooks/useSendEmailValidation.d.ts.map +1 -0
- package/dist/registration/hooks/useSubscriptions.d.ts +15 -0
- package/dist/registration/hooks/useSubscriptions.d.ts.map +1 -0
- package/dist/registration/index.d.ts +2 -0
- package/dist/registration/index.d.ts.map +1 -0
- package/dist/utils/classnames.d.ts +3 -0
- package/dist/utils/classnames.d.ts.map +1 -0
- package/dist/utils/fetcher/fetchResponse.d.ts +14 -0
- package/dist/utils/fetcher/fetchResponse.d.ts.map +1 -0
- package/dist/utils/fetcher/fetcher.d.ts +2 -0
- package/dist/utils/fetcher/fetcher.d.ts.map +1 -0
- package/dist/utils/fetcher/index.d.ts +3 -0
- package/dist/utils/fetcher/index.d.ts.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/track.d.ts +16 -0
- package/dist/utils/track.d.ts.map +1 -0
- package/dist/utils/useCountDown.d.ts +6 -0
- package/dist/utils/useCountDown.d.ts.map +1 -0
- package/esbuild-esm.mjs +1 -0
- package/jest.config.ts +3 -0
- package/package.json +4 -5
- package/src/cart/context/index.tsx +310 -0
- package/src/cart/hooks/basic/useAddToCart.ts +161 -0
- package/src/cart/hooks/basic/useApplyCartCodes.ts +72 -0
- package/src/cart/hooks/basic/useBuyNow.ts +10 -7
- package/src/cart/hooks/basic/useCreateCart.ts +32 -0
- package/src/cart/hooks/basic/useRemoveCartCodes.ts +55 -0
- package/src/cart/hooks/basic/useRemoveCartLines.ts +51 -0
- package/src/cart/hooks/basic/useUpdateCartAttributes.ts +42 -0
- package/src/cart/hooks/basic/useUpdateCartBuyerIdentity.ts +34 -0
- package/src/cart/hooks/basic/useUpdateCartLines.ts +34 -0
- package/src/cart/hooks/feature/useCalcAutoFreeGift.tsx +178 -0
- package/src/cart/hooks/feature/useCalcOrderDiscount.tsx +127 -0
- package/src/cart/hooks/feature/useCartAttributes.tsx +133 -0
- package/src/cart/hooks/feature/useCartItemQuantityLimit.tsx +59 -0
- package/src/cart/hooks/feature/useScriptAutoFreeGift.tsx +256 -0
- package/src/cart/hooks/feature/useUpdateLineCodeAmountAttributes.tsx +184 -0
- package/src/cart/track/fbq.ts +4 -29
- package/src/cart/track/gtm.ts +159 -0
- package/src/cart/types/autoFreeGift.ts +169 -0
- package/src/cart/types/index.ts +1 -0
- package/src/cart/types/orderDiscount.ts +38 -0
- package/src/cart/types/priceDiscount.ts +21 -0
- package/src/cart/utils/autoFreeGift.ts +297 -0
- package/src/cart/utils/index.ts +13 -0
- package/src/constants.ts +1 -0
- package/src/context/index.ts +0 -1
- package/src/index.ts +6 -0
- package/src/registration/hooks/index.ts +3 -0
- package/src/registration/hooks/useEmailValidation.ts +28 -0
- package/src/registration/hooks/useSendEmailValidation.ts +21 -0
- package/src/registration/hooks/useSubscriptions.ts +36 -0
- package/src/registration/index.ts +2 -0
- package/src/shopify/fetchers/index.ts +2 -0
- package/src/utils/classnames.ts +6 -0
- package/src/utils/fetcher/fetchResponse.ts +33 -0
- package/src/utils/fetcher/fetcher.ts +38 -0
- package/src/utils/fetcher/index.ts +2 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/track.ts +57 -0
- package/src/utils/useCountDown.tsx +41 -0
- package/tsconfig.json +4 -0
- package/tsup.config.ts +10 -8
- package/dist/cjs/registration/context/index.d.ts +0 -24
- package/dist/cjs/registration/context/index.d.ts.map +0 -1
- package/dist/cjs/registration/context/index.js +0 -2
- package/dist/cjs/registration/context/index.js.map +0 -7
- package/dist/esm/registration/context/index.d.ts +0 -24
- package/dist/esm/registration/context/index.d.ts.map +0 -1
- package/dist/esm/registration/context/index.js +0 -2
- package/dist/esm/registration/context/index.js.map +0 -7
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../../src/utils/fetcher/fetcher.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,GAAU,mEAS3B,GAAG,iBA0BL,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/fetcher/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA;AACvB,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Window {
|
|
3
|
+
dataLayer?: Array<any>;
|
|
4
|
+
fbq?: (...args: any[]) => void;
|
|
5
|
+
klaviyo?: any;
|
|
6
|
+
gtag?: (...args: any[]) => void;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export declare const gaTrack: (data: any) => "" | undefined;
|
|
10
|
+
export declare function gaNormalClick({ position, label }: {
|
|
11
|
+
position: string;
|
|
12
|
+
label: string;
|
|
13
|
+
}): void;
|
|
14
|
+
export declare const fbq: (...args: any[]) => "" | undefined;
|
|
15
|
+
export declare const gtag: (...args: any[]) => "" | undefined;
|
|
16
|
+
//# sourceMappingURL=track.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"track.d.ts","sourceRoot":"","sources":["../../src/utils/track.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,SAAS,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;QACtB,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;QAC9B,OAAO,CAAC,EAAE,GAAG,CAAA;QACb,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;KAChC;CACF;AAGD,eAAO,MAAM,OAAO,GAAI,MAAM,GAAG,mBAehC,CAAA;AAED,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,QAUrF;AAGD,eAAO,MAAM,GAAG,GAAI,GAAG,MAAM,GAAG,EAAE,mBAOjC,CAAA;AAED,eAAO,MAAM,IAAI,GAAI,GAAG,MAAM,GAAG,EAAE,mBAOlC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCountDown.d.ts","sourceRoot":"","sources":["../../src/utils/useCountDown.tsx"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,aAAa,EAAE,MAAM,EAAE,KAAK,aAAW;;;;EAsCnE"}
|
package/esbuild-esm.mjs
CHANGED
package/jest.config.ts
CHANGED
|
@@ -7,6 +7,9 @@ const config: JestConfigWithTsJest = {
|
|
|
7
7
|
coverageDirectory: 'coverage', // 输出覆盖率报告
|
|
8
8
|
testMatch: ['**/__tests__/**/*.test.ts'], // 匹配测试文件路径
|
|
9
9
|
moduleFileExtensions: ['ts', 'js', 'json'],
|
|
10
|
+
moduleNameMapper: {
|
|
11
|
+
'^src/(.*)$': '<rootDir>/src/$1',
|
|
12
|
+
},
|
|
10
13
|
}
|
|
11
14
|
|
|
12
15
|
export default config
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anker-in/lib",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2-beta.1",
|
|
4
4
|
"description": "Unified Anker headless library with shared context, Shopify integration, and cart utilities",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -18,8 +18,6 @@
|
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"react": "^18.0.0",
|
|
22
|
-
"react-dom": "^18.0.0",
|
|
23
21
|
"tailwind-merge": "^1.11.0",
|
|
24
22
|
"clsx": "^2.1.1"
|
|
25
23
|
},
|
|
@@ -54,10 +52,11 @@
|
|
|
54
52
|
"license": "MIT",
|
|
55
53
|
"scripts": {
|
|
56
54
|
"dev": "tsup --watch",
|
|
57
|
-
"build": "pnpm run build:js:esm & pnpm run build:js:cjs & pnpm run build:types",
|
|
55
|
+
"build": "pnpm run build:js:esm & pnpm run build:js:cjs & pnpm run build:types:esm & pnpm run build:types:cjs",
|
|
58
56
|
"build:js:cjs": "node esbuild-cjs.mjs",
|
|
59
57
|
"build:js:esm": "node esbuild-esm.mjs",
|
|
60
|
-
"build:types": "tsc --outdir dist",
|
|
58
|
+
"build:types:esm": "tsc --outdir dist/esm",
|
|
59
|
+
"build:types:cjs": "tsc --outdir dist/cjs",
|
|
61
60
|
"test": "jest --passWithNoTests",
|
|
62
61
|
"test:watch": "jest --watch",
|
|
63
62
|
"coverage": "jest --coverage",
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import React, { createContext, useContext, useState, useMemo, useEffect, useCallback } from 'react'
|
|
2
|
+
import { Cart } from '../../shopify/types/cart'
|
|
3
|
+
|
|
4
|
+
import { AutoFreeGiftConfig, FunctionGiftResult, AutoFreeGiftList } from '../types/autoFreeGift'
|
|
5
|
+
import { useCalcAutoFreeGift } from '../hooks/feature/useCalcAutoFreeGift'
|
|
6
|
+
import { getCart } from '../../shopify/fetchers/get-cart'
|
|
7
|
+
import { useRequest } from 'ahooks'
|
|
8
|
+
import { useHeadlessContext } from '../../context'
|
|
9
|
+
import { useUpdateCartAttributes } from '../hooks/basic/useUpdateCartAttributes'
|
|
10
|
+
import { useCartAttributes } from '../hooks/feature/useCartAttributes'
|
|
11
|
+
import { AttributeInput } from '../../shopify/gql'
|
|
12
|
+
import { isAttributesEqual } from '../utils'
|
|
13
|
+
import { useUpdateLineCodeAmountAttributes } from '../hooks/feature/useUpdateLineCodeAmountAttributes'
|
|
14
|
+
import useScriptAutoFreeGift, { UseScriptAutoFreeGiftResult } from '../hooks/feature/useScriptAutoFreeGift'
|
|
15
|
+
import {
|
|
16
|
+
formatScriptAutoFreeGift,
|
|
17
|
+
formatFunctionAutoFreeGift,
|
|
18
|
+
getDiscountEnvAttributeValue,
|
|
19
|
+
} from '../utils/autoFreeGift'
|
|
20
|
+
import { CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY } from '../../shopify/utils/const'
|
|
21
|
+
|
|
22
|
+
export type LoadingState = {
|
|
23
|
+
editLineQuantityLoading: boolean
|
|
24
|
+
editLineCodeAmountLoading: boolean
|
|
25
|
+
listingAutoCodeApplying: boolean
|
|
26
|
+
userCodeApplying: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type CartContextType = {
|
|
30
|
+
cart: Cart | undefined
|
|
31
|
+
isCartLoading: boolean
|
|
32
|
+
mutateCart: (cart: Cart | undefined) => void
|
|
33
|
+
triggerFetch: () => void
|
|
34
|
+
calculatedAutoFreeGift?: FunctionGiftResult | undefined
|
|
35
|
+
addCustomAttributes: (attributes: AttributeInput[]) => void
|
|
36
|
+
removeCustomAttributes: (attributes: { key: string }[]) => void
|
|
37
|
+
setCustomAttributes: (attributes: AttributeInput[]) => void
|
|
38
|
+
isCodeChanging: boolean
|
|
39
|
+
setIsCodeChanging: (isCodeChanging: boolean) => void
|
|
40
|
+
autoFreeGiftConfig?: AutoFreeGiftConfig
|
|
41
|
+
setLoadingState: React.Dispatch<React.SetStateAction<LoadingState>>
|
|
42
|
+
loadingState: LoadingState
|
|
43
|
+
scriptAutoFreeGiftResult?: UseScriptAutoFreeGiftResult
|
|
44
|
+
scriptAutoFreeGift?: AutoFreeGiftList
|
|
45
|
+
functionAutoFreeGiftResult?: FunctionGiftResult
|
|
46
|
+
functionAutoFreeGift?: AutoFreeGiftList
|
|
47
|
+
setFunctionAutoFreeGift: (functionAutoFreeGift: AutoFreeGiftList) => void
|
|
48
|
+
setScriptAutoFreeGift: (scriptAutoFreeGift: AutoFreeGiftList) => void
|
|
49
|
+
giftNeedAddToCartLines: AutoFreeGiftList
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const initialState: CartContextType = {
|
|
53
|
+
cart: undefined,
|
|
54
|
+
isCartLoading: false,
|
|
55
|
+
mutateCart: () => {},
|
|
56
|
+
triggerFetch: () => {},
|
|
57
|
+
calculatedAutoFreeGift: undefined,
|
|
58
|
+
addCustomAttributes: () => {},
|
|
59
|
+
removeCustomAttributes: () => {},
|
|
60
|
+
setCustomAttributes: () => {},
|
|
61
|
+
isCodeChanging: false,
|
|
62
|
+
setIsCodeChanging: () => {},
|
|
63
|
+
setLoadingState: () => {},
|
|
64
|
+
loadingState: {
|
|
65
|
+
editLineQuantityLoading: false,
|
|
66
|
+
editLineCodeAmountLoading: false,
|
|
67
|
+
listingAutoCodeApplying: false,
|
|
68
|
+
userCodeApplying: false,
|
|
69
|
+
},
|
|
70
|
+
scriptAutoFreeGift: undefined,
|
|
71
|
+
functionAutoFreeGift: undefined,
|
|
72
|
+
scriptAutoFreeGiftResult: undefined,
|
|
73
|
+
functionAutoFreeGiftResult: undefined,
|
|
74
|
+
setFunctionAutoFreeGift: () => {},
|
|
75
|
+
setScriptAutoFreeGift: () => {},
|
|
76
|
+
giftNeedAddToCartLines: [],
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export const CartContext = createContext<CartContextType>(initialState)
|
|
80
|
+
|
|
81
|
+
type CartProviderProps = {
|
|
82
|
+
children: React.ReactNode
|
|
83
|
+
autoFreeGiftConfig?: AutoFreeGiftConfig
|
|
84
|
+
gradientGiftsConfig: any
|
|
85
|
+
profile: any
|
|
86
|
+
customer: any
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const CartProvider = ({
|
|
90
|
+
children,
|
|
91
|
+
autoFreeGiftConfig,
|
|
92
|
+
gradientGiftsConfig,
|
|
93
|
+
profile,
|
|
94
|
+
customer,
|
|
95
|
+
}: CartProviderProps) => {
|
|
96
|
+
const { storefrontToken, storeDomain, cartIdCookieName, locale } = useHeadlessContext()
|
|
97
|
+
const [customAttributes, setCustomAttributes] = useState<AttributeInput[]>([])
|
|
98
|
+
const [isCodeChanging, setIsCodeChanging] = useState(false)
|
|
99
|
+
const [loadingState, setLoadingState] = useState<LoadingState>({
|
|
100
|
+
editLineQuantityLoading: false,
|
|
101
|
+
editLineCodeAmountLoading: false,
|
|
102
|
+
listingAutoCodeApplying: false,
|
|
103
|
+
userCodeApplying: false,
|
|
104
|
+
})
|
|
105
|
+
const [scriptAutoFreeGift, setScriptAutoFreeGift] = useState<AutoFreeGiftList>([])
|
|
106
|
+
const [functionAutoFreeGift, setFunctionAutoFreeGift] = useState<AutoFreeGiftList>([])
|
|
107
|
+
|
|
108
|
+
// 获取购物车逻辑
|
|
109
|
+
const {
|
|
110
|
+
run: fetchCart,
|
|
111
|
+
data: cart,
|
|
112
|
+
loading: isCartLoading,
|
|
113
|
+
mutate: mutateCart,
|
|
114
|
+
} = useRequest(
|
|
115
|
+
async () => {
|
|
116
|
+
// 从 cookie 获取 cartId
|
|
117
|
+
const cartId =
|
|
118
|
+
typeof window !== 'undefined'
|
|
119
|
+
? document.cookie
|
|
120
|
+
.split('; ')
|
|
121
|
+
.find(row => row.startsWith(`${cartIdCookieName}=`))
|
|
122
|
+
?.split('=')[1]
|
|
123
|
+
: undefined
|
|
124
|
+
|
|
125
|
+
if (!cartId) {
|
|
126
|
+
return undefined
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return getCart({
|
|
130
|
+
options: { cartId },
|
|
131
|
+
config: {
|
|
132
|
+
storefrontToken,
|
|
133
|
+
storeDomain,
|
|
134
|
+
},
|
|
135
|
+
})
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
refreshDeps: [locale, storefrontToken, storeDomain, cartIdCookieName],
|
|
139
|
+
}
|
|
140
|
+
) as unknown as {
|
|
141
|
+
run: () => Promise<Cart | undefined>
|
|
142
|
+
mutate: (cart: Cart | undefined) => void
|
|
143
|
+
data: Cart | undefined
|
|
144
|
+
loading: boolean
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// 更新 attributes
|
|
148
|
+
const { trigger: updateAttributes } = useUpdateCartAttributes()
|
|
149
|
+
// 公共 attributes
|
|
150
|
+
const { attributes } = useCartAttributes({ profile, customer, cart })
|
|
151
|
+
|
|
152
|
+
useRequest(
|
|
153
|
+
async () => {
|
|
154
|
+
// 去重逻辑
|
|
155
|
+
const newAttributes = [...attributes, ...customAttributes]
|
|
156
|
+
|
|
157
|
+
const needUpdate = cart && !isAttributesEqual(cart.customAttributes, newAttributes)
|
|
158
|
+
|
|
159
|
+
// 如果 attributes 没有变化,不更新
|
|
160
|
+
if (needUpdate && cart) {
|
|
161
|
+
const updatedCart = await updateAttributes({
|
|
162
|
+
cartId: cart.id,
|
|
163
|
+
attributes: newAttributes,
|
|
164
|
+
})
|
|
165
|
+
if (updatedCart) {
|
|
166
|
+
mutateCart(updatedCart)
|
|
167
|
+
}
|
|
168
|
+
return updatedCart
|
|
169
|
+
} else {
|
|
170
|
+
return Promise.resolve(cart)
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
throttleWait: 1000, // 1 秒内只触发最后一次更新
|
|
175
|
+
throttleTrailing: true,
|
|
176
|
+
throttleLeading: false,
|
|
177
|
+
refreshDeps: [attributes, customAttributes, cart?.id],
|
|
178
|
+
}
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
// 更新 code 时,同步更新 line item 中的 code amount attribute
|
|
182
|
+
useUpdateLineCodeAmountAttributes({
|
|
183
|
+
cart,
|
|
184
|
+
mutateCart,
|
|
185
|
+
isCartLoading: isCartLoading || isCodeChanging,
|
|
186
|
+
setLoadingState,
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
// 计算购物车赠品 - 只计算,不执行副作用
|
|
190
|
+
const functionAutoFreeGiftResult = useCalcAutoFreeGift(cart, autoFreeGiftConfig || [], customer)
|
|
191
|
+
const scriptAutoFreeGiftResult = useScriptAutoFreeGift({
|
|
192
|
+
campaign: gradientGiftsConfig,
|
|
193
|
+
_giveaway: CUSTOMER_SCRIPT_GIFT_KEY,
|
|
194
|
+
cart,
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
const formattedScriptGifts = useMemo(() => {
|
|
198
|
+
return formatScriptAutoFreeGift({
|
|
199
|
+
scriptAutoFreeGiftResult,
|
|
200
|
+
gradient_gifts: gradientGiftsConfig,
|
|
201
|
+
locale,
|
|
202
|
+
})
|
|
203
|
+
}, [scriptAutoFreeGiftResult, gradientGiftsConfig, locale])
|
|
204
|
+
|
|
205
|
+
const formattedFunctionGifts = useMemo(() => {
|
|
206
|
+
return formatFunctionAutoFreeGift({
|
|
207
|
+
qualifyingGift: functionAutoFreeGiftResult?.qualifyingGift || null,
|
|
208
|
+
giftProductsResult: (functionAutoFreeGiftResult?.giftProductsResult as any[]) || [],
|
|
209
|
+
locale,
|
|
210
|
+
})
|
|
211
|
+
}, [functionAutoFreeGiftResult, locale])
|
|
212
|
+
|
|
213
|
+
// 当格式化结果变化时更新状态
|
|
214
|
+
useEffect(() => {
|
|
215
|
+
if (
|
|
216
|
+
loadingState.userCodeApplying ||
|
|
217
|
+
loadingState.editLineQuantityLoading ||
|
|
218
|
+
loadingState.editLineCodeAmountLoading ||
|
|
219
|
+
loadingState.listingAutoCodeApplying
|
|
220
|
+
) {
|
|
221
|
+
return
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
setScriptAutoFreeGift(formattedScriptGifts)
|
|
225
|
+
setFunctionAutoFreeGift(formattedFunctionGifts)
|
|
226
|
+
}, [
|
|
227
|
+
formattedScriptGifts,
|
|
228
|
+
formattedFunctionGifts,
|
|
229
|
+
loadingState.userCodeApplying,
|
|
230
|
+
loadingState.editLineQuantityLoading,
|
|
231
|
+
loadingState.editLineCodeAmountLoading,
|
|
232
|
+
loadingState.listingAutoCodeApplying,
|
|
233
|
+
])
|
|
234
|
+
|
|
235
|
+
const giftNeedAddToCartLines = useMemo(() => {
|
|
236
|
+
const cartGiftLineItems = cart?.lineItems.filter(line =>
|
|
237
|
+
line.customAttributes?.some((attr: any) => [CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY].includes(attr.key))
|
|
238
|
+
)
|
|
239
|
+
const result = [...scriptAutoFreeGift, ...functionAutoFreeGift].filter(
|
|
240
|
+
item =>
|
|
241
|
+
// 如果购物车中已经存在对应赠品,且标记了 function 满赠的属性,则不添加
|
|
242
|
+
!cartGiftLineItems?.find(line => {
|
|
243
|
+
return (
|
|
244
|
+
line.variantId === item.line.variantId &&
|
|
245
|
+
line.customAttributes?.some((attr: any) => {
|
|
246
|
+
if (attr.key === '_discounts_function_env') {
|
|
247
|
+
return getDiscountEnvAttributeValue(line.customAttributes).is_gift
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return false
|
|
251
|
+
})
|
|
252
|
+
)
|
|
253
|
+
})
|
|
254
|
+
)
|
|
255
|
+
return result
|
|
256
|
+
}, [cart?.lineItems, scriptAutoFreeGift, functionAutoFreeGift])
|
|
257
|
+
|
|
258
|
+
const removeCustomAttributes = useCallback((attributes: { key: string }[]) => {
|
|
259
|
+
setCustomAttributes(prev => prev.filter((attr: AttributeInput) => !attributes.some(a => a.key === attr.key)))
|
|
260
|
+
}, [])
|
|
261
|
+
|
|
262
|
+
const addCustomAttributes = useCallback(
|
|
263
|
+
(attributes: AttributeInput[]) => {
|
|
264
|
+
const sameAttributes = attributes.filter(attr => customAttributes.some(a => a.key === attr.key))
|
|
265
|
+
if (sameAttributes.length) {
|
|
266
|
+
setCustomAttributes(prev => {
|
|
267
|
+
// 更新相同的属性
|
|
268
|
+
const removedAttributes = prev.filter((attr: AttributeInput) => !sameAttributes.some(a => a.key === attr.key))
|
|
269
|
+
return [...removedAttributes, ...attributes]
|
|
270
|
+
})
|
|
271
|
+
} else {
|
|
272
|
+
// 添加新的属性
|
|
273
|
+
setCustomAttributes(prev => [...prev, ...attributes])
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
[customAttributes]
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
return (
|
|
280
|
+
<CartContext.Provider
|
|
281
|
+
value={{
|
|
282
|
+
cart,
|
|
283
|
+
mutateCart,
|
|
284
|
+
triggerFetch: fetchCart,
|
|
285
|
+
isCartLoading,
|
|
286
|
+
setCustomAttributes,
|
|
287
|
+
addCustomAttributes: addCustomAttributes,
|
|
288
|
+
removeCustomAttributes: removeCustomAttributes,
|
|
289
|
+
calculatedAutoFreeGift: functionAutoFreeGiftResult || scriptAutoFreeGiftResult,
|
|
290
|
+
isCodeChanging,
|
|
291
|
+
setIsCodeChanging,
|
|
292
|
+
setLoadingState,
|
|
293
|
+
loadingState,
|
|
294
|
+
// function满赠
|
|
295
|
+
functionAutoFreeGift,
|
|
296
|
+
functionAutoFreeGiftResult,
|
|
297
|
+
setFunctionAutoFreeGift,
|
|
298
|
+
// script满赠
|
|
299
|
+
scriptAutoFreeGift,
|
|
300
|
+
scriptAutoFreeGiftResult,
|
|
301
|
+
setScriptAutoFreeGift,
|
|
302
|
+
giftNeedAddToCartLines,
|
|
303
|
+
}}
|
|
304
|
+
>
|
|
305
|
+
{children}
|
|
306
|
+
</CartContext.Provider>
|
|
307
|
+
)
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export const useCartContext = () => useContext(CartContext)
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { Cart, Attributes } from '../../../shopify'
|
|
2
|
+
import { CartBuyerIdentityInput } from '../../../shopify/gql'
|
|
3
|
+
import { useCallback } from 'react'
|
|
4
|
+
import useSWRMutation, { SWRMutationConfiguration } from 'swr/mutation'
|
|
5
|
+
import { GtmParams } from '../../types'
|
|
6
|
+
// import { startInactiveSpan } from '@sentry/nextjs'
|
|
7
|
+
import { addCartLines as addCartLinesFetcher, createCart as createCartFetcher } from '../../../shopify'
|
|
8
|
+
import { useHeadlessContext } from '../../../context'
|
|
9
|
+
import { defaultSWRMutationConfiguration } from '../../const'
|
|
10
|
+
import { addToCartFbq } from '../../track/fbq'
|
|
11
|
+
import { addToCartGa } from '../../track/gtm'
|
|
12
|
+
|
|
13
|
+
type AddToCartLineItem = {
|
|
14
|
+
variant?: { id: string }
|
|
15
|
+
variantId?: string
|
|
16
|
+
quantity?: number
|
|
17
|
+
attributes?: Attributes
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type AddToCartArgs = {
|
|
21
|
+
lineItems: AddToCartLineItem[]
|
|
22
|
+
cartId?: string
|
|
23
|
+
discountCodes?: string[]
|
|
24
|
+
customAttributes?: Attributes
|
|
25
|
+
buyerIdentity?: CartBuyerIdentityInput
|
|
26
|
+
gtmParams?: Exclude<GtmParams, 'brand'>
|
|
27
|
+
needCreateCart?: boolean // 是否强制创建新购物车
|
|
28
|
+
onCodesInvalid?: (updatedCart: Cart, invalidCodes: string[]) => Promise<Cart | undefined> // 折扣码不可用时的回调
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type UseAddToCartProps = {
|
|
32
|
+
withTrack?: boolean // 是否需要默认埋点(暂时注释,需要时可以启用)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const useAddToCart = (
|
|
36
|
+
{ withTrack = true }: UseAddToCartProps = {},
|
|
37
|
+
swrOptions: SWRMutationConfiguration<Cart | undefined, Error, string, AddToCartArgs> & {
|
|
38
|
+
throwOnError?: boolean
|
|
39
|
+
} = defaultSWRMutationConfiguration
|
|
40
|
+
) => {
|
|
41
|
+
const { storefrontToken, storeDomain, brand } = useHeadlessContext()
|
|
42
|
+
|
|
43
|
+
const trigger = useCallback(
|
|
44
|
+
async (_: any, { arg }: { arg: AddToCartArgs }) => {
|
|
45
|
+
const {
|
|
46
|
+
lineItems,
|
|
47
|
+
cartId,
|
|
48
|
+
discountCodes,
|
|
49
|
+
gtmParams = {},
|
|
50
|
+
buyerIdentity,
|
|
51
|
+
needCreateCart = false,
|
|
52
|
+
onCodesInvalid,
|
|
53
|
+
} = arg
|
|
54
|
+
|
|
55
|
+
if (!lineItems || lineItems.length === 0) {
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// const addToCartSpan = startInactiveSpan({
|
|
60
|
+
// name: 'addToCart',
|
|
61
|
+
// op: 'business',
|
|
62
|
+
// })
|
|
63
|
+
|
|
64
|
+
// 准备要添加的商品数据
|
|
65
|
+
const linesToAdd = lineItems
|
|
66
|
+
.map(item => ({
|
|
67
|
+
merchandiseId: item.variant?.id || item.variantId || '',
|
|
68
|
+
quantity: item.quantity || 1,
|
|
69
|
+
attributes: item.attributes,
|
|
70
|
+
}))
|
|
71
|
+
.filter(item => item.merchandiseId && item.quantity)
|
|
72
|
+
|
|
73
|
+
let resultCart: Cart | undefined
|
|
74
|
+
|
|
75
|
+
if (linesToAdd.length > 0) {
|
|
76
|
+
// const addToCartAPISpan = startInactiveSpan({
|
|
77
|
+
// name: 'addToCartAPI',
|
|
78
|
+
// op: 'business',
|
|
79
|
+
// parentSpan: addToCartSpan,
|
|
80
|
+
// })
|
|
81
|
+
|
|
82
|
+
if (!cartId || needCreateCart) {
|
|
83
|
+
// 创建新购物车
|
|
84
|
+
// const createCartApiSpan = startInactiveSpan({
|
|
85
|
+
// name: 'createCartAPI',
|
|
86
|
+
// op: 'business',
|
|
87
|
+
// parentSpan: addToCartAPISpan,
|
|
88
|
+
// })
|
|
89
|
+
|
|
90
|
+
resultCart = await createCartFetcher({
|
|
91
|
+
options: {
|
|
92
|
+
lines: linesToAdd,
|
|
93
|
+
buyerIdentity,
|
|
94
|
+
discountCodes,
|
|
95
|
+
},
|
|
96
|
+
config: {
|
|
97
|
+
storefrontToken,
|
|
98
|
+
storeDomain,
|
|
99
|
+
},
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
// createCartApiSpan.end()
|
|
103
|
+
} else {
|
|
104
|
+
// 添加到现有购物车
|
|
105
|
+
// const addCartLinesApiSpan = startInactiveSpan({
|
|
106
|
+
// name: 'addCartLinesAPI',
|
|
107
|
+
// op: 'business',
|
|
108
|
+
// parentSpan: addToCartAPISpan,
|
|
109
|
+
// })
|
|
110
|
+
|
|
111
|
+
resultCart = await addCartLinesFetcher({
|
|
112
|
+
options: {
|
|
113
|
+
lines: linesToAdd,
|
|
114
|
+
cartId,
|
|
115
|
+
},
|
|
116
|
+
config: {
|
|
117
|
+
storefrontToken,
|
|
118
|
+
storeDomain,
|
|
119
|
+
},
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
// addCartLinesApiSpan.end()
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// addToCartAPISpan.end()
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// 检查是否有不可用的折扣码
|
|
129
|
+
if (resultCart && onCodesInvalid) {
|
|
130
|
+
const unApplicableCodes = resultCart.discountCodes
|
|
131
|
+
?.filter((item) => !item.applicable)
|
|
132
|
+
.map((item) => item.code)
|
|
133
|
+
|
|
134
|
+
if (unApplicableCodes?.length) {
|
|
135
|
+
// const removeCartCodesApiSpan = startInactiveSpan({
|
|
136
|
+
// name: 'removeCartCodesAPI',
|
|
137
|
+
// op: 'business',
|
|
138
|
+
// parentSpan: addToCartSpan,
|
|
139
|
+
// })
|
|
140
|
+
|
|
141
|
+
resultCart = (await onCodesInvalid(resultCart, unApplicableCodes)) || resultCart
|
|
142
|
+
|
|
143
|
+
// removeCartCodesApiSpan.end()
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// 埋点(需要时可以启用)
|
|
148
|
+
if (withTrack) {
|
|
149
|
+
addToCartFbq({ lineItems: resultCart?.lineItems || [] })
|
|
150
|
+
addToCartGa({ lineItems: resultCart?.lineItems || [], gtmParams: { ...gtmParams, brand } })
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// addToCartSpan.end()
|
|
154
|
+
|
|
155
|
+
return resultCart
|
|
156
|
+
},
|
|
157
|
+
[storefrontToken, storeDomain]
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
return useSWRMutation('add-to-cart', trigger, swrOptions)
|
|
161
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Cart } from '../../../shopify'
|
|
2
|
+
import { useCallback } from 'react'
|
|
3
|
+
import useSWRMutation, { SWRMutationConfiguration } from 'swr/mutation'
|
|
4
|
+
import { MutationCartDiscountCodesUpdateArgs } from '../../../shopify/gql'
|
|
5
|
+
// import { startInactiveSpan } from '@sentry/nextjs'
|
|
6
|
+
import { updateCartCodes as updateCartCodesFetcher } from '../../../shopify'
|
|
7
|
+
import { useHeadlessContext } from '../../../context'
|
|
8
|
+
import { defaultSWRMutationConfiguration } from '../../const'
|
|
9
|
+
|
|
10
|
+
export type ApplyCartCodesArgs = {
|
|
11
|
+
cartId: string
|
|
12
|
+
discountCodes: string[]
|
|
13
|
+
currentCart?: Cart // 当前购物车状态,用于合并已有的折扣码
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const useApplyCartCodes = (
|
|
17
|
+
swrOptions: SWRMutationConfiguration<Cart | undefined, Error, string, ApplyCartCodesArgs> & {
|
|
18
|
+
throwOnError?: boolean
|
|
19
|
+
} = defaultSWRMutationConfiguration
|
|
20
|
+
) => {
|
|
21
|
+
const { storefrontToken, storeDomain } = useHeadlessContext()
|
|
22
|
+
|
|
23
|
+
const trigger = useCallback(
|
|
24
|
+
async (_: any, { arg }: { arg: ApplyCartCodesArgs }) => {
|
|
25
|
+
const { cartId, discountCodes, currentCart } = arg
|
|
26
|
+
|
|
27
|
+
if (!discountCodes?.length) {
|
|
28
|
+
throw new Error('Invalid input used for this operation: Miss discountCode')
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (!cartId) {
|
|
32
|
+
throw new Error('cartId is required')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 合并当前已有的可用折扣码
|
|
36
|
+
let existingCodes = currentCart?.discountCodes?.filter(code => code.applicable) || []
|
|
37
|
+
const uniqueCodes = [...new Set([...existingCodes.map(code => code.code), ...discountCodes])]
|
|
38
|
+
|
|
39
|
+
// const applyCartCodesApiSpan = startInactiveSpan({
|
|
40
|
+
// name: 'applyCartCodesAPI',
|
|
41
|
+
// op: 'business',
|
|
42
|
+
// })
|
|
43
|
+
|
|
44
|
+
const updatedCart = await updateCartCodesFetcher({
|
|
45
|
+
options: {
|
|
46
|
+
cartId,
|
|
47
|
+
discountCodes: uniqueCodes,
|
|
48
|
+
},
|
|
49
|
+
config: {
|
|
50
|
+
storefrontToken,
|
|
51
|
+
storeDomain,
|
|
52
|
+
},
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
// applyCartCodesApiSpan.end()
|
|
56
|
+
|
|
57
|
+
// 检查新添加的折扣码是否有不可用的
|
|
58
|
+
const unApplicableCodes = discountCodes.filter((code) =>
|
|
59
|
+
updatedCart?.discountCodes?.find((item) => item.code === code && !item.applicable)
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
if (unApplicableCodes.length) {
|
|
63
|
+
throw new Error(`${unApplicableCodes.join(', ')} is not applicable to the cart`)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return updatedCart
|
|
67
|
+
},
|
|
68
|
+
[storefrontToken, storeDomain]
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
return useSWRMutation('apply-cart-codes', trigger, swrOptions)
|
|
72
|
+
}
|