@shopify/hydrogen-react 2022.10.5 → 2022.10.7

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.
Files changed (43) hide show
  1. package/dist/browser-dev/CartProvider.mjs +5 -109
  2. package/dist/browser-dev/CartProvider.mjs.map +1 -1
  3. package/dist/browser-dev/cart-queries.mjs +207 -59
  4. package/dist/browser-dev/cart-queries.mjs.map +1 -1
  5. package/dist/browser-dev/useCartAPIStateMachine.mjs +6 -3
  6. package/dist/browser-dev/useCartAPIStateMachine.mjs.map +1 -1
  7. package/dist/browser-prod/CartProvider.mjs +5 -109
  8. package/dist/browser-prod/CartProvider.mjs.map +1 -1
  9. package/dist/browser-prod/cart-queries.mjs +207 -59
  10. package/dist/browser-prod/cart-queries.mjs.map +1 -1
  11. package/dist/browser-prod/useCartAPIStateMachine.mjs +6 -3
  12. package/dist/browser-prod/useCartAPIStateMachine.mjs.map +1 -1
  13. package/dist/node-dev/CartProvider.js +6 -110
  14. package/dist/node-dev/CartProvider.js.map +1 -1
  15. package/dist/node-dev/CartProvider.mjs +5 -109
  16. package/dist/node-dev/CartProvider.mjs.map +1 -1
  17. package/dist/node-dev/cart-queries.js +206 -58
  18. package/dist/node-dev/cart-queries.js.map +1 -1
  19. package/dist/node-dev/cart-queries.mjs +207 -59
  20. package/dist/node-dev/cart-queries.mjs.map +1 -1
  21. package/dist/node-dev/useCartAPIStateMachine.js +6 -3
  22. package/dist/node-dev/useCartAPIStateMachine.js.map +1 -1
  23. package/dist/node-dev/useCartAPIStateMachine.mjs +6 -3
  24. package/dist/node-dev/useCartAPIStateMachine.mjs.map +1 -1
  25. package/dist/node-prod/CartProvider.js +6 -110
  26. package/dist/node-prod/CartProvider.js.map +1 -1
  27. package/dist/node-prod/CartProvider.mjs +5 -109
  28. package/dist/node-prod/CartProvider.mjs.map +1 -1
  29. package/dist/node-prod/cart-queries.js +206 -58
  30. package/dist/node-prod/cart-queries.js.map +1 -1
  31. package/dist/node-prod/cart-queries.mjs +207 -59
  32. package/dist/node-prod/cart-queries.mjs.map +1 -1
  33. package/dist/node-prod/useCartAPIStateMachine.js +6 -3
  34. package/dist/node-prod/useCartAPIStateMachine.js.map +1 -1
  35. package/dist/node-prod/useCartAPIStateMachine.mjs +6 -3
  36. package/dist/node-prod/useCartAPIStateMachine.mjs.map +1 -1
  37. package/dist/types/CartProvider.d.ts +0 -1
  38. package/dist/types/cart-queries.d.ts +1 -1
  39. package/dist/umd/hydrogen-react.dev.js +216 -170
  40. package/dist/umd/hydrogen-react.dev.js.map +1 -1
  41. package/dist/umd/hydrogen-react.prod.js +195 -148
  42. package/dist/umd/hydrogen-react.prod.js.map +1 -1
  43. package/package.json +3 -8
@@ -664,106 +664,253 @@
664
664
  return [];
665
665
  }
666
666
  const CartLineAdd = (cartFragment) => `
667
- mutation CartLineAdd($cartId: ID!, $lines: [CartLineInput!]!, $numCartLines: Int = 250, $country: CountryCode = ZZ) @inContext(country: $country) {
668
- cartLinesAdd(cartId: $cartId, lines: $lines) {
669
- cart {
670
- ...CartFragment
667
+ mutation CartLineAdd(
668
+ $cartId: ID!
669
+ $lines: [CartLineInput!]!
670
+ $numCartLines: Int = 250
671
+ $country: CountryCode = ZZ
672
+ ) @inContext(country: $country) {
673
+ cartLinesAdd(cartId: $cartId, lines: $lines) {
674
+ cart {
675
+ ...CartFragment
676
+ }
671
677
  }
672
678
  }
673
- }
674
679
 
675
- ${cartFragment}
680
+ ${cartFragment}
676
681
  `;
