@surfside/ads-react 0.1.0 → 0.1.2

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 (72) hide show
  1. package/README.md +127 -127
  2. package/lib/cjs/components/SurfsideBanner.js +71 -0
  3. package/lib/cjs/components/SurfsideBanner.js.map +1 -0
  4. package/lib/cjs/components/SurfsideCarousel.js +103 -0
  5. package/lib/cjs/components/SurfsideCarousel.js.map +1 -0
  6. package/lib/cjs/components/SurfsideDynamicZone.js +131 -0
  7. package/lib/cjs/components/SurfsideDynamicZone.js.map +1 -0
  8. package/lib/cjs/components/SurfsideProduct.js +3 -0
  9. package/lib/cjs/components/SurfsideProduct.js.map +1 -0
  10. package/lib/cjs/components/SurfsideVideo.js +82 -0
  11. package/lib/cjs/components/SurfsideVideo.js.map +1 -0
  12. package/lib/cjs/components/index.js +23 -0
  13. package/lib/cjs/components/index.js.map +1 -0
  14. package/lib/cjs/hooks/index.js +22 -0
  15. package/lib/cjs/hooks/index.js.map +1 -0
  16. package/lib/cjs/hooks/useSurfsideBanner.js +215 -0
  17. package/lib/cjs/hooks/useSurfsideBanner.js.map +1 -0
  18. package/lib/cjs/hooks/useSurfsideDynamicZone.js +202 -0
  19. package/lib/cjs/hooks/useSurfsideDynamicZone.js.map +1 -0
  20. package/lib/cjs/hooks/useSurfsideProducts.js +366 -0
  21. package/lib/cjs/hooks/useSurfsideProducts.js.map +1 -0
  22. package/lib/cjs/hooks/useSurfsideVideo.js +295 -0
  23. package/lib/cjs/hooks/useSurfsideVideo.js.map +1 -0
  24. package/lib/cjs/index.js +20 -16325
  25. package/lib/cjs/index.js.map +1 -0
  26. package/lib/cjs/provider/SurfsideContextProvider.js +158 -0
  27. package/lib/cjs/provider/SurfsideContextProvider.js.map +1 -0
  28. package/lib/cjs/provider/index.js +19 -0
  29. package/lib/cjs/provider/index.js.map +1 -0
  30. package/lib/cjs/utils/Analytics.js +181 -0
  31. package/lib/cjs/utils/Analytics.js.map +1 -0
  32. package/lib/cjs/utils/index.js +18 -0
  33. package/lib/cjs/utils/index.js.map +1 -0
  34. package/lib/esm/components/SurfsideBanner.js +67 -0
  35. package/lib/esm/components/SurfsideBanner.js.map +1 -0
  36. package/lib/esm/components/SurfsideCarousel.js +99 -0
  37. package/lib/esm/components/SurfsideCarousel.js.map +1 -0
  38. package/lib/esm/components/SurfsideDynamicZone.js +126 -0
  39. package/lib/esm/components/SurfsideDynamicZone.js.map +1 -0
  40. package/lib/esm/components/SurfsideProduct.js +2 -0
  41. package/lib/esm/components/SurfsideProduct.js.map +1 -0
  42. package/lib/esm/components/SurfsideVideo.js +78 -0
  43. package/lib/esm/components/SurfsideVideo.js.map +1 -0
  44. package/lib/esm/components/index.js +7 -0
  45. package/lib/esm/components/index.js.map +1 -0
  46. package/lib/esm/hooks/index.js +6 -0
  47. package/lib/esm/hooks/index.js.map +1 -0
  48. package/lib/esm/hooks/useSurfsideBanner.js +209 -0
  49. package/lib/esm/hooks/useSurfsideBanner.js.map +1 -0
  50. package/lib/esm/hooks/useSurfsideDynamicZone.js +197 -0
  51. package/lib/esm/hooks/useSurfsideDynamicZone.js.map +1 -0
  52. package/lib/esm/hooks/useSurfsideProducts.js +359 -0
  53. package/lib/esm/hooks/useSurfsideProducts.js.map +1 -0
  54. package/lib/esm/hooks/useSurfsideVideo.js +289 -0
  55. package/lib/esm/hooks/useSurfsideVideo.js.map +1 -0
  56. package/lib/esm/index.js +4 -16299
  57. package/lib/esm/index.js.map +1 -0
  58. package/lib/esm/provider/SurfsideContextProvider.js +151 -0
  59. package/lib/esm/provider/SurfsideContextProvider.js.map +1 -0
  60. package/lib/esm/provider/index.js +3 -0
  61. package/lib/esm/provider/index.js.map +1 -0
  62. package/lib/esm/utils/Analytics.js +171 -0
  63. package/lib/esm/utils/Analytics.js.map +1 -0
  64. package/lib/esm/utils/index.js +2 -0
  65. package/lib/esm/utils/index.js.map +1 -0
  66. package/lib/types/components/SurfsideBanner.d.ts +1 -2
  67. package/lib/types/components/SurfsideVideo.d.ts +0 -1
  68. package/lib/types/hooks/useSurfsideBanner.d.ts +1 -1
  69. package/package.json +13 -6
  70. package/lib/types/hooks/useSurfDynamicZone.d.ts +0 -7
  71. package/lib/types/types.d.ts +0 -33
  72. package/lib/types/utils/analytics.d.ts +0 -58
