n8n-nodes-onedrive-business-sp 1.0.0 → 1.1.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.
|
@@ -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
|
|
80
|
+
displayName: 'Watch Folder',
|
|
81
81
|
name: 'watchFolderId',
|
|
82
|
-
type: '
|
|
83
|
-
default: 'root',
|
|
84
|
-
|
|
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
|
|
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) {
|
|
@@ -217,7 +311,15 @@ class MicrosoftOneDriveBusinessTrigger {
|
|
|
217
311
|
};
|
|
218
312
|
}
|
|
219
313
|
const event = this.getNodeParameter('event');
|
|
220
|
-
const
|
|
314
|
+
const watchFolder = this.getNodeParameter('watchFolderId', {});
|
|
315
|
+
// Extract folder ID from resource locator
|
|
316
|
+
let watchFolderId;
|
|
317
|
+
if (typeof watchFolder === 'string') {
|
|
318
|
+
watchFolderId = watchFolder;
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
watchFolderId = watchFolder.value || 'root';
|
|
322
|
+
}
|
|
221
323
|
const driveId = webhookData.driveId;
|
|
222
324
|
// Use delta query to get changes
|
|
223
325
|
let deltaUrl = webhookData.deltaLink;
|