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

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 (54) hide show
  1. package/package.json +64 -35
  2. package/src/components/AddToCartBtn/AddToCartBtn.tsx +0 -45
  3. package/src/components/AddToCartBtn/HydrogenAddToCartBtn.tsx +0 -43
  4. package/src/components/AddToCartBtn/HydrogenReactAddToCartBtn.tsx +0 -35
  5. package/src/components/AddToCartBtn/index.ts +0 -1
  6. package/src/components/AddToCartBtn/types.ts +0 -27
  7. package/src/components/ProductCard/ProductCard.tsx +0 -70
  8. package/src/components/ProductCard/index.ts +0 -1
  9. package/src/components/ProductCard/types.ts +0 -10
  10. package/src/components/ProductPrice/ProductPrice.tsx +0 -49
  11. package/src/components/ProductPrice/index.ts +0 -1
  12. package/src/components/Title/Title.tsx +0 -19
  13. package/src/components/Title/index.ts +0 -1
  14. package/src/components/Title/types.ts +0 -7
  15. package/src/components/VariantSelect/VariantSelect.tsx +0 -45
  16. package/src/components/VariantSelect/index.ts +0 -1
  17. package/src/components/VariantSelect/types.ts +0 -6
  18. package/src/context/RebuyContext.tsx +0 -9
  19. package/src/hooks/titleLevel.tsx +0 -42
  20. package/src/index.ts +0 -7
  21. package/src/providers/RebuyHydrogenContextProvider.tsx +0 -112
  22. package/src/providers/RebuyHydrogenReactContextProvider.tsx +0 -192
  23. package/src/providers/types.ts +0 -58
  24. package/src/queries/cart.queries.ts +0 -467
  25. package/src/types/common.ts +0 -8
  26. package/src/types/css.d.ts +0 -11
  27. package/src/types/env.d.ts +0 -12
  28. package/src/types/rebuy.d.ts +0 -31
  29. package/src/types/rebuyCustom.ts +0 -263
  30. package/src/types/rebuySmartCart.ts +0 -188
  31. package/src/types/shopify.ts +0 -142
  32. package/src/types/widgets.ts +0 -29
  33. package/src/utils/convertToRebuyProduct.tsx +0 -319
  34. package/src/utils/createContextParameters.ts +0 -142
  35. package/src/utils/getEncodedAttributes.ts +0 -11
  36. package/src/utils/getRebuyConfig.ts +0 -31
  37. package/src/widgetContainer/RebuyWidgetContainer.tsx +0 -183
  38. package/src/widgets/RebuyCompleteTheLook/RebuyCompleteTheLook.tsx +0 -50
  39. package/src/widgets/RebuyCompleteTheLook/index.ts +0 -1
  40. package/src/widgets/RebuyCompleteTheLook/types.ts +0 -5
  41. package/src/widgets/RebuyDynamicBundleProducts/BundleImages.tsx +0 -62
  42. package/src/widgets/RebuyDynamicBundleProducts/BundlePrice.tsx +0 -93
  43. package/src/widgets/RebuyDynamicBundleProducts/BundleSelection.tsx +0 -65
  44. package/src/widgets/RebuyDynamicBundleProducts/RebuyDynamicBundleProducts.tsx +0 -118
  45. package/src/widgets/RebuyDynamicBundleProducts/Select.tsx +0 -41
  46. package/src/widgets/RebuyDynamicBundleProducts/index.ts +0 -1
  47. package/src/widgets/RebuyDynamicBundleProducts/types.ts +0 -23
  48. package/src/widgets/RebuyProductAddOns/RebuyProductAddOnCard.tsx +0 -66
  49. package/src/widgets/RebuyProductAddOns/RebuyProductAddOns.tsx +0 -218
  50. package/src/widgets/RebuyProductAddOns/index.ts +0 -1
  51. package/src/widgets/RebuyProductAddOns/types.ts +0 -24
  52. package/src/widgets/RebuyProductRecommendations/RebuyProductRecommendations.tsx +0 -50
  53. package/src/widgets/RebuyProductRecommendations/index.ts +0 -1
  54. package/src/widgets/RebuyProductRecommendations/types.ts +0 -5
@@ -1,112 +0,0 @@
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
- };
@@ -1,192 +0,0 @@
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
- };
@@ -1,58 +0,0 @@
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
- };