Hooks (Before & After)
Edge Functions Overview
Pulsabase Edge Functions let you run custom server-side logic close to your data. Functions are defined as a sequence of typed steps — HTTP requests, database queries, transforms, conditionals, emails, and more — without managing infrastructure.
Invoking a Function
Section titled “Invoking a Function”// Synchronous — waits for the full resultconst result = await pb.edge('send-welcome-email').invoke({ userId: 'abc-123',});
// Async — fire and forget (does not block)await pb.edge('log-activity').invokeAsync({ userId: 'abc-123' });// Synchronousfinal result = await pb.edge('send-welcome-email').invoke({ 'userId': 'abc-123',});curl -X POST https://api.yourproject.pulsabase.io/edge/api/v1/invoke/send-welcome-email \ -H "X-Api-Key: pk_live_your_api_key" \ -H "Authorization: Bearer <user_token>" \ -H "Content-Type: application/json" \ -d '{ "userId": "abc-123" }'Sync vs. Async Execution
Section titled “Sync vs. Async Execution”Edge functions can run in two modes, chosen per invocation:
| Mode | SDK Method | Behavior |
|---|---|---|
| Synchronous | .invoke(payload) | Waits for the full result. Use for functions where you need the output (e.g., data enrichment, validation). |
| Asynchronous | .invokeAsync(payload) | Returns immediately with { "queued": true }. The function runs in the background. Use for side effects (emails, notifications, logging). |
Before hooks are always synchronous (they block the DB mutation). After hooks are always asynchronous (they run post-mutation).
Creating Functions
Section titled “Creating Functions”Edge functions are managed in Dashboard → Edge Functions:
- Click Create Function
- Name your function (used for invocation and webhook URLs)
- Add steps using the visual flow builder
- Test with the built-in dry-run executor
- Save — the function is immediately available
Step Types
Section titled “Step Types”| Step Type | Description |
|---|---|
| HTTP | Make outbound HTTP requests to external APIs |
| Database | Execute queries against your Pulsabase database |
| Transform | Manipulate data with JavaScript expressions |
| Condition | Branch the sequence based on a boolean expression |
| Loop | Iterate over an array from a previous step |
| Send emails via SMTP (Pulsabase-managed or your own) | |
| Log | Output current variables to the execution __logs |
Variable Interpolation
Section titled “Variable Interpolation”Step outputs are available to subsequent steps using {{}} syntax:
{{steps.<step_name>.body.<field>}} ← Output of a previous step{{input.<field>}} ← The invocation payload{{env.STRIPE_KEY}} ← Secure environment variable{{jwt.sub}} ← Current user's ID from JWT{{jwt.role}} ← Current user's roleExample: Multi-Step Function
Section titled “Example: Multi-Step Function”This is a process-order function that validates stock, conditionally errors, creates the order, and sends a confirmation email:
Dry Run Mode
Section titled “Dry Run Mode”Test any function without triggering real side effects — emails are not sent, HTTP calls are made but clearly flagged.
const result = await pb.edge('process-order').dryRun().invoke({ productId: 'p-123', quantity: 2,});
// Step-by-step execution logconsole.log(result.__logs);curl -X POST "https://api.yourproject.pulsabase.io/edge/api/v1/invoke/process-order?dry_run=true" \ -H "X-Api-Key: pk_live_your_api_key" \ -H "Content-Type: application/json" \ -d '{ "productId": "p-123", "quantity": 2 }'Further Reading
Section titled “Further Reading”Email & SMTP
Cron Jobs
Webhooks (Inbound)