n8n-nodes-daytona-tool 0.1.3 → 0.1.5

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.
@@ -1,4 +1,5 @@
1
1
  import { Daytona } from '@daytonaio/sdk';
2
+ import { Readable } from 'node:stream';
2
3
  type DaytonaConfig = {
3
4
  baseUrl: string;
4
5
  token: string;
@@ -16,6 +17,7 @@ export declare const runNodeCode: (sandbox: any, code: string, timeoutMs?: numbe
16
17
  export declare const disposeSandbox: (sandbox: any) => Promise<any>;
17
18
  export declare const startSandbox: (sandbox: any) => Promise<any>;
18
19
  export declare const stopSandbox: (sandbox: any) => Promise<any>;
19
- export declare const createSandboxFile: (content: string, name: string, contentType?: string) => import("node:buffer").File;
20
- export declare const uploadSandboxFile: (sandbox: any, remotePath: string, file: File) => Promise<any>;
20
+ export declare const createSandboxFile: (content: string, name: string, contentType?: string) => Readable;
21
+ export declare const uploadSandboxFile: (sandbox: any, remotePath: string, file: any) => Promise<any>;
22
+ export declare const uploadSandboxFileFromContent: (sandbox: any, remotePath: string, content: string, fileName: string) => Promise<any>;
21
23
  export {};
@@ -1,7 +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");
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"));
5
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; };
6
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; };
7
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; };
@@ -94,14 +101,12 @@ const stopSandbox = async (sandbox) => {
94
101
  };
95
102
  exports.stopSandbox = stopSandbox;
96
103
  const createSandboxFile = (content, name, contentType) => {
97
- const FileCtor = globalThis
98
- .File;
99
- if (!FileCtor) {
100
- throw new Error('File constructor is not available in this runtime.');
101
- }
102
- return new FileCtor([content], name, {
103
- type: contentType || 'text/plain',
104
- });
104
+ const buffer = Buffer.from(content, 'utf8');
105
+ const stream = node_stream_1.Readable.from(buffer);
106
+ stream.name = name;
107
+ stream.type = contentType || 'text/plain';
108
+ stream.size = buffer.length;
109
+ return stream;
105
110
  };
106
111
  exports.createSandboxFile = createSandboxFile;
107
112
  const uploadSandboxFile = async (sandbox, remotePath, file) => {
@@ -114,3 +119,26 @@ const uploadSandboxFile = async (sandbox, remotePath, file) => {
114
119
  return uploadFn.call(fsApi, remotePath, file);
115
120
  };
116
121
  exports.uploadSandboxFile = uploadSandboxFile;
122
+ const writeTempFile = async (content, fileName) => {
123
+ const dir = await promises_1.default.mkdtemp(node_path_1.default.join(node_os_1.default.tmpdir(), 'daytona-'));
124
+ const filePath = node_path_1.default.join(dir, fileName);
125
+ await promises_1.default.writeFile(filePath, content, 'utf8');
126
+ return { dir, filePath };
127
+ };
128
+ const uploadSandboxFileFromContent = async (sandbox, remotePath, content, fileName) => {
129
+ var _a, _b;
130
+ const fsApi = (_a = sandbox === null || sandbox === void 0 ? void 0 : sandbox.fs) !== null && _a !== void 0 ? _a : sandbox;
131
+ 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;
132
+ if (!uploadFn) {
133
+ throw new Error('Daytona SDK: upload file method not found.');
134
+ }
135
+ const { dir, filePath } = await writeTempFile(content, fileName);
136
+ try {
137
+ return await uploadFn.call(fsApi, filePath, remotePath);
138
+ }
139
+ finally {
140
+ await promises_1.default.unlink(filePath).catch(() => undefined);
141
+ await promises_1.default.rmdir(dir).catch(() => undefined);
142
+ }
143
+ };
144
+ exports.uploadSandboxFileFromContent = uploadSandboxFileFromContent;
@@ -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 file = (0, daytonaClient_1.createSandboxFile)(content, fileName, contentType);
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-daytona-tool",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "n8n community nodes for running code in Daytona sandboxes.",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",