@shopify/hydrogen-react 2022.7.0 → 2022.7.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.
Files changed (261) hide show
  1. package/README.md +6 -4
  2. package/dist/dev/CartProvider.cjs +485 -0
  3. package/dist/dev/CartProvider.cjs.map +1 -0
  4. package/dist/dev/CartProvider.js +485 -0
  5. package/dist/dev/CartProvider.js.map +1 -0
  6. package/dist/dev/MediaFile.cjs.map +1 -1
  7. package/dist/dev/MediaFile.js.map +1 -1
  8. package/dist/dev/Metafield.cjs +2 -2
  9. package/dist/dev/Metafield.cjs.map +1 -1
  10. package/dist/dev/ModelViewer.cjs +4 -4
  11. package/dist/dev/ModelViewer.cjs.map +1 -1
  12. package/dist/dev/Money.cjs.map +1 -1
  13. package/dist/dev/Money.js.map +1 -1
  14. package/dist/dev/ProductPrice.cjs.map +1 -1
  15. package/dist/dev/ProductPrice.js.map +1 -1
  16. package/dist/dev/ProductProvider.cjs +14 -14
  17. package/dist/dev/ProductProvider.cjs.map +1 -1
  18. package/dist/dev/ShopPayButton.cjs.map +1 -1
  19. package/dist/dev/ShopPayButton.js.map +1 -1
  20. package/dist/dev/ShopifyProvider.cjs +4 -4
  21. package/dist/dev/ShopifyProvider.cjs.map +1 -1
  22. package/dist/dev/Video.cjs +2 -2
  23. package/dist/dev/_virtual/index.cjs +5 -0
  24. package/dist/dev/_virtual/index.cjs.map +1 -0
  25. package/dist/dev/_virtual/index.js +5 -0
  26. package/dist/dev/_virtual/index.js.map +1 -0
  27. package/dist/dev/_virtual/use-sync-external-store-shim.development.cjs +5 -0
  28. package/dist/dev/_virtual/use-sync-external-store-shim.development.cjs.map +1 -0
  29. package/dist/dev/_virtual/use-sync-external-store-shim.development.js +5 -0
  30. package/dist/dev/_virtual/use-sync-external-store-shim.development.js.map +1 -0
  31. package/dist/dev/_virtual/use-sync-external-store-shim.production.min.cjs +5 -0
  32. package/dist/dev/_virtual/use-sync-external-store-shim.production.min.cjs.map +1 -0
  33. package/dist/dev/_virtual/use-sync-external-store-shim.production.min.js +5 -0
  34. package/dist/dev/_virtual/use-sync-external-store-shim.production.min.js.map +1 -0
  35. package/dist/dev/_virtual/with-selector.cjs +5 -0
  36. package/dist/dev/_virtual/with-selector.cjs.map +1 -0
  37. package/dist/dev/_virtual/with-selector.development.cjs +5 -0
  38. package/dist/dev/_virtual/with-selector.development.cjs.map +1 -0
  39. package/dist/dev/_virtual/with-selector.development.js +5 -0
  40. package/dist/dev/_virtual/with-selector.development.js.map +1 -0
  41. package/dist/dev/_virtual/with-selector.js +5 -0
  42. package/dist/dev/_virtual/with-selector.js.map +1 -0
  43. package/dist/dev/_virtual/with-selector.production.min.cjs +5 -0
  44. package/dist/dev/_virtual/with-selector.production.min.cjs.map +1 -0
  45. package/dist/dev/_virtual/with-selector.production.min.js +5 -0
  46. package/dist/dev/_virtual/with-selector.production.min.js.map +1 -0
  47. package/dist/dev/cart-constants.cjs +17 -0
  48. package/dist/dev/cart-constants.cjs.map +1 -0
  49. package/dist/dev/cart-constants.js +17 -0
  50. package/dist/dev/cart-constants.js.map +1 -0
  51. package/dist/dev/cart-hooks.cjs +89 -0
  52. package/dist/dev/cart-hooks.cjs.map +1 -0
  53. package/dist/dev/cart-hooks.js +89 -0
  54. package/dist/dev/cart-hooks.js.map +1 -0
  55. package/dist/dev/cart-queries.cjs +216 -0
  56. package/dist/dev/cart-queries.cjs.map +1 -0
  57. package/dist/dev/cart-queries.js +216 -0
  58. package/dist/dev/cart-queries.js.map +1 -0
  59. package/dist/dev/flatten-connection.cjs +6 -0
  60. package/dist/dev/flatten-connection.cjs.map +1 -1
  61. package/dist/dev/flatten-connection.js +6 -0
  62. package/dist/dev/flatten-connection.js.map +1 -1
  63. package/dist/dev/index.cjs +6 -0
  64. package/dist/dev/index.cjs.map +1 -1
  65. package/dist/dev/index.js +6 -0
  66. package/dist/dev/index.js.map +1 -1
  67. package/dist/dev/load-script.cjs +3 -3
  68. package/dist/dev/load-script.cjs.map +1 -1
  69. package/dist/dev/node_modules/@xstate/fsm/es/index.cjs +158 -0
  70. package/dist/dev/node_modules/@xstate/fsm/es/index.cjs.map +1 -0
  71. package/dist/dev/node_modules/@xstate/fsm/es/index.js +159 -0
  72. package/dist/dev/node_modules/@xstate/fsm/es/index.js.map +1 -0
  73. package/dist/dev/node_modules/@xstate/react/es/fsm.cjs +94 -0
  74. package/dist/dev/node_modules/@xstate/react/es/fsm.cjs.map +1 -0
  75. package/dist/dev/node_modules/@xstate/react/es/fsm.js +94 -0
  76. package/dist/dev/node_modules/@xstate/react/es/fsm.js.map +1 -0
  77. package/dist/dev/node_modules/@xstate/react/es/useConstant.cjs +30 -0
  78. package/dist/dev/node_modules/@xstate/react/es/useConstant.cjs.map +1 -0
  79. package/dist/dev/node_modules/@xstate/react/es/useConstant.js +12 -0
  80. package/dist/dev/node_modules/@xstate/react/es/useConstant.js.map +1 -0
  81. package/dist/dev/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.cjs +5 -0
  82. package/dist/dev/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.cjs.map +1 -0
  83. package/dist/dev/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.js +6 -0
  84. package/dist/dev/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.js.map +1 -0
  85. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.cjs +107 -0
  86. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.cjs.map +1 -0
  87. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js +105 -0
  88. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js.map +1 -0
  89. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.cjs +74 -0
  90. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.cjs.map +1 -0
  91. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js +72 -0
  92. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js.map +1 -0
  93. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.cjs +138 -0
  94. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.cjs.map +1 -0
  95. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +136 -0
  96. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js.map +1 -0
  97. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.cjs +60 -0
  98. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.cjs.map +1 -0
  99. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js +58 -0
  100. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js.map +1 -0
  101. package/dist/dev/node_modules/use-sync-external-store/shim/index.cjs +21 -0
  102. package/dist/dev/node_modules/use-sync-external-store/shim/index.cjs.map +1 -0
  103. package/dist/dev/node_modules/use-sync-external-store/shim/index.js +21 -0
  104. package/dist/dev/node_modules/use-sync-external-store/shim/index.js.map +1 -0
  105. package/dist/dev/node_modules/use-sync-external-store/shim/with-selector.cjs +12 -0
  106. package/dist/dev/node_modules/use-sync-external-store/shim/with-selector.cjs.map +1 -0
  107. package/dist/dev/node_modules/use-sync-external-store/shim/with-selector.js +11 -0
  108. package/dist/dev/node_modules/use-sync-external-store/shim/with-selector.js.map +1 -0
  109. package/dist/dev/node_modules/worktop/cookie/index.cjs +27 -0
  110. package/dist/dev/node_modules/worktop/cookie/index.cjs.map +1 -0
  111. package/dist/dev/node_modules/worktop/cookie/index.js +27 -0
  112. package/dist/dev/node_modules/worktop/cookie/index.js.map +1 -0
  113. package/dist/dev/useCartAPIStateMachine.cjs +326 -0
  114. package/dist/dev/useCartAPIStateMachine.cjs.map +1 -0
  115. package/dist/dev/useCartAPIStateMachine.js +326 -0
  116. package/dist/dev/useCartAPIStateMachine.js.map +1 -0
  117. package/dist/dev/useCartActions.cjs +123 -0
  118. package/dist/dev/useCartActions.cjs.map +1 -0
  119. package/dist/dev/useCartActions.js +123 -0
  120. package/dist/dev/useCartActions.js.map +1 -0
  121. package/dist/dev/useMoney.cjs +5 -5
  122. package/dist/dev/useMoney.cjs.map +1 -1
  123. package/dist/prod/CartProvider.cjs +485 -0
  124. package/dist/prod/CartProvider.cjs.map +1 -0
  125. package/dist/prod/CartProvider.js +485 -0
  126. package/dist/prod/CartProvider.js.map +1 -0
  127. package/dist/prod/MediaFile.cjs.map +1 -1
  128. package/dist/prod/MediaFile.js.map +1 -1
  129. package/dist/prod/Metafield.cjs +2 -2
  130. package/dist/prod/Metafield.cjs.map +1 -1
  131. package/dist/prod/ModelViewer.cjs +4 -4
  132. package/dist/prod/ModelViewer.cjs.map +1 -1
  133. package/dist/prod/Money.cjs.map +1 -1
  134. package/dist/prod/Money.js.map +1 -1
  135. package/dist/prod/ProductPrice.cjs.map +1 -1
  136. package/dist/prod/ProductPrice.js.map +1 -1
  137. package/dist/prod/ProductProvider.cjs +14 -14
  138. package/dist/prod/ProductProvider.cjs.map +1 -1
  139. package/dist/prod/ShopPayButton.cjs.map +1 -1
  140. package/dist/prod/ShopPayButton.js.map +1 -1
  141. package/dist/prod/ShopifyProvider.cjs +4 -4
  142. package/dist/prod/ShopifyProvider.cjs.map +1 -1
  143. package/dist/prod/Video.cjs +2 -2
  144. package/dist/prod/_virtual/index.cjs +5 -0
  145. package/dist/prod/_virtual/index.cjs.map +1 -0
  146. package/dist/prod/_virtual/index.js +5 -0
  147. package/dist/prod/_virtual/index.js.map +1 -0
  148. package/dist/prod/_virtual/use-sync-external-store-shim.development.cjs +5 -0
  149. package/dist/prod/_virtual/use-sync-external-store-shim.development.cjs.map +1 -0
  150. package/dist/prod/_virtual/use-sync-external-store-shim.development.js +5 -0
  151. package/dist/prod/_virtual/use-sync-external-store-shim.development.js.map +1 -0
  152. package/dist/prod/_virtual/use-sync-external-store-shim.production.min.cjs +5 -0
  153. package/dist/prod/_virtual/use-sync-external-store-shim.production.min.cjs.map +1 -0
  154. package/dist/prod/_virtual/use-sync-external-store-shim.production.min.js +5 -0
  155. package/dist/prod/_virtual/use-sync-external-store-shim.production.min.js.map +1 -0
  156. package/dist/prod/_virtual/with-selector.cjs +5 -0
  157. package/dist/prod/_virtual/with-selector.cjs.map +1 -0
  158. package/dist/prod/_virtual/with-selector.development.cjs +5 -0
  159. package/dist/prod/_virtual/with-selector.development.cjs.map +1 -0
  160. package/dist/prod/_virtual/with-selector.development.js +5 -0
  161. package/dist/prod/_virtual/with-selector.development.js.map +1 -0
  162. package/dist/prod/_virtual/with-selector.js +5 -0
  163. package/dist/prod/_virtual/with-selector.js.map +1 -0
  164. package/dist/prod/_virtual/with-selector.production.min.cjs +5 -0
  165. package/dist/prod/_virtual/with-selector.production.min.cjs.map +1 -0
  166. package/dist/prod/_virtual/with-selector.production.min.js +5 -0
  167. package/dist/prod/_virtual/with-selector.production.min.js.map +1 -0
  168. package/dist/prod/cart-constants.cjs +17 -0
  169. package/dist/prod/cart-constants.cjs.map +1 -0
  170. package/dist/prod/cart-constants.js +17 -0
  171. package/dist/prod/cart-constants.js.map +1 -0
  172. package/dist/prod/cart-hooks.cjs +89 -0
  173. package/dist/prod/cart-hooks.cjs.map +1 -0
  174. package/dist/prod/cart-hooks.js +89 -0
  175. package/dist/prod/cart-hooks.js.map +1 -0
  176. package/dist/prod/cart-queries.cjs +216 -0
  177. package/dist/prod/cart-queries.cjs.map +1 -0
  178. package/dist/prod/cart-queries.js +216 -0
  179. package/dist/prod/cart-queries.js.map +1 -0
  180. package/dist/prod/flatten-connection.cjs +7 -0
  181. package/dist/prod/flatten-connection.cjs.map +1 -1
  182. package/dist/prod/flatten-connection.js +7 -0
  183. package/dist/prod/flatten-connection.js.map +1 -1
  184. package/dist/prod/index.cjs +6 -0
  185. package/dist/prod/index.cjs.map +1 -1
  186. package/dist/prod/index.js +6 -0
  187. package/dist/prod/index.js.map +1 -1
  188. package/dist/prod/load-script.cjs +3 -3
  189. package/dist/prod/load-script.cjs.map +1 -1
  190. package/dist/prod/node_modules/@xstate/fsm/es/index.cjs +158 -0
  191. package/dist/prod/node_modules/@xstate/fsm/es/index.cjs.map +1 -0
  192. package/dist/prod/node_modules/@xstate/fsm/es/index.js +159 -0
  193. package/dist/prod/node_modules/@xstate/fsm/es/index.js.map +1 -0
  194. package/dist/prod/node_modules/@xstate/react/es/fsm.cjs +94 -0
  195. package/dist/prod/node_modules/@xstate/react/es/fsm.cjs.map +1 -0
  196. package/dist/prod/node_modules/@xstate/react/es/fsm.js +94 -0
  197. package/dist/prod/node_modules/@xstate/react/es/fsm.js.map +1 -0
  198. package/dist/prod/node_modules/@xstate/react/es/useConstant.cjs +30 -0
  199. package/dist/prod/node_modules/@xstate/react/es/useConstant.cjs.map +1 -0
  200. package/dist/prod/node_modules/@xstate/react/es/useConstant.js +12 -0
  201. package/dist/prod/node_modules/@xstate/react/es/useConstant.js.map +1 -0
  202. package/dist/prod/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.cjs +5 -0
  203. package/dist/prod/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.cjs.map +1 -0
  204. package/dist/prod/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.js +6 -0
  205. package/dist/prod/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.js.map +1 -0
  206. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.cjs +107 -0
  207. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.cjs.map +1 -0
  208. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js +105 -0
  209. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js.map +1 -0
  210. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.cjs +74 -0
  211. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.cjs.map +1 -0
  212. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js +72 -0
  213. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js.map +1 -0
  214. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.cjs +138 -0
  215. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.cjs.map +1 -0
  216. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +136 -0
  217. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js.map +1 -0
  218. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.cjs +60 -0
  219. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.cjs.map +1 -0
  220. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js +58 -0
  221. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js.map +1 -0
  222. package/dist/prod/node_modules/use-sync-external-store/shim/index.cjs +21 -0
  223. package/dist/prod/node_modules/use-sync-external-store/shim/index.cjs.map +1 -0
  224. package/dist/prod/node_modules/use-sync-external-store/shim/index.js +21 -0
  225. package/dist/prod/node_modules/use-sync-external-store/shim/index.js.map +1 -0
  226. package/dist/prod/node_modules/use-sync-external-store/shim/with-selector.cjs +12 -0
  227. package/dist/prod/node_modules/use-sync-external-store/shim/with-selector.cjs.map +1 -0
  228. package/dist/prod/node_modules/use-sync-external-store/shim/with-selector.js +11 -0
  229. package/dist/prod/node_modules/use-sync-external-store/shim/with-selector.js.map +1 -0
  230. package/dist/prod/node_modules/worktop/cookie/index.cjs +27 -0
  231. package/dist/prod/node_modules/worktop/cookie/index.cjs.map +1 -0
  232. package/dist/prod/node_modules/worktop/cookie/index.js +27 -0
  233. package/dist/prod/node_modules/worktop/cookie/index.js.map +1 -0
  234. package/dist/prod/useCartAPIStateMachine.cjs +326 -0
  235. package/dist/prod/useCartAPIStateMachine.cjs.map +1 -0
  236. package/dist/prod/useCartAPIStateMachine.js +326 -0
  237. package/dist/prod/useCartAPIStateMachine.js.map +1 -0
  238. package/dist/prod/useCartActions.cjs +123 -0
  239. package/dist/prod/useCartActions.cjs.map +1 -0
  240. package/dist/prod/useCartActions.js +123 -0
  241. package/dist/prod/useCartActions.js.map +1 -0
  242. package/dist/prod/useMoney.cjs +5 -5
  243. package/dist/prod/useMoney.cjs.map +1 -1
  244. package/dist/types/CartProvider.d.ts +61 -0
  245. package/dist/types/MediaFile.d.ts +0 -1
  246. package/dist/types/Money.d.ts +1 -1
  247. package/dist/types/ProductPrice.d.ts +0 -1
  248. package/dist/types/cart-constants.d.ts +8 -0
  249. package/dist/types/cart-hooks.d.ts +24 -0
  250. package/dist/types/cart-queries.d.ts +10 -0
  251. package/dist/types/cart-types.d.ts +289 -0
  252. package/dist/types/flatten-connection.d.ts +3 -1
  253. package/dist/types/index.d.cts +3 -0
  254. package/dist/types/index.d.ts +3 -0
  255. package/dist/types/useCartAPIStateMachine.d.ts +25 -0
  256. package/dist/types/useCartActions.d.ts +64 -0
  257. package/dist/umd/hydrogen-react.dev.js +1949 -102
  258. package/dist/umd/hydrogen-react.dev.js.map +1 -1
  259. package/dist/umd/hydrogen-react.prod.js +339 -2
  260. package/dist/umd/hydrogen-react.prod.js.map +1 -1
  261. package/package.json +23 -12
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const react = require("react");
3
+ const require$$0 = require("react");
4
4
  const ShopifyProvider = require("./ShopifyProvider.cjs");
