@streamlayer/feature-advertisement 1.0.0 → 1.1.1-rc.10.p6eb7304a

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 (105) hide show
  1. package/classic/package.json +5 -0
  2. package/lib/advertisement.d.ts +6 -6
  3. package/lib/advertisement.js +32 -17
  4. package/lib/cjs/advertisement.d.ts +64 -0
  5. package/lib/cjs/advertisement.js +322 -0
  6. package/lib/cjs/index.d.ts +21 -0
  7. package/lib/cjs/index.js +41 -0
  8. package/lib/cjs/package.json +1 -0
  9. package/lib/cjs/units/ad-macros.d.ts +7 -0
  10. package/lib/cjs/units/ad-macros.js +91 -0
  11. package/lib/cjs/units/external-ad.d.ts +127 -0
  12. package/lib/cjs/units/external-ad.js +421 -0
  13. package/lib/cjs/units/external-pause-ad.d.ts +50 -0
  14. package/lib/cjs/units/external-pause-ad.js +259 -0
  15. package/lib/cjs/units/gam.d.ts +26 -0
  16. package/lib/cjs/units/gam.js +152 -0
  17. package/lib/cjs/units/parse-vast-extensions.d.ts +26 -0
  18. package/lib/cjs/units/parse-vast-extensions.js +56 -0
  19. package/lib/cjs/units/pause-ad-card.d.ts +49 -0
  20. package/lib/cjs/units/pause-ad-card.js +136 -0
  21. package/lib/cjs/units/pause-ad.d.ts +16 -0
  22. package/lib/cjs/units/pause-ad.js +52 -0
  23. package/lib/cjs/units/sponsor-logo.d.ts +78 -0
  24. package/lib/cjs/units/sponsor-logo.js +194 -0
  25. package/lib/cjs/units/ssai-ad-break.d.ts +21 -0
  26. package/lib/cjs/units/ssai-ad-break.js +11 -0
  27. package/lib/cjs/units/ssai-creative.d.ts +89 -0
  28. package/lib/cjs/units/ssai-creative.js +136 -0
  29. package/lib/cjs/units/ssai-detector.d.ts +180 -0
  30. package/lib/cjs/units/ssai-detector.js +1172 -0
  31. package/lib/cjs/units/ssai-log.d.ts +16 -0
  32. package/lib/cjs/units/ssai-log.js +23 -0
  33. package/lib/cjs/units/ssai-preload.d.ts +20 -0
  34. package/lib/cjs/units/ssai-preload.js +62 -0
  35. package/lib/cjs/units/ssai-providers.d.ts +117 -0
  36. package/lib/cjs/units/ssai-providers.js +300 -0
  37. package/lib/cjs/units/vast-tracker.d.ts +45 -0
  38. package/lib/cjs/units/vast-tracker.js +64 -0
  39. package/lib/classic/_virtual/_rollupPluginBabelHelpers.js +71 -0
  40. package/lib/classic/advertisement.js +348 -0
  41. package/lib/classic/cjs/_virtual/_rollupPluginBabelHelpers.js +77 -0
  42. package/lib/classic/cjs/advertisement.js +350 -0
  43. package/lib/classic/cjs/index.js +49 -0
  44. package/lib/classic/cjs/package.json +1 -0
  45. package/lib/classic/cjs/units/ad-macros.js +115 -0
  46. package/lib/classic/cjs/units/external-ad.js +500 -0
  47. package/lib/classic/cjs/units/external-pause-ad.js +278 -0
  48. package/lib/classic/cjs/units/gam.js +173 -0
  49. package/lib/classic/cjs/units/parse-vast-extensions.js +60 -0
  50. package/lib/classic/cjs/units/pause-ad-card.js +134 -0
  51. package/lib/classic/cjs/units/pause-ad.js +72 -0
  52. package/lib/classic/cjs/units/sponsor-logo.js +201 -0
  53. package/lib/classic/cjs/units/ssai-ad-break.js +11 -0
  54. package/lib/classic/cjs/units/ssai-creative.js +142 -0
  55. package/lib/classic/cjs/units/ssai-detector.js +1195 -0
  56. package/lib/classic/cjs/units/ssai-log.js +23 -0
  57. package/lib/classic/cjs/units/ssai-preload.js +72 -0
  58. package/lib/classic/cjs/units/ssai-providers.js +361 -0
  59. package/lib/classic/cjs/units/vast-tracker.js +81 -0
  60. package/lib/classic/index.js +29 -0
  61. package/lib/classic/units/ad-macros.js +113 -0
  62. package/lib/classic/units/external-ad.js +491 -0
  63. package/lib/classic/units/external-pause-ad.js +275 -0
  64. package/lib/classic/units/gam.js +171 -0
  65. package/lib/classic/units/parse-vast-extensions.js +58 -0
  66. package/lib/classic/units/pause-ad-card.js +131 -0
  67. package/lib/classic/units/pause-ad.js +70 -0
  68. package/lib/classic/units/sponsor-logo.js +197 -0
  69. package/lib/classic/units/ssai-ad-break.js +9 -0
  70. package/lib/classic/units/ssai-creative.js +140 -0
  71. package/lib/classic/units/ssai-detector.js +1192 -0
  72. package/lib/classic/units/ssai-log.js +21 -0
  73. package/lib/classic/units/ssai-preload.js +68 -0
  74. package/lib/classic/units/ssai-providers.js +351 -0
  75. package/lib/classic/units/vast-tracker.js +77 -0
  76. package/lib/index.d.ts +15 -12
  77. package/lib/index.js +14 -7
  78. package/lib/units/ad-macros.d.ts +7 -0
  79. package/lib/units/ad-macros.js +87 -0
  80. package/lib/units/external-ad.d.ts +71 -2
  81. package/lib/units/external-ad.js +94 -66
  82. package/lib/units/external-pause-ad.js +7 -1
  83. package/lib/units/gam.d.ts +11 -1
  84. package/lib/units/gam.js +65 -17
  85. package/lib/units/parse-vast-extensions.d.ts +10 -1
  86. package/lib/units/parse-vast-extensions.js +5 -1
  87. package/lib/units/pause-ad-card.d.ts +49 -0
  88. package/lib/units/pause-ad-card.js +130 -0
  89. package/lib/units/pause-ad.d.ts +1 -18
  90. package/lib/units/pause-ad.js +2 -49
  91. package/lib/units/sponsor-logo.d.ts +78 -0
  92. package/lib/units/sponsor-logo.js +188 -0
  93. package/lib/units/ssai-ad-break.d.ts +1 -1
  94. package/lib/units/ssai-creative.d.ts +1 -1
  95. package/lib/units/ssai-creative.js +1 -1
  96. package/lib/units/ssai-detector.d.ts +1 -1
  97. package/lib/units/ssai-detector.js +27 -11
  98. package/lib/units/ssai-log.d.ts +16 -0
  99. package/lib/units/ssai-log.js +18 -0
  100. package/lib/units/ssai-preload.d.ts +1 -1
  101. package/lib/units/ssai-providers.d.ts +1 -1
  102. package/lib/units/ssai-providers.js +48 -11
  103. package/lib/units/vast-tracker.d.ts +1 -1
  104. package/lib/vast-client.d.ts +9 -0
  105. package/package.json +43 -10
