@trillboards/api-client 0.1.3 → 0.3.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2026 Trillboards, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -67,20 +67,52 @@ try {
67
67
 
68
68
  ## Webhook Verification
69
69
 
70
+ Trillboards webhooks carry a Stripe-style compound signature header
71
+ `X-Trillboards-Signature: t=<timestamp>,v0=<hex>,v1=<hex>` and a separate
72
+ `X-Trillboards-Timestamp: <unix_seconds>` for redundancy.
73
+
74
+ The verifier accepts either format and rejects payloads outside a 300-second
75
+ replay window by default.
76
+
70
77
  ```typescript
71
78
  import { Webhooks } from '@trillboards/api-client';
72
79
 
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);
80
+ // Use express.raw for the webhook route so req.body is the exact signed bytes
81
+ app.post('/webhooks', express.raw({ type: 'application/json' }), (req, res) => {
82
+ try {
83
+ const event = Webhooks.constructEvent(
84
+ req.body, // raw Buffer or string (NOT JSON.parsed)
85
+ req.headers, // IncomingHttpHeaders — case-insensitive lookup
86
+ process.env.WEBHOOK_SECRET!,
87
+ );
88
+ console.log('Event:', event.type, event.data);
89
+ res.sendStatus(200);
90
+ } catch (err) {
91
+ // TrillboardsError with code "webhook_signature_invalid"
92
+ res.sendStatus(401);
93
+ }
94
+ });
95
+ ```
96
+
97
+ Override the replay-window tolerance (default 300s):
98
+
99
+ ```typescript
100
+ const event = Webhooks.constructEvent(req.body, req.headers, secret, {
101
+ tolerance: 600, // 10 minutes
81
102
  });
82
103
  ```
83
104
 
105
+ > **Upgrading from 0.2.0**: the 0.2.0 call shape
106
+ > `Webhooks.constructEvent(payload, signatureString, secret)` produced
107
+ > verification failures against the production server because the server
108
+ > signs `${timestamp}.${payload}` while the 0.2.0 verifier signed `payload`
109
+ > only. The 0.3.0 verifier handles both formats AND adds replay protection.
110
+ > Migrate to the new `Webhooks.constructEvent(payload, req.headers, secret)`
111
+ > call shape. The 0.2.0 shape is preserved as `Webhooks.constructEventLegacy`
112
+ > for one minor version (logs a deprecation warning).
113
+
114
+ Full webhook contract: https://api.trillboards.com/docs/integrations/webhook-signature-verification.md
115
+
84
116
  ## Configuration
85
117
 
86
118
  ```typescript