@rebuy/rebuy-hydrogen 3.0.0-beta.2 → 3.0.0-beta.20

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 (307) hide show
  1. package/README.md +988 -16
  2. package/dist/assets/Close.d.ts +2 -0
  3. package/dist/assets/Close.d.ts.map +1 -0
  4. package/dist/components/AddToCartBtn/AddToCartBtn.d.ts +1 -1
  5. package/dist/components/AddToCartBtn/AddToCartBtn.d.ts.map +1 -1
  6. package/dist/components/AddToCartBtn/HydrogenAddToCartBtn.d.ts +1 -1
  7. package/dist/components/AddToCartBtn/HydrogenAddToCartBtn.d.ts.map +1 -1
  8. package/dist/components/AddToCartBtn/HydrogenReactAddToCartBtn.d.ts +1 -1
  9. package/dist/components/AddToCartBtn/HydrogenReactAddToCartBtn.d.ts.map +1 -1
  10. package/dist/components/AddToCartBtn/types.d.ts +5 -0
  11. package/dist/components/AddToCartBtn/types.d.ts.map +1 -1
  12. package/dist/components/ProductCard/ProductCard.d.ts +1 -1
  13. package/dist/components/ProductCard/ProductCard.d.ts.map +1 -1
  14. package/dist/components/ProductCard/defaultSettings.d.ts +3 -0
  15. package/dist/components/ProductCard/defaultSettings.d.ts.map +1 -0
  16. package/dist/components/ProductCard/index.d.ts +1 -0
  17. package/dist/components/ProductCard/index.d.ts.map +1 -1
  18. package/dist/components/ProductCard/types.d.ts +46 -0
  19. package/dist/components/ProductCard/types.d.ts.map +1 -1
  20. package/dist/components/ProductCarousel/ProductCarousel.d.ts +3 -0
  21. package/dist/components/ProductCarousel/ProductCarousel.d.ts.map +1 -0
  22. package/dist/components/ProductCarousel/index.d.ts +2 -0
  23. package/dist/components/ProductCarousel/index.d.ts.map +1 -0
  24. package/dist/components/ProductCarousel/types.d.ts +18 -0
  25. package/dist/components/ProductCarousel/types.d.ts.map +1 -0
  26. package/dist/components/ProductPrice/ProductPrice.d.ts +2 -4
  27. package/dist/components/ProductPrice/ProductPrice.d.ts.map +1 -1
  28. package/dist/components/ProductPrice/types.d.ts +23 -0
  29. package/dist/components/ProductPrice/types.d.ts.map +1 -0
  30. package/dist/components/QuantityInput/QuantityInput.d.ts +3 -0
  31. package/dist/components/QuantityInput/QuantityInput.d.ts.map +1 -0
  32. package/dist/components/QuantityInput/index.d.ts +3 -0
  33. package/dist/components/QuantityInput/index.d.ts.map +1 -0
  34. package/dist/components/QuantityInput/types.d.ts +7 -0
  35. package/dist/components/QuantityInput/types.d.ts.map +1 -0
  36. package/dist/components/RebuyLink/RebuyLink.d.ts +3 -0
  37. package/dist/components/RebuyLink/RebuyLink.d.ts.map +1 -0
  38. package/dist/components/RebuyLink/index.d.ts +2 -0
  39. package/dist/components/RebuyLink/index.d.ts.map +1 -0
  40. package/dist/components/RebuyLink/types.d.ts +10 -0
  41. package/dist/components/RebuyLink/types.d.ts.map +1 -0
  42. package/dist/components/Timer/Timer.d.ts +3 -0
  43. package/dist/components/Timer/Timer.d.ts.map +1 -0
  44. package/dist/components/Timer/index.d.ts +3 -0
  45. package/dist/components/Timer/index.d.ts.map +1 -0
  46. package/dist/components/Timer/types.d.ts +20 -0
  47. package/dist/components/Timer/types.d.ts.map +1 -0
  48. package/dist/components/Title/Title.d.ts +1 -1
  49. package/dist/components/Title/Title.d.ts.map +1 -1
  50. package/dist/components/Title/types.d.ts +1 -0
  51. package/dist/components/Title/types.d.ts.map +1 -1
  52. package/dist/components/VariantSelect/VariantSelect.d.ts +1 -1
  53. package/dist/components/VariantSelect/VariantSelect.d.ts.map +1 -1
  54. package/dist/components/VariantSelect/types.d.ts +2 -0
  55. package/dist/components/VariantSelect/types.d.ts.map +1 -1
  56. package/dist/constants/api.d.ts +2 -0
  57. package/dist/constants/api.d.ts.map +1 -0
  58. package/dist/constants/debug.d.ts +28 -0
  59. package/dist/constants/debug.d.ts.map +1 -0
  60. package/dist/context/RebuyConfigContext.d.ts +23 -0
  61. package/dist/context/RebuyConfigContext.d.ts.map +1 -0
  62. package/dist/context/RebuyWidgetContext.d.ts +7 -0
  63. package/dist/context/RebuyWidgetContext.d.ts.map +1 -0
  64. package/dist/hooks/titleLevel.d.ts.map +1 -1
  65. package/dist/hooks/useBFCacheReset.d.ts +7 -0
  66. package/dist/hooks/useBFCacheReset.d.ts.map +1 -0
  67. package/dist/hooks/useBreakpoint.d.ts +5 -0
  68. package/dist/hooks/useBreakpoint.d.ts.map +1 -0
  69. package/dist/hooks/usePopupTrigger.d.ts +3 -0
  70. package/dist/hooks/usePopupTrigger.d.ts.map +1 -0
  71. package/dist/index.css +2680 -99
  72. package/dist/index.css.map +4 -4
  73. package/dist/index.d.ts +9 -0
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +9756 -1461
  76. package/dist/index.js.map +4 -4
  77. package/dist/index.mjs +9768 -1482
  78. package/dist/index.mjs.map +4 -4
  79. package/dist/providers/RebuyHydrogenContextProvider.d.ts +1 -1
  80. package/dist/providers/RebuyHydrogenContextProvider.d.ts.map +1 -1
  81. package/dist/providers/RebuyHydrogenReactContextProvider.d.ts +6 -1
  82. package/dist/providers/RebuyHydrogenReactContextProvider.d.ts.map +1 -1
  83. package/dist/providers/types.d.ts +29 -14
  84. package/dist/providers/types.d.ts.map +1 -1
  85. package/dist/queries/cart.queries.d.ts +4 -4
  86. package/dist/queries/cart.queries.d.ts.map +1 -1
  87. package/dist/smart-cart/RebuySmartCart.d.ts +10 -0
  88. package/dist/smart-cart/RebuySmartCart.d.ts.map +1 -0
  89. package/dist/smart-cart/components/AnnouncementBar/AnnouncementBar.d.ts +10 -0
  90. package/dist/smart-cart/components/AnnouncementBar/AnnouncementBar.d.ts.map +1 -0
  91. package/dist/smart-cart/components/CartItem/CartItem.d.ts +7 -0
  92. package/dist/smart-cart/components/CartItem/CartItem.d.ts.map +1 -0
  93. package/dist/smart-cart/components/CartItemList/CartItemList.d.ts +10 -0
  94. package/dist/smart-cart/components/CartItemList/CartItemList.d.ts.map +1 -0
  95. package/dist/smart-cart/components/CartNoteInput/CartNoteInput.d.ts +10 -0
  96. package/dist/smart-cart/components/CartNoteInput/CartNoteInput.d.ts.map +1 -0
  97. package/dist/smart-cart/components/CartSubtotal/CartSubtotal.d.ts +11 -0
  98. package/dist/smart-cart/components/CartSubtotal/CartSubtotal.d.ts.map +1 -0
  99. package/dist/smart-cart/components/CartTitleBar/CartTitleBar.d.ts +7 -0
  100. package/dist/smart-cart/components/CartTitleBar/CartTitleBar.d.ts.map +1 -0
  101. package/dist/smart-cart/components/CheckoutArea/CheckoutArea.d.ts +10 -0
  102. package/dist/smart-cart/components/CheckoutArea/CheckoutArea.d.ts.map +1 -0
  103. package/dist/smart-cart/components/CrossSell/CrossSell.d.ts +10 -0
  104. package/dist/smart-cart/components/CrossSell/CrossSell.d.ts.map +1 -0
  105. package/dist/smart-cart/components/CustomCode/CustomCodeBlock.d.ts +21 -0
  106. package/dist/smart-cart/components/CustomCode/CustomCodeBlock.d.ts.map +1 -0
  107. package/dist/smart-cart/components/DebugPanel/DebugPanel.d.ts +13 -0
  108. package/dist/smart-cart/components/DebugPanel/DebugPanel.d.ts.map +1 -0
  109. package/dist/smart-cart/components/DebugPanel/index.d.ts +11 -0
  110. package/dist/smart-cart/components/DebugPanel/index.d.ts.map +1 -0
  111. package/dist/smart-cart/components/DiscountCodeInput/DiscountCodeInput.d.ts +10 -0
  112. package/dist/smart-cart/components/DiscountCodeInput/DiscountCodeInput.d.ts.map +1 -0
  113. package/dist/smart-cart/components/EmptyCart/EmptyCart.d.ts +3 -0
  114. package/dist/smart-cart/components/EmptyCart/EmptyCart.d.ts.map +1 -0
  115. package/dist/smart-cart/components/LoginButton/LoginButton.d.ts +3 -0
  116. package/dist/smart-cart/components/LoginButton/LoginButton.d.ts.map +1 -0
  117. package/dist/smart-cart/components/ScreenReaderText/ScreenReaderText.d.ts +8 -0
  118. package/dist/smart-cart/components/ScreenReaderText/ScreenReaderText.d.ts.map +1 -0
  119. package/dist/smart-cart/components/SmartCartApp/SmartCartApp.d.ts +20 -0
  120. package/dist/smart-cart/components/SmartCartApp/SmartCartApp.d.ts.map +1 -0
  121. package/dist/smart-cart/components/SmartCartContainer/SmartCartContainer.d.ts +8 -0
  122. package/dist/smart-cart/components/SmartCartContainer/SmartCartContainer.d.ts.map +1 -0
  123. package/dist/smart-cart/components/TieredProgressBar/Icons.d.ts +5 -0
  124. package/dist/smart-cart/components/TieredProgressBar/Icons.d.ts.map +1 -0
  125. package/dist/smart-cart/components/TieredProgressBar/TPBGiftItem.d.ts +21 -0
  126. package/dist/smart-cart/components/TieredProgressBar/TPBGiftItem.d.ts.map +1 -0
  127. package/dist/smart-cart/components/TieredProgressBar/TieredProgressBar.d.ts +11 -0
  128. package/dist/smart-cart/components/TieredProgressBar/TieredProgressBar.d.ts.map +1 -0
  129. package/dist/smart-cart/components/TieredProgressBar/progressBarUtils.d.ts +173 -0
  130. package/dist/smart-cart/components/TieredProgressBar/progressBarUtils.d.ts.map +1 -0
  131. package/dist/smart-cart/components/TieredProgressBar/types.d.ts +261 -0
  132. package/dist/smart-cart/components/TieredProgressBar/types.d.ts.map +1 -0
  133. package/dist/smart-cart/components/_Layouts/AnchorSlot.d.ts +13 -0
  134. package/dist/smart-cart/components/_Layouts/AnchorSlot.d.ts.map +1 -0
  135. package/dist/smart-cart/components/_Layouts/DoubleColumnLayout.d.ts +9 -0
  136. package/dist/smart-cart/components/_Layouts/DoubleColumnLayout.d.ts.map +1 -0
  137. package/dist/smart-cart/components/_Layouts/SingleColumnLayout.d.ts +8 -0
  138. package/dist/smart-cart/components/_Layouts/SingleColumnLayout.d.ts.map +1 -0
  139. package/dist/smart-cart/components/componentRegistry.d.ts +3 -0
  140. package/dist/smart-cart/components/componentRegistry.d.ts.map +1 -0
  141. package/dist/smart-cart/constants.d.ts +58 -0
  142. package/dist/smart-cart/constants.d.ts.map +1 -0
  143. package/dist/smart-cart/context/SmartCartContext.d.ts +62 -0
  144. package/dist/smart-cart/context/SmartCartContext.d.ts.map +1 -0
  145. package/dist/smart-cart/context/StorefrontCartContext.d.ts +32 -0
  146. package/dist/smart-cart/context/StorefrontCartContext.d.ts.map +1 -0
  147. package/dist/smart-cart/hooks/useCartItemFeatures.d.ts +84 -0
  148. package/dist/smart-cart/hooks/useCartItemFeatures.d.ts.map +1 -0
  149. package/dist/smart-cart/hooks/useDiscountManager.d.ts +28 -0
  150. package/dist/smart-cart/hooks/useDiscountManager.d.ts.map +1 -0
  151. package/dist/smart-cart/hooks/useGeolocation.d.ts +12 -0
  152. package/dist/smart-cart/hooks/useGeolocation.d.ts.map +1 -0
  153. package/dist/smart-cart/hooks/useIsScrolled.d.ts +14 -0
  154. package/dist/smart-cart/hooks/useIsScrolled.d.ts.map +1 -0
  155. package/dist/smart-cart/hooks/useSmartCartApps.d.ts +17 -0
  156. package/dist/smart-cart/hooks/useSmartCartApps.d.ts.map +1 -0
  157. package/dist/smart-cart/store/tieredProgressBarStore.d.ts +76 -0
  158. package/dist/smart-cart/store/tieredProgressBarStore.d.ts.map +1 -0
  159. package/dist/smart-cart/types/rebuy-storefront-cart.d.ts +142 -0
  160. package/dist/smart-cart/types/rebuy-storefront-cart.d.ts.map +1 -0
  161. package/dist/smart-cart/types/rebuy.d.ts +15 -0
  162. package/dist/smart-cart/types/rebuy.d.ts.map +1 -0
  163. package/dist/smart-cart/types/shop.d.ts +26 -0
  164. package/dist/smart-cart/types/shop.d.ts.map +1 -0
  165. package/dist/smart-cart/types/smart-cart-app.d.ts +103 -0
  166. package/dist/smart-cart/types/smart-cart-app.d.ts.map +1 -0
  167. package/dist/smart-cart/types/smart-cart-component.d.ts +1350 -0
  168. package/dist/smart-cart/types/smart-cart-component.d.ts.map +1 -0
  169. package/dist/smart-cart/types/smart-cart.d.ts +82 -0
  170. package/dist/smart-cart/types/smart-cart.d.ts.map +1 -0
  171. package/dist/smart-cart/utils/cartItemUtils.d.ts +292 -0
  172. package/dist/smart-cart/utils/cartItemUtils.d.ts.map +1 -0
  173. package/dist/smart-cart/utils/debugLog.d.ts +77 -0
  174. package/dist/smart-cart/utils/debugLog.d.ts.map +1 -0
  175. package/dist/smart-cart/utils/debugStyles.d.ts +3342 -0
  176. package/dist/smart-cart/utils/debugStyles.d.ts.map +1 -0
  177. package/dist/smart-cart/utils/executeScriptsInContainer.d.ts +14 -0
  178. package/dist/smart-cart/utils/executeScriptsInContainer.d.ts.map +1 -0
  179. package/dist/smart-cart/utils/imageUtils.d.ts +2 -0
  180. package/dist/smart-cart/utils/imageUtils.d.ts.map +1 -0
  181. package/dist/smart-cart/utils/mapHydrogenCartToStorefrontCartData.d.ts +14 -0
  182. package/dist/smart-cart/utils/mapHydrogenCartToStorefrontCartData.d.ts.map +1 -0
  183. package/dist/smart-cart/utils/moneyUtils.d.ts +24 -0
  184. package/dist/smart-cart/utils/moneyUtils.d.ts.map +1 -0
  185. package/dist/smart-cart/utils/safeJsonParse.d.ts +2 -0
  186. package/dist/smart-cart/utils/safeJsonParse.d.ts.map +1 -0
  187. package/dist/types/common.d.ts +16 -0
  188. package/dist/types/common.d.ts.map +1 -1
  189. package/dist/types/rebuyCustom.d.ts +133 -17
  190. package/dist/types/rebuyCustom.d.ts.map +1 -1
  191. package/dist/types/shopify.d.ts +1 -2
  192. package/dist/types/shopify.d.ts.map +1 -1
  193. package/dist/types/widgets.d.ts +20078 -7
  194. package/dist/types/widgets.d.ts.map +1 -1
  195. package/dist/utils/convertToRebuyProduct.d.ts.map +1 -1
  196. package/dist/utils/createContextParameters.d.ts +1 -1
  197. package/dist/utils/createContextParameters.d.ts.map +1 -1
  198. package/dist/utils/filterContextUtils.d.ts +3 -0
  199. package/dist/utils/filterContextUtils.d.ts.map +1 -0
  200. package/dist/utils/getEncodedAttributes.d.ts.map +1 -1
  201. package/dist/utils/getRebuyConfig.d.ts +1 -1
  202. package/dist/utils/getRebuyConfig.d.ts.map +1 -1
  203. package/dist/utils/nonceManager.d.ts +10 -0
  204. package/dist/utils/nonceManager.d.ts.map +1 -0
  205. package/dist/utils/theme.d.ts +20 -0
  206. package/dist/utils/theme.d.ts.map +1 -0
  207. package/dist/widgetContainer/RebuyWidgetContainer.d.ts +1 -1
  208. package/dist/widgetContainer/RebuyWidgetContainer.d.ts.map +1 -1
  209. package/dist/widgets/RebuyCompleteTheLook/RebuyCompleteTheLook.d.ts.map +1 -1
  210. package/dist/widgets/RebuyDynamicBundleProducts/BundleImages.d.ts.map +1 -1
  211. package/dist/widgets/RebuyDynamicBundleProducts/BundlePrice.d.ts.map +1 -1
  212. package/dist/widgets/RebuyDynamicBundleProducts/BundleSelection.d.ts +1 -1
  213. package/dist/widgets/RebuyDynamicBundleProducts/BundleSelection.d.ts.map +1 -1
  214. package/dist/widgets/RebuyDynamicBundleProducts/RebuyDynamicBundleProducts.d.ts.map +1 -1
  215. package/dist/widgets/RebuyDynamicBundleProducts/Select.d.ts.map +1 -1
  216. package/dist/widgets/RebuyGiftWithPurchase/RebuyGiftWithPurchase.d.ts +11 -0
  217. package/dist/widgets/RebuyGiftWithPurchase/RebuyGiftWithPurchase.d.ts.map +1 -0
  218. package/dist/widgets/RebuyGiftWithPurchase/index.d.ts +3 -0
  219. package/dist/widgets/RebuyGiftWithPurchase/index.d.ts.map +1 -0
  220. package/dist/widgets/RebuyGiftWithPurchase/store/giftWithPurchaseStore.d.ts +31 -0
  221. package/dist/widgets/RebuyGiftWithPurchase/store/giftWithPurchaseStore.d.ts.map +1 -0
  222. package/dist/widgets/RebuyGiftWithPurchase/types.d.ts +12 -0
  223. package/dist/widgets/RebuyGiftWithPurchase/types.d.ts.map +1 -0
  224. package/dist/widgets/RebuyGiftWithPurchase/utils.d.ts +35 -0
  225. package/dist/widgets/RebuyGiftWithPurchase/utils.d.ts.map +1 -0
  226. package/dist/widgets/RebuyProductAddOns/RebuyProductAddOnCard.d.ts.map +1 -1
  227. package/dist/widgets/RebuyProductAddOns/RebuyProductAddOns.d.ts.map +1 -1
  228. package/dist/widgets/RebuyProductAddOns/types.d.ts.map +1 -1
  229. package/dist/widgets/RebuyProductRecommendations/RebuyProductRecommendations.d.ts.map +1 -1
  230. package/dist/widgets/RebuyProductViewed/RebuyProductViewed.d.ts +3 -0
  231. package/dist/widgets/RebuyProductViewed/RebuyProductViewed.d.ts.map +1 -0
  232. package/dist/widgets/RebuyProductViewed/index.d.ts +2 -0
  233. package/dist/widgets/RebuyProductViewed/index.d.ts.map +1 -0
  234. package/dist/widgets/RebuyProductViewed/types.d.ts +8 -0
  235. package/dist/widgets/RebuyProductViewed/types.d.ts.map +1 -0
  236. package/dist/widgets/RebuyRecentlyViewedProducts/RebuyRecentlyViewedProducts.d.ts +3 -0
  237. package/dist/widgets/RebuyRecentlyViewedProducts/RebuyRecentlyViewedProducts.d.ts.map +1 -0
  238. package/dist/widgets/RebuyRecentlyViewedProducts/index.d.ts +2 -0
  239. package/dist/widgets/RebuyRecentlyViewedProducts/index.d.ts.map +1 -0
  240. package/dist/widgets/RebuyRecentlyViewedProducts/types.d.ts +11 -0
  241. package/dist/widgets/RebuyRecentlyViewedProducts/types.d.ts.map +1 -0
  242. package/dist/widgets/RebuyWidget/RebuyWidget.d.ts +3 -0
  243. package/dist/widgets/RebuyWidget/RebuyWidget.d.ts.map +1 -0
  244. package/dist/widgets/RebuyWidget/WidgetContent.d.ts +3 -0
  245. package/dist/widgets/RebuyWidget/WidgetContent.d.ts.map +1 -0
  246. package/dist/widgets/RebuyWidget/index.d.ts +2 -0
  247. package/dist/widgets/RebuyWidget/index.d.ts.map +1 -0
  248. package/dist/widgets/RebuyWidget/types.d.ts +28 -0
  249. package/dist/widgets/RebuyWidget/types.d.ts.map +1 -0
  250. package/dist/zustandStores/productViewed.d.ts +9 -0
  251. package/dist/zustandStores/productViewed.d.ts.map +1 -0
  252. package/package.json +57 -41
  253. package/dist/types/rebuySmartCart.d.ts +0 -184
  254. package/dist/types/rebuySmartCart.d.ts.map +0 -1
  255. package/src/components/AddToCartBtn/AddToCartBtn.tsx +0 -45
  256. package/src/components/AddToCartBtn/HydrogenAddToCartBtn.tsx +0 -43
  257. package/src/components/AddToCartBtn/HydrogenReactAddToCartBtn.tsx +0 -35
  258. package/src/components/AddToCartBtn/index.ts +0 -1
  259. package/src/components/AddToCartBtn/types.ts +0 -27
  260. package/src/components/ProductCard/ProductCard.tsx +0 -70
  261. package/src/components/ProductCard/index.ts +0 -1
  262. package/src/components/ProductCard/types.ts +0 -10
  263. package/src/components/ProductPrice/ProductPrice.tsx +0 -49
  264. package/src/components/ProductPrice/index.ts +0 -1
  265. package/src/components/Title/Title.tsx +0 -19
  266. package/src/components/Title/index.ts +0 -1
  267. package/src/components/Title/types.ts +0 -7
  268. package/src/components/VariantSelect/VariantSelect.tsx +0 -45
  269. package/src/components/VariantSelect/index.ts +0 -1
  270. package/src/components/VariantSelect/types.ts +0 -6
  271. package/src/context/RebuyContext.tsx +0 -9
  272. package/src/hooks/titleLevel.tsx +0 -42
  273. package/src/index.ts +0 -7
  274. package/src/providers/RebuyHydrogenContextProvider.tsx +0 -112
  275. package/src/providers/RebuyHydrogenReactContextProvider.tsx +0 -192
  276. package/src/providers/types.ts +0 -58
  277. package/src/queries/cart.queries.ts +0 -467
  278. package/src/types/common.ts +0 -8
  279. package/src/types/css.d.ts +0 -11
  280. package/src/types/env.d.ts +0 -12
  281. package/src/types/rebuy.d.ts +0 -31
  282. package/src/types/rebuyCustom.ts +0 -263
  283. package/src/types/rebuySmartCart.ts +0 -188
  284. package/src/types/shopify.ts +0 -142
  285. package/src/types/widgets.ts +0 -29
  286. package/src/utils/convertToRebuyProduct.tsx +0 -319
  287. package/src/utils/createContextParameters.ts +0 -142
  288. package/src/utils/getEncodedAttributes.ts +0 -11
  289. package/src/utils/getRebuyConfig.ts +0 -31
  290. package/src/widgetContainer/RebuyWidgetContainer.tsx +0 -183
  291. package/src/widgets/RebuyCompleteTheLook/RebuyCompleteTheLook.tsx +0 -50
  292. package/src/widgets/RebuyCompleteTheLook/index.ts +0 -1
  293. package/src/widgets/RebuyCompleteTheLook/types.ts +0 -5
  294. package/src/widgets/RebuyDynamicBundleProducts/BundleImages.tsx +0 -62
  295. package/src/widgets/RebuyDynamicBundleProducts/BundlePrice.tsx +0 -93
  296. package/src/widgets/RebuyDynamicBundleProducts/BundleSelection.tsx +0 -65
  297. package/src/widgets/RebuyDynamicBundleProducts/RebuyDynamicBundleProducts.tsx +0 -118
  298. package/src/widgets/RebuyDynamicBundleProducts/Select.tsx +0 -41
  299. package/src/widgets/RebuyDynamicBundleProducts/index.ts +0 -1
  300. package/src/widgets/RebuyDynamicBundleProducts/types.ts +0 -23
  301. package/src/widgets/RebuyProductAddOns/RebuyProductAddOnCard.tsx +0 -66
  302. package/src/widgets/RebuyProductAddOns/RebuyProductAddOns.tsx +0 -218
  303. package/src/widgets/RebuyProductAddOns/index.ts +0 -1
  304. package/src/widgets/RebuyProductAddOns/types.ts +0 -24
  305. package/src/widgets/RebuyProductRecommendations/RebuyProductRecommendations.tsx +0 -50
  306. package/src/widgets/RebuyProductRecommendations/index.ts +0 -1
  307. package/src/widgets/RebuyProductRecommendations/types.ts +0 -5
