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

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 (77) hide show
  1. package/classic/package.json +5 -0
  2. package/lib/advertisement.d.ts +6 -6
  3. package/lib/advertisement.js +8 -8
  4. package/lib/cjs/advertisement.d.ts +64 -0
  5. package/lib/cjs/advertisement.js +307 -0
  6. package/lib/cjs/index.d.ts +19 -0
  7. package/lib/cjs/index.js +39 -0
  8. package/lib/cjs/package.json +1 -0
  9. package/lib/cjs/units/external-ad.d.ts +58 -0
  10. package/lib/cjs/units/external-ad.js +390 -0
  11. package/lib/cjs/units/external-pause-ad.d.ts +50 -0
  12. package/lib/cjs/units/external-pause-ad.js +253 -0
  13. package/lib/cjs/units/gam.d.ts +16 -0
  14. package/lib/cjs/units/gam.js +104 -0
  15. package/lib/cjs/units/parse-vast-extensions.d.ts +17 -0
  16. package/lib/cjs/units/parse-vast-extensions.js +52 -0
  17. package/lib/cjs/units/pause-ad-card.d.ts +49 -0
  18. package/lib/cjs/units/pause-ad-card.js +136 -0
  19. package/lib/cjs/units/pause-ad.d.ts +16 -0
  20. package/lib/cjs/units/pause-ad.js +52 -0
  21. package/lib/cjs/units/ssai-ad-break.d.ts +21 -0
  22. package/lib/cjs/units/ssai-ad-break.js +11 -0
  23. package/lib/cjs/units/ssai-creative.d.ts +89 -0
  24. package/lib/cjs/units/ssai-creative.js +136 -0
  25. package/lib/cjs/units/ssai-detector.d.ts +180 -0
  26. package/lib/cjs/units/ssai-detector.js +1156 -0
  27. package/lib/cjs/units/ssai-preload.d.ts +20 -0
  28. package/lib/cjs/units/ssai-preload.js +62 -0
  29. package/lib/cjs/units/ssai-providers.d.ts +117 -0
  30. package/lib/cjs/units/ssai-providers.js +263 -0
  31. package/lib/cjs/units/vast-tracker.d.ts +45 -0
  32. package/lib/cjs/units/vast-tracker.js +64 -0
  33. package/lib/classic/_virtual/_rollupPluginBabelHelpers.js +71 -0
  34. package/lib/classic/advertisement.js +331 -0
  35. package/lib/classic/cjs/_virtual/_rollupPluginBabelHelpers.js +77 -0
  36. package/lib/classic/cjs/advertisement.js +333 -0
  37. package/lib/classic/cjs/index.js +47 -0
  38. package/lib/classic/cjs/package.json +1 -0
  39. package/lib/classic/cjs/units/external-ad.js +453 -0
  40. package/lib/classic/cjs/units/external-pause-ad.js +274 -0
  41. package/lib/classic/cjs/units/gam.js +110 -0
  42. package/lib/classic/cjs/units/parse-vast-extensions.js +56 -0
  43. package/lib/classic/cjs/units/pause-ad-card.js +134 -0
  44. package/lib/classic/cjs/units/pause-ad.js +72 -0
  45. package/lib/classic/cjs/units/ssai-ad-break.js +11 -0
  46. package/lib/classic/cjs/units/ssai-creative.js +142 -0
  47. package/lib/classic/cjs/units/ssai-detector.js +1170 -0
  48. package/lib/classic/cjs/units/ssai-preload.js +72 -0
  49. package/lib/classic/cjs/units/ssai-providers.js +299 -0
  50. package/lib/classic/cjs/units/vast-tracker.js +81 -0
  51. package/lib/classic/index.js +28 -0
  52. package/lib/classic/units/external-ad.js +447 -0
  53. package/lib/classic/units/external-pause-ad.js +271 -0
  54. package/lib/classic/units/gam.js +108 -0
  55. package/lib/classic/units/parse-vast-extensions.js +54 -0
  56. package/lib/classic/units/pause-ad-card.js +131 -0
  57. package/lib/classic/units/pause-ad.js +70 -0
  58. package/lib/classic/units/ssai-ad-break.js +9 -0
  59. package/lib/classic/units/ssai-creative.js +140 -0
  60. package/lib/classic/units/ssai-detector.js +1167 -0
  61. package/lib/classic/units/ssai-preload.js +68 -0
  62. package/lib/classic/units/ssai-providers.js +289 -0
  63. package/lib/classic/units/vast-tracker.js +77 -0
  64. package/lib/index.d.ts +13 -13
  65. package/lib/index.js +8 -8
  66. package/lib/units/external-ad.d.ts +2 -2
  67. package/lib/units/external-ad.js +2 -2
  68. package/lib/units/pause-ad.d.ts +1 -1
  69. package/lib/units/pause-ad.js +1 -1
  70. package/lib/units/ssai-ad-break.d.ts +1 -1
  71. package/lib/units/ssai-creative.d.ts +1 -1
  72. package/lib/units/ssai-creative.js +1 -1
  73. package/lib/units/ssai-detector.d.ts +1 -1
  74. package/lib/units/ssai-preload.d.ts +1 -1
  75. package/lib/units/ssai-providers.d.ts +1 -1
  76. package/lib/units/vast-tracker.d.ts +1 -1
  77. package/package.json +41 -8
