@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/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createContext, useMemo, useContext, useRef, useState, useEffect, useCallback } from 'react';
|
|
2
|
-
import { createShopifyClient, getProductsByHandles, createCart, updateCartCodes, addCartLines, getLocalStorage, updateCartLines, removeCartLines, updateCartAttributes, getProduct, getAllProducts, getCollection, getAllCollections, getCollections, getBlog, getAllBlogs, getArticle, getArticles, getArticlesInBlog, getCart, setLocalStorage } from '@anker-in/shopify-sdk';
|
|
2
|
+
import { createShopifyClient, getProductsByHandles, createCart, updateCartCodes, addCartLines, getLocalStorage, updateCartLines, removeCartLines, updateCartAttributes, updateBuyerIdentity, getProduct, getAllProducts, getCollection, getAllCollections, getCollections, getBlog, getAllBlogs, getArticle, getArticles, getArticlesInBlog, getCart, setLocalStorage } from '@anker-in/shopify-sdk';
|
|
3
3
|
export * from '@anker-in/shopify-sdk';
|
|
4
4
|
import Cookies5 from 'js-cookie';
|
|
5
5
|
import { jsx } from 'react/jsx-runtime';
|
|
@@ -210,8 +210,6 @@ function createMockCartFromLines(lines, existingCart) {
|
|
|
210
210
|
const currency = lines[0]?.variant?.price?.currencyCode;
|
|
211
211
|
return {
|
|
212
212
|
id: existingCart?.id || "temp-cart-id",
|
|
213
|
-
customerId: existingCart?.customerId,
|
|
214
|
-
email: existingCart?.email,
|
|
215
213
|
createdAt: existingCart?.createdAt || (/* @__PURE__ */ new Date()).toISOString(),
|
|
216
214
|
currency: existingCart?.currency || { code: currency },
|
|
217
215
|
taxesIncluded: existingCart?.taxesIncluded,
|
|
@@ -226,7 +224,8 @@ function createMockCartFromLines(lines, existingCart) {
|
|
|
226
224
|
discountAllocations: [],
|
|
227
225
|
url: existingCart?.url || "",
|
|
228
226
|
ready: true,
|
|
229
|
-
customAttributes: existingCart?.customAttributes
|
|
227
|
+
customAttributes: existingCart?.customAttributes,
|
|
228
|
+
buyerIdentity: existingCart?.buyerIdentity
|
|
230
229
|
};
|
|
231
230
|
}
|
|
232
231
|
|
|
@@ -802,14 +801,15 @@ function useAddCartLines(options) {
|
|
|
802
801
|
const { mutateCart, metafieldIdentifiers } = useCartContext();
|
|
803
802
|
const addLines = useCallback(
|
|
804
803
|
async (_key, { arg }) => {
|
|
805
|
-
const { cartId, lines } = arg;
|
|
804
|
+
const { cartId, lines, updateCookie = true } = arg;
|
|
806
805
|
const id = cartId || cartCookieAdapter?.getCartId(locale);
|
|
807
806
|
let updatedCart;
|
|
808
807
|
if (!id) {
|
|
809
808
|
updatedCart = await createCart(client, {
|
|
810
809
|
lines,
|
|
811
810
|
metafieldIdentifiers,
|
|
812
|
-
cookieAdapter: cartCookieAdapter
|
|
811
|
+
cookieAdapter: cartCookieAdapter,
|
|
812
|
+
updateCookie
|
|
813
813
|
});
|
|
814
814
|
} else {
|
|
815
815
|
updatedCart = await addCartLines(client, {
|
|
@@ -1006,14 +1006,10 @@ function useApplyCartCodes(options) {
|
|
|
1006
1006
|
const { mutateCart, cart, metafieldIdentifiers } = useCartContext();
|
|
1007
1007
|
const applyCodes = useCallback(
|
|
1008
1008
|
async (_key, { arg }) => {
|
|
1009
|
-
const { cartId
|
|
1009
|
+
const { cartId, discountCodes, replaceExistingCodes } = arg;
|
|
1010
1010
|
if (!discountCodes?.length) {
|
|
1011
1011
|
throw new Error("Invalid input used for this operation: Miss discountCode");
|
|
1012
1012
|
}
|
|
1013
|
-
const cartId = providedCartId || cart?.id;
|
|
1014
|
-
if (!cartId) {
|
|
1015
|
-
return void 0;
|
|
1016
|
-
}
|
|
1017
1013
|
const updatedCart = await updateCartCodes(client, {
|
|
1018
1014
|
cartId,
|
|
1019
1015
|
discountCodes: replaceExistingCodes ? discountCodes : [
|
|
@@ -1043,8 +1039,7 @@ function useRemoveCartCodes(options) {
|
|
|
1043
1039
|
const { mutateCart, cart, metafieldIdentifiers } = useCartContext();
|
|
1044
1040
|
const removeCodes = useCallback(
|
|
1045
1041
|
async (_key, { arg }) => {
|
|
1046
|
-
const { cartId
|
|
1047
|
-
const cartId = providedCartId || cart?.id;
|
|
1042
|
+
const { cartId, discountCodes } = arg;
|
|
1048
1043
|
const codes = cart?.discountCodes?.filter((code) => !!code.applicable) || [];
|
|
1049
1044
|
const leftCodes = codes.filter((code) => discountCodes?.length ? !discountCodes.includes(code.code) : code.code).map((code) => code.code);
|
|
1050
1045
|
const updatedCart = await updateCartCodes(client, {
|
|
@@ -2341,6 +2336,32 @@ function useUpdateCartAttributes({
|
|
|
2341
2336
|
);
|
|
2342
2337
|
return useSWRMutation("update-cart-attributes", updateAttributes, swrOptions);
|
|
2343
2338
|
}
|
|
2339
|
+
function useUpdateBuyerIdentity({
|
|
2340
|
+
mutate,
|
|
2341
|
+
metafieldIdentifiers,
|
|
2342
|
+
disabled = false,
|
|
2343
|
+
swrOptions
|
|
2344
|
+
}) {
|
|
2345
|
+
const { client, locale, cartCookieAdapter } = useShopify();
|
|
2346
|
+
const updateIdentity = useCallback(
|
|
2347
|
+
async (_key, { arg }) => {
|
|
2348
|
+
if (disabled) {
|
|
2349
|
+
return void 0;
|
|
2350
|
+
}
|
|
2351
|
+
const updatedCart = await updateBuyerIdentity(client, {
|
|
2352
|
+
...arg,
|
|
2353
|
+
metafieldIdentifiers,
|
|
2354
|
+
cookieAdapter: cartCookieAdapter
|
|
2355
|
+
});
|
|
2356
|
+
if (updatedCart) {
|
|
2357
|
+
mutate(updatedCart);
|
|
2358
|
+
}
|
|
2359
|
+
return updatedCart;
|
|
2360
|
+
},
|
|
2361
|
+
[client, locale, cartCookieAdapter, mutate, metafieldIdentifiers, disabled]
|
|
2362
|
+
);
|
|
2363
|
+
return useSWRMutation("update-buyer-identity", updateIdentity, swrOptions);
|
|
2364
|
+
}
|
|
2344
2365
|
function useBuyNow({ withTrack = true } = {}, swrOptions) {
|
|
2345
2366
|
const { client, config, locale, cartCookieAdapter, userAdapter } = useShopify();
|
|
2346
2367
|
const { profile, customer, memberSetting } = useCartContext();
|
|
@@ -3444,6 +3465,6 @@ function useCartContext(options) {
|
|
|
3444
3465
|
return context;
|
|
3445
3466
|
}
|
|
3446
3467
|
|
|
3447
|
-
export { BrowserPerformanceAdapter, BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, CartProvider, DeliveryPlusType, MAIN_PRODUCT_CODE, MEMBER_PRICE_ATTRIBUTE_KEY, OrderBasePriceType, OrderDiscountType, PLUS_MEMBER_TYPE, PlusMemberContext, PlusMemberMode, PlusMemberProvider, PriceBasePriceType, PriceDiscountType, RuleType, SCRIPT_CODE_AMOUNT_KEY, ShippingMethodMode, ShopifyContext, ShopifyProvider, SpendMoneyType, browserCartCookieAdapter, browserCookieAdapter, clearGeoLocationCache, createMockCartFromLines, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, gaTrack, getCachedGeoLocation, getCartAttributes, getDiscountEnvAttributeValue, getMatchedMainProductSubTotal, getQuery, getReferralAttributes, getUserType, hasPlusMemberInCart, hasPlusMemberInLines, normalizeAddToCartLines, preCheck, safeParse, trackAddToCartFBQ, trackAddToCartGA, trackBeginCheckoutGA, trackBuyNowFBQ, trackBuyNowGA, useAddCartLines, useAddToCart, useAllBlogs, useAllCollections, useAllProducts, useApplyCartCodes, useArticle, useArticles, useArticlesInBlog, useAutoRemovePlusMemberInCart, useAvailableDeliveryCoupon, useBlog, useBuyNow, useCalcAutoFreeGift, useCalcGiftsFromLines, useCalcOrderDiscount, useCartAttributes, useCartContext, useCartItemQuantityLimit, useCollection, useCollections, useCreateCart, useExposure, useGeoLocation, useHasPlusMemberInCart, useHasPlusMemberInLines, useIntersection, usePlusMemberCheckoutCustomAttributes, usePlusMemberContext, usePlusMemberNeedAddToCart, usePlusMemberVariants, usePrice, useProduct, useProductUrl, useProductsByHandles, useRemoveCartCodes, useRemoveCartLines, useReplaceCartPlusMember, useScriptAutoFreeGift, useSearch, useSelectedOptions, useShippingMethods, useShopify, useSite, useUpdateCartAttributes, useUpdateCartLines, useUpdateLineCodeAmountAttributes, useUpdateVariantQuery, useVariant, useVariantMedia };
|
|
3468
|
+
export { BrowserPerformanceAdapter, BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, CartProvider, DeliveryPlusType, MAIN_PRODUCT_CODE, MEMBER_PRICE_ATTRIBUTE_KEY, OrderBasePriceType, OrderDiscountType, PLUS_MEMBER_TYPE, PlusMemberContext, PlusMemberMode, PlusMemberProvider, PriceBasePriceType, PriceDiscountType, RuleType, SCRIPT_CODE_AMOUNT_KEY, ShippingMethodMode, ShopifyContext, ShopifyProvider, SpendMoneyType, browserCartCookieAdapter, browserCookieAdapter, clearGeoLocationCache, createMockCartFromLines, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, gaTrack, getCachedGeoLocation, getCartAttributes, getDiscountEnvAttributeValue, getMatchedMainProductSubTotal, getQuery, getReferralAttributes, getUserType, hasPlusMemberInCart, hasPlusMemberInLines, normalizeAddToCartLines, preCheck, safeParse, trackAddToCartFBQ, trackAddToCartGA, trackBeginCheckoutGA, trackBuyNowFBQ, trackBuyNowGA, useAddCartLines, useAddToCart, useAllBlogs, useAllCollections, useAllProducts, useApplyCartCodes, useArticle, useArticles, useArticlesInBlog, useAutoRemovePlusMemberInCart, useAvailableDeliveryCoupon, useBlog, useBuyNow, useCalcAutoFreeGift, useCalcGiftsFromLines, useCalcOrderDiscount, useCartAttributes, useCartContext, useCartItemQuantityLimit, useCollection, useCollections, useCreateCart, useExposure, useGeoLocation, useHasPlusMemberInCart, useHasPlusMemberInLines, useIntersection, usePlusMemberCheckoutCustomAttributes, usePlusMemberContext, usePlusMemberNeedAddToCart, usePlusMemberVariants, usePrice, useProduct, useProductUrl, useProductsByHandles, useRemoveCartCodes, useRemoveCartLines, useReplaceCartPlusMember, useScriptAutoFreeGift, useSearch, useSelectedOptions, useShippingMethods, useShopify, useSite, useUpdateBuyerIdentity, useUpdateCartAttributes, useUpdateCartLines, useUpdateLineCodeAmountAttributes, useUpdateVariantQuery, useVariant, useVariantMedia };
|
|
3448
3469
|
//# sourceMappingURL=index.mjs.map
|
|
3449
3470
|
//# sourceMappingURL=index.mjs.map
|