n8n-nodes-onedrive-business 1.0.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.
- package/README.md +452 -0
- package/dist/credentials/OneDriveBusinessOAuth2.credentials.d.ts +25 -0
- package/dist/credentials/OneDriveBusinessOAuth2.credentials.js +114 -0
- package/dist/nodes/OneDriveBusiness.node.d.ts +35 -0
- package/dist/nodes/OneDriveBusiness.node.js +661 -0
- package/dist/nodes/OneDriveBusinessTrigger.node.d.ts +63 -0
- package/dist/nodes/OneDriveBusinessTrigger.node.js +332 -0
- package/dist/onedrive.svg +1 -0
- package/dist/types.d.ts +218 -0
- package/dist/types.js +8 -0
- package/dist/utils/DeltaProcessor.d.ts +91 -0
- package/dist/utils/DeltaProcessor.js +267 -0
- package/dist/utils/GraphClient.d.ts +67 -0
- package/dist/utils/GraphClient.js +182 -0
- package/dist/utils/StateStore.d.ts +96 -0
- package/dist/utils/StateStore.js +280 -0
- package/dist/utils/WebhookHandler.d.ts +78 -0
- package/dist/utils/WebhookHandler.js +220 -0
- package/dist/utils/helpers.d.ts +113 -0
- package/dist/utils/helpers.js +250 -0
- package/package.json +56 -0
|
@@ -0,0 +1,661 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OneDriveBusiness = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
const GraphClient_1 = require("../utils/GraphClient");
|
|
6
|
+
const helpers_1 = require("../utils/helpers");
|
|
7
|
+
/**
|
|
8
|
+
* OneDrive Business Node
|
|
9
|
+
*
|
|
10
|
+
* Provides file and folder operations for OneDrive Business:
|
|
11
|
+
* - File: Delete, Download, Get, Rename, Search, Share, Upload
|
|
12
|
+
* - Folder: Create, Delete, Get Items, Rename, Search, Share
|
|
13
|
+
*
|
|
14
|
+
* Uses Microsoft Graph API v1.0 with tenant-based authentication.
|
|
15
|
+
*/
|
|
16
|
+
class OneDriveBusiness {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.description = {
|
|
19
|
+
displayName: 'OneDrive Business',
|
|
20
|
+
name: 'oneDriveBusiness',
|
|
21
|
+
icon: 'file:onedrive.svg',
|
|
22
|
+
group: ['transform'],
|
|
23
|
+
version: 1,
|
|
24
|
+
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
25
|
+
description: 'Access OneDrive Business files and folders',
|
|
26
|
+
defaults: {
|
|
27
|
+
name: 'OneDrive Business',
|
|
28
|
+
},
|
|
29
|
+
inputs: ['main'],
|
|
30
|
+
outputs: ['main'],
|
|
31
|
+
credentials: [
|
|
32
|
+
{
|
|
33
|
+
name: 'oneDriveBusinessOAuth2Api',
|
|
34
|
+
required: true,
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
properties: [
|
|
38
|
+
{
|
|
39
|
+
displayName: 'Resource',
|
|
40
|
+
name: 'resource',
|
|
41
|
+
type: 'options',
|
|
42
|
+
noDataExpression: true,
|
|
43
|
+
options: [
|
|
44
|
+
{
|
|
45
|
+
name: 'File',
|
|
46
|
+
value: 'file',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: 'Folder',
|
|
50
|
+
value: 'folder',
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
default: 'file',
|
|
54
|
+
},
|
|
55
|
+
// Drive Location
|
|
56
|
+
{
|
|
57
|
+
displayName: 'Drive Type',
|
|
58
|
+
name: 'driveType',
|
|
59
|
+
type: 'options',
|
|
60
|
+
options: [
|
|
61
|
+
{
|
|
62
|
+
name: 'User Drive',
|
|
63
|
+
value: 'user',
|
|
64
|
+
description: 'Access a user\'s OneDrive',
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'Site Drive',
|
|
68
|
+
value: 'site',
|
|
69
|
+
description: 'Access a SharePoint site\'s document library',
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
default: 'user',
|
|
73
|
+
description: 'Type of drive to access',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
displayName: 'User ID',
|
|
77
|
+
name: 'userId',
|
|
78
|
+
type: 'string',
|
|
79
|
+
displayOptions: {
|
|
80
|
+
show: {
|
|
81
|
+
driveType: ['user'],
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
default: '',
|
|
85
|
+
required: true,
|
|
86
|
+
placeholder: 'user@contoso.com or user-id',
|
|
87
|
+
description: 'User principal name or ID',
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
displayName: 'Site ID',
|
|
91
|
+
name: 'siteId',
|
|
92
|
+
type: 'string',
|
|
93
|
+
displayOptions: {
|
|
94
|
+
show: {
|
|
95
|
+
driveType: ['site'],
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
default: '',
|
|
99
|
+
required: true,
|
|
100
|
+
placeholder: 'contoso.sharepoint.com,site-id,web-id',
|
|
101
|
+
description: 'SharePoint site ID',
|
|
102
|
+
},
|
|
103
|
+
// FILE OPERATIONS
|
|
104
|
+
{
|
|
105
|
+
displayName: 'Operation',
|
|
106
|
+
name: 'operation',
|
|
107
|
+
type: 'options',
|
|
108
|
+
noDataExpression: true,
|
|
109
|
+
displayOptions: {
|
|
110
|
+
show: {
|
|
111
|
+
resource: ['file'],
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
options: [
|
|
115
|
+
{
|
|
116
|
+
name: 'Delete',
|
|
117
|
+
value: 'delete',
|
|
118
|
+
description: 'Delete a file',
|
|
119
|
+
action: 'Delete a file',
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
name: 'Download',
|
|
123
|
+
value: 'download',
|
|
124
|
+
description: 'Download a file',
|
|
125
|
+
action: 'Download a file',
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
name: 'Get',
|
|
129
|
+
value: 'get',
|
|
130
|
+
description: 'Get file metadata',
|
|
131
|
+
action: 'Get file metadata',
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
name: 'Rename',
|
|
135
|
+
value: 'rename',
|
|
136
|
+
description: 'Rename a file',
|
|
137
|
+
action: 'Rename a file',
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
name: 'Search',
|
|
141
|
+
value: 'search',
|
|
142
|
+
description: 'Search for files',
|
|
143
|
+
action: 'Search for files',
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
name: 'Share',
|
|
147
|
+
value: 'share',
|
|
148
|
+
description: 'Create a sharing link',
|
|
149
|
+
action: 'Create a sharing link',
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
name: 'Upload',
|
|
153
|
+
value: 'upload',
|
|
154
|
+
description: 'Upload a file',
|
|
155
|
+
action: 'Upload a file',
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
default: 'upload',
|
|
159
|
+
},
|
|
160
|
+
// FOLDER OPERATIONS
|
|
161
|
+
{
|
|
162
|
+
displayName: 'Operation',
|
|
163
|
+
name: 'operation',
|
|
164
|
+
type: 'options',
|
|
165
|
+
noDataExpression: true,
|
|
166
|
+
displayOptions: {
|
|
167
|
+
show: {
|
|
168
|
+
resource: ['folder'],
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
options: [
|
|
172
|
+
{
|
|
173
|
+
name: 'Create',
|
|
174
|
+
value: 'create',
|
|
175
|
+
description: 'Create a folder',
|
|
176
|
+
action: 'Create a folder',
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
name: 'Delete',
|
|
180
|
+
value: 'delete',
|
|
181
|
+
description: 'Delete a folder',
|
|
182
|
+
action: 'Delete a folder',
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
name: 'Get Items',
|
|
186
|
+
value: 'getItems',
|
|
187
|
+
description: 'Get folder items',
|
|
188
|
+
action: 'Get folder items',
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
name: 'Rename',
|
|
192
|
+
value: 'rename',
|
|
193
|
+
description: 'Rename a folder',
|
|
194
|
+
action: 'Rename a folder',
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
name: 'Search',
|
|
198
|
+
value: 'search',
|
|
199
|
+
description: 'Search for folders',
|
|
200
|
+
action: 'Search for folders',
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
name: 'Share',
|
|
204
|
+
value: 'share',
|
|
205
|
+
description: 'Create a sharing link',
|
|
206
|
+
action: 'Create a sharing link',
|
|
207
|
+
},
|
|
208
|
+
],
|
|
209
|
+
default: 'create',
|
|
210
|
+
},
|
|
211
|
+
// FILE: Delete, Get, Download, Rename
|
|
212
|
+
{
|
|
213
|
+
displayName: 'File ID or Path',
|
|
214
|
+
name: 'fileId',
|
|
215
|
+
type: 'string',
|
|
216
|
+
displayOptions: {
|
|
217
|
+
show: {
|
|
218
|
+
resource: ['file'],
|
|
219
|
+
operation: ['delete', 'get', 'download', 'rename', 'share'],
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
default: '',
|
|
223
|
+
required: true,
|
|
224
|
+
placeholder: 'Item ID or /path/to/file.pdf',
|
|
225
|
+
description: 'File item ID or path from drive root',
|
|
226
|
+
},
|
|
227
|
+
// FILE: Rename
|
|
228
|
+
{
|
|
229
|
+
displayName: 'New Name',
|
|
230
|
+
name: 'newName',
|
|
231
|
+
type: 'string',
|
|
232
|
+
displayOptions: {
|
|
233
|
+
show: {
|
|
234
|
+
resource: ['file'],
|
|
235
|
+
operation: ['rename'],
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
default: '',
|
|
239
|
+
required: true,
|
|
240
|
+
placeholder: 'newfile.pdf',
|
|
241
|
+
description: 'New filename',
|
|
242
|
+
},
|
|
243
|
+
// FILE: Upload
|
|
244
|
+
{
|
|
245
|
+
displayName: 'File Path',
|
|
246
|
+
name: 'filePath',
|
|
247
|
+
type: 'string',
|
|
248
|
+
displayOptions: {
|
|
249
|
+
show: {
|
|
250
|
+
resource: ['file'],
|
|
251
|
+
operation: ['upload'],
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
default: '',
|
|
255
|
+
required: true,
|
|
256
|
+
placeholder: '/Documents/file.pdf',
|
|
257
|
+
description: 'Destination path in OneDrive (including filename)',
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
displayName: 'Binary Property',
|
|
261
|
+
name: 'binaryPropertyName',
|
|
262
|
+
type: 'string',
|
|
263
|
+
displayOptions: {
|
|
264
|
+
show: {
|
|
265
|
+
resource: ['file'],
|
|
266
|
+
operation: ['upload'],
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
default: 'data',
|
|
270
|
+
required: true,
|
|
271
|
+
description: 'Name of the binary property containing the file data',
|
|
272
|
+
},
|
|
273
|
+
// FILE & FOLDER: Search
|
|
274
|
+
{
|
|
275
|
+
displayName: 'Query',
|
|
276
|
+
name: 'query',
|
|
277
|
+
type: 'string',
|
|
278
|
+
displayOptions: {
|
|
279
|
+
show: {
|
|
280
|
+
operation: ['search'],
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
default: '',
|
|
284
|
+
required: true,
|
|
285
|
+
placeholder: 'report.pdf',
|
|
286
|
+
description: 'Search query',
|
|
287
|
+
},
|
|
288
|
+
// FILE & FOLDER: Share
|
|
289
|
+
{
|
|
290
|
+
displayName: 'Link Type',
|
|
291
|
+
name: 'linkType',
|
|
292
|
+
type: 'options',
|
|
293
|
+
displayOptions: {
|
|
294
|
+
show: {
|
|
295
|
+
operation: ['share'],
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
options: [
|
|
299
|
+
{
|
|
300
|
+
name: 'View',
|
|
301
|
+
value: 'view',
|
|
302
|
+
description: 'View-only link',
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
name: 'Edit',
|
|
306
|
+
value: 'edit',
|
|
307
|
+
description: 'Edit link',
|
|
308
|
+
},
|
|
309
|
+
],
|
|
310
|
+
default: 'view',
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
displayName: 'Link Scope',
|
|
314
|
+
name: 'linkScope',
|
|
315
|
+
type: 'options',
|
|
316
|
+
displayOptions: {
|
|
317
|
+
show: {
|
|
318
|
+
operation: ['share'],
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
options: [
|
|
322
|
+
{
|
|
323
|
+
name: 'Anonymous',
|
|
324
|
+
value: 'anonymous',
|
|
325
|
+
description: 'Anyone with the link',
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
name: 'Organization',
|
|
329
|
+
value: 'organization',
|
|
330
|
+
description: 'Only people in your organization',
|
|
331
|
+
},
|
|
332
|
+
],
|
|
333
|
+
default: 'organization',
|
|
334
|
+
},
|
|
335
|
+
// FOLDER: Create, Delete, Get Items, Rename
|
|
336
|
+
{
|
|
337
|
+
displayName: 'Folder ID or Path',
|
|
338
|
+
name: 'folderId',
|
|
339
|
+
type: 'string',
|
|
340
|
+
displayOptions: {
|
|
341
|
+
show: {
|
|
342
|
+
resource: ['folder'],
|
|
343
|
+
operation: ['delete', 'getItems', 'rename', 'share'],
|
|
344
|
+
},
|
|
345
|
+
},
|
|
346
|
+
default: '',
|
|
347
|
+
required: true,
|
|
348
|
+
placeholder: 'Item ID or /path/to/folder',
|
|
349
|
+
description: 'Folder item ID or path from drive root',
|
|
350
|
+
},
|
|
351
|
+
// FOLDER: Create
|
|
352
|
+
{
|
|
353
|
+
displayName: 'Folder Path',
|
|
354
|
+
name: 'folderPath',
|
|
355
|
+
type: 'string',
|
|
356
|
+
displayOptions: {
|
|
357
|
+
show: {
|
|
358
|
+
resource: ['folder'],
|
|
359
|
+
operation: ['create'],
|
|
360
|
+
},
|
|
361
|
+
},
|
|
362
|
+
default: '',
|
|
363
|
+
required: true,
|
|
364
|
+
placeholder: '/Documents/NewFolder',
|
|
365
|
+
description: 'Path where to create the folder',
|
|
366
|
+
},
|
|
367
|
+
// FOLDER: Rename
|
|
368
|
+
{
|
|
369
|
+
displayName: 'New Name',
|
|
370
|
+
name: 'newName',
|
|
371
|
+
type: 'string',
|
|
372
|
+
displayOptions: {
|
|
373
|
+
show: {
|
|
374
|
+
resource: ['folder'],
|
|
375
|
+
operation: ['rename'],
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
default: '',
|
|
379
|
+
required: true,
|
|
380
|
+
placeholder: 'NewFolderName',
|
|
381
|
+
description: 'New folder name',
|
|
382
|
+
},
|
|
383
|
+
],
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
async execute() {
|
|
387
|
+
const items = this.getInputData();
|
|
388
|
+
const returnData = [];
|
|
389
|
+
const resource = this.getNodeParameter('resource', 0);
|
|
390
|
+
const operation = this.getNodeParameter('operation', 0);
|
|
391
|
+
// Initialize Graph client
|
|
392
|
+
const graphClient = new GraphClient_1.GraphClient(this);
|
|
393
|
+
for (let i = 0; i < items.length; i++) {
|
|
394
|
+
try {
|
|
395
|
+
// Get drive location
|
|
396
|
+
const driveType = this.getNodeParameter('driveType', i);
|
|
397
|
+
const driveLocation = {
|
|
398
|
+
type: driveType,
|
|
399
|
+
userId: driveType === 'user' ? this.getNodeParameter('userId', i) : undefined,
|
|
400
|
+
siteId: driveType === 'site' ? this.getNodeParameter('siteId', i) : undefined,
|
|
401
|
+
};
|
|
402
|
+
const drivePath = (0, helpers_1.resolveDrivePath)(driveLocation);
|
|
403
|
+
// Execute operation
|
|
404
|
+
if (resource === 'file') {
|
|
405
|
+
const result = await OneDriveBusiness.executeFileOperation(this, graphClient, drivePath, operation, i);
|
|
406
|
+
if (Array.isArray(result)) {
|
|
407
|
+
returnData.push(...result);
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
returnData.push(result);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
else if (resource === 'folder') {
|
|
414
|
+
const result = await OneDriveBusiness.executeFolderOperation(this, graphClient, drivePath, operation, i);
|
|
415
|
+
if (Array.isArray(result)) {
|
|
416
|
+
returnData.push(...result);
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
returnData.push(result);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
catch (error) {
|
|
424
|
+
if (this.continueOnFail()) {
|
|
425
|
+
returnData.push({
|
|
426
|
+
json: {
|
|
427
|
+
error: error.message,
|
|
428
|
+
},
|
|
429
|
+
pairedItem: { item: i },
|
|
430
|
+
});
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
throw error;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
return [returnData];
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Execute file operations
|
|
440
|
+
*/
|
|
441
|
+
static async executeFileOperation(context, graphClient, drivePath, operation, itemIndex) {
|
|
442
|
+
switch (operation) {
|
|
443
|
+
case 'delete':
|
|
444
|
+
return await OneDriveBusiness.fileDelete(context, graphClient, drivePath, itemIndex);
|
|
445
|
+
case 'download':
|
|
446
|
+
return await OneDriveBusiness.fileDownload(context, graphClient, drivePath, itemIndex);
|
|
447
|
+
case 'get':
|
|
448
|
+
return await OneDriveBusiness.fileGet(context, graphClient, drivePath, itemIndex);
|
|
449
|
+
case 'rename':
|
|
450
|
+
return await OneDriveBusiness.fileRename(context, graphClient, drivePath, itemIndex);
|
|
451
|
+
case 'search':
|
|
452
|
+
return await OneDriveBusiness.fileSearch(context, graphClient, drivePath, itemIndex);
|
|
453
|
+
case 'share':
|
|
454
|
+
return await OneDriveBusiness.fileShare(context, graphClient, drivePath, itemIndex);
|
|
455
|
+
case 'upload':
|
|
456
|
+
return await OneDriveBusiness.fileUpload(context, graphClient, drivePath, itemIndex);
|
|
457
|
+
default:
|
|
458
|
+
throw new n8n_workflow_1.NodeOperationError(context.getNode(), `Unknown file operation: ${operation}`);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Execute folder operations
|
|
463
|
+
*/
|
|
464
|
+
static async executeFolderOperation(context, graphClient, drivePath, operation, itemIndex) {
|
|
465
|
+
switch (operation) {
|
|
466
|
+
case 'create':
|
|
467
|
+
return await OneDriveBusiness.folderCreate(context, graphClient, drivePath, itemIndex);
|
|
468
|
+
case 'delete':
|
|
469
|
+
return await OneDriveBusiness.folderDelete(context, graphClient, drivePath, itemIndex);
|
|
470
|
+
case 'getItems':
|
|
471
|
+
return await OneDriveBusiness.folderGetItems(context, graphClient, drivePath, itemIndex);
|
|
472
|
+
case 'rename':
|
|
473
|
+
return await OneDriveBusiness.folderRename(context, graphClient, drivePath, itemIndex);
|
|
474
|
+
case 'search':
|
|
475
|
+
return await OneDriveBusiness.folderSearch(context, graphClient, drivePath, itemIndex);
|
|
476
|
+
case 'share':
|
|
477
|
+
return await OneDriveBusiness.folderShare(context, graphClient, drivePath, itemIndex);
|
|
478
|
+
default:
|
|
479
|
+
throw new n8n_workflow_1.NodeOperationError(context.getNode(), `Unknown folder operation: ${operation}`);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
// ============================================
|
|
483
|
+
// FILE OPERATIONS IMPLEMENTATION
|
|
484
|
+
// ============================================
|
|
485
|
+
static async fileDelete(context, graphClient, drivePath, itemIndex) {
|
|
486
|
+
const fileId = context.getNodeParameter('fileId', itemIndex);
|
|
487
|
+
const itemPath = (0, helpers_1.buildItemPath)(drivePath, (0, helpers_1.isValidItemId)(fileId) ? undefined : fileId, (0, helpers_1.isValidItemId)(fileId) ? fileId : undefined);
|
|
488
|
+
await graphClient.delete(itemPath);
|
|
489
|
+
return {
|
|
490
|
+
json: {
|
|
491
|
+
success: true,
|
|
492
|
+
fileId,
|
|
493
|
+
},
|
|
494
|
+
pairedItem: { item: itemIndex },
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
static async fileDownload(context, graphClient, drivePath, itemIndex) {
|
|
498
|
+
const fileId = context.getNodeParameter('fileId', itemIndex);
|
|
499
|
+
const itemPath = (0, helpers_1.buildItemPath)(drivePath, (0, helpers_1.isValidItemId)(fileId) ? undefined : fileId, (0, helpers_1.isValidItemId)(fileId) ? fileId : undefined);
|
|
500
|
+
// Get file metadata first
|
|
501
|
+
const fileMetadata = await graphClient.get(itemPath);
|
|
502
|
+
// Download content
|
|
503
|
+
const binaryData = await graphClient.downloadBinary(`${itemPath}/content`);
|
|
504
|
+
return {
|
|
505
|
+
json: fileMetadata,
|
|
506
|
+
binary: {
|
|
507
|
+
data: {
|
|
508
|
+
data: binaryData.toString('base64'),
|
|
509
|
+
mimeType: (0, helpers_1.getMimeType)(fileMetadata),
|
|
510
|
+
fileName: fileMetadata.name,
|
|
511
|
+
},
|
|
512
|
+
},
|
|
513
|
+
pairedItem: { item: itemIndex },
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
static async fileGet(context, graphClient, drivePath, itemIndex) {
|
|
517
|
+
const fileId = context.getNodeParameter('fileId', itemIndex);
|
|
518
|
+
const itemPath = (0, helpers_1.buildItemPath)(drivePath, (0, helpers_1.isValidItemId)(fileId) ? undefined : fileId, (0, helpers_1.isValidItemId)(fileId) ? fileId : undefined);
|
|
519
|
+
const file = await graphClient.get(itemPath);
|
|
520
|
+
return {
|
|
521
|
+
json: file,
|
|
522
|
+
pairedItem: { item: itemIndex },
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
static async fileRename(context, graphClient, drivePath, itemIndex) {
|
|
526
|
+
const fileId = context.getNodeParameter('fileId', itemIndex);
|
|
527
|
+
const newName = context.getNodeParameter('newName', itemIndex);
|
|
528
|
+
const itemPath = (0, helpers_1.buildItemPath)(drivePath, (0, helpers_1.isValidItemId)(fileId) ? undefined : fileId, (0, helpers_1.isValidItemId)(fileId) ? fileId : undefined);
|
|
529
|
+
const updatedFile = await graphClient.patch(itemPath, {
|
|
530
|
+
name: newName,
|
|
531
|
+
});
|
|
532
|
+
return {
|
|
533
|
+
json: updatedFile,
|
|
534
|
+
pairedItem: { item: itemIndex },
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
static async fileSearch(context, graphClient, drivePath, itemIndex) {
|
|
538
|
+
const query = context.getNodeParameter('query', itemIndex);
|
|
539
|
+
const files = await graphClient.getAllPages(`${drivePath}/root/search(q='${encodeURIComponent(query)}')`);
|
|
540
|
+
// Filter to only files (exclude folders)
|
|
541
|
+
const fileResults = files.filter(item => !!item.file);
|
|
542
|
+
return fileResults.map(file => ({
|
|
543
|
+
json: file,
|
|
544
|
+
pairedItem: { item: itemIndex },
|
|
545
|
+
}));
|
|
546
|
+
}
|
|
547
|
+
static async fileShare(context, graphClient, drivePath, itemIndex) {
|
|
548
|
+
const fileId = context.getNodeParameter('fileId', itemIndex);
|
|
549
|
+
const linkType = context.getNodeParameter('linkType', itemIndex);
|
|
550
|
+
const linkScope = context.getNodeParameter('linkScope', itemIndex);
|
|
551
|
+
const itemPath = (0, helpers_1.buildItemPath)(drivePath, (0, helpers_1.isValidItemId)(fileId) ? undefined : fileId, (0, helpers_1.isValidItemId)(fileId) ? fileId : undefined);
|
|
552
|
+
const shareRequest = {
|
|
553
|
+
type: linkType,
|
|
554
|
+
scope: linkScope,
|
|
555
|
+
};
|
|
556
|
+
const shareLink = await graphClient.post(`${itemPath}/createLink`, shareRequest);
|
|
557
|
+
return {
|
|
558
|
+
json: shareLink,
|
|
559
|
+
pairedItem: { item: itemIndex },
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
static async fileUpload(context, graphClient, drivePath, itemIndex) {
|
|
563
|
+
const filePath = context.getNodeParameter('filePath', itemIndex);
|
|
564
|
+
const binaryPropertyName = context.getNodeParameter('binaryPropertyName', itemIndex);
|
|
565
|
+
// Get binary data
|
|
566
|
+
const binaryData = context.helpers.assertBinaryData(itemIndex, binaryPropertyName);
|
|
567
|
+
const buffer = await context.helpers.getBinaryDataBuffer(itemIndex, binaryPropertyName);
|
|
568
|
+
// Build upload path
|
|
569
|
+
const sanitizedPath = (0, helpers_1.sanitizePath)(filePath);
|
|
570
|
+
const uploadEndpoint = `${drivePath}/root:/${sanitizedPath}:/content`;
|
|
571
|
+
// Upload
|
|
572
|
+
const uploadedFile = await graphClient.uploadBinary(uploadEndpoint, buffer, binaryData.mimeType);
|
|
573
|
+
return {
|
|
574
|
+
json: uploadedFile,
|
|
575
|
+
pairedItem: { item: itemIndex },
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
// ============================================
|
|
579
|
+
// FOLDER OPERATIONS IMPLEMENTATION
|
|
580
|
+
// ============================================
|
|
581
|
+
static async folderCreate(context, graphClient, drivePath, itemIndex) {
|
|
582
|
+
const folderPath = context.getNodeParameter('folderPath', itemIndex);
|
|
583
|
+
const sanitized = (0, helpers_1.sanitizePath)(folderPath);
|
|
584
|
+
// Extract parent path and folder name
|
|
585
|
+
const lastSlash = sanitized.lastIndexOf('/');
|
|
586
|
+
const parentPath = lastSlash > 0 ? sanitized.substring(0, lastSlash) : '';
|
|
587
|
+
const folderName = lastSlash >= 0 ? sanitized.substring(lastSlash + 1) : sanitized;
|
|
588
|
+
// Build parent endpoint
|
|
589
|
+
const parentEndpoint = parentPath
|
|
590
|
+
? `${drivePath}/root:/${parentPath}:/children`
|
|
591
|
+
: `${drivePath}/root/children`;
|
|
592
|
+
const newFolder = await graphClient.post(parentEndpoint, {
|
|
593
|
+
name: folderName,
|
|
594
|
+
folder: {},
|
|
595
|
+
'@microsoft.graph.conflictBehavior': 'fail',
|
|
596
|
+
});
|
|
597
|
+
return {
|
|
598
|
+
json: newFolder,
|
|
599
|
+
pairedItem: { item: itemIndex },
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
static async folderDelete(context, graphClient, drivePath, itemIndex) {
|
|
603
|
+
const folderId = context.getNodeParameter('folderId', itemIndex);
|
|
604
|
+
const itemPath = (0, helpers_1.buildItemPath)(drivePath, (0, helpers_1.isValidItemId)(folderId) ? undefined : folderId, (0, helpers_1.isValidItemId)(folderId) ? folderId : undefined);
|
|
605
|
+
await graphClient.delete(itemPath);
|
|
606
|
+
return {
|
|
607
|
+
json: {
|
|
608
|
+
success: true,
|
|
609
|
+
folderId,
|
|
610
|
+
},
|
|
611
|
+
pairedItem: { item: itemIndex },
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
static async folderGetItems(context, graphClient, drivePath, itemIndex) {
|
|
615
|
+
const folderId = context.getNodeParameter('folderId', itemIndex);
|
|
616
|
+
const itemPath = (0, helpers_1.buildItemPath)(drivePath, (0, helpers_1.isValidItemId)(folderId) ? undefined : folderId, (0, helpers_1.isValidItemId)(folderId) ? folderId : undefined);
|
|
617
|
+
const items = await graphClient.getAllPages(`${itemPath}/children`);
|
|
618
|
+
return items.map(item => ({
|
|
619
|
+
json: item,
|
|
620
|
+
pairedItem: { item: itemIndex },
|
|
621
|
+
}));
|
|
622
|
+
}
|
|
623
|
+
static async folderRename(context, graphClient, drivePath, itemIndex) {
|
|
624
|
+
const folderId = context.getNodeParameter('folderId', itemIndex);
|
|
625
|
+
const newName = context.getNodeParameter('newName', itemIndex);
|
|
626
|
+
const itemPath = (0, helpers_1.buildItemPath)(drivePath, (0, helpers_1.isValidItemId)(folderId) ? undefined : folderId, (0, helpers_1.isValidItemId)(folderId) ? folderId : undefined);
|
|
627
|
+
const updatedFolder = await graphClient.patch(itemPath, {
|
|
628
|
+
name: newName,
|
|
629
|
+
});
|
|
630
|
+
return {
|
|
631
|
+
json: updatedFolder,
|
|
632
|
+
pairedItem: { item: itemIndex },
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
static async folderSearch(context, graphClient, drivePath, itemIndex) {
|
|
636
|
+
const query = context.getNodeParameter('query', itemIndex);
|
|
637
|
+
const items = await graphClient.getAllPages(`${drivePath}/root/search(q='${encodeURIComponent(query)}')`);
|
|
638
|
+
// Filter to only folders (exclude files)
|
|
639
|
+
const folderResults = items.filter(item => !!item.folder);
|
|
640
|
+
return folderResults.map(folder => ({
|
|
641
|
+
json: folder,
|
|
642
|
+
pairedItem: { item: itemIndex },
|
|
643
|
+
}));
|
|
644
|
+
}
|
|
645
|
+
static async folderShare(context, graphClient, drivePath, itemIndex) {
|
|
646
|
+
const folderId = context.getNodeParameter('folderId', itemIndex);
|
|
647
|
+
const linkType = context.getNodeParameter('linkType', itemIndex);
|
|
648
|
+
const linkScope = context.getNodeParameter('linkScope', itemIndex);
|
|
649
|
+
const itemPath = (0, helpers_1.buildItemPath)(drivePath, (0, helpers_1.isValidItemId)(folderId) ? undefined : folderId, (0, helpers_1.isValidItemId)(folderId) ? folderId : undefined);
|
|
650
|
+
const shareRequest = {
|
|
651
|
+
type: linkType,
|
|
652
|
+
scope: linkScope,
|
|
653
|
+
};
|
|
654
|
+
const shareLink = await graphClient.post(`${itemPath}/createLink`, shareRequest);
|
|
655
|
+
return {
|
|
656
|
+
json: shareLink,
|
|
657
|
+
pairedItem: { item: itemIndex },
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
exports.OneDriveBusiness = OneDriveBusiness;
|