@pipedream/google_drive 0.3.1 → 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,120 @@
1
+ import googleDrive from "../../google_drive.app.mjs";
2
+ import fs from "fs";
3
+ import stream from "stream";
4
+ import { promisify } from "util";
5
+ import { GOOGLE_DRIVE_MIME_TYPE_PREFIX } from "../../constants.mjs";
6
+ import googleWorkspaceExportFormats from "../google-workspace-export-formats.mjs";
7
+ import { toSingleLineString } from "../../utils.mjs";
8
+
9
+ /**
10
+ * Uses Google Drive API to download files to a `filePath` in the /tmp
11
+ * directory.
12
+ *
13
+ * Use `files.export` for Google Workspace files types (e.g.,
14
+ * `application/vnd.google-apps.document`) and `files.get` for other file types,
15
+ * as per the [Download files API guide](https://bit.ly/2ZbJvcn).
16
+ */
17
+ export default {
18
+ key: "google_drive-download-file",
19
+ name: "Download File",
20
+ description: "Download a file. [See the docs](https://developers.google.com/drive/api/v3/manage-downloads) for more information",
21
+ version: "0.0.3",
22
+ type: "action",
23
+ props: {
24
+ googleDrive,
25
+ drive: {
26
+ propDefinition: [
27
+ googleDrive,
28
+ "watchedDrive",
29
+ ],
30
+
31
+ optional: true,
32
+ },
33
+ fileId: {
34
+ propDefinition: [
35
+ googleDrive,
36
+ "fileId",
37
+ (c) => ({
38
+ drive: c.drive,
39
+ }),
40
+ ],
41
+ description: "The file to download",
42
+ },
43
+ filePath: {
44
+ type: "string",
45
+ label: "Destination File Path",
46
+ description: toSingleLineString(`
47
+ The destination path for the file in the [\`/tmp\`
48
+ directory](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory)
49
+ (e.g., \`/tmp/myFile.csv\`)
50
+ `),
51
+ },
52
+ mimeType: {
53
+ type: "string",
54
+ label: "Conversion Format",
55
+ description: toSingleLineString(`
56
+ The format to which to convert the downloaded file if it is a [Google Workspace
57
+ document](https://developers.google.com/drive/api/v3/ref-export-formats)
58
+ `),
59
+ optional: true,
60
+ async options() {
61
+ const fileId = this.fileId;
62
+ if (!fileId) {
63
+ return googleWorkspaceExportFormats;
64
+ }
65
+ let file, exportFormats;
66
+ try {
67
+ ([
68
+ file,
69
+ exportFormats,
70
+ ] = await Promise.all([
71
+ this.googleDrive.getFile(fileId, {
72
+ fields: "mimeType",
73
+ }),
74
+ this.googleDrive.getExportFormats(),
75
+ ]));
76
+ } catch (err) {
77
+ return googleWorkspaceExportFormats;
78
+ }
79
+ const mimeTypes = exportFormats[file.mimeType];
80
+ if (!mimeTypes) {
81
+ return [];
82
+ }
83
+ return exportFormats[file.mimeType].map((f) =>
84
+ googleWorkspaceExportFormats.find(
85
+ (format) => format.value === f,
86
+ ) ?? f);
87
+ },
88
+ },
89
+ },
90
+ async run({ $ }) {
91
+ // Get file metadata to get file's MIME type
92
+ const fileMetadata = await this.googleDrive.getFile(this.fileId, {
93
+ fields: "name,mimeType",
94
+ });
95
+ const mimeType = fileMetadata.mimeType;
96
+
97
+ const isWorkspaceDocument = mimeType.includes(GOOGLE_DRIVE_MIME_TYPE_PREFIX);
98
+ if (isWorkspaceDocument && !this.mimeType) {
99
+ throw new Error("Conversion Format is required when File is a Google Workspace Document");
100
+ }
101
+ // Download file
102
+ // If `mimeType` is a Google MIME type, use `downloadWorkspaceFile`. Otherwise, use `getFile`.
103
+ // See https://developers.google.com/drive/api/v3/mime-types for a list of Google MIME types.
104
+ // Google Workspace format to MIME type map:
105
+ // https://developers.google.com/drive/api/v3/ref-export-formats
106
+ const file = isWorkspaceDocument
107
+ ? await this.googleDrive.downloadWorkspaceFile(this.fileId, {
108
+ mimeType: this.mimeType,
109
+ })
110
+ : await this.googleDrive.getFile(this.fileId, {
111
+ alt: "media",
112
+ });
113
+
114
+ // Stream file to `filePath`
115
+ const pipeline = promisify(stream.pipeline);
116
+ await pipeline(file, fs.createWriteStream(this.filePath));
117
+ $.export("$summary", `Successfully downloaded the file, "${fileMetadata.name}"`);
118
+ return fileMetadata;
119
+ },
120
+ };
@@ -0,0 +1,35 @@
1
+ import googleDrive from "../../google_drive.app.mjs";
2
+ import { getListFilesOpts } from "../../utils.mjs";
3
+
4
+ export default {
5
+ key: "google_drive-find-file",
6
+ name: "Find File",
7
+ description: "Search for a specific file by name. [See the docs](https://developers.google.com/drive/api/v3/search-files) for more information",
8
+ version: "0.0.3",
9
+ type: "action",
10
+ props: {
11
+ googleDrive,
12
+ drive: {
13
+ propDefinition: [
14
+ googleDrive,
15
+ "watchedDrive",
16
+ ],
17
+ optional: true,
18
+ },
19
+ nameSearchTerm: {
20
+ propDefinition: [
21
+ googleDrive,
22
+ "fileNameSearchTerm",
23
+ ],
24
+ },
25
+ },
26
+ async run({ $ }) {
27
+ const opts = getListFilesOpts(this.drive, {
28
+ q: `name contains '${this.nameSearchTerm}'`,
29
+ });
30
+ const files = (await this.googleDrive.listFilesInPage(null, opts)).files;
31
+ // eslint-disable-next-line multiline-ternary
32
+ $.export("$summary", `Successfully found ${files.length} file${files.length === 1 ? "" : "s"} containing the term, "${this.nameSearchTerm}"`);
33
+ return files;
34
+ },
35
+ };
@@ -0,0 +1,38 @@
1
+ import googleDrive from "../../google_drive.app.mjs";
2
+ import { getListFilesOpts } from "../../utils.mjs";
3
+
4
+ import { GOOGLE_DRIVE_FOLDER_MIME_TYPE } from "../../constants.mjs";
5
+
6
+ export default {
7
+ key: "google_drive-find-folder",
8
+ name: "Find Folder",
9
+ description: "Search for a specific folder by name. [See the docs](https://developers.google.com/drive/api/v3/search-files) for more information",
10
+ version: "0.0.3",
11
+ type: "action",
12
+ props: {
13
+ googleDrive,
14
+ drive: {
15
+ propDefinition: [
16
+ googleDrive,
17
+ "watchedDrive",
18
+ ],
19
+ optional: true,
20
+ },
21
+ nameSearchTerm: {
22
+ propDefinition: [
23
+ googleDrive,
24
+ "fileNameSearchTerm",
25
+ ],
26
+ description: "The name of the folder to search for",
27
+ },
28
+ },
29
+ async run({ $ }) {
30
+ const opts = getListFilesOpts(this.drive, {
31
+ q: `mimeType = '${GOOGLE_DRIVE_FOLDER_MIME_TYPE}' and name contains '${this.nameSearchTerm}'`,
32
+ });
33
+ const folders = (await this.googleDrive.listFilesInPage(null, opts)).files;
34
+ // eslint-disable-next-line multiline-ternary
35
+ $.export("$summary", `Successfully found ${folders.length} folder${folders.length === 1 ? "" : "s"} containing the term, "${this.nameSearchTerm}"`);
36
+ return folders;
37
+ },
38
+ };
@@ -0,0 +1,62 @@
1
+ import googleDrive from "../../google_drive.app.mjs";
2
+
3
+ /**
4
+ * Uses Google Drive API to get the folder ID for a Google Drive folder from
5
+ * the `path` to the folder (e.g., `folder1/subFolderA/subFolderB`).
6
+ *
7
+ * For each part of the path, uses the Google Drive API to find a folder with
8
+ * `name` of the part and with `id` of the found folder of the previous part in
9
+ * its `parents`.
10
+ */
11
+ export default {
12
+ key: "google_drive-get-folder-id-for-path",
13
+ name: "Get Folder ID for a Path",
14
+ description: "Retrieve a folderId for a path. [See the docs](https://developers.google.com/drive/api/v3/search-files) for more information",
15
+ version: "0.0.3",
16
+ type: "action",
17
+ props: {
18
+ googleDrive,
19
+ drive: {
20
+ propDefinition: [
21
+ googleDrive,
22
+ "watchedDrive",
23
+ ],
24
+ optional: true,
25
+ },
26
+ path: {
27
+ type: "string",
28
+ label: "Path",
29
+ description:
30
+ "The path to the folder (e.g., `myFolder/mySubFolder1/mySubFolder2`)",
31
+ optional: false,
32
+ },
33
+ },
34
+ async run({ $ }) {
35
+ // Convert path to array (e.g., `"folder1/subFolderA/subFolderB" ->
36
+ // ["folder1","subFolderA","subFolderB"]`)
37
+ const parts = this.path.split("/");
38
+
39
+ let part;
40
+ let parentId;
41
+ // Iterate over parts
42
+ // `parentId` of initial folder is `undefined` or root ("My Drive")
43
+ while ((part = parts.shift())) {
44
+ const folders = await this.googleDrive.findFolder({
45
+ drive: this.drive,
46
+ name: part,
47
+ parentId,
48
+ });
49
+ if (!folders[0]) {
50
+ // Folder at path is not found
51
+ $.export("$summary", `Couldn't find a folderId for the path, "${this.path}"`);
52
+ return undefined;
53
+ }
54
+ // Set parentId of next folder in path to find
55
+ parentId = folders[0] && folders[0].id;
56
+ }
57
+
58
+ $.export("$summary", `Successfully retrieved the folderId for the path, "${this.path}"`);
59
+ // Return id of last folder that is found
60
+ return parentId;
61
+ },
62
+ };
@@ -0,0 +1,37 @@
1
+ import googleDrive from "../../google_drive.app.mjs";
2
+
3
+ export default {
4
+ key: "google_drive-get-shared-drive",
5
+ name: "Get Shared Drive",
6
+ description: "Get a shared drive's metadata by ID. [See the docs](https://developers.google.com/drive/api/v3/reference/drives/get) 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).",
18
+ default: "",
19
+ },
20
+ useDomainAdminAccess: {
21
+ propDefinition: [
22
+ googleDrive,
23
+ "useDomainAdminAccess",
24
+ ],
25
+ },
26
+ },
27
+ async run({ $ }) {
28
+ const resp = await this.googleDrive.getSharedDrive(
29
+ this.googleDrive.getDriveId(this.drive),
30
+ {
31
+ useDomainAdminAccess: this.useDomainAdminAccess,
32
+ },
33
+ );
34
+ $.export("$summary", `Successfully fetched the shared drive, "${resp.name}"`);
35
+ return resp;
36
+ },
37
+ };
@@ -0,0 +1,19 @@
1
+ export default [
2
+ "application/vnd.google-apps.audio",
3
+ "application/vnd.google-apps.document",
4
+ "application/vnd.google-apps.drive-sdk",
5
+ "application/vnd.google-apps.drawing",
6
+ "application/vnd.google-apps.file",
7
+ "application/vnd.google-apps.folder",
8
+ "application/vnd.google-apps.form",
9
+ "application/vnd.google-apps.fusiontable",
10
+ "application/vnd.google-apps.map",
11
+ "application/vnd.google-apps.photo",
12
+ "application/vnd.google-apps.presentation",
13
+ "application/vnd.google-apps.script",
14
+ "application/vnd.google-apps.shortcut",
15
+ "application/vnd.google-apps.site",
16
+ "application/vnd.google-apps.spreadsheet",
17
+ "application/vnd.google-apps.unknown",
18
+ "application/vnd.google-apps.video",
19
+ ];
@@ -0,0 +1,74 @@
1
+ export default [
2
+ {
3
+ value: "application/epub+zip",
4
+ label: "EPUB",
5
+ },
6
+ {
7
+ value: "application/pdf",
8
+ label: "PDF",
9
+ },
10
+ {
11
+ value: "application/rtf",
12
+ label: "Rich Text",
13
+ },
14
+ {
15
+ value: "application/vnd.google-apps.script+json",
16
+ label: "JSON",
17
+ },
18
+ {
19
+ value: "application/vnd.oasis.opendocument.presentation",
20
+ label: "Open Office presentation",
21
+ },
22
+ {
23
+ value: "application/x-vnd.oasis.opendocument.spreadsheet",
24
+ label: "Open Office sheet",
25
+ },
26
+ {
27
+ value: "application/vnd.oasis.opendocument.text",
28
+ label: "Open Office doc",
29
+ },
30
+ {
31
+ value: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
32
+ label: "MS PowerPoint",
33
+ },
34
+ {
35
+ value: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
36
+ label: "MS Excel",
37
+ },
38
+ {
39
+ value: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
40
+ label: "MS Word document",
41
+ },
42
+ {
43
+ value: "application/zip",
44
+ label: "HTML (zipped)",
45
+ },
46
+ {
47
+ value: "image/jpeg",
48
+ label: "JPEG",
49
+ },
50
+ {
51
+ value: "image/png",
52
+ label: "PNG",
53
+ },
54
+ {
55
+ value: "image/svg+xml",
56
+ label: "SVG",
57
+ },
58
+ {
59
+ value: "text/csv",
60
+ label: "CSV (first sheet only)",
61
+ },
62
+ {
63
+ value: "text/html",
64
+ label: "HTML",
65
+ },
66
+ {
67
+ value: "text/plain",
68
+ label: "Plain text",
69
+ },
70
+ {
71
+ value: "text/tab-separated-values",
72
+ label: "TSV (sheet only)",
73
+ },
74
+ ];