677
682
  const CartCreate = (cartFragment) => `
678
- mutation CartCreate($input: CartInput!, $numCartLines: Int = 250, $country: CountryCode = ZZ) @inContext(country: $country) {
679
- cartCreate(input: $input) {
680
- cart {
681
- ...CartFragment
683
+ mutation CartCreate(
684
+ $input: CartInput!
685
+ $numCartLines: Int = 250
686
+ $country: CountryCode = ZZ
687
+ ) @inContext(country: $country) {
688
+ cartCreate(input: $input) {
689
+ cart {
690
+ ...CartFragment
691
+ }
682
692
  }
683
693
  }
684
- }
685
694
 
686
- ${cartFragment}
695
+ ${cartFragment}
687
696
  `;
688
697
  const CartLineRemove = (cartFragment) => `
689
- mutation CartLineRemove($cartId: ID!, $lines: [ID!]!, $numCartLines: Int = 250, $country: CountryCode = ZZ) @inContext(country: $country) {
690
- cartLinesRemove(cartId: $cartId, lineIds: $lines) {
691
- cart {
692
- ...CartFragment
698
+ mutation CartLineRemove(
699
+ $cartId: ID!
700
+ $lines: [ID!]!
701
+ $numCartLines: Int = 250
702
+ $country: CountryCode = ZZ
703
+ ) @inContext(country: $country) {
704
+ cartLinesRemove(cartId: $cartId, lineIds: $lines) {
705
+ cart {
706
+ ...CartFragment
707
+ }
693
708
  }
694
709
  }
695
- }
696
710
 
697
- ${cartFragment}
711
+ ${cartFragment}
698
712
  `;
699
713
  const CartLineUpdate = (cartFragment) => `
700
- mutation CartLineUpdate($cartId: ID!, $lines: [CartLineUpdateInput!]!, $numCartLines: Int = 250, $country: CountryCode = ZZ) @inContext(country: $country) {
701
- cartLinesUpdate(cartId: $cartId, lines: $lines) {
702
- cart {
703
- ...CartFragment
714
+ mutation CartLineUpdate(
715
+ $cartId: ID!
716
+ $lines: [CartLineUpdateInput!]!
717
+ $numCartLines: Int = 250
718
+ $country: CountryCode = ZZ
719
+ ) @inContext(country: $country) {
720
+ cartLinesUpdate(cartId: $cartId, lines: $lines) {
721
+ cart {
722
+ ...CartFragment
723
+ }
704
724
  }
705
725
  }
706
- }
707
726
 
708
- ${cartFragment}
727
+ ${cartFragment}
709
728
  `;
710
729
  const CartNoteUpdate = (cartFragment) => `
711
- mutation CartNoteUpdate($cartId: ID!, $note: String, $numCartLines: Int = 250, $country: CountryCode = ZZ) @inContext(country: $country) {
712
- cartNoteUpdate(cartId: $cartId, note: $note) {
713
- cart {
714
- ...CartFragment
730
+ mutation CartNoteUpdate(
731
+ $cartId: ID!
732
+ $note: String
733
+ $numCartLines: Int = 250
734
+ $country: CountryCode = ZZ
735
+ ) @inContext(country: $country) {
736
+ cartNoteUpdate(cartId: $cartId, note: $note) {
737
+ cart {
738
+ ...CartFragment
739
+ }
715
740
  }
716
741
  }
717
- }
718
742
 
719
- ${cartFragment}
743
+ ${cartFragment}
720
744
  `;
721
745
  const CartBuyerIdentityUpdate = (cartFragment) => `
722
- mutation CartBuyerIdentityUpdate(
723
- $cartId: ID!
724
- $buyerIdentity: CartBuyerIdentityInput!
725
- $numCartLines: Int = 250
726
- $country: CountryCode = ZZ
727
- ) @inContext(country: $country) {
728
- cartBuyerIdentityUpdate(cartId: $cartId, buyerIdentity: $buyerIdentity) {
729
- cart {
730
- ...CartFragment
746
+ mutation CartBuyerIdentityUpdate(
747
+ $cartId: ID!
748
+ $buyerIdentity: CartBuyerIdentityInput!
749
+ $numCartLines: Int = 250
750
+ $country: CountryCode = ZZ
751
+ ) @inContext(country: $country) {
752
+ cartBuyerIdentityUpdate(cartId: $cartId, buyerIdentity: $buyerIdentity) {
753
+ cart {
754
+ ...CartFragment
755
+ }
731
756
  }
732
757
  }
733
- }
734
758
 
735
- ${cartFragment}
759
+ ${cartFragment}
736
760
  `;
