@joai/warps-vm-node
v1.0.0-beta.10
Published
Node.js VM runtime for Warps SDK output transformations. Safely executes transformation code using vm2 in a sandboxed environment.
Readme
@joai/warps-vm-node
Node.js VM runtime for Warps SDK output transformations. Safely executes transformation code using vm2 in a sandboxed environment.
Installation
npm install @joai/warps-vm-nodeNote: This package requires vm2 as an optional dependency. Install it separately:
npm install vm2Usage
import { createNodeTransformRunner } from '@joai/warps-vm-node'
import { WarpClient } from '@joai/warps'
const config = {
env: 'mainnet',
transform: {
runner: createNodeTransformRunner(),
},
// ... rest of config
}
const client = new WarpClient(config, { chains: [...] })Features
- Safe code execution using vm2
- Sandboxed environment
- Supports arrow functions, regular functions, and expressions
- Error handling and timeout protection
How It Works
The Node.js VM uses vm2 to execute transformation code in an isolated sandbox, preventing access to Node.js globals and ensuring security.
Example Transformation
// Warp output transformation
const transform = (results) => {
return {
value: results.amount * 2,
formatted: `$${results.amount.toFixed(2)}`
}
}Security
The vm2 sandbox provides isolation from the Node.js runtime, preventing unauthorized access to system resources.
