@pipedream/google_drive 0.3.3 → 0.4.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.
Files changed (41) hide show
  1. package/actions/add-file-sharing-preference/add-file-sharing-preference.mjs +83 -0
  2. package/actions/copy-file/copy-file.mjs +34 -0
  3. package/actions/create-file/create-file.mjs +242 -0
  4. package/actions/create-file-from-template/create-file-from-template.mjs +98 -0
  5. package/actions/create-file-from-text/create-file-from-text.mjs +67 -0
  6. package/actions/create-folder/create-folder.mjs +54 -0
  7. package/actions/create-shared-drive/create-shared-drive.mjs +25 -0
  8. package/actions/delete-file/delete-file.mjs +37 -0
  9. package/actions/delete-shared-drive/delete-shared-drive.mjs +30 -0
  10. package/actions/download-file/download-file.mjs +120 -0
  11. package/actions/find-file/find-file.mjs +35 -0
  12. package/actions/find-folder/find-folder.mjs +38 -0
  13. package/actions/get-folder-id-for-path/get-folder-id-for-path.mjs +62 -0
  14. package/actions/get-shared-drive/get-shared-drive.mjs +37 -0
  15. package/actions/google-mime-types.mjs +19 -0
  16. package/actions/google-workspace-export-formats.mjs +74 -0
  17. package/actions/language-codes.mjs +742 -0
  18. package/actions/move-file/move-file.mjs +52 -0
  19. package/actions/move-file-to-trash/move-file-to-trash.mjs +41 -0
  20. package/actions/replace-file/replace-file.mjs +90 -0
  21. package/actions/search-shared-drives/search-shared-drives.mjs +34 -0
  22. package/actions/update-file/update-file.mjs +164 -0
  23. package/actions/update-shared-drive/update-shared-drive.mjs +77 -0
  24. package/actions/upload-file/upload-file.mjs +89 -0
  25. package/constants.mjs +190 -0
  26. package/google_drive.app.mjs +1429 -0
  27. package/package.json +23 -20
  28. package/pnpm-lock.yaml +393 -0
  29. package/sources/changes-to-specific-files/changes-to-specific-files.mjs +226 -0
  30. package/sources/changes-to-specific-files-shared-drive/changes-to-specific-files-shared-drive.mjs +110 -0
  31. package/sources/common-webhook.mjs +201 -0
  32. package/sources/new-files-instant/new-files-instant.mjs +95 -0
  33. package/sources/new-or-modified-comments/new-or-modified-comments.mjs +104 -0
  34. package/sources/new-or-modified-files/new-or-modified-files.mjs +66 -0
  35. package/sources/new-or-modified-folders/new-or-modified-folders.mjs +86 -0
  36. package/sources/new-shared-drive/new-shared-drive.mjs +68 -0
  37. package/utils.mjs +247 -0
  38. package/LICENSE +0 -7
  39. package/google_drive.app.js +0 -212
  40. package/sources/changes-to-specific-files/changes-to-specific-files.js +0 -226
  41. package/sources/new-or-modified-files/new-or-modified-files.js +0 -213
