Transformations
Transformations are powerful JavaScript functions that modify webhook payloads in real-time as they flow through your Connections. They enable you to reshape, enrich, filter, and customize webhook data before it reaches its destination, all within a secure, sandboxed environment.
Overviewā
Transformations act as programmable middleware in your webhook pipeline. When a webhook arrives at your Connection, it can be processed by a transformation before being forwarded to its destination. This allows you to:
- Adapt webhook formats between incompatible services
- Enrich payloads with additional data or computed fields
- Filter or validate incoming webhooks based on custom logic
- Inject authentication headers or signatures
- Route webhooks to different destinations based on content
- Transform data structures to match destination requirements
How Transformations Workā
Transformations are JavaScript functions that run in a secure, isolated sandbox. Each transformation:
- Receives the incoming webhook request (headers, body, method, URL)
- Processes the data using your custom JavaScript logic
- Returns a modified request object
- Forwards the transformed payload to the destination
The Transformation APIā
Every transformation must register a handler function using the addHandler
API:
addHandler('transform', async (request, context) => {
// Your transformation logic here
return modifiedRequest;
});
The handler receives two parameters:
-
request
: The incoming webhook datamethod
: HTTP method (GET, POST, etc.)url
: Original request URLheaders
: Request headers objectbody
: Request body (parsed JSON or string)
-
context
: Execution context and metadataorganizationId
: Your organization identifiersecrets
: Organization secrets (available viaprocess.env
)- Additional metadata about the execution environment
Security & Isolationā
Transformations run in a completely isolated environment powered by isolated-vm, providing enterprise-grade security:
Sandbox Featuresā
- Complete isolation: Each execution runs in a fresh, isolated context
- Memory limits: 128MB per execution (configurable)
- Timeout protection: 5-second maximum execution time
- No network access: Transformations cannot make external API calls
- No file system access: Cannot read or write files
- Controlled APIs: Only approved JavaScript APIs are available
Organization Secretsā
Transformations can securely access your organization's secrets through process.env
:
addHandler('transform', async (request, context) => {
// Access secrets securely
const apiKey = process.env.API_KEY;
const secretToken = process.env.SECRET_TOKEN;
// Use secrets in your transformation
return {
...request,
headers: {
...request.headers,
'Authorization': `Bearer ${apiKey}`,
'X-Secret-Token': secretToken
}
};
});
Secrets are:
- Encrypted at rest
- Isolated per organization
- Never logged or exposed
- Available only during execution
- Managed through the Secrets API
Performance Considerationsā
Transformations are designed for high performance with minimal latency:
Execution Limitsā
- Memory: 128MB per execution
- Timeout: 5 seconds maximum
- CPU: Shared compute resources
- Payload size: Subject to platform limits
Optimization Tipsā
- Keep transformations simple: Complex logic increases latency
- Avoid heavy computations: The 5-second timeout is strict
- Return early: Exit as soon as processing is complete
- Minimize memory usage: Large data structures consume memory quickly
- Use efficient algorithms: Choose O(n) over O(n²) operations
Error Handlingā
Transformations include comprehensive error tracking:
Error Typesā
- Syntax errors: Invalid JavaScript code
- Runtime errors: Errors during execution
- Timeout errors: Execution exceeds 5 seconds
- Memory errors: Exceeds 128MB limit
- Validation errors: Missing handler or invalid return value
Error Recoveryā
When a transformation fails:
- The error is logged with full details
- The webhook can be configured to:
- Continue with the original payload (bypass transformation)
- Fail the entire delivery
- Trigger a retry based on your retry configuration
Debuggingā
All transformation executions are logged, including:
- Input payload
- Output result
- Execution time
- Memory usage
- Error details (if any)
- Console output from your code
Access logs through:
- The Transformations API (
/api/v1/transformations/:id/logs
) - The Dashboard UI (coming soon)
- Real-time monitoring during testing
Integration with Connectionsā
Transformations seamlessly integrate into your Connection workflow:
- Create a transformation using the API
- Attach it to a Connection's destination
- Process incoming webhooks automatically
- Monitor execution through logs and metrics
Execution Flowā
Incoming Webhook ā Source ā Transformation ā Destination
ā
Transformation Logs
Async Processingā
Transformations are designed to minimize impact on webhook delivery:
- Synchronous execution: Transformation runs inline with delivery
- Asynchronous logging: Logs are written after delivery completes
- Non-blocking errors: Failed transformations don't block retries
- Performance metrics: Track transformation impact on latency
Available JavaScript APIsā
The sandbox provides a limited but useful set of JavaScript capabilities:
Supportedā
- Core JavaScript (ES2020+)
JSON.parse()
/JSON.stringify()
Array
,Object
,String
,Number
methodsPromise
andasync/await
Date
and basic time operationsMath
functionsconsole.log()
for debugging- Regular expressions
Not Availableā
fetch()
or any network APIssetTimeout()
/setInterval()
require()
/import
(no external modules)- File system operations
- Process spawning
- Direct database access
Pricing & Limitsā
Transformations are available on Team and Enterprise plans:
Team Planā
- Unlimited transformations
- 128MB memory per execution
- 5-second timeout
- Basic metrics and logging
Enterprise Planā
- Everything in Team
- Configurable memory limits
- Extended timeout options
- Advanced monitoring
- Priority support
- Custom integration assistance
Next Stepsā
Ready to start transforming your webhooks?
- Create your first transformation with our step-by-step guide
- Explore examples for common use cases
- Review best practices for production deployments
- Check the API reference for detailed endpoints
Transformations unlock the full potential of webhook automation, letting you connect any service to any other service, regardless of their native compatibility.