@thead-vantage/react 2.7.0 → 2.9.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thead-vantage/react",
3
- "version": "2.7.0",
3
+ "version": "2.9.0",
4
4
  "description": "React components and utilities for TheAd Vantage ad platform integration",
5
5
  "main": "./src/index.ts",
6
6
  "module": "./src/index.ts",
@@ -124,7 +124,7 @@ export function AdBanner({
124
124
  rel="noopener noreferrer"
125
125
  className="block"
126
126
  >
127
- {ad.type === 'image' ? (
127
+ {(ad.type === 'image' || ad.type === 'standard') && ad.contentUrl ? (
128
128
  <Image
129
129
  src={ad.contentUrl}
130
130
  alt={ad.name}
@@ -2,7 +2,13 @@
2
2
 
3
3
  import { useEffect, useState } from 'react';
4
4
  import Image from 'next/image';
5
- import { fetchAds, trackImpression, trackClick, type AdData } from '../lib/ads';
5
+ import {
6
+ fetchAds,
7
+ trackImpression,
8
+ trackClick,
9
+ type AdData,
10
+ type AdsResponse
11
+ } from '../lib/ads';
6
12
 
7
13
  interface AdDisplayProps {
8
14
  position?: string;
@@ -21,12 +27,15 @@ export default function AdDisplay({ position, className = '' }: AdDisplayProps)
21
27
  setLoading(true);
22
28
  setError(null);
23
29
 
24
- const params: Record<string, string> = {};
25
- if (position) {
26
- params.position = position;
27
- }
30
+ // Build params object - fetchAds accepts Record<string, string> | undefined
31
+ // Note: fetchAds is different from fetchAdBanner (which requires platformId/apiKey)
32
+ const params: Record<string, string> | undefined = position
33
+ ? { position }
34
+ : undefined;
28
35
 
29
- const response = await fetchAds(params);
36
+ // Explicitly type to avoid confusion with fetchAdBanner's FetchAdBannerParams
37
+ const fetchAdsTyped: (params?: Record<string, string>) => Promise<AdsResponse> = fetchAds;
38
+ const response = await fetchAdsTyped(params);
30
39
 
31
40
  if (response.success && response.ad) {
32
41
  setAd(response.ad);
package/src/lib/ads.ts CHANGED
@@ -56,6 +56,9 @@ export interface FetchAdBannerParams {
56
56
  /**
57
57
  * Fetch ads from TheAd Vantage platform (generic)
58
58
  * In development mode, uses mock data and prevents tracking
59
+ *
60
+ * @param params - Optional query parameters as key-value pairs
61
+ * @returns Promise resolving to AdsResponse
59
62
  */
60
63
  export async function fetchAds(params?: Record<string, string>): Promise<AdsResponse> {
61
64
  try {
@@ -183,6 +186,14 @@ export async function fetchAdBanner(params: FetchAdBannerParams): Promise<AdBann
183
186
  };
184
187
  };
185
188
 
189
+ // Helper to normalize ad type - "standard" should be treated as "image"
190
+ const normalizeAdType = (ad: Ad): Ad => {
191
+ if (ad.type === 'standard' && ad.contentUrl) {
192
+ return { ...ad, type: 'image' };
193
+ }
194
+ return ad;
195
+ };
196
+
186
197
  // Handle both single ad and array of ads
187
198
  if (data.ads && Array.isArray(data.ads) && data.ads.length > 0) {
188
199
  // If we get an array, use the first ad and ensure it's Ad type
@@ -190,10 +201,13 @@ export async function fetchAdBanner(params: FetchAdBannerParams): Promise<AdBann
190
201
  console.log('[AdBanner] Processing ads array, first ad:', JSON.stringify(firstAd, null, 2));
191
202
 
192
203
  // Check if it's already an Ad, otherwise convert from AdData
193
- const ad: Ad = isAd(firstAd)
204
+ let ad: Ad = isAd(firstAd)
194
205
  ? firstAd
195
206
  : convertToAd(firstAd as AdData);
196
207
 
208
+ // Normalize the type (standard -> image)
209
+ ad = normalizeAdType(ad);
210
+
197
211
  console.log('[AdBanner] Converted ad:', JSON.stringify(ad, null, 2));
198
212
 
199
213
  return {
@@ -206,10 +220,19 @@ export async function fetchAdBanner(params: FetchAdBannerParams): Promise<AdBann
206
220
  }
207
221
 
208
222
  // Handle single ad response - convert AdData to Ad
209
- // Since data.ad is typed as AdData, we always convert it
210
223
  if (data.ad) {
211
224
  console.log('[AdBanner] Processing single ad:', JSON.stringify(data.ad, null, 2));
212
- const ad: Ad = convertToAd(data.ad);
225
+
226
+ // Check if it's already in Ad format or needs conversion
227
+ let ad: Ad;
228
+ if (isAd(data.ad)) {
229
+ // Already in Ad format, normalize the type
230
+ ad = normalizeAdType(data.ad);
231
+ } else {
232
+ // Convert from AdData format
233
+ ad = convertToAd(data.ad);
234
+ }
235
+
213
236
  console.log('[AdBanner] Converted ad:', JSON.stringify(ad, null, 2));
214
237
 
215
238
  return {