Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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,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}}`.",
},
},
};
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"
}
}
18 changes: 9 additions & 9 deletions components/google_docs/sources/common/base.mjs
Original file line number Diff line number Diff line change
@@ -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[]",
Expand All @@ -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 (
Expand All @@ -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);
Expand All @@ -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);
}, []);
Expand All @@ -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));
}
},
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 All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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;

Expand All @@ -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);
}
Expand Down
Loading
Loading