@rebuy/rebuy-hydrogen 3.0.0-beta.10 → 3.0.0-beta.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 (97) hide show
  1. package/dist/components/AddToCartBtn/AddToCartBtn.d.ts.map +1 -1
  2. package/dist/components/AddToCartBtn/HydrogenAddToCartBtn.d.ts.map +1 -1
  3. package/dist/components/AddToCartBtn/HydrogenReactAddToCartBtn.d.ts.map +1 -1
  4. package/dist/components/ProductCard/ProductCard.d.ts.map +1 -1
  5. package/dist/components/ProductPrice/ProductPrice.d.ts +1 -1
  6. package/dist/components/ProductPrice/ProductPrice.d.ts.map +1 -1
  7. package/dist/components/VariantSelect/VariantSelect.d.ts +1 -1
  8. package/dist/components/VariantSelect/VariantSelect.d.ts.map +1 -1
  9. package/dist/hooks/titleLevel.d.ts.map +1 -1
  10. package/dist/index.css +88 -88
  11. package/dist/index.css.map +4 -4
  12. package/dist/index.js +421 -195
  13. package/dist/index.js.map +4 -4
  14. package/dist/index.mjs +430 -196
  15. package/dist/index.mjs.map +4 -4
  16. package/dist/providers/RebuyHydrogenContextProvider.d.ts +1 -1
  17. package/dist/providers/RebuyHydrogenContextProvider.d.ts.map +1 -1
  18. package/dist/providers/RebuyHydrogenReactContextProvider.d.ts.map +1 -1
  19. package/dist/providers/types.d.ts +1 -7
  20. package/dist/providers/types.d.ts.map +1 -1
  21. package/dist/types/rebuyCustom.d.ts +0 -1
  22. package/dist/types/rebuyCustom.d.ts.map +1 -1
  23. package/dist/types/shopify.d.ts.map +1 -1
  24. package/dist/types/widgets.d.ts +1 -1
  25. package/dist/types/widgets.d.ts.map +1 -1
  26. package/dist/utils/convertToRebuyProduct.d.ts.map +1 -1
  27. package/dist/utils/createContextParameters.d.ts.map +1 -1
  28. package/dist/utils/getEncodedAttributes.d.ts.map +1 -1
  29. package/dist/utils/getRebuyConfig.d.ts +1 -1
  30. package/dist/utils/getRebuyConfig.d.ts.map +1 -1
  31. package/dist/widgetContainer/RebuyWidgetContainer.d.ts +1 -1
  32. package/dist/widgetContainer/RebuyWidgetContainer.d.ts.map +1 -1
  33. package/dist/widgets/RebuyCompleteTheLook/RebuyCompleteTheLook.d.ts.map +1 -1
  34. package/dist/widgets/RebuyDynamicBundleProducts/BundleImages.d.ts.map +1 -1
  35. package/dist/widgets/RebuyDynamicBundleProducts/BundlePrice.d.ts.map +1 -1
  36. package/dist/widgets/RebuyDynamicBundleProducts/BundleSelection.d.ts +1 -1
  37. package/dist/widgets/RebuyDynamicBundleProducts/BundleSelection.d.ts.map +1 -1
  38. package/dist/widgets/RebuyDynamicBundleProducts/RebuyDynamicBundleProducts.d.ts.map +1 -1
  39. package/dist/widgets/RebuyDynamicBundleProducts/Select.d.ts.map +1 -1
  40. package/dist/widgets/RebuyProductAddOns/RebuyProductAddOnCard.d.ts.map +1 -1
  41. package/dist/widgets/RebuyProductAddOns/RebuyProductAddOns.d.ts.map +1 -1
  42. package/dist/widgets/RebuyProductAddOns/types.d.ts.map +1 -1
  43. package/dist/widgets/RebuyProductRecommendations/RebuyProductRecommendations.d.ts.map +1 -1
  44. package/package.json +36 -48
  45. package/src/components/AddToCartBtn/AddToCartBtn.tsx +45 -0
  46. package/src/components/AddToCartBtn/HydrogenAddToCartBtn.tsx +43 -0
  47. package/src/components/AddToCartBtn/HydrogenReactAddToCartBtn.tsx +35 -0
  48. package/src/components/AddToCartBtn/index.ts +1 -0
  49. package/src/components/AddToCartBtn/types.ts +27 -0
  50. package/src/components/ProductCard/ProductCard.tsx +70 -0
  51. package/src/components/ProductCard/index.ts +1 -0
  52. package/src/components/ProductCard/types.ts +10 -0
  53. package/src/components/ProductPrice/ProductPrice.tsx +49 -0
  54. package/src/components/ProductPrice/index.ts +1 -0
  55. package/src/components/Title/Title.tsx +19 -0
  56. package/src/components/Title/index.ts +1 -0
  57. package/src/components/Title/types.ts +7 -0
  58. package/src/components/VariantSelect/VariantSelect.tsx +45 -0
  59. package/src/components/VariantSelect/index.ts +1 -0
  60. package/src/components/VariantSelect/types.ts +6 -0
  61. package/src/context/RebuyContext.tsx +9 -0
  62. package/src/hooks/titleLevel.tsx +42 -0
  63. package/src/index.ts +7 -0
  64. package/src/providers/RebuyHydrogenContextProvider.tsx +112 -0
  65. package/src/providers/RebuyHydrogenReactContextProvider.tsx +192 -0
  66. package/src/providers/types.ts +58 -0
  67. package/src/queries/cart.queries.ts +467 -0
  68. package/src/types/common.ts +8 -0
  69. package/src/types/css.d.ts +11 -0
  70. package/src/types/env.d.ts +12 -0
  71. package/src/types/rebuy.d.ts +31 -0
  72. package/src/types/rebuyCustom.ts +263 -0
  73. package/src/types/rebuySmartCart.ts +188 -0
  74. package/src/types/shopify.ts +142 -0
  75. package/src/types/widgets.ts +29 -0
  76. package/src/utils/convertToRebuyProduct.tsx +319 -0
  77. package/src/utils/createContextParameters.ts +142 -0
  78. package/src/utils/getEncodedAttributes.ts +11 -0
  79. package/src/utils/getRebuyConfig.ts +31 -0
  80. package/src/widgetContainer/RebuyWidgetContainer.tsx +183 -0
  81. package/src/widgets/RebuyCompleteTheLook/RebuyCompleteTheLook.tsx +50 -0
  82. package/src/widgets/RebuyCompleteTheLook/index.ts +1 -0
  83. package/src/widgets/RebuyCompleteTheLook/types.ts +5 -0
  84. package/src/widgets/RebuyDynamicBundleProducts/BundleImages.tsx +62 -0
  85. package/src/widgets/RebuyDynamicBundleProducts/BundlePrice.tsx +93 -0
  86. package/src/widgets/RebuyDynamicBundleProducts/BundleSelection.tsx +65 -0
  87. package/src/widgets/RebuyDynamicBundleProducts/RebuyDynamicBundleProducts.tsx +118 -0
  88. package/src/widgets/RebuyDynamicBundleProducts/Select.tsx +41 -0
  89. package/src/widgets/RebuyDynamicBundleProducts/index.ts +1 -0
  90. package/src/widgets/RebuyDynamicBundleProducts/types.ts +23 -0
  91. package/src/widgets/RebuyProductAddOns/RebuyProductAddOnCard.tsx +66 -0
  92. package/src/widgets/RebuyProductAddOns/RebuyProductAddOns.tsx +218 -0
  93. package/src/widgets/RebuyProductAddOns/index.ts +1 -0
  94. package/src/widgets/RebuyProductAddOns/types.ts +24 -0
  95. package/src/widgets/RebuyProductRecommendations/RebuyProductRecommendations.tsx +50 -0
  96. package/src/widgets/RebuyProductRecommendations/index.ts +1 -0
  97. package/src/widgets/RebuyProductRecommendations/types.ts +5 -0
