corsair.ts
Before Hooks
Before hooks run before an operation executes. Use them to:- Log or audit actions
- Validate or modify input
- Add default values
- Short-circuit operations
Modify Arguments
Transform the arguments before the API call is made.corsair.ts
Validate Input
Check conditions before proceeding.corsair.ts
Log Actions
Track every API call for debugging or auditing.corsair.ts
After Hooks
After hooks run after an operation completes. Use them to:- Log results
- Trigger side effects
- Transform responses
- Send notifications
Send Notifications
Notify your team when something happens.corsair.ts
Log Results
Track successful operations.corsair.ts
API Hooks
API hooks are defined underhooks in your plugin configuration. They follow the structure: hooks.[resource].[action].before/after.
corsair.ts
Webhook Hooks
Webhook hooks are defined underwebhookHooks. They guarantee your logic runs every time a webhook is processed — even if Corsair handles the database update automatically.
corsair.ts
Context Object
Both before and after hooks receive actx object with useful properties:
ctx.options— Plugin configuration optionsctx.db— Database service clients for this pluginctx.endpoints— Bound API endpoints (call other APIs within hooks)
example.ts
Hook Order
When both plugin-level and operation-level hooks exist:- Before hooks run in order: plugin → operation
- The operation executes
- After hooks run in order: operation → plugin