@streamlayer/feature-advertisement 1.1.0 → 1.1.1-rc.1342

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.
Files changed (62) hide show
  1. package/classic/package.json +5 -0
  2. package/lib/cjs/advertisement.d.ts +64 -0
  3. package/lib/cjs/advertisement.js +307 -0
  4. package/lib/cjs/index.d.ts +19 -0
  5. package/lib/cjs/index.js +39 -0
  6. package/lib/cjs/package.json +1 -0
  7. package/lib/cjs/units/external-ad.d.ts +58 -0
  8. package/lib/cjs/units/external-ad.js +390 -0
  9. package/lib/cjs/units/external-pause-ad.d.ts +50 -0
  10. package/lib/cjs/units/external-pause-ad.js +253 -0
  11. package/lib/cjs/units/gam.d.ts +16 -0
  12. package/lib/cjs/units/gam.js +104 -0
  13. package/lib/cjs/units/parse-vast-extensions.d.ts +17 -0
  14. package/lib/cjs/units/parse-vast-extensions.js +52 -0
  15. package/lib/cjs/units/pause-ad-card.d.ts +49 -0
  16. package/lib/cjs/units/pause-ad-card.js +136 -0
  17. package/lib/cjs/units/pause-ad.d.ts +16 -0
  18. package/lib/cjs/units/pause-ad.js +52 -0
  19. package/lib/cjs/units/ssai-ad-break.d.ts +21 -0
  20. package/lib/cjs/units/ssai-ad-break.js +11 -0
  21. package/lib/cjs/units/ssai-creative.d.ts +89 -0
  22. package/lib/cjs/units/ssai-creative.js +136 -0
  23. package/lib/cjs/units/ssai-detector.d.ts +180 -0
  24. package/lib/cjs/units/ssai-detector.js +1156 -0
  25. package/lib/cjs/units/ssai-preload.d.ts +20 -0
  26. package/lib/cjs/units/ssai-preload.js +62 -0
  27. package/lib/cjs/units/ssai-providers.d.ts +117 -0
  28. package/lib/cjs/units/ssai-providers.js +263 -0
  29. package/lib/cjs/units/vast-tracker.d.ts +45 -0
  30. package/lib/cjs/units/vast-tracker.js +64 -0
  31. package/lib/classic/_virtual/_rollupPluginBabelHelpers.js +71 -0
  32. package/lib/classic/advertisement.js +331 -0
  33. package/lib/classic/cjs/_virtual/_rollupPluginBabelHelpers.js +77 -0
  34. package/lib/classic/cjs/advertisement.js +333 -0
  35. package/lib/classic/cjs/index.js +47 -0
  36. package/lib/classic/cjs/package.json +1 -0
  37. package/lib/classic/cjs/units/external-ad.js +453 -0
  38. package/lib/classic/cjs/units/external-pause-ad.js +274 -0
  39. package/lib/classic/cjs/units/gam.js +110 -0
  40. package/lib/classic/cjs/units/parse-vast-extensions.js +56 -0
  41. package/lib/classic/cjs/units/pause-ad-card.js +134 -0
  42. package/lib/classic/cjs/units/pause-ad.js +72 -0
  43. package/lib/classic/cjs/units/ssai-ad-break.js +11 -0
  44. package/lib/classic/cjs/units/ssai-creative.js +142 -0
  45. package/lib/classic/cjs/units/ssai-detector.js +1170 -0
  46. package/lib/classic/cjs/units/ssai-preload.js +72 -0
  47. package/lib/classic/cjs/units/ssai-providers.js +299 -0
  48. package/lib/classic/cjs/units/vast-tracker.js +81 -0
  49. package/lib/classic/index.js +28 -0
  50. package/lib/classic/units/external-ad.js +447 -0
  51. package/lib/classic/units/external-pause-ad.js +271 -0
  52. package/lib/classic/units/gam.js +108 -0
  53. package/lib/classic/units/parse-vast-extensions.js +54 -0
  54. package/lib/classic/units/pause-ad-card.js +131 -0
  55. package/lib/classic/units/pause-ad.js +70 -0
  56. package/lib/classic/units/ssai-ad-break.js +9 -0
  57. package/lib/classic/units/ssai-creative.js +140 -0
  58. package/lib/classic/units/ssai-detector.js +1167 -0
  59. package/lib/classic/units/ssai-preload.js +68 -0
  60. package/lib/classic/units/ssai-providers.js +289 -0
  61. package/lib/classic/units/vast-tracker.js +77 -0
  62. package/package.json +41 -8