737
761
  const CartAttributesUpdate = (cartFragment) => `
738
- mutation CartAttributesUpdate($attributes: [AttributeInput!]!, $cartId: ID!, $numCartLines: Int = 250, $country: CountryCode = ZZ) @inContext(country: $country) {
739
- cartAttributesUpdate(attributes: $attributes, cartId: $cartId) {
740
- cart {
741
- ...CartFragment
762
+ mutation CartAttributesUpdate(
763
+ $attributes: [AttributeInput!]!
764
+ $cartId: ID!
765
+ $numCartLines: Int = 250
766
+ $country: CountryCode = ZZ
767
+ ) @inContext(country: $country) {
768
+ cartAttributesUpdate(attributes: $attributes, cartId: $cartId) {
769
+ cart {
770
+ ...CartFragment
771
+ }
742
772
  }
743
773
  }
744
- }
745
774
 
746
- ${cartFragment}
775
+ ${cartFragment}
747
776
  `;
748
777
  const CartDiscountCodesUpdate = (cartFragment) => `
749
- mutation CartDiscountCodesUpdate($cartId: ID!, $discountCodes: [String!], $numCartLines: Int = 250, $country: CountryCode = ZZ) @inContext(country: $country) {
750
- cartDiscountCodesUpdate(cartId: $cartId, discountCodes: $discountCodes) {
751
- cart {
752
- ...CartFragment
778
+ mutation CartDiscountCodesUpdate(
779
+ $cartId: ID!
780
+ $discountCodes: [String!]
781
+ $numCartLines: Int = 250
782
+ $country: CountryCode = ZZ
783
+ ) @inContext(country: $country) {
784
+ cartDiscountCodesUpdate(cartId: $cartId, discountCodes: $discountCodes) {
785
+ cart {
786
+ ...CartFragment
787
+ }
753
788
  }
754
789
  }
755
- }
756
790
 
757
- ${cartFragment}
791
+ ${cartFragment}
758
792
  `;
759
793
  const CartQuery = (cartFragment) => `
760
- query CartQuery($id: ID!, $numCartLines: Int = 250, $country: CountryCode = ZZ) @inContext(country: $country) {
761
- cart(id: $id) {
762
- ...CartFragment
794
+ query CartQuery(
795
+ $id: ID!
796
+ $numCartLines: Int = 250
797
+ $country: CountryCode = ZZ
798
+ ) @inContext(country: $country) {
799
+ cart(id: $id) {
800
+ ...CartFragment
801
+ }
763
802
  }
764
- }
765
803
 
766
- ${cartFragment}
804
+ ${cartFragment}
805
+ `;
806
+ const defaultCartFragment = `
807
+ fragment CartFragment on Cart {
808
+ id
809
+ checkoutUrl
810
+ totalQuantity
811
+ buyerIdentity {
812
+ countryCode
813
+ customer {
814
+ id
815
+ email
816
+ firstName
817
+ lastName
818
+ displayName
819
+ }
820
+ email
821
+ phone
822
+ }
823
+ lines(first: $numCartLines) {
824
+ edges {
825
+ node {
826
+ id
827
+ quantity
828
+ attributes {
829
+ key
830
+ value
831
+ }
832
+ cost {
833
+ totalAmount {
834
+ amount
835
+ currencyCode
836
+ }
837
+ compareAtAmountPerQuantity {
838
+ amount
839
+ currencyCode
840
+ }
841
+ }
842
+ merchandise {
843
+ ... on ProductVariant {
844
+ id
845
+ availableForSale
846
+ compareAtPrice {
847
+ ...MoneyFragment
848
+ }
849
+ # @deprecated remove in next major
850
+ compareAtPriceV2 {
851
+ ...MoneyFragment
852
+ }
853
+ price {
854
+ ...MoneyFragment
855
+ }
856
+ # @deprecated remove in next major
857
+ priceV2 {
858
+ ...MoneyFragment
859
+ }
860
+ requiresShipping
861
+ title
862
+ image {
863
+ ...ImageFragment
864
+ }
865
+ product {
866
+ handle
867
+ title
868
+ id
869
+ }
870
+ selectedOptions {
871
+ name
872
+ value
873
+ }
874
+ }
875
+ }
876
+ }
877
+ }
878
+ }
879
+ cost {
880
+ subtotalAmount {
881
+ ...MoneyFragment
882
+ }
883
+ totalAmount {
884
+ ...MoneyFragment
885
+ }
886
+ totalDutyAmount {
887
+ ...MoneyFragment
888
+ }
889
+ totalTaxAmount {
890
+ ...MoneyFragment
891
+ }
892
+ }
893
+ note
894
+ attributes {
895
+ key
896
+ value
897
+ }
898
+ discountCodes {
899
+ code
900
+ }
901
+ }
902
+
903
+ fragment MoneyFragment on MoneyV2 {
904
+ currencyCode
905
+ amount
906
+ }
907
+ fragment ImageFragment on Image {
908
+ id
909
+ url
910
+ altText
911
+ width
912
+ height
913
+ }
767
914
  `;
