@pipedream/google_drive 0.7.3 → 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.
Files changed (37) hide show
  1. package/actions/add-file-sharing-preference/add-file-sharing-preference.mjs +30 -8
  2. package/actions/copy-file/copy-file.mjs +2 -2
  3. package/actions/create-file-from-template/create-file-from-template.mjs +3 -3
  4. package/actions/create-file-from-text/create-file-from-text.mjs +3 -2
  5. package/actions/create-folder/create-folder.mjs +3 -2
  6. package/actions/create-shared-drive/create-shared-drive.mjs +1 -2
  7. package/actions/delete-file/delete-file.mjs +10 -3
  8. package/actions/delete-shared-drive/delete-shared-drive.mjs +7 -5
  9. package/actions/download-file/download-file.mjs +11 -6
  10. package/actions/find-file/find-file.mjs +8 -10
  11. package/actions/find-folder/find-folder.mjs +2 -2
  12. package/actions/find-forms/find-forms.mjs +22 -18
  13. package/actions/find-spreadsheets/find-spreadsheets.mjs +21 -18
  14. package/actions/get-file-by-id/get-file-by-id.mjs +1 -1
  15. package/actions/get-folder-id-for-path/get-folder-id-for-path.mjs +1 -1
  16. package/actions/get-shared-drive/get-shared-drive.mjs +8 -8
  17. package/actions/list-files/list-files.mjs +3 -3
  18. package/actions/move-file/move-file.mjs +2 -2
  19. package/actions/move-file-to-trash/move-file-to-trash.mjs +7 -2
  20. package/actions/search-shared-drives/search-shared-drives.mjs +1 -1
  21. package/actions/update-file/update-file.mjs +9 -7
  22. package/actions/update-shared-drive/update-shared-drive.mjs +11 -11
  23. package/actions/upload-file/upload-file.mjs +12 -4
  24. package/common/commonSearchQuery.mjs +48 -0
  25. package/common/constants.mjs +27 -22
  26. package/google_drive.app.mjs +41 -16
  27. package/package.json +1 -1
  28. package/sources/changes-to-specific-files/changes-to-specific-files.mjs +2 -3
  29. package/sources/changes-to-specific-files-shared-drive/changes-to-specific-files-shared-drive.mjs +1 -1
  30. package/sources/new-files-instant/new-files-instant.mjs +1 -1
  31. package/sources/new-or-modified-comments/new-or-modified-comments.mjs +23 -16
  32. package/sources/new-or-modified-files/new-or-modified-files.mjs +1 -1
  33. package/sources/new-or-modified-folders/new-or-modified-folders.mjs +1 -1
  34. package/sources/new-shared-drive/new-shared-drive.mjs +1 -1
  35. package/sources/new-spreadsheet/new-spreadsheet.mjs +1 -1
  36. package/actions/create-file/create-file.mjs +0 -242
  37. package/actions/replace-file/replace-file.mjs +0 -134
