# Changelog

All notable changes to the Milton Health Coach FCM Client SDK will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.4] - 2024-10-03

### Fixed
- **Critical Import Errors**: Fixed missing React Native imports causing runtime errors
  - Added missing `Platform` import from 'react-native' (fixes "Property 'Platform' doesn't exist" error)
  - Added missing `DeviceInfo` import from 'react-native-device-info'
  - Fixed deprecated AppState API usage to use modern subscription-based approach
- **Client ID Generation**: Resolved client ID generation failures due to missing imports
- **App State Handling**: Updated to use modern React Native AppState API to avoid deprecation warnings

### Technical Details
- All React Native imports now properly declared
- Event listeners use modern subscription APIs with proper cleanup
- Backward compatible with React Native 0.60+ while using current best practices

## [1.1.3] - 2024-10-03

### Fixed
- **All Async API Endpoints**: Fixed all three async endpoints to use proper form data submission
  - `/async/v1/user`: Updated to send form data with correct field mapping (`orgId` → `request_org_id`, etc.)
  - `/async/v1/survey`: Already fixed in 1.1.2, maintained form data submission
  - `/async/v1/calculate_fitness`: Updated to use correct fitness parameters with form data
- **Offline Queue Processing**: Updated to handle all three endpoints with appropriate form submission methods
- **Parameter Mapping**: All endpoints now correctly map SDK parameters to server form field names

### Added
- **User Form Submission**: New `submitAsyncRequestForUserForm()` method for `/async/v1/user` endpoint
- **Fitness Form Submission**: New `submitAsyncRequestForFitnessForm()` method for `/async/v1/calculate_fitness` endpoint

### Breaking Changes
- **Fitness API Parameters**: The `calculateFitness()` method now requires different parameters:
  ```javascript
  // Before (incorrect)
  client.calculateFitness({ orgId: 123, userId: 456, fitnessData: {...} })
  
  // After (correct)
  client.calculateFitness({ 
    bmr: 1800, 
    tdee: 2400, 
    fitness_goal: "weight_loss", 
    current_weight: 75.5,
    activity_level: "moderate",
    fitness_experience: "intermediate"
  })
  ```

### Technical Details
- All async endpoints now send form data instead of JSON where required by server
- Maintained backward compatibility for user message parameters (no breaking changes)
- Enhanced offline queue to route requests to appropriate form submission methods
- Updated all documentation, examples, and type definitions

## [1.1.2] - 2024-10-03

### Fixed
- **Survey API Implementation**: Fixed `submitSurvey()` method to use correct API parameters
  - Changed from `orgId`, `userId`, `surveyData` to `phone_number`, `survey`, `birthday`, `default_timezone`
  - Added form data submission for survey endpoint (`/async/v1/survey`)
  - Updated offline queue processing to handle survey requests correctly
- **Documentation**: Updated all examples and API documentation to reflect correct survey usage
- **Type Definitions**: Updated TypeScript definitions for `SurveyRequest` interface

### Added
- **Survey Form Submission**: New `submitAsyncRequestForSurveyForm()` method for proper form data handling

### Breaking Changes
- **Survey API Parameters**: The `submitSurvey()` method now requires different parameters:
  ```javascript
  // Before (incorrect)
  client.submitSurvey({ orgId: 123, userId: 456, surveyData: {...} })
  
  // After (correct)
  client.submitSurvey({ 
    phone_number: "+1234567890", 
    survey: "Mood: good, Energy: 8/10", 
    birthday: "1990-01-01", 
    default_timezone: "America/New_York" 
  })
  ```

## [1.1.1] - 2024-10-02

### Added
- **SDK Information Method**: New `getSDKInfo()` method to retrieve SDK version, configuration, and status
- **Enhanced Error Messages**: More descriptive error messages for common configuration issues
- **Configuration Warnings**: Helpful warnings for common configuration mistakes (e.g., trailing slashes in baseUrl)

### Fixed
- **Test Suite**: Removed unused variable warning in comprehensive tests
- **Error Handling**: Improved error messages with actionable guidance for developers

### Improved
- **Developer Experience**: Better error messages help developers quickly identify and fix configuration issues
- **Debugging**: SDK info method provides comprehensive status information for troubleshooting

## [1.1.0] - 2024-10-02

### Added
- **Automatic Client ID Generation**: SDK now automatically generates unique client identifiers
  - Configurable prefix, platform detection, app version inclusion
  - Persistent storage across app restarts
  - Manual override capabilities with `setClientId()` and `regenerateClientId()`
- **Enhanced Configuration Options**: Comprehensive configuration for all SDK features
  - Client ID configuration with auto-generation settings
  - Improved polling configuration with battery optimization
  - Enhanced offline configuration with retry policies
- **Installation Verification Script**: `npm run verify` command to check setup
- **Comprehensive Documentation Suite**:
  - FCM Setup Checklist for step-by-step verification
  - Complete API Reference with all methods
  - Configuration Guide with all parameters
  - TypeScript Definitions and examples
  - Troubleshooting Guide for common issues
  - Migration Guide for upgrading
  - Offline Handling documentation
- **9 Working Examples**: Complete React Native components demonstrating all features
  - All Milton APIs Example (User Messages, Surveys, Fitness)
  - Complete Integration Example with error handling
  - Client ID Management Example
  - Configurable Parameters Example
  - Offline Handling Example
  - Advanced Usage patterns
  - And more...

### Changed
- **Package Name**: Changed from `@milton/fcm-client-sdk` to `milton-fcm-client-sdk` for easier publishing
- **FCM Enforcement**: Firebase Cloud Messaging is now mandatory with clear error messages
- **Enhanced Error Handling**: More descriptive error messages with setup guidance
- **Improved Documentation**: All documentation updated with comprehensive examples

### Fixed
- **ESLint Configuration**: Removed dependency on React Native community config
- **Publishing Issues**: Resolved npm scope publishing problems
- **Import Statements**: Updated all examples and documentation with correct package name

### Technical Improvements
- **Better Type Definitions**: Enhanced TypeScript support with comprehensive interfaces
- **Validation**: Improved configuration validation with helpful error messages
- **Testing**: Comprehensive test suite for all features
- **Code Quality**: ESLint configuration and code formatting

## [1.0.0] - 2024-09-25

### Added
- Initial release of Milton Health Coach FCM Client SDK
- **Core Features**:
  - Async request processing for Milton APIs
  - Firebase Cloud Messaging integration
  - Intelligent polling with exponential backoff
  - Push notification coordination
  - Offline request queuing and retry
  - Battery optimization for background processing
- **API Support**:
  - User Message API with image support
  - Survey API for health and wellness data
  - Fitness Calculation API for activity metrics
- **Developer Features**:
  - React Native compatibility
  - Comprehensive error handling
  - Network resilience
  - Background processing support
- **Documentation**:
  - Basic README with installation instructions
  - Firebase setup guide
  - API usage examples

### Technical Details
- **Dependencies**: React Native Firebase, AsyncStorage, NetInfo
- **Platforms**: iOS and Android support
- **License**: MIT License
- **Package Size**: ~76KB compressed