@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,142 @@
1
+ 'use strict';
2
+
3
+ var _rollupPluginBabelHelpers = require('../_virtual/_rollupPluginBabelHelpers.js');
4
+ require('core-js/modules/es.array.iterator.js');
5
+ require('core-js/modules/es.promise.js');
6
+ require('core-js/modules/esnext.iterator.constructor.js');
7
+ require('core-js/modules/esnext.iterator.for-each.js');
8
+ require('core-js/modules/web.dom-collections.for-each.js');
9
+ require('core-js/modules/web.dom-collections.iterator.js');
10
+ var ssaiProviders = require('./ssai-providers.js');
11
+
12
+ /**
13
+ * Per-instance cache + impression-firing wrapper around a SsaiCreativeProvider.
14
+ * Caches resolved creatives by creativeId so repeated active-ad polls and pod
15
+ * repeats don't refetch. In-flight fetches are cancellable via AbortController.
16
+ */
17
+ class SsaiCreativeCache {
18
+ constructor(provider) {
19
+ _rollupPluginBabelHelpers.defineProperty(this, "provider", void 0);
20
+ _rollupPluginBabelHelpers.defineProperty(this, "cache", new Map());
21
+ _rollupPluginBabelHelpers.defineProperty(this, "inflight", new Map());
22
+ /**
23
+ * The already-resolved creative, or undefined — synchronous on purpose: a
24
+ * prefetched creative lets the ad break flip straight to 'ready' with no
25
+ * async gap (which the UI would render as a blink between two ads of a pod).
26
+ */
27
+ _rollupPluginBabelHelpers.defineProperty(this, "peek", creativeId => this.cache.get(creativeId));
28
+ _rollupPluginBabelHelpers.defineProperty(this, "resolve", creativeId => {
29
+ const cached = this.cache.get(creativeId);
30
+ if (cached) {
31
+ return Promise.resolve(cached);
32
+ }
33
+ const existing = this.inflight.get(creativeId);
34
+ if (existing) {
35
+ return existing.promise;
36
+ }
37
+ const controller = new AbortController();
38
+ const promise = this.provider.resolve(creativeId, controller.signal).then(creative => {
39
+ this.cache.set(creativeId, creative);
40
+ this.inflight.delete(creativeId);
41
+ return creative;
42
+ }).catch(error => {
43
+ this.inflight.delete(creativeId);
44
+ throw error;
45
+ });
46
+ this.inflight.set(creativeId, {
47
+ promise,
48
+ controller
49
+ });
50
+ return promise;
51
+ });
52
+ /**
53
+ * Cancel an in-flight fetch (e.g. the break ended before it resolved).
54
+ */
55
+ _rollupPluginBabelHelpers.defineProperty(this, "cancel", creativeId => {
56
+ const existing = this.inflight.get(creativeId);
57
+ if (existing) {
58
+ existing.controller.abort();
59
+ this.inflight.delete(creativeId);
60
+ }
61
+ });
62
+ /**
63
+ * Fire the impression for a creative. Delegates to the provider's
64
+ * `fireImpression` when present, otherwise the shared default (first
65
+ * trackingEvent named 'impression' via sendBeacon/fetch). Called once per
66
+ * visible appearance of the bar (the UI dedupes the ~250ms active-poll so a
67
+ * single continuous appearance fires exactly one impression). Each genuine pod
68
+ * insertion of the same creative is a distinct impression and re-fires.
69
+ */
70
+ _rollupPluginBabelHelpers.defineProperty(this, "fireImpression", creative => {
71
+ if (this.provider.fireImpression) {
72
+ this.provider.fireImpression(creative);
73
+ return;
74
+ }
75
+ ssaiProviders.fireDefaultImpression(creative);
76
+ });
77
+ /**
78
+ * Fire the impression for an already-resolved creativeId. No-op if the
79
+ * creative isn't cached yet (the bar only renders once resolved, so by the
80
+ * time the UI calls this the creative is present).
81
+ */
82
+ _rollupPluginBabelHelpers.defineProperty(this, "fireImpressionById", creativeId => {
83
+ const creative = this.cache.get(creativeId);
84
+ if (creative) {
85
+ this.fireImpression(creative);
86
+ }
87
+ });
88
+ /**
89
+ * Fire a lifecycle / click beacon. Delegates to the provider's `fireTracking`
90
+ * when it defines one, otherwise fires every matching `trackingEvents` URL.
91
+ */
92
+ _rollupPluginBabelHelpers.defineProperty(this, "fireTracking", (creative, event) => {
93
+ if (this.provider.fireTracking) {
94
+ this.provider.fireTracking(creative, event);
95
+ return;
96
+ }
97
+ ssaiProviders.fireTrackingEvents(creative, event);
98
+ });
99
+ /**
100
+ * Fire a beacon for a creativeId that may still be resolving.
101
+ *
102
+ * `start` in particular lands the instant the break opens, which is usually
103
+ * BEFORE the metadata request has come back — dropping it would silently lose
104
+ * the first beacon of every ad. Resolution is already in flight by then and
105
+ * `resolve` returns that same promise, so this attaches to it rather than
106
+ * issuing a second request. A creative that never resolves fires nothing,
107
+ * which is the correct outcome: there are no URLs to fire.
108
+ */
109
+ _rollupPluginBabelHelpers.defineProperty(this, "fireTrackingById", (creativeId, event) => {
110
+ const cached = this.cache.get(creativeId);
111
+ if (cached) {
112
+ this.fireTracking(cached, event);
113
+ return;
114
+ }
115
+ this.resolve(creativeId).then(creative => this.fireTracking(creative, event)).catch(() => undefined);
116
+ });
117
+ /**
118
+ * Fire the companion's `clickTracking` beacons. Separate from
119
+ * {@link fireTracking} because these live on the companion, not in
120
+ * `trackingEvents` — a provider's `fireTracking` override has no say over them.
121
+ */
122
+ _rollupPluginBabelHelpers.defineProperty(this, "fireCompanionClickById", creativeId => {
123
+ var _this$cache$get;
124
+ const companion = (_this$cache$get = this.cache.get(creativeId)) === null || _this$cache$get === void 0 ? void 0 : _this$cache$get.companion;
125
+ if (!companion) {
126
+ return;
127
+ }
128
+ for (const url of companion.clickTracking) {
129
+ ssaiProviders.fireBeacon(url);
130
+ }
131
+ });
132
+ _rollupPluginBabelHelpers.defineProperty(this, "destroy", () => {
133
+ this.inflight.forEach(entry => entry.controller.abort());
134
+ this.inflight.clear();
135
+ this.cache.clear();
136
+ });
137
+ this.provider = provider;
138
+ }
139
+ }
140
+
141
+ exports.DEFAULT_CREATIVE_API_BASE = ssaiProviders.DEFAULT_CREATIVE_API_BASE;
142
+ exports.SsaiCreativeCache = SsaiCreativeCache;