@trillboards/api-client 0.2.0 → 0.4.1
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 +72 -10
- package/dist/index.d.mts +430 -45
- package/dist/index.d.ts +430 -45
- package/dist/index.js +261 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +258 -29
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,8 +33,8 @@ const { data: earnings } = await client.earnings.get({ period: 'month' });
|
|
|
33
33
|
|
|
34
34
|
| Resource | Methods |
|
|
35
35
|
|----------|---------|
|
|
36
|
-
| `client.screens` | `list`, `get`, `create`, `delete` |
|
|
37
|
-
| `client.devices` | `list`, `get`, `create`, `delete`, `heartbeat` |
|
|
36
|
+
| `client.screens` | `list`, `get`, `create`, `delete`, `getDisplaySettings`, `patchDisplaySettings`, `updateDisplaySettings`, `batchUpdateDisplaySettings` |
|
|
37
|
+
| `client.devices` | `list`, `get`, `create`, `createBatch`, `delete`, `heartbeat` |
|
|
38
38
|
| `client.impressions` | `create`, `createBatch` |
|
|
39
39
|
| `client.analytics` | `get` |
|
|
40
40
|
| `client.earnings` | `get` |
|
|
@@ -45,6 +45,36 @@ const { data: earnings } = await client.earnings.get({ period: 'month' });
|
|
|
45
45
|
| `client.errors` | `list`, `get` |
|
|
46
46
|
| `client.billing` | `get`, `getStripeStatus`, `requestPayout` |
|
|
47
47
|
|
|
48
|
+
### Content fit
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
await client.screens.patchDisplaySettings('SCREEN_ID', {
|
|
52
|
+
content_fit: {
|
|
53
|
+
advertisements: 'fill',
|
|
54
|
+
default_streams: 'fill',
|
|
55
|
+
self_promo: 'fit',
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
await client.devices.createBatch({
|
|
60
|
+
defaults: {
|
|
61
|
+
display_settings: {
|
|
62
|
+
content_fit: { advertisements: 'fill', self_promo: 'fill' },
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
devices: [
|
|
66
|
+
{ device_id: 'screen-001' },
|
|
67
|
+
{
|
|
68
|
+
device_id: 'screen-002',
|
|
69
|
+
display_settings: { content_fit: { self_promo: 'fit' } },
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`fit` preserves the full creative and may letterbox; `fill` covers the screen
|
|
76
|
+
and may crop its edges. Omit `content_fit` to leave existing behavior unchanged.
|
|
77
|
+
|
|
48
78
|
## Error Handling
|
|
49
79
|
|
|
50
80
|
```typescript
|
|
@@ -67,20 +97,52 @@ try {
|
|
|
67
97
|
|
|
68
98
|
## Webhook Verification
|
|
69
99
|
|
|
100
|
+
Trillboards webhooks carry a Stripe-style compound signature header
|
|
101
|
+
`X-Trillboards-Signature: t=<timestamp>,v0=<hex>,v1=<hex>` and a separate
|
|
102
|
+
`X-Trillboards-Timestamp: <unix_seconds>` for redundancy.
|
|
103
|
+
|
|
104
|
+
The verifier accepts either format and rejects payloads outside a 300-second
|
|
105
|
+
replay window by default.
|
|
106
|
+
|
|
70
107
|
```typescript
|
|
71
108
|
import { Webhooks } from '@trillboards/api-client';
|
|
72
109
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
110
|
+
// Use express.raw for the webhook route so req.body is the exact signed bytes
|
|
111
|
+
app.post('/webhooks', express.raw({ type: 'application/json' }), (req, res) => {
|
|
112
|
+
try {
|
|
113
|
+
const event = Webhooks.constructEvent(
|
|
114
|
+
req.body, // raw Buffer or string (NOT JSON.parsed)
|
|
115
|
+
req.headers, // IncomingHttpHeaders — case-insensitive lookup
|
|
116
|
+
process.env.WEBHOOK_SECRET!,
|
|
117
|
+
);
|
|
118
|
+
console.log('Event:', event.type, event.data);
|
|
119
|
+
res.sendStatus(200);
|
|
120
|
+
} catch (err) {
|
|
121
|
+
// TrillboardsError with code "webhook_signature_invalid"
|
|
122
|
+
res.sendStatus(401);
|
|
123
|
+
}
|
|
81
124
|
});
|
|
82
125
|
```
|
|
83
126
|
|
|
127
|
+
Override the replay-window tolerance (default 300s):
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
const event = Webhooks.constructEvent(req.body, req.headers, secret, {
|
|
131
|
+
tolerance: 600, // 10 minutes
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
> **Upgrading from 0.2.0**: the 0.2.0 call shape
|
|
136
|
+
> `Webhooks.constructEvent(payload, signatureString, secret)` produced
|
|
137
|
+
> verification failures against the production server because the server
|
|
138
|
+
> signs `${timestamp}.${payload}` while the 0.2.0 verifier signed `payload`
|
|
139
|
+
> only. The 0.3.0 verifier handles both formats AND adds replay protection.
|
|
140
|
+
> Migrate to the new `Webhooks.constructEvent(payload, req.headers, secret)`
|
|
141
|
+
> call shape. The 0.2.0 shape is preserved as `Webhooks.constructEventLegacy`
|
|
142
|
+
> for one minor version (logs a deprecation warning).
|
|
143
|
+
|
|
144
|
+
Full webhook contract: https://api.trillboards.com/docs/integrations/webhook-signature-verification.md
|
|
145
|
+
|
|
84
146
|
## Configuration
|
|
85
147
|
|
|
86
148
|
```typescript
|