@divyacon/piece-google-drive 0.0.0-stage → 0.1.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 (293) hide show
  1. package/LICENSE.MIT-AP +24 -0
  2. package/dist/index.d.ts +6 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +155 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/lib/action/add-permission.action.d.ts +11 -0
  7. package/dist/lib/action/add-permission.action.d.ts.map +1 -0
  8. package/dist/lib/action/add-permission.action.js +83 -0
  9. package/dist/lib/action/add-permission.action.js.map +1 -0
  10. package/dist/lib/action/create-new-folder.d.ts +12 -0
  11. package/dist/lib/action/create-new-folder.d.ts.map +1 -0
  12. package/dist/lib/action/create-new-folder.js +43 -0
  13. package/dist/lib/action/create-new-folder.js.map +1 -0
  14. package/dist/lib/action/create-new-text-file.d.ts +14 -0
  15. package/dist/lib/action/create-new-text-file.d.ts.map +1 -0
  16. package/dist/lib/action/create-new-text-file.js +81 -0
  17. package/dist/lib/action/create-new-text-file.js.map +1 -0
  18. package/dist/lib/action/delete-file.d.ts +8 -0
  19. package/dist/lib/action/delete-file.d.ts.map +1 -0
  20. package/dist/lib/action/delete-file.js +38 -0
  21. package/dist/lib/action/delete-file.js.map +1 -0
  22. package/dist/lib/action/delete-permission.action.d.ts +9 -0
  23. package/dist/lib/action/delete-permission.action.d.ts.map +1 -0
  24. package/dist/lib/action/delete-permission.action.js +84 -0
  25. package/dist/lib/action/delete-permission.action.js.map +1 -0
  26. package/dist/lib/action/drive-copy-file.d.ts +10 -0
  27. package/dist/lib/action/drive-copy-file.d.ts.map +1 -0
  28. package/dist/lib/action/drive-copy-file.js +84 -0
  29. package/dist/lib/action/drive-copy-file.js.map +1 -0
  30. package/dist/lib/action/drive-create-comment.d.ts +8 -0
  31. package/dist/lib/action/drive-create-comment.d.ts.map +1 -0
  32. package/dist/lib/action/drive-create-comment.js +60 -0
  33. package/dist/lib/action/drive-create-comment.js.map +1 -0
  34. package/dist/lib/action/drive-create-file-from-text.d.ts +10 -0
  35. package/dist/lib/action/drive-create-file-from-text.d.ts.map +1 -0
  36. package/dist/lib/action/drive-create-file-from-text.js +91 -0
  37. package/dist/lib/action/drive-create-file-from-text.js.map +1 -0
  38. package/dist/lib/action/drive-create-folder.d.ts +8 -0
  39. package/dist/lib/action/drive-create-folder.d.ts.map +1 -0
  40. package/dist/lib/action/drive-create-folder.js +48 -0
  41. package/dist/lib/action/drive-create-folder.js.map +1 -0
  42. package/dist/lib/action/drive-create-reply.d.ts +10 -0
  43. package/dist/lib/action/drive-create-reply.d.ts.map +1 -0
  44. package/dist/lib/action/drive-create-reply.js +81 -0
  45. package/dist/lib/action/drive-create-reply.js.map +1 -0
  46. package/dist/lib/action/drive-create-shared-drive.d.ts +7 -0
  47. package/dist/lib/action/drive-create-shared-drive.d.ts.map +1 -0
  48. package/dist/lib/action/drive-create-shared-drive.js +53 -0
  49. package/dist/lib/action/drive-create-shared-drive.js.map +1 -0
  50. package/dist/lib/action/drive-delete-file.d.ts +7 -0
  51. package/dist/lib/action/drive-delete-file.d.ts.map +1 -0
  52. package/dist/lib/action/drive-delete-file.js +39 -0
  53. package/dist/lib/action/drive-delete-file.js.map +1 -0
  54. package/dist/lib/action/drive-delete-reply.d.ts +9 -0
  55. package/dist/lib/action/drive-delete-reply.d.ts.map +1 -0
  56. package/dist/lib/action/drive-delete-reply.js +64 -0
  57. package/dist/lib/action/drive-delete-reply.js.map +1 -0
  58. package/dist/lib/action/drive-delete-shared-drive.d.ts +7 -0
  59. package/dist/lib/action/drive-delete-shared-drive.d.ts.map +1 -0
  60. package/dist/lib/action/drive-delete-shared-drive.js +55 -0
  61. package/dist/lib/action/drive-delete-shared-drive.js.map +1 -0
  62. package/dist/lib/action/drive-download-file.d.ts +8 -0
  63. package/dist/lib/action/drive-download-file.d.ts.map +1 -0
  64. package/dist/lib/action/drive-download-file.js +37 -0
  65. package/dist/lib/action/drive-download-file.js.map +1 -0
  66. package/dist/lib/action/drive-empty-trash.d.ts +7 -0
  67. package/dist/lib/action/drive-empty-trash.d.ts.map +1 -0
  68. package/dist/lib/action/drive-empty-trash.js +47 -0
  69. package/dist/lib/action/drive-empty-trash.js.map +1 -0
  70. package/dist/lib/action/drive-export-workspace-file.d.ts +8 -0
  71. package/dist/lib/action/drive-export-workspace-file.d.ts.map +1 -0
  72. package/dist/lib/action/drive-export-workspace-file.js +116 -0
  73. package/dist/lib/action/drive-export-workspace-file.js.map +1 -0
  74. package/dist/lib/action/drive-get-about.d.ts +5 -0
  75. package/dist/lib/action/drive-get-about.d.ts.map +1 -0
  76. package/dist/lib/action/drive-get-about.js +43 -0
  77. package/dist/lib/action/drive-get-about.js.map +1 -0
  78. package/dist/lib/action/drive-get-file.d.ts +7 -0
  79. package/dist/lib/action/drive-get-file.d.ts.map +1 -0
  80. package/dist/lib/action/drive-get-file.js +46 -0
  81. package/dist/lib/action/drive-get-file.js.map +1 -0
  82. package/dist/lib/action/drive-get-reply.d.ts +9 -0
  83. package/dist/lib/action/drive-get-reply.d.ts.map +1 -0
  84. package/dist/lib/action/drive-get-reply.js +66 -0
  85. package/dist/lib/action/drive-get-reply.js.map +1 -0
  86. package/dist/lib/action/drive-get-shared-drive.d.ts +7 -0
  87. package/dist/lib/action/drive-get-shared-drive.d.ts.map +1 -0
  88. package/dist/lib/action/drive-get-shared-drive.js +52 -0
  89. package/dist/lib/action/drive-get-shared-drive.js.map +1 -0
  90. package/dist/lib/action/drive-list-comments.d.ts +7 -0
  91. package/dist/lib/action/drive-list-comments.d.ts.map +1 -0
  92. package/dist/lib/action/drive-list-comments.js +60 -0
  93. package/dist/lib/action/drive-list-comments.js.map +1 -0
  94. package/dist/lib/action/drive-list-files.d.ts +11 -0
  95. package/dist/lib/action/drive-list-files.d.ts.map +1 -0
  96. package/dist/lib/action/drive-list-files.js +174 -0
  97. package/dist/lib/action/drive-list-files.js.map +1 -0
  98. package/dist/lib/action/drive-list-permissions.d.ts +7 -0
  99. package/dist/lib/action/drive-list-permissions.d.ts.map +1 -0
  100. package/dist/lib/action/drive-list-permissions.js +59 -0
  101. package/dist/lib/action/drive-list-permissions.js.map +1 -0
  102. package/dist/lib/action/drive-list-replies.d.ts +8 -0
  103. package/dist/lib/action/drive-list-replies.d.ts.map +1 -0
  104. package/dist/lib/action/drive-list-replies.js +65 -0
  105. package/dist/lib/action/drive-list-replies.js.map +1 -0
  106. package/dist/lib/action/drive-list-shared-drives.d.ts +8 -0
  107. package/dist/lib/action/drive-list-shared-drives.d.ts.map +1 -0
  108. package/dist/lib/action/drive-list-shared-drives.js +60 -0
  109. package/dist/lib/action/drive-list-shared-drives.js.map +1 -0
  110. package/dist/lib/action/drive-move-file.d.ts +8 -0
  111. package/dist/lib/action/drive-move-file.d.ts.map +1 -0
  112. package/dist/lib/action/drive-move-file.js +57 -0
  113. package/dist/lib/action/drive-move-file.js.map +1 -0
  114. package/dist/lib/action/drive-remove-permission.d.ts +9 -0
  115. package/dist/lib/action/drive-remove-permission.d.ts.map +1 -0
  116. package/dist/lib/action/drive-remove-permission.js +75 -0
  117. package/dist/lib/action/drive-remove-permission.js.map +1 -0
  118. package/dist/lib/action/drive-replace-file-content.d.ts +9 -0
  119. package/dist/lib/action/drive-replace-file-content.d.ts.map +1 -0
  120. package/dist/lib/action/drive-replace-file-content.js +67 -0
  121. package/dist/lib/action/drive-replace-file-content.js.map +1 -0
  122. package/dist/lib/action/drive-save-file-as-pdf.d.ts +9 -0
  123. package/dist/lib/action/drive-save-file-as-pdf.d.ts.map +1 -0
  124. package/dist/lib/action/drive-save-file-as-pdf.js +73 -0
  125. package/dist/lib/action/drive-save-file-as-pdf.js.map +1 -0
  126. package/dist/lib/action/drive-search-files.d.ts +12 -0
  127. package/dist/lib/action/drive-search-files.d.ts.map +1 -0
  128. package/dist/lib/action/drive-search-files.js +130 -0
  129. package/dist/lib/action/drive-search-files.js.map +1 -0
  130. package/dist/lib/action/drive-set-public-access.d.ts +8 -0
  131. package/dist/lib/action/drive-set-public-access.d.ts.map +1 -0
  132. package/dist/lib/action/drive-set-public-access.js +71 -0
  133. package/dist/lib/action/drive-set-public-access.js.map +1 -0
  134. package/dist/lib/action/drive-share-file.d.ts +10 -0
  135. package/dist/lib/action/drive-share-file.d.ts.map +1 -0
  136. package/dist/lib/action/drive-share-file.js +69 -0
  137. package/dist/lib/action/drive-share-file.js.map +1 -0
  138. package/dist/lib/action/drive-trash-file.d.ts +7 -0
  139. package/dist/lib/action/drive-trash-file.d.ts.map +1 -0
  140. package/dist/lib/action/drive-trash-file.js +45 -0
  141. package/dist/lib/action/drive-trash-file.js.map +1 -0
  142. package/dist/lib/action/drive-untrash-file.d.ts +7 -0
  143. package/dist/lib/action/drive-untrash-file.d.ts.map +1 -0
  144. package/dist/lib/action/drive-untrash-file.js +54 -0
  145. package/dist/lib/action/drive-untrash-file.js.map +1 -0
  146. package/dist/lib/action/drive-update-file-metadata.d.ts +10 -0
  147. package/dist/lib/action/drive-update-file-metadata.d.ts.map +1 -0
  148. package/dist/lib/action/drive-update-file-metadata.js +79 -0
  149. package/dist/lib/action/drive-update-file-metadata.js.map +1 -0
  150. package/dist/lib/action/drive-update-permission.d.ts +9 -0
  151. package/dist/lib/action/drive-update-permission.d.ts.map +1 -0
  152. package/dist/lib/action/drive-update-permission.js +93 -0
  153. package/dist/lib/action/drive-update-permission.js.map +1 -0
  154. package/dist/lib/action/drive-update-reply.d.ts +10 -0
  155. package/dist/lib/action/drive-update-reply.d.ts.map +1 -0
  156. package/dist/lib/action/drive-update-reply.js +72 -0
  157. package/dist/lib/action/drive-update-reply.js.map +1 -0
  158. package/dist/lib/action/drive-update-shared-drive.d.ts +8 -0
  159. package/dist/lib/action/drive-update-shared-drive.d.ts.map +1 -0
  160. package/dist/lib/action/drive-update-shared-drive.js +62 -0
  161. package/dist/lib/action/drive-update-shared-drive.js.map +1 -0
  162. package/dist/lib/action/drive-upload-file.d.ts +9 -0
  163. package/dist/lib/action/drive-upload-file.d.ts.map +1 -0
  164. package/dist/lib/action/drive-upload-file.js +71 -0
  165. package/dist/lib/action/drive-upload-file.js.map +1 -0
  166. package/dist/lib/action/drive-upload-from-url.d.ts +10 -0
  167. package/dist/lib/action/drive-upload-from-url.d.ts.map +1 -0
  168. package/dist/lib/action/drive-upload-from-url.js +90 -0
  169. package/dist/lib/action/drive-upload-from-url.js.map +1 -0
  170. package/dist/lib/action/duplicate-file.action.d.ts +11 -0
  171. package/dist/lib/action/duplicate-file.action.d.ts.map +1 -0
  172. package/dist/lib/action/duplicate-file.action.js +83 -0
  173. package/dist/lib/action/duplicate-file.action.js.map +1 -0
  174. package/dist/lib/action/get-file-by-id.d.ts +8 -0
  175. package/dist/lib/action/get-file-by-id.d.ts.map +1 -0
  176. package/dist/lib/action/get-file-by-id.js +45 -0
  177. package/dist/lib/action/get-file-by-id.js.map +1 -0
  178. package/dist/lib/action/list-files.action.d.ts +11 -0
  179. package/dist/lib/action/list-files.action.d.ts.map +1 -0
  180. package/dist/lib/action/list-files.action.js +165 -0
  181. package/dist/lib/action/list-files.action.js.map +1 -0
  182. package/dist/lib/action/move-file.d.ts +12 -0
  183. package/dist/lib/action/move-file.d.ts.map +1 -0
  184. package/dist/lib/action/move-file.js +52 -0
  185. package/dist/lib/action/move-file.js.map +1 -0
  186. package/dist/lib/action/read-file.d.ts +8 -0
  187. package/dist/lib/action/read-file.d.ts.map +1 -0
  188. package/dist/lib/action/read-file.js +34 -0
  189. package/dist/lib/action/read-file.js.map +1 -0
  190. package/dist/lib/action/save-file-as-pdf.action.d.ts +10 -0
  191. package/dist/lib/action/save-file-as-pdf.action.d.ts.map +1 -0
  192. package/dist/lib/action/save-file-as-pdf.action.js +72 -0
  193. package/dist/lib/action/save-file-as-pdf.action.js.map +1 -0
  194. package/dist/lib/action/search-folder-or-file.action.d.ts +15 -0
  195. package/dist/lib/action/search-folder-or-file.action.d.ts.map +1 -0
  196. package/dist/lib/action/search-folder-or-file.action.js +119 -0
  197. package/dist/lib/action/search-folder-or-file.action.js.map +1 -0
  198. package/dist/lib/action/send-to-trash.d.ts +8 -0
  199. package/dist/lib/action/send-to-trash.d.ts.map +1 -0
  200. package/dist/lib/action/send-to-trash.js +44 -0
  201. package/dist/lib/action/send-to-trash.js.map +1 -0
  202. package/dist/lib/action/set-public-access.d.ts +8 -0
  203. package/dist/lib/action/set-public-access.d.ts.map +1 -0
  204. package/dist/lib/action/set-public-access.js +66 -0
  205. package/dist/lib/action/set-public-access.js.map +1 -0
  206. package/dist/lib/action/upload-file.d.ts +13 -0
  207. package/dist/lib/action/upload-file.d.ts.map +1 -0
  208. package/dist/lib/action/upload-file.js +58 -0
  209. package/dist/lib/action/upload-file.js.map +1 -0
  210. package/dist/lib/auth.d.ts +11 -0
  211. package/dist/lib/auth.d.ts.map +1 -0
  212. package/dist/lib/auth.js +87 -0
  213. package/dist/lib/auth.js.map +1 -0
  214. package/dist/lib/common/get-file-content.d.ts +4 -0
  215. package/dist/lib/common/get-file-content.d.ts.map +1 -0
  216. package/dist/lib/common/get-file-content.js +69 -0
  217. package/dist/lib/common/get-file-content.js.map +1 -0
  218. package/dist/lib/common/index.d.ts +23 -0
  219. package/dist/lib/common/index.d.ts.map +1 -0
  220. package/dist/lib/common/index.js +152 -0
  221. package/dist/lib/common/index.js.map +1 -0
  222. package/dist/lib/output-schemas.d.ts +53 -0
  223. package/dist/lib/output-schemas.d.ts.map +1 -0
  224. package/dist/lib/output-schemas.js +2022 -0
  225. package/dist/lib/output-schemas.js.map +1 -0
  226. package/dist/lib/triggers/new-file.d.ts +43 -0
  227. package/dist/lib/triggers/new-file.d.ts.map +1 -0
  228. package/dist/lib/triggers/new-file.js +107 -0
  229. package/dist/lib/triggers/new-file.js.map +1 -0
  230. package/dist/lib/triggers/new-folder.d.ts +39 -0
  231. package/dist/lib/triggers/new-folder.d.ts.map +1 -0
  232. package/dist/lib/triggers/new-folder.js +71 -0
  233. package/dist/lib/triggers/new-folder.js.map +1 -0
  234. package/package.json +50 -4
  235. package/src/index.ts +149 -0
  236. package/src/lib/action/add-permission.action.ts +82 -0
  237. package/src/lib/action/create-new-folder.ts +42 -0
  238. package/src/lib/action/create-new-text-file.ts +80 -0
  239. package/src/lib/action/delete-file.ts +33 -0
  240. package/src/lib/action/delete-permission.action.ts +84 -0
  241. package/src/lib/action/drive-copy-file.ts +86 -0
  242. package/src/lib/action/drive-create-comment.ts +61 -0
  243. package/src/lib/action/drive-create-file-from-text.ts +99 -0
  244. package/src/lib/action/drive-create-folder.ts +49 -0
  245. package/src/lib/action/drive-create-reply.ts +84 -0
  246. package/src/lib/action/drive-create-shared-drive.ts +52 -0
  247. package/src/lib/action/drive-delete-file.ts +36 -0
  248. package/src/lib/action/drive-delete-reply.ts +65 -0
  249. package/src/lib/action/drive-delete-shared-drive.ts +57 -0
  250. package/src/lib/action/drive-download-file.ts +38 -0
  251. package/src/lib/action/drive-empty-trash.ts +47 -0
  252. package/src/lib/action/drive-export-workspace-file.ts +129 -0
  253. package/src/lib/action/drive-get-about.ts +40 -0
  254. package/src/lib/action/drive-get-file.ts +40 -0
  255. package/src/lib/action/drive-get-reply.ts +67 -0
  256. package/src/lib/action/drive-get-shared-drive.ts +52 -0
  257. package/src/lib/action/drive-list-comments.ts +61 -0
  258. package/src/lib/action/drive-list-files.ts +238 -0
  259. package/src/lib/action/drive-list-permissions.ts +60 -0
  260. package/src/lib/action/drive-list-replies.ts +66 -0
  261. package/src/lib/action/drive-list-shared-drives.ts +59 -0
  262. package/src/lib/action/drive-move-file.ts +56 -0
  263. package/src/lib/action/drive-remove-permission.ts +75 -0
  264. package/src/lib/action/drive-replace-file-content.ts +71 -0
  265. package/src/lib/action/drive-save-file-as-pdf.ts +80 -0
  266. package/src/lib/action/drive-search-files.ts +127 -0
  267. package/src/lib/action/drive-set-public-access.ts +75 -0
  268. package/src/lib/action/drive-share-file.ts +69 -0
  269. package/src/lib/action/drive-trash-file.ts +41 -0
  270. package/src/lib/action/drive-untrash-file.ts +54 -0
  271. package/src/lib/action/drive-update-file-metadata.ts +82 -0
  272. package/src/lib/action/drive-update-permission.ts +100 -0
  273. package/src/lib/action/drive-update-reply.ts +73 -0
  274. package/src/lib/action/drive-update-shared-drive.ts +63 -0
  275. package/src/lib/action/drive-upload-file.ts +80 -0
  276. package/src/lib/action/drive-upload-from-url.ts +107 -0
  277. package/src/lib/action/duplicate-file.action.ts +82 -0
  278. package/src/lib/action/get-file-by-id.ts +37 -0
  279. package/src/lib/action/list-files.action.ts +214 -0
  280. package/src/lib/action/move-file.ts +48 -0
  281. package/src/lib/action/read-file.ts +28 -0
  282. package/src/lib/action/save-file-as-pdf.action.ts +76 -0
  283. package/src/lib/action/search-folder-or-file.action.ts +112 -0
  284. package/src/lib/action/send-to-trash.ts +38 -0
  285. package/src/lib/action/set-public-access.ts +68 -0
  286. package/src/lib/action/upload-file.ts +55 -0
  287. package/src/lib/auth.ts +79 -0
  288. package/src/lib/common/get-file-content.ts +109 -0
  289. package/src/lib/common/index.ts +182 -0
  290. package/src/lib/output-schemas.ts +2070 -0
  291. package/src/lib/triggers/new-file.ts +119 -0
  292. package/src/lib/triggers/new-folder.ts +78 -0
  293. package/README.md +0 -3