package/README.md CHANGED
@@ -1,28 +1,1000 @@
1
- # Rebuy + Hydrogen Overview
1
+ # Beta Documentation: Rebuy Hydrogen 2.0
2
2
 
3
- Rebuy + Hydrogen package is a web development framework used for building Shopify custom storefronts. It includes providers, components, and tooling you need to get started so you can spend your time creating intelligent shopping experiences.
3
+ ## Overview
4
4
 
5
- ## Rebuy + Hydrogen 2
5
+ The new beta version of our Rebuy Hydrogen package is designed to work with both Hydrogen and Hydrogen React versions 2.0. We've streamlined this package to be as plug-and-play as possible, with the package handling most of the work.
6
6
 
7
- Rebuy makes it incredibly easy to bring powerful personalized product recommendations and smart search to your Shopify Hydrogen 2.0 Storefront. For more details on this, please check out our [Rebuy + Shopify Hydrogen 2.0 documentation](https://developers.rebuyengine.com/reference/rebuy-shopify-hydrogen-2).
7
+ ## Quick Reference
8
8
 
9
- ## How Rebuy + Hydrogen Works
9
+ This documentation covers:
10
10
 
11
- Rebuy + Hydrogen is a lightweight framework for creating personalized shopping experiences that are lightening fast. The framework is composed of:
11
+ - **Installation** - Setup for Hydrogen and Hydrogen React applications
12
+ - **Themed Styles** - Automatic styling integration with your Rebuy admin settings
13
+ - **Components** - WidgetContainer, product recommendations, bundles, and more
14
+ - **Smart Cart** - Advanced cart features including discount codes and subscriptions
12
15
 
13
- 1. **Providers** - these components build contextual objects that are used during network calls.
14
- 2. **Containers** - these components get personalized data from Rebuy and pass the resulting information to children components via props.
15
- 3. **Components** - these components can be used to render various merchandising UI.
16
- 4. **Events** - these components automatically track user behaviors.
16
+ ---
17
17
 
18
- ### Data Sources
18
+ # 📦 Installation Guide
19
19
 
20
- Rebuy + Hydrogen is powered by Rebuy's Data Sources, which allows for AI-powered product recommendations, custom defined rulesets, or mixture of human and computer derived output. Data Sources are created in Rebuy's App Admin, and the data source URL is used in your Hydrogen project. Separating the logic from the codebase allows non-technical team members to manage the merchandising rules without the need for costly code changes or redeployments.
20
+ ### Prerequisites
21
21
 
22
- ### User Interfaces
22
+ First, determine whether your application uses:
23
23
 
24
- Rebuy + Hydrogen uses a React container pattern to separate the data fetching logic and state management from the presentational components. As such, container components do not render user interface elements. They simply pass their own properties, as well as data received from Rebuy, to their children components for consumption. This allows you to build your own user interface with your existing components, or use Rebuy's out of the box components to get up and running quickly.
24
+ - Hydrogen only
25
+ - Both Hydrogen and Hydrogen React
25
26
 
26
- ### Getting Started
27
+ This distinction is important as different hooks/functions are used in each case. Note that if you're using Hydrogen React, Hydrogen is also being used by default. Our components will call the appropriate hooks/functions/components for Hydrogen React applications.
27
28
 
28
- To get started, please visit our [Rebuy + Shopify Hydrogen documentation](https://developers.rebuyengine.com/reference/shopify-hydrogen-getting-started).
29
+ ### Prerequisites
30
+
31
+ - "@shopify/hydrogen": ">=2025.5.0",
32
+ - If you are also using hydrogen-react along with just hydrogen: "@shopify/hydrogen-react": ">=2025.4.0"
33
+ - Smart Cart V2. Legacy Smart Carts are not supported
34
+
35
+ ### Installation Steps
36
+
37
+ 1. Install the beta version of our package from npm:
38
+
39
+ Package URL: [https://www.npmjs.com/package/@rebuy/rebuy-hydrogen](https://www.npmjs.com/package/@rebuy/rebuy-hydrogen)
40
+
41
+ 2. In your server entry file (typically `app/entry.server.tsx`), update the `createContentSecurityPolicy` to have `rebuyengine.com` in the `connectSrc`.
42
+
43
+ ```typescript
44
+ const { nonce, header, NonceProvider } = createContentSecurityPolicy({
45
+ shop: {
46
+ checkoutDomain: context.env.PUBLIC_CHECKOUT_DOMAIN,
47
+ storeDomain: context.env.PUBLIC_STORE_DOMAIN,
48
+ },
49
+ connectSrc: ['*.rebuyengine.com', 'rebuyengine.com'],
50
+ });
51
+ ```
52
+
53
+ ### For Hydrogen-only Applications
54
+
55
+ 1. Navigate to your root layout file (typically `app/root.tsx`) and add the following imports:
56
+
57
+ ```typescript
58
+ import { RebuyHydrogenContextProvider } from '@rebuy/rebuy-hydrogen';
59
+ import '@rebuy/rebuy-hydrogen/dist/index.css';
60
+ ```
61
+
62
+ 2. Place the `<RebuyHydrogenContextProvider>` component as the parent component after the body. Required props: `cart.data`, `shop` (your store's domain), and `publicStoreDomain` (e.g., "example.myshopify.com").
63
+
64
+ ```typescript
65
+ {data ? (
66
+ <RebuyHydrogenContextProvider cart={data.cart} shop="example.com" publicStoreDomain="example.myshopify.com"
67
+ >
68
+ <Analytics.Provider
69
+ cart={data.cart}
70
+ shop={data.shop}
71
+ consent={data.consent}
72
+ >
73
+ <PageLayout {...data}>
74
+ {children}
75
+ </PageLayout>
76
+ </Analytics.Provider>
77
+ </RebuyHydrogenContextProvider>
78
+ ) : (
79
+ children
80
+ )}
81
+ ```
82
+
83
+ ### For Hydrogen React Applications
84
+
85
+ 1. Navigate to your root layout file (typically `app/root.tsx`) and add the import for the CSS:
86
+
87
+ ```typescript
88
+ import '@rebuy/rebuy-hydrogen/dist/index.css';
89
+ ```
90
+
91
+ 2. Navigate to where your context providers are located and wrap the `RebuyHydrogenReactContextProvider` around the children. Required Props: `publicPrimaryDomain` (your shop's main domain, e.g., "example.com"), `publicStoreDomain` (your Shopify domain, e.g., "example.myshopify.com"), `publicStorefrontToken` (your public storefront API token), and `publicStorefrontId` (your storefront ID). For Pack Digital users, this would typically be in `app/context/ContextProvider.tsx`:
92
+
93
+ ```typescript
94
+ <RebuyHydrogenReactContextProvider publicPrimaryDomain="example.com" publicStoreDomain="example.myshopify.com" publicStorefrontToken="1233456" publicStorefrontId="12345678" >
95
+ {children}
96
+ </RebuyHydrogenReactContextProvider>
97
+ ```
98
+
99
+ 3. With this, you can also pass in any CartProvider props that you need.
100
+
101
+ ### Cart Provider Properties
102
+
103
+ | Property | Type | Required | Description |
104
+ | :------------------------------ | :------------------------------------------------- | :------- | :----------------------------------------------------------------------------------------------------------------------------------------------------- |
105
+ | `children` | `React.ReactNode` | Yes | Any `ReactNode` elements. |
106
+ | `numCartLines` | `number` | No | Maximum number of cart lines to fetch. Defaults to 250 cart lines. |
107
+ | `onCreate` | `() => void` | No | A callback that is invoked when the process to create a cart begins, but before the cart is created in the Storefront API. |
108
+ | `onLineAdd` | `() => void` | No | A callback that is invoked when the process to add a line item to the cart begins, but before the line item is added to the Storefront API. |
109
+ | `onLineRemove` | `() => void` | No | A callback that is invoked when the process to remove a line item to the cart begins, but before the line item is removed from the Storefront API. |
110
+ | `onLineUpdate` | `() => void` | No | A callback that is invoked when the process to update a line item in the cart begins, but before the line item is updated in the Storefront API. |
111
+ | `onNoteUpdate` | `() => void` | No | A callback that is invoked when the process to add or update a note in the cart begins, but before the note is added or updated in the Storefront API. |
112
+ | `onBuyerIdentityUpdate` | `() => void` | No | A callback that is invoked when the process to update the buyer identity begins, but before the buyer identity is updated in the Storefront API. |
113
+ | `onAttributesUpdate` | `() => void` | No | A callback that is invoked when the process to update the cart attributes begins, but before the attributes are updated in the Storefront API. |
114
+ | `onDiscountCodesUpdate` | `() => void` | No | A callback that is invoked when the process to update the cart discount codes begins, but before the discount codes are updated in the Storefront API. |
115
+ | `onCreateComplete` | `() => void` | No | A callback that is invoked when the process to create a cart completes. |
116
+ | `onLineAddComplete` | `() => void` | No | A callback that is invoked when the process to add a line item to the cart completes. |
117
+ | `onLineRemoveComplete` | `() => void` | No | A callback that is invoked when the process to remove a line item to the cart completes. |
118
+ | `onLineUpdateComplete` | `() => void` | No | A callback that is invoked when the process to update a line item in the cart completes. |
119
+ | `onNoteUpdateComplete` | `() => void` | No | A callback that is invoked when the process to add or update a note in the cart completes. |
120
+ | `onBuyerIdentityUpdateComplete` | `() => void` | No | A callback that is invoked when the process to update the buyer identity completes. |
121
+ | `onAttributesUpdateComplete` | `() => void` | No | A callback that is invoked when the process to update the cart attributes completes. |
122
+ | `onDiscountCodesUpdateComplete` | `() => void` | No | A callback that is invoked when the process to update the cart discount codes completes. |
123
+ | `data` | `PartialDeep<CartType, {recurseIntoArrays: true}>` | No | An object with fields that correspond to the Storefront API's Cart object. |
124
+ | `cartFragment` | `string` | No | A fragment used to query the Storefront API's Cart object for all queries and mutations. A default value is used if no argument is provided. |
125
+ | `customerAccessToken` | `string` | No | A customer access token that's accessible on the server if there's a customer login. |
126
+ | `countryCode` | `CountryCode` | No | The ISO country code for i18n. |
127
+
128
+ ### Override Key
129
+
130
+ If you need to pass in a different Rebuy API key from the one that we dynamically use for your store, you can pass it in as a prop on either of the provider components, e.g., `overrideApiKey="123456"`.
131
+
132
+ ---
133
+
134
+ # 🎨 Themed Styles
135
+
136
+ Rebuy provides themed stylesheets that automatically synchronize your components with the design settings configured in your Rebuy admin panel. This ensures that button colors, widget text colors, typography, spacing, and other visual elements match your brand preferences without requiring manual CSS customization.
137
+
138
+ ### For Remix/Hydrogen Users
139
+
140
+ Use the `getRebuyThemeStylesLink` function in your root layout file's `links()` function for optimal performance:
141
+
142
+ 1. Import the function in your root layout file (typically `app/root.tsx`):
143
+
144
+ ```typescript
145
+ import { getRebuyThemeStylesLink } from '@rebuy/rebuy-hydrogen';
146
+ ```
147
+
148
+ 2. Add the theme styles to your `links()` function:
149
+
150
+ ```typescript
151
+ export function links() {
152
+ const links = [
153
+ {
154
+ rel: 'preconnect',
155
+ href: 'https://cdn.shopify.com',
156
+ },
157
+ // ... other links
158
+ ];
159
+
160
+ // Add Rebuy theme styles
161
+ links.push(
162
+ ...getRebuyThemeStylesLink({
163
+ apiKey: 'your-rebuy-api-key-here',
164
+ })
165
+ );
166
+
167
+ return links;
168
+ }
169
+ ```
170
+
171
+ ### For Other Frameworks
172
+
173
+ If you're not using Remix, you can include the stylesheet directly in your HTML `<head>` or via your framework's preferred method:
174
+
175
+ ```html
176
+ <link rel="stylesheet" href="https://rebuyengine.com/api/v1/theme-styles?key=your-rebuy-api-key-here" />
177
+ ```
178
+
179
+ ### Finding Your API Key
180
+
181
+ You can find your Rebuy API key in your [Rebuy admin account settings](https://rebuyengine.com/account/keys) (login required).
182
+
183
+ ---
184
+
185
+ # 🧩 Components Reference
186
+
187
+ Our components work seamlessly in both Hydrogen-only and Hydrogen React applications by using the existing context to call the correct hooks/functions.
188
+
189
+ ### WidgetContainer
190
+
191
+ This is the parent component that provides the needed context to child widgets.
192
+
193
+ **Properties:**
194
+
195
+ | Property | Description |
196
+ | :----------- | :----------------------------------------------------------------------------------------- |
197
+ | `dataSource` | The Rebuy API endpoint to use for product recommendations |
198
+ | `productId` | The Shopify product ID |
199
+ | `product` | The entire product object |
200
+ | `variantID` | The selected variant ID |
201
+ | `variant` | The selected variant object |
202
+ | `limit` | How many product recommendations to return |
203
+ | `options` | An object with key-value pairs of Rebuy REST API arguments (e.g., `{ metafields: "yes" }`) |
204
+
205
+ ### RebuyCompleteTheLook
206
+
207
+ **Properties:**
208
+
209
+ | Property | Description |
210
+ | :------------------ | :----------------------------------------------------------------------------------------------------------------- |
211
+ | `customTitle` | A custom title displayed above the component |
212
+ | `customTitleLevel` | Sets the initial title level (e.g., if set to `h2`, other titles in the component will adjust to `h3` accordingly) |
213
+ | `customTitleStyle` | An object of custom styles for the title (e.g., text color, text align) |
214
+ | `addToCartCallback` | A callback function for custom functionality when items are added to the cart |
215
+ | `addToCartBtnText` | Custom text for the Add To Cart button |
216
+
217
+ ### RebuyDynamicBundleProducts
218
+
219
+ **Properties:**
220
+
221
+ | Property | Description |
222
+ | :------------------ | :----------------------------------------------------------------------------------------------------------------- |
223
+ | `customTitle` | A custom title displayed above the component |
224
+ | `customTitleLevel` | Sets the initial title level (e.g., if set to `h2`, other titles in the component will adjust to `h3` accordingly) |
225
+ | `customTitleStyle` | An object of custom styles for the title (e.g., text color, text align) |
226
+ | `addToCartCallback` | A callback function for custom functionality when items are added to the cart |
227
+ | `addToCartBtnText` | Custom text for the Add To Cart button |
228
+
229
+ ### RebuyProductRecommendations
230
+
231
+ **Properties:**
232
+
233
+ | Property | Description |
234
+ | :------------------ | :----------------------------------------------------------------------------------------------------------------- |
235
+ | `customTitle` | A custom title displayed above the component |
236
+ | `customTitleLevel` | Sets the initial title level (e.g., if set to `h2`, other titles in the component will adjust to `h3` accordingly) |
237
+ | `customTitleStyle` | An object of custom styles for the title (e.g., text color, text align) |
238
+ | `addToCartCallback` | A callback function for custom functionality when items are added to the cart |
239
+ | `addToCartBtnText` | Custom text for the Add To Cart button |
240
+
241
+ ### RebuyProductAddOns
242
+
243
+ **Properties:**
244
+
245
+ | Property | Description |
246
+ | :------------------- | :-------------------------------------------------------------------------------------------------------------------- |
247
+ | `customTitle` | A custom title displayed above the component |
248
+ | `customTitleLevel` | Sets the initial title level (e.g., if set to `h2`, other titles in the component will adjust to `h3` accordingly) |
249
+ | `customTitleStyle` | An object of custom styles for the title (e.g., text color, text align) |
250
+ | `addToCartCallback` | A callback function for custom functionality when items are added to the cart |
251
+ | `addToCartBtnText` | Custom text for the Add To Cart button |
252
+ | `includeMainProduct` | Option to include the product passed from the `WidgetContainer` in the add to cart functionality |
253
+ | `learnMoreText` | Text displayed in a CTA that takes users to the product page |
254
+ | `subtotalText` | Text that appears before the subtotal of all add-ons |
255
+ | `withProductText` | Text that appears before the total if the product from `WidgetContainer` is included in the add to cart functionality |
256
+
257
+ ### RebuyWidget
258
+
259
+ Dynamic widget that can be set up to display a widget that you have created in the Rebuy Admin.
260
+
261
+ **Properties:**
262
+
263
+ | Property | Description |
264
+ | :------------------ | :-------------------------------------------------------------------------------------------------------------------------------------------- |
265
+ | `widgetId` | The widget ID for the widget that you want to display (can be found in the Rebuy Admin). |
266
+ | `addToCartCallback` | A callback function for custom functionality when items are added to the cart. |
267
+ | `customTitle` | A custom title displayed above the component. |
268
+ | `customTitleLevel` | Sets the initial title level (e.g., if set to `h2`, other titles in the component will adjust to `h3` accordingly). Defaults to `h2`. |
269
+ | `customTitleStyle` | An object of custom styles for the title (e.g., text color, text align). |
270
+ | `isHydrogenReact` | A boolean indicating if the application is using Hydrogen React. This helps the component use the correct hooks/functions. |
271
+ | `popupTriggerId` | If you have configured this to be a popup that is triggered on a button click, pass the ID of the element that you want to trigger the popup. |
272
+ | `product` | The entire product object. |
273
+ | `productId` | The Shopify product ID. |
274
+ | `variant` | The selected variant object. |
275
+ | `variantId` | The selected variant ID. |
276
+
277
+ ### RebuyGiftWithPurchase
278
+
279
+ A headless widget that automatically manages Gift With Purchase functionality. This component monitors cart state and automatically adds/removes free gifts based on data source rules configured in the Rebuy Admin. No UI is rendered - all gift management happens automatically in the background.
280
+
281
+ **Properties:**
282
+
283
+ | Property | Description |
284
+ | :--------- | :-------------------------------------------------------------------------- |
285
+ | `widgetId` | The widget ID for the gift with purchase widget (found in the Rebuy Admin). |
286
+
287
+ **Usage Example:**
288
+
289
+ ```typescript
290
+ // Place in your root layout
291
+ <RebuyGiftWithPurchase widgetId="12345" />
292
+ ```
293
+
294
+ **Notes:**
295
+
296
+ - This component is best suited for single-variant gift products.
297
+ - If your gift qualifier is the cart subtotal, we recommend using the Tiered Progress Bar as it can be used for selectable multi-variant gifts.
298
+
299
+ ### RebuyProductViewed
300
+
301
+ Place this component on any page or element where you would like to record that a customer has viewed one of your products. You will need to pass in either the entire product object, productID, or just the productHandle. This component will generate a UUID for registering the viewed products if a customerId is not passed along as well. To record a customer viewing a product and have that record attached to their customerID you will need to pass in the customerId as a sting.
302
+
303
+ **Properties:**
304
+
305
+ | Property | Description |
306
+ | :-------------- | :---------------------------------------------------------------------------------------------------------- |
307
+ | `productId` | The Shopify product ID |
308
+ | `product` | The entire product object |
309
+ | `productHandle` | The product's handle |
310
+ | `customerId` | The ID of the customer viewing the product. If no customerId is passed a UUID will be used locally instead. |
311
+
312
+ ### RebuyRecentlyViewedProducts
313
+
314
+ Component returns a list of the products that a customer has recently viewed based on either their customerId or the generated UUID
315
+
316
+ **Properties:**
317
+
318
+ | `customTitleLevel` | Sets the initial title level (e.g., if set to `h2`, other titles in the component will adjust to `h3` accordingly) |
319
+ | :------------------ | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
320
+ | `customTitleStyle` | An object of custom styles for the title (e.g., text color, text align) |
321
+ | `addToCartCallBack` | A callback function for custom functionality when items are added to the cart |
322
+ | `addToCartBtnText` | Custom text for the Add To Cart button |
323
+ | `productId` | If you pass in a shopify productId, then that product will be excluded from the list of returned products. Use case would be if on a product page and you do not want the product on that page also displaying in the recently viewed products component. |
324
+
325
+ ### Using useRebuyWidget in Custom Components
326
+
327
+ You can create custom components that access Rebuy widget data by using the `useRebuyWidget` hook within a `RebuyWidgetContainer`. This allows you to build custom UIs while maintaining access to all Rebuy widget functionality.
328
+
329
+ ```typescript
330
+ import { useRebuyWidget } from '@rebuy/rebuy-hydrogen';
331
+
332
+ // In your page/layout:
333
+ <RebuyWidgetContainer dataSource="/api/v1/products/recommended" limit={4}>
334
+ <MyCustomComponent />
335
+ <RebuyProductRecommendations />
336
+ </RebuyWidgetContainer>
337
+
338
+ // In your custom component:
339
+ const MyCustomComponent = () => {
340
+ const {
341
+ products,
342
+ isHydrogenReact,
343
+ metadata,
344
+ product,
345
+ variant
346
+ } = useRebuyWidget();
347
+
348
+ return (
349
+ <div>
350
+ {/* Custom implementation using Rebuy data */}
351
+ </div>
352
+ );
353
+ };
354
+ ```
355
+
356
+ **Available Context Properties:**
357
+
358
+ | Property | Type | Description |
359
+ | :---------------- | :--------------------------------- | :-------------------------------------- |
360
+ | `products` | `RebuyProduct[]` | Array of recommended products |
361
+ | `isHydrogenReact` | `boolean` | Whether the app is using Hydrogen React |
362
+ | `metadata` | `RebuyWidgetMetadata` | Widget metadata from Rebuy |
363
+ | `product` | `HydrogenProduct \| undefined` | The main product if provided |
364
+ | `variant` | `RebuyProductVariant \| undefined` | The selected variant if provided |
365
+ | `productId` | `string \| undefined` | The product ID if provided |
366
+ | `variantId` | `string \| undefined` | The variant ID if provided |
367
+ | `dataSource` | `string` | The Rebuy API endpoint being used |
368
+ | `limit` | `number` | Maximum number of products to return |
369
+ | `options` | `Record<string, unknown>` | Additional Rebuy API options |
370
+ | `key` | `string` | Unique key for the widget instance |
371
+ | `cacheKey` | `string \| undefined` | The shop's cache key for Rebuy |
372
+ | `apiKey` | `string \| undefined` | The Rebuy API key for the shop |
373
+
374
+ ---
375
+
376
+ # 🛒 Smart Cart Guide
377
+
378
+ 🚀 **Smart Cart: Supercharge Your Shopify Cart**
379
+
380
+ Welcome to the Rebuy Smart Cart! This powerful suite of features is designed to enhance your Shopify cart experience, boost conversions, and provide seamless integration with Rebuy's personalization engine.
381
+
382
+ > **📘 Framework Compatibility Note**
383
+ >
384
+ > This documentation covers Hydrogen projects using both Remix and React Router frameworks. If you're using React Router 7 (the newer standard), ensure you're importing from the correct packages:
385
+ >
386
+ > - Use `react-router` instead of `@remix-run/react`
387
+ > - Use `@react-router/dev` instead of `@remix-run/dev`
388
+ >
389
+ > The core functionality remains the same regardless of framework choice.
390
+
391
+ > **A Note on Hydrogen Versions**
392
+ >
393
+ > The instructions and examples in this guide are tailored for Shopify Hydrogen projects built with the **Remix framework (Hydrogen v2 and later)**. File paths like `app/root.tsx` and concepts such as route `action` functions are specific to this architecture.
394
+ >
395
+ > If you are using a non-Remix Hydrogen setup or a different React framework, you will need to adapt these instructions. While the core GraphQL fragments for the cart query are reusable, your project's methods for fetching data and handling cart mutations will be different.
396
+
397
+ ## Enabling Smart Cart Toggle
398
+
399
+ To replace Hydrogen's native cart drawer with Rebuy's Smart Cart, follow these steps:
400
+
401
+ ### 1. Enable Smart Cart in the Provider
402
+
403
+ In your root layout file (`app/root.tsx`), add the `enableSmartCart` prop to your context provider and include the `RebuySmartCart` component:
404
+
405
+ **For Hydrogen-only Applications:**
406
+
407
+ ```typescript
408
+ <RebuyHydrogenContextProvider
409
+ cart={data.cart}
410
+ shop="example.com"
411
+ publicStoreDomain="example.myshopify.com"
412
+ enableSmartCart={true}
413
+ >
414
+ {/* Your app content */}
415
+ <RebuySmartCart />
416
+ </RebuyHydrogenContextProvider>
417
+ ```
418
+
419
+ **For Hydrogen React Applications:**
420
+
421
+ ```typescript
422
+ <RebuyHydrogenReactContextProvider
423
+ publicPrimaryDomain="example.com"
424
+ publicStoreDomain="example.myshopify.com"
425
+ publicStorefrontToken="1233456"
426
+ publicStorefrontId="12345678"
427
+ enableSmartCart={true}
428
+ >
429
+ {/* Your app content */}
430
+ <RebuySmartCart />
431
+ </RebuyHydrogenReactContextProvider>
432
+ ```
433
+
434
+ ### 2. Disable the Native Cart Aside
435
+
436
+ Comment out or remove the native `CartAside` component in your layout file (typically in `PageLayout.tsx` or similar):
437
+
438
+ ```typescript
439
+ // Before
440
+ <CartAside cart={cart} />
441
+
442
+ // After - Comment out or remove
443
+ {/* <CartAside cart={cart} /> */}
444
+ ```
445
+
446
+ ### 3. Update Cart Toggle Interactions
447
+
448
+ Replace the native cart toggle functionality with Rebuy's Smart Cart:
449
+
450
+ **In your Header component:**
451
+
452
+ ```typescript
453
+ import { useSmartCart } from '@rebuy/rebuy-hydrogen';
454
+
455
+ export function Header() {
456
+ const { toggleCart } = useSmartCart();
457
+
458
+ // In your cart button/icon
459
+ return (
460
+ <button
461
+ onClick={(e) => {
462
+ e.preventDefault();
463
+ toggleCart();
464
+ }}
465
+ >
466
+ Cart ({itemCount})
467
+ </button>
468
+ );
469
+ }
470
+ ```
471
+
472
+ ### 4. Update Add to Cart Actions
473
+
474
+ After successful add to cart actions, open the Smart Cart:
475
+
476
+ ```typescript
477
+ import { useSmartCart } from '@rebuy/rebuy-hydrogen';
478
+
479
+ export function ProductForm() {
480
+ const { toggleCart } = useSmartCart();
481
+
482
+ // After successful add to cart
483
+ const handleAddToCart = async () => {
484
+ // ... add to cart logic
485
+ toggleCart(); // Opens Smart Cart after adding item
486
+ };
487
+ }
488
+ ```
489
+
490
+ ### Complete Example
491
+
492
+ Here's a complete example of converting a cart badge component:
493
+
494
+ **Before (Hydrogen):**
495
+
496
+ ```typescript
497
+ function CartBadge() {
498
+ const { open } = useAside();
499
+
500
+ return (
501
+ <a href="/cart" onClick={(e) => {
502
+ e.preventDefault();
503
+ open('cart');
504
+ }}>
505
+ Cart
506
+ </a>
507
+ );
508
+ }
509
+ ```
510
+
511
+ **After (Rebuy Smart Cart):**
512
+
513
+ ```typescript
514
+ import { useSmartCart } from '@rebuy/rebuy-hydrogen';
515
+
516
+ function CartBadge() {
517
+ const { toggleCart } = useSmartCart();
518
+
519
+ return (
520
+ <a href="/cart" onClick={(e) => {
521
+ e.preventDefault();
522
+ toggleCart();
523
+ }}>
524
+ Cart
525
+ </a>
526
+ );
527
+ }
528
+ ```
529
+
530
+ > **Note:** The `useSmartCart` hook provides `toggleCart()` to toggle the cart open/closed, along with other cart state management functions.
531
+
532
+ ## Prerequisites
533
+
534
+ Before implementing Smart Cart features, ensure your cart route can handle JSON payloads and your GraphQL queries include the necessary fields for discount and subscription functionality.
535
+
536
+ ### JSON Cart Action Support
537
+
538
+ Smart Cart components send updates as JSON payloads to your cart route. Your cart route file (e.g., `app/routes/cart.tsx` or `app/routes/($locale).cart.tsx`) must be able to parse both JSON and form data requests.
539
+
540
+ **Update your cart route's action function:**
541
+
542
+ ```typescript
543
+ export async function action({ request, context }: ActionFunctionArgs) {
544
+ const { cart } = context;
545
+
546
+ let formData;
547
+ let action;
548
+ let inputs;
549
+
550
+ const contentType = request.headers.get('Content-Type') || '';
551
+ if (contentType.includes('application/json')) {
552
+ const jsonData = (await request.json()) as { action: string; data: any };
553
+
554
+ const actionMap = {
555
+ cartLinesAdd: CartForm.ACTIONS.LinesAdd,
556
+ cartLinesUpdate: CartForm.ACTIONS.LinesUpdate,
557
+ cartLinesRemove: CartForm.ACTIONS.LinesRemove,
558
+ discountCodesUpdate: CartForm.ACTIONS.DiscountCodesUpdate,
559
+ giftCardCodesUpdate: CartForm.ACTIONS.GiftCardCodesUpdate,
560
+ buyerIdentityUpdate: CartForm.ACTIONS.BuyerIdentityUpdate,
561
+ cartAttributesUpdate: CartForm.ACTIONS.AttributesUpdateInput,
562
+ };
563
+
564
+ const actionKey = jsonData.action as string;
565
+ action = actionKey in actionMap ? actionMap[actionKey as keyof typeof actionMap] : actionKey;
566
+ inputs = jsonData.data;
567
+ } else {
568
+ formData = await request.formData();
569
+ const formInput = CartForm.getFormInput(formData);
570
+ action = formInput.action;
571
+ inputs = formInput.inputs;
572
+ }
573
+
574
+ if (!action) {
575
+ throw new Error('No action provided');
576
+ }
577
+
578
+ let status = 200;
579
+ let result: CartQueryDataReturn;
580
+
581
+ switch (action) {
582
+ case CartForm.ACTIONS.LinesAdd:
583
+ result = await cart.addLines(inputs.lines);
584
+ break;
585
+ case CartForm.ACTIONS.LinesUpdate:
586
+ result = await cart.updateLines(inputs.lines);
587
+ break;
588
+ case CartForm.ACTIONS.LinesRemove:
589
+ result = await cart.removeLines(inputs.lineIds);
590
+ break;
591
+ case CartForm.ACTIONS.DiscountCodesUpdate: {
592
+ const formDiscountCode = inputs.discountCode;
593
+ const discountCodes = (formDiscountCode ? [formDiscountCode] : []) as string[];
594
+ discountCodes.push(...(inputs.discountCodes || []));
595
+ result = await cart.updateDiscountCodes(discountCodes);
596
+ break;
597
+ }
598
+ case CartForm.ACTIONS.GiftCardCodesUpdate: {
599
+ const formGiftCardCode = inputs.giftCardCode;
600
+ const giftCardCodes = (formGiftCardCode ? [formGiftCardCode] : []) as string[];
601
+ giftCardCodes.push(...(inputs.giftCardCodes || []));
602
+ result = await cart.updateGiftCardCodes(giftCardCodes);
603
+ break;
604
+ }
605
+ case CartForm.ACTIONS.BuyerIdentityUpdate: {
606
+ result = await cart.updateBuyerIdentity({ ...inputs.buyerIdentity });
607
+ break;
608
+ }
609
+ case CartForm.ACTIONS.AttributesUpdateInput: {
610
+ result = await cart.updateAttributes(inputs.attributes || []);
611
+ break;
612
+ }
613
+ default:
614
+ throw new Error(`${action} cart action is not defined`);
615
+ }
616
+
617
+ const cartId = result?.cart?.id;
618
+ const headers = cartId ? cart.setCartId(result.cart.id) : new Headers();
619
+ const { cart: cartResult, errors, warnings } = result;
620
+
621
+ const redirectTo = formData ? (formData.get('redirectTo') ?? null) : null;
622
+ if (typeof redirectTo === 'string') {
623
+ status = 303;
624
+ headers.set('Location', redirectTo);
625
+ }
626
+
627
+ return data(
628
+ {
629
+ cart: cartResult,
630
+ errors,
631
+ warnings,
632
+ analytics: { cartId },
633
+ },
634
+ { status, headers }
635
+ );
636
+ }
637
+ ```
638
+
639
+ **Note:** Cart route file names may vary based on your project setup. Common variations include `cart.tsx`, `($locale).cart.tsx`, or `[locale].cart.tsx`.
640
+
641
+ ### Enhanced Cart Query for Smart Cart Features
642
+
643
+ To enable full discount and subscription functionality, your cart query must include specific GraphQL fields. Update your cart query fragment to include these essential fields:
644
+
645
+ ```graphql
646
+ #graphql
647
+ fragment Money on MoneyV2 {
648
+ currencyCode
649
+ amount
650
+ }
651
+
652
+ fragment CartLine on CartLine {
653
+ id
654
+ quantity
655
+ attributes {
656
+ key
657
+ value
658
+ }
659
+ cost {
660
+ totalAmount {
661
+ ...Money
662
+ }
663
+ amountPerQuantity {
664
+ ...Money
665
+ }
666
+ compareAtAmountPerQuantity {
667
+ ...Money
668
+ }
669
+ }
670
+ merchandise {
671
+ ... on ProductVariant {
672
+ id
673
+ availableForSale
674
+ compareAtPrice {
675
+ ...Money
676
+ }
677
+ price {
678
+ ...Money
679
+ }
680
+ requiresShipping
681
+ title
682
+ image {
683
+ id
684
+ url
685
+ altText
686
+ width
687
+ height
688
+ }
689
+ product {
690
+ handle
691
+ title
692
+ id
693
+ vendor
694
+ # Required for subscription functionality
695
+ requiresSellingPlan
696
+ sellingPlanGroups(first: 100) {
697
+ edges {
698
+ node {
699
+ appName
700
+ name
701
+ options {
702
+ name
703
+ values
704
+ }
705
+ sellingPlans(first: 100) {
706
+ edges {
707
+ node {
708
+ id
709
+ name
710
+ options {
711
+ name
712
+ value
713
+ }
714
+ priceAdjustments {
715
+ adjustmentValue {
716
+ ... on SellingPlanFixedAmountPriceAdjustment {
717
+ adjustmentAmount {
718
+ amount
719
+ currencyCode
720
+ }
721
+ }
722
+ ... on SellingPlanFixedPriceAdjustment {
723
+ price {
724
+ amount
725
+ currencyCode
726
+ }
727
+ }
728
+ ... on SellingPlanPercentagePriceAdjustment {
729
+ adjustmentPercentage
730
+ }
731
+ }
732
+ }
733
+ }
734
+ }
735
+ }
736
+ }
737
+ }
738
+ }
739
+ }
740
+ selectedOptions {
741
+ name
742
+ value
743
+ }
744
+ }
745
+ }
746
+ # Required for subscription functionality
747
+ sellingPlanAllocation {
748
+ sellingPlan {
749
+ id
750
+ name
751
+ }
752
+ }
753
+ }
754
+
755
+ fragment CartApiQuery on Cart {
756
+ updatedAt
757
+ id
758
+ appliedGiftCards {
759
+ lastCharacters
760
+ amountUsed {
761
+ ...Money
762
+ }
763
+ }
764
+ checkoutUrl
765
+ totalQuantity
766
+ buyerIdentity {
767
+ countryCode
768
+ customer {
769
+ id
770
+ email
771
+ firstName
772
+ lastName
773
+ displayName
774
+ }
775
+ email
776
+ phone
777
+ }
778
+ lines(first: $numCartLines) {
779
+ nodes {
780
+ ...CartLine
781
+ }
782
+ }
783
+ cost {
784
+ subtotalAmount {
785
+ ...Money
786
+ }
787
+ totalAmount {
788
+ ...Money
789
+ }
790
+ totalDutyAmount {
791
+ ...Money
792
+ }
793
+ totalTaxAmount {
794
+ ...Money
795
+ }
796
+ }
797
+ note
798
+ attributes {
799
+ key
800
+ value
801
+ }
802
+ discountCodes {
803
+ code
804
+ applicable
805
+ }
806
+ # Required for discount functionality
807
+ discountAllocations {
808
+ discountedAmount {
809
+ ...Money
810
+ }
811
+ ... on CartCodeDiscountAllocation {
812
+ code
813
+ }
814
+ ... on CartAutomaticDiscountAllocation {
815
+ title
816
+ }
817
+ }
818
+ }
819
+ ```
820
+
821
+ **Important:** After updating your cart query fragments, regenerate your Hydrogen types:
822
+
823
+ ```bash
824
+ npm run dev -- --codegen
825
+ # OR
826
+ npm run codegen
827
+ ```
828
+
829
+ This updates your `storefrontapi.generated.d.ts` file with the new TypeScript types for Smart Cart fields.
830
+
831
+ ### Using Smart Cart Apps & Custom Code
832
+
833
+ Features like **Smart Cart Apps** and **Custom Code Blocks** inject dynamic content and scripts directly into the cart. To enable these features, you must configure your Content Security Policy (CSP) and provide the nonce to the DOM.
834
+
835
+ #### Step 1: Configure Content Security Policy
836
+
837
+ Update your server entry file (typically `app/entry.server.tsx`) to include Rebuy domains and script sources:
838
+
839
+ ```typescript
840
+ import type {AppLoadContext} from '@shopify/remix-oxygen';
841
+ import {ServerRouter} from 'react-router';
842
+ import {isbot} from 'isbot';
843
+ import {renderToReadableStream} from 'react-dom/server';
844
+ import {createContentSecurityPolicy} from '@shopify/hydrogen';
845
+ import type {EntryContext} from 'react-router';
846
+
847
+ export default async function handleRequest(
848
+ request: Request,
849
+ responseStatusCode: number,
850
+ responseHeaders: Headers,
851
+ reactRouterContext: EntryContext,
852
+ context: AppLoadContext,
853
+ ) {
854
+ const {nonce, header, NonceProvider} = createContentSecurityPolicy({
855
+ shop: {
856
+ checkoutDomain: context.env.PUBLIC_CHECKOUT_DOMAIN,
857
+ storeDomain: context.env.PUBLIC_STORE_DOMAIN,
858
+ },
859
+ scriptSrc: [
860
+ "'self'",
861
+ 'https://cdn.shopify.com',
862
+ '*.rebuyengine.com',
863
+ 'rebuyengine.com',
864
+ ],
865
+ styleSrc: [
866
+ "'self'",
867
+ 'https://cdn.shopify.com',
868
+ '*.rebuyengine.com',
869
+ 'rebuyengine.com',
870
+ ],
871
+ connectSrc: [
872
+ "'self'",
873
+ '*.rebuyengine.com',
874
+ 'rebuyengine.com',
875
+ 'https://monorail-edge.shopifysvc.com',
876
+ ],
877
+ imgSrc: ["'self'", "data:", "https://cdn.shopify.com", "*.rebuyengine.com"],
878
+ fontSrc: ["'self'", "data:", "https://cdn.shopify.com"],
879
+ });
880
+
881
+ const body = await renderToReadableStream(
882
+ <NonceProvider>
883
+ <ServerRouter
884
+ context={reactRouterContext}
885
+ url={request.url}
886
+ nonce={nonce}
887
+ />
888
+ </NonceProvider>,
889
+ {
890
+ nonce,
891
+ signal: request.signal,
892
+ onError(error) {
893
+ console.error(error);
894
+ responseStatusCode = 500;
895
+ },
896
+ },
897
+ );
898
+
899
+ if (isbot(request.headers.get('user-agent'))) {
900
+ await body.allReady;
901
+ }
902
+
903
+ responseHeaders.set('Content-Type', 'text/html');
904
+ responseHeaders.set('Content-Security-Policy', header);
905
+
906
+ return new Response(body, {
907
+ headers: responseHeaders,
908
+ status: responseStatusCode,
909
+ });
910
+ }
911
+ ```
912
+
913
+ #### Step 2: Provide Nonce to DOM
914
+
915
+ Update your root layout file (typically `app/root.tsx`) to attach the nonce to the body element:
916
+
917
+ ```tsx
918
+ import { useNonce } from '@shopify/hydrogen';
919
+
920
+ export function Layout({ children }: { children?: React.ReactNode }) {
921
+ const nonce = useNonce();
922
+
923
+ return (
924
+ <html lang="en">
925
+ <head>{/* ... */}</head>
926
+ <body data-nonce={nonce} suppressHydrationWarning>
927
+ {/* ... your providers and app content ... */}
928
+ </body>
929
+ </html>
930
+ );
931
+ }
932
+ ```
933
+
934
+ ### Login Button
935
+
936
+ The Login Button component provides a link to your store's login page and automatically hides when a customer is logged in. Configure the login URL in your Rebuy admin (defaults to `/account/login`).
937
+
938
+ ---
939
+
940
+ ## 🔧 Troubleshooting
941
+
942
+ ### GraphQL Type Errors
943
+
944
+ If you encounter TypeScript errors after updating fragments:
945
+
946
+ 1. Run the codegen command: `npm run codegen`
947
+ 2. Restart your development server
948
+ 3. Verify `storefrontapi.generated.d.ts` has been updated
949
+
950
+ ### Cart Route Issues
951
+
952
+ If Smart Cart features aren't working:
953
+
954
+ 1. Verify your cart route handles JSON payloads
955
+ 2. Check your cart route file name matches your project structure
956
+ 3. Ensure your action function processes both JSON and FormData requests
957
+
958
+ ### CSP Issues
959
+
960
+ If Smart Cart Apps or Custom Code Blocks aren't working:
961
+
962
+ 1. Verify Rebuy domains are in your CSP configuration
963
+ 2. Ensure the nonce is set on the `<body>` element
964
+ 3. Check browser console for CSP violation errors
965
+
966
+ ---
967
+
968
+ ## 📋 Compatibility
969
+
970
+ ### Hydrogen Versions
971
+
972
+ - ✅ Hydrogen 2025.5.0+
973
+ - ✅ React Router 7.x
974
+ - ✅ Remix-based Hydrogen projects
975
+ - ✅ Hydrogen React 2.0+
976
+
977
+ ### Node.js Requirements
978
+
979
+ - Node.js 18.0.0 or higher
980
+ - npm 8.0.0 or higher
981
+
982
+ ### Framework Support
983
+
984
+ - **Remix Framework**: Full support
985
+ - **React Router 7**: Full support
986
+ - **Hydrogen React**: Enhanced cart provider with additional props
987
+
988
+ ### Browser Support
989
+
990
+ - Chrome 90+
991
+ - Firefox 88+
992
+ - Safari 14+
993
+ - Edge 90+
994
+
995
+ ### Shopify Compatibility
996
+
997
+ - Storefront API 2024-01+
998
+ - Checkout API compatibility
999
+ - Multi-language/locale support
1000
+ - Customer account integration