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-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..faf70debd6d97 --- /dev/null +++ b/components/google_docs/actions/create-document-from-template/create-document-from-template.mjs @@ -0,0 +1,32 @@ +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", + ], + 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}}`.", + }, + }, +}; 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/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/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..4517bf53ca8e7 --- /dev/null +++ b/components/google_docs/common/utils.mjs @@ -0,0 +1,68 @@ +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, + }; +} + +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, +}; 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..d25a51a0c33a6 100644 --- a/components/google_docs/sources/common/base.mjs +++ b/components/google_docs/sources/common/base.mjs @@ -1,6 +1,6 @@ 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 { MY_DRIVE_VALUE } from "@pipedream/google_drive/common/constants.mjs"; export default { ...newFilesInstant, 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..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 @@ -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: { 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..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,14 +2,14 @@ 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, 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: { 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