@@ -0,0 +1,10 @@
1
+ import type { ProductCardTitleLevel } from '~/types/common';
2
+ import type { RebuyProduct } from '~/types/rebuyCustom';
3
+
4
+ export type ProductCardProps = {
5
+ addToCartBtnText?: string;
6
+ addToCartCallback?: () => void; // to allow for custom add to cart logic/opening the cart drawer
7
+ isHydrogenReact?: boolean;
8
+ product: RebuyProduct;
9
+ productCardTitleLevel: ProductCardTitleLevel;
10
+ };
@@ -0,0 +1,49 @@
1
+ import { Money } from '@shopify/hydrogen';
2
+
3
+ import styles from './ProductPrice.module.css';
4
+
5
+ import type { MoneyV2 } from '@shopify/hydrogen-react/storefront-api-types';
6
+ import type { RebuyProductVariant } from '~/types/rebuyCustom';
7
+
8
+ export const RebuyProductPrice = ({
9
+ selectedVariant,
10
+ }: {
11
+ selectedVariant: RebuyProductVariant;
12
+ }) => {
13
+ if (!selectedVariant) return null;
14
+ const { compareAtPriceV2: compareAtPrice, priceV2: price } =
15
+ selectedVariant;
16
+
17
+ const isDiscounted = (
18
+ price: MoneyV2 | null,
19
+ compareAtPrice: MoneyV2 | null
20
+ ) => Number(compareAtPrice?.amount) > Number(price?.amount);
21
+
22
+ const CompareAtPrice = ({
23
+ data: compareAtPrice,
24
+ }: {
25
+ data: MoneyV2 | null;
26
+ }) => {
27
+ return (
28
+ compareAtPrice && (
29
+ <Money
30
+ as="span"
31
+ className={styles.compareAtPrice}
32
+ data={compareAtPrice}
33
+ withoutTrailingZeros
34
+ />
35
+ )
36
+ );
37
+ };
38
+
39
+ return (
40
+ price && (
41
+ <div className={styles.priceContainer}>
42
+ <Money data={price} withoutTrailingZeros />
43
+ {compareAtPrice && isDiscounted(price, compareAtPrice) && (
44
+ <CompareAtPrice data={compareAtPrice} />
45
+ )}
46
+ </div>
47
+ )
48
+ );
49
+ };
@@ -0,0 +1 @@
1
+ export * from './ProductPrice';
@@ -0,0 +1,19 @@
1
+ import type { TitleProps } from '~/components/Title/types';
2
+
3
+ export const Title = ({ level, style, text }: TitleProps) => {
4
+ switch (level) {
5
+ case 'h1':
6
+ return <h1 style={style}>{text}</h1>;
7
+ default:
8
+ case 'h2':
9
+ return <h2 style={style}>{text}</h2>;
10
+ case 'h3':
11
+ return <h3 style={style}>{text}</h3>;
12
+ case 'h4':
13
+ return <h4 style={style}>{text}</h4>;
14
+ case 'h5':
15
+ return <h5 style={style}>{text}</h5>;
16
+ case 'h6':
17
+ return <h6 style={style}>{text}</h6>;
18
+ }
19
+ };
@@ -0,0 +1 @@
1
+ export * from './Title';
@@ -0,0 +1,7 @@
1
+ import type { ProductCardTitleLevel } from '~/types/common';
2
+
3
+ export type TitleProps = {
4
+ level: ProductCardTitleLevel;
5
+ style?: React.CSSProperties;
6
+ text: string;
7
+ };
@@ -0,0 +1,45 @@
1
+ import styles from './VariantSelect.module.css';
2
+
3
+ import type { VariantSelectProps } from '~/components/VariantSelect/types';
4
+ import type { RebuyProduct } from '~/types/rebuyCustom';
5
+
6
+ export const VariantSelect = ({
7
+ handleSelectedVariant,
8
+ product,
9
+ }: VariantSelectProps) => {
10
+ const getOptionsLabel = (product: RebuyProduct) => {
11
+ const options = product.variants.nodes[0].selectedOptions;
12
+ const optionsFromKeys = options ? Object.keys(options[0]) : [];
13
+ const optionsFromValues = options
14
+ ? options.map((option) => option.name)
15
+ : [];
16
+ const useValues = optionsFromKeys.every((key) =>
17
+ ['name', 'value'].includes(key)
18
+ );
19
+
20
+ // Return delimited label for available option(s) e.g. Color / Size, Scent, etc
21
+ return (useValues ? optionsFromValues : optionsFromKeys).join(' / ');
22
+ };
23
+
24
+ return (
25
+ product?.variants.nodes.length > 1 && (
26
+ <div>
27
+ <select
28
+ aria-label="select variant"
29
+ className={styles.select}
30
+ onChange={(e) =>
31
+ handleSelectedVariant(product, e.target.value)
32
+ }
33
+ >
34
+ <optgroup label={getOptionsLabel(product)}>
35
+ {product.variants.nodes.map(({ id, title }) => (
36
+ <option key={id + '-variant'} value={id}>
37
+ {title}
38
+ </option>
39
+ ))}
40
+ </optgroup>
41
+ </select>
42
+ </div>
43
+ )
44
+ );
45
+ };
@@ -0,0 +1 @@
1
+ export * from './VariantSelect';
@@ -0,0 +1,6 @@
1
+ import type { RebuyProduct } from '~/types/rebuyCustom';
2
+
3
+ export type VariantSelectProps = {
4
+ handleSelectedVariant: (product: RebuyProduct, variant_id: string) => void;
5
+ product: RebuyProduct;
6
+ };
@@ -0,0 +1,9 @@
1
+ import { createContext } from 'react';
2
+
3
+ import { type ContextParameters } from '~/types/rebuyCustom';
4
+
5
+ export type RebuyContextType = {
6
+ contextParameters: ContextParameters;
7
+ };
8
+
9
+ export const RebuyContext = createContext<RebuyContextType | null>(null);
@@ -0,0 +1,42 @@
1
+ import { ProductCardTitleLevel } from '~/types/common';
2
+
3
+ // Convert the string header level to enum
4
+ export const getTitleLevel = (
5
+ level: string,
6
+ decreaseLevel: boolean = false
7
+ ): ProductCardTitleLevel => {
8
+ switch (level) {
9
+ case 'h1':
10
+ if (decreaseLevel) {
11
+ return ProductCardTitleLevel.H2;
12
+ }
13
+ return ProductCardTitleLevel.H1;
14
+ case 'h2':
15
+ if (decreaseLevel) {
16
+ return ProductCardTitleLevel.H3;
17
+ }
18
+ return ProductCardTitleLevel.H2;
19
+ case 'h3':
20
+ if (decreaseLevel) {
21
+ return ProductCardTitleLevel.H4;
22
+ }
23
+ return ProductCardTitleLevel.H3;
24
+ case 'h4':
25
+ if (decreaseLevel) {
26
+ return ProductCardTitleLevel.H5;
27
+ }
28
+ return ProductCardTitleLevel.H4;
29
+ case 'h5':
30
+ if (decreaseLevel) {
31
+ return ProductCardTitleLevel.H6;
32
+ }
33
+ return ProductCardTitleLevel.H5;
34
+ case 'h6':
35
+ if (decreaseLevel) {
36
+ return ProductCardTitleLevel.H6;
37
+ }
38
+ return ProductCardTitleLevel.H6;
39
+ default:
40
+ return ProductCardTitleLevel.H2;
41
+ }
42
+ };
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ export * from './providers/RebuyHydrogenContextProvider';
2
+ export * from './providers/RebuyHydrogenReactContextProvider';
3
+ export * from './widgetContainer/RebuyWidgetContainer';
4
+ export * from './widgets/RebuyCompleteTheLook';
5
+ export * from './widgets/RebuyDynamicBundleProducts';
6
+ export * from './widgets/RebuyProductAddOns';
7
+ export * from './widgets/RebuyProductRecommendations';
@@ -0,0 +1,112 @@
1
+ import * as Utilities from '@rebuy/rebuy/utilities';
2
+ import { Await, useLocation } from '@remix-run/react';
3
+ import { useEffect, useMemo, useState } from 'react';
4
+
5
+ import type { CartReturn } from '@shopify/hydrogen';
6
+ import type {
7
+ RebuyHydrogenContextProviderProps,
8
+ RebuyHydrogenProps,
9
+ } from '~/providers/types';
10
+
11
+ import { RebuyContext } from '~/context/RebuyContext';
12
+ import { RebuyConfig } from '~/types/rebuyCustom';
13
+ import { createContextParameters } from '~/utils/createContextParameters';
14
+ import { getRebuyConfig } from '~/utils/getRebuyConfig';
15
+
16
+ const RebuyHydrogenContext = ({
17
+ cartAttributes,
18
+ cartCost,
19
+ cartId,
20
+ cartLines,
21
+ cartNote,
22
+ cartQuantity,
23
+ children,
24
+ }: RebuyHydrogenProps) => {
25
+ const primaryDomain = import.meta.env.PRIMARY_DOMAIN;
26
+ const rebuyKey = import.meta.env.PUBLIC_REBUY_API_KEY;
27
+ const storeDomain = import.meta.env.PUBLIC_STORE_DOMAIN;
28
+
29
+ const [rebuyConfig, setRebuyConfig] = useState<RebuyConfig | null>(null);
30
+ const location = useLocation();
31
+ const queryObject = Utilities.queryStringToObject(location.search);
32
+ const windowUrl = `${primaryDomain}${location.pathname}${location.search}`;
33
+
34
+ // Initialization
35
+ useEffect(() => {
36
+ const initConfig = async () => {
37
+ const config = await getRebuyConfig(rebuyKey, storeDomain);
38
+ setRebuyConfig(config);
39
+ };
40
+
41
+ if (!rebuyConfig?.shop) {
42
+ initConfig();
43
+ }
44
+ }, [rebuyConfig, rebuyKey, storeDomain]);
45
+
46
+ const contextParameters = useMemo(
47
+ () =>
48
+ createContextParameters({
49
+ cacheKey: rebuyConfig?.shop?.cache_key,
50
+ cartAttributes,
51
+ cartId,
52
+ cartLines,
53
+ cartLinesLength: cartLines?.length,
54
+ cartNote: cartNote as string,
55
+ cartSubtotal: cartCost,
56
+ cartTotalQuantity: cartQuantity,
57
+ isHydrogenReact: false,
58
+ queryObject,
59
+ windowUrl,
60
+ }),
61
+ [
62
+ rebuyConfig,
63
+ windowUrl,
64
+ queryObject,
65
+ cartAttributes,
66
+ cartCost,
67
+ cartId,
68
+ cartLines,
69
+ cartQuantity,
70
+ cartNote,
71
+ ]
72
+ );
73
+
74
+ // Static reference (JSON) + memoization
75
+ // ^ prevent re-rendering children when context params are unchanged
76
+ const contextParametersJSON = JSON.stringify(contextParameters);
77
+ const contextValue = useMemo(
78
+ () => ({ contextParameters: JSON.parse(contextParametersJSON) }),
79
+ [contextParametersJSON]
80
+ );
81
+
82
+ return (
83
+ <RebuyContext.Provider value={contextValue}>
84
+ {children}
85
+ </RebuyContext.Provider>
86
+ );
87
+ };
88
+
89
+ export const RebuyHydrogenContextProvider = ({
90
+ cart,
91
+ children,
92
+ }: RebuyHydrogenContextProviderProps) => {
93
+ return (
94
+ <Await resolve={cart}>
95
+ {(resolvedCart) => {
96
+ const cart = resolvedCart as CartReturn;
97
+ return (
98
+ <RebuyHydrogenContext
99
+ cartAttributes={cart?.attributes}
100
+ cartCost={cart?.cost?.subtotalAmount?.amount}
101
+ cartId={cart?.id}
102
+ cartLines={cart?.lines?.nodes}
103
+ cartNote={cart?.note}
104
+ cartQuantity={cart?.totalQuantity}
105
+ >
106
+ {children}
107
+ </RebuyHydrogenContext>
108
+ );
109
+ }}
110
+ </Await>
111
+ );
112
+ };
@@ -0,0 +1,192 @@
1
+ import * as Utilities from '@rebuy/rebuy/utilities';
2
+ import { useLocation } from '@remix-run/react';
3
+ import {
4
+ CartProvider,
5
+ ShopifyProvider,
6
+ useCart,
7
+ } from '@shopify/hydrogen-react';
8
+ import { useEffect, useMemo, useState } from 'react';
9
+
10
+ import type { Attribute } from '@shopify/hydrogen-react/storefront-api-types';
11
+ import type {
12
+ RebuyHydrogenReactContextProviderProps,
13
+ RebuyHydrogenReactProps,
14
+ } from '~/providers/types';
15
+ import type { RebuyConfig } from '~/types/rebuyCustom';
16
+
17
+ import { RebuyContext } from '~/context/RebuyContext';
18
+ import { CART_FRAGMENT } from '~/queries/cart.queries';
19
+ import { createContextParameters } from '~/utils/createContextParameters';
20
+ import { getRebuyConfig } from '~/utils/getRebuyConfig';
21
+
22
+ const RebuyHydrogenReactContext = ({ children }: RebuyHydrogenReactProps) => {
23
+ const primaryDomain = import.meta.env.PRIMARY_DOMAIN;
24
+ const rebuyKey = import.meta.env.PUBLIC_REBUY_API_KEY;
25
+ const storeDomain = import.meta.env.PUBLIC_STORE_DOMAIN;
26
+
27
+ const [rebuyConfig, setRebuyConfig] = useState<RebuyConfig | null>(null);
28
+ const location = useLocation();
29
+ const queryObject = Utilities.queryStringToObject(location.search);
30
+ const windowUrl = `${primaryDomain}${location.pathname}${location.search}`;
31
+
32
+ // This is the cart object from Hydrogen-React
33
+ const cart = useCart();
34
+
35
+ // Initialization
36
+ useEffect(() => {
37
+ const initConfig = async () => {
38
+ const config = await getRebuyConfig(rebuyKey, storeDomain);
39
+ setRebuyConfig(config);
40
+ };
41
+
42
+ if (!rebuyConfig?.shop) {
43
+ initConfig();
44
+ }
45
+ }, [rebuyConfig, rebuyKey, storeDomain]);
46
+
47
+ const contextParameters = useMemo(
48
+ () =>
49
+ createContextParameters({
50
+ cacheKey: rebuyConfig?.shop?.cache_key,
51
+ cartAttributes: cart?.attributes as Attribute[],
52
+ cartId: cart?.id,
53
+ cartLines: cart?.lines,
54
+ cartLinesLength: cart?.lines?.length,
55
+ cartSubtotal: cart?.cost?.subtotalAmount?.amount,
56
+ cartTotalQuantity: cart?.totalQuantity,
57
+ isHydrogenReact: true,
58
+ queryObject,
59
+ windowUrl,
60
+ }),
61
+ [rebuyConfig, windowUrl, queryObject, cart]
62
+ );
63
+
64
+ // Static reference (JSON) + memoization
65
+ // ^ prevent re-rendering children when context params are unchanged
66
+ const contextParametersJSON = JSON.stringify(contextParameters);
67
+ const contextValue = useMemo(
68
+ () => ({ contextParameters: JSON.parse(contextParametersJSON) }),
69
+ [contextParametersJSON]
70
+ );
71
+
72
+ return (
73
+ <RebuyContext.Provider value={contextValue}>
74
+ {children}
75
+ </RebuyContext.Provider>
76
+ );
77
+ };
78
+
79
+ export const RebuyHydrogenReactContextProvider = ({
80
+ cartFragment = CART_FRAGMENT,
81
+ children,
82
+ countryIsoCode = 'US',
83
+ customerAccessToken = '',
84
+ data,
85
+ languageIsoCode = 'EN',
86
+ numCartLines,
87
+ onAttributesUpdate,
88
+ onAttributesUpdateComplete,
89
+ onBuyerIdentityUpdate,
90
+ onBuyerIdentityUpdateComplete,
91
+ onCreate,
92
+ onCreateComplete,
93
+ onDiscountCodesUpdate,
94
+ onDiscountCodesUpdateComplete,
95
+ onLineAdd,
96
+ onLineAddComplete,
97
+ onLineRemove,
98
+ onLineRemoveComplete,
99
+ onLineUpdate,
100
+ onLineUpdateComplete,
101
+ onNoteUpdate,
102
+ onNoteUpdateComplete,
103
+ storefrontApiVersion = '2025-01',
104
+ }: RebuyHydrogenReactContextProviderProps) => {
105
+ const publicStoreDomain = import.meta.env.PUBLIC_STORE_DOMAIN;
106
+ const storefrontId = import.meta.env.PUBLIC_STOREFRONT_ID;
107
+ const storefrontToken = import.meta.env.PUBLIC_STOREFRONT_API_TOKEN || '';
108
+ const adapted = {
109
+ onAttributesUpdate: onAttributesUpdate
110
+ ? () => onAttributesUpdate()
111
+ : undefined,
112
+ onAttributesUpdateComplete: onAttributesUpdateComplete
113
+ ? () => onAttributesUpdateComplete()
114
+ : undefined,
115
+ onBuyerIdentityUpdate: onBuyerIdentityUpdate
116
+ ? () => onBuyerIdentityUpdate()
117
+ : undefined,
118
+ onBuyerIdentityUpdateComplete: onBuyerIdentityUpdateComplete
119
+ ? () => onBuyerIdentityUpdateComplete()
120
+ : undefined,
121
+ onCreate: onCreate ? () => onCreate() : undefined,
122
+ onCreateComplete: onCreateComplete
123
+ ? () => onCreateComplete()
124
+ : undefined,
125
+ onDiscountCodesUpdate: onDiscountCodesUpdate
126
+ ? () => onDiscountCodesUpdate()
127
+ : undefined,
128
+ onDiscountCodesUpdateComplete: onDiscountCodesUpdateComplete
129
+ ? () => onDiscountCodesUpdateComplete()
130
+ : undefined,
131
+ onLineAdd: onLineAdd ? () => onLineAdd() : undefined,
132
+ onLineAddComplete: onLineAddComplete
133
+ ? () => onLineAddComplete()
134
+ : undefined,
135
+ onLineRemove: onLineRemove ? () => onLineRemove() : undefined,
136
+ onLineRemoveComplete: onLineRemoveComplete
137
+ ? () => onLineRemoveComplete()
138
+ : undefined,
139
+ onLineUpdate: onLineUpdate ? () => onLineUpdate() : undefined,
140
+ onLineUpdateComplete: onLineUpdateComplete
141
+ ? () => onLineUpdateComplete()
142
+ : undefined,
143
+ onNoteUpdate: onNoteUpdate ? () => onNoteUpdate() : undefined,
144
+ onNoteUpdateComplete: onNoteUpdateComplete
145
+ ? () => onNoteUpdateComplete()
146
+ : undefined,
147
+ };
148
+
149
+ return (
150
+ <ShopifyProvider
151
+ countryIsoCode={countryIsoCode}
152
+ languageIsoCode={languageIsoCode}
153
+ storeDomain={publicStoreDomain}
154
+ storefrontApiVersion={storefrontApiVersion}
155
+ storefrontId={storefrontId}
156
+ storefrontToken={storefrontToken}
157
+ >
158
+ <CartProvider
159
+ cartFragment={cartFragment}
160
+ countryCode={countryIsoCode}
161
+ customerAccessToken={customerAccessToken}
162
+ data={data}
163
+ languageCode={languageIsoCode}
164
+ numCartLines={numCartLines}
165
+ onAttributesUpdate={adapted.onAttributesUpdate}
166
+ onAttributesUpdateComplete={adapted.onAttributesUpdateComplete}
167
+ onBuyerIdentityUpdate={adapted.onBuyerIdentityUpdate}
168
+ onBuyerIdentityUpdateComplete={
169
+ adapted.onBuyerIdentityUpdateComplete
170
+ }
171
+ onCreate={adapted.onCreate}
172
+ onCreateComplete={adapted.onCreateComplete}
173
+ onDiscountCodesUpdate={adapted.onDiscountCodesUpdate}
174
+ onDiscountCodesUpdateComplete={
175
+ adapted.onDiscountCodesUpdateComplete
176
+ }
177
+ onLineAdd={adapted.onLineAdd}
178
+ onLineAddComplete={adapted.onLineAddComplete}
179
+ onLineRemove={adapted.onLineRemove}
180
+ onLineRemoveComplete={adapted.onLineRemoveComplete}
181
+ onLineUpdate={adapted.onLineUpdate}
182
+ onLineUpdateComplete={adapted.onLineUpdateComplete}
183
+ onNoteUpdate={adapted.onNoteUpdate}
184
+ onNoteUpdateComplete={adapted.onNoteUpdateComplete}
185
+ >
186
+ <RebuyHydrogenReactContext>
187
+ {children}
188
+ </RebuyHydrogenReactContext>
189
+ </CartProvider>
190
+ </ShopifyProvider>
191
+ );
192
+ };
@@ -0,0 +1,58 @@
1
+ import { PartialDeep } from 'type-fest';
2
+
3
+ import type { CartReturn } from '@shopify/hydrogen';
4
+ import type {
5
+ Attribute,
6
+ Cart,
7
+ CartLine,
8
+ ComponentizableCartLine,
9
+ CountryCode,
10
+ LanguageCode,
11
+ Maybe,
12
+ } from '@shopify/hydrogen-react/storefront-api-types';
13
+
14
+ export type RebuyHydrogenContextProviderProps = {
15
+ cart: CartReturn;
16
+ children: React.ReactNode;
17
+ };
18
+
19
+ export type RebuyHydrogenProps = {
20
+ cartAttributes?: Attribute[];
21
+ cartCost?: string;
22
+ cartId?: string;
23
+ cartLines?: (CartLine | ComponentizableCartLine)[];
24
+ cartNote?: Maybe<string>;
25
+ cartQuantity?: number;
26
+ children: React.ReactNode;
27
+ };
28
+
29
+ export type RebuyHydrogenReactProps = {
30
+ children: React.ReactNode;
31
+ };
32
+
33
+ export type RebuyHydrogenReactContextProviderProps = {
34
+ cartFragment?: string;
35
+ children: React.ReactNode;
36
+ countryIsoCode?: CountryCode;
37
+ customerAccessToken?: string;
38
+ data?: PartialDeep<Cart, { recurseIntoArrays: true }>;
39
+ languageIsoCode?: LanguageCode;
40
+ numCartLines?: number;
41
+ onAttributesUpdate?: () => void;
42
+ onAttributesUpdateComplete?: () => void;
43
+ onBuyerIdentityUpdate?: () => void;
44
+ onBuyerIdentityUpdateComplete?: () => void;
45
+ onCreate?: () => void;
46
+ onCreateComplete?: () => void;
47
+ onDiscountCodesUpdate?: () => void;
48
+ onDiscountCodesUpdateComplete?: () => void;
49
+ onLineAdd?: () => void;
50
+ onLineAddComplete?: () => void;
51
+ onLineRemove?: () => void;
52
+ onLineRemoveComplete?: () => void;
53
+ onLineUpdate?: () => void;
54
+ onLineUpdateComplete?: () => void;
55
+ onNoteUpdate?: () => void;
56
+ onNoteUpdateComplete?: () => void;
57
+ storefrontApiVersion?: string;
58
+ };