/** * Google OAuth configuration parsing from CLI arguments and environment variables. * * This module provides utilities to parse Google OAuth configuration from * CLI arguments and environment variables, following the same pattern as @mcp-z/server's * parseConfig(). */ import type { DcrConfig, OAuthConfig } from '../types.js'; export type { DcrConfig, OAuthConfig }; /** * Transport type for MCP servers * * @typedef {('stdio' | 'http')} TransportType * @property {'stdio'} stdio - Standard input/output transport for CLI applications * @property {'http'} http - HTTP transport for web-based applications */ export type TransportType = 'stdio' | 'http'; /** * Parse Google OAuth configuration from CLI arguments and environment variables. * * CLI Arguments: * - --auth: Auth mode ('loopback-oauth' | 'service-account' | 'dcr') * - Default: 'loopback-oauth' (if flag is omitted) * - --headless: Disable browser opening for OAuth flow (default: false, true in test env) * - --redirect-uri: Override OAuth redirect URI (default: ephemeral loopback) * - --service-account-key-file: Service account key file path (required for service-account mode) * * Required environment variables: * - GOOGLE_CLIENT_ID: OAuth 2.0 client ID from Google Cloud Console * * Optional environment variables: * - GOOGLE_CLIENT_SECRET: OAuth 2.0 client secret (optional for public clients) * - AUTH_MODE: Auth mode (same format as --auth flag) * - HEADLESS: Headless mode flag ('true' to enable) * - REDIRECT_URI: OAuth redirect URI (overridden by --redirect-uri CLI flag) * - GOOGLE_SERVICE_ACCOUNT_KEY_FILE: Service account key file (for service-account mode) * * @param args - CLI arguments array (typically process.argv) * @param env - Environment variables object (typically process.env) * @param transport - Optional transport type. If 'stdio' and auth mode is 'dcr', throws an error. * See {@link TransportType} for valid values. * @returns Parsed Google OAuth configuration * @throws Error if required environment variables are missing, values are invalid, or DCR is used with stdio transport * * @example Default mode (no flags) * ```typescript * const config = parseConfig(process.argv, process.env); * // { auth: 'loopback-oauth' } * ``` * * @example Override auth mode * ```typescript * parseConfig(['--auth=loopback-oauth'], process.env); * parseConfig(['--auth=service-account'], process.env); * parseConfig(['--auth=dcr'], process.env); * ``` * * @example With transport validation * ```typescript * parseConfig(['--auth=dcr'], process.env, 'http'); // OK * parseConfig(['--auth=dcr'], process.env, 'stdio'); // Throws error * ``` * * Valid auth modes: * - loopback-oauth (default) * - service-account * - dcr (HTTP transport only) */ export declare function parseConfig(args: string[], env: Record, transport?: TransportType): OAuthConfig; /** * Build production configuration from process globals. * Entry point for production server. */ export declare function createConfig(): OAuthConfig; /** * Parse DCR configuration from CLI arguments and environment variables. * * CLI Arguments: * - --dcr-mode: DCR mode ('self-hosted' | 'external') * - Default: 'self-hosted' (if flag is omitted) * - --dcr-verify-url: External verification endpoint URL (required for external mode) * - --dcr-store-uri: DCR client storage URI (required for self-hosted mode) * * Required environment variables: * - GOOGLE_CLIENT_ID: OAuth 2.0 client ID from Google Cloud Console * * Optional environment variables: * - GOOGLE_CLIENT_SECRET: OAuth 2.0 client secret (optional for public clients) * - DCR_MODE: DCR mode (same format as --dcr-mode flag) * - DCR_VERIFY_URL: External verification URL (same as --dcr-verify-url flag) * - DCR_STORE_URI: DCR storage URI (same as --dcr-store-uri flag) * * @param args - CLI arguments array (typically process.argv) * @param env - Environment variables object (typically process.env) * @param scope - OAuth scopes to request (space-separated) * @returns Parsed DCR configuration * @throws Error if required environment variables are missing or validation fails * * @example Self-hosted mode * ```typescript * const config = parseDcrConfig( * ['--dcr-mode=self-hosted', '--dcr-store-uri=file:///path/to/store.json'], * process.env, * 'https://www.googleapis.com/auth/drive.readonly' * ); * ``` * * @example External mode * ```typescript * const config = parseDcrConfig( * ['--dcr-mode=external', '--dcr-verify-url=https://auth0.example.com/verify'], * process.env, * 'https://www.googleapis.com/auth/drive.readonly' * ); * ``` */ export declare function parseDcrConfig(args: string[], env: Record, scope: string): DcrConfig;