Skip to content

Conversation

@ReeseAstor
Copy link
Owner

@ReeseAstor ReeseAstor commented Sep 28, 2025

Integrate Supabase, Notion, and Google Drive to add real-time database sync, collaborative documentation, and cloud file storage capabilities.

This PR introduces:

  • Supabase Integration: Real-time database sync for companies and novels.
  • Notion Integration: Sync credit memos and novel projects to Notion databases.
  • Google Drive Integration: Create Google Docs for chapters and financial spreadsheets, with OAuth authentication.
  • Frontend UI: New "Integrations" tab with status indicators and sync controls.
  • Backend Endpoints: API routes for authentication and syncing data to each service.
  • Setup Script: npm run setup for easy configuration.

Open in Cursor Open in Web


Note

Adds Supabase, Notion, and Google Drive integrations with new UI tab, backend services/endpoints, env/setup, and dependency updates.

  • Frontend:
    • Integrations Tab: New public/index.html section with status indicators and sync controls; corresponding logic in public/script.js to auth/sync with services and manage auto-sync; styles added in public/styles.css.
  • Backend:
    • Services: New services/supabase.js, services/notion.js, services/googleDrive.js clients and helpers (OAuth for Google, Notion page creation, Supabase CRUD/realtime helpers).
    • API Endpoints: Added routes in server.js for Supabase sync (/api/sync/supabase/*), Notion sync (/api/sync/notion/*), Google auth/callback and Drive ops (/api/drive/*), and a combined sync endpoint (/api/sync/all); enabled CORS and dotenv.
    • Startup: Loads Google tokens on boot; logs integration availability.
  • Tooling/Config:
    • Setup: New setup.js and npm run setup to generate .env.
    • Environment: Added .env.example; expanded .gitignore.
    • Docs: README overhauled with cloud integration setup/use, new endpoints, and project structure.
    • Dependencies: Added Supabase, Notion, Google APIs, auth, cron, axios, CORS, dotenv, JWT, etc., in package.json/lock.

Written by Cursor Bugbot for commit 2ebf3c7. This will update automatically on new commits. Configure here.

Co-authored-by: info <info@reeseastor.com>
@cursor
Copy link

cursor bot commented Sep 28, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

cursor[bot]

This comment was marked as outdated.

@ReeseAstor ReeseAstor marked this pull request as ready for review September 29, 2025 01:02
Copilot AI review requested due to automatic review settings September 29, 2025 01:02
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces comprehensive cloud integrations for the workspace application, adding real-time database sync with Supabase, collaborative documentation with Notion, and cloud file storage with Google Drive.

Key changes include:

  • Cloud Service Integration: Added Supabase, Notion, and Google Drive services with full authentication and data sync capabilities
  • Frontend Integration UI: New "Integrations" tab with status indicators, sync controls, and configuration options
  • Backend API Extensions: New endpoints for authentication, data syncing, and file management across all integrated services

Reviewed Changes

Copilot reviewed 11 out of 13 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
setup.js Interactive setup wizard for configuring cloud integrations
services/supabase.js Supabase service with database operations and real-time sync
services/notion.js Notion service for creating pages and syncing content
services/googleDrive.js Google Drive service for document and spreadsheet management
server.js Extended server with integration endpoints and middleware
public/styles.css Added CSS styling for integration status indicators and controls
public/script.js Extended frontend with integration functions and UI handling
public/index.html Added Integrations tab with status displays and sync controls
package.json Updated dependencies and added setup script
README.md Comprehensive rewrite with integration setup and usage instructions
.env.example Environment variable template for all integrations

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

{ responseType: 'stream' }
);

const dest = fs.createWriteStream(destPath);
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

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

The fs import at the top of the file imports the promises version (require('fs').promises), but this line uses the synchronous fs module. This will cause a runtime error since createWriteStream doesn't exist on the promises object. Import the regular fs module separately or use require('fs').createWriteStream(destPath).

Copilot uses AI. Check for mistakes.
Comment on lines +400 to +402
// Check Notion status (simplified check)
updateIntegrationStatus('notion', process.env.NOTION_API_KEY ? 'connected' : 'disconnected');

Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

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

Environment variables are not available in client-side JavaScript. process.env.NOTION_API_KEY will always be undefined in the browser, causing the Notion status to always show as disconnected. This check should be moved to the server-side or replaced with an API call to check the actual connection status.

Suggested change
// Check Notion status (simplified check)
updateIntegrationStatus('notion', process.env.NOTION_API_KEY ? 'connected' : 'disconnected');
// Check Notion status via API
updateIntegrationStatus('notion', 'checking');
try {
const response = await fetch('/api/sync/notion/status');
if (response.ok) {
const data = await response.json();
updateIntegrationStatus('notion', data.connected ? 'connected' : 'disconnected');
} else {
updateIntegrationStatus('notion', 'disconnected');
}
} catch {
updateIntegrationStatus('notion', 'disconnected');
}

Copilot uses AI. Check for mistakes.
}

// Create documents for novel chapters
const chaptersResponse = await fetch(`/api/novels/${currentNovelId}/chapters`);
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

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

The variable currentNovelId is referenced but not defined in the visible scope. This will cause a ReferenceError when the syncToGoogleDrive function is called. The variable should be defined or retrieved from the current application state.

Copilot uses AI. Check for mistakes.
Comment on lines +32 to +37
async createTables() {
if (!this.supabase) return;

// Note: These tables should ideally be created through Supabase dashboard
// This is just for reference of the schema
const tables = {
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

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

The createTables method defines table schemas but doesn't actually create them, making the method name misleading. Consider renaming to getTableSchemas or getSchemaReference to better reflect its purpose as a schema reference.

Copilot uses AI. Check for mistakes.

// Initialize Google Drive tokens on startup
(async () => {
await googleDriveService.loadTokens();
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

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

The immediately invoked async function expression (IIFE) for loading Google Drive tokens lacks error handling. If loadTokens() throws an error, it will be an unhandled promise rejection. Wrap the call in a try-catch block to handle potential errors gracefully.

Suggested change
await googleDriveService.loadTokens();
try {
await googleDriveService.loadTokens();
} catch (error) {
console.error('Failed to load Google Drive tokens:', error);
}

Copilot uses AI. Check for mistakes.
showSuccess('Sync settings saved!');
}

function showMessage(message, type) {
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

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

The showMessage function is duplicated - there's already an existing showMessage function in the codebase with different behavior. This creates a naming conflict and inconsistent behavior. Consider using the existing function or renaming this one to avoid confusion.

Suggested change
function showMessage(message, type) {
function displayMessage(message, type) {

Copilot uses AI. Check for mistakes.
if (settings.autoSyncNotion) syncToNotion();
if (settings.autoSyncDrive) syncToGoogleDrive();
}, intervalMinutes * 60 * 1000);
}
Copy link

Choose a reason for hiding this comment

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

Bug: Timer Overlap Causes Sync Issues

The saveSyncSettings function creates new setInterval timers without clearing previously set ones. This can lead to multiple sync operations running concurrently and potential memory leaks.

Fix in Cursor Fix in Web

data: company
})
});
}
Copy link

Choose a reason for hiding this comment

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

Bug: Company Sync Issue

The syncToSupabase function attempts to sync companies by sending type: 'company' to /api/sync/all. The server-side handler for this endpoint, however, only processes credit_memo, novel, and chapter types, meaning company data isn't synced.

Fix in Cursor Fix in Web

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Comment on lines +400 to +402
// Check Notion status (simplified check)
updateIntegrationStatus('notion', process.env.NOTION_API_KEY ? 'connected' : 'disconnected');

Choose a reason for hiding this comment

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

[P1] Don’t reference Node env vars in browser status check

checkIntegrationStatus reads process.env.NOTION_API_KEY to decide the Notion status. In the browser there is no process object, so this line throws a ReferenceError as soon as the integrations tab initializes and the rest of the status checks never run. The UI will always break unless this is replaced with a server-side check or some other client-safe flag.

Useful? React with 👍 / 👎.

Comment on lines +477 to +484
async function syncToNotion() {
showMessage('Syncing to Notion...', 'info');

try {
// Get all credit memos
const memoResponse = await fetch('/api/credit-memos');
const memos = await memoResponse.json();

Choose a reason for hiding this comment

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

[P1] Notion sync always fails because credit memo endpoint is missing

syncToNotion fetches /api/credit-memos to read existing memos before pushing to Notion, but the server defines only a POST handler for that path. The GET returns a 404 HTML page, memoResponse.json() throws, and no data is synced. Add a GET route (or use the existing POST results) so the Notion sync has data to work with.

Useful? React with 👍 / 👎.

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.

3 participants