768
915
  const SFAPI_VERSION = "2022-10";
769
916
  const warnings = /* @__PURE__ */ new Set();
@@ -1117,12 +1264,14 @@ ${cartFragment}
1117
1264
  }
1118
1265
  function invokeCart(action, options) {
1119
1266
  return {
1120
- entry: [...(options == null ? void 0 : options.entryActions) || [], "onCartActionEntry", "onCartActionOptimisticUI", action],
1267
+ entry: [...(options == null ? void 0 : options.entryActions) || [], i({
1268
+ lastValidCart: (context) => context == null ? void 0 : context.cart
1269
+ }), "onCartActionEntry", "onCartActionOptimisticUI", action],
1121
1270
  on: {
1122
1271
  RESOLVE: {
1123
1272
  target: (options == null ? void 0 : options.resolveTarget) || "idle",
1124
1273
  actions: [i({
1125
- prevCart: (context) => context == null ? void 0 : context.cart,
1274
+ prevCart: (context) => context == null ? void 0 : context.lastValidCart,
1126
1275
  cart: (_, event) => {
1127
1276
  var _a;
1128
1277
  return (_a = event == null ? void 0 : event.payload) == null ? void 0 : _a.cart;
@@ -1137,7 +1286,7 @@ ${cartFragment}
1137
1286
  ERROR: {
1138
1287
  target: (options == null ? void 0 : options.errorTarget) || "error",
1139
1288
  actions: [i({
1140
- prevCart: (context) => context == null ? void 0 : context.cart,
1289
+ prevCart: (context) => context == null ? void 0 : context.lastValidCart,
1141
1290
  cart: (context) => context == null ? void 0 : context.lastValidCart,
1142
1291
  errors: (_, event) => {
1143
1292
  var _a;
@@ -1151,6 +1300,7 @@ ${cartFragment}
1151
1300
  prevCart: (_) => void 0,
1152
1301
  cart: (_) => void 0,
1153
1302
  lastValidCart: (_) => void 0,
1303
+ rawCartResult: (_) => void 0,
1154
1304
  errors: (_) => void 0
1155
1305
  })
1156
1306
  }
@@ -1480,7 +1630,7 @@ ${cartFragment}
1480
1630
  data: cart,
1481
1631
  cartFragment,
1482
1632
  countryCode,
1483
- onCartActionEntry(context, event) {
1633
+ onCartActionEntry(_, event) {
1484
1634
  try {
1485
1635
  switch (event.type) {
1486
1636
  case "CART_CREATE":
@@ -1506,15 +1656,14 @@ ${cartFragment}
1506
1656
  },
1507
1657
  onCartActionOptimisticUI(context, event) {
1508
1658
  var _a2, _b2, _c2, _d2;
1509
- if (!(context == null ? void 0 : context.cart))
1659
+ if (!context.cart)
1510
1660
  return {
1511
- cart: void 0
1661
+ ...context
1512
1662
  };
1513
1663
  switch (event.type) {
1514
1664
  case "CARTLINE_REMOVE":
1515
1665
  return {
1516
1666
  ...context,
1517
- lastValidCart: context.cart,
1518
1667
  cart: {
1519
1668
  ...context.cart,
1520
1669
  lines: (_b2 = (_a2 = context == null ? void 0 : context.cart) == null ? void 0 : _a2.lines) == null ? void 0 : _b2.filter((line) => (line == null ? void 0 : line.id) && !event.payload.lines.includes(line == null ? void 0 : line.id))
@@ -1523,7 +1672,6 @@ ${cartFragment}
1523
1672
  case "CARTLINE_UPDATE":
1524
1673
  return {
1525
1674
  ...context,
1526
- lastValidCart: context.cart,
1527
1675
  cart: {
1528
1676
  ...context.cart,
1529
1677
  lines: (_d2 = (_c2 = context == null ? void 0 : context.cart) == null ? void 0 : _c2.lines) == null ? void 0 : _d2.map((line) => {
@@ -1542,9 +1690,7 @@ ${cartFragment}
1542
1690
  };
1543
1691
  }
1544
1692
  return {
1545
- cart: context.cart ? {
1546
- ...context.cart
1547
- } : void 0
1693
+ ...context
1548
1694
  };
1549
1695
  },
1550
1696
  onCartActionComplete(context, event) {
@@ -1745,7 +1891,7 @@ ${cartFragment}
1745
1891
  __self: this,
1746
1892
  __source: {
1747
1893
  fileName: _jsxFileName$e,
1748
- lineNumber: 425,
1894
+ lineNumber: 424,
1749
1895
  columnNumber: 5
1750
1896
  }
1751
1897
  }, children);
@@ -1810,106 +1956,6 @@ ${cartFragment}
1810
1956
  var _a, _b;
1811
1957
  return event.payload.buyerIdentity.countryCode && ((_b = (_a = context.cart) == null ? void 0 : _a.buyerIdentity) == null ? void 0 : _b.countryCode) !== event.payload.buyerIdentity.countryCode;
1812
1958
  }
1813
- const defaultCartFragment = `
1814
- fragment CartFragment on Cart {
1815
- id
1816
- checkoutUrl
1817
- totalQuantity
1818
- buyerIdentity {
1819
- countryCode
1820
- customer {
1821
- id
1822
- email
1823
- firstName
1824
- lastName
1825
- displayName
1826
- }
1827
- email
1828
- phone
1829
- }
1830
- lines(first: $numCartLines) {
1831
- edges {
1832
- node {
1833
- id
1834
- quantity
1835
- attributes {
1836
- key
1837
- value
1838
- }
1839
- cost {
1840
- totalAmount {
1841
- amount
1842
- currencyCode
1843
- }
1844
- compareAtAmountPerQuantity {
1845
- amount
1846
- currencyCode
1847
- }
1848
- }
1849
- merchandise {
1850
- ... on ProductVariant {
1851
- id
1852
- availableForSale
1853
- compareAtPriceV2 {
1854
- ...MoneyFragment
1855
- }
1856
- priceV2 {
1857
- ...MoneyFragment
1858
- }
1859
- requiresShipping
1860
- title
1861
- image {
1862
- ...ImageFragment
1863
- }
1864
- product {
1865
- handle
1866
- title
1867
- }
1868
- selectedOptions {
1869
- name
1870
- value
1871
- }
1872
- }
1873
- }
1874
- }
1875
- }
1876
- }
1877
- cost {
1878
- subtotalAmount {
1879
- ...MoneyFragment
1880
- }
1881
- totalAmount {
1882
- ...MoneyFragment
1883
- }
1884
- totalDutyAmount {
1885
- ...MoneyFragment
1886
- }
1887
- totalTaxAmount {
1888
- ...MoneyFragment
1889
- }
1890
- }
1891
- note
1892
- attributes {
1893
- key
1894
- value
1895
- }
1896
- discountCodes {
1897
- code
1898
- }
1899
- }
1900
-
1901
- fragment MoneyFragment on MoneyV2 {
1902
- currencyCode
1903
- amount
1904
- }
1905
- fragment ImageFragment on Image {
1906
- id
1907
- url
1908
- altText
1909
- width
1910
- height
1911
- }
1912
- `;
1913
1959
  var _jsxFileName$d = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ProductProvider.tsx";
1914
1960
  const ProductOptionsContext = React.createContext(null);
1915
1961
  function ProductProvider({