Skip to content

Add Google Sheets integration with OAuth and Apps Script support#94

Merged
davidrojasliblab merged 35 commits intodevfrom
dr/ENG-769
Sep 5, 2025
Merged

Add Google Sheets integration with OAuth and Apps Script support#94
davidrojasliblab merged 35 commits intodevfrom
dr/ENG-769

Conversation

@davidrojasliblab
Copy link
Copy Markdown
Contributor

Implements comprehensive Google Sheets integration with multiple authentication methods, full CRUD operations, and production-ready error handling. Supports OAuth 2.0, Apps Script Web Apps, and public sheet access with
automatic schema detection and row mapping system.

🔗 Related Issues

  • Fixes #ENG-769

📝 Changes Made

  • Added GoogleSheetsAccessor: Complete data access layer supporting all Google Sheets operations (read, write, update, delete)
  • Implemented OAuth 2.0 integration: Full Google Workspace authentication with token refresh and management
  • Created Apps Script Web App support: No-API-key solution for full read/write access to private sheets
  • Built row mapping system: Track relationships between app records and sheet rows for reliable updates/deletes
  • Added React components: GoogleWorkspaceConnector, GoogleDocumentPicker, GoogleSpreadsheetPicker for seamless setup
  • Implemented API endpoints: Complete authentication flow and sheet operation endpoints
  • Added schema auto-detection: Automatically infer column types, detect currency/dates, and generate table structure
  • Created comprehensive documentation: Setup guides, examples, and troubleshooting documentation
  • Production hardening: Removed all debug code, fixed lint issues, comprehensive error handling

Testing Details:

  • Tested OAuth authentication flow with Google account integration
  • Verified Apps Script Web App functionality with sample spreadsheet
  • Tested all CRUD operations (create, read, update, delete rows)
  • Validated public sheet read-only access
  • Tested row mapping system for record tracking and updates
  • Verified error handling for invalid inputs and network failures
  • Tested connection setup flow for all three authentication methods
  • Confirmed schema detection works with various spreadsheet formats

📋 Additional Notes

Key Implementation Highlights:

  • Three-tier authentication: OAuth (full API), Apps Script (no API key), Public (read-only)
  • Universal compatibility: Works with any Google Sheet structure without predefined schemas
  • 5-minute setup: Apps Script method allows non-technical users to set up full read/write access

Files Added:

  • Core: shared/src/data-access/accessors/google-sheets.ts
  • Auth: shared/src/data-access/accessors/google-workspace/auth-manager.ts
  • UI: app/components/google-workspace/
  • APIs: app/api/auth/google-workspace/, app/api/sheet-data/, app/api/sheets-rows/

@davidrojasliblab davidrojasliblab self-assigned this Aug 26, 2025
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @davidrojasliblab, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a comprehensive integration for Google Sheets, supporting multiple authentication methods including OAuth 2.0, Apps Script Web Apps, and public sheet access. It enables full CRUD operations, automatic schema detection, and a robust row mapping system, significantly enhancing data interaction capabilities.

Highlights

  • Comprehensive Google Sheets Integration: Adds full Create, Read, Update, Delete (CRUD) operations for Google Sheets.
  • Multiple Authentication Methods: Supports OAuth 2.0 for full Google Workspace authentication with token refresh, Apps Script Web Apps for keyless read/write access to private sheets, and public sheet read-only access.
  • Automatic Schema Detection: Infers column types, detects currency/dates, and generates table structures automatically.
  • Row Mapping System: Implements a system to track relationships between application records and sheet rows for reliable updates and deletes.
  • New UI Components: Introduces GoogleWorkspaceConnector, GoogleDocumentPicker, and GoogleSpreadsheetPicker for seamless setup and document selection.
  • Dedicated API Endpoints: Adds new backend API routes for Google Workspace authentication flows and sheet operations.
  • Production Hardening: Includes comprehensive error handling and removal of debug code.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive Google Sheets and Google Docs integration, which is a significant and well-executed feature. The implementation includes multiple authentication methods (OAuth 2.0, Apps Script), full CRUD operations, and a row-mapping system for reliable updates. The code is generally well-structured, with a good separation of concerns between API clients, services, and authentication management. However, there are several critical issues related to security, configuration, and production-readiness that must be addressed. Specifically, the use of in-memory storage for row mappings is not suitable for a serverless environment, the handling of environment variables for secrets needs to be more robust across all new API routes, and there's a potential XSS vulnerability in the OAuth callback. I've left detailed comments on these points and others.

