@wavebirdai/api 0.1.0-beta.2 → 0.1.0-beta.4

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.
@@ -7,7 +7,14 @@ export function WavebirdPlacement({ clientId, userId, conversationId, onReady })
7
7
  const target = useRef(null);
8
8
  useEffect(() => {
9
9
  if (!target.current || !clientId || !userId || !conversationId) return;
10
- const ads = createPublisherAds({
10
+ const controller = new AbortController();
11
+ let disposed = false;
12
+ let ads = null;
13
+ void fetch("/api/sponsor-session", { cache: "no-store", signal: controller.signal }).then(async response => {
14
+ if (!response.ok) return;
15
+ const sessionId = (await response.json()).session_id;
16
+ if (disposed || !/^[A-Za-z0-9_-]{1,128}$/.test(sessionId)) return;
17
+ ads = createPublisherAds({
11
18
  target: target.current,
12
19
  clientId,
13
20
  surfaceId: "chat_assistant",
@@ -16,13 +23,16 @@ export function WavebirdPlacement({ clientId, userId, conversationId, onReady })
16
23
  consentMode: "wavebird_consent",
17
24
  userId,
18
25
  conversationId,
26
+ sessionId,
27
+ turnBinding: true,
19
28
  rendererUrl: "https://api.wavebird.ai/v1/render.js",
20
29
  placementEndpoint: "/api/sponsor-slot",
21
30
  consentEndpoint: "/api/sponsor-consent",
22
31
  privacySettingsTarget: "#wavebird-privacy-settings"
23
- });
24
- onReady?.(ads);
25
- return () => { onReady?.(null); ads.dispose(); };
32
+ });
33
+ onReady?.(ads);
34
+ }).catch(() => {});
35
+ return () => { disposed = true; controller.abort(); onReady?.(null); ads?.dispose(); };
26
36
  }, [clientId, userId, conversationId, onReady]);
27
37
  return <>
28
38
  <button id="wavebird-privacy-settings" type="button">Sponsored choices</button>
@@ -12,8 +12,16 @@ export function WavebirdPlacement({ clientId, userId, conversationId, onReady }:
12
12
  const target = useRef<HTMLElement | null>(null);
13
13
  useEffect(() => {
14
14
  if (!target.current || !clientId || !userId || !conversationId) return;
15
- const ads = createPublisherAds({
16
- target: target.current,
15
+ const container = target.current;
16
+ const controller = new AbortController();
17
+ let disposed = false;
18
+ let ads: PublisherAds | null = null;
19
+ void fetch("/api/sponsor-session", { cache: "no-store", signal: controller.signal }).then(async response => {
20
+ if (!response.ok) return;
21
+ const sessionId = (await response.json()).session_id;
22
+ if (disposed || !/^[A-Za-z0-9_-]{1,128}$/.test(sessionId)) return;
23
+ ads = createPublisherAds({
24
+ target: container,
17
25
  clientId,
18
26
  surfaceId: "chat_assistant",
19
27
  jobType: "chat",
@@ -21,13 +29,16 @@ export function WavebirdPlacement({ clientId, userId, conversationId, onReady }:
21
29
  consentMode: "wavebird_consent",
22
30
  userId,
23
31
  conversationId,
32
+ sessionId,
33
+ turnBinding: true,
24
34
  rendererUrl: "https://api.wavebird.ai/v1/render.js",
25
35
  placementEndpoint: "/api/sponsor-slot",
26
36
  consentEndpoint: "/api/sponsor-consent",
27
37
  privacySettingsTarget: "#wavebird-privacy-settings"
28
- });
29
- onReady?.(ads);
30
- return () => { onReady?.(null); ads.dispose(); };
38
+ });
39
+ onReady?.(ads);
40
+ }).catch(() => {});
41
+ return () => { disposed = true; controller.abort(); onReady?.(null); ads?.dispose(); };
31
42
  }, [clientId, userId, conversationId, onReady]);
32
43
  return <>
33
44
  <button id="wavebird-privacy-settings" type="button">Sponsored choices</button>