n8n-nodes-daytona-tool 0.1.4 → 0.1.6
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.
|
@@ -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>;
|
|
@@ -19,4 +20,5 @@ export declare const startSandbox: (sandbox: any) => Promise<any>;
|
|
|
19
20
|
export declare const stopSandbox: (sandbox: any) => Promise<any>;
|
|
20
21
|
export declare const createSandboxFile: (content: string, name: string, contentType?: string) => Readable;
|
|
21
22
|
export declare const uploadSandboxFile: (sandbox: any, remotePath: string, file: any) => Promise<any>;
|
|
23
|
+
export declare const uploadSandboxFileFromContent: (sandbox: any, remotePath: string, content: string, fileName: string) => Promise<any>;
|
|
22
24
|
export {};
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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.stopSandbox = exports.startSandbox = exports.disposeSandbox = exports.runNodeCode = exports.getSandboxByName = exports.getSandbox = exports.createSandbox = exports.createDaytonaClient = void 0;
|
|
4
7
|
const sdk_1 = require("@daytonaio/sdk");
|
|
5
8
|
const node_stream_1 = require("node:stream");
|
|
9
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
10
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
11
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
6
12
|
const getCreateFn = (client) => { var _a, _b; return (_a = client === null || client === void 0 ? void 0 : client.create) !== null && _a !== void 0 ? _a : (_b = client === null || client === void 0 ? void 0 : client.sandbox) === null || _b === void 0 ? void 0 : _b.create; };
|
|
7
13
|
const getFetchFn = (client) => { var _a, _b, _c, _d; return (_c = (_a = client === null || client === void 0 ? void 0 : client.get) !== null && _a !== void 0 ? _a : (_b = client === null || client === void 0 ? void 0 : client.sandbox) === null || _b === void 0 ? void 0 : _b.get) !== null && _c !== void 0 ? _c : (_d = client === null || client === void 0 ? void 0 : client.sandbox) === null || _d === void 0 ? void 0 : _d.connect; };
|
|
8
14
|
const getDisposeFn = (sandbox) => { var _a, _b; return (_b = (_a = sandbox === null || sandbox === void 0 ? void 0 : sandbox.dispose) !== null && _a !== void 0 ? _a : sandbox === null || sandbox === void 0 ? void 0 : sandbox.destroy) !== null && _b !== void 0 ? _b : sandbox === null || sandbox === void 0 ? void 0 : sandbox.remove; };
|
|
@@ -27,6 +33,7 @@ const createSandbox = async (client, input) => {
|
|
|
27
33
|
const createArgs = {
|
|
28
34
|
name: input.name,
|
|
29
35
|
language: input.runtime,
|
|
36
|
+
envVars: input.envVars,
|
|
30
37
|
labels: input.sessionId ? { sessionId: input.sessionId } : undefined,
|
|
31
38
|
};
|
|
32
39
|
return createFn.call((_a = client === null || client === void 0 ? void 0 : client.sandbox) !== null && _a !== void 0 ? _a : client, createArgs);
|
|
@@ -113,3 +120,26 @@ const uploadSandboxFile = async (sandbox, remotePath, file) => {
|
|
|
113
120
|
return uploadFn.call(fsApi, remotePath, file);
|
|
114
121
|
};
|
|
115
122
|
exports.uploadSandboxFile = uploadSandboxFile;
|
|
123
|
+
const writeTempFile = async (content, fileName) => {
|
|
124
|
+
const dir = await promises_1.default.mkdtemp(node_path_1.default.join(node_os_1.default.tmpdir(), 'daytona-'));
|
|
125
|
+
const filePath = node_path_1.default.join(dir, fileName);
|
|
126
|
+
await promises_1.default.writeFile(filePath, content, 'utf8');
|
|
127
|
+
return { dir, filePath };
|
|
128
|
+
};
|
|
129
|
+
const uploadSandboxFileFromContent = async (sandbox, remotePath, content, fileName) => {
|
|
130
|
+
var _a, _b;
|
|
131
|
+
const fsApi = (_a = sandbox === null || sandbox === void 0 ? void 0 : sandbox.fs) !== null && _a !== void 0 ? _a : sandbox;
|
|
132
|
+
const uploadFn = (_b = fsApi === null || fsApi === void 0 ? void 0 : fsApi.uploadFile) !== null && _b !== void 0 ? _b : fsApi === null || fsApi === void 0 ? void 0 : fsApi.upload;
|
|
133
|
+
if (!uploadFn) {
|
|
134
|
+
throw new Error('Daytona SDK: upload file method not found.');
|
|
135
|
+
}
|
|
136
|
+
const { dir, filePath } = await writeTempFile(content, fileName);
|
|
137
|
+
try {
|
|
138
|
+
return await uploadFn.call(fsApi, filePath, remotePath);
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
await promises_1.default.unlink(filePath).catch(() => undefined);
|
|
142
|
+
await promises_1.default.rmdir(dir).catch(() => undefined);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
exports.uploadSandboxFileFromContent = uploadSandboxFileFromContent;
|
|
@@ -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: (
|
|
73
|
-
name: (
|
|
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
|
},
|
|
@@ -98,13 +98,11 @@ class UploadFile {
|
|
|
98
98
|
const identifierType = this.getNodeParameter('identifierType', i);
|
|
99
99
|
const remotePath = this.getNodeParameter('remotePath', i);
|
|
100
100
|
const fileName = this.getNodeParameter('fileName', i);
|
|
101
|
-
const contentType = this.getNodeParameter('contentType', i);
|
|
102
101
|
const content = this.getNodeParameter('content', i);
|
|
103
102
|
const sandbox = identifierType === 'name'
|
|
104
103
|
? await (0, daytonaClient_1.getSandboxByName)(client, identifier)
|
|
105
104
|
: await (0, daytonaClient_1.getSandbox)(client, identifier);
|
|
106
|
-
const
|
|
107
|
-
const result = await (0, daytonaClient_1.uploadSandboxFile)(sandbox, remotePath, file);
|
|
105
|
+
const result = await (0, daytonaClient_1.uploadSandboxFileFromContent)(sandbox, remotePath, content, fileName);
|
|
108
106
|
returnData.push({
|
|
109
107
|
json: {
|
|
110
108
|
identifier,
|