@@ -0,0 +1,52 @@
1
+ import googleDrive from "../../google_drive.app.mjs";
2
+
3
+ export default {
4
+ key: "google_drive-move-file",
5
+ name: "Move File",
6
+ description: "Move a file from one folder to another. [See the docs](https://developers.google.com/drive/api/v3/reference/files/update) for more information",
7
+ version: "0.0.4",
8
+ type: "action",
9
+ props: {
10
+ googleDrive,
11
+ drive: {
12
+ propDefinition: [
13
+ googleDrive,
14
+ "watchedDrive",
15
+ ],
16
+ optional: true,
17
+ },
18
+ fileId: {
19
+ propDefinition: [
20
+ googleDrive,
21
+ "fileId",
22
+ (c) => ({
23
+ drive: c.drive,
24
+ }),
25
+ ],
26
+ description: "The file to move",
27
+ },
28
+ folderId: {
29
+ propDefinition: [
30
+ googleDrive,
31
+ "folderId",
32
+ (c) => ({
33
+ drive: c.drive,
34
+ }),
35
+ ],
36
+ description: "The folder you want to move the file to",
37
+ optional: true,
38
+ },
39
+ },
40
+ async run({ $ }) {
41
+ // Get file to get parents to remove
42
+ const file = await this.googleDrive.getFile(this.fileId);
43
+ // Update file, removing old parents, adding new parent folder
44
+ const resp = await this.googleDrive.updateFile(this.fileId, {
45
+ fields: "*",
46
+ removeParents: file.parents.join(","),
47
+ addParents: this.folderId,
48
+ });
49
+ $.export("$summary", `Successfully moved the file, "${file.name}"`);
50
+ return resp;
51
+ },
52
+ };
@@ -0,0 +1,41 @@
1
+ import googleDrive from "../../google_drive.app.mjs";
2
+ import { GOOGLE_DRIVE_FOLDER_MIME_TYPE } from "../../constants.mjs";
3
+
4
+ export default {
5
+ key: "google_drive-move-file-to-trash",
6
+ name: "Move File to Trash",
7
+ description: "Move a file or folder to trash. [See the docs](https://developers.google.com/drive/api/v3/reference/files/update) for more information",
8
+ version: "0.0.4",
9
+ type: "action",
10
+ props: {
11
+ googleDrive,
12
+ drive: {
13
+ propDefinition: [
14
+ googleDrive,
15
+ "watchedDrive",
16
+ ],
17
+ optional: true,
18
+ },
19
+ fileId: {
20
+ propDefinition: [
21
+ googleDrive,
22
+ "fileOrFolderId",
23
+ (c) => ({
24
+ drive: c.drive,
25
+ }),
26
+ ],
27
+ description: "The file or folder to move to trash",
28
+ },
29
+ },
30
+ async run({ $ }) {
31
+ const resp = await this.googleDrive.updateFile(this.fileId, {
32
+ requestBody: {
33
+ trashed: true,
34
+ },
35
+ });
36
+ $.export("$summary", `Successfully moved the ${resp.mimeType === GOOGLE_DRIVE_FOLDER_MIME_TYPE
37
+ ? "folder"
38
+ : "file"} "${resp.name}" to trash`);
39
+ return resp;
40
+ },
41
+ };
@@ -0,0 +1,90 @@
1
+ import path from "path";
2
+ import googleDrive from "../../google_drive.app.mjs";
3
+ import { omitEmptyStringValues } from "../../utils.mjs";
4
+
5
+ import { getFileStream } from "../../utils.mjs";
6
+
7
+ export default {
8
+ key: "google_drive-replace-file",
9
+ name: "Replace File",
10
+ description: "Upload a file that replaces an existing file. [See the docs](https://developers.google.com/drive/api/v3/reference/files/update) for more information",
11
+ version: "0.0.4",
12
+ type: "action",
13
+ props: {
14
+ googleDrive,
15
+ drive: {
16
+ propDefinition: [
17
+ googleDrive,
18
+ "watchedDrive",
19
+ ],
20
+ optional: true,
21
+ },
22
+ fileId: {
23
+ propDefinition: [
24
+ googleDrive,
25
+ "fileId",
26
+ (c) => ({
27
+ drive: c.drive,
28
+ }),
29
+ ],
30
+ optional: false,
31
+ description: "The file to update",
32
+ },
33
+ fileUrl: {
34
+ propDefinition: [
35
+ googleDrive,
36
+ "fileUrl",
37
+ ],
38
+ },
39
+ filePath: {
40
+ propDefinition: [
41
+ googleDrive,
42
+ "filePath",
43
+ ],
44
+ },
45
+ name: {
46
+ propDefinition: [
47
+ googleDrive,
48
+ "fileName",
49
+ ],
50
+ label: "Name",
51
+ description: "The name of the new file (e.g., `myFile.csv`)",
52
+ },
53
+ mimeType: {
54
+ propDefinition: [
55
+ googleDrive,
56
+ "mimeType",
57
+ ],
58
+ description: "The MIME type of the new file (e.g., `image/jpeg`)",
59
+ },
60
+ },
61
+ async run({ $ }) {
62
+ const {
63
+ fileId,
64
+ fileUrl,
65
+ filePath,
66
+ name,
67
+ mimeType,
68
+ } = this;
69
+ if (!fileUrl && !filePath) {
70
+ throw new Error("One of File URL and File Path is required.");
71
+ }
72
+ const fileStream = await getFileStream({
73
+ $,
74
+ fileUrl,
75
+ filePath,
76
+ });
77
+ // Update file media separately from metadata to prevent multipart upload,
78
+ // which `google-apis-nodejs-client` doesn't seem to support for
79
+ // [files.update](https://bit.ly/3lP5sWn)
80
+ await this.googleDrive.updateFileMedia(fileId, fileStream, omitEmptyStringValues({
81
+ mimeType,
82
+ }));
83
+ const resp = await this.googleDrive.updateFile(fileId, omitEmptyStringValues({
84
+ name: name || path.basename(fileUrl || filePath),
85
+ mimeType,
86
+ }));
87
+ $.export("$summary", "Successfully replaced the file");
88
+ return resp;
89
+ },
90
+ };
@@ -0,0 +1,34 @@
1
+ import googleDrive from "../../google_drive.app.mjs";
2
+
3
+ export default {
4
+ key: "google_drive-search-shared-drives",
5
+ name: "Search for Shared Drives",
6
+ description: "Search for shared drives with query options. [See the docs](https://developers.google.com/drive/api/v3/search-shareddrives) for more information",
7
+ version: "0.0.3",
8
+ type: "action",
9
+ props: {
10
+ googleDrive,
11
+ q: {
12
+ type: "string",
13
+ label: "Search Query",
14
+ description:
15
+ "The [shared drives](https://support.google.com/a/users/answer/9310351) search query. See [query terms](https://developers.google.com/drive/api/v3/ref-search-terms#drive_properties) for a list of shard drive-specific query terms.",
16
+ },
17
+ useDomainAdminAccess: {
18
+ propDefinition: [
19
+ googleDrive,
20
+ "useDomainAdminAccess",
21
+ ],
22
+ },
23
+ },
24
+ async run({ $ }) {
25
+ const drives = (
26
+ await this.googleDrive.searchDrives({
27
+ q: this.q,
28
+ useDomainAdminAccess: this.useDomainAdminAccess,
29
+ })
30
+ ).drives;
31
+ $.export("$summary", `Successfully found ${drives.length} shared drives using the search query "${this.q}"`);
32
+ return drives;
33
+ },
34
+ };
@@ -0,0 +1,164 @@
1
+ import googleDrive from "../../google_drive.app.mjs";
2
+ import { toSingleLineString } from "../../utils.mjs";
3
+ import { getFileStream } from "../../utils.mjs";
4
+
5
+ export default {
6
+ key: "google_drive-update-file",
7
+ name: "Update File",
8
+ description: "Update a file's metadata and/or content. [See the docs](https://developers.google.com/drive/api/v3/reference/files/update) for more information",
9
+ version: "0.0.4",
10
+ type: "action",
11
+ props: {
12
+ googleDrive,
13
+ drive: {
14
+ propDefinition: [
15
+ googleDrive,
16
+ "watchedDrive",
17
+ ],
18
+
19
+ optional: true,
20
+ },
21
+ fileId: {
22
+ propDefinition: [
23
+ googleDrive,
24
+ "fileId",
25
+ (c) => ({
26
+ drive: c.drive,
27
+ }),
28
+ ],
29
+ description: "The file to update",
30
+ },
31
+ fileUrl: {
32
+ propDefinition: [
33
+ googleDrive,
34
+ "fileUrl",
35
+ ],
36
+ description: "The URL of the file to use to update content",
37
+ },
38
+ filePath: {
39
+ propDefinition: [
40
+ googleDrive,
41
+ "filePath",
42
+ ],
43
+ description: toSingleLineString(`
44
+ The path to the file saved to the [\`/tmp\`
45
+ directory](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory)
46
+ (e.g., \`/tmp/myFile.csv\`) with which to update content
47
+ `),
48
+ },
49
+ name: {
50
+ propDefinition: [
51
+ googleDrive,
52
+ "fileName",
53
+ ],
54
+ description: "The new name of the file",
55
+ },
56
+ mimeType: {
57
+ propDefinition: [
58
+ googleDrive,
59
+ "mimeType",
60
+ ],
61
+ description:
62
+ "The file's MIME type (e.g., `image/jpeg`). The value cannot be changed unless a new revision is uploaded.",
63
+ },
64
+ addParents: {
65
+ propDefinition: [
66
+ googleDrive,
67
+ "folderId",
68
+ ],
69
+ type: "string[]",
70
+ label: "Add Parents",
71
+ description: "A list of parent folder IDs to add",
72
+ optional: true,
73
+ },
74
+ removeParents: {
75
+ propDefinition: [
76
+ googleDrive,
77
+ "fileParents",
78
+ ({ fileId }) => ({
79
+ fileId,
80
+ }),
81
+ ],
82
+ label: "Remove Parents",
83
+ description: "A list of parent folder IDs to remove",
84
+ },
85
+ keepRevisionForever: {
86
+ propDefinition: [
87
+ googleDrive,
88
+ "keepRevisionForever",
89
+ ],
90
+ },
91
+ ocrLanguage: {
92
+ propDefinition: [
93
+ googleDrive,
94
+ "ocrLanguage",
95
+ ],
96
+ },
97
+ useContentAsIndexableText: {
98
+ propDefinition: [
99
+ googleDrive,
100
+ "useContentAsIndexableText",
101
+ ],
102
+ },
103
+ advanced: {
104
+ type: "object",
105
+ label: "Advanced Options",
106
+ optional: true,
107
+ description: toSingleLineString(`
108
+ Specify less-common properties that you want to use. See [Files: update]
109
+ (https://developers.google.com/drive/api/v3/reference/files/update#request-body) for a list
110
+ of supported properties.
111
+ `),
112
+ },
113
+ },
114
+ async run({ $ }) {
115
+ const {
116
+ fileId,
117
+ fileUrl,
118
+ filePath,
119
+ name,
120
+ mimeType,
121
+ addParents,
122
+ removeParents,
123
+ keepRevisionForever,
124
+ ocrLanguage,
125
+ useContentAsIndexableText,
126
+ advanced,
127
+ } = this;
128
+
129
+ const fileStream =
130
+ fileUrl || filePath
131
+ ? await getFileStream({
132
+ $,
133
+ fileUrl,
134
+ filePath,
135
+ })
136
+ : undefined;
137
+
138
+ // Update file content, if set, separately from metadata to prevent
139
+ // multipart upload, which `google-apis-nodejs-client` doesn't seem to
140
+ // support for [files.update](https://bit.ly/3lP5sWn)
141
+ if (fileStream) {
142
+ await this.googleDrive.updateFileMedia(fileId, fileStream, {
143
+ mimeType,
144
+ });
145
+ }
146
+
147
+ const resp = await this.googleDrive.updateFile(fileId, {
148
+ name,
149
+ mimeType,
150
+ addParents: addParents?.join(","),
151
+ removeParents: removeParents?.join(","),
152
+ keepRevisionForever,
153
+ ocrLanguage,
154
+ useContentAsIndexableText,
155
+ requestBody: {
156
+ ...advanced,
157
+ },
158
+ fields: "*",
159
+ });
160
+ // eslint-disable-next-line multiline-ternary
161
+ $.export("$summary", `Successfully updated the file, "${name ? resp.id : resp.name}"`);
162
+ return resp;
163
+ },
164
+ };
@@ -0,0 +1,77 @@
1
+ import googleDrive from "../../google_drive.app.mjs";
2
+
3
+ export default {
4
+ key: "google_drive-update-shared-drive",
5
+ name: "Update Shared Drive",
6
+ description: "Update an existing shared drive. [See the docs](https://developers.google.com/drive/api/v3/reference/drives/update) for more information",
7
+ version: "0.0.3",
8
+ type: "action",
9
+ props: {
10
+ googleDrive,
11
+ drive: {
12
+ propDefinition: [
13
+ googleDrive,
14
+ "watchedDrive",
15
+ ],
16
+ description:
17
+ "Select a [shared drive](https://support.google.com/a/users/answer/9310351) to update",
18
+ default: "",
19
+ },
20
+ useDomainAdminAccess: {
21
+ propDefinition: [
22
+ googleDrive,
23
+ "useDomainAdminAccess",
24
+ ],
25
+ },
26
+ backgroundImageLink: {
27
+ type: "string",
28
+ label: "Background Image Link",
29
+ description:
30
+ "A link to the new backround image for the shared drive. Cannot be set if `Theme ID` is set in the same request.",
31
+ optional: true,
32
+ },
33
+ colorRgb: {
34
+ type: "string",
35
+ label: "Color",
36
+ description:
37
+ "The new color of this shared drive as an RGB hex string. Cannot be set if `Theme ID` is set in the same request.",
38
+ optional: true,
39
+ },
40
+ themeId: {
41
+ type: "string",
42
+ label: "Theme ID",
43
+ description:
44
+ "The ID of the theme from which the background image and color will be set. Cannot be set if `Color` or `Background Image Link` is set in the same request.",
45
+ optional: true,
46
+ },
47
+ restrictions: {
48
+ type: "object",
49
+ label: "Restrictions",
50
+ description:
51
+ "A set of restrictions that apply to this shared drive or items inside this shared drive. See `restrictions` in the [Drive resource representation](https://developers.google.com/drive/api/v3/reference/drives#resource-representations).",
52
+ optional: true,
53
+ default: {},
54
+ },
55
+ },
56
+ async run({ $ }) {
57
+ const {
58
+ useDomainAdminAccess,
59
+ backgroundImageLink,
60
+ colorRgb,
61
+ themeId,
62
+ restrictions,
63
+ } = this;
64
+ const driveId = this.googleDrive.getDriveId(this.drive);
65
+ const resp = await this.googleDrive.updateSharedDrive(driveId, {
66
+ useDomainAdminAccess,
67
+ requestBody: {
68
+ backgroundImageLink,
69
+ colorRgb,
70
+ themeId,
71
+ restrictions,
72
+ },
73
+ });
74
+ $.export("$summary", `Successfully updated the shared drive, "${resp.name}"`);
75
+ return resp;
76
+ },
77
+ };
@@ -0,0 +1,89 @@
1
+ import googleDrive from "../../google_drive.app.mjs";
2
+ import path from "path";
3
+ import { getFileStream } from "../../utils.mjs";
4
+ import { omitEmptyStringValues } from "../../utils.mjs";
5
+
6
+ export default {
7
+ key: "google_drive-upload-file",
8
+ name: "Upload File",
9
+ description: "Copy an existing file to Google Drive. [See the docs](https://developers.google.com/drive/api/v3/manage-uploads) for more information",
10
+ version: "0.0.4",
11
+ type: "action",
12
+ props: {
13
+ googleDrive,
14
+ drive: {
15
+ propDefinition: [
16
+ googleDrive,
17
+ "watchedDrive",
18
+ ],
19
+ optional: true,
20
+ },
21
+ parentId: {
22
+ propDefinition: [
23
+ googleDrive,
24
+ "folderId",
25
+ (c) => ({
26
+ drive: c.drive,
27
+ }),
28
+ ],
29
+ description:
30
+ "The folder you want to upload the file to. If not specified, the file will be placed directly in the drive's top-level folder.",
31
+ optional: true,
32
+ },
33
+ fileUrl: {
34
+ propDefinition: [
35
+ googleDrive,
36
+ "fileUrl",
37
+ ],
38
+ },
39
+ filePath: {
40
+ propDefinition: [
41
+ googleDrive,
42
+ "filePath",
43
+ ],
44
+ },
45
+ name: {
46
+ propDefinition: [
47
+ googleDrive,
48
+ "fileName",
49
+ ],
50
+ description:
51
+ "The name of the new file (e.g. `/myFile.csv`). By default, the name is the same as the source file's.",
52
+ },
53
+ mimeType: {
54
+ propDefinition: [
55
+ googleDrive,
56
+ "mimeType",
57
+ ],
58
+ description:
59
+ "The file's MIME type (e.g., `image/jpeg`). Google Drive will attempt to automatically detect an appropriate value from uploaded content if no value is provided.",
60
+ },
61
+ },
62
+ async run({ $ }) {
63
+ const {
64
+ parentId,
65
+ fileUrl,
66
+ filePath,
67
+ name,
68
+ mimeType,
69
+ } = this;
70
+ if (!fileUrl && !filePath) {
71
+ throw new Error("One of File URL and File Path is required.");
72
+ }
73
+ const driveId = this.googleDrive.getDriveId(this.drive);
74
+ const file = await getFileStream({
75
+ $,
76
+ fileUrl,
77
+ filePath,
78
+ });
79
+ const resp = await this.googleDrive.createFile(omitEmptyStringValues({
80
+ file,
81
+ mimeType,
82
+ name: name || path.basename(fileUrl || filePath),
83
+ parentId,
84
+ driveId,
85
+ }));
86
+ $.export("$summary", `Successfully uploaded a new file, "${resp.name}"`);
87
+ return resp;
88
+ },
89
+ };