@ctera/n8n-nodes-ctera-ai 0.1.2 → 0.4.0

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.
@@ -0,0 +1,598 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CteraFilesystem = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
5
+ class CteraFilesystem {
6
+ constructor() {
7
+ this.description = {
8
+ displayName: 'CTERA Filesystem',
9
+ name: 'cteraFilesystem',
10
+ icon: 'file:ctera.svg',
11
+ group: ['transform'],
12
+ version: 1,
13
+ subtitle: '={{$parameter["resource"] + ": " + $parameter["operation"]}}',
14
+ description: 'Perform filesystem operations on CTERA Portal storage via MCP',
15
+ defaults: {
16
+ name: 'CTERA Filesystem',
17
+ },
18
+ inputs: ['main'],
19
+ outputs: ['main'],
20
+ credentials: [
21
+ {
22
+ name: 'cteraPortalOAuth2Api',
23
+ required: true,
24
+ },
25
+ ],
26
+ properties: [
27
+ // Resource selector
28
+ {
29
+ displayName: 'Resource',
30
+ name: 'resource',
31
+ type: 'options',
32
+ noDataExpression: true,
33
+ options: [
34
+ {
35
+ name: 'Directory',
36
+ value: 'directory',
37
+ description: 'Operations on directories',
38
+ },
39
+ {
40
+ name: 'File',
41
+ value: 'file',
42
+ description: 'Operations on files',
43
+ },
44
+ {
45
+ name: 'Link',
46
+ value: 'link',
47
+ description: 'Public link and permalink operations',
48
+ },
49
+ {
50
+ name: 'Version',
51
+ value: 'version',
52
+ description: 'File version operations',
53
+ },
54
+ ],
55
+ default: 'file',
56
+ },
57
+ // ==================== FILE OPERATIONS ====================
58
+ {
59
+ displayName: 'Operation',
60
+ name: 'operation',
61
+ type: 'options',
62
+ noDataExpression: true,
63
+ displayOptions: {
64
+ show: {
65
+ resource: ['file'],
66
+ },
67
+ },
68
+ options: [
69
+ {
70
+ name: 'Copy',
71
+ value: 'copy',
72
+ description: 'Copy a file to a new location',
73
+ action: 'Copy a file',
74
+ },
75
+ {
76
+ name: 'Delete',
77
+ value: 'delete',
78
+ description: 'Delete one or more files',
79
+ action: 'Delete files',
80
+ },
81
+ {
82
+ name: 'Move',
83
+ value: 'move',
84
+ description: 'Move a file to a new location',
85
+ action: 'Move a file',
86
+ },
87
+ {
88
+ name: 'Read',
89
+ value: 'read',
90
+ description: 'Read file contents (text files)',
91
+ action: 'Read a file',
92
+ },
93
+ {
94
+ name: 'Rename',
95
+ value: 'rename',
96
+ description: 'Rename a file',
97
+ action: 'Rename a file',
98
+ },
99
+ {
100
+ name: 'Write',
101
+ value: 'write',
102
+ description: 'Write content to a file',
103
+ action: 'Write a file',
104
+ },
105
+ ],
106
+ default: 'read',
107
+ },
108
+ // ==================== DIRECTORY OPERATIONS ====================
109
+ {
110
+ displayName: 'Operation',
111
+ name: 'operation',
112
+ type: 'options',
113
+ noDataExpression: true,
114
+ displayOptions: {
115
+ show: {
116
+ resource: ['directory'],
117
+ },
118
+ },
119
+ options: [
120
+ {
121
+ name: 'Create',
122
+ value: 'create',
123
+ description: 'Create a new directory',
124
+ action: 'Create a directory',
125
+ },
126
+ {
127
+ name: 'Delete',
128
+ value: 'delete',
129
+ description: 'Delete one or more directories',
130
+ action: 'Delete directories',
131
+ },
132
+ {
133
+ name: 'List',
134
+ value: 'list',
135
+ description: 'List directory contents',
136
+ action: 'List directory contents',
137
+ },
138
+ {
139
+ name: 'Recover',
140
+ value: 'recover',
141
+ description: 'Recover deleted items',
142
+ action: 'Recover deleted items',
143
+ },
144
+ {
145
+ name: 'Walk',
146
+ value: 'walk',
147
+ description: 'Recursively walk directory tree',
148
+ action: 'Walk directory tree',
149
+ },
150
+ ],
151
+ default: 'list',
152
+ },
153
+ // ==================== VERSION OPERATIONS ====================
154
+ {
155
+ displayName: 'Operation',
156
+ name: 'operation',
157
+ type: 'options',
158
+ noDataExpression: true,
159
+ displayOptions: {
160
+ show: {
161
+ resource: ['version'],
162
+ },
163
+ },
164
+ options: [
165
+ {
166
+ name: 'List',
167
+ value: 'list',
168
+ description: 'List all versions of a file',
169
+ action: 'List file versions',
170
+ },
171
+ ],
172
+ default: 'list',
173
+ },
174
+ // ==================== LINK OPERATIONS ====================
175
+ {
176
+ displayName: 'Operation',
177
+ name: 'operation',
178
+ type: 'options',
179
+ noDataExpression: true,
180
+ displayOptions: {
181
+ show: {
182
+ resource: ['link'],
183
+ },
184
+ },
185
+ options: [
186
+ {
187
+ name: 'Create Public Link',
188
+ value: 'createPublicLink',
189
+ description: 'Create a public sharing link',
190
+ action: 'Create a public link',
191
+ },
192
+ {
193
+ name: 'Get Permalink',
194
+ value: 'getPermalink',
195
+ description: 'Get permanent link to a file or directory',
196
+ action: 'Get permalink',
197
+ },
198
+ ],
199
+ default: 'createPublicLink',
200
+ },
201
+ // ==================== COMMON PARAMETERS ====================
202
+ // Path parameter (used by most operations)
203
+ {
204
+ displayName: 'Path',
205
+ name: 'path',
206
+ type: 'string',
207
+ default: '',
208
+ required: true,
209
+ placeholder: '/CloudFolders/shared/documents',
210
+ description: 'Path to the file or directory',
211
+ displayOptions: {
212
+ hide: {
213
+ operation: ['delete', 'recover'],
214
+ },
215
+ },
216
+ },
217
+ // Paths parameter (for delete/recover operations)
218
+ {
219
+ displayName: 'Paths',
220
+ name: 'paths',
221
+ type: 'string',
222
+ default: '',
223
+ required: true,
224
+ placeholder: '/CloudFolders/shared/file1.txt, /CloudFolders/shared/file2.txt',
225
+ description: 'Comma-separated list of paths to delete or recover',
226
+ displayOptions: {
227
+ show: {
228
+ operation: ['delete', 'recover'],
229
+ },
230
+ },
231
+ },
232
+ // ==================== FILE-SPECIFIC PARAMETERS ====================
233
+ // Content for write operation
234
+ {
235
+ displayName: 'Content',
236
+ name: 'content',
237
+ type: 'string',
238
+ default: '',
239
+ required: true,
240
+ typeOptions: {
241
+ rows: 5,
242
+ },
243
+ placeholder: 'File content to write...',
244
+ description: 'Content to write to the file (text or base64-encoded binary)',
245
+ displayOptions: {
246
+ show: {
247
+ resource: ['file'],
248
+ operation: ['write'],
249
+ },
250
+ },
251
+ },
252
+ // Destination for copy/move operations
253
+ {
254
+ displayName: 'Destination',
255
+ name: 'destination',
256
+ type: 'string',
257
+ default: '',
258
+ required: true,
259
+ placeholder: '/CloudFolders/archive/documents',
260
+ description: 'Destination path for the copy or move operation',
261
+ displayOptions: {
262
+ show: {
263
+ resource: ['file'],
264
+ operation: ['copy', 'move'],
265
+ },
266
+ },
267
+ },
268
+ // New name for rename operation
269
+ {
270
+ displayName: 'New Name',
271
+ name: 'newName',
272
+ type: 'string',
273
+ default: '',
274
+ required: true,
275
+ placeholder: 'new-filename.txt',
276
+ description: 'New name for the file (without path)',
277
+ displayOptions: {
278
+ show: {
279
+ resource: ['file'],
280
+ operation: ['rename'],
281
+ },
282
+ },
283
+ },
284
+ // ==================== DIRECTORY-SPECIFIC PARAMETERS ====================
285
+ // Create parents option
286
+ {
287
+ displayName: 'Create Parent Directories',
288
+ name: 'createParents',
289
+ type: 'boolean',
290
+ default: false,
291
+ description: 'Whether to create parent directories if they do not exist',
292
+ displayOptions: {
293
+ show: {
294
+ resource: ['directory'],
295
+ operation: ['create'],
296
+ },
297
+ },
298
+ },
299
+ // Include deleted option for list/walk
300
+ {
301
+ displayName: 'Include Deleted',
302
+ name: 'includeDeleted',
303
+ type: 'boolean',
304
+ default: false,
305
+ description: 'Whether to include deleted files in the results',
306
+ displayOptions: {
307
+ show: {
308
+ resource: ['directory'],
309
+ operation: ['list', 'walk'],
310
+ },
311
+ },
312
+ },
313
+ // ==================== LINK-SPECIFIC PARAMETERS ====================
314
+ // Access level for public link
315
+ {
316
+ displayName: 'Access Level',
317
+ name: 'access',
318
+ type: 'options',
319
+ options: [
320
+ {
321
+ name: 'Read Only',
322
+ value: 'RO',
323
+ description: 'Recipients can only view/download',
324
+ },
325
+ {
326
+ name: 'Read/Write',
327
+ value: 'RW',
328
+ description: 'Recipients can view, download, and modify',
329
+ },
330
+ ],
331
+ default: 'RO',
332
+ description: 'Access level for the public link',
333
+ displayOptions: {
334
+ show: {
335
+ resource: ['link'],
336
+ operation: ['createPublicLink'],
337
+ },
338
+ },
339
+ },
340
+ // Expiration for public link
341
+ {
342
+ displayName: 'Expire In (Days)',
343
+ name: 'expireIn',
344
+ type: 'number',
345
+ default: 30,
346
+ typeOptions: {
347
+ minValue: 1,
348
+ maxValue: 365,
349
+ },
350
+ description: 'Number of days until the link expires',
351
+ displayOptions: {
352
+ show: {
353
+ resource: ['link'],
354
+ operation: ['createPublicLink'],
355
+ },
356
+ },
357
+ },
358
+ ],
359
+ };
360
+ }
361
+ async execute() {
362
+ const items = this.getInputData();
363
+ const returnData = [];
364
+ // Get OAuth2 credentials
365
+ const oauth2Credentials = await this.getCredentials('cteraPortalOAuth2Api');
366
+ const oauthTokenData = oauth2Credentials.oauthTokenData;
367
+ const bearerToken = oauthTokenData === null || oauthTokenData === void 0 ? void 0 : oauthTokenData.access_token;
368
+ const mcpServerUrl = `${oauth2Credentials.portalUrl.replace(/\/$/, '')}/_SRV/MCP`;
369
+ const allowUnauthorizedCerts = oauth2Credentials.allowUnauthorizedCerts;
370
+ for (let i = 0; i < items.length; i++) {
371
+ try {
372
+ const resource = this.getNodeParameter('resource', i);
373
+ const operation = this.getNodeParameter('operation', i);
374
+ let toolName;
375
+ const toolArgs = {};
376
+ // Determine tool name and arguments based on resource and operation
377
+ if (resource === 'file') {
378
+ switch (operation) {
379
+ case 'read':
380
+ toolName = 'ctera_portal_read_file';
381
+ toolArgs.path = this.getNodeParameter('path', i);
382
+ break;
383
+ case 'write':
384
+ toolName = 'ctera_portal_upload_from_content';
385
+ toolArgs.filepath = this.getNodeParameter('path', i);
386
+ toolArgs.content = this.getNodeParameter('content', i);
387
+ break;
388
+ case 'delete': {
389
+ toolName = 'ctera_portal_delete_items';
390
+ const deletePaths = this.getNodeParameter('paths', i)
391
+ .split(',')
392
+ .map((p) => p.trim())
393
+ .filter((p) => p);
394
+ toolArgs.paths = deletePaths;
395
+ break;
396
+ }
397
+ case 'copy':
398
+ toolName = 'ctera_portal_copy_item';
399
+ toolArgs.source = this.getNodeParameter('path', i);
400
+ toolArgs.destination = this.getNodeParameter('destination', i);
401
+ break;
402
+ case 'move':
403
+ toolName = 'ctera_portal_move_item';
404
+ toolArgs.source = this.getNodeParameter('path', i);
405
+ toolArgs.destination = this.getNodeParameter('destination', i);
406
+ break;
407
+ case 'rename':
408
+ toolName = 'ctera_portal_rename_item';
409
+ toolArgs.path = this.getNodeParameter('path', i);
410
+ toolArgs.new_name = this.getNodeParameter('newName', i);
411
+ break;
412
+ default:
413
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown file operation: ${operation}`, { itemIndex: i });
414
+ }
415
+ }
416
+ else if (resource === 'directory') {
417
+ switch (operation) {
418
+ case 'list':
419
+ toolName = 'ctera_portal_list_dir';
420
+ toolArgs.path = this.getNodeParameter('path', i);
421
+ toolArgs.include_deleted = this.getNodeParameter('includeDeleted', i);
422
+ break;
423
+ case 'create': {
424
+ const createParents = this.getNodeParameter('createParents', i);
425
+ toolName = createParents ? 'ctera_portal_makedirs' : 'ctera_portal_create_directory';
426
+ toolArgs.path = this.getNodeParameter('path', i);
427
+ break;
428
+ }
429
+ case 'delete': {
430
+ toolName = 'ctera_portal_delete_items';
431
+ const dirPaths = this.getNodeParameter('paths', i)
432
+ .split(',')
433
+ .map((p) => p.trim())
434
+ .filter((p) => p);
435
+ toolArgs.paths = dirPaths;
436
+ break;
437
+ }
438
+ case 'recover': {
439
+ toolName = 'ctera_portal_recover_items';
440
+ const recoverPaths = this.getNodeParameter('paths', i)
441
+ .split(',')
442
+ .map((p) => p.trim())
443
+ .filter((p) => p);
444
+ toolArgs.paths = recoverPaths;
445
+ break;
446
+ }
447
+ case 'walk':
448
+ toolName = 'ctera_portal_walk_tree';
449
+ toolArgs.path = this.getNodeParameter('path', i);
450
+ toolArgs.include_deleted = this.getNodeParameter('includeDeleted', i);
451
+ break;
452
+ default:
453
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown directory operation: ${operation}`, { itemIndex: i });
454
+ }
455
+ }
456
+ else if (resource === 'version') {
457
+ switch (operation) {
458
+ case 'list':
459
+ toolName = 'ctera_portal_list_versions';
460
+ toolArgs.path = this.getNodeParameter('path', i);
461
+ break;
462
+ default:
463
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown version operation: ${operation}`, { itemIndex: i });
464
+ }
465
+ }
466
+ else if (resource === 'link') {
467
+ switch (operation) {
468
+ case 'createPublicLink':
469
+ toolName = 'ctera_portal_create_public_link';
470
+ toolArgs.path = this.getNodeParameter('path', i);
471
+ toolArgs.access = this.getNodeParameter('access', i);
472
+ toolArgs.expire_in = this.getNodeParameter('expireIn', i);
473
+ break;
474
+ case 'getPermalink':
475
+ toolName = 'ctera_portal_get_permalink';
476
+ toolArgs.path = this.getNodeParameter('path', i);
477
+ break;
478
+ default:
479
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown link operation: ${operation}`, { itemIndex: i });
480
+ }
481
+ }
482
+ else {
483
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown resource: ${resource}`, {
484
+ itemIndex: i,
485
+ });
486
+ }
487
+ // Construct JSON-RPC 2.0 request
488
+ const requestBody = {
489
+ jsonrpc: '2.0',
490
+ method: 'tools/call',
491
+ params: {
492
+ name: toolName,
493
+ arguments: toolArgs,
494
+ },
495
+ id: i + 1,
496
+ };
497
+ // Make HTTP request to MCP server
498
+ const response = await this.helpers.httpRequest({
499
+ method: 'POST',
500
+ url: `${mcpServerUrl}/mcp/`,
501
+ headers: {
502
+ 'Content-Type': 'application/json',
503
+ Authorization: `Bearer ${bearerToken}`,
504
+ },
505
+ body: JSON.stringify(requestBody),
506
+ skipSslCertificateValidation: allowUnauthorizedCerts,
507
+ });
508
+ // Parse response
509
+ const parsedResponse = typeof response === 'string' ? JSON.parse(response) : response;
510
+ // Handle MCP error responses
511
+ if (parsedResponse.error) {
512
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `MCP Error: ${parsedResponse.error.message || JSON.stringify(parsedResponse.error)}`, { itemIndex: i });
513
+ }
514
+ // Extract result from MCP response
515
+ let result = null;
516
+ if (parsedResponse.result && parsedResponse.result.content) {
517
+ const content = parsedResponse.result.content[0];
518
+ if (content && content.type === 'text') {
519
+ try {
520
+ // Convert Python syntax to JSON syntax
521
+ let jsonText = content.text
522
+ .replace(/'/g, '"') // Single quotes to double quotes
523
+ .replace(/None/g, 'null') // Python None to JSON null
524
+ .replace(/True/g, 'true') // Python True to JSON true
525
+ .replace(/False/g, 'false'); // Python False to JSON false
526
+ result = JSON.parse(jsonText);
527
+ }
528
+ catch {
529
+ result = content.text;
530
+ }
531
+ }
532
+ else {
533
+ result = content;
534
+ }
535
+ }
536
+ else {
537
+ result = parsedResponse.result;
538
+ }
539
+ // Handle fan-out for list operations (directory list, walk, versions)
540
+ if ((resource === 'directory' && (operation === 'list' || operation === 'walk')) ||
541
+ (resource === 'version' && operation === 'list')) {
542
+ if (Array.isArray(result) && result.length > 0) {
543
+ for (const item of result) {
544
+ returnData.push({
545
+ json: {
546
+ ...items[i].json,
547
+ resource,
548
+ operation,
549
+ ...item,
550
+ },
551
+ pairedItem: { item: i },
552
+ });
553
+ }
554
+ }
555
+ else {
556
+ // Empty result
557
+ returnData.push({
558
+ json: {
559
+ ...items[i].json,
560
+ resource,
561
+ operation,
562
+ result: [],
563
+ },
564
+ pairedItem: { item: i },
565
+ });
566
+ }
567
+ }
568
+ else {
569
+ // Single result operations
570
+ returnData.push({
571
+ json: {
572
+ ...items[i].json,
573
+ resource,
574
+ operation,
575
+ result: result,
576
+ },
577
+ pairedItem: { item: i },
578
+ });
579
+ }
580
+ }
581
+ catch (error) {
582
+ if (this.continueOnFail()) {
583
+ returnData.push({
584
+ json: {
585
+ ...items[i].json,
586
+ error: error.message,
587
+ },
588
+ pairedItem: { item: i },
589
+ });
590
+ continue;
591
+ }
592
+ throw error;
593
+ }
594
+ }
595
+ return [returnData];
596
+ }
597
+ }
598
+ exports.CteraFilesystem = CteraFilesystem;
@@ -0,0 +1,13 @@
1
+ <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <g clip-path="url(#ub91fxv4ea)" transform="scale(1.15) translate(-1.8, -1.8)">
3
+ <path d="M20 0H4a4 4 0 0 0-4 4v16a4 4 0 0 0 4 4h16a4 4 0 0 0 4-4V4a4 4 0 0 0-4-4z" fill="#4F5CE5"/>
4
+ <path d="M20.373 15.297a8.941 8.941 0 0 1-2.01 3.066A8.98 8.98 0 0 1 12 21a8.883 8.883 0 0 1-3.297-.627 8.942 8.942 0 0 1-3.066-2.01A8.981 8.981 0 0 1 3 12c0-1.163.22-2.277.627-3.297a8.943 8.943 0 0 1 2.01-3.066A8.982 8.982 0 0 1 12 3c1.163 0 2.277.22 3.297.627a8.943 8.943 0 0 1 3.066 2.01l-1.65 1.65A6.668 6.668 0 0 0 12 5.333a6.663 6.663 0 0 0-4.713 1.953A6.668 6.668 0 0 0 5.333 12a6.664 6.664 0 0 0 1.953 4.713A6.668 6.668 0 0 0 12 18.667a6.662 6.662 0 0 0 4.713-1.953 6.667 6.667 0 0 0 1.49-2.27l2.17.853z" fill="#fff" stroke="#4F5CE5" stroke-width=".667" stroke-miterlimit="10"/>
5
+ <path d="M18.203 14.443a6.668 6.668 0 0 1-3.543 3.67 6.608 6.608 0 0 1-2.66.554 6.669 6.669 0 0 1-6.113-4.007A6.607 6.607 0 0 1 5.333 12 6.668 6.668 0 0 1 9.34 5.887 6.607 6.607 0 0 1 12 5.333a6.667 6.667 0 0 1 4.713 1.953L14.71 9.29A3.818 3.818 0 0 0 12 8.167c-.543 0-1.06.113-1.53.316A3.85 3.85 0 0 0 8.167 12c0 .543.113 1.06.316 1.53a3.847 3.847 0 0 0 5.047 1.987 3.848 3.848 0 0 0 2.037-2.114l2.636 1.04z" fill="#fff" stroke="#4F5CE5" stroke-width=".667" stroke-miterlimit="10"/>
6
+ <path d="M13.874 12c0 .13-.08.247-.204.292l-1.006.372-.37 1.007a.31.31 0 0 1-.584 0l-.373-1.007-1.007-.371a.31.31 0 0 1 0-.583l1.007-.373.37-1.008a.31.31 0 0 1 .584 0l.373 1.008 1.007.37a.308.308 0 0 1 .203.293z" fill="#fff"/>
7
+ </g>
8
+ <defs>
9
+ <clipPath id="ub91fxv4ea">
10
+ <path fill="#fff" d="M0 0h24v24H0z"/>
11
+ </clipPath>
12
+ </defs>
13
+ </svg>
package/index.js CHANGED
@@ -1,10 +1,10 @@
1
- module.exports = {
2
- ...require('./dist/nodes/CteraAi/CteraAi.node'),
3
- ...require('./dist/credentials/CteraAiMcpApi.credentials'),
4
- };
5
-
6
-
7
-
8
-
9
-
10
-
1
+ module.exports = {
2
+ ...require('./dist/nodes/CteraAi/CteraAi.node'),
3
+ ...require('./dist/credentials/CteraAiMcpApi.credentials'),
4
+ };
5
+
6
+
7
+
8
+
9
+
10
+