@@ -1,242 +0,0 @@
1
- import googleDrive from "../../google_drive.app.mjs";
2
- import fs from "fs";
3
- import got from "got@13.0.0";
4
- import { toSingleLineString } from "../../common/utils.mjs";
5
-
6
- export default {
7
- key: "google_drive-create-file",
8
- name: "Create a New File",
9
- description: "Create a new file from a URL or /tmp/filepath. [See the docs](https://developers.google.com/drive/api/v3/reference/files/create) for more information",
10
- version: "0.1.6",
11
- type: "action",
12
- props: {
13
- googleDrive,
14
- drive: {
15
- propDefinition: [
16
- googleDrive,
17
- "watchedDrive",
18
- ],
19
- },
20
- parent: {
21
- propDefinition: [
22
- googleDrive,
23
- "folderId",
24
- (c) => ({
25
- drive: c.drive,
26
- }),
27
- ],
28
- label: "Parent Folder",
29
- description: toSingleLineString(`
30
- The ID of the parent folder which contains the file. If not specified, the file will be
31
- placed directly in the drive's top-level folder.
32
- `),
33
- optional: true,
34
- },
35
- uploadType: {
36
- propDefinition: [
37
- googleDrive,
38
- "uploadType",
39
- ],
40
- },
41
- fileUrl: {
42
- propDefinition: [
43
- googleDrive,
44
- "fileUrl",
45
- ],
46
- },
47
- filePath: {
48
- propDefinition: [
49
- googleDrive,
50
- "filePath",
51
- ],
52
- },
53
- ignoreDefaultVisibility: {
54
- type: "boolean",
55
- label: "Ignore Default Visibility",
56
- description: toSingleLineString(`
57
- Whether to ignore the domain's default visibility settings for the created
58
- file. Domain administrators can choose to make all uploaded files visible to the domain
59
- by default; this parameter bypasses that behavior for the request. Permissions are still
60
- inherited from parent folders.
61
- `),
62
- default: false,
63
- },
64
- includePermissionsForView: {
65
- type: "string",
66
- label: "Include Permissions For View",
67
- description: toSingleLineString(`
68
- Specifies which additional view's permissions to include in the response. Only
69
- 'published' is supported.
70
- `),
71
- optional: true,
72
- options: [
73
- "published",
74
- ],
75
- },
76
- keepRevisionForever: {
77
- propDefinition: [
78
- googleDrive,
79
- "keepRevisionForever",
80
- ],
81
- default: false,
82
- },
83
- ocrLanguage: {
84
- propDefinition: [
85
- googleDrive,
86
- "ocrLanguage",
87
- ],
88
- },
89
- useContentAsIndexableText: {
90
- propDefinition: [
91
- googleDrive,
92
- "useContentAsIndexableText",
93
- ],
94
- default: false,
95
- },
96
- supportsAllDrives: {
97
- type: "boolean",
98
- label: "Supports All Drives",
99
- description: toSingleLineString(`
100
- Whether to include shared drives. Set to 'true' if saving to a shared drive.
101
- Defaults to 'false' if left blank.
102
- `),
103
- optional: true,
104
- },
105
- contentHintsIndexableText: {
106
- type: "string",
107
- label: "Content Hints Indexable Text",
108
- description: toSingleLineString(`
109
- Text to be indexed for the file to improve fullText queries. This is limited to 128KB in
110
- length and may contain HTML elements.
111
- `),
112
- optional: true,
113
- },
114
- contentRestrictionsReadOnly: {
115
- type: "boolean",
116
- label: "Content Restrictions Read Only",
117
- description: toSingleLineString(`
118
- Whether the content of the file is read-only. If a file is read-only, a new revision of
119
- the file may not be added, comments may not be added or modified, and the title of the file
120
- may not be modified.
121
- `),
122
- optional: true,
123
- },
124
- contentRestrictionsReason: {
125
- type: "string",
126
- label: "Content Restrictions Reason",
127
- description: toSingleLineString(`
128
- Reason for why the content of the file is restricted. This is only mutable on requests
129
- that also set readOnly=true.
130
- `),
131
- optional: true,
132
- },
133
- copyRequiresWriterPermission: {
134
- type: "boolean",
135
- label: "Copy Requires Writer Permission",
136
- description: toSingleLineString(`
137
- Whether the options to copy, print, or download this file, should be disabled for
138
- readers and commentators
139
- `),
140
- optional: true,
141
- },
142
- description: {
143
- type: "string",
144
- label: "Description",
145
- description: "A short description of the file",
146
- optional: true,
147
- },
148
- folderColorRgb: {
149
- type: "string",
150
- label: "Folder Color RGB",
151
- description: toSingleLineString(`
152
- The color for a folder as an RGB hex string. If an unsupported color is specified,
153
- the closest color in the palette will be used instead.
154
- `),
155
- optional: true,
156
- },
157
- mimeType: {
158
- propDefinition: [
159
- googleDrive,
160
- "mimeType",
161
- ],
162
- },
163
- name: {
164
- propDefinition: [
165
- googleDrive,
166
- "fileName",
167
- ],
168
- description: "Name of the file",
169
- },
170
- originalFilename: {
171
- type: "string",
172
- label: "Original Filename",
173
- description:
174
- "The original filename of the uploaded content if available, or else the original value of the name field. This is only available for files with binary content in Google Drive.",
175
- optional: true,
176
- },
177
- shortcutDetailsTargetId: {
178
- type: "string",
179
- label: "Shortcut Details Target ID",
180
- description: "The ID of the file that this shortcut points to",
181
- optional: true,
182
- },
183
- starred: {
184
- type: "boolean",
185
- label: "Starred",
186
- description: "Whether the user has starred the file",
187
- optional: true,
188
- },
189
- writersCanShare: {
190
- type: "boolean",
191
- label: "Writers Can Share",
192
- description:
193
- "Whether users with only writer permission can modify the file's permissions. Not populated for items in shared drives.",
194
- optional: true,
195
- },
196
- },
197
- async run({ $ }) {
198
- const body = this.fileUrl
199
- ? await got.stream(this.fileUrl)
200
- : fs.createReadStream(this.filePath);
201
- const driveId = this.googleDrive.getDriveId(this.drive);
202
- const resp = await this.googleDrive.createFile({
203
- ignoreDefaultVisibility: this.ignoreDefaultVisibility,
204
- includePermissionsForView: this.includePermissionsForView,
205
- keepRevisionForever: this.keepRevisionForever,
206
- ocrLanguage: this.ocrLanguage,
207
- useContentAsIndexableText: this.useContentAsIndexableText,
208
- supportsAllDrives: this.supportsAllDrives,
209
- resource: {
210
- name: this.name,
211
- originalFilename: this.originalFilename,
212
- parents: [
213
- this.parent ?? driveId,
214
- ],
215
- mimeType: this.mimeType,
216
- description: this.description,
217
- folderColorRgb: this.folderColorRgb,
218
- shortcutDetails: {
219
- targetId: this.shortcutDetailsTargetId,
220
- },
221
- starred: this.starred,
222
- writersCanShare: this.writersCanShare,
223
- contentHints: {
224
- indexableText: this.contentHintsIndexableText,
225
- },
226
- contentRestrictions: {
227
- readOnly: this.contentRestrictionsReadOnly,
228
- reason: this.contentRestrictionsReason,
229
- },
230
- copyRequiresWriterPermission: this.copyRequiresWriterPermission,
231
- },
232
- media: {
233
- mimeType: this.mimeType,
234
- uploadType: this.uploadType,
235
- body,
236
- },
237
- fields: "*",
238
- });
239
- $.export("$summary", `Successfully created a new file, "${resp.name}"`);
240
- return resp;
241
- },
242
- };
@@ -1,134 +0,0 @@
1
- import path from "path";
2
- import googleDrive from "../../google_drive.app.mjs";
3
- import {
4
- omitEmptyStringValues,
5
- getFileStream,
6
- streamToBuffer,
7
- byteToMB,
8
- } from "../../common/utils.mjs";
9
- import {
10
- GOOGLE_DRIVE_UPLOAD_TYPE_MEDIA,
11
- GOOGLE_DRIVE_UPLOAD_TYPE_RESUMABLE,
12
- } from "../../common/constants.mjs";
13
-
14
- export default {
15
- key: "google_drive-replace-file",
16
- name: "Replace File",
17
- 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",
18
- version: "0.1.4",
19
- type: "action",
20
- props: {
21
- googleDrive,
22
- drive: {
23
- propDefinition: [
24
- googleDrive,
25
- "watchedDrive",
26
- ],
27
- optional: true,
28
- },
29
- fileId: {
30
- propDefinition: [
31
- googleDrive,
32
- "fileId",
33
- (c) => ({
34
- drive: c.drive,
35
- }),
36
- ],
37
- optional: false,
38
- description: "The file to update",
39
- },
40
- fileUrl: {
41
- propDefinition: [
42
- googleDrive,
43
- "fileUrl",
44
- ],
45
- },
46
- filePath: {
47
- propDefinition: [
48
- googleDrive,
49
- "filePath",
50
- ],
51
- },
52
- name: {
53
- propDefinition: [
54
- googleDrive,
55
- "fileName",
56
- ],
57
- label: "Name",
58
- description: "The name of the new file (e.g., `myFile.csv`)",
59
- },
60
- mimeType: {
61
- propDefinition: [
62
- googleDrive,
63
- "mimeType",
64
- ],
65
- description: "The MIME type of the new file (e.g., `image/jpeg`)",
66
- },
67
- uploadType: {
68
- propDefinition: [
69
- googleDrive,
70
- "uploadType",
71
- ],
72
- optional: true,
73
- },
74
- },
75
- async run({ $ }) {
76
- const {
77
- fileId,
78
- fileUrl,
79
- filePath,
80
- name,
81
- mimeType,
82
- } = this;
83
- let { uploadType } = this;
84
- if (!fileUrl && !filePath) {
85
- throw new Error("One of File URL and File Path is required.");
86
- }
87
- const fileStream = await getFileStream({
88
- $,
89
- fileUrl,
90
- filePath,
91
- });
92
-
93
- if (!uploadType || uploadType === "") {
94
- try {
95
- // Its necessary to get the file stream again, after user streamToBuffer function and pass
96
- // the same object to updateFileMedia function, the function will throw an error about
97
- // circular json structure.
98
- // Deep clone is very slow in this case, so its better get the stream again
99
- const fileBuffer = await streamToBuffer(await getFileStream({
100
- $,
101
- fileUrl,
102
- filePath,
103
- }));
104
- const bufferSize = byteToMB(Buffer.byteLength(fileBuffer));
105
- uploadType = bufferSize > 5
106
- ? GOOGLE_DRIVE_UPLOAD_TYPE_RESUMABLE
107
- : undefined;
108
- } catch (err) {
109
- console.log(err);
110
- uploadType = undefined;
111
- }
112
- }
113
-
114
- if (uploadType === GOOGLE_DRIVE_UPLOAD_TYPE_MEDIA) {
115
- uploadType = undefined;
116
- }
117
- console.log(`Upload type: ${uploadType}`);
118
- // Update file media separately from metadata to prevent multipart upload,
119
- // which `google-apis-nodejs-client` doesn't seem to support for
120
- // [files.update](https://bit.ly/3lP5sWn)
121
- await this.googleDrive.updateFileMedia(fileId, fileStream, omitEmptyStringValues({
122
- mimeType,
123
- uploadType,
124
- }));
125
-
126
- const resp = await this.googleDrive.updateFile(fileId, omitEmptyStringValues({
127
- name: name || path.basename(fileUrl || filePath),
128
- mimeType,
129
- uploadType,
130
- }));
131
- $.export("$summary", "Successfully replaced the file");
132
- return resp;
133
- },
134
- };