Hookflo + Tern Webhook Skill
This skill covers two tightly related tools in the Hookflo ecosystem:
- Tern (
@hookflo/tern) — an open-source, zero-dependency TypeScript library for
verifying webhook signatures. Algorithm-agnostic, supports all major platforms.
- Hookflo — a hosted webhook event alerting and logging platform. Sends real-time
Slack/email alerts when webhooks fire. No code required on their end; you point your
provider at Hookflo's URL and configure alerts in the dashboard.
Mental Model
Incoming Webhook Request
│
▼
[Tern] verify signature ←── your server/edge function
│
isValid?
│
yes │ no
│──────► 400 / reject
│
▼
process payload
│
(optionally forward to)
▼
[Hookflo] alert + log
Slack / Email / Dashboard
Use Tern when you need programmatic signature verification in your own code.
Use Hookflo when you want no-code / low-code alerting and centralized event logs.
They can be used together or independently.
Part 1 — Tern (Webhook Verification Library)
Installation
npm install @hookflo/tern
No other dependencies required. Full TypeScript support.
Core API
WebhookVerificationService.verify(request, config)
The primary method. Returns a WebhookVerificationResult.
import { WebhookVerificationService } from '@hookflo/tern';
const result = await WebhookVerificationService.verify(request, {
platform: 'stripe',
secret: process.env.STRIPE_WEBHOOK_SECRET!,
toleranceInSeconds: 300, // replay attack protection window (optional, default 300)
});
if (result.isValid) {
console.log('Verified payload:', result.payload);
console.log('Metadata:', result.metadata); // timestamp, id, etc.
} else {
console.error('Rejected:', result.error);
// return 400
}
WebhookVerificationService.verifyWithPlatformConfig(request, platform, secret, tolerance?)
Shorthand that accepts just a platform name + secret.
const result = await WebhookVerificationService.verifyWithPlatformConfig(
request,
'github',
process.env.GITHUB_WEBHOOK_SECRET!
);
WebhookVerificationService.verifyTokenBased(request, webhookId, webhookToken)
For token-based platforms (Supabase, GitLab).
const result = await WebhookVerificationService.verifyTokenBased(
request,
process.env.SUPABASE_WEBHOOK_ID!,
process.env.SUPABASE_WEBHOOK_TOKEN!
);
WebhookVerificationResult type
interface WebhookVerificationResult {
isValid: boolean;
error?: string;
platform: WebhookPlatform;
payload?: any; // parsed JSON body
metadata?: {
timestamp?: string;
id?: string | null;
[key: string]: any;
};
}
Built-in Platform Configs
| Platform |
Algorithm |
Signature Header |
Format |
stripe |
HMAC-SHA256 |
stripe-signature |
t={ts},v1={sig} |
github |
HMAC-SHA256 |
x-hub-signature-256 |
sha256={sig} |
clerk |
HMAC-SHA256 (base64) |
svix-signature |
v1,{sig} |
supabase |
Token-based |
custom |
— |
gitlab |
Token-based |
x-gitlab-token |
— |
shopify |
HMAC-SHA256 |
x-shopify-hmac-sha256 |
raw |
vercel |
HMAC-SHA256 |
custom |
— |
polar |
HMAC-SHA256 |
custom |
— |
dodo |
HMAC-SHA256 (svix) |
webhook-signature |
v1,{sig} |
Always use the lowercase string name (e.g., 'stripe', 'github').
Custom Platform Configuration
For any provider not in the list, supply a full signatureConfig:
import { WebhookVerificationService } from '@hookflo/tern';
// Standard HMAC-SHA256 with prefix
const result = await WebhookVerificationService.verify(request, {
platform: 'acmepay',
secret: 'your_secret',
signatureConfig: {
algorithm: 'hmac-sha256',
headerName: 'x-acme-signature',
headerFormat: 'prefixed',
prefix: 'sha256=',
payloadFormat: 'raw',
},
});
// Timestamped payload (signs "{timestamp}.{body}")
const result2 = await WebhookVerificationService.verify(request, {
platform: 'mypay',
secret: 'your_secret',
signatureConfig: {
algorithm: 'hmac-sha256',
headerName: 'x-webhook-signature',
headerFormat: 'raw',
timestampHeader: 'x-webhook-timestamp',
timestampFormat: 'unix',
payloadFormat: 'timestamped',
},
});
// Svix/StandardWebhooks compatible (Clerk, Dodo, etc.)
const result3 = await WebhookVerificationService.verify(request, {
platform: 'my-svix-platform',
secret: 'whsec_abc123...',
signatureConfig: {
algorithm: 'hmac-sha256',
headerName: 'webhook-signature',
headerFormat: 'raw',
timestampHeader: 'webhook-timestamp',
timestampFormat: 'unix',
payloadFormat: 'custom',
customConfig: {
payloadFormat: '{id}.{timestamp}.{body}',
idHeader: 'webhook-id',
},
},
});
SignatureConfig fields:
algorithm: 'hmac-sha256' | 'hmac-sha1' | 'hmac-sha512' | custom
headerName: the HTTP header that carries the signature
headerFormat: 'raw' | 'prefixed' | 'comma-separated' | 'space-separated'
prefix: string prefix to strip before comparing (e.g. 'sha256=')
timestampHeader: header name for the timestamp (if any)
timestampFormat: 'unix' | 'iso' | 'ms'
payloadFormat: 'raw' | 'timestamped' | 'custom'
customConfig.payloadFormat: template like '{id}.{timestamp}.{body}'
customConfig.idHeader: header supplying the {id} value
customConfig.encoding: 'base64' if the provider base64-encodes the key
Framework Integration
Express.js
import express from 'express';
import { WebhookVerificationService } from '@hookflo/tern';
const app = express();
// IMPORTANT: use raw body parser for webhook routes
app.post(
'/webhooks/stripe',
express.raw({ type: 'application/json' }),
async (req, res) => {
const result = await WebhookVerificationService.verifyWithPlatformConfig(
req,
'stripe',
process.env.STRIPE_WEBHOOK_SECRET!
);
if (!result.isValid) {
return res.status(400).json({ error: result.error });
}
const event = result.payload;
// handle event.type, e.g. 'payment_intent.succeeded'
res.json({ received: true });
}
);
Common mistake: Express's default json() middleware consumes and re-serializes
the body, breaking HMAC. Always use express.raw() on webhook endpoints.
Next.js App Router (Route Handler)
// app/api/webhooks/github/route.ts
import { NextRequest, NextResponse } from 'next/server';
import { WebhookVerificationService } from '@hookflo/tern';
export async function POST(req: NextRequest) {
const result = await WebhookVerificationService.verifyWithPlatformConfig(
req,
'github',
process.env.GITHUB_WEBHOOK_SECRET!
);
if (!result.isValid) {
return NextResponse.json({ error: result.error }, { status: 400 });
}
const event = req.headers.get('x-github-event');
// handle event
return NextResponse.json({ received: true });
}
// Disable body parsing so Tern gets the raw body
export const config = { api: { bodyParser: false } };
Cloudflare Workers
addEventListener('fetch', (event) => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request: Request): Promise<Response> {
if (request.method === 'POST' && new URL(request.url).pathname === '/webhooks/clerk') {
const result = await WebhookVerificationService.verifyWithPlatformConfig(
request,
'clerk',
CLERK_WEBHOOK_SECRET
);
if (!result.isValid) {
return new Response(JSON.stringify({ error: result.error }), {
status: 400,
headers: { 'Content-Type': 'application/json' },
});
}
return new Response(JSON.stringify({ received: true }));
}
return new Response('Not Found', { status: 404 });
}
Platform Manager (Advanced)
import { platformManager } from '@hookflo/tern';
// Verify using the platform manager directly
const result = await platformManager.verify(request, 'stripe', 'whsec_...');
// Get the config for a platform (for inspection)
const config = platformManager.getConfig('stripe');
// Get docs/metadata for a platform
const docs = platformManager.getDocumentation('stripe');
// Run built-in tests for a platform
const passed = await platformManager.runPlatformTests('stripe');
Testing
npm test # run all tests
npm run test:platform stripe # test one platform
npm run test:all # test all platforms
Part 2 — Hookflo (Hosted Alerting Platform)
Hookflo requires no library installation. The integration is:
- Create a webhook endpoint in the Hookflo Dashboard → get a Webhook URL + Secret
- Point your provider (Stripe, Supabase, Clerk, GitHub, etc.) at that URL
- Configure Slack/email notifications in the dashboard
How to Set Up a Hookflo Integration
Step 1 — Go to hookflo.com/dashboard and create a new webhook.
You'll receive:
- Webhook URL — paste into your provider's webhook settings
- Webhook ID — used for token-based platforms
- Secret Token — used by Hookflo to verify incoming events
- Notification channel settings — configure Slack or email
Step 2 — Set up the provider to send to that Hookflo URL:
| Provider |
Where to paste the URL |
| Stripe |
Dashboard → Developers → Webhooks → Add endpoint |
| Supabase |
Dashboard → Database → Webhooks → Create webhook |
| Clerk |
Dashboard → Webhooks → Add endpoint |
| GitHub |
Repo/Org Settings → Webhooks → Add webhook |
Step 3 — In the Hookflo dashboard, configure:
- Which event types to alert on (e.g.,
payment_intent.succeeded, user.created)
- Notification channels (Slack workspace/channel, email addresses)
- Digest frequency if you want batched summaries instead of per-event alerts
Hookflo Platform Docs
Hookflo + Tern Together
If you want both programmatic verification (Tern) AND logging/alerting (Hookflo), use a proxy pattern:
// Your server receives the webhook, verifies it with Tern, then forwards to Hookflo
app.post('/webhooks/stripe', express.raw({ type: 'application/json' }), async (req, res) => {
// 1. Verify with Tern
const result = await WebhookVerificationService.verifyWithPlatformConfig(
req, 'stripe', process.env.STRIPE_WEBHOOK_SECRET!
);
if (!result.isValid) return res.status(400).json({ error: result.error });
// 2. Process locally
handleStripeEvent(result.payload);
// 3. Forward to Hookflo for alerting/logging (optional)
await fetch(process.env.HOOKFLO_WEBHOOK_URL!, {
method: 'POST',
headers: { ...req.headers, 'Content-Type': 'application/json' },
body: req.body,
});
res.json({ received: true });
});
Alternatively, point Stripe directly at your Hookflo URL and keep Tern for a different endpoint.
Common Pitfalls & Best Practices
Raw Body Requirement
HMAC signatures are computed over the exact raw bytes of the request body. Any
re-serialization (e.g., by a JSON body parser) will break verification. Always ensure:
- Express: use
express.raw({ type: 'application/json' }) on webhook routes
- Next.js Pages Router: set
export const config = { api: { bodyParser: false } }
- Next.js App Router: Tern reads the body directly from the
Request object
Replay Attack Protection
Always pass toleranceInSeconds (default is 300 = 5 minutes). This rejects requests
with timestamps too far in the past, preventing replay attacks.
Secrets Management
- Never hardcode secrets in source code
- Use environment variables:
process.env.STRIPE_WEBHOOK_SECRET
- For Cloudflare Workers: use
wrangler secret put STRIPE_WEBHOOK_SECRET
- For Vercel: add secrets in project settings
Error Responses
Always return HTTP 400 (not 500) for failed verification — this signals to the sender
that the request was rejected (not that your server crashed).
HTTPS Only
Webhook endpoints must use HTTPS in production. Never accept webhook traffic over HTTP.
Troubleshooting
| Symptom |
Likely Cause |
Fix |
isValid: false, error about signature |
Body was parsed before Tern |
Use raw body parser |
isValid: false, error about timestamp |
Clock skew or replay attack |
Check server clock; increase tolerance if dev |
isValid: false for Clerk |
Missing svix headers |
Ensure svix-id, svix-timestamp, svix-signature are forwarded |
isValid: false for GitHub |
Wrong secret |
Re-copy secret from GitHub Webhooks settings |
| Tern not finding platform |
Typo in platform name |
Use lowercase: 'stripe', 'github', 'clerk' |
| Hookflo not receiving events |
Wrong URL pasted |
Re-copy URL from Hookflo dashboard |
Key Links
1---
2name: hookflo-tern
3description: >
4 Use this skill for requests touching webhooks, event-driven infrastructure, or real-time
5 HTTP callbacks — from beginner setup to advanced security and architecture.
6
7 Relevant topics: hookflo, tern, @hookflo/tern, webhook, webhooks, web hook, HTTP callback,
8 HTTP event, event listener, event endpoint, inbound event, incoming event, event-driven,
9 event notification, real-time notification, push notification from API, API event.
10
11 Receiving / handling: receive a webhook, listen for events, handle incoming POST,
12 process webhook payload, parse webhook body, read webhook data.
13
14 Security / verification: verify webhook, validate webhook, authenticate webhook,
15 webhook signature, HMAC, HMAC-SHA256, HMAC-SHA1, HMAC-SHA512, signing secret,
16 webhook secret, replay attack, timestamp tolerance, svix, StandardWebhooks,
17 webhook security, reject fake webhooks.
18
19 Alerting / monitoring: webhook alert, notify on event, Slack alert from webhook,
20 email alert from webhook, webhook log, webhook dashboard, monitor webhooks,
21 debug webhook, webhook not firing, webhook not received, test webhook,
22 webhook history, webhook retry, webhook delivery, event log.
23
24 Integration setup: webhooks for Stripe, GitHub, Supabase, Clerk, Shopify, Vercel,
25 Polar, Dodo Payments, GitLab, Linear, PagerDuty, Twilio, SendGrid, PayPal, Braintree,
26 Square, Plaid, Lemon Squeezy, Paddle, Chargebee, Recurly, HubSpot, Salesforce,
27 Intercom, Zendesk, Jira, Notion, Airtable, Zapier, Make, n8n, Pipedream,
28 or any SaaS platform that sends HTTP POST callbacks.
29
30 Framework / code: webhook in Express, Next.js, Fastify, Hono, NestJS, Bun, Deno,
31 Cloudflare Workers, AWS Lambda, Azure Functions, Google Cloud Functions,
32 webhook endpoint, webhook route, webhook handler, raw body parser, express.raw.
33
34 Troubleshooting: signature mismatch, invalid signature, webhook failing, body already
35 parsed, HMAC not matching, webhook timeout, webhook duplicate, idempotency key.
36
37 Architecture: webhook queue, webhook fanout, forward webhook, proxy webhook,
38 webhook ingestion, event bus, event pipeline.
39
40 Note: most webhook questions will not mention "hookflo" or "tern" by name — match
41 on the underlying concepts above.
42
43metadata:
44 openclaw:
45 emoji: "🪝"
46 homepage: "https://hookflo.com"
47 source: https://skillmd.com/skills/modbender/hookflo-tern
48 upstream: "https://github.com/Hookflo/tern"
49 requires:
50 env:
51 - name: STRIPE_WEBHOOK_SECRET
52 description: "Stripe webhook signing secret (whsec_...). Required only when verifying Stripe webhooks."
53 optional: true
54 - name: GITHUB_WEBHOOK_SECRET
55 description: "GitHub webhook secret. Required only when verifying GitHub webhooks."
56 optional: true
57 - name: CLERK_WEBHOOK_SECRET
58 description: "Clerk webhook signing secret (whsec_...). Required only when verifying Clerk webhooks."
59 optional: true
60 - name: SUPABASE_WEBHOOK_ID
61 description: "Supabase webhook ID for token-based verification. Required only when verifying Supabase webhooks."
62 optional: true
63 - name: SUPABASE_WEBHOOK_TOKEN
64 description: "Supabase webhook token for token-based verification. Required only when verifying Supabase webhooks."
65 optional: true
66 bins: []
67 tags:
68 - webhooks
69 - security
70 - hmac
71 - stripe
72 - github
73 - clerk
74 - supabase
75 - notifications
76 - express
77 - nextjs
78---
79
80# Hookflo + Tern Webhook Skill
81
82This skill covers two tightly related tools in the Hookflo ecosystem:
83
841. **Tern** (`@hookflo/tern`) — an open-source, zero-dependency TypeScript library for
85 verifying webhook signatures. Algorithm-agnostic, supports all major platforms.
862. **Hookflo** — a hosted webhook event alerting and logging platform. Sends real-time
87 Slack/email alerts when webhooks fire. No code required on their end; you point your
88 provider at Hookflo's URL and configure alerts in the dashboard.
89
90---
91
92## Mental Model
93
94```
95Incoming Webhook Request
96 │
97 ▼
98 [Tern] verify signature ←── your server/edge function
99 │
100 isValid?
101 │
102 yes │ no
103 │──────► 400 / reject
104 │
105 ▼
106 process payload
107 │
108 (optionally forward to)
109 ▼
110 [Hookflo] alert + log
111 Slack / Email / Dashboard
112```
113
114Use **Tern** when you need programmatic signature verification in your own code.
115Use **Hookflo** when you want no-code / low-code alerting and centralized event logs.
116They can be used together or independently.
117
118---
119
120## Part 1 — Tern (Webhook Verification Library)
121
122### Installation
123
124```bash
125npm install @hookflo/tern
126```
127
128No other dependencies required. Full TypeScript support.
129
130### Core API
131
132#### `WebhookVerificationService.verify(request, config)`
133The primary method. Returns a `WebhookVerificationResult`.
134
135```ts
136import { WebhookVerificationService } from '@hookflo/tern';
137
138const result = await WebhookVerificationService.verify(request, {
139 platform: 'stripe',
140 secret: process.env.STRIPE_WEBHOOK_SECRET!,
141 toleranceInSeconds: 300, // replay attack protection window (optional, default 300)
142});
143
144if (result.isValid) {
145 console.log('Verified payload:', result.payload);
146 console.log('Metadata:', result.metadata); // timestamp, id, etc.
147} else {
148 console.error('Rejected:', result.error);
149 // return 400
150}
151```
152
153#### `WebhookVerificationService.verifyWithPlatformConfig(request, platform, secret, tolerance?)`
154Shorthand that accepts just a platform name + secret.
155
156```ts
157const result = await WebhookVerificationService.verifyWithPlatformConfig(
158 request,
159 'github',
160 process.env.GITHUB_WEBHOOK_SECRET!
161);
162```
163
164#### `WebhookVerificationService.verifyTokenBased(request, webhookId, webhookToken)`
165For token-based platforms (Supabase, GitLab).
166
167```ts
168const result = await WebhookVerificationService.verifyTokenBased(
169 request,
170 process.env.SUPABASE_WEBHOOK_ID!,
171 process.env.SUPABASE_WEBHOOK_TOKEN!
172);
173```
174
175### `WebhookVerificationResult` type
176
177```ts
178interface WebhookVerificationResult {
179 isValid: boolean;
180 error?: string;
181 platform: WebhookPlatform;
182 payload?: any; // parsed JSON body
183 metadata?: {
184 timestamp?: string;
185 id?: string | null;
186 [key: string]: any;
187 };
188}
189```
190
191---
192
193### Built-in Platform Configs
194
195| Platform | Algorithm | Signature Header | Format |
196|---|---|---|---|
197| `stripe` | HMAC-SHA256 | `stripe-signature` | `t={ts},v1={sig}` |
198| `github` | HMAC-SHA256 | `x-hub-signature-256` | `sha256={sig}` |
199| `clerk` | HMAC-SHA256 (base64) | `svix-signature` | `v1,{sig}` |
200| `supabase` | Token-based | custom | — |
201| `gitlab` | Token-based | `x-gitlab-token` | — |
202| `shopify` | HMAC-SHA256 | `x-shopify-hmac-sha256` | raw |
203| `vercel` | HMAC-SHA256 | custom | — |
204| `polar` | HMAC-SHA256 | custom | — |
205| `dodo` | HMAC-SHA256 (svix) | `webhook-signature` | `v1,{sig}` |
206
207Always use the lowercase string name (e.g., `'stripe'`, `'github'`).
208
209---
210
211### Custom Platform Configuration
212
213For any provider not in the list, supply a full `signatureConfig`:
214
215```ts
216import { WebhookVerificationService } from '@hookflo/tern';
217
218// Standard HMAC-SHA256 with prefix
219const result = await WebhookVerificationService.verify(request, {
220 platform: 'acmepay',
221 secret: 'your_secret',
222 signatureConfig: {
223 algorithm: 'hmac-sha256',
224 headerName: 'x-acme-signature',
225 headerFormat: 'prefixed',
226 prefix: 'sha256=',
227 payloadFormat: 'raw',
228 },
229});
230
231// Timestamped payload (signs "{timestamp}.{body}")
232const result2 = await WebhookVerificationService.verify(request, {
233 platform: 'mypay',
234 secret: 'your_secret',
235 signatureConfig: {
236 algorithm: 'hmac-sha256',
237 headerName: 'x-webhook-signature',
238 headerFormat: 'raw',
239 timestampHeader: 'x-webhook-timestamp',
240 timestampFormat: 'unix',
241 payloadFormat: 'timestamped',
242 },
243});
244
245// Svix/StandardWebhooks compatible (Clerk, Dodo, etc.)
246const result3 = await WebhookVerificationService.verify(request, {
247 platform: 'my-svix-platform',
248 secret: 'whsec_abc123...',
249 signatureConfig: {
250 algorithm: 'hmac-sha256',
251 headerName: 'webhook-signature',
252 headerFormat: 'raw',
253 timestampHeader: 'webhook-timestamp',
254 timestampFormat: 'unix',
255 payloadFormat: 'custom',
256 customConfig: {
257 payloadFormat: '{id}.{timestamp}.{body}',
258 idHeader: 'webhook-id',
259 },
260 },
261});
262```
263
264**`SignatureConfig` fields:**
265- `algorithm`: `'hmac-sha256'` | `'hmac-sha1'` | `'hmac-sha512'` | custom
266- `headerName`: the HTTP header that carries the signature
267- `headerFormat`: `'raw'` | `'prefixed'` | `'comma-separated'` | `'space-separated'`
268- `prefix`: string prefix to strip before comparing (e.g. `'sha256='`)
269- `timestampHeader`: header name for the timestamp (if any)
270- `timestampFormat`: `'unix'` | `'iso'` | `'ms'`
271- `payloadFormat`: `'raw'` | `'timestamped'` | `'custom'`
272- `customConfig.payloadFormat`: template like `'{id}.{timestamp}.{body}'`
273- `customConfig.idHeader`: header supplying the `{id}` value
274- `customConfig.encoding`: `'base64'` if the provider base64-encodes the key
275
276---
277
278### Framework Integration
279
280#### Express.js
281
282```ts
283import express from 'express';
284import { WebhookVerificationService } from '@hookflo/tern';
285
286const app = express();
287
288// IMPORTANT: use raw body parser for webhook routes
289app.post(
290 '/webhooks/stripe',
291 express.raw({ type: 'application/json' }),
292 async (req, res) => {
293 const result = await WebhookVerificationService.verifyWithPlatformConfig(
294 req,
295 'stripe',
296 process.env.STRIPE_WEBHOOK_SECRET!
297 );
298
299 if (!result.isValid) {
300 return res.status(400).json({ error: result.error });
301 }
302
303 const event = result.payload;
304 // handle event.type, e.g. 'payment_intent.succeeded'
305
306 res.json({ received: true });
307 }
308);
309```
310
311> **Common mistake**: Express's default `json()` middleware consumes and re-serializes
312> the body, breaking HMAC. Always use `express.raw()` on webhook endpoints.
313
314#### Next.js App Router (Route Handler)
315
316```ts
317// app/api/webhooks/github/route.ts
318import { NextRequest, NextResponse } from 'next/server';
319import { WebhookVerificationService } from '@hookflo/tern';
320
321export async function POST(req: NextRequest) {
322 const result = await WebhookVerificationService.verifyWithPlatformConfig(
323 req,
324 'github',
325 process.env.GITHUB_WEBHOOK_SECRET!
326 );
327
328 if (!result.isValid) {
329 return NextResponse.json({ error: result.error }, { status: 400 });
330 }
331
332 const event = req.headers.get('x-github-event');
333 // handle event
334
335 return NextResponse.json({ received: true });
336}
337
338// Disable body parsing so Tern gets the raw body
339export const config = { api: { bodyParser: false } };
340```
341
342#### Cloudflare Workers
343
344```ts
345addEventListener('fetch', (event) => {
346 event.respondWith(handleRequest(event.request));
347});
348
349async function handleRequest(request: Request): Promise<Response> {
350 if (request.method === 'POST' && new URL(request.url).pathname === '/webhooks/clerk') {
351 const result = await WebhookVerificationService.verifyWithPlatformConfig(
352 request,
353 'clerk',
354 CLERK_WEBHOOK_SECRET
355 );
356
357 if (!result.isValid) {
358 return new Response(JSON.stringify({ error: result.error }), {
359 status: 400,
360 headers: { 'Content-Type': 'application/json' },
361 });
362 }
363
364 return new Response(JSON.stringify({ received: true }));
365 }
366
367 return new Response('Not Found', { status: 404 });
368}
369```
370
371---
372
373### Platform Manager (Advanced)
374
375```ts
376import { platformManager } from '@hookflo/tern';
377
378// Verify using the platform manager directly
379const result = await platformManager.verify(request, 'stripe', 'whsec_...');
380
381// Get the config for a platform (for inspection)
382const config = platformManager.getConfig('stripe');
383
384// Get docs/metadata for a platform
385const docs = platformManager.getDocumentation('stripe');
386
387// Run built-in tests for a platform
388const passed = await platformManager.runPlatformTests('stripe');
389```
390
391---
392
393### Testing
394
395```bash
396npm test # run all tests
397npm run test:platform stripe # test one platform
398npm run test:all # test all platforms
399```
400
401---
402
403## Part 2 — Hookflo (Hosted Alerting Platform)
404
405Hookflo requires **no library installation**. The integration is:
4061. Create a webhook endpoint in the Hookflo Dashboard → get a Webhook URL + Secret
4072. Point your provider (Stripe, Supabase, Clerk, GitHub, etc.) at that URL
4083. Configure Slack/email notifications in the dashboard
409
410### How to Set Up a Hookflo Integration
411
412**Step 1** — Go to [hookflo.com/dashboard](https://hookflo.com/dashboard/webhooks) and create a new webhook.
413You'll receive:
414- **Webhook URL** — paste into your provider's webhook settings
415- **Webhook ID** — used for token-based platforms
416- **Secret Token** — used by Hookflo to verify incoming events
417- **Notification channel settings** — configure Slack or email
418
419**Step 2** — Set up the provider to send to that Hookflo URL:
420
421| Provider | Where to paste the URL |
422|---|---|
423| Stripe | Dashboard → Developers → Webhooks → Add endpoint |
424| Supabase | Dashboard → Database → Webhooks → Create webhook |
425| Clerk | Dashboard → Webhooks → Add endpoint |
426| GitHub | Repo/Org Settings → Webhooks → Add webhook |
427
428**Step 3** — In the Hookflo dashboard, configure:
429- Which event types to alert on (e.g., `payment_intent.succeeded`, `user.created`)
430- Notification channels (Slack workspace/channel, email addresses)
431- Digest frequency if you want batched summaries instead of per-event alerts
432
433### Hookflo Platform Docs
434
435- **Stripe**: [docs.hookflo.com/webhook-platforms/stripe](https://docs.hookflo.com/webhook-platforms/stripe)
436- **Supabase**: [docs.hookflo.com/webhook-platforms/supabase](https://docs.hookflo.com/webhook-platforms/supabase)
437- **Clerk**: [docs.hookflo.com/webhook-platforms/clerk](https://docs.hookflo.com/webhook-platforms/clerk)
438- **GitHub**: [docs.hookflo.com/webhook-platforms/github](https://docs.hookflo.com/webhook-platforms/github)
439- **Slack notifications**: [docs.hookflo.com/notification-channels/slack](https://docs.hookflo.com/notification-channels/slack)
440
441### Hookflo + Tern Together
442
443If you want both programmatic verification (Tern) AND logging/alerting (Hookflo), use a proxy pattern:
444
445```ts
446// Your server receives the webhook, verifies it with Tern, then forwards to Hookflo
447app.post('/webhooks/stripe', express.raw({ type: 'application/json' }), async (req, res) => {
448 // 1. Verify with Tern
449 const result = await WebhookVerificationService.verifyWithPlatformConfig(
450 req, 'stripe', process.env.STRIPE_WEBHOOK_SECRET!
451 );
452 if (!result.isValid) return res.status(400).json({ error: result.error });
453
454 // 2. Process locally
455 handleStripeEvent(result.payload);
456
457 // 3. Forward to Hookflo for alerting/logging (optional)
458 await fetch(process.env.HOOKFLO_WEBHOOK_URL!, {
459 method: 'POST',
460 headers: { ...req.headers, 'Content-Type': 'application/json' },
461 body: req.body,
462 });
463
464 res.json({ received: true });
465});
466```
467
468Alternatively, point Stripe directly at your Hookflo URL and keep Tern for a different endpoint.
469
470---
471
472## Common Pitfalls & Best Practices
473
474### Raw Body Requirement
475HMAC signatures are computed over the **exact raw bytes** of the request body. Any
476re-serialization (e.g., by a JSON body parser) will break verification. Always ensure:
477- Express: use `express.raw({ type: 'application/json' })` on webhook routes
478- Next.js Pages Router: set `export const config = { api: { bodyParser: false } }`
479- Next.js App Router: Tern reads the body directly from the `Request` object
480
481### Replay Attack Protection
482Always pass `toleranceInSeconds` (default is 300 = 5 minutes). This rejects requests
483with timestamps too far in the past, preventing replay attacks.
484
485### Secrets Management
486- Never hardcode secrets in source code
487- Use environment variables: `process.env.STRIPE_WEBHOOK_SECRET`
488- For Cloudflare Workers: use `wrangler secret put STRIPE_WEBHOOK_SECRET`
489- For Vercel: add secrets in project settings
490
491### Error Responses
492Always return HTTP 400 (not 500) for failed verification — this signals to the sender
493that the request was rejected (not that your server crashed).
494
495### HTTPS Only
496Webhook endpoints must use HTTPS in production. Never accept webhook traffic over HTTP.
497
498---
499
500## Troubleshooting
501
502| Symptom | Likely Cause | Fix |
503|---|---|---|
504| `isValid: false`, error about signature | Body was parsed before Tern | Use raw body parser |
505| `isValid: false`, error about timestamp | Clock skew or replay attack | Check server clock; increase tolerance if dev |
506| `isValid: false` for Clerk | Missing svix headers | Ensure `svix-id`, `svix-timestamp`, `svix-signature` are forwarded |
507| `isValid: false` for GitHub | Wrong secret | Re-copy secret from GitHub Webhooks settings |
508| Tern not finding platform | Typo in platform name | Use lowercase: `'stripe'`, `'github'`, `'clerk'` |
509| Hookflo not receiving events | Wrong URL pasted | Re-copy URL from Hookflo dashboard |
510
511---
512
513## Key Links
514
515- **Tern GitHub**: https://github.com/Hookflo/tern
516- **Tern npm**: https://www.npmjs.com/package/@hookflo/tern
517- **Tern docs**: https://tern.hookflo.com
518- **Hookflo homepage**: https://hookflo.com
519- **Hookflo dashboard**: https://hookflo.com/dashboard
520- **Hookflo docs**: https://docs.hookflo.com
521- **Hookflo Discord**: https://discord.com/invite/SNmCjU97nr