@anker-in/shopify-react 1.0.1 → 1.0.3
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/hooks/index.d.mts +59 -1
- package/dist/hooks/index.d.ts +59 -1
- package/dist/hooks/index.js +34 -12
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +35 -14
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +34 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -14
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.js +2 -3
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs +2 -3
- package/dist/provider/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/hooks/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createContext, useMemo, useRef, useState, useEffect, useCallback, useContext } from 'react';
|
|
2
2
|
import useSWRMutation from 'swr/mutation';
|
|
3
|
-
import { getProductsByHandles, createCart, updateCartCodes, addCartLines, getLocalStorage, updateCartLines, removeCartLines, updateCartAttributes, getProduct, getAllProducts, getCollection, getAllCollections, getCollections, getBlog, getAllBlogs, getArticle, getArticles, getArticlesInBlog, setLocalStorage } from '@anker-in/shopify-sdk';
|
|
3
|
+
import { getProductsByHandles, createCart, updateCartCodes, addCartLines, getLocalStorage, updateCartLines, removeCartLines, updateCartAttributes, updateBuyerIdentity, getProduct, getAllProducts, getCollection, getAllCollections, getCollections, getBlog, getAllBlogs, getArticle, getArticles, getArticlesInBlog, setLocalStorage } from '@anker-in/shopify-sdk';
|
|
4
4
|
import Cookies5 from 'js-cookie';
|
|
5
5
|
import { jsx } from 'react/jsx-runtime';
|
|
6
6
|
import Decimal2 from 'decimal.js';
|
|
@@ -121,8 +121,6 @@ function createMockCartFromLines(lines, existingCart) {
|
|
|
121
121
|
const currency = lines[0]?.variant?.price?.currencyCode;
|
|
122
122
|
return {
|
|
123
123
|
id: existingCart?.id || "temp-cart-id",
|
|
124
|
-
customerId: existingCart?.customerId,
|
|
125
|
-
email: existingCart?.email,
|
|
126
124
|
createdAt: existingCart?.createdAt || (/* @__PURE__ */ new Date()).toISOString(),
|
|
127
125
|
currency: existingCart?.currency || { code: currency },
|
|
128
126
|
taxesIncluded: existingCart?.taxesIncluded,
|
|
@@ -137,7 +135,8 @@ function createMockCartFromLines(lines, existingCart) {
|
|
|
137
135
|
discountAllocations: [],
|
|
138
136
|
url: existingCart?.url || "",
|
|
139
137
|
ready: true,
|
|
140
|
-
customAttributes: existingCart?.customAttributes
|
|
138
|
+
customAttributes: existingCart?.customAttributes,
|
|
139
|
+
buyerIdentity: existingCart?.buyerIdentity
|
|
141
140
|
};
|
|
142
141
|
}
|
|
143
142
|
|
|
@@ -713,14 +712,15 @@ function useAddCartLines(options) {
|
|
|
713
712
|
const { mutateCart, metafieldIdentifiers } = useCartContext();
|
|
714
713
|
const addLines = useCallback(
|
|
715
714
|
async (_key, { arg }) => {
|
|
716
|
-
const { cartId, lines } = arg;
|
|
715
|
+
const { cartId, lines, updateCookie = true } = arg;
|
|
717
716
|
const id = cartId || cartCookieAdapter?.getCartId(locale);
|
|
718
717
|
let updatedCart;
|
|
719
718
|
if (!id) {
|
|
720
719
|
updatedCart = await createCart(client, {
|
|
721
720
|
lines,
|
|
722
721
|
metafieldIdentifiers,
|
|
723
|
-
cookieAdapter: cartCookieAdapter
|
|
722
|
+
cookieAdapter: cartCookieAdapter,
|
|
723
|
+
updateCookie
|
|
724
724
|
});
|
|
725
725
|
} else {
|
|
726
726
|
updatedCart = await addCartLines(client, {
|
|
@@ -882,14 +882,10 @@ function useApplyCartCodes(options) {
|
|
|
882
882
|
const { mutateCart, cart, metafieldIdentifiers } = useCartContext();
|
|
883
883
|
const applyCodes = useCallback(
|
|
884
884
|
async (_key, { arg }) => {
|
|
885
|
-
const { cartId
|
|
885
|
+
const { cartId, discountCodes, replaceExistingCodes } = arg;
|
|
886
886
|
if (!discountCodes?.length) {
|
|
887
887
|
throw new Error("Invalid input used for this operation: Miss discountCode");
|
|
888
888
|
}
|
|
889
|
-
const cartId = providedCartId || cart?.id;
|
|
890
|
-
if (!cartId) {
|
|
891
|
-
return void 0;
|
|
892
|
-
}
|
|
893
889
|
const updatedCart = await updateCartCodes(client, {
|
|
894
890
|
cartId,
|
|
895
891
|
discountCodes: replaceExistingCodes ? discountCodes : [
|
|
@@ -919,8 +915,7 @@ function useRemoveCartCodes(options) {
|
|
|
919
915
|
const { mutateCart, cart, metafieldIdentifiers } = useCartContext();
|
|
920
916
|
const removeCodes = useCallback(
|
|
921
917
|
async (_key, { arg }) => {
|
|
922
|
-
const { cartId
|
|
923
|
-
const cartId = providedCartId || cart?.id;
|
|
918
|
+
const { cartId, discountCodes } = arg;
|
|
924
919
|
const codes = cart?.discountCodes?.filter((code) => !!code.applicable) || [];
|
|
925
920
|
const leftCodes = codes.filter((code) => discountCodes?.length ? !discountCodes.includes(code.code) : code.code).map((code) => code.code);
|
|
926
921
|
const updatedCart = await updateCartCodes(client, {
|
|
@@ -2217,6 +2212,32 @@ function useUpdateCartAttributes({
|
|
|
2217
2212
|
);
|
|
2218
2213
|
return useSWRMutation("update-cart-attributes", updateAttributes, swrOptions);
|
|
2219
2214
|
}
|
|
2215
|
+
function useUpdateBuyerIdentity({
|
|
2216
|
+
mutate,
|
|
2217
|
+
metafieldIdentifiers,
|
|
2218
|
+
disabled = false,
|
|
2219
|
+
swrOptions
|
|
2220
|
+
}) {
|
|
2221
|
+
const { client, locale, cartCookieAdapter } = useShopify();
|
|
2222
|
+
const updateIdentity = useCallback(
|
|
2223
|
+
async (_key, { arg }) => {
|
|
2224
|
+
if (disabled) {
|
|
2225
|
+
return void 0;
|
|
2226
|
+
}
|
|
2227
|
+
const updatedCart = await updateBuyerIdentity(client, {
|
|
2228
|
+
...arg,
|
|
2229
|
+
metafieldIdentifiers,
|
|
2230
|
+
cookieAdapter: cartCookieAdapter
|
|
2231
|
+
});
|
|
2232
|
+
if (updatedCart) {
|
|
2233
|
+
mutate(updatedCart);
|
|
2234
|
+
}
|
|
2235
|
+
return updatedCart;
|
|
2236
|
+
},
|
|
2237
|
+
[client, locale, cartCookieAdapter, mutate, metafieldIdentifiers, disabled]
|
|
2238
|
+
);
|
|
2239
|
+
return useSWRMutation("update-buyer-identity", updateIdentity, swrOptions);
|
|
2240
|
+
}
|
|
2220
2241
|
function useBuyNow({ withTrack = true } = {}, swrOptions) {
|
|
2221
2242
|
const { client, config, locale, cartCookieAdapter, userAdapter } = useShopify();
|
|
2222
2243
|
const { profile, customer, memberSetting } = useCartContext();
|
|
@@ -3083,6 +3104,6 @@ function clearGeoLocationCache(cacheKey = "geoLocation") {
|
|
|
3083
3104
|
}
|
|
3084
3105
|
}
|
|
3085
3106
|
|
|
3086
|
-
export { BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, DeliveryPlusType, MAIN_PRODUCT_CODE, MEMBER_PRICE_ATTRIBUTE_KEY, OrderBasePriceType, OrderDiscountType, PLUS_MEMBER_TYPE, PlusMemberContext, PlusMemberMode, PlusMemberProvider, PriceBasePriceType, PriceDiscountType, RuleType, SCRIPT_CODE_AMOUNT_KEY, ShippingMethodMode, SpendMoneyType, clearGeoLocationCache, createMockCartFromLines, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, getCachedGeoLocation, getCartAttributes, getDiscountEnvAttributeValue, getMatchedMainProductSubTotal, getQuery, getReferralAttributes, getUserType, hasPlusMemberInCart, hasPlusMemberInLines, normalizeAddToCartLines, preCheck, safeParse, useAddCartLines, useAddToCart, useAllBlogs, useAllCollections, useAllProducts, useApplyCartCodes, useArticle, useArticles, useArticlesInBlog, useAutoRemovePlusMemberInCart, useAvailableDeliveryCoupon, useBlog, useBuyNow, useCalcAutoFreeGift, useCalcGiftsFromLines, useCalcOrderDiscount, useCartAttributes, useCartItemQuantityLimit, useCollection, useCollections, useCreateCart, useExposure, useGeoLocation, useHasPlusMemberInCart, useHasPlusMemberInLines, useIntersection, usePlusMemberCheckoutCustomAttributes, usePlusMemberContext, usePlusMemberNeedAddToCart, usePlusMemberVariants, usePrice, useProduct, useProductUrl, useProductsByHandles, useRemoveCartCodes, useRemoveCartLines, useReplaceCartPlusMember, useScriptAutoFreeGift, useSearch, useSelectedOptions, useShippingMethods, useSite, useUpdateCartAttributes, useUpdateCartLines, useUpdateLineCodeAmountAttributes, useUpdateVariantQuery, useVariant, useVariantMedia };
|
|
3107
|
+
export { BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, DeliveryPlusType, MAIN_PRODUCT_CODE, MEMBER_PRICE_ATTRIBUTE_KEY, OrderBasePriceType, OrderDiscountType, PLUS_MEMBER_TYPE, PlusMemberContext, PlusMemberMode, PlusMemberProvider, PriceBasePriceType, PriceDiscountType, RuleType, SCRIPT_CODE_AMOUNT_KEY, ShippingMethodMode, SpendMoneyType, clearGeoLocationCache, createMockCartFromLines, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, getCachedGeoLocation, getCartAttributes, getDiscountEnvAttributeValue, getMatchedMainProductSubTotal, getQuery, getReferralAttributes, getUserType, hasPlusMemberInCart, hasPlusMemberInLines, normalizeAddToCartLines, preCheck, safeParse, useAddCartLines, useAddToCart, useAllBlogs, useAllCollections, useAllProducts, useApplyCartCodes, useArticle, useArticles, useArticlesInBlog, useAutoRemovePlusMemberInCart, useAvailableDeliveryCoupon, useBlog, useBuyNow, useCalcAutoFreeGift, useCalcGiftsFromLines, useCalcOrderDiscount, useCartAttributes, useCartItemQuantityLimit, useCollection, useCollections, useCreateCart, useExposure, useGeoLocation, useHasPlusMemberInCart, useHasPlusMemberInLines, useIntersection, usePlusMemberCheckoutCustomAttributes, usePlusMemberContext, usePlusMemberNeedAddToCart, usePlusMemberVariants, usePrice, useProduct, useProductUrl, useProductsByHandles, useRemoveCartCodes, useRemoveCartLines, useReplaceCartPlusMember, useScriptAutoFreeGift, useSearch, useSelectedOptions, useShippingMethods, useSite, useUpdateBuyerIdentity, useUpdateCartAttributes, useUpdateCartLines, useUpdateLineCodeAmountAttributes, useUpdateVariantQuery, useVariant, useVariantMedia };
|
|
3087
3108
|
//# sourceMappingURL=index.mjs.map
|
|
3088
3109
|
//# sourceMappingURL=index.mjs.map
|