@@ -0,0 +1,72 @@
1
+ 'use strict';
2
+
3
+ require('core-js/modules/es.array.iterator.js');
4
+ require('core-js/modules/es.promise.js');
5
+ require('core-js/modules/esnext.iterator.constructor.js');
6
+ require('core-js/modules/esnext.iterator.filter.js');
7
+ require('core-js/modules/web.dom-collections.iterator.js');
8
+ var classic = require('@streamlayer/sdk-web-logger/classic');
9
+
10
+ const log = classic.createLogger('ssai:preload');
11
+ /**
12
+ * How long the overlay is willing to wait for artwork. A slow or dead image host
13
+ * must never hold the bar back — the ad is already playing, and a bar that shows
14
+ * late is worse than one that shows without its logo (the logo is hidden on error
15
+ * anyway). Warming the browser cache is the goal; blocking is not.
16
+ */
17
+ const DEFAULT_PRELOAD_TIMEOUT_MS = 2000;
18
+ /**
19
+ * Fetch images into the browser cache and resolve once they are all settled, or
20
+ * once `timeoutMs` elapses — whichever comes first. Never rejects: a creative
21
+ * whose artwork fails is still a creative worth showing.
22
+ */
23
+ const preloadImages = (urls, timeoutMs = DEFAULT_PRELOAD_TIMEOUT_MS) => {
24
+ const targets = urls.filter(url => !!url);
25
+ // `Image` is absent in SSR/worker contexts; there is nothing to warm there.
26
+ if (targets.length === 0 || typeof Image === 'undefined') {
27
+ return Promise.resolve();
28
+ }
29
+ return new Promise(resolve => {
30
+ let settled = false;
31
+ let remaining = targets.length;
32
+ const finish = () => {
33
+ if (settled) {
34
+ return;
35
+ }
36
+ settled = true;
37
+ clearTimeout(timer);
38
+ resolve();
39
+ };
40
+ const timer = setTimeout(() => {
41
+ log.debug({
42
+ remaining
43
+ }, 'ssai preload timed out, showing anyway');
44
+ finish();
45
+ }, timeoutMs);
46
+ const one = () => {
47
+ remaining -= 1;
48
+ if (remaining <= 0) {
49
+ finish();
50
+ }
51
+ };
52
+ for (const url of targets) {
53
+ const image = new Image();
54
+ image.onload = one;
55
+ image.onerror = one;
56
+ image.src = url;
57
+ }
58
+ });
59
+ };
60
+ /**
61
+ * Warm every image the creative carries — the overlay's brand logo, and the
62
+ * companion banner for hosts that render one — so the bar fades in complete
63
+ * rather than popping its artwork in a beat later.
64
+ */
65
+ const preloadCreativeAssets = (creative, timeoutMs) => {
66
+ var _creative$companion;
67
+ return preloadImages([creative.iconUrl, (_creative$companion = creative.companion) === null || _creative$companion === void 0 ? void 0 : _creative$companion.staticResource], timeoutMs);
68
+ };
69
+
70
+ exports.DEFAULT_PRELOAD_TIMEOUT_MS = DEFAULT_PRELOAD_TIMEOUT_MS;
71
+ exports.preloadCreativeAssets = preloadCreativeAssets;
72
+ exports.preloadImages = preloadImages;
@@ -0,0 +1,299 @@
1
+ 'use strict';
2
+
3
+ var _rollupPluginBabelHelpers = require('../_virtual/_rollupPluginBabelHelpers.js');
4
+ require('core-js/modules/es.error.cause.js');
5
+ require('core-js/modules/es.array.iterator.js');
6
+ require('core-js/modules/es.promise.js');
7
+ require('core-js/modules/esnext.iterator.constructor.js');
8
+ require('core-js/modules/esnext.iterator.filter.js');
9
+ require('core-js/modules/esnext.iterator.find.js');
10
+ require('core-js/modules/esnext.iterator.map.js');
11
+ require('core-js/modules/web.dom-collections.iterator.js');
12
+ require('core-js/modules/web.dom-exception.stack.js');
13
+ var classic = require('@streamlayer/sdk-web-logger/classic');
14
+ var vastClient = require('@dailymotion/vast-client');
15
+
16
+ const log = classic.createLogger('ssai:provider');
17
+ const DEFAULT_CREATIVE_API_BASE = 'https://hls.next.streamlayer.io/api/creatives/';
18
+ /**
19
+ * Shared low-level beacon helper. Prefers `navigator.sendBeacon` and falls back
20
+ * to a no-cors `fetch`. Used by the default impression path and available to
21
+ * providers that fire URL-based tracking pixels.
22
+ */
23
+ const fireBeacon = url => {
24
+ try {
25
+ if (typeof navigator !== 'undefined' && typeof navigator.sendBeacon === 'function') {
26
+ navigator.sendBeacon(url);
27
+ } else {
28
+ void fetch(url, {
29
+ mode: 'no-cors'
30
+ }).catch(error => {
31
+ log.warn(error, 'ssai beacon failed');
32
+ });
33
+ }
34
+ } catch (error) {
35
+ log.warn(error, 'ssai beacon failed');
36
+ }
37
+ };
38
+ const resolveAdvertiser = (advertiser, title) => {
39
+ if (advertiser) {
40
+ return advertiser;
41
+ }
42
+ if (title) {
43
+ return title;
44
+ }
45
+ return 'Ad';
46
+ };
47
+ const buildCreativeUrl = (base, creativeId) => {
48
+ const normalizedBase = base.endsWith('/') ? base : `${base}/`;
49
+ return `${normalizedBase}${encodeURIComponent(creativeId)}`;
50
+ };
51
+ const mapApiResponse = raw => {
52
+ const trackingEvents = Array.isArray(raw.trackingEvents) ? raw.trackingEvents.filter(entry => Boolean((entry === null || entry === void 0 ? void 0 : entry.event) && (entry === null || entry === void 0 ? void 0 : entry.url))).map(entry => ({
53
+ event: entry.event,
54
+ url: entry.url
55
+ })) : [];
56
+ const rawCompanion = Array.isArray(raw.companions) ? raw.companions.find(entry => !!(entry !== null && entry !== void 0 && entry.staticResource)) : undefined;
57
+ const companion = rawCompanion !== null && rawCompanion !== void 0 && rawCompanion.staticResource ? {
58
+ staticResource: rawCompanion.staticResource,
59
+ width: Number(rawCompanion.width) || 0,
60
+ height: Number(rawCompanion.height) || 0,
61
+ clickThrough: rawCompanion.clickThrough,
62
+ clickTracking: Array.isArray(rawCompanion.clickTracking) ? rawCompanion.clickTracking.filter(url => typeof url === 'string' && !!url) : []
63
+ } : undefined;
64
+ return {
65
+ creativeId: raw.creativeId,
66
+ advertiser: resolveAdvertiser(raw.advertiser, raw.title),
67
+ title: raw.title || resolveAdvertiser(raw.advertiser, raw.title),
68
+ iconUrl: raw.iconUrl || undefined,
69
+ clickThroughUrl: raw.clickThroughUrl || undefined,
70
+ trackingEvents,
71
+ companion
72
+ };
73
+ };
74
+ /**
75
+ * Fire every tracking event with the given name, and report how many went out.
76
+ *
77
+ * ALL matches, not the first: the creative contract states that a creative may
78
+ * repeat an `event` value to carry several URLs, and that consumers must not
79
+ * assume uniqueness. Today's payloads carry one URL per event, so this is not a
80
+ * change in what goes on the wire — it just stops being wrong the day a server
81
+ * sends two.
82
+ */
83
+ const fireTrackingEvents = (creative, event) => {
84
+ const matches = creative.trackingEvents.filter(entry => entry.event === event);
85
+ for (const match of matches) {
86
+ fireBeacon(match.url);
87
+ }
88
+ return matches.length;
89
+ };
90
+ /**
91
+ * Shared default impression behavior: fire the `impression` tracking events.
92
+ * Used by the StreamLayer provider and as the fallback in
93
+ * {@link SsaiCreativeCache} when a provider doesn't override `fireImpression`.
94
+ * Exported so both call sites share one definition.
95
+ */
96
+ const fireDefaultImpression = creative => {
97
+ fireTrackingEvents(creative, 'impression');
98
+ };
99
+ /**
100
+ * StreamLayer's internal creative provider. Resolves creatives from the JSON
101
+ * creative API (`GET {creativeApiBase}{encodeURIComponent(creativeId)}`) and
102
+ * fires impressions from the `'impression'` tracking event via `sendBeacon`.
103
+ */
104
+ const createStreamLayerProvider = (config = {}) => {
105
+ var _config$creativeApiBa;
106
+ const creativeApiBase = (_config$creativeApiBa = config.creativeApiBase) !== null && _config$creativeApiBa !== void 0 ? _config$creativeApiBa : DEFAULT_CREATIVE_API_BASE;
107
+ return {
108
+ id: 'streamlayer',
109
+ resolve: function () {
110
+ var _ref = _rollupPluginBabelHelpers.asyncToGenerator(function* (creativeId, signal) {
111
+ const url = buildCreativeUrl(creativeApiBase, creativeId);
112
+ const response = yield fetch(url, {
113
+ signal
114
+ });
115
+ if (!response.ok) {
116
+ throw new Error(`creative request failed: ${response.status}`);
117
+ }
118
+ const raw = yield response.json();
119
+ return mapApiResponse(_rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, raw), {}, {
120
+ creativeId: raw.creativeId || creativeId
121
+ }));
122
+ });
123
+ return function resolve(_x, _x2) {
124
+ return _ref.apply(this, arguments);
125
+ };
126
+ }(),
127
+ fireImpression: fireDefaultImpression
128
+ };
129
+ };
130
+ const buildQuortexUrl = (base, tenantName, adId) => {
131
+ // Deliberately string concatenation rather than `URL`/`URLSearchParams`: this
132
+ // package ships to 2016-era TV engines (see the chrome-32 classic build).
133
+ const separator = base.indexOf('?') === -1 ? '?' : '&';
134
+ const tenant = tenantName ? `TenantName=${encodeURIComponent(tenantName)}&` : '';
135
+ return `${base}${separator}${tenant}adID=${encodeURIComponent(adId)}&info=1`;
136
+ };
137
+ /**
138
+ * Quortex / Synamedia DAI ad metadata provider.
139
+ *
140
+ * `GET {adApiBase}?TenantName={tenantName}&adID={adId}&info=1` (the `TenantName`
141
+ * part omitted when `adApiBase` already carries it) — the ad id comes
142
+ * from the manifest's `X-AD-ID` DATERANGE attribute (see `ssai-detector.ts`, which
143
+ * reconstructs the ad window from the tracking-marker burst those tags form).
144
+ *
145
+ * The response is byte-compatible with the StreamLayer creative API, so the same
146
+ * `mapApiResponse` normalizes both.
147
+ *
148
+ * Known limitation: impressions fire the `impression` tracking event from the API
149
+ * response, not the per-session beacon the manifest carries in `X-AD-URL`. The two
150
+ * differ in `trackingid`/`USERID`, so Quortex-side attribution will see the
151
+ * generic id rather than the viewer's session until the manifest beacons are
152
+ * plumbed through to the provider.
153
+ */
154
+ const createQuortexProvider = (config = {}) => {
155
+ const {
156
+ adApiBase,
157
+ tenantName
158
+ } = config;
159
+ if (!adApiBase) {
160
+ // Loud, but not thrown: this runs inside the host's render effect via
161
+ // `startSsaiMonitoring`, and taking the app down over a config typo is worse
162
+ // than an overlay that never appears and says why.
163
+ log.error({
164
+ adApiBase,
165
+ tenantName
166
+ }, 'quortex provider requires `adApiBase`');
167
+ }
168
+ return {
169
+ id: 'quortex',
170
+ resolve: function () {
171
+ var _ref2 = _rollupPluginBabelHelpers.asyncToGenerator(function* (adId, signal) {
172
+ if (!adApiBase) {
173
+ throw new Error('quortex provider is missing `adApiBase`');
174
+ }
175
+ const response = yield fetch(buildQuortexUrl(adApiBase, tenantName, adId), {
176
+ signal
177
+ });
178
+ if (!response.ok) {
179
+ throw new Error(`quortex creative request failed: ${response.status}`);
180
+ }
181
+ const raw = yield response.json();
182
+ return mapApiResponse(_rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, raw), {}, {
183
+ creativeId: raw.creativeId || adId
184
+ }));
185
+ });
186
+ return function resolve(_x3, _x4) {
187
+ return _ref2.apply(this, arguments);
188
+ };
189
+ }(),
190
+ fireImpression: fireDefaultImpression
191
+ };
192
+ };
193
+ // --- VAST provider ---------------------------------------------------------
194
+ const mapVastResponse = /*#__PURE__*/function () {
195
+ var _ref3 = _rollupPluginBabelHelpers.asyncToGenerator(function* (creativeId, signal) {
196
+ var _validAd$advertiser$f;
197
+ const vastClient$1 = new vastClient.VASTClient();
198
+ const parsedVAST = yield vastClient$1.get(creativeId, {
199
+ timeout: 8000
200
+ });
201
+ if (signal.aborted) {
202
+ throw new DOMException('aborted', 'AbortError');
203
+ }
204
+ const validAd = parsedVAST.ads.find(ad => ad.creatives.length > 0);
205
+ if (!validAd) {
206
+ throw new Error('no_valid_ad');
207
+ }
208
+ const advertiserValue = Array.isArray(validAd.advertiser) ? (_validAd$advertiser$f = validAd.advertiser.find(entry => !!(entry !== null && entry !== void 0 && entry.value))) === null || _validAd$advertiser$f === void 0 ? void 0 : _validAd$advertiser$f.value : undefined;
209
+ const advertiser = resolveAdvertiser(advertiserValue, validAd.title || undefined);
210
+ let iconUrl;
211
+ let clickThroughUrl;
212
+ let companion;
213
+ for (const creative of validAd.creatives) {
214
+ if (creative.type === 'linear') {
215
+ var _linear$icons, _linear$videoClickThr;
216
+ const linear = creative;
217
+ iconUrl = iconUrl || ((_linear$icons = linear.icons) === null || _linear$icons === void 0 || (_linear$icons = _linear$icons.find(icon => !!(icon !== null && icon !== void 0 && icon.staticResource))) === null || _linear$icons === void 0 ? void 0 : _linear$icons.staticResource) || undefined;
218
+ clickThroughUrl = clickThroughUrl || ((_linear$videoClickThr = linear.videoClickThroughURLTemplate) === null || _linear$videoClickThr === void 0 ? void 0 : _linear$videoClickThr.url);
219
+ }
220
+ if (creative.type === 'companion') {
221
+ var _creative$variations, _variation$staticReso;
222
+ const variation = (_creative$variations = creative.variations) === null || _creative$variations === void 0 ? void 0 : _creative$variations[0];
223
+ const staticResource = variation === null || variation === void 0 || (_variation$staticReso = variation.staticResources) === null || _variation$staticReso === void 0 || (_variation$staticReso = _variation$staticReso[0]) === null || _variation$staticReso === void 0 ? void 0 : _variation$staticReso.url;
224
+ if (staticResource && !companion) {
225
+ var _variation$companionC, _variation$companionC2;
226
+ companion = {
227
+ staticResource,
228
+ width: Number(variation === null || variation === void 0 ? void 0 : variation.width) || 0,
229
+ height: Number(variation === null || variation === void 0 ? void 0 : variation.height) || 0,
230
+ clickThrough: variation === null || variation === void 0 || (_variation$companionC = variation.companionClickThroughURLTemplate) === null || _variation$companionC === void 0 ? void 0 : _variation$companionC.url,
231
+ clickTracking: ((_variation$companionC2 = variation === null || variation === void 0 ? void 0 : variation.companionClickTrackingURLTemplates) !== null && _variation$companionC2 !== void 0 ? _variation$companionC2 : []).map(entry => entry === null || entry === void 0 ? void 0 : entry.url).filter(url => !!url)
232
+ };
233
+ }
234
+ }
235
+ }
236
+ return {
237
+ creativeId,
238
+ advertiser,
239
+ title: validAd.title || advertiser,
240
+ iconUrl,
241
+ clickThroughUrl,
242
+ trackingEvents: [],
243
+ companion
244
+ };
245
+ });
246
+ return function mapVastResponse(_x5, _x6) {
247
+ return _ref3.apply(this, arguments);
248
+ };
249
+ }();
250
+ /**
251
+ * Maps a VAST tag into the normalized SsaiCreative shape.
252
+ *
253
+ * Note: `fireImpression` is intentionally left to the shared default for now.
254
+ * Proper VAST impression/tracking wiring through `VASTTracker` is a documented
255
+ * follow-up; it requires retaining the parsed ad/tracker per creative.
256
+ */
257
+ const createVastProvider = (_config = {}) => {
258
+ return {
259
+ id: 'vast',
260
+ resolve: mapVastResponse
261
+ };
262
+ };
263
+ /** Built-in provider factories keyed by name. */
264
+ const BUILTIN_PROVIDERS = {
265
+ streamlayer: config => createStreamLayerProvider(config),
266
+ quortex: config => createQuortexProvider(config),
267
+ vast: () => createVastProvider()
268
+ };
269
+ const isProviderInstance = option => {
270
+ return typeof option === 'object' && typeof option.resolve === 'function';
271
+ };
272
+ /**
273
+ * Resolve a {@link SsaiProviderOption} into a concrete {@link SsaiCreativeProvider}.
274
+ * Defaults to the StreamLayer provider (using `fallbackConfig`) when no option is
275
+ * supplied.
276
+ */
277
+ const resolveProvider = (option, fallbackConfig) => {
278
+ var _option$config;
279
+ if (!option) {
280
+ return createStreamLayerProvider(fallbackConfig);
281
+ }
282
+ if (typeof option === 'string') {
283
+ return BUILTIN_PROVIDERS[option](fallbackConfig);
284
+ }
285
+ if (isProviderInstance(option)) {
286
+ return option;
287
+ }
288
+ return BUILTIN_PROVIDERS[option.name]((_option$config = option.config) !== null && _option$config !== void 0 ? _option$config : fallbackConfig);
289
+ };
290
+
291
+ exports.BUILTIN_PROVIDERS = BUILTIN_PROVIDERS;
292
+ exports.DEFAULT_CREATIVE_API_BASE = DEFAULT_CREATIVE_API_BASE;
293
+ exports.createQuortexProvider = createQuortexProvider;
294
+ exports.createStreamLayerProvider = createStreamLayerProvider;
295
+ exports.createVastProvider = createVastProvider;
296
+ exports.fireBeacon = fireBeacon;
297
+ exports.fireDefaultImpression = fireDefaultImpression;
298
+ exports.fireTrackingEvents = fireTrackingEvents;
299
+ exports.resolveProvider = resolveProvider;
@@ -0,0 +1,81 @@
1
+ 'use strict';
2
+
3
+ var vastClient = require('@dailymotion/vast-client');
4
+
5
+ /**
6
+ * One place that constructs a `VASTTracker`.
7
+ *
8
+ * Every StreamLayer surface that reports VAST beacons — the GAM video player, both pause-ad
9
+ * renderers and the Standard Ad sidebar — needs the same `(ad, creative, variation)` triple, and
10
+ * each was assembling it by hand behind its own `@ts-ignore`. The parsed shapes those triples
11
+ * come from (`AdData` / `AdCompanion` / `AdNonLinear`) are defined in this package, so the
12
+ * mapping belongs here too.
13
+ *
14
+ * Deliberately *only* construction: when a beacon may fire, and how a surface de-duplicates its
15
+ * impression, stays with that surface. Those policies differ on purpose (per-ad-id in module
16
+ * scope for the sidebar, per component instance for the pause ads, per tracker identity for the
17
+ * player) and they are billing-visible, so collapsing them here would silently change counts.
18
+ */
19
+ // eslint-disable-next-line @typescript-eslint/triple-slash-reference
20
+ /// <reference path="../module.d.ts" />
21
+ const createVastTracker = ({
22
+ ad,
23
+ creative,
24
+ variation
25
+ }) =>
26
+ // The first argument is the `VASTClient` the tracker may update; every surface here drives
27
+ // playback itself and only wants the beacons, so it is always `null`.
28
+ //
29
+ // The type shim declares the 3rd argument as `VastCreativeLinear` and the 4th as another
30
+ // *creative*. At runtime `vast-client` accepts any creative in the 3rd and expects the
31
+ // `<Companion>` / `<NonLinear>` *variation* in the 4th. The casts encode that runtime contract
32
+ // once here rather than at every call site.
33
+ new vastClient.VASTTracker(null, ad, creative, variation);
34
+ /**
35
+ * A tracker for a single `<Companion>`. A `<CompanionAds>` creative has no creative-level
36
+ * `<TrackingEvents>` — each variation owns its own `creativeView` — so a companion is reported
37
+ * through its own tracker. `undefined` when the companion was parsed without them (nothing to
38
+ * report against).
39
+ */
40
+ const createCompanionTracker = (ad, companion) => companion.creative && companion.variation ? createVastTracker({
41
+ ad,
42
+ creative: companion.creative,
43
+ variation: companion.variation
44
+ }) : undefined;
45
+ /**
46
+ * The creative a parsed ad reports its impression / playback beacons through, in the order the
47
+ * shells draw them: the `<Linear>` creative first, then the `<NonLinear>` still, then — for a tag
48
+ * whose only creative is `<CompanionAds>` — the companion that was actually drawn.
49
+ *
50
+ * `drawnCompanion` is a parameter rather than `adData.companion` because only the rendering shell
51
+ * knows which companion reached the screen, and reporting one that did not is a false view.
52
+ */
53
+ const resolveVastTrackerTarget = (adData, drawnCompanion) => {
54
+ // `AdData.creative` is not optional in the type but `getCreative` can return nothing: a
55
+ // programmatic tag does not have to carry a `<Linear>` creative.
56
+ if (adData.creative) {
57
+ return {
58
+ ad: adData.ad,
59
+ creative: adData.creative
60
+ };
61
+ }
62
+ if (adData.nonLinear) {
63
+ return {
64
+ ad: adData.ad,
65
+ creative: adData.nonLinear.creative,
66
+ variation: adData.nonLinear.variation
67
+ };
68
+ }
69
+ if (drawnCompanion !== null && drawnCompanion !== void 0 && drawnCompanion.creative && drawnCompanion.variation) {
70
+ return {
71
+ ad: adData.ad,
72
+ creative: drawnCompanion.creative,
73
+ variation: drawnCompanion.variation
74
+ };
75
+ }
76
+ return undefined;
77
+ };
78
+
79
+ exports.createCompanionTracker = createCompanionTracker;
80
+ exports.createVastTracker = createVastTracker;
81
+ exports.resolveVastTrackerTarget = resolveVastTrackerTarget;
@@ -0,0 +1,28 @@
1
+ import { Advertisement } from './advertisement.js';
2
+ export { isFullbleedVideoTemplate } from './units/external-pause-ad.js';
3
+ export { INSIGHT_BODY_MAX_LENGTH } from './units/pause-ad-card.js';
4
+ export { gam } from './units/gam.js';
5
+ export { createCompanionTracker, createVastTracker, resolveVastTrackerTarget } from './units/vast-tracker.js';
6
+ import 'core-js/modules/es.array.iterator.js';
7
+ import 'core-js/modules/es.promise.js';
8
+ import 'core-js/modules/esnext.iterator.constructor.js';
9
+ import 'core-js/modules/esnext.iterator.for-each.js';
10
+ import 'core-js/modules/web.dom-collections.for-each.js';
11
+ import 'core-js/modules/web.dom-collections.iterator.js';
12
+ export { BUILTIN_PROVIDERS, DEFAULT_CREATIVE_API_BASE, createQuortexProvider, createStreamLayerProvider, createVastProvider, fireBeacon, fireTrackingEvents, resolveProvider } from './units/ssai-providers.js';
13
+ export { DEFAULT_PRELOAD_TIMEOUT_MS, preloadCreativeAssets, preloadImages } from './units/ssai-preload.js';
14
+
15
+ const advertisement = (instance, _opts, done) => {
16
+ instance.sdk.advertisement = new Advertisement(instance);
17
+ instance.sdk.onMount({
18
+ name: 'advertisement'
19
+ }, () => {
20
+ instance.sdk.advertisement.connect();
21
+ return () => {
22
+ instance.sdk.advertisement.disconnect();
23
+ };
24
+ });
25
+ done();
26
+ };
27
+
28
+ export { advertisement };