@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.
Files changed (50) hide show
  1. package/lib/cjs/BuildInfo.js +1 -1
  2. package/lib/cjs/BuildInfo.js.map +1 -1
  3. package/lib/cjs/components/SurfsideBanner.js +46 -0
  4. package/lib/cjs/components/SurfsideBanner.js.map +1 -0
  5. package/lib/cjs/components/SurfsideBannerRenderer.js +45 -0
  6. package/lib/cjs/components/SurfsideBannerRenderer.js.map +1 -0
  7. package/lib/cjs/components/SurfsideBannerVideoRenderer.js +25 -0
  8. package/lib/cjs/components/SurfsideBannerVideoRenderer.js.map +1 -0
  9. package/lib/cjs/components/SurfsideCarousel.js +116 -0
  10. package/lib/cjs/components/SurfsideCarousel.js.map +1 -0
  11. package/lib/cjs/components/SurfsideDynamicZone.js +141 -0
  12. package/lib/cjs/components/SurfsideDynamicZone.js.map +1 -0
  13. package/lib/cjs/components/SurfsideProduct.js +118 -0
  14. package/lib/cjs/components/SurfsideProduct.js.map +1 -0
  15. package/lib/cjs/components/SurfsideVideo.js +84 -0
  16. package/lib/cjs/components/SurfsideVideo.js.map +1 -0
  17. package/lib/cjs/components/SurfsideVideoRenderer.js +42 -0
  18. package/lib/cjs/components/SurfsideVideoRenderer.js.map +1 -0
  19. package/lib/cjs/components/index.js +23 -0
  20. package/lib/cjs/components/index.js.map +1 -0
  21. package/lib/cjs/hooks/index.js +20 -0
  22. package/lib/cjs/hooks/index.js.map +1 -0
  23. package/lib/cjs/hooks/useSurfsideBanner.js +215 -0
  24. package/lib/cjs/hooks/useSurfsideBanner.js.map +1 -0
  25. package/lib/cjs/hooks/useSurfsideDynamicZone.js +283 -0
  26. package/lib/cjs/hooks/useSurfsideDynamicZone.js.map +1 -0
  27. package/lib/cjs/hooks/useSurfsideProducts.js +445 -0
  28. package/lib/cjs/hooks/useSurfsideProducts.js.map +1 -0
  29. package/lib/cjs/hooks/useSurfsideVideo.js +299 -0
  30. package/lib/cjs/hooks/useSurfsideVideo.js.map +1 -0
  31. package/lib/cjs/index.js +71 -0
  32. package/lib/cjs/index.js.map +1 -0
  33. package/lib/cjs/provider/SurfsideContextProvider.js +175 -0
  34. package/lib/cjs/provider/SurfsideContextProvider.js.map +1 -0
  35. package/lib/cjs/provider/index.js +9 -0
  36. package/lib/cjs/provider/index.js.map +1 -0
  37. package/lib/cjs/utils/Analytics.js +181 -0
  38. package/lib/cjs/utils/Analytics.js.map +1 -0
  39. package/lib/cjs/utils/index.js +12 -0
  40. package/lib/cjs/utils/index.js.map +1 -0
  41. package/lib/esm/BuildInfo.js +1 -1
  42. package/lib/esm/BuildInfo.js.map +1 -1
  43. package/lib/esm/components/SurfsideDynamicZone.js +9 -1
  44. package/lib/esm/components/SurfsideDynamicZone.js.map +1 -1
  45. package/lib/esm/hooks/useSurfsideProducts.js +17 -6
  46. package/lib/esm/hooks/useSurfsideProducts.js.map +1 -1
  47. package/lib/esm/provider/SurfsideContextProvider.js +18 -2
  48. package/lib/esm/provider/SurfsideContextProvider.js.map +1 -1
  49. package/lib/types/components/SurfsideDynamicZone.d.ts +1 -1
  50. package/package.json +3 -3
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ 'use client';
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.SurfsideVideoRenderer = void 0;
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const react_1 = require("react");
7
+ const ads_core_client_1 = require("@surfside/ads-core-client");
8
+ const SurfsideContextProvider_1 = require("../provider/SurfsideContextProvider");
9
+ /**
10
+ * SurfsideVideoRenderer renders a pre-fetched video creative into the DOM.
11
+ * This component assumes the video has already been processed and only handles injection.
12
+ *
13
+ * @param props `ISurfsideVideoRendererProps`
14
+ * @returns The video container element
15
+ */
16
+ const SurfsideVideoRenderer = ({ video, onRender, onError, }) => {
17
+ const { logger, renderVideo, error: apiError } = (0, SurfsideContextProvider_1.useSurfsideContext)();
18
+ const log = (0, ads_core_client_1.Ctx)(logger)?.with('SurfsideVideoRenderer');
19
+ const ref = (0, react_1.useRef)(null);
20
+ (0, react_1.useEffect)(() => {
21
+ const container = ref.current;
22
+ if (container === null || renderVideo === undefined) {
23
+ if (apiError !== undefined) {
24
+ onError?.(apiError);
25
+ }
26
+ return;
27
+ }
28
+ const result = renderVideo(video);
29
+ if (!result.ok) {
30
+ log?.error('Video render error', result);
31
+ onError?.(result);
32
+ return;
33
+ }
34
+ container.innerHTML = '';
35
+ container.appendChild(result.value);
36
+ log?.info('Video rendered');
37
+ onRender?.(video.id);
38
+ }, [video, renderVideo, apiError]);
39
+ return (0, jsx_runtime_1.jsx)("div", { ref: ref });
40
+ };
41
+ exports.SurfsideVideoRenderer = SurfsideVideoRenderer;
42
+ //# sourceMappingURL=SurfsideVideoRenderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SurfsideVideoRenderer.js","sourceRoot":"src/","sources":["components/SurfsideVideoRenderer.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;AAEb,iCAAiD;AACjD,+DAAgE;AAChE,iFAAyE;AAiCzE;;;;;;GAMG;AACI,MAAM,qBAAqB,GAA0C,CAAC,EACzE,KAAK,EACL,QAAQ,EACR,OAAO,GACV,EAAE,EAAE;IACD,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAA,4CAAkB,GAAE,CAAC;IACtE,MAAM,GAAG,GAAG,IAAA,qBAAG,EAAC,MAAM,CAAC,EAAE,IAAI,CAAC,uBAAuB,CAAC,CAAC;IACvD,MAAM,GAAG,GAAG,IAAA,cAAM,EAAiB,IAAI,CAAC,CAAC;IAEzC,IAAA,iBAAS,EAAC,GAAG,EAAE;QACX,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC;QAC9B,IAAI,SAAS,KAAK,IAAI,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;YAClD,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;gBACzB,OAAO,EAAE,CAAC,QAAQ,CAAC,CAAC;YACxB,CAAC;YACD,OAAO;QACX,CAAC;QAED,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;QAClC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;YACb,GAAG,EAAE,KAAK,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC;YACzC,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC;YAClB,OAAO;QACX,CAAC;QAED,SAAS,CAAC,SAAS,GAAG,EAAE,CAAC;QACzB,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACpC,GAAG,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAC5B,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACzB,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC;IAEnC,OAAO,gCAAK,GAAG,EAAE,GAAG,GAAI,CAAC;AAC7B,CAAC,CAAC;AAhCW,QAAA,qBAAqB,yBAgChC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SurfsideBannerVideoRenderer = exports.SurfsideVideoRenderer = exports.SurfsideVideo = exports.ProductCardUnmountedError = exports.NoProductsReturnedError = exports.SurfsideProductCard = exports.DynamicZoneUnmountedError = exports.SurfsideDynamicZone = exports.SurfsideCarousel = exports.SurfsideBannerRenderer = exports.SurfsideBanner = void 0;
4
+ var SurfsideBanner_1 = require("./SurfsideBanner");
5
+ Object.defineProperty(exports, "SurfsideBanner", { enumerable: true, get: function () { return SurfsideBanner_1.SurfsideBanner; } });
6
+ var SurfsideBannerRenderer_1 = require("./SurfsideBannerRenderer");
7
+ Object.defineProperty(exports, "SurfsideBannerRenderer", { enumerable: true, get: function () { return SurfsideBannerRenderer_1.SurfsideBannerRenderer; } });
8
+ var SurfsideCarousel_1 = require("./SurfsideCarousel");
9
+ Object.defineProperty(exports, "SurfsideCarousel", { enumerable: true, get: function () { return SurfsideCarousel_1.SurfsideCarousel; } });
10
+ var SurfsideDynamicZone_1 = require("./SurfsideDynamicZone");
11
+ Object.defineProperty(exports, "SurfsideDynamicZone", { enumerable: true, get: function () { return SurfsideDynamicZone_1.SurfsideDynamicZone; } });
12
+ Object.defineProperty(exports, "DynamicZoneUnmountedError", { enumerable: true, get: function () { return SurfsideDynamicZone_1.DynamicZoneUnmountedError; } });
13
+ var SurfsideProduct_1 = require("./SurfsideProduct");
14
+ Object.defineProperty(exports, "SurfsideProductCard", { enumerable: true, get: function () { return SurfsideProduct_1.SurfsideProductCard; } });
15
+ Object.defineProperty(exports, "NoProductsReturnedError", { enumerable: true, get: function () { return SurfsideProduct_1.NoProductsReturnedError; } });
16
+ Object.defineProperty(exports, "ProductCardUnmountedError", { enumerable: true, get: function () { return SurfsideProduct_1.ProductCardUnmountedError; } });
17
+ var SurfsideVideo_1 = require("./SurfsideVideo");
18
+ Object.defineProperty(exports, "SurfsideVideo", { enumerable: true, get: function () { return SurfsideVideo_1.SurfsideVideo; } });
19
+ var SurfsideVideoRenderer_1 = require("./SurfsideVideoRenderer");
20
+ Object.defineProperty(exports, "SurfsideVideoRenderer", { enumerable: true, get: function () { return SurfsideVideoRenderer_1.SurfsideVideoRenderer; } });
21
+ var SurfsideBannerVideoRenderer_1 = require("./SurfsideBannerVideoRenderer");
22
+ Object.defineProperty(exports, "SurfsideBannerVideoRenderer", { enumerable: true, get: function () { return SurfsideBannerVideoRenderer_1.SurfsideBannerVideoRenderer; } });
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"src/","sources":["components/index.ts"],"names":[],"mappings":";;;AAAA,mDAG0B;AADtB,gHAAA,cAAc,OAAA;AAGlB,mEAGkC;AAD9B,gIAAA,sBAAsB,OAAA;AAG1B,uDAO4B;AADxB,oHAAA,gBAAgB,OAAA;AAGpB,6DAI+B;AAF3B,0HAAA,mBAAmB,OAAA;AACnB,gIAAA,yBAAyB,OAAA;AAG7B,qDAQ2B;AAHvB,sHAAA,mBAAmB,OAAA;AACnB,0HAAA,uBAAuB,OAAA;AACvB,4HAAA,yBAAyB,OAAA;AAG7B,iDAGyB;AADrB,8GAAA,aAAa,OAAA;AAGjB,iEAGiC;AAD7B,8HAAA,qBAAqB,OAAA;AAGzB,6EAIuC;AADnC,0IAAA,2BAA2B,OAAA"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidVideoStateError = exports.useSurfsideVideoResponse = exports.useSurfsideVideo = exports.InvalidProductsStateError = exports.InvalidStrategyError = exports.useSurfsideProductsResponse = exports.useSurfsideProducts = exports.InvalidDynamicZoneState = exports.useSurfsideDynamicZone = exports.InvalidBannerStateError = exports.useSurfsideBannerResponse = exports.useSurfsideBanner = void 0;
4
+ var useSurfsideBanner_1 = require("./useSurfsideBanner");
5
+ Object.defineProperty(exports, "useSurfsideBanner", { enumerable: true, get: function () { return useSurfsideBanner_1.useSurfsideBanner; } });
6
+ Object.defineProperty(exports, "useSurfsideBannerResponse", { enumerable: true, get: function () { return useSurfsideBanner_1.useSurfsideBannerResponse; } });
7
+ Object.defineProperty(exports, "InvalidBannerStateError", { enumerable: true, get: function () { return useSurfsideBanner_1.InvalidBannerStateError; } });
8
+ var useSurfsideDynamicZone_1 = require("./useSurfsideDynamicZone");
9
+ Object.defineProperty(exports, "useSurfsideDynamicZone", { enumerable: true, get: function () { return useSurfsideDynamicZone_1.useSurfsideDynamicZone; } });
10
+ Object.defineProperty(exports, "InvalidDynamicZoneState", { enumerable: true, get: function () { return useSurfsideDynamicZone_1.InvalidDynamicZoneState; } });
11
+ var useSurfsideProducts_1 = require("./useSurfsideProducts");
12
+ Object.defineProperty(exports, "useSurfsideProducts", { enumerable: true, get: function () { return useSurfsideProducts_1.useSurfsideProducts; } });
13
+ Object.defineProperty(exports, "useSurfsideProductsResponse", { enumerable: true, get: function () { return useSurfsideProducts_1.useSurfsideProductsResponse; } });
14
+ Object.defineProperty(exports, "InvalidStrategyError", { enumerable: true, get: function () { return useSurfsideProducts_1.InvalidStrategyError; } });
15
+ Object.defineProperty(exports, "InvalidProductsStateError", { enumerable: true, get: function () { return useSurfsideProducts_1.InvalidProductsStateError; } });
16
+ var useSurfsideVideo_1 = require("./useSurfsideVideo");
17
+ Object.defineProperty(exports, "useSurfsideVideo", { enumerable: true, get: function () { return useSurfsideVideo_1.useSurfsideVideo; } });
18
+ Object.defineProperty(exports, "useSurfsideVideoResponse", { enumerable: true, get: function () { return useSurfsideVideo_1.useSurfsideVideoResponse; } });
19
+ Object.defineProperty(exports, "InvalidVideoStateError", { enumerable: true, get: function () { return useSurfsideVideo_1.InvalidVideoStateError; } });
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"src/","sources":["hooks/index.ts"],"names":[],"mappings":";;;AAAA,yDAa6B;AAJzB,sHAAA,iBAAiB,OAAA;AAEjB,8HAAA,yBAAyB,OAAA;AACzB,4HAAA,uBAAuB,OAAA;AAG3B,mEAqBkC;AAF9B,gIAAA,sBAAsB,OAAA;AACtB,iIAAA,uBAAuB,OAAA;AAG3B,6DAuB+B;AAJ3B,0HAAA,mBAAmB,OAAA;AACnB,kIAAA,2BAA2B,OAAA;AAC3B,2HAAA,oBAAoB,OAAA;AACpB,gIAAA,yBAAyB,OAAA;AAG7B,uDAc4B;AAJxB,oHAAA,gBAAgB,OAAA;AAEhB,4HAAA,wBAAwB,OAAA;AACxB,0HAAA,sBAAsB,OAAA"}
@@ -0,0 +1,215 @@
1
+ "use strict";
2
+ 'use client';
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.InvalidBannerStateError = exports.useSurfsideBannerResponse = exports.useSurfsideBanner = 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 banner creative. Accepts a size argument and returns an object wrapping the creative markup
10
+ * (called the `adm`) and some analytics callbacks for tracking auction events, as well as metadata such as the original
11
+ * bid response which creatived the banner.
12
+ *
13
+ * For documentation on the return values and possible states of this hook, see {@link UseSurfsideBannerReturn}.
14
+ *
15
+ * @example
16
+ * To request a banner and display it, pass a desired creative aspect ratio and check the status of the hook, then
17
+ * render when the banner has returned successfully
18
+ *
19
+ * ```tsx
20
+ * const { banner, loading, error, analytics } = useSurfsideBanner({
21
+ * zoneId: 'my-zone',
22
+ * size: [4, 1] // 4x1 banner
23
+ * })
24
+ *
25
+ * // Track win event
26
+ * useEffect(() => analytics?.trackWin(banner), [analytics]);
27
+ *
28
+ * if (loading) {
29
+ * return <div>Loading...</div>
30
+ * }
31
+ *
32
+ * if (error !== undefined) {
33
+ * throw error.error; // error.error is the Javascript "Error" type which can be safely thrown
34
+ * }
35
+ *
36
+ * return <div dangerouslySetInnerHTML={{ __html: banner.adm }}></div>;
37
+ * ```
38
+ *
39
+ * @expandType IUseSurfsideBannerOptions
40
+ * @expandType UseSurfsideBannerReturn
41
+ *
42
+ * @param {IUseSurfsideBannerOptions} params
43
+ */
44
+ const useSurfsideBanner = ({ zoneId, size, enabled = true, category }) => {
45
+ const stableCategory = (0, react_1.useMemo)(() => category, [category?.join(',') ?? '']);
46
+ const respProps = (0, react_1.useMemo)(() => ({
47
+ banner: undefined,
48
+ zoneId,
49
+ size,
50
+ enabled,
51
+ category: stableCategory
52
+ }), [zoneId, size?.[0], size?.[1], enabled, stableCategory]);
53
+ const internalState = (0, exports.useSurfsideBannerResponse)(respProps);
54
+ (0, react_1.useEffect)(() => {
55
+ internalState.refetch?.();
56
+ }, [internalState.refetch]);
57
+ return internalState;
58
+ };
59
+ exports.useSurfsideBanner = useSurfsideBanner;
60
+ const useSurfsideBannerResponse = (props) => {
61
+ const { startRequest, requestBids, buildBannerResponse, logger, error: apiError, hasError: apiHasError, isReady: apiIsReady } = (0, provider_1.useSurfsideContext)();
62
+ const [internalBanner, setInternalBanner] = (0, react_1.useState)(props?.banner);
63
+ const [banner, setBanner] = (0, react_1.useState)();
64
+ const [loading, setLoading] = (0, react_1.useState)(true);
65
+ const [bannerError, setBannerError] = (0, react_1.useState)();
66
+ const log = (0, ads_core_client_1.Ctx)(logger)?.with('SurfsideBanner');
67
+ log?.info('Fetching Surfside Banner');
68
+ (0, react_1.useEffect)(() => {
69
+ if (internalBanner?.ok === true) {
70
+ setSuccessState({
71
+ ...internalBanner.value,
72
+ id: internalBanner.value.bid.id
73
+ });
74
+ }
75
+ else if (internalBanner?.ok === false) {
76
+ setErrorState(internalBanner);
77
+ }
78
+ }, [internalBanner]);
79
+ (0, react_1.useEffect)(() => {
80
+ if (props?.banner === undefined) {
81
+ setLoadingState();
82
+ }
83
+ else {
84
+ setInternalBanner(props?.banner);
85
+ }
86
+ }, [props?.banner]);
87
+ const setErrorState = (err) => {
88
+ log?.error('Setting banner error state', err);
89
+ setBannerError(err);
90
+ setBanner(undefined);
91
+ setLoading(false);
92
+ };
93
+ const setLoadingState = () => {
94
+ log?.info('Setting banner loading state');
95
+ setBannerError(undefined);
96
+ setBanner(undefined);
97
+ setLoading(true);
98
+ };
99
+ const setSuccessState = (banner) => {
100
+ log?.info('Setting banner success state', banner);
101
+ setBannerError(undefined);
102
+ setLoading(false);
103
+ setBanner({ ...banner });
104
+ };
105
+ const refetch = (0, react_1.useCallback)(async () => {
106
+ log?.info('Running banner refetch');
107
+ if (props === undefined || !apiIsReady || props.enabled === false) {
108
+ if (apiHasError) {
109
+ log?.warn('Banner unable to render do to api error');
110
+ setErrorState(apiError);
111
+ }
112
+ log?.warn('Banner not fetching, either enabled is false or incorrect initialization');
113
+ return;
114
+ }
115
+ setLoadingState();
116
+ const request = startRequest(props.zoneId)
117
+ .withSurfCategory(props?.category ?? [])
118
+ .withBanner(props.size[0], props.size[1])
119
+ .build();
120
+ const bannerResult = await (0, ads_core_client_1.AsyncPipe)(requestBids(request))
121
+ .then(bidResponse => (0, ads_core_client_1.WrapValue)(bidResponse.seatbid?.[0]?.bid?.[0]))
122
+ .then(buildBannerResponse)
123
+ .result();
124
+ log?.info('Setting banner result');
125
+ setInternalBanner(bannerResult);
126
+ }, [
127
+ apiIsReady,
128
+ apiError,
129
+ startRequest,
130
+ buildBannerResponse,
131
+ props?.enabled,
132
+ props?.zoneId,
133
+ props?.size?.[0],
134
+ props?.size?.[1],
135
+ props?.category
136
+ ]);
137
+ // memoize this for rerender edge cases
138
+ const analytics = (0, react_1.useMemo)(() => {
139
+ if (banner === undefined) {
140
+ return undefined;
141
+ }
142
+ return {
143
+ trackWin: trackWin(banner, logger)
144
+ };
145
+ }, [banner?.id]);
146
+ if (!loading && bannerError === undefined && banner !== undefined) { /* Handle Success State */
147
+ return {
148
+ banner,
149
+ error: bannerError,
150
+ loading,
151
+ isReady: true,
152
+ analytics,
153
+ refetch: refetch
154
+ };
155
+ }
156
+ else if (!loading && bannerError !== undefined && banner === undefined) { /* Handle Error State */
157
+ return {
158
+ banner,
159
+ error: bannerError,
160
+ loading: loading,
161
+ isReady: false,
162
+ analytics: undefined,
163
+ refetch: refetch
164
+ };
165
+ }
166
+ else if (loading && bannerError === undefined && banner === undefined) { /* Handle Loading State */
167
+ return {
168
+ banner,
169
+ error: bannerError,
170
+ loading,
171
+ isReady: false,
172
+ analytics: undefined,
173
+ refetch: refetch
174
+ };
175
+ }
176
+ else { /* Handle Invalid State */
177
+ return {
178
+ banner: undefined,
179
+ error: (0, ads_core_client_1.Err)(new InvalidBannerStateError(banner, bannerError, loading)),
180
+ loading: false,
181
+ isReady: false,
182
+ analytics: undefined,
183
+ refetch: refetch,
184
+ };
185
+ }
186
+ };
187
+ exports.useSurfsideBannerResponse = useSurfsideBannerResponse;
188
+ class InvalidBannerStateError extends Error {
189
+ banner;
190
+ error;
191
+ loading;
192
+ constructor(banner, error, loading) {
193
+ super('useSurfsideBanner resulted in an invalid state');
194
+ this.banner = banner;
195
+ this.error = error;
196
+ this.loading = loading;
197
+ }
198
+ }
199
+ exports.InvalidBannerStateError = InvalidBannerStateError;
200
+ ;
201
+ const trackWin = (banner, logger) => () => {
202
+ if (banner === undefined) {
203
+ return;
204
+ }
205
+ const log = (0, ads_core_client_1.Ctx)(logger)?.with('trackWin');
206
+ if (banner.bid.nurl !== undefined) {
207
+ const url = new URL(banner.bid.nurl);
208
+ url.searchParams.delete('url');
209
+ fetch(url.toString()).then(() => log?.debug('Won auction', banner));
210
+ }
211
+ else {
212
+ log?.error('Missing nurl on banner bid response! This should never happen', banner);
213
+ }
214
+ };
215
+ //# sourceMappingURL=useSurfsideBanner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSurfsideBanner.js","sourceRoot":"src/","sources":["hooks/useSurfsideBanner.ts"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;AAEb,iCAAkE;AAClE,0CAAiD;AACjD,+DASmC;AA4OnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEI,MAAM,iBAAiB,GAAG,CAAC,EAC9B,MAAM,EACN,IAAI,EACJ,OAAO,GAAG,IAAI,EACd,QAAQ,EACgB,EAA2B,EAAE;IAErD,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,MAAM,EAAE,SAAS;QACjB,MAAM;QACN,IAAI;QACJ,OAAO;QACP,QAAQ,EAAE,cAAc;KAC3B,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC;IAE7D,MAAM,aAAa,GAAG,IAAA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C;AAEL,CAAC,CAAC;AAjJW,QAAA,yBAAyB,6BAiJpC;AAEF,MAAa,uBAAwB,SAAQ,KAAK;IAE1B;IACA;IACA;IAHpB,YACoB,MAA2B,EAC3B,KAA4B,EAC5B,OAAgB;QAEhC,KAAK,CAAC,gDAAgD,CAAC,CAAC;QAJxC,WAAM,GAAN,MAAM,CAAqB;QAC3B,UAAK,GAAL,KAAK,CAAuB;QAC5B,YAAO,GAAP,OAAO,CAAS;IAGpC,CAAC;CACJ;AARD,0DAQC;AAAA,CAAC;AAEF,MAAM,QAAQ,GAAG,CAAC,MAA2B,EAAE,MAA2B,EAAE,EAAE,CAAC,GAAG,EAAE;IAChF,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACvB,OAAO;IACX,CAAC;IACD,MAAM,GAAG,GAAG,IAAA,qBAAG,EAAC,MAAM,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAC1C,IAAI,MAAM,CAAC,GAAG,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAChC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACrC,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC/B,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC,CAAC;IACxE,CAAC;SAAM,CAAC;QACJ,GAAG,EAAE,KAAK,CACN,+DAA+D,EAC/D,MAAM,CACT,CAAC;IACN,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,283 @@
1
+ "use strict";
2
+ 'use client';
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.InvalidDynamicZoneState = void 0;
5
+ exports.useSurfsideDynamicZone = useSurfsideDynamicZone;
6
+ const react_1 = require("react");
7
+ const provider_1 = require("../provider");
8
+ const ads_core_client_1 = require("@surfside/ads-core-client");
9
+ const hooks_1 = require("../hooks");
10
+ ;
11
+ ;
12
+ ;
13
+ ;
14
+ ;
15
+ ;
16
+ /**
17
+ * @overload
18
+ *
19
+ * Returns a typed version of the `UseSurfsideDynamicZoneReturn` populated with full product data, if product data is
20
+ * available. If you pass `withProductInfo: true` to props (or pass nothing at all), this overload will be used.
21
+ * @expandType UseSurfDynamicZoneOptionsWithProductInfo
22
+ * @param {UseSurfDynamicZoneOptionsWithProductInfo} props
23
+ */ ;
24
+ /**
25
+ * React hook for surfside dynamic zones. A dynamic zone is a creative which determines which type of creative to
26
+ * request based on the dimensions of the screen (i.e, it can request different creatives for desktop vs mobile).
27
+ * Dynamic zones can also define an order of priority for backup creatives. This requires you to have configured a
28
+ * dynamic zone ahead of time within the Surfside platform
29
+ *
30
+ * For example, a dynamic zone might be configured to request A carousel and a 4x1 banner on Desktop, or a 1x4 banner
31
+ * and 1x1 video on Mobile. Once it has selected the screen size, it will send a request for all configured creative
32
+ * types. It will then return the first available creative in order of priority. In our example, the dynamic zone might
33
+ * detect that we are on a Desktop view and then request the carousel and 4x1 banner at the same time. It will then try
34
+ * to render the carousel, if it is available. If it is not, it will render the banner. If neither are available,
35
+ * `useSurfsideDynamicZone` will return an error of type {@link NoBidsError}.
36
+ *
37
+ * @example
38
+ * To handle the output of each creative, check the `type` field after checking the value of `loading` and `error`.
39
+ * It is recommended that you implement renderer components which you can pass creative responses to, rather than trying
40
+ * to render each creative in the same component as your `useSurfsideDynamicZone` call.
41
+ *
42
+ * ```tsx
43
+ * const { data, error, loading, type } = useSurfsideDynamicZone({
44
+ * zoneId: 'my-zone'
45
+ * });
46
+ *
47
+ * if (loading) {
48
+ * return <div>Loading...</div>
49
+ * }
50
+ *
51
+ * if (error !== undefined) {
52
+ * throw error.error; // error.error is a Javascript Error type and can be safely thrown.
53
+ * }
54
+ *
55
+ * switch(type) {
56
+ * case 'banner': return <MyRenderBannerComponent banner={data} />;
57
+ * case 'video': return <MyRenderVideoComponent video={data} />;
58
+ * case 'products': return <MyRenderCarouselComponent products={data} />;
59
+ * }
60
+ * ```
61
+ *
62
+ * This pattern will allow you to re-use the renderer component across dynamic zones or pages where you call the other
63
+ * use hooks (i.e, `useSurfsideBanner`, `useSurfsideProducts`) directly.
64
+ * @param {UseSurfDynamicZoneOptions} props
65
+ */
66
+ function useSurfsideDynamicZone({ zoneId, pageSize, enabled = true, withProductInfo = true, category }) {
67
+ const { getDynamicZone, buildDynamicZoneRequest, buildDynamicResponse, isReady: apiIsReady, hasError: apiHasError, error: apiError, logger } = (0, provider_1.useSurfsideContext)();
68
+ const log = (0, ads_core_client_1.Ctx)(logger)?.with('useSurfsideDynamicZone');
69
+ const stableCategory = (0, react_1.useMemo)(() => category, [category?.join(',') ?? '']);
70
+ const [type, setType] = (0, react_1.useState)();
71
+ /* Products */
72
+ const [productsProps, setProductsProps] = (0, react_1.useState)();
73
+ const productsResponseState = (0, hooks_1.useSurfsideProductsResponse)(productsProps);
74
+ /* Banner */
75
+ const [bannerProps, setBannerProps] = (0, react_1.useState)();
76
+ const bannerResponseState = (0, hooks_1.useSurfsideBannerResponse)(bannerProps);
77
+ /* Video */
78
+ const [videoProps, setVideoProps] = (0, react_1.useState)();
79
+ const videoResponseState = (0, hooks_1.useSurfsideVideoResponse)(videoProps);
80
+ const [loading, setLoading] = (0, react_1.useState)(true);
81
+ const [error, setError] = (0, react_1.useState)();
82
+ const fetchDynamicZone = (0, react_1.useCallback)(async () => {
83
+ const localLog = log?.with('fetchDynamicZone');
84
+ if (!enabled || !apiIsReady) {
85
+ if (apiHasError) {
86
+ localLog?.debug('api has error', apiError);
87
+ setErrorState(apiError);
88
+ }
89
+ localLog?.debug('Not fetching dynamic zone yet');
90
+ return;
91
+ }
92
+ setLoadingState();
93
+ // Get dynamic response
94
+ const result = await (0, ads_core_client_1.AsyncPipe)(getDynamicZone(zoneId))
95
+ .then((zone) => buildDynamicZoneRequest(zoneId, zone, stableCategory ?? []))
96
+ .then(buildDynamicResponse)
97
+ .result();
98
+ /* If no creatives are available, this may return an error that should be handled explicitly */
99
+ if (!result.ok) {
100
+ localLog?.debug('No creatives available, setting error state');
101
+ setErrorState(result);
102
+ return;
103
+ }
104
+ const dynamicZone = result.value;
105
+ if (dynamicZone.type === 'carousel') {
106
+ localLog?.debug('Got carousel back from dynamic zone');
107
+ setProductsSuccessState((0, ads_core_client_1.Ok)(dynamicZone)); // re-box for type purposes
108
+ }
109
+ else if (dynamicZone.type === 'banner') {
110
+ localLog?.debug('Got banner back from dynamic zone');
111
+ setBannerSuccessState((0, ads_core_client_1.Ok)(dynamicZone));
112
+ }
113
+ else if (dynamicZone.type === 'video') {
114
+ localLog?.debug('Got video back from dynamic zone');
115
+ setVideoSuccessState((0, ads_core_client_1.Ok)(dynamicZone));
116
+ }
117
+ }, [
118
+ enabled,
119
+ apiError,
120
+ apiIsReady,
121
+ apiHasError,
122
+ getDynamicZone,
123
+ zoneId,
124
+ stableCategory?.join(',') ?? '',
125
+ ]);
126
+ // Fetch dynamic zone when dependencies change
127
+ (0, react_1.useEffect)(() => {
128
+ log?.info('Fetching dynamic zone', apiIsReady);
129
+ fetchDynamicZone();
130
+ }, [fetchDynamicZone]);
131
+ const setLoadingState = () => {
132
+ log?.info('Setting loading state');
133
+ setLoading(true);
134
+ setError(undefined);
135
+ setBannerProps(undefined);
136
+ setProductsProps(undefined);
137
+ setType(undefined);
138
+ };
139
+ const setErrorState = (error) => {
140
+ log?.info('Setting error state');
141
+ setLoading(false);
142
+ setError(error);
143
+ };
144
+ const setProductsSuccessState = (products) => {
145
+ log?.info('Setting carousel success state');
146
+ setError(undefined);
147
+ setType('products');
148
+ setProductsProps({
149
+ zoneId,
150
+ category: stableCategory,
151
+ carousel: products,
152
+ pageSize,
153
+ strategy: products.value.dynamicCarouselRequest.strategy,
154
+ withProductInfo
155
+ });
156
+ };
157
+ const setBannerSuccessState = (banner) => {
158
+ log?.info('Setting banner success state');
159
+ setError(undefined);
160
+ setType('banner');
161
+ const { width, height } = banner.value.dynamicBannerRequest;
162
+ setBannerProps({
163
+ banner,
164
+ zoneId,
165
+ size: [width, height],
166
+ category: stableCategory
167
+ });
168
+ };
169
+ const setVideoSuccessState = (video) => {
170
+ log?.info('Setting video success state');
171
+ setError(undefined);
172
+ setType('video');
173
+ const request = video.value.dynamicVideoRequest;
174
+ setVideoProps({
175
+ video,
176
+ category: stableCategory,
177
+ mimes: ['video/mp4', 'video/webm'],
178
+ minDuration: request.minDuration,
179
+ maxDuration: request.maxDuration,
180
+ zoneId: request.zoneId,
181
+ size: [request.width, request.height],
182
+ enabled
183
+ });
184
+ };
185
+ // Set loading to false if an error occurs or all response states are not loading
186
+ (0, react_1.useEffect)(() => {
187
+ // If there is an error, ensure loading is false
188
+ if (error !== undefined) {
189
+ return;
190
+ }
191
+ // If all response states are not loading, set loading to false
192
+ const allResponsesLoaded = (type === 'banner' && bannerResponseState?.loading === false) ||
193
+ (type === 'products' && productsResponseState?.loading === false) ||
194
+ (type === 'video' && videoResponseState?.loading === false);
195
+ if (allResponsesLoaded) {
196
+ setLoading(false);
197
+ }
198
+ else {
199
+ setLoading(true);
200
+ }
201
+ }, [
202
+ error,
203
+ type,
204
+ bannerResponseState?.loading,
205
+ productsResponseState?.loading,
206
+ videoResponseState?.loading
207
+ ]);
208
+ if (error !== undefined) {
209
+ return {
210
+ type: undefined,
211
+ loading: false,
212
+ refetchDynamicZone: fetchDynamicZone,
213
+ data: undefined,
214
+ error
215
+ };
216
+ }
217
+ else if (loading || !enabled) {
218
+ return {
219
+ type: undefined,
220
+ loading: true,
221
+ refetchDynamicZone: fetchDynamicZone,
222
+ data: undefined,
223
+ error
224
+ };
225
+ }
226
+ else if (type === 'banner' &&
227
+ bannerResponseState !== undefined &&
228
+ bannerResponseState.loading === false &&
229
+ bannerResponseState.error === undefined) {
230
+ return {
231
+ type: 'banner',
232
+ loading,
233
+ error,
234
+ data: bannerResponseState,
235
+ refetchDynamicZone: fetchDynamicZone
236
+ };
237
+ }
238
+ else if (type === 'products' && productsResponseState !== undefined) {
239
+ return {
240
+ type: 'products',
241
+ loading,
242
+ error,
243
+ data: productsResponseState,
244
+ refetchDynamicZone: fetchDynamicZone
245
+ };
246
+ }
247
+ else if (type === 'video' && videoResponseState !== undefined) {
248
+ return {
249
+ type: 'video',
250
+ loading,
251
+ error,
252
+ data: videoResponseState,
253
+ refetchDynamicZone: fetchDynamicZone
254
+ };
255
+ }
256
+ else {
257
+ log?.debug('Invalid dynamic zone state', zoneId);
258
+ log?.debug('Type', type);
259
+ log?.debug('Loading', loading);
260
+ log?.debug('Banner response state', bannerResponseState);
261
+ log?.debug('Products response state', productsResponseState);
262
+ log?.debug('Video response state', videoResponseState);
263
+ log?.debug('Error', error);
264
+ return {
265
+ error: (0, ads_core_client_1.Err)(new InvalidDynamicZoneState(zoneId)),
266
+ loading: false,
267
+ data: undefined,
268
+ refetchDynamicZone: fetchDynamicZone,
269
+ type: undefined
270
+ };
271
+ }
272
+ }
273
+ ;
274
+ class InvalidDynamicZoneState extends Error {
275
+ zoneId;
276
+ constructor(zoneId) {
277
+ super('useSurfsideDynamicZone was left in an invalid state. This is an internal error, please ' +
278
+ 'contact Surfside');
279
+ this.zoneId = zoneId;
280
+ }
281
+ }
282
+ exports.InvalidDynamicZoneState = InvalidDynamicZoneState;
283
+ //# sourceMappingURL=useSurfsideDynamicZone.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSurfsideDynamicZone.js","sourceRoot":"src/","sources":["hooks/useSurfsideDynamicZone.ts"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;AAyTb,wDA2OC;AAliBD,iCAAkE;AAClE,0CAAiD;AACjD,+DAWmC;AACnC,oCAckB;AAqHjB,CAAC;AAWD,CAAC;AAUD,CAAC;AAoBD,CAAC;AAYD,CAAC;AAcD,CAAC;AA6BF;;;;;;;GAOG,CAAA,CAAC;AAqBJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA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