@divyacon/piece-google-docs 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.MIT-AP +24 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +128 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/actions/append-text.d.ts +8 -0
- package/dist/lib/actions/append-text.d.ts.map +1 -0
- package/dist/lib/actions/append-text.js +40 -0
- package/dist/lib/actions/append-text.js.map +1 -0
- package/dist/lib/actions/batch-update.action.d.ts +8 -0
- package/dist/lib/actions/batch-update.action.d.ts.map +1 -0
- package/dist/lib/actions/batch-update.action.js +63 -0
- package/dist/lib/actions/batch-update.action.js.map +1 -0
- package/dist/lib/actions/copy-document.action.d.ts +12 -0
- package/dist/lib/actions/copy-document.action.d.ts.map +1 -0
- package/dist/lib/actions/copy-document.action.js +72 -0
- package/dist/lib/actions/copy-document.action.js.map +1 -0
- package/dist/lib/actions/create-and-populate-table.action.d.ts +8 -0
- package/dist/lib/actions/create-and-populate-table.action.d.ts.map +1 -0
- package/dist/lib/actions/create-and-populate-table.action.js +138 -0
- package/dist/lib/actions/create-and-populate-table.action.js.map +1 -0
- package/dist/lib/actions/create-document-based-on-template.action.d.ts +10 -0
- package/dist/lib/actions/create-document-based-on-template.action.d.ts.map +1 -0
- package/dist/lib/actions/create-document-based-on-template.action.js +107 -0
- package/dist/lib/actions/create-document-based-on-template.action.js.map +1 -0
- package/dist/lib/actions/create-document-from-markdown.action.d.ts +8 -0
- package/dist/lib/actions/create-document-from-markdown.action.d.ts.map +1 -0
- package/dist/lib/actions/create-document-from-markdown.action.js +69 -0
- package/dist/lib/actions/create-document-from-markdown.action.js.map +1 -0
- package/dist/lib/actions/create-document.d.ts +8 -0
- package/dist/lib/actions/create-document.d.ts.map +1 -0
- package/dist/lib/actions/create-document.js +35 -0
- package/dist/lib/actions/create-document.js.map +1 -0
- package/dist/lib/actions/create-footer.action.d.ts +8 -0
- package/dist/lib/actions/create-footer.action.d.ts.map +1 -0
- package/dist/lib/actions/create-footer.action.js +66 -0
- package/dist/lib/actions/create-footer.action.js.map +1 -0
- package/dist/lib/actions/create-footnote.action.d.ts +8 -0
- package/dist/lib/actions/create-footnote.action.d.ts.map +1 -0
- package/dist/lib/actions/create-footnote.action.js +58 -0
- package/dist/lib/actions/create-footnote.action.js.map +1 -0
- package/dist/lib/actions/create-header.action.d.ts +8 -0
- package/dist/lib/actions/create-header.action.d.ts.map +1 -0
- package/dist/lib/actions/create-header.action.js +66 -0
- package/dist/lib/actions/create-header.action.js.map +1 -0
- package/dist/lib/actions/create-named-range.action.d.ts +10 -0
- package/dist/lib/actions/create-named-range.action.d.ts.map +1 -0
- package/dist/lib/actions/create-named-range.action.js +74 -0
- package/dist/lib/actions/create-named-range.action.js.map +1 -0
- package/dist/lib/actions/create-paragraph-bullets.action.d.ts +10 -0
- package/dist/lib/actions/create-paragraph-bullets.action.d.ts.map +1 -0
- package/dist/lib/actions/create-paragraph-bullets.action.js +98 -0
- package/dist/lib/actions/create-paragraph-bullets.action.js.map +1 -0
- package/dist/lib/actions/create-text-document.action.d.ts +8 -0
- package/dist/lib/actions/create-text-document.action.d.ts.map +1 -0
- package/dist/lib/actions/create-text-document.action.js +42 -0
- package/dist/lib/actions/create-text-document.action.js.map +1 -0
- package/dist/lib/actions/delete-content-range.action.d.ts +9 -0
- package/dist/lib/actions/delete-content-range.action.d.ts.map +1 -0
- package/dist/lib/actions/delete-content-range.action.js +64 -0
- package/dist/lib/actions/delete-content-range.action.js.map +1 -0
- package/dist/lib/actions/delete-footer.action.d.ts +8 -0
- package/dist/lib/actions/delete-footer.action.d.ts.map +1 -0
- package/dist/lib/actions/delete-footer.action.js +56 -0
- package/dist/lib/actions/delete-footer.action.js.map +1 -0
- package/dist/lib/actions/delete-header.action.d.ts +8 -0
- package/dist/lib/actions/delete-header.action.d.ts.map +1 -0
- package/dist/lib/actions/delete-header.action.js +56 -0
- package/dist/lib/actions/delete-header.action.js.map +1 -0
- package/dist/lib/actions/delete-named-range.action.d.ts +9 -0
- package/dist/lib/actions/delete-named-range.action.d.ts.map +1 -0
- package/dist/lib/actions/delete-named-range.action.js +69 -0
- package/dist/lib/actions/delete-named-range.action.js.map +1 -0
- package/dist/lib/actions/delete-paragraph-bullets.action.d.ts +9 -0
- package/dist/lib/actions/delete-paragraph-bullets.action.d.ts.map +1 -0
- package/dist/lib/actions/delete-paragraph-bullets.action.js +66 -0
- package/dist/lib/actions/delete-paragraph-bullets.action.js.map +1 -0
- package/dist/lib/actions/delete-table-column.action.d.ts +10 -0
- package/dist/lib/actions/delete-table-column.action.d.ts.map +1 -0
- package/dist/lib/actions/delete-table-column.action.js +72 -0
- package/dist/lib/actions/delete-table-column.action.js.map +1 -0
- package/dist/lib/actions/delete-table-row.action.d.ts +10 -0
- package/dist/lib/actions/delete-table-row.action.d.ts.map +1 -0
- package/dist/lib/actions/delete-table-row.action.js +72 -0
- package/dist/lib/actions/delete-table-row.action.js.map +1 -0
- package/dist/lib/actions/export-as-pdf.action.d.ts +7 -0
- package/dist/lib/actions/export-as-pdf.action.d.ts.map +1 -0
- package/dist/lib/actions/export-as-pdf.action.js +61 -0
- package/dist/lib/actions/export-as-pdf.action.js.map +1 -0
- package/dist/lib/actions/find-document.d.ts +16 -0
- package/dist/lib/actions/find-document.d.ts.map +1 -0
- package/dist/lib/actions/find-document.js +127 -0
- package/dist/lib/actions/find-document.js.map +1 -0
- package/dist/lib/actions/get-document-end-index.action.d.ts +7 -0
- package/dist/lib/actions/get-document-end-index.action.d.ts.map +1 -0
- package/dist/lib/actions/get-document-end-index.action.js +54 -0
- package/dist/lib/actions/get-document-end-index.action.js.map +1 -0
- package/dist/lib/actions/get-document-plaintext.action.d.ts +7 -0
- package/dist/lib/actions/get-document-plaintext.action.d.ts.map +1 -0
- package/dist/lib/actions/get-document-plaintext.action.js +76 -0
- package/dist/lib/actions/get-document-plaintext.action.js.map +1 -0
- package/dist/lib/actions/get-document.action.d.ts +7 -0
- package/dist/lib/actions/get-document.action.d.ts.map +1 -0
- package/dist/lib/actions/get-document.action.js +45 -0
- package/dist/lib/actions/get-document.action.js.map +1 -0
- package/dist/lib/actions/insert-image-in-table-cell.action.d.ts +13 -0
- package/dist/lib/actions/insert-image-in-table-cell.action.d.ts.map +1 -0
- package/dist/lib/actions/insert-image-in-table-cell.action.js +128 -0
- package/dist/lib/actions/insert-image-in-table-cell.action.js.map +1 -0
- package/dist/lib/actions/insert-inline-image.action.d.ts +11 -0
- package/dist/lib/actions/insert-inline-image.action.d.ts.map +1 -0
- package/dist/lib/actions/insert-inline-image.action.js +84 -0
- package/dist/lib/actions/insert-inline-image.action.js.map +1 -0
- package/dist/lib/actions/insert-page-break.action.d.ts +8 -0
- package/dist/lib/actions/insert-page-break.action.d.ts.map +1 -0
- package/dist/lib/actions/insert-page-break.action.js +60 -0
- package/dist/lib/actions/insert-page-break.action.js.map +1 -0
- package/dist/lib/actions/insert-table-column.action.d.ts +11 -0
- package/dist/lib/actions/insert-table-column.action.d.ts.map +1 -0
- package/dist/lib/actions/insert-table-column.action.js +86 -0
- package/dist/lib/actions/insert-table-column.action.js.map +1 -0
- package/dist/lib/actions/insert-table-row.action.d.ts +11 -0
- package/dist/lib/actions/insert-table-row.action.d.ts.map +1 -0
- package/dist/lib/actions/insert-table-row.action.js +86 -0
- package/dist/lib/actions/insert-table-row.action.js.map +1 -0
- package/dist/lib/actions/insert-table.action.d.ts +10 -0
- package/dist/lib/actions/insert-table.action.d.ts.map +1 -0
- package/dist/lib/actions/insert-table.action.js +72 -0
- package/dist/lib/actions/insert-table.action.js.map +1 -0
- package/dist/lib/actions/insert-text-in-table-cell.action.d.ts +11 -0
- package/dist/lib/actions/insert-text-in-table-cell.action.d.ts.map +1 -0
- package/dist/lib/actions/insert-text-in-table-cell.action.js +115 -0
- package/dist/lib/actions/insert-text-in-table-cell.action.js.map +1 -0
- package/dist/lib/actions/insert-text.action.d.ts +9 -0
- package/dist/lib/actions/insert-text.action.d.ts.map +1 -0
- package/dist/lib/actions/insert-text.action.js +66 -0
- package/dist/lib/actions/insert-text.action.js.map +1 -0
- package/dist/lib/actions/read-document.action.d.ts +7 -0
- package/dist/lib/actions/read-document.action.d.ts.map +1 -0
- package/dist/lib/actions/read-document.action.js +44 -0
- package/dist/lib/actions/read-document.action.js.map +1 -0
- package/dist/lib/actions/replace-all-text.action.d.ts +10 -0
- package/dist/lib/actions/replace-all-text.action.d.ts.map +1 -0
- package/dist/lib/actions/replace-all-text.action.js +92 -0
- package/dist/lib/actions/replace-all-text.action.js.map +1 -0
- package/dist/lib/actions/replace-body-with-markdown.action.d.ts +8 -0
- package/dist/lib/actions/replace-body-with-markdown.action.d.ts.map +1 -0
- package/dist/lib/actions/replace-body-with-markdown.action.js +79 -0
- package/dist/lib/actions/replace-body-with-markdown.action.js.map +1 -0
- package/dist/lib/actions/replace-image.action.d.ts +9 -0
- package/dist/lib/actions/replace-image.action.d.ts.map +1 -0
- package/dist/lib/actions/replace-image.action.js +65 -0
- package/dist/lib/actions/replace-image.action.js.map +1 -0
- package/dist/lib/actions/replace-section-with-markdown.action.d.ts +10 -0
- package/dist/lib/actions/replace-section-with-markdown.action.d.ts.map +1 -0
- package/dist/lib/actions/replace-section-with-markdown.action.js +106 -0
- package/dist/lib/actions/replace-section-with-markdown.action.js.map +1 -0
- package/dist/lib/actions/search-documents.action.d.ts +11 -0
- package/dist/lib/actions/search-documents.action.d.ts.map +1 -0
- package/dist/lib/actions/search-documents.action.js +121 -0
- package/dist/lib/actions/search-documents.action.js.map +1 -0
- package/dist/lib/actions/unmerge-table-cells.action.d.ts +12 -0
- package/dist/lib/actions/unmerge-table-cells.action.d.ts.map +1 -0
- package/dist/lib/actions/unmerge-table-cells.action.js +94 -0
- package/dist/lib/actions/unmerge-table-cells.action.js.map +1 -0
- package/dist/lib/actions/update-document-style.action.d.ts +11 -0
- package/dist/lib/actions/update-document-style.action.d.ts.map +1 -0
- package/dist/lib/actions/update-document-style.action.js +95 -0
- package/dist/lib/actions/update-document-style.action.js.map +1 -0
- package/dist/lib/actions/update-table-row-style.action.d.ts +10 -0
- package/dist/lib/actions/update-table-row-style.action.d.ts.map +1 -0
- package/dist/lib/actions/update-table-row-style.action.js +78 -0
- package/dist/lib/actions/update-table-row-style.action.js.map +1 -0
- package/dist/lib/auth.d.ts +11 -0
- package/dist/lib/auth.d.ts.map +1 -0
- package/dist/lib/auth.js +92 -0
- package/dist/lib/auth.js.map +1 -0
- package/dist/lib/common/index.d.ts +11 -0
- package/dist/lib/common/index.d.ts.map +1 -0
- package/dist/lib/common/index.js +124 -0
- package/dist/lib/common/index.js.map +1 -0
- package/dist/lib/common/props.d.ts +5 -0
- package/dist/lib/common/props.d.ts.map +1 -0
- package/dist/lib/common/props.js +53 -0
- package/dist/lib/common/props.js.map +1 -0
- package/dist/lib/output-schemas.d.ts +43 -0
- package/dist/lib/output-schemas.d.ts.map +1 -0
- package/dist/lib/output-schemas.js +554 -0
- package/dist/lib/output-schemas.js.map +1 -0
- package/dist/lib/triggers/new-document.d.ts +35 -0
- package/dist/lib/triggers/new-document.d.ts.map +1 -0
- package/dist/lib/triggers/new-document.js +104 -0
- package/dist/lib/triggers/new-document.js.map +1 -0
- package/package.json +48 -4
- package/src/index.ts +120 -0
- package/src/lib/actions/append-text.ts +37 -0
- package/src/lib/actions/batch-update.action.ts +58 -0
- package/src/lib/actions/copy-document.action.ts +74 -0
- package/src/lib/actions/create-and-populate-table.action.ts +141 -0
- package/src/lib/actions/create-document-based-on-template.action.ts +110 -0
- package/src/lib/actions/create-document-from-markdown.action.ts +63 -0
- package/src/lib/actions/create-document.ts +36 -0
- package/src/lib/actions/create-footer.action.ts +59 -0
- package/src/lib/actions/create-footnote.action.ts +53 -0
- package/src/lib/actions/create-header.action.ts +59 -0
- package/src/lib/actions/create-named-range.action.ts +70 -0
- package/src/lib/actions/create-paragraph-bullets.action.ts +95 -0
- package/src/lib/actions/create-text-document.action.ts +35 -0
- package/src/lib/actions/delete-content-range.action.ts +59 -0
- package/src/lib/actions/delete-footer.action.ts +51 -0
- package/src/lib/actions/delete-header.action.ts +51 -0
- package/src/lib/actions/delete-named-range.action.ts +65 -0
- package/src/lib/actions/delete-paragraph-bullets.action.ts +62 -0
- package/src/lib/actions/delete-table-column.action.ts +67 -0
- package/src/lib/actions/delete-table-row.action.ts +67 -0
- package/src/lib/actions/export-as-pdf.action.ts +59 -0
- package/src/lib/actions/find-document.ts +136 -0
- package/src/lib/actions/get-document-end-index.action.ts +47 -0
- package/src/lib/actions/get-document-plaintext.action.ts +74 -0
- package/src/lib/actions/get-document.action.ts +37 -0
- package/src/lib/actions/insert-image-in-table-cell.action.ts +139 -0
- package/src/lib/actions/insert-inline-image.action.ts +83 -0
- package/src/lib/actions/insert-page-break.action.ts +56 -0
- package/src/lib/actions/insert-table-column.action.ts +80 -0
- package/src/lib/actions/insert-table-row.action.ts +80 -0
- package/src/lib/actions/insert-table.action.ts +68 -0
- package/src/lib/actions/insert-text-in-table-cell.action.ts +120 -0
- package/src/lib/actions/insert-text.action.ts +62 -0
- package/src/lib/actions/read-document.action.ts +40 -0
- package/src/lib/actions/replace-all-text.action.ts +95 -0
- package/src/lib/actions/replace-body-with-markdown.action.ts +76 -0
- package/src/lib/actions/replace-image.action.ts +60 -0
- package/src/lib/actions/replace-section-with-markdown.action.ts +104 -0
- package/src/lib/actions/search-documents.action.ts +131 -0
- package/src/lib/actions/unmerge-table-cells.action.ts +88 -0
- package/src/lib/actions/update-document-style.action.ts +93 -0
- package/src/lib/actions/update-table-row-style.action.ts +73 -0
- package/src/lib/auth.ts +84 -0
- package/src/lib/common/index.ts +126 -0
- package/src/lib/common/props.ts +55 -0
- package/src/lib/output-schemas.ts +593 -0
- package/src/lib/triggers/new-document.ts +108 -0
- package/README.md +0 -3
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.newDocumentTrigger = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
// Vendored from Activepieces packages/pieces/community/google-docs/src/lib/triggers/new-document.ts (MIT).
|
|
6
|
+
// Generated by packages/scripts/vendor-ap.mjs - do not edit by hand.
|
|
7
|
+
const auth_1 = require("../auth");
|
|
8
|
+
const pieces_common_1 = require("@agnocon/pieces-common");
|
|
9
|
+
const pieces_framework_1 = require("@agnocon/pieces-framework");
|
|
10
|
+
const props_1 = require("../common/props");
|
|
11
|
+
const output_schemas_1 = require("../output-schemas");
|
|
12
|
+
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
13
|
+
const drive_1 = require("@googleapis/drive");
|
|
14
|
+
const polling = {
|
|
15
|
+
strategy: pieces_common_1.DedupeStrategy.TIMEBASED,
|
|
16
|
+
items(_a) {
|
|
17
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* ({ auth, propsValue, lastFetchEpochMS }) {
|
|
18
|
+
const folderId = propsValue.folderId;
|
|
19
|
+
const q = ["mimeType='application/vnd.google-apps.document'", 'trashed = false'];
|
|
20
|
+
if (lastFetchEpochMS) {
|
|
21
|
+
q.push(`createdTime > '${(0, dayjs_1.default)(lastFetchEpochMS).toISOString()}'`);
|
|
22
|
+
}
|
|
23
|
+
if (folderId) {
|
|
24
|
+
q.push(`'${folderId}' in parents`);
|
|
25
|
+
}
|
|
26
|
+
const authClient = yield (0, auth_1.createGoogleClient)(auth);
|
|
27
|
+
const drive = (0, drive_1.drive)({ version: 'v3', auth: authClient });
|
|
28
|
+
let nextPageToken;
|
|
29
|
+
const items = [];
|
|
30
|
+
do {
|
|
31
|
+
const response = yield drive.files.list({
|
|
32
|
+
q: q.join(' and '),
|
|
33
|
+
fields: '*',
|
|
34
|
+
orderBy: 'createdTime desc',
|
|
35
|
+
supportsAllDrives: true,
|
|
36
|
+
includeItemsFromAllDrives: true,
|
|
37
|
+
corpora: 'allDrives',
|
|
38
|
+
pageToken: nextPageToken,
|
|
39
|
+
});
|
|
40
|
+
const fileList = response.data;
|
|
41
|
+
if (fileList.files) {
|
|
42
|
+
items.push(...fileList.files);
|
|
43
|
+
}
|
|
44
|
+
if (lastFetchEpochMS === 0)
|
|
45
|
+
break;
|
|
46
|
+
nextPageToken = response.data.nextPageToken;
|
|
47
|
+
} while (nextPageToken);
|
|
48
|
+
return items.map((item) => ({
|
|
49
|
+
epochMilliSeconds: (0, dayjs_1.default)(item.createdTime).valueOf(),
|
|
50
|
+
data: item,
|
|
51
|
+
}));
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
exports.newDocumentTrigger = (0, pieces_framework_1.createTrigger)({
|
|
56
|
+
auth: auth_1.googleDocsAuth,
|
|
57
|
+
name: 'new-document',
|
|
58
|
+
displayName: 'New Document',
|
|
59
|
+
description: 'Triggers when a new document is added to a specific folder(optional).',
|
|
60
|
+
aiMetadata: {
|
|
61
|
+
description: 'Fires when a new Google Docs document is created, optionally limited to a specific Drive folder. Use to react when a document first appears; it does not fire on edits to existing documents.',
|
|
62
|
+
},
|
|
63
|
+
type: pieces_framework_1.TriggerStrategy.POLLING,
|
|
64
|
+
props: {
|
|
65
|
+
folderId: props_1.folderIdProp,
|
|
66
|
+
},
|
|
67
|
+
outputSchema: output_schemas_1.newDocumentTriggerOutputSchema,
|
|
68
|
+
onEnable(context) {
|
|
69
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
yield pieces_common_1.pollingHelper.onEnable(polling, {
|
|
71
|
+
auth: context.auth,
|
|
72
|
+
store: context.store,
|
|
73
|
+
propsValue: context.propsValue,
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
onDisable(context) {
|
|
78
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
yield pieces_common_1.pollingHelper.onDisable(polling, {
|
|
80
|
+
auth: context.auth,
|
|
81
|
+
store: context.store,
|
|
82
|
+
propsValue: context.propsValue,
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
test(context) {
|
|
87
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
return yield pieces_common_1.pollingHelper.test(polling, context);
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
run(context) {
|
|
92
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
return yield pieces_common_1.pollingHelper.poll(polling, context);
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
sampleData: {
|
|
97
|
+
kind: 'drive#file',
|
|
98
|
+
mimeType: 'application/vnd.google-apps.document',
|
|
99
|
+
webViewLink: 'https://docs.google.com/document/d/1_9xjsrYFgHVvgqYwAJ8KcsDcNU/edit?usp=drivesdk',
|
|
100
|
+
id: '1_9xjsrYFgHVvgqYwAJ8KcsDcN3AzPelsux',
|
|
101
|
+
name: 'Test Document',
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
//# sourceMappingURL=new-document.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"new-document.js","sourceRoot":"","sources":["../../../src/lib/triggers/new-document.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@divyacon/piece-google-docs",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "DivyaCon google-docs connector",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"require": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"src",
|
|
17
|
+
"LICENSE.MIT-AP"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc -p tsconfig.json",
|
|
21
|
+
"vendor": "node ../scripts/vendor-ap.mjs piece-google-docs"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@agnocon/core-utils": "0.2.0",
|
|
25
|
+
"@agnocon/piece-types": "0.3.1",
|
|
26
|
+
"@agnocon/pieces-common": "0.12.8",
|
|
27
|
+
"@agnocon/pieces-framework": "0.36.0",
|
|
28
|
+
"tslib": "2.6.2",
|
|
29
|
+
"@googleapis/docs": "9.3.0",
|
|
30
|
+
"@googleapis/drive": "20.2.0",
|
|
31
|
+
"dayjs": "1.11.9",
|
|
32
|
+
"google-auth-library": "10.5.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/node": "20.17.6",
|
|
36
|
+
"typescript": "5.5.4"
|
|
37
|
+
},
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"agnocon": {
|
|
40
|
+
"originVersion": "0.4.8"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public",
|
|
44
|
+
"tag": "latest"
|
|
45
|
+
},
|
|
46
|
+
"keywords": [
|
|
47
|
+
"agnocon",
|
|
48
|
+
"connector"
|
|
49
|
+
]
|
|
50
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { createPiece } from '@agnocon/pieces-framework';
|
|
2
|
+
|
|
3
|
+
import { createCustomApiCallAction } from '@agnocon/pieces-common';
|
|
4
|
+
import { PieceCategory } from '@agnocon/pieces-framework';
|
|
5
|
+
import { createDocument } from './lib/actions/create-document';
|
|
6
|
+
import { createDocumentBasedOnTemplate } from './lib/actions/create-document-based-on-template.action';
|
|
7
|
+
import { readDocument } from './lib/actions/read-document.action';
|
|
8
|
+
import { appendText } from './lib/actions/append-text';
|
|
9
|
+
import { findDocumentAction } from './lib/actions/find-document';
|
|
10
|
+
import { getDocumentPlaintext } from './lib/actions/get-document-plaintext.action';
|
|
11
|
+
import { replaceAllText } from './lib/actions/replace-all-text.action';
|
|
12
|
+
import { searchDocuments } from './lib/actions/search-documents.action';
|
|
13
|
+
import { copyDocument } from './lib/actions/copy-document.action';
|
|
14
|
+
import { getDocument } from './lib/actions/get-document.action';
|
|
15
|
+
import { createTextDocument } from './lib/actions/create-text-document.action';
|
|
16
|
+
import { getDocumentEndIndex } from './lib/actions/get-document-end-index.action';
|
|
17
|
+
import { insertText } from './lib/actions/insert-text.action';
|
|
18
|
+
import { deleteContentRange } from './lib/actions/delete-content-range.action';
|
|
19
|
+
import { createDocumentFromMarkdown } from './lib/actions/create-document-from-markdown.action';
|
|
20
|
+
import { createFooter } from './lib/actions/create-footer.action';
|
|
21
|
+
import { createFootnote } from './lib/actions/create-footnote.action';
|
|
22
|
+
import { createHeader } from './lib/actions/create-header.action';
|
|
23
|
+
import { createNamedRange } from './lib/actions/create-named-range.action';
|
|
24
|
+
import { createParagraphBullets } from './lib/actions/create-paragraph-bullets.action';
|
|
25
|
+
import { deleteFooter } from './lib/actions/delete-footer.action';
|
|
26
|
+
import { deleteHeader } from './lib/actions/delete-header.action';
|
|
27
|
+
import { deleteNamedRange } from './lib/actions/delete-named-range.action';
|
|
28
|
+
import { deleteParagraphBullets } from './lib/actions/delete-paragraph-bullets.action';
|
|
29
|
+
import { deleteTableColumn } from './lib/actions/delete-table-column.action';
|
|
30
|
+
import { deleteTableRow } from './lib/actions/delete-table-row.action';
|
|
31
|
+
import { insertTable } from './lib/actions/insert-table.action';
|
|
32
|
+
import { insertTableColumn } from './lib/actions/insert-table-column.action';
|
|
33
|
+
import { insertTableRow } from './lib/actions/insert-table-row.action';
|
|
34
|
+
import { insertTextInTableCell } from './lib/actions/insert-text-in-table-cell.action';
|
|
35
|
+
import { insertImageInTableCell } from './lib/actions/insert-image-in-table-cell.action';
|
|
36
|
+
import { unmergeTableCells } from './lib/actions/unmerge-table-cells.action';
|
|
37
|
+
import { updateTableRowStyle } from './lib/actions/update-table-row-style.action';
|
|
38
|
+
import { insertInlineImage } from './lib/actions/insert-inline-image.action';
|
|
39
|
+
import { insertPageBreak } from './lib/actions/insert-page-break.action';
|
|
40
|
+
import { replaceImage } from './lib/actions/replace-image.action';
|
|
41
|
+
import { updateDocumentStyle } from './lib/actions/update-document-style.action';
|
|
42
|
+
import { exportAsPdf } from './lib/actions/export-as-pdf.action';
|
|
43
|
+
import { createAndPopulateTable } from './lib/actions/create-and-populate-table.action';
|
|
44
|
+
import { replaceBodyWithMarkdown } from './lib/actions/replace-body-with-markdown.action';
|
|
45
|
+
import { replaceSectionWithMarkdown } from './lib/actions/replace-section-with-markdown.action';
|
|
46
|
+
import { batchUpdate } from './lib/actions/batch-update.action';
|
|
47
|
+
import { newDocumentTrigger } from './lib/triggers/new-document';
|
|
48
|
+
import { googleDocsAuth, getAccessToken, GoogleDocsAuthValue } from './lib/auth';
|
|
49
|
+
|
|
50
|
+
export { googleDocsAuth, getAccessToken, GoogleDocsAuthValue } from './lib/auth';
|
|
51
|
+
|
|
52
|
+
export const googleDocs = createPiece({
|
|
53
|
+
displayName: 'Google Docs',
|
|
54
|
+
description: 'Create and edit documents online',
|
|
55
|
+
minimumSupportedRelease: '0.86.4',
|
|
56
|
+
logoUrl: 'https://cdn.activepieces.com/pieces/google-docs.png',
|
|
57
|
+
categories: [PieceCategory.CONTENT_AND_FILES],
|
|
58
|
+
authors: [
|
|
59
|
+
'pfernandez98',
|
|
60
|
+
'kishanprmr',
|
|
61
|
+
'MoShizzle',
|
|
62
|
+
'khaledmashaly',
|
|
63
|
+
'abuaboud',
|
|
64
|
+
'AbdullahBitar',
|
|
65
|
+
'Kevinyu-alan'
|
|
66
|
+
],
|
|
67
|
+
auth: googleDocsAuth,
|
|
68
|
+
actions: [
|
|
69
|
+
createDocument,
|
|
70
|
+
createDocumentBasedOnTemplate,
|
|
71
|
+
readDocument,
|
|
72
|
+
findDocumentAction,
|
|
73
|
+
getDocumentPlaintext,
|
|
74
|
+
replaceAllText,
|
|
75
|
+
searchDocuments,
|
|
76
|
+
copyDocument,
|
|
77
|
+
getDocumentEndIndex,
|
|
78
|
+
insertText,
|
|
79
|
+
deleteContentRange,
|
|
80
|
+
createDocumentFromMarkdown,
|
|
81
|
+
getDocument,
|
|
82
|
+
createTextDocument,
|
|
83
|
+
createFooter,
|
|
84
|
+
createFootnote,
|
|
85
|
+
createHeader,
|
|
86
|
+
createNamedRange,
|
|
87
|
+
createParagraphBullets,
|
|
88
|
+
deleteFooter,
|
|
89
|
+
deleteHeader,
|
|
90
|
+
deleteNamedRange,
|
|
91
|
+
deleteParagraphBullets,
|
|
92
|
+
deleteTableColumn,
|
|
93
|
+
deleteTableRow,
|
|
94
|
+
insertTable,
|
|
95
|
+
insertTableColumn,
|
|
96
|
+
insertTableRow,
|
|
97
|
+
insertTextInTableCell,
|
|
98
|
+
insertImageInTableCell,
|
|
99
|
+
unmergeTableCells,
|
|
100
|
+
updateTableRowStyle,
|
|
101
|
+
insertInlineImage,
|
|
102
|
+
insertPageBreak,
|
|
103
|
+
replaceImage,
|
|
104
|
+
updateDocumentStyle,
|
|
105
|
+
exportAsPdf,
|
|
106
|
+
createAndPopulateTable,
|
|
107
|
+
replaceBodyWithMarkdown,
|
|
108
|
+
replaceSectionWithMarkdown,
|
|
109
|
+
batchUpdate,
|
|
110
|
+
createCustomApiCallAction({
|
|
111
|
+
baseUrl: () => 'https://docs.googleapis.com/v1',
|
|
112
|
+
auth: googleDocsAuth,
|
|
113
|
+
authMapping: async (auth) => ({
|
|
114
|
+
Authorization: `Bearer ${await getAccessToken(auth as GoogleDocsAuthValue)}`,
|
|
115
|
+
}),
|
|
116
|
+
}),
|
|
117
|
+
appendText,
|
|
118
|
+
],
|
|
119
|
+
triggers: [newDocumentTrigger],
|
|
120
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { docsCommon } from '../common';
|
|
2
|
+
import { googleDocsAuth, getAccessToken } from '../auth';
|
|
3
|
+
import { Property, createAction } from "@agnocon/pieces-framework";
|
|
4
|
+
import { appendTextActionOutputSchema } from '../output-schemas';
|
|
5
|
+
|
|
6
|
+
export const appendText = createAction({
|
|
7
|
+
auth: googleDocsAuth,
|
|
8
|
+
name: 'append_text',
|
|
9
|
+
description: 'Appends text to google docs',
|
|
10
|
+
audience: 'human',
|
|
11
|
+
aiMetadata: {
|
|
12
|
+
description:
|
|
13
|
+
'Appends text to the end of an existing Google Docs document identified by its ID. Use when an agent needs to add content to a known document without altering its existing text. Requires the document ID; not idempotent, since each call inserts the text again, accumulating duplicates.',
|
|
14
|
+
idempotent: false,
|
|
15
|
+
},
|
|
16
|
+
displayName: 'Append text to google docs',
|
|
17
|
+
props: {
|
|
18
|
+
text: Property.LongText({
|
|
19
|
+
displayName: 'Text to append',
|
|
20
|
+
description: 'The text to append to the document',
|
|
21
|
+
required: true,
|
|
22
|
+
}),
|
|
23
|
+
documentId: Property.ShortText({
|
|
24
|
+
displayName: 'Document ID',
|
|
25
|
+
description: 'The ID of the document to append text to',
|
|
26
|
+
required: true,
|
|
27
|
+
})
|
|
28
|
+
},
|
|
29
|
+
outputSchema: appendTextActionOutputSchema,
|
|
30
|
+
async run(context) {
|
|
31
|
+
return await docsCommon.writeToDocument(
|
|
32
|
+
context.propsValue.documentId,
|
|
33
|
+
context.propsValue.text,
|
|
34
|
+
await getAccessToken(context.auth)
|
|
35
|
+
);
|
|
36
|
+
},
|
|
37
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { googleDocsAuth, createGoogleClient } from '../auth';
|
|
2
|
+
import { docsCommon } from '../common';
|
|
3
|
+
import { Property, createAction } from '@agnocon/pieces-framework';
|
|
4
|
+
import { docs as googleDocs, docs_v1 } from '@googleapis/docs';
|
|
5
|
+
import { batchUpdateActionOutputSchema } from '../output-schemas';
|
|
6
|
+
|
|
7
|
+
export const batchUpdate = createAction({
|
|
8
|
+
auth: googleDocsAuth,
|
|
9
|
+
name: 'batch_update',
|
|
10
|
+
displayName: 'Batch Update (Advanced)',
|
|
11
|
+
description: 'Send a raw Google Docs batchUpdate requests array to a document',
|
|
12
|
+
audience: 'ai',
|
|
13
|
+
aiMetadata: {
|
|
14
|
+
description:
|
|
15
|
+
'Advanced escape hatch that sends a raw array of Google Docs API batchUpdate request objects directly to documents.batchUpdate. Only for callers who know the Google Docs API and need a request kind not covered by a dedicated atomic — prefer the specific atomics (Insert Text, Create Header, Insert Table, Delete Content Range, etc.) for common operations, as they validate inputs and resolve indices for you. Each request is a Docs API Request object, e.g. {"insertText":{"text":"hi","location":{"index":1}}}; requests run in order and indices must already account for prior edits in the same call. Not idempotent in general (depends on the requests supplied).',
|
|
16
|
+
idempotent: false,
|
|
17
|
+
},
|
|
18
|
+
outputSchema: batchUpdateActionOutputSchema,
|
|
19
|
+
props: {
|
|
20
|
+
documentId: Property.ShortText({
|
|
21
|
+
displayName: 'Document ID',
|
|
22
|
+
description: 'The ID of the document to update.',
|
|
23
|
+
required: true,
|
|
24
|
+
}),
|
|
25
|
+
requests: Property.Json({
|
|
26
|
+
displayName: 'Requests',
|
|
27
|
+
description:
|
|
28
|
+
'An array of raw Google Docs batchUpdate request objects, e.g. [{"insertText":{"text":"hi","location":{"index":1}}}]. See the Google Docs API documents.batchUpdate reference for the available request kinds.',
|
|
29
|
+
required: true,
|
|
30
|
+
}),
|
|
31
|
+
},
|
|
32
|
+
async run(context) {
|
|
33
|
+
const { documentId, requests } = context.propsValue;
|
|
34
|
+
|
|
35
|
+
if (!Array.isArray(requests)) {
|
|
36
|
+
throw new Error('Requests must be an array of Google Docs batchUpdate request objects.');
|
|
37
|
+
}
|
|
38
|
+
const docsRequests = requests as docs_v1.Schema$Request[];
|
|
39
|
+
|
|
40
|
+
const authClient = await createGoogleClient(context.auth);
|
|
41
|
+
const docs = googleDocs({ version: 'v1', auth: authClient });
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const response = await docs.documents.batchUpdate({
|
|
45
|
+
documentId,
|
|
46
|
+
requestBody: { requests: docsRequests },
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
success: true,
|
|
50
|
+
documentId,
|
|
51
|
+
appliedRequests: docsRequests.length,
|
|
52
|
+
replies: response.data.replies ?? [],
|
|
53
|
+
};
|
|
54
|
+
} catch (error) {
|
|
55
|
+
throw new Error(docsCommon.formatError(error, 'apply a batch update to'));
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { googleDocsAuth, createGoogleClient } from '../auth';
|
|
2
|
+
import { Property, createAction } from '@agnocon/pieces-framework';
|
|
3
|
+
import { drive as googleDrive } from '@googleapis/drive';
|
|
4
|
+
import { folderIdProp } from '../common/props';
|
|
5
|
+
import { copyDocumentActionOutputSchema } from '../output-schemas';
|
|
6
|
+
|
|
7
|
+
export const copyDocument = createAction({
|
|
8
|
+
auth: googleDocsAuth,
|
|
9
|
+
name: 'copy_document',
|
|
10
|
+
displayName: 'Copy Document',
|
|
11
|
+
description: 'Create a copy of an existing Google Docs document.',
|
|
12
|
+
audience: 'ai',
|
|
13
|
+
aiMetadata: {
|
|
14
|
+
description:
|
|
15
|
+
'Duplicates an existing Google Docs document into a new file with the given title. Pick this to spin a working copy off a template or snapshot a version before editing; it is distinct from Edit Template File, which merges data in place. Each call creates a new file, so it is not idempotent (retries produce duplicates).',
|
|
16
|
+
idempotent: false,
|
|
17
|
+
},
|
|
18
|
+
outputSchema: copyDocumentActionOutputSchema,
|
|
19
|
+
props: {
|
|
20
|
+
fileId: Property.ShortText({
|
|
21
|
+
displayName: 'Source Document ID',
|
|
22
|
+
description:
|
|
23
|
+
"The ID of the document to copy, found in its URL: 'https://docs.google.com/document/d/<documentId>/edit'.",
|
|
24
|
+
required: true,
|
|
25
|
+
}),
|
|
26
|
+
title: Property.ShortText({
|
|
27
|
+
displayName: 'New Document Title',
|
|
28
|
+
description: 'The name to give the copied document.',
|
|
29
|
+
required: true,
|
|
30
|
+
}),
|
|
31
|
+
// Destination folder maps directly to the native Drive files.copy
|
|
32
|
+
// endpoint (the requestBody.parents field), letting the copy be placed in
|
|
33
|
+
// a chosen folder instead of defaulting to the source document's location.
|
|
34
|
+
parents: folderIdProp,
|
|
35
|
+
},
|
|
36
|
+
async run(context) {
|
|
37
|
+
const { fileId, title, parents } = context.propsValue;
|
|
38
|
+
|
|
39
|
+
const authClient = await createGoogleClient(context.auth);
|
|
40
|
+
const drive = googleDrive({ version: 'v3', auth: authClient });
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
const response = await drive.files.copy({
|
|
44
|
+
fileId,
|
|
45
|
+
supportsAllDrives: true,
|
|
46
|
+
fields: 'id, name, webViewLink, parents',
|
|
47
|
+
requestBody: {
|
|
48
|
+
name: title,
|
|
49
|
+
...(parents ? { parents: [parents] } : {}),
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
id: response.data.id ?? '',
|
|
55
|
+
name: response.data.name ?? '',
|
|
56
|
+
webViewLink: response.data.webViewLink ?? '',
|
|
57
|
+
parents: response.data.parents ?? [],
|
|
58
|
+
};
|
|
59
|
+
} catch (e) {
|
|
60
|
+
const error = e as { code?: number; message?: string };
|
|
61
|
+
if (error.code === 403) {
|
|
62
|
+
throw new Error(
|
|
63
|
+
'Permission denied copying the document. Ensure the connected account has access to the source document and the destination folder.'
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
if (error.code === 404) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
`Source document not found for ID '${fileId}'. Verify the document ID.`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
throw e;
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
});
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { googleDocsAuth, createGoogleClient } from '../auth';
|
|
2
|
+
import { docsCommon } from '../common';
|
|
3
|
+
import { Property, createAction } from '@agnocon/pieces-framework';
|
|
4
|
+
import { docs as googleDocs, docs_v1 } from '@googleapis/docs';
|
|
5
|
+
import { createAndPopulateTableActionOutputSchema } from '../output-schemas';
|
|
6
|
+
|
|
7
|
+
export const createAndPopulateTable = createAction({
|
|
8
|
+
auth: googleDocsAuth,
|
|
9
|
+
name: 'create_and_populate_table',
|
|
10
|
+
displayName: 'Create and Populate Table',
|
|
11
|
+
description: 'Insert a table into a Google Docs document and fill its cells with text',
|
|
12
|
+
audience: 'ai',
|
|
13
|
+
aiMetadata: {
|
|
14
|
+
description:
|
|
15
|
+
'Inserts a new table at the end of a Google Docs document, sized to the supplied 2D array of strings, and writes each value into its cell in one operation — so an agent can drop a fully-populated table without computing cell indices. The column count is the width of the widest row; shorter rows leave their trailing cells empty. Not idempotent: each call adds another table.',
|
|
16
|
+
idempotent: false,
|
|
17
|
+
},
|
|
18
|
+
outputSchema: createAndPopulateTableActionOutputSchema,
|
|
19
|
+
props: {
|
|
20
|
+
documentId: Property.ShortText({
|
|
21
|
+
displayName: 'Document ID',
|
|
22
|
+
description: 'The ID of the document to insert the table into.',
|
|
23
|
+
required: true,
|
|
24
|
+
}),
|
|
25
|
+
data: Property.Json({
|
|
26
|
+
displayName: 'Table Data',
|
|
27
|
+
description:
|
|
28
|
+
'A 2D array of strings (rows of columns), e.g. [["Name","Age"],["Alice","30"]]. Each string is written into its matching cell. The table width is the widest row; shorter rows leave trailing cells empty.',
|
|
29
|
+
required: true,
|
|
30
|
+
}),
|
|
31
|
+
},
|
|
32
|
+
async run(context) {
|
|
33
|
+
const { documentId, data } = context.propsValue;
|
|
34
|
+
|
|
35
|
+
const rowsData = data as unknown;
|
|
36
|
+
if (!Array.isArray(rowsData) || rowsData.length === 0 || !rowsData.every((row) => Array.isArray(row))) {
|
|
37
|
+
throw new Error('Table Data must be a non-empty 2D array of strings (rows of columns).');
|
|
38
|
+
}
|
|
39
|
+
const tableData = rowsData as string[][];
|
|
40
|
+
const rows = tableData.length;
|
|
41
|
+
const columns = Math.max(...tableData.map((row) => row.length));
|
|
42
|
+
if (columns === 0) {
|
|
43
|
+
throw new Error('Table Data rows must contain at least one column.');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const authClient = await createGoogleClient(context.auth);
|
|
47
|
+
const docs = googleDocs({ version: 'v1', auth: authClient });
|
|
48
|
+
|
|
49
|
+
// Append at the end of the body so the new table is unambiguously the last
|
|
50
|
+
// one in the document when we read back to resolve its cell indices.
|
|
51
|
+
const insertTableRequest: docs_v1.Schema$Request = {
|
|
52
|
+
insertTable: { rows, columns, endOfSegmentLocation: {} },
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
await docs.documents.batchUpdate({
|
|
57
|
+
documentId,
|
|
58
|
+
requestBody: { requests: [insertTableRequest] },
|
|
59
|
+
});
|
|
60
|
+
} catch (error) {
|
|
61
|
+
throw new Error(docsCommon.formatError(error, 'insert a table into'));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let reloaded: docs_v1.Schema$Document;
|
|
65
|
+
try {
|
|
66
|
+
const response = await docs.documents.get({ documentId });
|
|
67
|
+
reloaded = response.data;
|
|
68
|
+
} catch (error) {
|
|
69
|
+
throw new Error(docsCommon.formatError(error, 'read back the new table in'));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const content = reloaded.body?.content ?? [];
|
|
73
|
+
const tableElement = findLastTable(content);
|
|
74
|
+
if (!tableElement?.table) {
|
|
75
|
+
throw new Error('Could not locate the inserted table when reading the document back.');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const cellInserts: docs_v1.Schema$Request[] = [];
|
|
79
|
+
const tableRows = tableElement.table.tableRows ?? [];
|
|
80
|
+
for (let r = 0; r < tableRows.length; r++) {
|
|
81
|
+
const cells = tableRows[r].tableCells ?? [];
|
|
82
|
+
for (let c = 0; c < cells.length; c++) {
|
|
83
|
+
const value = tableData[r]?.[c];
|
|
84
|
+
if (value === undefined || value === null || value === '') {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const cellContent = cells[c].content ?? [];
|
|
88
|
+
const firstParagraph = cellContent[0];
|
|
89
|
+
const insertIndex = firstParagraph?.startIndex;
|
|
90
|
+
if (insertIndex === undefined || insertIndex === null) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
cellInserts.push({ insertText: { text: String(value), location: { index: insertIndex } } });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Apply highest-index inserts first so earlier (lower) indices stay valid as
|
|
98
|
+
// text shifts the document; each insert below an applied one is unaffected.
|
|
99
|
+
cellInserts.sort((a, b) => (b.insertText?.location?.index ?? 0) - (a.insertText?.location?.index ?? 0));
|
|
100
|
+
|
|
101
|
+
if (cellInserts.length > 0) {
|
|
102
|
+
try {
|
|
103
|
+
await docs.documents.batchUpdate({
|
|
104
|
+
documentId,
|
|
105
|
+
requestBody: {
|
|
106
|
+
requests: cellInserts,
|
|
107
|
+
// Fail loudly instead of misplacing text if the document changed
|
|
108
|
+
// between the read-back above and this write.
|
|
109
|
+
writeControl: reloaded.revisionId
|
|
110
|
+
? { requiredRevisionId: reloaded.revisionId }
|
|
111
|
+
: undefined,
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
} catch (error) {
|
|
115
|
+
throw new Error(docsCommon.formatError(error, 'populate the new table in'));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
success: true,
|
|
121
|
+
documentId,
|
|
122
|
+
rows,
|
|
123
|
+
columns,
|
|
124
|
+
cellsPopulated: cellInserts.length,
|
|
125
|
+
};
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// The table appended at end-of-body has the greatest startIndex, so the last
|
|
130
|
+
// table element in document order is unambiguously the one just inserted.
|
|
131
|
+
function findLastTable(
|
|
132
|
+
content: docs_v1.Schema$StructuralElement[]
|
|
133
|
+
): docs_v1.Schema$StructuralElement | undefined {
|
|
134
|
+
let match: docs_v1.Schema$StructuralElement | undefined;
|
|
135
|
+
for (const element of content) {
|
|
136
|
+
if (element.table) {
|
|
137
|
+
match = element;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return match;
|
|
141
|
+
}
|