@trillboards/ads-sdk 2.0.0 → 2.1.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.
@@ -15,6 +15,7 @@ interface TrillboardsConfig {
15
15
  programmaticRetry?: number;
16
16
  programmaticBackoffMax?: number;
17
17
  cacheSize?: number;
18
+ debug?: boolean;
18
19
  }
19
20
  type WaterfallMode = 'programmatic_only' | 'programmatic_then_direct' | 'direct_only';
20
21
  interface AdItem {
@@ -15,6 +15,7 @@ interface TrillboardsConfig {
15
15
  programmaticRetry?: number;
16
16
  programmaticBackoffMax?: number;
17
17
  cacheSize?: number;
18
+ debug?: boolean;
18
19
  }
19
20
  type WaterfallMode = 'programmatic_only' | 'programmatic_then_direct' | 'direct_only';
20
21
  interface AdItem {
package/dist/react.d.mts CHANGED
@@ -16,6 +16,7 @@ interface TrillboardsConfig {
16
16
  programmaticRetry?: number;
17
17
  programmaticBackoffMax?: number;
18
18
  cacheSize?: number;
19
+ debug?: boolean;
19
20
  }
20
21
  type WaterfallMode = 'programmatic_only' | 'programmatic_then_direct' | 'direct_only';
21
22
  interface AdItem {
package/dist/react.d.ts CHANGED
@@ -16,6 +16,7 @@ interface TrillboardsConfig {
16
16
  programmaticRetry?: number;
17
17
  programmaticBackoffMax?: number;
18
18
  cacheSize?: number;
19
+ debug?: boolean;
19
20
  }
20
21
  type WaterfallMode = 'programmatic_only' | 'programmatic_then_direct' | 'direct_only';
21
22
  interface AdItem {
package/dist/react.js CHANGED
@@ -42,7 +42,8 @@ function resolveConfig(userConfig) {
42
42
  programmaticMinInterval: Math.max(userConfig.programmaticMinInterval ?? DEFAULT_CONFIG.PROGRAMMATIC_MIN_INTERVAL_MS, 1e3),
43
43
  programmaticRetry: Math.max(userConfig.programmaticRetry ?? DEFAULT_CONFIG.PROGRAMMATIC_RETRY_MS, 1e3),
44
44
  programmaticBackoffMax: Math.max(userConfig.programmaticBackoffMax ?? DEFAULT_CONFIG.PROGRAMMATIC_BACKOFF_MAX_MS, 5e3),
45
- cacheSize: Math.max(userConfig.cacheSize ?? DEFAULT_CONFIG.CACHE_SIZE, 1)
45
+ cacheSize: Math.max(userConfig.cacheSize ?? DEFAULT_CONFIG.CACHE_SIZE, 1),
46
+ debug: userConfig.debug ?? false
46
47
  };
47
48
  }
48
49
 
@@ -169,6 +170,64 @@ var EventEmitter = class {
169
170
  }
170
171
  };
171
172
 
173
+ // src/logger.ts
174
+ var LEVEL_PRIORITY = {
175
+ debug: 0,
176
+ info: 1,
177
+ warn: 2,
178
+ error: 3,
179
+ none: 4
180
+ };
181
+ var PREFIX = "[Trillboards]";
182
+ var Logger = class {
183
+ constructor() {
184
+ this.level = "none";
185
+ }
186
+ setLevel(level) {
187
+ this.level = level;
188
+ }
189
+ getLevel() {
190
+ return this.level;
191
+ }
192
+ debug(message, data) {
193
+ if (LEVEL_PRIORITY[this.level] <= LEVEL_PRIORITY.debug) {
194
+ if (data !== void 0) {
195
+ console.debug(PREFIX, message, data);
196
+ } else {
197
+ console.debug(PREFIX, message);
198
+ }
199
+ }
200
+ }
201
+ info(message, data) {
202
+ if (LEVEL_PRIORITY[this.level] <= LEVEL_PRIORITY.info) {
203
+ if (data !== void 0) {
204
+ console.info(PREFIX, message, data);
205
+ } else {
206
+ console.info(PREFIX, message);
207
+ }
208
+ }
209
+ }
210
+ warn(message, data) {
211
+ if (LEVEL_PRIORITY[this.level] <= LEVEL_PRIORITY.warn) {
212
+ if (data !== void 0) {
213
+ console.warn(PREFIX, message, data);
214
+ } else {
215
+ console.warn(PREFIX, message);
216
+ }
217
+ }
218
+ }
219
+ error(message, data) {
220
+ if (LEVEL_PRIORITY[this.level] <= LEVEL_PRIORITY.error) {
221
+ if (data !== void 0) {
222
+ console.error(PREFIX, message, data);
223
+ } else {
224
+ console.error(PREFIX, message);
225
+ }
226
+ }
227
+ }
228
+ };
229
+ var logger = new Logger();
230
+
172
231
  // src/api/client.ts
173
232
  function getPlayerTruth(container) {
174
233
  if (typeof window === "undefined") {
@@ -218,6 +277,7 @@ var ApiClient = class {
218
277
  * The request is aborted after 10 seconds.
219
278
  */
220
279
  async fetchAds(deviceId, etag = null) {
280
+ logger.debug("Fetching ads", { deviceId });
221
281
  const headers = { Accept: "application/json" };
222
282
  if (etag) headers["If-None-Match"] = etag;
223
283
  const controller = new AbortController();
@@ -252,7 +312,7 @@ var ApiClient = class {
252
312
  }
253
313
  const data = await response.json();
254
314
  const newEtag = response.headers.get("ETag");
255
- return {
315
+ const result = {
256
316
  ads: data.data?.ads ?? [],
257
317
  settings: data.data?.settings ?? {},
258
318
  programmatic: data.data?.header_bidding_settings ?? null,
@@ -262,6 +322,8 @@ var ApiClient = class {
262
322
  etag: newEtag,
263
323
  notModified: false
264
324
  };
325
+ logger.debug("Ads fetched", { deviceId, count: result.ads.length, notModified: false });
326
+ return result;
265
327
  } catch (error) {
266
328
  clearTimeout(timeoutId);
267
329
  throw error;
@@ -277,6 +339,7 @@ var ApiClient = class {
277
339
  * Returns `true` if the server acknowledged the impression.
278
340
  */
279
341
  async reportImpression(impression) {
342
+ logger.debug("Reporting impression", { adId: impression.adid, impressionId: impression.impid });
280
343
  try {
281
344
  const params = new URLSearchParams({
282
345
  adid: impression.adid,
@@ -300,6 +363,7 @@ var ApiClient = class {
300
363
  * Returns `true` on 2xx, `false` on any error.
301
364
  */
302
365
  async sendHeartbeat(deviceId, screenId) {
366
+ logger.debug("Sending heartbeat", { deviceId });
303
367
  try {
304
368
  const response = await fetch(`${this.apiBase}/device/${deviceId}/heartbeat`, {
305
369
  method: "POST",
@@ -322,6 +386,7 @@ var ApiClient = class {
322
386
  * error, etc.) to the analytics backend.
323
387
  */
324
388
  async reportProgrammaticEvent(event) {
389
+ logger.debug("Reporting programmatic event", { eventType: event.eventType });
325
390
  try {
326
391
  const response = await fetch(`${this.apiBase}/programmatic-event`, {
327
392
  method: "POST",