@joai/warps-vm-node 1.0.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # @joai/warps-vm-node
2
+
3
+ Node.js VM runtime for Warps SDK output transformations. Safely executes transformation code using vm2 in a sandboxed environment.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @joai/warps-vm-node
9
+ ```
10
+
11
+ **Note:** This package requires `vm2` as an optional dependency. Install it separately:
12
+
13
+ ```bash
14
+ npm install vm2
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```typescript
20
+ import { createNodeTransformRunner } from '@joai/warps-vm-node'
21
+ import { WarpClient } from '@joai/warps'
22
+
23
+ const config = {
24
+ env: 'mainnet',
25
+ transform: {
26
+ runner: createNodeTransformRunner(),
27
+ },
28
+ // ... rest of config
29
+ }
30
+
31
+ const client = new WarpClient(config, { chains: [...] })
32
+ ```
33
+
34
+ ## Features
35
+
36
+ - Safe code execution using vm2
37
+ - Sandboxed environment
38
+ - Supports arrow functions, regular functions, and expressions
39
+ - Error handling and timeout protection
40
+
41
+ ## How It Works
42
+
43
+ The Node.js VM uses vm2 to execute transformation code in an isolated sandbox, preventing access to Node.js globals and ensuring security.
44
+
45
+ ## Example Transformation
46
+
47
+ ```typescript
48
+ // Warp output transformation
49
+ const transform = (results) => {
50
+ return {
51
+ value: results.amount * 2,
52
+ formatted: `$${results.amount.toFixed(2)}`
53
+ }
54
+ }
55
+ ```
56
+
57
+ ## Security
58
+
59
+ The vm2 sandbox provides isolation from the Node.js runtime, preventing unauthorized access to system resources.
@@ -0,0 +1,6 @@
1
+ import { TransformRunner } from '@joai/warps';
2
+
3
+ declare const runInVm: (code: string, results: any) => Promise<any>;
4
+ declare const createNodeTransformRunner: () => TransformRunner;
5
+
6
+ export { createNodeTransformRunner, runInVm };
@@ -0,0 +1,6 @@
1
+ import { TransformRunner } from '@joai/warps';
2
+
3
+ declare const runInVm: (code: string, results: any) => Promise<any>;
4
+ declare const createNodeTransformRunner: () => TransformRunner;
5
+
6
+ export { createNodeTransformRunner, runInVm };
@@ -0,0 +1 @@
1
+ "use strict";var u=Object.create;var o=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,c=Object.prototype.hasOwnProperty;var y=(n,t)=>{for(var r in t)o(n,r,{get:t[r],enumerable:!0})},i=(n,t,r,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of f(t))!c.call(n,s)&&s!==r&&o(n,s,{get:()=>t[s],enumerable:!(e=l(t,s))||e.enumerable});return n};var d=(n,t,r)=>(r=n!=null?u(p(n)):{},i(t||!n||!n.__esModule?o(r,"default",{value:n,enumerable:!0}):r,n)),w=n=>i(o({},"__esModule",{value:!0}),n);var T={};y(T,{createNodeTransformRunner:()=>v,runInVm:()=>m});module.exports=w(T);var a=null;async function h(){if(a)return a;try{return a=await import("vm2"),a}catch(n){throw n?.code==="MODULE_NOT_FOUND"||n?.message?.includes("Cannot find module")?new Error('The optional dependency "vm2" is not installed. To use runInVm in Node.js, please install vm2: npm install vm2 --save.'):n}}var m=async(n,t)=>{try{let{VM:r}=await h(),e=new r({timeout:2e3,sandbox:{results:t},eval:!1,wasm:!1});return n.trim().startsWith("(")&&n.includes("=>")?e.run(`(${n})(results)`):n.trim().startsWith("function")?e.run(`(${n})(results)`):e.run(`(${n})`)}catch(r){throw r?.message?.includes('The optional dependency "vm2" is not installed')?r:new Error(`Transform error: ${r?.message||String(r)}`)}},v=()=>({run:m});0&&(module.exports={createNodeTransformRunner,runInVm});
@@ -0,0 +1 @@
1
+ var t=null;async function o(){if(t)return t;try{return t=await import("vm2"),t}catch(n){throw n?.code==="MODULE_NOT_FOUND"||n?.message?.includes("Cannot find module")?new Error('The optional dependency "vm2" is not installed. To use runInVm in Node.js, please install vm2: npm install vm2 --save.'):n}}var a=async(n,s)=>{try{let{VM:r}=await o(),e=new r({timeout:2e3,sandbox:{results:s},eval:!1,wasm:!1});return n.trim().startsWith("(")&&n.includes("=>")?e.run(`(${n})(results)`):n.trim().startsWith("function")?e.run(`(${n})(results)`):e.run(`(${n})`)}catch(r){throw r?.message?.includes('The optional dependency "vm2" is not installed')?r:new Error(`Transform error: ${r?.message||String(r)}`)}},i=()=>({run:a});export{i as createNodeTransformRunner,a as runInVm};
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@joai/warps-vm-node",
3
+ "version": "1.0.0-beta.10",
4
+ "type": "module",
5
+ "types": "dist/runInVm.d.ts",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "dependencies": {
10
+ "@joai/warps": "^3.0.0-beta.198",
11
+ "vm2": "^3.10.0"
12
+ },
13
+ "devDependencies": {
14
+ "jest": "^30.2.0",
15
+ "ts-jest": "^29.4.6"
16
+ },
17
+ "license": "MIT",
18
+ "scripts": {
19
+ "build": "tsup",
20
+ "test": "jest --env=node"
21
+ },
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/runInVm.d.ts",
25
+ "import": "./dist/runInVm.mjs",
26
+ "require": "./dist/runInVm.js",
27
+ "default": "./dist/runInVm.mjs"
28
+ }
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ }
33
+ }