vayu-ts 0.2.11 → 0.2.12
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 +27 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -193,6 +193,33 @@ await vayu.webhooks.subscribeToOverage('https://your-webhook-url.com/overage');
|
|
|
193
193
|
// Subscribe to anonymous customer creation notifications
|
|
194
194
|
await vayu.webhooks.subscribeToAnonymousCustomerCreated('https://your-webhook-url.com/your_path');
|
|
195
195
|
|
|
196
|
+
// Validate webhook security
|
|
197
|
+
app.post('/webhooks', (req, res) => {
|
|
198
|
+
const payload = JSON.stringify(req.body);
|
|
199
|
+
const timestamp = Number(req.headers['x-timestamp']);
|
|
200
|
+
const signature = String(req.headers['x-signature']);
|
|
201
|
+
|
|
202
|
+
// Important to login before verifying webhook signatures.
|
|
203
|
+
await vayu.login();
|
|
204
|
+
|
|
205
|
+
const isValid = vayu.verifyWebhookSignature({
|
|
206
|
+
payload,
|
|
207
|
+
timestamp,
|
|
208
|
+
signature,
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
if (!isValid) {
|
|
212
|
+
// Handle invalid token.
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Proceed with webhook handling
|
|
216
|
+
console.log('Webhook is valid', JSON.parse(payload));
|
|
217
|
+
|
|
218
|
+
// ... Handle event.
|
|
219
|
+
|
|
220
|
+
res.sendStatus(200);
|
|
221
|
+
});
|
|
222
|
+
|
|
196
223
|
```
|
|
197
224
|
|
|
198
225
|
## Features
|