n8n-nodes-daytona-tool 0.1.5 → 0.1.7

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 CHANGED
@@ -10,6 +10,7 @@ Programmatic n8n community nodes for managing Daytona sandboxes and running Node
10
10
  - Daytona Start Sandbox
11
11
  - Daytona Stop Sandbox
12
12
  - Daytona Upload File
13
+ - Daytona Execute Command
13
14
 
14
15
  ## Credentials
15
16
 
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ const RunCode_node_1 = require("./nodes/Daytona/RunCode.node");
8
8
  const StartSandbox_node_1 = require("./nodes/Daytona/StartSandbox.node");
9
9
  const StopSandbox_node_1 = require("./nodes/Daytona/StopSandbox.node");
10
10
  const UploadFile_node_1 = require("./nodes/Daytona/UploadFile.node");
11
+ const ExecuteCommand_node_1 = require("./nodes/Daytona/ExecuteCommand.node");
11
12
  exports.credentials = [new DaytonaApi_credentials_1.DaytonaApi()];
12
13
  exports.nodes = [
13
14
  new CreateSandbox_node_1.CreateSandbox(),
@@ -16,4 +17,5 @@ exports.nodes = [
16
17
  new StartSandbox_node_1.StartSandbox(),
17
18
  new StopSandbox_node_1.StopSandbox(),
18
19
  new UploadFile_node_1.UploadFile(),
20
+ new ExecuteCommand_node_1.ExecuteCommand(),
19
21
  ];
@@ -8,6 +8,7 @@ type SandboxCreateInput = {
8
8
  name?: string;
9
9
  sessionId?: string;
10
10
  runtime?: string;
11
+ envVars?: Record<string, string>;
11
12
  };
12
13
  export declare const createDaytonaClient: (config: DaytonaConfig) => Daytona;
13
14
  export declare const createSandbox: (client: any, input: SandboxCreateInput) => Promise<any>;
@@ -17,6 +18,7 @@ export declare const runNodeCode: (sandbox: any, code: string, timeoutMs?: numbe
17
18
  export declare const disposeSandbox: (sandbox: any) => Promise<any>;
18
19
  export declare const startSandbox: (sandbox: any) => Promise<any>;
19
20
  export declare const stopSandbox: (sandbox: any) => Promise<any>;
21
+ export declare const executeSandboxCommand: (sandbox: any, command: string, cwd?: string, env?: Record<string, string>, timeoutSeconds?: number) => Promise<any>;
20
22
  export declare const createSandboxFile: (content: string, name: string, contentType?: string) => Readable;
21
23
  export declare const uploadSandboxFile: (sandbox: any, remotePath: string, file: any) => Promise<any>;
22
24
  export declare const uploadSandboxFileFromContent: (sandbox: any, remotePath: string, content: string, fileName: string) => Promise<any>;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.uploadSandboxFileFromContent = exports.uploadSandboxFile = exports.createSandboxFile = exports.stopSandbox = exports.startSandbox = exports.disposeSandbox = exports.runNodeCode = exports.getSandboxByName = exports.getSandbox = exports.createSandbox = exports.createDaytonaClient = void 0;
6
+ exports.uploadSandboxFileFromContent = exports.uploadSandboxFile = exports.createSandboxFile = exports.executeSandboxCommand = exports.stopSandbox = exports.startSandbox = exports.disposeSandbox = exports.runNodeCode = exports.getSandboxByName = exports.getSandbox = exports.createSandbox = exports.createDaytonaClient = void 0;
7
7
  const sdk_1 = require("@daytonaio/sdk");
8
8
  const node_stream_1 = require("node:stream");
9
9
  const promises_1 = __importDefault(require("node:fs/promises"));
@@ -33,6 +33,7 @@ const createSandbox = async (client, input) => {
33
33
  const createArgs = {
34
34
  name: input.name,
35
35
  language: input.runtime,
36
+ envVars: input.envVars,
36
37
  labels: input.sessionId ? { sessionId: input.sessionId } : undefined,
37
38
  };
38
39
  return createFn.call((_a = client === null || client === void 0 ? void 0 : client.sandbox) !== null && _a !== void 0 ? _a : client, createArgs);
@@ -100,6 +101,16 @@ const stopSandbox = async (sandbox) => {
100
101
  return stopFn.call(sandbox);
101
102
  };
102
103
  exports.stopSandbox = stopSandbox;
104
+ const executeSandboxCommand = async (sandbox, command, cwd, env, timeoutSeconds) => {
105
+ var _a, _b;
106
+ const processApi = (_a = sandbox === null || sandbox === void 0 ? void 0 : sandbox.process) !== null && _a !== void 0 ? _a : sandbox;
107
+ const executeFn = (_b = processApi === null || processApi === void 0 ? void 0 : processApi.executeCommand) !== null && _b !== void 0 ? _b : processApi === null || processApi === void 0 ? void 0 : processApi.runCommand;
108
+ if (!executeFn) {
109
+ throw new Error('Daytona SDK: execute command method not found.');
110
+ }
111
+ return executeFn.call(processApi, command, cwd, env, timeoutSeconds);
112
+ };
113
+ exports.executeSandboxCommand = executeSandboxCommand;
103
114
  const createSandboxFile = (content, name, contentType) => {
104
115
  const buffer = Buffer.from(content, 'utf8');
105
116
  const stream = node_stream_1.Readable.from(buffer);
@@ -45,11 +45,41 @@ class CreateSandbox {
45
45
  default: 'nodejs',
46
46
  description: 'Runtime/language to provision in the sandbox.',
47
47
  },
48
+ {
49
+ displayName: 'Env Vars',
50
+ name: 'envVars',
51
+ type: 'fixedCollection',
52
+ typeOptions: {
53
+ multipleValues: true,
54
+ },
55
+ default: {},
56
+ description: 'Environment variables to set in the sandbox.',
57
+ options: [
58
+ {
59
+ name: 'entries',
60
+ displayName: 'Entry',
61
+ values: [
62
+ {
63
+ displayName: 'Key',
64
+ name: 'key',
65
+ type: 'string',
66
+ default: '',
67
+ },
68
+ {
69
+ displayName: 'Value',
70
+ name: 'value',
71
+ type: 'string',
72
+ default: '',
73
+ },
74
+ ],
75
+ },
76
+ ],
77
+ },
48
78
  ],
49
79
  };
50
80
  }
51
81
  async execute() {
52
- var _a, _b, _c, _d;
82
+ var _a, _b, _c, _d, _e;
53
83
  const items = this.getInputData();
54
84
  const credentials = await this.getCredentials('daytonaApi');
55
85
  const client = (0, daytonaClient_1.createDaytonaClient)({
@@ -61,16 +91,29 @@ class CreateSandbox {
61
91
  const sessionId = this.getNodeParameter('sessionId', i);
62
92
  const sandboxName = this.getNodeParameter('sandboxName', i);
63
93
  const runtime = this.getNodeParameter('runtime', i);
94
+ const envVarsRaw = this.getNodeParameter('envVars', i);
95
+ const envVars = ((_a = envVarsRaw === null || envVarsRaw === void 0 ? void 0 : envVarsRaw.entries) === null || _a === void 0 ? void 0 : _a.length)
96
+ ? envVarsRaw.entries.reduce((acc, entry) => {
97
+ var _a;
98
+ const key = ((entry === null || entry === void 0 ? void 0 : entry.key) || '').trim();
99
+ if (!key) {
100
+ return acc;
101
+ }
102
+ acc[key] = (_a = entry === null || entry === void 0 ? void 0 : entry.value) !== null && _a !== void 0 ? _a : '';
103
+ return acc;
104
+ }, {})
105
+ : undefined;
64
106
  const sandbox = await (0, daytonaClient_1.createSandbox)(client, {
65
107
  name: sandboxName || undefined,
66
108
  sessionId,
67
109
  runtime,
110
+ envVars,
68
111
  });
69
112
  returnData.push({
70
113
  json: {
71
114
  sessionId,
72
- sandboxId: (_b = (_a = sandbox === null || sandbox === void 0 ? void 0 : sandbox.id) !== null && _a !== void 0 ? _a : sandbox === null || sandbox === void 0 ? void 0 : sandbox.sandboxId) !== null && _b !== void 0 ? _b : (_c = sandbox === null || sandbox === void 0 ? void 0 : sandbox.metadata) === null || _c === void 0 ? void 0 : _c.id,
73
- name: (_d = sandbox === null || sandbox === void 0 ? void 0 : sandbox.name) !== null && _d !== void 0 ? _d : sandboxName,
115
+ sandboxId: (_c = (_b = sandbox === null || sandbox === void 0 ? void 0 : sandbox.id) !== null && _b !== void 0 ? _b : sandbox === null || sandbox === void 0 ? void 0 : sandbox.sandboxId) !== null && _c !== void 0 ? _c : (_d = sandbox === null || sandbox === void 0 ? void 0 : sandbox.metadata) === null || _d === void 0 ? void 0 : _d.id,
116
+ name: (_e = sandbox === null || sandbox === void 0 ? void 0 : sandbox.name) !== null && _e !== void 0 ? _e : sandboxName,
74
117
  runtime,
75
118
  raw: sandbox !== null && sandbox !== void 0 ? sandbox : null,
76
119
  },
@@ -0,0 +1,5 @@
1
+ import type { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
2
+ export declare class ExecuteCommand implements INodeType {
3
+ description: INodeTypeDescription;
4
+ execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
5
+ }
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExecuteCommand = void 0;
4
+ const daytonaClient_1 = require("../../lib/daytonaClient");
5
+ class ExecuteCommand {
6
+ constructor() {
7
+ this.description = {
8
+ displayName: 'Daytona Execute Command',
9
+ name: 'daytonaExecuteCommand',
10
+ group: ['transform'],
11
+ version: 1,
12
+ description: 'Execute a shell command in a Daytona sandbox.',
13
+ defaults: {
14
+ name: 'Daytona Execute Command',
15
+ },
16
+ inputs: ['main'],
17
+ outputs: ['main'],
18
+ usableAsTool: true,
19
+ credentials: [
20
+ {
21
+ name: 'daytonaApi',
22
+ required: true,
23
+ },
24
+ ],
25
+ properties: [
26
+ {
27
+ displayName: 'Identifier',
28
+ name: 'identifier',
29
+ type: 'string',
30
+ default: '',
31
+ required: true,
32
+ description: 'Sandbox ID or name.',
33
+ },
34
+ {
35
+ displayName: 'Identifier Type',
36
+ name: 'identifierType',
37
+ type: 'options',
38
+ default: 'id',
39
+ options: [
40
+ {
41
+ name: 'ID',
42
+ value: 'id',
43
+ },
44
+ {
45
+ name: 'Name',
46
+ value: 'name',
47
+ },
48
+ ],
49
+ },
50
+ {
51
+ displayName: 'Command',
52
+ name: 'command',
53
+ type: 'string',
54
+ typeOptions: {
55
+ rows: 4,
56
+ },
57
+ default: '',
58
+ required: true,
59
+ description: 'Shell command to execute.',
60
+ },
61
+ {
62
+ displayName: 'Working Directory',
63
+ name: 'cwd',
64
+ type: 'string',
65
+ default: '',
66
+ description: 'Optional working directory (for example: workspace).',
67
+ },
68
+ {
69
+ displayName: 'Env Vars',
70
+ name: 'envVars',
71
+ type: 'fixedCollection',
72
+ typeOptions: {
73
+ multipleValues: true,
74
+ },
75
+ default: {},
76
+ description: 'Environment variables for the command.',
77
+ options: [
78
+ {
79
+ name: 'entries',
80
+ displayName: 'Entry',
81
+ values: [
82
+ {
83
+ displayName: 'Key',
84
+ name: 'key',
85
+ type: 'string',
86
+ default: '',
87
+ },
88
+ {
89
+ displayName: 'Value',
90
+ name: 'value',
91
+ type: 'string',
92
+ default: '',
93
+ },
94
+ ],
95
+ },
96
+ ],
97
+ },
98
+ {
99
+ displayName: 'Timeout (seconds)',
100
+ name: 'timeoutSeconds',
101
+ type: 'number',
102
+ default: 0,
103
+ description: 'Maximum time in seconds to wait. 0 waits indefinitely.',
104
+ },
105
+ ],
106
+ };
107
+ }
108
+ async execute() {
109
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
110
+ const items = this.getInputData();
111
+ const credentials = await this.getCredentials('daytonaApi');
112
+ const client = (0, daytonaClient_1.createDaytonaClient)({
113
+ baseUrl: credentials.baseUrl,
114
+ token: credentials.token,
115
+ });
116
+ const returnData = [];
117
+ for (let i = 0; i < items.length; i++) {
118
+ const identifier = this.getNodeParameter('identifier', i);
119
+ const identifierType = this.getNodeParameter('identifierType', i);
120
+ const command = this.getNodeParameter('command', i);
121
+ const cwd = this.getNodeParameter('cwd', i) || undefined;
122
+ const timeoutSeconds = this.getNodeParameter('timeoutSeconds', i);
123
+ const envVarsRaw = this.getNodeParameter('envVars', i);
124
+ const envVars = ((_a = envVarsRaw === null || envVarsRaw === void 0 ? void 0 : envVarsRaw.entries) === null || _a === void 0 ? void 0 : _a.length)
125
+ ? envVarsRaw.entries.reduce((acc, entry) => {
126
+ var _a;
127
+ const key = ((entry === null || entry === void 0 ? void 0 : entry.key) || '').trim();
128
+ if (!key) {
129
+ return acc;
130
+ }
131
+ acc[key] = (_a = entry === null || entry === void 0 ? void 0 : entry.value) !== null && _a !== void 0 ? _a : '';
132
+ return acc;
133
+ }, {})
134
+ : undefined;
135
+ const sandbox = identifierType === 'name'
136
+ ? await (0, daytonaClient_1.getSandboxByName)(client, identifier)
137
+ : await (0, daytonaClient_1.getSandbox)(client, identifier);
138
+ const result = await (0, daytonaClient_1.executeSandboxCommand)(sandbox, command, cwd, envVars, timeoutSeconds > 0 ? timeoutSeconds : undefined);
139
+ returnData.push({
140
+ json: {
141
+ identifier,
142
+ identifierType,
143
+ sandboxId: (_c = (_b = sandbox === null || sandbox === void 0 ? void 0 : sandbox.id) !== null && _b !== void 0 ? _b : sandbox === null || sandbox === void 0 ? void 0 : sandbox.sandboxId) !== null && _c !== void 0 ? _c : (_d = sandbox === null || sandbox === void 0 ? void 0 : sandbox.metadata) === null || _d === void 0 ? void 0 : _d.id,
144
+ name: (_e = sandbox === null || sandbox === void 0 ? void 0 : sandbox.name) !== null && _e !== void 0 ? _e : (_f = sandbox === null || sandbox === void 0 ? void 0 : sandbox.metadata) === null || _f === void 0 ? void 0 : _f.name,
145
+ command,
146
+ cwd,
147
+ exitCode: (_h = (_g = result === null || result === void 0 ? void 0 : result.exitCode) !== null && _g !== void 0 ? _g : result === null || result === void 0 ? void 0 : result.code) !== null && _h !== void 0 ? _h : result === null || result === void 0 ? void 0 : result.status,
148
+ stdout: (_k = (_j = result === null || result === void 0 ? void 0 : result.stdout) !== null && _j !== void 0 ? _j : result === null || result === void 0 ? void 0 : result.result) !== null && _k !== void 0 ? _k : result === null || result === void 0 ? void 0 : result.output,
149
+ stderr: (_l = result === null || result === void 0 ? void 0 : result.stderr) !== null && _l !== void 0 ? _l : result === null || result === void 0 ? void 0 : result.error,
150
+ raw: result !== null && result !== void 0 ? result : null,
151
+ },
152
+ });
153
+ }
154
+ return [returnData];
155
+ }
156
+ }
157
+ exports.ExecuteCommand = ExecuteCommand;
@@ -0,0 +1,20 @@
1
+ {
2
+ "node": "n8n-nodes-daytona-tool.ExecuteCommand",
3
+ "nodeVersion": "1.0",
4
+ "codexVersion": "1.0",
5
+ "categories": [
6
+ "Development"
7
+ ],
8
+ "resources": {
9
+ "credentialDocumentation": [
10
+ {
11
+ "url": "https://www.daytona.io/docs/en/typescript-sdk/process/"
12
+ }
13
+ ],
14
+ "primaryDocumentation": [
15
+ {
16
+ "url": "https://www.daytona.io/docs/en/typescript-sdk/process/"
17
+ }
18
+ ]
19
+ }
20
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-daytona-tool",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "n8n community nodes for running code in Daytona sandboxes.",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",
@@ -47,7 +47,8 @@
47
47
  "dist/nodes/Daytona/DisposeSandbox.node.js",
48
48
  "dist/nodes/Daytona/StartSandbox.node.js",
49
49
  "dist/nodes/Daytona/StopSandbox.node.js",
50
- "dist/nodes/Daytona/UploadFile.node.js"
50
+ "dist/nodes/Daytona/UploadFile.node.js",
51
+ "dist/nodes/Daytona/ExecuteCommand.node.js"
51
52
  ]
52
53
  }
53
54
  }