Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion components/google_docs/actions/append-text/append-text.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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}}`.",
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
36 changes: 36 additions & 0 deletions components/google_docs/actions/find-document/find-document.mjs
Original file line number Diff line number Diff line change
@@ -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;
},
};
4 changes: 3 additions & 1 deletion components/google_docs/actions/get-document/get-document.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
68 changes: 68 additions & 0 deletions components/google_docs/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -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,
};
6 changes: 4 additions & 2 deletions components/google_docs/google_docs.app.mjs
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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({
Expand Down
4 changes: 2 additions & 2 deletions components/google_docs/package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand All @@ -14,6 +14,6 @@
},
"dependencies": {
"@googleapis/docs": "^3.3.0",
"@pipedream/google_drive": "^0.6.19"
"@pipedream/google_drive": "^0.8.8"
}
}
2 changes: 1 addition & 1 deletion components/google_docs/sources/common/base.mjs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
25 changes: 21 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading