@anker-in/shopify-react 0.1.1-beta.17 → 0.1.1-beta.19

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.
@@ -456,18 +456,24 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
456
456
  }
457
457
  return true;
458
458
  }, [giftHandles]);
459
- const { data: giftProductsResult } = useSWR__default.default(shouldFetch ? giftHandles : null, async () => {
460
- const res = await shopifySdk.getProductsByHandles(client, {
461
- handles: giftHandles,
462
- locale
463
- });
464
- const result = Array.isArray(res) ? res : [];
465
- giftProductsCache.current = {
466
- data: result,
467
- giftHandles: [...giftHandles]
468
- };
469
- return result;
470
- });
459
+ const { data: giftProductsResult } = useSWR__default.default(
460
+ shouldFetch ? giftHandles : null,
461
+ async () => {
462
+ const res = await shopifySdk.getProductsByHandles(client, {
463
+ handles: giftHandles,
464
+ locale
465
+ });
466
+ const result = Array.isArray(res) ? res : [];
467
+ giftProductsCache.current = {
468
+ data: result,
469
+ giftHandles: [...giftHandles]
470
+ };
471
+ return result;
472
+ },
473
+ {
474
+ revalidateOnFocus: false
475
+ }
476
+ );
471
477
  const finalGiftProductsResult = react.useMemo(() => {
472
478
  if (giftProductsCache.current && !shouldFetch) {
473
479
  return giftProductsCache.current.data || void 0;
@@ -520,12 +526,14 @@ var useScriptAutoFreeGift = ({
520
526
  upgrade_multiple2 = 1.2;
521
527
  upgrade_value2 = 40;
522
528
  }
523
- effectiveCart?.lineItems?.forEach(({ customAttributes }) => {
524
- customAttributes?.forEach(({ key, value }) => {
525
- if (key === "_amount_upgrade_multiple") upgrade_multiple2 = Number(value) || 1;
526
- if (key === "_amount_upgrade_value") upgrade_value2 = Number(value) || 0;
527
- });
528
- });
529
+ effectiveCart?.lineItems?.forEach(
530
+ ({ customAttributes }) => {
531
+ customAttributes?.forEach(({ key, value }) => {
532
+ if (key === "_amount_upgrade_multiple") upgrade_multiple2 = Number(value) || 1;
533
+ if (key === "_amount_upgrade_value") upgrade_value2 = Number(value) || 0;
534
+ });
535
+ }
536
+ );
529
537
  return [upgrade_multiple2, upgrade_value2];
530
538
  }, [effectiveCart?.lineItems, points_subscribe]);
531
539
  const breakpoints = react.useMemo(() => {
@@ -590,18 +598,24 @@ var useScriptAutoFreeGift = ({
590
598
  const nextLevel = levelIndex > 0 ? sortedLevels[levelIndex - 1] ?? null : null;
591
599
  return [currentLevel, nextLevel];
592
600
  }, [breakpoints, involvedSubTotal, involvedLines.length]);
593
- const { data: giftProductsResult } = useSWR__default.default(shouldFetch ? giftHandles : null, async () => {
594
- const res = await shopifySdk.getProductsByHandles(client, {
595
- handles: giftHandles,
596
- locale
597
- });
598
- const result = Array.isArray(res) ? res : [];
599
- giftProductsCache.current = {
600
- data: result,
601
- giftHandles: [...giftHandles]
602
- };
603
- return result;
604
- });
601
+ const { data: giftProductsResult } = useSWR__default.default(
602
+ shouldFetch ? giftHandles : null,
603
+ async () => {
604
+ const res = await shopifySdk.getProductsByHandles(client, {
605
+ handles: giftHandles,
606
+ locale
607
+ });
608
+ const result = Array.isArray(res) ? res : [];
609
+ giftProductsCache.current = {
610
+ data: result,
611
+ giftHandles: [...giftHandles]
612
+ };
613
+ return result;
614
+ },
615
+ {
616
+ revalidateOnFocus: false
617
+ }
618
+ );
605
619
  const finalGiftProductsResult = react.useMemo(() => {
606
620
  if (giftProductsCache.current && !shouldFetch) {
607
621
  return giftProductsCache.current.data || void 0;
@@ -839,7 +853,7 @@ function useApplyCartCodes(options) {
839
853
  if (!discountCodes?.length) {
840
854
  throw new Error("Invalid input used for this operation: Miss discountCode");
841
855
  }
842
- const cartId = providedCartId ? void 0 : providedCartId || cart?.id;
856
+ const cartId = providedCartId || cart?.id;
843
857
  if (!cartId) {
844
858
  return void 0;
845
859
  }
@@ -867,7 +881,7 @@ function useRemoveCartCodes(options) {
867
881
  const removeCodes = react.useCallback(
868
882
  async (_key, { arg }) => {
869
883
  const { cartId: providedCartId, discountCodes } = arg;
870
- const cartId = providedCartId ? void 0 : providedCartId || cart?.id;
884
+ const cartId = providedCartId || cart?.id;
871
885
  const codes = cart?.discountCodes?.filter((code) => !!code.applicable) || [];
872
886
  const leftCodes = codes.filter((code) => discountCodes?.length ? !discountCodes.includes(code.code) : code.code).map((code) => code.code);
873
887
  const updatedCart = await shopifySdk.updateCartCodes(client, {
@@ -1418,8 +1432,29 @@ var useCartAttributes = ({
1418
1432
  [memberAttributes, functionAttributes, presellAttributes, weightAttributes, trackingAttributes]
1419
1433
  );
1420
1434
  const extraAttributesInCart = react.useMemo(() => {
1435
+ const commonAttributeKeys = [
1436
+ // member attributes
1437
+ "_token",
1438
+ "_member_type",
1439
+ "_user_type",
1440
+ "_is_login",
1441
+ "_login_user",
1442
+ // function attributes
1443
+ "_discounts_function_env",
1444
+ // presell attributes
1445
+ "_presale",
1446
+ // weight attributes
1447
+ "_weight",
1448
+ "_app_source_name",
1449
+ // tracking attributes
1450
+ "utm_params",
1451
+ // referral attributes
1452
+ "_invite_code",
1453
+ "_play_mode_id",
1454
+ "_popup"
1455
+ ];
1421
1456
  return cart?.customAttributes?.filter(
1422
- (item) => !commonAttributes.some((attr) => attr.key === item.key)
1457
+ (item) => !commonAttributeKeys.includes(item.key)
1423
1458
  ) || [];
1424
1459
  }, [cart]);
1425
1460
  return react.useMemo(
@@ -1645,8 +1680,9 @@ function useProductsByHandles(options = {}) {
1645
1680
  metafieldIdentifiers
1646
1681
  });
1647
1682
  },
1648
- swrOptions || {
1649
- revalidateOnFocus: false
1683
+ {
1684
+ revalidateOnFocus: false,
1685
+ ...swrOptions
1650
1686
  }
1651
1687
  );
1652
1688
  }