@rebuy/rebuy-hydrogen 3.0.0-beta.1 → 3.0.0-beta.10

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 (143) hide show
  1. package/README.md +0 -2
  2. package/dist/components/AddToCartBtn/AddToCartBtn.d.ts +3 -0
  3. package/dist/components/AddToCartBtn/AddToCartBtn.d.ts.map +1 -0
  4. package/dist/components/AddToCartBtn/HydrogenAddToCartBtn.d.ts +3 -0
  5. package/dist/components/AddToCartBtn/HydrogenAddToCartBtn.d.ts.map +1 -0
  6. package/dist/components/AddToCartBtn/HydrogenReactAddToCartBtn.d.ts +3 -0
  7. package/dist/components/AddToCartBtn/HydrogenReactAddToCartBtn.d.ts.map +1 -0
  8. package/dist/components/AddToCartBtn/index.d.ts +2 -0
  9. package/dist/components/AddToCartBtn/index.d.ts.map +1 -0
  10. package/{src/components/AddToCartBtn/types.ts → dist/components/AddToCartBtn/types.d.ts} +1 -2
  11. package/dist/components/AddToCartBtn/types.d.ts.map +1 -0
  12. package/dist/components/ProductCard/ProductCard.d.ts +3 -0
  13. package/dist/components/ProductCard/ProductCard.d.ts.map +1 -0
  14. package/dist/components/ProductCard/index.d.ts +2 -0
  15. package/dist/components/ProductCard/index.d.ts.map +1 -0
  16. package/{src/components/ProductCard/types.ts → dist/components/ProductCard/types.d.ts} +2 -2
  17. package/dist/components/ProductCard/types.d.ts.map +1 -0
  18. package/dist/components/ProductPrice/ProductPrice.d.ts +5 -0
  19. package/dist/components/ProductPrice/ProductPrice.d.ts.map +1 -0
  20. package/dist/components/ProductPrice/index.d.ts +2 -0
  21. package/dist/components/ProductPrice/index.d.ts.map +1 -0
  22. package/dist/components/Title/Title.d.ts +3 -0
  23. package/dist/components/Title/Title.d.ts.map +1 -0
  24. package/dist/components/Title/index.d.ts +2 -0
  25. package/dist/components/Title/index.d.ts.map +1 -0
  26. package/{src/components/Title/types.ts → dist/components/Title/types.d.ts} +1 -1
  27. package/dist/components/Title/types.d.ts.map +1 -0
  28. package/dist/components/VariantSelect/VariantSelect.d.ts +3 -0
  29. package/dist/components/VariantSelect/VariantSelect.d.ts.map +1 -0
  30. package/dist/components/VariantSelect/index.d.ts +2 -0
  31. package/dist/components/VariantSelect/index.d.ts.map +1 -0
  32. package/{src/components/VariantSelect/types.ts → dist/components/VariantSelect/types.d.ts} +1 -1
  33. package/dist/components/VariantSelect/types.d.ts.map +1 -0
  34. package/{src/context/RebuyContext.tsx → dist/context/RebuyContext.d.ts} +2 -5
  35. package/dist/context/RebuyContext.d.ts.map +1 -0
  36. package/dist/hooks/titleLevel.d.ts +3 -0
  37. package/dist/hooks/titleLevel.d.ts.map +1 -0
  38. package/dist/index.css +296 -0
  39. package/dist/index.css.map +7 -0
  40. package/{src/index.ts → dist/index.d.ts} +1 -0
  41. package/dist/index.d.ts.map +1 -0
  42. package/dist/index.js +1967 -0
  43. package/dist/index.js.map +7 -0
  44. package/dist/index.mjs +1935 -0
  45. package/dist/index.mjs.map +7 -0
  46. package/dist/providers/RebuyHydrogenContextProvider.d.ts +3 -0
  47. package/dist/providers/RebuyHydrogenContextProvider.d.ts.map +1 -0
  48. package/dist/providers/RebuyHydrogenReactContextProvider.d.ts +3 -0
  49. package/dist/providers/RebuyHydrogenReactContextProvider.d.ts.map +1 -0
  50. package/{src/providers/types.ts → dist/providers/types.d.ts} +12 -16
  51. package/dist/providers/types.d.ts.map +1 -0
  52. package/dist/queries/cart.queries.d.ts +5 -0
  53. package/dist/queries/cart.queries.d.ts.map +1 -0
  54. package/dist/types/common.d.ts +9 -0
  55. package/dist/types/common.d.ts.map +1 -0
  56. package/{src/types/rebuyCustom.ts → dist/types/rebuyCustom.d.ts} +12 -35
  57. package/dist/types/rebuyCustom.d.ts.map +1 -0
  58. package/{src/types/rebuySmartCart.ts → dist/types/rebuySmartCart.d.ts} +1 -5
  59. package/dist/types/rebuySmartCart.d.ts.map +1 -0
  60. package/dist/types/shopify.d.ts +85 -0
  61. package/dist/types/shopify.d.ts.map +1 -0
  62. package/{src/types/widgets.ts → dist/types/widgets.d.ts} +2 -9
  63. package/dist/types/widgets.d.ts.map +1 -0
  64. package/dist/utils/convertToRebuyProduct.d.ts +156 -0
  65. package/dist/utils/convertToRebuyProduct.d.ts.map +1 -0
  66. package/dist/utils/createContextParameters.d.ts +3 -0
  67. package/dist/utils/createContextParameters.d.ts.map +1 -0
  68. package/dist/utils/getEncodedAttributes.d.ts +3 -0
  69. package/dist/utils/getEncodedAttributes.d.ts.map +1 -0
  70. package/dist/utils/getRebuyConfig.d.ts +3 -0
  71. package/dist/utils/getRebuyConfig.d.ts.map +1 -0
  72. package/dist/widgetContainer/RebuyWidgetContainer.d.ts +8 -0
  73. package/dist/widgetContainer/RebuyWidgetContainer.d.ts.map +1 -0
  74. package/dist/widgets/RebuyCompleteTheLook/RebuyCompleteTheLook.d.ts +3 -0
  75. package/dist/widgets/RebuyCompleteTheLook/RebuyCompleteTheLook.d.ts.map +1 -0
  76. package/{src/widgets/RebuyCompleteTheLook/index.ts → dist/widgets/RebuyCompleteTheLook/index.d.ts} +1 -0
  77. package/dist/widgets/RebuyCompleteTheLook/index.d.ts.map +1 -0
  78. package/{src/widgets/RebuyCompleteTheLook/types.ts → dist/widgets/RebuyCompleteTheLook/types.d.ts} +1 -1
  79. package/dist/widgets/RebuyCompleteTheLook/types.d.ts.map +1 -0
  80. package/dist/widgets/RebuyDynamicBundleProducts/BundleImages.d.ts +5 -0
  81. package/dist/widgets/RebuyDynamicBundleProducts/BundleImages.d.ts.map +1 -0
  82. package/dist/widgets/RebuyDynamicBundleProducts/BundlePrice.d.ts +5 -0
  83. package/dist/widgets/RebuyDynamicBundleProducts/BundlePrice.d.ts.map +1 -0
  84. package/dist/widgets/RebuyDynamicBundleProducts/BundleSelection.d.ts +3 -0
  85. package/dist/widgets/RebuyDynamicBundleProducts/BundleSelection.d.ts.map +1 -0
  86. package/dist/widgets/RebuyDynamicBundleProducts/RebuyDynamicBundleProducts.d.ts +3 -0
  87. package/dist/widgets/RebuyDynamicBundleProducts/RebuyDynamicBundleProducts.d.ts.map +1 -0
  88. package/dist/widgets/RebuyDynamicBundleProducts/Select.d.ts +3 -0
  89. package/dist/widgets/RebuyDynamicBundleProducts/Select.d.ts.map +1 -0
  90. package/{src/widgets/RebuyDynamicBundleProducts/index.ts → dist/widgets/RebuyDynamicBundleProducts/index.d.ts} +1 -0
  91. package/dist/widgets/RebuyDynamicBundleProducts/index.d.ts.map +1 -0
  92. package/{src/widgets/RebuyDynamicBundleProducts/types.ts → dist/widgets/RebuyDynamicBundleProducts/types.d.ts} +1 -5
  93. package/dist/widgets/RebuyDynamicBundleProducts/types.d.ts.map +1 -0
  94. package/dist/widgets/RebuyProductAddOns/RebuyProductAddOnCard.d.ts +3 -0
  95. package/dist/widgets/RebuyProductAddOns/RebuyProductAddOnCard.d.ts.map +1 -0
  96. package/dist/widgets/RebuyProductAddOns/RebuyProductAddOns.d.ts +3 -0
  97. package/dist/widgets/RebuyProductAddOns/RebuyProductAddOns.d.ts.map +1 -0
  98. package/{src/widgets/RebuyProductAddOns/index.ts → dist/widgets/RebuyProductAddOns/index.d.ts} +1 -0
  99. package/dist/widgets/RebuyProductAddOns/index.d.ts.map +1 -0
  100. package/{src/widgets/RebuyProductAddOns/types.ts → dist/widgets/RebuyProductAddOns/types.d.ts} +2 -7
  101. package/dist/widgets/RebuyProductAddOns/types.d.ts.map +1 -0
  102. package/dist/widgets/RebuyProductRecommendations/RebuyProductRecommendations.d.ts +3 -0
  103. package/dist/widgets/RebuyProductRecommendations/RebuyProductRecommendations.d.ts.map +1 -0
  104. package/{src/widgets/RebuyProductRecommendations/index.ts → dist/widgets/RebuyProductRecommendations/index.d.ts} +1 -0
  105. package/dist/widgets/RebuyProductRecommendations/index.d.ts.map +1 -0
  106. package/{src/widgets/RebuyProductRecommendations/types.ts → dist/widgets/RebuyProductRecommendations/types.d.ts} +1 -1
  107. package/dist/widgets/RebuyProductRecommendations/types.d.ts.map +1 -0
  108. package/package.json +48 -36
  109. package/src/components/AddToCartBtn/AddToCartBtn.tsx +0 -45
  110. package/src/components/AddToCartBtn/HydrogenAddToCartBtn.tsx +0 -43
  111. package/src/components/AddToCartBtn/HydrogenReactAddToCartBtn.tsx +0 -35
  112. package/src/components/AddToCartBtn/index.ts +0 -1
  113. package/src/components/ProductCard/ProductCard.tsx +0 -70
  114. package/src/components/ProductCard/index.ts +0 -1
  115. package/src/components/ProductPrice/ProductPrice.tsx +0 -49
  116. package/src/components/ProductPrice/index.ts +0 -1
  117. package/src/components/Title/Title.tsx +0 -20
  118. package/src/components/Title/index.ts +0 -1
  119. package/src/components/VariantSelect/VariantSelect.tsx +0 -45
  120. package/src/components/VariantSelect/index.ts +0 -1
  121. package/src/hooks/titleLevel.tsx +0 -42
  122. package/src/providers/RebuyHydrogenContextProvider.tsx +0 -112
  123. package/src/providers/RebuyHydrogenReactContextProvider.tsx +0 -192
  124. package/src/queries/cart.queries.ts +0 -467
  125. package/src/types/common.ts +0 -8
  126. package/src/types/css.d.ts +0 -11
  127. package/src/types/env.d.ts +0 -12
  128. package/src/types/rebuy.d.ts +0 -31
  129. package/src/types/shopify.ts +0 -142
  130. package/src/utils/convertToRebuyProduct.tsx +0 -319
  131. package/src/utils/createContextParameters.ts +0 -142
  132. package/src/utils/getEncodedAttributes.ts +0 -11
  133. package/src/utils/getRebuyConfig.ts +0 -31
  134. package/src/widgetContainer/RebuyWidgetContainer.tsx +0 -183
  135. package/src/widgets/RebuyCompleteTheLook/RebuyCompleteTheLook.tsx +0 -50
  136. package/src/widgets/RebuyDynamicBundleProducts/BundleImages.tsx +0 -62
  137. package/src/widgets/RebuyDynamicBundleProducts/BundlePrice.tsx +0 -93
  138. package/src/widgets/RebuyDynamicBundleProducts/BundleSelection.tsx +0 -65
  139. package/src/widgets/RebuyDynamicBundleProducts/RebuyDynamicBundleProducts.tsx +0 -118
  140. package/src/widgets/RebuyDynamicBundleProducts/Select.tsx +0 -41
  141. package/src/widgets/RebuyProductAddOns/RebuyProductAddOnCard.tsx +0 -66
  142. package/src/widgets/RebuyProductAddOns/RebuyProductAddOns.tsx +0 -218
  143. package/src/widgets/RebuyProductRecommendations/RebuyProductRecommendations.tsx +0 -50
