@shopify/hydrogen-react 2026.1.0 → 2026.1.2

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 (287) hide show
  1. package/LICENSE.md +7 -0
  2. package/dist/browser-dev/AddToCartButton.mjs.map +1 -1
  3. package/dist/browser-dev/BuyNowButton.mjs.map +1 -1
  4. package/dist/browser-dev/CartCost.mjs.map +1 -1
  5. package/dist/browser-dev/CartLineProvider.mjs +1 -1
  6. package/dist/browser-dev/CartProvider.mjs +1 -1
  7. package/dist/browser-dev/ProductPrice.mjs.map +1 -1
  8. package/dist/browser-dev/ProductProvider.mjs +1 -1
  9. package/dist/browser-dev/ShopifyProvider.mjs +1 -1
  10. package/dist/browser-dev/ShopifyProvider.mjs.map +1 -1
  11. package/dist/browser-dev/analytics-schema-custom-storefront-customer-tracking.mjs +1 -1
  12. package/dist/{node-dev/packages/hydrogen-react → browser-dev}/package.json.mjs +1 -1
  13. package/dist/browser-dev/useCartAPIStateMachine.mjs +9 -9
  14. package/dist/browser-dev/useCartAPIStateMachine.mjs.map +1 -1
  15. package/dist/browser-dev/useMachine.mjs +68 -0
  16. package/dist/browser-dev/useMachine.mjs.map +1 -0
  17. package/dist/browser-prod/AddToCartButton.mjs.map +1 -1
  18. package/dist/browser-prod/BuyNowButton.mjs.map +1 -1
  19. package/dist/browser-prod/CartCost.mjs.map +1 -1
  20. package/dist/browser-prod/CartLineProvider.mjs +1 -1
  21. package/dist/browser-prod/CartProvider.mjs +1 -1
  22. package/dist/browser-prod/ProductPrice.mjs.map +1 -1
  23. package/dist/browser-prod/ProductProvider.mjs +1 -1
  24. package/dist/browser-prod/ShopifyProvider.mjs +1 -1
  25. package/dist/browser-prod/ShopifyProvider.mjs.map +1 -1
  26. package/dist/browser-prod/analytics-schema-custom-storefront-customer-tracking.mjs +1 -1
  27. package/dist/browser-prod/{packages/hydrogen-react/package.json.mjs → package.json.mjs} +1 -1
  28. package/dist/browser-prod/useCartAPIStateMachine.mjs +9 -9
  29. package/dist/browser-prod/useCartAPIStateMachine.mjs.map +1 -1
  30. package/dist/browser-prod/useMachine.mjs +68 -0
  31. package/dist/browser-prod/useMachine.mjs.map +1 -0
  32. package/dist/node-dev/AddToCartButton.js.map +1 -1
  33. package/dist/node-dev/AddToCartButton.mjs.map +1 -1
  34. package/dist/node-dev/BuyNowButton.js.map +1 -1
  35. package/dist/node-dev/BuyNowButton.mjs.map +1 -1
  36. package/dist/node-dev/CartCost.js.map +1 -1
  37. package/dist/node-dev/CartCost.mjs.map +1 -1
  38. package/dist/node-dev/CartLineProvider.mjs +1 -1
  39. package/dist/node-dev/CartProvider.mjs +1 -1
  40. package/dist/node-dev/ProductPrice.js.map +1 -1
  41. package/dist/node-dev/ProductPrice.mjs.map +1 -1
  42. package/dist/node-dev/ProductProvider.mjs +1 -1
  43. package/dist/node-dev/ShopifyProvider.js.map +1 -1
  44. package/dist/node-dev/ShopifyProvider.mjs +1 -1
  45. package/dist/node-dev/ShopifyProvider.mjs.map +1 -1
  46. package/dist/node-dev/analytics-schema-custom-storefront-customer-tracking.js +1 -1
  47. package/dist/node-dev/analytics-schema-custom-storefront-customer-tracking.mjs +1 -1
  48. package/dist/{node-prod/packages/hydrogen-react → node-dev}/package.json.js +1 -1
  49. package/dist/{node-prod/packages/hydrogen-react → node-dev}/package.json.mjs +1 -1
  50. package/dist/node-dev/useCartAPIStateMachine.js +10 -10
  51. package/dist/node-dev/useCartAPIStateMachine.js.map +1 -1
  52. package/dist/node-dev/useCartAPIStateMachine.mjs +9 -9
  53. package/dist/node-dev/useCartAPIStateMachine.mjs.map +1 -1
  54. package/dist/node-dev/useMachine.js +68 -0
  55. package/dist/node-dev/useMachine.js.map +1 -0
  56. package/dist/node-dev/useMachine.mjs +68 -0
  57. package/dist/node-dev/useMachine.mjs.map +1 -0
  58. package/dist/node-prod/AddToCartButton.js.map +1 -1
  59. package/dist/node-prod/AddToCartButton.mjs.map +1 -1
  60. package/dist/node-prod/BuyNowButton.js.map +1 -1
  61. package/dist/node-prod/BuyNowButton.mjs.map +1 -1
  62. package/dist/node-prod/CartCost.js.map +1 -1
  63. package/dist/node-prod/CartCost.mjs.map +1 -1
  64. package/dist/node-prod/CartLineProvider.mjs +1 -1
  65. package/dist/node-prod/CartProvider.mjs +1 -1
  66. package/dist/node-prod/ProductPrice.js.map +1 -1
  67. package/dist/node-prod/ProductPrice.mjs.map +1 -1
  68. package/dist/node-prod/ProductProvider.mjs +1 -1
  69. package/dist/node-prod/ShopifyProvider.js.map +1 -1
  70. package/dist/node-prod/ShopifyProvider.mjs +1 -1
  71. package/dist/node-prod/ShopifyProvider.mjs.map +1 -1
  72. package/dist/node-prod/analytics-schema-custom-storefront-customer-tracking.js +1 -1
  73. package/dist/node-prod/analytics-schema-custom-storefront-customer-tracking.mjs +1 -1
  74. package/dist/{node-dev/packages/hydrogen-react → node-prod}/package.json.js +1 -1
  75. package/dist/{browser-dev/packages/hydrogen-react → node-prod}/package.json.mjs +1 -1
  76. package/dist/node-prod/useCartAPIStateMachine.js +10 -10
  77. package/dist/node-prod/useCartAPIStateMachine.js.map +1 -1
  78. package/dist/node-prod/useCartAPIStateMachine.mjs +9 -9
  79. package/dist/node-prod/useCartAPIStateMachine.mjs.map +1 -1
  80. package/dist/node-prod/useMachine.js +68 -0
  81. package/dist/node-prod/useMachine.js.map +1 -0
  82. package/dist/node-prod/useMachine.mjs +68 -0
  83. package/dist/node-prod/useMachine.mjs.map +1 -0
  84. package/dist/types/useMachine.d.ts +11 -0
  85. package/dist/umd/hydrogen-react.dev.js +56 -251
  86. package/dist/umd/hydrogen-react.dev.js.map +1 -1
  87. package/dist/umd/hydrogen-react.prod.js +16 -32
  88. package/dist/umd/hydrogen-react.prod.js.map +1 -1
  89. package/package.json +38 -44
  90. package/dist/browser-dev/_virtual/index.mjs +0 -5
  91. package/dist/browser-dev/_virtual/index.mjs.map +0 -1
  92. package/dist/browser-dev/_virtual/use-sync-external-store-shim.development.mjs +0 -5
  93. package/dist/browser-dev/_virtual/use-sync-external-store-shim.development.mjs.map +0 -1
  94. package/dist/browser-dev/_virtual/use-sync-external-store-shim.production.mjs +0 -5
  95. package/dist/browser-dev/_virtual/use-sync-external-store-shim.production.mjs.map +0 -1
  96. package/dist/browser-dev/_virtual/with-selector.development.mjs +0 -5
  97. package/dist/browser-dev/_virtual/with-selector.development.mjs.map +0 -1
  98. package/dist/browser-dev/_virtual/with-selector.mjs +0 -6
  99. package/dist/browser-dev/_virtual/with-selector.mjs.map +0 -1
  100. package/dist/browser-dev/_virtual/with-selector.production.mjs +0 -5
  101. package/dist/browser-dev/_virtual/with-selector.production.mjs.map +0 -1
  102. package/dist/browser-dev/_virtual/with-selector2.mjs +0 -5
  103. package/dist/browser-dev/_virtual/with-selector2.mjs.map +0 -1
  104. package/dist/browser-dev/node_modules/@xstate/fsm/es/index.mjs +0 -151
  105. package/dist/browser-dev/node_modules/@xstate/fsm/es/index.mjs.map +0 -1
  106. package/dist/browser-dev/node_modules/@xstate/react/es/fsm.mjs +0 -89
  107. package/dist/browser-dev/node_modules/@xstate/react/es/fsm.mjs.map +0 -1
  108. package/dist/browser-dev/node_modules/@xstate/react/es/useConstant.mjs +0 -12
  109. package/dist/browser-dev/node_modules/@xstate/react/es/useConstant.mjs.map +0 -1
  110. package/dist/browser-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.mjs +0 -82
  111. package/dist/browser-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.mjs.map +0 -1
  112. package/dist/browser-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.mjs +0 -78
  113. package/dist/browser-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.mjs.map +0 -1
  114. package/dist/browser-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.mjs +0 -78
  115. package/dist/browser-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.mjs.map +0 -1
  116. package/dist/browser-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.mjs +0 -63
  117. package/dist/browser-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.mjs.map +0 -1
  118. package/dist/browser-dev/node_modules/use-sync-external-store/shim/index.mjs +0 -18
  119. package/dist/browser-dev/node_modules/use-sync-external-store/shim/index.mjs.map +0 -1
  120. package/dist/browser-dev/node_modules/use-sync-external-store/shim/with-selector.mjs +0 -18
  121. package/dist/browser-dev/node_modules/use-sync-external-store/shim/with-selector.mjs.map +0 -1
  122. package/dist/browser-prod/_virtual/index.mjs +0 -5
  123. package/dist/browser-prod/_virtual/index.mjs.map +0 -1
  124. package/dist/browser-prod/_virtual/use-sync-external-store-shim.development.mjs +0 -5
  125. package/dist/browser-prod/_virtual/use-sync-external-store-shim.development.mjs.map +0 -1
  126. package/dist/browser-prod/_virtual/use-sync-external-store-shim.production.mjs +0 -5
  127. package/dist/browser-prod/_virtual/use-sync-external-store-shim.production.mjs.map +0 -1
  128. package/dist/browser-prod/_virtual/with-selector.development.mjs +0 -5
  129. package/dist/browser-prod/_virtual/with-selector.development.mjs.map +0 -1
  130. package/dist/browser-prod/_virtual/with-selector.mjs +0 -6
  131. package/dist/browser-prod/_virtual/with-selector.mjs.map +0 -1
  132. package/dist/browser-prod/_virtual/with-selector.production.mjs +0 -5
  133. package/dist/browser-prod/_virtual/with-selector.production.mjs.map +0 -1
  134. package/dist/browser-prod/_virtual/with-selector2.mjs +0 -5
  135. package/dist/browser-prod/_virtual/with-selector2.mjs.map +0 -1
  136. package/dist/browser-prod/node_modules/@xstate/fsm/es/index.mjs +0 -151
  137. package/dist/browser-prod/node_modules/@xstate/fsm/es/index.mjs.map +0 -1
  138. package/dist/browser-prod/node_modules/@xstate/react/es/fsm.mjs +0 -89
  139. package/dist/browser-prod/node_modules/@xstate/react/es/fsm.mjs.map +0 -1
  140. package/dist/browser-prod/node_modules/@xstate/react/es/useConstant.mjs +0 -12
  141. package/dist/browser-prod/node_modules/@xstate/react/es/useConstant.mjs.map +0 -1
  142. package/dist/browser-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.mjs +0 -82
  143. package/dist/browser-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.mjs.map +0 -1
  144. package/dist/browser-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.mjs +0 -78
  145. package/dist/browser-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.mjs.map +0 -1
  146. package/dist/browser-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.mjs +0 -78
  147. package/dist/browser-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.mjs.map +0 -1
  148. package/dist/browser-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.mjs +0 -63
  149. package/dist/browser-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.mjs.map +0 -1
  150. package/dist/browser-prod/node_modules/use-sync-external-store/shim/index.mjs +0 -18
  151. package/dist/browser-prod/node_modules/use-sync-external-store/shim/index.mjs.map +0 -1
  152. package/dist/browser-prod/node_modules/use-sync-external-store/shim/with-selector.mjs +0 -18
  153. package/dist/browser-prod/node_modules/use-sync-external-store/shim/with-selector.mjs.map +0 -1
  154. package/dist/node-dev/_virtual/index.js +0 -5
  155. package/dist/node-dev/_virtual/index.js.map +0 -1
  156. package/dist/node-dev/_virtual/index.mjs +0 -5
  157. package/dist/node-dev/_virtual/index.mjs.map +0 -1
  158. package/dist/node-dev/_virtual/use-sync-external-store-shim.development.js +0 -5
  159. package/dist/node-dev/_virtual/use-sync-external-store-shim.development.js.map +0 -1
  160. package/dist/node-dev/_virtual/use-sync-external-store-shim.development.mjs +0 -5
  161. package/dist/node-dev/_virtual/use-sync-external-store-shim.development.mjs.map +0 -1
  162. package/dist/node-dev/_virtual/use-sync-external-store-shim.production.js +0 -5
  163. package/dist/node-dev/_virtual/use-sync-external-store-shim.production.js.map +0 -1
  164. package/dist/node-dev/_virtual/use-sync-external-store-shim.production.mjs +0 -5
  165. package/dist/node-dev/_virtual/use-sync-external-store-shim.production.mjs.map +0 -1
  166. package/dist/node-dev/_virtual/with-selector.development.js +0 -5
  167. package/dist/node-dev/_virtual/with-selector.development.js.map +0 -1
  168. package/dist/node-dev/_virtual/with-selector.development.mjs +0 -5
  169. package/dist/node-dev/_virtual/with-selector.development.mjs.map +0 -1
  170. package/dist/node-dev/_virtual/with-selector.js +0 -6
  171. package/dist/node-dev/_virtual/with-selector.js.map +0 -1
  172. package/dist/node-dev/_virtual/with-selector.mjs +0 -6
  173. package/dist/node-dev/_virtual/with-selector.mjs.map +0 -1
  174. package/dist/node-dev/_virtual/with-selector.production.js +0 -5
  175. package/dist/node-dev/_virtual/with-selector.production.js.map +0 -1
  176. package/dist/node-dev/_virtual/with-selector.production.mjs +0 -5
  177. package/dist/node-dev/_virtual/with-selector.production.mjs.map +0 -1
  178. package/dist/node-dev/_virtual/with-selector2.js +0 -5
  179. package/dist/node-dev/_virtual/with-selector2.js.map +0 -1
  180. package/dist/node-dev/_virtual/with-selector2.mjs +0 -5
  181. package/dist/node-dev/_virtual/with-selector2.mjs.map +0 -1
  182. package/dist/node-dev/node_modules/@xstate/fsm/es/index.js +0 -150
  183. package/dist/node-dev/node_modules/@xstate/fsm/es/index.js.map +0 -1
  184. package/dist/node-dev/node_modules/@xstate/fsm/es/index.mjs +0 -151
  185. package/dist/node-dev/node_modules/@xstate/fsm/es/index.mjs.map +0 -1
  186. package/dist/node-dev/node_modules/@xstate/react/es/fsm.js +0 -89
  187. package/dist/node-dev/node_modules/@xstate/react/es/fsm.js.map +0 -1
  188. package/dist/node-dev/node_modules/@xstate/react/es/fsm.mjs +0 -89
  189. package/dist/node-dev/node_modules/@xstate/react/es/fsm.mjs.map +0 -1
  190. package/dist/node-dev/node_modules/@xstate/react/es/useConstant.js +0 -28
  191. package/dist/node-dev/node_modules/@xstate/react/es/useConstant.js.map +0 -1
  192. package/dist/node-dev/node_modules/@xstate/react/es/useConstant.mjs +0 -12
  193. package/dist/node-dev/node_modules/@xstate/react/es/useConstant.mjs.map +0 -1
  194. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js +0 -82
  195. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js.map +0 -1
  196. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.mjs +0 -82
  197. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.mjs.map +0 -1
  198. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.js +0 -78
  199. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.js.map +0 -1
  200. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.mjs +0 -78
  201. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.mjs.map +0 -1
  202. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +0 -78
  203. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js.map +0 -1
  204. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.mjs +0 -78
  205. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.mjs.map +0 -1
  206. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js +0 -63
  207. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js.map +0 -1
  208. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.mjs +0 -63
  209. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.mjs.map +0 -1
  210. package/dist/node-dev/node_modules/use-sync-external-store/shim/index.js +0 -18
  211. package/dist/node-dev/node_modules/use-sync-external-store/shim/index.js.map +0 -1
  212. package/dist/node-dev/node_modules/use-sync-external-store/shim/index.mjs +0 -18
  213. package/dist/node-dev/node_modules/use-sync-external-store/shim/index.mjs.map +0 -1
  214. package/dist/node-dev/node_modules/use-sync-external-store/shim/with-selector.js +0 -18
  215. package/dist/node-dev/node_modules/use-sync-external-store/shim/with-selector.js.map +0 -1
  216. package/dist/node-dev/node_modules/use-sync-external-store/shim/with-selector.mjs +0 -18
  217. package/dist/node-dev/node_modules/use-sync-external-store/shim/with-selector.mjs.map +0 -1
  218. package/dist/node-prod/_virtual/index.js +0 -5
  219. package/dist/node-prod/_virtual/index.js.map +0 -1
  220. package/dist/node-prod/_virtual/index.mjs +0 -5
  221. package/dist/node-prod/_virtual/index.mjs.map +0 -1
  222. package/dist/node-prod/_virtual/use-sync-external-store-shim.development.js +0 -5
  223. package/dist/node-prod/_virtual/use-sync-external-store-shim.development.js.map +0 -1
  224. package/dist/node-prod/_virtual/use-sync-external-store-shim.development.mjs +0 -5
  225. package/dist/node-prod/_virtual/use-sync-external-store-shim.development.mjs.map +0 -1
  226. package/dist/node-prod/_virtual/use-sync-external-store-shim.production.js +0 -5
  227. package/dist/node-prod/_virtual/use-sync-external-store-shim.production.js.map +0 -1
  228. package/dist/node-prod/_virtual/use-sync-external-store-shim.production.mjs +0 -5
  229. package/dist/node-prod/_virtual/use-sync-external-store-shim.production.mjs.map +0 -1
  230. package/dist/node-prod/_virtual/with-selector.development.js +0 -5
  231. package/dist/node-prod/_virtual/with-selector.development.js.map +0 -1
  232. package/dist/node-prod/_virtual/with-selector.development.mjs +0 -5
  233. package/dist/node-prod/_virtual/with-selector.development.mjs.map +0 -1
  234. package/dist/node-prod/_virtual/with-selector.js +0 -6
  235. package/dist/node-prod/_virtual/with-selector.js.map +0 -1
  236. package/dist/node-prod/_virtual/with-selector.mjs +0 -6
  237. package/dist/node-prod/_virtual/with-selector.mjs.map +0 -1
  238. package/dist/node-prod/_virtual/with-selector.production.js +0 -5
  239. package/dist/node-prod/_virtual/with-selector.production.js.map +0 -1
  240. package/dist/node-prod/_virtual/with-selector.production.mjs +0 -5
  241. package/dist/node-prod/_virtual/with-selector.production.mjs.map +0 -1
  242. package/dist/node-prod/_virtual/with-selector2.js +0 -5
  243. package/dist/node-prod/_virtual/with-selector2.js.map +0 -1
  244. package/dist/node-prod/_virtual/with-selector2.mjs +0 -5
  245. package/dist/node-prod/_virtual/with-selector2.mjs.map +0 -1
  246. package/dist/node-prod/node_modules/@xstate/fsm/es/index.js +0 -150
  247. package/dist/node-prod/node_modules/@xstate/fsm/es/index.js.map +0 -1
  248. package/dist/node-prod/node_modules/@xstate/fsm/es/index.mjs +0 -151
  249. package/dist/node-prod/node_modules/@xstate/fsm/es/index.mjs.map +0 -1
  250. package/dist/node-prod/node_modules/@xstate/react/es/fsm.js +0 -89
  251. package/dist/node-prod/node_modules/@xstate/react/es/fsm.js.map +0 -1
  252. package/dist/node-prod/node_modules/@xstate/react/es/fsm.mjs +0 -89
  253. package/dist/node-prod/node_modules/@xstate/react/es/fsm.mjs.map +0 -1
  254. package/dist/node-prod/node_modules/@xstate/react/es/useConstant.js +0 -28
  255. package/dist/node-prod/node_modules/@xstate/react/es/useConstant.js.map +0 -1
  256. package/dist/node-prod/node_modules/@xstate/react/es/useConstant.mjs +0 -12
  257. package/dist/node-prod/node_modules/@xstate/react/es/useConstant.mjs.map +0 -1
  258. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js +0 -82
  259. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js.map +0 -1
  260. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.mjs +0 -82
  261. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.mjs.map +0 -1
  262. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.js +0 -78
  263. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.js.map +0 -1
  264. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.mjs +0 -78
  265. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.mjs.map +0 -1
  266. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +0 -78
  267. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js.map +0 -1
  268. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.mjs +0 -78
  269. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.mjs.map +0 -1
  270. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js +0 -63
  271. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js.map +0 -1
  272. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.mjs +0 -63
  273. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.mjs.map +0 -1
  274. package/dist/node-prod/node_modules/use-sync-external-store/shim/index.js +0 -18
  275. package/dist/node-prod/node_modules/use-sync-external-store/shim/index.js.map +0 -1
  276. package/dist/node-prod/node_modules/use-sync-external-store/shim/index.mjs +0 -18
  277. package/dist/node-prod/node_modules/use-sync-external-store/shim/index.mjs.map +0 -1
  278. package/dist/node-prod/node_modules/use-sync-external-store/shim/with-selector.js +0 -18
  279. package/dist/node-prod/node_modules/use-sync-external-store/shim/with-selector.js.map +0 -1
  280. package/dist/node-prod/node_modules/use-sync-external-store/shim/with-selector.mjs +0 -18
  281. package/dist/node-prod/node_modules/use-sync-external-store/shim/with-selector.mjs.map +0 -1
  282. /package/dist/browser-dev/{packages/hydrogen-react/package.json.mjs.map → package.json.mjs.map} +0 -0
  283. /package/dist/browser-prod/{packages/hydrogen-react/package.json.mjs.map → package.json.mjs.map} +0 -0
  284. /package/dist/node-dev/{packages/hydrogen-react/package.json.js.map → package.json.js.map} +0 -0
  285. /package/dist/node-dev/{packages/hydrogen-react/package.json.mjs.map → package.json.mjs.map} +0 -0
  286. /package/dist/node-prod/{packages/hydrogen-react/package.json.js.map → package.json.js.map} +0 -0
  287. /package/dist/node-prod/{packages/hydrogen-react/package.json.mjs.map → package.json.mjs.map} +0 -0
