@trillboards/api-client 0.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/README.md +96 -0
- package/dist/index.d.mts +642 -0
- package/dist/index.d.ts +642 -0
- package/dist/index.js +416 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +398 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +65 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,642 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core type definitions for the Trillboards API Client SDK.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the canonical error contract from trillboard-api/utils/apiErrors.ts
|
|
5
|
+
* and the OpenAPI schema at trillboard-api/docs/openapi/partner-api.yaml.
|
|
6
|
+
*/
|
|
7
|
+
type ApiErrorType = 'invalid_request_error' | 'authentication_error' | 'permission_error' | 'rate_limit_error' | 'idempotency_error' | 'api_error';
|
|
8
|
+
interface ErrorDetail {
|
|
9
|
+
field: string;
|
|
10
|
+
message: string;
|
|
11
|
+
code: string;
|
|
12
|
+
}
|
|
13
|
+
interface ErrorResponseBody {
|
|
14
|
+
error: {
|
|
15
|
+
type: ApiErrorType;
|
|
16
|
+
code: string;
|
|
17
|
+
message: string;
|
|
18
|
+
param?: string | null;
|
|
19
|
+
request_id?: string;
|
|
20
|
+
doc_url?: string;
|
|
21
|
+
details?: ErrorDetail[];
|
|
22
|
+
help?: Record<string, unknown>;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
interface ClientOptions {
|
|
26
|
+
/** Partner API key (e.g. trb_partner_xxxxx). */
|
|
27
|
+
apiKey: string;
|
|
28
|
+
/** Base URL for the API. Defaults to https://api.trillboards.com */
|
|
29
|
+
baseUrl?: string;
|
|
30
|
+
/** API version header value. When set, sent as Trillboards-Version. */
|
|
31
|
+
version?: string;
|
|
32
|
+
}
|
|
33
|
+
interface RequestOptions {
|
|
34
|
+
params?: Record<string, unknown>;
|
|
35
|
+
body?: unknown;
|
|
36
|
+
headers?: Record<string, string>;
|
|
37
|
+
}
|
|
38
|
+
interface ListResponse<T> {
|
|
39
|
+
success: boolean;
|
|
40
|
+
data: T[];
|
|
41
|
+
pagination?: {
|
|
42
|
+
total: number;
|
|
43
|
+
limit: number;
|
|
44
|
+
offset: number;
|
|
45
|
+
has_more: boolean;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
interface Screen {
|
|
49
|
+
screen_id: string;
|
|
50
|
+
name: string;
|
|
51
|
+
status: string;
|
|
52
|
+
device_id?: string;
|
|
53
|
+
venue_type?: string;
|
|
54
|
+
country?: string;
|
|
55
|
+
city?: string;
|
|
56
|
+
timezone?: string;
|
|
57
|
+
resolution?: string;
|
|
58
|
+
embed_url?: string;
|
|
59
|
+
created_at: string;
|
|
60
|
+
updated_at: string;
|
|
61
|
+
}
|
|
62
|
+
interface Device {
|
|
63
|
+
device_id: string;
|
|
64
|
+
device_name: string;
|
|
65
|
+
device_type?: string;
|
|
66
|
+
platform?: string;
|
|
67
|
+
screen_id?: string;
|
|
68
|
+
status: string;
|
|
69
|
+
last_heartbeat?: string;
|
|
70
|
+
created_at: string;
|
|
71
|
+
updated_at: string;
|
|
72
|
+
}
|
|
73
|
+
interface Impression {
|
|
74
|
+
impression_id: string;
|
|
75
|
+
screen_id: string;
|
|
76
|
+
device_id: string;
|
|
77
|
+
ad_type?: string;
|
|
78
|
+
advertiser_name?: string;
|
|
79
|
+
cpm?: number;
|
|
80
|
+
earnings?: number;
|
|
81
|
+
played_at: string;
|
|
82
|
+
duration_seconds?: number;
|
|
83
|
+
}
|
|
84
|
+
interface AnalyticsData {
|
|
85
|
+
period: string;
|
|
86
|
+
total_impressions: number;
|
|
87
|
+
total_earnings: number;
|
|
88
|
+
average_cpm: number;
|
|
89
|
+
fill_rate: number;
|
|
90
|
+
screens_active: number;
|
|
91
|
+
screens_total: number;
|
|
92
|
+
by_screen?: Array<{
|
|
93
|
+
screen_id: string;
|
|
94
|
+
name: string;
|
|
95
|
+
impressions: number;
|
|
96
|
+
earnings: number;
|
|
97
|
+
}>;
|
|
98
|
+
}
|
|
99
|
+
interface EarningsData {
|
|
100
|
+
period: string;
|
|
101
|
+
total_earnings: number;
|
|
102
|
+
total_impressions: number;
|
|
103
|
+
average_cpm: number;
|
|
104
|
+
daily?: Array<{
|
|
105
|
+
date: string;
|
|
106
|
+
earnings: number;
|
|
107
|
+
impressions: number;
|
|
108
|
+
}>;
|
|
109
|
+
pending_payout: number;
|
|
110
|
+
last_payout_date?: string;
|
|
111
|
+
last_payout_amount?: number;
|
|
112
|
+
}
|
|
113
|
+
interface WebhookEvent {
|
|
114
|
+
id: string;
|
|
115
|
+
type: string;
|
|
116
|
+
created_at: string;
|
|
117
|
+
data: Record<string, unknown>;
|
|
118
|
+
partner_id: string;
|
|
119
|
+
}
|
|
120
|
+
interface Webhook {
|
|
121
|
+
id: string;
|
|
122
|
+
url: string;
|
|
123
|
+
events: string[];
|
|
124
|
+
status: string;
|
|
125
|
+
secret: string;
|
|
126
|
+
created_at: string;
|
|
127
|
+
updated_at: string;
|
|
128
|
+
}
|
|
129
|
+
interface ErrorEntry {
|
|
130
|
+
id: string;
|
|
131
|
+
code: string;
|
|
132
|
+
type: ApiErrorType;
|
|
133
|
+
message: string;
|
|
134
|
+
param?: string;
|
|
135
|
+
doc_url: string;
|
|
136
|
+
timestamp: string;
|
|
137
|
+
request_id: string;
|
|
138
|
+
endpoint: string;
|
|
139
|
+
method: string;
|
|
140
|
+
}
|
|
141
|
+
interface FleetCommand {
|
|
142
|
+
command_id: string;
|
|
143
|
+
command: string;
|
|
144
|
+
status: string;
|
|
145
|
+
target_screens: string[];
|
|
146
|
+
created_at: string;
|
|
147
|
+
completed_at?: string;
|
|
148
|
+
}
|
|
149
|
+
interface AudienceData {
|
|
150
|
+
screen_id: string;
|
|
151
|
+
timestamp: string;
|
|
152
|
+
attention_count: number;
|
|
153
|
+
dwell_time_avg: number;
|
|
154
|
+
demographics?: Record<string, unknown>;
|
|
155
|
+
}
|
|
156
|
+
interface BillingInfo {
|
|
157
|
+
plan: string;
|
|
158
|
+
credits_remaining: number;
|
|
159
|
+
credits_used: number;
|
|
160
|
+
usage_this_month: Record<string, number>;
|
|
161
|
+
stripe_connected: boolean;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Internal HTTP client for the Trillboards API.
|
|
166
|
+
*
|
|
167
|
+
* Uses native fetch (Node 18+). Zero runtime dependencies.
|
|
168
|
+
* Sends standard headers: Authorization, Content-Type, User-Agent, X-Trillboards-Client.
|
|
169
|
+
*/
|
|
170
|
+
|
|
171
|
+
interface HttpClientConfig {
|
|
172
|
+
apiKey: string;
|
|
173
|
+
baseUrl: string;
|
|
174
|
+
version?: string;
|
|
175
|
+
}
|
|
176
|
+
declare class HttpClient {
|
|
177
|
+
private readonly config;
|
|
178
|
+
constructor(config: HttpClientConfig);
|
|
179
|
+
request<T>(method: string, path: string, options?: RequestOptions): Promise<T>;
|
|
180
|
+
get<T>(path: string, opts?: {
|
|
181
|
+
params?: Record<string, unknown>;
|
|
182
|
+
}): Promise<T>;
|
|
183
|
+
post<T>(path: string, body?: unknown): Promise<T>;
|
|
184
|
+
put<T>(path: string, body?: unknown): Promise<T>;
|
|
185
|
+
patch<T>(path: string, body?: unknown): Promise<T>;
|
|
186
|
+
delete<T>(path: string): Promise<T>;
|
|
187
|
+
private buildUrl;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* ScreensClient — Partner API screen management.
|
|
192
|
+
*
|
|
193
|
+
* Base path: /v1/partner (screens are mapped from devices + screen pairs)
|
|
194
|
+
*/
|
|
195
|
+
|
|
196
|
+
declare class ScreensClient {
|
|
197
|
+
private readonly http;
|
|
198
|
+
constructor(http: HttpClient);
|
|
199
|
+
/** List all screens owned by this partner. */
|
|
200
|
+
list(params?: {
|
|
201
|
+
limit?: number;
|
|
202
|
+
offset?: number;
|
|
203
|
+
}): Promise<ListResponse<Screen>>;
|
|
204
|
+
/** Get a single screen by ID. */
|
|
205
|
+
get(screenId: string): Promise<{
|
|
206
|
+
success: boolean;
|
|
207
|
+
data: Screen;
|
|
208
|
+
}>;
|
|
209
|
+
/** Register a new device/screen. */
|
|
210
|
+
create(body: {
|
|
211
|
+
device_name: string;
|
|
212
|
+
device_type?: string;
|
|
213
|
+
venue_type?: string;
|
|
214
|
+
country?: string;
|
|
215
|
+
city?: string;
|
|
216
|
+
timezone?: string;
|
|
217
|
+
resolution?: string;
|
|
218
|
+
}): Promise<{
|
|
219
|
+
success: boolean;
|
|
220
|
+
data: Screen;
|
|
221
|
+
}>;
|
|
222
|
+
/** Delete a screen/device. */
|
|
223
|
+
delete(screenId: string): Promise<{
|
|
224
|
+
success: boolean;
|
|
225
|
+
}>;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* DevicesClient — device registration and heartbeat.
|
|
230
|
+
*
|
|
231
|
+
* Base path: /v1/partner
|
|
232
|
+
*/
|
|
233
|
+
|
|
234
|
+
declare class DevicesClient {
|
|
235
|
+
private readonly http;
|
|
236
|
+
constructor(http: HttpClient);
|
|
237
|
+
/** List all devices for this partner. */
|
|
238
|
+
list(params?: {
|
|
239
|
+
limit?: number;
|
|
240
|
+
offset?: number;
|
|
241
|
+
}): Promise<ListResponse<Device>>;
|
|
242
|
+
/** Get a single device by ID. */
|
|
243
|
+
get(deviceId: string): Promise<{
|
|
244
|
+
success: boolean;
|
|
245
|
+
data: Device;
|
|
246
|
+
}>;
|
|
247
|
+
/** Register a new device. */
|
|
248
|
+
create(body: {
|
|
249
|
+
device_name: string;
|
|
250
|
+
device_type?: string;
|
|
251
|
+
platform?: string;
|
|
252
|
+
}): Promise<{
|
|
253
|
+
success: boolean;
|
|
254
|
+
data: Device;
|
|
255
|
+
}>;
|
|
256
|
+
/** Delete a device. */
|
|
257
|
+
delete(deviceId: string): Promise<{
|
|
258
|
+
success: boolean;
|
|
259
|
+
}>;
|
|
260
|
+
/** Send heartbeat for a device. */
|
|
261
|
+
heartbeat(deviceId: string, body?: Record<string, unknown>): Promise<{
|
|
262
|
+
success: boolean;
|
|
263
|
+
}>;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* ImpressionsClient — impression tracking.
|
|
268
|
+
*
|
|
269
|
+
* Base path: /v1/partner
|
|
270
|
+
*/
|
|
271
|
+
|
|
272
|
+
declare class ImpressionsClient {
|
|
273
|
+
private readonly http;
|
|
274
|
+
constructor(http: HttpClient);
|
|
275
|
+
/** Record a single impression. */
|
|
276
|
+
create(body: {
|
|
277
|
+
screen_id: string;
|
|
278
|
+
device_id: string;
|
|
279
|
+
ad_type?: string;
|
|
280
|
+
duration_seconds?: number;
|
|
281
|
+
metadata?: Record<string, unknown>;
|
|
282
|
+
}): Promise<{
|
|
283
|
+
success: boolean;
|
|
284
|
+
data: Impression;
|
|
285
|
+
}>;
|
|
286
|
+
/** Record a batch of impressions (offline sync). */
|
|
287
|
+
createBatch(body: {
|
|
288
|
+
impressions: Array<{
|
|
289
|
+
screen_id: string;
|
|
290
|
+
device_id: string;
|
|
291
|
+
ad_type?: string;
|
|
292
|
+
duration_seconds?: number;
|
|
293
|
+
played_at?: string;
|
|
294
|
+
metadata?: Record<string, unknown>;
|
|
295
|
+
}>;
|
|
296
|
+
}): Promise<{
|
|
297
|
+
success: boolean;
|
|
298
|
+
count: number;
|
|
299
|
+
}>;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* AnalyticsClient — partner analytics and reporting.
|
|
304
|
+
*
|
|
305
|
+
* Base path: /v1/partner
|
|
306
|
+
*/
|
|
307
|
+
|
|
308
|
+
declare class AnalyticsClient {
|
|
309
|
+
private readonly http;
|
|
310
|
+
constructor(http: HttpClient);
|
|
311
|
+
/** Get partner analytics summary. */
|
|
312
|
+
get(params?: {
|
|
313
|
+
period?: 'day' | 'week' | 'month';
|
|
314
|
+
start_date?: string;
|
|
315
|
+
end_date?: string;
|
|
316
|
+
screen_id?: string;
|
|
317
|
+
}): Promise<{
|
|
318
|
+
success: boolean;
|
|
319
|
+
data: AnalyticsData;
|
|
320
|
+
}>;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* EarningsClient — earnings, payouts, and transaction history.
|
|
325
|
+
*
|
|
326
|
+
* Base path: /v1/partner
|
|
327
|
+
*/
|
|
328
|
+
|
|
329
|
+
declare class EarningsClient {
|
|
330
|
+
private readonly http;
|
|
331
|
+
constructor(http: HttpClient);
|
|
332
|
+
/** Get earnings summary for the authenticated partner. */
|
|
333
|
+
get(params?: {
|
|
334
|
+
period?: 'day' | 'week' | 'month';
|
|
335
|
+
start_date?: string;
|
|
336
|
+
end_date?: string;
|
|
337
|
+
}): Promise<{
|
|
338
|
+
success: boolean;
|
|
339
|
+
data: EarningsData;
|
|
340
|
+
}>;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* ErrorsClient — query the partner error log.
|
|
345
|
+
*
|
|
346
|
+
* Base path: /v1/partner
|
|
347
|
+
*/
|
|
348
|
+
|
|
349
|
+
declare class ErrorsClient {
|
|
350
|
+
private readonly http;
|
|
351
|
+
constructor(http: HttpClient);
|
|
352
|
+
/** List recent errors for this partner. */
|
|
353
|
+
list(params?: {
|
|
354
|
+
limit?: number;
|
|
355
|
+
offset?: number;
|
|
356
|
+
code?: string;
|
|
357
|
+
type?: string;
|
|
358
|
+
}): Promise<ListResponse<ErrorEntry>>;
|
|
359
|
+
/** Get a single error by request_id. */
|
|
360
|
+
get(requestId: string): Promise<{
|
|
361
|
+
success: boolean;
|
|
362
|
+
data: ErrorEntry;
|
|
363
|
+
}>;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* WebhooksClient — webhook subscription management.
|
|
368
|
+
*
|
|
369
|
+
* Base path: /v1/partner
|
|
370
|
+
*/
|
|
371
|
+
|
|
372
|
+
declare class WebhooksClient {
|
|
373
|
+
private readonly http;
|
|
374
|
+
constructor(http: HttpClient);
|
|
375
|
+
/** List all webhook subscriptions. */
|
|
376
|
+
list(): Promise<ListResponse<Webhook>>;
|
|
377
|
+
/** Create a new webhook subscription. */
|
|
378
|
+
create(body: {
|
|
379
|
+
url: string;
|
|
380
|
+
events: string[];
|
|
381
|
+
}): Promise<{
|
|
382
|
+
success: boolean;
|
|
383
|
+
data: Webhook;
|
|
384
|
+
}>;
|
|
385
|
+
/** Update a webhook subscription. */
|
|
386
|
+
update(webhookId: string, body: {
|
|
387
|
+
url?: string;
|
|
388
|
+
events?: string[];
|
|
389
|
+
status?: string;
|
|
390
|
+
}): Promise<{
|
|
391
|
+
success: boolean;
|
|
392
|
+
data: Webhook;
|
|
393
|
+
}>;
|
|
394
|
+
/** Delete a webhook subscription. */
|
|
395
|
+
delete(webhookId: string): Promise<{
|
|
396
|
+
success: boolean;
|
|
397
|
+
}>;
|
|
398
|
+
/** Send a test event to a webhook. */
|
|
399
|
+
test(webhookId: string): Promise<{
|
|
400
|
+
success: boolean;
|
|
401
|
+
}>;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* FleetClient — fleet-wide device management.
|
|
406
|
+
*
|
|
407
|
+
* Base path: /v1/partner
|
|
408
|
+
*/
|
|
409
|
+
|
|
410
|
+
declare class FleetClient {
|
|
411
|
+
private readonly http;
|
|
412
|
+
constructor(http: HttpClient);
|
|
413
|
+
/** Push a command to a set of screens. */
|
|
414
|
+
pushCommand(body: {
|
|
415
|
+
command: string;
|
|
416
|
+
target_screens?: string[];
|
|
417
|
+
venue_type?: string;
|
|
418
|
+
country?: string;
|
|
419
|
+
params?: Record<string, unknown>;
|
|
420
|
+
}): Promise<{
|
|
421
|
+
success: boolean;
|
|
422
|
+
data: FleetCommand;
|
|
423
|
+
}>;
|
|
424
|
+
/** List recent fleet commands. */
|
|
425
|
+
listCommands(params?: {
|
|
426
|
+
limit?: number;
|
|
427
|
+
offset?: number;
|
|
428
|
+
}): Promise<ListResponse<FleetCommand>>;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* AudienceClient — audience intelligence API.
|
|
433
|
+
*
|
|
434
|
+
* Base path: /v1/partner/audience
|
|
435
|
+
*/
|
|
436
|
+
|
|
437
|
+
declare class AudienceClient {
|
|
438
|
+
private readonly http;
|
|
439
|
+
constructor(http: HttpClient);
|
|
440
|
+
/** Get live audience data for a screen. */
|
|
441
|
+
getLive(screenId: string): Promise<{
|
|
442
|
+
success: boolean;
|
|
443
|
+
data: AudienceData;
|
|
444
|
+
}>;
|
|
445
|
+
/** Get audience heatmap across screens. */
|
|
446
|
+
getHeatmap(params?: {
|
|
447
|
+
start_date?: string;
|
|
448
|
+
end_date?: string;
|
|
449
|
+
screen_ids?: string[];
|
|
450
|
+
}): Promise<{
|
|
451
|
+
success: boolean;
|
|
452
|
+
data: Record<string, unknown>;
|
|
453
|
+
}>;
|
|
454
|
+
/** Get aggregate audience statistics. */
|
|
455
|
+
getStats(params?: {
|
|
456
|
+
period?: 'day' | 'week' | 'month';
|
|
457
|
+
}): Promise<{
|
|
458
|
+
success: boolean;
|
|
459
|
+
data: Record<string, unknown>;
|
|
460
|
+
}>;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* DataClient — data export and venue intelligence.
|
|
465
|
+
*
|
|
466
|
+
* Base path: /v1/partner
|
|
467
|
+
*/
|
|
468
|
+
|
|
469
|
+
declare class DataClient {
|
|
470
|
+
private readonly http;
|
|
471
|
+
constructor(http: HttpClient);
|
|
472
|
+
/** Get venue intelligence data for a screen. */
|
|
473
|
+
getVenueIntelligence(screenId: string): Promise<{
|
|
474
|
+
success: boolean;
|
|
475
|
+
data: Record<string, unknown>;
|
|
476
|
+
}>;
|
|
477
|
+
/** Get API usage summary. */
|
|
478
|
+
getUsage(params?: {
|
|
479
|
+
period?: 'day' | 'week' | 'month';
|
|
480
|
+
}): Promise<{
|
|
481
|
+
success: boolean;
|
|
482
|
+
data: Record<string, unknown>;
|
|
483
|
+
}>;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* BillingClient — usage-based billing and credits.
|
|
488
|
+
*
|
|
489
|
+
* Base path: /v1/partner
|
|
490
|
+
*/
|
|
491
|
+
|
|
492
|
+
declare class BillingClient {
|
|
493
|
+
private readonly http;
|
|
494
|
+
constructor(http: HttpClient);
|
|
495
|
+
/** Get current billing info (plan, credits, usage). */
|
|
496
|
+
get(): Promise<{
|
|
497
|
+
success: boolean;
|
|
498
|
+
data: BillingInfo;
|
|
499
|
+
}>;
|
|
500
|
+
/** Get Stripe Connect account status. */
|
|
501
|
+
getStripeStatus(): Promise<{
|
|
502
|
+
success: boolean;
|
|
503
|
+
data: Record<string, unknown>;
|
|
504
|
+
}>;
|
|
505
|
+
/** Request a payout transfer. */
|
|
506
|
+
requestPayout(body?: {
|
|
507
|
+
amount?: number;
|
|
508
|
+
}): Promise<{
|
|
509
|
+
success: boolean;
|
|
510
|
+
data: Record<string, unknown>;
|
|
511
|
+
}>;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* TrillboardsClient — main entry point for the Trillboards Partner API SDK.
|
|
516
|
+
*
|
|
517
|
+
* Usage:
|
|
518
|
+
* import { TrillboardsClient } from '@trillboards/api-client';
|
|
519
|
+
*
|
|
520
|
+
* const client = new TrillboardsClient({ apiKey: 'trb_partner_xxxxx' });
|
|
521
|
+
* const screens = await client.screens.list();
|
|
522
|
+
*/
|
|
523
|
+
|
|
524
|
+
declare class TrillboardsClient {
|
|
525
|
+
readonly screens: ScreensClient;
|
|
526
|
+
readonly devices: DevicesClient;
|
|
527
|
+
readonly impressions: ImpressionsClient;
|
|
528
|
+
readonly analytics: AnalyticsClient;
|
|
529
|
+
readonly webhooks: WebhooksClient;
|
|
530
|
+
readonly earnings: EarningsClient;
|
|
531
|
+
readonly fleet: FleetClient;
|
|
532
|
+
readonly audience: AudienceClient;
|
|
533
|
+
readonly data: DataClient;
|
|
534
|
+
readonly errors: ErrorsClient;
|
|
535
|
+
readonly billing: BillingClient;
|
|
536
|
+
/** The underlying HTTP client (exposed for advanced use cases). */
|
|
537
|
+
readonly _http: HttpClient;
|
|
538
|
+
constructor(options: ClientOptions);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* TrillboardsError — client-side error class that mirrors the server-side
|
|
543
|
+
* canonical error envelope from utils/apiErrors.ts.
|
|
544
|
+
*
|
|
545
|
+
* Error shape from the API:
|
|
546
|
+
* { error: { type, code, message, param, doc_url, request_id, details?, help? } }
|
|
547
|
+
*/
|
|
548
|
+
|
|
549
|
+
interface TrillboardsErrorOptions {
|
|
550
|
+
type: ApiErrorType;
|
|
551
|
+
code: string;
|
|
552
|
+
message: string;
|
|
553
|
+
statusCode: number;
|
|
554
|
+
param?: string | null;
|
|
555
|
+
requestId?: string;
|
|
556
|
+
docsUrl?: string;
|
|
557
|
+
details?: ErrorDetail[];
|
|
558
|
+
help?: Record<string, unknown>;
|
|
559
|
+
retryAfterSeconds?: number | null;
|
|
560
|
+
}
|
|
561
|
+
declare class TrillboardsError extends Error {
|
|
562
|
+
readonly type: ApiErrorType;
|
|
563
|
+
readonly code: string;
|
|
564
|
+
readonly param: string | null;
|
|
565
|
+
readonly requestId: string;
|
|
566
|
+
readonly docsUrl: string;
|
|
567
|
+
readonly statusCode: number;
|
|
568
|
+
readonly details: ErrorDetail[];
|
|
569
|
+
readonly help: Record<string, unknown> | null;
|
|
570
|
+
private readonly _retryAfterSeconds;
|
|
571
|
+
constructor(opts: TrillboardsErrorOptions);
|
|
572
|
+
/**
|
|
573
|
+
* Construct a TrillboardsError from an API error response body and fetch Response.
|
|
574
|
+
*
|
|
575
|
+
* The API wraps errors in { error: { ... } }. We unwrap and map to class fields.
|
|
576
|
+
*/
|
|
577
|
+
static fromResponse(body: ErrorResponseBody | Record<string, unknown>, response: {
|
|
578
|
+
status: number;
|
|
579
|
+
headers: {
|
|
580
|
+
get(name: string): string | null;
|
|
581
|
+
};
|
|
582
|
+
}): TrillboardsError;
|
|
583
|
+
/** True if this is a 429 rate limit response. */
|
|
584
|
+
get isRateLimited(): boolean;
|
|
585
|
+
/**
|
|
586
|
+
* Number of seconds to wait before retrying, from the Retry-After header.
|
|
587
|
+
* Returns null if no Retry-After header was present.
|
|
588
|
+
*/
|
|
589
|
+
get retryAfter(): number | null;
|
|
590
|
+
/** True if this is an authentication error (401). */
|
|
591
|
+
get isAuthError(): boolean;
|
|
592
|
+
/** True if this is a permission/forbidden error (403). */
|
|
593
|
+
get isForbidden(): boolean;
|
|
594
|
+
/** True if this is a server-side error (5xx). */
|
|
595
|
+
get isServerError(): boolean;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Webhook signature verification for Trillboards Partner API webhooks.
|
|
600
|
+
*
|
|
601
|
+
* Uses HMAC-SHA256 with timing-safe comparison to prevent signature
|
|
602
|
+
* forgery and timing attacks.
|
|
603
|
+
*/
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* Verify a webhook payload signature and parse the event.
|
|
607
|
+
*
|
|
608
|
+
* @param payload - Raw request body as string or Buffer.
|
|
609
|
+
* @param signature - The signature from the `X-Trillboards-Signature` header.
|
|
610
|
+
* @param secret - The webhook secret from your webhook subscription.
|
|
611
|
+
* @returns The parsed WebhookEvent if signature is valid.
|
|
612
|
+
* @throws TrillboardsError if the signature does not match.
|
|
613
|
+
*
|
|
614
|
+
* @example
|
|
615
|
+
* ```typescript
|
|
616
|
+
* import { Webhooks } from '@trillboards/api-client';
|
|
617
|
+
*
|
|
618
|
+
* app.post('/webhooks', (req, res) => {
|
|
619
|
+
* const event = Webhooks.constructEvent(
|
|
620
|
+
* req.body,
|
|
621
|
+
* req.headers['x-trillboards-signature'],
|
|
622
|
+
* process.env.WEBHOOK_SECRET
|
|
623
|
+
* );
|
|
624
|
+
* console.log('Received event:', event.type);
|
|
625
|
+
* res.sendStatus(200);
|
|
626
|
+
* });
|
|
627
|
+
* ```
|
|
628
|
+
*/
|
|
629
|
+
declare function constructEvent(payload: string | Buffer, signature: string, secret: string): WebhookEvent;
|
|
630
|
+
declare const Webhooks: {
|
|
631
|
+
constructEvent: typeof constructEvent;
|
|
632
|
+
};
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* SDK version constant. Sent in User-Agent and X-Trillboards-Client headers.
|
|
636
|
+
* Keep in sync with package.json version.
|
|
637
|
+
*/
|
|
638
|
+
declare const VERSION = "0.1.0";
|
|
639
|
+
|
|
640
|
+
declare const generatedTypes: {};
|
|
641
|
+
|
|
642
|
+
export { AnalyticsClient, type AnalyticsData, type ApiErrorType, AudienceClient, type AudienceData, BillingClient, type BillingInfo, type ClientOptions, DataClient, type Device, DevicesClient, EarningsClient, type EarningsData, type ErrorDetail, type ErrorEntry, type ErrorResponseBody, ErrorsClient, FleetClient, type FleetCommand, type Impression, ImpressionsClient, type ListResponse, type RequestOptions, type Screen, ScreensClient, TrillboardsClient, TrillboardsError, type TrillboardsErrorOptions, VERSION, type Webhook, type WebhookEvent, Webhooks, WebhooksClient, constructEvent, generatedTypes };
|