@pipedream/google_drive 1.0.7 → 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.
- package/package.json +1 -1
- package/sources/changes-to-files-in-drive/changes-to-files-in-drive.mjs +147 -0
- package/sources/changes-to-specific-files/changes-to-specific-files.mjs +13 -1
- package/sources/changes-to-specific-files-shared-drive/changes-to-specific-files-shared-drive.mjs +6 -6
- package/sources/common-dedupe-changes.mjs +1 -1
- package/sources/common-webhook.mjs +8 -1
- package/sources/new-files-instant/new-files-instant.mjs +1 -1
- package/sources/new-files-shared-drive/new-files-shared-drive.mjs +1 -1
- package/sources/new-or-modified-comments/new-or-modified-comments.mjs +1 -1
- package/sources/new-or-modified-files/new-or-modified-files.mjs +1 -1
- package/sources/new-or-modified-folders/new-or-modified-folders.mjs +1 -1
- package/sources/new-spreadsheet/new-spreadsheet.mjs +1 -1
package/package.json
CHANGED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import common from "../common-webhook.mjs";
|
|
2
|
+
import {
|
|
3
|
+
MY_DRIVE_VALUE,
|
|
4
|
+
GOOGLE_DRIVE_NOTIFICATION_ADD,
|
|
5
|
+
GOOGLE_DRIVE_NOTIFICATION_CHANGE,
|
|
6
|
+
GOOGLE_DRIVE_NOTIFICATION_UPDATE,
|
|
7
|
+
} from "../../common/constants.mjs";
|
|
8
|
+
import commonDedupeChanges from "../common-dedupe-changes.mjs";
|
|
9
|
+
import { stashFile } from "../../common/utils.mjs";
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
...common,
|
|
13
|
+
key: "google_drive-changes-to-files-in-drive",
|
|
14
|
+
name: "Changes to Files in Drive",
|
|
15
|
+
description: "Emit new event when a change is made to one of the specified files. [See the documentation](https://developers.google.com/drive/api/v3/reference/changes/watch)",
|
|
16
|
+
version: "0.0.1",
|
|
17
|
+
type: "source",
|
|
18
|
+
dedupe: "unique",
|
|
19
|
+
props: {
|
|
20
|
+
infoAlert: {
|
|
21
|
+
type: "alert",
|
|
22
|
+
alertType: "info",
|
|
23
|
+
content: "This source uses `changes.watch` and supports watching 10+ files. To watch for changes to fewer than 10 files, you may want to use the **Changes to Specific Files** source instead (uses `files.watch`).",
|
|
24
|
+
},
|
|
25
|
+
...common.props,
|
|
26
|
+
drive: {
|
|
27
|
+
type: "string",
|
|
28
|
+
label: "Drive",
|
|
29
|
+
description: "Defaults to `My Drive`. To use a [Shared Drive](https://support.google.com/a/users/answer/9310351), use the **Changes to Specific Files (Shared Drive)** source instead.",
|
|
30
|
+
optional: true,
|
|
31
|
+
default: MY_DRIVE_VALUE,
|
|
32
|
+
},
|
|
33
|
+
files: {
|
|
34
|
+
type: "string[]",
|
|
35
|
+
label: "Files",
|
|
36
|
+
description: "The files you want to watch for changes.",
|
|
37
|
+
options({ prevContext }) {
|
|
38
|
+
const { nextPageToken } = prevContext;
|
|
39
|
+
return this.googleDrive.listFilesOptions(nextPageToken, this.getListFilesOpts());
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
includeLink: {
|
|
43
|
+
label: "Include Link",
|
|
44
|
+
type: "boolean",
|
|
45
|
+
description: "Upload file to your File Stash and emit temporary download link to the file. Google Workspace documents will be converted to PDF. See [the docs](https://pipedream.com/docs/connect/components/files) to learn more about working with files in Pipedream.",
|
|
46
|
+
default: false,
|
|
47
|
+
optional: true,
|
|
48
|
+
},
|
|
49
|
+
dir: {
|
|
50
|
+
type: "dir",
|
|
51
|
+
accessMode: "write",
|
|
52
|
+
optional: true,
|
|
53
|
+
},
|
|
54
|
+
...commonDedupeChanges.props,
|
|
55
|
+
},
|
|
56
|
+
hooks: {
|
|
57
|
+
async deploy() {
|
|
58
|
+
const daysAgo = new Date();
|
|
59
|
+
daysAgo.setDate(daysAgo.getDate() - 30);
|
|
60
|
+
const timeString = daysAgo.toISOString();
|
|
61
|
+
|
|
62
|
+
const args = this.getListFilesOpts({
|
|
63
|
+
q: `mimeType != "application/vnd.google-apps.folder" and modifiedTime > "${timeString}" and trashed = false`,
|
|
64
|
+
fields: "files",
|
|
65
|
+
pageSize: 5,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const { files } = await this.googleDrive.listFilesInPage(null, args);
|
|
69
|
+
|
|
70
|
+
await this.processChanges(files);
|
|
71
|
+
},
|
|
72
|
+
...common.hooks,
|
|
73
|
+
},
|
|
74
|
+
methods: {
|
|
75
|
+
...common.methods,
|
|
76
|
+
getUpdateTypes() {
|
|
77
|
+
return [
|
|
78
|
+
GOOGLE_DRIVE_NOTIFICATION_ADD,
|
|
79
|
+
GOOGLE_DRIVE_NOTIFICATION_CHANGE,
|
|
80
|
+
GOOGLE_DRIVE_NOTIFICATION_UPDATE,
|
|
81
|
+
];
|
|
82
|
+
},
|
|
83
|
+
generateMeta(data, headers) {
|
|
84
|
+
const {
|
|
85
|
+
id: fileId,
|
|
86
|
+
name: fileName,
|
|
87
|
+
modifiedTime: tsString,
|
|
88
|
+
} = data;
|
|
89
|
+
const ts = Date.parse(tsString);
|
|
90
|
+
const resourceState = headers && headers["x-goog-resource-state"];
|
|
91
|
+
|
|
92
|
+
const summary = resourceState
|
|
93
|
+
? `${resourceState.toUpperCase()} - ${fileName || "Untitled"}`
|
|
94
|
+
: fileName || "Untitled";
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
id: `${fileId}-${ts}`,
|
|
98
|
+
summary,
|
|
99
|
+
ts,
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
isFileRelevant(file) {
|
|
103
|
+
return this.files.includes(file.id);
|
|
104
|
+
},
|
|
105
|
+
getChanges(headers) {
|
|
106
|
+
if (!headers) {
|
|
107
|
+
return {
|
|
108
|
+
change: { },
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
change: {
|
|
113
|
+
state: headers["x-goog-resource-state"],
|
|
114
|
+
resourceURI: headers["x-goog-resource-uri"],
|
|
115
|
+
changed: headers["x-goog-changed"], // "Additional details about the changes. Possible values: content, parents, children, permissions"
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
},
|
|
119
|
+
async processChange(file, headers) {
|
|
120
|
+
const changes = this.getChanges(headers);
|
|
121
|
+
const fileInfo = await this.googleDrive.getFile(file.id);
|
|
122
|
+
if (this.includeLink) {
|
|
123
|
+
fileInfo.file = await stashFile(file, this.googleDrive, this.dir);
|
|
124
|
+
}
|
|
125
|
+
const eventToEmit = {
|
|
126
|
+
file: fileInfo,
|
|
127
|
+
...changes,
|
|
128
|
+
};
|
|
129
|
+
const meta = this.generateMeta(fileInfo, headers);
|
|
130
|
+
this.$emit(eventToEmit, meta);
|
|
131
|
+
},
|
|
132
|
+
async processChanges(changedFiles, headers) {
|
|
133
|
+
console.log(`Processing ${changedFiles.length} changed files`);
|
|
134
|
+
console.log(`Changed files: ${JSON.stringify(changedFiles, null, 2)}!!!`);
|
|
135
|
+
console.log(`Files: ${this.files}!!!`);
|
|
136
|
+
|
|
137
|
+
const filteredFiles = this.checkMinimumInterval(changedFiles);
|
|
138
|
+
for (const file of filteredFiles) {
|
|
139
|
+
if (!this.isFileRelevant(file)) {
|
|
140
|
+
console.log(`Skipping event for irrelevant file ${file.id}`);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
await this.processChange(file, headers);
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
};
|
|
@@ -3,6 +3,7 @@ import includes from "lodash/includes.js";
|
|
|
3
3
|
import { v4 as uuid } from "uuid";
|
|
4
4
|
import { MY_DRIVE_VALUE } from "../../common/constants.mjs";
|
|
5
5
|
import changesToSpecificFiles from "../changes-to-specific-files-shared-drive/changes-to-specific-files-shared-drive.mjs";
|
|
6
|
+
import { ConfigurationError } from "@pipedream/platform";
|
|
6
7
|
import sampleEmit from "./test-event.mjs";
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -15,12 +16,17 @@ export default {
|
|
|
15
16
|
key: "google_drive-changes-to-specific-files",
|
|
16
17
|
name: "Changes to Specific Files",
|
|
17
18
|
description: "Watches for changes to specific files, emitting an event when a change is made to one of those files. To watch for changes to [shared drive](https://support.google.com/a/users/answer/9310351) files, use the **Changes to Specific Files (Shared Drive)** source instead.",
|
|
18
|
-
version: "0.3.
|
|
19
|
+
version: "0.3.1",
|
|
19
20
|
type: "source",
|
|
20
21
|
// Dedupe events based on the "x-goog-message-number" header for the target channel:
|
|
21
22
|
// https://developers.google.com/drive/api/v3/push#making-watch-requests
|
|
22
23
|
dedupe: "unique",
|
|
23
24
|
props: {
|
|
25
|
+
infoAlert: {
|
|
26
|
+
type: "alert",
|
|
27
|
+
alertType: "info",
|
|
28
|
+
content: "This source uses `files.watch` and supports up to 10 file subscriptions. To watch for changes to more than 10 files, use the **Changes to Files in Drive** source instead (uses `changes.watch`).",
|
|
29
|
+
},
|
|
24
30
|
...changesToSpecificFiles.props,
|
|
25
31
|
drive: {
|
|
26
32
|
type: "string",
|
|
@@ -50,6 +56,12 @@ export default {
|
|
|
50
56
|
},
|
|
51
57
|
hooks: {
|
|
52
58
|
...changesToSpecificFiles.hooks,
|
|
59
|
+
async deploy() {
|
|
60
|
+
if (this.files.length > 10) {
|
|
61
|
+
throw new ConfigurationError("This source only supports up to 10 files");
|
|
62
|
+
}
|
|
63
|
+
await changesToSpecificFiles.hooks.deploy.bind(this)();
|
|
64
|
+
},
|
|
53
65
|
async activate() {
|
|
54
66
|
// Called when a component is created or updated. Handles all the logic
|
|
55
67
|
// for starting and stopping watch notifications tied to the desired
|
package/sources/changes-to-specific-files-shared-drive/changes-to-specific-files-shared-drive.mjs
CHANGED
|
@@ -28,7 +28,7 @@ export default {
|
|
|
28
28
|
key: "google_drive-changes-to-specific-files-shared-drive",
|
|
29
29
|
name: "Changes to Specific Files (Shared Drive)",
|
|
30
30
|
description: "Watches for changes to specific files in a shared drive, emitting an event when a change is made to one of those files",
|
|
31
|
-
version: "0.3.
|
|
31
|
+
version: "0.3.1",
|
|
32
32
|
type: "source",
|
|
33
33
|
// Dedupe events based on the "x-goog-message-number" header for the target channel:
|
|
34
34
|
// https://developers.google.com/drive/api/v3/push#making-watch-requests
|
|
@@ -92,7 +92,6 @@ export default {
|
|
|
92
92
|
modifiedTime: tsString,
|
|
93
93
|
} = data;
|
|
94
94
|
const ts = Date.parse(tsString);
|
|
95
|
-
const eventId = headers && headers["x-goog-message-number"];
|
|
96
95
|
const resourceState = headers && headers["x-goog-resource-state"];
|
|
97
96
|
|
|
98
97
|
const summary = resourceState
|
|
@@ -100,7 +99,7 @@ export default {
|
|
|
100
99
|
: fileName || "Untitled";
|
|
101
100
|
|
|
102
101
|
return {
|
|
103
|
-
id: `${fileId}-${
|
|
102
|
+
id: `${fileId}-${ts}`,
|
|
104
103
|
summary,
|
|
105
104
|
ts,
|
|
106
105
|
};
|
|
@@ -124,14 +123,15 @@ export default {
|
|
|
124
123
|
},
|
|
125
124
|
async processChange(file, headers) {
|
|
126
125
|
const changes = this.getChanges(headers);
|
|
126
|
+
const fileInfo = await this.googleDrive.getFile(file.id);
|
|
127
127
|
if (this.includeLink) {
|
|
128
|
-
|
|
128
|
+
fileInfo.file = await stashFile(file, this.googleDrive, this.dir);
|
|
129
129
|
}
|
|
130
130
|
const eventToEmit = {
|
|
131
|
-
file,
|
|
131
|
+
file: fileInfo,
|
|
132
132
|
...changes,
|
|
133
133
|
};
|
|
134
|
-
const meta = this.generateMeta(
|
|
134
|
+
const meta = this.generateMeta(fileInfo, headers);
|
|
135
135
|
this.$emit(eventToEmit, meta);
|
|
136
136
|
},
|
|
137
137
|
async processChanges(changedFiles, headers) {
|
|
@@ -13,7 +13,7 @@ You can change or disable this minimum interval using the prop \`Minimum Interva
|
|
|
13
13
|
description: "How many minutes to wait until the same file can emit another event.\n\nIf set to `0`, this interval is disabled and all events will be emitted.",
|
|
14
14
|
min: 0,
|
|
15
15
|
max: 60,
|
|
16
|
-
default:
|
|
16
|
+
default: 3,
|
|
17
17
|
optional: true,
|
|
18
18
|
},
|
|
19
19
|
},
|
|
@@ -10,7 +10,10 @@ export default {
|
|
|
10
10
|
props: {
|
|
11
11
|
googleDrive,
|
|
12
12
|
db: "$.service.db",
|
|
13
|
-
http:
|
|
13
|
+
http: {
|
|
14
|
+
type: "$.interface.http",
|
|
15
|
+
customResponse: true,
|
|
16
|
+
},
|
|
14
17
|
drive: {
|
|
15
18
|
propDefinition: [
|
|
16
19
|
googleDrive,
|
|
@@ -157,6 +160,10 @@ export default {
|
|
|
157
160
|
this._setChannelID(newChannelID);
|
|
158
161
|
this._setPageToken(newPageToken);
|
|
159
162
|
return;
|
|
163
|
+
} else {
|
|
164
|
+
this.http.respond({
|
|
165
|
+
status: 200,
|
|
166
|
+
});
|
|
160
167
|
}
|
|
161
168
|
|
|
162
169
|
const { headers } = event;
|
|
@@ -11,7 +11,7 @@ export default {
|
|
|
11
11
|
key: "google_drive-new-files-instant",
|
|
12
12
|
name: "New Files (Instant)",
|
|
13
13
|
description: "Emit new event when a new file is added in your linked Google Drive",
|
|
14
|
-
version: "0.2.
|
|
14
|
+
version: "0.2.1",
|
|
15
15
|
type: "source",
|
|
16
16
|
dedupe: "unique",
|
|
17
17
|
props: {
|
|
@@ -7,7 +7,7 @@ export default {
|
|
|
7
7
|
key: "google_drive-new-files-shared-drive",
|
|
8
8
|
name: "New Files (Shared Drive)",
|
|
9
9
|
description: "Emit new event when a new file is added in your shared Google Drive",
|
|
10
|
-
version: "0.1.
|
|
10
|
+
version: "0.1.1",
|
|
11
11
|
type: "source",
|
|
12
12
|
dedupe: "unique",
|
|
13
13
|
props: {
|
|
@@ -17,7 +17,7 @@ export default {
|
|
|
17
17
|
name: "New or Modified Comments (Instant)",
|
|
18
18
|
description:
|
|
19
19
|
"Emit new event when a comment is created or modified in the selected file",
|
|
20
|
-
version: "1.0.
|
|
20
|
+
version: "1.0.10",
|
|
21
21
|
type: "source",
|
|
22
22
|
// Dedupe events based on the "x-goog-message-number" header for the target channel:
|
|
23
23
|
// https://developers.google.com/drive/api/v3/push#making-watch-requests
|
|
@@ -25,7 +25,7 @@ export default {
|
|
|
25
25
|
key: "google_drive-new-or-modified-files",
|
|
26
26
|
name: "New or Modified Files (Instant)",
|
|
27
27
|
description: "Emit new event when a file in the selected Drive is created, modified or trashed.",
|
|
28
|
-
version: "0.4.
|
|
28
|
+
version: "0.4.1",
|
|
29
29
|
type: "source",
|
|
30
30
|
// Dedupe events based on the "x-goog-message-number" header for the target channel:
|
|
31
31
|
// https://developers.google.com/drive/api/v3/push#making-watch-requests
|
|
@@ -20,7 +20,7 @@ export default {
|
|
|
20
20
|
key: "google_drive-new-or-modified-folders",
|
|
21
21
|
name: "New or Modified Folders (Instant)",
|
|
22
22
|
description: "Emit new event when a folder is created or modified in the selected Drive",
|
|
23
|
-
version: "0.2.
|
|
23
|
+
version: "0.2.3",
|
|
24
24
|
type: "source",
|
|
25
25
|
// Dedupe events based on the "x-goog-message-number" header for the target channel:
|
|
26
26
|
// https://developers.google.com/drive/api/v3/push#making-watch-requests
|
|
@@ -6,7 +6,7 @@ export default {
|
|
|
6
6
|
type: "source",
|
|
7
7
|
name: "New Spreadsheet (Instant)",
|
|
8
8
|
description: "Emit new event when a new spreadsheet is created in a drive.",
|
|
9
|
-
version: "0.1.
|
|
9
|
+
version: "0.1.16",
|
|
10
10
|
props: {
|
|
11
11
|
googleDrive: newFilesInstant.props.googleDrive,
|
|
12
12
|
db: newFilesInstant.props.db,
|