@surfside/ads-react 0.1.16 → 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/components/SurfsideBanner.js +46 -0
- package/lib/cjs/components/SurfsideBanner.js.map +1 -0
- package/lib/cjs/components/SurfsideBannerRenderer.js +45 -0
- package/lib/cjs/components/SurfsideBannerRenderer.js.map +1 -0
- package/lib/cjs/components/SurfsideBannerVideoRenderer.js +25 -0
- package/lib/cjs/components/SurfsideBannerVideoRenderer.js.map +1 -0
- package/lib/cjs/components/SurfsideCarousel.js +116 -0
- package/lib/cjs/components/SurfsideCarousel.js.map +1 -0
- package/lib/cjs/components/SurfsideDynamicZone.js +141 -0
- package/lib/cjs/components/SurfsideDynamicZone.js.map +1 -0
- package/lib/cjs/components/SurfsideProduct.js +118 -0
- package/lib/cjs/components/SurfsideProduct.js.map +1 -0
- package/lib/cjs/components/SurfsideVideo.js +84 -0
- package/lib/cjs/components/SurfsideVideo.js.map +1 -0
- package/lib/cjs/components/SurfsideVideoRenderer.js +42 -0
- package/lib/cjs/components/SurfsideVideoRenderer.js.map +1 -0
- package/lib/cjs/components/index.js +23 -0
- package/lib/cjs/components/index.js.map +1 -0
- package/lib/cjs/hooks/index.js +20 -0
- package/lib/cjs/hooks/index.js.map +1 -0
- package/lib/cjs/hooks/useSurfsideBanner.js +215 -0
- package/lib/cjs/hooks/useSurfsideBanner.js.map +1 -0
- package/lib/cjs/hooks/useSurfsideDynamicZone.js +283 -0
- package/lib/cjs/hooks/useSurfsideDynamicZone.js.map +1 -0
- package/lib/cjs/hooks/useSurfsideProducts.js +445 -0
- package/lib/cjs/hooks/useSurfsideProducts.js.map +1 -0
- package/lib/cjs/hooks/useSurfsideVideo.js +299 -0
- package/lib/cjs/hooks/useSurfsideVideo.js.map +1 -0
- package/lib/cjs/index.js +71 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/provider/SurfsideContextProvider.js +175 -0
- package/lib/cjs/provider/SurfsideContextProvider.js.map +1 -0
- package/lib/cjs/provider/index.js +9 -0
- package/lib/cjs/provider/index.js.map +1 -0
- package/lib/cjs/utils/Analytics.js +181 -0
- package/lib/cjs/utils/Analytics.js.map +1 -0
- package/lib/cjs/utils/index.js +12 -0
- package/lib/cjs/utils/index.js.map +1 -0
- package/lib/esm/BuildInfo.js +1 -1
- package/lib/esm/BuildInfo.js.map +1 -1
- package/lib/esm/components/SurfsideDynamicZone.js +9 -1
- package/lib/esm/components/SurfsideDynamicZone.js.map +1 -1
- package/lib/esm/hooks/useSurfsideProducts.js +17 -6
- package/lib/esm/hooks/useSurfsideProducts.js.map +1 -1
- package/lib/esm/provider/SurfsideContextProvider.js +18 -2
- package/lib/esm/provider/SurfsideContextProvider.js.map +1 -1
- package/lib/types/components/SurfsideDynamicZone.d.ts +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.InvalidVideoStateError = exports.useSurfsideVideoResponse = exports.useSurfsideVideo = void 0;
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const provider_1 = require("../provider");
|
|
7
|
+
const ads_core_client_1 = require("@surfside/ads-core-client");
|
|
8
|
+
/**
|
|
9
|
+
* Requests and returns a video creative. Accepts size, duration, and MIME type arguments and returns an object wrapping
|
|
10
|
+
* the creative, exporting both a deserialized object representing the VAST 3.0 XML markup as well as the raw XML
|
|
11
|
+
* itself, which can be passed into video players supporting the VAST 3.0 XML specification. The return type also
|
|
12
|
+
* contains an `analytics` object which is a set of callback functions to be called for specific video playback events,
|
|
13
|
+
* such as completing each quartile of the video playback, recording impressions, and starting/finishing the video.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* Video players are more complicated to implement than static banner creatives because of their inherently interactive
|
|
17
|
+
* nature. Modern browsers will disallow videos from autoplaying unmuted, [except under specific circumstances](
|
|
18
|
+
* https://developer.mozilla.org/en-US/docs/Web/Media/Guides/Autoplay#autoplay_availability). For this reason, it is
|
|
19
|
+
* recommended that you mark your `<video>` tag as `autoPlay muted`. e.g:
|
|
20
|
+
*
|
|
21
|
+
* ```html
|
|
22
|
+
* <video autoPlay muted>
|
|
23
|
+
* <!-- ... <source> tags go here -->
|
|
24
|
+
* </video>
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* It is *possible* to autoplay a video unmuted under other circumstances, such as if the user has interacted with the
|
|
28
|
+
* page already. That implementation is left up to the developer.
|
|
29
|
+
*
|
|
30
|
+
* Surfside's bidder will always return with a single video creative per video bid request. This means that the
|
|
31
|
+
* `video.vast.ads` field will always have exactly one {@link IAd} object, and all VAST creative types will be a single
|
|
32
|
+
* `linear` video creative. This means that it will always be safe to do this:
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* if (video !== undefined) {
|
|
36
|
+
* // URL of the video and its MIME type
|
|
37
|
+
* const { url, type } = video.ads[0].inline.creatives[0].mediaFiles[0];
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* Since this is somewhat verbose, these values are available to you through the `video.url` and `video.mime` fields
|
|
42
|
+
* within the {@link IVideo} object.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* A very simple video player for a video response might look like this
|
|
46
|
+
*
|
|
47
|
+
* ```tsx
|
|
48
|
+
* const { video, loading, error, analytics } = useSurfsideVideo({
|
|
49
|
+
* zoneId: 'my-zone',
|
|
50
|
+
* size: [4, 3], // 4x3 video ad
|
|
51
|
+
* maxDuration: 30 // 30 seconds max
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* // Call impression and win handlers if they exist
|
|
55
|
+
* useEffect(() => {
|
|
56
|
+
* analytics?.impression();
|
|
57
|
+
* analytics?.win();
|
|
58
|
+
* }, [analytics]);
|
|
59
|
+
*
|
|
60
|
+
* if (loading) {
|
|
61
|
+
* return <div>loading...</div>;
|
|
62
|
+
* }
|
|
63
|
+
*
|
|
64
|
+
* if (error) {
|
|
65
|
+
* throw error.error; // error.error is the Javascript Error type and can be safely thrown
|
|
66
|
+
* }
|
|
67
|
+
*
|
|
68
|
+
* return (
|
|
69
|
+
* <video autoplay muted>
|
|
70
|
+
* <source src={video.url} type={video.mime} />
|
|
71
|
+
* </video>
|
|
72
|
+
* );
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* Note that this implementation ONLY implements the `win` and `impression` events. In order to implement playback-based
|
|
76
|
+
* events, you must write handlers for the [`play`, `ended`, and `timeupdate` events](
|
|
77
|
+
* https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/video#events). For quartile playback events, you
|
|
78
|
+
* will need to check the current time of the video during the `timeupdate` events to determine if the proper quartile
|
|
79
|
+
* has been passed (e.g, `firstQuartile` must be fired **a single time, only after the video has surpassed 25% of its
|
|
80
|
+
* duration**).
|
|
81
|
+
*
|
|
82
|
+
* @param {IUseSurfsideVideoOptions} props
|
|
83
|
+
*
|
|
84
|
+
* @expandType IUseSurfsideVideoOptions
|
|
85
|
+
* @expandType UseSurfsideVideoReturn
|
|
86
|
+
*/
|
|
87
|
+
const useSurfsideVideo = ({ zoneId, size, minDuration = 0, maxDuration, mimes = ['video/mp4'], enabled = true, category }) => {
|
|
88
|
+
const resolvedMimes = (0, react_1.useMemo)(() => mimes, [mimes.join(',')]);
|
|
89
|
+
const stableCategory = (0, react_1.useMemo)(() => category, [category?.join(',') ?? '']);
|
|
90
|
+
const respProps = (0, react_1.useMemo)(() => ({
|
|
91
|
+
video: undefined,
|
|
92
|
+
zoneId,
|
|
93
|
+
size,
|
|
94
|
+
minDuration,
|
|
95
|
+
maxDuration,
|
|
96
|
+
mimes: resolvedMimes,
|
|
97
|
+
enabled,
|
|
98
|
+
category: stableCategory
|
|
99
|
+
}), [zoneId, size?.[0], size?.[1], minDuration, maxDuration, resolvedMimes, enabled, stableCategory]);
|
|
100
|
+
const internalState = (0, exports.useSurfsideVideoResponse)(respProps);
|
|
101
|
+
(0, react_1.useEffect)(() => {
|
|
102
|
+
internalState.refetch?.();
|
|
103
|
+
}, [internalState.refetch]);
|
|
104
|
+
return internalState;
|
|
105
|
+
};
|
|
106
|
+
exports.useSurfsideVideo = useSurfsideVideo;
|
|
107
|
+
const useSurfsideVideoResponse = (props) => {
|
|
108
|
+
const { startRequest, requestBids, buildVideoResponse, logger, error: apiError, hasError: apiHasError, isReady: apiIsReady } = (0, provider_1.useSurfsideContext)();
|
|
109
|
+
const [internalVideo, setInternalVideo] = (0, react_1.useState)(props?.video);
|
|
110
|
+
const [video, setVideo] = (0, react_1.useState)();
|
|
111
|
+
const [loading, setLoading] = (0, react_1.useState)(true);
|
|
112
|
+
const [videoError, setVideoError] = (0, react_1.useState)();
|
|
113
|
+
const trackingEvents = (0, react_1.useRef)();
|
|
114
|
+
(0, react_1.useEffect)(() => {
|
|
115
|
+
if (internalVideo?.ok === true) {
|
|
116
|
+
const value = internalVideo.value;
|
|
117
|
+
const ad = value.video.ads[0];
|
|
118
|
+
const creative = ad?.inline.creatives[0];
|
|
119
|
+
const mediaFile = creative?.mediaFiles[0];
|
|
120
|
+
const adm = internalVideo.value.bid.adm;
|
|
121
|
+
if (ad !== undefined && creative !== undefined && mediaFile !== undefined && adm !== undefined) {
|
|
122
|
+
setSuccessState({
|
|
123
|
+
...internalVideo.value,
|
|
124
|
+
id: internalVideo.value.bid.id,
|
|
125
|
+
title: ad.inline.adTitle,
|
|
126
|
+
duration: creative.duration,
|
|
127
|
+
mime: mediaFile.type,
|
|
128
|
+
adm: adm,
|
|
129
|
+
videoUrl: mediaFile.url,
|
|
130
|
+
}, creative.trackingEvents);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else if (internalVideo?.ok === false) {
|
|
134
|
+
setErrorState(internalVideo);
|
|
135
|
+
}
|
|
136
|
+
}, [internalVideo]);
|
|
137
|
+
(0, react_1.useEffect)(() => {
|
|
138
|
+
if (props?.video === undefined) {
|
|
139
|
+
// setLoadingState();
|
|
140
|
+
// } else if (internalVideo?.ok === false) {
|
|
141
|
+
// setErrorState(internalVideo);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
setInternalVideo(props?.video);
|
|
145
|
+
}
|
|
146
|
+
}, [props?.video]);
|
|
147
|
+
const setErrorState = (err) => {
|
|
148
|
+
setVideoError(err);
|
|
149
|
+
setVideo(undefined);
|
|
150
|
+
setLoading(false);
|
|
151
|
+
trackingEvents.current = undefined;
|
|
152
|
+
};
|
|
153
|
+
const setLoadingState = () => {
|
|
154
|
+
setVideoError(undefined);
|
|
155
|
+
setVideo(undefined);
|
|
156
|
+
setLoading(true);
|
|
157
|
+
trackingEvents.current = undefined;
|
|
158
|
+
};
|
|
159
|
+
const setSuccessState = (video, track) => {
|
|
160
|
+
setVideoError(undefined);
|
|
161
|
+
setVideo(video);
|
|
162
|
+
setLoading(false);
|
|
163
|
+
trackingEvents.current = track;
|
|
164
|
+
};
|
|
165
|
+
const refetch = (0, react_1.useCallback)(async () => {
|
|
166
|
+
if (props === undefined || !apiIsReady || props.enabled === false) {
|
|
167
|
+
if (apiHasError) {
|
|
168
|
+
setErrorState(apiError);
|
|
169
|
+
}
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
setLoadingState();
|
|
173
|
+
const request = startRequest(props.zoneId)
|
|
174
|
+
.withSurfCategory(props?.category ?? [])
|
|
175
|
+
.withVideo(props.size[0], props.size[1], props.minDuration, props.maxDuration, props.mimes)
|
|
176
|
+
.build();
|
|
177
|
+
const videoResult = await (0, ads_core_client_1.AsyncPipe)(requestBids(request))
|
|
178
|
+
.then(bidResponse => (0, ads_core_client_1.WrapValue)(bidResponse.seatbid?.[0]?.bid?.[0]))
|
|
179
|
+
.then(buildVideoResponse)
|
|
180
|
+
.result();
|
|
181
|
+
setInternalVideo(videoResult);
|
|
182
|
+
}, [
|
|
183
|
+
apiIsReady,
|
|
184
|
+
apiError,
|
|
185
|
+
startRequest,
|
|
186
|
+
buildVideoResponse,
|
|
187
|
+
props?.enabled,
|
|
188
|
+
props?.zoneId,
|
|
189
|
+
props?.size[0],
|
|
190
|
+
props?.size[1],
|
|
191
|
+
props?.minDuration,
|
|
192
|
+
props?.maxDuration,
|
|
193
|
+
props?.mimes,
|
|
194
|
+
props?.category
|
|
195
|
+
]);
|
|
196
|
+
const analytics = (0, react_1.useMemo)(() => {
|
|
197
|
+
if (video === undefined) {
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
...trackVideoEvents(trackingEvents.current, logger),
|
|
202
|
+
...trackVideoWin
|
|
203
|
+
};
|
|
204
|
+
}, [video?.id]);
|
|
205
|
+
if (!loading && videoError === undefined && video !== undefined) {
|
|
206
|
+
return {
|
|
207
|
+
video,
|
|
208
|
+
error: videoError,
|
|
209
|
+
loading,
|
|
210
|
+
isReady: true,
|
|
211
|
+
analytics,
|
|
212
|
+
refetch
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
else if (!loading && videoError !== undefined && video === undefined) {
|
|
216
|
+
return {
|
|
217
|
+
video,
|
|
218
|
+
error: videoError,
|
|
219
|
+
loading: loading,
|
|
220
|
+
isReady: false,
|
|
221
|
+
analytics: undefined,
|
|
222
|
+
refetch
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
else if (loading && videoError === undefined && video === undefined) {
|
|
226
|
+
return {
|
|
227
|
+
video,
|
|
228
|
+
error: videoError,
|
|
229
|
+
loading,
|
|
230
|
+
isReady: false,
|
|
231
|
+
analytics: undefined,
|
|
232
|
+
refetch
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
return {
|
|
237
|
+
video: undefined,
|
|
238
|
+
error: (0, ads_core_client_1.Err)(new InvalidVideoStateError(video, videoError, loading)),
|
|
239
|
+
loading: false,
|
|
240
|
+
isReady: false,
|
|
241
|
+
analytics: undefined,
|
|
242
|
+
refetch: refetch
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
exports.useSurfsideVideoResponse = useSurfsideVideoResponse;
|
|
247
|
+
class InvalidVideoStateError extends Error {
|
|
248
|
+
video;
|
|
249
|
+
error;
|
|
250
|
+
loading;
|
|
251
|
+
constructor(video, error, loading) {
|
|
252
|
+
super('useSurfsideBanner resulted in an invalid state');
|
|
253
|
+
this.video = video;
|
|
254
|
+
this.error = error;
|
|
255
|
+
this.loading = loading;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
exports.InvalidVideoStateError = InvalidVideoStateError;
|
|
259
|
+
;
|
|
260
|
+
const trackVideoWin = (video, logger) => () => {
|
|
261
|
+
if (video === undefined) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const log = (0, ads_core_client_1.Ctx)(logger)?.with('trackWin');
|
|
265
|
+
if (video.bid.nurl !== undefined) {
|
|
266
|
+
const url = new URL(video.bid.nurl);
|
|
267
|
+
url.searchParams.delete('url');
|
|
268
|
+
fetch(url.toString()).then(() => log?.debug('Won auction', video));
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
log?.error('Missing nurl on video bid response! This should never happen', video);
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
const trackVideoEvents = (trackingEvents, logger) => {
|
|
275
|
+
if (trackingEvents === undefined) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const log = (0, ads_core_client_1.Ctx)(logger)?.with('trackVideoEvents');
|
|
279
|
+
// Helper to safely return a tracking function or no-op
|
|
280
|
+
const getTracker = (eventName) => {
|
|
281
|
+
const event = trackingEvents.find((e) => e.event === eventName);
|
|
282
|
+
if (event?.url === undefined) {
|
|
283
|
+
return () => log?.debug(`No tracker for event: ${eventName}`);
|
|
284
|
+
}
|
|
285
|
+
return () => {
|
|
286
|
+
fetch(event.url).then(() => log?.debug(`Tracked event: ${eventName}`));
|
|
287
|
+
};
|
|
288
|
+
};
|
|
289
|
+
return {
|
|
290
|
+
start: getTracker('start'),
|
|
291
|
+
firstQuartile: getTracker('firstQuartile'),
|
|
292
|
+
midpoint: getTracker('midpoint'),
|
|
293
|
+
thirdQuartile: getTracker('thirdQuartile'),
|
|
294
|
+
complete: getTracker('complete'),
|
|
295
|
+
impression: getTracker('impression'),
|
|
296
|
+
win: getTracker('win'),
|
|
297
|
+
};
|
|
298
|
+
};
|
|
299
|
+
//# sourceMappingURL=useSurfsideVideo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSurfsideVideo.js","sourceRoot":"src/","sources":["hooks/useSurfsideVideo.ts"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;AAEb,iCAA0E;AAC1E,0CAAiD;AACjD,+DAWmC;AA8MnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8EG;AACI,MAAM,gBAAgB,GAAG,CAAC,EAC7B,MAAM,EACN,IAAI,EACJ,WAAW,GAAG,CAAC,EACf,WAAW,EACX,KAAK,GAAG,CAAC,WAAW,CAAC,EACrB,OAAO,GAAG,IAAI,EACd,QAAQ,EACe,EAA0B,EAAE;IACnD,MAAM,aAAa,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAE9D,MAAM,cAAc,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAE5E,MAAM,SAAS,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE,CAAC,CAAC;QAC7B,KAAK,EAAE,SAAS;QAChB,MAAM;QACN,IAAI;QACJ,WAA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E,CAAC,CAAC;IACN,CAAC,CAAC;IAEF,OAAO;QACH,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC;QAC1B,aAAa,EAAE,UAAU,CAAC,eAAe,CAAC;QAC1C,QAAQ,EAAE,UAAU,CAAC,UAAU,CAAC;QAChC,aAAa,EAAE,UAAU,CAAC,eAAe,CAAC;QAC1C,QAAQ,EAAE,UAAU,CAAC,UAAU,CAAC;QAChC,UAAU,EAAE,UAAU,CAAC,YAAY,CAAC;QACpC,GAAG,EAAE,UAAU,CAAC,KAAK,CAAC;KACzB,CAAC;AACN,CAAC,CAAC"}
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.InvalidVideoStateError = exports.useSurfsideVideoResponse = exports.useSurfsideVideo = exports.InvalidProductsStateError = exports.InvalidStrategyError = exports.useSurfsideProductsResponse = exports.useSurfsideProducts = exports.InvalidDynamicZoneState = exports.useSurfsideDynamicZone = exports.InvalidBannerStateError = exports.useSurfsideBannerResponse = exports.useSurfsideBanner = exports.SurfsideBannerVideoRenderer = exports.SurfsideVideoRenderer = exports.SurfsideVideo = exports.ProductCardUnmountedError = exports.NoProductsReturnedError = exports.SurfsideProductCard = exports.DynamicZoneUnmountedError = exports.SurfsideDynamicZone = exports.SurfsideCarousel = exports.SurfsideBannerRenderer = exports.SurfsideBanner = exports.trackZoneEvent = exports.trackVideoEvent = exports.trackVideoImpression = exports.trackBannerImpression = exports.trackProductImpressions = exports.trackBannerClick = exports.trackProductClick = exports.NotInProviderError = exports.InvalidStateError = exports.SurfsideProvider = exports.useSurfsideContext = void 0;
|
|
18
|
+
// Provider
|
|
19
|
+
var provider_1 = require("./provider");
|
|
20
|
+
Object.defineProperty(exports, "useSurfsideContext", { enumerable: true, get: function () { return provider_1.useSurfsideContext; } });
|
|
21
|
+
Object.defineProperty(exports, "SurfsideProvider", { enumerable: true, get: function () { return provider_1.SurfsideProvider; } });
|
|
22
|
+
Object.defineProperty(exports, "InvalidStateError", { enumerable: true, get: function () { return provider_1.InvalidStateError; } });
|
|
23
|
+
Object.defineProperty(exports, "NotInProviderError", { enumerable: true, get: function () { return provider_1.NotInProviderError; } });
|
|
24
|
+
// Analytics
|
|
25
|
+
var utils_1 = require("./utils");
|
|
26
|
+
Object.defineProperty(exports, "trackProductClick", { enumerable: true, get: function () { return utils_1.trackProductClick; } });
|
|
27
|
+
Object.defineProperty(exports, "trackBannerClick", { enumerable: true, get: function () { return utils_1.trackBannerClick; } });
|
|
28
|
+
Object.defineProperty(exports, "trackProductImpressions", { enumerable: true, get: function () { return utils_1.trackProductImpressions; } });
|
|
29
|
+
Object.defineProperty(exports, "trackBannerImpression", { enumerable: true, get: function () { return utils_1.trackBannerImpression; } });
|
|
30
|
+
Object.defineProperty(exports, "trackVideoImpression", { enumerable: true, get: function () { return utils_1.trackVideoImpression; } });
|
|
31
|
+
Object.defineProperty(exports, "trackVideoEvent", { enumerable: true, get: function () { return utils_1.trackVideoEvent; } });
|
|
32
|
+
Object.defineProperty(exports, "trackZoneEvent", { enumerable: true, get: function () { return utils_1.trackZoneEvent; } });
|
|
33
|
+
// Components
|
|
34
|
+
var components_1 = require("./components");
|
|
35
|
+
Object.defineProperty(exports, "SurfsideBanner", { enumerable: true, get: function () { return components_1.SurfsideBanner; } });
|
|
36
|
+
var components_2 = require("./components");
|
|
37
|
+
Object.defineProperty(exports, "SurfsideBannerRenderer", { enumerable: true, get: function () { return components_2.SurfsideBannerRenderer; } });
|
|
38
|
+
var components_3 = require("./components");
|
|
39
|
+
Object.defineProperty(exports, "SurfsideCarousel", { enumerable: true, get: function () { return components_3.SurfsideCarousel; } });
|
|
40
|
+
var components_4 = require("./components");
|
|
41
|
+
Object.defineProperty(exports, "SurfsideDynamicZone", { enumerable: true, get: function () { return components_4.SurfsideDynamicZone; } });
|
|
42
|
+
Object.defineProperty(exports, "DynamicZoneUnmountedError", { enumerable: true, get: function () { return components_4.DynamicZoneUnmountedError; } });
|
|
43
|
+
var components_5 = require("./components");
|
|
44
|
+
Object.defineProperty(exports, "SurfsideProductCard", { enumerable: true, get: function () { return components_5.SurfsideProductCard; } });
|
|
45
|
+
Object.defineProperty(exports, "NoProductsReturnedError", { enumerable: true, get: function () { return components_5.NoProductsReturnedError; } });
|
|
46
|
+
Object.defineProperty(exports, "ProductCardUnmountedError", { enumerable: true, get: function () { return components_5.ProductCardUnmountedError; } });
|
|
47
|
+
var components_6 = require("./components");
|
|
48
|
+
Object.defineProperty(exports, "SurfsideVideo", { enumerable: true, get: function () { return components_6.SurfsideVideo; } });
|
|
49
|
+
var components_7 = require("./components");
|
|
50
|
+
Object.defineProperty(exports, "SurfsideVideoRenderer", { enumerable: true, get: function () { return components_7.SurfsideVideoRenderer; } });
|
|
51
|
+
var components_8 = require("./components");
|
|
52
|
+
Object.defineProperty(exports, "SurfsideBannerVideoRenderer", { enumerable: true, get: function () { return components_8.SurfsideBannerVideoRenderer; } });
|
|
53
|
+
// Hooks
|
|
54
|
+
var hooks_1 = require("./hooks");
|
|
55
|
+
Object.defineProperty(exports, "useSurfsideBanner", { enumerable: true, get: function () { return hooks_1.useSurfsideBanner; } });
|
|
56
|
+
Object.defineProperty(exports, "useSurfsideBannerResponse", { enumerable: true, get: function () { return hooks_1.useSurfsideBannerResponse; } });
|
|
57
|
+
Object.defineProperty(exports, "InvalidBannerStateError", { enumerable: true, get: function () { return hooks_1.InvalidBannerStateError; } });
|
|
58
|
+
var hooks_2 = require("./hooks");
|
|
59
|
+
Object.defineProperty(exports, "useSurfsideDynamicZone", { enumerable: true, get: function () { return hooks_2.useSurfsideDynamicZone; } });
|
|
60
|
+
Object.defineProperty(exports, "InvalidDynamicZoneState", { enumerable: true, get: function () { return hooks_2.InvalidDynamicZoneState; } });
|
|
61
|
+
var hooks_3 = require("./hooks");
|
|
62
|
+
Object.defineProperty(exports, "useSurfsideProducts", { enumerable: true, get: function () { return hooks_3.useSurfsideProducts; } });
|
|
63
|
+
Object.defineProperty(exports, "useSurfsideProductsResponse", { enumerable: true, get: function () { return hooks_3.useSurfsideProductsResponse; } });
|
|
64
|
+
Object.defineProperty(exports, "InvalidStrategyError", { enumerable: true, get: function () { return hooks_3.InvalidStrategyError; } });
|
|
65
|
+
Object.defineProperty(exports, "InvalidProductsStateError", { enumerable: true, get: function () { return hooks_3.InvalidProductsStateError; } });
|
|
66
|
+
var hooks_4 = require("./hooks");
|
|
67
|
+
Object.defineProperty(exports, "useSurfsideVideo", { enumerable: true, get: function () { return hooks_4.useSurfsideVideo; } });
|
|
68
|
+
Object.defineProperty(exports, "useSurfsideVideoResponse", { enumerable: true, get: function () { return hooks_4.useSurfsideVideoResponse; } });
|
|
69
|
+
Object.defineProperty(exports, "InvalidVideoStateError", { enumerable: true, get: function () { return hooks_4.InvalidVideoStateError; } });
|
|
70
|
+
__exportStar(require("./BuildInfo"), exports);
|
|
71
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["index.ts"],"names":[],"mappings":";;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4B"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.NotInProviderError = exports.InvalidStateError = exports.SurfsideProvider = exports.useSurfsideContext = void 0;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const ads_core_1 = require("@surfside/ads-core");
|
|
8
|
+
const ads_core_web_1 = require("@surfside/ads-core-web");
|
|
9
|
+
const ads_core_mock_1 = require("@surfside/ads-core-mock");
|
|
10
|
+
const ads_core_client_1 = require("@surfside/ads-core-client");
|
|
11
|
+
;
|
|
12
|
+
;
|
|
13
|
+
;
|
|
14
|
+
const SurfsideContext = (0, react_1.createContext)(undefined);
|
|
15
|
+
/**
|
|
16
|
+
* Returns the Surfside Context state, or throws an error if the context failed to return at all (i.e, you are calling
|
|
17
|
+
* useSurfsideContext outside of SurfsideProvider node)
|
|
18
|
+
*
|
|
19
|
+
* @throws {Error} If the context failed to initialize.
|
|
20
|
+
*/
|
|
21
|
+
const useSurfsideContext = () => {
|
|
22
|
+
const context = (0, react_1.useContext)(SurfsideContext);
|
|
23
|
+
if (context === undefined) {
|
|
24
|
+
return {
|
|
25
|
+
error: (0, ads_core_1.Err)(new NotInProviderError),
|
|
26
|
+
status: 'error',
|
|
27
|
+
isReady: false,
|
|
28
|
+
setLocationId: () => void 0,
|
|
29
|
+
setUserId: () => void 0,
|
|
30
|
+
isInitializing: false,
|
|
31
|
+
hasError: true
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return context;
|
|
35
|
+
};
|
|
36
|
+
exports.useSurfsideContext = useSurfsideContext;
|
|
37
|
+
const searchHasString = (str) => typeof window !== 'undefined' &&
|
|
38
|
+
window.location.search.toLowerCase().includes(str);
|
|
39
|
+
/**
|
|
40
|
+
* The provider for the Surfside ads context.
|
|
41
|
+
*
|
|
42
|
+
* @see {@link ISurfsideProviderProps}
|
|
43
|
+
*/
|
|
44
|
+
const SurfsideProvider = ({ accountId, channelId, siteId, locationId: cfgLocationId, userId: cfgUserId, config, onError, children, logger: userLogger }) => {
|
|
45
|
+
const [api, setApi] = (0, react_1.useState)();
|
|
46
|
+
const [isInitializing, setIsInitializing] = (0, react_1.useState)(true);
|
|
47
|
+
const [error, setError] = (0, react_1.useState)();
|
|
48
|
+
const [locationId, setLocationId] = (0, react_1.useState)(cfgLocationId);
|
|
49
|
+
const [userId, setUserId] = (0, react_1.useState)(cfgUserId);
|
|
50
|
+
const debug = config?.debug ?? searchHasString('surf_debug=true');
|
|
51
|
+
const mock = config?.mock ?? searchHasString('surf_mock=true');
|
|
52
|
+
const { mockRecommendedProducts, mockSponsoredProducts } = config?.customMockData ?? {};
|
|
53
|
+
const logger = (0, react_1.useMemo)(() => (0, ads_core_1.Ctx)(userLogger ?? (debug ? (0, ads_core_1.InitLogger)() : undefined)), [userLogger]);
|
|
54
|
+
const log = (0, ads_core_1.Ctx)(logger)?.with('SurfsideProvider');
|
|
55
|
+
log?.info('Initializing Surfside provider');
|
|
56
|
+
(0, react_1.useEffect)(() => {
|
|
57
|
+
let cancel = false;
|
|
58
|
+
log?.info('Checking initialization state');
|
|
59
|
+
if (locationId === undefined) {
|
|
60
|
+
setLoadingState();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const initializerPromise = !mock
|
|
64
|
+
? (0, ads_core_web_1.InitSurfAdsWeb)(accountId, siteId, channelId, locationId, userId, logger)
|
|
65
|
+
: (0, ads_core_web_1.InitSurfAdsWebInternal)((0, ads_core_mock_1.InitSurfAdsCoreMock)(accountId, channelId, siteId, locationId, userId, (0, ads_core_1.InitLogger)(), mockSponsoredProducts, mockRecommendedProducts, config?.simulateNoResponse, config?.simulateTimeout));
|
|
66
|
+
initializerPromise.then(web => {
|
|
67
|
+
if (cancel) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (!web.ok) {
|
|
71
|
+
setErrorState(web);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const { logger } = web.value;
|
|
75
|
+
logger?.table(SurfsideAdsVersionTable);
|
|
76
|
+
setSuccessState(web.value);
|
|
77
|
+
});
|
|
78
|
+
return () => {
|
|
79
|
+
cancel = true;
|
|
80
|
+
};
|
|
81
|
+
}, [locationId, accountId, siteId, channelId, userId, logger]);
|
|
82
|
+
const setLoadingState = () => {
|
|
83
|
+
setIsInitializing(true);
|
|
84
|
+
setError(undefined);
|
|
85
|
+
setApi(undefined);
|
|
86
|
+
};
|
|
87
|
+
const setErrorState = (err) => {
|
|
88
|
+
setIsInitializing(false);
|
|
89
|
+
setError(err);
|
|
90
|
+
setApi(undefined);
|
|
91
|
+
};
|
|
92
|
+
const setSuccessState = (api) => {
|
|
93
|
+
setIsInitializing(false);
|
|
94
|
+
setError(undefined);
|
|
95
|
+
setApi(api);
|
|
96
|
+
};
|
|
97
|
+
const contextValue = (0, ads_core_1.GetValueOrThrow)((0, ads_core_1.TryDo)(() => {
|
|
98
|
+
if (isInitializing) { // Loading state
|
|
99
|
+
return {
|
|
100
|
+
isInitializing: true,
|
|
101
|
+
status: 'initializing',
|
|
102
|
+
isReady: false,
|
|
103
|
+
error: undefined,
|
|
104
|
+
hasError: false,
|
|
105
|
+
setLocationId,
|
|
106
|
+
setUserId
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
else if (error !== undefined) { // error state
|
|
110
|
+
return {
|
|
111
|
+
isInitializing: false,
|
|
112
|
+
status: 'error',
|
|
113
|
+
error,
|
|
114
|
+
setLocationId,
|
|
115
|
+
setUserId,
|
|
116
|
+
isReady: false,
|
|
117
|
+
hasError: true
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
else if (api !== undefined) { // success state
|
|
121
|
+
return {
|
|
122
|
+
...api,
|
|
123
|
+
isReady: true,
|
|
124
|
+
status: 'ready',
|
|
125
|
+
setLocationId,
|
|
126
|
+
setUserId,
|
|
127
|
+
hasError: false,
|
|
128
|
+
isInitializing: false
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
else { // error - indeterminate state. Set error state
|
|
132
|
+
return {
|
|
133
|
+
error: (0, ads_core_1.Err)(new InvalidStateError),
|
|
134
|
+
isReady: false,
|
|
135
|
+
isInitializing: false,
|
|
136
|
+
status: 'error',
|
|
137
|
+
setLocationId,
|
|
138
|
+
setUserId,
|
|
139
|
+
hasError: true
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}));
|
|
143
|
+
if (contextValue.status === 'error') {
|
|
144
|
+
onError?.(contextValue.error);
|
|
145
|
+
}
|
|
146
|
+
return ((0, jsx_runtime_1.jsx)(SurfsideContext.Provider, { value: contextValue, children: children }));
|
|
147
|
+
};
|
|
148
|
+
exports.SurfsideProvider = SurfsideProvider;
|
|
149
|
+
class InvalidStateError extends Error {
|
|
150
|
+
constructor() {
|
|
151
|
+
super('Surfside context provider was left in an invalid state. Contact the vendor');
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.InvalidStateError = InvalidStateError;
|
|
155
|
+
class NotInProviderError extends Error {
|
|
156
|
+
constructor() {
|
|
157
|
+
super('useSurfsideContext must be used within a SurfsideProvider block. Did you forget to add the provider to' +
|
|
158
|
+
' your App.tsx?');
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
exports.NotInProviderError = NotInProviderError;
|
|
162
|
+
const pad = (name) => {
|
|
163
|
+
let newName = name;
|
|
164
|
+
const remaining = 25 - name.length;
|
|
165
|
+
for (let i = 0; i < remaining; i++) {
|
|
166
|
+
newName += ' ';
|
|
167
|
+
}
|
|
168
|
+
return newName;
|
|
169
|
+
};
|
|
170
|
+
const SurfsideAdsVersionTable = {
|
|
171
|
+
[pad('@surfside/ads-core')]: ads_core_1.SurfsideAdsCoreVersionInfo,
|
|
172
|
+
[pad('@surfside/ads-core-client')]: ads_core_client_1.SurfsideAdsCoreClientVersionInfo,
|
|
173
|
+
[pad('@surfside/ads-core-web')]: ads_core_web_1.SurfsideAdsCoreWebVersionInfo
|
|
174
|
+
};
|
|
175
|
+
//# sourceMappingURL=SurfsideContextProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SurfsideContextProvider.js","sourceRoot":"src/","sources":["provider/SurfsideContextProvider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;AAEb,iCAQe;AAEf,iDAU4B;AAC5B,yDAKgC;AAChC,2DAAyF;AACzF,+DAA6E;AAiF5E,CAAC;AAkDD,CAAC;AAiBD,CAAC;AAUF,MAAM,eAAe,GAAG,IAAA,qBAAa,EACjC,SAAS,CACZ,CAAC;AAEF;;;;;GAKG;AACI,MAAM,kBAAkB,GAAG,GAAyB,EAAE;IACzD,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,eAAe,CAAC,CAAC;IAC5C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO;YACH,KAAK,EAAE,IAAA,cAAG,EAAC,IAAI,kBAAkB,CAAC;YAClC,MAAM,EAAE,OAAO;YACf,OAAO,EAAE,KAAK;YACd,aAAa,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC;YAC3B,SAAS,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC;YACvB,cAAc,EAAE,KAAK;YACrB,QAAQ,EAAE,IAAI;SACjB,CAAC;IACN,CAAC;IACD,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC;AAdW,QAAA,kBAAkB,sBAc7B;AAEF,MAAM,eAAe,GAAG,CAAC,GAAW,EAAE,EAAE,CACpC,OAAO,MAAM,KAAK,WAAW;IAC7B,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AAEvD;;;;GAIG;AACI,MAAM,gBAAgB,GAAqC,CAAC,EAC/D,SAAS,EACT,SAAS,EACT,MAAM,EACN,UAAU,EAAE,aAAa,EACzB,MAAM,EAAE,SAAS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", { value: true });
|
|
3
|
+
exports.NotInProviderError = exports.InvalidStateError = exports.SurfsideProvider = exports.useSurfsideContext = void 0;
|
|
4
|
+
var SurfsideContextProvider_1 = require("./SurfsideContextProvider");
|
|
5
|
+
Object.defineProperty(exports, "useSurfsideContext", { enumerable: true, get: function () { return SurfsideContextProvider_1.useSurfsideContext; } });
|
|
6
|
+
Object.defineProperty(exports, "SurfsideProvider", { enumerable: true, get: function () { return SurfsideContextProvider_1.SurfsideProvider; } });
|
|
7
|
+
Object.defineProperty(exports, "InvalidStateError", { enumerable: true, get: function () { return SurfsideContextProvider_1.InvalidStateError; } });
|
|
8
|
+
Object.defineProperty(exports, "NotInProviderError", { enumerable: true, get: function () { return SurfsideContextProvider_1.NotInProviderError; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["provider/index.ts"],"names":[],"mappings":";;;AAAA,qEAYmC;AAJ/B,6HAAA,kBAAkB,OAAA;AAClB,2HAAA,gBAAgB,OAAA;AAChB,4HAAA,iBAAiB,OAAA;AACjB,6HAAA,kBAAkB,OAAA"}
|