From 43ddba649bcc9206613e0f8a33f33f59ec5f1e9f Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Wed, 12 Nov 2025 16:03:42 -0500 Subject: [PATCH 1/4] support templates in shared drives --- .../create-file-from-template.mjs | 36 +++++++++++++++++-- components/google_drive/package.json | 2 +- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/components/google_drive/actions/create-file-from-template/create-file-from-template.mjs b/components/google_drive/actions/create-file-from-template/create-file-from-template.mjs index 529923991dbaa..4d561c4c696f2 100644 --- a/components/google_drive/actions/create-file-from-template/create-file-from-template.mjs +++ b/components/google_drive/actions/create-file-from-template/create-file-from-template.mjs @@ -8,7 +8,7 @@ export default { key: "google_drive-create-file-from-template", name: "Create New File From Template", description: "Create a new Google Docs file from a template. Optionally include placeholders in the template document that will get replaced from this action. [See documentation](https://www.npmjs.com/package/google-docs-mustaches)", - version: "0.1.16", + version: "0.1.17", annotations: { destructiveHint: true, openWorldHint: true, @@ -17,10 +17,20 @@ export default { type: "action", props: { googleDrive, + drive: { + propDefinition: [ + googleDrive, + "watchedDrive", + ], + optional: true, + }, templateId: { propDefinition: [ googleDrive, "fileId", + (c) => ({ + drive: c.drive, + }), ], description: "Select the template document you'd like to use as the template, or use a custom expression to reference a document ID from a previous step. Template documents should contain placeholders in the format `{{xyz}}`.", @@ -69,12 +79,27 @@ export default { token: () => this.googleDrive.$auth.oauth_access_token, }); + // COPY THE TEMPLATE + + const drive = this.googleDrive.drive(); + const copiedTemplate = await drive.files.copy({ + fileId: this.templateId, + requestBody: { + name: "template-copy", + parents: [ + this.folderId, + ], + }, + supportsAllDrives: true, + }); + const templateId = copiedTemplate.data.id; + /* CREATE THE GOOGLE DOC */ let googleDocId; try { googleDocId = await client.interpolate({ - source: this.templateId, + source: templateId, destination: this.folderId, name: this.name, data: this.replaceValues, @@ -109,6 +134,13 @@ export default { await this.googleDrive.deleteFile(googleDocId); } + // REMOVE THE COPIED TEMPLATE + + await drive.files.delete({ + fileId: templateId, + supportsAllDrives: true, + }); + $.export("$summary", "New file successfully created"); return result; }, diff --git a/components/google_drive/package.json b/components/google_drive/package.json index 588de2ce0ac3c..ed4a73dea83ac 100644 --- a/components/google_drive/package.json +++ b/components/google_drive/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/google_drive", - "version": "1.2.0", + "version": "1.2.1", "description": "Pipedream Google_drive Components", "main": "google_drive.app.mjs", "keywords": [ From aac3f8a936c111184f5ac12031d6d7de5653913d Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Thu, 13 Nov 2025 12:26:49 -0500 Subject: [PATCH 2/4] updates --- .../create-file-from-template/create-file-from-template.mjs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/google_drive/actions/create-file-from-template/create-file-from-template.mjs b/components/google_drive/actions/create-file-from-template/create-file-from-template.mjs index 4d561c4c696f2..8ed5280047402 100644 --- a/components/google_drive/actions/create-file-from-template/create-file-from-template.mjs +++ b/components/google_drive/actions/create-file-from-template/create-file-from-template.mjs @@ -1,5 +1,6 @@ import Mustaches from "google-docs-mustaches"; import googleDrive from "../../google_drive.app.mjs"; +import { parseObjectEntries } from "../../common/utils.mjs"; const MODE_GOOGLE_DOC = "Google Doc"; const MODE_PDF = "Pdf"; @@ -87,7 +88,7 @@ export default { requestBody: { name: "template-copy", parents: [ - this.folderId, + this.folderId || "root", ], }, supportsAllDrives: true, @@ -102,7 +103,7 @@ export default { source: templateId, destination: this.folderId, name: this.name, - data: this.replaceValues, + data: parseObjectEntries(this.replaceValues), }); } catch (e) { const { From 323d89f04aea96e2b903b45fca1f03de31c4ad80 Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Fri, 14 Nov 2025 11:26:55 -0500 Subject: [PATCH 3/4] save to shared drive --- .../create-file-from-template.mjs | 42 +++++++++++++++++-- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/components/google_drive/actions/create-file-from-template/create-file-from-template.mjs b/components/google_drive/actions/create-file-from-template/create-file-from-template.mjs index 8ed5280047402..5f64e76abaf67 100644 --- a/components/google_drive/actions/create-file-from-template/create-file-from-template.mjs +++ b/components/google_drive/actions/create-file-from-template/create-file-from-template.mjs @@ -40,6 +40,9 @@ export default { propDefinition: [ googleDrive, "folderId", + (c) => ({ + drive: c.drive, + }), ], description: "Select the folder of the newly created Google Doc and/or PDF, or use a custom expression to reference a folder ID from a previous step.", @@ -76,6 +79,8 @@ export default { mode: this.mode, }; + const isSharedDrive = this.drive !== "My Drive"; + const client = new Mustaches.default({ token: () => this.googleDrive.$auth.oauth_access_token, }); @@ -88,7 +93,7 @@ export default { requestBody: { name: "template-copy", parents: [ - this.folderId || "root", + "root", ], }, supportsAllDrives: true, @@ -101,7 +106,9 @@ export default { try { googleDocId = await client.interpolate({ source: templateId, - destination: this.folderId, + destination: !isSharedDrive + ? this.folderId + : undefined, name: this.name, data: parseObjectEntries(this.replaceValues), }); @@ -119,16 +126,43 @@ export default { /* CREATE THE PDF */ + let pdfId; if (this.mode.includes(MODE_PDF)) { - const pdfId = await client.export({ + pdfId = await client.export({ file: googleDocId, mimeType: "application/pdf", name: this.name, - destination: this.folderId, + destination: !isSharedDrive + ? this.folderId + : undefined, }); result["pdfId"] = pdfId; } + // MOVE FILE(S) TO SHARED DRIVE + + if (isSharedDrive) { + if (this.mode.includes(MODE_GOOGLE_DOC)) { + const file = await this.googleDrive.getFile(googleDocId); + await this.googleDrive.updateFile(googleDocId, { + fields: "*", + removeParents: file.parents.join(","), + addParents: this.folderId || this.drive, + supportsAllDrives: true, + }); + } + + if (pdfId) { + const pdf = await this.googleDrive.getFile(pdfId); + await this.googleDrive.updateFile(pdfId, { + fields: "*", + removeParents: pdf.parents.join(","), + addParents: this.folderId || this.drive, + supportsAllDrives: true, + }); + } + } + /* REMOVE THE GOOGLE DOC */ if (!this.mode.includes(MODE_GOOGLE_DOC)) { From 17f235ba8332241373eb72aee5e83cb8a3d0f2a5 Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Fri, 14 Nov 2025 11:32:31 -0500 Subject: [PATCH 4/4] update --- .../create-file-from-template/create-file-from-template.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/google_drive/actions/create-file-from-template/create-file-from-template.mjs b/components/google_drive/actions/create-file-from-template/create-file-from-template.mjs index 5f64e76abaf67..bbc13b23d724b 100644 --- a/components/google_drive/actions/create-file-from-template/create-file-from-template.mjs +++ b/components/google_drive/actions/create-file-from-template/create-file-from-template.mjs @@ -79,7 +79,7 @@ export default { mode: this.mode, }; - const isSharedDrive = this.drive !== "My Drive"; + const isSharedDrive = this.drive && this.drive !== "My Drive"; const client = new Mustaches.default({ token: () => this.googleDrive.$auth.oauth_access_token,