adgent-sdk 0.1.1

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.
@@ -0,0 +1,874 @@
1
+ /** Ad element - can be inline or wrapper */
2
+ export declare interface Ad {
3
+ id: string;
4
+ sequence?: number;
5
+ adSystem?: AdSystem;
6
+ adTitle?: string;
7
+ impressions: Impression[];
8
+ creatives: Creative[];
9
+ errors: string[];
10
+ /** Present if this is a wrapper ad */
11
+ wrapper?: Wrapper;
12
+ /** Present if this is an inline ad */
13
+ inLine?: InLine;
14
+ }
15
+
16
+ /** Error structure */
17
+ export declare interface AdError {
18
+ code: VASTErrorCode | number;
19
+ message: string;
20
+ details?: string;
21
+ recoverable: boolean;
22
+ }
23
+
24
+ /**
25
+ * Ad Player with fault-tolerant playback for Smart TV platforms
26
+ *
27
+ * Features:
28
+ * - "Nuclear Mute" strategy: muted + playsinline + autoplay attributes
29
+ * - Soft-fail autoplay: catches play() rejection, shows interactive overlay
30
+ * - Focus management: captures remote keys during ad playback
31
+ */
32
+ declare class AdPlayer {
33
+ private readonly config;
34
+ private readonly platform;
35
+ private readonly parser;
36
+ private videoElement;
37
+ private overlayElement;
38
+ private skipButtonElement;
39
+ private tracker;
40
+ private state;
41
+ private ads;
42
+ private listeners;
43
+ private quartilesFired;
44
+ private boundKeyHandler;
45
+ private focusTrap;
46
+ constructor(config: AdPlayerConfig);
47
+ /**
48
+ * Initialize the SDK: fetch VAST, create video element, attempt autoplay
49
+ */
50
+ init(): Promise<void>;
51
+ /**
52
+ * Get the first linear creative from parsed ads
53
+ */
54
+ private getFirstLinearCreative;
55
+ /**
56
+ * Create video element with "Nuclear Mute" strategy
57
+ * Applies muted, playsinline, autoplay for maximum TV compatibility
58
+ */
59
+ private createVideoElement;
60
+ /**
61
+ * Attempt autoplay with soft-fail handling
62
+ * If play() rejects (common on TVs), show interactive overlay
63
+ */
64
+ private attemptAutoplay;
65
+ /**
66
+ * Show interactive overlay for manual ad start (autoplay fallback)
67
+ */
68
+ private showStartOverlay;
69
+ /**
70
+ * Handle start button click (from overlay)
71
+ */
72
+ private onStartClick;
73
+ /**
74
+ * Remove the start overlay
75
+ */
76
+ private removeOverlay;
77
+ /**
78
+ * Handle successful playback start
79
+ */
80
+ private handlePlaybackStart;
81
+ /**
82
+ * Handle time updates for progress tracking
83
+ */
84
+ private handleTimeUpdate;
85
+ /**
86
+ * Calculate current quartile (0-4)
87
+ */
88
+ private calculateQuartile;
89
+ /**
90
+ * Fire quartile tracking events
91
+ */
92
+ private fireQuartileEvents;
93
+ /**
94
+ * Set up skip button
95
+ */
96
+ private setupSkipButton;
97
+ /**
98
+ * Update skip countdown
99
+ */
100
+ private updateSkipCountdown;
101
+ /**
102
+ * Skip the ad
103
+ */
104
+ skip(): void;
105
+ /**
106
+ * Handle ad completion
107
+ */
108
+ private handleComplete;
109
+ /**
110
+ * Handle errors with recovery attempt or callback
111
+ */
112
+ private handleError;
113
+ /**
114
+ * Set up focus management to capture remote keys
115
+ */
116
+ private setupFocusManagement;
117
+ /**
118
+ * Handle key actions from remote control
119
+ */
120
+ private handleKeyAction;
121
+ /**
122
+ * Unmute video (call after playback starts if needed)
123
+ */
124
+ unmute(): void;
125
+ /**
126
+ * Mute video
127
+ */
128
+ mute(): void;
129
+ /**
130
+ * Add event listener
131
+ */
132
+ on(listener: AdPlayerEventListener): () => void;
133
+ /**
134
+ * Get current state
135
+ */
136
+ getState(): AdPlayerState;
137
+ /**
138
+ * Clean up all resources
139
+ */
140
+ destroy(): void;
141
+ /**
142
+ * Update internal state
143
+ */
144
+ private updateState;
145
+ /**
146
+ * Emit event to listeners
147
+ */
148
+ private emit;
149
+ /**
150
+ * Create error object
151
+ */
152
+ private createError;
153
+ /**
154
+ * Debug logging
155
+ */
156
+ private log;
157
+ }
158
+ export { AdPlayer }
159
+ export { AdPlayer as AdgentSDK }
160
+
161
+ /** SDK initialization configuration */
162
+ export declare interface AdPlayerConfig {
163
+ /** Container element to render ad player into */
164
+ container: HTMLElement;
165
+ /** VAST tag URL to fetch */
166
+ vastUrl: string;
167
+ /** Target bitrate in kbps (default: 2500 for ~1080p) */
168
+ targetBitrate?: number;
169
+ /** Maximum VAST wrapper depth (default: 5) */
170
+ maxWrapperDepth?: number;
171
+ /** Request timeout in ms (default: 10000) */
172
+ timeout?: number;
173
+ /** Enable debug logging (default: false) */
174
+ debug?: boolean;
175
+ /** Custom skip button text */
176
+ skipButtonText?: string;
177
+ /** Skip offset override in seconds (0 = no skip allowed) */
178
+ skipOffset?: number;
179
+ /** Callback when ad playback completes */
180
+ onComplete?: () => void;
181
+ /** Callback when an error occurs */
182
+ onError?: (error: AdError) => void;
183
+ /** Callback when ad starts playing */
184
+ onStart?: () => void;
185
+ /** Callback for progress updates */
186
+ onProgress?: (progress: AdProgress) => void;
187
+ /** Callback when ad is skipped */
188
+ onSkip?: () => void;
189
+ /** Callback when user clicks the ad */
190
+ onClick?: (clickThroughUrl: string) => void;
191
+ /** Callback when ad is paused */
192
+ onPause?: () => void;
193
+ /** Callback when ad resumes */
194
+ onResume?: () => void;
195
+ /** Custom "Start Ad" overlay UI (for autoplay fallback) */
196
+ customStartOverlay?: HTMLElement;
197
+ }
198
+
199
+ /** Events emitted by the player */
200
+ export declare type AdPlayerEvent = {
201
+ type: 'loaded';
202
+ } | {
203
+ type: 'start';
204
+ } | {
205
+ type: 'progress';
206
+ data: AdProgress;
207
+ } | {
208
+ type: 'quartile';
209
+ data: {
210
+ quartile: TrackingEventType;
211
+ };
212
+ } | {
213
+ type: 'complete';
214
+ } | {
215
+ type: 'skip';
216
+ } | {
217
+ type: 'click';
218
+ data: {
219
+ url: string;
220
+ };
221
+ } | {
222
+ type: 'pause';
223
+ } | {
224
+ type: 'resume';
225
+ } | {
226
+ type: 'mute';
227
+ } | {
228
+ type: 'unmute';
229
+ } | {
230
+ type: 'error';
231
+ data: AdError;
232
+ } | {
233
+ type: 'destroy';
234
+ };
235
+
236
+ /** Event listener callback */
237
+ export declare type AdPlayerEventListener = (event: AdPlayerEvent) => void;
238
+
239
+ /** Current player state */
240
+ export declare interface AdPlayerState {
241
+ /** Current playback status */
242
+ status: PlaybackStatus;
243
+ /** Current playback time in seconds */
244
+ currentTime: number;
245
+ /** Total duration in seconds */
246
+ duration: number;
247
+ /** Whether ad is muted */
248
+ muted: boolean;
249
+ /** Current volume (0-1) */
250
+ volume: number;
251
+ /** Whether skip is available */
252
+ canSkip: boolean;
253
+ /** Seconds until skip is available */
254
+ skipCountdown: number;
255
+ /** Selected media file being played */
256
+ mediaFile: MediaFile | null;
257
+ /** Last error if any */
258
+ error: AdError | null;
259
+ }
260
+
261
+ /** Progress event data */
262
+ export declare interface AdProgress {
263
+ currentTime: number;
264
+ duration: number;
265
+ percentage: number;
266
+ quartile: 0 | 1 | 2 | 3 | 4;
267
+ }
268
+
269
+ /** Ad system information */
270
+ declare interface AdSystem {
271
+ name: string;
272
+ version?: string;
273
+ }
274
+
275
+ /**
276
+ * Fire-and-forget pixel tracker for VAST events
277
+ */
278
+ export declare class AdTracker {
279
+ private readonly config;
280
+ private readonly trackingEvents;
281
+ private firedEvents;
282
+ private macroContext;
283
+ constructor(events?: TrackingEvent[], config?: TrackerConfig);
284
+ /**
285
+ * Group tracking events by their event type
286
+ */
287
+ private groupEventsByType;
288
+ /**
289
+ * Update macro context for URL replacement
290
+ */
291
+ updateMacroContext(context: Partial<MacroContext>): void;
292
+ /**
293
+ * Track a specific event type
294
+ * @param eventType - The VAST event type to track
295
+ * @param once - Only fire once per event type (default: true)
296
+ */
297
+ track(eventType: TrackingEventType, once?: boolean): void;
298
+ /**
299
+ * Fire a single tracking pixel (fire-and-forget)
300
+ * Uses sendBeacon when available, falls back to fetch with keepalive
301
+ */
302
+ firePixel(url: string): void;
303
+ /**
304
+ * Image beacon fallback
305
+ */
306
+ private fireImageBeacon;
307
+ /**
308
+ * Fire impression pixels
309
+ * @param impressionUrls - Array of impression URLs
310
+ */
311
+ fireImpressions(impressionUrls: string[]): void;
312
+ /**
313
+ * Fire error tracking with error code
314
+ * @param errorUrls - Array of error tracking URLs
315
+ * @param errorCode - VAST error code
316
+ */
317
+ fireError(errorUrls: string[], errorCode: number): void;
318
+ /**
319
+ * Reset fired events (for replay scenarios)
320
+ */
321
+ reset(): void;
322
+ /**
323
+ * Debug logging
324
+ */
325
+ private log;
326
+ }
327
+
328
+ /** Content category */
329
+ declare interface Category {
330
+ authority?: string;
331
+ value: string;
332
+ }
333
+
334
+ export declare interface ClickThrough {
335
+ id?: string;
336
+ url: string;
337
+ }
338
+
339
+ declare interface ClickTracking {
340
+ id?: string;
341
+ url: string;
342
+ }
343
+
344
+ /** Companion ad (banner alongside video) */
345
+ export declare interface CompanionAd {
346
+ id?: string;
347
+ width: number;
348
+ height: number;
349
+ staticResource?: string;
350
+ iFrameResource?: string;
351
+ htmlResource?: string;
352
+ companionClickThrough?: string;
353
+ trackingEvents: TrackingEvent[];
354
+ }
355
+
356
+ /** Creative element containing Linear/NonLinear/Companion ads */
357
+ export declare interface Creative {
358
+ id?: string;
359
+ sequence?: number;
360
+ adId?: string;
361
+ linear?: Linear;
362
+ nonLinearAds?: NonLinearAd[];
363
+ companionAds?: CompanionAd[];
364
+ }
365
+
366
+ declare interface CustomClick {
367
+ id?: string;
368
+ url: string;
369
+ }
370
+
371
+ /** Default key codes (varies by platform) */
372
+ export declare const DEFAULT_KEY_CODES: Record<Platform, PlatformKeyMap>;
373
+
374
+ /** Device info */
375
+ export declare interface DeviceInfo {
376
+ platform: Platform;
377
+ model?: string;
378
+ manufacturer?: string;
379
+ osVersion?: string;
380
+ firmwareVersion?: string;
381
+ screenWidth?: number;
382
+ screenHeight?: number;
383
+ devicePixelRatio?: number;
384
+ }
385
+
386
+ /**
387
+ * Get or create the platform adapter singleton
388
+ */
389
+ export declare function getPlatformAdapter(): PlatformAdapter;
390
+
391
+ /** Icon overlay (e.g., AdChoices) */
392
+ export declare interface Icon {
393
+ program?: string;
394
+ width: number;
395
+ height: number;
396
+ xPosition: string | number;
397
+ yPosition: string | number;
398
+ duration?: number;
399
+ offset?: number;
400
+ staticResource?: string;
401
+ iFrameResource?: string;
402
+ htmlResource?: string;
403
+ iconClicks?: IconClicks;
404
+ }
405
+
406
+ declare interface IconClicks {
407
+ iconClickThrough?: string;
408
+ iconClickTracking?: string[];
409
+ }
410
+
411
+ /** Impression pixel */
412
+ export declare interface Impression {
413
+ id?: string;
414
+ url: string;
415
+ }
416
+
417
+ /** Inline ad content */
418
+ export declare interface InLine {
419
+ adTitle: string;
420
+ description?: string;
421
+ advertiser?: string;
422
+ pricing?: Pricing;
423
+ survey?: string;
424
+ category?: Category[];
425
+ creatives: Creative[];
426
+ }
427
+
428
+ /** Platform adapter interface */
429
+ export declare interface IPlatformAdapter {
430
+ /** Current detected platform */
431
+ readonly platform: Platform;
432
+ /** Platform capabilities */
433
+ readonly capabilities: PlatformCapabilities;
434
+ /** Device information */
435
+ readonly deviceInfo: DeviceInfo;
436
+ /**
437
+ * Normalize a raw key code to a KeyAction
438
+ * @param keyCode - Raw keyboard/remote key code
439
+ */
440
+ normalizeKeyCode(keyCode: number): KeyAction | null;
441
+ /**
442
+ * Get platform-specific key codes for an action
443
+ * @param action - The key action to get codes for
444
+ */
445
+ getKeyCodesForAction(action: KeyAction): number[];
446
+ /**
447
+ * Check if a specific codec is supported
448
+ * @param codec - MIME type with codec (e.g., 'video/mp4; codecs="hvc1"')
449
+ */
450
+ isCodecSupported(codec: string): boolean;
451
+ }
452
+
453
+ /** Remote control key actions */
454
+ export declare enum KeyAction {
455
+ Enter = "enter",
456
+ Back = "back",
457
+ Left = "left",
458
+ Right = "right",
459
+ Up = "up",
460
+ Down = "down",
461
+ Play = "play",
462
+ Pause = "pause",
463
+ PlayPause = "playPause",
464
+ Stop = "stop",
465
+ FastForward = "fastForward",
466
+ Rewind = "rewind",
467
+ Menu = "menu",
468
+ Info = "info",
469
+ Red = "red",
470
+ Green = "green",
471
+ Yellow = "yellow",
472
+ Blue = "blue",
473
+ ChannelUp = "channelUp",
474
+ ChannelDown = "channelDown",
475
+ VolumeUp = "volumeUp",
476
+ VolumeDown = "volumeDown",
477
+ Mute = "mute"
478
+ }
479
+
480
+ /** Linear (video) ad */
481
+ export declare interface Linear {
482
+ duration: number;
483
+ skipOffset?: number;
484
+ mediaFiles: MediaFile[];
485
+ trackingEvents: TrackingEvent[];
486
+ videoClicks?: VideoClicks;
487
+ adParameters?: string;
488
+ icons?: Icon[];
489
+ }
490
+
491
+ /** Macro replacement context */
492
+ export declare interface MacroContext {
493
+ assetUri?: string;
494
+ contentPlayhead?: number;
495
+ adPlayhead?: number;
496
+ errorCode?: number;
497
+ breakPosition?: number;
498
+ adType?: string;
499
+ }
500
+
501
+ /** Video file reference */
502
+ export declare interface MediaFile {
503
+ id?: string;
504
+ url: string;
505
+ delivery: 'progressive' | 'streaming';
506
+ type: string;
507
+ width: number;
508
+ height: number;
509
+ bitrate?: number;
510
+ minBitrate?: number;
511
+ maxBitrate?: number;
512
+ scalable?: boolean;
513
+ maintainAspectRatio?: boolean;
514
+ codec?: string;
515
+ apiFramework?: string;
516
+ }
517
+
518
+ /** NonLinear ad (overlay) */
519
+ export declare interface NonLinearAd {
520
+ id?: string;
521
+ width: number;
522
+ height: number;
523
+ minSuggestedDuration?: number;
524
+ staticResource?: string;
525
+ iFrameResource?: string;
526
+ htmlResource?: string;
527
+ nonLinearClickThrough?: string;
528
+ trackingEvents: TrackingEvent[];
529
+ }
530
+
531
+ /** Parse result */
532
+ declare interface ParseResult {
533
+ success: boolean;
534
+ response?: VASTResponse;
535
+ error?: {
536
+ code: VASTErrorCode;
537
+ message: string;
538
+ };
539
+ }
540
+
541
+ /**
542
+ * Platform Detection Types
543
+ * For Smart TV web runtimes (WebOS, Tizen, Vidaa, WhaleOS) and streaming devices
544
+ */
545
+ /** Supported Smart TV platforms */
546
+ export declare enum Platform {
547
+ WebOS = "webos",
548
+ Tizen = "tizen",
549
+ Vidaa = "vidaa",
550
+ WhaleOS = "whaleos",
551
+ FireTV = "firetv",
552
+ Roku = "roku",
553
+ Xbox = "xbox",
554
+ PlayStation = "playstation",
555
+ AndroidTV = "androidtv",
556
+ Vizio = "vizio",
557
+ Generic = "generic"
558
+ }
559
+
560
+ /** Platform detection patterns */
561
+ export declare const PLATFORM_DETECTION_PATTERNS: Record<Platform, RegExp[]>;
562
+
563
+ /**
564
+ * Platform detection and key code normalization for Smart TV runtimes
565
+ */
566
+ export declare class PlatformAdapter implements IPlatformAdapter {
567
+ readonly platform: Platform;
568
+ readonly capabilities: PlatformCapabilities;
569
+ readonly deviceInfo: DeviceInfo;
570
+ private readonly keyMap;
571
+ private readonly reverseKeyMap;
572
+ constructor();
573
+ /**
574
+ * Detect the current Smart TV platform using userAgent and global objects
575
+ */
576
+ private detectPlatform;
577
+ /**
578
+ * Detect platform capabilities
579
+ */
580
+ private detectCapabilities;
581
+ /**
582
+ * Detect device information
583
+ */
584
+ private detectDeviceInfo;
585
+ /**
586
+ * Detect maximum supported resolution
587
+ */
588
+ private detectMaxResolution;
589
+ /**
590
+ * Build reverse mapping from KeyAction to key codes
591
+ */
592
+ private buildReverseKeyMap;
593
+ /**
594
+ * Normalize a raw key code to a KeyAction
595
+ * @param keyCode - Raw keyboard/remote key code
596
+ * @returns KeyAction or null if not mapped
597
+ */
598
+ normalizeKeyCode(keyCode: number): KeyAction | null;
599
+ /**
600
+ * Get all key codes that map to a specific action
601
+ * @param action - The key action
602
+ * @returns Array of key codes
603
+ */
604
+ getKeyCodesForAction(action: KeyAction): number[];
605
+ /**
606
+ * Check if a specific codec is supported
607
+ * @param codec - MIME type with codec string
608
+ * @returns true if codec is supported
609
+ */
610
+ isCodecSupported(codec: string): boolean;
611
+ /**
612
+ * Register Tizen-specific key handlers
613
+ * Must be called for Tizen apps to receive media keys
614
+ */
615
+ registerTizenKeys(): void;
616
+ /**
617
+ * Register WebOS-specific key handlers
618
+ */
619
+ registerWebOSKeys(): void;
620
+ /**
621
+ * Get platform-specific video element attributes
622
+ * @returns Object of attributes to set on video element
623
+ */
624
+ getVideoAttributes(): Record<string, string | boolean>;
625
+ /**
626
+ * Get recommended video settings for this platform
627
+ */
628
+ getRecommendedVideoSettings(): {
629
+ maxBitrate: number;
630
+ preferredCodec: string;
631
+ maxResolution: string;
632
+ };
633
+ }
634
+
635
+ /** Platform capability flags */
636
+ export declare interface PlatformCapabilities {
637
+ /** Supports sendBeacon API */
638
+ sendBeacon: boolean;
639
+ /** Supports fetch with keepalive */
640
+ fetchKeepalive: boolean;
641
+ /** Requires muted autoplay */
642
+ mutedAutoplayRequired: boolean;
643
+ /** Supports fullscreen API */
644
+ fullscreen: boolean;
645
+ /** Supports hardware video decode info */
646
+ hardwareDecodeInfo: boolean;
647
+ /** Supports HDR playback */
648
+ hdr: boolean;
649
+ /** Supports HDR10+ */
650
+ hdr10Plus: boolean;
651
+ /** Supports Dolby Vision */
652
+ dolbyVision: boolean;
653
+ /** Supports Dolby Atmos */
654
+ dolbyAtmos: boolean;
655
+ /** Supports HEVC/H.265 */
656
+ hevc: boolean;
657
+ /** Supports VP9 */
658
+ vp9: boolean;
659
+ /** Supports AV1 */
660
+ av1: boolean;
661
+ /** Maximum supported resolution */
662
+ maxResolution: '4k' | '1080p' | '720p' | 'unknown';
663
+ /** Device has touch support */
664
+ touch: boolean;
665
+ /** Device has voice control */
666
+ voice: boolean;
667
+ }
668
+
669
+ /** Platform-specific key code mapping */
670
+ export declare interface PlatformKeyMap {
671
+ [keyCode: number]: KeyAction;
672
+ }
673
+
674
+ /** Playback status enum */
675
+ export declare enum PlaybackStatus {
676
+ Idle = "idle",
677
+ Loading = "loading",
678
+ Ready = "ready",
679
+ Playing = "playing",
680
+ Paused = "paused",
681
+ Completed = "completed",
682
+ Error = "error",
683
+ WaitingForInteraction = "waiting_for_interaction"
684
+ }
685
+
686
+ /** Pricing information */
687
+ declare interface Pricing {
688
+ model: 'cpm' | 'cpc' | 'cpe' | 'cpv';
689
+ currency: string;
690
+ value: number;
691
+ }
692
+
693
+ /**
694
+ * Replace all VAST macros in a URL
695
+ * @param url - URL containing macros
696
+ * @param context - Values to substitute
697
+ */
698
+ export declare function replaceMacros(url: string, context?: MacroContext): string;
699
+
700
+ /** Tracker configuration */
701
+ declare interface TrackerConfig {
702
+ /** Enable debug logging */
703
+ debug?: boolean;
704
+ /** Retry failed requests (default: false for fire-and-forget) */
705
+ retry?: boolean;
706
+ /** Maximum retry attempts */
707
+ maxRetries?: number;
708
+ }
709
+
710
+ /** Tracking event for analytics */
711
+ export declare interface TrackingEvent {
712
+ event: TrackingEventType;
713
+ url: string;
714
+ offset?: number;
715
+ }
716
+
717
+ /** Supported tracking event types per VAST 4.x */
718
+ export declare type TrackingEventType = 'creativeView' | 'start' | 'firstQuartile' | 'midpoint' | 'thirdQuartile' | 'complete' | 'mute' | 'unmute' | 'pause' | 'resume' | 'rewind' | 'skip' | 'playerExpand' | 'playerCollapse' | 'progress' | 'closeLinear' | 'loaded' | 'impression' | 'error';
719
+
720
+ /** Error codes per VAST spec */
721
+ export declare enum VASTErrorCode {
722
+ XML_PARSING_ERROR = 100,
723
+ VAST_SCHEMA_VALIDATION_ERROR = 101,
724
+ VAST_VERSION_NOT_SUPPORTED = 102,
725
+ GENERAL_WRAPPER_ERROR = 300,
726
+ WRAPPER_TIMEOUT = 301,
727
+ WRAPPER_LIMIT_REACHED = 302,
728
+ NO_VAST_RESPONSE = 303,
729
+ GENERAL_LINEAR_ERROR = 400,
730
+ FILE_NOT_FOUND = 401,
731
+ MEDIA_TIMEOUT = 402,
732
+ MEDIA_NOT_SUPPORTED = 403,
733
+ GENERAL_COMPANION_ERROR = 600,
734
+ UNDEFINED_ERROR = 900
735
+ }
736
+
737
+ /**
738
+ * Macro Replacement Utilities
739
+ * Handles VAST macro substitution for tracking URLs
740
+ */
741
+ /** Supported VAST macros */
742
+ export declare type VastMacro = '[TIMESTAMP]' | '[CACHEBUSTING]' | '[ASSETURI]' | '[CONTENTPLAYHEAD]' | '[ERRORCODE]' | '[BREAKPOSITION]' | '[ADPLAYHEAD]' | '[ADTYPE]';
743
+
744
+ /**
745
+ * VAST XML Parser with wrapper resolution
746
+ */
747
+ export declare class VASTParser {
748
+ private readonly config;
749
+ private readonly xmlParser;
750
+ constructor(config?: VASTParserConfig);
751
+ /**
752
+ * Parse a VAST URL and resolve all wrappers
753
+ * @param vastUrl - URL to the VAST document
754
+ */
755
+ parse(vastUrl: string): Promise<ParseResult>;
756
+ /**
757
+ * Fetch and parse VAST document with wrapper resolution
758
+ */
759
+ private fetchAndParse;
760
+ /**
761
+ * Resolve a wrapper ad by fetching the nested VAST
762
+ */
763
+ private resolveWrapper;
764
+ /**
765
+ * Merge tracking events from wrapper into nested ad
766
+ */
767
+ private mergeWrapperTracking;
768
+ /**
769
+ * Extract tracking events from wrapper creatives
770
+ */
771
+ private getWrapperTrackingEvents;
772
+ /**
773
+ * Fetch URL with timeout
774
+ */
775
+ private fetchWithTimeout;
776
+ /**
777
+ * Parse raw VAST XML into structured response
778
+ */
779
+ private parseXml;
780
+ /**
781
+ * Parse Ad elements
782
+ */
783
+ private parseAds;
784
+ /**
785
+ * Parse a single Ad element
786
+ */
787
+ private parseAd;
788
+ /**
789
+ * Parse Impression elements
790
+ */
791
+ private parseImpressions;
792
+ /**
793
+ * Parse Creative elements
794
+ */
795
+ private parseCreatives;
796
+ /**
797
+ * Parse Linear element
798
+ */
799
+ private parseLinear;
800
+ /**
801
+ * Parse MediaFile elements
802
+ */
803
+ private parseMediaFiles;
804
+ /**
805
+ * Parse Tracking elements
806
+ */
807
+ private parseTrackingEvents;
808
+ /**
809
+ * Parse Error elements
810
+ */
811
+ private parseErrors;
812
+ /**
813
+ * Parse duration string (HH:MM:SS or seconds) to seconds
814
+ */
815
+ private parseDuration;
816
+ /**
817
+ * Select the best media file based on target bitrate
818
+ * Prefers 1080p/720p over 4K for TV compatibility
819
+ */
820
+ selectBestMediaFile(mediaFiles: MediaFile[], targetBitrate?: number): MediaFile | null;
821
+ /**
822
+ * Aggregate all tracking events from parsed ads
823
+ */
824
+ aggregateTrackingEvents(ads: Ad[]): TrackingEvent[];
825
+ /**
826
+ * Get all impression URLs from parsed ads
827
+ */
828
+ aggregateImpressions(ads: Ad[]): string[];
829
+ /**
830
+ * Debug logging
831
+ */
832
+ private log;
833
+ }
834
+
835
+ /** Parser configuration */
836
+ declare interface VASTParserConfig {
837
+ /** Maximum wrapper depth (default: 5) */
838
+ maxWrapperDepth?: number;
839
+ /** Request timeout in ms (default: 10000) */
840
+ timeout?: number;
841
+ /** Enable debug logging */
842
+ debug?: boolean;
843
+ /** Custom fetch implementation */
844
+ fetchFn?: typeof fetch;
845
+ }
846
+
847
+ /**
848
+ * VAST 4.x Type Definitions
849
+ * Based on IAB VAST (Video Ad Serving Template) 4.x Specification
850
+ * @see https://iabtechlab.com/standards/vast/
851
+ */
852
+ /** Root VAST response structure */
853
+ export declare interface VASTResponse {
854
+ version: string;
855
+ ads: Ad[];
856
+ errors: string[];
857
+ }
858
+
859
+ /** Video click tracking */
860
+ export declare interface VideoClicks {
861
+ clickThrough?: ClickThrough;
862
+ clickTracking?: ClickTracking[];
863
+ customClick?: CustomClick[];
864
+ }
865
+
866
+ /** Wrapper ad - points to another VAST */
867
+ export declare interface Wrapper {
868
+ vastAdTagURI: string;
869
+ followAdditionalWrappers?: boolean;
870
+ allowMultipleAds?: boolean;
871
+ fallbackOnNoAd?: boolean;
872
+ }
873
+
874
+ export { }