@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.
package/dist/react.mjs CHANGED
@@ -40,7 +40,8 @@ function resolveConfig(userConfig) {
40
40
  programmaticMinInterval: Math.max(userConfig.programmaticMinInterval ?? DEFAULT_CONFIG.PROGRAMMATIC_MIN_INTERVAL_MS, 1e3),
41
41
  programmaticRetry: Math.max(userConfig.programmaticRetry ?? DEFAULT_CONFIG.PROGRAMMATIC_RETRY_MS, 1e3),
42
42
  programmaticBackoffMax: Math.max(userConfig.programmaticBackoffMax ?? DEFAULT_CONFIG.PROGRAMMATIC_BACKOFF_MAX_MS, 5e3),
43
- cacheSize: Math.max(userConfig.cacheSize ?? DEFAULT_CONFIG.CACHE_SIZE, 1)
43
+ cacheSize: Math.max(userConfig.cacheSize ?? DEFAULT_CONFIG.CACHE_SIZE, 1),
44
+ debug: userConfig.debug ?? false
44
45
  };
45
46
  }
46
47
 
@@ -167,6 +168,64 @@ var EventEmitter = class {
167
168
  }
168
169
  };
169
170
 
171
+ // src/logger.ts
172
+ var LEVEL_PRIORITY = {
173
+ debug: 0,
174
+ info: 1,
175
+ warn: 2,
176
+ error: 3,
177
+ none: 4
178
+ };
179
+ var PREFIX = "[Trillboards]";
180
+ var Logger = class {
181
+ constructor() {
182
+ this.level = "none";
183
+ }
184
+ setLevel(level) {
185
+ this.level = level;
186
+ }
187
+ getLevel() {
188
+ return this.level;
189
+ }
190
+ debug(message, data) {
191
+ if (LEVEL_PRIORITY[this.level] <= LEVEL_PRIORITY.debug) {
192
+ if (data !== void 0) {
193
+ console.debug(PREFIX, message, data);
194
+ } else {
195
+ console.debug(PREFIX, message);
196
+ }
197
+ }
198
+ }
199
+ info(message, data) {
200
+ if (LEVEL_PRIORITY[this.level] <= LEVEL_PRIORITY.info) {
201
+ if (data !== void 0) {
202
+ console.info(PREFIX, message, data);
203
+ } else {
204
+ console.info(PREFIX, message);
205
+ }
206
+ }
207
+ }
208
+ warn(message, data) {
209
+ if (LEVEL_PRIORITY[this.level] <= LEVEL_PRIORITY.warn) {
210
+ if (data !== void 0) {
211
+ console.warn(PREFIX, message, data);
212
+ } else {
213
+ console.warn(PREFIX, message);
214
+ }
215
+ }
216
+ }
217
+ error(message, data) {
218
+ if (LEVEL_PRIORITY[this.level] <= LEVEL_PRIORITY.error) {
219
+ if (data !== void 0) {
220
+ console.error(PREFIX, message, data);
221
+ } else {
222
+ console.error(PREFIX, message);
223
+ }
224
+ }
225
+ }
226
+ };
227
+ var logger = new Logger();
228
+
170
229
  // src/api/client.ts
171
230
  function getPlayerTruth(container) {
172
231
  if (typeof window === "undefined") {
@@ -216,6 +275,7 @@ var ApiClient = class {
216
275
  * The request is aborted after 10 seconds.
217
276
  */
218
277
  async fetchAds(deviceId, etag = null) {
278
+ logger.debug("Fetching ads", { deviceId });
219
279
  const headers = { Accept: "application/json" };
220
280
  if (etag) headers["If-None-Match"] = etag;
221
281
  const controller = new AbortController();
@@ -250,7 +310,7 @@ var ApiClient = class {
250
310
  }
251
311
  const data = await response.json();
252
312
  const newEtag = response.headers.get("ETag");
253
- return {
313
+ const result = {
254
314
  ads: data.data?.ads ?? [],
255
315
  settings: data.data?.settings ?? {},
256
316
  programmatic: data.data?.header_bidding_settings ?? null,
@@ -260,6 +320,8 @@ var ApiClient = class {
260
320
  etag: newEtag,
261
321
  notModified: false
262
322
  };
323
+ logger.debug("Ads fetched", { deviceId, count: result.ads.length, notModified: false });
324
+ return result;
263
325
  } catch (error) {
264
326
  clearTimeout(timeoutId);
265
327
  throw error;
@@ -275,6 +337,7 @@ var ApiClient = class {
275
337
  * Returns `true` if the server acknowledged the impression.
276
338
  */
277
339
  async reportImpression(impression) {
340
+ logger.debug("Reporting impression", { adId: impression.adid, impressionId: impression.impid });
278
341
  try {
279
342
  const params = new URLSearchParams({
280
343
  adid: impression.adid,
@@ -298,6 +361,7 @@ var ApiClient = class {
298
361
  * Returns `true` on 2xx, `false` on any error.
299
362
  */
300
363
  async sendHeartbeat(deviceId, screenId) {
364
+ logger.debug("Sending heartbeat", { deviceId });
301
365
  try {
302
366
  const response = await fetch(`${this.apiBase}/device/${deviceId}/heartbeat`, {
303
367
  method: "POST",
@@ -320,6 +384,7 @@ var ApiClient = class {
320
384
  * error, etc.) to the analytics backend.
321
385
  */
322
386
  async reportProgrammaticEvent(event) {
387
+ logger.debug("Reporting programmatic event", { eventType: event.eventType });
323
388
  try {
324
389
  const response = await fetch(`${this.apiBase}/programmatic-event`, {
325
390
  method: "POST",