Version Management
DesterLib uses centralized version management with strict version matching between the API and all client applications.
Overview
Section titled “Overview”All versions are managed from a single source of truth: the root package.json. A sync script automatically propagates version changes to all dependent projects.
Current Version: 0.1.0
Version Format
Section titled “Version Format”We follow Semantic Versioning 2.0.0:
MAJOR.MINOR.PATCH- MAJOR: Incompatible API changes
- MINOR: Backward-compatible functionality additions
- PATCH: Backward-compatible bug fixes
Version Matching Rules
Section titled “Version Matching Rules”The system enforces strict semantic versioning:
- ✅ Major.Minor must match exactly
- ✅ Patch can differ (backwards compatible)
Compatibility Examples
Section titled “Compatibility Examples”| Client | API | Compatible? | Reason |
|---|---|---|---|
| 0.1.0 | 0.1.0 | ✅ Yes | Exact match |
| 0.1.0 | 0.1.5 | ✅ Yes | Patch difference OK |
| 0.1.0 | 0.2.0 | ❌ No | Minor version mismatch |
| 0.1.0 | 1.0.0 | ❌ No | Major version mismatch |
Updating Versions
Section titled “Updating Versions”Quick Process
Section titled “Quick Process”# 1. Create a changeset for your changespnpm changeset
# 2. Commit changes and changesetpnpm commitgit push origin dev
# 3. After merge, version packages (maintainers only)pnpm version
# 4. Version bump generates package CHANGELOG.md files automaticallyWhat Gets Synced
Section titled “What Gets Synced”The pnpm version:sync script automatically updates:
- ✅
apps/api/package.json- API version - ✅
../desterlib-flutter/pubspec.yaml- Flutter app version - ✅
../desterlib-flutter/lib/api/pubspec.yaml- Generated client version - ✅
../desterlib-flutter/lib/core/config/api_config.dart- Client version constant
Changelog Management
Section titled “Changelog Management”DesterLib uses Changesets for automatic changelog generation:
- 📝 Package changelogs are auto-generated in:
apps/api/CHANGELOG.md- API changesapps/docs/CHANGELOG.md- Documentation changes
- 📝 Aggregated changelog synced to docs site
- 📝 Use
pnpm changesetto document your changes
How It Works
Section titled “How It Works”API Side
Section titled “API Side”-
Version Exposure
/healthendpoint returns:{ status, version, timestamp, uptime }- All responses include
X-API-Versionheader - Swagger docs display current version
-
Version Validation
- Middleware checks
X-Client-Versionheader on all/api/v1requests - Returns HTTP 426 (Upgrade Required) if incompatible
- Provides clear error message with upgrade instructions
- Middleware checks
-
Compatibility Check
// Major and minor must match exactlyclient.major === api.major && client.minor === api.minor;
Client Side
Section titled “Client Side”-
Version Declaration
- All requests include
X-Client-Version: 0.1.0header - Version constant synced from root package.json
- All requests include
-
Version Detection
- Dio interceptor reads
X-API-Versionfrom responses - Automatically updates version provider
- Handles HTTP 426 errors gracefully
- Dio interceptor reads
-
User Experience
- Shows friendly error when version mismatch occurs
- Suggests updating the app
- Provides clear instructions
Error Handling
Section titled “Error Handling”API Response (HTTP 426)
Section titled “API Response (HTTP 426)”When versions are incompatible:
{ "success": false, "error": "Version mismatch", "message": "Client version 0.1.0 is not compatible with API version 0.2.0. Please update your client.", "data": { "clientVersion": "0.1.0", "apiVersion": "0.2.0", "upgradeRequired": true }}Client Behavior
Section titled “Client Behavior”The Flutter client:
- Detects version mismatch (HTTP 426)
- Updates version provider
- Shows user-friendly error
- Suggests app update
Version Sync Script
Section titled “Version Sync Script”Check and sync versions:
pnpm version:syncOutput Example
Section titled “Output Example”📦 Syncing version: 0.1.0──────────────────────────────────────────────────✅ Updated apps/api/package.json: 0.1.0✅ Updated desterlib-flutter/pubspec.yaml: 0.1.0✅ Updated desterlib-flutter/lib/api/pubspec.yaml: 0.1.0✅ Updated desterlib-flutter/lib/core/config/api_config.dart: 0.1.0
──────────────────────────────────────────────────✅ Successfully updated 4 file(s)API Route Version vs Semantic Version
Section titled “API Route Version vs Semantic Version”Don’t confuse these two concepts:
- API Route Version:
v1in/api/v1/...- Rarely changes, represents API schema version - Semantic Version:
0.1.0- Changes with each release, represents application version
In api_config.dart:
static const String apiRouteVersion = 'v1'; // API endpoint versionstatic const String clientVersion = '0.1.0'; // Semantic versionDevelopment
Section titled “Development”Skipping Version Checks
Section titled “Skipping Version Checks”For local development, you can temporarily disable validation:
- Comment out
validateVersionmiddleware insetup.middleware.ts - Or omit the
X-Client-Versionheader (logs warning but allows request)
Testing Version Mismatches
Section titled “Testing Version Mismatches”To test the version mismatch flow:
- Change
clientVersioninapi_config.dartto a different version - Make an API request
- Verify HTTP 426 response
- Verify client handles error appropriately
Best Practices
Section titled “Best Practices”- Create changesets - Always run
pnpm changesetfor user-facing changes - Use conventional commits - Helps with changelog generation
- Test thoroughly - Test both compatible and incompatible scenarios
- Clear communication - Inform users about breaking changes
- Review generated changelogs - Verify changesets generate correct entries
Troubleshooting
Section titled “Troubleshooting”Versions Out of Sync
Section titled “Versions Out of Sync”# Fix itpnpm version:syncScript Not Found
Section titled “Script Not Found”# Make executablechmod +x scripts/sync-version.js
# Or run directlynode scripts/sync-version.jsManual Verification
Section titled “Manual Verification”Check these files if sync seems incorrect:
package.json- Root version (source of truth)apps/api/package.json- Should match rootdesterlib-flutter/pubspec.yaml- Should match rootdesterlib-flutter/lib/api/pubspec.yaml- Should match rootdesterlib-flutter/lib/core/config/api_config.dart-clientVersionshould match root