@@ -0,0 +1,271 @@
1
+ import { asyncToGenerator as _asyncToGenerator } from '../_virtual/_rollupPluginBabelHelpers.js';
2
+ import 'core-js/modules/es.error.cause.js';
3
+ import 'core-js/modules/es.array.iterator.js';
4
+ import 'core-js/modules/es.array.sort.js';
5
+ import 'core-js/modules/es.promise.js';
6
+ import 'core-js/modules/esnext.iterator.constructor.js';
7
+ import 'core-js/modules/esnext.iterator.filter.js';
8
+ import 'core-js/modules/esnext.iterator.find.js';
9
+ import 'core-js/modules/esnext.iterator.some.js';
10
+ import 'core-js/modules/web.dom-collections.iterator.js';
11
+ import { eventBus } from '@streamlayer/sdk-web-interfaces/classic';
12
+ import { createLogger } from '@streamlayer/sdk-web-logger/classic';
13
+ import '@streamlayer/sdk-web-api/classic';
14
+ import { VASTClient } from '@dailymotion/vast-client';
15
+
16
+ const FULLBLEED_VIDEO_TEMPLATES = ['fullbleed-video', 'fullbleed-video-center', 'fullbleed-video-left'];
17
+ /**
18
+ * `indexOf` rather than `Array.prototype.includes`: this package ships to Chrome 32
19
+ * TV webviews and must stay ES5-compatible without a polyfill.
20
+ */
21
+ const isFullbleedVideoTemplate = template => !!template && FULLBLEED_VIDEO_TEMPLATES.indexOf(template) !== -1;
22
+ const MP4_MIME = 'video/mp4';
23
+ // Programmatic spec (Index Exchange): bitrate window for a linear pause-ad MP4.
24
+ const MIN_BITRATE = 5000;
25
+ const MAX_BITRATE = 40000;
26
+ const TARGET_WIDTH = 1920;
27
+ const TARGET_HEIGHT = 1080;
28
+ const bitrateDistanceToWindow = bitrate => {
29
+ if (bitrate < MIN_BITRATE) return MIN_BITRATE - bitrate;
30
+ if (bitrate > MAX_BITRATE) return bitrate - MAX_BITRATE;
31
+ return 0;
32
+ };
33
+ const resolutionDistanceToTarget = file => {
34
+ var _file$width, _file$height;
35
+ return Math.abs(((_file$width = file.width) !== null && _file$width !== void 0 ? _file$width : 0) - TARGET_WIDTH) + Math.abs(((_file$height = file.height) !== null && _file$height !== void 0 ? _file$height : 0) - TARGET_HEIGHT);
36
+ };
37
+ /**
38
+ * Pick the best linear MP4 from a VAST creative's media files: prefer the
39
+ * highest bitrate inside the 5000–40000 kbps window; if none qualify, pick the
40
+ * one closest to the window. Ties break toward 1920×1080. Returns `undefined`
41
+ * when no MP4 is present so image-only VAST keeps working.
42
+ */
43
+ const selectMp4MediaFile = (mediaFiles = []) => {
44
+ const mp4s = (mediaFiles !== null && mediaFiles !== void 0 ? mediaFiles : []).filter(file => !!(file !== null && file !== void 0 && file.fileURL) && file.mimeType === MP4_MIME);
45
+ if (mp4s.length === 0) {
46
+ return undefined;
47
+ }
48
+ const inWindow = mp4s.filter(file => {
49
+ var _file$bitrate;
50
+ const bitrate = (_file$bitrate = file.bitrate) !== null && _file$bitrate !== void 0 ? _file$bitrate : 0;
51
+ return bitrate >= MIN_BITRATE && bitrate <= MAX_BITRATE;
52
+ });
53
+ if (inWindow.length > 0) {
54
+ return [...inWindow].sort((a, b) => {
55
+ var _b$bitrate, _a$bitrate;
56
+ const byBitrate = ((_b$bitrate = b.bitrate) !== null && _b$bitrate !== void 0 ? _b$bitrate : 0) - ((_a$bitrate = a.bitrate) !== null && _a$bitrate !== void 0 ? _a$bitrate : 0);
57
+ return byBitrate !== 0 ? byBitrate : resolutionDistanceToTarget(a) - resolutionDistanceToTarget(b);
58
+ })[0];
59
+ }
60
+ return [...mp4s].sort((a, b) => {
61
+ var _a$bitrate2, _b$bitrate2;
62
+ const byWindow = bitrateDistanceToWindow((_a$bitrate2 = a.bitrate) !== null && _a$bitrate2 !== void 0 ? _a$bitrate2 : 0) - bitrateDistanceToWindow((_b$bitrate2 = b.bitrate) !== null && _b$bitrate2 !== void 0 ? _b$bitrate2 : 0);
63
+ return byWindow !== 0 ? byWindow : resolutionDistanceToTarget(a) - resolutionDistanceToTarget(b);
64
+ })[0];
65
+ };
66
+ const vastClient = new VASTClient();
67
+ const log = createLogger('ui:gam-static');
68
+ const preloadImage = src => {
69
+ return new Promise((resolve, reject) => {
70
+ const image = new Image();
71
+ image.onload = () => resolve(src);
72
+ image.onerror = () => reject();
73
+ image.src = src;
74
+ });
75
+ };
76
+ const externalPauseAd = instance => {
77
+ return (gamUrl, $enabled, options) => {
78
+ var _options$template;
79
+ return (
80
+ // `template` MUST be a key part: nanoquery joins parts with `''` (no separator)
81
+ // and its `cache` Map is global per transport, so two stores that produce the
82
+ // same joined key share data AND cross-trigger each other's `revalidate()`.
83
+ // The `tpl:` prefix keeps the url/template boundary unambiguous. Never let this
84
+ // part be `undefined` — an undefined part nulls the WHOLE key and permanently
85
+ // suspends fetching (that is exactly how `$enabled: false` works).
86
+ instance.transport.nanoquery.createFetcherStore([gamUrl, $enabled, `tpl:${(_options$template = options.template) !== null && _options$template !== void 0 ? _options$template : 'default'}`], {
87
+ dedupeTime: options.prefetch ? options.refetchInterval : Infinity,
88
+ revalidateInterval: options.refetchInterval > 0 ? options.refetchInterval : 0,
89
+ // A creative-type mismatch is DETERMINISTIC: this tag returned no usable linear
90
+ // MP4 and retrying it can never change that, so cancel nanoquery's BACKOFF RETRY
91
+ // LOOP (any falsy return does) instead of re-hitting the ad server for the rest of
92
+ // the session — with the default `pauseAdDelay: 0` the store is enabled from mount.
93
+ // This only cancels the retry loop: `revalidateInterval` still re-runs the fetcher
94
+ // on its timer, and `Advertisement.getExternalPauseAd` forces a `revalidate()` on
95
+ // every `$enabled` false → true edge, so with `pauseAdDelay > 0` the tag is still
96
+ // re-requested on every pause.
97
+ // Transient failures (network, CORS, malformed XML, 5xx) still retry; the backoff
98
+ // below mirrors nanoquery's `defaultOnErrorRetry` so the two templates stay on the
99
+ // same curve. The jitter is not decorative — it spreads out retries that would
100
+ // otherwise fire in lockstep when the failure is correlated across stores/clients
101
+ // (ad-server 5xx, CORS), which the `pauseAdDelay: 0` prefetch-at-mount makes more
102
+ // likely.
103
+ // On `default` this is `undefined`, i.e. exactly as if the option were not passed —
104
+ // true as long as the shared nanoquery instance sets no global `onErrorRetry` (an
105
+ // explicit `undefined` DOES shadow a global one, and only then does nanoquery's
106
+ // destructuring default restore `defaultOnErrorRetry`).
107
+ onErrorRetry: isFullbleedVideoTemplate(options.template) ? ({
108
+ error,
109
+ retryCount
110
+ }) => {
111
+ if (error instanceof Error && error.message === 'no_valid_ad') {
112
+ return false;
113
+ }
114
+ return ~~((Math.random() + 0.5) * (1 << Math.min(retryCount, 8))) * 2000;
115
+ } : undefined,
116
+ fetcher: function () {
117
+ var _ref = _asyncToGenerator(function* (adUrl) {
118
+ if (!adUrl || typeof adUrl !== 'string') {
119
+ throw new Error('ad url is empty');
120
+ }
121
+ eventBus.emit('exposedPauseAd', {
122
+ action: 'load',
123
+ payload: {}
124
+ });
125
+ try {
126
+ var _options$template2, _parsedVAST$ads$find;
127
+ // `resolveAll: true` follows every `VASTAdTagURI` wrapper chain and resolves all
128
+ // Ads (the default only resolves the first standalone Ad and stops at the wrapper).
129
+ const parsedVAST = yield vastClient.get(adUrl, {
130
+ resolveAll: true
131
+ });
132
+ const template = (_options$template2 = options.template) !== null && _options$template2 !== void 0 ? _options$template2 : 'default';
133
+ // `fullbleed-video` needs an ad that actually carries a usable linear MP4. With
134
+ // `resolveAll: true` the response can be a pod/wrapper chain, so prefer the first
135
+ // ad that satisfies the template and fall back to the first ad with any creative
136
+ // (which preserves the existing `no_valid_ad` error and event sequencing).
137
+ const validAd = isFullbleedVideoTemplate(template) ? (_parsedVAST$ads$find = parsedVAST.ads.find(ad => ad.creatives.some(creative => {
138
+ var _selectMp4MediaFile;
139
+ return creative.type === 'linear' && (// eslint-disable-next-line @typescript-eslint/ban-ts-comment
140
+ // @ts-ignore vast-client linear creative carries mediaFiles
141
+ (_selectMp4MediaFile = selectMp4MediaFile(creative.mediaFiles)) === null || _selectMp4MediaFile === void 0 ? void 0 : _selectMp4MediaFile.fileURL);
142
+ }))) !== null && _parsedVAST$ads$find !== void 0 ? _parsedVAST$ads$find : parsedVAST.ads.find(ads => ads.creatives.length > 0) : parsedVAST.ads.find(ads => ads.creatives.length > 0);
143
+ if (validAd) {
144
+ var _companion$variations, _variation$staticReso;
145
+ const parentId = validAd.id || '';
146
+ log.debug(validAd, 'validAd');
147
+ // The HOST decides which creative wins (SC-322-2). `fullbleed-video` asks
148
+ // for the linear MP4 explicitly, so it is resolved FIRST and never falls
149
+ // back to a static image — the nonlinear/companion branches below `return`
150
+ // early, so without this a VAST carrying BOTH an image and a linear MP4
151
+ // (e.g. Google `single_ad_samples`) would never reach the linear creative.
152
+ // `default` keeps the pre-SC-322 nonlinear → companion order below and can
153
+ // never produce a video.
154
+ if (isFullbleedVideoTemplate(template)) {
155
+ const linear = validAd.creatives.find(creative => {
156
+ var _selectMp4MediaFile2;
157
+ return creative.type === 'linear' && (// eslint-disable-next-line @typescript-eslint/ban-ts-comment
158
+ // @ts-ignore vast-client linear creative carries mediaFiles
159
+ (_selectMp4MediaFile2 = selectMp4MediaFile(creative.mediaFiles)) === null || _selectMp4MediaFile2 === void 0 ? void 0 : _selectMp4MediaFile2.fileURL);
160
+ });
161
+ if (linear) {
162
+ log.debug(linear, 'linear');
163
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
164
+ // @ts-ignore vast-client linear creative carries mediaFiles
165
+ const mediaFile = selectMp4MediaFile(linear.mediaFiles);
166
+ if (mediaFile !== null && mediaFile !== void 0 && mediaFile.fileURL) {
167
+ const id = linear.adId || linear.id || parentId;
168
+ eventBus.emit('exposedPauseAd', {
169
+ action: 'loaded',
170
+ payload: {
171
+ id,
172
+ parentId
173
+ }
174
+ });
175
+ return {
176
+ id,
177
+ parentId,
178
+ url: adUrl,
179
+ backgroundVideoSrc: mediaFile.fileURL,
180
+ ad: validAd,
181
+ creative: linear
182
+ };
183
+ }
184
+ }
185
+ // Host asked for full-bleed video and this VAST carries no usable linear
186
+ // MP4 → fail closed so `ExposedPauseAd`'s error effect auto-closes the ad,
187
+ // exactly like any other unusable VAST. See §5 of the brief.
188
+ throw new Error('no_valid_ad');
189
+ }
190
+ const nonlinear = validAd.creatives.find(creative => creative.type === 'nonlinear');
191
+ if (nonlinear) {
192
+ var _nonlinear$variations;
193
+ const id = nonlinear.adId || nonlinear.id || parentId;
194
+ log.debug(nonlinear, 'nonlinear');
195
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
196
+ // @ts-ignore
197
+ const variation = (_nonlinear$variations = nonlinear.variations) === null || _nonlinear$variations === void 0 ? void 0 : _nonlinear$variations[0];
198
+ const staticResource = variation === null || variation === void 0 ? void 0 : variation.staticResource;
199
+ const adUrlTemplate = variation === null || variation === void 0 ? void 0 : variation.nonlinearClickThroughURLTemplate;
200
+ if (staticResource) {
201
+ yield preloadImage(staticResource);
202
+ eventBus.emit('exposedPauseAd', {
203
+ action: 'loaded',
204
+ payload: {
205
+ id,
206
+ parentId
207
+ }
208
+ });
209
+ return {
210
+ id,
211
+ parentId,
212
+ url: adUrl,
213
+ imageSrc: staticResource,
214
+ adUrl: adUrlTemplate,
215
+ ad: validAd,
216
+ creative: nonlinear,
217
+ variation
218
+ };
219
+ }
220
+ }
221
+ const companion = validAd.creatives.find(creative => creative.type === 'companion');
222
+ log.debug(companion, 'companion');
223
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
224
+ // @ts-ignore
225
+ const variation = companion === null || companion === void 0 || (_companion$variations = companion.variations) === null || _companion$variations === void 0 ? void 0 : _companion$variations[0];
226
+ 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;
227
+ const adUrlTemplate = variation === null || variation === void 0 ? void 0 : variation.companionClickThroughURLTemplate;
228
+ // `&& companion` is for TS narrowing only (companion.adId access below);
229
+ // it is runtime-redundant since staticResource derives from companion.
230
+ if (staticResource && companion) {
231
+ const id = companion.adId || companion.id || parentId;
232
+ yield preloadImage(staticResource);
233
+ eventBus.emit('exposedPauseAd', {
234
+ action: 'loaded',
235
+ payload: {
236
+ id,
237
+ parentId
238
+ }
239
+ });
240
+ return {
241
+ id,
242
+ parentId,
243
+ url: adUrl,
244
+ imageSrc: staticResource,
245
+ adUrl: adUrlTemplate,
246
+ ad: validAd,
247
+ creative: companion,
248
+ variation
249
+ };
250
+ }
251
+ }
252
+ throw new Error('no_valid_ad');
253
+ } catch (err) {
254
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
255
+ // @ts-expect-error
256
+ if (err.message !== 'no_valid_ad' && err.message !== 'ad url is empty') {
257
+ console.error(err);
258
+ }
259
+ throw err;
260
+ }
261
+ });
262
+ return function fetcher(_x) {
263
+ return _ref.apply(this, arguments);
264
+ };
265
+ }()
266
+ })
267
+ );
268
+ };
269
+ };
270
+
271
+ export { externalPauseAd, isFullbleedVideoTemplate };
@@ -0,0 +1,108 @@
1
+ import { asyncToGenerator as _asyncToGenerator } from '../_virtual/_rollupPluginBabelHelpers.js';
2
+ import 'core-js/modules/es.array.iterator.js';
3
+ import 'core-js/modules/web.dom-collections.iterator.js';
4
+ import 'core-js/modules/web.url.js';
5
+ import 'core-js/modules/web.url.to-json.js';
6
+ import 'core-js/modules/web.url-search-params.js';
7
+ import 'core-js/modules/web.url-search-params.delete.js';
8
+ import 'core-js/modules/web.url-search-params.has.js';
9
+ import 'core-js/modules/web.url-search-params.size.js';
10
+ import { safeLocalStorage, safeSessionStorage } from '@streamlayer/sdk-web-storage/classic';
11
+ import { v4, validate, v5 } from 'uuid';
12
+
13
+ const urlIsNotGam = url => {
14
+ return url.origin !== 'https://pubads.g.doubleclick.net';
15
+ };
16
+ const gam = (url, adContainer) => {
17
+ const parsedUrl = (() => {
18
+ try {
19
+ const parsedUrl = new URL(url);
20
+ return parsedUrl;
21
+ } catch (_err) {
22
+ return undefined;
23
+ }
24
+ })();
25
+ // Non-GAM VAST/VMAP URLs carry no GAM ad-request params and need no PAL nonce, so
26
+ // resolve them directly. PAL is only required for pubads.g.doubleclick.net requests —
27
+ // raw-VAST consumers (e.g. injected sidebar / l-bar) must not depend on the Google PAL
28
+ // SDK being loaded, so this must run before touching `goog`.
29
+ if (parsedUrl && urlIsNotGam(parsedUrl)) {
30
+ // eslint-disable-next-line require-await
31
+ return /*#__PURE__*/_asyncToGenerator(function* () {
32
+ return {
33
+ url: parsedUrl
34
+ };
35
+ });
36
+ }
37
+ // @ts-expect-error goog is injected by the externally-loaded Google PAL SDK
38
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
+ const pal = typeof goog === 'undefined' ? undefined : goog.pal;
40
+ if (!pal || !parsedUrl) {
41
+ // eslint-disable-next-line require-await
42
+ return /*#__PURE__*/_asyncToGenerator(function* () {
43
+ return undefined;
44
+ });
45
+ }
46
+ const consentSettings = new pal.ConsentSettings();
47
+ consentSettings.allowStorage = false;
48
+ const nonceLoader = new pal.NonceLoader(consentSettings);
49
+ const generateUrl = /*#__PURE__*/function () {
50
+ var _ref3 = _asyncToGenerator(function* () {
51
+ try {
52
+ var _adContainer$clientHe, _adContainer$clientWi;
53
+ const parsedUrl = new URL(url);
54
+ const request = new pal.NonceRequest();
55
+ let deviceId = safeLocalStorage().getItem('sl-device-id') || v4();
56
+ let sessionId = safeSessionStorage().getItem('sl-ad-session-id');
57
+ if (!sessionId) {
58
+ sessionId = v4();
59
+ safeSessionStorage().setItem('sl-ad-session-id', sessionId);
60
+ }
61
+ if (!validate(deviceId)) {
62
+ deviceId = v5(`https://${deviceId}`, v5.URL);
63
+ }
64
+ if (!parsedUrl.searchParams.get('url')) {
65
+ parsedUrl.searchParams.set('url', 'https://streamlayer.io');
66
+ }
67
+ if (!parsedUrl.searchParams.get('description_url')) {
68
+ parsedUrl.searchParams.set('description_url', 'https://streamlayer.io');
69
+ }
70
+ request.adWillAutoPlay = parsedUrl.searchParams.get('vpa') === 'auto';
71
+ request.adWillPlayMuted = parsedUrl.searchParams.get('vpmute') === '1';
72
+ request.continuousPlayback = true;
73
+ request.descriptionUrl = parsedUrl.searchParams.get('description_url');
74
+ request.iconsSupported = true;
75
+ request.sessionId = deviceId;
76
+ // Player support for VPAID 2.0, OMID 1.0, and SIMID 1.1
77
+ request.supportedApiFrameworks = '2,7,9';
78
+ request.videoHeight = (_adContainer$clientHe = adContainer === null || adContainer === void 0 ? void 0 : adContainer.clientHeight) !== null && _adContainer$clientHe !== void 0 ? _adContainer$clientHe : 0;
79
+ request.videoWidth = (_adContainer$clientWi = adContainer === null || adContainer === void 0 ? void 0 : adContainer.clientWidth) !== null && _adContainer$clientWi !== void 0 ? _adContainer$clientWi : 0;
80
+ const nonceManager = yield nonceLoader.loadNonceManager(request);
81
+ if (parsedUrl.searchParams.get('is_lat') === '[placeholder]') {
82
+ parsedUrl.searchParams.set('is_lat', '1');
83
+ }
84
+ if (parsedUrl.searchParams.get('rdid') === '[placeholder]') {
85
+ parsedUrl.searchParams.set('rdid', deviceId);
86
+ }
87
+ if (parsedUrl.searchParams.get('correlator') === '[placeholder]') {
88
+ parsedUrl.searchParams.set('correlator', sessionId);
89
+ }
90
+ parsedUrl.searchParams.set('wta', '1');
91
+ parsedUrl.searchParams.set('givn', nonceManager.getNonce());
92
+ return {
93
+ url: parsedUrl,
94
+ manager: nonceManager
95
+ };
96
+ } catch (adError) {
97
+ console.log('AdsManager could not be started', adError);
98
+ return undefined;
99
+ }
100
+ });
101
+ return function generateUrl() {
102
+ return _ref3.apply(this, arguments);
103
+ };
104
+ }();
105
+ return generateUrl;
106
+ };
107
+
108
+ export { gam };
@@ -0,0 +1,54 @@
1
+ import 'core-js/modules/esnext.iterator.constructor.js';
2
+ import 'core-js/modules/esnext.iterator.filter.js';
3
+ import 'core-js/modules/esnext.iterator.find.js';
4
+ import 'core-js/modules/esnext.iterator.map.js';
5
+ import { AdType } from '@streamlayer/sl-eslib/interactive/interactive.common_pb';
6
+
7
+ const MAP_EXTENSION_NAME_AD_TYPE = {
8
+ DoubleBox: AdType.SIDE_BY_SIDE
9
+ };
10
+ function parseVastExtension(root) {
11
+ var _child$value2, _child2, _child$value3, _child3, _child$value4, _child4, _backgrounds$find, _backgrounds$find2, _logos$find;
12
+ if (!root) {
13
+ return undefined;
14
+ }
15
+ const child = (node, name) => node.children.find(c => c.name === name);
16
+ const childrenByName = (node, name) => node.children.filter(c => c.name === name);
17
+ const urlOf = node => {
18
+ var _child$value, _child;
19
+ return (_child$value = (_child = child(node, 'Url')) === null || _child === void 0 ? void 0 : _child.value) !== null && _child$value !== void 0 ? _child$value : '';
20
+ };
21
+ const num = v => v == null ? NaN : Number(v);
22
+ const adName = (_child$value2 = (_child2 = child(root, 'AdName')) === null || _child2 === void 0 ? void 0 : _child2.value) !== null && _child$value2 !== void 0 ? _child$value2 : '';
23
+ const backgroundsNode = child(root, 'Backgrounds');
24
+ const backgrounds = backgroundsNode ? childrenByName(backgroundsNode, 'Background').map(bg => ({
25
+ orientation: bg.attributes.orientation,
26
+ width: num(bg.attributes.width),
27
+ height: num(bg.attributes.height),
28
+ type: bg.attributes.type,
29
+ url: urlOf(bg)
30
+ })) : [];
31
+ const logosNode = child(root, 'Logos');
32
+ const logos = logosNode ? childrenByName(logosNode, 'Logo').map(logo => ({
33
+ role: logo.attributes.role,
34
+ width: num(logo.attributes.width),
35
+ height: num(logo.attributes.height),
36
+ type: logo.attributes.type,
37
+ url: urlOf(logo)
38
+ })) : [];
39
+ const ctaNode = child(root, 'CTA');
40
+ const cta = {
41
+ label: ctaNode ? (_child$value3 = (_child3 = child(ctaNode, 'Label')) === null || _child3 === void 0 ? void 0 : _child3.value) !== null && _child$value3 !== void 0 ? _child$value3 : '' : '',
42
+ type: ctaNode ? (_child$value4 = (_child4 = child(ctaNode, 'Type')) === null || _child4 === void 0 ? void 0 : _child4.value) !== null && _child$value4 !== void 0 ? _child$value4 : '' : ''
43
+ };
44
+ return {
45
+ adName,
46
+ adType: MAP_EXTENSION_NAME_AD_TYPE[root.name] || AdType.SIDE_BY_SIDE,
47
+ landscapeBackground: (_backgrounds$find = backgrounds.find(b => b.orientation === 'landscape')) === null || _backgrounds$find === void 0 ? void 0 : _backgrounds$find.url,
48
+ portraitBackground: (_backgrounds$find2 = backgrounds.find(b => b.orientation === 'portrait')) === null || _backgrounds$find2 === void 0 ? void 0 : _backgrounds$find2.url,
49
+ sponsorLogo: (_logos$find = logos.find(l => l.role === 'header')) === null || _logos$find === void 0 ? void 0 : _logos$find.url,
50
+ ctaLabel: cta.label
51
+ };
52
+ }
53
+
54
+ export { parseVastExtension };
@@ -0,0 +1,131 @@
1
+ import 'core-js/modules/esnext.iterator.constructor.js';
2
+ import 'core-js/modules/esnext.iterator.filter.js';
3
+ import 'core-js/modules/esnext.iterator.map.js';
4
+ import { FactoidMediaMode, CardFormat, PromotionFormat, PauseAdLayout, PromotionButtonType, QRCode, UserAccountInfo, NotificationSponsorLogoMode, UseGeneralLogo } from '@streamlayer/sl-eslib/interactive/interactive.common_pb';
5
+
6
+ /**
7
+ * Insight body cap (SC-353). Studio enforces it on the Additional Content field; the
8
+ * SDK clamps as well so a card authored before the limit landed cannot overflow the
9
+ * screen — the format is explicitly designed to fit without scrolling.
10
+ */
11
+ const INSIGHT_BODY_MAX_LENGTH = 600;
12
+ /**
13
+ * Sponsor logo for a factoid card. Same General-tab opt-in as the promotion path below,
14
+ * but the logo lives on `question.promotion.sponsor` (a factoid card carries no
15
+ * `PromotionOptions`) and Studio writes the uploaded file to `logo`, not `centerLogo`.
16
+ *
17
+ * `logo` therefore WINS over `centerLogo`: the latter is an optional field carried over from the
18
+ * notification/header surfaces, so a card that kept a stale `centerLogo` from an earlier revision
19
+ * would otherwise render it instead of the Insight logo the author just uploaded.
20
+ */
21
+ const resolveInsightSponsorLogo = question => {
22
+ var _question$promotion, _question$promotion2;
23
+ const sponsor = (_question$promotion = question.promotion) === null || _question$promotion === void 0 ? void 0 : _question$promotion.sponsor;
24
+ if ((sponsor === null || sponsor === void 0 ? void 0 : sponsor.logoPosition) === NotificationSponsorLogoMode.NOTIFICATION_SPONSOR_LOGO_NONE) {
25
+ return undefined;
26
+ }
27
+ return (sponsor === null || sponsor === void 0 ? void 0 : sponsor.useGeneralLogo) === UseGeneralLogo.ENABLED ? ((_question$promotion2 = question.promotion) === null || _question$promotion2 === void 0 || (_question$promotion2 = _question$promotion2.generalTabMetadata) === null || _question$promotion2 === void 0 ? void 0 : _question$promotion2.advertiserTransparentLogo) || undefined : (sponsor === null || sponsor === void 0 ? void 0 : sponsor.logo) || (sponsor === null || sponsor === void 0 ? void 0 : sponsor.centerLogo) || undefined;
28
+ };
29
+ const MEDIA_MODE_BY_PROTO = {
30
+ [FactoidMediaMode.IMAGE]: 'image',
31
+ [FactoidMediaMode.CIRCLE]: 'circle'
32
+ };
33
+ /**
34
+ * Insight Pause Ad, Full Bleed (SC-353). A factoid card, so none of the promotion
35
+ * plumbing above applies: the heading is the question subject, the body is
36
+ * `FactoidOptions.body`, and the sponsor logo comes off `question.promotion.sponsor`.
37
+ *
38
+ * `FACTOID_MEDIA_MODE_VIDEO` is deliberately treated as "no media": the full-bleed
39
+ * format has no player chrome and no way to start playback, unlike the sidebar variant.
40
+ */
41
+ const parseInsightPauseAdCard = question => {
42
+ var _question$options, _MEDIA_MODE_BY_PROTO$, _question$backgroundI;
43
+ const factoidOptions = ((_question$options = question.options) === null || _question$options === void 0 ? void 0 : _question$options.options.case) === 'factoid' ? question.options.options.value : undefined;
44
+ if (!factoidOptions) {
45
+ return null;
46
+ }
47
+ const mediaMode = (_MEDIA_MODE_BY_PROTO$ = MEDIA_MODE_BY_PROTO[factoidOptions.mode]) !== null && _MEDIA_MODE_BY_PROTO$ !== void 0 ? _MEDIA_MODE_BY_PROTO$ : 'none';
48
+ const body = factoidOptions.body.slice(0, INSIGHT_BODY_MAX_LENGTH);
49
+ return {
50
+ id: question.id,
51
+ parentId: question.eventId || question.id,
52
+ // `landscapeUrl` ONLY. `portraitUrl` keeps stale artwork from earlier revisions of the
53
+ // card that Studio no longer shows in its Background Image slot, so falling back to it
54
+ // paints a background the author has already removed. Unlike the standard card, an
55
+ // Insight one renders fine with no background at all — its copy is the ad.
56
+ backgroundImageSrc: ((_question$backgroundI = question.backgroundImage) === null || _question$backgroundI === void 0 ? void 0 : _question$backgroundI.landscapeUrl) || undefined,
57
+ kind: 'insight',
58
+ layout: 'left',
59
+ isInteractive: false,
60
+ logoSrc: resolveInsightSponsorLogo(question),
61
+ title: question.subject || undefined,
62
+ description: body || undefined,
63
+ mediaSrc: mediaMode === 'none' ? undefined : factoidOptions.image || undefined,
64
+ mediaMode
65
+ };
66
+ };
67
+ const parsePauseAdCard = question => {
68
+ var _question$options2, _question$backgroundI2, _question$options3, _pauseAdOptions$layou, _question$promotion3, _promotionOptions$ban, _promotionOptions$ban2, _pauseAdOptions$qrCod, _pauseAdOptions$qrCod2;
69
+ if (((_question$options2 = question.options) === null || _question$options2 === void 0 ? void 0 : _question$options2.options.case) === 'factoid') {
70
+ return parseInsightPauseAdCard(question);
71
+ }
72
+ const backgroundImageSrc = (_question$backgroundI2 = question.backgroundImage) === null || _question$backgroundI2 === void 0 ? void 0 : _question$backgroundI2.landscapeUrl;
73
+ if (!backgroundImageSrc) {
74
+ return null;
75
+ }
76
+ const promotionOptions = ((_question$options3 = question.options) === null || _question$options3 === void 0 ? void 0 : _question$options3.options.case) === 'promotion' ? question.options.options.value : undefined;
77
+ const pauseAdOptions = promotionOptions === null || promotionOptions === void 0 ? void 0 : promotionOptions.pauseAdOptions;
78
+ const optionsSponsor = promotionOptions === null || promotionOptions === void 0 ? void 0 : promotionOptions.sponsor;
79
+ const layoutProto = (_pauseAdOptions$layou = pauseAdOptions === null || pauseAdOptions === void 0 ? void 0 : pauseAdOptions.layout) !== null && _pauseAdOptions$layou !== void 0 ? _pauseAdOptions$layou : PauseAdLayout.UNSET;
80
+ const layout = layoutProto === PauseAdLayout.CENTER ? 'center' : layoutProto === PauseAdLayout.IMAGE ? 'image' : 'left';
81
+ const isInteractive = (promotionOptions === null || promotionOptions === void 0 ? void 0 : promotionOptions.buttonType) === PromotionButtonType.SEND_TO_USER;
82
+ const hasQr = (pauseAdOptions === null || pauseAdOptions === void 0 ? void 0 : pauseAdOptions.qrCode) === QRCode.QR_CODE_ENABLED && !!(pauseAdOptions !== null && pauseAdOptions !== void 0 && pauseAdOptions.qrCodeUrl);
83
+ let ctaLabel;
84
+ let ctaUrl;
85
+ if (isInteractive && (promotionOptions === null || promotionOptions === void 0 ? void 0 : promotionOptions.buttonOptions.case) === 'sendToUserOptions') {
86
+ const accountInfo = promotionOptions.buttonOptions.value.userAccountInfo;
87
+ const isPhone = accountInfo === UserAccountInfo.PHONE;
88
+ ctaUrl = isPhone ? 'sendToPhone:' : 'sendToEmail:';
89
+ ctaLabel = isPhone ? 'Send info to account phone' : 'Send info to account email';
90
+ }
91
+ const logoSrc = (optionsSponsor === null || optionsSponsor === void 0 ? void 0 : optionsSponsor.logoPosition) === NotificationSponsorLogoMode.NOTIFICATION_SPONSOR_LOGO_NONE ? undefined : (optionsSponsor === null || optionsSponsor === void 0 ? void 0 : optionsSponsor.useGeneralLogo) === UseGeneralLogo.ENABLED ? ((_question$promotion3 = question.promotion) === null || _question$promotion3 === void 0 || (_question$promotion3 = _question$promotion3.generalTabMetadata) === null || _question$promotion3 === void 0 ? void 0 : _question$promotion3.advertiserTransparentLogo) || undefined : (optionsSponsor === null || optionsSponsor === void 0 ? void 0 : optionsSponsor.centerLogo) || undefined;
92
+ return {
93
+ id: question.id,
94
+ parentId: question.eventId || question.id,
95
+ backgroundImageSrc,
96
+ layout,
97
+ logoSrc,
98
+ title: (promotionOptions === null || promotionOptions === void 0 || (_promotionOptions$ban = promotionOptions.banner) === null || _promotionOptions$ban === void 0 ? void 0 : _promotionOptions$ban.title) || undefined,
99
+ description: (promotionOptions === null || promotionOptions === void 0 || (_promotionOptions$ban2 = promotionOptions.banner) === null || _promotionOptions$ban2 === void 0 ? void 0 : _promotionOptions$ban2.body) || undefined,
100
+ isInteractive,
101
+ ctaLabel: ctaLabel || undefined,
102
+ ctaUrl: ctaUrl || undefined,
103
+ qrCodeUrl: hasQr ? (_pauseAdOptions$qrCod = pauseAdOptions === null || pauseAdOptions === void 0 ? void 0 : pauseAdOptions.qrCodeUrl) !== null && _pauseAdOptions$qrCod !== void 0 ? _pauseAdOptions$qrCod : undefined : undefined,
104
+ qrCodeLabel: hasQr ? (_pauseAdOptions$qrCod2 = pauseAdOptions === null || pauseAdOptions === void 0 ? void 0 : pauseAdOptions.qrCodeLabel) !== null && _pauseAdOptions$qrCod2 !== void 0 ? _pauseAdOptions$qrCod2 : undefined : undefined
105
+ };
106
+ };
107
+ /**
108
+ * Which cards from `pauseAdList` the SDK can actually draw. Both renderers are full bleed; a
109
+ * Sidebar-format pause ad has no chrome yet and is skipped.
110
+ */
111
+ const isFullBleedPauseAd = question => {
112
+ var _question$options4, _question$options5;
113
+ if (((_question$options4 = question.options) === null || _question$options4 === void 0 ? void 0 : _question$options4.options.case) === 'factoid') {
114
+ // Insight Pause Ad (SC-353). Studio does not write `CardFormat` on these cards yet
115
+ // (SLW-7062), so an UNSET format is taken as Full Bleed — the only Insight pause-ad chrome
116
+ // the SDK has. An explicit Sidebar stays out. Drop the UNSET arm once Studio sets the field.
117
+ return question.format === CardFormat.FULL_BLEED || question.format === CardFormat.UNSET;
118
+ }
119
+ const promotionOptions = ((_question$options5 = question.options) === null || _question$options5 === void 0 ? void 0 : _question$options5.options.case) === 'promotion' ? question.options.options.value : undefined;
120
+ return (promotionOptions === null || promotionOptions === void 0 ? void 0 : promotionOptions.format) === PromotionFormat.FULL_BLEED || question.format === CardFormat.FULL_BLEED;
121
+ };
122
+ /**
123
+ * The `pauseAdList` response, shaped for the renderers: keep the cards the SDK has chrome for,
124
+ * turn each into a `PauseAdCard`, drop the ones that cannot be drawn.
125
+ *
126
+ * Pure on purpose — `pause-ad.ts` owns the store and the transport, this owns the card shapes,
127
+ * and only this half needs unit tests.
128
+ */
129
+ const parsePauseAdCards = questions => questions.filter(isFullBleedPauseAd).map(parsePauseAdCard).filter(card => card !== null);
130
+
131
+ export { INSIGHT_BODY_MAX_LENGTH, parsePauseAdCards };
@@ -0,0 +1,70 @@
1
+ import { asyncToGenerator as _asyncToGenerator } from '../_virtual/_rollupPluginBabelHelpers.js';
2
+ import { createLogger } from '@streamlayer/sdk-web-logger/classic';
3
+ import { atom } from 'nanostores';
4
+ import '@streamlayer/sdk-web-api/classic';
5
+ import '@streamlayer/sdk-web-core/classic/store';
6
+ import { Feed } from '@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb';
7
+ import { parsePauseAdCards } from './pause-ad-card.js';
8
+
9
+ const log = createLogger('advertisement:pause-ad');
10
+ const pauseAdListStore = instance => {
11
+ const $slStreamId = instance.stores.slStreamId.getAtomStore();
12
+ return ($enabled, options) => {
13
+ const {
14
+ client,
15
+ queryKey
16
+ } = instance.transport.createPromiseClient(Feed, {
17
+ method: 'pauseAdList',
18
+ params: [$slStreamId, $enabled]
19
+ });
20
+ const $list = instance.transport.nanoquery.createFetcherStore(queryKey, {
21
+ dedupeTime: 0,
22
+ revalidateInterval: options.refetchInterval > 0 ? options.refetchInterval : 0,
23
+ fetcher: function () {
24
+ var _ref = _asyncToGenerator(function* (_, __, eventId, isEnabled) {
25
+ var _res$data;
26
+ if (!eventId || typeof eventId !== 'string' || !isEnabled) {
27
+ return [];
28
+ }
29
+ log.debug({
30
+ eventId
31
+ }, 'fetching pause ad list');
32
+ const res = yield client.pauseAdList({
33
+ eventId
34
+ });
35
+ const cards = parsePauseAdCards((_res$data = res.data) !== null && _res$data !== void 0 ? _res$data : []);
36
+ log.debug({
37
+ count: cards.length
38
+ }, 'parsed %d fullbleed pause ad cards');
39
+ return cards;
40
+ });
41
+ return function fetcher(_x, _x2, _x3, _x4) {
42
+ return _ref.apply(this, arguments);
43
+ };
44
+ }()
45
+ });
46
+ const $index = atom(0);
47
+ const next = () => {
48
+ const list = $list.get().data;
49
+ if (!(list !== null && list !== void 0 && list.length)) return;
50
+ $index.set(($index.get() + 1) % list.length);
51
+ };
52
+ const reset = () => {
53
+ $index.set(0);
54
+ };
55
+ const getCurrent = () => {
56
+ const list = $list.get().data;
57
+ if (!(list !== null && list !== void 0 && list.length)) return undefined;
58
+ return list[$index.get()];
59
+ };
60
+ return {
61
+ $list,
62
+ $index,
63
+ next,
64
+ reset,
65
+ getCurrent
66
+ };
67
+ };
68
+ };
69
+
70
+ export { pauseAdListStore };
@@ -0,0 +1,9 @@
1
+ import { createSingleStore } from '@streamlayer/sdk-web-interfaces/classic';
2
+
3
+ /**
4
+ * Imperative atom driven directly by the detector (no nanoquery — the trigger
5
+ * is push-based, not request/response).
6
+ */
7
+ const createSsaiAdBreakStore = () => createSingleStore(null);
8
+
9
+ export { createSsaiAdBreakStore };