package/README.md CHANGED
@@ -1,127 +1,127 @@
1
- ## Core Library Elements
2
-
3
- ## Design Architecture
4
-
5
- The library follows a modern, modular React architecture with two primary layers:
6
-
7
- 1. **Provider**: `SurfsideProvider` – Initializes the Surfside Ads SDK and manages shared global context.
8
- 2. **Hooks**: Custom hooks that encapsulate ad fetching, rendering logic, state management, and analytics.
9
-
10
- This separation of concerns allows for clean and extensible integration across a variety of use cases.
11
-
12
- ## Quick Start
13
-
14
- ### Installation
15
-
16
- ```bash
17
- # Using npm
18
- npm install @surfside/ads-react
19
-
20
- # Using yarn
21
- yarn add @surfside/ads-react
22
-
23
- # Using bun
24
- bun add @surfside/ads-react
25
- ```
26
-
27
- ### Basic Usage
28
-
29
- 1. **Wrap your application with `SurfsideProvider`** to provide the necessary context.
30
-
31
- ```tsx
32
- export default function App() {
33
- return (
34
- <html lang="en">
35
- <head>
36
- {/* Head Content */}
37
- </head>
38
- <body>
39
- <SurfsideProvider
40
- channelId='XXXXX'
41
- accountId='XXXXX'
42
- siteId='XXXXX'
43
- locationId='surfside-nyc'
44
- userId='surfside-007'
45
- >
46
- <div>
47
- {/* Application Content */}
48
- </div>
49
- </SurfsideProvider>
50
- </body>
51
- </html>
52
- );
53
- }
54
- ```
55
-
56
- 2. **Render a banner ad using the `useSurfsideBanner` hook**.
57
-
58
- ```tsx
59
- const Homepage = () => {
60
- const {
61
- banner,
62
- loading,
63
- error,
64
- analytics
65
- } = useSurfsideBanner({
66
- zoneId: 'XXXXX',
67
- size: [4,1 ]
68
- });
69
-
70
- useEffect(() => {
71
- analytics?.trackWin();
72
- }, [analytics]);
73
-
74
- if (loading) {
75
- return <BannerSkeleton/>;
76
- }
77
-
78
- if (error) {
79
- return <FallbackComponent/>;
80
- }
81
-
82
- return (
83
- <div>
84
- <h1>Welcome!</h1>
85
- <MenuBar/>
86
- {/* Banner Ad right below the menu bar */}
87
- <div dangerouslySetInnerHTML={{__html: banner.adm}}></div>
88
- {/* ... webpage content */}
89
- </div>
90
- );
91
- };
92
- ```
93
-
94
- ## Where to start
95
-
96
- Follow these guides to set up your Surfside Ads implementation
97
-
98
- * [Surfside API Provider Implementation Guide](../documents/_surfside_ads-react.Implementation_Guides.Surfside_Provider.html)
99
-
100
- * [Banner Implementation Guide](../documents/_surfside_ads-react.Implementation_Guides.Banner_Ads.html)
101
-
102
- * [Video Implementation Guide](../documents/_surfside_ads-react.Implementation_Guides.Video_Ads.html)
103
-
104
- * [Product Feed Implementation Guide](../documents/_surfside_ads-react.Implementation_Guides.Sponsored_and_Recommended_Products.html)
105
-
106
- * [Dynamic Zone Integration Guide](../documents/_surfside_ads-react.Implementation_Guides.Dynamic_Zones.html)
107
-
108
- ## Performance & Compatibility
109
-
110
- The `@surfside/ads-react` library is designed to be **client-side only**. All hooks and rendering logic must run in the browser as access to the browser API is required for bid requests to function correctly. Server-side rendering (SSR) is **not supported yet**, and attempting to use hooks or providers on the server will result in runtime errors.
111
-
112
- To avoid hydration issues, always ensure components using Surfside hooks are rendered only after the client has mounted.
113
-
114
-
115
- ```tsx
116
- const IsClientOnly = ({ children }: { children: React.ReactNode }) => {
117
- const [ready, setReady] = React.useState(false);
118
- React.useEffect(() => setReady(true), []);
119
- return ready ? <>{children}</> : null;
120
- };
121
- ```
122
-
123
- You can wrap Surfside components in a guard like this if needed.
124
-
125
- ## License
126
-
127
- Copyright © 2025 Surfside. All rights reserved.
1
+ ## Core Library Elements
2
+
3
+ ## Design Architecture
4
+
5
+ The library follows a modern, modular React architecture with two primary layers:
6
+
7
+ 1. **Provider**: `SurfsideProvider` – Initializes the Surfside Ads SDK and manages shared global context.
8
+ 2. **Hooks**: Custom hooks that encapsulate ad fetching, rendering logic, state management, and analytics.
9
+
10
+ This separation of concerns allows for clean and extensible integration across a variety of use cases.
11
+
12
+ ## Quick Start
13
+
14
+ ### Installation
15
+
16
+ ```bash
17
+ # Using npm
18
+ npm install @surfside/ads-react
19
+
20
+ # Using yarn
21
+ yarn add @surfside/ads-react
22
+
23
+ # Using bun
24
+ bun add @surfside/ads-react
25
+ ```
26
+
27
+ ### Basic Usage
28
+
29
+ 1. **Wrap your application with `SurfsideProvider`** to provide the necessary context.
30
+
31
+ ```tsx
32
+ export default function App() {
33
+ return (
34
+ <html lang="en">
35
+ <head>
36
+ {/* Head Content */}
37
+ </head>
38
+ <body>
39
+ <SurfsideProvider
40
+ channelId='XXXXX'
41
+ accountId='XXXXX'
42
+ siteId='XXXXX'
43
+ locationId='surfside-nyc'
44
+ userId='surfside-007'
45
+ >
46
+ <div>
47
+ {/* Application Content */}
48
+ </div>
49
+ </SurfsideProvider>
50
+ </body>
51
+ </html>
52
+ );
53
+ }
54
+ ```
55
+
56
+ 2. **Render a banner ad using the `useSurfsideBanner` hook**.
57
+
58
+ ```tsx
59
+ const Homepage = () => {
60
+ const {
61
+ banner,
62
+ loading,
63
+ error,
64
+ analytics
65
+ } = useSurfsideBanner({
66
+ zoneId: 'XXXXX',
67
+ size: [4,1 ]
68
+ });
69
+
70
+ useEffect(() => {
71
+ analytics?.trackWin();
72
+ }, [analytics]);
73
+
74
+ if (loading) {
75
+ return <BannerSkeleton/>;
76
+ }
77
+
78
+ if (error) {
79
+ return <FallbackComponent/>;
80
+ }
81
+
82
+ return (
83
+ <div>
84
+ <h1>Welcome!</h1>
85
+ <MenuBar/>
86
+ {/* Banner Ad right below the menu bar */}
87
+ <div dangerouslySetInnerHTML={{__html: banner.adm}}></div>
88
+ {/* ... webpage content */}
89
+ </div>
90
+ );
91
+ };
92
+ ```
93
+
94
+ ## Where to start
95
+
96
+ Follow these guides to set up your Surfside Ads implementation
97
+
98
+ * [Surfside API Provider Implementation Guide](../documents/_surfside_ads-react.Implementation_Guides.Surfside_Provider.html)
99
+
100
+ * [Banner Implementation Guide](../documents/_surfside_ads-react.Implementation_Guides.Banner_Ads.html)
101
+
102
+ * [Video Implementation Guide](../documents/_surfside_ads-react.Implementation_Guides.Video_Ads.html)
103
+
104
+ * [Product Feed Implementation Guide](../documents/_surfside_ads-react.Implementation_Guides.Sponsored_and_Recommended_Products.html)
105
+
106
+ * [Dynamic Zone Integration Guide](../documents/_surfside_ads-react.Implementation_Guides.Dynamic_Zones.html)
107
+
108
+ ## Performance & Compatibility
109
+
110
+ The `@surfside/ads-react` library is designed to be **client-side only**. All hooks and rendering logic must run in the browser as access to the browser API is required for bid requests to function correctly. Server-side rendering (SSR) is **not supported yet**, and attempting to use hooks or providers on the server will result in runtime errors.
111
+
112
+ To avoid hydration issues, always ensure components using Surfside hooks are rendered only after the client has mounted.
113
+
114
+
115
+ ```tsx
116
+ const IsClientOnly = ({ children }: { children: React.ReactNode }) => {
117
+ const [ready, setReady] = React.useState(false);
118
+ React.useEffect(() => setReady(true), []);
119
+ return ready ? <>{children}</> : null;
120
+ };
121
+ ```
122
+
123
+ You can wrap Surfside components in a guard like this if needed.
124
+
125
+ ## License
126
+
127
+ Copyright © 2025 Surfside. All rights reserved.
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ 'use client';
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.SurfsideBanner = void 0;
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const react_1 = require("react");
7
+ const hooks_1 = require("../hooks");
8
+ const provider_1 = require("../provider");
9
+ const ads_core_1 = require("@surfside/ads-core");
10
+ const ads_core_web_1 = require("@surfside/ads-core-web");
11
+ /**
12
+ * SurfsideBanner renders a banner ad using the `useSurfsideBanner` hook. It automatically
13
+ * manages banner fetching, win tracking, and optional UI fallback states.
14
+ *
15
+ * Customize the banner lifecycle using callbacks and optionally inject custom styles
16
+ * or loading/error content.
17
+ *
18
+ * @param {ISurfsideBannerProps} props Props used to configure the banner rendering behavior
19
+ * @returns A responsive ad container that manages display and state transitions
20
+ */
21
+ const SurfsideBanner = ({ zoneId, size, enabled = true, renderLoading, renderError, onRender, onWin, onError, }) => {
22
+ const { banner, loading, error } = (0, hooks_1.useSurfsideBanner)({
23
+ zoneId,
24
+ size,
25
+ enabled,
26
+ });
27
+ const [renderedBanner, setRenderedBanner] = (0, react_1.useState)();
28
+ const { logger } = (0, provider_1.useSurfsideContext)();
29
+ const log = (0, ads_core_1.Ctx)(logger)?.with('SurfsideBanner');
30
+ // call user callback
31
+ (0, react_1.useEffect)(() => {
32
+ if (banner !== undefined) {
33
+ log?.info('SurfsideBanner: win tracked', banner.id);
34
+ onWin?.(banner.id);
35
+ }
36
+ }, [banner]);
37
+ // Call render callback
38
+ (0, react_1.useEffect)(() => {
39
+ if (banner !== undefined) {
40
+ log?.info('SurfsideBanner: banner rendered', banner.id);
41
+ onRender?.(banner.id);
42
+ }
43
+ }, [banner]);
44
+ // Handle error callback
45
+ (0, react_1.useEffect)(() => {
46
+ if (error !== undefined) {
47
+ log?.error('SurfsideBanner: error', error);
48
+ onError?.(error);
49
+ }
50
+ }, [error]);
51
+ (0, react_1.useEffect)(() => {
52
+ if (banner != undefined) {
53
+ const rendered = (0, ads_core_web_1.RenderBanner)(logger, banner);
54
+ if (rendered.ok) {
55
+ setRenderedBanner(rendered.value);
56
+ }
57
+ }
58
+ else {
59
+ setRenderedBanner(undefined);
60
+ }
61
+ }, [banner]);
62
+ return ((0, jsx_runtime_1.jsxs)("div", { children: [loading && renderLoading?.(), error !== undefined && renderError?.(), banner !== undefined &&
63
+ renderedBanner !== undefined && ((0, jsx_runtime_1.jsx)("div", { ref: (ref) => {
64
+ if (ref != undefined) {
65
+ ref.innerHTML = '';
66
+ ref.appendChild(renderedBanner);
67
+ }
68
+ } }))] }));
69
+ };
70
+ exports.SurfsideBanner = SurfsideBanner;
71
+ //# sourceMappingURL=SurfsideBanner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SurfsideBanner.js","sourceR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AC,CAAC;IAEb,wBAAwB;IACxB,IAAA,iBAAS,EAAC,GAAG,EAAE;QACX,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACtB,GAAG,EAAE,KAAK,CAAC,uBAAuB,EAAE,KAAK,CAAC,CAAC;YAC3C,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;IACL,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,IAAA,iBAAS,EAAC,GAAG,EAAE;QACX,IAAI,MAAM,IAAI,SAAS,EAAE,CAAC;YACtB,MAAM,QAAQ,GAAG,IAAA,2BAAY,EAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YAC9C,IAAI,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACd,iBAAiB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACtC,CAAC;QACL,CAAC;aAAM,CAAC;YACJ,iBAAiB,CAAC,SAAS,CAAC,CAAC;QACjC,CAAC;IACL,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,OAAO,CACH,4CACK,OAAO,IAAI,aAAa,EAAE,EAAE,EAE5B,KAAK,KAAK,SAAS,IAAI,WAAW,EAAE,EAAE,EAEtC,MAAM,KAAK,SAAS;gBACnB,cAAc,KAAK,SAAS,IAAI,CAC9B,gCACI,GAAG,EAAE,CAAC,GAAG,EAAE,EAAE;oBACT,IAAI,GAAG,IAAI,SAAS,EAAE,CAAC;wBACnB,GAAG,CAAC,SAAS,GAAG,EAAE,CAAC;wBACnB,GAAG,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;oBACpC,CAAC;gBACL,CAAC,GACH,CACL,IACC,CACT,CAAC;AACN,CAAC,CAAC;AAzEW,QAAA,cAAc,kBAyEzB"}
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ 'use client';
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.SurfsideCarousel = void 0;
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const ads_core_1 = require("@surfside/ads-core");
7
+ const provider_1 = require("../provider");
8
+ const react_1 = require("react");
9
+ ;
10
+ const SurfsideCarousel = ({ zoneId, cardMinWidth, carouselLimits, nextType, recommender, requestBuilder, nativeRequestBuilder, enabled = true, strategy }) => {
11
+ const { isReady, error: apiError, hasError, startRequest, defaultNative, buildHybridCarousel, buildSponsoredCarousel, buildRecommendedCarousel, renderCarousel, logger } = (0, provider_1.useSurfsideContext)();
12
+ const log = (0, ads_core_1.Ctx)(logger)?.with('SurfsideCarousel');
13
+ const [error, setError] = (0, react_1.useState)();
14
+ const [renderedCarousel, setRenderedCarousel] = (0, react_1.useState)();
15
+ const ref = (0, react_1.useRef)(null);
16
+ (0, react_1.useEffect)(() => {
17
+ let cancelled = false;
18
+ if (!isReady || !enabled) {
19
+ if (hasError) {
20
+ setErrorState(apiError);
21
+ }
22
+ else {
23
+ setLoadingState();
24
+ }
25
+ return;
26
+ }
27
+ const request = (requestBuilder ?? startRequest(zoneId))
28
+ .withNative((nativeRequestBuilder ?? defaultNative())
29
+ .withMetaProduct()
30
+ .build());
31
+ const builtCarousel = (0, ads_core_1.TryDoFlat)(() => {
32
+ switch (strategy) {
33
+ case 'hybrid': {
34
+ return buildHybridCarousel({
35
+ type: recommender,
36
+ }, request.build());
37
+ }
38
+ case 'recommended': {
39
+ return buildRecommendedCarousel({
40
+ type: recommender
41
+ });
42
+ }
43
+ case 'sponsored': {
44
+ return buildSponsoredCarousel(request.build());
45
+ }
46
+ }
47
+ });
48
+ if (!builtCarousel.ok) {
49
+ setErrorState(builtCarousel);
50
+ return;
51
+ }
52
+ const builtCarouselValue = builtCarousel.value;
53
+ renderCarousel(builtCarouselValue, cardMinWidth, carouselLimits, nextType)
54
+ .then(renderedCarouselResult => {
55
+ if (cancelled) {
56
+ return;
57
+ }
58
+ if (!renderedCarouselResult.ok) {
59
+ setErrorState(renderedCarouselResult);
60
+ return;
61
+ }
62
+ else {
63
+ setSuccessState(renderedCarouselResult.value);
64
+ }
65
+ });
66
+ return () => void (cancelled = true);
67
+ }, [isReady, apiError, hasError, strategy, recommender, cardMinWidth, carouselLimits, nextType]);
68
+ (0, react_1.useEffect)(() => {
69
+ if (ref.current === null || renderedCarousel === undefined) {
70
+ return;
71
+ }
72
+ ref.current.innerHTML = '';
73
+ ref.current.appendChild(renderedCarousel.element);
74
+ renderedCarousel.init()
75
+ .then(initResult => {
76
+ if (!initResult.ok) {
77
+ setErrorState(initResult);
78
+ if (ref.current !== null) {
79
+ log?.error('First page was null');
80
+ ref.current.innerHTML = '';
81
+ }
82
+ }
83
+ });
84
+ ;
85
+ }, [renderedCarousel]);
86
+ const setErrorState = (error) => {
87
+ setError(error);
88
+ setRenderedCarousel(undefined);
89
+ };
90
+ const setLoadingState = () => {
91
+ setError(undefined);
92
+ };
93
+ const setSuccessState = (renderedCarousel) => {
94
+ setRenderedCarousel(renderedCarousel);
95
+ setError(undefined);
96
+ };
97
+ if (error !== undefined) {
98
+ log?.error(error.error);
99
+ }
100
+ return (0, jsx_runtime_1.jsx)("div", { ref: ref });
101
+ };
102
+ exports.SurfsideCarousel = SurfsideCarousel;
103
+ //# sourceMappingURL=SurfsideCarousel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SurfsideCarousel.js","sourceRoot":"src/","sources":["components/SurfsideCarousel.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;AAEb,iDAM4B;AAE5B,0CAAiD;AACjD,iCAAoD;AAmBnD,CAAC;AAWK,MAAM,gBAAgB,GAAG,CAAC,EAC7B,MAAM,EACN,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,WAAW,EACX,cAAc,EACd,oBAAoB,EACpB,OAAO,GAAG,IAAI,EACd,QAAQ,EACY,EAAE,EAAE;IACxB,MAAM,EACF,OAAO,EACP,KAAK,EAAE,QAAQ,EACf,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,mBAAmB,EACnB,sBAAsB,EACtB,wBAAwB,EACxB,cAAc,EACd,MAAM,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AAC,CAAC;gBAC1B,IAAI,GAAG,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;oBACvB,GAAG,EAAE,KAAK,CAAC,qBAAqB,CAAC,CAAC;oBAClC,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,EAAE,CAAC;gBAC/B,CAAC;YACL,CAAC;QACL,CAAC,CAAC,CAAC;QACP,CAAC;IACL,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAEvB,MAAM,aAAa,GAAG,CAAC,KAAgB,EAAE,EAAE;QACvC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAChB,mBAAmB,CAAC,SAAS,CAAC,CAAC;IACnC,CAAC,CAAC;IAEF,MAAM,eAAe,GAAG,GAAG,EAAE;QACzB,QAAQ,CAAC,SAAS,CAAC,CAAC;IACxB,CAAC,CAAC;IAEF,MAAM,eAAe,GAAG,CAAC,gBAAmC,EAAE,EAAE;QAC5D,mBAAmB,CAAC,gBAAgB,CAAC,CAAC;QACtC,QAAQ,CAAC,SAAS,CAAC,CAAC;IACxB,CAAC,CAAC;IAEF,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACtB,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IACD,OAAO,gCAAK,GAAG,EAAE,GAAG,GAAQ,CAAC;AACjC,CAAC,CAAC;AA9HW,QAAA,gBAAgB,oBA8H3B"}
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ 'use client';
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.DynamicZoneUnmountedError = exports.SurfsideDynamicZone = void 0;
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const ads_core_1 = require("@surfside/ads-core");
7
+ const react_1 = require("react");
8
+ const provider_1 = require("../provider");
9
+ const SurfsideDynamicZone = ({ zoneId, carousel, enabled = true, onError }) => {
10
+ const { isReady: apiIsReady, hasError: apiHasError, error: apiError, getDynamicZone, buildDynamicZoneRequest, buildDynamicResponse, renderBanner, renderVideo, renderCarousel, logger } = (0, provider_1.useSurfsideContext)();
11
+ const log = (0, react_1.useMemo)(() => (0, ads_core_1.Ctx)(logger)?.with('SurfsideDynamicZone'), [logger]);
12
+ log?.info('Rendering SurfsideDynamicZone component');
13
+ const [error, setError] = (0, react_1.useState)();
14
+ const [dynamicResponse, setDynamicResponse] = (0, react_1.useState)();
15
+ const ref = (0, react_1.useRef)(null);
16
+ (0, react_1.useEffect)(() => {
17
+ let cancelled = false;
18
+ if (!apiIsReady || !enabled) {
19
+ if (apiHasError) {
20
+ setErrorState(apiError);
21
+ }
22
+ return;
23
+ }
24
+ (0, ads_core_1.AsyncPipe)(getDynamicZone(zoneId))
25
+ .then(buildDynamicZoneRequest.bind(undefined, zoneId))
26
+ .then(buildDynamicResponse)
27
+ .result()
28
+ .then(dynamicResponse => {
29
+ if (cancelled) {
30
+ return;
31
+ }
32
+ if (!dynamicResponse.ok) {
33
+ setErrorState(dynamicResponse);
34
+ return;
35
+ }
36
+ setSuccessState(dynamicResponse.value);
37
+ });
38
+ return () => void (cancelled = true);
39
+ }, [
40
+ apiIsReady,
41
+ apiError,
42
+ apiHasError,
43
+ getDynamicZone,
44
+ buildDynamicZoneRequest,
45
+ buildDynamicResponse,
46
+ log,
47
+ zoneId,
48
+ enabled
49
+ ]);
50
+ (0, react_1.useEffect)(() => {
51
+ let cancelled = false;
52
+ if (!apiIsReady || !enabled ||
53
+ dynamicResponse === undefined ||
54
+ ref.current === null) {
55
+ return;
56
+ }
57
+ switch (dynamicResponse.type) {
58
+ case 'banner': {
59
+ const bannerResult = renderBanner(dynamicResponse);
60
+ if (!bannerResult.ok) {
61
+ setErrorState(bannerResult);
62
+ return;
63
+ }
64
+ ref.current.appendChild(bannerResult.value);
65
+ break;
66
+ }
67
+ case 'video': {
68
+ const videoResult = renderVideo(dynamicResponse);
69
+ if (!videoResult.ok) {
70
+ setErrorState(videoResult);
71
+ return;
72
+ }
73
+ ref.current.appendChild(videoResult.value);
74
+ break;
75
+ }
76
+ case 'carousel': {
77
+ renderCarousel(dynamicResponse, carousel.cardMinWidth, carousel.carouselLimits, carousel.nextType).then(carouselResponse => {
78
+ if (cancelled) {
79
+ return;
80
+ }
81
+ if (!carouselResponse.ok) {
82
+ setErrorState(carouselResponse);
83
+ return;
84
+ }
85
+ // Have to check ref again since we're in a promise.then
86
+ if (ref.current === null) {
87
+ setErrorState((0, ads_core_1.Err)(new DynamicZoneUnmountedError));
88
+ return;
89
+ }
90
+ ref.current.appendChild(carouselResponse.value.element);
91
+ carouselResponse.value.init()
92
+ .then(initResult => {
93
+ if (!initResult.ok) {
94
+ setErrorState(initResult);
95
+ if (ref.current !== null) {
96
+ ref.current.innerHTML = '';
97
+ }
98
+ }
99
+ });
100
+ });
101
+ }
102
+ }
103
+ return () => {
104
+ cancelled = true;
105
+ if (ref.current !== null) {
106
+ ref.current.innerHTML = '';
107
+ }
108
+ };
109
+ }, [dynamicResponse, renderBanner, renderVideo, renderCarousel, enabled]);
110
+ const setErrorState = (error) => {
111
+ setError(error);
112
+ setDynamicResponse(undefined);
113
+ };
114
+ const setSuccessState = (response) => {
115
+ setError(undefined);
116
+ setDynamicResponse(response);
117
+ };
118
+ if (error !== undefined) {
119
+ log?.error(error.error);
120
+ onError?.(error);
121
+ }
122
+ return (0, jsx_runtime_1.jsx)("div", { ref: ref });
123
+ };
124
+ exports.SurfsideDynamicZone = SurfsideDynamicZone;
125
+ class DynamicZoneUnmountedError extends Error {
126
+ constructor() {
127
+ super('Dynamic zone container unmounted while processing carousel');
128
+ }
129
+ }
130
+ exports.DynamicZoneUnmountedError = DynamicZoneUnmountedError;
131
+ //# sourceMappingURL=SurfsideDynamicZone.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SurfsideDynamicZone.js","sourceRoot":"src/","sources":["components/SurfsideDynamicZone.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;AAEb,iDAAyE;AAEzE,iCAA6D;AAC7D,0CAAiD;AAU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AE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC;IAE1E,MAAM,aAAa,GAAG,CAAC,KAAgB,EAAE,EAAE;QACvC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAChB,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAClC,CAAC,CAAC;IAEF,MAAM,eAAe,GAAG,CAAC,QAA+B,EAAE,EAAE;QACxD,QAAQ,CAAC,SAAS,CAAC,CAAC;QACpB,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC,CAAC;IAEF,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACtB,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACxB,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;IAED,OAAO,gCAAK,GAAG,EAAE,GAAG,GAAQ,CAAC;AACjC,CAAC,CAAC;AAxJW,QAAA,mBAAmB,uBAwJ9B;AAEF,MAAa,yBAA0B,SAAQ,KAAK;IAChD;QACI,KAAK,CAAC,4DAA4D,CAAC,CAAC;IACxE,CAAC;CACJ;AAJD,8DAIC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=SurfsideProduct.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SurfsideProduct.js","sourceRoot":"src/","sources":["components/SurfsideProduct.tsx"],"names":[],"mappings":""}