@pipedream/sharepoint 0.8.0 → 0.8.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.
package/package.json
CHANGED
|
@@ -4,9 +4,9 @@ import { WEBHOOK_SUBSCRIPTION_RENEWAL_SECONDS } from "../../common/constants.mjs
|
|
|
4
4
|
|
|
5
5
|
export default {
|
|
6
6
|
key: "sharepoint-updated-file-instant",
|
|
7
|
-
name: "
|
|
8
|
-
description: "Emit new event when specific files are updated in a SharePoint document library",
|
|
9
|
-
version: "0.0.
|
|
7
|
+
name: "File Updated or Deleted (Instant)",
|
|
8
|
+
description: "Emit a new event when specific files are updated or deleted in a SharePoint document library",
|
|
9
|
+
version: "0.0.2",
|
|
10
10
|
type: "source",
|
|
11
11
|
dedupe: "unique",
|
|
12
12
|
props: {
|
|
@@ -67,8 +67,8 @@ export default {
|
|
|
67
67
|
],
|
|
68
68
|
label: "Files to Monitor",
|
|
69
69
|
description:
|
|
70
|
-
"Select one or more files to monitor for
|
|
71
|
-
"You'll receive a real-time event whenever any of these files are modified.\n\n" +
|
|
70
|
+
"Select one or more files to monitor for changes. " +
|
|
71
|
+
"You'll receive a real-time event whenever any of these files are modified or deleted.\n\n" +
|
|
72
72
|
"**Important:** Only the selected files will trigger events. Changes to other files in the drive will be ignored. " +
|
|
73
73
|
"This ensures you only receive notifications for the documents you care about.",
|
|
74
74
|
},
|
|
@@ -101,8 +101,39 @@ export default {
|
|
|
101
101
|
clientState,
|
|
102
102
|
});
|
|
103
103
|
|
|
104
|
-
// Store the file IDs we're monitoring (unwrap labeled values)
|
|
105
|
-
const
|
|
104
|
+
// Store the file IDs we're monitoring (unwrap labeled values and parse JSON)
|
|
105
|
+
const wrappedFileIds = this.sharepoint.resolveWrappedArrayValues(this.fileIds);
|
|
106
|
+
// Parse JSON strings to extract just the IDs, handle objects, and trim strings
|
|
107
|
+
const fileIds = wrappedFileIds.map((fileId) => {
|
|
108
|
+
// Handle object values directly
|
|
109
|
+
if (typeof fileId === "object" && fileId !== null) {
|
|
110
|
+
if (!fileId.id) {
|
|
111
|
+
console.log(`Warning: Object fileId missing 'id' field: ${JSON.stringify(fileId)}`);
|
|
112
|
+
return String(fileId);
|
|
113
|
+
}
|
|
114
|
+
return fileId.id;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Handle string values - trim whitespace first
|
|
118
|
+
if (typeof fileId === "string") {
|
|
119
|
+
const trimmedFileId = fileId.trim();
|
|
120
|
+
if (trimmedFileId.startsWith("{")) {
|
|
121
|
+
try {
|
|
122
|
+
const parsed = JSON.parse(trimmedFileId);
|
|
123
|
+
if (!parsed || !parsed.id) {
|
|
124
|
+
throw new Error("Parsed object missing 'id' field");
|
|
125
|
+
}
|
|
126
|
+
return parsed.id;
|
|
127
|
+
} catch (e) {
|
|
128
|
+
console.log(`Warning: Failed to parse fileId: ${trimmedFileId}, error: ${e.message}`);
|
|
129
|
+
return trimmedFileId;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return trimmedFileId;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return fileId;
|
|
136
|
+
});
|
|
106
137
|
this._setMonitoredFileIds(fileIds);
|
|
107
138
|
|
|
108
139
|
// Initialize delta tracking - get current state so we only see future changes
|
|
@@ -220,10 +251,23 @@ export default {
|
|
|
220
251
|
}
|
|
221
252
|
},
|
|
222
253
|
generateMeta(file) {
|
|
223
|
-
|
|
254
|
+
// Use lastModifiedDateTime for updated files, deletedDateTime for deleted files
|
|
255
|
+
// Fall back to current time only if neither is available
|
|
256
|
+
let ts;
|
|
257
|
+
if (file.lastModifiedDateTime) {
|
|
258
|
+
ts = Date.parse(file.lastModifiedDateTime);
|
|
259
|
+
} else if (file.deletedDateTime) {
|
|
260
|
+
ts = Date.parse(file.deletedDateTime);
|
|
261
|
+
} else {
|
|
262
|
+
ts = Date.now();
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const action = file.deleted
|
|
266
|
+
? "deleted"
|
|
267
|
+
: "updated";
|
|
224
268
|
return {
|
|
225
269
|
id: `${file.id}-${ts}`,
|
|
226
|
-
summary: `File
|
|
270
|
+
summary: `File ${action}: ${file.name}`,
|
|
227
271
|
ts,
|
|
228
272
|
};
|
|
229
273
|
},
|
|
@@ -272,8 +316,8 @@ export default {
|
|
|
272
316
|
|
|
273
317
|
const validNotifications = body.value.filter((notification) => {
|
|
274
318
|
if (notification.clientState !== clientState) {
|
|
275
|
-
console.
|
|
276
|
-
`Ignoring notification with unexpected clientState: ${notification.clientState}`,
|
|
319
|
+
console.log(
|
|
320
|
+
`Warning: Ignoring notification with unexpected clientState: ${notification.clientState}`,
|
|
277
321
|
);
|
|
278
322
|
return false;
|
|
279
323
|
}
|
|
@@ -313,8 +357,9 @@ export default {
|
|
|
313
357
|
});
|
|
314
358
|
|
|
315
359
|
// Find files that changed and are in our monitored list
|
|
360
|
+
// Include both updated files (item.file) and deleted files (item.deleted)
|
|
316
361
|
for (const item of deltaResponse.value || []) {
|
|
317
|
-
if (item.file && monitoredFileIds.includes(item.id)) {
|
|
362
|
+
if ((item.file || item.deleted) && monitoredFileIds.includes(item.id)) {
|
|
318
363
|
changedFiles.push(item);
|
|
319
364
|
}
|
|
320
365
|
}
|
|
@@ -336,8 +381,9 @@ export default {
|
|
|
336
381
|
// Emit events for each changed file
|
|
337
382
|
for (const file of changedFiles) {
|
|
338
383
|
// Delta response may not include downloadUrl - fetch fresh if needed
|
|
384
|
+
// Skip fetching download URL for deleted files (they no longer exist)
|
|
339
385
|
let downloadUrl = file["@microsoft.graph.downloadUrl"];
|
|
340
|
-
if (!downloadUrl) {
|
|
386
|
+
if (!downloadUrl && !file.deleted) {
|
|
341
387
|
try {
|
|
342
388
|
const freshFile = await this.sharepoint.getDriveItem({
|
|
343
389
|
driveId,
|