|
| 1 | +# @ever-co/shared-environment |
| 2 | + |
| 3 | +A robust, SOLID-principles-based environment management library for Angular applications. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- 🏗️ **SOLID Principles** - Follows all five SOLID principles |
| 8 | +- 🎨 **Design Patterns** - Implements Singleton, Factory, Builder, Strategy, Adapter, Facade, Command, and Observer patterns |
| 9 | +- 🔒 **Type Safety** - Full TypeScript support with comprehensive interfaces |
| 10 | +- ✅ **Validation** - Extensible validation system with custom rules |
| 11 | +- 🔄 **Async/Sync** - Support for both asynchronous and synchronous operations |
| 12 | +- 🧪 **Testable** - Comprehensive unit tests included |
| 13 | +- 📦 **Reusable** - Can be used across multiple Angular applications |
| 14 | + |
| 15 | +## Installation |
| 16 | + |
| 17 | +```bash |
| 18 | +npm install @ever-co/shared-environment |
| 19 | +``` |
| 20 | + |
| 21 | +## Quick Start |
| 22 | + |
| 23 | +```typescript |
| 24 | +import { Environment, EnvironmentService, createEnvironmentProviders } from '@ever-co/shared-environment'; |
| 25 | + |
| 26 | +// Configure environment loading |
| 27 | +Environment.setLoadFunction(() => { |
| 28 | + // Your environment loading logic |
| 29 | + return { API_URL: 'http://localhost:3000' }; |
| 30 | +}); |
| 31 | + |
| 32 | +// Use in components |
| 33 | +@Component({ |
| 34 | + providers: [...createEnvironmentProviders()] |
| 35 | +}) |
| 36 | +export class MyComponent { |
| 37 | + constructor(private envService: EnvironmentService) {} |
| 38 | + |
| 39 | + async ngOnInit() { |
| 40 | + const apiUrl = await this.envService.get('API_URL'); |
| 41 | + console.log('API URL:', apiUrl); |
| 42 | + } |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +## Architecture |
| 47 | + |
| 48 | +The library implements multiple design patterns: |
| 49 | + |
| 50 | +- **Singleton Pattern** - Environment class ensures single instance |
| 51 | +- **Factory Pattern** - ConfigurationFactory creates configuration objects |
| 52 | +- **Builder Pattern** - ConfigurationBuilder constructs complex configurations |
| 53 | +- **Strategy Pattern** - Different loading strategies for various environments |
| 54 | +- **Adapter Pattern** - Adapts new system to legacy interfaces |
| 55 | +- **Facade Pattern** - EnvironmentService provides simplified interface |
| 56 | + |
| 57 | +## API Reference |
| 58 | + |
| 59 | +### Environment Class |
| 60 | + |
| 61 | +```typescript |
| 62 | +// Get singleton instance |
| 63 | +const env = Environment.getInstance(); |
| 64 | + |
| 65 | +// Access configuration |
| 66 | +console.log(env.apiUrl); |
| 67 | +console.log(env.appName); |
| 68 | +console.log(env.debug); |
| 69 | +``` |
| 70 | + |
| 71 | +### EnvironmentService |
| 72 | + |
| 73 | +```typescript |
| 74 | +// Async operations |
| 75 | +const apiUrl = await envService.get('API_URL', 'default'); |
| 76 | +const isDebug = await envService.getBoolean('DEBUG', false); |
| 77 | +const port = await envService.getNumber('PORT', 3000); |
| 78 | + |
| 79 | +// Validation |
| 80 | +const validation = await envService.getValidationResult(); |
| 81 | +``` |
| 82 | + |
| 83 | +### Configuration Models |
| 84 | + |
| 85 | +```typescript |
| 86 | +import { ConfigurationFactory } from '@ever-co/shared-environment'; |
| 87 | + |
| 88 | +const config = ConfigurationFactory.createConfiguration(envVars); |
| 89 | +console.log(config.apiUrl); |
| 90 | +console.log(config.google.clientId); |
| 91 | +``` |
| 92 | + |
| 93 | +## Testing |
| 94 | + |
| 95 | +```bash |
| 96 | +# Run tests |
| 97 | +nx test environment |
| 98 | + |
| 99 | +# Build library |
| 100 | +nx build environment |
| 101 | +``` |
| 102 | + |
| 103 | +## Contributing |
| 104 | + |
| 105 | +1. Follow SOLID principles |
| 106 | +2. Add comprehensive tests |
| 107 | +3. Update documentation |
| 108 | +4. Ensure backward compatibility |
| 109 | + |
| 110 | +## License |
| 111 | + |
| 112 | +AGPL-3.0 |
0 commit comments