@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/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# @trillboards/api-client
|
|
2
|
+
|
|
3
|
+
Official TypeScript SDK for the Trillboards DOOH Partner API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @trillboards/api-client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Requires Node.js 18+ (uses native `fetch` and `crypto`). Zero runtime dependencies.
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { TrillboardsClient } from '@trillboards/api-client';
|
|
17
|
+
|
|
18
|
+
const client = new TrillboardsClient({
|
|
19
|
+
apiKey: 'trb_partner_xxxxx',
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// List screens
|
|
23
|
+
const { data: screens } = await client.screens.list({ limit: 10 });
|
|
24
|
+
|
|
25
|
+
// Get analytics
|
|
26
|
+
const { data: analytics } = await client.analytics.get({ period: 'week' });
|
|
27
|
+
|
|
28
|
+
// Get earnings
|
|
29
|
+
const { data: earnings } = await client.earnings.get({ period: 'month' });
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Resources
|
|
33
|
+
|
|
34
|
+
| Resource | Methods |
|
|
35
|
+
|----------|---------|
|
|
36
|
+
| `client.screens` | `list`, `get`, `create`, `delete` |
|
|
37
|
+
| `client.devices` | `list`, `get`, `create`, `delete`, `heartbeat` |
|
|
38
|
+
| `client.impressions` | `create`, `createBatch` |
|
|
39
|
+
| `client.analytics` | `get` |
|
|
40
|
+
| `client.earnings` | `get` |
|
|
41
|
+
| `client.webhooks` | `list`, `create`, `update`, `delete`, `test` |
|
|
42
|
+
| `client.fleet` | `pushCommand`, `listCommands` |
|
|
43
|
+
| `client.audience` | `getLive`, `getHeatmap`, `getStats` |
|
|
44
|
+
| `client.data` | `getVenueIntelligence`, `getUsage` |
|
|
45
|
+
| `client.errors` | `list`, `get` |
|
|
46
|
+
| `client.billing` | `get`, `getStripeStatus`, `requestPayout` |
|
|
47
|
+
|
|
48
|
+
## Error Handling
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { TrillboardsClient, TrillboardsError } from '@trillboards/api-client';
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
await client.screens.get('nonexistent');
|
|
55
|
+
} catch (err) {
|
|
56
|
+
if (err instanceof TrillboardsError) {
|
|
57
|
+
console.log(err.code); // 'screen_not_found'
|
|
58
|
+
console.log(err.statusCode); // 404
|
|
59
|
+
console.log(err.docsUrl); // 'https://api.trillboards.com/docs/errors#screen_not_found'
|
|
60
|
+
|
|
61
|
+
if (err.isRateLimited) {
|
|
62
|
+
const retryAfter = err.retryAfter; // seconds from Retry-After header
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Webhook Verification
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import { Webhooks } from '@trillboards/api-client';
|
|
72
|
+
|
|
73
|
+
app.post('/webhooks', (req, res) => {
|
|
74
|
+
const event = Webhooks.constructEvent(
|
|
75
|
+
req.body,
|
|
76
|
+
req.headers['x-trillboards-signature'],
|
|
77
|
+
process.env.WEBHOOK_SECRET
|
|
78
|
+
);
|
|
79
|
+
console.log('Event:', event.type, event.data);
|
|
80
|
+
res.sendStatus(200);
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Configuration
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
const client = new TrillboardsClient({
|
|
88
|
+
apiKey: 'trb_partner_xxxxx', // Required
|
|
89
|
+
baseUrl: 'https://api.trillboards.com', // Optional, defaults to production
|
|
90
|
+
version: '2024-01-15', // Optional, sent as Trillboards-Version header
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
MIT
|