@@ -0,0 +1,238 @@
1
+ import { HttpMethod, httpClient } from '@agnocon/pieces-common';
2
+ import { googleDriveAuth, getAccessToken } from '../auth';
3
+ import { Property, createAction } from '@agnocon/pieces-framework';
4
+ import querystring from 'querystring';
5
+ import { downloadFileFromDrive } from '../common/get-file-content';
6
+ import { driveListFilesOutputSchema } from '../output-schemas';
7
+
8
+ interface ListFilesResult {
9
+ type: string;
10
+ incompleteSearch: boolean;
11
+ files: unknown[];
12
+ downloadedFiles?: string[];
13
+ }
14
+
15
+ interface FileWithLevel {
16
+ file: any;
17
+ level: number;
18
+ parentFolder?: string;
19
+ }
20
+
21
+ async function getFilesRecursively(
22
+ auth: any,
23
+ folderId: string,
24
+ maxLevel: number,
25
+ includeTrashed: boolean,
26
+ includeTeamDrives: boolean,
27
+ currentLevel = 0
28
+ ): Promise<FileWithLevel[]> {
29
+ const files: FileWithLevel[] = [];
30
+
31
+ if (currentLevel > maxLevel) {
32
+ return files;
33
+ }
34
+
35
+ const accessToken = await getAccessToken(auth);
36
+
37
+ let q = `'${folderId}' in parents`;
38
+ if (!includeTrashed) {
39
+ q += ' and trashed=false';
40
+ }
41
+
42
+ const params: Record<string, string> = {
43
+ q: q,
44
+ fields: 'nextPageToken,files(id,kind,mimeType,name,trashed,parents)',
45
+ supportsAllDrives: 'true',
46
+ includeItemsFromAllDrives: includeTeamDrives ? 'true' : 'false',
47
+ corpora: includeTeamDrives ? 'allDrives' : 'user',
48
+ pageSize: '1000',
49
+ };
50
+
51
+ let response = await httpClient.sendRequest({
52
+ method: HttpMethod.GET,
53
+ url: `https://www.googleapis.com/drive/v3/files?${querystring.stringify(params)}`,
54
+ headers: {
55
+ Authorization: `Bearer ${accessToken}`,
56
+ },
57
+ });
58
+
59
+ // Add files from current level
60
+ for (const file of response.body.files) {
61
+ files.push({
62
+ file,
63
+ level: currentLevel,
64
+ parentFolder: folderId,
65
+ });
66
+ }
67
+
68
+ // Handle pagination for current level
69
+ while (response.body.nextPageToken) {
70
+ params.pageToken = response.body.nextPageToken;
71
+ response = await httpClient.sendRequest({
72
+ method: HttpMethod.GET,
73
+ url: `https://www.googleapis.com/drive/v3/files?${querystring.stringify(params)}`,
74
+ headers: {
75
+ Authorization: `Bearer ${accessToken}`,
76
+ },
77
+ });
78
+
79
+ for (const file of response.body.files) {
80
+ files.push({
81
+ file,
82
+ level: currentLevel,
83
+ parentFolder: folderId,
84
+ });
85
+ }
86
+ }
87
+
88
+ // If we haven't reached max level, recursively get files from subfolders
89
+ if (currentLevel + 1 < maxLevel) {
90
+ const subfolders = files.filter(
91
+ (f) => f.file.mimeType === 'application/vnd.google-apps.folder'
92
+ );
93
+
94
+ for (const subfolder of subfolders) {
95
+ const subfolderFiles = await getFilesRecursively(
96
+ auth,
97
+ subfolder.file.id,
98
+ maxLevel,
99
+ includeTrashed,
100
+ includeTeamDrives,
101
+ currentLevel + 1
102
+ );
103
+ files.push(...subfolderFiles);
104
+ }
105
+ }
106
+
107
+ return files;
108
+ }
109
+
110
+ export const driveListFiles = createAction({
111
+ auth: googleDriveAuth,
112
+ name: 'drive_list_files',
113
+ displayName: 'List Folder Contents',
114
+ description: 'List files from a Google Drive folder',
115
+ audience: 'ai',
116
+ aiMetadata: {
117
+ description:
118
+ 'Lists files and subfolders inside a given folder ID, optionally recursing to a chosen depth and downloading each file\'s content. Use to enumerate the contents of a known folder; to find a file by name across Drive use `drive_search_files`. Read-only. Requires the folder ID, not a name.',
119
+ idempotent: true,
120
+ },
121
+ outputSchema: driveListFilesOutputSchema,
122
+ props: {
123
+ folder_id: Property.ShortText({
124
+ displayName: 'Folder ID',
125
+ description:
126
+ 'The ID of the folder to list. Resolve it via `drive_search_files` (or any other source).',
127
+ required: true,
128
+ }),
129
+ include_trashed: Property.Checkbox({
130
+ displayName: 'Include Trashed',
131
+ description: 'Include new files that have been trashed.',
132
+ required: false,
133
+ defaultValue: false,
134
+ }),
135
+ depth_level: Property.Number({
136
+ displayName: 'Depth Level',
137
+ description:
138
+ 'How many levels deep to search for files. 1 = current folder only, 2 = current + next level, etc.',
139
+ required: false,
140
+ defaultValue: 1,
141
+ }),
142
+ download_files: Property.Checkbox({
143
+ displayName: 'Download Files',
144
+ description: 'Download all file contents in a list',
145
+ required: false,
146
+ defaultValue: false,
147
+ }),
148
+ include_team_drives: Property.Checkbox({
149
+ displayName: 'Include Team Drives',
150
+ description:
151
+ 'Determines if folders from Team Drives should be included in the results.',
152
+ defaultValue: false,
153
+ required: false,
154
+ }),
155
+ },
156
+ async run(context) {
157
+ const result: ListFilesResult = {
158
+ type: 'drive#fileList',
159
+ incompleteSearch: false,
160
+ files: [],
161
+ };
162
+
163
+ const depthLevel = context.propsValue.depth_level || 1;
164
+
165
+ // Get files recursively based on depth level
166
+ const filesWithLevel = await getFilesRecursively(
167
+ context.auth,
168
+ context.propsValue.folder_id,
169
+ depthLevel,
170
+ context.propsValue.include_trashed ?? false,
171
+ context.propsValue.include_team_drives ?? false
172
+ );
173
+
174
+ // Extract just the file objects for backward compatibility
175
+ result.files = filesWithLevel.map((f) => f.file);
176
+
177
+ // If downloadFiles is enabled, download each file and add URLs to array
178
+ if (context.propsValue.download_files) {
179
+ const downloadedFiles: string[] = [];
180
+ const extensionMap: Record<string, string> = {
181
+ 'application/pdf': '.pdf',
182
+ 'image/jpeg': '.jpg',
183
+ 'image/png': '.png',
184
+ 'image/tiff': '.tiff',
185
+ 'text/plain': '.txt',
186
+ 'text/csv': '.csv',
187
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
188
+ '.docx',
189
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
190
+ '.xlsx',
191
+ };
192
+
193
+ for (const fileWithLevel of filesWithLevel) {
194
+ const file = fileWithLevel.file;
195
+ // Skip folders when downloading
196
+ if (file.mimeType === 'application/vnd.google-apps.folder') {
197
+ continue;
198
+ }
199
+
200
+ let safeName = file.name;
201
+ const correctExtension = extensionMap[file.mimeType];
202
+ if (
203
+ correctExtension &&
204
+ !safeName.toLowerCase().endsWith(correctExtension)
205
+ ) {
206
+ // Check for the .jpeg edge case before appending .jpg
207
+ if (
208
+ !(
209
+ file.mimeType === 'image/jpeg' &&
210
+ safeName.toLowerCase().endsWith('.jpeg')
211
+ )
212
+ ) {
213
+ safeName = safeName + correctExtension;
214
+ }
215
+ }
216
+
217
+ try {
218
+ const fileUrl = await downloadFileFromDrive(
219
+ context.auth,
220
+ context.files,
221
+ file.id,
222
+ safeName
223
+ );
224
+ downloadedFiles.push(fileUrl);
225
+ } catch (error) {
226
+ console.warn(
227
+ `Failed to download file ${file.name}: ${
228
+ error instanceof Error ? error.message : 'Download failed'
229
+ }`
230
+ );
231
+ }
232
+ }
233
+ result.downloadedFiles = downloadedFiles;
234
+ }
235
+
236
+ return result;
237
+ },
238
+ });
@@ -0,0 +1,60 @@
1
+ import { Property, createAction } from '@agnocon/pieces-framework';
2
+ import { googleDriveAuth, createGoogleClient } from '../auth';
3
+ import { drive as googleDrive } from '@googleapis/drive';
4
+ import { driveListPermissionsOutputSchema } from '../output-schemas';
5
+
6
+ export const driveListPermissions = createAction({
7
+ auth: googleDriveAuth,
8
+ name: 'drive_list_permissions',
9
+ displayName: 'List Permissions',
10
+ description: 'List every permission on a Drive file or folder.',
11
+ audience: 'ai',
12
+ aiMetadata: {
13
+ description:
14
+ 'Lists every permission (who has access and at what role) on a file or folder, with each permission\'s id, type, role, and email/domain. Use to audit sharing before granting or revoking; it is the resolver for the permissionId other sharing atomics need. Read-only.',
15
+ idempotent: true,
16
+ },
17
+ outputSchema: driveListPermissionsOutputSchema,
18
+ props: {
19
+ file_id: Property.ShortText({
20
+ displayName: 'File or Folder ID',
21
+ description:
22
+ 'The ID of the file or folder whose permissions to list. Resolve it via drive_search_files or drive_get_file.',
23
+ required: true,
24
+ }),
25
+ },
26
+ async run(context) {
27
+ const { file_id } = context.propsValue;
28
+
29
+ const authClient = await createGoogleClient(context.auth);
30
+
31
+ const drive = googleDrive({ version: 'v3', auth: authClient });
32
+
33
+ try {
34
+ const response = await drive.permissions.list({
35
+ fileId: file_id,
36
+ fields: 'permissions(id,type,role,emailAddress,domain)',
37
+ supportsAllDrives: true,
38
+ });
39
+
40
+ const permissions = response.data.permissions ?? [];
41
+
42
+ return {
43
+ permissions,
44
+ count: permissions.length,
45
+ };
46
+ } catch (error: any) {
47
+ if (error.code === 404) {
48
+ throw new Error(
49
+ `File or folder not found (ID: ${file_id}). Resolve a valid ID via drive_search_files or drive_get_file.`
50
+ );
51
+ }
52
+ if (error.code === 403) {
53
+ throw new Error(
54
+ `Permission denied listing permissions for file ${file_id}. You may lack access to this resource.`
55
+ );
56
+ }
57
+ throw error;
58
+ }
59
+ },
60
+ });
@@ -0,0 +1,66 @@
1
+ import { Property, createAction } from '@agnocon/pieces-framework';
2
+ import { googleDriveAuth, createGoogleClient } from '../auth';
3
+ import { drive as googleDrive } from '@googleapis/drive';
4
+ import { driveListRepliesOutputSchema } from '../output-schemas';
5
+
6
+ export const driveListReplies = createAction({
7
+ auth: googleDriveAuth,
8
+ name: 'drive_list_replies',
9
+ displayName: 'List Replies',
10
+ description: 'List the replies under a Drive comment.',
11
+ audience: 'ai',
12
+ aiMetadata: {
13
+ description:
14
+ 'Lists the replies under a given comment with each reply\'s id, author, content, and action. Use to read a comment thread or to resolve a replyId before fetching (drive_get_reply), editing (drive_update_reply), or deleting (drive_delete_reply) a reply. Read-only.',
15
+ idempotent: true,
16
+ },
17
+ outputSchema: driveListRepliesOutputSchema,
18
+ props: {
19
+ file_id: Property.ShortText({
20
+ displayName: 'File ID',
21
+ description:
22
+ 'The ID of the file the comment belongs to. Resolve it via drive_search_files or drive_get_file.',
23
+ required: true,
24
+ }),
25
+ comment_id: Property.ShortText({
26
+ displayName: 'Comment ID',
27
+ description: 'The ID of the comment whose replies to list. Resolve it via drive_list_comments.',
28
+ required: true,
29
+ }),
30
+ },
31
+ async run(context) {
32
+ const { file_id, comment_id } = context.propsValue;
33
+
34
+ const authClient = await createGoogleClient(context.auth);
35
+
36
+ const drive = googleDrive({ version: 'v3', auth: authClient });
37
+
38
+ try {
39
+ // The Drive replies endpoints require a fields parameter or the API returns 400.
40
+ const response = await drive.replies.list({
41
+ fileId: file_id,
42
+ commentId: comment_id,
43
+ fields: '*',
44
+ });
45
+
46
+ const replies = response.data.replies ?? [];
47
+
48
+ return {
49
+ replies,
50
+ count: replies.length,
51
+ };
52
+ } catch (error: any) {
53
+ if (error.code === 404) {
54
+ throw new Error(
55
+ `File or comment not found (file ID: ${file_id}, comment ID: ${comment_id}). Resolve the comment ID via drive_list_comments.`
56
+ );
57
+ }
58
+ if (error.code === 403) {
59
+ throw new Error(
60
+ `Permission denied listing replies for comment ${comment_id} on file ${file_id}. You may lack access to this file.`
61
+ );
62
+ }
63
+ throw error;
64
+ }
65
+ },
66
+ });
@@ -0,0 +1,59 @@
1
+ import { Property, createAction } from '@agnocon/pieces-framework';
2
+ import { googleDriveAuth, createGoogleClient } from '../auth';
3
+ import { drive as googleDrive } from '@googleapis/drive';
4
+ import { driveListSharedDrivesOutputSchema } from '../output-schemas';
5
+
6
+ export const driveListSharedDrives = createAction({
7
+ auth: googleDriveAuth,
8
+ name: 'drive_list_shared_drives',
9
+ displayName: 'List Shared Drives',
10
+ description: 'List the shared drives the account can access.',
11
+ audience: 'ai',
12
+ aiMetadata: {
13
+ description:
14
+ 'Lists the shared drives the account can access, with each drive\'s id and name. Use to discover a driveId before creating or listing content in a shared drive or before drive_get_shared_drive, drive_update_shared_drive, or drive_delete_shared_drive. Read-only.',
15
+ idempotent: true,
16
+ },
17
+ outputSchema: driveListSharedDrivesOutputSchema,
18
+ props: {
19
+ query: Property.ShortText({
20
+ displayName: 'Query',
21
+ description:
22
+ 'Optional search query to filter shared drives, e.g. name contains \'marketing\'. See https://developers.google.com/drive/api/guides/search-shareddrives',
23
+ required: false,
24
+ }),
25
+ page_size: Property.Number({
26
+ displayName: 'Page Size',
27
+ description: 'Maximum number of shared drives to return (1-100). Defaults to 100.',
28
+ required: false,
29
+ }),
30
+ },
31
+ async run(context) {
32
+ const { query, page_size } = context.propsValue;
33
+
34
+ const authClient = await createGoogleClient(context.auth);
35
+
36
+ const drive = googleDrive({ version: 'v3', auth: authClient });
37
+
38
+ try {
39
+ const response = await drive.drives.list({
40
+ q: query || undefined,
41
+ pageSize: page_size || undefined,
42
+ });
43
+
44
+ const drives = response.data.drives ?? [];
45
+
46
+ return {
47
+ drives,
48
+ count: drives.length,
49
+ };
50
+ } catch (error: any) {
51
+ if (error.code === 403) {
52
+ throw new Error(
53
+ 'Permission denied listing shared drives. Your account may not have shared-drive access.'
54
+ );
55
+ }
56
+ throw error;
57
+ }
58
+ },
59
+ });
@@ -0,0 +1,56 @@
1
+ import { googleDriveAuth, createGoogleClient } from '../auth';
2
+ import { createAction, Property } from '@agnocon/pieces-framework';
3
+ import { drive as googleDrive } from '@googleapis/drive';
4
+ import { driveMoveFileOutputSchema } from '../output-schemas';
5
+
6
+ export const driveMoveFile = createAction({
7
+ auth: googleDriveAuth,
8
+ name: 'drive_move_file',
9
+ displayName: 'Move File',
10
+ description: 'Move a Drive file from its current folder(s) to a target folder.',
11
+ audience: 'ai',
12
+ aiMetadata: {
13
+ description:
14
+ 'Relocates a file to a target folder, detaching it from its current parents and attaching the new one. Use to reorganize a file by ID; to copy instead of move use drive_copy_file, and to rename without moving use drive_update_file_metadata. Safe to retry — repeating leaves the file in the same destination.',
15
+ idempotent: true,
16
+ },
17
+ outputSchema: driveMoveFileOutputSchema,
18
+ props: {
19
+ file_id: Property.ShortText({
20
+ displayName: 'File ID',
21
+ description:
22
+ 'The ID of the file to move. Resolve it via drive_search_files or drive_get_file.',
23
+ required: true,
24
+ }),
25
+ folder_id: Property.ShortText({
26
+ displayName: 'Destination Folder ID',
27
+ description:
28
+ 'The ID of the folder to move the file into. Resolve it via drive_search_files; leave empty for the root of My Drive.',
29
+ required: true,
30
+ }),
31
+ },
32
+ async run(context) {
33
+ const fileId = context.propsValue.file_id;
34
+ const folderId = context.propsValue.folder_id;
35
+
36
+ const authClient = await createGoogleClient(context.auth);
37
+
38
+ const drive = googleDrive({ version: 'v3', auth: authClient });
39
+
40
+ const file = await drive.files.get({
41
+ fileId,
42
+ supportsAllDrives: true,
43
+ fields: 'id,parents',
44
+ });
45
+
46
+ const response = await drive.files.update({
47
+ fileId: fileId,
48
+ fields: '*',
49
+ removeParents: file.data.parents?.join(','),
50
+ addParents: folderId,
51
+ supportsAllDrives: true,
52
+ });
53
+
54
+ return response.data;
55
+ },
56
+ });
@@ -0,0 +1,75 @@
1
+ import { Property, createAction } from '@agnocon/pieces-framework';
2
+ import { googleDriveAuth, createGoogleClient } from '../auth';
3
+ import { drive as googleDrive } from '@googleapis/drive';
4
+ import { driveRemovePermissionOutputSchema } from '../output-schemas';
5
+
6
+ export const driveRemovePermission = createAction({
7
+ auth: googleDriveAuth,
8
+ name: 'drive_remove_permission',
9
+ displayName: 'Remove Permission',
10
+ description: 'Revoke a role from a user on a Drive file or folder.',
11
+ audience: 'ai',
12
+ aiMetadata: {
13
+ description:
14
+ 'Revokes a specific role from a user (matched by email and role) on a file or folder, resolving the permission ID internally. Use to unshare or remove access; to lower a role instead of removing it use drive_update_permission. Safe to retry — if no matching permission exists it is a no-op.',
15
+ idempotent: true,
16
+ },
17
+ outputSchema: driveRemovePermissionOutputSchema,
18
+ props: {
19
+ file_id: Property.ShortText({
20
+ displayName: 'File or Folder ID',
21
+ description:
22
+ 'The ID of the file or folder to remove the permission from. Resolve it via drive_search_files or drive_get_file.',
23
+ required: true,
24
+ }),
25
+ user_email: Property.ShortText({
26
+ displayName: 'User Email',
27
+ description: 'The email address of the user whose access to revoke.',
28
+ required: true,
29
+ }),
30
+ role: Property.StaticDropdown({
31
+ displayName: 'Role',
32
+ description: 'The role to remove from the user. The grant is matched by email and role.',
33
+ required: true,
34
+ options: {
35
+ options: [
36
+ { label: 'Organizer', value: 'organizer' },
37
+ { label: 'File Organizer', value: 'fileOrganizer' },
38
+ { label: 'Writer', value: 'writer' },
39
+ { label: 'Commenter', value: 'commenter' },
40
+ { label: 'Reader', value: 'reader' },
41
+ ],
42
+ },
43
+ }),
44
+ },
45
+ async run(context) {
46
+ const [file_id, user_email] = [context.propsValue.file_id, context.propsValue.user_email];
47
+ const authClient = await createGoogleClient(context.auth);
48
+
49
+ const drive = googleDrive({ version: 'v3', auth: authClient });
50
+
51
+ const response_permissions_list = await drive.permissions.list({
52
+ fileId: file_id,
53
+ fields: 'permissions(id, emailAddress, role)',
54
+ supportsAllDrives: true,
55
+ });
56
+
57
+ if (response_permissions_list.data.permissions) {
58
+ for (const permission of response_permissions_list.data.permissions) {
59
+ if (
60
+ permission.emailAddress === user_email &&
61
+ permission.role === context.propsValue.role
62
+ ) {
63
+ await drive.permissions.delete({
64
+ fileId: file_id,
65
+ permissionId: permission.id ? permission.id : '',
66
+ supportsAllDrives: true,
67
+ });
68
+ return { removed: true, message: 'Permission removed' };
69
+ }
70
+ }
71
+ }
72
+
73
+ return { removed: false, message: 'Permission not found' };
74
+ },
75
+ });
@@ -0,0 +1,71 @@
1
+ import { createAction, Property } from '@agnocon/pieces-framework';
2
+ import {
3
+ httpClient,
4
+ HttpMethod,
5
+ AuthenticationType,
6
+ } from '@agnocon/pieces-common';
7
+ import { googleDriveAuth, getAccessToken } from '../auth';
8
+ import mime from 'mime-types';
9
+ import { driveReplaceFileContentOutputSchema } from '../output-schemas';
10
+
11
+ export const driveReplaceFileContent = createAction({
12
+ auth: googleDriveAuth,
13
+ name: 'drive_replace_file_content',
14
+ displayName: 'Replace File Content',
15
+ description: "Replace an existing Drive file's bytes, keeping its ID and name.",
16
+ audience: 'ai',
17
+ aiMetadata: {
18
+ description:
19
+ "Replaces the contents of an existing Drive file with new bytes, keeping the same file ID, name, and location. Use to update a file in place (e.g. overwrite a report); to create a brand-new file use `drive_upload_file`, and to rename without changing content use `drive_update_file_metadata`. Each call overwrites the previous content.",
20
+ idempotent: false,
21
+ },
22
+ outputSchema: driveReplaceFileContentOutputSchema,
23
+ props: {
24
+ file_id: Property.ShortText({
25
+ displayName: 'File ID',
26
+ description:
27
+ 'The ID of the existing file whose content to replace. Resolve it via `drive_search_files` or `drive_get_file`.',
28
+ required: true,
29
+ }),
30
+ file: Property.File({
31
+ displayName: 'New File Content',
32
+ description: 'The file URL or base64 whose bytes will replace the existing content.',
33
+ required: true,
34
+ }),
35
+ mime_type: Property.ShortText({
36
+ displayName: 'MIME Type',
37
+ description:
38
+ 'Optional MIME type for the new content (e.g. application/pdf). Provide this when the source has no file extension; otherwise the type is inferred from the extension.',
39
+ required: false,
40
+ }),
41
+ },
42
+ async run(context) {
43
+ const { file_id, file, mime_type } = context.propsValue;
44
+
45
+ const resolvedMimeType =
46
+ mime_type ||
47
+ mime.lookup(file.extension ? file.extension : '') ||
48
+ 'application/octet-stream';
49
+
50
+ const fileBuffer = Buffer.from(file.base64, 'base64');
51
+
52
+ const result = await httpClient.sendRequest({
53
+ method: HttpMethod.PATCH,
54
+ url: `https://www.googleapis.com/upload/drive/v3/files/${file_id}`,
55
+ queryParams: {
56
+ uploadType: 'media',
57
+ supportsAllDrives: 'true',
58
+ },
59
+ body: fileBuffer,
60
+ headers: {
61
+ 'Content-Type': resolvedMimeType,
62
+ },
63
+ authentication: {
64
+ type: AuthenticationType.BEARER_TOKEN,
65
+ token: await getAccessToken(context.auth),
66
+ },
67
+ });
68
+
69
+ return result.body;
70
+ },
71
+ });