feat: Implement Option 3 Hybrid activeDid approach
- Updated plugin interface to support hybrid activeDid management - Added setActiveDidFromHost() and refreshActiveDidFromDatabase() methods - Enhanced database configuration with platform awareness and hostDbPath - Implemented dual-mode activeDid access: * Foreground: Host provides activeDid from TimeSafari PlatformServiceMixin * Background: Plugin looks up activeDid from active_identity table - Added enableAutoActiveDidMode() for automatic identity synchronization - Updated all platform integrations to support hybrid approach: * Android/Electron: SQLite access with active_identity table reading * Web: Host delegation pattern with provided activeDid * iOS: Core Data hybrid with TimeSafari database access - Enhanced testing strategy for hybrid activeDid validation - Added TimeSafari integration methods for seamless hosting This hybrid approach provides optimal integration with TimeSafari's identity management while maintaining plugin autonomy for background operations.
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
**Author**: Matthew Raymer
|
**Author**: Matthew Raymer
|
||||||
**Version**: 1.0.0
|
**Version**: 1.0.0
|
||||||
**Created**: 2025-10-02 07:47:04 UTC
|
**Created**: 2025-10-02 07:47:04 UTC
|
||||||
**Last Updated**: 2025-10-02 10:45:00 UTC
|
**Last Updated**: 2025-10-02 11:30:00 UTC
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
@@ -258,64 +258,81 @@ Based on TimeSafari's optimization patterns:
|
|||||||
|
|
||||||
#### **Database Integration Patterns**
|
#### **Database Integration Patterns**
|
||||||
|
|
||||||
**Android/Electron: Plugin-Managed SQLite**
|
**Android/Electron: Hybrid activeDid Approach**
|
||||||
```typescript
|
```typescript
|
||||||
// Plugin handles database operations directly
|
// TimeSafari integration with hybrid activeDid management
|
||||||
await plugin.configure({
|
await plugin.configureDatabase({
|
||||||
dbPath: 'daily_notifications.db',
|
platform: 'android',
|
||||||
storage: 'shared'
|
storageType: 'hybrid',
|
||||||
|
hostDbPath: 'timesafari.sqlite' // Access TimeSafari's active_identity
|
||||||
});
|
});
|
||||||
|
|
||||||
// Plugin provides database access methods
|
// Host provides current activeDid
|
||||||
const results = await plugin.executeContentFetch(config);
|
const activeIdentity = await this.$getActiveIdentity();
|
||||||
await plugin.cacheContentData(results);
|
await plugin.setActiveDidFromHost(activeIdentity.activeDid);
|
||||||
|
|
||||||
// Host application accesses cached data via plugin
|
// Enable automatic background lookup
|
||||||
const cachedData = await plugin.getContentCache();
|
await plugin.enableAutoActiveDidMode();
|
||||||
|
|
||||||
|
// Plugin can fetch content and cache independently
|
||||||
|
const results = await plugin.executeContentFetch(config);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Web: Host-Managed Database**
|
**Web: Host-Managed Database with Hybrid activeDid**
|
||||||
```typescript
|
```typescript
|
||||||
// Host application manages absurd-sql database
|
// Host application manages absurd-sql database
|
||||||
import { openDatabase } from 'absurd-sql';
|
await plugin.configureDatabase({
|
||||||
|
platform: 'web',
|
||||||
|
storageType: 'hybrid'
|
||||||
|
});
|
||||||
|
|
||||||
const db = await openDatabase('daily_notifications.db');
|
// Host provides activeDid (plugin doesn't access web database)
|
||||||
|
const activeIdentity = await this.$getActiveIdentity();
|
||||||
|
await plugin.setActiveDidFromHost(activeIdentity.activeDid);
|
||||||
|
|
||||||
// Plugin provides SQL queries, host executes them
|
// Plugin delegates SQL operations to host
|
||||||
const query = await plugin.getContentFetchQuery(apiEndpoint, credentials);
|
const query = await plugin.getContentFetchQuery(apiEndpoint, activeDid);
|
||||||
const results = await db.exec(query);
|
const results = await hostDatabase.exec(query);
|
||||||
|
|
||||||
// Plugin receives results for processing
|
|
||||||
await plugin.processContentData(results);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**iOS: Hybrid Approach**
|
**iOS: Hybrid Approach with Active Identity Access**
|
||||||
```typescript
|
```typescript
|
||||||
// Plugin manages Core Data operations on background thread
|
// Plugin manages Core Data + reads TimeSafari's active_identity
|
||||||
await plugin.scheduleContentFetch(config);
|
await plugin.configureDatabase({
|
||||||
|
platform: 'ios',
|
||||||
|
storageType: 'hybrid',
|
||||||
|
hostDbPath: 'timesafari.sqlite'
|
||||||
|
});
|
||||||
|
|
||||||
// Host application accesses stored data via plugin APIs
|
// Host provides activeDid initially
|
||||||
const notificationData = await plugin.getLastNotification();
|
const activeIdentity = await this.$getActiveIdentity();
|
||||||
const cachedContent = await plugin.getContentHistory();
|
await plugin.setActiveDidFromHost(activeIdentity.activeDid);
|
||||||
|
|
||||||
|
// Plugin can refresh activeDid in background tasks
|
||||||
|
await plugin.enableAutoActiveDidMode();
|
||||||
```
|
```
|
||||||
|
|
||||||
#### **New Plugin Methods Required**
|
#### **New Plugin Methods Required**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
interface EnhancedDailyNotificationPlugin {
|
interface EnhancedDailyNotificationPlugin {
|
||||||
// Database configuration
|
// Database configuration - Platform-aware based on TimeSafari integration
|
||||||
configureDatabase(options: {
|
configureDatabase(options: {
|
||||||
storageType: 'plugin-managed' | 'host-managed';
|
platform: 'android' | 'ios' | 'web' | 'electron';
|
||||||
|
storageType: 'plugin-managed' | 'host-managed' | 'hybrid';
|
||||||
dbPath?: string;
|
dbPath?: string;
|
||||||
encryption?: boolean;
|
encryption?: boolean;
|
||||||
|
hostDbPath?: string; // Path to TimeSafari's active_identity database
|
||||||
}): Promise<void>;
|
}): Promise<void>;
|
||||||
|
|
||||||
|
// Hybrid activeDid Management (Option 3 Implementation)
|
||||||
|
setActiveDidFromHost(activeDid: string): Promise<void>;
|
||||||
|
refreshActiveDidFromDatabase(): Promise<string>;
|
||||||
|
enableAutoActiveDidMode(): Promise<void>;
|
||||||
|
|
||||||
// Content fetch with database integration
|
// Content fetch with database integration
|
||||||
fetchAndStoreContent(config: ContentFetchConfig): Promise<ContentFetchResult>;
|
fetchAndStoreContent(config: ContentFetchConfig): Promise<ContentFetchResult>;
|
||||||
|
|
||||||
// Credential management - simplified to activeDid only
|
|
||||||
setActiveDid(activeDid: string): Promise<void>;
|
|
||||||
|
|
||||||
// Data access for host application
|
// Data access for host application
|
||||||
getStoredContent(query: string, params?: any[]): Promise<any[]>;
|
getStoredContent(query: string, params?: any[]): Promise<any[]>;
|
||||||
clearStoredContent(options?: { olderThan?: number }): Promise<void>;
|
clearStoredContent(options?: { olderThan?: number }): Promise<void>;
|
||||||
@@ -324,14 +341,22 @@ interface EnhancedDailyNotificationPlugin {
|
|||||||
getBackgroundTaskStatus(): Promise<BackgroundTaskStatus>;
|
getBackgroundTaskStatus(): Promise<BackgroundTaskStatus>;
|
||||||
pauseBackgroundTasks(): Promise<void>;
|
pauseBackgroundTasks(): Promise<void>;
|
||||||
resumeBackgroundTasks(): Promise<void>;
|
resumeBackgroundTasks(): Promise<void>;
|
||||||
|
|
||||||
|
// TimeSafari Integration Methods
|
||||||
|
initializeFromTimeSafari(): Promise<void>;
|
||||||
|
listenForActiveDidChanges(): Promise<void>;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Background Scheduling
|
### Background Scheduling with Hybrid activeDid Management
|
||||||
|
|
||||||
- **Integrate** with existing WorkManager/BGTaskScheduler
|
- **Integrate** with existing WorkManager/BGTaskScheduler
|
||||||
- **Coordinate** API fetch timing with notification schedules
|
- **Coordinate** API fetch timing with notification schedules
|
||||||
- **Handle** app lifecycle events (background/foreground)
|
- **Handle** app lifecycle events (background/foreground)
|
||||||
|
- **Implement** dual-mode activeDid access:
|
||||||
|
- **Foreground**: Host provides activeDid via `setActiveDidFromHost()`
|
||||||
|
- **Background**: Plugin looks up activeDid via `refreshActiveDidFromDatabase()`
|
||||||
|
- **Coordinate** with TimeSafari's PlatformServiceMixin for identity changes
|
||||||
|
|
||||||
## Migration & Testing Strategy
|
## Migration & Testing Strategy
|
||||||
|
|
||||||
@@ -342,12 +367,17 @@ interface EnhancedDailyNotificationPlugin {
|
|||||||
3. **Phase 3**: Integrate with notification scheduling
|
3. **Phase 3**: Integrate with notification scheduling
|
||||||
4. **Phase 4**: Add passkey authentication support
|
4. **Phase 4**: Add passkey authentication support
|
||||||
|
|
||||||
### Testing Approach
|
### Testing Approach with Hybrid activeDid Management
|
||||||
|
|
||||||
- **Unit tests** for JWT generation and HTTP clients
|
- **Unit tests** for JWT generation and HTTP clients with activeDid
|
||||||
- **Integration tests** for API endpoint interactions
|
- **Integration tests** for API endpoint interactions using TimeSafari active_identity patterns
|
||||||
|
- **Hybrid activeDid testing**:
|
||||||
|
- Test `setActiveDidFromHost()` with TimeSafari PlatformServiceMixin
|
||||||
|
- Test `refreshActiveDidFromDatabase()` with background tasks
|
||||||
|
- Test `enableAutoActiveDidMode()` for automatic synchronization
|
||||||
- **Background testing** on real devices (doze mode, app backgrounding)
|
- **Background testing** on real devices (doze mode, app backgrounding)
|
||||||
- **Authentication testing** with actual DID credentials
|
- **Authentication testing** with actual DID credentials from TimeSafari active_identity table
|
||||||
|
- **Cross-platform testing** for Android/Electron (SQLite access) vs Web (host delegation) patterns
|
||||||
|
|
||||||
## API Endpoints to Support
|
## API Endpoints to Support
|
||||||
|
|
||||||
@@ -448,16 +478,18 @@ GET {apiServer}/api/v2/report/offersToPlansOwnedByMe?afterId={jwtId}&beforeId={j
|
|||||||
- Create plugin configuration interfaces
|
- Create plugin configuration interfaces
|
||||||
- Set up basic error handling
|
- Set up basic error handling
|
||||||
|
|
||||||
### Phase 2: Authentication & API Integration (Weeks 3-4)
|
### Phase 2: Hybrid activeDid Integration & API Access (Weeks 3-4)
|
||||||
|
|
||||||
- Implement DID-based authentication
|
- Implement hybrid activeDid management (Option 3 approach)
|
||||||
- Integrate API endpoint calls
|
- Add `setActiveDidFromHost()` and `refreshActiveDidFromDatabase()` methods
|
||||||
|
- Implement TimeSafari active_identity table access
|
||||||
|
- Integrate API endpoint calls with activeDid-based authentication
|
||||||
- Add response parsing and validation
|
- Add response parsing and validation
|
||||||
- Implement platform-specific database integration:
|
- Implement platform-specific database integration:
|
||||||
- **Android/Electron**: Direct @capacitor-community/sqlite integration
|
- **Android/Electron**: Direct @capacitor-community/sqlite integration with active_identity access
|
||||||
- **Web**: Plugin delegation pattern with absurd-sql coordination
|
- **Web**: Plugin delegation pattern with host-provided activeDid
|
||||||
- **iOS**: Core Data background thread integration
|
- **iOS**: Core Data background thread integration with TimeSafari database access
|
||||||
- Implement simplified activeDid-based authentication and API calls
|
- Add `enableAutoActiveDidMode()` for automatic identity synchronization
|
||||||
|
|
||||||
### Phase 3: Background Integration (Weeks 5-6)
|
### Phase 3: Background Integration (Weeks 5-6)
|
||||||
|
|
||||||
@@ -502,7 +534,12 @@ GET {apiServer}/api/v2/report/offersToPlansOwnedByMe?afterId={jwtId}&beforeId={j
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**Status**: Enhanced planning document - Ready for implementation
|
**Status**: Hybrid activeDid implementation plan - Ready for implementation
|
||||||
**Next Steps**: Begin Phase 1 implementation with Android HTTP client setup
|
**Next Steps**: Begin Phase 1 implementation with Android HTTP client setup
|
||||||
**Dependencies**: Android Studio, Xcode, Capacitor CLI, existing plugin infrastructure, @capacitor-community/sqlite, @simplewebauthn packages
|
**Dependencies**: Android Studio, Xcode, Capacitor CLI, existing plugin infrastructure, @capacitor-community/sqlite, TimeSafari active_identity table access
|
||||||
**Enhanced Features**: DID authentication, batch processing, structured logging, cross-platform storage optimization
|
**Hybrid Features**:
|
||||||
|
- **Option 3 Implementation**: Dual-mode activeDid access (host-provided + background lookup)
|
||||||
|
- **TimeSafari Integration**: PlatformServiceMixin coordination and active_identity table access
|
||||||
|
- **Cross-Platform**: Android/Electron SQLite access, Web host delegation, iOS Core Data hybrid
|
||||||
|
- **Authentication**: DID-based JWT with activeDid from TimeSafari's identity system
|
||||||
|
- **Background Tasks**: Automatic activeDid synchronization across app lifecycle states
|
||||||
|
|||||||
Reference in New Issue
Block a user