@@ -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,197 @@
1
+ import 'core-js/modules/es.array.push.js';
2
+ import 'core-js/modules/esnext.iterator.constructor.js';
3
+ import 'core-js/modules/esnext.iterator.filter.js';
4
+ import 'core-js/modules/esnext.iterator.map.js';
5
+
6
+ /**
7
+ * Sponsor-logo slot selection for a **feature** ad unit (Insight, Prediction and Trivia today;
8
+ * Poll is the same shape and is a separate ticket).
9
+ *
10
+ * Deliberately NOT `selectCompanions` (`./external-ad.ts`). That rule is the *display*-unit rule:
11
+ * it promotes a companion to the logo slot only when the tag ships an exact 300x75 `<Companion>`
12
+ * next to at least one other. A feature ad-unit tag is typically a **single** creative — often a
13
+ * lone NonLinear `<StaticResource>` — where the ad IS the logo, which is exactly the shape that
14
+ * rule returns nothing for. `selectCompanions` stays untouched: SC-335's three shipped units
15
+ * depend on its exact behaviour and impression counts are billing-visible.
16
+ *
17
+ * Mirrors iOS `SLRVASTSlotRole.logo` + `SLRVASTAssetPool`
18
+ * (`StreamLayerSDK/Frameworks/SLRGAMFramework/Sources/VASTSlotFiller/`):
19
+ *
20
+ * - **Images only.** A video-only tag yields no logo. `<Icon>` is never projected — icons hang off
21
+ * the `<Linear>` creative, which this selector does not look at. A `<StaticResource>` the tag
22
+ * declares as a non-image `creativeType` is skipped too, so a companion that lists a script
23
+ * before its image still resolves to the image (see `isImageResource`).
24
+ * - **Origin-agnostic.** A lone NonLinear `<StaticResource>` is as valid as a `<Companion>`.
25
+ * - **Aspect-dominant** toward 1:1: the smallest `|log(assetAspect) - log(1)|` wins, ties broken by
26
+ * larger area, then by higher pixel density. Aspect is a *preference, never a filter* — the only
27
+ * hard constraint is the asset kind, so a badly shaped asset still wins if it is the only one.
28
+ * - Assets whose intrinsic size the tag never declared rank last, but still beat nothing.
29
+ *
30
+ * The module also hosts iOS's second logo role, `SLRVASTSlotRole.cardLogo` (`selectCardLogo`) —
31
+ * the same ranking narrowed to `<Companion>` origins, for the hero-card display units.
32
+ */
33
+ // eslint-disable-next-line @typescript-eslint/triple-slash-reference
34
+ /// <reference path="../module.d.ts" />
35
+ /** `width`/`height` are XML attributes (strings at runtime); 0 and NaN both mean "not declared". */
36
+ const toSize = value => {
37
+ const size = Number(value);
38
+ return size > 0 ? size : undefined;
39
+ };
40
+ /**
41
+ * VAST 4 `<CompanionAds pxratio>`; `@dailymotion/vast-client` defaults it to `'1'` and the
42
+ * `@types/vast-client` shim does not declare it, hence the loose read.
43
+ */
44
+ const toPxRatio = variation => {
45
+ return Number(variation.pxratio) || 1;
46
+ };
47
+ /**
48
+ * `<StaticResource creativeType>`. The slot draws an `<img>`, so a resource the tag declares as
49
+ * anything else — the `application/x-shockwave-flash` or `application/javascript` creative a
50
+ * companion may list beside its image — must never fill it: it would swap the proto logo for a
51
+ * broken image AND still fire an impression for something nobody ever saw.
52
+ *
53
+ * An ABSENT type is not a rejection. VAST requires the attribute but real GAM image companions
54
+ * routinely omit it, and this module's only hard constraint is the asset kind, so an undeclared
55
+ * type stays a candidate. `@dailymotion/vast-client` writes `0` for a missing NonLinear
56
+ * `creativeType` and `null` for a missing companion one; both are falsy, hence the single guard.
57
+ */
58
+ const isImageResource = creativeType => {
59
+ if (!creativeType) {
60
+ return true;
61
+ }
62
+ return String(creativeType).toLowerCase().indexOf('image/') === 0;
63
+ };
64
+ /**
65
+ * The first resource a `<Companion>` declares as an image (or leaves undeclared). NOT
66
+ * `staticResources[0]`: the order in the tag is the advertiser's, and a non-image resource listed
67
+ * first must not hide a usable image behind it.
68
+ */
69
+ const pickCompanionImage = variation => {
70
+ const resources = variation.staticResources || [];
71
+ for (let i = 0; i < resources.length; i++) {
72
+ const resource = resources[i];
73
+ if (resource && resource.url && isImageResource(resource.creativeType)) {
74
+ return resource.url;
75
+ }
76
+ }
77
+ return undefined;
78
+ };
79
+ /** Distance from square on a log scale, so 2:1 and 1:2 are equally far from 1:1. */
80
+ const aspectDistance = asset => {
81
+ if (!asset.width || !asset.height) {
82
+ // Unknown intrinsic size — rank last, but still a candidate.
83
+ return Infinity;
84
+ }
85
+ return Math.abs(Math.log(asset.width / asset.height));
86
+ };
87
+ const collectAssetsFrom = ad => {
88
+ const assets = [];
89
+ for (let i = 0; i < ad.creatives.length; i++) {
90
+ const creative = ad.creatives[i];
91
+ if (creative.type === 'companion') {
92
+ const companionCreative = creative;
93
+ const variations = companionCreative.variations || [];
94
+ for (let j = 0; j < variations.length; j++) {
95
+ const variation = variations[j];
96
+ const imageUrl = variation && pickCompanionImage(variation);
97
+ if (imageUrl) {
98
+ var _variation$companionC;
99
+ assets.push({
100
+ imageUrl,
101
+ clickUrl: (_variation$companionC = variation.companionClickThroughURLTemplate) !== null && _variation$companionC !== void 0 ? _variation$companionC : undefined,
102
+ width: toSize(variation.width),
103
+ height: toSize(variation.height),
104
+ origin: 'companion',
105
+ creative: companionCreative,
106
+ variation
107
+ });
108
+ }
109
+ }
110
+ continue;
111
+ }
112
+ if (creative.type === 'nonlinear') {
113
+ const nonLinearCreative = creative;
114
+ const variations = nonLinearCreative.variations || [];
115
+ for (let j = 0; j < variations.length; j++) {
116
+ const variation = variations[j];
117
+ // `type` is where the parser puts a `<NonLinear>`'s `creativeType`, and it is written last
118
+ // from the `<StaticResource>` element, so it describes `staticResource` whenever that is
119
+ // set. An HTML- or iframe-typed variation carries no `staticResource` and drops out here.
120
+ const imageUrl = variation && isImageResource(variation.type) ? variation.staticResource : undefined;
121
+ if (imageUrl) {
122
+ var _variation$nonlinearC;
123
+ assets.push({
124
+ imageUrl,
125
+ // 6.4.2 emits `nonlinearClickThroughURLTemplate` (lower-case `l`); the shim declares
126
+ // the upper-case spelling. The runtime one is authoritative — see `getNonLinear`.
127
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
128
+ // @ts-ignore
129
+ clickUrl: (_variation$nonlinearC = variation.nonlinearClickThroughURLTemplate) !== null && _variation$nonlinearC !== void 0 ? _variation$nonlinearC : undefined,
130
+ width: toSize(variation.width),
131
+ height: toSize(variation.height),
132
+ origin: 'nonlinear',
133
+ creative: nonLinearCreative,
134
+ variation
135
+ });
136
+ }
137
+ }
138
+ }
139
+ }
140
+ return assets;
141
+ };
142
+ /**
143
+ * The shared ranking both roles use: aspect distance from 1:1, ties broken by larger area, then by
144
+ * higher pixel density. Aspect is a preference, never a filter — the best of a bad set still wins.
145
+ */
146
+ const rankBest = assets => {
147
+ if (!assets.length) {
148
+ return undefined;
149
+ }
150
+ let best = assets[0];
151
+ let bestDistance = aspectDistance(best);
152
+ let bestArea = (best.width || 0) * (best.height || 0);
153
+ let bestPxRatio = toPxRatio(best.variation);
154
+ for (let i = 1; i < assets.length; i++) {
155
+ const asset = assets[i];
156
+ const distance = aspectDistance(asset);
157
+ const area = (asset.width || 0) * (asset.height || 0);
158
+ const pxRatio = toPxRatio(asset.variation);
159
+ const wins = distance !== bestDistance ? distance < bestDistance : area !== bestArea ? area > bestArea : pxRatio > bestPxRatio;
160
+ if (wins) {
161
+ best = asset;
162
+ bestDistance = distance;
163
+ bestArea = area;
164
+ bestPxRatio = pxRatio;
165
+ }
166
+ }
167
+ return best;
168
+ };
169
+ /**
170
+ * Pick the image a parsed VAST ad offers for a sponsor-logo slot, or `undefined` when it offers
171
+ * none (a video-only tag, or an empty response). A caller that gets `undefined` must fall back to
172
+ * its own proto/Studio logo rather than suppressing the card.
173
+ */
174
+ const collectAssets = ad => collectAssetsFrom(ad);
175
+ const selectSponsorLogo = ad => rankBest(collectAssetsFrom(ad));
176
+ /**
177
+ * iOS `SLRVASTSlotRole.cardLogo` — the sponsor logo of a **hero card** (1:1 / 2:1 / Picture in
178
+ * Picture / Side-by-Side / Sponsor Frame). Same 1:1 aspect-dominant ranking as `.logo`, plus the
179
+ * one constraint that distinguishes the two roles:
180
+ *
181
+ * - **`requiredOrigin: .companion`.** A NonLinear image is a hero creative, never a logo. iOS's
182
+ * reason: a leftover hero-type asset — a second `<NonLinear>` overlay, or a stray image still in
183
+ * the pool after the hero role claimed its own — must never leak into the card's logo slot,
184
+ * where it would render at logo size as an unreadable smudge of the advertiser's key art.
185
+ * `nonlinear_full` is the fixture that pins it: `.logo` takes the 500x500 NonLinear, `.cardLogo`
186
+ * must take the 200x200 `<Companion>`.
187
+ * - **`exclude`** mirrors iOS's **greedy** `pool.select([hero, .cardLogo])`: roles resolve in array
188
+ * order and an asset a role claims is removed from the pool for every later role. We have no
189
+ * pool object, so the caller passes the assets the hero already claimed and they are filtered
190
+ * out here by `imageUrl`.
191
+ */
192
+ const selectCardLogo = (ad, exclude) => {
193
+ const claimed = (exclude || []).map(item => item === null || item === void 0 ? void 0 : item.imageUrl).filter(url => !!url);
194
+ return rankBest(collectAssetsFrom(ad).filter(asset => asset.origin === 'companion' && claimed.indexOf(asset.imageUrl) === -1));
195
+ };
196
+
197
+ export { collectAssets, selectCardLogo, selectSponsorLogo };
@@ -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 };
@@ -0,0 +1,140 @@
1
+ import { defineProperty as _defineProperty } from '../_virtual/_rollupPluginBabelHelpers.js';
2
+ import 'core-js/modules/es.array.iterator.js';
3
+ import 'core-js/modules/es.promise.js';
4
+ import 'core-js/modules/esnext.iterator.constructor.js';
5
+ import 'core-js/modules/esnext.iterator.for-each.js';
6
+ import 'core-js/modules/web.dom-collections.for-each.js';
7
+ import 'core-js/modules/web.dom-collections.iterator.js';
8
+ import { fireDefaultImpression, fireTrackingEvents, fireBeacon } from './ssai-providers.js';
9
+ export { DEFAULT_CREATIVE_API_BASE } from './ssai-providers.js';
10
+
11
+ /**
12
+ * Per-instance cache + impression-firing wrapper around a SsaiCreativeProvider.
13
+ * Caches resolved creatives by creativeId so repeated active-ad polls and pod
14
+ * repeats don't refetch. In-flight fetches are cancellable via AbortController.
15
+ */
16
+ class SsaiCreativeCache {
17
+ constructor(provider) {
18
+ _defineProperty(this, "provider", void 0);
19
+ _defineProperty(this, "cache", new Map());
20
+ _defineProperty(this, "inflight", new Map());
21
+ /**
22
+ * The already-resolved creative, or undefined — synchronous on purpose: a
23
+ * prefetched creative lets the ad break flip straight to 'ready' with no
24
+ * async gap (which the UI would render as a blink between two ads of a pod).
25
+ */
26
+ _defineProperty(this, "peek", creativeId => this.cache.get(creativeId));
27
+ _defineProperty(this, "resolve", creativeId => {
28
+ const cached = this.cache.get(creativeId);
29
+ if (cached) {
30
+ return Promise.resolve(cached);
31
+ }
32
+ const existing = this.inflight.get(creativeId);
33
+ if (existing) {
34
+ return existing.promise;
35
+ }
36
+ const controller = new AbortController();
37
+ const promise = this.provider.resolve(creativeId, controller.signal).then(creative => {
38
+ this.cache.set(creativeId, creative);
39
+ this.inflight.delete(creativeId);
40
+ return creative;
41
+ }).catch(error => {
42
+ this.inflight.delete(creativeId);
43
+ throw error;
44
+ });
45
+ this.inflight.set(creativeId, {
46
+ promise,
47
+ controller
48
+ });
49
+ return promise;
50
+ });
51
+ /**
52
+ * Cancel an in-flight fetch (e.g. the break ended before it resolved).
53
+ */
54
+ _defineProperty(this, "cancel", creativeId => {
55
+ const existing = this.inflight.get(creativeId);
56
+ if (existing) {
57
+ existing.controller.abort();
58
+ this.inflight.delete(creativeId);
59
+ }
60
+ });
61
+ /**
62
+ * Fire the impression for a creative. Delegates to the provider's
63
+ * `fireImpression` when present, otherwise the shared default (first
64
+ * trackingEvent named 'impression' via sendBeacon/fetch). Called once per
65
+ * visible appearance of the bar (the UI dedupes the ~250ms active-poll so a
66
+ * single continuous appearance fires exactly one impression). Each genuine pod
67
+ * insertion of the same creative is a distinct impression and re-fires.
68
+ */
69
+ _defineProperty(this, "fireImpression", creative => {
70
+ if (this.provider.fireImpression) {
71
+ this.provider.fireImpression(creative);
72
+ return;
73
+ }
74
+ fireDefaultImpression(creative);
75
+ });
76
+ /**
77
+ * Fire the impression for an already-resolved creativeId. No-op if the
78
+ * creative isn't cached yet (the bar only renders once resolved, so by the
79
+ * time the UI calls this the creative is present).
80
+ */
81
+ _defineProperty(this, "fireImpressionById", creativeId => {
82
+ const creative = this.cache.get(creativeId);
83
+ if (creative) {
84
+ this.fireImpression(creative);
85
+ }
86
+ });
87
+ /**
88
+ * Fire a lifecycle / click beacon. Delegates to the provider's `fireTracking`
89
+ * when it defines one, otherwise fires every matching `trackingEvents` URL.
90
+ */
91
+ _defineProperty(this, "fireTracking", (creative, event) => {
92
+ if (this.provider.fireTracking) {
93
+ this.provider.fireTracking(creative, event);
94
+ return;
95
+ }
96
+ fireTrackingEvents(creative, event);
97
+ });
98
+ /**
99
+ * Fire a beacon for a creativeId that may still be resolving.
100
+ *
101
+ * `start` in particular lands the instant the break opens, which is usually
102
+ * BEFORE the metadata request has come back — dropping it would silently lose
103
+ * the first beacon of every ad. Resolution is already in flight by then and
104
+ * `resolve` returns that same promise, so this attaches to it rather than
105
+ * issuing a second request. A creative that never resolves fires nothing,
106
+ * which is the correct outcome: there are no URLs to fire.
107
+ */
108
+ _defineProperty(this, "fireTrackingById", (creativeId, event) => {
109
+ const cached = this.cache.get(creativeId);
110
+ if (cached) {
111
+ this.fireTracking(cached, event);
112
+ return;
113
+ }
114
+ this.resolve(creativeId).then(creative => this.fireTracking(creative, event)).catch(() => undefined);
115
+ });
116
+ /**
117
+ * Fire the companion's `clickTracking` beacons. Separate from
118
+ * {@link fireTracking} because these live on the companion, not in
119
+ * `trackingEvents` — a provider's `fireTracking` override has no say over them.
120
+ */
121
+ _defineProperty(this, "fireCompanionClickById", creativeId => {
122
+ var _this$cache$get;
123
+ const companion = (_this$cache$get = this.cache.get(creativeId)) === null || _this$cache$get === void 0 ? void 0 : _this$cache$get.companion;
124
+ if (!companion) {
125
+ return;
126
+ }
127
+ for (const url of companion.clickTracking) {
128
+ fireBeacon(url);
129
+ }
130
+ });
131
+ _defineProperty(this, "destroy", () => {
132
+ this.inflight.forEach(entry => entry.controller.abort());
133
+ this.inflight.clear();
134
+ this.cache.clear();
135
+ });
136
+ this.provider = provider;
137
+ }
138
+ }
139
+
140
+ export { SsaiCreativeCache };