Comment thread app/api/sheets-rows/route.ts Outdated
Comment thread shared/src/data-access/accessors/google-workspace/auth-manager.ts Outdated
Comment thread app/api/auth/google-workspace/authorize/route.ts
Comment thread app/api/auth/google-workspace/callback/route.ts Outdated
Comment thread app/api/users/[id]/route.ts Outdated
Comment thread app/api/auth/google-workspace/config/route.ts Outdated
Comment thread app/api/auth/google-workspace/status/route.ts Outdated
Comment thread app/components/@settings/tabs/data/forms/AddDataSourceForm.tsx Outdated
Comment thread app/data-source-connection/page.tsx Outdated
@davidrojasliblab davidrojasliblab changed the base branch from main to develop August 27, 2025 14:48
@kapicic kapicic changed the base branch from develop to dev August 29, 2025 14:27
Comment thread app/api/auth/google-workspace/authorize/route.ts Outdated
Comment thread app/api/auth/google-workspace/authorize/route.ts Outdated
Comment thread app/api/auth/google-workspace/callback/route.ts Outdated
Comment thread app/data-source-connection/page.tsx Outdated
Comment thread app/data-source-connection/page.tsx Outdated
Comment thread app/lib/schema.ts Outdated
Comment thread app/lib/schema.ts Outdated
Comment thread scripts/utils/google-sheets-apps-script.js Outdated
davidrojasliblab and others added 4 commits August 29, 2025 10:28
- Resolved conflicts by keeping dev branch changes
- Updated schema.ts to include both environmentId and forceRefresh parameters
- Removed deleted files (format-query route, datasourceService)
- Merged environment support and other dev branch features
error: Error | null;
}

class CallStackErrorBoundary extends Component<Props, State> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this component used for in our case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question, while I was working I found that most of the errors show a default message without valuable information. I added this component with easy to read and friendly messages and can guide the users and us to understand where the issue is happening. In Google sheets due to the variable data sizes I found a lot of let's call them "stack overflows" and this component was extremely useful to get the component in the AI side where it was happening.

Comment thread starters/remix-starter/app/hooks/useChunkedData.ts Outdated
Comment thread starters/next-starter/app/components/hoc/WithErrorHandling.tsx Outdated
Comment thread starters/next-starter/app/components/hoc/WithErrorHandling.tsx Outdated
Comment thread starters/next-starter/app/db/execute-query.direct.ts Outdated
Comment thread app/api/auth/google-workspace/config/route.ts Outdated
Comment thread app/api/users/[id]/route.ts Outdated
Comment thread app/api/auth/google-workspace/callback/route.ts
Comment thread app/api/auth/google-workspace/config/route.ts
Comment thread app/api/clear-schema-cache/route.ts Outdated
Comment thread app/components/google-workspace/GoogleSpreadsheetPicker.tsx Outdated
Comment thread shared/src/data-access/accessors/google-workspace/auth-manager.ts Outdated
davidrojasliblab and others added 3 commits September 4, 2025 11:21
- Fixed execute-query route to include both Zod validation and logging
- Resolved dataSourceService.ts conflicts by using dev version
- Fixed TypeScript errors from API signature changes
- Updated function calls to match new service signatures
- All review improvements maintained including:
  - Zod validation across API routes
  - Proper OAuth HTML templates
  - Consistent response formats
  - Environment variable usage
@davidrojasliblab davidrojasliblab merged commit 1d6f949 into dev Sep 5, 2025
4 checks passed
@davidrojasliblab davidrojasliblab deleted the dr/ENG-769 branch September 5, 2025 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants