@surfside/ads-react 0.1.17 → 0.1.18
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.
- package/lib/cjs/BuildInfo.js +1 -1
- package/lib/cjs/BuildInfo.js.map +1 -1
- package/lib/cjs/hooks/useSurfsideProducts.js +17 -6
- package/lib/cjs/hooks/useSurfsideProducts.js.map +1 -1
- package/lib/cjs/provider/SurfsideContextProvider.js +16 -0
- package/lib/cjs/provider/SurfsideContextProvider.js.map +1 -1
- package/lib/esm/BuildInfo.js +1 -1
- package/lib/esm/BuildInfo.js.map +1 -1
- package/lib/esm/components/SurfsideBanner.js +43 -0
- package/lib/esm/components/SurfsideBanner.js.map +1 -0
- package/lib/esm/components/SurfsideBannerRenderer.js +41 -0
- package/lib/esm/components/SurfsideBannerRenderer.js.map +1 -0
- package/lib/esm/components/SurfsideBannerVideoRenderer.js +21 -0
- package/lib/esm/components/SurfsideBannerVideoRenderer.js.map +1 -0
- package/lib/esm/components/SurfsideCarousel.js +112 -0
- package/lib/esm/components/SurfsideCarousel.js.map +1 -0
- package/lib/esm/components/SurfsideDynamicZone.js +136 -0
- package/lib/esm/components/SurfsideDynamicZone.js.map +1 -0
- package/lib/esm/components/SurfsideProduct.js +113 -0
- package/lib/esm/components/SurfsideProduct.js.map +1 -0
- package/lib/esm/components/SurfsideVideo.js +81 -0
- package/lib/esm/components/SurfsideVideo.js.map +1 -0
- package/lib/esm/components/SurfsideVideoRenderer.js +38 -0
- package/lib/esm/components/SurfsideVideoRenderer.js.map +1 -0
- package/lib/esm/components/index.js +9 -0
- package/lib/esm/components/index.js.map +1 -0
- package/lib/esm/hooks/index.js +5 -0
- package/lib/esm/hooks/index.js.map +1 -0
- package/lib/esm/hooks/useSurfsideBanner.js +209 -0
- package/lib/esm/hooks/useSurfsideBanner.js.map +1 -0
- package/lib/esm/hooks/useSurfsideDynamicZone.js +278 -0
- package/lib/esm/hooks/useSurfsideDynamicZone.js.map +1 -0
- package/lib/esm/hooks/useSurfsideProducts.js +438 -0
- package/lib/esm/hooks/useSurfsideProducts.js.map +1 -0
- package/lib/esm/hooks/useSurfsideVideo.js +293 -0
- package/lib/esm/hooks/useSurfsideVideo.js.map +1 -0
- package/lib/esm/index.js +20 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/provider/SurfsideContextProvider.js +168 -0
- package/lib/esm/provider/SurfsideContextProvider.js.map +1 -0
- package/lib/esm/provider/index.js +2 -0
- package/lib/esm/provider/index.js.map +1 -0
- package/lib/esm/utils/Analytics.js +171 -0
- package/lib/esm/utils/Analytics.js.map +1 -0
- package/lib/esm/utils/index.js +2 -0
- package/lib/esm/utils/index.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useState, useEffect, useCallback, useMemo } from 'react';
|
|
3
|
+
import { useSurfsideContext } from '../provider';
|
|
4
|
+
import { ConsumeNAsync, Ctx, Err, GetValueOrThrow, TryDo } from '@surfside/ads-core-client';
|
|
5
|
+
;
|
|
6
|
+
;
|
|
7
|
+
;
|
|
8
|
+
/**
|
|
9
|
+
* Fetches a page of either product data or product IDs. Returns a set of callbacks for fetching more products and
|
|
10
|
+
* callbacks for tracking impression and click events.
|
|
11
|
+
*
|
|
12
|
+
* This hook is useful for implementing carousels or pages of sponsored product listings within search results.
|
|
13
|
+
*
|
|
14
|
+
* This will either return a set of products and their data fields (i.e, name, description, price, etc.) or a set of
|
|
15
|
+
* product IDs, depending on the value of `props.withProductInfo`.
|
|
16
|
+
*
|
|
17
|
+
* @param props The page information and recommender strategy. See {@link UseSurfsideProductsPropsWithProductIDs} and
|
|
18
|
+
* {@link UseSurfsideProductsPropsWithProductData}
|
|
19
|
+
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* To retrieve full product data, including all available fields:
|
|
23
|
+
*
|
|
24
|
+
* ```tsx
|
|
25
|
+
* // returns product data
|
|
26
|
+
* const { products } = useSurfsideProducts({
|
|
27
|
+
* zoneId: '123',
|
|
28
|
+
* pageSize: 6,
|
|
29
|
+
* strategy: 'sponsored',
|
|
30
|
+
* withProductInfo: true // or pass nothing - withProductInfo is true by default
|
|
31
|
+
* })
|
|
32
|
+
*
|
|
33
|
+
* console.log(products.map(product => product.data.name))
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* *(See {@link IProductInfoData} and {@link IProductInformation} for a list of fields and the full return type)*
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* To retrieve *only* product IDs:
|
|
40
|
+
*
|
|
41
|
+
* ```tsx
|
|
42
|
+
* // returns product IDs
|
|
43
|
+
* const { products } = useSurfsideProducts({
|
|
44
|
+
* zoneId: '123',
|
|
45
|
+
* pageSize: 6,
|
|
46
|
+
* strategy: 'sponsored',
|
|
47
|
+
* withProductInfo: false
|
|
48
|
+
* })
|
|
49
|
+
*
|
|
50
|
+
* console.log(products.map(product => product.id))
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* *(See {@link IProductIDData} for the full return type)*
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* Both return types will return an object with a `type` field:
|
|
57
|
+
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* {
|
|
60
|
+
* type: 'sponsored' | 'recommended'
|
|
61
|
+
* // either product ID or product data goes here...
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* This is so you can mark Sponsored products as sponsored. In the United States,
|
|
66
|
+
* [
|
|
67
|
+
* the FTC requires all advertisements be conspicuously labeled as such
|
|
68
|
+
* ](https://www.ftc.gov/business-guidance/resources/ftcs-endorsement-guides-what-people-are-asking#\
|
|
69
|
+
* :~:text=The%20FTC%20Act%20applies%20to,have%20you%20mention%20that%20product).
|
|
70
|
+
*
|
|
71
|
+
* When rendering a product card, you might use this field thusly:
|
|
72
|
+
*
|
|
73
|
+
* ```tsx
|
|
74
|
+
* products.map(product => <div>
|
|
75
|
+
* {product.data.name}
|
|
76
|
+
* {product.type === 'sponsored'
|
|
77
|
+
* ? <span>Sponsored</span>
|
|
78
|
+
* : <></>
|
|
79
|
+
* }
|
|
80
|
+
* </div>);
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* A very simple carousel implementation might look like:
|
|
85
|
+
*
|
|
86
|
+
* ```tsx
|
|
87
|
+
* const myCarousel = ({ zoneId }: MyCarouselProps) => {
|
|
88
|
+
* const { products, hasMore, fetchNextPage, analytics } = useSurfsideProducts({
|
|
89
|
+
* zoneId,
|
|
90
|
+
* strategy: 'sponsored',
|
|
91
|
+
* pageSize: 6
|
|
92
|
+
* });
|
|
93
|
+
*
|
|
94
|
+
* return <div>
|
|
95
|
+
* <div class="products">
|
|
96
|
+
* {products.map(product => <div>
|
|
97
|
+
* { \/* Product Image is a URL string *\/ }
|
|
98
|
+
* <img src={product.data.image} />
|
|
99
|
+
* { \/* Product name *\/ }
|
|
100
|
+
* <h2>{product.data.name}</h2>
|
|
101
|
+
* { \/* Details is a short description of the product *\/ }
|
|
102
|
+
* <p>{product.data.details}</p>
|
|
103
|
+
* { \/* product.type is either 'sponsored' or 'recommended' *\/ }
|
|
104
|
+
* {product.type === 'sponsored'
|
|
105
|
+
* ? <span>Sponsored</span>
|
|
106
|
+
* : <></>
|
|
107
|
+
* }
|
|
108
|
+
* </div>)}
|
|
109
|
+
* </div>
|
|
110
|
+
* <div class="controls">
|
|
111
|
+
* { \/* hasMore indicates that there are more products available to be fetched *\/ }
|
|
112
|
+
* {hasMore
|
|
113
|
+
* ? <button class="nextButton" onClick={fetchNextPage}>➡️</button>
|
|
114
|
+
* : <></>
|
|
115
|
+
* }
|
|
116
|
+
* </div>
|
|
117
|
+
* </div>
|
|
118
|
+
* }
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export function useSurfsideProducts(props) {
|
|
122
|
+
const stableCategory = useMemo(() => props.category, [props.category?.join(',') ?? '']);
|
|
123
|
+
const internalProps = useMemo(() => ({
|
|
124
|
+
carousel: undefined,
|
|
125
|
+
...props,
|
|
126
|
+
category: stableCategory,
|
|
127
|
+
}), [
|
|
128
|
+
props.zoneId,
|
|
129
|
+
props.pageSize,
|
|
130
|
+
props.maxProducts,
|
|
131
|
+
props.enabled,
|
|
132
|
+
stableCategory,
|
|
133
|
+
props.withProductInfo,
|
|
134
|
+
props.strategy,
|
|
135
|
+
props.recommenderType,
|
|
136
|
+
]);
|
|
137
|
+
const internalState = useSurfsideProductsResponse(internalProps);
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
internalState.refetch?.();
|
|
140
|
+
}, [internalState.refetch]);
|
|
141
|
+
return internalState;
|
|
142
|
+
}
|
|
143
|
+
;
|
|
144
|
+
/** There are three workflows for fetching products:
|
|
145
|
+
* 1. Internal carousel is provided, and sets the dataSource, and triggers a fetchProducts call
|
|
146
|
+
* 2. Refetch
|
|
147
|
+
* - this builds the carousel and and sets the internal carousel
|
|
148
|
+
* - this triggers a useEffect and sets the dataSource
|
|
149
|
+
* - this triggers a rebuild of fetchProducts callback and triggers a fetchProducts call
|
|
150
|
+
* 3. Fetch next page
|
|
151
|
+
* - this triggers a call to fetchProducts with isRefetch set to false
|
|
152
|
+
* - and loads in the next page size of products
|
|
153
|
+
*/
|
|
154
|
+
/**
|
|
155
|
+
* Good things to know:
|
|
156
|
+
* category, zoneId, and other props changing only matter in refetch because its safe to assume that
|
|
157
|
+
if they come from dynamic zone, the carousel will be provided from the dynamic zone
|
|
158
|
+
* if they come from useSurfsideProducts, we need to call refetch to rebuild the carousel
|
|
159
|
+
*/
|
|
160
|
+
export function useSurfsideProductsResponse(props) {
|
|
161
|
+
const { defaultNative, startRequest, buildHybridCarousel, buildSponsoredCarousel, buildRecommendedCarousel, isReady: apiIsReady, hasError: apiHasError, error: apiError, logger } = useSurfsideContext();
|
|
162
|
+
const log = Ctx(logger)?.with('useSurfsideProductsResponse');
|
|
163
|
+
log?.info('Using surfside products response!');
|
|
164
|
+
const [internalCarousel, setInternalCarousel] = useState(props?.carousel);
|
|
165
|
+
const [loading, setLoading] = useState(true);
|
|
166
|
+
const [products, setProducts] = useState([]);
|
|
167
|
+
const [dataSource, setDataSource] = useState();
|
|
168
|
+
const [productsError, setProductsError] = useState();
|
|
169
|
+
const [hasMore, setHasMore] = useState(false);
|
|
170
|
+
log?.debug('Props', props, products);
|
|
171
|
+
/* If the API has an error, set an error */
|
|
172
|
+
useEffect(() => {
|
|
173
|
+
if (apiError !== undefined) {
|
|
174
|
+
log?.error(apiError);
|
|
175
|
+
setErrorState(apiError);
|
|
176
|
+
}
|
|
177
|
+
}, [apiHasError, apiError]);
|
|
178
|
+
/* If the API is still loading, set the loading state */
|
|
179
|
+
useEffect(() => {
|
|
180
|
+
if (!apiIsReady) {
|
|
181
|
+
log?.debug('Loading...');
|
|
182
|
+
setLoadingState();
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
log?.debug('Ready!');
|
|
186
|
+
setReady();
|
|
187
|
+
}
|
|
188
|
+
}, [apiIsReady]);
|
|
189
|
+
/* If the datasource was just set, fetch a page of products */
|
|
190
|
+
/* This is only called if a new internal carousel is set */
|
|
191
|
+
useEffect(() => {
|
|
192
|
+
log?.debug('Checking data source...');
|
|
193
|
+
if (dataSource !== undefined) {
|
|
194
|
+
log?.debug('DataSource set, fetching!');
|
|
195
|
+
fetchProducts();
|
|
196
|
+
}
|
|
197
|
+
}, [dataSource]);
|
|
198
|
+
/* If the internalCarousel was just set, set the datasource from that internal carousel
|
|
199
|
+
* This can either be passed in to the arguments (i.e, dynamic zones) or it can be set by calling
|
|
200
|
+
* refetch, which also works as an initial fetch request */
|
|
201
|
+
useEffect(() => {
|
|
202
|
+
log?.debug('Checking internal carousel response...');
|
|
203
|
+
if (internalCarousel?.ok === true) {
|
|
204
|
+
log?.debug('Found internal carousel!');
|
|
205
|
+
setDataSource(internalCarousel.value.getProduct());
|
|
206
|
+
}
|
|
207
|
+
else if (internalCarousel?.ok === false) {
|
|
208
|
+
log?.debug('Did not find internal carousel!');
|
|
209
|
+
setErrorState(internalCarousel);
|
|
210
|
+
}
|
|
211
|
+
}, [internalCarousel]);
|
|
212
|
+
useEffect(() => {
|
|
213
|
+
log?.info('Setting loading state...');
|
|
214
|
+
if (props === undefined) {
|
|
215
|
+
setLoadingState();
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
setInternalCarousel(props.carousel);
|
|
219
|
+
}
|
|
220
|
+
}, [props]);
|
|
221
|
+
const setSuccessState = (newProduct, hasMore, isFetchMore = true) => {
|
|
222
|
+
log?.debug('Success!', newProduct, products, isFetchMore);
|
|
223
|
+
setLoading(false);
|
|
224
|
+
setProductsError(undefined);
|
|
225
|
+
setHasMore(hasMore);
|
|
226
|
+
setProducts((currentProducts) => {
|
|
227
|
+
return isFetchMore ? [...currentProducts, ...newProduct] : newProduct;
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
const setErrorState = (error) => {
|
|
231
|
+
log?.error('Setting error state', error);
|
|
232
|
+
setLoading(false);
|
|
233
|
+
setProductsError(error);
|
|
234
|
+
setHasMore(false);
|
|
235
|
+
};
|
|
236
|
+
const setLoadingState = () => {
|
|
237
|
+
log?.debug('Setting loading state');
|
|
238
|
+
setLoading(true);
|
|
239
|
+
setProductsError(undefined);
|
|
240
|
+
};
|
|
241
|
+
const setReady = () => {
|
|
242
|
+
log?.debug('Setting ready state');
|
|
243
|
+
setLoading(false);
|
|
244
|
+
setProductsError(undefined);
|
|
245
|
+
};
|
|
246
|
+
/* This is used for re-requesting the carousel, and is also called by useSurfsideProducts to initialize the data */
|
|
247
|
+
const refetch = useCallback(() => {
|
|
248
|
+
log?.debug('Refetching!');
|
|
249
|
+
if (props === undefined || !apiIsReady || props.enabled === false) {
|
|
250
|
+
if (apiHasError) {
|
|
251
|
+
setErrorState(apiError);
|
|
252
|
+
}
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
setLoadingState();
|
|
256
|
+
const request = startRequest(props.zoneId)
|
|
257
|
+
.withNative(defaultNative()
|
|
258
|
+
.withMetaProduct(80, false)
|
|
259
|
+
.withMetaBrand(80, false)
|
|
260
|
+
.build())
|
|
261
|
+
.withSurfCategory(props?.category ?? [])
|
|
262
|
+
.build();
|
|
263
|
+
const recommenderType = props.recommenderType ?? 'top-products';
|
|
264
|
+
const carousel = TryDo(() => {
|
|
265
|
+
switch (props.strategy) {
|
|
266
|
+
case 'hybrid':
|
|
267
|
+
return GetValueOrThrow(buildHybridCarousel({
|
|
268
|
+
type: recommenderType
|
|
269
|
+
}, request));
|
|
270
|
+
case 'sponsored':
|
|
271
|
+
return GetValueOrThrow(buildSponsoredCarousel(request));
|
|
272
|
+
case 'recommended':
|
|
273
|
+
return GetValueOrThrow(buildRecommendedCarousel({ type: recommenderType }));
|
|
274
|
+
default:
|
|
275
|
+
throw new InvalidStrategyError(props.strategy);
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
setInternalCarousel(carousel);
|
|
279
|
+
}, [
|
|
280
|
+
apiIsReady,
|
|
281
|
+
apiError,
|
|
282
|
+
startRequest,
|
|
283
|
+
defaultNative,
|
|
284
|
+
buildHybridCarousel,
|
|
285
|
+
buildSponsoredCarousel,
|
|
286
|
+
buildRecommendedCarousel,
|
|
287
|
+
props?.enabled,
|
|
288
|
+
props?.category?.join(',') ?? '',
|
|
289
|
+
props?.strategy,
|
|
290
|
+
props?.recommenderType,
|
|
291
|
+
props?.zoneId,
|
|
292
|
+
props?.pageSize,
|
|
293
|
+
props?.maxProducts,
|
|
294
|
+
props?.withProductInfo,
|
|
295
|
+
props?.recommenderType,
|
|
296
|
+
]);
|
|
297
|
+
/*
|
|
298
|
+
* This can be called in two different ways, either by the dataSource (internal carousel)
|
|
299
|
+
or by the fetchNextPage callback
|
|
300
|
+
* It is crucial to break these into two different calls with isFetchMore
|
|
301
|
+
because the fetchNextPage callback is called and the dataSource is called when the internal carousel is set
|
|
302
|
+
* if the dataSource is called, we need to set isFetchMore to false which replaces the old dataSource's products
|
|
303
|
+
*/
|
|
304
|
+
const fetchProducts = useCallback((isFetchMore = false) => {
|
|
305
|
+
log?.debug('Fetching', products);
|
|
306
|
+
if (props === undefined) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
if (dataSource !== undefined) {
|
|
310
|
+
const actualPageSize = props.maxProducts !== undefined
|
|
311
|
+
? Math.min(props.maxProducts - products.length, props.pageSize)
|
|
312
|
+
: props.pageSize;
|
|
313
|
+
ConsumeNAsync(dataSource, actualPageSize)
|
|
314
|
+
.then(([data, finished]) => {
|
|
315
|
+
setSuccessState(data, !finished, isFetchMore);
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
}, [dataSource, props, products]);
|
|
319
|
+
const mappedProducts = useMemo(() => {
|
|
320
|
+
// safe assumption that product feed and recommender returns products with ids
|
|
321
|
+
const validProducts = products.filter((p) => typeof p.product.id === 'string' && p.product.id.trim() !== '');
|
|
322
|
+
return props?.withProductInfo === true
|
|
323
|
+
? validProducts.map(mapProductToData)
|
|
324
|
+
: validProducts.map(mapProductToIds);
|
|
325
|
+
}, [props?.withProductInfo, products]);
|
|
326
|
+
log?.debug('Final State', loading, productsError, products, apiError);
|
|
327
|
+
if (!loading && productsError === undefined) { /* Handle Success State */
|
|
328
|
+
return {
|
|
329
|
+
loading,
|
|
330
|
+
error: undefined,
|
|
331
|
+
products: mappedProducts,
|
|
332
|
+
hasMore,
|
|
333
|
+
refetch,
|
|
334
|
+
fetchNextPage: () => fetchProducts(true),
|
|
335
|
+
analytics: {
|
|
336
|
+
trackWin: product => {
|
|
337
|
+
const winTrackers = product.productCardResponse.trackers?.namedTrackers.win ?? [];
|
|
338
|
+
if (winTrackers.length === 0) {
|
|
339
|
+
log?.warn('Missing win trackers from namedTrackers in bid response');
|
|
340
|
+
}
|
|
341
|
+
for (const tracker of winTrackers) {
|
|
342
|
+
if (tracker.type === 'pixel') {
|
|
343
|
+
fetch(tracker.url);
|
|
344
|
+
;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
trackImpression: product => {
|
|
349
|
+
const impTrackers = product.productCardResponse.trackers?.namedTrackers.impression ?? [];
|
|
350
|
+
if (impTrackers.length === 0) {
|
|
351
|
+
log?.warn('Missing win trackers from namedTrackers in bid response');
|
|
352
|
+
}
|
|
353
|
+
for (const tracker of impTrackers) {
|
|
354
|
+
if (tracker.type === 'pixel') {
|
|
355
|
+
fetch(tracker.url);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
trackClick: product => {
|
|
360
|
+
const clickUrl = product.productCardResponse.clickthrough;
|
|
361
|
+
const parsedClickUrl = new URL(clickUrl);
|
|
362
|
+
// Remove the 'url' query parameter if it exists
|
|
363
|
+
parsedClickUrl.searchParams.delete('url');
|
|
364
|
+
fetch(parsedClickUrl.toString());
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
else if (!loading && productsError !== undefined) { /* Handle Error State */
|
|
370
|
+
return {
|
|
371
|
+
loading,
|
|
372
|
+
error: productsError,
|
|
373
|
+
products: mappedProducts,
|
|
374
|
+
hasMore: false,
|
|
375
|
+
refetch,
|
|
376
|
+
fetchNextPage: undefined,
|
|
377
|
+
analytics: undefined
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
else if (loading && productsError === undefined) { /* Handle Loading State */
|
|
381
|
+
return {
|
|
382
|
+
loading,
|
|
383
|
+
error: undefined,
|
|
384
|
+
products: mappedProducts,
|
|
385
|
+
hasMore,
|
|
386
|
+
refetch,
|
|
387
|
+
fetchNextPage: undefined,
|
|
388
|
+
analytics: undefined
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
else { /* Handle invalid states */
|
|
392
|
+
return {
|
|
393
|
+
loading: false,
|
|
394
|
+
error: Err(new InvalidProductsStateError(products, productsError, loading)),
|
|
395
|
+
products: mappedProducts,
|
|
396
|
+
hasMore,
|
|
397
|
+
refetch,
|
|
398
|
+
fetchNextPage: undefined,
|
|
399
|
+
analytics: undefined
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
;
|
|
404
|
+
const mapProductToData = (product) => ({
|
|
405
|
+
data: {
|
|
406
|
+
...product.product,
|
|
407
|
+
id: product.product.id !== undefined ? product.product.id : ''
|
|
408
|
+
},
|
|
409
|
+
type: product.sponsored ? 'sponsored' : 'recommended',
|
|
410
|
+
productCardResponse: product,
|
|
411
|
+
});
|
|
412
|
+
const mapProductToIds = (product) => ({
|
|
413
|
+
data: {
|
|
414
|
+
id: product.product.id
|
|
415
|
+
},
|
|
416
|
+
type: product.sponsored ? 'sponsored' : 'recommended',
|
|
417
|
+
productCardResponse: product
|
|
418
|
+
});
|
|
419
|
+
export class InvalidStrategyError extends Error {
|
|
420
|
+
strategy;
|
|
421
|
+
constructor(strategy) {
|
|
422
|
+
super('Invalid strategy withing useSurfsideProducts');
|
|
423
|
+
this.strategy = strategy;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
export class InvalidProductsStateError extends Error {
|
|
427
|
+
products;
|
|
428
|
+
error;
|
|
429
|
+
loading;
|
|
430
|
+
constructor(products, error, loading) {
|
|
431
|
+
super('useSurfsideProducts resulted in an invalid state');
|
|
432
|
+
this.products = products;
|
|
433
|
+
this.error = error;
|
|
434
|
+
this.loading = loading;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
;
|
|
438
|
+
//# sourceMappingURL=useSurfsideProducts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSurfsideProducts.js","sourceRoot":"src/","sources":["hooks/useSurfsideProducts.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAA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