@surfside/ads 2.0.0 → 3.6.0-0652b02f.0

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 (88) hide show
  1. package/README.md +15 -69
  2. package/lib/cjs/BuildInfo.js +9 -0
  3. package/lib/cjs/BuildInfo.js.map +1 -0
  4. package/lib/cjs/Constants.js +5 -0
  5. package/lib/cjs/Constants.js.map +1 -0
  6. package/lib/cjs/Init.js +130 -0
  7. package/lib/cjs/Init.js.map +1 -0
  8. package/lib/cjs/components/Banner.js +136 -0
  9. package/lib/cjs/components/Banner.js.map +1 -0
  10. package/lib/cjs/components/Card.js +170 -0
  11. package/lib/cjs/components/Card.js.map +1 -0
  12. package/lib/cjs/components/Carousel.js +249 -0
  13. package/lib/cjs/components/Carousel.js.map +1 -0
  14. package/lib/cjs/components/Creative.js +285 -0
  15. package/lib/cjs/components/Creative.js.map +1 -0
  16. package/lib/cjs/components/Dynamic.js +310 -0
  17. package/lib/cjs/components/Dynamic.js.map +1 -0
  18. package/lib/cjs/components/SimpleCreative.js +81 -0
  19. package/lib/cjs/components/SimpleCreative.js.map +1 -0
  20. package/lib/cjs/components/Video.js +144 -0
  21. package/lib/cjs/components/Video.js.map +1 -0
  22. package/lib/cjs/demo/test.js +7 -0
  23. package/lib/cjs/demo/test.js.map +1 -0
  24. package/lib/cjs/index.module.js +107 -0
  25. package/lib/cjs/index.module.js.map +1 -0
  26. package/lib/cjs/index.script.js +102 -0
  27. package/lib/cjs/index.script.js.map +1 -0
  28. package/lib/cjs/index.script.mock.js +154 -0
  29. package/lib/cjs/index.script.mock.js.map +1 -0
  30. package/lib/cjs/service/Init.js +3 -0
  31. package/lib/cjs/service/Init.js.map +1 -0
  32. package/lib/cjs/util/Attributes.js +93 -0
  33. package/lib/cjs/util/Attributes.js.map +1 -0
  34. package/lib/cjs/util/Types.js +3 -0
  35. package/lib/cjs/util/Types.js.map +1 -0
  36. package/lib/esm/BuildInfo.js +6 -0
  37. package/lib/esm/BuildInfo.js.map +1 -0
  38. package/lib/esm/Constants.js +2 -0
  39. package/lib/esm/Constants.js.map +1 -0
  40. package/lib/esm/Init.js +92 -0
  41. package/lib/esm/Init.js.map +1 -0
  42. package/lib/esm/components/Banner.js +132 -0
  43. package/lib/esm/components/Banner.js.map +1 -0
  44. package/lib/esm/components/Card.js +166 -0
  45. package/lib/esm/components/Card.js.map +1 -0
  46. package/lib/esm/components/Carousel.js +245 -0
  47. package/lib/esm/components/Carousel.js.map +1 -0
  48. package/lib/esm/components/Creative.js +280 -0
  49. package/lib/esm/components/Creative.js.map +1 -0
  50. package/lib/esm/components/Dynamic.js +306 -0
  51. package/lib/esm/components/Dynamic.js.map +1 -0
  52. package/lib/esm/components/SimpleCreative.js +75 -0
  53. package/lib/esm/components/SimpleCreative.js.map +1 -0
  54. package/lib/esm/components/Video.js +140 -0
  55. package/lib/esm/components/Video.js.map +1 -0
  56. package/lib/esm/demo/test.js +5 -0
  57. package/lib/esm/demo/test.js.map +1 -0
  58. package/lib/esm/index.module.js +67 -0
  59. package/lib/esm/index.module.js.map +1 -0
  60. package/lib/esm/index.script.js +100 -0
  61. package/lib/esm/index.script.js.map +1 -0
  62. package/lib/esm/index.script.mock.js +152 -0
  63. package/lib/esm/index.script.mock.js.map +1 -0
  64. package/lib/esm/service/Init.js +2 -0
  65. package/lib/esm/service/Init.js.map +1 -0
  66. package/lib/esm/util/Attributes.js +81 -0
  67. package/lib/esm/util/Attributes.js.map +1 -0
  68. package/lib/esm/util/Types.js +2 -0
  69. package/lib/esm/util/Types.js.map +1 -0
  70. package/lib/types/BuildInfo.d.ts +5 -0
  71. package/lib/types/Constants.d.ts +1 -0
  72. package/lib/types/Init.d.ts +31 -0
  73. package/lib/types/components/Banner.d.ts +17 -0
  74. package/lib/types/components/Card.d.ts +18 -0
  75. package/lib/types/components/Carousel.d.ts +32 -0
  76. package/lib/types/components/Creative.d.ts +84 -0
  77. package/lib/types/components/Dynamic.d.ts +24 -0
  78. package/lib/types/components/SimpleCreative.d.ts +20 -0
  79. package/lib/types/components/Video.d.ts +23 -0
  80. package/lib/types/demo/test.d.ts +1 -0
  81. package/lib/types/index.module.d.ts +12 -0
  82. package/lib/types/index.script.d.ts +1 -0
  83. package/lib/types/index.script.mock.d.ts +1 -0
  84. package/lib/types/service/Init.d.ts +1 -0
  85. package/lib/types/util/Attributes.d.ts +24 -0
  86. package/lib/types/util/Types.d.ts +3 -0
  87. package/package.json +42 -73
  88. package/lib/index.js +0 -2
