// Service configuration - enables modular service management
// Users can enable/disable services via environment variables
export type ServiceName = 'drive' | 'docs' | 'sheets' | 'slides' | 'calendar' | 'gmail' | 'meet' | 'tasks' | 'contacts';
export interface ServiceConfig {
name: ServiceName;
displayName: string;
scopes: string[];
envVar: string;
defaultEnabled: boolean;
}
// Service definitions with their OAuth scopes
export const SERVICE_DEFINITIONS: Record<ServiceName, ServiceConfig> = {
drive: {
name: 'drive',
displayName: 'Google Drive',
scopes: [
'https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive.readonly',
],
envVar: 'GOOGLE_WORKSPACE_DRIVE',
defaultEnabled: true,
},
docs: {
name: 'docs',
displayName: 'Google Docs',
scopes: ['https://www.googleapis.com/auth/documents'],
envVar: 'GOOGLE_WORKSPACE_DOCS',
defaultEnabled: true,
},
sheets: {
name: 'sheets',
displayName: 'Google Sheets',
scopes: ['https://www.googleapis.com/auth/spreadsheets'],
envVar: 'GOOGLE_WORKSPACE_SHEETS',
defaultEnabled: true,
},
slides: {
name: 'slides',
displayName: 'Google Slides',
scopes: ['https://www.googleapis.com/auth/presentations'],
envVar: 'GOOGLE_WORKSPACE_SLIDES',
defaultEnabled: true,
},
calendar: {
name: 'calendar',
displayName: 'Google Calendar',
scopes: [
'https://www.googleapis.com/auth/calendar',
'https://www.googleapis.com/auth/calendar.events',
],
envVar: 'GOOGLE_WORKSPACE_CALENDAR',
defaultEnabled: false, // Opt-in for now
},
gmail: {
name: 'gmail',
displayName: 'Gmail',
scopes: [
'https://www.googleapis.com/auth/gmail.readonly',
'https://www.googleapis.com/auth/gmail.send',
'https://www.googleapis.com/auth/gmail.modify',
'https://www.googleapis.com/auth/gmail.settings.basic',
],
envVar: 'GOOGLE_WORKSPACE_GMAIL',
defaultEnabled: false, // Opt-in - sensitive
},
meet: {
name: 'meet',
displayName: 'Google Meet',
scopes: [
'https://www.googleapis.com/auth/meetings.space.created',
'https://www.googleapis.com/auth/meetings.space.readonly',
'https://www.googleapis.com/auth/drive.meet.readonly',
],
envVar: 'GOOGLE_WORKSPACE_MEET',
defaultEnabled: false, // Opt-in - sensitive
},
tasks: {
name: 'tasks',
displayName: 'Google Tasks',
scopes: [
'https://www.googleapis.com/auth/tasks',
],
envVar: 'GOOGLE_WORKSPACE_TASKS',
defaultEnabled: false, // Opt-in
},
contacts: {
name: 'contacts',
displayName: 'Google Contacts',
scopes: [
'https://www.googleapis.com/auth/contacts',
'https://www.googleapis.com/auth/contacts.readonly',
],
envVar: 'GOOGLE_WORKSPACE_CONTACTS',
defaultEnabled: false, // Opt-in - sensitive
},
};
// Check if a service is enabled via environment variable
function isServiceEnabled(service: ServiceConfig): boolean {
const envValue = process.env[service.envVar];
// If env var is explicitly set, use that value
if (envValue !== undefined) {
return envValue.toLowerCase() === 'true' || envValue === '1';
}
// Otherwise use default
return service.defaultEnabled;
}
// Get list of enabled services
export function getEnabledServices(): ServiceName[] {
return Object.values(SERVICE_DEFINITIONS)
.filter(isServiceEnabled)
.map(s => s.name);
}
// Get OAuth scopes for enabled services only
export function getEnabledScopes(): string[] {
const enabledServices = getEnabledServices();
const scopes = new Set<string>();
for (const serviceName of enabledServices) {
const service = SERVICE_DEFINITIONS[serviceName];
for (const scope of service.scopes) {
scopes.add(scope);
}
}
return Array.from(scopes);
}
// Get service config by name
export function getServiceConfig(name: ServiceName): ServiceConfig {
return SERVICE_DEFINITIONS[name];
}
// Check if specific service is enabled
export function isEnabled(name: ServiceName): boolean {
return getEnabledServices().includes(name);
}
// Generate help text for service configuration
export function generateServiceConfigHelp(): string {
const lines = [
'Service Configuration',
'═════════════════════',
'',
'Enable or disable services using environment variables:',
'',
];
for (const service of Object.values(SERVICE_DEFINITIONS)) {
const status = isServiceEnabled(service) ? '✅ Enabled' : '❌ Disabled';
lines.push(`${service.displayName}: ${status}`);
lines.push(` ${service.envVar}=true|false`);
lines.push('');
}
lines.push('Example:');
lines.push(' GOOGLE_WORKSPACE_CALENDAR=true npm run auth');
lines.push(' GOOGLE_WORKSPACE_GMAIL=false npm run auth');
return lines.join('\n');
}