webhook-handler.ts
Note that webhooks are not guaranteed by most senders. If your project requires completely fresh data, add polling for that integration using an api call.
Automatic Routing
Point all your webhooks to a single endpoint. Corsair inspects the headers and payload to determine:- Which integration the webhook is from (Slack, Linear, etc.)
- Which event type it represents (message, issue created, etc.)
- Which tenant it belongs to (in multi-tenant setups)
Handling Out-of-Order Webhooks
Webhooks don’t guarantee delivery order. You might receive an “updated” event before you’ve processed the “created” event. Most applications fail here — they don’t know about a record, so they can’t process its update. Corsair solves this automatically:- Detects when an update arrives for an unknown record
- Fetches the latest data from the API
- Creates the record in your database
- Processes both the create and update
Multi-Tenancy with Webhooks
If you have multi-tenancy enabled, we recommend adding a hashed tenant ID as a query parameter to your webhook URL.Signature Verification
Corsair automatically verifies webhook signatures using your stored webhook credentials. If a signature doesn’t match, the webhook is rejected — protecting you from spoofed requests.Webhook Hooks
Hooks let you add custom logic that runs every time a webhook is processed. This guarantees your code executes — even when Corsair handles the database update automatically.corsair.ts
Before Hooks
Before hooks run before the webhook is processed. Use them to:- Validate the payload
- Log incoming webhooks
- Modify the payload before processing
- Skip processing by throwing an error
corsair.ts
After Hooks
After hooks run after the webhook is processed and the database is updated. Use them to:- Trigger side effects (notifications, syncs)
- Update related records in your application
- Send data to external services
- Log processed webhooks
corsair.ts
Guaranteed Execution
The key benefit of webhook hooks is they always run when that webhook type is processed. Unlike manually handling webhooks where you might forget to add logging or notifications, hooks ensure your logic is centralized and guaranteed to execute.corsair.ts