Finance SDK
A Flutter plugin that provides Firebase-driven dynamic API orchestration using Firestore and Remote Config.
π Features
- Firebase Integration: Automatic initialization of Firestore and Remote Config
- Dynamic API Configuration: Fetch API definitions from Firestore
- Dynamic Enum Generation: Auto-generate enums from Firestore data
- Caching Layer: Local caching with SharedPreferences for offline support
- Comprehensive Logging: Built-in logging system for debugging
- Error Handling: Robust error handling with structured responses
π¦ Installation
Add this to your package's pubspec.yaml file:
dependencies:
finance_sdk: ^1.0.0
The plugin handles Firebase initialization internally, so you don't need to add firebase_core to your dependencies.
π§ Quick Start
1. Configure Firebase for the Plugin
See FIREBASE_PLUGIN_SETUP.md for detailed instructions.
Important: Firebase is initialized internally by the plugin. Your app does NOT need to call Firebase.initializeApp().
2. Initialize the SDK
import 'package:finance_sdk/finance_sdk.dart';
final financeSdk = FinanceSdk();
// Initialize the SDK (this fetches data from Firebase)
await financeSdk.initialize();
3. Send API Requests
// Send a request using an API key from Firestore
final response = await financeSdk.sendRequest(
apiKey: 'GET_USER_DETAIL',
requestBody: {
'userId': '12345',
'includeProfile': true,
},
);
if (response.success) {
print('Success: ${response.data}');
} else {
print('Error: ${response.error}');
}
ποΈ Firebase Setup
The plugin requires Firebase to be configured in the plugin itself, not in your app.
Setup Guide: FIREBASE_PLUGIN_SETUP.md
Quick Setup Steps:
- Create Firebase Project with Firestore and Remote Config enabled
- Add Android App with package:
com.mytm.finance.sdk.finance_sdk - Add iOS App with bundle ID:
com.mytm.finance.sdk.finance_sdk - Place configuration files:
google-services.jsonβandroid/google-services.jsonGoogleService-Info.plistβios/GoogleService-Info.plist
- Configure Firestore: Create
api_definitionscollection - Configure Remote Config: Add
baseUrlparameter
π± Example App
The example app demonstrates all SDK features:
cd example
flutter run
π How It Works
-
Initialization: The SDK initializes Firebase services and fetches API definitions from Firestore
-
Request Processing: When you call
sendRequest():- SDK looks up the API definition by key
- Retrieves the base URL from Remote Config
- Constructs the final URL:
$baseUrl/$service$endpoint - Merges request body with default parameters
- Sends HTTP request with configured headers
- Returns structured response
-
Caching: All data is cached locally for offline support and faster access
π» API Reference
FinanceSdk Class
initialize()
Initializes the Firebase-based API handling system. Must be called before using other methods.
sendRequest({required String apiKey, required Map<String, dynamic> requestBody})
Sends an API request using Firebase configuration.
Parameters:
apiKey: The API key identifier from FirestorerequestBody: The request body data to send
Returns: Future<ApiResponse>
getAvailableApiKeys()
Returns all available API keys from Firestore.
Returns: Future<Map<String, String>>
getAvailableServices()
Returns all available services from Firestore.
Returns: Future<Map<String, String>>
refreshData()
Refreshes data from Firebase (API definitions and base URL).
Returns: Future<void>
ApiResponse Class
Properties
success:bool- Whether the request was successfuldata:dynamic- Response data (if successful)error:String?- Error message (if failed)statusCode:int?- HTTP status code
π οΈ Development
Running Tests
flutter test
Running Integration Tests
cd example
flutter test integration_test/
π Security Considerations
Firebase Configuration
- The plugin uses an embedded Firebase configuration to ensure all users access the same Firebase project
- Firebase credentials are protected by ProGuard rules in Android release builds
- Firebase Security Rules should be configured on the server side to protect your data
Best Practices
- Store sensitive API keys securely in Firestore with proper Security Rules
- Use Firebase App Check for additional security
- Implement proper authentication in your backend APIs
- Never commit Firebase configuration files to public repositories
- Use environment-specific Firebase projects for development and production
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π€ Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
π Support
For support, please open an issue in the GitHub repository or contact the development team.