@thead-vantage/react 2.22.0 → 2.24.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.22.0",
3
+ "version": "2.24.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",
@@ -35,6 +35,7 @@
35
35
  "files": [
36
36
  "src/components",
37
37
  "src/lib",
38
+ "src/assets",
38
39
  "src/index.ts",
39
40
  "README.md"
40
41
  ],
@@ -140,18 +140,25 @@ export function AdBanner({
140
140
  if (development || isLocalhost) {
141
141
  // In development mode or localhost, show TheAd Vantage logo as fallback ad
142
142
  console.warn('[AdBanner] CORS error in development mode - showing TheAd Vantage fallback ad. Tracking is disabled.');
143
- // Create a fallback ad with TheAd Vantage logo
144
- setAd({
145
- id: 'thead-vantage-fallback',
146
- name: 'TheAd Vantage',
147
- type: 'image',
148
- contentUrl: '/TheAd-Vantage-Logo.png',
149
- targetUrl: 'https://www.thead-vantage.com',
150
- width: 300,
151
- height: 250,
143
+ // Import and use fallback ad configuration
144
+ import('../lib/thead-vantage-assets').then(({ THEAD_VANTAGE_FALLBACK_AD }) => {
145
+ setAd(THEAD_VANTAGE_FALLBACK_AD);
146
+ setDevMode(true);
147
+ setError(null); // Don't show error in dev mode
148
+ }).catch(() => {
149
+ // If import fails, use inline fallback
150
+ setAd({
151
+ id: 'thead-vantage-fallback',
152
+ name: 'TheAd Vantage',
153
+ type: 'image',
154
+ contentUrl: '/TheAd-Vantage-Logo.png',
155
+ targetUrl: 'https://www.thead-vantage.com',
156
+ width: 300,
157
+ height: 250,
158
+ });
159
+ setDevMode(true);
160
+ setError(null);
152
161
  });
153
- setDevMode(true);
154
- setError(null); // Don't show error in dev mode
155
162
  } else {
156
163
  console.error('[AdBanner] CORS Error Details:', {
157
164
  message: err.message,
@@ -164,18 +171,25 @@ export function AdBanner({
164
171
  // For other errors, show the error message (unless in development or localhost)
165
172
  if (development || isLocalhost) {
166
173
  console.warn('[AdBanner] Error in development mode - showing TheAd Vantage fallback ad:', err);
167
- // Create a fallback ad with TheAd Vantage logo
168
- setAd({
169
- id: 'thead-vantage-fallback',
170
- name: 'TheAd Vantage',
171
- type: 'image',
172
- contentUrl: '/TheAd-Vantage-Logo.png',
173
- targetUrl: 'https://www.thead-vantage.com',
174
- width: 300,
175
- height: 250,
174
+ // Import and use fallback ad configuration
175
+ import('../lib/thead-vantage-assets').then(({ THEAD_VANTAGE_FALLBACK_AD }) => {
176
+ setAd(THEAD_VANTAGE_FALLBACK_AD);
177
+ setDevMode(true);
178
+ setError(null); // Don't show errors in dev mode
179
+ }).catch(() => {
180
+ // If import fails, use inline fallback
181
+ setAd({
182
+ id: 'thead-vantage-fallback',
183
+ name: 'TheAd Vantage',
184
+ type: 'image',
185
+ contentUrl: '/TheAd-Vantage-Logo.png',
186
+ targetUrl: 'https://www.thead-vantage.com',
187
+ width: 300,
188
+ height: 250,
189
+ });
190
+ setDevMode(true);
191
+ setError(null);
176
192
  });
177
- setDevMode(true);
178
- setError(null); // Don't show errors in dev mode
179
193
  } else {
180
194
  setError(err instanceof Error ? err.message : 'Failed to fetch ad');
181
195
  }
package/src/lib/ads.ts CHANGED
@@ -332,18 +332,13 @@ export async function fetchAdBanner(params: FetchAdBannerParams): Promise<AdBann
332
332
  // On localhost, return TheAd Vantage fallback ad instead of throwing
333
333
  if (isLocalhost) {
334
334
  console.warn('[AdBanner] CORS error on localhost - returning TheAd Vantage fallback ad. Tracking is disabled.');
335
+ // Import fallback ad configuration
336
+ const { THEAD_VANTAGE_FALLBACK_AD } = await import('./thead-vantage-assets');
337
+
335
338
  return {
336
339
  success: true,
337
340
  dev_mode: true,
338
- ad: {
339
- id: 'thead-vantage-fallback',
340
- name: 'TheAd Vantage',
341
- type: 'image',
342
- contentUrl: '/TheAd-Vantage-Logo.png',
343
- targetUrl: 'https://www.thead-vantage.com',
344
- width: 300,
345
- height: 250,
346
- },
341
+ ad: THEAD_VANTAGE_FALLBACK_AD,
347
342
  message: 'Localhost development: Using TheAd Vantage fallback ad due to CORS',
348
343
  _dev_note: 'CORS error on localhost - showing fallback ad. This is expected in development.',
349
344
  };
@@ -0,0 +1,65 @@
1
+ /**
2
+ * TheAd Vantage Asset Utilities
3
+ *
4
+ * Provides fallback assets that work both in the library and when installed from npm.
5
+ *
6
+ * The logo is imported as a module so it gets bundled with the library.
7
+ * Next.js will process this import and create a URL that works in consuming applications.
8
+ */
9
+
10
+ // Import the logo image - Next.js will process this and bundle it
11
+ // When the library is used in other Next.js apps, the image will be available
12
+ import theadVantageLogoSrc from '../assets/TheAd-Vantage-Logo.png';
13
+
14
+ /**
15
+ * Get the URL for the TheAd Vantage logo fallback ad
16
+ *
17
+ * Uses the imported image module. Next.js processes image imports and creates
18
+ * a URL that points to the bundled asset. This works when the library is installed
19
+ * from npm because the image is included in the library bundle.
20
+ */
21
+ export function getTheadVantageLogoUrl(): string {
22
+ // Next.js processes image imports and returns either:
23
+ // - A string URL (in some configurations)
24
+ // - An object with src, width, height properties (typical Next.js behavior)
25
+
26
+ if (typeof theadVantageLogoSrc === 'string') {
27
+ return theadVantageLogoSrc;
28
+ }
29
+
30
+ // Next.js Image import typically returns an object with src property
31
+ if (typeof theadVantageLogoSrc === 'object' && theadVantageLogoSrc !== null) {
32
+ // Check for src property (Next.js ImageStaticImport type)
33
+ if ('src' in theadVantageLogoSrc) {
34
+ return (theadVantageLogoSrc as { src: string }).src;
35
+ }
36
+ // Some bundlers might return the object directly with a default export
37
+ if ('default' in theadVantageLogoSrc) {
38
+ const defaultExport = (theadVantageLogoSrc as { default: string | { src: string } }).default;
39
+ if (typeof defaultExport === 'string') {
40
+ return defaultExport;
41
+ }
42
+ if (typeof defaultExport === 'object' && defaultExport !== null && 'src' in defaultExport) {
43
+ return (defaultExport as { src: string }).src;
44
+ }
45
+ }
46
+ }
47
+
48
+ // Fallback to CDN if import doesn't work as expected
49
+ return 'https://www.thead-vantage.com/assets/TheAd-Vantage-Logo.png';
50
+ }
51
+
52
+ /**
53
+ * TheAd Vantage fallback ad configuration
54
+ * Used when CORS errors occur on localhost
55
+ */
56
+ export const THEAD_VANTAGE_FALLBACK_AD = {
57
+ id: 'thead-vantage-fallback',
58
+ name: 'TheAd Vantage',
59
+ type: 'image' as const,
60
+ contentUrl: getTheadVantageLogoUrl(),
61
+ targetUrl: 'https://www.thead-vantage.com',
62
+ width: 300,
63
+ height: 250,
64
+ };
65
+