Workspace Email And Drive Sync
CaseSolo supports a live Workspace sync runtime for Google Workspace and Microsoft 365. The implementation is user-scoped and stores OAuth tokens plus incremental cursors in user metadata.
Storage
- Google Workspace config:
user.metadata.googleWorkspace - Microsoft 365 config:
user.metadata.microsoft365Workspace - OAuth state keys:
googleWorkspaceOAuthStateandmicrosoft365WorkspaceOAuthState
The API never returns stored tokens.
Provider Coverage
Google Workspace:
- OAuth scopes: Gmail read-only and Drive read-only.
- Gmail sync uses message list or history deltas, then fetches metadata headers.
- Drive sync uses an initial file snapshot plus
changes/startPageToken, then Drive changes for later runs.
Microsoft 365:
- OAuth scopes:
offline_access,User.Read,Mail.Read, andFiles.Read.All. - Mail sync uses Microsoft Graph message delta queries.
- Drive sync uses Microsoft Graph drive root delta.
Both providers normalize synced emails/documents into case hints and can write Activity rows when a caseId is supplied to the sync action.
API
GET /api/integrations/workspace-sync returns secret-safe provider status and readiness.
POST /api/integrations/workspace-sync supports:
google_authorizemicrosoft_authorizeupdate_google_optionsupdate_microsoft_optionssync_google_workspacesync_microsoft_365sync_alldisconnect_google_workspacedisconnect_microsoft_365
OAuth callbacks:
/api/integrations/google-workspace/callback/api/integrations/microsoft-365/callback
Provider References
- Gmail history sync: https://developers.google.com/workspace/gmail/api/guides/sync
- Gmail push notifications: https://developers.google.com/workspace/gmail/api/guides/push
- Drive changes: https://developers.google.com/drive/api/guides/manage-changes
- Microsoft Graph mail delta: https://learn.microsoft.com/graph/delta-query-messages
- Microsoft Graph change notifications: https://learn.microsoft.com/graph/change-notifications-overview
- Microsoft Graph drive delta: https://learn.microsoft.com/graph/api/driveitem-delta
Verification
npm run test:run -- workspace-sync
npx eslint src/lib/integrations/workspace-sync.ts src/app/api/integrations/workspace-sync/route.ts src/app/api/integrations/google-workspace/callback/route.ts src/app/api/integrations/microsoft-365/callback/route.ts src/__tests__/lib/workspace-sync.test.ts src/__tests__/api/workspace-sync.test.ts
npm run typecheck