@@ -1,142 +0,0 @@
1
- import type {
2
- Collection,
3
- Image,
4
- Maybe,
5
- MoneyV2,
6
- PageInfo,
7
- Product,
8
- ProductOption,
9
- ProductOptionValue,
10
- ProductOptionValueSwatch,
11
- ProductVariant,
12
- SelectedOption,
13
- Seo,
14
- } from '@shopify/hydrogen-react/storefront-api-types';
15
- import type { RebuyProductVariant } from './rebuyCustom';
16
-
17
- export type HydrogenProduct = Pick<
18
- Product,
19
- | 'id'
20
- | 'title'
21
- | 'vendor'
22
- | 'handle'
23
- | 'descriptionHtml'
24
- | 'description'
25
- | 'encodedVariantExistence'
26
- | 'encodedVariantAvailability'
27
- > & {
28
- adjacentVariants: (Pick<
29
- ProductVariant,
30
- 'availableForSale' | 'id' | 'sku' | 'title'
31
- > & {
32
- compareAtPrice?: Maybe<Pick<MoneyV2, 'amount' | 'currencyCode'>>;
33
- image?: Maybe<
34
- { __typename: 'Image' } & Pick<
35
- Image,
36
- 'id' | 'url' | 'altText' | 'width' | 'height'
37
- >
38
- >;
39
- price: Pick<MoneyV2, 'amount' | 'currencyCode'>;
40
- product: Pick<Product, 'title' | 'handle'>;
41
- selectedOptions: Pick<SelectedOption, 'name' | 'value'>[];
42
- unitPrice?: Maybe<Pick<MoneyV2, 'amount' | 'currencyCode'>>;
43
- })[];
44
- collections: {
45
- nodes: {
46
- handle: string;
47
- }[];
48
- };
49
- featuredImage?: {
50
- altText: string | null;
51
- height: number;
52
- id: string;
53
- url: string;
54
- width: number;
55
- };
56
- images: {
57
- altText: string | null;
58
- height: number;
59
- id: string;
60
- url: string;
61
- width: number;
62
- }[];
63
- options: (Pick<ProductOption, 'name'> & {
64
- optionValues: (Pick<ProductOptionValue, 'name'> & {
65
- firstSelectableVariant?: Maybe<
66
- Pick<
67
- ProductVariant,
68
- 'availableForSale' | 'id' | 'sku' | 'title'
69
- > & {
70
- compareAtPrice?: Maybe<
71
- Pick<MoneyV2, 'amount' | 'currencyCode'>
72
- >;
73
- image?: Maybe<
74
- { __typename: 'Image' } & Pick<
75
- Image,
76
- 'id' | 'url' | 'altText' | 'width' | 'height'
77
- >
78
- >;
79
- price: Pick<MoneyV2, 'amount' | 'currencyCode'>;
80
- product: Pick<Product, 'title' | 'handle'>;
81
- selectedOptions: Pick<SelectedOption, 'name' | 'value'>[];
82
- unitPrice?: Maybe<Pick<MoneyV2, 'amount' | 'currencyCode'>>;
83
- }
84
- >;
85
- swatch?: Maybe<
86
- Pick<ProductOptionValueSwatch, 'color'> & {
87
- image?: Maybe<{
88
- previewImage?: Maybe<Pick<Image, 'url'>>;
89
- }>;
90
- }
91
- >;
92
- })[];
93
- })[];
94
- priceRange: {
95
- maxVariantPrice: MoneyV2;
96
- minVariantPrice: MoneyV2;
97
- };
98
- selectedOrFirstAvailableVariant?: HydrogenProductVariant;
99
- selectedVariant?: HydrogenProductVariant;
100
- seo: Pick<Seo, 'description' | 'title'>;
101
- variants?: {
102
- nodes: RebuyProductVariant[];
103
- };
104
- };
105
-
106
- export type HydrogenProductVariant = Pick<
107
- ProductVariant,
108
- 'availableForSale' | 'id' | 'sku' | 'title'
109
- > & {
110
- compareAtPrice?: Maybe<Pick<MoneyV2, 'amount' | 'currencyCode'>>;
111
- image?: Maybe<
112
- { __typename: 'Image' } & Pick<
113
- Image,
114
- 'id' | 'url' | 'altText' | 'width' | 'height'
115
- >
116
- >;
117
- price: Pick<MoneyV2, 'amount' | 'currencyCode'>;
118
- product: Pick<Product, 'title' | 'handle'>;
119
- selectedOptions: Pick<SelectedOption, 'name' | 'value'>[];
120
- unitPrice?: Maybe<Pick<MoneyV2, 'amount' | 'currencyCode'>>;
121
- };
122
-
123
- export type HydrogenCollection = Pick<
124
- Collection,
125
- 'id' | 'handle' | 'title' | 'description'
126
- > & {
127
- products: {
128
- nodes: (Pick<Product, 'id' | 'handle' | 'title'> & {
129
- featuredImage?: Maybe<
130
- Pick<Image, 'id' | 'altText' | 'url' | 'width' | 'height'>
131
- >;
132
- priceRange: {
133
- maxVariantPrice: Pick<MoneyV2, 'amount' | 'currencyCode'>;
134
- minVariantPrice: Pick<MoneyV2, 'amount' | 'currencyCode'>;
135
- };
136
- })[];
137
- pageInfo: Pick<
138
- PageInfo,
139
- 'hasPreviousPage' | 'hasNextPage' | 'endCursor' | 'startCursor'
140
- >;
141
- };
142
- };
@@ -1,319 +0,0 @@
1
- import type { RebuyProductVariant } from '~/types/rebuyCustom';
2
- import type { HydrogenProduct } from '~/types/shopify';
3
-
4
- export const convertToRebuyProduct = (
5
- isHydrogenReact: boolean,
6
- product?: HydrogenProduct
7
- ) => {
8
- const mainProductVariants: RebuyProductVariant[] = isHydrogenReact
9
- ? product?.variants?.nodes?.map((variant) => {
10
- return {
11
- ...variant,
12
- };
13
- }) || []
14
- : product?.adjacentVariants.map((variant) => {
15
- return {
16
- availableForSale: variant.availableForSale,
17
- compareAtPriceV2: {
18
- amount: variant.compareAtPrice?.amount || '',
19
- currencyCode:
20
- variant.compareAtPrice?.currencyCode || 'USD',
21
- },
22
- id: variant.id,
23
- image: {
24
- altText: variant.image?.altText || '',
25
- height: variant.image?.height || 100,
26
- id: variant.image?.id || '',
27
- url: variant.image?.url || '',
28
- width: variant.image?.width || 100,
29
- },
30
- priceV2: {
31
- amount: variant.price.amount || '',
32
- currencyCode: variant.price.currencyCode || 'USD',
33
- },
34
- product: {
35
- handle: product.handle,
36
- id: product.id,
37
- title: product.title,
38
- vendor: product.vendor,
39
- },
40
- selectedOptions: variant.selectedOptions,
41
- sku: variant.sku || '',
42
- title: variant.title || '',
43
- };
44
- }) || [];
45
-
46
- return isHydrogenReact
47
- ? {
48
- collections: {
49
- nodes:
50
- product?.collections.nodes.map((collection) => {
51
- return {
52
- handle: collection.handle,
53
- };
54
- }) || [],
55
- },
56
- compareAtPriceRange: {
57
- maxVariantCompareAtPrice: null,
58
- minVariantCompareAtPrice: null,
59
- },
60
- description: product?.description || '',
61
- descriptionHtml: product?.descriptionHtml || '',
62
- featuredImage: {
63
- altText: product?.featuredImage?.altText || '',
64
- height: product?.featuredImage?.height || 100,
65
- id: product?.featuredImage?.id || '',
66
- url: product?.featuredImage?.url || '',
67
- width: product?.featuredImage?.width || 100,
68
- },
69
- handle: product?.handle || '',
70
- id: product?.id || '',
71
- images: [
72
- { altText: '', height: 100, id: '', url: '', width: 100 },
73
- ],
74
- media: [],
75
- metafields: [],
76
- options: [],
77
- priceRange: product?.priceRange || {
78
- maxVariantPrice: { amount: '0', currencyCode: 'USD' },
79
- minVariantPrice: { amount: '0', currencyCode: 'USD' },
80
- },
81
- selected: true,
82
- selectedOptions:
83
- product?.selectedVariant?.selectedOptions?.reduce(
84
- (acc, option) => {
85
- return { ...acc, [option.name]: option.value };
86
- },
87
- {}
88
- ) || {},
89
- selectedSellingPlan: {},
90
- selectedSellingPlanAllocation: {},
91
- selectedVariant: {
92
- availableForSale:
93
- product?.selectedVariant?.availableForSale || false,
94
- compareAtPriceV2: {
95
- amount:
96
- product?.selectedVariant?.compareAtPrice?.amount ||
97
- '',
98
- currencyCode:
99
- product?.selectedVariant?.compareAtPrice
100
- ?.currencyCode || 'USD',
101
- },
102
- id: product?.selectedVariant?.id || '',
103
- image: {
104
- altText: product?.selectedVariant?.image?.altText || '',
105
- height: product?.selectedVariant?.image?.height || 100,
106
- id: product?.selectedVariant?.image?.id || '',
107
- url: product?.selectedVariant?.image?.url || '',
108
- width: product?.selectedVariant?.image?.width || 100,
109
- },
110
- priceV2: {
111
- amount: product?.selectedVariant?.price.amount || '',
112
- currencyCode:
113
- product?.selectedVariant?.price.currencyCode || 'USD',
114
- },
115
- product: {
116
- handle: product?.handle || '',
117
- id: product?.id || '',
118
- title: product?.title || '',
119
- vendor: product?.vendor || '',
120
- },
121
- selectedOptions:
122
- product?.selectedVariant?.selectedOptions || [],
123
- sku: product?.selectedVariant?.sku || '',
124
- title: product?.selectedVariant?.title || '',
125
- },
126
- sellingPlanGroups: [],
127
- seo: {
128
- description: product?.seo?.description || '',
129
- title: product?.seo?.title || '',
130
- },
131
- title: product?.title || '',
132
- variants: {
133
- nodes: mainProductVariants,
134
- },
135
- vendor: product?.vendor || '',
136
- }
137
- : {
138
- collections: {
139
- nodes: [],
140
- },
141
- compareAtPriceRange: {
142
- maxVariantCompareAtPrice: null,
143
- minVariantCompareAtPrice: null,
144
- },
145
- description: product?.description || '',
146
- descriptionHtml: product?.descriptionHtml || '',
147
- featuredImage: {
148
- altText:
149
- product?.selectedOrFirstAvailableVariant?.image
150
- ?.altText || '',
151
- height:
152
- product?.selectedOrFirstAvailableVariant?.image?.height ||
153
- 100,
154
- id: product?.selectedOrFirstAvailableVariant?.image?.id || '',
155
- url:
156
- product?.selectedOrFirstAvailableVariant?.image?.url ||
157
- '',
158
- width:
159
- product?.selectedOrFirstAvailableVariant?.image?.width ||
160
- 100,
161
- },
162
- handle: product?.handle || '',
163
- id: product?.id || '',
164
- images: [
165
- {
166
- altText:
167
- product?.selectedOrFirstAvailableVariant?.image
168
- ?.altText || '',
169
- height:
170
- product?.selectedOrFirstAvailableVariant?.image
171
- ?.height || 100,
172
- id:
173
- product?.selectedOrFirstAvailableVariant?.image?.id ||
174
- '',
175
- url:
176
- product?.selectedOrFirstAvailableVariant?.image
177
- ?.url || '',
178
- width:
179
- product?.selectedOrFirstAvailableVariant?.image
180
- ?.width || 100,
181
- },
182
- ],
183
- media: [],
184
- metafields: [],
185
- options: [],
186
- priceRange: product?.priceRange || {
187
- maxVariantPrice: { amount: '0', currencyCode: 'USD' },
188
- minVariantPrice: { amount: '0', currencyCode: 'USD' },
189
- },
190
- selected: true,
191
- selectedOptions:
192
- product?.selectedOrFirstAvailableVariant?.selectedOptions?.reduce(
193
- (acc, option) => {
194
- return { ...acc, [option.name]: option.value };
195
- },
196
- {}
197
- ) || {},
198
- selectedSellingPlan: {},
199
- selectedSellingPlanAllocation: {},
200
- selectedVariant: {
201
- availableForSale:
202
- product?.selectedOrFirstAvailableVariant
203
- ?.availableForSale || false,
204
- compareAtPriceV2: {
205
- amount:
206
- product?.selectedOrFirstAvailableVariant
207
- ?.compareAtPrice?.amount || '',
208
- currencyCode:
209
- product?.selectedOrFirstAvailableVariant
210
- ?.compareAtPrice?.currencyCode || 'USD',
211
- },
212
- id: product?.selectedOrFirstAvailableVariant?.id || '',
213
- image: {
214
- altText:
215
- product?.selectedOrFirstAvailableVariant?.image
216
- ?.altText || '',
217
- height:
218
- product?.selectedOrFirstAvailableVariant?.image
219
- ?.height || 100,
220
- id:
221
- product?.selectedOrFirstAvailableVariant?.image?.id ||
222
- '',
223
- url:
224
- product?.selectedOrFirstAvailableVariant?.image
225
- ?.url || '',
226
- width:
227
- product?.selectedOrFirstAvailableVariant?.image
228
- ?.width || 100,
229
- },
230
- priceV2: {
231
- amount:
232
- product?.selectedOrFirstAvailableVariant?.price
233
- .amount || '',
234
- currencyCode:
235
- product?.selectedOrFirstAvailableVariant?.price
236
- .currencyCode || 'USD',
237
- },
238
- product: {
239
- handle: product?.handle || '',
240
- id: product?.id || '',
241
- title: product?.title || '',
242
- vendor: product?.vendor || '',
243
- },
244
- selectedOptions:
245
- product?.selectedOrFirstAvailableVariant
246
- ?.selectedOptions || [],
247
- sku: product?.selectedOrFirstAvailableVariant?.sku || '',
248
- title: product?.selectedOrFirstAvailableVariant?.title || '',
249
- },
250
- sellingPlanGroups: [],
251
- seo: {
252
- description: null,
253
- title: null,
254
- },
255
- title: product?.title || '',
256
- variants: {
257
- nodes: [
258
- {
259
- availableForSale:
260
- product?.selectedOrFirstAvailableVariant
261
- ?.availableForSale || false,
262
- compareAtPriceV2: {
263
- amount:
264
- product?.selectedOrFirstAvailableVariant
265
- ?.compareAtPrice?.amount || '',
266
- currencyCode:
267
- product?.selectedOrFirstAvailableVariant
268
- ?.compareAtPrice?.currencyCode || 'USD',
269
- },
270
- id:
271
- product?.selectedOrFirstAvailableVariant?.id ||
272
- '',
273
- image: {
274
- altText:
275
- product?.selectedOrFirstAvailableVariant
276
- ?.image?.altText || '',
277
- height:
278
- product?.selectedOrFirstAvailableVariant
279
- ?.image?.height || 100,
280
- id:
281
- product?.selectedOrFirstAvailableVariant
282
- ?.image?.id || '',
283
- url:
284
- product?.selectedOrFirstAvailableVariant
285
- ?.image?.url || '',
286
- width:
287
- product?.selectedOrFirstAvailableVariant
288
- ?.image?.width || 100,
289
- },
290
- priceV2: {
291
- amount:
292
- product?.selectedOrFirstAvailableVariant
293
- ?.price.amount || '',
294
- currencyCode:
295
- product?.selectedOrFirstAvailableVariant
296
- ?.price.currencyCode || 'USD',
297
- },
298
- product: {
299
- handle: product?.handle || '',
300
- id: product?.id || '',
301
- title: product?.title || '',
302
- vendor: product?.vendor || '',
303
- },
304
- selectedOptions:
305
- product?.selectedOrFirstAvailableVariant
306
- ?.selectedOptions || [],
307
- sku:
308
- product?.selectedOrFirstAvailableVariant?.sku ||
309
- '',
310
- title:
311
- product?.selectedOrFirstAvailableVariant?.title ||
312
- '',
313
- },
314
- ...mainProductVariants,
315
- ],
316
- },
317
- vendor: product?.vendor || '',
318
- };
319
- };
@@ -1,142 +0,0 @@
1
- import * as Utilities from '@rebuy/rebuy/utilities';
2
-
3
- import type { Attribute } from '@shopify/hydrogen-react/storefront-api-types';
4
- import type {
5
- CartContext,
6
- CartItem,
7
- ContextParameters,
8
- RebuyContextProps,
9
- } from '~/types/rebuyCustom';
10
-
11
- import { getEncodedAttributes } from '~/utils/getEncodedAttributes';
12
-
13
- export const createContextParameters = ({
14
- cacheKey,
15
- cartAttributes,
16
- cartId,
17
- cartLines,
18
- cartLinesLength,
19
- cartNote,
20
- cartSubtotal,
21
- cartTotalQuantity,
22
- isHydrogenReact,
23
- queryObject,
24
- windowUrl,
25
- }: RebuyContextProps) => {
26
- const contextParameters: ContextParameters = {
27
- cache_key: cacheKey,
28
- cart_count: 0,
29
- cart_item_count: 0,
30
- cart_line_count: 0,
31
- cart_subtotal: 0,
32
- isHydrogenReact,
33
- time: '',
34
- url: windowUrl,
35
- };
36
-
37
- const cartContext: CartContext = {
38
- attributes: '',
39
- item_count: 0,
40
- items: [],
41
- line_count: 0,
42
- note: '',
43
- subtotal: 0,
44
- token: '',
45
- };
46
- if (Object.prototype.hasOwnProperty.call(queryObject, 'time')) {
47
- contextParameters.time = queryObject.time;
48
- }
49
-
50
- // Set Cart: token
51
- if (cartId) {
52
- cartContext.token = Utilities.getIdFromGraphUrl(cartId, 'Cart');
53
- contextParameters.cart_token = Utilities.getIdFromGraphUrl(
54
- cartId,
55
- 'Cart'
56
- );
57
- }
58
-
59
- // Set Cart: subtotal
60
- if (cartSubtotal) {
61
- cartContext.subtotal = Utilities.amountToCents(
62
- parseFloat(cartSubtotal)
63
- );
64
- contextParameters.cart_subtotal = Utilities.amountToCents(
65
- parseFloat(cartSubtotal)
66
- );
67
- }
68
-
69
- // Set Cart: line count
70
- if (cartLinesLength) {
71
- const totalLines = cartLinesLength;
72
- cartContext.line_count = totalLines;
73
- contextParameters.cart_count = totalLines;
74
- contextParameters.cart_line_count = totalLines;
75
- }
76
-
77
- // Set Cart: item count
78
- if (cartTotalQuantity) {
79
- cartContext.item_count = cartTotalQuantity;
80
- contextParameters.cart_item_count = cartTotalQuantity;
81
- }
82
-
83
- if (cartLines) {
84
- cartContext.items = [];
85
-
86
- for (const cartItem of cartLines) {
87
- const item: CartItem = {
88
- attributes: [],
89
- product_id: '',
90
- properties: '',
91
- quantity: cartItem?.quantity,
92
- variant_id: '',
93
- };
94
-
95
- if (cartItem?.merchandise?.product?.id) {
96
- item.product_id = Utilities.getIdFromGraphUrl(
97
- cartItem.merchandise.product.id,
98
- 'Product'
99
- );
100
- }
101
-
102
- if (cartItem?.merchandise?.id) {
103
- item.variant_id = Utilities.getIdFromGraphUrl(
104
- cartItem.merchandise.id,
105
- 'ProductVariant'
106
- );
107
- }
108
-
109
- if (cartItem?.attributes?.length) {
110
- const validAttributes = cartItem.attributes.filter(
111
- (attr: Attribute) =>
112
- attr !== undefined &&
113
- typeof attr.key === 'string' &&
114
- typeof attr.value === 'string'
115
- );
116
- item.properties = getEncodedAttributes(validAttributes);
117
- }
118
- cartContext.items.push(item);
119
- }
120
- }
121
-
122
- // Set Cart: attributes
123
- if (cartAttributes) {
124
- const validAttributes = cartAttributes.filter(
125
- (attr): attr is Attribute =>
126
- attr !== undefined &&
127
- typeof attr.key === 'string' &&
128
- typeof attr.value === 'string'
129
- );
130
- cartContext.attributes = getEncodedAttributes(validAttributes);
131
- }
132
-
133
- // Set Cart: notes
134
- if (cartNote) {
135
- cartContext.note = cartNote;
136
- }
137
-
138
- // Set cart
139
- contextParameters.cart = cartContext;
140
-
141
- return contextParameters;
142
- };
@@ -1,11 +0,0 @@
1
- import type { Attribute } from '@shopify/hydrogen-react/storefront-api-types';
2
-
3
- export const getEncodedAttributes = (attributes: Attribute[]) =>
4
- encodeURIComponent(
5
- JSON.stringify(
6
- attributes.reduce(
7
- (merged, { key, value }) => ({ ...merged, [key]: value }),
8
- {}
9
- )
10
- )
11
- );
@@ -1,31 +0,0 @@
1
- import { RebuyClient } from '@rebuy/rebuy';
2
- import type { RebuyConfig, RebuyResponse } from '~/types/rebuyCustom';
3
-
4
- export const getRebuyConfig = async (
5
- rebuyKey: string,
6
- storeDomain: string
7
- ): Promise<RebuyConfig> => {
8
- try {
9
- const request = {
10
- parameters: { shop: storeDomain },
11
- url: `/api/v1/user/config`,
12
- };
13
-
14
- const { data: rebuy, ...response } = (await new RebuyClient(
15
- rebuyKey
16
- ).getShieldedAsset(request.url, request.parameters)) as RebuyResponse;
17
-
18
- if (!rebuy?.shop) {
19
- throw new Error(
20
- 'Rebuy configuration is not properly set up - missing shop',
21
- { cause: response }
22
- );
23
- }
24
- return rebuy;
25
- } catch (error: unknown) {
26
- const err = error as Error;
27
- console.warn('Error fetching Rebuy shop config');
28
- console.error(err, err.cause);
29
- throw err;
30
- }
31
- };