@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/CHANGELOG.md +15 -0
- package/README.md +65 -0
- package/dist/cli.js +158 -0
- package/dist/index.d.mts +56 -3
- package/dist/index.d.ts +56 -3
- package/dist/index.js +147 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +141 -4
- package/dist/index.mjs.map +1 -1
- package/dist/react-native.d.mts +1 -0
- package/dist/react-native.d.ts +1 -0
- package/dist/react.d.mts +1 -0
- package/dist/react.d.ts +1 -0
- package/dist/react.js +67 -2
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +67 -2
- package/dist/react.mjs.map +1 -1
- package/dist/server.d.mts +106 -4
- package/dist/server.d.ts +106 -4
- package/dist/server.js +250 -4
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +244 -5
- package/dist/server.mjs.map +1 -1
- package/dist/trillboards-lite.global.js +1 -1
- package/dist/trillboards-lite.global.js.map +1 -1
- package/package.json +4 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/core/config.ts
|
|
2
|
-
var SDK_VERSION = "2.
|
|
2
|
+
var SDK_VERSION = "2.1.0";
|
|
3
3
|
var DEFAULT_CONFIG = {
|
|
4
4
|
API_BASE: "https://api.trillboards.com/v1/partner",
|
|
5
5
|
CDN_BASE: "https://cdn.trillboards.com",
|
|
@@ -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,67 @@ 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
|
+
function setLogLevel(level) {
|
|
231
|
+
logger.setLevel(level);
|
|
232
|
+
}
|
|
233
|
+
|
|
172
234
|
// src/api/client.ts
|
|
173
235
|
function getPlayerTruth(container) {
|
|
174
236
|
if (typeof window === "undefined") {
|
|
@@ -218,6 +280,7 @@ var ApiClient = class {
|
|
|
218
280
|
* The request is aborted after 10 seconds.
|
|
219
281
|
*/
|
|
220
282
|
async fetchAds(deviceId, etag = null) {
|
|
283
|
+
logger.debug("Fetching ads", { deviceId });
|
|
221
284
|
const headers = { Accept: "application/json" };
|
|
222
285
|
if (etag) headers["If-None-Match"] = etag;
|
|
223
286
|
const controller = new AbortController();
|
|
@@ -252,7 +315,7 @@ var ApiClient = class {
|
|
|
252
315
|
}
|
|
253
316
|
const data = await response.json();
|
|
254
317
|
const newEtag = response.headers.get("ETag");
|
|
255
|
-
|
|
318
|
+
const result = {
|
|
256
319
|
ads: data.data?.ads ?? [],
|
|
257
320
|
settings: data.data?.settings ?? {},
|
|
258
321
|
programmatic: data.data?.header_bidding_settings ?? null,
|
|
@@ -262,6 +325,8 @@ var ApiClient = class {
|
|
|
262
325
|
etag: newEtag,
|
|
263
326
|
notModified: false
|
|
264
327
|
};
|
|
328
|
+
logger.debug("Ads fetched", { deviceId, count: result.ads.length, notModified: false });
|
|
329
|
+
return result;
|
|
265
330
|
} catch (error) {
|
|
266
331
|
clearTimeout(timeoutId);
|
|
267
332
|
throw error;
|
|
@@ -277,6 +342,7 @@ var ApiClient = class {
|
|
|
277
342
|
* Returns `true` if the server acknowledged the impression.
|
|
278
343
|
*/
|
|
279
344
|
async reportImpression(impression) {
|
|
345
|
+
logger.debug("Reporting impression", { adId: impression.adid, impressionId: impression.impid });
|
|
280
346
|
try {
|
|
281
347
|
const params = new URLSearchParams({
|
|
282
348
|
adid: impression.adid,
|
|
@@ -300,6 +366,7 @@ var ApiClient = class {
|
|
|
300
366
|
* Returns `true` on 2xx, `false` on any error.
|
|
301
367
|
*/
|
|
302
368
|
async sendHeartbeat(deviceId, screenId) {
|
|
369
|
+
logger.debug("Sending heartbeat", { deviceId });
|
|
303
370
|
try {
|
|
304
371
|
const response = await fetch(`${this.apiBase}/device/${deviceId}/heartbeat`, {
|
|
305
372
|
method: "POST",
|
|
@@ -322,6 +389,7 @@ var ApiClient = class {
|
|
|
322
389
|
* error, etc.) to the analytics backend.
|
|
323
390
|
*/
|
|
324
391
|
async reportProgrammaticEvent(event) {
|
|
392
|
+
logger.debug("Reporting programmatic event", { eventType: event.eventType });
|
|
325
393
|
try {
|
|
326
394
|
const response = await fetch(`${this.apiBase}/programmatic-event`, {
|
|
327
395
|
method: "POST",
|
|
@@ -1734,6 +1802,75 @@ var _TrillboardsAds = class _TrillboardsAds {
|
|
|
1734
1802
|
_TrillboardsAds._instance = null;
|
|
1735
1803
|
var TrillboardsAds = _TrillboardsAds;
|
|
1736
1804
|
|
|
1737
|
-
|
|
1805
|
+
// src/errors.ts
|
|
1806
|
+
var TrillboardsError = class extends Error {
|
|
1807
|
+
constructor(message, options = {}) {
|
|
1808
|
+
super(message);
|
|
1809
|
+
this.name = "TrillboardsError";
|
|
1810
|
+
this.type = options.type ?? "api_error";
|
|
1811
|
+
this.code = options.code ?? "unknown_error";
|
|
1812
|
+
this.statusCode = options.statusCode ?? 500;
|
|
1813
|
+
this.help = options.help;
|
|
1814
|
+
this.param = options.param;
|
|
1815
|
+
}
|
|
1816
|
+
};
|
|
1817
|
+
var TrillboardsAuthenticationError = class extends TrillboardsError {
|
|
1818
|
+
constructor(message) {
|
|
1819
|
+
super(
|
|
1820
|
+
message ?? "Invalid API key. Check your key at https://trillboards.com/developers",
|
|
1821
|
+
{
|
|
1822
|
+
type: "authentication_error",
|
|
1823
|
+
code: "invalid_api_key",
|
|
1824
|
+
statusCode: 401,
|
|
1825
|
+
help: "https://trillboards.com/developers"
|
|
1826
|
+
}
|
|
1827
|
+
);
|
|
1828
|
+
this.name = "TrillboardsAuthenticationError";
|
|
1829
|
+
}
|
|
1830
|
+
};
|
|
1831
|
+
var TrillboardsRateLimitError = class extends TrillboardsError {
|
|
1832
|
+
constructor(retryAfter, message) {
|
|
1833
|
+
super(
|
|
1834
|
+
message ?? `Rate limit exceeded. Retry after ${retryAfter} seconds.`,
|
|
1835
|
+
{
|
|
1836
|
+
type: "rate_limit_error",
|
|
1837
|
+
code: "rate_limited",
|
|
1838
|
+
statusCode: 429
|
|
1839
|
+
}
|
|
1840
|
+
);
|
|
1841
|
+
this.name = "TrillboardsRateLimitError";
|
|
1842
|
+
this.retryAfter = retryAfter;
|
|
1843
|
+
}
|
|
1844
|
+
};
|
|
1845
|
+
var TrillboardsNotFoundError = class extends TrillboardsError {
|
|
1846
|
+
constructor(message) {
|
|
1847
|
+
super(
|
|
1848
|
+
message ?? "The requested resource was not found.",
|
|
1849
|
+
{
|
|
1850
|
+
type: "not_found_error",
|
|
1851
|
+
code: "resource_not_found",
|
|
1852
|
+
statusCode: 404,
|
|
1853
|
+
help: "Verify the ID is correct and belongs to your account."
|
|
1854
|
+
}
|
|
1855
|
+
);
|
|
1856
|
+
this.name = "TrillboardsNotFoundError";
|
|
1857
|
+
}
|
|
1858
|
+
};
|
|
1859
|
+
var TrillboardsValidationError = class extends TrillboardsError {
|
|
1860
|
+
constructor(message, param) {
|
|
1861
|
+
super(
|
|
1862
|
+
message ?? "The request was invalid.",
|
|
1863
|
+
{
|
|
1864
|
+
type: "validation_error",
|
|
1865
|
+
code: "invalid_request",
|
|
1866
|
+
statusCode: 400,
|
|
1867
|
+
param
|
|
1868
|
+
}
|
|
1869
|
+
);
|
|
1870
|
+
this.name = "TrillboardsValidationError";
|
|
1871
|
+
}
|
|
1872
|
+
};
|
|
1873
|
+
|
|
1874
|
+
export { ApiClient, CircuitBreaker, DEFAULT_CONFIG, DEFAULT_PUBLIC_STATE, EventEmitter, SDK_VERSION, Telemetry, TrillboardsAds, TrillboardsAuthenticationError, TrillboardsError, TrillboardsNotFoundError, TrillboardsRateLimitError, TrillboardsValidationError, WaterfallEngine, createInitialState, getPublicState, logger, resolveConfig, setLogLevel };
|
|
1738
1875
|
//# sourceMappingURL=index.mjs.map
|
|
1739
1876
|
//# sourceMappingURL=index.mjs.map
|