@@ -8,7 +8,13 @@ import { AdPixels } from './AdPixels';
88import adRainbow from './assets/ad-rainbow.svg' ;
99import { AdItem , AdsResponse } from './types' ;
1010
11- interface FetchAdOptions {
11+ type FetchAdOptions = FetchLiveAdOptions | FetchPlaceholderAdOptions ;
12+
13+ interface FetchLiveAdOptions {
14+ /**
15+ * Source of the ad (live: from the platform)
16+ */
17+ source : 'live' ;
1218 /** ID of the zone to fetch Ads for */
1319 zoneId : string ;
1420 /** Mode to render the Ad */
@@ -17,12 +23,13 @@ interface FetchAdOptions {
1723 placement : string ;
1824 /** If true, we'll not track it as an impression */
1925 ignore : boolean ;
26+ }
27+
28+ interface FetchPlaceholderAdOptions {
2029 /**
21- * Source of the ad (live: from the platform, placeholder: static placeholder)
22- *
23- * Defaults to live.
24- * */
25- source ?: 'live' | 'placeholder' ;
30+ * Source of the ad (placeholder: static placeholder ad)
31+ */
32+ source : 'placeholder' ;
2633}
2734
2835/**
@@ -31,9 +38,9 @@ interface FetchAdOptions {
3138 * and properly access user-agent and IP.
3239 */
3340export async function renderAd ( options : FetchAdOptions ) {
34- const { mode, source = 'live' } = options ;
41+ const mode = options . source === 'live' ? options . mode : 'classic' ;
3542
36- const result = source === 'live' ? await fetchAd ( options ) : getPlaceholderAd ( ) ;
43+ const result = options . source === 'live' ? await fetchAd ( options ) : getPlaceholderAd ( ) ;
3744 if ( ! result || ! result . ad . description || ! result . ad . statlink ) {
3845 return null ;
3946 }
@@ -56,7 +63,7 @@ async function fetchAd({
5663 zoneId,
5764 placement,
5865 ignore,
59- } : FetchAdOptions ) : Promise < { ad : AdItem ; ip : string } | null > {
66+ } : FetchLiveAdOptions ) : Promise < { ad : AdItem ; ip : string } | null > {
6067 const { ip, userAgent } = getUserAgentAndIp ( ) ;
6168
6269 const url = new URL ( `https://srv.buysellads.com/ads/${ zoneId } .json` ) ;
0 commit comments