package/LICENSE.md ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2023-present, Shopify Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1 +1 @@
1
- {"version":3,"file":"AddToCartButton.mjs","sources":["../../src/AddToCartButton.tsx"],"sourcesContent":["import {useCallback, useEffect, useState} from 'react';\nimport {useCart} from './CartProvider.js';\nimport {useProduct} from './ProductProvider.js';\nimport {\n BaseButton,\n type CustomBaseButtonProps,\n type BaseButtonProps,\n} from './BaseButton.js';\nimport * as React from 'react';\nimport {CartLineParentInput} from './storefront-api-types.js';\n\nexport interface AddToCartButtonPropsBase {\n /** An array of cart line attributes that belong to the item being added to the cart. */\n attributes?: {\n key: string;\n value: string;\n }[];\n /** The ID of the variant. */\n variantId?: string | null;\n /** The item quantity. */\n quantity?: number;\n /** The text that is announced by the screen reader when the item is being added to the cart. Used for accessibility purposes only and not displayed on the page. */\n accessibleAddingToCartLabel?: string;\n /** The parent line item of the item being added to the cart. Used for nested cart lines. */\n parent?: CartLineParentInput;\n /** The selling plan ID of the subscription variant */\n sellingPlanId?: string;\n}\n\nexport type AddToCartButtonProps<AsType extends React.ElementType = 'button'> =\n AddToCartButtonPropsBase & BaseButtonProps<AsType>;\n\n/**\n * The `AddToCartButton` component renders a button that adds an item to the cart when pressed.\n * It must be a descendent of the `CartProvider` component.\n */\nexport function AddToCartButton<AsType extends React.ElementType = 'button'>(\n props: AddToCartButtonProps<AsType>,\n): JSX.Element {\n const [addingItem, setAddingItem] = useState<boolean>(false);\n const {\n variantId: explicitVariantId,\n quantity = 1,\n attributes,\n sellingPlanId,\n onClick,\n children,\n accessibleAddingToCartLabel,\n parent,\n ...passthroughProps\n } = props;\n const {status, linesAdd} = useCart();\n const {selectedVariant} = useProduct();\n const variantId = explicitVariantId ?? selectedVariant?.id ?? '';\n const disabled =\n explicitVariantId === null ||\n variantId === '' ||\n selectedVariant === null ||\n addingItem ||\n // Only certain 'as' types such as 'button' contain `disabled`\n (passthroughProps as {disabled?: boolean}).disabled;\n\n useEffect(() => {\n if (addingItem && status === 'idle') {\n setAddingItem(false);\n }\n }, [status, addingItem]);\n\n const handleAddItem = useCallback(() => {\n setAddingItem(true);\n linesAdd([\n {\n quantity,\n merchandiseId: variantId || '',\n attributes,\n parent,\n sellingPlanId,\n },\n ]);\n }, [linesAdd, quantity, variantId, attributes, sellingPlanId, parent]);\n\n return (\n <>\n <BaseButton\n {...passthroughProps}\n disabled={disabled}\n onClick={onClick}\n defaultOnClick={handleAddItem}\n >\n {children}\n </BaseButton>\n {accessibleAddingToCartLabel ? (\n <p\n style={{\n position: 'absolute',\n width: '1px',\n height: '1px',\n padding: '0',\n margin: '-1px',\n overflow: 'hidden',\n clip: 'rect(0, 0, 0, 0)',\n whiteSpace: 'nowrap',\n borderWidth: '0',\n }}\n role=\"alert\"\n aria-live=\"assertive\"\n >\n {addingItem ? accessibleAddingToCartLabel : null}\n </p>\n ) : null}\n </>\n );\n}\n\n// This is only for documentation purposes, and it is not used in the code.\nexport interface AddToCartButtonPropsForDocs<\n AsType extends React.ElementType = 'button',\n> extends AddToCartButtonPropsBase,\n CustomBaseButtonProps<AsType> {}\n"],"names":[],"mappings":";;;;;AAoCO,SAAS,gBACd,OACa;AACb,QAAM,CAAC,YAAY,aAAa,IAAI,SAAkB,KAAK;AAC3D,QAAM;AAAA,IACJ,WAAW;AAAA,IACX,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,IACD;AACJ,QAAM,EAAC,QAAQ,SAAA,IAAY,QAAA;AAC3B,QAAM,EAAC,gBAAA,IAAmB,WAAA;AAC1B,QAAM,YAAY,sBAAqB,mDAAiB,OAAM;AAC9D,QAAM,WACJ,sBAAsB,QACtB,cAAc,MACd,oBAAoB,QACpB;AAAA,EAEC,iBAA0C;AAE7C,YAAU,MAAM;AACd,QAAI,cAAc,WAAW,QAAQ;AACnC,oBAAc,KAAK;AAAA,IACrB;AAAA,EACF,GAAG,CAAC,QAAQ,UAAU,CAAC;AAEvB,QAAM,gBAAgB,YAAY,MAAM;AACtC,kBAAc,IAAI;AAClB,aAAS;AAAA,MACP;AAAA,QACE;AAAA,QACA,eAAe,aAAa;AAAA,QAC5B;AAAA,QACA;AAAA,QACA;AAAA,MAAA;AAAA,IACF,CACD;AAAA,EACH,GAAG,CAAC,UAAU,UAAU,WAAW,YAAY,eAAe,MAAM,CAAC;AAErE,SACE,qBAAA,UAAA,EACE,UAAA;AAAA,IAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACE,GAAG;AAAA,QACJ;AAAA,QACA;AAAA,QACA,gBAAgB;AAAA,QAEf;AAAA,MAAA;AAAA,IAAA;AAAA,IAEF,8BACC;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,OAAO;AAAA,UACL,UAAU;AAAA,UACV,OAAO;AAAA,UACP,QAAQ;AAAA,UACR,SAAS;AAAA,UACT,QAAQ;AAAA,UACR,UAAU;AAAA,UACV,MAAM;AAAA,UACN,YAAY;AAAA,UACZ,aAAa;AAAA,QAAA;AAAA,QAEf,MAAK;AAAA,QACL,aAAU;AAAA,QAET,uBAAa,8BAA8B;AAAA,MAAA;AAAA,IAAA,IAE5C;AAAA,EAAA,GACN;AAEJ;"}
1
+ {"version":3,"file":"AddToCartButton.mjs","sources":["../../src/AddToCartButton.tsx"],"sourcesContent":["import {useCallback, useEffect, useState} from 'react';\nimport {useCart} from './CartProvider.js';\nimport {useProduct} from './ProductProvider.js';\nimport {\n BaseButton,\n type CustomBaseButtonProps,\n type BaseButtonProps,\n} from './BaseButton.js';\nimport * as React from 'react';\nimport {CartLineParentInput} from './storefront-api-types.js';\n\nexport interface AddToCartButtonPropsBase {\n /** An array of cart line attributes that belong to the item being added to the cart. */\n attributes?: {\n key: string;\n value: string;\n }[];\n /** The ID of the variant. */\n variantId?: string | null;\n /** The item quantity. */\n quantity?: number;\n /** The text that is announced by the screen reader when the item is being added to the cart. Used for accessibility purposes only and not displayed on the page. */\n accessibleAddingToCartLabel?: string;\n /** The parent line item of the item being added to the cart. Used for nested cart lines. */\n parent?: CartLineParentInput;\n /** The selling plan ID of the subscription variant */\n sellingPlanId?: string;\n}\n\nexport type AddToCartButtonProps<AsType extends React.ElementType = 'button'> =\n AddToCartButtonPropsBase & BaseButtonProps<AsType>;\n\n/**\n * The `AddToCartButton` component renders a button that adds an item to the cart when pressed.\n * It must be a descendent of the `CartProvider` component.\n */\nexport function AddToCartButton<AsType extends React.ElementType = 'button'>(\n props: AddToCartButtonProps<AsType>,\n): JSX.Element {\n const [addingItem, setAddingItem] = useState<boolean>(false);\n const {\n variantId: explicitVariantId,\n quantity = 1,\n attributes,\n sellingPlanId,\n onClick,\n children,\n accessibleAddingToCartLabel,\n parent,\n ...passthroughProps\n } = props;\n const {status, linesAdd} = useCart();\n const {selectedVariant} = useProduct();\n const variantId = explicitVariantId ?? selectedVariant?.id ?? '';\n const disabled =\n explicitVariantId === null ||\n variantId === '' ||\n selectedVariant === null ||\n addingItem ||\n // Only certain 'as' types such as 'button' contain `disabled`\n (passthroughProps as {disabled?: boolean}).disabled;\n\n useEffect(() => {\n if (addingItem && status === 'idle') {\n setAddingItem(false);\n }\n }, [status, addingItem]);\n\n const handleAddItem = useCallback(() => {\n setAddingItem(true);\n linesAdd([\n {\n quantity,\n merchandiseId: variantId || '',\n attributes,\n parent,\n sellingPlanId,\n },\n ]);\n }, [linesAdd, quantity, variantId, attributes, sellingPlanId, parent]);\n\n return (\n <>\n <BaseButton\n {...passthroughProps}\n disabled={disabled}\n onClick={onClick}\n defaultOnClick={handleAddItem}\n >\n {children}\n </BaseButton>\n {accessibleAddingToCartLabel ? (\n <p\n style={{\n position: 'absolute',\n width: '1px',\n height: '1px',\n padding: '0',\n margin: '-1px',\n overflow: 'hidden',\n clip: 'rect(0, 0, 0, 0)',\n whiteSpace: 'nowrap',\n borderWidth: '0',\n }}\n role=\"alert\"\n aria-live=\"assertive\"\n >\n {addingItem ? accessibleAddingToCartLabel : null}\n </p>\n ) : null}\n </>\n );\n}\n\n// This is only for documentation purposes, and it is not used in the code.\nexport interface AddToCartButtonPropsForDocs<\n AsType extends React.ElementType = 'button',\n>\n extends AddToCartButtonPropsBase, CustomBaseButtonProps<AsType> {}\n"],"names":[],"mappings":";;;;;AAoCO,SAAS,gBACd,OACa;AACb,QAAM,CAAC,YAAY,aAAa,IAAI,SAAkB,KAAK;AAC3D,QAAM;AAAA,IACJ,WAAW;AAAA,IACX,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,IACD;AACJ,QAAM,EAAC,QAAQ,SAAA,IAAY,QAAA;AAC3B,QAAM,EAAC,gBAAA,IAAmB,WAAA;AAC1B,QAAM,YAAY,sBAAqB,mDAAiB,OAAM;AAC9D,QAAM,WACJ,sBAAsB,QACtB,cAAc,MACd,oBAAoB,QACpB;AAAA,EAEC,iBAA0C;AAE7C,YAAU,MAAM;AACd,QAAI,cAAc,WAAW,QAAQ;AACnC,oBAAc,KAAK;AAAA,IACrB;AAAA,EACF,GAAG,CAAC,QAAQ,UAAU,CAAC;AAEvB,QAAM,gBAAgB,YAAY,MAAM;AACtC,kBAAc,IAAI;AAClB,aAAS;AAAA,MACP;AAAA,QACE;AAAA,QACA,eAAe,aAAa;AAAA,QAC5B;AAAA,QACA;AAAA,QACA;AAAA,MAAA;AAAA,IACF,CACD;AAAA,EACH,GAAG,CAAC,UAAU,UAAU,WAAW,YAAY,eAAe,MAAM,CAAC;AAErE,SACE,qBAAA,UAAA,EACE,UAAA;AAAA,IAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACE,GAAG;AAAA,QACJ;AAAA,QACA;AAAA,QACA,gBAAgB;AAAA,QAEf;AAAA,MAAA;AAAA,IAAA;AAAA,IAEF,8BACC;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,OAAO;AAAA,UACL,UAAU;AAAA,UACV,OAAO;AAAA,UACP,QAAQ;AAAA,UACR,SAAS;AAAA,UACT,QAAQ;AAAA,UACR,UAAU;AAAA,UACV,MAAM;AAAA,UACN,YAAY;AAAA,UACZ,aAAa;AAAA,QAAA;AAAA,QAEf,MAAK;AAAA,QACL,aAAU;AAAA,QAET,uBAAa,8BAA8B;AAAA,MAAA;AAAA,IAAA,IAE5C;AAAA,EAAA,GACN;AAEJ;"}
@@ -1 +1 @@
1
- {"version":3,"file":"BuyNowButton.mjs","sources":["../../src/BuyNowButton.tsx"],"sourcesContent":["import {useEffect, useState, useCallback} from 'react';\nimport {useCart} from './CartProvider.js';\nimport {\n BaseButton,\n type BaseButtonProps,\n type CustomBaseButtonProps,\n} from './BaseButton.js';\n\ninterface BuyNowButtonPropsBase {\n /** The item quantity. Defaults to 1. */\n quantity?: number;\n /** The ID of the variant. */\n variantId: string;\n /** The selling plan ID of the subscription variant */\n sellingPlanId?: string;\n /** An array of cart line attributes that belong to the item being added to the cart. */\n attributes?: {\n key: string;\n value: string;\n }[];\n}\n\ntype BuyNowButtonProps<AsType extends React.ElementType = 'button'> =\n BuyNowButtonPropsBase & BaseButtonProps<AsType>;\n\n/**\n * The `BuyNowButton` component renders a button that adds an item to the cart and redirects the customer to checkout.\n * Must be a child of a `CartProvider` component.\n */\nexport function BuyNowButton<AsType extends React.ElementType = 'button'>(\n props: BuyNowButtonProps<AsType>,\n): JSX.Element {\n const {cartCreate, checkoutUrl} = useCart();\n const [loading, setLoading] = useState<boolean>(false);\n\n const {\n quantity,\n variantId,\n sellingPlanId,\n onClick,\n attributes,\n children,\n ...passthroughProps\n } = props;\n\n useEffect(() => {\n if (loading && checkoutUrl) {\n window.location.href = checkoutUrl;\n }\n }, [loading, checkoutUrl]);\n\n const handleBuyNow = useCallback(() => {\n setLoading(true);\n cartCreate({\n lines: [\n {\n quantity: quantity ?? 1,\n merchandiseId: variantId,\n attributes,\n sellingPlanId,\n },\n ],\n });\n }, [cartCreate, quantity, variantId, attributes, sellingPlanId]);\n\n return (\n <BaseButton\n // Only certain 'as' types such as 'button' contain `disabled`\n disabled={loading ?? (passthroughProps as {disabled?: boolean}).disabled}\n {...passthroughProps}\n onClick={onClick}\n defaultOnClick={handleBuyNow}\n >\n {children}\n </BaseButton>\n );\n}\n\n// This is only for documentation purposes, and it is not used in the code.\nexport interface BuyNowButtonPropsForDocs<\n AsType extends React.ElementType = 'button',\n> extends BuyNowButtonPropsBase,\n CustomBaseButtonProps<AsType> {}\n"],"names":[],"mappings":";;;;AA6BO,SAAS,aACd,OACa;AACb,QAAM,EAAC,YAAY,YAAA,IAAe,QAAA;AAClC,QAAM,CAAC,SAAS,UAAU,IAAI,SAAkB,KAAK;AAErD,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,IACD;AAEJ,YAAU,MAAM;AACd,QAAI,WAAW,aAAa;AAC1B,aAAO,SAAS,OAAO;AAAA,IACzB;AAAA,EACF,GAAG,CAAC,SAAS,WAAW,CAAC;AAEzB,QAAM,eAAe,YAAY,MAAM;AACrC,eAAW,IAAI;AACf,eAAW;AAAA,MACT,OAAO;AAAA,QACL;AAAA,UACE,UAAU,YAAY;AAAA,UACtB,eAAe;AAAA,UACf;AAAA,UACA;AAAA,QAAA;AAAA,MACF;AAAA,IACF,CACD;AAAA,EACH,GAAG,CAAC,YAAY,UAAU,WAAW,YAAY,aAAa,CAAC;AAE/D,SACE;AAAA,IAAC;AAAA,IAAA;AAAA,MAEC,UAAU,WAAY,iBAA0C;AAAA,MAC/D,GAAG;AAAA,MACJ;AAAA,MACA,gBAAgB;AAAA,MAEf;AAAA,IAAA;AAAA,EAAA;AAGP;"}
1
+ {"version":3,"file":"BuyNowButton.mjs","sources":["../../src/BuyNowButton.tsx"],"sourcesContent":["import {useEffect, useState, useCallback} from 'react';\nimport {useCart} from './CartProvider.js';\nimport {\n BaseButton,\n type BaseButtonProps,\n type CustomBaseButtonProps,\n} from './BaseButton.js';\n\ninterface BuyNowButtonPropsBase {\n /** The item quantity. Defaults to 1. */\n quantity?: number;\n /** The ID of the variant. */\n variantId: string;\n /** The selling plan ID of the subscription variant */\n sellingPlanId?: string;\n /** An array of cart line attributes that belong to the item being added to the cart. */\n attributes?: {\n key: string;\n value: string;\n }[];\n}\n\ntype BuyNowButtonProps<AsType extends React.ElementType = 'button'> =\n BuyNowButtonPropsBase & BaseButtonProps<AsType>;\n\n/**\n * The `BuyNowButton` component renders a button that adds an item to the cart and redirects the customer to checkout.\n * Must be a child of a `CartProvider` component.\n */\nexport function BuyNowButton<AsType extends React.ElementType = 'button'>(\n props: BuyNowButtonProps<AsType>,\n): JSX.Element {\n const {cartCreate, checkoutUrl} = useCart();\n const [loading, setLoading] = useState<boolean>(false);\n\n const {\n quantity,\n variantId,\n sellingPlanId,\n onClick,\n attributes,\n children,\n ...passthroughProps\n } = props;\n\n useEffect(() => {\n if (loading && checkoutUrl) {\n window.location.href = checkoutUrl;\n }\n }, [loading, checkoutUrl]);\n\n const handleBuyNow = useCallback(() => {\n setLoading(true);\n cartCreate({\n lines: [\n {\n quantity: quantity ?? 1,\n merchandiseId: variantId,\n attributes,\n sellingPlanId,\n },\n ],\n });\n }, [cartCreate, quantity, variantId, attributes, sellingPlanId]);\n\n return (\n <BaseButton\n // Only certain 'as' types such as 'button' contain `disabled`\n disabled={loading ?? (passthroughProps as {disabled?: boolean}).disabled}\n {...passthroughProps}\n onClick={onClick}\n defaultOnClick={handleBuyNow}\n >\n {children}\n </BaseButton>\n );\n}\n\n// This is only for documentation purposes, and it is not used in the code.\nexport interface BuyNowButtonPropsForDocs<\n AsType extends React.ElementType = 'button',\n>\n extends BuyNowButtonPropsBase, CustomBaseButtonProps<AsType> {}\n"],"names":[],"mappings":";;;;AA6BO,SAAS,aACd,OACa;AACb,QAAM,EAAC,YAAY,YAAA,IAAe,QAAA;AAClC,QAAM,CAAC,SAAS,UAAU,IAAI,SAAkB,KAAK;AAErD,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,IACD;AAEJ,YAAU,MAAM;AACd,QAAI,WAAW,aAAa;AAC1B,aAAO,SAAS,OAAO;AAAA,IACzB;AAAA,EACF,GAAG,CAAC,SAAS,WAAW,CAAC;AAEzB,QAAM,eAAe,YAAY,MAAM;AACrC,eAAW,IAAI;AACf,eAAW;AAAA,MACT,OAAO;AAAA,QACL;AAAA,UACE,UAAU,YAAY;AAAA,UACtB,eAAe;AAAA,UACf;AAAA,UACA;AAAA,QAAA;AAAA,MACF;AAAA,IACF,CACD;AAAA,EACH,GAAG,CAAC,YAAY,UAAU,WAAW,YAAY,aAAa,CAAC;AAE/D,SACE;AAAA,IAAC;AAAA,IAAA;AAAA,MAEC,UAAU,WAAY,iBAA0C;AAAA,MAC/D,GAAG;AAAA,MACJ;AAAA,MACA,gBAAgB;AAAA,MAEf;AAAA,IAAA;AAAA,EAAA;AAGP;"}
@@ -1 +1 @@
1
- {"version":3,"file":"CartCost.mjs","sources":["../../src/CartCost.tsx"],"sourcesContent":["import {Money, type MoneyPropsBase} from './Money.js';\nimport {useCart} from './CartProvider.js';\n\ninterface CartCostPropsBase {\n /** A string type that defines the type of cost needed. Valid values: `total`, `subtotal`, `tax`, or `duty`. */\n amountType?: 'total' | 'subtotal' | 'tax' | 'duty';\n /** Any `ReactNode` elements. */\n children?: React.ReactNode;\n}\n\ntype CartCostProps = Omit<React.ComponentProps<typeof Money>, 'data'> &\n CartCostPropsBase;\n\n/**\n * The `CartCost` component renders a `Money` component with the cost associated with the `amountType` prop.\n * If no `amountType` prop is specified, then it defaults to `totalAmount`.\n * Depends on `useCart()` and must be a child of `<CartProvider/>`\n */\nexport function CartCost(props: CartCostProps): JSX.Element | null {\n const {cost} = useCart();\n const {amountType = 'total', children, ...passthroughProps} = props;\n let amount;\n\n if (amountType == 'total') {\n amount = cost?.totalAmount;\n } else if (amountType == 'subtotal') {\n amount = cost?.subtotalAmount;\n } else if (amountType == 'tax') {\n amount = cost?.totalTaxAmount;\n } else if (amountType == 'duty') {\n amount = cost?.totalDutyAmount;\n }\n\n if (amount == null) {\n return null;\n }\n\n return (\n <Money {...passthroughProps} data={amount}>\n {children}\n </Money>\n );\n}\n\n// This is only for documentation purposes, and it is not used in the code.\nexport interface CartCostPropsForDocs<AsType extends React.ElementType = 'div'>\n extends Omit<MoneyPropsBase<AsType>, 'data'>,\n CartCostPropsBase {}\n"],"names":[],"mappings":";;;AAkBO,SAAS,SAAS,OAA0C;AACjE,QAAM,EAAC,KAAA,IAAQ,QAAA;AACf,QAAM,EAAC,aAAa,SAAS,UAAU,GAAG,qBAAoB;AAC9D,MAAI;AAEJ,MAAI,cAAc,SAAS;AACzB,aAAS,6BAAM;AAAA,EACjB,WAAW,cAAc,YAAY;AACnC,aAAS,6BAAM;AAAA,EACjB,WAAW,cAAc,OAAO;AAC9B,aAAS,6BAAM;AAAA,EACjB,WAAW,cAAc,QAAQ;AAC/B,aAAS,6BAAM;AAAA,EACjB;AAEA,MAAI,UAAU,MAAM;AAClB,WAAO;AAAA,EACT;AAEA,6BACG,OAAA,EAAO,GAAG,kBAAkB,MAAM,QAChC,UACH;AAEJ;"}
1
+ {"version":3,"file":"CartCost.mjs","sources":["../../src/CartCost.tsx"],"sourcesContent":["import {Money, type MoneyPropsBase} from './Money.js';\nimport {useCart} from './CartProvider.js';\n\ninterface CartCostPropsBase {\n /** A string type that defines the type of cost needed. Valid values: `total`, `subtotal`, `tax`, or `duty`. */\n amountType?: 'total' | 'subtotal' | 'tax' | 'duty';\n /** Any `ReactNode` elements. */\n children?: React.ReactNode;\n}\n\ntype CartCostProps = Omit<React.ComponentProps<typeof Money>, 'data'> &\n CartCostPropsBase;\n\n/**\n * The `CartCost` component renders a `Money` component with the cost associated with the `amountType` prop.\n * If no `amountType` prop is specified, then it defaults to `totalAmount`.\n * Depends on `useCart()` and must be a child of `<CartProvider/>`\n */\nexport function CartCost(props: CartCostProps): JSX.Element | null {\n const {cost} = useCart();\n const {amountType = 'total', children, ...passthroughProps} = props;\n let amount;\n\n if (amountType == 'total') {\n amount = cost?.totalAmount;\n } else if (amountType == 'subtotal') {\n amount = cost?.subtotalAmount;\n } else if (amountType == 'tax') {\n amount = cost?.totalTaxAmount;\n } else if (amountType == 'duty') {\n amount = cost?.totalDutyAmount;\n }\n\n if (amount == null) {\n return null;\n }\n\n return (\n <Money {...passthroughProps} data={amount}>\n {children}\n </Money>\n );\n}\n\n// This is only for documentation purposes, and it is not used in the code.\nexport interface CartCostPropsForDocs<AsType extends React.ElementType = 'div'>\n extends Omit<MoneyPropsBase<AsType>, 'data'>, CartCostPropsBase {}\n"],"names":[],"mappings":";;;AAkBO,SAAS,SAAS,OAA0C;AACjE,QAAM,EAAC,KAAA,IAAQ,QAAA;AACf,QAAM,EAAC,aAAa,SAAS,UAAU,GAAG,qBAAoB;AAC9D,MAAI;AAEJ,MAAI,cAAc,SAAS;AACzB,aAAS,6BAAM;AAAA,EACjB,WAAW,cAAc,YAAY;AACnC,aAAS,6BAAM;AAAA,EACjB,WAAW,cAAc,OAAO;AAC9B,aAAS,6BAAM;AAAA,EACjB,WAAW,cAAc,QAAQ;AAC/B,aAAS,6BAAM;AAAA,EACjB;AAEA,MAAI,UAAU,MAAM;AAClB,WAAO;AAAA,EACT;AAEA,6BACG,OAAA,EAAO,GAAG,kBAAkB,MAAM,QAChC,UACH;AAEJ;"}
@@ -1,5 +1,5 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { createContext, useContext } from "react";
2
+ import { useContext, createContext } from "react";
3
3
  const CartLineContext = createContext(null);
