From 68ee4704513bb2c178b84363641eb9f8a05ecf07 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Wed, 22 Jan 2025 10:42:56 -0500 Subject: [PATCH 1/5] updates --- .../actions/append-image/append-image.mjs | 2 +- .../actions/append-text/append-text.mjs | 2 +- .../create-document/create-document.mjs | 2 +- .../actions/get-document/get-document.mjs | 4 ++- .../actions/replace-image/replace-image.mjs | 2 +- .../actions/replace-text/replace-text.mjs | 2 +- components/google_docs/common/utils.mjs | 26 +++++++++++++++++++ components/google_docs/google_docs.app.mjs | 6 +++-- components/google_docs/package.json | 4 +-- .../google_docs/sources/common/base.mjs | 18 ++++++------- .../new-document-created.mjs | 4 +-- .../new-or-updated-document.mjs | 6 ++--- 12 files changed, 54 insertions(+), 24 deletions(-) create mode 100644 components/google_docs/common/utils.mjs diff --git a/components/google_docs/actions/append-image/append-image.mjs b/components/google_docs/actions/append-image/append-image.mjs index aa88909800e7c..71e5a369f330d 100644 --- a/components/google_docs/actions/append-image/append-image.mjs +++ b/components/google_docs/actions/append-image/append-image.mjs @@ -4,7 +4,7 @@ export default { key: "google_docs-append-image", name: "Append Image to Document", description: "Appends an image to the end of a document. [See the documentation](https://developers.google.com/docs/api/reference/rest/v1/documents/request#InsertInlineImageRequest)", - version: "0.0.5", + version: "0.0.6", type: "action", props: { googleDocs, diff --git a/components/google_docs/actions/append-text/append-text.mjs b/components/google_docs/actions/append-text/append-text.mjs index ced20415acefd..712f38c3374c1 100644 --- a/components/google_docs/actions/append-text/append-text.mjs +++ b/components/google_docs/actions/append-text/append-text.mjs @@ -4,7 +4,7 @@ export default { key: "google_docs-append-text", name: "Append Text", description: "Append text to an existing document. [See the documentation](https://developers.google.com/docs/api/reference/rest/v1/documents/request#InsertTextRequest)", - version: "0.1.4", + version: "0.1.5", type: "action", props: { googleDocs, diff --git a/components/google_docs/actions/create-document/create-document.mjs b/components/google_docs/actions/create-document/create-document.mjs index c781c11406e0f..9b1a20da98dc9 100644 --- a/components/google_docs/actions/create-document/create-document.mjs +++ b/components/google_docs/actions/create-document/create-document.mjs @@ -4,7 +4,7 @@ export default { key: "google_docs-create-document", name: "Create a New Document", description: "Create a new document. [See the documentation](https://developers.google.com/docs/api/reference/rest/v1/documents/create)", - version: "0.1.4", + version: "0.1.5", type: "action", props: { googleDocs, diff --git a/components/google_docs/actions/get-document/get-document.mjs b/components/google_docs/actions/get-document/get-document.mjs index a23eeae69ade5..5a68e88be88a2 100644 --- a/components/google_docs/actions/get-document/get-document.mjs +++ b/components/google_docs/actions/get-document/get-document.mjs @@ -4,7 +4,7 @@ export default { key: "google_docs-get-document", name: "Get Document", description: "Get the contents of the latest version of a document. [See the documentation](https://developers.google.com/docs/api/reference/rest/v1/documents/get)", - version: "0.1.3", + version: "0.1.4", type: "action", props: { googleDocs, @@ -17,7 +17,9 @@ export default { }, async run({ $ }) { const response = await this.googleDocs.getDocument(this.docId); + $.export("$summary", `Successfully retrieved document with ID: ${this.docId}`); + return response; }, }; diff --git a/components/google_docs/actions/replace-image/replace-image.mjs b/components/google_docs/actions/replace-image/replace-image.mjs index 52bdfeae99cb1..92c801f59692c 100644 --- a/components/google_docs/actions/replace-image/replace-image.mjs +++ b/components/google_docs/actions/replace-image/replace-image.mjs @@ -4,7 +4,7 @@ export default { key: "google_docs-replace-image", name: "Replace Image", description: "Replace image in a existing document. [See the documentation](https://developers.google.com/docs/api/reference/rest/v1/documents/request#ReplaceImageRequest)", - version: "0.0.5", + version: "0.0.6", type: "action", props: { googleDocs, diff --git a/components/google_docs/actions/replace-text/replace-text.mjs b/components/google_docs/actions/replace-text/replace-text.mjs index afb44176bdf84..f578bd40c1077 100644 --- a/components/google_docs/actions/replace-text/replace-text.mjs +++ b/components/google_docs/actions/replace-text/replace-text.mjs @@ -4,7 +4,7 @@ export default { key: "google_docs-replace-text", name: "Replace Text", description: "Replace all instances of matched text in an existing document. [See the documentation](https://developers.google.com/docs/api/reference/rest/v1/documents/request#ReplaceAllTextRequest)", - version: "0.0.5", + version: "0.0.6", type: "action", props: { googleDocs, diff --git a/components/google_docs/common/utils.mjs b/components/google_docs/common/utils.mjs new file mode 100644 index 0000000000000..3d048e2997551 --- /dev/null +++ b/components/google_docs/common/utils.mjs @@ -0,0 +1,26 @@ +function getTextContentFromDocument(content) { + let textContent = ""; + content.forEach((element) => { + if (element.paragraph) { + element.paragraph.elements.forEach((textRun) => { + if (textRun.textRun) { + textContent += textRun.textRun.content; + } + }); + } + }); + return textContent; +} + +function addTextContentToDocument(response) { + const textContent = getTextContentFromDocument(response.body.content); + return { + textContent, + ...response, + }; +} + +export default { + getTextContentFromDocument, + addTextContentToDocument, +}; diff --git a/components/google_docs/google_docs.app.mjs b/components/google_docs/google_docs.app.mjs index 78174abef5bd6..9623b990184fd 100644 --- a/components/google_docs/google_docs.app.mjs +++ b/components/google_docs/google_docs.app.mjs @@ -1,5 +1,6 @@ import docs from "@googleapis/docs"; import googleDrive from "@pipedream/google_drive"; +import utils from "./common/utils.mjs"; export default { type: "app", @@ -36,7 +37,7 @@ export default { imageUri: { type: "string", label: "Image URL", - description: "The URL of the image you want to insert to the doc", + description: "The URL of the image you want to insert into the doc", }, text: { type: "string", @@ -105,7 +106,8 @@ export default { const { data } = await this.docs().documents.get({ documentId, }); - return data; + const doc = utils.addTextContentToDocument(data); + return doc; }, async createEmptyDoc(title) { const { data: createdDoc } = await this.docs().documents.create({ diff --git a/components/google_docs/package.json b/components/google_docs/package.json index dd78b14d98d9c..d3f2d39b36b28 100644 --- a/components/google_docs/package.json +++ b/components/google_docs/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/google_docs", - "version": "0.4.1", + "version": "0.4.2", "description": "Pipedream Google_docs Components", "main": "google_docs.app.mjs", "keywords": [ @@ -14,6 +14,6 @@ }, "dependencies": { "@googleapis/docs": "^3.3.0", - "@pipedream/google_drive": "^0.6.19" + "@pipedream/google_drive": "^0.8.8" } } diff --git a/components/google_docs/sources/common/base.mjs b/components/google_docs/sources/common/base.mjs index c9989e379e7f2..88544e9e4e6c3 100644 --- a/components/google_docs/sources/common/base.mjs +++ b/components/google_docs/sources/common/base.mjs @@ -1,17 +1,17 @@ import newFilesInstant from "@pipedream/google_drive/sources/new-files-instant/new-files-instant.mjs"; -import googleDrive from "../../google_docs.app.mjs"; -import { MY_DRIVE_VALUE } from "../../../google_drive/common/constants.mjs"; +import app from "../../google_docs.app.mjs"; +import { MY_DRIVE_VALUE } from "@pipedream/google_drive/common/constants.mjs"; export default { ...newFilesInstant, props: { - googleDrive, + app, db: "$.service.db", http: "$.interface.http", timer: newFilesInstant.props.timer, folders: { propDefinition: [ - googleDrive, + app, "folderId", ], type: "string[]", @@ -30,7 +30,7 @@ export default { methods: { ...newFilesInstant.methods, getDriveId() { - return googleDrive.methods.getDriveId(MY_DRIVE_VALUE); + return app.methods.getDriveId(MY_DRIVE_VALUE); }, shouldProcess(file) { return ( @@ -48,7 +48,7 @@ export default { async getDocumentsFromFiles(files, limit) { return files.reduce(async (acc, file) => { const docs = await acc; - const fileInfo = await this.googleDrive.getFile(file.id); + const fileInfo = await this.app.getFile(file.id); return docs.length >= limit ? docs : docs.concat(fileInfo); @@ -59,13 +59,13 @@ export default { if (!foldersIds?.length) { const opts = this.getDocumentsFromFolderOpts("root"); - const { files } = await this.googleDrive.listFilesInPage(null, opts); + const { files } = await this.app.listFilesInPage(null, opts); return this.getDocumentsFromFiles(files, limit); } return foldersIds.reduce(async (docs, folderId) => { const opts = this.getDocumentsFromFolderOpts(folderId); - const { files } = await this.googleDrive.listFilesInPage(null, opts); + const { files } = await this.app.listFilesInPage(null, opts); const nextDocuments = await this.getDocumentsFromFiles(files, limit); return (await docs).concat(nextDocuments); }, []); @@ -75,7 +75,7 @@ export default { if (!this.shouldProcess(file)) { continue; } - const doc = await this.googleDrive.getDocument(file.id); + const doc = await this.app.getDocument(file.id); this.$emit(doc, this.generateMeta(doc)); } }, diff --git a/components/google_docs/sources/new-document-created/new-document-created.mjs b/components/google_docs/sources/new-document-created/new-document-created.mjs index d560b4edad9d7..4430b9a00d4c1 100644 --- a/components/google_docs/sources/new-document-created/new-document-created.mjs +++ b/components/google_docs/sources/new-document-created/new-document-created.mjs @@ -5,7 +5,7 @@ export default { key: "google_docs-new-document-created", name: "New Document Created (Instant)", description: "Emit new event when a new document is created in Google Docs. [See the documentation](https://developers.google.com/drive/api/reference/rest/v3/changes/watch)", - version: "0.0.2", + version: "0.0.3", type: "source", dedupe: "unique", methods: { @@ -27,7 +27,7 @@ export default { fields: "*", }); - const { files } = await this.googleDrive.listFilesInPage(null, args); + const { files } = await this.app.listFilesInPage(null, args); if (!files?.length) { return; } diff --git a/components/google_docs/sources/new-or-updated-document/new-or-updated-document.mjs b/components/google_docs/sources/new-or-updated-document/new-or-updated-document.mjs index 5bdb5aa8d0024..7c9e80eaea9de 100644 --- a/components/google_docs/sources/new-or-updated-document/new-or-updated-document.mjs +++ b/components/google_docs/sources/new-or-updated-document/new-or-updated-document.mjs @@ -9,7 +9,7 @@ export default { key: "google_docs-new-or-updated-document", name: "New or Updated Document (Instant)", description: "Emit new event when a document is created or updated in Google Docs. [See the documentation](https://developers.google.com/drive/api/reference/rest/v3/changes/watch)", - version: "0.0.2", + version: "0.0.3", type: "source", dedupe: "unique", methods: { @@ -31,7 +31,7 @@ export default { const filteredFiles = this.checkMinimumInterval(changedFiles); for (const file of filteredFiles) { - file.parents = (await this.googleDrive.getFile(file.id, { + file.parents = (await this.app.getFile(file.id, { fields: "parents", })).parents; @@ -42,7 +42,7 @@ export default { continue; } - const doc = await this.googleDrive.getDocument(file.id); + const doc = await this.app.getDocument(file.id); const meta = this.generateMeta(doc); this.$emit(doc, meta); } From db76106df436bfd9875fe845c5a27de71cd403a7 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Wed, 22 Jan 2025 12:21:17 -0500 Subject: [PATCH 2/5] add new actions --- .../create-document-from-template.mjs | 31 ++++++++++++++ .../actions/find-document/find-document.mjs | 36 ++++++++++++++++ components/google_docs/common/utils.mjs | 42 +++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 components/google_docs/actions/create-document-from-template/create-document-from-template.mjs create mode 100644 components/google_docs/actions/find-document/find-document.mjs diff --git a/components/google_docs/actions/create-document-from-template/create-document-from-template.mjs b/components/google_docs/actions/create-document-from-template/create-document-from-template.mjs new file mode 100644 index 0000000000000..90a04ccf9b231 --- /dev/null +++ b/components/google_docs/actions/create-document-from-template/create-document-from-template.mjs @@ -0,0 +1,31 @@ +import app from "../../google_docs.app.mjs"; +import common from "@pipedream/google_drive/actions/create-file-from-template/create-file-from-template.mjs"; + +import utils from "../../common/utils.mjs"; + +const { + // eslint-disable-next-line no-unused-vars + name, description, type, ...others +} = common; +const props = utils.adjustPropDefinitions(others.props, app); + +export default { + ...others, + key: "google_docs-create-document-from-template", + name: "Create New Document From Template", + version: "0.0.1", + description, + type, + props: { + googleDrive: app, + ...props, + templateId: { + propDefinition: [ + app, + "docId", + ], + 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}}`.", + }, + }, +}; diff --git a/components/google_docs/actions/find-document/find-document.mjs b/components/google_docs/actions/find-document/find-document.mjs new file mode 100644 index 0000000000000..83d7934a45d2a --- /dev/null +++ b/components/google_docs/actions/find-document/find-document.mjs @@ -0,0 +1,36 @@ +import app from "../../google_docs.app.mjs"; +import common from "@pipedream/google_drive/actions/find-file/find-file.mjs"; +import { getListFilesOpts } from "@pipedream/google_drive/common/utils.mjs"; + +import utils from "../../common/utils.mjs"; + +const { + // eslint-disable-next-line no-unused-vars + name, description, type, ...others +} = common; +const props = utils.adjustPropDefinitions(others.props, app); + +export default { + ...others, + key: "google_docs-find-document", + name: "Find Document", + version: "0.0.1", + description, + type, + props: { + googleDrive: app, + ...props, + }, + async run({ $ }) { + const q = this.getQuery(); + const opts = getListFilesOpts(this.drive, { + q, + }); + const files = (await this.googleDrive.listFilesInPage(null, opts)).files?.filter(({ mimeType }) => mimeType === "application/vnd.google-apps.document") || []; + + $.export("$summary", `Successfully found ${files.length} file${files.length === 1 + ? "" + : "s"} with the query "${q}"`); + return files; + }, +}; diff --git a/components/google_docs/common/utils.mjs b/components/google_docs/common/utils.mjs index 3d048e2997551..4517bf53ca8e7 100644 --- a/components/google_docs/common/utils.mjs +++ b/components/google_docs/common/utils.mjs @@ -20,7 +20,49 @@ function addTextContentToDocument(response) { }; } +function adjustPropDefinitions(props, app) { + return Object.fromEntries( + Object.entries(props).map(([ + key, + prop, + ]) => { + if (typeof prop === "string") return [ + key, + prop, + ]; + const { + propDefinition, ...otherValues + } = prop; + if (propDefinition) { + const [ + , ...otherDefs + ] = propDefinition; + return [ + key, + { + propDefinition: [ + app, + ...otherDefs, + ], + ...otherValues, + }, + ]; + } + return [ + key, + otherValues.type === "app" + ? null + : otherValues, + ]; + }) + .filter(([ + , value, + ]) => value), + ); +} + export default { getTextContentFromDocument, addTextContentToDocument, + adjustPropDefinitions, }; From ef3fed67893696d3edfab5ac33293675f32773f3 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Wed, 22 Jan 2025 12:24:18 -0500 Subject: [PATCH 3/5] pnpm-lock.yaml --- pnpm-lock.yaml | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a2d916b34964b..419cd1b768c2e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4363,8 +4363,8 @@ importers: specifier: ^3.3.0 version: 3.3.0 '@pipedream/google_drive': - specifier: ^0.6.19 - version: 0.6.19 + specifier: ^0.8.8 + version: 0.8.8 components/google_drive: dependencies: @@ -8294,8 +8294,7 @@ importers: components/propeller: {} - components/proposify: - specifiers: {} + components/proposify: {} components/proprofs_quiz_maker: {} @@ -15296,6 +15295,9 @@ packages: '@pipedream/google_drive@0.6.19': resolution: {integrity: sha512-+JtwPhh0mHN3z3bOeyfw6OIztPhT0cVy/r/rpB5b0TFKWVly25Wz6Zv6zug5EhzyEt6DT7dnh9CpIhlxEj7SuA==} + '@pipedream/google_drive@0.8.8': + resolution: {integrity: sha512-cwRCfFv86+GW0G3huAzhXCPvZ+BWaQ+KAeOlGUJBCK1sPsHzNWY1sOAOvDKDVPh1xiSyCzO29+e9UynCfcCSrw==} + '@pipedream/helper_functions@0.3.13': resolution: {integrity: sha512-67zXT5rMccSYEeQCEKjO0g/U2Wnc3q1ErRWt0sivqJEF/KYqAb3tWmznDYGACbC8L6ML0WWSWRy7nEGt5Vyuaw==} @@ -31105,6 +31107,21 @@ snapshots: - encoding - supports-color + '@pipedream/google_drive@0.8.8': + dependencies: + '@googleapis/drive': 2.4.0 + '@pipedream/platform': 1.6.6 + cron-parser: 4.9.0 + google-docs-mustaches: 1.2.2 + got: 13.0.0 + lodash: 4.17.21 + mime-db: 1.53.0 + uuid: 8.3.2 + transitivePeerDependencies: + - debug + - encoding + - supports-color + '@pipedream/helper_functions@0.3.13': dependencies: '@pipedream/platform': 1.6.6 From 71e12b0d952997730fa848f929c08b28613d9968 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Mon, 27 Jan 2025 10:52:37 -0500 Subject: [PATCH 4/5] rename prop --- .../create-document-from-template.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/components/google_docs/actions/create-document-from-template/create-document-from-template.mjs b/components/google_docs/actions/create-document-from-template/create-document-from-template.mjs index 90a04ccf9b231..faf70debd6d97 100644 --- a/components/google_docs/actions/create-document-from-template/create-document-from-template.mjs +++ b/components/google_docs/actions/create-document-from-template/create-document-from-template.mjs @@ -24,6 +24,7 @@ export default { app, "docId", ], + label: "Template", 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}}`.", }, From 995c4790d6daf1f2ed25e1f84dfa7ffc9c8714e5 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Mon, 27 Jan 2025 11:05:14 -0500 Subject: [PATCH 5/5] fix sources --- components/google_docs/sources/common/base.mjs | 16 ++++++++-------- .../new-document-created.mjs | 2 +- .../new-or-updated-document.mjs | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/components/google_docs/sources/common/base.mjs b/components/google_docs/sources/common/base.mjs index 88544e9e4e6c3..d25a51a0c33a6 100644 --- a/components/google_docs/sources/common/base.mjs +++ b/components/google_docs/sources/common/base.mjs @@ -1,17 +1,17 @@ import newFilesInstant from "@pipedream/google_drive/sources/new-files-instant/new-files-instant.mjs"; -import app from "../../google_docs.app.mjs"; +import googleDrive from "../../google_docs.app.mjs"; import { MY_DRIVE_VALUE } from "@pipedream/google_drive/common/constants.mjs"; export default { ...newFilesInstant, props: { - app, + googleDrive, db: "$.service.db", http: "$.interface.http", timer: newFilesInstant.props.timer, folders: { propDefinition: [ - app, + googleDrive, "folderId", ], type: "string[]", @@ -30,7 +30,7 @@ export default { methods: { ...newFilesInstant.methods, getDriveId() { - return app.methods.getDriveId(MY_DRIVE_VALUE); + return googleDrive.methods.getDriveId(MY_DRIVE_VALUE); }, shouldProcess(file) { return ( @@ -48,7 +48,7 @@ export default { async getDocumentsFromFiles(files, limit) { return files.reduce(async (acc, file) => { const docs = await acc; - const fileInfo = await this.app.getFile(file.id); + const fileInfo = await this.googleDrive.getFile(file.id); return docs.length >= limit ? docs : docs.concat(fileInfo); @@ -59,13 +59,13 @@ export default { if (!foldersIds?.length) { const opts = this.getDocumentsFromFolderOpts("root"); - const { files } = await this.app.listFilesInPage(null, opts); + const { files } = await this.googleDrive.listFilesInPage(null, opts); return this.getDocumentsFromFiles(files, limit); } return foldersIds.reduce(async (docs, folderId) => { const opts = this.getDocumentsFromFolderOpts(folderId); - const { files } = await this.app.listFilesInPage(null, opts); + const { files } = await this.googleDrive.listFilesInPage(null, opts); const nextDocuments = await this.getDocumentsFromFiles(files, limit); return (await docs).concat(nextDocuments); }, []); @@ -75,7 +75,7 @@ export default { if (!this.shouldProcess(file)) { continue; } - const doc = await this.app.getDocument(file.id); + const doc = await this.googleDrive.getDocument(file.id); this.$emit(doc, this.generateMeta(doc)); } }, diff --git a/components/google_docs/sources/new-document-created/new-document-created.mjs b/components/google_docs/sources/new-document-created/new-document-created.mjs index 4430b9a00d4c1..1fb69e568c26a 100644 --- a/components/google_docs/sources/new-document-created/new-document-created.mjs +++ b/components/google_docs/sources/new-document-created/new-document-created.mjs @@ -27,7 +27,7 @@ export default { fields: "*", }); - const { files } = await this.app.listFilesInPage(null, args); + const { files } = await this.googleDrive.listFilesInPage(null, args); if (!files?.length) { return; } diff --git a/components/google_docs/sources/new-or-updated-document/new-or-updated-document.mjs b/components/google_docs/sources/new-or-updated-document/new-or-updated-document.mjs index 7c9e80eaea9de..9c6a32a23c7f0 100644 --- a/components/google_docs/sources/new-or-updated-document/new-or-updated-document.mjs +++ b/components/google_docs/sources/new-or-updated-document/new-or-updated-document.mjs @@ -2,7 +2,7 @@ import common from "../common/base.mjs"; import { GOOGLE_DRIVE_NOTIFICATION_CHANGE, GOOGLE_DRIVE_NOTIFICATION_UPDATE, -} from "../../../google_drive/common/constants.mjs"; +} from "@pipedream/google_drive/common/constants.mjs"; export default { ...common, @@ -31,7 +31,7 @@ export default { const filteredFiles = this.checkMinimumInterval(changedFiles); for (const file of filteredFiles) { - file.parents = (await this.app.getFile(file.id, { + file.parents = (await this.googleDrive.getFile(file.id, { fields: "parents", })).parents; @@ -42,7 +42,7 @@ export default { continue; } - const doc = await this.app.getDocument(file.id); + const doc = await this.googleDrive.getDocument(file.id); const meta = this.generateMeta(doc); this.$emit(doc, meta); }