Browse Source

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.
research/notification-plugin-enhancement
Matthew Raymer 20 hours ago
parent
commit
51034998dd
  1. 129
      doc/BACKGROUND_DATA_FETCHING_PLAN.md

129
doc/BACKGROUND_DATA_FETCHING_PLAN.md

@ -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);
// Enable automatic background lookup
await plugin.enableAutoActiveDidMode();
// Host application accesses cached data via plugin // Plugin can fetch content and cache independently
const cachedData = await plugin.getContentCache(); 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',
const db = await openDatabase('daily_notifications.db'); storageType: 'hybrid'
});
// Plugin provides SQL queries, host executes them // Host provides activeDid (plugin doesn't access web database)
const query = await plugin.getContentFetchQuery(apiEndpoint, credentials); const activeIdentity = await this.$getActiveIdentity();
const results = await db.exec(query); await plugin.setActiveDidFromHost(activeIdentity.activeDid);
// Plugin receives results for processing // Plugin delegates SQL operations to host
await plugin.processContentData(results); const query = await plugin.getContentFetchQuery(apiEndpoint, activeDid);
const results = await hostDatabase.exec(query);
``` ```
**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 provides activeDid initially
const activeIdentity = await this.$getActiveIdentity();
await plugin.setActiveDidFromHost(activeIdentity.activeDid);
// Host application accesses stored data via plugin APIs // Plugin can refresh activeDid in background tasks
const notificationData = await plugin.getLastNotification(); await plugin.enableAutoActiveDidMode();
const cachedContent = await plugin.getContentHistory();
``` ```
#### **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

Loading…
Cancel
Save