4
4
  function useCartLine() {
5
5
  const context = useContext(CartLineContext);
@@ -1,5 +1,5 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { useState, useRef, useEffect, useCallback, useMemo, createContext, useContext, useTransition } from "react";
2
+ import { useState, useRef, useEffect, useCallback, useMemo, useContext, useTransition, createContext } from "react";
3
3
  import { useCartAPIStateMachine } from "./useCartAPIStateMachine.mjs";
4
4
  import { CART_ID_STORAGE_KEY } from "./cart-constants.mjs";
5
5
  import { defaultCartFragment } from "./cart-queries.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"ProductPrice.mjs","sources":["../../src/ProductPrice.tsx"],"sourcesContent":["import type {\n MoneyV2,\n UnitPriceMeasurement,\n Product,\n} from './storefront-api-types.js';\nimport {Money, type MoneyProps, type MoneyPropsBase} from './Money.js';\nimport type {PartialDeep} from 'type-fest';\nimport {flattenConnection} from './flatten-connection.js';\n\nexport interface ProductPriceProps {\n /** A Storefront API [Product object](https://shopify.dev/api/storefront/reference/products/product). */\n data: PartialDeep<Product, {recurseIntoArrays: true}>;\n /** The type of price. Valid values: `regular` (default) or `compareAt`. */\n priceType?: 'regular' | 'compareAt';\n /** The type of value. Valid values: `min` (default), `max` or `unit`. */\n valueType?: 'max' | 'min' | 'unit';\n /** The ID of the variant. */\n variantId?: string;\n}\n\n/**\n * The `ProductPrice` component renders a `Money` component with the product\n * [`priceRange`](https://shopify.dev/api/storefront/reference/products/productpricerange)'s `maxVariantPrice` or `minVariantPrice`, for either the regular price or compare at price range.\n */\nexport function ProductPrice<\n ComponentGeneric extends React.ElementType = 'div',\n>(\n props: ProductPriceProps &\n Omit<MoneyProps<ComponentGeneric>, 'data' | 'measurement'>,\n): JSX.Element | null {\n const {\n priceType = 'regular',\n variantId,\n valueType = 'min',\n data: product,\n ...passthroughProps\n } = props;\n\n if (product == null) {\n throw new Error(`<ProductPrice/> requires a product as the 'data' prop`);\n }\n\n let price: Partial<MoneyV2> | undefined | null;\n let measurement: Partial<UnitPriceMeasurement> | undefined | null;\n\n const variant = variantId\n ? (flattenConnection(product?.variants ?? {}).find(\n (variant) => variant?.id === variantId,\n ) ?? null)\n : null;\n\n const variantPriceProperty =\n valueType === 'max' ? 'maxVariantPrice' : 'minVariantPrice';\n\n if (priceType === 'compareAt') {\n if (variantId && variant) {\n price = variant.compareAtPrice;\n } else {\n price = product?.compareAtPriceRange?.[variantPriceProperty];\n }\n\n let priceAsNumber: number;\n if (variantId && variant) {\n priceAsNumber = parseFloat(variant.price?.amount ?? '0');\n } else {\n priceAsNumber = parseFloat(\n product?.priceRange?.[variantPriceProperty]?.amount ?? '0',\n );\n }\n\n const compareAtPriceAsNumber = parseFloat(price?.amount ?? '0');\n\n if (priceAsNumber >= compareAtPriceAsNumber) {\n return null;\n }\n } else {\n if (variantId && variant) {\n price = variant.price;\n if (valueType === 'unit') {\n price = variant.unitPrice;\n measurement = variant.unitPriceMeasurement;\n }\n } else if (valueType === 'max') {\n price = product.priceRange?.maxVariantPrice;\n } else {\n price = product.priceRange?.minVariantPrice;\n }\n }\n\n if (!price) {\n return null;\n }\n\n if (measurement) {\n return (\n <Money {...passthroughProps} data={price} measurement={measurement} />\n );\n }\n\n return <Money {...passthroughProps} data={price} />;\n}\n\n// This is only for documentation purposes, and it is not used in the code.\nexport interface ProductPricePropsForDocs<\n AsType extends React.ElementType = 'div',\n> extends Omit<MoneyPropsBase<AsType>, 'data' | 'measurement'>,\n ProductPriceProps {}\n"],"names":["variant"],"mappings":";;;AAwBO,SAAS,aAGd,OAEoB;;AACpB,QAAM;AAAA,IACJ,YAAY;AAAA,IACZ;AAAA,IACA,YAAY;AAAA,IACZ,MAAM;AAAA,IACN,GAAG;AAAA,EAAA,IACD;AAEJ,MAAI,WAAW,MAAM;AACnB,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAEA,MAAI;AACJ,MAAI;AAEJ,QAAM,UAAU,YACX,mBAAkB,mCAAS,aAAY,CAAA,CAAE,EAAE;AAAA,IAC1C,CAACA,cAAYA,qCAAS,QAAO;AAAA,EAAA,KAC1B,OACL;AAEJ,QAAM,uBACJ,cAAc,QAAQ,oBAAoB;AAE5C,MAAI,cAAc,aAAa;AAC7B,QAAI,aAAa,SAAS;AACxB,cAAQ,QAAQ;AAAA,IAClB,OAAO;AACL,eAAQ,wCAAS,wBAAT,mBAA+B;AAAA,IACzC;AAEA,QAAI;AACJ,QAAI,aAAa,SAAS;AACxB,sBAAgB,aAAW,aAAQ,UAAR,mBAAe,WAAU,GAAG;AAAA,IACzD,OAAO;AACL,sBAAgB;AAAA,UACd,8CAAS,eAAT,mBAAsB,0BAAtB,mBAA6C,WAAU;AAAA,MAAA;AAAA,IAE3D;AAEA,UAAM,yBAAyB,YAAW,+BAAO,WAAU,GAAG;AAE9D,QAAI,iBAAiB,wBAAwB;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,OAAO;AACL,QAAI,aAAa,SAAS;AACxB,cAAQ,QAAQ;AAChB,UAAI,cAAc,QAAQ;AACxB,gBAAQ,QAAQ;AAChB,sBAAc,QAAQ;AAAA,MACxB;AAAA,IACF,WAAW,cAAc,OAAO;AAC9B,eAAQ,aAAQ,eAAR,mBAAoB;AAAA,IAC9B,OAAO;AACL,eAAQ,aAAQ,eAAR,mBAAoB;AAAA,IAC9B;AAAA,EACF;AAEA,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AAEA,MAAI,aAAa;AACf,+BACG,OAAA,EAAO,GAAG,kBAAkB,MAAM,OAAO,aAA0B;AAAA,EAExE;AAEA,SAAO,oBAAC,OAAA,EAAO,GAAG,kBAAkB,MAAM,OAAO;AACnD;"}
1
+ {"version":3,"file":"ProductPrice.mjs","sources":["../../src/ProductPrice.tsx"],"sourcesContent":["import type {\n MoneyV2,\n UnitPriceMeasurement,\n Product,\n} from './storefront-api-types.js';\nimport {Money, type MoneyProps, type MoneyPropsBase} from './Money.js';\nimport type {PartialDeep} from 'type-fest';\nimport {flattenConnection} from './flatten-connection.js';\n\nexport interface ProductPriceProps {\n /** A Storefront API [Product object](https://shopify.dev/api/storefront/reference/products/product). */\n data: PartialDeep<Product, {recurseIntoArrays: true}>;\n /** The type of price. Valid values: `regular` (default) or `compareAt`. */\n priceType?: 'regular' | 'compareAt';\n /** The type of value. Valid values: `min` (default), `max` or `unit`. */\n valueType?: 'max' | 'min' | 'unit';\n /** The ID of the variant. */\n variantId?: string;\n}\n\n/**\n * The `ProductPrice` component renders a `Money` component with the product\n * [`priceRange`](https://shopify.dev/api/storefront/reference/products/productpricerange)'s `maxVariantPrice` or `minVariantPrice`, for either the regular price or compare at price range.\n */\nexport function ProductPrice<\n ComponentGeneric extends React.ElementType = 'div',\n>(\n props: ProductPriceProps &\n Omit<MoneyProps<ComponentGeneric>, 'data' | 'measurement'>,\n): JSX.Element | null {\n const {\n priceType = 'regular',\n variantId,\n valueType = 'min',\n data: product,\n ...passthroughProps\n } = props;\n\n if (product == null) {\n throw new Error(`<ProductPrice/> requires a product as the 'data' prop`);\n }\n\n let price: Partial<MoneyV2> | undefined | null;\n let measurement: Partial<UnitPriceMeasurement> | undefined | null;\n\n const variant = variantId\n ? (flattenConnection(product?.variants ?? {}).find(\n (variant) => variant?.id === variantId,\n ) ?? null)\n : null;\n\n const variantPriceProperty =\n valueType === 'max' ? 'maxVariantPrice' : 'minVariantPrice';\n\n if (priceType === 'compareAt') {\n if (variantId && variant) {\n price = variant.compareAtPrice;\n } else {\n price = product?.compareAtPriceRange?.[variantPriceProperty];\n }\n\n let priceAsNumber: number;\n if (variantId && variant) {\n priceAsNumber = parseFloat(variant.price?.amount ?? '0');\n } else {\n priceAsNumber = parseFloat(\n product?.priceRange?.[variantPriceProperty]?.amount ?? '0',\n );\n }\n\n const compareAtPriceAsNumber = parseFloat(price?.amount ?? '0');\n\n if (priceAsNumber >= compareAtPriceAsNumber) {\n return null;\n }\n } else {\n if (variantId && variant) {\n price = variant.price;\n if (valueType === 'unit') {\n price = variant.unitPrice;\n measurement = variant.unitPriceMeasurement;\n }\n } else if (valueType === 'max') {\n price = product.priceRange?.maxVariantPrice;\n } else {\n price = product.priceRange?.minVariantPrice;\n }\n }\n\n if (!price) {\n return null;\n }\n\n if (measurement) {\n return (\n <Money {...passthroughProps} data={price} measurement={measurement} />\n );\n }\n\n return <Money {...passthroughProps} data={price} />;\n}\n\n// This is only for documentation purposes, and it is not used in the code.\nexport interface ProductPricePropsForDocs<\n AsType extends React.ElementType = 'div',\n>\n extends\n Omit<MoneyPropsBase<AsType>, 'data' | 'measurement'>,\n ProductPriceProps {}\n"],"names":["variant"],"mappings":";;;AAwBO,SAAS,aAGd,OAEoB;;AACpB,QAAM;AAAA,IACJ,YAAY;AAAA,IACZ;AAAA,IACA,YAAY;AAAA,IACZ,MAAM;AAAA,IACN,GAAG;AAAA,EAAA,IACD;AAEJ,MAAI,WAAW,MAAM;AACnB,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAEA,MAAI;AACJ,MAAI;AAEJ,QAAM,UAAU,YACX,mBAAkB,mCAAS,aAAY,CAAA,CAAE,EAAE;AAAA,IAC1C,CAACA,cAAYA,qCAAS,QAAO;AAAA,EAAA,KAC1B,OACL;AAEJ,QAAM,uBACJ,cAAc,QAAQ,oBAAoB;AAE5C,MAAI,cAAc,aAAa;AAC7B,QAAI,aAAa,SAAS;AACxB,cAAQ,QAAQ;AAAA,IAClB,OAAO;AACL,eAAQ,wCAAS,wBAAT,mBAA+B;AAAA,IACzC;AAEA,QAAI;AACJ,QAAI,aAAa,SAAS;AACxB,sBAAgB,aAAW,aAAQ,UAAR,mBAAe,WAAU,GAAG;AAAA,IACzD,OAAO;AACL,sBAAgB;AAAA,UACd,8CAAS,eAAT,mBAAsB,0BAAtB,mBAA6C,WAAU;AAAA,MAAA;AAAA,IAE3D;AAEA,UAAM,yBAAyB,YAAW,+BAAO,WAAU,GAAG;AAE9D,QAAI,iBAAiB,wBAAwB;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,OAAO;AACL,QAAI,aAAa,SAAS;AACxB,cAAQ,QAAQ;AAChB,UAAI,cAAc,QAAQ;AACxB,gBAAQ,QAAQ;AAChB,sBAAc,QAAQ;AAAA,MACxB;AAAA,IACF,WAAW,cAAc,OAAO;AAC9B,eAAQ,aAAQ,eAAR,mBAAoB;AAAA,IAC9B,OAAO;AACL,eAAQ,aAAQ,eAAR,mBAAoB;AAAA,IAC9B;AAAA,EACF;AAEA,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AAEA,MAAI,aAAa;AACf,+BACG,OAAA,EAAO,GAAG,kBAAkB,MAAM,OAAO,aAA0B;AAAA,EAExE;AAEA,SAAO,oBAAC,OAAA,EAAO,GAAG,kBAAkB,MAAM,OAAO;AACnD;"}
@@ -1,5 +1,5 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { useMemo, useState, useEffect, useCallback, createContext, useContext } from "react";
2
+ import { useMemo, useState, useEffect, useCallback, useContext, createContext } from "react";
3
3
  import { flattenConnection } from "./flatten-connection.mjs";
4
4
  const ProductOptionsContext = createContext(null);
5
5
  function ProductProvider({
@@ -1,5 +1,5 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { useMemo, createContext, useContext } from "react";
2
+ import { useMemo, useContext, createContext } from "react";
3
3
  import { SFAPI_VERSION } from "./storefront-api-constants.mjs";
4
4
  import { getPublicTokenHeadersRaw } from "./storefront-client.mjs";
5
5
  const defaultShopifyContext = {
@@ -1 +1 @@
1
- {"version":3,"file":"ShopifyProvider.mjs","sources":["../../src/ShopifyProvider.tsx"],"sourcesContent":["import {createContext, useContext, useMemo, type ReactNode} from 'react';\nimport type {LanguageCode, CountryCode} from './storefront-api-types.js';\nimport {SFAPI_VERSION} from './storefront-api-constants.js';\nimport {getPublicTokenHeadersRaw} from './storefront-client.js';\n\nexport const defaultShopifyContext: ShopifyContextValue = {\n storeDomain: 'test',\n storefrontToken: 'abc123',\n storefrontApiVersion: SFAPI_VERSION,\n countryIsoCode: 'US',\n languageIsoCode: 'EN',\n getStorefrontApiUrl() {\n return '';\n },\n getPublicTokenHeaders() {\n return {};\n },\n getShopifyDomain() {\n return '';\n },\n};\n\nconst ShopifyContext = createContext<ShopifyContextValue>(\n defaultShopifyContext,\n);\n\n/**\n * Hydrogen server sets this server timing key when the SFAPI proxy is enabled.\n * Read it automatically in the browser for apps using frontend cart in full-stack Hydrogen,\n * but don't export this utility yet since we don't want to make this a public convention.\n */\nfunction isSfapiProxyEnabled() {\n if (typeof window === 'undefined') return false;\n\n try {\n const navigationEntry = window.performance?.getEntriesByType?.(\n 'navigation',\n )[0] as PerformanceNavigationTiming;\n\n return !!navigationEntry?.serverTiming?.some(\n (entry) => entry.name === '_sfapi_proxy',\n );\n } catch (e) {\n return false;\n }\n}\n\n/**\n * The `<ShopifyProvider/>` component enables use of the `useShop()` hook. The component should wrap your app.\n */\nexport function ShopifyProvider({\n children,\n ...shopifyConfig\n}: ShopifyProviderProps): JSX.Element {\n if (\n !shopifyConfig.countryIsoCode ||\n !shopifyConfig.languageIsoCode ||\n !shopifyConfig.storeDomain ||\n !shopifyConfig.storefrontToken ||\n !shopifyConfig.storefrontApiVersion\n ) {\n throw new Error(\n `Please provide the necessary props to '<ShopifyProvider/>'`,\n );\n }\n\n if (shopifyConfig.storefrontApiVersion !== SFAPI_VERSION) {\n console.warn(\n `<ShopifyProvider/>: This version of Hydrogen React is built for Shopify's Storefront API version ${SFAPI_VERSION}, but it looks like you're using version ${shopifyConfig.storefrontApiVersion}. There may be issues or bugs if you use a mismatched version of Hydrogen React and the Storefront API.`,\n );\n }\n\n const finalConfig = useMemo<ShopifyContextValue>(() => {\n const sameDomainForStorefrontApi =\n shopifyConfig.sameDomainForStorefrontApi ?? isSfapiProxyEnabled();\n\n function getShopifyDomain(overrideProps?: {storeDomain?: string}): string {\n const domain = overrideProps?.storeDomain ?? shopifyConfig.storeDomain;\n return domain.includes('://') ? domain : `https://${domain}`;\n }\n\n return {\n ...shopifyConfig,\n sameDomainForStorefrontApi,\n getPublicTokenHeaders(overrideProps): Record<string, string> {\n return getPublicTokenHeadersRaw(\n overrideProps.contentType,\n shopifyConfig.storefrontApiVersion,\n overrideProps.storefrontToken ?? shopifyConfig.storefrontToken,\n );\n },\n getShopifyDomain,\n getStorefrontApiUrl(overrideProps): string {\n const finalDomainUrl =\n sameDomainForStorefrontApi && typeof window !== 'undefined'\n ? window.location.origin\n : getShopifyDomain({\n storeDomain:\n overrideProps?.storeDomain ?? shopifyConfig.storeDomain,\n });\n\n return `${finalDomainUrl}${\n finalDomainUrl.endsWith('/') ? '' : '/'\n }api/${\n overrideProps?.storefrontApiVersion ??\n shopifyConfig.storefrontApiVersion\n }/graphql.json`;\n },\n };\n }, [shopifyConfig]);\n\n return (\n <ShopifyContext.Provider value={finalConfig}>\n {children}\n </ShopifyContext.Provider>\n );\n}\n\n/**\n * Provides access to the `shopifyConfig` prop of `<ShopifyProvider/>`. Must be a descendent of `<ShopifyProvider/>`.\n */\nexport function useShop(): ShopifyContextValue {\n const shopContext = useContext(ShopifyContext);\n if (!shopContext) {\n throw new Error(`'useShop()' must be a descendent of <ShopifyProvider/>`);\n }\n return shopContext;\n}\n\nexport interface ShopifyProviderBase {\n /** The globally-unique identifier for the Shop */\n storefrontId?: string;\n /** The full domain of your Shopify storefront URL (eg: the complete string of `{subdomain}.myshopify.com`). */\n storeDomain: string;\n /** The Storefront API public access token. Refer to the [authentication](https://shopify.dev/api/storefront#authentication) documentation for more details. */\n storefrontToken: string;\n /** The Storefront API version. This should almost always be the same as the version Hydrogen React was built for. Learn more about Shopify [API versioning](https://shopify.dev/api/usage/versioning) for more details. */\n storefrontApiVersion: string;\n /**\n * The code designating a country, which generally follows ISO 3166-1 alpha-2 guidelines. If a territory doesn't have a country code value in the `CountryCode` enum, it might be considered a subdivision of another country. For example, the territories associated with Spain are represented by the country code `ES`, and the territories associated with the United States of America are represented by the country code `US`.\n */\n countryIsoCode: CountryCode;\n /**\n * `ISO 369` language codes supported by Shopify.\n */\n languageIsoCode: LanguageCode;\n /**\n * Uses the current window.location.origin for Storefront API requests.\n * This requires setting up a proxy for Storefront API requests in your domain.\n */\n sameDomainForStorefrontApi?: boolean;\n}\n\n/**\n * Shopify-specific values that are used in various Hydrogen React components and hooks.\n */\nexport interface ShopifyProviderProps extends ShopifyProviderBase {\n /** React children to render. */\n children?: ReactNode;\n}\n\nexport interface ShopifyContextValue\n extends ShopifyProviderBase,\n ShopifyContextReturn {}\n\ntype ShopifyContextReturn = {\n /**\n * Creates the fully-qualified URL to your store's GraphQL endpoint.\n *\n * By default, it will use the config you passed in when creating `<ShopifyProvider/>`. However, you can override the following settings on each invocation of `getStorefrontApiUrl({...})`:\n *\n * - `storeDomain`\n * - `storefrontApiVersion`\n */\n getStorefrontApiUrl: (props?: GetStorefrontApiUrlProps) => string;\n /**\n * Returns an object that contains headers that are needed for each query to Storefront API GraphQL endpoint. This uses the public Storefront API token.\n *\n * By default, it will use the config you passed in when creating `<ShopifyProvider/>`. However, you can override the following settings on each invocation of `getPublicTokenHeaders({...})`:\n *\n * - `contentType`\n * - `storefrontToken`\n *\n */\n getPublicTokenHeaders: (\n props: GetPublicTokenHeadersProps,\n ) => Record<string, string>;\n /**\n * Creates the fully-qualified URL to your myshopify.com domain.\n *\n * By default, it will use the config you passed in when calling `<ShopifyProvider/>`. However, you can override the following settings on each invocation of `getShopifyDomain({...})`:\n *\n * - `storeDomain`\n */\n getShopifyDomain: (props?: GetShopifyDomainProps) => string;\n};\n\ntype GetStorefrontApiUrlProps = {\n /** The host name of the domain (eg: `{shop}.myshopify.com`). */\n storeDomain?: string;\n /** The Storefront API version. This should almost always be the same as the version Hydrogen-UI was built for. Learn more about Shopify [API versioning](https://shopify.dev/api/usage/versioning) for more details. */\n storefrontApiVersion?: string;\n};\n\ntype GetPublicTokenHeadersProps = {\n /**\n * Customizes which `\"content-type\"` header is added when using `getPrivateTokenHeaders()` and `getPublicTokenHeaders()`. When fetching with a `JSON.stringify()`-ed `body`, use `\"json\"`. When fetching with a `body` that is a plain string, use `\"graphql\"`. Defaults to `\"json\"`\n */\n contentType: 'json' | 'graphql';\n /** The Storefront API access token. Refer to the [authentication](https://shopify.dev/api/storefront#authentication) documentation for more details. */\n storefrontToken?: string;\n};\n\ntype GetShopifyDomainProps = {storeDomain?: string};\n"],"names":[],"mappings":";;;;AAKO,MAAM,wBAA6C;AAAA,EACxD,aAAa;AAAA,EACb,iBAAiB;AAAA,EACjB,sBAAsB;AAAA,EACtB,gBAAgB;AAAA,EAChB,iBAAiB;AAAA,EACjB,sBAAsB;AACpB,WAAO;AAAA,EACT;AAAA,EACA,wBAAwB;AACtB,WAAO,CAAA;AAAA,EACT;AAAA,EACA,mBAAmB;AACjB,WAAO;AAAA,EACT;AACF;AAEA,MAAM,iBAAiB;AAAA,EACrB;AACF;AAOA,SAAS,sBAAsB;;AAC7B,MAAI,OAAO,WAAW,YAAa,QAAO;AAE1C,MAAI;AACF,UAAM,mBAAkB,kBAAO,gBAAP,mBAAoB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e,UAAf,EAAwB,OAAO,aAC7B,UACH;AAEJ;AAKO,SAAS,UAA+B;AAC7C,QAAM,cAAc,WAAW,cAAc;AAC7C,MAAI,CAAC,aAAa;AAChB,UAAM,IAAI,MAAM,wDAAwD;AAAA,EAC1E;AACA,SAAO;AACT;"}
1
+ {"version":3,"file":"ShopifyProvider.mjs","sources":["../../src/ShopifyProvider.tsx"],"sourcesContent":["import {createContext, useContext, useMemo, type ReactNode} from 'react';\nimport type {LanguageCode, CountryCode} from './storefront-api-types.js';\nimport {SFAPI_VERSION} from './storefront-api-constants.js';\nimport {getPublicTokenHeadersRaw} from './storefront-client.js';\n\nexport const defaultShopifyContext: ShopifyContextValue = {\n storeDomain: 'test',\n storefrontToken: 'abc123',\n storefrontApiVersion: SFAPI_VERSION,\n countryIsoCode: 'US',\n languageIsoCode: 'EN',\n getStorefrontApiUrl() {\n return '';\n },\n getPublicTokenHeaders() {\n return {};\n },\n getShopifyDomain() {\n return '';\n },\n};\n\nconst ShopifyContext = createContext<ShopifyContextValue>(\n defaultShopifyContext,\n);\n\n/**\n * Hydrogen server sets this server timing key when the SFAPI proxy is enabled.\n * Read it automatically in the browser for apps using frontend cart in full-stack Hydrogen,\n * but don't export this utility yet since we don't want to make this a public convention.\n */\nfunction isSfapiProxyEnabled() {\n if (typeof window === 'undefined') return false;\n\n try {\n const navigationEntry = window.performance?.getEntriesByType?.(\n 'navigation',\n )[0] as PerformanceNavigationTiming;\n\n return !!navigationEntry?.serverTiming?.some(\n (entry) => entry.name === '_sfapi_proxy',\n );\n } catch (e) {\n return false;\n }\n}\n\n/**\n * The `<ShopifyProvider/>` component enables use of the `useShop()` hook. The component should wrap your app.\n */\nexport function ShopifyProvider({\n children,\n ...shopifyConfig\n}: ShopifyProviderProps): JSX.Element {\n if (\n !shopifyConfig.countryIsoCode ||\n !shopifyConfig.languageIsoCode ||\n !shopifyConfig.storeDomain ||\n !shopifyConfig.storefrontToken ||\n !shopifyConfig.storefrontApiVersion\n ) {\n throw new Error(\n `Please provide the necessary props to '<ShopifyProvider/>'`,\n );\n }\n\n if (shopifyConfig.storefrontApiVersion !== SFAPI_VERSION) {\n console.warn(\n `<ShopifyProvider/>: This version of Hydrogen React is built for Shopify's Storefront API version ${SFAPI_VERSION}, but it looks like you're using version ${shopifyConfig.storefrontApiVersion}. There may be issues or bugs if you use a mismatched version of Hydrogen React and the Storefront API.`,\n );\n }\n\n const finalConfig = useMemo<ShopifyContextValue>(() => {\n const sameDomainForStorefrontApi =\n shopifyConfig.sameDomainForStorefrontApi ?? isSfapiProxyEnabled();\n\n function getShopifyDomain(overrideProps?: {storeDomain?: string}): string {\n const domain = overrideProps?.storeDomain ?? shopifyConfig.storeDomain;\n return domain.includes('://') ? domain : `https://${domain}`;\n }\n\n return {\n ...shopifyConfig,\n sameDomainForStorefrontApi,\n getPublicTokenHeaders(overrideProps): Record<string, string> {\n return getPublicTokenHeadersRaw(\n overrideProps.contentType,\n shopifyConfig.storefrontApiVersion,\n overrideProps.storefrontToken ?? shopifyConfig.storefrontToken,\n );\n },\n getShopifyDomain,\n getStorefrontApiUrl(overrideProps): string {\n const finalDomainUrl =\n sameDomainForStorefrontApi && typeof window !== 'undefined'\n ? window.location.origin\n : getShopifyDomain({\n storeDomain:\n overrideProps?.storeDomain ?? shopifyConfig.storeDomain,\n });\n\n return `${finalDomainUrl}${\n finalDomainUrl.endsWith('/') ? '' : '/'\n }api/${\n overrideProps?.storefrontApiVersion ??\n shopifyConfig.storefrontApiVersion\n }/graphql.json`;\n },\n };\n }, [shopifyConfig]);\n\n return (\n <ShopifyContext.Provider value={finalConfig}>\n {children}\n </ShopifyContext.Provider>\n );\n}\n\n/**\n * Provides access to the `shopifyConfig` prop of `<ShopifyProvider/>`. Must be a descendent of `<ShopifyProvider/>`.\n */\nexport function useShop(): ShopifyContextValue {\n const shopContext = useContext(ShopifyContext);\n if (!shopContext) {\n throw new Error(`'useShop()' must be a descendent of <ShopifyProvider/>`);\n }\n return shopContext;\n}\n\nexport interface ShopifyProviderBase {\n /** The globally-unique identifier for the Shop */\n storefrontId?: string;\n /** The full domain of your Shopify storefront URL (eg: the complete string of `{subdomain}.myshopify.com`). */\n storeDomain: string;\n /** The Storefront API public access token. Refer to the [authentication](https://shopify.dev/api/storefront#authentication) documentation for more details. */\n storefrontToken: string;\n /** The Storefront API version. This should almost always be the same as the version Hydrogen React was built for. Learn more about Shopify [API versioning](https://shopify.dev/api/usage/versioning) for more details. */\n storefrontApiVersion: string;\n /**\n * The code designating a country, which generally follows ISO 3166-1 alpha-2 guidelines. If a territory doesn't have a country code value in the `CountryCode` enum, it might be considered a subdivision of another country. For example, the territories associated with Spain are represented by the country code `ES`, and the territories associated with the United States of America are represented by the country code `US`.\n */\n countryIsoCode: CountryCode;\n /**\n * `ISO 369` language codes supported by Shopify.\n */\n languageIsoCode: LanguageCode;\n /**\n * Uses the current window.location.origin for Storefront API requests.\n * This requires setting up a proxy for Storefront API requests in your domain.\n */\n sameDomainForStorefrontApi?: boolean;\n}\n\n/**\n * Shopify-specific values that are used in various Hydrogen React components and hooks.\n */\nexport interface ShopifyProviderProps extends ShopifyProviderBase {\n /** React children to render. */\n children?: ReactNode;\n}\n\nexport interface ShopifyContextValue\n extends ShopifyProviderBase, ShopifyContextReturn {}\n\ntype ShopifyContextReturn = {\n /**\n * Creates the fully-qualified URL to your store's GraphQL endpoint.\n *\n * By default, it will use the config you passed in when creating `<ShopifyProvider/>`. However, you can override the following settings on each invocation of `getStorefrontApiUrl({...})`:\n *\n * - `storeDomain`\n * - `storefrontApiVersion`\n */\n getStorefrontApiUrl: (props?: GetStorefrontApiUrlProps) => string;\n /**\n * Returns an object that contains headers that are needed for each query to Storefront API GraphQL endpoint. This uses the public Storefront API token.\n *\n * By default, it will use the config you passed in when creating `<ShopifyProvider/>`. However, you can override the following settings on each invocation of `getPublicTokenHeaders({...})`:\n *\n * - `contentType`\n * - `storefrontToken`\n *\n */\n getPublicTokenHeaders: (\n props: GetPublicTokenHeadersProps,\n ) => Record<string, string>;\n /**\n * Creates the fully-qualified URL to your myshopify.com domain.\n *\n * By default, it will use the config you passed in when calling `<ShopifyProvider/>`. However, you can override the following settings on each invocation of `getShopifyDomain({...})`:\n *\n * - `storeDomain`\n */\n getShopifyDomain: (props?: GetShopifyDomainProps) => string;\n};\n\ntype GetStorefrontApiUrlProps = {\n /** The host name of the domain (eg: `{shop}.myshopify.com`). */\n storeDomain?: string;\n /** The Storefront API version. This should almost always be the same as the version Hydrogen-UI was built for. Learn more about Shopify [API versioning](https://shopify.dev/api/usage/versioning) for more details. */\n storefrontApiVersion?: string;\n};\n\ntype GetPublicTokenHeadersProps = {\n /**\n * Customizes which `\"content-type\"` header is added when using `getPrivateTokenHeaders()` and `getPublicTokenHeaders()`. When fetching with a `JSON.stringify()`-ed `body`, use `\"json\"`. When fetching with a `body` that is a plain string, use `\"graphql\"`. Defaults to `\"json\"`\n */\n contentType: 'json' | 'graphql';\n /** The Storefront API access token. Refer to the [authentication](https://shopify.dev/api/storefront#authentication) documentation for more details. */\n storefrontToken?: string;\n};\n\ntype GetShopifyDomainProps = {storeDomain?: string};\n"],"names":[],"mappings":";;;;AAKO,MAAM,wBAA6C;AAAA,EACxD,aAAa;AAAA,EACb,iBAAiB;AAAA,EACjB,sBAAsB;AAAA,EACtB,gBAAgB;AAAA,EAChB,iBAAiB;AAAA,EACjB,sBAAsB;AACpB,WAAO;AAAA,EACT;AAAA,EACA,wBAAwB;AACtB,WAAO,CAAA;AAAA,EACT;AAAA,EACA,mBAAmB;AACjB,WAAO;AAAA,EACT;AACF;AAEA,MAAM,iBAAiB;AAAA,EACrB;AACF;AAOA,SAAS,sBAAsB;;AAC7B,MAAI,OAAO,WAAW,YAAa,QAAO;AAE1C,MAAI;AACF,UAAM,mBAAkB,kBAAO,gBAAP,mBAAoB,qBAApB;AAAA;AAAA,MACtB;AAAA,MACA;AAEF,WAAO,CAAC,GAAC,wDAAiB,iBAAjB,mBAA+B;AAAA,MACtC,CAAC,UAAU,MAAM,S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AChB,UAAM,IAAI,MAAM,wDAAwD;AAAA,EAC1E;AACA,SAAO;AACT;"}
@@ -1,7 +1,7 @@
1
1
  import { AnalyticsPageType, ShopifySalesChannel } from "./analytics-constants.mjs";
2
2
  import { schemaWrapper, addDataIf, parseGid } from "./analytics-utils.mjs";
3
3
  import { buildUUID } from "./cookies-utils.mjs";
4
- import { version } from "./packages/hydrogen-react/package.json.mjs";
4
+ import { version } from "./package.json.mjs";
5
5
  const SCHEMA_ID = "custom_storefront_customer_tracking/1.2";
6
6
  const PAGE_RENDERED_EVENT_NAME = "page_rendered";
7
7
  const COLLECTION_PAGE_RENDERED_EVENT_NAME = "collection_page_rendered";
@@ -1,4 +1,4 @@
1
- const version = "2026.1.0";
1
+ const version = "2026.1.2";
2
2
  export {
3
3
  version
4
4
  };
@@ -1,5 +1,5 @@
1
- import { useMachine } from "./node_modules/@xstate/react/es/fsm.mjs";
2
- import { assign as i, createMachine as s } from "./node_modules/@xstate/fsm/es/index.mjs";
1
+ import { useMachine } from "./useMachine.mjs";
2
+ import { assign, createMachine } from "@xstate/fsm";
3
3
  import { flattenConnection } from "./flatten-connection.mjs";
4
4
  import { useCartActions } from "./useCartActions.mjs";
5
5
  import { useMemo } from "react";
@@ -7,7 +7,7 @@ function invokeCart(action, options) {
7
7
  return {
8
8
  entry: [
9
9
  ...(options == null ? void 0 : options.entryActions) || [],
10
- i({
10
+ assign({
11
11
  lastValidCart: (context) => context == null ? void 0 : context.cart
12
12
  }),
13
13
  "onCartActionEntry",
@@ -18,7 +18,7 @@ function invokeCart(action, options) {
18
18
  RESOLVE: {
19
19
  target: (options == null ? void 0 : options.resolveTarget) || "idle",
20
20
  actions: [
21
- i({
21
+ assign({
22
22
  prevCart: (context) => context == null ? void 0 : context.lastValidCart,
23
23
  cart: (_, event) => {
24
24
  var _a;
@@ -36,7 +36,7 @@ function invokeCart(action, options) {
36
36
  ERROR: {
37
37
  target: (options == null ? void 0 : options.errorTarget) || "error",
38
38
  actions: [
39
- i({
39
+ assign({
40
40
  prevCart: (context) => context == null ? void 0 : context.lastValidCart,
41
41
  cart: (context) => context == null ? void 0 : context.lastValidCart,
42
42
  errors: (_, event) => {
@@ -48,7 +48,7 @@ function invokeCart(action, options) {
48
48
  },
49
49
  CART_COMPLETED: {
50
50
  target: "cartCompleted",
51
- actions: i({
51
+ actions: assign({
52
52
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
53
53
  prevCart: (_) => void 0,
54
54
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -75,7 +75,7 @@ const INITIALIZING_CART_EVENTS = {
75
75
  CART_SET: {
76
76
  target: "idle",
77
77
  actions: [
78
- i({
78
+ assign({
79
79
  rawCartResult: (_, event) => event.payload.cart,
80
80
  cart: (_, event) => cartFromGraphQL(event.payload.cart)
81
81
  })
@@ -106,7 +106,7 @@ const UPDATING_CART_EVENTS = {
106
106
  }
107
107
  };
108
108
  function createCartMachine(initialCart) {
109
- return s({
109
+ return createMachine({
110
110
  id: "Cart",
111
111
  initial: initialCart ? "idle" : "uninitialized",
112
112
  context: {
@@ -309,7 +309,7 @@ function useCartAPIStateMachine({
309
309
  }
310
310
  },
311
311
  ...onCartActionOptimisticUI && {
312
- onCartActionOptimisticUI: i((context, event) => {
312
+ onCartActionOptimisticUI: assign((context, event) => {
313
313
  return onCartActionOptimisticUI(context, event);
314
314
  })
315
315
  },
@@ -1 +1 @@
1
- {"version":3,"file":"useCartAPIStateMachine.mjs","sources":["../../src/useCartAPIStateMachine.tsx"],"sourcesContent":["import {useMachine} from '@xstate/react/fsm';\nimport {createMachine, assign, StateMachine} from '@xstate/fsm';\nimport {\n Cart,\n CartMachineActionEvent,\n CartMachineActions,\n CartMachineContext,\n CartMachineEvent,\n CartMachineFetchResultEvent,\n CartMachineTypeState,\n} from './cart-types.js';\nimport {flattenConnection} from './flatten-connection.js';\nimport {useCartActions} from './useCartActions.js';\nimport {useMemo} from 'react';\nimport {InitEvent} from '@xstate/fsm/lib/types.js';\nimport {\n CountryCode,\n Cart as CartType,\n LanguageCode,\n} from './storefront-api-types.js';\nimport type {PartialDeep} from 'type-fest';\n\nfunction invokeCart(\n action: keyof CartMachineActions,\n options?: {\n entryActions?: [keyof CartMachineActions];\n resolveTarget?: CartMachineTypeState['value'];\n errorTarget?: CartMachineTypeState['value'];\n exitActions?: [keyof CartMachineActions];\n },\n): StateMachine.Config<CartMachineContext, CartMachineEvent>['states']['on'] {\n return {\n entry: [\n ...(options?.entryActions || []),\n assign({\n lastValidCart: (context) => context?.cart,\n }),\n 'onCartActionEntry',\n 'onCartActionOptimisticUI',\n action,\n ],\n on: {\n RESOLVE: {\n target: options?.resolveTarget || 'idle',\n actions: [\n assign({\n prevCart: (context) => context?.lastValidCart,\n cart: (_, event) => event?.payload?.cart,\n rawCartResult: (_, event) => event?.payload?.rawCartResult,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n errors: (_) => undefined,\n }),\n ],\n },\n ERROR: {\n target: options?.errorTarget || 'error',\n actions: [\n assign({\n prevCart: (context) => context?.lastValidCart,\n cart: (context) => context?.lastValidCart,\n errors: (_, event) => event?.payload?.errors,\n }),\n ],\n },\n CART_COMPLETED: {\n target: 'cartCompleted',\n actions: assign({\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n prevCart: (_) => undefined,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n cart: (_) => undefined,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n lastValidCart: (_) => undefined,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n rawCartResult: (_) => undefined,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n errors: (_) => undefined,\n }),\n },\n },\n exit: ['onCartActionComplete', ...(options?.exitActions || [])],\n };\n}\n\nconst INITIALIZING_CART_EVENTS: StateMachine.Machine<\n CartMachineContext,\n CartMachineEvent,\n CartMachineTypeState\n>['config']['states']['uninitialized']['on'] = {\n CART_FETCH: {\n target: 'cartFetching',\n },\n CART_CREATE: {\n target: 'cartCreating',\n },\n CART_SET: {\n target: 'idle',\n actions: [\n assign({\n rawCartResult: (_, event) => event.payload.cart,\n cart: (_, event) => cartFromGraphQL(event.payload.cart),\n }),\n ],\n },\n};\n\nconst UPDATING_CART_EVENTS: StateMachine.Machine<\n CartMachineContext,\n CartMachineEvent,\n CartMachineTypeState\n>['config']['states']['idle']['on'] = {\n CARTLINE_ADD: {\n target: 'cartLineAdding',\n },\n CARTLINE_UPDATE: {\n target: 'cartLineUpdating',\n },\n CARTLINE_REMOVE: {\n target: 'cartLineRemoving',\n },\n NOTE_UPDATE: {\n target: 'noteUpdating',\n },\n BUYER_IDENTITY_UPDATE: {\n target: 'buyerIdentityUpdating',\n },\n CART_ATTRIBUTES_UPDATE: {\n target: 'cartAttributesUpdating',\n },\n DISCOUNT_CODES_UPDATE: {\n target: 'discountCodesUpdating',\n },\n};\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nfunction createCartMachine(\n initialCart?: PartialDeep<CartType, {recurseIntoArrays: true}>,\n) {\n return createMachine<\n CartMachineContext,\n CartMachineEvent,\n CartMachineTypeState\n >({\n id: 'Cart',\n initial: initialCart ? 'idle' : 'uninitialized',\n context: {\n cart: initialCart && cartFromGraphQL(initialCart),\n },\n states: {\n uninitialized: {\n on: INITIALIZING_CART_EVENTS,\n },\n cartCompleted: {\n on: INITIALIZING_CART_EVENTS,\n },\n initializationError: {\n on: INITIALIZING_CART_EVENTS,\n },\n idle: {\n on: {...INITIALIZING_CART_EVENTS, ...UPDATING_CART_EVENTS},\n },\n error: {\n on: {...INITIALIZING_CART_EVENTS, ...UPDATING_CART_EVENTS},\n },\n cartFetching: invokeCart('cartFetchAction', {\n errorTarget: 'initializationError',\n }),\n cartCreating: invokeCart('cartCreateAction', {\n errorTarget: 'initializationError',\n }),\n cartLineRemoving: invokeCart('cartLineRemoveAction'),\n cartLineUpdating: invokeCart('cartLineUpdateAction'),\n cartLineAdding: invokeCart('cartLineAddAction'),\n noteUpdating: invokeCart('noteUpdateAction'),\n buyerIdentityUpdating: invokeCart('buyerIdentityUpdateAction'),\n cartAttributesUpdating: invokeCart('cartAttributesUpdateAction'),\n discountCodesUpdating: invokeCart('discountCodesUpdateAction'),\n },\n });\n}\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function useCartAPIStateMachine({\n numCartLines,\n onCartActionEntry,\n onCartActionOptimisticUI,\n onCartActionComplete,\n data: cart,\n cartFragment,\n countryCode,\n languageCode,\n}: {\n /** Maximum number of cart lines to fetch. Defaults to 250 cart lines. */\n numCartLines?: number;\n /** A callback that is invoked just before a Cart API action executes. */\n onCartActionEntry?: (\n context: CartMachineContext,\n event: CartMachineActionEvent,\n ) => void;\n /** A callback that is invoked after executing the entry actions for optimistic UI changes. */\n onCartActionOptimisticUI?: (\n context: CartMachineContext,\n event: CartMachineEvent,\n ) => Partial<CartMachineContext>;\n /** A callback that is invoked after a Cart API completes. */\n onCartActionComplete?: (\n context: CartMachineContext,\n event: CartMachineFetchResultEvent,\n ) => void;\n /** An object with fields that correspond to the Storefront API's [Cart object](https://shopify.dev/api/storefront/2026-01/objects/cart). */\n data?: PartialDeep<CartType, {recurseIntoArrays: true}>;\n /** A fragment used to query the Storefront API's [Cart object](https://shopify.dev/api/storefront/2026-01/objects/cart) for all queries and mutations. A default value is used if no argument is provided. */\n cartFragment: string;\n /** The ISO country code for i18n. */\n countryCode?: CountryCode;\n /** The ISO language code for i18n. */\n languageCode?: LanguageCode;\n}) {\n const {\n cartFetch,\n cartCreate,\n cartLineAdd,\n cartLineUpdate,\n cartLineRemove,\n noteUpdate,\n buyerIdentityUpdate,\n cartAttributesUpdate,\n discountCodesUpdate,\n } = useCartActions({\n numCartLines,\n cartFragment,\n countryCode,\n languageCode,\n });\n\n const cartMachine = useMemo(() => createCartMachine(cart), [cart]);\n\n const [state, send, service] = useMachine(cartMachine, {\n actions: {\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n cartFetchAction: async (_, event) => {\n if (event.type !== 'CART_FETCH') return;\n\n const {data, errors} = await cartFetch(event?.payload?.cartId);\n const resultEvent = eventFromFetchResult(event, data?.cart, errors);\n send(resultEvent);\n },\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n cartCreateAction: async (_, event) => {\n if (event.type !== 'CART_CREATE') return;\n\n const {data, errors} = await cartCreate(event?.payload);\n const resultEvent = eventFromFetchResult(\n event,\n data?.cartCreate?.cart,\n errors,\n );\n send(resultEvent);\n },\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n cartLineAddAction: async (context, event) => {\n if (event.type !== 'CARTLINE_ADD' || !context?.cart?.id) return;\n\n const {data, errors} = await cartLineAdd(\n context.cart.id,\n event.payload.lines,\n );\n\n const resultEvent = eventFromFetchResult(\n event,\n data?.cartLinesAdd?.cart,\n errors,\n );\n\n send(resultEvent);\n },\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n cartLineUpdateAction: async (context, event) => {\n if (event.type !== 'CARTLINE_UPDATE' || !context?.cart?.id) return;\n const {data, errors} = await cartLineUpdate(\n context.cart.id,\n event.payload.lines,\n );\n\n const resultEvent = eventFromFetchResult(\n event,\n data?.cartLinesUpdate?.cart,\n errors,\n );\n\n send(resultEvent);\n },\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n cartLineRemoveAction: async (context, event) => {\n if (event.type !== 'CARTLINE_REMOVE' || !context?.cart?.id) return;\n const {data, errors} = await cartLineRemove(\n context.cart.id,\n event.payload.lines,\n );\n\n const resultEvent = eventFromFetchResult(\n event,\n data?.cartLinesRemove?.cart,\n errors,\n );\n\n send(resultEvent);\n },\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n noteUpdateAction: async (context, event) => {\n if (event.type !== 'NOTE_UPDATE' || !context?.cart?.id) return;\n const {data, errors} = await noteUpdate(\n context.cart.id,\n event.payload.note,\n );\n\n const resultEvent = eventFromFetchResult(\n event,\n data?.cartNoteUpdate?.cart,\n errors,\n );\n\n send(resultEvent);\n },\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n buyerIdentityUpdateAction: async (context, event) => {\n if (event.type !== 'BUYER_IDENTITY_UPDATE' || !context?.cart?.id)\n return;\n const {data, errors} = await buyerIdentityUpdate(\n context.cart.id,\n event.payload.buyerIdentity,\n );\n\n const resultEvent = eventFromFetchResult(\n event,\n data?.cartBuyerIdentityUpdate?.cart,\n errors,\n );\n\n send(resultEvent);\n },\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n cartAttributesUpdateAction: async (context, event) => {\n if (event.type !== 'CART_ATTRIBUTES_UPDATE' || !context?.cart?.id)\n return;\n const {data, errors} = await cartAttributesUpdate(\n context.cart.id,\n event.payload.attributes,\n );\n\n const resultEvent = eventFromFetchResult(\n event,\n data?.cartAttributesUpdate?.cart,\n errors,\n );\n\n send(resultEvent);\n },\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n discountCodesUpdateAction: async (context, event) => {\n if (event.type !== 'DISCOUNT_CODES_UPDATE' || !context?.cart?.id)\n return;\n const {data, errors} = await discountCodesUpdate(\n context.cart.id,\n event.payload.discountCodes,\n );\n const resultEvent = eventFromFetchResult(\n event,\n data?.cartDiscountCodesUpdate?.cart,\n errors,\n );\n\n send(resultEvent);\n },\n ...(onCartActionEntry && {\n onCartActionEntry: (context, event): void => {\n if (isCartActionEvent(event)) {\n onCartActionEntry(context, event);\n }\n },\n }),\n ...(onCartActionOptimisticUI && {\n onCartActionOptimisticUI: assign((context, event) => {\n return onCartActionOptimisticUI(context, event);\n }),\n }),\n ...(onCartActionComplete && {\n onCartActionComplete: (context, event): void => {\n if (isCartFetchResultEvent(event)) {\n onCartActionComplete(context, event);\n }\n },\n }),\n } as CartMachineActions,\n });\n\n return useMemo(() => [state, send, service] as const, [state, send, service]);\n}\n\nexport function cartFromGraphQL(\n cart: PartialDeep<CartType, {recurseIntoArrays: true}>,\n): Cart {\n return {\n ...cart,\n lines: flattenConnection(cart?.lines),\n note: cart.note ?? undefined,\n };\n}\n\nfunction eventFromFetchResult(\n cartActionEvent: CartMachineActionEvent,\n cart?: PartialDeep<CartType, {recurseIntoArrays: true}> | null,\n errors?: unknown,\n): CartMachineFetchResultEvent {\n if (errors) {\n return {type: 'ERROR', payload: {errors, cartActionEvent}};\n }\n\n if (!cart) {\n return {\n type: 'CART_COMPLETED',\n payload: {\n cartActionEvent,\n },\n };\n }\n\n return {\n type: 'RESOLVE',\n payload: {\n cart: cartFromGraphQL(cart),\n rawCartResult: cart,\n cartActionEvent,\n },\n };\n}\n\nfunction isCartActionEvent(\n event: CartMachineEvent | InitEvent,\n): event is CartMachineActionEvent {\n return (\n event.type === 'CART_CREATE' ||\n event.type === 'CARTLINE_ADD' ||\n event.type === 'CARTLINE_UPDATE' ||\n event.type === 'CARTLINE_REMOVE' ||\n event.type === 'NOTE_UPDATE' ||\n event.type === 'BUYER_IDENTITY_UPDATE' ||\n event.type === 'CART_ATTRIBUTES_UPDATE' ||\n event.type === 'DISCOUNT_CODES_UPDATE'\n );\n}\n\nfunction isCartFetchResultEvent(\n event: CartMachineEvent | InitEvent,\n): event is CartMachineFetchResultEvent {\n return (\n event.type === 'RESOLVE' ||\n event.type === 'ERROR' ||\n event.type === 'CART_COMPLETED'\n );\n}\n"],"names":["assign","createMachine"],"mappings":";;;;;AAsBA,SAAS,WACP,QACA,SAM2E;AAC3E,SAAO;AAAA,IACL,OAAO;AAAA,MACL,IAAI,mCAAS,iBAAgB,CAAA;AAAA,MAC7BA,EAAO;AAAA,QACL,eAAe,CAAC,YAAY,mCAAS;AAAA,MAAA,CACtC;AAAA,MACD;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAAA,IAEF,IAAI;AAAA,MACF,SAAS;AAAA,QACP,SAAQ,mCAAS,kBAAiB;AAAA,QAClC,SAAS;AAAA,UACPA,EAAO;AAAA,YACL,UAAU,CAAC,YAAY,mCAAS;AAAA,YAChC,MAAM,CAAC,GAAG,UAAA;;AAAU,0DAAO,YAAP,mBAAgB;AAAA;AAAA,YACpC,eAAe,CAAC,GAAG,UAAA;;AAAU,0D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AAA,EACF,CACD;AAED,SAAO,QAAQ,MAAM,CAAC,OAAO,MAAM,OAAO,GAAY,CAAC,OAAO,MAAM,OAAO,CAAC;AAC9E;AAEO,SAAS,gBACd,MACM;AACN,SAAO;AAAA,IACL,GAAG;AAAA,IACH,OAAO,kBAAkB,6BAAM,KAAK;AAAA,IACpC,MAAM,KAAK,QAAQ;AAAA,EAAA;AAEvB;AAEA,SAAS,qBACP,iBACA,MACA,QAC6B;AAC7B,MAAI,QAAQ;AACV,WAAO,EAAC,MAAM,SAAS,SAAS,EAAC,QAAQ,kBAAe;AAAA,EAC1D;AAEA,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,MACL,MAAM;AAAA,MACN,SAAS;AAAA,QACP;AAAA,MAAA;AAAA,IACF;AAAA,EAEJ;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,MACP,MAAM,gBAAgB,IAAI;AAAA,MAC1B,eAAe;AAAA,MACf;AAAA,IAAA;AAAA,EACF;AAEJ;AAEA,SAAS,kBACP,OACiC;AACjC,SACE,MAAM,SAAS,iBACf,MAAM,SAAS,kBACf,MAAM,SAAS,qBACf,MAAM,SAAS,qBACf,MAAM,SAAS,iBACf,MAAM,SAAS,2BACf,MAAM,SAAS,4BACf,MAAM,SAAS;AAEnB;AAEA,SAAS,uBACP,OACsC;AACtC,SACE,MAAM,SAAS,aACf,MAAM,SAAS,WACf,MAAM,SAAS;AAEnB;"}
1
+ {"version":3,"file":"useCartAPIStateMachine.mjs","sources":["../../src/useCartAPIStateMachine.tsx"],"sourcesContent":["import {useMachine} from './useMachine.js';\nimport {createMachine, assign, StateMachine} from '@xstate/fsm';\nimport {\n Cart,\n CartMachineActionEvent,\n CartMachineActions,\n CartMachineContext,\n CartMachineEvent,\n CartMachineFetchResultEvent,\n CartMachineTypeState,\n} from './cart-types.js';\nimport {flattenConnection} from './flatten-connection.js';\nimport {useCartActions} from './useCartActions.js';\nimport {useMemo} from 'react';\nimport {InitEvent} from '@xstate/fsm/lib/types.js';\nimport {\n CountryCode,\n Cart as CartType,\n LanguageCode,\n} from './storefront-api-types.js';\nimport type {PartialDeep} from 'type-fest';\n\nfunction invokeCart(\n action: keyof CartMachineActions,\n options?: {\n entryActions?: [keyof CartMachineActions];\n resolveTarget?: CartMachineTypeState['value'];\n errorTarget?: CartMachineTypeState['value'];\n exitActions?: [keyof CartMachineActions];\n },\n): StateMachine.Config<CartMachineContext, CartMachineEvent>['states']['on'] {\n return {\n entry: [\n ...(options?.entryActions || []),\n assign({\n lastValidCart: (context) => context?.cart,\n }),\n 'onCartActionEntry',\n 'onCartActionOptimisticUI',\n action,\n ],\n on: {\n RESOLVE: {\n target: options?.resolveTarget || 'idle',\n actions: [\n assign({\n prevCart: (context) => context?.lastValidCart,\n cart: (_, event) => event?.payload?.cart,\n rawCartResult: (_, event) => event?.payload?.rawCartResult,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n errors: (_) => undefined,\n }),\n ],\n },\n ERROR: {\n target: options?.errorTarget || 'error',\n actions: [\n assign({\n prevCart: (context) => context?.lastValidCart,\n cart: (context) => context?.lastValidCart,\n errors: (_, event) => event?.payload?.errors,\n }),\n ],\n },\n CART_COMPLETED: {\n target: 'cartCompleted',\n actions: assign({\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n prevCart: (_) => undefined,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n cart: (_) => undefined,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n lastValidCart: (_) => undefined,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n rawCartResult: (_) => undefined,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n errors: (_) => undefined,\n }),\n },\n },\n exit: ['onCartActionComplete', ...(options?.exitActions || [])],\n };\n}\n\nconst INITIALIZING_CART_EVENTS: StateMachine.Machine<\n CartMachineContext,\n CartMachineEvent,\n CartMachineTypeState\n>['config']['states']['uninitialized']['on'] = {\n CART_FETCH: {\n target: 'cartFetching',\n },\n CART_CREATE: {\n target: 'cartCreating',\n },\n CART_SET: {\n target: 'idle',\n actions: [\n assign({\n rawCartResult: (_, event) => event.payload.cart,\n cart: (_, event) => cartFromGraphQL(event.payload.cart),\n }),\n ],\n },\n};\n\nconst UPDATING_CART_EVENTS: StateMachine.Machine<\n CartMachineContext,\n CartMachineEvent,\n CartMachineTypeState\n>['config']['states']['idle']['on'] = {\n CARTLINE_ADD: {\n target: 'cartLineAdding',\n },\n CARTLINE_UPDATE: {\n target: 'cartLineUpdating',\n },\n CARTLINE_REMOVE: {\n target: 'cartLineRemoving',\n },\n NOTE_UPDATE: {\n target: 'noteUpdating',\n },\n BUYER_IDENTITY_UPDATE: {\n target: 'buyerIdentityUpdating',\n },\n CART_ATTRIBUTES_UPDATE: {\n target: 'cartAttributesUpdating',\n },\n DISCOUNT_CODES_UPDATE: {\n target: 'discountCodesUpdating',\n },\n};\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nfunction createCartMachine(\n initialCart?: PartialDeep<CartType, {recurseIntoArrays: true}>,\n) {\n return createMachine<\n CartMachineContext,\n CartMachineEvent,\n CartMachineTypeState\n >({\n id: 'Cart',\n initial: initialCart ? 'idle' : 'uninitialized',\n context: {\n cart: initialCart && cartFromGraphQL(initialCart),\n },\n states: {\n uninitialized: {\n on: INITIALIZING_CART_EVENTS,\n },\n cartCompleted: {\n on: INITIALIZING_CART_EVENTS,\n },\n initializationError: {\n on: INITIALIZING_CART_EVENTS,\n },\n idle: {\n on: {...INITIALIZING_CART_EVENTS, ...UPDATING_CART_EVENTS},\n },\n error: {\n on: {...INITIALIZING_CART_EVENTS, ...UPDATING_CART_EVENTS},\n },\n cartFetching: invokeCart('cartFetchAction', {\n errorTarget: 'initializationError',\n }),\n cartCreating: invokeCart('cartCreateAction', {\n errorTarget: 'initializationError',\n }),\n cartLineRemoving: invokeCart('cartLineRemoveAction'),\n cartLineUpdating: invokeCart('cartLineUpdateAction'),\n cartLineAdding: invokeCart('cartLineAddAction'),\n noteUpdating: invokeCart('noteUpdateAction'),\n buyerIdentityUpdating: invokeCart('buyerIdentityUpdateAction'),\n cartAttributesUpdating: invokeCart('cartAttributesUpdateAction'),\n discountCodesUpdating: invokeCart('discountCodesUpdateAction'),\n },\n });\n}\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function useCartAPIStateMachine({\n numCartLines,\n onCartActionEntry,\n onCartActionOptimisticUI,\n onCartActionComplete,\n data: cart,\n cartFragment,\n countryCode,\n languageCode,\n}: {\n /** Maximum number of cart lines to fetch. Defaults to 250 cart lines. */\n numCartLines?: number;\n /** A callback that is invoked just before a Cart API action executes. */\n onCartActionEntry?: (\n context: CartMachineContext,\n event: CartMachineActionEvent,\n ) => void;\n /** A callback that is invoked after executing the entry actions for optimistic UI changes. */\n onCartActionOptimisticUI?: (\n context: CartMachineContext,\n event: CartMachineEvent,\n ) => Partial<CartMachineContext>;\n /** A callback that is invoked after a Cart API completes. */\n onCartActionComplete?: (\n context: CartMachineContext,\n event: CartMachineFetchResultEvent,\n ) => void;\n /** An object with fields that correspond to the Storefront API's [Cart object](https://shopify.dev/api/storefront/2026-01/objects/cart). */\n data?: PartialDeep<CartType, {recurseIntoArrays: true}>;\n /** A fragment used to query the Storefront API's [Cart object](https://shopify.dev/api/storefront/2026-01/objects/cart) for all queries and mutations. A default value is used if no argument is provided. */\n cartFragment: string;\n /** The ISO country code for i18n. */\n countryCode?: CountryCode;\n /** The ISO language code for i18n. */\n languageCode?: LanguageCode;\n}) {\n const {\n cartFetch,\n cartCreate,\n cartLineAdd,\n cartLineUpdate,\n cartLineRemove,\n noteUpdate,\n buyerIdentityUpdate,\n cartAttributesUpdate,\n discountCodesUpdate,\n } = useCartActions({\n numCartLines,\n cartFragment,\n countryCode,\n languageCode,\n });\n\n const cartMachine = useMemo(() => createCartMachine(cart), [cart]);\n\n const [state, send, service] = useMachine(cartMachine, {\n actions: {\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n cartFetchAction: async (_, event) => {\n if (event.type !== 'CART_FETCH') return;\n\n const {data, errors} = await cartFetch(event?.payload?.cartId);\n const resultEvent = eventFromFetchResult(event, data?.cart, errors);\n send(resultEvent);\n },\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n cartCreateAction: async (_, event) => {\n if (event.type !== 'CART_CREATE') return;\n\n const {data, errors} = await cartCreate(event?.payload);\n const resultEvent = eventFromFetchResult(\n event,\n data?.cartCreate?.cart,\n errors,\n );\n send(resultEvent);\n },\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n cartLineAddAction: async (context, event) => {\n if (event.type !== 'CARTLINE_ADD' || !context?.cart?.id) return;\n\n const {data, errors} = await cartLineAdd(\n context.cart.id,\n event.payload.lines,\n );\n\n const resultEvent = eventFromFetchResult(\n event,\n data?.cartLinesAdd?.cart,\n errors,\n );\n\n send(resultEvent);\n },\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n cartLineUpdateAction: async (context, event) => {\n if (event.type !== 'CARTLINE_UPDATE' || !context?.cart?.id) return;\n const {data, errors} = await cartLineUpdate(\n context.cart.id,\n event.payload.lines,\n );\n\n const resultEvent = eventFromFetchResult(\n event,\n data?.cartLinesUpdate?.cart,\n errors,\n );\n\n send(resultEvent);\n },\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n cartLineRemoveAction: async (context, event) => {\n if (event.type !== 'CARTLINE_REMOVE' || !context?.cart?.id) return;\n const {data, errors} = await cartLineRemove(\n context.cart.id,\n event.payload.lines,\n );\n\n const resultEvent = eventFromFetchResult(\n event,\n data?.cartLinesRemove?.cart,\n errors,\n );\n\n send(resultEvent);\n },\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n noteUpdateAction: async (context, event) => {\n if (event.type !== 'NOTE_UPDATE' || !context?.cart?.id) return;\n const {data, errors} = await noteUpdate(\n context.cart.id,\n event.payload.note,\n );\n\n const resultEvent = eventFromFetchResult(\n event,\n data?.cartNoteUpdate?.cart,\n errors,\n );\n\n send(resultEvent);\n },\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n buyerIdentityUpdateAction: async (context, event) => {\n if (event.type !== 'BUYER_IDENTITY_UPDATE' || !context?.cart?.id)\n return;\n const {data, errors} = await buyerIdentityUpdate(\n context.cart.id,\n event.payload.buyerIdentity,\n );\n\n const resultEvent = eventFromFetchResult(\n event,\n data?.cartBuyerIdentityUpdate?.cart,\n errors,\n );\n\n send(resultEvent);\n },\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n cartAttributesUpdateAction: async (context, event) => {\n if (event.type !== 'CART_ATTRIBUTES_UPDATE' || !context?.cart?.id)\n return;\n const {data, errors} = await cartAttributesUpdate(\n context.cart.id,\n event.payload.attributes,\n );\n\n const resultEvent = eventFromFetchResult(\n event,\n data?.cartAttributesUpdate?.cart,\n errors,\n );\n\n send(resultEvent);\n },\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n discountCodesUpdateAction: async (context, event) => {\n if (event.type !== 'DISCOUNT_CODES_UPDATE' || !context?.cart?.id)\n return;\n const {data, errors} = await discountCodesUpdate(\n context.cart.id,\n event.payload.discountCodes,\n );\n const resultEvent = eventFromFetchResult(\n event,\n data?.cartDiscountCodesUpdate?.cart,\n errors,\n );\n\n send(resultEvent);\n },\n ...(onCartActionEntry && {\n onCartActionEntry: (context, event): void => {\n if (isCartActionEvent(event)) {\n onCartActionEntry(context, event);\n }\n },\n }),\n ...(onCartActionOptimisticUI && {\n onCartActionOptimisticUI: assign((context, event) => {\n return onCartActionOptimisticUI(context, event);\n }),\n }),\n ...(onCartActionComplete && {\n onCartActionComplete: (context, event): void => {\n if (isCartFetchResultEvent(event)) {\n onCartActionComplete(context, event);\n }\n },\n }),\n } as CartMachineActions,\n });\n\n return useMemo(() => [state, send, service] as const, [state, send, service]);\n}\n\nexport function cartFromGraphQL(\n cart: PartialDeep<CartType, {recurseIntoArrays: true}>,\n): Cart {\n return {\n ...cart,\n lines: flattenConnection(cart?.lines),\n note: cart.note ?? undefined,\n };\n}\n\nfunction eventFromFetchResult(\n cartActionEvent: CartMachineActionEvent,\n cart?: PartialDeep<CartType, {recurseIntoArrays: true}> | null,\n errors?: unknown,\n): CartMachineFetchResultEvent {\n if (errors) {\n return {type: 'ERROR', payload: {errors, cartActionEvent}};\n }\n\n if (!cart) {\n return {\n type: 'CART_COMPLETED',\n payload: {\n cartActionEvent,\n },\n };\n }\n\n return {\n type: 'RESOLVE',\n payload: {\n cart: cartFromGraphQL(cart),\n rawCartResult: cart,\n cartActionEvent,\n },\n };\n}\n\nfunction isCartActionEvent(\n event: CartMachineEvent | InitEvent,\n): event is CartMachineActionEvent {\n return (\n event.type === 'CART_CREATE' ||\n event.type === 'CARTLINE_ADD' ||\n event.type === 'CARTLINE_UPDATE' ||\n event.type === 'CARTLINE_REMOVE' ||\n event.type === 'NOTE_UPDATE' ||\n event.type === 'BUYER_IDENTITY_UPDATE' ||\n event.type === 'CART_ATTRIBUTES_UPDATE' ||\n event.type === 'DISCOUNT_CODES_UPDATE'\n );\n}\n\nfunction isCartFetchResultEvent(\n event: CartMachineEvent | InitEvent,\n): event is CartMachineFetchResultEvent {\n return (\n event.type === 'RESOLVE' ||\n event.type === 'ERROR' ||\n event.type === 'CART_COMPLETED'\n );\n}\n"],"names":[],"mappings":";;;;;AAsBA,SAAS,WACP,QACA,SAM2E;AAC3E,SAAO;AAAA,IACL,OAAO;AAAA,MACL,IAAI,mCAAS,iBAAgB,CAAA;AAAA,MAC7B,OAAO;AAAA,QACL,eAAe,CAAC,YAAY,mCAAS;AAAA,MAAA,CACtC;AAAA,MACD;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAAA,IAEF,IAAI;AAAA,MACF,SAAS;AAAA,QACP,SAAQ,mCAAS,kBAAiB;AAAA,QAClC,SAAS;AAAA,UACP,OAAO;AAAA,YACL,UAAU,CAAC,YAAY,mCAAS;AAAA,YAChC,MAAM,CAAC,GAAG,UAAA;;AAAU,0DAAO,YAAP,mBAAgB;AAAA;AAAA,YACpC,eAAe,CAAC,GAAG,UA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A,IACF;AAAA,EACF,CACD;AAED,SAAO,QAAQ,MAAM,CAAC,OAAO,MAAM,OAAO,GAAY,CAAC,OAAO,MAAM,OAAO,CAAC;AAC9E;AAEO,SAAS,gBACd,MACM;AACN,SAAO;AAAA,IACL,GAAG;AAAA,IACH,OAAO,kBAAkB,6BAAM,KAAK;AAAA,IACpC,MAAM,KAAK,QAAQ;AAAA,EAAA;AAEvB;AAEA,SAAS,qBACP,iBACA,MACA,QAC6B;AAC7B,MAAI,QAAQ;AACV,WAAO,EAAC,MAAM,SAAS,SAAS,EAAC,QAAQ,kBAAe;AAAA,EAC1D;AAEA,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,MACL,MAAM;AAAA,MACN,SAAS;AAAA,QACP;AAAA,MAAA;AAAA,IACF;AAAA,EAEJ;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,MACP,MAAM,gBAAgB,IAAI;AAAA,MAC1B,eAAe;AAAA,MACf;AAAA,IAAA;AAAA,EACF;AAEJ;AAEA,SAAS,kBACP,OACiC;AACjC,SACE,MAAM,SAAS,iBACf,MAAM,SAAS,kBACf,MAAM,SAAS,qBACf,MAAM,SAAS,qBACf,MAAM,SAAS,iBACf,MAAM,SAAS,2BACf,MAAM,SAAS,4BACf,MAAM,SAAS;AAEnB;AAEA,SAAS,uBACP,OACsC;AACtC,SACE,MAAM,SAAS,aACf,MAAM,SAAS,WACf,MAAM,SAAS;AAEnB;"}
@@ -0,0 +1,68 @@
1
+ import { interpret, createMachine, InterpreterStatus } from "@xstate/fsm";
2
+ import { useRef, useCallback, useSyncExternalStore, useEffect, useLayoutEffect } from "react";
3
+ const useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
4
+ function useConstant(fn) {
5
+ const ref = useRef();
6
+ if (!ref.current) {
7
+ ref.current = { v: fn() };
8
+ }
9
+ return ref.current.v;
10
+ }
11
+ function getServiceState(service) {
12
+ let currentValue;
13
+ service.subscribe((state) => currentValue = state).unsubscribe();
14
+ return currentValue;
15
+ }
16
+ function useMachine(stateMachine, options) {
17
+ const persistedStateRef = useRef();
18
+ const [service, queue] = useConstant(() => {
19
+ const eventQueue = [];
20
+ const svc = interpret(
21
+ createMachine(
22
+ stateMachine.config,
23
+ options ? options : stateMachine._options
24
+ )
25
+ );
26
+ const originalSend = svc.send;
27
+ svc.send = (event) => {
28
+ if (svc.status === InterpreterStatus.NotStarted) {
29
+ eventQueue.push(event);
30
+ return;
31
+ }
32
+ originalSend(event);
33
+ persistedStateRef.current = svc.state;
34
+ };
35
+ return [svc, eventQueue];
36
+ });
37
+ useIsomorphicLayoutEffect(() => {
38
+ if (options) {
39
+ service._machine._options = options;
40
+ }
41
+ });
42
+ const getSnapshot = useCallback(() => getServiceState(service), [service]);
43
+ const subscribe = useCallback(
44
+ (handleStoreChange) => {
45
+ const { unsubscribe } = service.subscribe(handleStoreChange);
46
+ return unsubscribe;
47
+ },
48
+ [service]
49
+ );
50
+ const storeSnapshot = useSyncExternalStore(
51
+ subscribe,
52
+ getSnapshot,
53
+ getSnapshot
54
+ );
55
+ useEffect(() => {
56
+ service.start(persistedStateRef.current);
57
+ queue.forEach(service.send);
58
+ persistedStateRef.current = service.state;
59
+ return () => {
60
+ service.stop();
61
+ };
62
+ }, []);
63
+ return [storeSnapshot, service.send, service];
64
+ }
65
+ export {
66
+ useMachine
67
+ };
68
+ //# sourceMappingURL=useMachine.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMachine.mjs","sources":["../../src/useMachine.ts"],"sourcesContent":["// Inlined React binding for xstate/fsm's state machine interpreter.\n//\n// This replaces the xstate/react/fsm entrypoint, which had no official version\n// supporting both React 19 and xstate/fsm. By owning this hook, we eliminate\n// the xstate/react dependency (and its React version peer dep constraint)\n// while keeping xstate/fsm and the cart state machine definition unchanged.\n//\n// Adapted from xstate/react v3.2.1/fsm (MIT license, Stately/xstate).\n// Copyright (c) 2015 David Khourshid\nimport {\n createMachine,\n interpret,\n InterpreterStatus,\n StateMachine,\n EventObject,\n} from '@xstate/fsm';\nimport {\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n useSyncExternalStore,\n} from 'react';\n\n// useLayoutEffect in the browser (sync after DOM mutations, before paint),\n// useEffect on the server (where useLayoutEffect warns). The check runs once\n// at module evaluation time (not per-render). This matches the original\n// xstate/react behavior via use-isomorphic-layout-effect.\nconst useIsomorphicLayoutEffect =\n typeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\nfunction useConstant<T>(fn: () => T): T {\n const ref = useRef<{v: T}>();\n if (!ref.current) {\n ref.current = {v: fn()};\n }\n return ref.current.v;\n}\n\nfunction getServiceState<\n TC extends object,\n TE extends EventObject,\n TS extends {value: any; context: TC},\n>(service: StateMachine.Service<TC, TE, TS>): StateMachine.State<TC, TE, TS> {\n let currentValue!: StateMachine.State<TC, TE, TS>;\n service.subscribe((state) => (currentValue = state)).unsubscribe();\n return currentValue;\n}\n\nexport function useMachine<\n TC extends object,\n TE extends EventObject,\n TS extends {value: any; context: TC},\n>(\n stateMachine: StateMachine.Machine<TC, TE, TS>,\n options?: {actions?: StateMachine.ActionMap<TC, TE>},\n): readonly [\n StateMachine.State<TC, TE, TS>,\n StateMachine.Service<TC, TE, TS>['send'],\n StateMachine.Service<TC, TE, TS>,\n] {\n const persistedStateRef = useRef<StateMachine.State<TC, TE, TS>>();\n\n const [service, queue] = useConstant(() => {\n const eventQueue: Array<TE | TE['type']> = [];\n const svc = interpret(\n createMachine(\n stateMachine.config,\n options ? options : (stateMachine as any)._options,\n ),\n );\n const originalSend = svc.send;\n svc.send = (event: TE | TE['type']) => {\n if (svc.status === InterpreterStatus.NotStarted) {\n eventQueue.push(event);\n return;\n }\n originalSend(event);\n persistedStateRef.current = svc.state;\n };\n return [svc, eventQueue] as const;\n });\n\n // Keep action implementations in sync without re-creating the service.\n // useIsomorphicLayoutEffect ensures this runs before child effects and paint,\n // preventing a window where stale action handlers could be invoked.\n useIsomorphicLayoutEffect(() => {\n if (options) {\n (service as any)._machine._options = options;\n }\n });\n\n const getSnapshot = useCallback(() => getServiceState(service), [service]);\n\n const subscribe = useCallback(\n (handleStoreChange: () => void) => {\n const {unsubscribe} = service.subscribe(handleStoreChange);\n return unsubscribe;\n },\n [service],\n );\n\n const storeSnapshot = useSyncExternalStore(\n subscribe,\n getSnapshot,\n getSnapshot,\n );\n\n useEffect(() => {\n service.start(persistedStateRef.current as any);\n queue.forEach(service.send);\n persistedStateRef.current = service.state;\n return () => {\n service.stop();\n };\n // service and queue are stable refs from useConstant\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return [storeSnapshot, service.send, service] as const;\n}\n"],"names":[],"mappings":";;AA4BA,MAAM,4BACJ,OAAO,WAAW,cAAc,kBAAkB;AAEpD,SAAS,YAAe,IAAgB;AACtC,QAAM,MAAM,OAAA;AACZ,MAAI,CAAC,IAAI,SAAS;AAChB,QAAI,UAAU,EAAC,GAAG,GAAA,EAAG;AAAA,EACvB;AACA,SAAO,IAAI,QAAQ;AACrB;AAEA,SAAS,gBAIP,SAA2E;AAC3E,MAAI;AACJ,UAAQ,UAAU,CAAC,UAAW,eAAe,KAAM,EAAE,YAAA;AACrD,SAAO;AACT;AAEO,SAAS,WAKd,cACA,SAKA;AACA,QAAM,oBAAoB,OAAA;AAE1B,QAAM,CAAC,SAAS,KAAK,IAAI,YAAY,MAAM;AACzC,UAAM,aAAqC,CAAA;AAC3C,UAAM,MAAM;AAAA,MACV;AAAA,QACE,aAAa;AAAA,QACb,UAAU,UAAW,aAAqB;AAAA,MAAA;AAAA,IAC5C;AAEF,UAAM,eAAe,IAAI;AACzB,QAAI,OAAO,CAAC,UAA2B;AACrC,UAAI,IAAI,WAAW,kBAAkB,YAAY;AAC/C,mBAAW,KAAK,KAAK;AACrB;AAAA,MACF;AACA,mBAAa,KAAK;AAClB,wBAAkB,UAAU,IAAI;AAAA,IAClC;AACA,WAAO,CAAC,KAAK,UAAU;AAAA,EACzB,CAAC;AAKD,4BAA0B,MAAM;AAC9B,QAAI,SAAS;AACV,cAAgB,SAAS,WAAW;AAAA,IACvC;AAAA,EACF,CAAC;AAED,QAAM,cAAc,YAAY,MAAM,gBAAgB,OAAO,GAAG,CAAC,OAAO,CAAC;AAEzE,QAAM,YAAY;AAAA,IAChB,CAAC,sBAAkC;AACjC,YAAM,EAAC,YAAA,IAAe,QAAQ,UAAU,iBAAiB;AACzD,aAAO;AAAA,IACT;AAAA,IACA,CAAC,OAAO;AAAA,EAAA;AAGV,QAAM,gBAAgB;AAAA,IACpB;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAGF,YAAU,MAAM;AACd,YAAQ,MAAM,kBAAkB,OAAc;AAC9C,UAAM,QAAQ,QAAQ,IAAI;AAC1B,sBAAkB,UAAU,QAAQ;AACpC,WAAO,MAAM;AACX,cAAQ,KAAA;AAAA,IACV;AAAA,EAGF,GAAG,CAAA,CAAE;AAEL,SAAO,CAAC,eAAe,QAAQ,MAAM,OAAO;AAC9C;"}
@@ -1 +1 @@
1
- {"version":3,"file":"AddToCartButton.mjs","sources":["../../src/AddToCartButton.tsx"],"sourcesContent":["import {useCallback, useEffect, useState} from 'react';\nimport {useCart} from './CartProvider.js';\nimport {useProduct} from './ProductProvider.js';\nimport {\n BaseButton,\n type CustomBaseButtonProps,\n type BaseButtonProps,\n} from './BaseButton.js';\nimport * as React from 'react';\nimport {CartLineParentInput} from './storefront-api-types.js';\n\nexport interface AddToCartButtonPropsBase {\n /** An array of cart line attributes that belong to the item being added to the cart. */\n attributes?: {\n key: string;\n value: string;\n }[];\n /** The ID of the variant. */\n variantId?: string | null;\n /** The item quantity. */\n quantity?: number;\n /** The text that is announced by the screen reader when the item is being added to the cart. Used for accessibility purposes only and not displayed on the page. */\n accessibleAddingToCartLabel?: string;\n /** The parent line item of the item being added to the cart. Used for nested cart lines. */\n parent?: CartLineParentInput;\n /** The selling plan ID of the subscription variant */\n sellingPlanId?: string;\n}\n\nexport type AddToCartButtonProps<AsType extends React.ElementType = 'button'> =\n AddToCartButtonPropsBase & BaseButtonProps<AsType>;\n\n/**\n * The `AddToCartButton` component renders a button that adds an item to the cart when pressed.\n * It must be a descendent of the `CartProvider` component.\n */\nexport function AddToCartButton<AsType extends React.ElementType = 'button'>(\n props: AddToCartButtonProps<AsType>,\n): JSX.Element {\n const [addingItem, setAddingItem] = useState<boolean>(false);\n const {\n variantId: explicitVariantId,\n quantity = 1,\n attributes,\n sellingPlanId,\n onClick,\n children,\n accessibleAddingToCartLabel,\n parent,\n ...passthroughProps\n } = props;\n const {status, linesAdd} = useCart();\n const {selectedVariant} = useProduct();\n const variantId = explicitVariantId ?? selectedVariant?.id ?? '';\n const disabled =\n explicitVariantId === null ||\n variantId === '' ||\n selectedVariant === null ||\n addingItem ||\n // Only certain 'as' types such as 'button' contain `disabled`\n (passthroughProps as {disabled?: boolean}).disabled;\n\n useEffect(() => {\n if (addingItem && status === 'idle') {\n setAddingItem(false);\n }\n }, [status, addingItem]);\n\n const handleAddItem = useCallback(() => {\n setAddingItem(true);\n linesAdd([\n {\n quantity,\n merchandiseId: variantId || '',\n attributes,\n parent,\n sellingPlanId,\n },\n ]);\n }, [linesAdd, quantity, variantId, attributes, sellingPlanId, parent]);\n\n return (\n <>\n <BaseButton\n {...passthroughProps}\n disabled={disabled}\n onClick={onClick}\n defaultOnClick={handleAddItem}\n >\n {children}\n </BaseButton>\n {accessibleAddingToCartLabel ? (\n <p\n style={{\n position: 'absolute',\n width: '1px',\n height: '1px',\n padding: '0',\n margin: '-1px',\n overflow: 'hidden',\n clip: 'rect(0, 0, 0, 0)',\n whiteSpace: 'nowrap',\n borderWidth: '0',\n }}\n role=\"alert\"\n aria-live=\"assertive\"\n >\n {addingItem ? accessibleAddingToCartLabel : null}\n </p>\n ) : null}\n </>\n );\n}\n\n// This is only for documentation purposes, and it is not used in the code.\nexport interface AddToCartButtonPropsForDocs<\n AsType extends React.ElementType = 'button',\n> extends AddToCartButtonPropsBase,\n CustomBaseButtonProps<AsType> {}\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AAAA,QAET,uBAAa,8BAA8B;AAAA,MAAA;AAAA,IAAA,IAE5C;AAAA,EAAA,GACN;AAEJ;"}
1
+ {"version":3,"file":"AddToCartButton.mjs","sources":["../../src/AddToCartButton.tsx"],"sourcesContent":["import {useCallback, useEffect, useState} from 'react';\nimport {useCart} from './CartProvider.js';\nimport {useProduct} from './ProductProvider.js';\nimport {\n BaseButton,\n type CustomBaseButtonProps,\n type BaseButtonProps,\n} from './BaseButton.js';\nimport * as React from 'react';\nimport {CartLineParentInput} from './storefront-api-types.js';\n\nexport interface AddToCartButtonPropsBase {\n /** An array of cart line attributes that belong to the item being added to the cart. */\n attributes?: {\n key: string;\n value: string;\n }[];\n /** The ID of the variant. */\n variantId?: string | null;\n /** The item quantity. */\n quantity?: number;\n /** The text that is announced by the screen reader when the item is being added to the cart. Used for accessibility purposes only and not displayed on the page. */\n accessibleAddingToCartLabel?: string;\n /** The parent line item of the item being added to the cart. Used for nested cart lines. */\n parent?: CartLineParentInput;\n /** The selling plan ID of the subscription variant */\n sellingPlanId?: string;\n}\n\nexport type AddToCartButtonProps<AsType extends React.ElementType = 'button'> =\n AddToCartButtonPropsBase & BaseButtonProps<AsType>;\n\n/**\n * The `AddToCartButton` component renders a button that adds an item to the cart when pressed.\n * It must be a descendent of the `CartProvider` component.\n */\nexport function AddToCartButton<AsType extends React.ElementType = 'button'>(\n props: AddToCartButtonProps<AsType>,\n): JSX.Element {\n const [addingItem, setAddingItem] = useState<boolean>(false);\n const {\n variantId: explicitVariantId,\n quantity = 1,\n attributes,\n sellingPlanId,\n onClick,\n children,\n accessibleAddingToCartLabel,\n parent,\n ...passthroughProps\n } = props;\n const {status, linesAdd} = useCart();\n const {selectedVariant} = useProduct();\n const variantId = explicitVariantId ?? selectedVariant?.id ?? '';\n const disabled =\n explicitVariantId === null ||\n variantId === '' ||\n selectedVariant === null ||\n addingItem ||\n // Only certain 'as' types such as 'button' contain `disabled`\n (passthroughProps as {disabled?: boolean}).disabled;\n\n useEffect(() => {\n if (addingItem && status === 'idle') {\n setAddingItem(false);\n }\n }, [status, addingItem]);\n\n const handleAddItem = useCallback(() => {\n setAddingItem(true);\n linesAdd([\n {\n quantity,\n merchandiseId: variantId || '',\n attributes,\n parent,\n sellingPlanId,\n },\n ]);\n }, [linesAdd, quantity, variantId, attributes, sellingPlanId, parent]);\n\n return (\n <>\n <BaseButton\n {...passthroughProps}\n disabled={disabled}\n onClick={onClick}\n defaultOnClick={handleAddItem}\n >\n {children}\n </BaseButton>\n {accessibleAddingToCartLabel ? (\n <p\n style={{\n position: 'absolute',\n width: '1px',\n height: '1px',\n padding: '0',\n margin: '-1px',\n overflow: 'hidden',\n clip: 'rect(0, 0, 0, 0)',\n whiteSpace: 'nowrap',\n borderWidth: '0',\n }}\n role=\"alert\"\n aria-live=\"assertive\"\n >\n {addingItem ? accessibleAddingToCartLabel : null}\n </p>\n ) : null}\n </>\n );\n}\n\n// This is only for documentation purposes, and it is not used in the code.\nexport interface AddToCartButtonPropsForDocs<\n AsType extends React.ElementType = 'button',\n>\n extends AddToCartButtonPropsBase, CustomBaseButtonProps<AsType> {}\n"],"names":[],"mappings":";;;;;AAoCO,SAAS,gBACd,OACa;AACb,QAAM,CAAC,YAAY,aAAa,IAAI,SAAkB,KAAK;AAC3D,QAAM;AAAA,IACJ,WAAW;AAAA,IACX,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,IACD;AACJ,QAAM,EAAC,QAAQ,SAAA,IAAY,QAAA;AAC3B,QAAM,EAAC,gBAAA,IAAmB,WAAA;AAC1B,QAAM,YAAY,sBAAqB,mDAAiB,OAAM;AAC9D,QAAM,WACJ,sBAAsB,QACtB,cAAc,MACd,oBAAoB,QACpB;AAAA,EAEC,iBAA0C;AAE7C,YAAU,MAAM;AACd,QAAI,cAAc,WAAW,QAAQ;AACnC,oBAAc,KAAK;AAAA,IACrB;AAAA,EACF,GAAG,CAAC,QAAQ,UAAU,CAAC;AAEvB,QAAM,gBAAgB,YAAY,MAAM;AACtC,kBAAc,IAAI;AAClB,aAAS;AAAA,MACP;AAAA,QACE;AAAA,QACA,eAAe,aAAa;AAAA,QAC5B;AAAA,QACA;AAAA,QACA;AAAA,MAAA;AAAA,IACF,CACD;AAAA,EACH,GAAG,CAAC,UAAU,UAAU,WAAW,YAAY,eAAe,MAAM,CAAC;AAErE,SACE,qBAAA,UAAA,EACE,UAAA;AAAA,IAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACE,GAAG;AAAA,QACJ;AAAA,QACA;AAAA,QACA,gBAAgB;AAAA,QAEf;AAAA,MAAA;AAAA,IAAA;AAAA,IAEF,8BACC;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,OAAO;AAAA,UACL,UAAU;AAAA,UACV,OAAO;AAAA,UACP,QAAQ;AAAA,UACR,SAAS;AAAA,UACT,QAAQ;AAAA,UACR,UAAU;AAAA,UACV,MAAM;AAAA,UACN,YAAY;AAAA,UACZ,aAAa;AAAA,QAAA;AAAA,QAEf,MAAK;AAAA,QACL,aAAU;AAAA,QAET,uBAAa,8BAA8B;AAAA,MAAA;AAAA,IAAA,IAE5C;AAAA,EAAA,GACN;AAEJ;"}
@@ -1 +1 @@
1
- {"version":3,"file":"BuyNowButton.mjs","sources":["../../src/BuyNowButton.tsx"],"sourcesContent":["import {useEffect, useState, useCallback} from 'react';\nimport {useCart} from './CartProvider.js';\nimport {\n BaseButton,\n type BaseButtonProps,\n type CustomBaseButtonProps,\n} from './BaseButton.js';\n\ninterface BuyNowButtonPropsBase {\n /** The item quantity. Defaults to 1. */\n quantity?: number;\n /** The ID of the variant. */\n variantId: string;\n /** The selling plan ID of the subscription variant */\n sellingPlanId?: string;\n /** An array of cart line attributes that belong to the item being added to the cart. */\n attributes?: {\n key: string;\n value: string;\n }[];\n}\n\ntype BuyNowButtonProps<AsType extends React.ElementType = 'button'> =\n BuyNowButtonPropsBase & BaseButtonProps<AsType>;\n\n/**\n * The `BuyNowButton` component renders a button that adds an item to the cart and redirects the customer to checkout.\n * Must be a child of a `CartProvider` component.\n */\nexport function BuyNowButton<AsType extends React.ElementType = 'button'>(\n props: BuyNowButtonProps<AsType>,\n): JSX.Element {\n const {cartCreate, checkoutUrl} = useCart();\n const [loading, setLoading] = useState<boolean>(false);\n\n const {\n quantity,\n variantId,\n sellingPlanId,\n onClick,\n attributes,\n children,\n ...passthroughProps\n } = props;\n\n useEffect(() => {\n if (loading && checkoutUrl) {\n window.location.href = checkoutUrl;\n }\n }, [loading, checkoutUrl]);\n\n const handleBuyNow = useCallback(() => {\n setLoading(true);\n cartCreate({\n lines: [\n {\n quantity: quantity ?? 1,\n merchandiseId: variantId,\n attributes,\n sellingPlanId,\n },\n ],\n });\n }, [cartCreate, quantity, variantId, attributes, sellingPlanId]);\n\n return (\n <BaseButton\n // Only certain 'as' types such as 'button' contain `disabled`\n disabled={loading ?? (passthroughProps as {disabled?: boolean}).disabled}\n {...passthroughProps}\n onClick={onClick}\n defaultOnClick={handleBuyNow}\n >\n {children}\n </BaseButton>\n );\n}\n\n// This is only for documentation purposes, and it is not used in the code.\nexport interface BuyNowButtonPropsForDocs<\n AsType extends React.ElementType = 'button',\n> extends BuyNowButtonPropsBase,\n CustomBaseButtonProps<AsType> {}\n"],"names":[],"mappings":";;;;AA6BO,SAAS,aACd,OACa;AACb,QAAM,EAAC,YAAY,YAAA,IAAe,QAAA;AAClC,QAAM,CAAC,SAAS,UAAU,IAAI,SAAkB,KAAK;AAErD,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,IACD;AAEJ,YAAU,MAAM;AACd,QAAI,WAAW,aAAa;AAC1B,aAAO,SAAS,OAAO;AAAA,IACzB;AAAA,EACF,GAAG,CAAC,SAAS,WAAW,CAAC;AAEzB,QAAM,eAAe,YAAY,MAAM;AACrC,eAAW,IAAI;AACf,eAAW;AAAA,MACT,OAAO;AAAA,QACL;AAAA,UACE,UAAU,YAAY;AAAA,UACtB,eAAe;AAAA,UACf;AAAA,UACA;AAAA,QAAA;AAAA,MACF;AAAA,IACF,CACD;AAAA,EACH,GAAG,CAAC,YAAY,UAAU,WAAW,YAAY,aAAa,CAAC;AAE/D,SACE;AAAA,IAAC;AAAA,IAAA;AAAA,MAEC,UAAU,WAAY,iBAA0C;AAAA,MAC/D,GAAG;AAAA,MACJ;AAAA,MACA,gBAAgB;AAAA,MAEf;AAAA,IAAA;AAAA,EAAA;AAGP;"}
1
+ {"version":3,"file":"BuyNowButton.mjs","sources":["../../src/BuyNowButton.tsx"],"sourcesContent":["import {useEffect, useState, useCallback} from 'react';\nimport {useCart} from './CartProvider.js';\nimport {\n BaseButton,\n type BaseButtonProps,\n type CustomBaseButtonProps,\n} from './BaseButton.js';\n\ninterface BuyNowButtonPropsBase {\n /** The item quantity. Defaults to 1. */\n quantity?: number;\n /** The ID of the variant. */\n variantId: string;\n /** The selling plan ID of the subscription variant */\n sellingPlanId?: string;\n /** An array of cart line attributes that belong to the item being added to the cart. */\n attributes?: {\n key: string;\n value: string;\n }[];\n}\n\ntype BuyNowButtonProps<AsType extends React.ElementType = 'button'> =\n BuyNowButtonPropsBase & BaseButtonProps<AsType>;\n\n/**\n * The `BuyNowButton` component renders a button that adds an item to the cart and redirects the customer to checkout.\n * Must be a child of a `CartProvider` component.\n */\nexport function BuyNowButton<AsType extends React.ElementType = 'button'>(\n props: BuyNowButtonProps<AsType>,\n): JSX.Element {\n const {cartCreate, checkoutUrl} = useCart();\n const [loading, setLoading] = useState<boolean>(false);\n\n const {\n quantity,\n variantId,\n sellingPlanId,\n onClick,\n attributes,\n children,\n ...passthroughProps\n } = props;\n\n useEffect(() => {\n if (loading && checkoutUrl) {\n window.location.href = checkoutUrl;\n }\n }, [loading, checkoutUrl]);\n\n const handleBuyNow = useCallback(() => {\n setLoading(true);\n cartCreate({\n lines: [\n {\n quantity: quantity ?? 1,\n merchandiseId: variantId,\n attributes,\n sellingPlanId,\n },\n ],\n });\n }, [cartCreate, quantity, variantId, attributes, sellingPlanId]);\n\n return (\n <BaseButton\n // Only certain 'as' types such as 'button' contain `disabled`\n disabled={loading ?? (passthroughProps as {disabled?: boolean}).disabled}\n {...passthroughProps}\n onClick={onClick}\n defaultOnClick={handleBuyNow}\n >\n {children}\n </BaseButton>\n );\n}\n\n// This is only for documentation purposes, and it is not used in the code.\nexport interface BuyNowButtonPropsForDocs<\n AsType extends React.ElementType = 'button',\n>\n extends BuyNowButtonPropsBase, CustomBaseButtonProps<AsType> {}\n"],"names":[],"mappings":";;;;AA6BO,SAAS,aACd,OACa;AACb,QAAM,EAAC,YAAY,YAAA,IAAe,QAAA;AAClC,QAAM,CAAC,SAAS,UAAU,IAAI,SAAkB,KAAK;AAErD,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,IACD;AAEJ,YAAU,MAAM;AACd,QAAI,WAAW,aAAa;AAC1B,aAAO,SAAS,OAAO;AAAA,IACzB;AAAA,EACF,GAAG,CAAC,SAAS,WAAW,CAAC;AAEzB,QAAM,eAAe,YAAY,MAAM;AACrC,eAAW,IAAI;AACf,eAAW;AAAA,MACT,OAAO;AAAA,QACL;AAAA,UACE,UAAU,YAAY;AAAA,UACtB,eAAe;AAAA,UACf;AAAA,UACA;AAAA,QAAA;AAAA,MACF;AAAA,IACF,CACD;AAAA,EACH,GAAG,CAAC,YAAY,UAAU,WAAW,YAAY,aAAa,CAAC;AAE/D,SACE;AAAA,IAAC;AAAA,IAAA;AAAA,MAEC,UAAU,WAAY,iBAA0C;AAAA,MAC/D,GAAG;AAAA,MACJ;AAAA,MACA,gBAAgB;AAAA,MAEf;AAAA,IAAA;AAAA,EAAA;AAGP;"}
@@ -1 +1 @@
1
- {"version":3,"file":"CartCost.mjs","sources":["../../src/CartCost.tsx"],"sourcesContent":["import {Money, type MoneyPropsBase} from './Money.js';\nimport {useCart} from './CartProvider.js';\n\ninterface CartCostPropsBase {\n /** A string type that defines the type of cost needed. Valid values: `total`, `subtotal`, `tax`, or `duty`. */\n amountType?: 'total' | 'subtotal' | 'tax' | 'duty';\n /** Any `ReactNode` elements. */\n children?: React.ReactNode;\n}\n\ntype CartCostProps = Omit<React.ComponentProps<typeof Money>, 'data'> &\n CartCostPropsBase;\n\n/**\n * The `CartCost` component renders a `Money` component with the cost associated with the `amountType` prop.\n * If no `amountType` prop is specified, then it defaults to `totalAmount`.\n * Depends on `useCart()` and must be a child of `<CartProvider/>`\n */\nexport function CartCost(props: CartCostProps): JSX.Element | null {\n const {cost} = useCart();\n const {amountType = 'total', children, ...passthroughProps} = props;\n let amount;\n\n if (amountType == 'total') {\n amount = cost?.totalAmount;\n } else if (amountType == 'subtotal') {\n amount = cost?.subtotalAmount;\n } else if (amountType == 'tax') {\n amount = cost?.totalTaxAmount;\n } else if (amountType == 'duty') {\n amount = cost?.totalDutyAmount;\n }\n\n if (amount == null) {\n return null;\n }\n\n return (\n <Money {...passthroughProps} data={amount}>\n {children}\n </Money>\n );\n}\n\n// This is only for documentation purposes, and it is not used in the code.\nexport interface CartCostPropsForDocs<AsType extends React.ElementType = 'div'>\n extends Omit<MoneyPropsBase<AsType>, 'data'>,\n CartCostPropsBase {}\n"],"names":[],"mappings":";;;AAkBO,SAAS,SAAS,OAA0C;AACjE,QAAM,EAAC,KAAA,IAAQ,QAAA;AACf,QAAM,EAAC,aAAa,SAAS,UAAU,GAAG,qBAAoB;AAC9D,MAAI;AAEJ,MAAI,cAAc,SAAS;AACzB,aAAS,6BAAM;AAAA,EACjB,WAAW,cAAc,YAAY;AACnC,aAAS,6BAAM;AAAA,EACjB,WAAW,cAAc,OAAO;AAC9B,aAAS,6BAAM;AAAA,EACjB,WAAW,cAAc,QAAQ;AAC/B,aAAS,6BAAM;AAAA,EACjB;AAEA,MAAI,UAAU,MAAM;AAClB,WAAO;AAAA,EACT;AAEA,6BACG,OAAA,EAAO,GAAG,kBAAkB,MAAM,QAChC,UACH;AAEJ;"}
1
+ {"version":3,"file":"CartCost.mjs","sources":["../../src/CartCost.tsx"],"sourcesContent":["import {Money, type MoneyPropsBase} from './Money.js';\nimport {useCart} from './CartProvider.js';\n\ninterface CartCostPropsBase {\n /** A string type that defines the type of cost needed. Valid values: `total`, `subtotal`, `tax`, or `duty`. */\n amountType?: 'total' | 'subtotal' | 'tax' | 'duty';\n /** Any `ReactNode` elements. */\n children?: React.ReactNode;\n}\n\ntype CartCostProps = Omit<React.ComponentProps<typeof Money>, 'data'> &\n CartCostPropsBase;\n\n/**\n * The `CartCost` component renders a `Money` component with the cost associated with the `amountType` prop.\n * If no `amountType` prop is specified, then it defaults to `totalAmount`.\n * Depends on `useCart()` and must be a child of `<CartProvider/>`\n */\nexport function CartCost(props: CartCostProps): JSX.Element | null {\n const {cost} = useCart();\n const {amountType = 'total', children, ...passthroughProps} = props;\n let amount;\n\n if (amountType == 'total') {\n amount = cost?.totalAmount;\n } else if (amountType == 'subtotal') {\n amount = cost?.subtotalAmount;\n } else if (amountType == 'tax') {\n amount = cost?.totalTaxAmount;\n } else if (amountType == 'duty') {\n amount = cost?.totalDutyAmount;\n }\n\n if (amount == null) {\n return null;\n }\n\n return (\n <Money {...passthroughProps} data={amount}>\n {children}\n </Money>\n );\n}\n\n// This is only for documentation purposes, and it is not used in the code.\nexport interface CartCostPropsForDocs<AsType extends React.ElementType = 'div'>\n extends Omit<MoneyPropsBase<AsType>, 'data'>, CartCostPropsBase {}\n"],"names":[],"mappings":";;;AAkBO,SAAS,SAAS,OAA0C;AACjE,QAAM,EAAC,KAAA,IAAQ,QAAA;AACf,QAAM,EAAC,aAAa,SAAS,UAAU,GAAG,qBAAoB;AAC9D,MAAI;AAEJ,MAAI,cAAc,SAAS;AACzB,aAAS,6BAAM;AAAA,EACjB,WAAW,cAAc,YAAY;AACnC,aAAS,6BAAM;AAAA,EACjB,WAAW,cAAc,OAAO;AAC9B,aAAS,6BAAM;AAAA,EACjB,WAAW,cAAc,QAAQ;AAC/B,aAAS,6BAAM;AAAA,EACjB;AAEA,MAAI,UAAU,MAAM;AAClB,WAAO;AAAA,EACT;AAEA,6BACG,OAAA,EAAO,GAAG,kBAAkB,MAAM,QAChC,UACH;AAEJ;"}
@@ -1,5 +1,5 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { createContext, useContext } from "react";
2
+ import { useContext, createContext } from "react";
3
3
  const CartLineContext = createContext(null);
4
4
  function useCartLine() {
5
5
  const context = useContext(CartLineContext);
@@ -1,5 +1,5 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { useState, useRef, useEffect, useCallback, useMemo, createContext, useContext, useTransition } from "react";
2
+ import { useState, useRef, useEffect, useCallback, useMemo, useContext, useTransition, createContext } from "react";
3
3
  import { useCartAPIStateMachine } from "./useCartAPIStateMachine.mjs";
4
4
  import { CART_ID_STORAGE_KEY } from "./cart-constants.mjs";
5
5
  import { defaultCartFragment } from "./cart-queries.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"ProductPrice.mjs","sources":["../../src/ProductPrice.tsx"],"sourcesContent":["import type {\n MoneyV2,\n UnitPriceMeasurement,\n Product,\n} from './storefront-api-types.js';\nimport {Money, type MoneyProps, type MoneyPropsBase} from './Money.js';\nimport type {PartialDeep} from 'type-fest';\nimport {flattenConnection} from './flatten-connection.js';\n\nexport interface ProductPriceProps {\n /** A Storefront API [Product object](https://shopify.dev/api/storefront/reference/products/product). */\n data: PartialDeep<Product, {recurseIntoArrays: true}>;\n /** The type of price. Valid values: `regular` (default) or `compareAt`. */\n priceType?: 'regular' | 'compareAt';\n /** The type of value. Valid values: `min` (default), `max` or `unit`. */\n valueType?: 'max' | 'min' | 'unit';\n /** The ID of the variant. */\n variantId?: string;\n}\n\n/**\n * The `ProductPrice` component renders a `Money` component with the product\n * [`priceRange`](https://shopify.dev/api/storefront/reference/products/productpricerange)'s `maxVariantPrice` or `minVariantPrice`, for either the regular price or compare at price range.\n */\nexport function ProductPrice<\n ComponentGeneric extends React.ElementType = 'div',\n>(\n props: ProductPriceProps &\n Omit<MoneyProps<ComponentGeneric>, 'data' | 'measurement'>,\n): JSX.Element | null {\n const {\n priceType = 'regular',\n variantId,\n valueType = 'min',\n data: product,\n ...passthroughProps\n } = props;\n\n if (product == null) {\n throw new Error(`<ProductPrice/> requires a product as the 'data' prop`);\n }\n\n let price: Partial<MoneyV2> | undefined | null;\n let measurement: Partial<UnitPriceMeasurement> | undefined | null;\n\n const variant = variantId\n ? (flattenConnection(product?.variants ?? {}).find(\n (variant) => variant?.id === variantId,\n ) ?? null)\n : null;\n\n const variantPriceProperty =\n valueType === 'max' ? 'maxVariantPrice' : 'minVariantPrice';\n\n if (priceType === 'compareAt') {\n if (variantId && variant) {\n price = variant.compareAtPrice;\n } else {\n price = product?.compareAtPriceRange?.[variantPriceProperty];\n }\n\n let priceAsNumber: number;\n if (variantId && variant) {\n priceAsNumber = parseFloat(variant.price?.amount ?? '0');\n } else {\n priceAsNumber = parseFloat(\n product?.priceRange?.[variantPriceProperty]?.amount ?? '0',\n );\n }\n\n const compareAtPriceAsNumber = parseFloat(price?.amount ?? '0');\n\n if (priceAsNumber >= compareAtPriceAsNumber) {\n return null;\n }\n } else {\n if (variantId && variant) {\n price = variant.price;\n if (valueType === 'unit') {\n price = variant.unitPrice;\n measurement = variant.unitPriceMeasurement;\n }\n } else if (valueType === 'max') {\n price = product.priceRange?.maxVariantPrice;\n } else {\n price = product.priceRange?.minVariantPrice;\n }\n }\n\n if (!price) {\n return null;\n }\n\n if (measurement) {\n return (\n <Money {...passthroughProps} data={price} measurement={measurement} />\n );\n }\n\n return <Money {...passthroughProps} data={price} />;\n}\n\n// This is only for documentation purposes, and it is not used in the code.\nexport interface ProductPricePropsForDocs<\n AsType extends React.ElementType = 'div',\n> extends Omit<MoneyPropsBase<AsType>, 'data' | 'measurement'>,\n ProductPriceProps {}\n"],"names":["variant"],"mappings":";;;AAwBO,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;AAAA,EAExE;AAEA,SAAO,oBAAC,OAAA,EAAO,GAAG,kBAAkB,MAAM,OAAO;AACnD;"}
1
+ {"version":3,"file":"ProductPrice.mjs","sources":["../../src/ProductPrice.tsx"],"sourcesContent":["import type {\n MoneyV2,\n UnitPriceMeasurement,\n Product,\n} from './storefront-api-types.js';\nimport {Money, type MoneyProps, type MoneyPropsBase} from './Money.js';\nimport type {PartialDeep} from 'type-fest';\nimport {flattenConnection} from './flatten-connection.js';\n\nexport interface ProductPriceProps {\n /** A Storefront API [Product object](https://shopify.dev/api/storefront/reference/products/product). */\n data: PartialDeep<Product, {recurseIntoArrays: true}>;\n /** The type of price. Valid values: `regular` (default) or `compareAt`. */\n priceType?: 'regular' | 'compareAt';\n /** The type of value. Valid values: `min` (default), `max` or `unit`. */\n valueType?: 'max' | 'min' | 'unit';\n /** The ID of the variant. */\n variantId?: string;\n}\n\n/**\n * The `ProductPrice` component renders a `Money` component with the product\n * [`priceRange`](https://shopify.dev/api/storefront/reference/products/productpricerange)'s `maxVariantPrice` or `minVariantPrice`, for either the regular price or compare at price range.\n */\nexport function ProductPrice<\n ComponentGeneric extends React.ElementType = 'div',\n>(\n props: ProductPriceProps &\n Omit<MoneyProps<ComponentGeneric>, 'data' | 'measurement'>,\n): JSX.Element | null {\n const {\n priceType = 'regular',\n variantId,\n valueType = 'min',\n data: product,\n ...passthroughProps\n } = props;\n\n if (product == null) {\n throw new Error(`<ProductPrice/> requires a product as the 'data' prop`);\n }\n\n let price: Partial<MoneyV2> | undefined | null;\n let measurement: Partial<UnitPriceMeasurement> | undefined | null;\n\n const variant = variantId\n ? (flattenConnection(product?.variants ?? {}).find(\n (variant) => variant?.id === variantId,\n ) ?? null)\n : null;\n\n const variantPriceProperty =\n valueType === 'max' ? 'maxVariantPrice' : 'minVariantPrice';\n\n if (priceType === 'compareAt') {\n if (variantId && variant) {\n price = variant.compareAtPrice;\n } else {\n price = product?.compareAtPriceRange?.[variantPriceProperty];\n }\n\n let priceAsNumber: number;\n if (variantId && variant) {\n priceAsNumber = parseFloat(variant.price?.amount ?? '0');\n } else {\n priceAsNumber = parseFloat(\n product?.priceRange?.[variantPriceProperty]?.amount ?? '0',\n );\n }\n\n const compareAtPriceAsNumber = parseFloat(price?.amount ?? '0');\n\n if (priceAsNumber >= compareAtPriceAsNumber) {\n return null;\n }\n } else {\n if (variantId && variant) {\n price = variant.price;\n if (valueType === 'unit') {\n price = variant.unitPrice;\n measurement = variant.unitPriceMeasurement;\n }\n } else if (valueType === 'max') {\n price = product.priceRange?.maxVariantPrice;\n } else {\n price = product.priceRange?.minVariantPrice;\n }\n }\n\n if (!price) {\n return null;\n }\n\n if (measurement) {\n return (\n <Money {...passthroughProps} data={price} measurement={measurement} />\n );\n }\n\n return <Money {...passthroughProps} data={price} />;\n}\n\n// This is only for documentation purposes, and it is not used in the code.\nexport interface ProductPricePropsForDocs<\n AsType extends React.ElementType = 'div',\n>\n extends\n Omit<MoneyPropsBase<AsType>, 'data' | 'measurement'>,\n ProductPriceProps {}\n"],"names":["variant"],"mappings":";;;AAwBO,SAAS,aAGd,OAEoB;;AACpB,QAAM;AAAA,IACJ,YAAY;AAAA,IACZ;AAAA,IACA,YAAY;AAAA,IACZ,MAAM;AAAA,IACN,GAAG;AAAA,EAAA,IACD;AAEJ,MAAI,WAAW,MAAM;AACnB,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAEA,MAAI;AACJ,MAAI;AAEJ,QAAM,UAAU,YACX,mBAAkB,mCAAS,aAAY,CAAA,CAAE,EAAE;AAAA,IAC1C,CAACA,cAAYA,qCAAS,QAAO;AAAA,EAAA,KAC1B,OACL;AAEJ,QAAM,uBACJ,cAAc,QAAQ,oBAAoB;AAE5C,MAAI,cAAc,aAAa;AAC7B,QAAI,aAAa,SAAS;AACxB,cAAQ,QAAQ;AAAA,IAClB,OAAO;AACL,eAAQ,wCAAS,wBAAT,mBAA+B;AAAA,IACzC;AAEA,QAAI;AACJ,QAAI,aAAa,SAAS;AACxB,sBAAgB,aAAW,aAAQ,UAAR,mBAAe,WAAU,GAAG;AAAA,IACzD,OAAO;AACL,sBAAgB;AAAA,UACd,8CAAS,eAAT,mBAAsB,0BAAtB,mBAA6C,WAAU;AAAA,MAAA;AAAA,IAE3D;AAEA,UAAM,yBAAyB,YAAW,+BAAO,WAAU,GAAG;AAE9D,QAAI,iBAAiB,wBAAwB;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,OAAO;AACL,QAAI,aAAa,SAAS;AACxB,cAAQ,QAAQ;AAChB,UAAI,cAAc,QAAQ;AACxB,gBAAQ,QAAQ;AAChB,sBAAc,QAAQ;AAAA,MACxB;AAAA,IACF,WAAW,cAAc,OAAO;AAC9B,eAAQ,aAAQ,eAAR,mBAAoB;AAAA,IAC9B,OAAO;AACL,eAAQ,aAAQ,eAAR,mBAAoB;AAAA,IAC9B;AAAA,EACF;AAEA,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AAEA,MAAI,aAAa;AACf,+BACG,OAAA,EAAO,GAAG,kBAAkB,MAAM,OAAO,aAA0B;AAAA,EAExE;AAEA,SAAO,oBAAC,OAAA,EAAO,GAAG,kBAAkB,MAAM,OAAO;AACnD;"}
@@ -1,5 +1,5 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { useMemo, useState, useEffect, useCallback, createContext, useContext } from "react";
2
+ import { useMemo, useState, useEffect, useCallback, useContext, createContext } from "react";
3
3
  import { flattenConnection } from "./flatten-connection.mjs";
4
4
  const ProductOptionsContext = createContext(null);
5
5
  function ProductProvider({
@@ -1,5 +1,5 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { useMemo, createContext, useContext } from "react";
2
+ import { useMemo, useContext, createContext } from "react";
3
3
  import { SFAPI_VERSION } from "./storefront-api-constants.mjs";
4
4
  import { getPublicTokenHeadersRaw } from "./storefront-client.mjs";
5
5
  const defaultShopifyContext = {