5
5
  function useMoney(money) {
6
6
  const {
@@ -10,7 +10,7 @@ function useMoney(money) {
10
10
  throw new Error(`useMoney(): Unable to get 'locale' from 'useShop()', which means that 'locale' was not passed to '<ShopifyProvider/>'. 'locale' is required for 'useMoney()' to work`);
11
11
  }
12
12
  const amount = parseFloat(money.amount);
13
- const options = react.useMemo(() => ({
13
+ const options = require$$0.useMemo(() => ({
14
14
  style: "currency",
15
15
  currency: money.currencyCode
16
16
  }), [money.currencyCode]);
@@ -34,7 +34,7 @@ function useMoney(money) {
34
34
  maximumFractionDigits: 0
35
35
  });
36
36
  const isPartCurrency = (part) => part.type === "currency";
37
- const lazyFormatters = react.useMemo(() => ({
37
+ const lazyFormatters = require$$0.useMemo(() => ({
38
38
  original: () => money,
39
39
  currencyCode: () => money.currencyCode,
40
40
  localizedString: () => defaultFormatter().format(amount),
@@ -55,7 +55,7 @@ function useMoney(money) {
55
55
  },
56
56
  amount: () => defaultFormatter().formatToParts(amount).filter((part) => ["decimal", "fraction", "group", "integer", "literal"].includes(part.type)).map((part) => part.value).join("")
57
57
  }), [money, amount, nameFormatter, defaultFormatter, narrowSymbolFormatter, withoutCurrencyFormatter, withoutTrailingZerosFormatter, withoutTrailingZerosOrCurrencyFormatter]);
58
- return react.useMemo(() => new Proxy(lazyFormatters, {
58
+ return require$$0.useMemo(() => new Proxy(lazyFormatters, {
59
59
  get: (target, key) => {
60
60
  var _a;
61
61
  return (_a = Reflect.get(target, key)) == null ? void 0 : _a.call(null);
@@ -63,7 +63,7 @@ function useMoney(money) {
63
63
  }), [lazyFormatters]);
64
64
  }
65
65
  function useLazyFormatter(locale, options) {
66
- return react.useMemo(() => {
66
+ return require$$0.useMemo(() => {
67
67
  let memoized;
68
68
  return () => memoized != null ? memoized : memoized = new Intl.NumberFormat(locale, options);
69
69
  }, [locale, options]);
@@ -1 +1 @@
1
- {"version":3,"file":"useMoney.cjs","sources":["../../src/useMoney.tsx"],"sourcesContent":["import {useMemo} from 'react';\nimport {useShop} from './ShopifyProvider.js';\nimport {CurrencyCode, MoneyV2} from './storefront-api-types.js';\n\nexport type UseMoneyValue = {\n /**\n * The currency code from the `MoneyV2` object.\n */\n currencyCode: CurrencyCode;\n /**\n * The name for the currency code, returned by `Intl.NumberFormat`.\n */\n currencyName?: string;\n /**\n * The currency symbol returned by `Intl.NumberFormat`.\n */\n currencySymbol?: string;\n /**\n * The currency narrow symbol returned by `Intl.NumberFormat`.\n */\n currencyNarrowSymbol?: string;\n /**\n * The localized amount, without any currency symbols or non-number types from the `Intl.NumberFormat.formatToParts` parts.\n */\n amount: string;\n /**\n * All parts returned by `Intl.NumberFormat.formatToParts`.\n */\n parts: Intl.NumberFormatPart[];\n /**\n * A string returned by `new Intl.NumberFormat` for the amount and currency code,\n * using the `locale` value in the [`LocalizationProvider` component](https://shopify.dev/api/hydrogen/components/localization/localizationprovider).\n */\n localizedString: string;\n /**\n * The `MoneyV2` object provided as an argument to the hook.\n */\n original: MoneyV2;\n /**\n * A string with trailing zeros removed from the fractional part, if any exist. If there are no trailing zeros, then the fractional part remains.\n * For example, `$640.00` turns into `$640`.\n * `$640.42` remains `$640.42`.\n */\n withoutTrailingZeros: string;\n /**\n * A string without currency and without trailing zeros removed from the fractional part, if any exist. If there are no trailing zeros, then the fractional part remains.\n * For example, `$640.00` turns into `640`.\n * `$640.42` turns into `640.42`.\n */\n withoutTrailingZerosAndCurrency: string;\n};\n\n/**\n * The `useMoney` hook takes a [MoneyV2 object](https://shopify.dev/api/storefront/reference/common-objects/moneyv2) and returns a\n * default-formatted string of the amount with the correct currency indicator, along with some of the parts provided by\n * [Intl.NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat).\n * Uses `locale` from `ShopifyProvider`\n */\nexport function useMoney(money: MoneyV2): UseMoneyValue {\n const {locale} = useShop();\n\n if (!locale) {\n throw new Error(\n `useMoney(): Unable to get 'locale' from 'useShop()', which means that 'locale' was not passed to '<ShopifyProvider/>'. 'locale' is required for 'useMoney()' to work`\n );\n }\n\n const amount = parseFloat(money.amount);\n\n const options = useMemo(\n () => ({\n style: 'currency',\n currency: money.currencyCode,\n }),\n [money.currencyCode]\n );\n\n const defaultFormatter = useLazyFormatter(locale, options);\n\n const nameFormatter = useLazyFormatter(locale, {\n ...options,\n currencyDisplay: 'name',\n });\n\n const narrowSymbolFormatter = useLazyFormatter(locale, {\n ...options,\n currencyDisplay: 'narrowSymbol',\n });\n\n const withoutTrailingZerosFormatter = useLazyFormatter(locale, {\n ...options,\n minimumFractionDigits: 0,\n maximumFractionDigits: 0,\n });\n\n const withoutCurrencyFormatter = useLazyFormatter(locale);\n\n const withoutTrailingZerosOrCurrencyFormatter = useLazyFormatter(locale, {\n minimumFractionDigits: 0,\n maximumFractionDigits: 0,\n });\n\n const isPartCurrency = (part: Intl.NumberFormatPart) =>\n part.type === 'currency';\n\n // By wrapping these properties in functions, we only\n // create formatters if they are going to be used.\n const lazyFormatters = useMemo(\n () => ({\n original: () => money,\n currencyCode: () => money.currencyCode,\n\n localizedString: () => defaultFormatter().format(amount),\n\n parts: () => defaultFormatter().formatToParts(amount),\n\n withoutTrailingZeros: () =>\n amount % 1 === 0\n ? withoutTrailingZerosFormatter().format(amount)\n : defaultFormatter().format(amount),\n\n withoutTrailingZerosAndCurrency: () =>\n amount % 1 === 0\n ? withoutTrailingZerosOrCurrencyFormatter().format(amount)\n : withoutCurrencyFormatter().format(amount),\n\n currencyName: () =>\n nameFormatter().formatToParts(amount).find(isPartCurrency)?.value ??\n money.currencyCode, // e.g. \"US dollars\"\n\n currencySymbol: () =>\n defaultFormatter().formatToParts(amount).find(isPartCurrency)?.value ??\n money.currencyCode, // e.g. \"USD\"\n\n currencyNarrowSymbol: () =>\n narrowSymbolFormatter().formatToParts(amount).find(isPartCurrency)\n ?.value ?? '', // e.g. \"$\"\n\n amount: () =>\n defaultFormatter()\n .formatToParts(amount)\n .filter((part) =>\n ['decimal', 'fraction', 'group', 'integer', 'literal'].includes(\n part.type\n )\n )\n .map((part) => part.value)\n .join(''),\n }),\n [\n money,\n amount,\n nameFormatter,\n defaultFormatter,\n narrowSymbolFormatter,\n withoutCurrencyFormatter,\n withoutTrailingZerosFormatter,\n withoutTrailingZerosOrCurrencyFormatter,\n ]\n );\n\n // Call functions automatically when the properties are accessed\n // to keep these functions as an implementation detail.\n return useMemo(\n () =>\n new Proxy(lazyFormatters as unknown as UseMoneyValue, {\n get: (target, key) => Reflect.get(target, key)?.call(null),\n }),\n [lazyFormatters]\n );\n}\n\nfunction useLazyFormatter(locale: string, options?: Intl.NumberFormatOptions) {\n return useMemo(() => {\n let memoized: Intl.NumberFormat;\n return () => (memoized ??= new Intl.NumberFormat(locale, options));\n }, [locale, options]);\n}\n"],"names":["useMoney","money","locale","useShop","Error","amount","parseFloat","options","useMemo","style","currency","currencyCode","defaultFormatter","useLazyFormatter","nameFormatter","currencyDisplay","narrowSymbolFormatter","withoutTrailingZerosFormatter","minimumFractionDigits","maximumFractionDigits","withoutCurrencyFormatter","withoutTrailingZerosOrCurrencyFormatter","isPartCurrency","part","type","lazyFormatters","original","localizedString","format","parts","formatToParts","withoutTrailingZeros","withoutTrailingZerosAndCurrency","currencyName","find","value","currencySymbol","currencyNarrowSymbol","filter","includes","map","join","Proxy","get","target","key","Reflect","call","memoized","Intl","NumberFormat"],"mappings":"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"}
1
+ {"version":3,"file":"useMoney.cjs","sources":["../../src/useMoney.tsx"],"sourcesContent":["import {useMemo} from 'react';\nimport {useShop} from './ShopifyProvider.js';\nimport {CurrencyCode, MoneyV2} from './storefront-api-types.js';\n\nexport type UseMoneyValue = {\n /**\n * The currency code from the `MoneyV2` object.\n */\n currencyCode: CurrencyCode;\n /**\n * The name for the currency code, returned by `Intl.NumberFormat`.\n */\n currencyName?: string;\n /**\n * The currency symbol returned by `Intl.NumberFormat`.\n */\n currencySymbol?: string;\n /**\n * The currency narrow symbol returned by `Intl.NumberFormat`.\n */\n currencyNarrowSymbol?: string;\n /**\n * The localized amount, without any currency symbols or non-number types from the `Intl.NumberFormat.formatToParts` parts.\n */\n amount: string;\n /**\n * All parts returned by `Intl.NumberFormat.formatToParts`.\n */\n parts: Intl.NumberFormatPart[];\n /**\n * A string returned by `new Intl.NumberFormat` for the amount and currency code,\n * using the `locale` value in the [`LocalizationProvider` component](https://shopify.dev/api/hydrogen/components/localization/localizationprovider).\n */\n localizedString: string;\n /**\n * The `MoneyV2` object provided as an argument to the hook.\n */\n original: MoneyV2;\n /**\n * A string with trailing zeros removed from the fractional part, if any exist. If there are no trailing zeros, then the fractional part remains.\n * For example, `$640.00` turns into `$640`.\n * `$640.42` remains `$640.42`.\n */\n withoutTrailingZeros: string;\n /**\n * A string without currency and without trailing zeros removed from the fractional part, if any exist. If there are no trailing zeros, then the fractional part remains.\n * For example, `$640.00` turns into `640`.\n * `$640.42` turns into `640.42`.\n */\n withoutTrailingZerosAndCurrency: string;\n};\n\n/**\n * The `useMoney` hook takes a [MoneyV2 object](https://shopify.dev/api/storefront/reference/common-objects/moneyv2) and returns a\n * default-formatted string of the amount with the correct currency indicator, along with some of the parts provided by\n * [Intl.NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat).\n * Uses `locale` from `ShopifyProvider`\n */\nexport function useMoney(money: MoneyV2): UseMoneyValue {\n const {locale} = useShop();\n\n if (!locale) {\n throw new Error(\n `useMoney(): Unable to get 'locale' from 'useShop()', which means that 'locale' was not passed to '<ShopifyProvider/>'. 'locale' is required for 'useMoney()' to work`\n );\n }\n\n const amount = parseFloat(money.amount);\n\n const options = useMemo(\n () => ({\n style: 'currency',\n currency: money.currencyCode,\n }),\n [money.currencyCode]\n );\n\n const defaultFormatter = useLazyFormatter(locale, options);\n\n const nameFormatter = useLazyFormatter(locale, {\n ...options,\n currencyDisplay: 'name',\n });\n\n const narrowSymbolFormatter = useLazyFormatter(locale, {\n ...options,\n currencyDisplay: 'narrowSymbol',\n });\n\n const withoutTrailingZerosFormatter = useLazyFormatter(locale, {\n ...options,\n minimumFractionDigits: 0,\n maximumFractionDigits: 0,\n });\n\n const withoutCurrencyFormatter = useLazyFormatter(locale);\n\n const withoutTrailingZerosOrCurrencyFormatter = useLazyFormatter(locale, {\n minimumFractionDigits: 0,\n maximumFractionDigits: 0,\n });\n\n const isPartCurrency = (part: Intl.NumberFormatPart) =>\n part.type === 'currency';\n\n // By wrapping these properties in functions, we only\n // create formatters if they are going to be used.\n const lazyFormatters = useMemo(\n () => ({\n original: () => money,\n currencyCode: () => money.currencyCode,\n\n localizedString: () => defaultFormatter().format(amount),\n\n parts: () => defaultFormatter().formatToParts(amount),\n\n withoutTrailingZeros: () =>\n amount % 1 === 0\n ? withoutTrailingZerosFormatter().format(amount)\n : defaultFormatter().format(amount),\n\n withoutTrailingZerosAndCurrency: () =>\n amount % 1 === 0\n ? withoutTrailingZerosOrCurrencyFormatter().format(amount)\n : withoutCurrencyFormatter().format(amount),\n\n currencyName: () =>\n nameFormatter().formatToParts(amount).find(isPartCurrency)?.value ??\n money.currencyCode, // e.g. \"US dollars\"\n\n currencySymbol: () =>\n defaultFormatter().formatToParts(amount).find(isPartCurrency)?.value ??\n money.currencyCode, // e.g. \"USD\"\n\n currencyNarrowSymbol: () =>\n narrowSymbolFormatter().formatToParts(amount).find(isPartCurrency)\n ?.value ?? '', // e.g. \"$\"\n\n amount: () =>\n defaultFormatter()\n .formatToParts(amount)\n .filter((part) =>\n ['decimal', 'fraction', 'group', 'integer', 'literal'].includes(\n part.type\n )\n )\n .map((part) => part.value)\n .join(''),\n }),\n [\n money,\n amount,\n nameFormatter,\n defaultFormatter,\n narrowSymbolFormatter,\n withoutCurrencyFormatter,\n withoutTrailingZerosFormatter,\n withoutTrailingZerosOrCurrencyFormatter,\n ]\n );\n\n // Call functions automatically when the properties are accessed\n // to keep these functions as an implementation detail.\n return useMemo(\n () =>\n new Proxy(lazyFormatters as unknown as UseMoneyValue, {\n get: (target, key) => Reflect.get(target, key)?.call(null),\n }),\n [lazyFormatters]\n );\n}\n\nfunction useLazyFormatter(locale: string, options?: Intl.NumberFormatOptions) {\n return useMemo(() => {\n let memoized: Intl.NumberFormat;\n return () => (memoized ??= new Intl.NumberFormat(locale, options));\n }, [locale, options]);\n}\n"],"names":["useMoney","money","locale","useShop","Error","amount","parseFloat","options","useMemo","style","currency","currencyCode","defaultFormatter","useLazyFormatter","nameFormatter","currencyDisplay","narrowSymbolFormatter","withoutTrailingZerosFormatter","minimumFractionDigits","maximumFractionDigits","withoutCurrencyFormatter","withoutTrailingZerosOrCurrencyFormatter","isPartCurrency","part","type","lazyFormatters","original","localizedString","format","parts","formatToParts","withoutTrailingZeros","withoutTrailingZerosAndCurrency","currencyName","find","value","currencySymbol","currencyNarrowSymbol","filter","includes","map","join","Proxy","get","target","key","Reflect","call","memoized","Intl","NumberFormat"],"mappings":"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"}
@@ -0,0 +1,61 @@
1
+ import { CartBuyerIdentityInput, CountryCode, Cart as CartType } from './storefront-api-types.js';
2
+ import { CartWithActions } from './cart-types.js';
3
+ import { PartialDeep } from 'type-fest';
4
+ export declare const CartContext: import("react").Context<CartWithActions | null>;
5
+ /**
6
+ * The `useCart` hook provides access to the cart object. It must be a descendent of a `CartProvider` component.
7
+ */
8
+ export declare function useCart(): CartWithActions;
9
+ export declare function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLineRemove, onLineUpdate, onNoteUpdate, onBuyerIdentityUpdate, onAttributesUpdate, onDiscountCodesUpdate, onCreateComplete, onLineAddComplete, onLineRemoveComplete, onLineUpdateComplete, onNoteUpdateComplete, onBuyerIdentityUpdateComplete, onAttributesUpdateComplete, onDiscountCodesUpdateComplete, data: cart, cartFragment, customerAccessToken, countryCode, }: {
10
+ /** Any `ReactNode` elements. */
11
+ children: React.ReactNode;
12
+ /** Maximum number of cart lines to fetch. Defaults to 250 cart lines. */
13
+ numCartLines?: number;
14
+ /** A callback that is invoked when the process to create a cart begins, but before the cart is created in the Storefront API. */
15
+ onCreate?: () => void;
16
+ /** A callback that is invoked when the process to add a line item to the cart begins, but before the line item is added to the Storefront API. */
17
+ onLineAdd?: () => void;
18
+ /** A callback that is invoked when the process to remove a line item to the cart begins, but before the line item is removed from the Storefront API. */
19
+ onLineRemove?: () => void;
20
+ /** A callback that is invoked when the process to update a line item in the cart begins, but before the line item is updated in the Storefront API. */
21
+ onLineUpdate?: () => void;
22
+ /** A callback that is invoked when the process to add or update a note in the cart begins, but before the note is added or updated in the Storefront API. */
23
+ onNoteUpdate?: () => void;
24
+ /** A callback that is invoked when the process to update the buyer identity begins, but before the buyer identity is updated in the Storefront API. */
25
+ onBuyerIdentityUpdate?: () => void;
26
+ /** A callback that is invoked when the process to update the cart attributes begins, but before the attributes are updated in the Storefront API. */
27
+ onAttributesUpdate?: () => void;
28
+ /** A callback that is invoked when the process to update the cart discount codes begins, but before the discount codes are updated in the Storefront API. */
29
+ onDiscountCodesUpdate?: () => void;
30
+ /** A callback that is invoked when the process to create a cart completes */
31
+ onCreateComplete?: () => void;
32
+ /** A callback that is invoked when the process to add a line item to the cart completes */
33
+ onLineAddComplete?: () => void;
34
+ /** A callback that is invoked when the process to remove a line item to the cart completes */
35
+ onLineRemoveComplete?: () => void;
36
+ /** A callback that is invoked when the process to update a line item in the cart completes */
37
+ onLineUpdateComplete?: () => void;
38
+ /** A callback that is invoked when the process to add or update a note in the cart completes */
39
+ onNoteUpdateComplete?: () => void;
40
+ /** A callback that is invoked when the process to update the buyer identity completes */
41
+ onBuyerIdentityUpdateComplete?: () => void;
42
+ /** A callback that is invoked when the process to update the cart attributes completes */
43
+ onAttributesUpdateComplete?: () => void;
44
+ /** A callback that is invoked when the process to update the cart discount codes completes */
45
+ onDiscountCodesUpdateComplete?: () => void;
46
+ /** An object with fields that correspond to the Storefront API's [Cart object](https://shopify.dev/api/storefront/latest/objects/cart). */
47
+ data?: PartialDeep<CartType, {
48
+ recurseIntoArrays: true;
49
+ }>;
50
+ /** A fragment used to query the Storefront API's [Cart object](https://shopify.dev/api/storefront/latest/objects/cart) for all queries and mutations. A default value is used if no argument is provided. */
51
+ cartFragment?: string;
52
+ /** A customer access token that's accessible on the server if there's a customer login. */
53
+ customerAccessToken?: CartBuyerIdentityInput['customerAccessToken'];
54
+ /** The ISO country code for i18n. */
55
+ countryCode?: CountryCode;
56
+ }): JSX.Element;
57
+ /** Check for storage availability funciton obtained from
58
+ * https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API
59
+ */
60
+ export declare function storageAvailable(type: 'localStorage' | 'sessionStorage'): boolean | undefined;
61
+ export declare const defaultCartFragment = "\nfragment CartFragment on Cart {\n id\n checkoutUrl\n totalQuantity\n buyerIdentity {\n countryCode\n customer {\n id\n email\n firstName\n lastName\n displayName\n }\n email\n phone\n }\n lines(first: $numCartLines) {\n edges {\n node {\n id\n quantity\n attributes {\n key\n value\n }\n cost {\n totalAmount {\n amount\n currencyCode\n }\n compareAtAmountPerQuantity {\n amount\n currencyCode\n }\n }\n merchandise {\n ... on ProductVariant {\n id\n availableForSale\n compareAtPriceV2 {\n ...MoneyFragment\n }\n priceV2 {\n ...MoneyFragment\n }\n requiresShipping\n title\n image {\n ...ImageFragment\n }\n product {\n handle\n title\n }\n selectedOptions {\n name\n value\n }\n }\n }\n }\n }\n }\n cost {\n subtotalAmount {\n ...MoneyFragment\n }\n totalAmount {\n ...MoneyFragment\n }\n totalDutyAmount {\n ...MoneyFragment\n }\n totalTaxAmount {\n ...MoneyFragment\n }\n }\n note\n attributes {\n key\n value\n }\n discountCodes {\n code\n }\n}\n\nfragment MoneyFragment on MoneyV2 {\n currencyCode\n amount\n}\nfragment ImageFragment on Image {\n id\n url\n altText\n width\n height\n}\n";
@@ -1,4 +1,3 @@
1
- import React from 'react';
2
1
  import { type ShopifyImageProps } from './Image.js';
3
2
  import { Video } from './Video.js';
4
3
  import { ExternalVideo } from './ExternalVideo.js';
@@ -1,4 +1,4 @@
1
- import React, { type ReactNode } from 'react';
1
+ import { type ReactNode } from 'react';
2
2
  import type { MoneyV2, UnitPriceMeasurement } from './storefront-api-types.js';
3
3
  import type { PartialDeep } from 'type-fest';
4
4
  interface CustomProps<ComponentGeneric extends React.ElementType> {
@@ -1,4 +1,3 @@
1
- import React from 'react';
2
1
  import type { Product } from './storefront-api-types.js';
3
2
  import { type MoneyProps } from './Money.js';
4
3
  import type { PartialDeep } from 'type-fest';
@@ -0,0 +1,8 @@
1
+ export declare const CART_ID_STORAGE_KEY = "shopifyCartId";
2
+ export declare const CART_COOKIE_TTL_DAYS = 14;
3
+ export declare const STOREFRONT_API_PUBLIC_TOKEN_HEADER = "X-Shopify-Storefront-Access-Token";
4
+ export declare const SHOPIFY_STOREFRONT_ID_HEADER = "Shopify-Storefront-Id";
5
+ export declare const SHOPIFY_STOREFRONT_Y_HEADER = "Shopify-Storefront-Y";
6
+ export declare const SHOPIFY_STOREFRONT_S_HEADER = "Shopify-Storefront-S";
7
+ export declare const SHOPIFY_Y = "_shopify_y";
8
+ export declare const SHOPIFY_S = "_shopify_s";
@@ -0,0 +1,24 @@
1
+ import { CartInput } from './storefront-api-types.js';
2
+ import type { StorefrontApiResponseOkPartial } from './storefront-api-response.types.js';
3
+ export declare function useCartFetch(): <ReturnDataGeneric>({ query, variables, }: {
4
+ query: string;
5
+ variables: Record<string, unknown>;
6
+ }) => Promise<StorefrontApiResponseOkPartial<ReturnDataGeneric>>;
7
+ export declare function useInstantCheckout(): {
8
+ cart: import("type-fest/source/partial-deep.js").PartialObjectDeep<{
9
+ id?: string | undefined;
10
+ lines: import("./storefront-api-types.js").CartLine[];
11
+ checkoutUrl?: string | undefined;
12
+ note?: string | undefined;
13
+ buyerIdentity?: import("./storefront-api-types.js").CartBuyerIdentity | undefined;
14
+ attributes: import("./storefront-api-types.js").Attribute[];
15
+ discountCodes?: import("./storefront-api-types.js").CartDiscountCode[] | undefined;
16
+ cost?: import("./storefront-api-types.js").CartCost | undefined;
17
+ totalQuantity: number;
18
+ }, {
19
+ recurseIntoArrays: true;
20
+ }> | undefined;
21
+ checkoutUrl: string | undefined;
22
+ error: string | undefined;
23
+ createInstantCheckout: (cartInput: CartInput) => Promise<void>;
24
+ };
@@ -0,0 +1,10 @@
1
+ export declare const CartLineAdd: (cartFragment: string) => string;
2
+ export declare const CartCreate: (cartFragment: string) => string;
3
+ export declare const CartLineRemove: (cartFragment: string) => string;
4
+ export declare const CartLineUpdate: (cartFragment: string) => string;
5
+ export declare const CartNoteUpdate: (cartFragment: string) => string;
6
+ export declare const CartBuyerIdentityUpdate: (cartFragment: string) => string;
7
+ export declare const CartAttributesUpdate: (cartFragment: string) => string;
8
+ export declare const CartDiscountCodesUpdate: (cartFragment: string) => string;
9
+ export declare const CartQuery: (cartFragment: string) => string;
10
+ export declare const defaultCartFragment = "\nfragment CartFragment on Cart {\n id\n checkoutUrl\n totalQuantity\n buyerIdentity {\n countryCode\n customer {\n id\n email\n firstName\n lastName\n displayName\n }\n email\n phone\n }\n lines(first: $numCartLines) {\n edges {\n node {\n id\n quantity\n attributes {\n key\n value\n }\n cost {\n totalAmount {\n amount\n currencyCode\n }\n compareAtAmountPerQuantity {\n amount\n currencyCode\n }\n }\n merchandise {\n ... on ProductVariant {\n id\n availableForSale\n compareAtPriceV2 {\n ...MoneyFragment\n }\n priceV2 {\n ...MoneyFragment\n }\n requiresShipping\n title\n image {\n ...ImageFragment\n }\n product {\n handle\n title\n id\n }\n selectedOptions {\n name\n value\n }\n }\n }\n }\n }\n }\n cost {\n subtotalAmount {\n ...MoneyFragment\n }\n totalAmount {\n ...MoneyFragment\n }\n totalDutyAmount {\n ...MoneyFragment\n }\n totalTaxAmount {\n ...MoneyFragment\n }\n }\n note\n attributes {\n key\n value\n }\n discountCodes {\n code\n }\n}\n\nfragment MoneyFragment on MoneyV2 {\n currencyCode\n amount\n}\nfragment ImageFragment on Image {\n id\n url\n altText\n width\n height\n}\n";
@@ -0,0 +1,289 @@
1
+ import { Cart as CartType, CartInput, CartLine, CartLineInput, CartLineUpdateInput, MutationCartNoteUpdateArgs, CartBuyerIdentityInput, MutationCartAttributesUpdateArgs } from './storefront-api-types.js';
2
+ import { StateMachine } from '@xstate/fsm';
3
+ import type { PartialDeep } from 'type-fest';
4
+ export declare type CartStatus = CartState['status'];
5
+ export declare type Cart = PartialDeep<{
6
+ /** The cart's ID if it has been created through the Storefront API. */
7
+ id?: string;
8
+ /** The cart lines. */
9
+ lines: CartLine[];
10
+ /** The checkout URL for the cart, if the cart has been created in the Storefront API. */
11
+ checkoutUrl?: string;
12
+ /** The cart's note. */
13
+ note?: string;
14
+ /** The cart's buyer identity. */
15
+ buyerIdentity?: CartType['buyerIdentity'];
16
+ /** The cart's attributes. */
17
+ attributes: CartType['attributes'];
18
+ /** The discount codes applied to the cart. */
19
+ discountCodes?: CartType['discountCodes'];
20
+ /** The cost for the cart, including the subtotal, total, taxes, and duties. */
21
+ cost?: CartType['cost'];
22
+ /** The total number of items in the cart, across all lines. If there are no lines, then the value is 0. */
23
+ totalQuantity: number;
24
+ }, {
25
+ recurseIntoArrays: true;
26
+ }>;
27
+ export interface CartWithActions extends Cart {
28
+ /** The status of the cart. This returns 'uninitialized' when the cart is not yet created, `creating` when the cart is being created, `fetching` when an existing cart is being fetched, `updating` when the cart is updating, and `idle` when the cart isn't being created or updated. */
29
+ status: CartStatus;
30
+ /** If an error occurred on the previous cart action, then `error` will exist and `cart` will be put back into the last valid status it was in. */
31
+ error?: unknown;
32
+ /** A callback that creates a cart. Expects the same input you would provide to the Storefront API's `cartCreate` mutation. */
33
+ cartCreate: (cart: CartInput) => void;
34
+ /** A callback that adds lines to the cart. Expects the same `lines` input that you would provide to the Storefront API's `cartLinesAdd` mutation. If a cart doesn't already exist, then it will create the cart for you. */
35
+ linesAdd: (lines: CartLineInput[]) => void;
36
+ /** A callback that removes lines from the cart. Expects the same `lines` input that you would provide to the Storefront API's `cartLinesRemove` mutation. Only lines that are included in the `lines` parameter will be in the cart afterwards. */
37
+ linesRemove: (lines: string[]) => void;
38
+ /** A callback that updates lines in the cart. Expects the same `lines` input that you would provide to the Storefront API's `cartLinesUpdate` mutation. If a line item is not included in the `lines` parameter, it will still exist in the cart and will not be changed. */
39
+ linesUpdate: (lines: CartLineUpdateInput[]) => void;
40
+ /** A callback that updates the note in the cart. Expects the same `note` input that you would provide to the Storefront API's `cartNoteUpdate` mutation. */
41
+ noteUpdate: (note: MutationCartNoteUpdateArgs['note']) => void;
42
+ /** A callback that updates the buyer identity in the cart. Expects the same `buyerIdentity` input that you would provide to the Storefront API's `cartBuyerIdentityUpdate` mutation. */
43
+ buyerIdentityUpdate: (buyerIdenity: CartBuyerIdentityInput) => void;
44
+ /** A callback that updates the cart attributes. Expects the same `attributes` input that you would provide to the Storefront API's `cartAttributesUpdate` mutation. */
45
+ cartAttributesUpdate: (attributes: MutationCartAttributesUpdateArgs['attributes']) => void;
46
+ /** A callback that updates the cart's discount codes. Expects the same `codes` input that you would provide to the Storefront API's `cartDiscountCodesUpdate` mutation. */
47
+ discountCodesUpdate: (discountCodes: string[]) => void;
48
+ /** The total number of items in the cart, across all lines. If there are no lines, then the value is 0. */
49
+ totalQuantity: number;
50
+ /** The fragment used to query the cart object for all queries and mutations. */
51
+ cartFragment: string;
52
+ }
53
+ export declare type CartState =
54
+ /** A cart has not been created yet, or an error occurred when a cart was attempting to be created or fetched. */
55
+ {
56
+ status: 'uninitialized';
57
+ error?: string;
58
+ }
59
+ /** An existing cart is being fetched from the Storefront API. */
60
+ | {
61
+ status: 'fetching';
62
+ }
63
+ /** A new cart is being created through the Storefront API. */
64
+ | {
65
+ status: 'creating';
66
+ }
67
+ /** The cart is in the process of being updated. */
68
+ | {
69
+ status: 'updating';
70
+ cart: Cart;
71
+ lastValidCart: Cart;
72
+ }
73
+ /** The cart has been created and no action is currently happening. */
74
+ | {
75
+ status: 'idle';
76
+ cart: Cart;
77
+ error?: string;
78
+ };
79
+ export declare type CartAction = {
80
+ type: 'cartFetch';
81
+ } | {
82
+ type: 'cartCreate';
83
+ } | {
84
+ type: 'addLineItem';
85
+ } | {
86
+ type: 'removeLineItem';
87
+ lines: string[];
88
+ } | {
89
+ type: 'updateLineItem';
90
+ lines: CartLineUpdateInput[];
91
+ } | {
92
+ type: 'noteUpdate';
93
+ } | {
94
+ type: 'buyerIdentityUpdate';
95
+ } | {
96
+ type: 'cartAttributesUpdate';
97
+ } | {
98
+ type: 'discountCodesUpdate';
99
+ } | {
100
+ type: 'resolve';
101
+ cart: Cart;
102
+ rawCartResult?: PartialDeep<CartType, {
103
+ recurseIntoArrays: true;
104
+ }>;
105
+ } | {
106
+ type: 'reject';
107
+ errors: unknown;
108
+ } | {
109
+ type: 'resetCart';
110
+ };
111
+ export declare type CartMachineContext = {
112
+ cart?: PartialDeep<Cart, {
113
+ recurseIntoArrays: true;
114
+ }>;
115
+ lastValidCart?: PartialDeep<Cart, {
116
+ recurseIntoArrays: true;
117
+ }>;
118
+ rawCartResult?: PartialDeep<CartType, {
119
+ recurseIntoArrays: true;
120
+ }>;
121
+ prevCart?: PartialDeep<Cart, {
122
+ recurseIntoArrays: true;
123
+ }>;
124
+ errors?: unknown;
125
+ };
126
+ export declare type CartFetchEvent = {
127
+ type: 'CART_FETCH';
128
+ payload: {
129
+ cartId: string;
130
+ };
131
+ };
132
+ export declare type CartCreateEvent = {
133
+ type: 'CART_CREATE';
134
+ payload: CartInput;
135
+ };
136
+ export declare type CartSetEvent = {
137
+ type: 'CART_SET';
138
+ payload: {
139
+ cart: CartType;
140
+ };
141
+ };
142
+ export declare type CartLineAddEvent = {
143
+ type: 'CARTLINE_ADD';
144
+ payload: {
145
+ lines: CartLineInput[];
146
+ };
147
+ };
148
+ export declare type CartLineRemoveEvent = {
149
+ type: 'CARTLINE_REMOVE';
150
+ payload: {
151
+ lines: string[];
152
+ };
153
+ };
154
+ export declare type CartLineUpdateEvent = {
155
+ type: 'CARTLINE_UPDATE';
156
+ payload: {
157
+ lines: CartLineUpdateInput[];
158
+ };
159
+ };
160
+ export declare type NoteUpdateEvent = {
161
+ type: 'NOTE_UPDATE';
162
+ payload: {
163
+ note: MutationCartNoteUpdateArgs['note'];
164
+ };
165
+ };
166
+ export declare type BuyerIdentityUpdateEvent = {
167
+ type: 'BUYER_IDENTITY_UPDATE';
168
+ payload: {
169
+ buyerIdentity: CartBuyerIdentityInput;
170
+ };
171
+ };
172
+ export declare type CartAttributesUpdateEvent = {
173
+ type: 'CART_ATTRIBUTES_UPDATE';
174
+ payload: {
175
+ attributes: MutationCartAttributesUpdateArgs['attributes'];
176
+ };
177
+ };
178
+ export declare type DiscountCodesUpdateEvent = {
179
+ type: 'DISCOUNT_CODES_UPDATE';
180
+ payload: {
181
+ discountCodes: string[];
182
+ };
183
+ };
184
+ export declare type CartMachineActionEvent = CartFetchEvent | CartCreateEvent | CartSetEvent | CartLineAddEvent | CartLineRemoveEvent | CartLineUpdateEvent | NoteUpdateEvent | BuyerIdentityUpdateEvent | CartAttributesUpdateEvent | DiscountCodesUpdateEvent;
185
+ export declare type CartMachineFetchResultEvent = {
186
+ type: 'CART_COMPLETED';
187
+ payload: {
188
+ cartActionEvent: CartMachineActionEvent;
189
+ };
190
+ } | {
191
+ type: 'RESOLVE';
192
+ payload: {
193
+ cartActionEvent: CartMachineActionEvent;
194
+ cart: Cart;
195
+ rawCartResult: PartialDeep<CartType, {
196
+ recurseIntoArrays: true;
197
+ }>;
198
+ };
199
+ } | {
200
+ type: 'ERROR';
201
+ payload: {
202
+ cartActionEvent: CartMachineActionEvent;
203
+ errors: unknown;
204
+ };
205
+ };
206
+ export declare type CartMachineEvent = CartMachineActionEvent | CartMachineFetchResultEvent;
207
+ export declare type CartMachineTypeState = {
208
+ value: 'uninitialized';
209
+ context: CartMachineContext & {
210
+ cart: undefined;
211
+ lastValidCart: undefined;
212
+ prevCart: undefined;
213
+ errors?: unknown;
214
+ };
215
+ } | {
216
+ value: 'initializationError';
217
+ context: CartMachineContext & {
218
+ cart: undefined;
219
+ lastValidCart: undefined;
220
+ prevCart: undefined;
221
+ errors: unknown;
222
+ };
223
+ } | {
224
+ value: 'cartCompleted';
225
+ context: CartMachineContext & {
226
+ cart: undefined;
227
+ prevCart?: Cart;
228
+ lastValidCart: undefined;
229
+ errors: unknown;
230
+ };
231
+ } | {
232
+ value: 'idle';
233
+ context: CartMachineContext & {
234
+ cart: Cart;
235
+ prevCart?: Cart;
236
+ lastValidCart?: Cart;
237
+ errors?: unknown;
238
+ };
239
+ } | {
240
+ value: 'error';
241
+ context: CartMachineContext & {
242
+ cart?: Cart;
243
+ prevCart?: Cart;
244
+ lastValidCart?: Cart;
245
+ errors: unknown;
246
+ };
247
+ } | {
248
+ value: 'cartFetching';
249
+ context: CartMachineContext;
250
+ } | {
251
+ value: 'cartCreating';
252
+ context: CartMachineContext;
253
+ } | {
254
+ value: 'cartLineRemoving';
255
+ context: CartMachineContext;
256
+ } | {
257
+ value: 'cartLineUpdating';
258
+ context: CartMachineContext;
259
+ } | {
260
+ value: 'cartLineAdding';
261
+ context: CartMachineContext;
262
+ } | {
263
+ value: 'noteUpdating';
264
+ context: CartMachineContext;
265
+ } | {
266
+ value: 'buyerIdentityUpdating';
267
+ context: CartMachineContext;
268
+ } | {
269
+ value: 'cartAttributesUpdating';
270
+ context: CartMachineContext;
271
+ } | {
272
+ value: 'discountCodesUpdating';
273
+ context: CartMachineContext;
274
+ };
275
+ export declare type CartMachineAction = StateMachine.ActionFunction<CartMachineContext, CartMachineEvent>;
276
+ export declare type CartMachineActions = {
277
+ cartFetchAction: CartMachineAction;
278
+ cartCreateAction: CartMachineAction;
279
+ cartLineRemoveAction: CartMachineAction;
280
+ cartLineUpdateAction: CartMachineAction;
281
+ cartLineAddAction: CartMachineAction;
282
+ noteUpdateAction: CartMachineAction;
283
+ buyerIdentityUpdateAction: CartMachineAction;
284
+ cartAttributesUpdateAction: CartMachineAction;
285
+ discountCodesUpdateAction: CartMachineAction;
286
+ onCartActionEntry?: CartMachineAction;
287
+ onCartActionOptimisticUI?: StateMachine.AssignActionObject<CartMachineContext, CartMachineEvent>;
288
+ onCartActionComplete?: CartMachineAction;
289
+ };
@@ -2,8 +2,10 @@ import type { PartialDeep } from 'type-fest';
2
2
  /**
3
3
  * The `flattenConnection` utility transforms a connection object from the Storefront API (for example, [Product-related connections](https://shopify.dev/api/storefront/reference/products/product)) into a flat array of nodes.
4
4
  * The utility works with either `nodes` or `edges.node`.
5
+ *
6
+ * If `connection` is null or undefined, will return an empty array instead in production. In development, an error will be thrown.
5
7
  */
6
- export declare function flattenConnection<T>(connection: PartialDeep<GraphQLConnection<T>, {
8
+ export declare function flattenConnection<T>(connection?: PartialDeep<GraphQLConnection<T>, {
7
9
  recurseIntoArrays: true;
8
10
  }>): PartialDeep<T, {
9
11
  recurseIntoArrays: true;
@@ -1,3 +1,6 @@
1
+ export { useCartFetch, useInstantCheckout } from './cart-hooks.js';
2
+ export type { CartState, CartStatus, Cart, CartWithActions, CartAction, } from './cart-types.js';
3
+ export { CartProvider, useCart } from './CartProvider.js';
1
4
  export { ExternalVideo } from './ExternalVideo.js';
2
5
  export { flattenConnection } from './flatten-connection.js';
3
6
  export { Image } from './Image.js';
@@ -1,3 +1,6 @@
1
+ export { useCartFetch, useInstantCheckout } from './cart-hooks.js';
2
+ export type { CartState, CartStatus, Cart, CartWithActions, CartAction, } from './cart-types.js';
3
+ export { CartProvider, useCart } from './CartProvider.js';
1
4
  export { ExternalVideo } from './ExternalVideo.js';
2
5
  export { flattenConnection } from './flatten-connection.js';
3
6
  export { Image } from './Image.js';
@@ -0,0 +1,25 @@
1
+ import { StateMachine } from '@xstate/fsm';
2
+ import { Cart, CartMachineActionEvent, CartMachineContext, CartMachineEvent, CartMachineFetchResultEvent, CartMachineTypeState } from './cart-types.js';
3
+ import { CountryCode, Cart as CartType } from './storefront-api-types.js';
4
+ import type { PartialDeep } from 'type-fest';
5
+ export declare function useCartAPIStateMachine({ numCartLines, onCartActionEntry, onCartActionOptimisticUI, onCartActionComplete, data: cart, cartFragment, countryCode, }: {
6
+ /** Maximum number of cart lines to fetch. Defaults to 250 cart lines. */
7
+ numCartLines?: number;
8
+ /** A callback that is invoked just before a Cart API action executes. */
9
+ onCartActionEntry?: (context: CartMachineContext, event: CartMachineActionEvent) => void;
10
+ /** A callback that is invoked after executing the entry actions for optimistic UI changes. */
11
+ onCartActionOptimisticUI?: (context: CartMachineContext, event: CartMachineEvent) => Partial<CartMachineContext>;
12
+ /** A callback that is invoked after a Cart API completes. */
13
+ onCartActionComplete?: (context: CartMachineContext, event: CartMachineFetchResultEvent) => void;
14
+ /** An object with fields that correspond to the Storefront API's [Cart object](https://shopify.dev/api/storefront/latest/objects/cart). */
15
+ data?: PartialDeep<CartType, {
16
+ recurseIntoArrays: true;
17
+ }>;
18
+ /** A fragment used to query the Storefront API's [Cart object](https://shopify.dev/api/storefront/latest/objects/cart) for all queries and mutations. A default value is used if no argument is provided. */
19
+ cartFragment: string;
20
+ /** The ISO country code for i18n. */
21
+ countryCode?: CountryCode;
22
+ }): readonly [StateMachine.State<CartMachineContext, CartMachineEvent, CartMachineTypeState>, (event: "CART_FETCH" | "CART_CREATE" | "CART_SET" | "CARTLINE_ADD" | "CARTLINE_REMOVE" | "CARTLINE_UPDATE" | "NOTE_UPDATE" | "BUYER_IDENTITY_UPDATE" | "CART_ATTRIBUTES_UPDATE" | "DISCOUNT_CODES_UPDATE" | "CART_COMPLETED" | "RESOLVE" | "ERROR" | CartMachineEvent) => void, StateMachine.Service<CartMachineContext, CartMachineEvent, CartMachineTypeState>];
23
+ export declare function cartFromGraphQL(cart: PartialDeep<CartType, {
24
+ recurseIntoArrays: true;
25
+ }>): Cart;
@@ -0,0 +1,64 @@
1
+ import { AttributeInput, CartBuyerIdentityInput, CartInput, CartLineInput, CartLineUpdateInput, CountryCode, Cart as CartType, MutationCartDiscountCodesUpdateArgs, MutationCartNoteUpdateArgs } from './storefront-api-types.js';
2
+ import { PartialDeep } from 'type-fest';
3
+ declare type CartResponse = PartialDeep<CartType, {
4
+ recurseIntoArrays: true;
5
+ }>;
6
+ /**
7
+ * The `useCartActions` hook returns helper graphql functions for Storefront Cart API
8
+ *
9
+ * See [cart API graphql mutations](https://shopify.dev/api/storefront/2022-07/objects/Cart)
10
+ */
11
+ export declare function useCartActions({ numCartLines, cartFragment, countryCode, }: {
12
+ /** Maximum number of cart lines to fetch. Defaults to 250 cart lines. */
13
+ numCartLines?: number;
14
+ /** A fragment used to query the Storefront API's [Cart object](https://shopify.dev/api/storefront/latest/objects/cart) for all queries and mutations. A default value is used if no argument is provided. */
15
+ cartFragment: string;
16
+ /** The ISO country code for i18n. */
17
+ countryCode?: CountryCode;
18
+ }): {
19
+ cartFetch: (cartId: string) => Promise<import("./storefront-api-response.types.js").StorefrontApiResponseOkPartial<{
20
+ cart: CartResponse;
21
+ }>>;
22
+ cartCreate: (cart: CartInput) => Promise<import("./storefront-api-response.types.js").StorefrontApiResponseOkPartial<{
23
+ cartCreate: {
24
+ cart: CartResponse;
25
+ };
26
+ }>>;
27
+ cartLineAdd: (cartId: string, lines: CartLineInput[]) => Promise<import("./storefront-api-response.types.js").StorefrontApiResponseOkPartial<{
28
+ cartLinesAdd: {
29
+ cart: CartResponse;
30
+ };
31
+ }>>;
32
+ cartLineUpdate: (cartId: string, lines: CartLineUpdateInput[]) => Promise<import("./storefront-api-response.types.js").StorefrontApiResponseOkPartial<{
33
+ cartLinesUpdate: {
34
+ cart: CartResponse;
35
+ };
36
+ }>>;
37
+ cartLineRemove: (cartId: string, lines: string[]) => Promise<import("./storefront-api-response.types.js").StorefrontApiResponseOkPartial<{
38
+ cartLinesRemove: {
39
+ cart: CartResponse;
40
+ };
41
+ }>>;
42
+ noteUpdate: (cartId: string, note: MutationCartNoteUpdateArgs['note']) => Promise<import("./storefront-api-response.types.js").StorefrontApiResponseOkPartial<{
43
+ cartNoteUpdate: {
44
+ cart: CartResponse;
45
+ };
46
+ }>>;
47
+ buyerIdentityUpdate: (cartId: string, buyerIdentity: CartBuyerIdentityInput) => Promise<import("./storefront-api-response.types.js").StorefrontApiResponseOkPartial<{
48
+ cartBuyerIdentityUpdate: {
49
+ cart: CartResponse;
50
+ };
51
+ }>>;
52
+ cartAttributesUpdate: (cartId: string, attributes: AttributeInput[]) => Promise<import("./storefront-api-response.types.js").StorefrontApiResponseOkPartial<{
53
+ cartAttributesUpdate: {
54
+ cart: CartResponse;
55
+ };
56
+ }>>;
57
+ discountCodesUpdate: (cartId: string, discountCodes: MutationCartDiscountCodesUpdateArgs['discountCodes']) => Promise<import("./storefront-api-response.types.js").StorefrontApiResponseOkPartial<{
58
+ cartDiscountCodesUpdate: {
59
+ cart: CartResponse;
60
+ };
61
+ }>>;
62
+ cartFragment: string;
63
+ };
64
+ export {};