diff --git a/CONFIG.md b/CONFIG.md new file mode 100644 index 0000000..6457cf1 --- /dev/null +++ b/CONFIG.md @@ -0,0 +1,225 @@ +# Configuration Management + +This document explains how to use the configuration management system in Commad. + +## Overview + +The configuration system provides: +- Global configuration store using React Context +- Persistent storage in localStorage +- Browser console tools for easy configuration management +- Validation for configuration values +- Real-time updates across the application + +## Available Configuration Options + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| `couchdbUrl` | string | `/db` | URL for CouchDB server (use `/db` for Vite proxy) | +| `couchdbUsername` | string | `""` | CouchDB username (optional) | +| `couchdbPassword` | string | `""` | CouchDB password (optional) | +| `syncEnabled` | boolean | `false` | Enable/disable synchronization | +| `syncInterval` | number | `30000` | Sync interval in milliseconds | +| `appName` | string | `commad` | Application name | +| `theme` | string | `light` | UI theme preference | + +## Using Console Tools + +The configuration can be managed through the browser console using the `commad` global object. + +### Configuration Commands + +```javascript +// Show help +commad.help() +commad.config.help() + +// Quick setup (recommended for 401 errors) +commad.config.setup("http://localhost:5984", "username", "password") + +// Manual configuration +// Set CouchDB URL with validation +commad.config.setCouchDB('/db') // Use Vite proxy (recommended) +// OR +commad.config.setCouchDB('http://localhost:5984') // Direct connection +commad.config.setAuth('username', 'password') + +// View current configuration +commad.config.getAll() + +// Get a specific config value +commad.config.get('couchdbUrl') + +// Set a configuration value +commad.config.set('syncEnabled', true) + +// Clear authentication +commad.config.clearAuth() +``` + +### Sync Management Commands + +```javascript +// Show sync help +commad.sync.help() + +// Check sync status +commad.sync.status() +commad.sync.info() + +// Manual sync operations +commad.sync.force() // Force a full sync +commad.sync.push() // Push local changes to remote +commad.sync.pull() // Pull changes from remote + +// Connection management +commad.sync.start() // Start continuous sync +commad.sync.stop() // Stop sync +commad.sync.reconnect() // Reconnect to remote + +// Conflict resolution +commad.sync.conflicts() // List documents with conflicts +commad.sync.resolve(docId, winningRev, losingRevs) // Resolve conflict +``` + +### Advanced Commands + +```javascript +// Export configuration as JSON +commad.config.export() + +// Import configuration from JSON +commad.config.import('{"couchdbUrl": "http://example.com:5984", "syncEnabled": true}') + +// Reset to default configuration +commad.config.reset() + +// Test CouchDB connection +commad.utils.testCouchDB() + +// Clear all application data +commad.utils.clearData() +``` + +## Using in React Components + +```jsx +import { useConfig } from '../contexts/ConfigContext'; + +function MyComponent() { + const { config, setConfig, setCouchDBUrl } = useConfig(); + + // Access config values + const couchdbUrl = config.couchdbUrl; + + // Update configuration + const handleUrlChange = (url) => { + setCouchDBUrl(url); + }; + + return ( +
Current CouchDB URL: {couchdbUrl}
+ +đĄ Use browser console commands to modify configuration:
+commad.config.setCouchDB("http://your-couchdb-url:5984")
+
+ Use console tools to resolve conflicts: commad.sync.conflicts()
+