@@ -0,0 +1,310 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SurfsideDynamicZone = void 0;
4
+ const ads_core_1 = require("@surfside/ads-core");
5
+ const Constants_1 = require("../Constants");
6
+ const Creative_1 = require("./Creative");
7
+ const Carousel_1 = require("./Carousel");
8
+ const SimpleCreative_1 = require("./SimpleCreative");
9
+ class SurfsideDynamicZone extends Creative_1.CreativeComponent {
10
+ _cancellationToken = new ads_core_1.CancellationToken();
11
+ maxItems;
12
+ cardMinWidth = Constants_1.DefaultMinCardWidth;
13
+ strategy;
14
+ recommend;
15
+ nextType;
16
+ _bounce;
17
+ getComponentName() {
18
+ return 'SurfsideDynamicZone';
19
+ }
20
+ static get observedAttributes() {
21
+ return [
22
+ ...Creative_1.CreativeComponent.observedBaseAttributes,
23
+ 'max-items',
24
+ 'card-min-width',
25
+ 'next-type'
26
+ ];
27
+ }
28
+ async attributeChangedCallback(name, oldValue, newValue) {
29
+ const log = this.log?.with('attributeChangedCallback');
30
+ log?.info('Carousel attribute changed');
31
+ switch (name) {
32
+ case 'max-items': {
33
+ try {
34
+ this.maxItems = (0, SimpleCreative_1.IntValOrThrow)(this, 'max-items', newValue);
35
+ }
36
+ catch (err) {
37
+ log?.warn('Failed to parse. Got', err);
38
+ }
39
+ break;
40
+ }
41
+ case 'card-min-width': {
42
+ try {
43
+ this.cardMinWidth = (0, SimpleCreative_1.IntValOrThrow)(this, 'card-min-width', newValue);
44
+ }
45
+ catch (err) {
46
+ log?.warn('Failed to parse. Got', err);
47
+ }
48
+ break;
49
+ }
50
+ case 'strategy': {
51
+ const strategy = newValue?.toLowerCase();
52
+ switch (strategy) {
53
+ case Creative_1.ProductFeedStrategy.Sponsored:
54
+ case Creative_1.ProductFeedStrategy.Hybrid:
55
+ case Creative_1.ProductFeedStrategy.Recommended:
56
+ this.strategy = strategy;
57
+ break;
58
+ default:
59
+ log?.warn('Unrecognized or null strategy:', newValue);
60
+ break;
61
+ }
62
+ break;
63
+ }
64
+ case 'recommend': {
65
+ const recommend = newValue?.toLowerCase();
66
+ switch (recommend) {
67
+ case Creative_1.RecommenderTypeInputs.TopProducts:
68
+ this.recommend = 'top-products';
69
+ break;
70
+ case Creative_1.RecommenderTypeInputs.ForYou:
71
+ this.recommend = 'for-you';
72
+ break;
73
+ case Creative_1.RecommenderTypeInputs.PastPurchases:
74
+ case Creative_1.RecommenderTypeInputs.BuyAgain:
75
+ this.recommend = 'past-purchases';
76
+ break;
77
+ default:
78
+ log?.warn('Unrecognized or null recommender type:', newValue);
79
+ break;
80
+ }
81
+ break;
82
+ }
83
+ case 'next-type': {
84
+ const nextType = newValue?.toLowerCase();
85
+ switch (nextType) {
86
+ case Carousel_1.NextType.Page:
87
+ case Carousel_1.NextType.Product:
88
+ this.nextType = nextType;
89
+ break;
90
+ default:
91
+ log?.warn('Unrecognized or null next-type:', newValue);
92
+ break;
93
+ }
94
+ break;
95
+ }
96
+ default: {
97
+ const baseName = name;
98
+ if (Creative_1.CreativeComponent.observedBaseAttributes.includes(baseName)) {
99
+ await super.baseAttributeChangedCallback(baseName, oldValue, newValue, log);
100
+ }
101
+ break;
102
+ }
103
+ }
104
+ const totem = crypto.randomUUID();
105
+ this.totem = totem;
106
+ if (!this.attributesLoaded()) {
107
+ log?.debug('Attributes not ready yet...', this.accountId);
108
+ return;
109
+ }
110
+ else {
111
+ log?.debug('Attributes ready!');
112
+ }
113
+ await this.lazyLoadApi();
114
+ if (this.totem !== totem) {
115
+ log?.debug('Totem changed in between attribute callbacks. Waiting for final attribue to render dynamic');
116
+ return;
117
+ }
118
+ if (this._bounce !== undefined) {
119
+ globalThis.clearTimeout(this._bounce);
120
+ }
121
+ this._bounce = globalThis.setTimeout(() => this.render(), Creative_1.DEBOUNCE_THRESHOLD);
122
+ }
123
+ disconnectedCallback() {
124
+ super.disconnectedCallback();
125
+ this._cancellationToken.cancel();
126
+ if (this._bounce !== undefined) {
127
+ globalThis.clearTimeout(this._bounce);
128
+ this._bounce = undefined;
129
+ }
130
+ }
131
+ async render() {
132
+ const log = this.log?.with('SurfsideDynamicZone', { zoneId: this.zoneId });
133
+ log?.info('Rendering Dynamic Zone', this.api);
134
+ const stopTimer = log?.time?.('render dynamic zone');
135
+ this._cancellationToken.cancel();
136
+ this.clearReauction();
137
+ const token = new ads_core_1.CancellationToken();
138
+ this._cancellationToken = token;
139
+ const { getDynamicZone, buildDynamicZoneRequest } = this.api;
140
+ const dynamicZoneRes = await getDynamicZone(this.zoneId);
141
+ if (this._cancellationToken.cancelled === true) {
142
+ log?.error('Dynamic zone request was cancelled');
143
+ return;
144
+ }
145
+ else if (!dynamicZoneRes.ok) {
146
+ log?.error('Dynamic zone failed to load', dynamicZoneRes.error);
147
+ return;
148
+ }
149
+ const dynamicZone = dynamicZoneRes.value;
150
+ const dynamicZoneRequestRes = buildDynamicZoneRequest(this.zoneId, dynamicZone, this.category);
151
+ if (!dynamicZoneRequestRes.ok) {
152
+ log?.error('Failed to build dynamic zone request', dynamicZoneRequestRes.error);
153
+ return;
154
+ }
155
+ const dynamicZoneRequest = dynamicZoneRequestRes.value;
156
+ await this.requestAndRender(dynamicZoneRequest);
157
+ stopTimer?.();
158
+ }
159
+ async requestAndRender(dynamicZoneRequest) {
160
+ const { buildDynamicResponse, renderBanner, renderVideo, renderCarousel, renderProductCard } = this.api;
161
+ const log = this.log?.with('SurfsideDynamicZone', { zoneId: this.zoneId });
162
+ const dynamicResponseRes = await buildDynamicResponse(dynamicZoneRequest);
163
+ // Have to cast too boolean here because typescript is too stupid to understand that
164
+ // cancellationtoken can be mutated between async calls and is trying to narrow the type to false
165
+ // based on the last cancellation check
166
+ if (this._cancellationToken.cancelled === true) {
167
+ log?.error('Dynamic zone request was cancelled');
168
+ return;
169
+ }
170
+ else if (!dynamicResponseRes.ok) {
171
+ log?.error('Dynamic response failed', dynamicResponseRes);
172
+ return;
173
+ }
174
+ const dynamicResponse = dynamicResponseRes.value;
175
+ const finalRender = (element, reauctionEnabled) => {
176
+ this.shadow.innerHTML = '';
177
+ this.shadow.appendChild(element);
178
+ if (this.api.configuration.settings.reauctionEnabled && reauctionEnabled) {
179
+ switch (dynamicResponse.type) {
180
+ case 'banner': {
181
+ log?.info('Attempting re-auction for banner...');
182
+ this.scheduleReauction(() => {
183
+ log?.info('Re-auctioning banner...');
184
+ const bannerImp = dynamicZoneRequest.request.imp.find(i => i.banner !== undefined);
185
+ if (bannerImp === undefined) {
186
+ log?.error('Failed to find original banner request for re-auction');
187
+ return;
188
+ }
189
+ const partialRequest = {
190
+ requestIds: dynamicZoneRequest.requestIds,
191
+ request: {
192
+ ...dynamicZoneRequest.request,
193
+ id: crypto.randomUUID(),
194
+ imp: [{
195
+ ...bannerImp,
196
+ id: crypto.randomUUID(),
197
+ banner: {
198
+ ...bannerImp.banner,
199
+ w: dynamicResponse.dynamicBannerRequest.width,
200
+ h: dynamicResponse.dynamicBannerRequest.height,
201
+ format: [{
202
+ w: dynamicResponse.dynamicBannerRequest.width,
203
+ h: dynamicResponse.dynamicBannerRequest.height
204
+ }]
205
+ }
206
+ }]
207
+ }
208
+ };
209
+ log?.info('sending re-auction', partialRequest);
210
+ this.requestAndRender(partialRequest);
211
+ }, Math.max(this.api.configuration.settings.reauctionIntervalMs, 10_000));
212
+ break;
213
+ }
214
+ case 'video': {
215
+ log?.info('Attempting re-auction for video...');
216
+ const video = element.shadowRoot?.querySelector('video');
217
+ if (video === null || video === undefined) {
218
+ log?.error('Failed to find video element for re-auction in dynamic zone!');
219
+ return;
220
+ }
221
+ log?.info('Re-auctioning video...');
222
+ // Deferred until the page regains focus if blurred
223
+ video.addEventListener('ended', () => this.scheduleReauction(() => {
224
+ log?.info('video ended');
225
+ const videoImp = dynamicZoneRequest.request.imp.find(i => i.video !== undefined);
226
+ if (videoImp === undefined) {
227
+ log?.error('Failed to find original banner request for re-auction');
228
+ return;
229
+ }
230
+ const partialRequest = {
231
+ requestIds: dynamicZoneRequest.requestIds,
232
+ request: {
233
+ ...dynamicZoneRequest.request,
234
+ id: crypto.randomUUID(),
235
+ imp: [{
236
+ ...videoImp,
237
+ id: crypto.randomUUID(),
238
+ video: {
239
+ ...videoImp.video,
240
+ w: dynamicResponse.dynamicVideoRequest.width,
241
+ h: dynamicResponse.dynamicVideoRequest.height,
242
+ minduration: dynamicResponse.dynamicVideoRequest.minDuration,
243
+ maxduration: dynamicResponse.dynamicVideoRequest.maxDuration
244
+ }
245
+ }]
246
+ }
247
+ };
248
+ log?.info('Sending re-auction for video', partialRequest);
249
+ this.requestAndRender(partialRequest);
250
+ }, 0));
251
+ }
252
+ }
253
+ }
254
+ return (0, ads_core_1.Ok)(true);
255
+ };
256
+ switch (dynamicResponse.type) {
257
+ case 'banner': {
258
+ log?.info('Banner response', dynamicResponse);
259
+ const reauctionEnabled = dynamicResponse.bid.ext?.takeover !== true;
260
+ const result = (0, ads_core_1.Pipe)(renderBanner(dynamicResponse))
261
+ .then(r => finalRender(r, reauctionEnabled))
262
+ .result();
263
+ if (!result.ok) {
264
+ log?.error('Failed to render banner', result.error);
265
+ }
266
+ break;
267
+ }
268
+ case 'video': {
269
+ const reauction = dynamicResponse.bid.ext?.takeover !== true;
270
+ const result = (0, ads_core_1.Pipe)(renderVideo(dynamicResponse))
271
+ .then(r => finalRender(r, reauction))
272
+ .result();
273
+ if (!result.ok) {
274
+ log?.error('Failed to render video', result.error);
275
+ }
276
+ break;
277
+ }
278
+ case 'carousel': {
279
+ const request = dynamicResponse.dynamicCarouselRequest;
280
+ const maxItems = this.maxItems ?? request.maxItems;
281
+ const cardMinWidth = this.cardMinWidth ?? request.cardMinWidth;
282
+ const nextType = this.nextType ?? request.nextType;
283
+ const result = await renderCarousel(dynamicResponse, cardMinWidth, maxItems === undefined
284
+ ? { type: 'infinite' }
285
+ : { type: 'limited', limit: maxItems }, nextType);
286
+ if (!result.ok) {
287
+ log?.error('Failed to render carousel', result.error);
288
+ break;
289
+ }
290
+ finalRender(result.value.element, false);
291
+ result.value.init();
292
+ break;
293
+ }
294
+ case 'product-card': {
295
+ const result = (0, ads_core_1.Pipe)(renderProductCard(dynamicResponse))
296
+ .then(r => finalRender(r, false))
297
+ .result();
298
+ if (!result.ok) {
299
+ log?.error('Failed to render product card', result.error);
300
+ }
301
+ break;
302
+ }
303
+ default:
304
+ log?.error('Invalid creative type returned from dynamic zone', dynamicResponse);
305
+ break;
306
+ }
307
+ }
308
+ }
309
+ exports.SurfsideDynamicZone = SurfsideDynamicZone;
310
+ //# sourceMappingURL=Dynamic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Dynamic.js","sourceRoot":"../@surfside-ads/","sources":["components/Dynamic.ts"],"names":[],"mappings":";;;AAAA,iDAO4B;AAC5B,4CAAmD;AACnD,yCAOoB;AACpB,yCAAsC;AACtC,qDAAiD;AAUjD,MAAa,mBAAoB,SAAQ,4BAAiB;IAC9C,kBAAkB,GAAsB,IAAI,4BAAiB,EAAE,CAAC;IAE9D,QAAQ,CAAU;IAClB,YAAY,GAAY,+BAAmB,CAAC;IAE5C,QAAQ,CAAU;IAClB,SAAS,CAAmB;IAC5B,QAAQ,CAAsB;IAEhC,OAAO,CAAwB;IAE7B,gBAAgB;QACtB,OAAO,qBAAqB,CAAC;IACjC,CAAC;IAEM,MAAM,KAAK,kBAAkB;QAChC,OAAO;YACH,GAAG,4BAAiB,CAAC,sBAAsB;YAC3C,WAAW;YACX,gBAAgB;YAChB,WAAW;SACd,CAAC;IACN,CAAC;IAEM,KAAK,CAAC,wBAAwB,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MAAM;YACV,CAAC;YACD;gBACI,GAAG,EAAE,KAAK,CAAC,kDAAkD,EAAE,eAAe,CAAC,CAAC;gBAChF,MAAM;QACd,CAAC;IACL,CAAC;CACJ;AA5UD,kDA4UC"}
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SimpleCreativeComponent = exports.IntValOr = exports.IntValOrThrow = void 0;
4
+ const Creative_1 = require("./Creative");
5
+ const Attributes_1 = require("../util/Attributes");
6
+ const ads_core_1 = require("@surfside/ads-core");
7
+ const NumberValOrThrow = (element, attribute, value) => {
8
+ const strValue = (0, Creative_1.AttributeValOrThrow)(element, attribute, value);
9
+ const numValue = Number(strValue);
10
+ if (Number.isNaN(numValue)) {
11
+ throw new Attributes_1.AttributeNotANumberError(element, attribute);
12
+ }
13
+ return numValue;
14
+ };
15
+ const IntValOrThrow = (element, attribute, value) => {
16
+ const numValue = NumberValOrThrow(element, attribute, value);
17
+ if (!Number.isInteger(numValue)) {
18
+ throw new Attributes_1.AttributeNotIntError(element, attribute);
19
+ }
20
+ return numValue;
21
+ };
22
+ exports.IntValOrThrow = IntValOrThrow;
23
+ const IntValOr = (element, attribute, value, or) => {
24
+ try {
25
+ return (0, exports.IntValOrThrow)(element, attribute, value);
26
+ }
27
+ catch {
28
+ return or;
29
+ }
30
+ };
31
+ exports.IntValOr = IntValOr;
32
+ class SimpleCreativeComponent extends Creative_1.CreativeComponent {
33
+ width;
34
+ height;
35
+ constructor(initApi, getUserId, logger) {
36
+ super(initApi, getUserId, logger);
37
+ }
38
+ attributesLoaded() {
39
+ return (super.attributesLoaded() &&
40
+ this.width !== undefined &&
41
+ this.height !== undefined &&
42
+ this.width !== null &&
43
+ this.height !== null);
44
+ }
45
+ static get observedSimpleAttributes() {
46
+ return [...Creative_1.CreativeComponent.observedBaseAttributes, 'width', 'height'];
47
+ }
48
+ async handleSimpleAttributeChange(name, oldValue, newValue, logger) {
49
+ const changed = this.simpleAttributeChangedCallback(name, oldValue, newValue, logger);
50
+ if (this.api !== undefined) {
51
+ await changed;
52
+ }
53
+ }
54
+ async simpleAttributeChangedCallback(name, oldValue, newValue, logger) {
55
+ const log = logger?.with('simpleAttributeChangedCallback');
56
+ log?.info('Simple attribute changed: ', name);
57
+ if (Creative_1.CreativeComponent.observedBaseAttributes.includes(name)) {
58
+ log?.info('Base attribute changed');
59
+ const key = name;
60
+ await this.baseAttributeChangedCallback(key, oldValue, newValue, log);
61
+ return;
62
+ }
63
+ if (name === 'width' || name === 'height') {
64
+ log?.debug('Before: width', this.width, 'height', this.height);
65
+ try {
66
+ this[name] = (0, exports.IntValOrThrow)(this, name, newValue);
67
+ }
68
+ catch (error) {
69
+ log?.warn('Couldn\'t parse number attribute', error);
70
+ }
71
+ log?.debug('After: width', this.width, 'height', this.height);
72
+ }
73
+ }
74
+ readSimpleAttributes() {
75
+ this.readBaseAttributes();
76
+ this.width = (0, ads_core_1.GetValue)((0, Attributes_1.ReadIntAttribute)(this, 'width')) ?? this.width;
77
+ this.height = (0, ads_core_1.GetValue)((0, Attributes_1.ReadIntAttribute)(this, 'height')) ?? this.height;
78
+ }
79
+ }
80
+ exports.SimpleCreativeComponent = SimpleCreativeComponent;
81
+ //# sourceMappingURL=SimpleCreative.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SimpleCreative.js","sourceRoot":"../@surfside-ads/","sources":["components/SimpleCreative.ts"],"names":[],"mappings":";;;AAAA,yCAMoB;AACpB,mDAAsG;AAEtG,iDAAiF;AASjF,MAAM,gBAAgB,GAAG,CAAC,OAAgB,EAAE,SAAiB,EAAE,KAAoB,EAAE,EAAE;IACnF,MAAM,QAAQ,GAAG,IAAA,8BAAmB,EAAC,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;IAChE,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IAClC,IAAI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;QACzB,MA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kC,EAAE,KAAK,CAAC,CAAC;YACzD,CAAC;YACD,GAAG,EAAE,KAAK,CAAC,cAAc,EAAE,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAClE,CAAC;IACL,CAAC;IAEM,oBAAoB;QACvB,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAC1B,IAAI,CAAC,KAAK,GAAG,IAAA,mBAAQ,EAAC,IAAA,6BAAgB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC;QACrE,IAAI,CAAC,MAAM,GAAG,IAAA,mBAAQ,EAAC,IAAA,6BAAgB,EAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC;IAC5E,CAAC;CACJ;AApED,0DAoEC"}
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SurfsideVideo = void 0;
4
+ const ads_core_1 = require("@surfside/ads-core");
5
+ const SimpleCreative_1 = require("./SimpleCreative");
6
+ const Creative_1 = require("./Creative");
7
+ class SurfsideVideo extends SimpleCreative_1.SimpleCreativeComponent {
8
+ _cancellationToken = new ads_core_1.CancellationToken();
9
+ minDuration;
10
+ maxDuration;
11
+ _bounce;
12
+ static get observedAttributes() {
13
+ return [...SimpleCreative_1.SimpleCreativeComponent.observedSimpleAttributes, 'min-duration', 'max-duration'];
14
+ }
15
+ constructor(initApi, getUserId, logger) {
16
+ super(initApi, getUserId, logger);
17
+ }
18
+ getComponentName() {
19
+ return 'SurfsideVideo';
20
+ }
21
+ attributesLoaded() {
22
+ return (super.attributesLoaded() && this.minDuration !== undefined && this.maxDuration !== undefined
23
+ && this.minDuration !== null && this.maxDuration !== null);
24
+ }
25
+ async attributeChangedCallback(name, oldValue, newValue) {
26
+ const log = this.log?.with('attributeChangedCallback');
27
+ log?.info('Attribute changed');
28
+ if (name === 'min-duration') {
29
+ try {
30
+ this.minDuration = (0, SimpleCreative_1.IntValOrThrow)(this, 'min-duration', newValue);
31
+ }
32
+ catch (err) {
33
+ log?.warn('Couldn\'t parse min-duration', err);
34
+ }
35
+ }
36
+ else if (name === 'max-duration') {
37
+ try {
38
+ this.maxDuration = (0, SimpleCreative_1.IntValOrThrow)(this, 'max-duration', newValue);
39
+ }
40
+ catch (err) {
41
+ log?.warn('Couldn\'t parse min-duration', err);
42
+ }
43
+ }
44
+ else {
45
+ await this.handleSimpleAttributeChange(name, oldValue, newValue, log);
46
+ }
47
+ const totem = crypto.randomUUID();
48
+ this.totem = totem;
49
+ log?.debug(name, 'totem', totem);
50
+ if (!this.attributesLoaded()) {
51
+ log?.debug('Attributes not ready yet...');
52
+ return;
53
+ }
54
+ if (this.totem !== totem) {
55
+ log?.debug('Totem changed. Deferring rendering of video until last attribute changed', totem, this.totem);
56
+ return;
57
+ }
58
+ log?.debug(`Rendering video upon change of [${name}]`);
59
+ if (this._bounce !== undefined) {
60
+ globalThis.clearTimeout(this._bounce);
61
+ }
62
+ this._bounce = globalThis.setTimeout(() => this.render(), Creative_1.DEBOUNCE_THRESHOLD);
63
+ }
64
+ readVideoAttributes() {
65
+ this.readSimpleAttributes();
66
+ }
67
+ async connectedCallback() {
68
+ super.connectedCallback();
69
+ this.readVideoAttributes();
70
+ await this.initApi();
71
+ const totem = crypto.randomUUID();
72
+ this.totem = totem;
73
+ if (this.attributesLoaded()) {
74
+ await this.lazyLoadApi();
75
+ if (this.totem !== totem) {
76
+ this.log?.debug('Attributes changed after connectedCallback, waiting to render');
77
+ return;
78
+ }
79
+ this.log?.debug('Rendering upon connectedCallback');
80
+ await this.render();
81
+ }
82
+ else {
83
+ this.log?.warn('ConnectedCallback called before attributes were all ready.');
84
+ }
85
+ }
86
+ disconnectedCallback() {
87
+ super.disconnectedCallback();
88
+ this._cancellationToken.cancel();
89
+ if (this._bounce !== undefined) {
90
+ globalThis.clearTimeout(this._bounce);
91
+ this._bounce = undefined;
92
+ }
93
+ }
94
+ async render() {
95
+ const log = this.log?.with('SurfsideVideo', { zoneId: this.zoneId });
96
+ log?.info('rendering');
97
+ log?.debug('width', this.width, 'height', this.height);
98
+ const stopTimer = log?.time?.('render video');
99
+ this._cancellationToken.cancel();
100
+ this.clearReauction();
101
+ const token = new ads_core_1.CancellationToken();
102
+ this._cancellationToken = token;
103
+ const { requestBids, startRequest, buildVideoResponse, renderVideo } = this.api;
104
+ const bidResponseResult = await requestBids(startRequest(this.zoneId)
105
+ .withSurfCategory(this.category)
106
+ .withKeywords(this.keywords)
107
+ .withVideo(this.width, this.height, this.minDuration, this.maxDuration)
108
+ .build());
109
+ if (token.cancelled) {
110
+ return;
111
+ }
112
+ if (!bidResponseResult.ok) {
113
+ log?.warn('Did not get any bid responses', bidResponseResult.error);
114
+ return;
115
+ }
116
+ const bid = bidResponseResult.value.seatbid?.[0]?.bid?.[0];
117
+ if (bid === undefined) {
118
+ log?.error('Got a bid response, but it was malformed', bidResponseResult);
119
+ return;
120
+ }
121
+ const responseResult = buildVideoResponse(bid);
122
+ if (!responseResult.ok) {
123
+ log?.error(responseResult.error);
124
+ return;
125
+ }
126
+ const elementResult = renderVideo(responseResult.value);
127
+ if (!elementResult.ok) {
128
+ log?.error(elementResult.error);
129
+ return;
130
+ }
131
+ if (!token.cancelled) {
132
+ stopTimer?.();
133
+ this.shadow.innerHTML = '';
134
+ this.shadow.appendChild(elementResult.value);
135
+ elementResult.value.classList.add(`surf-zone-${this.zoneId}`);
136
+ if (this.api.configuration.settings.reauctionEnabled && bid.ext?.takeover !== true) {
137
+ // Re-auction once the video ends. Deferred until the page regains focus if blurred
138
+ elementResult.value.onended = () => this.scheduleReauction(() => this.render(), 0);
139
+ }
140
+ }
141
+ }
142
+ }
143
+ exports.SurfsideVideo = SurfsideVideo;
144
+ //# sourceMappingURL=Video.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Video.js","sourceRoot":"../@surfside-ads/","sources":["components/Video.ts"],"names":[],"mappings":";;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AAI,CAAC,cAAc,CAAC,EAAE,EAAE,CAAC;YACrB,GAAG,EAAE,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;YACjC,OAAO;QACX,CAAC;QAED,MAAM,aAAa,GAAG,WAAW,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QACxD,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC;YACpB,GAAG,EAAE,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;YAChC,OAAO;QACX,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;YACnB,SAAS,EAAE,EAAE,CAAC;YACd,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,EAAE,CAAC;YAC3B,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;YAC7C,aAAa,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,aAAa,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;YAC9D,IAAI,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,QAAQ,CAAC,gBAAgB,IAAI,GAAG,CAAC,GAAG,EAAE,QAAQ,KAAK,IAAI,EAAE,CAAC;gBACjF,mFAAmF;gBACnF,aAAa,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC;YACvF,CAAC;QACL,CAAC;IACL,CAAC;CACJ;AA7KD,sCA6KC"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const index_module_1 = require("../index.module");
4
+ window.onload = () => {
5
+ (0, index_module_1.InitSurfAdsWebComponents)();
6
+ };
7
+ //# sourceMappingURL=test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.js","sourceRoot":"../@surfside-ads/","sources":["demo/test.ts"],"names":[],"mappings":";;AAAA,kDAA2D;AAE3D,MAAM,CAAC,MAAM,GAAG,GAAG,EAAE;IACjB,IAAA,uCAAwB,GAAE,CAAC;AAC/B,CAAC,CAAA"}