n8n-nodes-onedrive-business-sp 1.0.0 → 1.1.1

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,6 +1,11 @@
1
- import { IHookFunctions, IWebhookFunctions, INodeType, INodeTypeDescription, IWebhookResponseData } from 'n8n-workflow';
1
+ import { IHookFunctions, IWebhookFunctions, INodeType, INodeTypeDescription, IWebhookResponseData, ILoadOptionsFunctions, INodeListSearchResult } from 'n8n-workflow';
2
2
  export declare class MicrosoftOneDriveBusinessTrigger implements INodeType {
3
3
  description: INodeTypeDescription;
4
+ methods: {
5
+ listSearch: {
6
+ getFolders(this: ILoadOptionsFunctions, filter?: string): Promise<INodeListSearchResult>;
7
+ };
8
+ };
4
9
  webhookMethods: {
5
10
  default: {
6
11
  checkExists(this: IHookFunctions): Promise<boolean>;
@@ -77,11 +77,29 @@ class MicrosoftOneDriveBusinessTrigger {
77
77
  description: 'The event to trigger on',
78
78
  },
79
79
  {
80
- displayName: 'Watch Folder ID',
80
+ displayName: 'Watch Folder',
81
81
  name: 'watchFolderId',
82
- type: 'string',
83
- default: 'root',
84
- description: 'The ID of the folder to watch. Use "root" to watch the entire drive.',
82
+ type: 'resourceLocator',
83
+ default: { mode: 'list', value: 'root' },
84
+ required: true,
85
+ modes: [
86
+ {
87
+ displayName: 'From List',
88
+ name: 'list',
89
+ type: 'list',
90
+ typeOptions: {
91
+ searchListMethod: 'getFolders',
92
+ searchable: true,
93
+ },
94
+ },
95
+ {
96
+ displayName: 'By ID',
97
+ name: 'id',
98
+ type: 'string',
99
+ placeholder: 'e.g. 01BYE5RZZFWGWWVNHHKVHYXE4GQI3YKIME',
100
+ },
101
+ ],
102
+ description: 'The folder to watch for changes',
85
103
  },
86
104
  {
87
105
  displayName: 'Options',
@@ -101,6 +119,74 @@ class MicrosoftOneDriveBusinessTrigger {
101
119
  },
102
120
  ],
103
121
  };
122
+ this.methods = {
123
+ listSearch: {
124
+ async getFolders(filter) {
125
+ const siteId = this.getNodeParameter('siteId', '');
126
+ const driveId = this.getNodeParameter('driveId', '');
127
+ if (!siteId) {
128
+ return {
129
+ results: [
130
+ {
131
+ name: 'Root Folder',
132
+ value: 'root',
133
+ },
134
+ ],
135
+ };
136
+ }
137
+ try {
138
+ // Get drive ID if not provided
139
+ let actualDriveId = driveId;
140
+ if (!actualDriveId) {
141
+ const driveResponse = await this.helpers.requestOAuth2.call(this, 'microsoftOneDriveBusinessOAuth2Api', {
142
+ method: 'GET',
143
+ url: `https://graph.microsoft.com/v1.0/sites/${siteId}/drive`,
144
+ json: true,
145
+ });
146
+ actualDriveId = driveResponse.id;
147
+ }
148
+ // Get folders from root
149
+ const response = await this.helpers.requestOAuth2.call(this, 'microsoftOneDriveBusinessOAuth2Api', {
150
+ method: 'GET',
151
+ url: `https://graph.microsoft.com/v1.0/drives/${actualDriveId}/root/children`,
152
+ qs: {
153
+ $filter: 'folder ne null',
154
+ $select: 'id,name,folder',
155
+ $top: 100,
156
+ },
157
+ json: true,
158
+ });
159
+ const folders = response.value;
160
+ const returnData = [
161
+ {
162
+ name: 'Root Folder',
163
+ value: 'root',
164
+ },
165
+ ];
166
+ for (const folder of folders) {
167
+ const folderName = folder.name;
168
+ if (!filter || folderName.toLowerCase().includes(filter.toLowerCase())) {
169
+ returnData.push({
170
+ name: folderName,
171
+ value: folder.id,
172
+ });
173
+ }
174
+ }
175
+ return { results: returnData };
176
+ }
177
+ catch (error) {
178
+ return {
179
+ results: [
180
+ {
181
+ name: 'Root Folder',
182
+ value: 'root',
183
+ },
184
+ ],
185
+ };
186
+ }
187
+ },
188
+ },
189
+ };
104
190
  this.webhookMethods = {
105
191
  default: {
106
192
  async checkExists() {
@@ -137,7 +223,15 @@ class MicrosoftOneDriveBusinessTrigger {
137
223
  const webhookData = this.getWorkflowStaticData('node');
138
224
  const siteId = this.getNodeParameter('siteId');
139
225
  const driveId = this.getNodeParameter('driveId', '');
140
- const watchFolderId = this.getNodeParameter('watchFolderId');
226
+ const watchFolder = this.getNodeParameter('watchFolderId', {});
227
+ // Extract folder ID from resource locator
228
+ let watchFolderId;
229
+ if (typeof watchFolder === 'string') {
230
+ watchFolderId = watchFolder;
231
+ }
232
+ else {
233
+ watchFolderId = watchFolder.value || 'root';
234
+ }
141
235
  // Get drive ID if not provided
142
236
  let actualDriveId = driveId;
143
237
  if (!actualDriveId) {
@@ -148,8 +242,9 @@ class MicrosoftOneDriveBusinessTrigger {
148
242
  });
149
243
  actualDriveId = driveResponse.id;
150
244
  }
151
- const watchPath = watchFolderId === 'root' ? 'root' : `items/${watchFolderId}`;
152
- const resource = `/drives/${actualDriveId}/${watchPath}`;
245
+ // Microsoft Graph only supports subscriptions at drive root level
246
+ // We'll filter by folder in the webhook handler
247
+ const resource = `/drives/${actualDriveId}/root`;
153
248
  // Create subscription
154
249
  const expirationDateTime = new Date();
155
250
  expirationDateTime.setHours(expirationDateTime.getHours() + 72); // 72 hours max
@@ -169,6 +264,7 @@ class MicrosoftOneDriveBusinessTrigger {
169
264
  });
170
265
  webhookData.subscriptionId = responseData.id;
171
266
  webhookData.driveId = actualDriveId;
267
+ webhookData.watchFolderId = watchFolderId;
172
268
  webhookData.deltaLink = null;
173
269
  }
174
270
  catch (error) {
@@ -217,13 +313,21 @@ class MicrosoftOneDriveBusinessTrigger {
217
313
  };
218
314
  }
219
315
  const event = this.getNodeParameter('event');
220
- const watchFolderId = this.getNodeParameter('watchFolderId');
316
+ const watchFolder = this.getNodeParameter('watchFolderId', {});
317
+ // Extract folder ID from resource locator
318
+ let watchFolderId;
319
+ if (typeof watchFolder === 'string') {
320
+ watchFolderId = watchFolder;
321
+ }
322
+ else {
323
+ watchFolderId = watchFolder.value || 'root';
324
+ }
221
325
  const driveId = webhookData.driveId;
222
- // Use delta query to get changes
326
+ const storedWatchFolderId = webhookData.watchFolderId || 'root';
327
+ // Always use root delta query (Microsoft Graph requirement)
223
328
  let deltaUrl = webhookData.deltaLink;
224
329
  if (!deltaUrl) {
225
- const watchPath = watchFolderId === 'root' ? 'root' : `items/${watchFolderId}`;
226
- deltaUrl = `https://graph.microsoft.com/v1.0/drives/${driveId}/${watchPath}/delta`;
330
+ deltaUrl = `https://graph.microsoft.com/v1.0/drives/${driveId}/root/delta`;
227
331
  }
228
332
  try {
229
333
  const deltaResponse = await this.helpers.requestOAuth2.call(this, 'microsoftOneDriveBusinessOAuth2Api', {
@@ -234,12 +338,37 @@ class MicrosoftOneDriveBusinessTrigger {
234
338
  // Store the new delta link
235
339
  webhookData.deltaLink = deltaResponse['@odata.deltaLink'];
236
340
  const changes = deltaResponse.value;
341
+ // Get folder path if watching specific folder
342
+ let watchFolderPath = null;
343
+ if (storedWatchFolderId !== 'root') {
344
+ try {
345
+ const folderInfo = await this.helpers.requestOAuth2.call(this, 'microsoftOneDriveBusinessOAuth2Api', {
346
+ method: 'GET',
347
+ url: `https://graph.microsoft.com/v1.0/drives/${driveId}/items/${storedWatchFolderId}`,
348
+ qs: { $select: 'id,name,parentReference' },
349
+ json: true,
350
+ });
351
+ const parentRef = folderInfo.parentReference;
352
+ watchFolderPath = (parentRef?.path || '') + '/' + folderInfo.name;
353
+ }
354
+ catch (error) {
355
+ // If can't get folder path, don't filter
356
+ }
357
+ }
237
358
  const filteredChanges = changes.filter((change) => {
238
359
  const isFile = change.file !== undefined;
239
360
  const isFolder = change.folder !== undefined;
240
361
  const isDeleted = change.deleted !== undefined;
241
362
  if (isDeleted)
242
363
  return false;
364
+ // Filter by folder path if watching specific folder
365
+ if (watchFolderPath && change.parentReference) {
366
+ const parentRef = change.parentReference;
367
+ const itemPath = parentRef.path || '';
368
+ if (!itemPath.includes(watchFolderPath)) {
369
+ return false;
370
+ }
371
+ }
243
372
  if (event === 'fileCreated' && isFile) {
244
373
  return change.createdDateTime === change.lastModifiedDateTime;
245
374
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-onedrive-business-sp",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "description": "n8n node for Microsoft OneDrive for Business (SharePoint)",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",