@openworkspace/docs
v0.1.1
Published
Google Docs API client for documents and content
Maintainers
Readme
@openworkspace/docs
Google Docs API client for OpenWorkspace -- get, create, batch update, export.
Part of the OpenWorkspace monorepo.
Install
npm install @openworkspace/docs @openworkspace/coreUsage
import { createHttpClient } from '@openworkspace/core';
import { getDocument, createDocument, insertText, replaceAllText, exportDocument } from '@openworkspace/docs';
const http = createHttpClient({ auth: { accessToken: 'token' } });
// Get a document
const result = await getDocument(http, 'docId123');
if (result.ok) {
console.log(result.value.title);
}
// Create a document
const doc = await createDocument(http, 'Meeting Notes');
// Insert text
await insertText(http, 'docId123', { text: 'Hello, World!', index: 1 });
// Find and replace
await replaceAllText(http, 'docId123', { find: '{{name}}', replaceWith: 'Alice' });
// Export as PDF
const pdf = await exportDocument(http, 'docId123', 'application/pdf');API
All functions take an HttpClient as the first parameter and return Result<T, E>.
getDocument(http, id)-- Get document content and metadatacreateDocument(http, title)-- Create a new documentcopyDocument(http, id)-- Copy a documentgetDocumentTabs(http, id)-- Get document tabsreadText(http, id)-- Read document as plain textbatchUpdate(http, id, requests)-- Send batch update requestsinsertText(http, id, params)-- Insert text at an indexdeleteContent(http, id, range)-- Delete a content rangereplaceAllText(http, id, params)-- Find and replace textexportDocument(http, id, format)-- Export as PDF, DOCX, etc.
