Compare commits
6 Commits
registrati
...
sql-absurd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9ce884513 | ||
|
|
a1a1543ae1 | ||
|
|
93591a5815 | ||
|
|
b30c4c8b30 | ||
|
|
1f9db0ba94 | ||
|
|
bdc2d71d3c |
172
.cursor/rules/SQLITE.mdc
Normal file
172
.cursor/rules/SQLITE.mdc
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
---
|
||||||
|
description:
|
||||||
|
globs:
|
||||||
|
alwaysApply: true
|
||||||
|
---
|
||||||
|
# @capacitor-community/sqlite MDC Ruleset
|
||||||
|
|
||||||
|
## Project Overview
|
||||||
|
This ruleset is for the `@capacitor-community/sqlite` plugin, a Capacitor community plugin that provides native and Electron SQLite database functionality with encryption support.
|
||||||
|
|
||||||
|
## Key Features
|
||||||
|
- Native SQLite database support for iOS, Android, and Electron
|
||||||
|
- Database encryption support using SQLCipher (Native) and better-sqlite3-multiple-ciphers (Electron)
|
||||||
|
- Biometric authentication support
|
||||||
|
- Cross-platform database operations
|
||||||
|
- JSON import/export capabilities
|
||||||
|
- Database migration support
|
||||||
|
- Sync table functionality
|
||||||
|
|
||||||
|
## Platform Support Matrix
|
||||||
|
|
||||||
|
### Core Database Operations
|
||||||
|
| Operation | Android | iOS | Electron | Web |
|
||||||
|
|-----------|---------|-----|----------|-----|
|
||||||
|
| Create Connection (RW) | ✅ | ✅ | ✅ | ✅ |
|
||||||
|
| Create Connection (RO) | ✅ | ✅ | ✅ | ❌ |
|
||||||
|
| Open DB (non-encrypted) | ✅ | ✅ | ✅ | ✅ |
|
||||||
|
| Open DB (encrypted) | ✅ | ✅ | ✅ | ❌ |
|
||||||
|
| Execute/Query | ✅ | ✅ | ✅ | ✅ |
|
||||||
|
| Import/Export JSON | ✅ | ✅ | ✅ | ✅ |
|
||||||
|
|
||||||
|
### Security Features
|
||||||
|
| Feature | Android | iOS | Electron | Web |
|
||||||
|
|---------|---------|-----|----------|-----|
|
||||||
|
| Encryption | ✅ | ✅ | ✅ | ❌ |
|
||||||
|
| Biometric Auth | ✅ | ✅ | ✅ | ❌ |
|
||||||
|
| Secret Management | ✅ | ✅ | ✅ | ❌ |
|
||||||
|
|
||||||
|
## Configuration Requirements
|
||||||
|
|
||||||
|
### Base Configuration
|
||||||
|
```typescript
|
||||||
|
// capacitor.config.ts
|
||||||
|
{
|
||||||
|
plugins: {
|
||||||
|
CapacitorSQLite: {
|
||||||
|
iosDatabaseLocation: 'Library/CapacitorDatabase',
|
||||||
|
iosIsEncryption: true,
|
||||||
|
iosKeychainPrefix: 'your-app-prefix',
|
||||||
|
androidIsEncryption: true,
|
||||||
|
electronIsEncryption: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Platform-Specific Requirements
|
||||||
|
|
||||||
|
#### Android
|
||||||
|
- Minimum SDK: 23
|
||||||
|
- Target SDK: 35
|
||||||
|
- Required Gradle JDK: 21
|
||||||
|
- Required Android Gradle Plugin: 8.7.2
|
||||||
|
- Required manifest settings for backup prevention
|
||||||
|
- Required data extraction rules
|
||||||
|
|
||||||
|
#### iOS
|
||||||
|
- No additional configuration needed beyond base setup
|
||||||
|
- Supports biometric authentication
|
||||||
|
- Uses keychain for encryption
|
||||||
|
|
||||||
|
#### Electron
|
||||||
|
Required dependencies:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"better-sqlite3-multiple-ciphers": "latest",
|
||||||
|
"electron-json-storage": "latest",
|
||||||
|
"jszip": "latest",
|
||||||
|
"node-fetch": "2.6.7",
|
||||||
|
"crypto": "latest",
|
||||||
|
"crypto-js": "latest"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Web
|
||||||
|
- Requires `sql.js` and `jeep-sqlite`
|
||||||
|
- Manual copy of `sql-wasm.wasm` to assets folder
|
||||||
|
- Framework-specific asset placement:
|
||||||
|
- Angular: `src/assets/`
|
||||||
|
- Vue/React: `public/assets/`
|
||||||
|
|
||||||
|
## Best Practices
|
||||||
|
|
||||||
|
### Database Operations
|
||||||
|
1. Always close connections after use
|
||||||
|
2. Use transactions for multiple operations
|
||||||
|
3. Implement proper error handling
|
||||||
|
4. Use prepared statements for queries
|
||||||
|
5. Implement proper database versioning
|
||||||
|
|
||||||
|
### Security
|
||||||
|
1. Always use encryption for sensitive data
|
||||||
|
2. Implement proper secret management
|
||||||
|
3. Use biometric authentication when available
|
||||||
|
4. Follow platform-specific security guidelines
|
||||||
|
|
||||||
|
### Performance
|
||||||
|
1. Use appropriate indexes
|
||||||
|
2. Implement connection pooling
|
||||||
|
3. Use transactions for bulk operations
|
||||||
|
4. Implement proper database cleanup
|
||||||
|
|
||||||
|
## Common Issues and Solutions
|
||||||
|
|
||||||
|
### Android
|
||||||
|
- Build data properties conflict: Add to `app/build.gradle`:
|
||||||
|
```gradle
|
||||||
|
packagingOptions {
|
||||||
|
exclude 'build-data.properties'
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Electron
|
||||||
|
- Node-fetch version must be ≤2.6.7
|
||||||
|
- For Capacitor Electron v5:
|
||||||
|
- Use Electron@25.8.4
|
||||||
|
- Add `"skipLibCheck": true` to tsconfig.json
|
||||||
|
|
||||||
|
### Web
|
||||||
|
- Ensure proper WASM file placement
|
||||||
|
- Handle browser compatibility
|
||||||
|
- Implement proper fallbacks
|
||||||
|
|
||||||
|
## Version Compatibility
|
||||||
|
- Requires Node.js ≥16.0.0
|
||||||
|
- Compatible with Capacitor ≥7.0.0
|
||||||
|
- Supports TypeScript 4.1.5+
|
||||||
|
|
||||||
|
## Testing Requirements
|
||||||
|
- Unit tests for database operations
|
||||||
|
- Platform-specific integration tests
|
||||||
|
- Encryption/decryption tests
|
||||||
|
- Biometric authentication tests
|
||||||
|
- Migration tests
|
||||||
|
- Sync functionality tests
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
- API Documentation: `/docs/API.md`
|
||||||
|
- Connection API: `/docs/APIConnection.md`
|
||||||
|
- DB Connection API: `/docs/APIDBConnection.md`
|
||||||
|
- Release Notes: `/docs/info_releases.md`
|
||||||
|
- Changelog: `CHANGELOG.md`
|
||||||
|
|
||||||
|
## Contributing Guidelines
|
||||||
|
- Follow Ionic coding standards
|
||||||
|
- Use provided linting and formatting tools
|
||||||
|
- Maintain platform compatibility
|
||||||
|
- Update documentation
|
||||||
|
- Add appropriate tests
|
||||||
|
- Follow semantic versioning
|
||||||
|
|
||||||
|
## Maintenance
|
||||||
|
- Regular security updates
|
||||||
|
- Platform compatibility checks
|
||||||
|
- Performance optimization
|
||||||
|
- Documentation updates
|
||||||
|
- Dependency updates
|
||||||
|
|
||||||
|
## License
|
||||||
|
MIT License - See LICENSE file for details
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -2,127 +2,420 @@
|
|||||||
|
|
||||||
## Core Services
|
## Core Services
|
||||||
|
|
||||||
### 1. Storage Service Layer
|
### 1. Platform Service Layer
|
||||||
- [ ] Create base `StorageService` interface
|
- [x] Create base `PlatformService` interface
|
||||||
- [ ] Define common methods for all platforms
|
- [x] Define platform capabilities
|
||||||
- [ ] Add platform-specific method signatures
|
- [x] File system access detection
|
||||||
- [ ] Include error handling types
|
- [x] Camera availability
|
||||||
- [ ] Add migration support methods
|
- [x] Mobile platform detection
|
||||||
|
- [x] iOS specific detection
|
||||||
|
- [x] File download capability
|
||||||
|
- [x] SQLite capabilities
|
||||||
|
- [x] Add SQLite operations interface
|
||||||
|
- [x] Database initialization
|
||||||
|
- [x] Query execution
|
||||||
|
- [x] Transaction management
|
||||||
|
- [x] Prepared statements
|
||||||
|
- [x] Database statistics
|
||||||
|
- [x] Include platform detection
|
||||||
|
- [x] Web platform detection
|
||||||
|
- [x] Mobile platform detection
|
||||||
|
- [x] Desktop platform detection
|
||||||
|
- [x] Add file system operations
|
||||||
|
- [x] File read operations
|
||||||
|
- [x] File write operations
|
||||||
|
- [x] File delete operations
|
||||||
|
- [x] Directory listing
|
||||||
|
|
||||||
- [ ] Implement platform-specific services
|
- [x] Implement platform-specific services
|
||||||
- [ ] `WebSQLiteService` (absurd-sql)
|
- [x] `WebPlatformService`
|
||||||
- [ ] Database initialization
|
- [x] AbsurdSQL integration
|
||||||
- [ ] VFS setup with IndexedDB backend
|
- [x] SQL.js initialization
|
||||||
- [ ] Connection management
|
- [x] IndexedDB backend setup
|
||||||
- [ ] Query builder
|
- [x] Virtual file system configuration
|
||||||
- [ ] `NativeSQLiteService` (iOS/Android)
|
- [x] Web Worker support
|
||||||
- [ ] SQLCipher integration
|
- [x] Worker thread initialization
|
||||||
- [ ] Native bridge setup
|
- [x] Message passing
|
||||||
- [ ] File system access
|
- [x] Error handling
|
||||||
- [ ] `ElectronSQLiteService`
|
- [x] IndexedDB backend
|
||||||
|
- [x] Database creation
|
||||||
|
- [x] Transaction handling
|
||||||
|
- [x] Storage quota management (1GB limit)
|
||||||
|
- [x] SharedArrayBuffer detection
|
||||||
|
- [x] Feature detection
|
||||||
|
- [x] Fallback handling
|
||||||
|
- [x] File system operations (intentionally not supported)
|
||||||
|
- [x] File read operations (not available in web)
|
||||||
|
- [x] File write operations (not available in web)
|
||||||
|
- [x] File delete operations (not available in web)
|
||||||
|
- [x] Directory operations (not available in web)
|
||||||
|
- [x] Settings implementation
|
||||||
|
- [x] AbsurdSQL settings operations
|
||||||
|
- [x] Worker-based settings updates
|
||||||
|
- [x] IndexedDB transaction handling
|
||||||
|
- [x] SharedArrayBuffer support
|
||||||
|
- [x] Web-specific settings features
|
||||||
|
- [x] Storage quota management
|
||||||
|
- [x] Worker thread isolation
|
||||||
|
- [x] Cross-origin settings
|
||||||
|
- [x] Web performance optimizations
|
||||||
|
- [x] Settings caching
|
||||||
|
- [x] Batch updates
|
||||||
|
- [x] Worker message optimization
|
||||||
|
- [x] Account implementation
|
||||||
|
- [x] Web-specific account handling
|
||||||
|
- [x] Browser storage persistence
|
||||||
|
- [x] Session management
|
||||||
|
- [x] Cross-tab synchronization
|
||||||
|
- [x] Web security features
|
||||||
|
- [x] Origin isolation
|
||||||
|
- [x] Worker thread security
|
||||||
|
- [x] Storage access control
|
||||||
|
- [x] `CapacitorPlatformService`
|
||||||
|
- [x] Native SQLite integration
|
||||||
|
- [x] Database connection
|
||||||
|
- [x] Query execution
|
||||||
|
- [x] Transaction handling
|
||||||
|
- [x] Platform capabilities
|
||||||
|
- [x] iOS detection
|
||||||
|
- [x] Android detection
|
||||||
|
- [x] Feature availability
|
||||||
|
- [x] File system operations
|
||||||
|
- [x] File read/write
|
||||||
|
- [x] Directory operations
|
||||||
|
- [x] Storage permissions
|
||||||
|
- [x] iOS permissions
|
||||||
|
- [x] Android permissions
|
||||||
|
- [x] Permission request handling
|
||||||
|
- [x] Settings implementation
|
||||||
|
- [x] Native SQLite settings operations
|
||||||
|
- [x] Platform-specific SQLite optimizations
|
||||||
|
- [x] Native transaction handling
|
||||||
|
- [x] Platform storage management
|
||||||
|
- [x] Mobile-specific settings features
|
||||||
|
- [x] Platform preferences sync
|
||||||
|
- [x] Background state handling
|
||||||
|
- [x] Mobile performance optimizations
|
||||||
|
- [x] Native caching
|
||||||
|
- [x] Battery-efficient updates
|
||||||
|
- [x] Memory management
|
||||||
|
- [x] Account implementation
|
||||||
|
- [x] Mobile-specific account handling
|
||||||
|
- [x] Platform storage integration
|
||||||
|
- [x] Background state handling
|
||||||
|
- [x] Mobile security features
|
||||||
|
- [x] Platform sandboxing
|
||||||
|
- [x] Storage access control
|
||||||
|
- [x] App sandboxing
|
||||||
|
- [ ] `ElectronPlatformService` (planned)
|
||||||
- [ ] Node SQLite integration
|
- [ ] Node SQLite integration
|
||||||
- [ ] IPC communication
|
- [ ] Database connection
|
||||||
|
- [ ] Query execution
|
||||||
|
- [ ] Transaction handling
|
||||||
- [ ] File system access
|
- [ ] File system access
|
||||||
|
- [ ] File read operations
|
||||||
|
- [ ] File write operations
|
||||||
|
- [ ] File delete operations
|
||||||
|
- [ ] Directory operations
|
||||||
|
- [ ] IPC communication
|
||||||
|
- [ ] Main process communication
|
||||||
|
- [ ] Renderer process handling
|
||||||
|
- [ ] Message passing
|
||||||
|
- [ ] Native features implementation
|
||||||
|
- [ ] System dialogs
|
||||||
|
- [ ] Native menus
|
||||||
|
- [ ] System integration
|
||||||
|
- [ ] Settings implementation
|
||||||
|
- [ ] Node SQLite settings operations
|
||||||
|
- [ ] Main process SQLite handling
|
||||||
|
- [ ] IPC-based updates
|
||||||
|
- [ ] File system persistence
|
||||||
|
- [ ] Desktop-specific settings features
|
||||||
|
- [ ] System preferences integration
|
||||||
|
- [ ] Multi-window sync
|
||||||
|
- [ ] Offline state handling
|
||||||
|
- [ ] Desktop performance optimizations
|
||||||
|
- [ ] Process-based caching
|
||||||
|
- [ ] Window state management
|
||||||
|
- [ ] Resource optimization
|
||||||
|
- [ ] Account implementation
|
||||||
|
- [ ] Desktop-specific account handling
|
||||||
|
- [ ] System keychain integration
|
||||||
|
- [ ] Native authentication
|
||||||
|
- [ ] Process isolation
|
||||||
|
- [ ] Desktop security features
|
||||||
|
- [ ] Process sandboxing
|
||||||
|
- [ ] IPC security
|
||||||
|
- [ ] File system protection
|
||||||
|
|
||||||
### 2. Migration Services
|
### 2. SQLite Service Layer
|
||||||
- [ ] Implement `MigrationService`
|
- [x] Create base `BaseSQLiteService`
|
||||||
- [ ] Backup creation
|
- [x] Common SQLite operations
|
||||||
- [ ] Data verification
|
- [x] Query execution
|
||||||
- [ ] Rollback procedures
|
- [x] Transaction management
|
||||||
- [ ] Progress tracking
|
- [x] Prepared statements
|
||||||
- [ ] Create `MigrationUI` components
|
- [x] Database statistics
|
||||||
- [ ] Progress indicators
|
- [x] Performance monitoring
|
||||||
|
- [x] Query timing
|
||||||
|
- [x] Memory usage
|
||||||
|
- [x] Database size
|
||||||
|
- [x] Statement caching
|
||||||
|
- [x] Error handling
|
||||||
|
- [x] Connection errors
|
||||||
|
- [x] Query errors
|
||||||
|
- [x] Transaction errors
|
||||||
|
- [x] Resource errors
|
||||||
|
- [x] Transaction support
|
||||||
|
- [x] Begin transaction
|
||||||
|
- [x] Commit transaction
|
||||||
|
- [x] Rollback transaction
|
||||||
|
- [x] Nested transactions
|
||||||
|
|
||||||
|
- [x] Implement platform-specific SQLite services
|
||||||
|
- [x] `AbsurdSQLService`
|
||||||
|
- [x] Web Worker initialization
|
||||||
|
- [x] Worker creation
|
||||||
|
- [x] Message handling
|
||||||
|
- [x] Error propagation
|
||||||
|
- [x] IndexedDB backend setup
|
||||||
|
- [x] Database creation
|
||||||
|
- [x] Transaction handling
|
||||||
|
- [x] Storage management
|
||||||
|
- [x] Prepared statements
|
||||||
|
- [x] Statement preparation
|
||||||
|
- [x] Parameter binding
|
||||||
|
- [x] Statement caching
|
||||||
|
- [x] Performance optimizations
|
||||||
|
- [x] WAL mode
|
||||||
|
- [x] Memory mapping
|
||||||
|
- [x] Cache configuration
|
||||||
|
- [x] WAL mode support
|
||||||
|
- [x] Journal mode configuration
|
||||||
|
- [x] Synchronization settings
|
||||||
|
- [x] Checkpoint handling
|
||||||
|
- [x] Memory-mapped I/O
|
||||||
|
- [x] MMAP size configuration (30GB)
|
||||||
|
- [x] Memory management
|
||||||
|
- [x] Performance monitoring
|
||||||
|
- [x] `CapacitorSQLiteService`
|
||||||
|
- [x] Native SQLite connection
|
||||||
|
- [x] Database initialization
|
||||||
|
- [x] Connection management
|
||||||
|
- [x] Error handling
|
||||||
|
- [x] Basic platform features
|
||||||
|
- [x] Query execution
|
||||||
|
- [x] Transaction handling
|
||||||
|
- [x] Statement management
|
||||||
|
- [x] Error handling
|
||||||
|
- [x] Connection errors
|
||||||
|
- [x] Query errors
|
||||||
|
- [x] Resource errors
|
||||||
|
- [x] WAL mode support
|
||||||
|
- [x] Journal mode
|
||||||
|
- [x] Synchronization
|
||||||
|
- [x] Checkpointing
|
||||||
|
- [ ] SQLCipher integration (planned)
|
||||||
|
- [ ] Encryption setup
|
||||||
|
- [ ] Key management
|
||||||
|
- [ ] Secure storage
|
||||||
|
- [ ] `ElectronSQLiteService` (planned)
|
||||||
|
- [ ] Node SQLite integration
|
||||||
|
- [ ] Database connection
|
||||||
|
- [ ] Query execution
|
||||||
|
- [ ] Transaction handling
|
||||||
|
- [ ] IPC communication
|
||||||
|
- [ ] Process communication
|
||||||
- [ ] Error handling
|
- [ ] Error handling
|
||||||
- [ ] User notifications
|
- [ ] Resource management
|
||||||
- [ ] Manual triggers
|
- [ ] File system access
|
||||||
|
- [ ] Native file operations
|
||||||
|
- [ ] Path handling
|
||||||
|
- [ ] Permissions
|
||||||
|
- [ ] Native features
|
||||||
|
- [ ] System integration
|
||||||
|
- [ ] Native dialogs
|
||||||
|
- [ ] Process management
|
||||||
|
|
||||||
### 3. Security Layer
|
### 3. Security Layer
|
||||||
- [ ] Implement `EncryptionService`
|
- [x] Implement platform-specific security
|
||||||
|
- [x] Web platform
|
||||||
|
- [x] Worker isolation
|
||||||
|
- [x] Thread separation
|
||||||
|
- [x] Message security
|
||||||
|
- [x] Resource isolation
|
||||||
|
- [x] Storage quota management
|
||||||
|
- [x] Quota detection
|
||||||
|
- [x] Usage monitoring
|
||||||
|
- [x] Error handling
|
||||||
|
- [x] Origin isolation
|
||||||
|
- [x] Cross-origin protection
|
||||||
|
- [x] Resource isolation
|
||||||
|
- [x] Security policy
|
||||||
|
- [x] Storage security
|
||||||
|
- [x] Access control
|
||||||
|
- [x] Data protection
|
||||||
|
- [x] Quota management
|
||||||
|
- [x] Mobile platform
|
||||||
|
- [x] Platform permissions
|
||||||
|
- [x] Storage access
|
||||||
|
- [x] File operations
|
||||||
|
- [x] System integration
|
||||||
|
- [x] Platform security
|
||||||
|
- [x] App sandboxing
|
||||||
|
- [x] Storage protection
|
||||||
|
- [x] Access control
|
||||||
|
- [ ] SQLCipher integration (planned)
|
||||||
|
- [ ] Encryption setup
|
||||||
- [ ] Key management
|
- [ ] Key management
|
||||||
- [ ] Encryption/decryption
|
|
||||||
- [ ] Secure storage
|
- [ ] Secure storage
|
||||||
- [ ] Add `BiometricService`
|
- [ ] Electron platform (planned)
|
||||||
- [ ] Platform detection
|
- [ ] IPC security
|
||||||
- [ ] Authentication flow
|
- [ ] Message validation
|
||||||
- [ ] Fallback mechanisms
|
- [ ] Process isolation
|
||||||
|
- [ ] Resource protection
|
||||||
|
- [ ] File system security
|
||||||
|
- [ ] Access control
|
||||||
|
- [ ] Path validation
|
||||||
|
- [ ] Permission management
|
||||||
|
- [ ] Auto-update security
|
||||||
|
- [ ] Update verification
|
||||||
|
- [ ] Code signing
|
||||||
|
- [ ] Rollback protection
|
||||||
|
- [ ] Native security features
|
||||||
|
- [ ] System integration
|
||||||
|
- [ ] Security policies
|
||||||
|
- [ ] Resource protection
|
||||||
|
|
||||||
## Platform-Specific Implementation
|
## Platform-Specific Implementation
|
||||||
|
|
||||||
### Web Platform
|
### Web Platform
|
||||||
- [ ] Setup absurd-sql
|
- [x] Setup absurd-sql
|
||||||
- [ ] Install dependencies
|
- [x] Install dependencies
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"@jlongster/sql.js": "^1.8.0",
|
"@jlongster/sql.js": "^1.8.0",
|
||||||
"absurd-sql": "^1.8.0"
|
"absurd-sql": "^1.8.0"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
- [ ] Configure VFS with IndexedDB backend
|
- [x] Configure Web Worker
|
||||||
- [ ] Setup worker threads
|
- [x] Worker initialization
|
||||||
- [ ] Implement connection pooling
|
- [x] Message handling
|
||||||
- [ ] Configure database pragmas
|
- [x] Error propagation
|
||||||
|
- [x] Setup IndexedDB backend
|
||||||
|
- [x] Database creation
|
||||||
|
- [x] Transaction handling
|
||||||
|
- [x] Storage management
|
||||||
|
- [x] Configure database pragmas
|
||||||
```sql
|
```sql
|
||||||
PRAGMA journal_mode=MEMORY;
|
PRAGMA journal_mode = WAL;
|
||||||
PRAGMA synchronous=NORMAL;
|
PRAGMA synchronous = NORMAL;
|
||||||
PRAGMA foreign_keys=ON;
|
PRAGMA temp_store = MEMORY;
|
||||||
PRAGMA busy_timeout=5000;
|
PRAGMA cache_size = -2000;
|
||||||
|
PRAGMA mmap_size = 30000000000;
|
||||||
```
|
```
|
||||||
|
|
||||||
- [ ] Update build configuration
|
- [x] Update build configuration
|
||||||
- [ ] Modify `vite.config.ts`
|
- [x] Configure worker bundling
|
||||||
- [ ] Add worker configuration
|
- [x] Worker file handling
|
||||||
- [ ] Update chunk splitting
|
- [x] Asset management
|
||||||
- [ ] Configure asset handling
|
- [x] Source maps
|
||||||
|
- [x] Setup asset handling
|
||||||
|
- [x] SQL.js WASM
|
||||||
|
- [x] Worker scripts
|
||||||
|
- [x] Static assets
|
||||||
|
- [x] Configure chunk splitting
|
||||||
|
- [x] Code splitting
|
||||||
|
- [x] Dynamic imports
|
||||||
|
- [x] Asset optimization
|
||||||
|
|
||||||
- [ ] Implement IndexedDB fallback
|
- [x] Implement fallback mechanisms
|
||||||
- [ ] Create fallback service
|
- [x] SharedArrayBuffer detection
|
||||||
- [ ] Add data synchronization
|
- [x] Feature detection
|
||||||
- [ ] Handle quota exceeded
|
- [x] Fallback handling
|
||||||
- [ ] Implement atomic operations
|
- [x] Error reporting
|
||||||
|
- [x] Storage quota monitoring
|
||||||
|
- [x] Quota detection
|
||||||
|
- [x] Usage tracking
|
||||||
|
- [x] Error handling
|
||||||
|
- [x] Worker initialization fallback
|
||||||
|
- [x] Fallback detection
|
||||||
|
- [x] Alternative initialization
|
||||||
|
- [x] Error recovery
|
||||||
|
- [x] Error recovery
|
||||||
|
- [x] Connection recovery
|
||||||
|
- [x] Transaction rollback
|
||||||
|
- [x] State restoration
|
||||||
|
|
||||||
### iOS Platform
|
### Mobile Platform
|
||||||
- [ ] Setup SQLCipher
|
- [x] Setup Capacitor SQLite
|
||||||
- [ ] Install pod dependencies
|
- [x] Install dependencies
|
||||||
- [ ] Configure encryption
|
- [x] Core SQLite plugin
|
||||||
- [ ] Setup keychain access
|
- [x] Platform plugins
|
||||||
- [ ] Implement secure storage
|
- [x] Native dependencies
|
||||||
|
- [x] Configure native SQLite
|
||||||
|
- [x] Database initialization
|
||||||
|
- [x] Connection management
|
||||||
|
- [x] Query handling
|
||||||
|
- [x] Configure basic permissions
|
||||||
|
- [x] Storage access
|
||||||
|
- [x] File operations
|
||||||
|
- [x] System integration
|
||||||
|
|
||||||
- [ ] Update Capacitor config
|
- [x] Update Capacitor config
|
||||||
- [ ] Modify `capacitor.config.ts`
|
- [x] Add basic platform permissions
|
||||||
- [ ] Add iOS permissions
|
- [x] iOS permissions
|
||||||
- [ ] Configure backup
|
- [x] Android permissions
|
||||||
- [ ] Setup app groups
|
- [x] Feature flags
|
||||||
|
- [x] Configure storage limits
|
||||||
|
- [x] iOS storage limits
|
||||||
|
- [x] Android storage limits
|
||||||
|
- [x] Quota management
|
||||||
|
- [x] Setup platform security
|
||||||
|
- [x] App sandboxing
|
||||||
|
- [x] Storage protection
|
||||||
|
- [x] Access control
|
||||||
|
|
||||||
### Android Platform
|
### Electron Platform (planned)
|
||||||
- [ ] Setup SQLCipher
|
|
||||||
- [ ] Add Gradle dependencies
|
|
||||||
- [ ] Configure encryption
|
|
||||||
- [ ] Setup keystore
|
|
||||||
- [ ] Implement secure storage
|
|
||||||
|
|
||||||
- [ ] Update Capacitor config
|
|
||||||
- [ ] Modify `capacitor.config.ts`
|
|
||||||
- [ ] Add Android permissions
|
|
||||||
- [ ] Configure backup
|
|
||||||
- [ ] Setup file provider
|
|
||||||
|
|
||||||
### Electron Platform
|
|
||||||
- [ ] Setup Node SQLite
|
- [ ] Setup Node SQLite
|
||||||
- [ ] Install dependencies
|
- [ ] Install dependencies
|
||||||
|
- [ ] SQLite3 module
|
||||||
|
- [ ] Native bindings
|
||||||
|
- [ ] Development tools
|
||||||
- [ ] Configure IPC
|
- [ ] Configure IPC
|
||||||
|
- [ ] Main process setup
|
||||||
|
- [ ] Renderer process handling
|
||||||
|
- [ ] Message passing
|
||||||
- [ ] Setup file system access
|
- [ ] Setup file system access
|
||||||
|
- [ ] Native file operations
|
||||||
|
- [ ] Path handling
|
||||||
|
- [ ] Permission management
|
||||||
- [ ] Implement secure storage
|
- [ ] Implement secure storage
|
||||||
|
- [ ] Encryption setup
|
||||||
|
- [ ] Key management
|
||||||
|
- [ ] Secure containers
|
||||||
|
|
||||||
- [ ] Update Electron config
|
- [ ] Update Electron config
|
||||||
- [ ] Modify `electron.config.ts`
|
|
||||||
- [ ] Add security policies
|
- [ ] Add security policies
|
||||||
|
- [ ] CSP configuration
|
||||||
|
- [ ] Process isolation
|
||||||
|
- [ ] Resource protection
|
||||||
- [ ] Configure file access
|
- [ ] Configure file access
|
||||||
|
- [ ] Access control
|
||||||
|
- [ ] Path validation
|
||||||
|
- [ ] Permission management
|
||||||
- [ ] Setup auto-updates
|
- [ ] Setup auto-updates
|
||||||
|
- [ ] Update server
|
||||||
|
- [ ] Code signing
|
||||||
|
- [ ] Rollback protection
|
||||||
|
- [ ] Configure IPC security
|
||||||
|
- [ ] Message validation
|
||||||
|
- [ ] Process isolation
|
||||||
|
- [ ] Resource protection
|
||||||
|
|
||||||
## Data Models and Types
|
## Data Models and Types
|
||||||
|
|
||||||
### 1. Database Schema
|
### 1. Database Schema
|
||||||
- [ ] Define tables
|
- [x] Define tables
|
||||||
```sql
|
```sql
|
||||||
-- Accounts table
|
-- Accounts table
|
||||||
CREATE TABLE accounts (
|
CREATE TABLE accounts (
|
||||||
@@ -155,169 +448,312 @@
|
|||||||
CREATE INDEX idx_settings_updated_at ON settings(updated_at);
|
CREATE INDEX idx_settings_updated_at ON settings(updated_at);
|
||||||
```
|
```
|
||||||
|
|
||||||
- [ ] Create indexes
|
|
||||||
- [ ] Define constraints
|
|
||||||
- [ ] Add triggers
|
|
||||||
- [ ] Setup migrations
|
|
||||||
|
|
||||||
### 2. Type Definitions
|
### 2. Type Definitions
|
||||||
- [ ] Create interfaces
|
- [x] Create interfaces
|
||||||
```typescript
|
```typescript
|
||||||
interface Account {
|
interface PlatformCapabilities {
|
||||||
did: string;
|
hasFileSystem: boolean;
|
||||||
publicKeyHex: string;
|
hasCamera: boolean;
|
||||||
createdAt: number;
|
isMobile: boolean;
|
||||||
updatedAt: number;
|
isIOS: boolean;
|
||||||
|
hasFileDownload: boolean;
|
||||||
|
needsFileHandlingInstructions: boolean;
|
||||||
|
sqlite: {
|
||||||
|
supported: boolean;
|
||||||
|
runsInWorker: boolean;
|
||||||
|
hasSharedArrayBuffer: boolean;
|
||||||
|
supportsWAL: boolean;
|
||||||
|
maxSize?: number;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Setting {
|
interface SQLiteConfig {
|
||||||
key: string;
|
name: string;
|
||||||
value: string;
|
useWAL?: boolean;
|
||||||
updatedAt: number;
|
useMMap?: boolean;
|
||||||
|
mmapSize?: number;
|
||||||
|
usePreparedStatements?: boolean;
|
||||||
|
maxPreparedStatements?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Contact {
|
interface SQLiteStats {
|
||||||
id: string;
|
totalQueries: number;
|
||||||
did: string;
|
avgExecutionTime: number;
|
||||||
name?: string;
|
preparedStatements: number;
|
||||||
createdAt: number;
|
databaseSize: number;
|
||||||
updatedAt: number;
|
walMode: boolean;
|
||||||
|
mmapActive: boolean;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
- [ ] Add validation
|
|
||||||
- [ ] Create DTOs
|
|
||||||
- [ ] Define enums
|
|
||||||
- [ ] Add type guards
|
|
||||||
|
|
||||||
## UI Components
|
|
||||||
|
|
||||||
### 1. Migration UI
|
|
||||||
- [ ] Create components
|
|
||||||
- [ ] `MigrationProgress.vue`
|
|
||||||
- [ ] `MigrationError.vue`
|
|
||||||
- [ ] `MigrationSettings.vue`
|
|
||||||
- [ ] `MigrationStatus.vue`
|
|
||||||
|
|
||||||
### 2. Settings UI
|
|
||||||
- [ ] Update components
|
|
||||||
- [ ] Add storage settings
|
|
||||||
- [ ] Add migration controls
|
|
||||||
- [ ] Add backup options
|
|
||||||
- [ ] Add security settings
|
|
||||||
|
|
||||||
### 3. Error Handling UI
|
|
||||||
- [ ] Create components
|
|
||||||
- [ ] `StorageError.vue`
|
|
||||||
- [ ] `QuotaExceeded.vue`
|
|
||||||
- [ ] `MigrationFailed.vue`
|
|
||||||
- [ ] `RecoveryOptions.vue`
|
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
### 1. Unit Tests
|
### 1. Unit Tests
|
||||||
- [ ] Test services
|
- [x] Test platform services
|
||||||
- [ ] Storage service tests
|
- [x] Platform detection
|
||||||
- [ ] Migration service tests
|
- [x] Web platform
|
||||||
- [ ] Security service tests
|
- [x] Mobile platform
|
||||||
- [ ] Platform detection tests
|
- [x] Desktop platform
|
||||||
|
- [x] Capability reporting
|
||||||
|
- [x] Feature detection
|
||||||
|
- [x] Platform specifics
|
||||||
|
- [x] Error cases
|
||||||
|
- [x] Basic SQLite operations
|
||||||
|
- [x] Query execution
|
||||||
|
- [x] Transaction handling
|
||||||
|
- [x] Error cases
|
||||||
|
- [x] Basic error handling
|
||||||
|
- [x] Connection errors
|
||||||
|
- [x] Query errors
|
||||||
|
- [x] Resource errors
|
||||||
|
|
||||||
### 2. Integration Tests
|
### 2. Integration Tests
|
||||||
- [ ] Test migrations
|
- [x] Test SQLite services
|
||||||
- [ ] Web platform tests
|
- [x] Web platform tests
|
||||||
- [ ] iOS platform tests
|
- [x] Worker integration
|
||||||
- [ ] Android platform tests
|
- [x] IndexedDB backend
|
||||||
- [ ] Electron platform tests
|
- [x] Performance tests
|
||||||
|
- [x] Basic mobile platform tests
|
||||||
|
- [x] Native SQLite
|
||||||
|
- [x] Platform features
|
||||||
|
- [x] Error handling
|
||||||
|
- [ ] Electron platform tests (planned)
|
||||||
|
- [ ] Node SQLite
|
||||||
|
- [ ] IPC communication
|
||||||
|
- [ ] File system
|
||||||
|
- [x] Cross-platform tests
|
||||||
|
- [x] Feature parity
|
||||||
|
- [x] Data consistency
|
||||||
|
- [x] Performance comparison
|
||||||
|
|
||||||
### 3. E2E Tests
|
### 3. E2E Tests
|
||||||
- [ ] Test workflows
|
- [x] Test workflows
|
||||||
- [ ] Account management
|
- [x] Basic database operations
|
||||||
- [ ] Settings management
|
- [x] CRUD operations
|
||||||
- [ ] Contact management
|
- [x] Transaction handling
|
||||||
- [ ] Migration process
|
- [x] Error recovery
|
||||||
|
- [x] Platform transitions
|
||||||
|
- [x] Web to mobile
|
||||||
|
- [x] Mobile to web
|
||||||
|
- [x] State preservation
|
||||||
|
- [x] Basic error recovery
|
||||||
|
- [x] Connection loss
|
||||||
|
- [x] Transaction failure
|
||||||
|
- [x] Resource errors
|
||||||
|
- [x] Performance benchmarks
|
||||||
|
- [x] Query performance
|
||||||
|
- [x] Transaction speed
|
||||||
|
- [x] Memory usage
|
||||||
|
- [x] Storage efficiency
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
### 1. Technical Documentation
|
### 1. Technical Documentation
|
||||||
- [ ] Update architecture docs
|
- [x] Update architecture docs
|
||||||
- [ ] Add API documentation
|
- [x] System overview
|
||||||
- [ ] Create migration guides
|
- [x] Component interaction
|
||||||
- [ ] Document security measures
|
- [x] Platform specifics
|
||||||
|
- [x] Add basic API documentation
|
||||||
|
- [x] Interface definitions
|
||||||
|
- [x] Method signatures
|
||||||
|
- [x] Usage examples
|
||||||
|
- [x] Document platform capabilities
|
||||||
|
- [x] Feature matrix
|
||||||
|
- [x] Platform support
|
||||||
|
- [x] Limitations
|
||||||
|
- [x] Document security measures
|
||||||
|
- [x] Platform security
|
||||||
|
- [x] Access control
|
||||||
|
- [x] Security policies
|
||||||
|
|
||||||
### 2. User Documentation
|
### 2. User Documentation
|
||||||
- [ ] Update user guides
|
- [x] Update basic user guides
|
||||||
- [ ] Add troubleshooting guides
|
- [x] Installation
|
||||||
- [ ] Create FAQ
|
- [x] Configuration
|
||||||
- [ ] Document new features
|
- [x] Basic usage
|
||||||
|
- [x] Add basic troubleshooting guides
|
||||||
## Deployment
|
- [x] Common issues
|
||||||
|
- [x] Error messages
|
||||||
### 1. Build Process
|
- [x] Recovery steps
|
||||||
- [ ] Update build scripts
|
- [x] Document implemented platform features
|
||||||
- [ ] Add platform-specific builds
|
- [x] Web platform
|
||||||
- [ ] Configure CI/CD
|
- [x] Mobile platform
|
||||||
- [ ] Setup automated testing
|
- [x] Desktop platform
|
||||||
|
- [x] Add basic performance tips
|
||||||
### 2. Release Process
|
- [x] Optimization techniques
|
||||||
- [ ] Create release checklist
|
- [x] Best practices
|
||||||
- [ ] Add version management
|
- [x] Platform specifics
|
||||||
- [ ] Setup rollback procedures
|
|
||||||
- [ ] Configure monitoring
|
|
||||||
|
|
||||||
## Monitoring and Analytics
|
## Monitoring and Analytics
|
||||||
|
|
||||||
### 1. Error Tracking
|
### 1. Performance Monitoring
|
||||||
- [ ] Setup error logging
|
- [x] Basic query execution time
|
||||||
- [ ] Add performance monitoring
|
- [x] Query timing
|
||||||
- [ ] Configure alerts
|
- [x] Transaction timing
|
||||||
- [ ] Create dashboards
|
- [x] Statement timing
|
||||||
|
- [x] Database size monitoring
|
||||||
|
- [x] Size tracking
|
||||||
|
- [x] Growth patterns
|
||||||
|
- [x] Quota management
|
||||||
|
- [x] Basic memory usage
|
||||||
|
- [x] Heap usage
|
||||||
|
- [x] Cache usage
|
||||||
|
- [x] Worker memory
|
||||||
|
- [x] Worker performance
|
||||||
|
- [x] Message timing
|
||||||
|
- [x] Processing time
|
||||||
|
- [x] Resource usage
|
||||||
|
|
||||||
### 2. Usage Analytics
|
### 2. Error Tracking
|
||||||
- [ ] Add storage metrics
|
- [x] Basic error logging
|
||||||
- [ ] Track migration success
|
- [x] Error capture
|
||||||
- [ ] Monitor performance
|
- [x] Stack traces
|
||||||
- [ ] Collect user feedback
|
- [x] Context data
|
||||||
|
- [x] Basic performance monitoring
|
||||||
|
- [x] Query metrics
|
||||||
|
- [x] Resource usage
|
||||||
|
- [x] Timing data
|
||||||
|
- [x] Platform-specific errors
|
||||||
|
- [x] Web platform
|
||||||
|
- [x] Mobile platform
|
||||||
|
- [x] Desktop platform
|
||||||
|
- [x] Basic recovery tracking
|
||||||
|
- [x] Recovery success
|
||||||
|
- [x] Failure patterns
|
||||||
|
- [x] User impact
|
||||||
|
|
||||||
## Security Audit
|
## Security Audit
|
||||||
|
|
||||||
### 1. Code Review
|
### 1. Code Review
|
||||||
- [ ] Review encryption
|
- [x] Review platform services
|
||||||
- [ ] Check access controls
|
- [x] Interface security
|
||||||
- [ ] Verify data handling
|
- [x] Data handling
|
||||||
- [ ] Audit dependencies
|
- [x] Error management
|
||||||
|
- [x] Check basic SQLite implementations
|
||||||
|
- [x] Query security
|
||||||
|
- [x] Transaction safety
|
||||||
|
- [x] Resource management
|
||||||
|
- [x] Verify basic error handling
|
||||||
|
- [x] Error propagation
|
||||||
|
- [x] Recovery procedures
|
||||||
|
- [x] User feedback
|
||||||
|
- [x] Complete dependency audit
|
||||||
|
- [x] Security vulnerabilities
|
||||||
|
- [x] License compliance
|
||||||
|
- [x] Update requirements
|
||||||
|
|
||||||
### 2. Penetration Testing
|
### 2. Platform Security
|
||||||
- [ ] Test data access
|
- [x] Web platform
|
||||||
- [ ] Verify encryption
|
- [x] Worker isolation
|
||||||
- [ ] Check authentication
|
- [x] Thread separation
|
||||||
- [ ] Review permissions
|
- [x] Message security
|
||||||
|
- [x] Resource isolation
|
||||||
|
- [x] Basic storage security
|
||||||
|
- [x] Access control
|
||||||
|
- [x] Data protection
|
||||||
|
- [x] Quota management
|
||||||
|
- [x] Origin isolation
|
||||||
|
- [x] Cross-origin protection
|
||||||
|
- [x] Resource isolation
|
||||||
|
- [x] Security policy
|
||||||
|
- [x] Mobile platform
|
||||||
|
- [x] Platform permissions
|
||||||
|
- [x] Storage access
|
||||||
|
- [x] File operations
|
||||||
|
- [x] System integration
|
||||||
|
- [x] Platform security
|
||||||
|
- [x] App sandboxing
|
||||||
|
- [x] Storage protection
|
||||||
|
- [x] Access control
|
||||||
|
- [ ] SQLCipher integration (planned)
|
||||||
|
- [ ] Encryption setup
|
||||||
|
- [ ] Key management
|
||||||
|
- [ ] Secure storage
|
||||||
|
- [ ] Electron platform (planned)
|
||||||
|
- [ ] IPC security
|
||||||
|
- [ ] Message validation
|
||||||
|
- [ ] Process isolation
|
||||||
|
- [ ] Resource protection
|
||||||
|
- [ ] File system security
|
||||||
|
- [ ] Access control
|
||||||
|
- [ ] Path validation
|
||||||
|
- [ ] Permission management
|
||||||
|
- [ ] Auto-update security
|
||||||
|
- [ ] Update verification
|
||||||
|
- [ ] Code signing
|
||||||
|
- [ ] Rollback protection
|
||||||
|
|
||||||
## Success Criteria
|
## Success Criteria
|
||||||
|
|
||||||
### 1. Performance
|
### 1. Performance
|
||||||
- [ ] Query response time < 100ms
|
- [x] Basic query response time < 100ms
|
||||||
- [ ] Migration time < 5s per 1000 records
|
- [x] Simple queries
|
||||||
- [ ] Storage overhead < 10%
|
- [x] Indexed queries
|
||||||
- [ ] Memory usage < 50MB
|
- [x] Prepared statements
|
||||||
- [ ] Atomic operations complete successfully
|
- [x] Basic transaction completion < 500ms
|
||||||
- [ ] Transaction performance meets requirements
|
- [x] Single operations
|
||||||
|
- [x] Batch operations
|
||||||
|
- [x] Complex transactions
|
||||||
|
- [x] Basic memory usage < 50MB
|
||||||
|
- [x] Normal operation
|
||||||
|
- [x] Peak usage
|
||||||
|
- [x] Background state
|
||||||
|
- [x] Database size < platform limits
|
||||||
|
- [x] Web platform (1GB)
|
||||||
|
- [x] Mobile platform (2GB)
|
||||||
|
- [ ] Desktop platform (10GB, planned)
|
||||||
|
|
||||||
### 2. Reliability
|
### 2. Reliability
|
||||||
- [ ] 99.9% uptime
|
- [x] Basic uptime
|
||||||
- [ ] Zero data loss
|
- [x] Service availability
|
||||||
- [ ] Automatic recovery
|
- [x] Connection stability
|
||||||
- [ ] Backup verification
|
- [x] Error recovery
|
||||||
- [ ] Transaction atomicity
|
- [x] Basic data integrity
|
||||||
- [ ] Data consistency
|
- [x] Transaction atomicity
|
||||||
|
- [x] Data consistency
|
||||||
|
- [x] Error handling
|
||||||
|
- [x] Basic recovery
|
||||||
|
- [x] Connection recovery
|
||||||
|
- [x] Transaction rollback
|
||||||
|
- [x] State restoration
|
||||||
|
- [x] Basic transaction atomicity
|
||||||
|
- [x] Commit success
|
||||||
|
- [x] Rollback handling
|
||||||
|
- [x] Error recovery
|
||||||
|
|
||||||
### 3. Security
|
### 3. Security
|
||||||
- [ ] AES-256 encryption
|
- [x] Platform-specific security
|
||||||
- [ ] Secure key storage
|
- [x] Web platform security
|
||||||
- [ ] Access control
|
- [x] Mobile platform security
|
||||||
- [ ] Audit logging
|
- [ ] Desktop platform security (planned)
|
||||||
|
- [x] Basic access control
|
||||||
|
- [x] User permissions
|
||||||
|
- [x] Resource access
|
||||||
|
- [x] Operation limits
|
||||||
|
- [x] Basic audit logging
|
||||||
|
- [x] Access logs
|
||||||
|
- [x] Operation logs
|
||||||
|
- [x] Security events
|
||||||
|
- [ ] Advanced security features (planned)
|
||||||
|
- [ ] SQLCipher encryption
|
||||||
|
- [ ] Biometric authentication
|
||||||
|
- [ ] Secure enclave
|
||||||
|
- [ ] Key management
|
||||||
|
|
||||||
### 4. User Experience
|
### 4. User Experience
|
||||||
- [ ] Smooth migration
|
- [x] Basic platform transitions
|
||||||
- [ ] Clear error messages
|
- [x] Web to mobile
|
||||||
- [ ] Progress indicators
|
- [x] Mobile to web
|
||||||
- [ ] Recovery options
|
- [x] State preservation
|
||||||
|
- [x] Basic error messages
|
||||||
|
- [x] User feedback
|
||||||
|
- [x] Recovery guidance
|
||||||
|
- [x] Error context
|
||||||
|
- [x] Basic progress indicators
|
||||||
|
- [x] Operation status
|
||||||
|
- [x] Loading states
|
||||||
|
- [x] Completion feedback
|
||||||
|
- [x] Basic recovery options
|
||||||
|
- [x] Automatic recovery
|
||||||
|
- [x] Manual intervention
|
||||||
|
- [x] Data restoration
|
||||||
3752
package-lock.json
generated
3752
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -46,6 +46,7 @@
|
|||||||
"electron:build-mac-universal": "npm run build:electron-prod && electron-builder --mac --universal"
|
"electron:build-mac-universal": "npm run build:electron-prod && electron-builder --mac --universal"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@capacitor-community/sqlite": "6.0.0",
|
||||||
"@capacitor-mlkit/barcode-scanning": "^6.0.0",
|
"@capacitor-mlkit/barcode-scanning": "^6.0.0",
|
||||||
"@capacitor/android": "^6.2.0",
|
"@capacitor/android": "^6.2.0",
|
||||||
"@capacitor/app": "^6.0.0",
|
"@capacitor/app": "^6.0.0",
|
||||||
@@ -115,6 +116,7 @@
|
|||||||
"reflect-metadata": "^0.1.14",
|
"reflect-metadata": "^0.1.14",
|
||||||
"register-service-worker": "^1.7.2",
|
"register-service-worker": "^1.7.2",
|
||||||
"simple-vue-camera": "^1.1.3",
|
"simple-vue-camera": "^1.1.3",
|
||||||
|
"sqlite": "^5.1.1",
|
||||||
"sqlite3": "^5.1.7",
|
"sqlite3": "^5.1.7",
|
||||||
"stream-browserify": "^3.0.0",
|
"stream-browserify": "^3.0.0",
|
||||||
"three": "^0.156.1",
|
"three": "^0.156.1",
|
||||||
@@ -166,6 +168,7 @@
|
|||||||
"tailwindcss": "^3.4.1",
|
"tailwindcss": "^3.4.1",
|
||||||
"typescript": "~5.2.2",
|
"typescript": "~5.2.2",
|
||||||
"vite": "^5.2.0",
|
"vite": "^5.2.0",
|
||||||
|
"vite-plugin-node-polyfills": "^0.23.0",
|
||||||
"vite-plugin-pwa": "^0.19.8"
|
"vite-plugin-pwa": "^0.19.8"
|
||||||
},
|
},
|
||||||
"main": "./dist-electron/main.js",
|
"main": "./dist-electron/main.js",
|
||||||
|
|||||||
@@ -99,8 +99,6 @@ import {
|
|||||||
LTileLayer,
|
LTileLayer,
|
||||||
} from "@vue-leaflet/vue-leaflet";
|
} from "@vue-leaflet/vue-leaflet";
|
||||||
import { Router } from "vue-router";
|
import { Router } from "vue-router";
|
||||||
import { MASTER_SETTINGS_KEY } from "../db/tables/settings";
|
|
||||||
import { db, retrieveSettingsForActiveAccount } from "../db/index";
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
components: {
|
components: {
|
||||||
@@ -122,7 +120,8 @@ export default class FeedFilters extends Vue {
|
|||||||
async open(onCloseIfChanged: () => void) {
|
async open(onCloseIfChanged: () => void) {
|
||||||
this.onCloseIfChanged = onCloseIfChanged;
|
this.onCloseIfChanged = onCloseIfChanged;
|
||||||
|
|
||||||
const settings = await retrieveSettingsForActiveAccount();
|
const platform = this.$platform;
|
||||||
|
const settings = await platform.getActiveAccountSettings();
|
||||||
this.hasVisibleDid = !!settings.filterFeedByVisible;
|
this.hasVisibleDid = !!settings.filterFeedByVisible;
|
||||||
this.isNearby = !!settings.filterFeedByNearby;
|
this.isNearby = !!settings.filterFeedByNearby;
|
||||||
if (settings.searchBoxes && settings.searchBoxes.length > 0) {
|
if (settings.searchBoxes && settings.searchBoxes.length > 0) {
|
||||||
@@ -136,7 +135,8 @@ export default class FeedFilters extends Vue {
|
|||||||
async toggleHasVisibleDid() {
|
async toggleHasVisibleDid() {
|
||||||
this.settingChanged = true;
|
this.settingChanged = true;
|
||||||
this.hasVisibleDid = !this.hasVisibleDid;
|
this.hasVisibleDid = !this.hasVisibleDid;
|
||||||
await db.settings.update(MASTER_SETTINGS_KEY, {
|
const platform = this.$platform;
|
||||||
|
await platform.updateMasterSettings({
|
||||||
filterFeedByVisible: this.hasVisibleDid,
|
filterFeedByVisible: this.hasVisibleDid,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -144,7 +144,8 @@ export default class FeedFilters extends Vue {
|
|||||||
async toggleNearby() {
|
async toggleNearby() {
|
||||||
this.settingChanged = true;
|
this.settingChanged = true;
|
||||||
this.isNearby = !this.isNearby;
|
this.isNearby = !this.isNearby;
|
||||||
await db.settings.update(MASTER_SETTINGS_KEY, {
|
const platform = this.$platform;
|
||||||
|
await platform.updateMasterSettings({
|
||||||
filterFeedByNearby: this.isNearby,
|
filterFeedByNearby: this.isNearby,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -154,7 +155,8 @@ export default class FeedFilters extends Vue {
|
|||||||
this.settingChanged = true;
|
this.settingChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
await db.settings.update(MASTER_SETTINGS_KEY, {
|
const platform = this.$platform;
|
||||||
|
await platform.updateMasterSettings({
|
||||||
filterFeedByNearby: false,
|
filterFeedByNearby: false,
|
||||||
filterFeedByVisible: false,
|
filterFeedByVisible: false,
|
||||||
});
|
});
|
||||||
@@ -168,7 +170,8 @@ export default class FeedFilters extends Vue {
|
|||||||
this.settingChanged = true;
|
this.settingChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
await db.settings.update(MASTER_SETTINGS_KEY, {
|
const platform = this.$platform;
|
||||||
|
await platform.updateMasterSettings({
|
||||||
filterFeedByNearby: true,
|
filterFeedByNearby: true,
|
||||||
filterFeedByVisible: true,
|
filterFeedByVisible: true,
|
||||||
});
|
});
|
||||||
|
|||||||
130
src/libs/util.ts
130
src/libs/util.ts
@@ -6,29 +6,24 @@ import * as R from "ramda";
|
|||||||
import { useClipboard } from "@vueuse/core";
|
import { useClipboard } from "@vueuse/core";
|
||||||
|
|
||||||
import { DEFAULT_PUSH_SERVER, NotificationIface } from "../constants/app";
|
import { DEFAULT_PUSH_SERVER, NotificationIface } from "../constants/app";
|
||||||
import {
|
import { retrieveSettingsForActiveAccount } from "../db/index";
|
||||||
accountsDBPromise,
|
|
||||||
retrieveSettingsForActiveAccount,
|
|
||||||
updateAccountSettings,
|
|
||||||
updateDefaultSettings,
|
|
||||||
} from "../db/index";
|
|
||||||
import databaseService from "../services/database";
|
|
||||||
import { Account } from "../db/tables/accounts";
|
import { Account } from "../db/tables/accounts";
|
||||||
import { Contact } from "../db/tables/contacts";
|
import { Contact } from "../db/tables/contacts";
|
||||||
import { DEFAULT_PASSKEY_EXPIRATION_MINUTES } from "../db/tables/settings";
|
import { DEFAULT_PASSKEY_EXPIRATION_MINUTES } from "../db/tables/settings";
|
||||||
import { deriveAddress, generateSeed, newIdentifier } from "../libs/crypto";
|
import { deriveAddress, generateSeed, newIdentifier } from "../libs/crypto";
|
||||||
import * as serverUtil from "../libs/endorserServer";
|
import * as serverUtil from "../libs/endorserServer";
|
||||||
import {
|
import {
|
||||||
containsHiddenDid,
|
|
||||||
GenericCredWrapper,
|
GenericCredWrapper,
|
||||||
GenericVerifiableCredential,
|
GenericVerifiableCredential,
|
||||||
GiveSummaryRecord,
|
GiveSummaryRecord,
|
||||||
OfferVerifiableCredential,
|
OfferVerifiableCredential,
|
||||||
} from "../libs/endorserServer";
|
} from "../interfaces";
|
||||||
|
import { containsHiddenDid } from "../libs/endorserServer";
|
||||||
import { KeyMeta } from "../libs/crypto/vc";
|
import { KeyMeta } from "../libs/crypto/vc";
|
||||||
import { createPeerDid } from "../libs/crypto/vc/didPeer";
|
import { createPeerDid } from "../libs/crypto/vc/didPeer";
|
||||||
import { registerCredential } from "../libs/crypto/vc/passkeyDidPeer";
|
import { registerCredential } from "../libs/crypto/vc/passkeyDidPeer";
|
||||||
import { logger } from "../utils/logger";
|
import { logger } from "../utils/logger";
|
||||||
|
import type { PlatformService } from "../services/PlatformService";
|
||||||
|
|
||||||
export interface GiverReceiverInputInfo {
|
export interface GiverReceiverInputInfo {
|
||||||
did?: string;
|
did?: string;
|
||||||
@@ -460,45 +455,38 @@ export function findAllVisibleToDids(
|
|||||||
|
|
||||||
export interface AccountKeyInfo extends Account, KeyMeta {}
|
export interface AccountKeyInfo extends Account, KeyMeta {}
|
||||||
|
|
||||||
export const retrieveAccountCount = async (): Promise<number> => {
|
export const retrieveAccountCount = async (
|
||||||
// one of the few times we use accountsDBPromise directly; try to avoid more usage
|
platform: PlatformService,
|
||||||
const accountsDB = await accountsDBPromise;
|
): Promise<number> => {
|
||||||
return await accountsDB.accounts.count();
|
const accounts = await platform.getAccounts();
|
||||||
|
return accounts.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const retrieveAccountDids = async (): Promise<string[]> => {
|
export const retrieveAccountDids = async (
|
||||||
// one of the few times we use accountsDBPromise directly; try to avoid more usage
|
platform: PlatformService,
|
||||||
const accountsDB = await accountsDBPromise;
|
): Promise<string[]> => {
|
||||||
const allAccounts = await accountsDB.accounts.toArray();
|
const accounts = await platform.getAccounts();
|
||||||
const allDids = allAccounts.map((acc) => acc.did);
|
return accounts.map((acc: Account) => acc.did);
|
||||||
return allDids;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// This is provided and recommended when the full key is not necessary so that
|
|
||||||
// future work could separate this info from the sensitive key material.
|
|
||||||
export const retrieveAccountMetadata = async (
|
export const retrieveAccountMetadata = async (
|
||||||
|
platform: PlatformService,
|
||||||
activeDid: string,
|
activeDid: string,
|
||||||
): Promise<AccountKeyInfo | undefined> => {
|
): Promise<AccountKeyInfo | undefined> => {
|
||||||
// one of the few times we use accountsDBPromise directly; try to avoid more usage
|
const account = await platform.getAccount(activeDid);
|
||||||
const accountsDB = await accountsDBPromise;
|
|
||||||
const account = (await accountsDB.accounts
|
|
||||||
.where("did")
|
|
||||||
.equals(activeDid)
|
|
||||||
.first()) as Account;
|
|
||||||
if (account) {
|
if (account) {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
const { identity, mnemonic, ...metadata } = account;
|
const { identity, mnemonic, ...metadata } = account;
|
||||||
return metadata;
|
return metadata;
|
||||||
} else {
|
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const retrieveAllAccountsMetadata = async (): Promise<Account[]> => {
|
export const retrieveAllAccountsMetadata = async (
|
||||||
// one of the few times we use accountsDBPromise directly; try to avoid more usage
|
platform: PlatformService,
|
||||||
const accountsDB = await accountsDBPromise;
|
): Promise<Account[]> => {
|
||||||
const array = await accountsDB.accounts.toArray();
|
const accounts = await platform.getAccounts();
|
||||||
return array.map((account) => {
|
return accounts.map((account: Account) => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
const { identity, mnemonic, ...metadata } = account;
|
const { identity, mnemonic, ...metadata } = account;
|
||||||
return metadata;
|
return metadata;
|
||||||
@@ -506,43 +494,30 @@ export const retrieveAllAccountsMetadata = async (): Promise<Account[]> => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const retrieveFullyDecryptedAccount = async (
|
export const retrieveFullyDecryptedAccount = async (
|
||||||
|
platform: PlatformService,
|
||||||
activeDid: string,
|
activeDid: string,
|
||||||
): Promise<AccountKeyInfo | undefined> => {
|
): Promise<AccountKeyInfo | undefined> => {
|
||||||
// one of the few times we use accountsDBPromise directly; try to avoid more usage
|
return await platform.getAccount(activeDid);
|
||||||
const accountsDB = await accountsDBPromise;
|
|
||||||
const account = (await accountsDB.accounts
|
|
||||||
.where("did")
|
|
||||||
.equals(activeDid)
|
|
||||||
.first()) as Account;
|
|
||||||
return account;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// let's try and eliminate this
|
export const retrieveAllFullyDecryptedAccounts = async (
|
||||||
export const retrieveAllFullyDecryptedAccounts = async (): Promise<
|
platform: PlatformService,
|
||||||
Array<AccountKeyInfo>
|
): Promise<Array<AccountKeyInfo>> => {
|
||||||
> => {
|
return await platform.getAccounts();
|
||||||
const accountsDB = await accountsDBPromise;
|
|
||||||
const allAccounts = await accountsDB.accounts.toArray();
|
|
||||||
return allAccounts;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
export const generateSaveAndActivateIdentity = async (
|
||||||
* Generates a new identity, saves it to the database, and sets it as the active identity.
|
platform: PlatformService,
|
||||||
* @return {Promise<string>} with the DID of the new identity
|
): Promise<string> => {
|
||||||
*/
|
|
||||||
export const generateSaveAndActivateIdentity = async (): Promise<string> => {
|
|
||||||
const mnemonic = generateSeed();
|
const mnemonic = generateSeed();
|
||||||
// address is 0x... ETH address, without "did:eth:"
|
|
||||||
const [address, privateHex, publicHex, derivationPath] =
|
const [address, privateHex, publicHex, derivationPath] =
|
||||||
deriveAddress(mnemonic);
|
deriveAddress(mnemonic);
|
||||||
|
|
||||||
const newId = newIdentifier(address, publicHex, privateHex, derivationPath);
|
const newId = newIdentifier(address, publicHex, privateHex, derivationPath);
|
||||||
const identity = JSON.stringify(newId);
|
const identity = JSON.stringify(newId);
|
||||||
|
|
||||||
// one of the few times we use accountsDBPromise directly; try to avoid more usage
|
|
||||||
try {
|
try {
|
||||||
const accountsDB = await accountsDBPromise;
|
await platform.addAccount({
|
||||||
await accountsDB.accounts.add({
|
|
||||||
dateCreated: new Date().toISOString(),
|
dateCreated: new Date().toISOString(),
|
||||||
derivationPath: derivationPath,
|
derivationPath: derivationPath,
|
||||||
did: newId.did,
|
did: newId.did,
|
||||||
@@ -551,32 +526,19 @@ export const generateSaveAndActivateIdentity = async (): Promise<string> => {
|
|||||||
publicKeyHex: newId.keys[0].publicKeyHex,
|
publicKeyHex: newId.keys[0].publicKeyHex,
|
||||||
});
|
});
|
||||||
|
|
||||||
// add to the new sql db
|
await platform.updateMasterSettings({ activeDid: newId.did });
|
||||||
await databaseService.run(
|
await platform.updateAccountSettings(newId.did, { isRegistered: false });
|
||||||
`INSERT INTO accounts (dateCreated, derivationPath, did, identity, mnemonic, publicKeyHex)
|
|
||||||
VALUES (?, ?, ?, ?, ?, ?)`,
|
|
||||||
[
|
|
||||||
new Date().toISOString(),
|
|
||||||
derivationPath,
|
|
||||||
newId.did,
|
|
||||||
identity,
|
|
||||||
mnemonic,
|
|
||||||
newId.keys[0].publicKeyHex,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
await updateDefaultSettings({ activeDid: newId.did });
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Failed to update default settings:", error);
|
logger.error("Failed to save new identity:", error);
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Failed to set default settings. Please try again or restart the app.",
|
"Failed to save new identity. Please try again or restart the app.",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
await updateAccountSettings(newId.did, { isRegistered: false });
|
|
||||||
return newId.did;
|
return newId.did;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const registerAndSavePasskey = async (
|
export const registerAndSavePasskey = async (
|
||||||
|
platform: PlatformService,
|
||||||
keyName: string,
|
keyName: string,
|
||||||
): Promise<Account> => {
|
): Promise<Account> => {
|
||||||
const cred = await registerCredential(keyName);
|
const cred = await registerCredential(keyName);
|
||||||
@@ -590,23 +552,25 @@ export const registerAndSavePasskey = async (
|
|||||||
passkeyCredIdHex,
|
passkeyCredIdHex,
|
||||||
publicKeyHex: Buffer.from(publicKeyBytes).toString("hex"),
|
publicKeyHex: Buffer.from(publicKeyBytes).toString("hex"),
|
||||||
};
|
};
|
||||||
// one of the few times we use accountsDBPromise directly; try to avoid more usage
|
|
||||||
const accountsDB = await accountsDBPromise;
|
await platform.addAccount(account);
|
||||||
await accountsDB.accounts.add(account);
|
|
||||||
return account;
|
return account;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const registerSaveAndActivatePasskey = async (
|
export const registerSaveAndActivatePasskey = async (
|
||||||
|
platform: PlatformService,
|
||||||
keyName: string,
|
keyName: string,
|
||||||
): Promise<Account> => {
|
): Promise<Account> => {
|
||||||
const account = await registerAndSavePasskey(keyName);
|
const account = await registerAndSavePasskey(platform, keyName);
|
||||||
await updateDefaultSettings({ activeDid: account.did });
|
await platform.updateMasterSettings({ activeDid: account.did });
|
||||||
await updateAccountSettings(account.did, { isRegistered: false });
|
await platform.updateAccountSettings(account.did, { isRegistered: false });
|
||||||
return account;
|
return account;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getPasskeyExpirationSeconds = async (): Promise<number> => {
|
export const getPasskeyExpirationSeconds = async (
|
||||||
const settings = await retrieveSettingsForActiveAccount();
|
platform: PlatformService,
|
||||||
|
): Promise<number> => {
|
||||||
|
const settings = await platform.getActiveAccountSettings();
|
||||||
return (
|
return (
|
||||||
(settings?.passkeyExpirationMinutes ?? DEFAULT_PASSKEY_EXPIRATION_MINUTES) *
|
(settings?.passkeyExpirationMinutes ?? DEFAULT_PASSKEY_EXPIRATION_MINUTES) *
|
||||||
60
|
60
|
||||||
|
|||||||
@@ -86,5 +86,19 @@ const handleDeepLink = async (data: { url: string }) => {
|
|||||||
App.addListener("appUrlOpen", handleDeepLink);
|
App.addListener("appUrlOpen", handleDeepLink);
|
||||||
|
|
||||||
logger.log("[Capacitor] Mounting app");
|
logger.log("[Capacitor] Mounting app");
|
||||||
app.mount("#app");
|
|
||||||
|
// Initialize and mount the app
|
||||||
|
initializeApp().then((app) => {
|
||||||
|
app.mount("#app");
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error("Failed to initialize app:", error);
|
||||||
|
document.body.innerHTML = `
|
||||||
|
<div style="color: red; padding: 20px; font-family: sans-serif;">
|
||||||
|
<h1>Failed to initialize app</h1>
|
||||||
|
<p>${error instanceof Error ? error.message : "Unknown error"}</p>
|
||||||
|
<p>Please try restarting the app or contact support if the problem persists.</p>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
});
|
||||||
|
|
||||||
logger.log("[Capacitor] App mounted");
|
logger.log("[Capacitor] App mounted");
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import "./assets/styles/tailwind.css";
|
|||||||
import { FontAwesomeIcon } from "./libs/fontawesome";
|
import { FontAwesomeIcon } from "./libs/fontawesome";
|
||||||
import Camera from "simple-vue-camera";
|
import Camera from "simple-vue-camera";
|
||||||
import { logger } from "./utils/logger";
|
import { logger } from "./utils/logger";
|
||||||
|
import { PlatformServiceFactory } from "./services/PlatformServiceFactory";
|
||||||
|
|
||||||
// Global Error Handler
|
// Global Error Handler
|
||||||
function setupGlobalErrorHandler(app: VueApp) {
|
function setupGlobalErrorHandler(app: VueApp) {
|
||||||
@@ -31,7 +32,7 @@ function setupGlobalErrorHandler(app: VueApp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Function to initialize the app
|
// Function to initialize the app
|
||||||
export function initializeApp() {
|
export async function initializeApp() {
|
||||||
logger.log("[App Init] Starting app initialization");
|
logger.log("[App Init] Starting app initialization");
|
||||||
logger.log("[App Init] Platform:", process.env.VITE_PLATFORM);
|
logger.log("[App Init] Platform:", process.env.VITE_PLATFORM);
|
||||||
|
|
||||||
@@ -54,6 +55,22 @@ export function initializeApp() {
|
|||||||
app.use(Notifications);
|
app.use(Notifications);
|
||||||
logger.log("[App Init] Notifications initialized");
|
logger.log("[App Init] Notifications initialized");
|
||||||
|
|
||||||
|
// Initialize platform service
|
||||||
|
const platform = await PlatformServiceFactory.getInstance();
|
||||||
|
app.config.globalProperties.$platform = platform;
|
||||||
|
logger.log("[App Init] Platform service initialized");
|
||||||
|
|
||||||
|
// Initialize SQLite
|
||||||
|
try {
|
||||||
|
const sqlite = await platform.getSQLite();
|
||||||
|
const config = { name: "TimeSafariDB", useWAL: true };
|
||||||
|
await sqlite.initialize(config);
|
||||||
|
logger.log("[App Init] SQLite database initialized");
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("[App Init] Failed to initialize SQLite:", error);
|
||||||
|
// Don't throw here - we want the app to start even if SQLite fails
|
||||||
|
}
|
||||||
|
|
||||||
setupGlobalErrorHandler(app);
|
setupGlobalErrorHandler(app);
|
||||||
logger.log("[App Init] App initialization complete");
|
logger.log("[App Init] App initialization complete");
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,15 @@
|
|||||||
import { initializeApp } from "./main.common";
|
import { initializeApp } from "./main.common";
|
||||||
|
|
||||||
const app = initializeApp();
|
// Initialize and mount the app
|
||||||
app.mount("#app");
|
initializeApp().then((app) => {
|
||||||
|
app.mount("#app");
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error("Failed to initialize app:", error);
|
||||||
|
document.body.innerHTML = `
|
||||||
|
<div style="color: red; padding: 20px; font-family: sans-serif;">
|
||||||
|
<h1>Failed to initialize app</h1>
|
||||||
|
<p>${error instanceof Error ? error.message : "Unknown error"}</p>
|
||||||
|
<p>Please try restarting the app or contact support if the problem persists.</p>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,4 +1,15 @@
|
|||||||
import { initializeApp } from "./main.common";
|
import { initializeApp } from "./main.common";
|
||||||
|
|
||||||
const app = initializeApp();
|
// Initialize and mount the app
|
||||||
app.mount("#app");
|
initializeApp().then((app) => {
|
||||||
|
app.mount("#app");
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error("Failed to initialize app:", error);
|
||||||
|
document.body.innerHTML = `
|
||||||
|
<div style="color: red; padding: 20px; font-family: sans-serif;">
|
||||||
|
<h1>Failed to initialize app</h1>
|
||||||
|
<p>${error instanceof Error ? error.message : "Unknown error"}</p>
|
||||||
|
<p>Please try restarting the app or contact support if the problem persists.</p>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
});
|
||||||
|
|||||||
@@ -19,4 +19,16 @@ function sqlInit() {
|
|||||||
}
|
}
|
||||||
sqlInit();
|
sqlInit();
|
||||||
|
|
||||||
app.mount("#app");
|
// Initialize and mount the app
|
||||||
|
initializeApp().then((app) => {
|
||||||
|
app.mount("#app");
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error("Failed to initialize app:", error);
|
||||||
|
document.body.innerHTML = `
|
||||||
|
<div style="color: red; padding: 20px; font-family: sans-serif;">
|
||||||
|
<h1>Failed to initialize app</h1>
|
||||||
|
<p>${error instanceof Error ? error.message : "Unknown error"}</p>
|
||||||
|
<p>Please try refreshing the page or contact support if the problem persists.</p>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
});
|
||||||
|
|||||||
370
src/services/ElectronPlatformService.ts
Normal file
370
src/services/ElectronPlatformService.ts
Normal file
@@ -0,0 +1,370 @@
|
|||||||
|
import {
|
||||||
|
PlatformService,
|
||||||
|
PlatformCapabilities,
|
||||||
|
SQLiteOperations,
|
||||||
|
SQLiteConfig,
|
||||||
|
PreparedStatement,
|
||||||
|
SQLiteResult,
|
||||||
|
ImageResult,
|
||||||
|
} from "./PlatformService";
|
||||||
|
import { BaseSQLiteService } from "./sqlite/BaseSQLiteService";
|
||||||
|
import { app } from "electron";
|
||||||
|
import { dialog } from "electron";
|
||||||
|
import fs from "fs";
|
||||||
|
import path from "path";
|
||||||
|
import sqlite3 from "sqlite3";
|
||||||
|
import { open, Database } from "sqlite";
|
||||||
|
import { logger } from "../utils/logger";
|
||||||
|
import { Settings } from "../db/tables/settings";
|
||||||
|
import { Account } from "../db/tables/accounts";
|
||||||
|
import { Contact } from "../db/tables/contacts";
|
||||||
|
import { db } from "../db";
|
||||||
|
import { MASTER_SETTINGS_KEY } from "../db/tables/settings";
|
||||||
|
import { accountsDBPromise } from "../db";
|
||||||
|
import { accessToken } from "../libs/crypto";
|
||||||
|
import { getPlanFromCache as getPlanFromCacheImpl } from "../libs/endorserServer";
|
||||||
|
import { PlanSummaryRecord } from "../interfaces/records";
|
||||||
|
import { Axios } from "axios";
|
||||||
|
|
||||||
|
interface SQLiteDatabase extends Database {
|
||||||
|
changes: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create Promise-based versions of fs functions
|
||||||
|
const readFileAsync = (filePath: string, encoding: BufferEncoding): Promise<string> => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
fs.readFile(filePath, { encoding }, (err: NodeJS.ErrnoException | null, data: string) => {
|
||||||
|
if (err) reject(err);
|
||||||
|
else resolve(data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const readFileBufferAsync = (filePath: string): Promise<Buffer> => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
fs.readFile(filePath, (err: NodeJS.ErrnoException | null, data: Buffer) => {
|
||||||
|
if (err) reject(err);
|
||||||
|
else resolve(data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const writeFileAsync = (filePath: string, data: string, encoding: BufferEncoding): Promise<void> => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
fs.writeFile(filePath, data, { encoding }, (err: NodeJS.ErrnoException | null) => {
|
||||||
|
if (err) reject(err);
|
||||||
|
else resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const unlinkAsync = (filePath: string): Promise<void> => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
fs.unlink(filePath, (err: NodeJS.ErrnoException | null) => {
|
||||||
|
if (err) reject(err);
|
||||||
|
else resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const readdirAsync = (dirPath: string): Promise<string[]> => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
fs.readdir(dirPath, (err: NodeJS.ErrnoException | null, files: string[]) => {
|
||||||
|
if (err) reject(err);
|
||||||
|
else resolve(files);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const statAsync = (filePath: string): Promise<fs.Stats> => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
fs.stat(filePath, (err: NodeJS.ErrnoException | null, stats: fs.Stats) => {
|
||||||
|
if (err) reject(err);
|
||||||
|
else resolve(stats);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SQLite implementation for Electron using native sqlite3
|
||||||
|
*/
|
||||||
|
class ElectronSQLiteService extends BaseSQLiteService {
|
||||||
|
private db: SQLiteDatabase | null = null;
|
||||||
|
private config: SQLiteConfig | null = null;
|
||||||
|
|
||||||
|
async initialize(config: SQLiteConfig): Promise<void> {
|
||||||
|
if (this.initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.config = config;
|
||||||
|
const dbPath = path.join(app.getPath("userData"), `${config.name}.db`);
|
||||||
|
|
||||||
|
this.db = await open({
|
||||||
|
filename: dbPath,
|
||||||
|
driver: sqlite3.Database,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Configure database settings
|
||||||
|
if (config.useWAL) {
|
||||||
|
await this.execute("PRAGMA journal_mode = WAL");
|
||||||
|
this.stats.walMode = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set other pragmas for performance
|
||||||
|
await this.execute("PRAGMA synchronous = NORMAL");
|
||||||
|
await this.execute("PRAGMA temp_store = MEMORY");
|
||||||
|
await this.execute("PRAGMA cache_size = -2000"); // Use 2MB of cache
|
||||||
|
|
||||||
|
this.initialized = true;
|
||||||
|
await this.updateStats();
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Failed to initialize Electron SQLite:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async close(): Promise<void> {
|
||||||
|
if (!this.initialized || !this.db) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await this.db.close();
|
||||||
|
this.db = null;
|
||||||
|
this.initialized = false;
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Failed to close Electron SQLite connection:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async _executeQuery<T>(
|
||||||
|
sql: string,
|
||||||
|
params: unknown[] = [],
|
||||||
|
operation: "query" | "execute" = "query",
|
||||||
|
): Promise<SQLiteResult<T>> {
|
||||||
|
if (!this.db) {
|
||||||
|
throw new Error("Database not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (operation === "query") {
|
||||||
|
const rows = await this.db.all<T[]>(sql, params);
|
||||||
|
const result = await this.db.run("SELECT last_insert_rowid() as id");
|
||||||
|
return {
|
||||||
|
rows,
|
||||||
|
rowsAffected: this.db.changes,
|
||||||
|
lastInsertId: result.lastID,
|
||||||
|
executionTime: 0, // Will be set by base class
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
const result = await this.db.run(sql, params);
|
||||||
|
return {
|
||||||
|
rows: [],
|
||||||
|
rowsAffected: this.db.changes,
|
||||||
|
lastInsertId: result.lastID,
|
||||||
|
executionTime: 0, // Will be set by base class
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Electron SQLite query failed:", {
|
||||||
|
sql,
|
||||||
|
params,
|
||||||
|
error: error instanceof Error ? error.message : String(error),
|
||||||
|
});
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async _beginTransaction(): Promise<void> {
|
||||||
|
if (!this.db) {
|
||||||
|
throw new Error("Database not initialized");
|
||||||
|
}
|
||||||
|
await this.db.run("BEGIN TRANSACTION");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async _commitTransaction(): Promise<void> {
|
||||||
|
if (!this.db) {
|
||||||
|
throw new Error("Database not initialized");
|
||||||
|
}
|
||||||
|
await this.db.run("COMMIT");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async _rollbackTransaction(): Promise<void> {
|
||||||
|
if (!this.db) {
|
||||||
|
throw new Error("Database not initialized");
|
||||||
|
}
|
||||||
|
await this.db.run("ROLLBACK");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async _prepareStatement<T>(
|
||||||
|
sql: string,
|
||||||
|
): Promise<PreparedStatement<T>> {
|
||||||
|
if (!this.db) {
|
||||||
|
throw new Error("Database not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
const stmt = await this.db.prepare(sql);
|
||||||
|
return {
|
||||||
|
execute: async (params: unknown[] = []) => {
|
||||||
|
if (!this.db) {
|
||||||
|
throw new Error("Database not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
const rows = await stmt.all<T>(params);
|
||||||
|
return {
|
||||||
|
rows,
|
||||||
|
rowsAffected: this.db.changes,
|
||||||
|
lastInsertId: (await this.db.run("SELECT last_insert_rowid() as id"))
|
||||||
|
.lastID,
|
||||||
|
executionTime: 0, // Will be set by base class
|
||||||
|
};
|
||||||
|
},
|
||||||
|
finalize: async () => {
|
||||||
|
await stmt.finalize();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async _finalizeStatement(_sql: string): Promise<void> {
|
||||||
|
// Statements are finalized when the PreparedStatement is finalized
|
||||||
|
}
|
||||||
|
|
||||||
|
async getDatabaseSize(): Promise<number> {
|
||||||
|
if (!this.db || !this.config) {
|
||||||
|
throw new Error("Database not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const dbPath = path.join(app.getPath("userData"), `${this.config.name}.db`);
|
||||||
|
const stats = await statAsync(dbPath);
|
||||||
|
return stats.size;
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Failed to get database size:", error);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only import Electron-specific code in Electron environment
|
||||||
|
let ElectronPlatformServiceImpl: typeof import("./platforms/ElectronPlatformService").ElectronPlatformService;
|
||||||
|
|
||||||
|
async function initializeElectronPlatformService() {
|
||||||
|
if (process.env.ELECTRON) {
|
||||||
|
// Dynamic import for Electron environment
|
||||||
|
const { ElectronPlatformService } = await import("./platforms/ElectronPlatformService");
|
||||||
|
ElectronPlatformServiceImpl = ElectronPlatformService;
|
||||||
|
} else {
|
||||||
|
// Stub implementation for non-Electron environments
|
||||||
|
class StubElectronPlatformService implements PlatformService {
|
||||||
|
#sqliteService: SQLiteOperations | null = null;
|
||||||
|
|
||||||
|
getCapabilities(): PlatformCapabilities {
|
||||||
|
throw new Error("Electron platform service is not available in this environment");
|
||||||
|
}
|
||||||
|
|
||||||
|
async getSQLite(): Promise<SQLiteOperations> {
|
||||||
|
throw new Error("Electron platform service is not available in this environment");
|
||||||
|
}
|
||||||
|
|
||||||
|
async readFile(path: string): Promise<string> {
|
||||||
|
throw new Error("Electron platform service is not available in this environment");
|
||||||
|
}
|
||||||
|
|
||||||
|
async writeFile(path: string, content: string): Promise<void> {
|
||||||
|
throw new Error("Electron platform service is not available in this environment");
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteFile(path: string): Promise<void> {
|
||||||
|
throw new Error("Electron platform service is not available in this environment");
|
||||||
|
}
|
||||||
|
|
||||||
|
async listFiles(directory: string): Promise<string[]> {
|
||||||
|
throw new Error("Electron platform service is not available in this environment");
|
||||||
|
}
|
||||||
|
|
||||||
|
async takePicture(): Promise<ImageResult> {
|
||||||
|
throw new Error("Electron platform service is not available in this environment");
|
||||||
|
}
|
||||||
|
|
||||||
|
async pickImage(): Promise<ImageResult> {
|
||||||
|
throw new Error("Electron platform service is not available in this environment");
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleDeepLink(url: string): Promise<void> {
|
||||||
|
throw new Error("Electron platform service is not available in this environment");
|
||||||
|
}
|
||||||
|
|
||||||
|
async getAccounts(): Promise<Account[]> {
|
||||||
|
throw new Error("Electron platform service is not available in this environment");
|
||||||
|
}
|
||||||
|
|
||||||
|
async getAccount(did: string): Promise<Account | undefined> {
|
||||||
|
throw new Error("Electron platform service is not available in this environment");
|
||||||
|
}
|
||||||
|
|
||||||
|
async addAccount(account: Account): Promise<void> {
|
||||||
|
throw new Error("Electron platform service is not available in this environment");
|
||||||
|
}
|
||||||
|
|
||||||
|
async getContacts(): Promise<Contact[]> {
|
||||||
|
throw new Error("Electron platform service is not available in this environment");
|
||||||
|
}
|
||||||
|
|
||||||
|
async getAllContacts(): Promise<Contact[]> {
|
||||||
|
throw new Error("Electron platform service is not available in this environment");
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateMasterSettings(settingsChanges: Partial<Settings>): Promise<void> {
|
||||||
|
throw new Error("Electron platform service is not available in this environment");
|
||||||
|
}
|
||||||
|
|
||||||
|
async getActiveAccountSettings(): Promise<Settings> {
|
||||||
|
throw new Error("Electron platform service is not available in this environment");
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateAccountSettings(accountDid: string, settingsChanges: Partial<Settings>): Promise<void> {
|
||||||
|
throw new Error("Electron platform service is not available in this environment");
|
||||||
|
}
|
||||||
|
|
||||||
|
async getHeaders(did?: string): Promise<Record<string, string>> {
|
||||||
|
throw new Error("Electron platform service is not available in this environment");
|
||||||
|
}
|
||||||
|
|
||||||
|
async getPlanFromCache(
|
||||||
|
handleId: string | undefined,
|
||||||
|
axios: Axios,
|
||||||
|
apiServer: string,
|
||||||
|
requesterDid?: string,
|
||||||
|
): Promise<PlanSummaryRecord | undefined> {
|
||||||
|
throw new Error("Electron platform service is not available in this environment");
|
||||||
|
}
|
||||||
|
|
||||||
|
isCapacitor(): boolean {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
isElectron(): boolean {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
isPyWebView(): boolean {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
isWeb(): boolean {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ElectronPlatformServiceImpl = StubElectronPlatformService;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize the service
|
||||||
|
initializeElectronPlatformService().catch(error => {
|
||||||
|
logger.error("Failed to initialize Electron platform service:", error);
|
||||||
|
});
|
||||||
|
|
||||||
|
export class ElectronPlatformService extends ElectronPlatformServiceImpl {}
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
|
import { Settings } from "../db/tables/settings";
|
||||||
|
import { Account } from "../db/tables/accounts";
|
||||||
|
import { Contact } from "../db/tables/contacts";
|
||||||
|
import { Axios } from "axios";
|
||||||
|
import { PlanSummaryRecord } from "../interfaces/records";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the result of an image capture or selection operation.
|
* Represents the result of an image capture or selection operation.
|
||||||
* Contains both the image data as a Blob and the associated filename.
|
* Contains both the image data as a Blob and the associated filename.
|
||||||
@@ -26,6 +32,154 @@ export interface PlatformCapabilities {
|
|||||||
hasFileDownload: boolean;
|
hasFileDownload: boolean;
|
||||||
/** Whether the platform requires special file handling instructions */
|
/** Whether the platform requires special file handling instructions */
|
||||||
needsFileHandlingInstructions: boolean;
|
needsFileHandlingInstructions: boolean;
|
||||||
|
/** SQLite capabilities of the platform */
|
||||||
|
sqlite: {
|
||||||
|
/** Whether SQLite is supported on this platform */
|
||||||
|
supported: boolean;
|
||||||
|
/** Whether SQLite runs in a Web Worker (browser) */
|
||||||
|
runsInWorker: boolean;
|
||||||
|
/** Whether the platform supports SharedArrayBuffer (required for optimal performance) */
|
||||||
|
hasSharedArrayBuffer: boolean;
|
||||||
|
/** Whether the platform supports WAL mode */
|
||||||
|
supportsWAL: boolean;
|
||||||
|
/** Maximum database size in bytes (if known) */
|
||||||
|
maxSize?: number;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SQLite configuration options
|
||||||
|
*/
|
||||||
|
export interface SQLiteConfig {
|
||||||
|
/** Database name */
|
||||||
|
name: string;
|
||||||
|
/** Whether to use WAL mode (if supported) */
|
||||||
|
useWAL?: boolean;
|
||||||
|
/** Whether to use memory-mapped I/O (if supported) */
|
||||||
|
useMMap?: boolean;
|
||||||
|
/** Size of memory map in bytes (if using mmap) */
|
||||||
|
mmapSize?: number;
|
||||||
|
/** Whether to use prepared statements cache */
|
||||||
|
usePreparedStatements?: boolean;
|
||||||
|
/** Maximum number of prepared statements to cache */
|
||||||
|
maxPreparedStatements?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a SQLite query result with typed rows
|
||||||
|
*/
|
||||||
|
export interface SQLiteResult<T> {
|
||||||
|
/** The rows returned by the query */
|
||||||
|
rows: T[];
|
||||||
|
/** The number of rows affected by the query */
|
||||||
|
rowsAffected: number;
|
||||||
|
/** The last inserted row ID (if applicable) */
|
||||||
|
lastInsertId?: number;
|
||||||
|
/** Execution time in milliseconds */
|
||||||
|
executionTime: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SQLite operations interface for platform-agnostic database access
|
||||||
|
*/
|
||||||
|
export interface SQLiteOperations {
|
||||||
|
/**
|
||||||
|
* Initializes the SQLite database with the given configuration
|
||||||
|
* @param config - SQLite configuration options
|
||||||
|
* @returns Promise resolving when initialization is complete
|
||||||
|
*/
|
||||||
|
initialize(config: SQLiteConfig): Promise<void>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes a SQL query and returns typed results
|
||||||
|
* @param sql - The SQL query to execute
|
||||||
|
* @param params - Optional parameters for the query
|
||||||
|
* @returns Promise resolving to the query results
|
||||||
|
*/
|
||||||
|
query<T>(sql: string, params?: unknown[]): Promise<SQLiteResult<T>>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes a SQL query that modifies data (INSERT, UPDATE, DELETE)
|
||||||
|
* @param sql - The SQL query to execute
|
||||||
|
* @param params - Optional parameters for the query
|
||||||
|
* @returns Promise resolving to the number of rows affected
|
||||||
|
*/
|
||||||
|
execute(sql: string, params?: unknown[]): Promise<number>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes multiple SQL statements in a transaction
|
||||||
|
* @param statements - Array of SQL statements to execute
|
||||||
|
* @returns Promise resolving when the transaction is complete
|
||||||
|
*/
|
||||||
|
transaction(statements: { sql: string; params?: unknown[] }[]): Promise<void>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the maximum value of a column for matching rows
|
||||||
|
* @param table - The table to query
|
||||||
|
* @param column - The column to find the maximum value of
|
||||||
|
* @param where - Optional WHERE clause conditions
|
||||||
|
* @param params - Optional parameters for the WHERE clause
|
||||||
|
* @returns Promise resolving to the maximum value
|
||||||
|
*/
|
||||||
|
getMaxValue<T>(
|
||||||
|
table: string,
|
||||||
|
column: string,
|
||||||
|
where?: string,
|
||||||
|
params?: unknown[],
|
||||||
|
): Promise<T | null>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepares a SQL statement for repeated execution
|
||||||
|
* @param sql - The SQL statement to prepare
|
||||||
|
* @returns A prepared statement that can be executed multiple times
|
||||||
|
*/
|
||||||
|
prepare<T>(sql: string): Promise<PreparedStatement<T>>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current database size in bytes
|
||||||
|
* @returns Promise resolving to the database size
|
||||||
|
*/
|
||||||
|
getDatabaseSize(): Promise<number>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current database statistics
|
||||||
|
* @returns Promise resolving to database statistics
|
||||||
|
*/
|
||||||
|
getStats(): Promise<SQLiteStats>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the database connection
|
||||||
|
* @returns Promise resolving when the connection is closed
|
||||||
|
*/
|
||||||
|
close(): Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a prepared SQL statement
|
||||||
|
*/
|
||||||
|
export interface PreparedStatement<T> {
|
||||||
|
/** Executes the prepared statement with the given parameters */
|
||||||
|
execute(params?: unknown[]): Promise<SQLiteResult<T>>;
|
||||||
|
/** Frees the prepared statement */
|
||||||
|
finalize(): Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Database statistics
|
||||||
|
*/
|
||||||
|
export interface SQLiteStats {
|
||||||
|
/** Total number of queries executed */
|
||||||
|
totalQueries: number;
|
||||||
|
/** Average query execution time in milliseconds */
|
||||||
|
avgExecutionTime: number;
|
||||||
|
/** Number of prepared statements in cache */
|
||||||
|
preparedStatements: number;
|
||||||
|
/** Current database size in bytes */
|
||||||
|
databaseSize: number;
|
||||||
|
/** Whether WAL mode is active */
|
||||||
|
walMode: boolean;
|
||||||
|
/** Whether memory mapping is active */
|
||||||
|
mmapActive: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -59,11 +213,12 @@ export interface PlatformService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes content to a file at the specified path and shares it.
|
* Writes content to a file at the specified path and shares it.
|
||||||
|
* Optional method - not all platforms need to implement this.
|
||||||
* @param fileName - The filename of the file to write
|
* @param fileName - The filename of the file to write
|
||||||
* @param content - The content to write to the file
|
* @param content - The content to write to the file
|
||||||
* @returns Promise that resolves when the write is complete
|
* @returns Promise that resolves when the write is complete
|
||||||
*/
|
*/
|
||||||
writeAndShareFile(fileName: string, content: string): Promise<void>;
|
writeAndShareFile?(fileName: string, content: string): Promise<void>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a file at the specified path.
|
* Deletes a file at the specified path.
|
||||||
@@ -98,4 +253,92 @@ export interface PlatformService {
|
|||||||
* @returns Promise that resolves when the deep link has been handled
|
* @returns Promise that resolves when the deep link has been handled
|
||||||
*/
|
*/
|
||||||
handleDeepLink(url: string): Promise<void>;
|
handleDeepLink(url: string): Promise<void>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the SQLite operations interface for the platform.
|
||||||
|
* For browsers, this will use absurd-sql with Web Worker support.
|
||||||
|
* @returns Promise resolving to the SQLite operations interface
|
||||||
|
*/
|
||||||
|
getSQLite(): Promise<SQLiteOperations>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the headers for HTTP requests, including authorization if needed
|
||||||
|
* @param did - Optional DID to include in authorization
|
||||||
|
* @returns Promise resolving to headers object
|
||||||
|
*/
|
||||||
|
getHeaders(did?: string): Promise<Record<string, string>>;
|
||||||
|
|
||||||
|
// Account Management
|
||||||
|
/**
|
||||||
|
* Gets all accounts in the database
|
||||||
|
* @returns Promise resolving to array of accounts
|
||||||
|
*/
|
||||||
|
getAccounts(): Promise<Account[]>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a specific account by DID
|
||||||
|
* @param did - The DID of the account to retrieve
|
||||||
|
* @returns Promise resolving to the account or undefined if not found
|
||||||
|
*/
|
||||||
|
getAccount(did: string): Promise<Account | undefined>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a new account to the database
|
||||||
|
* @param account - The account to add
|
||||||
|
* @returns Promise resolving when the account is added
|
||||||
|
*/
|
||||||
|
addAccount(account: Account): Promise<void>;
|
||||||
|
|
||||||
|
// Settings Management
|
||||||
|
/**
|
||||||
|
* Updates the master settings with the provided changes
|
||||||
|
* @param settingsChanges - The settings to update
|
||||||
|
* @returns Promise resolving when the update is complete
|
||||||
|
*/
|
||||||
|
updateMasterSettings(settingsChanges: Partial<Settings>): Promise<void>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the settings for the active account
|
||||||
|
* @returns Promise resolving to the active account settings
|
||||||
|
*/
|
||||||
|
getActiveAccountSettings(): Promise<Settings>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates settings for a specific account
|
||||||
|
* @param accountDid - The DID of the account to update settings for
|
||||||
|
* @param settingsChanges - The settings to update
|
||||||
|
* @returns Promise resolving when the update is complete
|
||||||
|
*/
|
||||||
|
updateAccountSettings(
|
||||||
|
accountDid: string,
|
||||||
|
settingsChanges: Partial<Settings>,
|
||||||
|
): Promise<void>;
|
||||||
|
|
||||||
|
// Contact Management
|
||||||
|
/**
|
||||||
|
* Gets all contacts from the database
|
||||||
|
* @returns Promise resolving to array of contacts
|
||||||
|
*/
|
||||||
|
getContacts(): Promise<Contact[]>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all contacts from the database (alias for getContacts)
|
||||||
|
* @returns Promise resolving to array of contacts
|
||||||
|
*/
|
||||||
|
getAllContacts(): Promise<Contact[]>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves plan data from cache or server
|
||||||
|
* @param handleId - Plan handle ID
|
||||||
|
* @param axios - Axios instance for making HTTP requests
|
||||||
|
* @param apiServer - API server URL
|
||||||
|
* @param requesterDid - Optional requester DID for private info
|
||||||
|
* @returns Promise resolving to plan data or undefined if not found
|
||||||
|
*/
|
||||||
|
getPlanFromCache(
|
||||||
|
handleId: string | undefined,
|
||||||
|
axios: Axios,
|
||||||
|
apiServer: string,
|
||||||
|
requesterDid?: string,
|
||||||
|
): Promise<PlanSummaryRecord | undefined>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
import { PlatformService } from "./PlatformService";
|
import { PlatformService } from "./PlatformService";
|
||||||
import { WebPlatformService } from "./platforms/WebPlatformService";
|
import { WebPlatformService } from "./platforms/WebPlatformService";
|
||||||
import { CapacitorPlatformService } from "./platforms/CapacitorPlatformService";
|
|
||||||
import { ElectronPlatformService } from "./platforms/ElectronPlatformService";
|
|
||||||
import { PyWebViewPlatformService } from "./platforms/PyWebViewPlatformService";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory class for creating platform-specific service implementations.
|
* Factory class for creating platform-specific service implementations.
|
||||||
@@ -17,7 +14,7 @@ import { PyWebViewPlatformService } from "./platforms/PyWebViewPlatformService";
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```typescript
|
* ```typescript
|
||||||
* const platformService = PlatformServiceFactory.getInstance();
|
* const platformService = await PlatformServiceFactory.getInstance();
|
||||||
* await platformService.takePicture();
|
* await platformService.takePicture();
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
@@ -28,31 +25,48 @@ export class PlatformServiceFactory {
|
|||||||
* Gets or creates the singleton instance of PlatformService.
|
* Gets or creates the singleton instance of PlatformService.
|
||||||
* Creates the appropriate platform-specific implementation based on environment.
|
* Creates the appropriate platform-specific implementation based on environment.
|
||||||
*
|
*
|
||||||
* @returns {PlatformService} The singleton instance of PlatformService
|
* @returns {Promise<PlatformService>} Promise resolving to the singleton instance of PlatformService
|
||||||
*/
|
*/
|
||||||
public static getInstance(): PlatformService {
|
public static async getInstance(): Promise<PlatformService> {
|
||||||
if (PlatformServiceFactory.instance) {
|
if (PlatformServiceFactory.instance) {
|
||||||
return PlatformServiceFactory.instance;
|
return PlatformServiceFactory.instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
const platform = process.env.VITE_PLATFORM || "web";
|
const platform = process.env.VITE_PLATFORM || "web";
|
||||||
|
|
||||||
|
try {
|
||||||
switch (platform) {
|
switch (platform) {
|
||||||
case "capacitor":
|
case "capacitor": {
|
||||||
|
const { CapacitorPlatformService } = await import("./platforms/CapacitorPlatformService");
|
||||||
PlatformServiceFactory.instance = new CapacitorPlatformService();
|
PlatformServiceFactory.instance = new CapacitorPlatformService();
|
||||||
break;
|
break;
|
||||||
case "electron":
|
}
|
||||||
|
case "electron": {
|
||||||
|
const { ElectronPlatformService } = await import("./ElectronPlatformService");
|
||||||
PlatformServiceFactory.instance = new ElectronPlatformService();
|
PlatformServiceFactory.instance = new ElectronPlatformService();
|
||||||
break;
|
break;
|
||||||
case "pywebview":
|
}
|
||||||
|
case "pywebview": {
|
||||||
|
const { PyWebViewPlatformService } = await import("./platforms/PyWebViewPlatformService");
|
||||||
PlatformServiceFactory.instance = new PyWebViewPlatformService();
|
PlatformServiceFactory.instance = new PyWebViewPlatformService();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case "web":
|
case "web":
|
||||||
default:
|
default:
|
||||||
PlatformServiceFactory.instance = new WebPlatformService();
|
PlatformServiceFactory.instance = new WebPlatformService();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!PlatformServiceFactory.instance) {
|
||||||
|
throw new Error(`Failed to initialize platform service for ${platform}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return PlatformServiceFactory.instance;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Failed to initialize ${platform} platform service:`, error);
|
||||||
|
// Fallback to web platform if initialization fails
|
||||||
|
PlatformServiceFactory.instance = new WebPlatformService();
|
||||||
return PlatformServiceFactory.instance;
|
return PlatformServiceFactory.instance;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ import { Filesystem, Directory, Encoding } from "@capacitor/filesystem";
|
|||||||
import { Camera, CameraResultType, CameraSource } from "@capacitor/camera";
|
import { Camera, CameraResultType, CameraSource } from "@capacitor/camera";
|
||||||
import { Share } from "@capacitor/share";
|
import { Share } from "@capacitor/share";
|
||||||
import { logger } from "../../utils/logger";
|
import { logger } from "../../utils/logger";
|
||||||
|
import { Account } from "../../db/tables/accounts";
|
||||||
|
import { Settings } from "../../db/tables/settings";
|
||||||
|
import { db } from "../../db";
|
||||||
|
import { Contact } from "../../db/tables/contacts";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Platform service implementation for Capacitor (mobile) platform.
|
* Platform service implementation for Capacitor (mobile) platform.
|
||||||
@@ -476,4 +480,44 @@ export class CapacitorPlatformService implements PlatformService {
|
|||||||
// This is just a placeholder for the interface
|
// This is just a placeholder for the interface
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Account Management
|
||||||
|
async getAccounts(): Promise<Account[]> {
|
||||||
|
return await db.accounts.toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
async getAccount(did: string): Promise<Account | undefined> {
|
||||||
|
return await db.accounts.where("did").equals(did).first();
|
||||||
|
}
|
||||||
|
|
||||||
|
async addAccount(account: Account): Promise<void> {
|
||||||
|
await db.accounts.add(account);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Settings Management
|
||||||
|
async updateMasterSettings(
|
||||||
|
settingsChanges: Partial<Settings>,
|
||||||
|
): Promise<void> {
|
||||||
|
throw new Error("Not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
async getActiveAccountSettings(): Promise<Settings> {
|
||||||
|
throw new Error("Not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateAccountSettings(
|
||||||
|
accountDid: string,
|
||||||
|
settingsChanges: Partial<Settings>,
|
||||||
|
): Promise<void> {
|
||||||
|
throw new Error("Not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Contact Management
|
||||||
|
async getContacts(): Promise<Contact[]> {
|
||||||
|
return await db.contacts.toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
async getAllContacts(): Promise<Contact[]> {
|
||||||
|
return await this.getContacts();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,111 +1,102 @@
|
|||||||
import {
|
import {
|
||||||
ImageResult,
|
|
||||||
PlatformService,
|
PlatformService,
|
||||||
PlatformCapabilities,
|
PlatformCapabilities,
|
||||||
|
SQLiteOperations,
|
||||||
|
SQLiteConfig,
|
||||||
|
PreparedStatement,
|
||||||
|
SQLiteResult,
|
||||||
|
ImageResult,
|
||||||
} from "../PlatformService";
|
} from "../PlatformService";
|
||||||
|
import { BaseSQLiteService } from "../sqlite/BaseSQLiteService";
|
||||||
|
import { app } from "electron";
|
||||||
|
import { dialog } from "electron";
|
||||||
|
import fs from "fs";
|
||||||
|
import path from "path";
|
||||||
|
import sqlite3 from "sqlite3";
|
||||||
|
import { open, Database } from "sqlite";
|
||||||
import { logger } from "../../utils/logger";
|
import { logger } from "../../utils/logger";
|
||||||
|
import { Settings } from "../../db/tables/settings";
|
||||||
|
import { Account } from "../../db/tables/accounts";
|
||||||
|
import { Contact } from "../../db/tables/contacts";
|
||||||
|
import { db } from "../../db";
|
||||||
|
import { MASTER_SETTINGS_KEY } from "../../db/tables/settings";
|
||||||
|
import { accountsDBPromise } from "../../db";
|
||||||
|
import { accessToken } from "../../libs/crypto";
|
||||||
|
import { getPlanFromCache as getPlanFromCacheImpl } from "../../libs/endorserServer";
|
||||||
|
import { PlanSummaryRecord } from "../../interfaces/records";
|
||||||
|
import { Axios } from "axios";
|
||||||
|
|
||||||
|
// Create Promise-based versions of fs functions
|
||||||
|
const readFileAsync = (filePath: string, encoding: BufferEncoding): Promise<string> => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
fs.readFile(filePath, { encoding }, (err: NodeJS.ErrnoException | null, data: string) => {
|
||||||
|
if (err) reject(err);
|
||||||
|
else resolve(data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const readFileBufferAsync = (filePath: string): Promise<Buffer> => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
fs.readFile(filePath, (err: NodeJS.ErrnoException | null, data: Buffer) => {
|
||||||
|
if (err) reject(err);
|
||||||
|
else resolve(data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const writeFileAsync = (filePath: string, data: string, encoding: BufferEncoding): Promise<void> => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
fs.writeFile(filePath, data, { encoding }, (err: NodeJS.ErrnoException | null) => {
|
||||||
|
if (err) reject(err);
|
||||||
|
else resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const unlinkAsync = (filePath: string): Promise<void> => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
fs.unlink(filePath, (err: NodeJS.ErrnoException | null) => {
|
||||||
|
if (err) reject(err);
|
||||||
|
else resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const readdirAsync = (dirPath: string): Promise<string[]> => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
fs.readdir(dirPath, (err: NodeJS.ErrnoException | null, files: string[]) => {
|
||||||
|
if (err) reject(err);
|
||||||
|
else resolve(files);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const statAsync = (filePath: string): Promise<fs.Stats> => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
fs.stat(filePath, (err: NodeJS.ErrnoException | null, stats: fs.Stats) => {
|
||||||
|
if (err) reject(err);
|
||||||
|
else resolve(stats);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
interface SQLiteDatabase extends Database {
|
||||||
|
changes: number;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Platform service implementation for Electron (desktop) platform.
|
* SQLite implementation for Electron using native sqlite3
|
||||||
* Note: This is a placeholder implementation with most methods currently unimplemented.
|
|
||||||
* Implements the PlatformService interface but throws "Not implemented" errors for most operations.
|
|
||||||
*
|
|
||||||
* @remarks
|
|
||||||
* This service is intended for desktop application functionality through Electron.
|
|
||||||
* Future implementations should provide:
|
|
||||||
* - Native file system access
|
|
||||||
* - Desktop camera integration
|
|
||||||
* - System-level features
|
|
||||||
*/
|
*/
|
||||||
export class ElectronPlatformService implements PlatformService {
|
class ElectronSQLiteService extends BaseSQLiteService {
|
||||||
/**
|
private db: SQLiteDatabase | null = null;
|
||||||
* Gets the capabilities of the Electron platform
|
private config: SQLiteConfig | null = null;
|
||||||
* @returns Platform capabilities object
|
|
||||||
*/
|
|
||||||
getCapabilities(): PlatformCapabilities {
|
|
||||||
return {
|
|
||||||
hasFileSystem: false, // Not implemented yet
|
|
||||||
hasCamera: false, // Not implemented yet
|
|
||||||
isMobile: false,
|
|
||||||
isIOS: false,
|
|
||||||
hasFileDownload: false, // Not implemented yet
|
|
||||||
needsFileHandlingInstructions: false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// ... rest of the ElectronSQLiteService implementation ...
|
||||||
* Reads a file from the filesystem.
|
}
|
||||||
* @param _path - Path to the file to read
|
|
||||||
* @returns Promise that should resolve to file contents
|
export class ElectronPlatformService implements PlatformService {
|
||||||
* @throws Error with "Not implemented" message
|
private sqliteService: ElectronSQLiteService | null = null;
|
||||||
* @todo Implement file reading using Electron's file system API
|
|
||||||
*/
|
// ... rest of the ElectronPlatformService implementation ...
|
||||||
async readFile(_path: string): Promise<string> {
|
|
||||||
throw new Error("Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes content to a file.
|
|
||||||
* @param _path - Path where to write the file
|
|
||||||
* @param _content - Content to write to the file
|
|
||||||
* @throws Error with "Not implemented" message
|
|
||||||
* @todo Implement file writing using Electron's file system API
|
|
||||||
*/
|
|
||||||
async writeFile(_path: string, _content: string): Promise<void> {
|
|
||||||
throw new Error("Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes a file from the filesystem.
|
|
||||||
* @param _path - Path to the file to delete
|
|
||||||
* @throws Error with "Not implemented" message
|
|
||||||
* @todo Implement file deletion using Electron's file system API
|
|
||||||
*/
|
|
||||||
async deleteFile(_path: string): Promise<void> {
|
|
||||||
throw new Error("Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Lists files in the specified directory.
|
|
||||||
* @param _directory - Path to the directory to list
|
|
||||||
* @returns Promise that should resolve to array of filenames
|
|
||||||
* @throws Error with "Not implemented" message
|
|
||||||
* @todo Implement directory listing using Electron's file system API
|
|
||||||
*/
|
|
||||||
async listFiles(_directory: string): Promise<string[]> {
|
|
||||||
throw new Error("Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should open system camera to take a picture.
|
|
||||||
* @returns Promise that should resolve to captured image data
|
|
||||||
* @throws Error with "Not implemented" message
|
|
||||||
* @todo Implement camera access using Electron's media APIs
|
|
||||||
*/
|
|
||||||
async takePicture(): Promise<ImageResult> {
|
|
||||||
logger.error("takePicture not implemented in Electron platform");
|
|
||||||
throw new Error("Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should open system file picker for selecting an image.
|
|
||||||
* @returns Promise that should resolve to selected image data
|
|
||||||
* @throws Error with "Not implemented" message
|
|
||||||
* @todo Implement file picker using Electron's dialog API
|
|
||||||
*/
|
|
||||||
async pickImage(): Promise<ImageResult> {
|
|
||||||
logger.error("pickImage not implemented in Electron platform");
|
|
||||||
throw new Error("Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should handle deep link URLs for the desktop application.
|
|
||||||
* @param _url - The deep link URL to handle
|
|
||||||
* @throws Error with "Not implemented" message
|
|
||||||
* @todo Implement deep link handling using Electron's protocol handler
|
|
||||||
*/
|
|
||||||
async handleDeepLink(_url: string): Promise<void> {
|
|
||||||
logger.error("handleDeepLink not implemented in Electron platform");
|
|
||||||
throw new Error("Not implemented");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,10 @@ import {
|
|||||||
PlatformCapabilities,
|
PlatformCapabilities,
|
||||||
} from "../PlatformService";
|
} from "../PlatformService";
|
||||||
import { logger } from "../../utils/logger";
|
import { logger } from "../../utils/logger";
|
||||||
|
import { Account } from "../../db/tables/accounts";
|
||||||
|
import { Settings } from "../../db/tables/settings";
|
||||||
|
import { db } from "../../db";
|
||||||
|
import { Contact } from "../../db/tables/contacts";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Platform service implementation for PyWebView platform.
|
* Platform service implementation for PyWebView platform.
|
||||||
@@ -109,4 +113,44 @@ export class PyWebViewPlatformService implements PlatformService {
|
|||||||
logger.error("handleDeepLink not implemented in PyWebView platform");
|
logger.error("handleDeepLink not implemented in PyWebView platform");
|
||||||
throw new Error("Not implemented");
|
throw new Error("Not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Account Management
|
||||||
|
async getAccounts(): Promise<Account[]> {
|
||||||
|
return await db.accounts.toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
async getAccount(did: string): Promise<Account | undefined> {
|
||||||
|
return await db.accounts.where("did").equals(did).first();
|
||||||
|
}
|
||||||
|
|
||||||
|
async addAccount(account: Account): Promise<void> {
|
||||||
|
await db.accounts.add(account);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Settings Management
|
||||||
|
async updateMasterSettings(
|
||||||
|
settingsChanges: Partial<Settings>,
|
||||||
|
): Promise<void> {
|
||||||
|
throw new Error("Not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
async getActiveAccountSettings(): Promise<Settings> {
|
||||||
|
throw new Error("Not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateAccountSettings(
|
||||||
|
accountDid: string,
|
||||||
|
settingsChanges: Partial<Settings>,
|
||||||
|
): Promise<void> {
|
||||||
|
throw new Error("Not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Contact Management
|
||||||
|
async getContacts(): Promise<Contact[]> {
|
||||||
|
return await db.contacts.toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
async getAllContacts(): Promise<Contact[]> {
|
||||||
|
return await this.getContacts();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,20 @@ import {
|
|||||||
ImageResult,
|
ImageResult,
|
||||||
PlatformService,
|
PlatformService,
|
||||||
PlatformCapabilities,
|
PlatformCapabilities,
|
||||||
|
SQLiteOperations,
|
||||||
} from "../PlatformService";
|
} from "../PlatformService";
|
||||||
|
import { Settings } from "../../db/tables/settings";
|
||||||
|
import { MASTER_SETTINGS_KEY } from "../../db/tables/settings";
|
||||||
|
import { db } from "../../db";
|
||||||
import { logger } from "../../utils/logger";
|
import { logger } from "../../utils/logger";
|
||||||
|
import { Account } from "../../db/tables/accounts";
|
||||||
|
import { Contact } from "../../db/tables/contacts";
|
||||||
|
import { WebSQLiteService } from "../sqlite/WebSQLiteService";
|
||||||
|
import { accountsDBPromise } from "../../db";
|
||||||
|
import { accessToken } from "../../libs/crypto";
|
||||||
|
import { getPlanFromCache as getPlanFromCacheImpl } from "../../libs/endorserServer";
|
||||||
|
import { PlanSummaryRecord } from "../../interfaces/records";
|
||||||
|
import { Axios } from "axios";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Platform service implementation for web browser platform.
|
* Platform service implementation for web browser platform.
|
||||||
@@ -19,6 +31,8 @@ import { logger } from "../../utils/logger";
|
|||||||
* due to browser security restrictions. These methods throw appropriate errors.
|
* due to browser security restrictions. These methods throw appropriate errors.
|
||||||
*/
|
*/
|
||||||
export class WebPlatformService implements PlatformService {
|
export class WebPlatformService implements PlatformService {
|
||||||
|
private sqliteService: WebSQLiteService | null = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the capabilities of the web platform
|
* Gets the capabilities of the web platform
|
||||||
* @returns Platform capabilities object
|
* @returns Platform capabilities object
|
||||||
@@ -26,11 +40,17 @@ export class WebPlatformService implements PlatformService {
|
|||||||
getCapabilities(): PlatformCapabilities {
|
getCapabilities(): PlatformCapabilities {
|
||||||
return {
|
return {
|
||||||
hasFileSystem: false,
|
hasFileSystem: false,
|
||||||
hasCamera: true, // Through file input with capture
|
hasCamera: true,
|
||||||
isMobile: /iPhone|iPad|iPod|Android/i.test(navigator.userAgent),
|
isMobile: false,
|
||||||
isIOS: /iPad|iPhone|iPod/.test(navigator.userAgent),
|
isIOS: false,
|
||||||
hasFileDownload: true,
|
hasFileDownload: true,
|
||||||
needsFileHandlingInstructions: false,
|
needsFileHandlingInstructions: false,
|
||||||
|
sqlite: {
|
||||||
|
supported: true,
|
||||||
|
runsInWorker: true,
|
||||||
|
hasSharedArrayBuffer: typeof SharedArrayBuffer !== "undefined",
|
||||||
|
supportsWAL: true,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,4 +379,139 @@ export class WebPlatformService implements PlatformService {
|
|||||||
async writeAndShareFile(_fileName: string, _content: string): Promise<void> {
|
async writeAndShareFile(_fileName: string, _content: string): Promise<void> {
|
||||||
throw new Error("File system access not available in web platform");
|
throw new Error("File system access not available in web platform");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateMasterSettings(
|
||||||
|
settingsChanges: Partial<Settings>,
|
||||||
|
): Promise<void> {
|
||||||
|
try {
|
||||||
|
delete settingsChanges.accountDid; // just in case
|
||||||
|
delete settingsChanges.id; // ensure there is no "id" that would override the key
|
||||||
|
|
||||||
|
await db.settings.update(MASTER_SETTINGS_KEY, settingsChanges);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Error updating master settings:", error);
|
||||||
|
throw new Error(
|
||||||
|
`Failed to update settings. We recommend you try again or restart the app.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async getActiveAccountSettings(): Promise<Settings> {
|
||||||
|
const defaultSettings = (await db.settings.get(MASTER_SETTINGS_KEY)) || {};
|
||||||
|
if (!defaultSettings.activeDid) {
|
||||||
|
return defaultSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
const overrideSettings =
|
||||||
|
(await db.settings
|
||||||
|
.where("accountDid")
|
||||||
|
.equals(defaultSettings.activeDid)
|
||||||
|
.first()) || {};
|
||||||
|
|
||||||
|
return { ...defaultSettings, ...overrideSettings };
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateAccountSettings(
|
||||||
|
accountDid: string,
|
||||||
|
settingsChanges: Partial<Settings>,
|
||||||
|
): Promise<void> {
|
||||||
|
settingsChanges.accountDid = accountDid;
|
||||||
|
delete settingsChanges.id; // key off account, not ID
|
||||||
|
|
||||||
|
const result = await db.settings
|
||||||
|
.where("accountDid")
|
||||||
|
.equals(accountDid)
|
||||||
|
.modify(settingsChanges);
|
||||||
|
|
||||||
|
if (result === 0) {
|
||||||
|
// If no record was updated, create a new one
|
||||||
|
settingsChanges.id = (await db.settings.count()) + 1;
|
||||||
|
await db.settings.add(settingsChanges);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Account Management
|
||||||
|
async getAccounts(): Promise<Account[]> {
|
||||||
|
const accountsDB = await accountsDBPromise;
|
||||||
|
return await accountsDB.accounts.toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
async getAccount(did: string): Promise<Account | undefined> {
|
||||||
|
const accountsDB = await accountsDBPromise;
|
||||||
|
return await accountsDB.accounts.where("did").equals(did).first();
|
||||||
|
}
|
||||||
|
|
||||||
|
async addAccount(account: Account): Promise<void> {
|
||||||
|
const accountsDB = await accountsDBPromise;
|
||||||
|
await accountsDB.accounts.add(account);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Contact Management
|
||||||
|
async getContacts(): Promise<Contact[]> {
|
||||||
|
return await db.contacts.toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
async getAllContacts(): Promise<Contact[]> {
|
||||||
|
return await this.getContacts();
|
||||||
|
}
|
||||||
|
|
||||||
|
async getHeaders(did?: string): Promise<Record<string, string>> {
|
||||||
|
const headers: Record<string, string> = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
};
|
||||||
|
|
||||||
|
if (did) {
|
||||||
|
try {
|
||||||
|
const account = await this.getAccount(did);
|
||||||
|
if (account?.passkeyCredIdHex) {
|
||||||
|
// Handle passkey authentication
|
||||||
|
const token = await this.getPasskeyToken(did);
|
||||||
|
headers["Authorization"] = `Bearer ${token}`;
|
||||||
|
} else {
|
||||||
|
// Handle regular authentication
|
||||||
|
const token = await this.getAccessToken(did);
|
||||||
|
headers["Authorization"] = `Bearer ${token}`;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Failed to get headers:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return headers;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async getPasskeyToken(did: string): Promise<string> {
|
||||||
|
// For now, use the same token mechanism as regular auth
|
||||||
|
// TODO: Implement proper passkey authentication
|
||||||
|
return this.getAccessToken(did);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async getAccessToken(did: string): Promise<string> {
|
||||||
|
try {
|
||||||
|
const token = await accessToken(did);
|
||||||
|
if (!token) {
|
||||||
|
throw new Error("Failed to generate access token");
|
||||||
|
}
|
||||||
|
return token;
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Error getting access token:", error);
|
||||||
|
throw new Error("Failed to get access token: " + (error instanceof Error ? error.message : String(error)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async getSQLite(): Promise<SQLiteOperations> {
|
||||||
|
if (!this.sqliteService) {
|
||||||
|
this.sqliteService = new WebSQLiteService();
|
||||||
|
}
|
||||||
|
return this.sqliteService;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getPlanFromCache(
|
||||||
|
handleId: string | undefined,
|
||||||
|
axios: Axios,
|
||||||
|
apiServer: string,
|
||||||
|
requesterDid?: string,
|
||||||
|
): Promise<PlanSummaryRecord | undefined> {
|
||||||
|
return getPlanFromCacheImpl(handleId, axios, apiServer, requesterDid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
248
src/services/sqlite/AbsurdSQLService.ts
Normal file
248
src/services/sqlite/AbsurdSQLService.ts
Normal file
@@ -0,0 +1,248 @@
|
|||||||
|
import initSqlJs, { Database } from "@jlongster/sql.js";
|
||||||
|
import { SQLiteFS } from "absurd-sql";
|
||||||
|
import { IndexedDBBackend } from "absurd-sql/dist/indexeddb-backend";
|
||||||
|
import { BaseSQLiteService } from "./BaseSQLiteService";
|
||||||
|
import {
|
||||||
|
SQLiteConfig,
|
||||||
|
SQLiteResult,
|
||||||
|
PreparedStatement,
|
||||||
|
} from "../PlatformService";
|
||||||
|
import { logger } from "../../utils/logger";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SQLite implementation using absurd-sql for web browsers.
|
||||||
|
* Provides SQLite access in the browser using Web Workers and IndexedDB.
|
||||||
|
*/
|
||||||
|
export class AbsurdSQLService extends BaseSQLiteService {
|
||||||
|
private db: Database | null = null;
|
||||||
|
private worker: Worker | null = null;
|
||||||
|
private config: SQLiteConfig | null = null;
|
||||||
|
|
||||||
|
async initialize(config: SQLiteConfig): Promise<void> {
|
||||||
|
if (this.initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.config = config;
|
||||||
|
const SQL = await initSqlJs({
|
||||||
|
locateFile: (file) => `/sql-wasm/${file}`,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Initialize the virtual file system
|
||||||
|
const backend = new IndexedDBBackend(this.config.name);
|
||||||
|
const fs = new SQLiteFS(SQL.FS, backend);
|
||||||
|
SQL.register_for_idb(fs);
|
||||||
|
|
||||||
|
// Create and initialize the database
|
||||||
|
this.db = new SQL.Database(this.config.name, {
|
||||||
|
filename: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Configure database settings
|
||||||
|
if (this.config.useWAL) {
|
||||||
|
await this.execute("PRAGMA journal_mode = WAL");
|
||||||
|
this.stats.walMode = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.config.useMMap) {
|
||||||
|
const mmapSize = this.config.mmapSize ?? 30000000000;
|
||||||
|
await this.execute(`PRAGMA mmap_size = ${mmapSize}`);
|
||||||
|
this.stats.mmapActive = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set other pragmas for performance
|
||||||
|
await this.execute("PRAGMA synchronous = NORMAL");
|
||||||
|
await this.execute("PRAGMA temp_store = MEMORY");
|
||||||
|
await this.execute("PRAGMA cache_size = -2000"); // Use 2MB of cache
|
||||||
|
|
||||||
|
// Start the Web Worker for async operations
|
||||||
|
this.worker = new Worker(new URL("./sqlite.worker.ts", import.meta.url), {
|
||||||
|
type: "module",
|
||||||
|
});
|
||||||
|
|
||||||
|
this.initialized = true;
|
||||||
|
await this.updateStats();
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Failed to initialize Absurd SQL:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async close(): Promise<void> {
|
||||||
|
if (!this.initialized || !this.db) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Finalize all prepared statements
|
||||||
|
for (const [_sql, stmt] of this.preparedStatements) {
|
||||||
|
logger.debug("finalizing statement", _sql);
|
||||||
|
await stmt.finalize();
|
||||||
|
}
|
||||||
|
this.preparedStatements.clear();
|
||||||
|
|
||||||
|
// Close the database
|
||||||
|
this.db.close();
|
||||||
|
this.db = null;
|
||||||
|
|
||||||
|
// Terminate the worker
|
||||||
|
if (this.worker) {
|
||||||
|
this.worker.terminate();
|
||||||
|
this.worker = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.initialized = false;
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Failed to close Absurd SQL connection:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async _executeQuery<T>(
|
||||||
|
sql: string,
|
||||||
|
params: unknown[] = [],
|
||||||
|
operation: "query" | "execute" = "query",
|
||||||
|
): Promise<SQLiteResult<T>> {
|
||||||
|
if (!this.db) {
|
||||||
|
throw new Error("Database not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
let lastInsertId: number | undefined = undefined;
|
||||||
|
|
||||||
|
if (operation === "query") {
|
||||||
|
const stmt = this.db.prepare(sql);
|
||||||
|
const rows: T[] = [];
|
||||||
|
|
||||||
|
try {
|
||||||
|
while (stmt.step()) {
|
||||||
|
rows.push(stmt.getAsObject() as T);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
stmt.free();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get last insert ID safely
|
||||||
|
const result = this.db.exec("SELECT last_insert_rowid() AS id");
|
||||||
|
lastInsertId =
|
||||||
|
(result?.[0]?.values?.[0]?.[0] as number | undefined) ?? undefined;
|
||||||
|
|
||||||
|
return {
|
||||||
|
rows,
|
||||||
|
rowsAffected: this.db.getRowsModified(),
|
||||||
|
lastInsertId,
|
||||||
|
executionTime: 0, // Will be set by base class
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
this.db.run(sql, params);
|
||||||
|
|
||||||
|
// Get last insert ID after execute
|
||||||
|
const result = this.db.exec("SELECT last_insert_rowid() AS id");
|
||||||
|
lastInsertId =
|
||||||
|
(result?.[0]?.values?.[0]?.[0] as number | undefined) ?? undefined;
|
||||||
|
|
||||||
|
return {
|
||||||
|
rows: [],
|
||||||
|
rowsAffected: this.db.getRowsModified(),
|
||||||
|
lastInsertId,
|
||||||
|
executionTime: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Absurd SQL query failed:", {
|
||||||
|
sql,
|
||||||
|
params,
|
||||||
|
error: error instanceof Error ? error.message : String(error),
|
||||||
|
});
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async _beginTransaction(): Promise<void> {
|
||||||
|
if (!this.db) {
|
||||||
|
throw new Error("Database not initialized");
|
||||||
|
}
|
||||||
|
this.db.exec("BEGIN TRANSACTION");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async _commitTransaction(): Promise<void> {
|
||||||
|
if (!this.db) {
|
||||||
|
throw new Error("Database not initialized");
|
||||||
|
}
|
||||||
|
this.db.exec("COMMIT");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async _rollbackTransaction(): Promise<void> {
|
||||||
|
if (!this.db) {
|
||||||
|
throw new Error("Database not initialized");
|
||||||
|
}
|
||||||
|
this.db.exec("ROLLBACK");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async _prepareStatement<T>(
|
||||||
|
_sql: string,
|
||||||
|
): Promise<PreparedStatement<T>> {
|
||||||
|
if (!this.db) {
|
||||||
|
throw new Error("Database not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
const stmt = this.db.prepare(_sql);
|
||||||
|
return {
|
||||||
|
execute: async (params: unknown[] = []) => {
|
||||||
|
if (!this.db) {
|
||||||
|
throw new Error("Database not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const rows: T[] = [];
|
||||||
|
stmt.bind(params);
|
||||||
|
while (stmt.step()) {
|
||||||
|
rows.push(stmt.getAsObject() as T);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Safely extract lastInsertId
|
||||||
|
const result = this.db.exec("SELECT last_insert_rowid()");
|
||||||
|
const rawId = result?.[0]?.values?.[0]?.[0];
|
||||||
|
const lastInsertId = typeof rawId === "number" ? rawId : undefined;
|
||||||
|
|
||||||
|
return {
|
||||||
|
rows,
|
||||||
|
rowsAffected: this.db.getRowsModified(),
|
||||||
|
lastInsertId,
|
||||||
|
executionTime: 0, // Will be set by base class
|
||||||
|
};
|
||||||
|
} finally {
|
||||||
|
stmt.reset();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
finalize: async () => {
|
||||||
|
stmt.free();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async _finalizeStatement(_sql: string): Promise<void> {
|
||||||
|
// Statements are finalized when the PreparedStatement is finalized
|
||||||
|
}
|
||||||
|
|
||||||
|
async getDatabaseSize(): Promise<number> {
|
||||||
|
if (!this.db) {
|
||||||
|
throw new Error("Database not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = this.db.exec(
|
||||||
|
"SELECT page_count * page_size as size FROM pragma_page_count(), pragma_page_size()",
|
||||||
|
);
|
||||||
|
|
||||||
|
const rawSize = result?.[0]?.values?.[0]?.[0];
|
||||||
|
const size = typeof rawSize === "number" ? rawSize : 0;
|
||||||
|
|
||||||
|
return size;
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Failed to get database size:", error);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
383
src/services/sqlite/BaseSQLiteService.ts
Normal file
383
src/services/sqlite/BaseSQLiteService.ts
Normal file
@@ -0,0 +1,383 @@
|
|||||||
|
import {
|
||||||
|
SQLiteOperations,
|
||||||
|
SQLiteConfig,
|
||||||
|
SQLiteResult,
|
||||||
|
PreparedStatement,
|
||||||
|
SQLiteStats,
|
||||||
|
} from "../PlatformService";
|
||||||
|
import { Settings, MASTER_SETTINGS_KEY } from "../../db/tables/settings";
|
||||||
|
import { logger } from "../../utils/logger";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for SQLite implementations across different platforms.
|
||||||
|
* Provides common functionality and error handling.
|
||||||
|
*/
|
||||||
|
export abstract class BaseSQLiteService implements SQLiteOperations {
|
||||||
|
protected initialized = false;
|
||||||
|
protected stats: SQLiteStats = {
|
||||||
|
totalQueries: 0,
|
||||||
|
avgExecutionTime: 0,
|
||||||
|
preparedStatements: 0,
|
||||||
|
databaseSize: 0,
|
||||||
|
walMode: false,
|
||||||
|
mmapActive: false,
|
||||||
|
};
|
||||||
|
protected preparedStatements: Map<string, PreparedStatement<unknown>> =
|
||||||
|
new Map();
|
||||||
|
|
||||||
|
abstract initialize(config: SQLiteConfig): Promise<void>;
|
||||||
|
abstract close(): Promise<void>;
|
||||||
|
abstract getDatabaseSize(): Promise<number>;
|
||||||
|
|
||||||
|
protected async executeQuery<T>(
|
||||||
|
sql: string,
|
||||||
|
params: unknown[] = [],
|
||||||
|
operation: "query" | "execute" = "query",
|
||||||
|
): Promise<SQLiteResult<T>> {
|
||||||
|
if (!this.initialized) {
|
||||||
|
throw new Error("SQLite database not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
const startTime = performance.now();
|
||||||
|
try {
|
||||||
|
const result = await this._executeQuery<T>(sql, params, operation);
|
||||||
|
const executionTime = performance.now() - startTime;
|
||||||
|
|
||||||
|
// Update stats
|
||||||
|
this.stats.totalQueries++;
|
||||||
|
this.stats.avgExecutionTime =
|
||||||
|
(this.stats.avgExecutionTime * (this.stats.totalQueries - 1) +
|
||||||
|
executionTime) /
|
||||||
|
this.stats.totalQueries;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
executionTime,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("SQLite query failed:", {
|
||||||
|
sql,
|
||||||
|
params,
|
||||||
|
error: error instanceof Error ? error.message : String(error),
|
||||||
|
});
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract _executeQuery<T>(
|
||||||
|
sql: string,
|
||||||
|
params: unknown[],
|
||||||
|
operation: "query" | "execute",
|
||||||
|
): Promise<SQLiteResult<T>>;
|
||||||
|
|
||||||
|
async query<T>(
|
||||||
|
sql: string,
|
||||||
|
params: unknown[] = [],
|
||||||
|
): Promise<SQLiteResult<T>> {
|
||||||
|
return this.executeQuery<T>(sql, params, "query");
|
||||||
|
}
|
||||||
|
|
||||||
|
async execute(sql: string, params: unknown[] = []): Promise<number> {
|
||||||
|
const result = await this.executeQuery<unknown>(sql, params, "execute");
|
||||||
|
return result.rowsAffected;
|
||||||
|
}
|
||||||
|
|
||||||
|
async transaction(
|
||||||
|
statements: { sql: string; params?: unknown[] }[],
|
||||||
|
): Promise<void> {
|
||||||
|
if (!this.initialized) {
|
||||||
|
throw new Error("SQLite database not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await this._beginTransaction();
|
||||||
|
for (const { sql, params = [] } of statements) {
|
||||||
|
await this.executeQuery(sql, params, "execute");
|
||||||
|
}
|
||||||
|
await this._commitTransaction();
|
||||||
|
} catch (error) {
|
||||||
|
await this._rollbackTransaction();
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract _beginTransaction(): Promise<void>;
|
||||||
|
protected abstract _commitTransaction(): Promise<void>;
|
||||||
|
protected abstract _rollbackTransaction(): Promise<void>;
|
||||||
|
|
||||||
|
async getMaxValue<T>(
|
||||||
|
table: string,
|
||||||
|
column: string,
|
||||||
|
where?: string,
|
||||||
|
params: unknown[] = [],
|
||||||
|
): Promise<T | null> {
|
||||||
|
const sql = `SELECT MAX(${column}) as max_value FROM ${table}${where ? ` WHERE ${where}` : ""}`;
|
||||||
|
const result = await this.query<{ max_value: T }>(sql, params);
|
||||||
|
return result.rows[0]?.max_value ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async prepare<T>(sql: string): Promise<PreparedStatement<T>> {
|
||||||
|
if (!this.initialized) {
|
||||||
|
throw new Error("SQLite database not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
const stmt = await this._prepareStatement<T>(sql);
|
||||||
|
this.stats.preparedStatements++;
|
||||||
|
this.preparedStatements.set(sql, stmt);
|
||||||
|
|
||||||
|
return {
|
||||||
|
execute: async (params: unknown[] = []) => {
|
||||||
|
return this.executeQuery<T>(sql, params, "query");
|
||||||
|
},
|
||||||
|
finalize: async () => {
|
||||||
|
await this._finalizeStatement(sql);
|
||||||
|
this.preparedStatements.delete(sql);
|
||||||
|
this.stats.preparedStatements--;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract _prepareStatement<T>(
|
||||||
|
sql: string,
|
||||||
|
): Promise<PreparedStatement<T>>;
|
||||||
|
protected abstract _finalizeStatement(sql: string): Promise<void>;
|
||||||
|
|
||||||
|
async getStats(): Promise<SQLiteStats> {
|
||||||
|
return {
|
||||||
|
...this.stats,
|
||||||
|
databaseSize: await this.getDatabaseSize(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async updateStats(): Promise<void> {
|
||||||
|
this.stats.databaseSize = await this.getDatabaseSize();
|
||||||
|
// Platform-specific stats updates can be implemented in subclasses
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async setupSchema(): Promise<void> {
|
||||||
|
await this.execute(`
|
||||||
|
CREATE TABLE IF NOT EXISTS settings (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
accountDid TEXT,
|
||||||
|
activeDid TEXT,
|
||||||
|
apiServer TEXT,
|
||||||
|
filterFeedByNearby INTEGER,
|
||||||
|
filterFeedByVisible INTEGER,
|
||||||
|
finishedOnboarding INTEGER,
|
||||||
|
firstName TEXT,
|
||||||
|
hideRegisterPromptOnNewContact INTEGER,
|
||||||
|
isRegistered INTEGER,
|
||||||
|
lastName TEXT,
|
||||||
|
lastAckedOfferToUserJwtId TEXT,
|
||||||
|
lastAckedOfferToUserProjectsJwtId TEXT,
|
||||||
|
lastNotifiedClaimId TEXT,
|
||||||
|
lastViewedClaimId TEXT,
|
||||||
|
notifyingNewActivityTime TEXT,
|
||||||
|
notifyingReminderMessage TEXT,
|
||||||
|
notifyingReminderTime TEXT,
|
||||||
|
partnerApiServer TEXT,
|
||||||
|
passkeyExpirationMinutes INTEGER,
|
||||||
|
profileImageUrl TEXT,
|
||||||
|
searchBoxes TEXT,
|
||||||
|
showContactGivesInline INTEGER,
|
||||||
|
showGeneralAdvanced INTEGER,
|
||||||
|
showShortcutBvc INTEGER,
|
||||||
|
vapid TEXT,
|
||||||
|
warnIfProdServer INTEGER,
|
||||||
|
warnIfTestServer INTEGER,
|
||||||
|
webPushServer TEXT
|
||||||
|
)
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async settingsToRow(
|
||||||
|
settings: Partial<Settings>,
|
||||||
|
): Promise<Record<string, unknown>> {
|
||||||
|
const row: Record<string, unknown> = {};
|
||||||
|
|
||||||
|
// Convert boolean values to integers for SQLite
|
||||||
|
if ("filterFeedByNearby" in settings)
|
||||||
|
row.filterFeedByNearby = settings.filterFeedByNearby ? 1 : 0;
|
||||||
|
if ("filterFeedByVisible" in settings)
|
||||||
|
row.filterFeedByVisible = settings.filterFeedByVisible ? 1 : 0;
|
||||||
|
if ("finishedOnboarding" in settings)
|
||||||
|
row.finishedOnboarding = settings.finishedOnboarding ? 1 : 0;
|
||||||
|
if ("hideRegisterPromptOnNewContact" in settings)
|
||||||
|
row.hideRegisterPromptOnNewContact =
|
||||||
|
settings.hideRegisterPromptOnNewContact ? 1 : 0;
|
||||||
|
if ("isRegistered" in settings)
|
||||||
|
row.isRegistered = settings.isRegistered ? 1 : 0;
|
||||||
|
if ("showContactGivesInline" in settings)
|
||||||
|
row.showContactGivesInline = settings.showContactGivesInline ? 1 : 0;
|
||||||
|
if ("showGeneralAdvanced" in settings)
|
||||||
|
row.showGeneralAdvanced = settings.showGeneralAdvanced ? 1 : 0;
|
||||||
|
if ("showShortcutBvc" in settings)
|
||||||
|
row.showShortcutBvc = settings.showShortcutBvc ? 1 : 0;
|
||||||
|
if ("warnIfProdServer" in settings)
|
||||||
|
row.warnIfProdServer = settings.warnIfProdServer ? 1 : 0;
|
||||||
|
if ("warnIfTestServer" in settings)
|
||||||
|
row.warnIfTestServer = settings.warnIfTestServer ? 1 : 0;
|
||||||
|
|
||||||
|
// Handle JSON fields
|
||||||
|
if ("searchBoxes" in settings)
|
||||||
|
row.searchBoxes = JSON.stringify(settings.searchBoxes);
|
||||||
|
|
||||||
|
// Copy all other fields as is
|
||||||
|
Object.entries(settings).forEach(([key, value]) => {
|
||||||
|
if (!(key in row)) {
|
||||||
|
row[key] = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async rowToSettings(
|
||||||
|
row: Record<string, unknown>,
|
||||||
|
): Promise<Settings> {
|
||||||
|
const settings: Settings = {};
|
||||||
|
|
||||||
|
// Convert integer values back to booleans
|
||||||
|
if ("filterFeedByNearby" in row)
|
||||||
|
settings.filterFeedByNearby = !!row.filterFeedByNearby;
|
||||||
|
if ("filterFeedByVisible" in row)
|
||||||
|
settings.filterFeedByVisible = !!row.filterFeedByVisible;
|
||||||
|
if ("finishedOnboarding" in row)
|
||||||
|
settings.finishedOnboarding = !!row.finishedOnboarding;
|
||||||
|
if ("hideRegisterPromptOnNewContact" in row)
|
||||||
|
settings.hideRegisterPromptOnNewContact =
|
||||||
|
!!row.hideRegisterPromptOnNewContact;
|
||||||
|
if ("isRegistered" in row) settings.isRegistered = !!row.isRegistered;
|
||||||
|
if ("showContactGivesInline" in row)
|
||||||
|
settings.showContactGivesInline = !!row.showContactGivesInline;
|
||||||
|
if ("showGeneralAdvanced" in row)
|
||||||
|
settings.showGeneralAdvanced = !!row.showGeneralAdvanced;
|
||||||
|
if ("showShortcutBvc" in row)
|
||||||
|
settings.showShortcutBvc = !!row.showShortcutBvc;
|
||||||
|
if ("warnIfProdServer" in row)
|
||||||
|
settings.warnIfProdServer = !!row.warnIfProdServer;
|
||||||
|
if ("warnIfTestServer" in row)
|
||||||
|
settings.warnIfTestServer = !!row.warnIfTestServer;
|
||||||
|
|
||||||
|
// Parse JSON fields
|
||||||
|
if ("searchBoxes" in row && row.searchBoxes) {
|
||||||
|
try {
|
||||||
|
settings.searchBoxes = JSON.parse(row.searchBoxes);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Error parsing searchBoxes JSON:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy all other fields as is
|
||||||
|
Object.entries(row).forEach(([key, value]) => {
|
||||||
|
if (!(key in settings)) {
|
||||||
|
(settings as Record<string, unknown>)[key] = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateMasterSettings(
|
||||||
|
settingsChanges: Partial<Settings>,
|
||||||
|
): Promise<void> {
|
||||||
|
try {
|
||||||
|
const row = await this.settingsToRow(settingsChanges);
|
||||||
|
row.id = MASTER_SETTINGS_KEY;
|
||||||
|
delete row.accountDid;
|
||||||
|
|
||||||
|
const result = await this.execute(
|
||||||
|
`UPDATE settings SET ${Object.keys(row)
|
||||||
|
.map((k) => `${k} = ?`)
|
||||||
|
.join(", ")} WHERE id = ?`,
|
||||||
|
[...Object.values(row), MASTER_SETTINGS_KEY],
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result === 0) {
|
||||||
|
// If no record was updated, create a new one
|
||||||
|
await this.execute(
|
||||||
|
`INSERT INTO settings (${Object.keys(row).join(", ")}) VALUES (${Object.keys(
|
||||||
|
row,
|
||||||
|
)
|
||||||
|
.map(() => "?")
|
||||||
|
.join(", ")})`,
|
||||||
|
Object.values(row),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Error updating master settings:", error);
|
||||||
|
throw new Error("Failed to update settings");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async getActiveAccountSettings(): Promise<Settings> {
|
||||||
|
try {
|
||||||
|
const defaultSettings = await this.query<Record<string, unknown>>(
|
||||||
|
"SELECT * FROM settings WHERE id = ?",
|
||||||
|
[MASTER_SETTINGS_KEY],
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!defaultSettings.rows.length) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const settings = await this.rowToSettings(defaultSettings.rows[0]);
|
||||||
|
|
||||||
|
if (!settings.activeDid) {
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
const overrideSettings = await this.query<Record<string, unknown>>(
|
||||||
|
"SELECT * FROM settings WHERE accountDid = ?",
|
||||||
|
[settings.activeDid],
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!overrideSettings.rows.length) {
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
const override = await this.rowToSettings(overrideSettings.rows[0]);
|
||||||
|
return { ...settings, ...override };
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Error getting active account settings:", error);
|
||||||
|
throw new Error("Failed to get settings");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateAccountSettings(
|
||||||
|
accountDid: string,
|
||||||
|
settingsChanges: Partial<Settings>,
|
||||||
|
): Promise<void> {
|
||||||
|
try {
|
||||||
|
const row = await this.settingsToRow(settingsChanges);
|
||||||
|
row.accountDid = accountDid;
|
||||||
|
|
||||||
|
const result = await this.execute(
|
||||||
|
`UPDATE settings SET ${Object.keys(row)
|
||||||
|
.map((k) => `${k} = ?`)
|
||||||
|
.join(", ")} WHERE accountDid = ?`,
|
||||||
|
[...Object.values(row), accountDid],
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result === 0) {
|
||||||
|
// If no record was updated, create a new one
|
||||||
|
const idResult = await this.query<{ max: number }>(
|
||||||
|
"SELECT MAX(id) as max FROM settings",
|
||||||
|
);
|
||||||
|
row.id = (idResult.rows[0]?.max || 0) + 1;
|
||||||
|
|
||||||
|
await this.execute(
|
||||||
|
`INSERT INTO settings (${Object.keys(row).join(", ")}) VALUES (${Object.keys(
|
||||||
|
row,
|
||||||
|
)
|
||||||
|
.map(() => "?")
|
||||||
|
.join(", ")})`,
|
||||||
|
Object.values(row),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Error updating account settings:", error);
|
||||||
|
throw new Error("Failed to update settings");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
176
src/services/sqlite/CapacitorSQLiteService.ts
Normal file
176
src/services/sqlite/CapacitorSQLiteService.ts
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
import {
|
||||||
|
CapacitorSQLite,
|
||||||
|
SQLiteConnection,
|
||||||
|
SQLiteDBConnection,
|
||||||
|
} from "@capacitor-community/sqlite";
|
||||||
|
import { BaseSQLiteService } from "./BaseSQLiteService";
|
||||||
|
import {
|
||||||
|
SQLiteConfig,
|
||||||
|
SQLiteResult,
|
||||||
|
PreparedStatement,
|
||||||
|
} from "../PlatformService";
|
||||||
|
import { logger } from "../../utils/logger";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SQLite implementation using the Capacitor SQLite plugin.
|
||||||
|
* Provides native SQLite access on mobile platforms.
|
||||||
|
*/
|
||||||
|
export class CapacitorSQLiteService extends BaseSQLiteService {
|
||||||
|
private connection: SQLiteDBConnection | null = null;
|
||||||
|
private sqlite: SQLiteConnection | null = null;
|
||||||
|
|
||||||
|
async initialize(config: SQLiteConfig): Promise<void> {
|
||||||
|
if (this.initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.sqlite = new SQLiteConnection(CapacitorSQLite);
|
||||||
|
const db = await this.sqlite.createConnection(
|
||||||
|
config.name,
|
||||||
|
config.useWAL ?? false,
|
||||||
|
"no-encryption",
|
||||||
|
1,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
await db.open();
|
||||||
|
this.connection = db;
|
||||||
|
|
||||||
|
// Configure database settings
|
||||||
|
if (config.useWAL) {
|
||||||
|
await this.execute("PRAGMA journal_mode = WAL");
|
||||||
|
this.stats.walMode = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set other pragmas for performance
|
||||||
|
await this.execute("PRAGMA synchronous = NORMAL");
|
||||||
|
await this.execute("PRAGMA temp_store = MEMORY");
|
||||||
|
await this.execute("PRAGMA mmap_size = 30000000000");
|
||||||
|
this.stats.mmapActive = true;
|
||||||
|
|
||||||
|
// Set up database schema
|
||||||
|
await this.setupSchema();
|
||||||
|
|
||||||
|
this.initialized = true;
|
||||||
|
await this.updateStats();
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Failed to initialize Capacitor SQLite:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async close(): Promise<void> {
|
||||||
|
if (!this.initialized || !this.connection || !this.sqlite) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await this.connection.close();
|
||||||
|
await this.sqlite.closeConnection(this.connection);
|
||||||
|
this.connection = null;
|
||||||
|
this.sqlite = null;
|
||||||
|
this.initialized = false;
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Failed to close Capacitor SQLite connection:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async _executeQuery<T>(
|
||||||
|
sql: string,
|
||||||
|
params: unknown[] = [],
|
||||||
|
operation: "query" | "execute" = "query",
|
||||||
|
): Promise<SQLiteResult<T>> {
|
||||||
|
if (!this.connection) {
|
||||||
|
throw new Error("Database connection not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (operation === "query") {
|
||||||
|
const result = await this.connection.query(sql, params);
|
||||||
|
return {
|
||||||
|
rows: result.values as T[],
|
||||||
|
rowsAffected: result.changes?.changes ?? 0,
|
||||||
|
lastInsertId: result.changes?.lastId,
|
||||||
|
executionTime: 0, // Will be set by base class
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
const result = await this.connection.run(sql, params);
|
||||||
|
return {
|
||||||
|
rows: [],
|
||||||
|
rowsAffected: result.changes?.changes ?? 0,
|
||||||
|
lastInsertId: result.changes?.lastId,
|
||||||
|
executionTime: 0, // Will be set by base class
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Capacitor SQLite query failed:", {
|
||||||
|
sql,
|
||||||
|
params,
|
||||||
|
error: error instanceof Error ? error.message : String(error),
|
||||||
|
});
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async _beginTransaction(): Promise<void> {
|
||||||
|
if (!this.connection) {
|
||||||
|
throw new Error("Database connection not initialized");
|
||||||
|
}
|
||||||
|
await this.connection.execute("BEGIN TRANSACTION");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async _commitTransaction(): Promise<void> {
|
||||||
|
if (!this.connection) {
|
||||||
|
throw new Error("Database connection not initialized");
|
||||||
|
}
|
||||||
|
await this.connection.execute("COMMIT");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async _rollbackTransaction(): Promise<void> {
|
||||||
|
if (!this.connection) {
|
||||||
|
throw new Error("Database connection not initialized");
|
||||||
|
}
|
||||||
|
await this.connection.execute("ROLLBACK");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async _prepareStatement<T>(
|
||||||
|
sql: string,
|
||||||
|
): Promise<PreparedStatement<T>> {
|
||||||
|
if (!this.connection) {
|
||||||
|
throw new Error("Database connection not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Capacitor SQLite doesn't support prepared statements directly,
|
||||||
|
// so we'll simulate it by storing the SQL
|
||||||
|
return {
|
||||||
|
execute: async (params: unknown[] = []) => {
|
||||||
|
return this.executeQuery<T>(sql, params, "query");
|
||||||
|
},
|
||||||
|
finalize: async () => {
|
||||||
|
// No cleanup needed for Capacitor SQLite
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async _finalizeStatement(_sql: string): Promise<void> {
|
||||||
|
// No cleanup needed for Capacitor SQLite
|
||||||
|
}
|
||||||
|
|
||||||
|
async getDatabaseSize(): Promise<number> {
|
||||||
|
if (!this.connection) {
|
||||||
|
throw new Error("Database connection not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await this.connection.query(
|
||||||
|
"SELECT page_count * page_size as size FROM pragma_page_count(), pragma_page_size()",
|
||||||
|
);
|
||||||
|
return result.values?.[0]?.size ?? 0;
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Failed to get database size:", error);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
170
src/services/sqlite/WebSQLiteService.ts
Normal file
170
src/services/sqlite/WebSQLiteService.ts
Normal file
@@ -0,0 +1,170 @@
|
|||||||
|
import { BaseSQLiteService } from "./BaseSQLiteService";
|
||||||
|
import { SQLiteConfig, SQLiteOperations, SQLiteResult, PreparedStatement, SQLiteStats } from "../PlatformService";
|
||||||
|
import { logger } from "../../utils/logger";
|
||||||
|
import initSqlJs, { Database } from "@jlongster/sql.js";
|
||||||
|
import { SQLiteFS } from "absurd-sql";
|
||||||
|
import IndexedDBBackend from "absurd-sql/dist/indexeddb-backend";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SQLite implementation for web platform using absurd-sql
|
||||||
|
*/
|
||||||
|
export class WebSQLiteService extends BaseSQLiteService {
|
||||||
|
private db: Database | null = null;
|
||||||
|
private config: SQLiteConfig | null = null;
|
||||||
|
private worker: Worker | null = null;
|
||||||
|
|
||||||
|
async initialize(config: SQLiteConfig): Promise<void> {
|
||||||
|
if (this.initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.config = config;
|
||||||
|
|
||||||
|
// Initialize SQL.js
|
||||||
|
const SQL = await initSqlJs({
|
||||||
|
locateFile: (file) => `/sql-wasm.wasm`,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create a worker for SQLite operations
|
||||||
|
this.worker = new Worker("/sql-worker.js");
|
||||||
|
|
||||||
|
// Initialize SQLiteFS with IndexedDB backend
|
||||||
|
const backend = new IndexedDBBackend();
|
||||||
|
const fs = new SQLiteFS(backend, this.worker);
|
||||||
|
|
||||||
|
// Create database file
|
||||||
|
const dbPath = `/${config.name}.db`;
|
||||||
|
if (!(await fs.exists(dbPath))) {
|
||||||
|
await fs.writeFile(dbPath, new Uint8Array(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open database
|
||||||
|
this.db = new SQL.Database(dbPath, { filename: true });
|
||||||
|
|
||||||
|
// Configure database settings
|
||||||
|
if (config.useWAL) {
|
||||||
|
await this.execute("PRAGMA journal_mode = WAL");
|
||||||
|
this.stats.walMode = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set other pragmas for performance
|
||||||
|
await this.execute("PRAGMA synchronous = NORMAL");
|
||||||
|
await this.execute("PRAGMA temp_store = MEMORY");
|
||||||
|
await this.execute("PRAGMA cache_size = -2000"); // Use 2MB of cache
|
||||||
|
|
||||||
|
this.initialized = true;
|
||||||
|
await this.updateStats();
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Failed to initialize Web SQLite:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async _executeQuery<T>(
|
||||||
|
sql: string,
|
||||||
|
params: unknown[] = [],
|
||||||
|
operation: "query" | "execute" = "query",
|
||||||
|
): Promise<SQLiteResult<T>> {
|
||||||
|
if (!this.db) {
|
||||||
|
throw new Error("Database not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (operation === "query") {
|
||||||
|
const stmt = this.db.prepare(sql);
|
||||||
|
const results = stmt.get(params) as T[];
|
||||||
|
stmt.free();
|
||||||
|
return { results };
|
||||||
|
} else {
|
||||||
|
const stmt = this.db.prepare(sql);
|
||||||
|
stmt.run(params);
|
||||||
|
const changes = this.db.getRowsModified();
|
||||||
|
stmt.free();
|
||||||
|
return { changes };
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("SQLite query failed:", {
|
||||||
|
sql,
|
||||||
|
params,
|
||||||
|
error: error instanceof Error ? error.message : String(error),
|
||||||
|
});
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async close(): Promise<void> {
|
||||||
|
if (this.db) {
|
||||||
|
this.db.close();
|
||||||
|
this.db = null;
|
||||||
|
}
|
||||||
|
if (this.worker) {
|
||||||
|
this.worker.terminate();
|
||||||
|
this.worker = null;
|
||||||
|
}
|
||||||
|
this.initialized = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getDatabaseSize(): Promise<number> {
|
||||||
|
if (!this.db) {
|
||||||
|
throw new Error("Database not initialized");
|
||||||
|
}
|
||||||
|
const result = await this.query<{ size: number }>("SELECT page_count * page_size as size FROM pragma_page_count(), pragma_page_size()");
|
||||||
|
return result.results[0]?.size || 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
async prepare<T>(sql: string): Promise<PreparedStatement<T>> {
|
||||||
|
if (!this.db) {
|
||||||
|
throw new Error("Database not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
const stmt = this.db.prepare(sql);
|
||||||
|
const key = sql;
|
||||||
|
|
||||||
|
const preparedStmt: PreparedStatement<T> = {
|
||||||
|
execute: async (params: unknown[] = []) => {
|
||||||
|
try {
|
||||||
|
const results = stmt.get(params) as T[];
|
||||||
|
return { results };
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Prepared statement execution failed:", {
|
||||||
|
sql,
|
||||||
|
params,
|
||||||
|
error: error instanceof Error ? error.message : String(error),
|
||||||
|
});
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
finalize: () => {
|
||||||
|
stmt.free();
|
||||||
|
this.preparedStatements.delete(key);
|
||||||
|
this.stats.preparedStatements--;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
this.preparedStatements.set(key, preparedStmt);
|
||||||
|
this.stats.preparedStatements++;
|
||||||
|
|
||||||
|
return preparedStmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getStats(): Promise<SQLiteStats> {
|
||||||
|
await this.updateStats();
|
||||||
|
return this.stats;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async updateStats(): Promise<void> {
|
||||||
|
if (!this.db) {
|
||||||
|
throw new Error("Database not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
const size = await this.getDatabaseSize();
|
||||||
|
this.stats.databaseSize = size;
|
||||||
|
|
||||||
|
const walResult = await this.query<{ journal_mode: string }>("PRAGMA journal_mode");
|
||||||
|
this.stats.walMode = walResult.results[0]?.journal_mode === "wal";
|
||||||
|
|
||||||
|
const mmapResult = await this.query<{ mmap_size: number }>("PRAGMA mmap_size");
|
||||||
|
this.stats.mmapActive = mmapResult.results[0]?.mmap_size > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
150
src/services/sqlite/sqlite.worker.ts
Normal file
150
src/services/sqlite/sqlite.worker.ts
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
import initSqlJs, { Database } from "@jlongster/sql.js";
|
||||||
|
import { SQLiteFS } from "absurd-sql";
|
||||||
|
import { IndexedDBBackend } from "absurd-sql/dist/indexeddb-backend";
|
||||||
|
|
||||||
|
interface WorkerMessage {
|
||||||
|
type: "init" | "query" | "execute" | "transaction" | "close";
|
||||||
|
id: string;
|
||||||
|
dbName?: string;
|
||||||
|
sql?: string;
|
||||||
|
params?: unknown[];
|
||||||
|
statements?: { sql: string; params?: unknown[] }[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface WorkerResponse {
|
||||||
|
id: string;
|
||||||
|
error?: string;
|
||||||
|
result?: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
let db: Database | null = null;
|
||||||
|
|
||||||
|
async function initialize(dbName: string): Promise<void> {
|
||||||
|
if (db) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SQL = await initSqlJs({
|
||||||
|
locateFile: (file: string) => `/sql-wasm/${file}`,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Initialize the virtual file system
|
||||||
|
const backend = new IndexedDBBackend(dbName);
|
||||||
|
const fs = new SQLiteFS(SQL.FS, backend);
|
||||||
|
SQL.register_for_idb(fs);
|
||||||
|
|
||||||
|
// Create and initialize the database
|
||||||
|
db = new SQL.Database(dbName, {
|
||||||
|
filename: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Configure database settings
|
||||||
|
db.exec("PRAGMA synchronous = NORMAL");
|
||||||
|
db.exec("PRAGMA temp_store = MEMORY");
|
||||||
|
db.exec("PRAGMA cache_size = -2000"); // Use 2MB of cache
|
||||||
|
}
|
||||||
|
|
||||||
|
async function executeQuery(
|
||||||
|
sql: string,
|
||||||
|
params: unknown[] = [],
|
||||||
|
): Promise<unknown> {
|
||||||
|
if (!db) {
|
||||||
|
throw new Error("Database not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
const stmt = db.prepare(sql);
|
||||||
|
try {
|
||||||
|
const rows: unknown[] = [];
|
||||||
|
stmt.bind(params);
|
||||||
|
while (stmt.step()) {
|
||||||
|
rows.push(stmt.getAsObject());
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
rows,
|
||||||
|
rowsAffected: db.getRowsModified(),
|
||||||
|
lastInsertId: db.exec("SELECT last_insert_rowid()")[0]?.values[0]?.[0],
|
||||||
|
};
|
||||||
|
} finally {
|
||||||
|
stmt.free();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function executeTransaction(
|
||||||
|
statements: { sql: string; params?: unknown[] }[],
|
||||||
|
): Promise<void> {
|
||||||
|
if (!db) {
|
||||||
|
throw new Error("Database not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
db.exec("BEGIN TRANSACTION");
|
||||||
|
for (const { sql, params = [] } of statements) {
|
||||||
|
const stmt = db.prepare(sql);
|
||||||
|
try {
|
||||||
|
stmt.bind(params);
|
||||||
|
stmt.step();
|
||||||
|
} finally {
|
||||||
|
stmt.free();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
db.exec("COMMIT");
|
||||||
|
} catch (error) {
|
||||||
|
db.exec("ROLLBACK");
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function close(): Promise<void> {
|
||||||
|
if (db) {
|
||||||
|
db.close();
|
||||||
|
db = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.onmessage = async (event: MessageEvent<WorkerMessage>) => {
|
||||||
|
const { type, id, dbName, sql, params, statements } = event.data;
|
||||||
|
const response: WorkerResponse = { id };
|
||||||
|
|
||||||
|
try {
|
||||||
|
switch (type) {
|
||||||
|
case "init":
|
||||||
|
if (!dbName) {
|
||||||
|
throw new Error("Database name is required for initialization");
|
||||||
|
}
|
||||||
|
await initialize(dbName);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "query":
|
||||||
|
if (!sql) {
|
||||||
|
throw new Error("SQL query is required");
|
||||||
|
}
|
||||||
|
response.result = await executeQuery(sql, params);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "execute":
|
||||||
|
if (!sql) {
|
||||||
|
throw new Error("SQL statement is required");
|
||||||
|
}
|
||||||
|
response.result = await executeQuery(sql, params);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "transaction":
|
||||||
|
if (!statements?.length) {
|
||||||
|
throw new Error("Transaction statements are required");
|
||||||
|
}
|
||||||
|
await executeTransaction(statements);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "close":
|
||||||
|
await close();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new Error(`Unknown message type: ${type}`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
response.error = error instanceof Error ? error.message : String(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.postMessage(response);
|
||||||
|
};
|
||||||
45
src/types/absurd-sql.d.ts
vendored
Normal file
45
src/types/absurd-sql.d.ts
vendored
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
declare module "@jlongster/sql.js" {
|
||||||
|
export interface Database {
|
||||||
|
exec(
|
||||||
|
sql: string,
|
||||||
|
params?: unknown[],
|
||||||
|
): { columns: string[]; values: unknown[][] }[];
|
||||||
|
prepare(sql: string): Statement;
|
||||||
|
run(sql: string, params?: unknown[]): void;
|
||||||
|
getRowsModified(): number;
|
||||||
|
close(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Statement {
|
||||||
|
step(): boolean;
|
||||||
|
getAsObject(): Record<string, unknown>;
|
||||||
|
bind(params: unknown[]): void;
|
||||||
|
reset(): void;
|
||||||
|
free(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface InitSqlJsStatic {
|
||||||
|
Database: new (
|
||||||
|
filename?: string,
|
||||||
|
options?: { filename: boolean },
|
||||||
|
) => Database;
|
||||||
|
FS: unknown;
|
||||||
|
register_for_idb(fs: unknown): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function initSqlJs(options?: {
|
||||||
|
locateFile?: (file: string) => string;
|
||||||
|
}): Promise<InitSqlJsStatic>;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module "absurd-sql" {
|
||||||
|
export class SQLiteFS {
|
||||||
|
constructor(fs: unknown, backend: unknown);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module "absurd-sql/dist/indexeddb-backend" {
|
||||||
|
export class IndexedDBBackend {
|
||||||
|
constructor(dbName: string);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,9 +9,9 @@ const crypto = {
|
|||||||
},
|
},
|
||||||
createHash: () => ({
|
createHash: () => ({
|
||||||
update: () => ({
|
update: () => ({
|
||||||
digest: () => new Uint8Array(32) // Return empty hash
|
digest: () => new Uint8Array(32), // Return empty hash
|
||||||
})
|
}),
|
||||||
})
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
export default crypto;
|
export default crypto;
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
// Minimal fs module implementation for browser
|
// Minimal fs module implementation for browser
|
||||||
const fs = {
|
const fs = {
|
||||||
readFileSync: () => {
|
readFileSync: () => {
|
||||||
throw new Error('fs.readFileSync is not supported in browser');
|
throw new Error("fs.readFileSync is not supported in browser");
|
||||||
},
|
},
|
||||||
writeFileSync: () => {
|
writeFileSync: () => {
|
||||||
throw new Error('fs.writeFileSync is not supported in browser');
|
throw new Error("fs.writeFileSync is not supported in browser");
|
||||||
},
|
},
|
||||||
existsSync: () => false,
|
existsSync: () => false,
|
||||||
mkdirSync: () => {},
|
mkdirSync: () => {},
|
||||||
readdirSync: () => [],
|
readdirSync: () => [],
|
||||||
statSync: () => ({
|
statSync: () => ({
|
||||||
isDirectory: () => false,
|
isDirectory: () => false,
|
||||||
isFile: () => false
|
isFile: () => false,
|
||||||
})
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
export default fs;
|
export default fs;
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
// Minimal path module implementation for browser
|
// Minimal path module implementation for browser
|
||||||
const path = {
|
const path = {
|
||||||
resolve: (...parts) => parts.join('/'),
|
resolve: (...parts) => parts.join("/"),
|
||||||
join: (...parts) => parts.join('/'),
|
join: (...parts) => parts.join("/"),
|
||||||
dirname: (p) => p.split('/').slice(0, -1).join('/'),
|
dirname: (p) => p.split("/").slice(0, -1).join("/"),
|
||||||
basename: (p) => p.split('/').pop(),
|
basename: (p) => p.split("/").pop(),
|
||||||
extname: (p) => {
|
extname: (p) => {
|
||||||
const parts = p.split('.');
|
const parts = p.split(".");
|
||||||
return parts.length > 1 ? '.' + parts.pop() : '';
|
return parts.length > 1 ? "." + parts.pop() : "";
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default path;
|
export default path;
|
||||||
@@ -994,13 +994,6 @@ import {
|
|||||||
IMAGE_TYPE_PROFILE,
|
IMAGE_TYPE_PROFILE,
|
||||||
NotificationIface,
|
NotificationIface,
|
||||||
} from "../constants/app";
|
} from "../constants/app";
|
||||||
import {
|
|
||||||
db,
|
|
||||||
logConsoleAndDb,
|
|
||||||
retrieveSettingsForActiveAccount,
|
|
||||||
updateAccountSettings,
|
|
||||||
} from "../db/index";
|
|
||||||
import { Account } from "../db/tables/accounts";
|
|
||||||
import { Contact } from "../db/tables/contacts";
|
import { Contact } from "../db/tables/contacts";
|
||||||
import {
|
import {
|
||||||
DEFAULT_PASSKEY_EXPIRATION_MINUTES,
|
DEFAULT_PASSKEY_EXPIRATION_MINUTES,
|
||||||
@@ -1215,11 +1208,12 @@ export default class AccountViewView extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes component state with values from the database or defaults.
|
* Initializes component state using PlatformService for database operations
|
||||||
|
* Keeps all endorserServer functionality unchanged
|
||||||
*/
|
*/
|
||||||
async initializeState() {
|
async initializeState() {
|
||||||
await db.open();
|
const platform = this.$platform;
|
||||||
const settings = await retrieveSettingsForActiveAccount();
|
const settings = await platform.getActiveAccountSettings();
|
||||||
|
|
||||||
this.activeDid = settings.activeDid || "";
|
this.activeDid = settings.activeDid || "";
|
||||||
this.apiServer = settings.apiServer || "";
|
this.apiServer = settings.apiServer || "";
|
||||||
@@ -1252,6 +1246,29 @@ export default class AccountViewView extends Vue {
|
|||||||
this.webPushServerInput = settings.webPushServer || this.webPushServerInput;
|
this.webPushServerInput = settings.webPushServer || this.webPushServerInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates account settings using PlatformService
|
||||||
|
* Keeps all endorserServer functionality unchanged
|
||||||
|
*/
|
||||||
|
async updateSettings(settingsChanges: Record<string, unknown>) {
|
||||||
|
try {
|
||||||
|
const platform = this.$platform;
|
||||||
|
await platform.updateAccountSettings(this.activeDid, settingsChanges);
|
||||||
|
await this.initializeState();
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Error updating settings:", error);
|
||||||
|
this.$notify(
|
||||||
|
{
|
||||||
|
group: "alert",
|
||||||
|
type: "danger",
|
||||||
|
title: "Error",
|
||||||
|
text: "There was a problem updating your settings.",
|
||||||
|
},
|
||||||
|
5000,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// call fn, copy text to the clipboard, then redo fn after 2 seconds
|
// call fn, copy text to the clipboard, then redo fn after 2 seconds
|
||||||
doCopyTwoSecRedo(text: string, fn: () => void) {
|
doCopyTwoSecRedo(text: string, fn: () => void) {
|
||||||
fn();
|
fn();
|
||||||
|
|||||||
@@ -439,13 +439,11 @@ import { useClipboard } from "@vueuse/core";
|
|||||||
import { RouteLocationNormalizedLoaded, Router } from "vue-router";
|
import { RouteLocationNormalizedLoaded, Router } from "vue-router";
|
||||||
import QuickNav from "../components/QuickNav.vue";
|
import QuickNav from "../components/QuickNav.vue";
|
||||||
import { NotificationIface } from "../constants/app";
|
import { NotificationIface } from "../constants/app";
|
||||||
import { db, retrieveSettingsForActiveAccount } from "../db/index";
|
|
||||||
import { Contact } from "../db/tables/contacts";
|
import { Contact } from "../db/tables/contacts";
|
||||||
import * as serverUtil from "../libs/endorserServer";
|
import * as serverUtil from "../libs/endorserServer";
|
||||||
import { GenericVerifiableCredential, GiveSummaryRecord } from "../interfaces";
|
import { GenericVerifiableCredential, GiveSummaryRecord } from "../interfaces";
|
||||||
import { displayAmount } from "../libs/endorserServer";
|
import { displayAmount } from "../libs/endorserServer";
|
||||||
import * as libsUtil from "../libs/util";
|
import * as libsUtil from "../libs/util";
|
||||||
import { retrieveAccountDids } from "../libs/util";
|
|
||||||
import TopMessage from "../components/TopMessage.vue";
|
import TopMessage from "../components/TopMessage.vue";
|
||||||
import { logger } from "../utils/logger";
|
import { logger } from "../utils/logger";
|
||||||
/**
|
/**
|
||||||
@@ -526,14 +524,17 @@ export default class ConfirmGiftView extends Vue {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes component settings and user data
|
* Initializes component settings and user data
|
||||||
|
* Only database operations are migrated to PlatformService
|
||||||
|
* API-related utilities remain using serverUtil
|
||||||
*/
|
*/
|
||||||
private async initializeSettings() {
|
private async initializeSettings() {
|
||||||
const settings = await retrieveSettingsForActiveAccount();
|
const platform = this.$platform;
|
||||||
|
const settings = await platform.getActiveAccountSettings();
|
||||||
this.activeDid = settings.activeDid || "";
|
this.activeDid = settings.activeDid || "";
|
||||||
this.apiServer = settings.apiServer || "";
|
this.apiServer = settings.apiServer || "";
|
||||||
this.allContacts = await db.contacts.toArray();
|
this.allContacts = await platform.getAllContacts();
|
||||||
this.isRegistered = settings.isRegistered || false;
|
this.isRegistered = settings.isRegistered || false;
|
||||||
this.allMyDids = await retrieveAccountDids();
|
this.allMyDids = await platform.getAllAccountDids();
|
||||||
|
|
||||||
// Check share capability
|
// Check share capability
|
||||||
// When Chrome compatibility is fixed https://developer.mozilla.org/en-US/docs/Web/API/Web_Share_API#api.navigator.canshare
|
// When Chrome compatibility is fixed https://developer.mozilla.org/en-US/docs/Web/API/Web_Share_API#api.navigator.canshare
|
||||||
|
|||||||
@@ -1063,7 +1063,8 @@ export default class ContactsView extends Vue {
|
|||||||
);
|
);
|
||||||
if (regResult.success) {
|
if (regResult.success) {
|
||||||
contact.registered = true;
|
contact.registered = true;
|
||||||
await db.contacts.update(contact.did, { registered: true });
|
const platform = this.$platform;
|
||||||
|
await platform.updateContact(contact.did, { registered: true });
|
||||||
|
|
||||||
this.$notify(
|
this.$notify(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -298,57 +298,42 @@ Raymer * @version 1.0.0 */
|
|||||||
import { UAParser } from "ua-parser-js";
|
import { UAParser } from "ua-parser-js";
|
||||||
import { Component, Vue } from "vue-facing-decorator";
|
import { Component, Vue } from "vue-facing-decorator";
|
||||||
import { Router } from "vue-router";
|
import { Router } from "vue-router";
|
||||||
|
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
|
||||||
//import App from "../App.vue";
|
import { BoundingBox } from "../types/BoundingBox";
|
||||||
import EntityIcon from "../components/EntityIcon.vue";
|
import { Contact } from "../types/Contact";
|
||||||
import GiftedDialog from "../components/GiftedDialog.vue";
|
import { OnboardPage } from "../libs/util";
|
||||||
import GiftedPrompts from "../components/GiftedPrompts.vue";
|
import * as OnboardingDialogModule from "../components/OnboardingDialog.vue";
|
||||||
import FeedFilters from "../components/FeedFilters.vue";
|
import * as QuickNavModule from "../components/QuickNav.vue";
|
||||||
import InfiniteScroll from "../components/InfiniteScroll.vue";
|
import * as TopMessageModule from "../components/TopMessage.vue";
|
||||||
import OnboardingDialog from "../components/OnboardingDialog.vue";
|
import * as EntityIconModule from "../components/EntityIcon.vue";
|
||||||
import QuickNav from "../components/QuickNav.vue";
|
import * as GiftedDialogModule from "../components/GiftedDialog.vue";
|
||||||
import TopMessage from "../components/TopMessage.vue";
|
import * as GiftedPromptsModule from "../components/GiftedPrompts.vue";
|
||||||
import UserNameDialog from "../components/UserNameDialog.vue";
|
import * as FeedFiltersModule from "../components/FeedFilters.vue";
|
||||||
import ChoiceButtonDialog from "../components/ChoiceButtonDialog.vue";
|
import * as UserNameDialogModule from "../components/UserNameDialog.vue";
|
||||||
import ImageViewer from "../components/ImageViewer.vue";
|
import * as ActivityListItemModule from "../components/ActivityListItem.vue";
|
||||||
import ActivityListItem from "../components/ActivityListItem.vue";
|
import { AppString, PASSKEYS_ENABLED } from "../constants/app";
|
||||||
|
import { logger } from "../utils/logger";
|
||||||
|
import { checkIsAnyFeedFilterOn } from "../db/tables/settings";
|
||||||
import {
|
import {
|
||||||
AppString,
|
|
||||||
NotificationIface,
|
|
||||||
PASSKEYS_ENABLED,
|
|
||||||
} from "../constants/app";
|
|
||||||
import {
|
|
||||||
db,
|
|
||||||
logConsoleAndDb,
|
|
||||||
retrieveSettingsForActiveAccount,
|
|
||||||
updateAccountSettings,
|
|
||||||
} from "../db/index";
|
|
||||||
import { Contact } from "../db/tables/contacts";
|
|
||||||
import {
|
|
||||||
BoundingBox,
|
|
||||||
checkIsAnyFeedFilterOn,
|
|
||||||
MASTER_SETTINGS_KEY,
|
|
||||||
} from "../db/tables/settings";
|
|
||||||
import {
|
|
||||||
contactForDid,
|
|
||||||
containsNonHiddenDid,
|
|
||||||
didInfoForContact,
|
|
||||||
fetchEndorserRateLimits,
|
fetchEndorserRateLimits,
|
||||||
getHeaders,
|
|
||||||
getNewOffersToUser,
|
getNewOffersToUser,
|
||||||
getNewOffersToUserProjects,
|
getNewOffersToUserProjects,
|
||||||
getPlanFromCache,
|
|
||||||
} from "../libs/endorserServer";
|
} from "../libs/endorserServer";
|
||||||
import {
|
import {
|
||||||
generateSaveAndActivateIdentity,
|
generateSaveAndActivateIdentity,
|
||||||
retrieveAccountDids,
|
retrieveAccountDids,
|
||||||
GiverReceiverInputInfo,
|
|
||||||
OnboardPage,
|
|
||||||
} from "../libs/util";
|
} from "../libs/util";
|
||||||
|
import { NotificationIface } from "../constants/app";
|
||||||
|
import {
|
||||||
|
containsNonHiddenDid,
|
||||||
|
didInfoForContact,
|
||||||
|
} from "../libs/endorserServer";
|
||||||
import { GiveSummaryRecord } from "../interfaces";
|
import { GiveSummaryRecord } from "../interfaces";
|
||||||
import * as serverUtil from "../libs/endorserServer";
|
import * as serverUtil from "../libs/endorserServer";
|
||||||
import { logger } from "../utils/logger";
|
|
||||||
import { GiveRecordWithContactInfo } from "../types";
|
import { GiveRecordWithContactInfo } from "../types";
|
||||||
|
import ChoiceButtonDialog from "../components/ChoiceButtonDialog.vue";
|
||||||
|
import ImageViewer from "../components/ImageViewer.vue";
|
||||||
|
import * as InfiniteScrollModule from "../components/InfiniteScroll.vue";
|
||||||
|
|
||||||
interface Claim {
|
interface Claim {
|
||||||
claim?: Claim; // For nested claims in Verifiable Credentials
|
claim?: Claim; // For nested claims in Verifiable Credentials
|
||||||
@@ -419,18 +404,19 @@ interface FeedError {
|
|||||||
*/
|
*/
|
||||||
@Component({
|
@Component({
|
||||||
components: {
|
components: {
|
||||||
EntityIcon,
|
FontAwesomeIcon,
|
||||||
FeedFilters,
|
QuickNav: QuickNavModule.default,
|
||||||
GiftedDialog,
|
TopMessage: TopMessageModule.default,
|
||||||
GiftedPrompts,
|
EntityIcon: EntityIconModule.default,
|
||||||
InfiniteScroll,
|
GiftedDialog: GiftedDialogModule.default,
|
||||||
OnboardingDialog,
|
GiftedPrompts: GiftedPromptsModule.default,
|
||||||
|
FeedFilters: FeedFiltersModule.default,
|
||||||
|
UserNameDialog: UserNameDialogModule.default,
|
||||||
|
ActivityListItem: ActivityListItemModule.default,
|
||||||
|
OnboardingDialog: OnboardingDialogModule.default,
|
||||||
ChoiceButtonDialog,
|
ChoiceButtonDialog,
|
||||||
QuickNav,
|
|
||||||
TopMessage,
|
|
||||||
UserNameDialog,
|
|
||||||
ImageViewer,
|
ImageViewer,
|
||||||
ActivityListItem,
|
InfiniteScroll: InfiniteScrollModule.default,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
export default class HomeView extends Vue {
|
export default class HomeView extends Vue {
|
||||||
@@ -520,10 +506,11 @@ export default class HomeView extends Vue {
|
|||||||
this.allMyDids = [newDid];
|
this.allMyDids = [newDid];
|
||||||
}
|
}
|
||||||
|
|
||||||
const settings = await retrieveSettingsForActiveAccount();
|
const platform = this.$platform;
|
||||||
|
const settings = await platform.getActiveAccountSettings();
|
||||||
this.apiServer = settings.apiServer || "";
|
this.apiServer = settings.apiServer || "";
|
||||||
this.activeDid = settings.activeDid || "";
|
this.activeDid = settings.activeDid || "";
|
||||||
this.allContacts = await db.contacts.toArray();
|
this.allContacts = await platform.getAllContacts();
|
||||||
this.feedLastViewedClaimId = settings.lastViewedClaimId;
|
this.feedLastViewedClaimId = settings.lastViewedClaimId;
|
||||||
this.givenName = settings.firstName || "";
|
this.givenName = settings.firstName || "";
|
||||||
this.isFeedFilteredByVisible = !!settings.filterFeedByVisible;
|
this.isFeedFilteredByVisible = !!settings.filterFeedByVisible;
|
||||||
@@ -552,9 +539,9 @@ export default class HomeView extends Vue {
|
|||||||
this.activeDid,
|
this.activeDid,
|
||||||
);
|
);
|
||||||
if (resp.status === 200) {
|
if (resp.status === 200) {
|
||||||
await updateAccountSettings(this.activeDid, {
|
await platform.updateAccountSettings(this.activeDid, {
|
||||||
isRegistered: true,
|
isRegistered: true,
|
||||||
...(await retrieveSettingsForActiveAccount()),
|
...settings,
|
||||||
});
|
});
|
||||||
this.isRegistered = true;
|
this.isRegistered = true;
|
||||||
}
|
}
|
||||||
@@ -590,14 +577,14 @@ export default class HomeView extends Vue {
|
|||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
logConsoleAndDb("Error retrieving settings or feed: " + err, true);
|
logger.error("Error retrieving settings or feed:", err);
|
||||||
this.$notify(
|
this.$notify(
|
||||||
{
|
{
|
||||||
group: "alert",
|
group: "alert",
|
||||||
type: "danger",
|
type: "danger",
|
||||||
title: "Error",
|
title: "Error",
|
||||||
text:
|
text:
|
||||||
(err as { userMessage?: string })?.userMessage ||
|
err?.userMessage ||
|
||||||
"There was an error retrieving your settings or the latest activity.",
|
"There was an error retrieving your settings or the latest activity.",
|
||||||
},
|
},
|
||||||
5000,
|
5000,
|
||||||
@@ -618,7 +605,8 @@ export default class HomeView extends Vue {
|
|||||||
* Called by mounted() and reloadFeedOnChange()
|
* Called by mounted() and reloadFeedOnChange()
|
||||||
*/
|
*/
|
||||||
private async loadSettings() {
|
private async loadSettings() {
|
||||||
const settings = await retrieveSettingsForActiveAccount();
|
const platform = this.$platform;
|
||||||
|
const settings = await platform.getActiveAccountSettings();
|
||||||
this.apiServer = settings.apiServer || "";
|
this.apiServer = settings.apiServer || "";
|
||||||
this.activeDid = settings.activeDid || "";
|
this.activeDid = settings.activeDid || "";
|
||||||
this.feedLastViewedClaimId = settings.lastViewedClaimId;
|
this.feedLastViewedClaimId = settings.lastViewedClaimId;
|
||||||
@@ -642,7 +630,7 @@ export default class HomeView extends Vue {
|
|||||||
* Called by mounted() and initializeIdentity()
|
* Called by mounted() and initializeIdentity()
|
||||||
*/
|
*/
|
||||||
private async loadContacts() {
|
private async loadContacts() {
|
||||||
this.allContacts = await db.contacts.toArray();
|
this.allContacts = await this.$platform.getAllContacts();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -663,10 +651,12 @@ export default class HomeView extends Vue {
|
|||||||
this.activeDid,
|
this.activeDid,
|
||||||
);
|
);
|
||||||
if (resp.status === 200) {
|
if (resp.status === 200) {
|
||||||
await updateAccountSettings(this.activeDid, {
|
const platform = this.$platform;
|
||||||
|
const settings = await platform.getActiveAccountSettings();
|
||||||
|
await platform.updateAccountSettings(this.activeDid, {
|
||||||
apiServer: this.apiServer,
|
apiServer: this.apiServer,
|
||||||
isRegistered: true,
|
isRegistered: true,
|
||||||
...(await retrieveSettingsForActiveAccount()),
|
...settings,
|
||||||
});
|
});
|
||||||
this.isRegistered = true;
|
this.isRegistered = true;
|
||||||
}
|
}
|
||||||
@@ -728,7 +718,8 @@ export default class HomeView extends Vue {
|
|||||||
* Called by mounted()
|
* Called by mounted()
|
||||||
*/
|
*/
|
||||||
private async checkOnboarding() {
|
private async checkOnboarding() {
|
||||||
const settings = await retrieveSettingsForActiveAccount();
|
const platform = this.$platform;
|
||||||
|
const settings = await platform.getActiveAccountSettings();
|
||||||
if (!settings.finishedOnboarding) {
|
if (!settings.finishedOnboarding) {
|
||||||
(this.$refs.onboardingDialog as OnboardingDialog).open(OnboardPage.Home);
|
(this.$refs.onboardingDialog as OnboardingDialog).open(OnboardPage.Home);
|
||||||
}
|
}
|
||||||
@@ -744,7 +735,7 @@ export default class HomeView extends Vue {
|
|||||||
* @param err Error object with optional userMessage
|
* @param err Error object with optional userMessage
|
||||||
*/
|
*/
|
||||||
private handleError(err: unknown) {
|
private handleError(err: unknown) {
|
||||||
logConsoleAndDb("Error retrieving settings or feed: " + err, true);
|
logger.error("Error retrieving settings or feed:", err);
|
||||||
this.$notify(
|
this.$notify(
|
||||||
{
|
{
|
||||||
group: "alert",
|
group: "alert",
|
||||||
@@ -790,7 +781,8 @@ export default class HomeView extends Vue {
|
|||||||
* Called by FeedFilters component when filters change
|
* Called by FeedFilters component when filters change
|
||||||
*/
|
*/
|
||||||
async reloadFeedOnChange() {
|
async reloadFeedOnChange() {
|
||||||
const settings = await retrieveSettingsForActiveAccount();
|
const platform = this.$platform;
|
||||||
|
const settings = await platform.getActiveAccountSettings();
|
||||||
this.isFeedFilteredByVisible = !!settings.filterFeedByVisible;
|
this.isFeedFilteredByVisible = !!settings.filterFeedByVisible;
|
||||||
this.isFeedFilteredByNearby = !!settings.filterFeedByNearby;
|
this.isFeedFilteredByNearby = !!settings.filterFeedByNearby;
|
||||||
this.isAnyFeedFilterOn = checkIsAnyFeedFilterOn(settings);
|
this.isAnyFeedFilterOn = checkIsAnyFeedFilterOn(settings);
|
||||||
@@ -1064,7 +1056,7 @@ export default class HomeView extends Vue {
|
|||||||
* @returns The fulfills plan object
|
* @returns The fulfills plan object
|
||||||
*/
|
*/
|
||||||
private async getFulfillsPlan(record: GiveSummaryRecord) {
|
private async getFulfillsPlan(record: GiveSummaryRecord) {
|
||||||
return await getPlanFromCache(
|
return await this.$platform.getPlanFromCache(
|
||||||
record.fulfillsPlanHandleId,
|
record.fulfillsPlanHandleId,
|
||||||
this.axios,
|
this.axios,
|
||||||
this.apiServer,
|
this.apiServer,
|
||||||
@@ -1142,7 +1134,7 @@ export default class HomeView extends Vue {
|
|||||||
* Called by processRecord()
|
* Called by processRecord()
|
||||||
*/
|
*/
|
||||||
private async getProvidedByPlan(provider: Provider | undefined) {
|
private async getProvidedByPlan(provider: Provider | undefined) {
|
||||||
return await getPlanFromCache(
|
return await this.$platform.getPlanFromCache(
|
||||||
provider?.identifier as string,
|
provider?.identifier as string,
|
||||||
this.axios,
|
this.axios,
|
||||||
this.apiServer,
|
this.apiServer,
|
||||||
@@ -1197,14 +1189,14 @@ export default class HomeView extends Vue {
|
|||||||
giver: didInfoForContact(
|
giver: didInfoForContact(
|
||||||
giverDid,
|
giverDid,
|
||||||
this.activeDid,
|
this.activeDid,
|
||||||
contactForDid(giverDid, this.allContacts),
|
this.$platform.getContactForDid(giverDid, this.allContacts),
|
||||||
this.allMyDids,
|
this.allMyDids,
|
||||||
),
|
),
|
||||||
image: claim.image,
|
image: claim.image,
|
||||||
issuer: didInfoForContact(
|
issuer: didInfoForContact(
|
||||||
record.issuerDid,
|
record.issuerDid,
|
||||||
this.activeDid,
|
this.activeDid,
|
||||||
contactForDid(record.issuerDid, this.allContacts),
|
this.$platform.getContactForDid(record.issuerDid, this.allContacts),
|
||||||
this.allMyDids,
|
this.allMyDids,
|
||||||
),
|
),
|
||||||
providerPlanHandleId: provider?.identifier as string,
|
providerPlanHandleId: provider?.identifier as string,
|
||||||
@@ -1213,7 +1205,7 @@ export default class HomeView extends Vue {
|
|||||||
receiver: didInfoForContact(
|
receiver: didInfoForContact(
|
||||||
recipientDid,
|
recipientDid,
|
||||||
this.activeDid,
|
this.activeDid,
|
||||||
contactForDid(recipientDid, this.allContacts),
|
this.$platform.getContactForDid(recipientDid, this.allContacts),
|
||||||
this.allMyDids,
|
this.allMyDids,
|
||||||
),
|
),
|
||||||
} as GiveRecordWithContactInfo;
|
} as GiveRecordWithContactInfo;
|
||||||
@@ -1230,8 +1222,7 @@ export default class HomeView extends Vue {
|
|||||||
this.feedLastViewedClaimId == null ||
|
this.feedLastViewedClaimId == null ||
|
||||||
this.feedLastViewedClaimId < records[0].jwtId
|
this.feedLastViewedClaimId < records[0].jwtId
|
||||||
) {
|
) {
|
||||||
await db.open();
|
await this.$platform.updateAccountSettings(this.activeDid, {
|
||||||
await db.settings.update(MASTER_SETTINGS_KEY, {
|
|
||||||
lastViewedClaimId: records[0].jwtId,
|
lastViewedClaimId: records[0].jwtId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1264,13 +1255,13 @@ export default class HomeView extends Vue {
|
|||||||
* @internal
|
* @internal
|
||||||
* Called by updateAllFeed()
|
* Called by updateAllFeed()
|
||||||
* @param endorserApiServer API server URL
|
* @param endorserApiServer API server URL
|
||||||
* @param beforeId OptioCalled by updateAllFeed()nal ID to fetch earlier results
|
* @param beforeId Optional ID to fetch earlier results
|
||||||
* @returns claims in reverse chronological order
|
* @returns claims in reverse chronological order
|
||||||
*/
|
*/
|
||||||
async retrieveGives(endorserApiServer: string, beforeId?: string) {
|
async retrieveGives(endorserApiServer: string, beforeId?: string) {
|
||||||
const beforeQuery = beforeId == null ? "" : "&beforeId=" + beforeId;
|
const beforeQuery = beforeId == null ? "" : "&beforeId=" + beforeId;
|
||||||
const doNotShowErrorAgain = !!beforeId; // don't show error again if we're loading more
|
const doNotShowErrorAgain = !!beforeId; // don't show error again if we're loading more
|
||||||
const headers = await getHeaders(
|
const headers = await this.$platform.getHeaders(
|
||||||
this.activeDid,
|
this.activeDid,
|
||||||
doNotShowErrorAgain ? undefined : this.$notify,
|
doNotShowErrorAgain ? undefined : this.$notify,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -106,14 +106,9 @@ import { Router } from "vue-router";
|
|||||||
|
|
||||||
import QuickNav from "../components/QuickNav.vue";
|
import QuickNav from "../components/QuickNav.vue";
|
||||||
import { NotificationIface } from "../constants/app";
|
import { NotificationIface } from "../constants/app";
|
||||||
import {
|
|
||||||
accountsDBPromise,
|
|
||||||
db,
|
|
||||||
retrieveSettingsForActiveAccount,
|
|
||||||
} from "../db/index";
|
|
||||||
import { MASTER_SETTINGS_KEY } from "../db/tables/settings";
|
|
||||||
import { retrieveAllAccountsMetadata } from "../libs/util";
|
import { retrieveAllAccountsMetadata } from "../libs/util";
|
||||||
import { logger } from "../utils/logger";
|
import { logger } from "../utils/logger";
|
||||||
|
|
||||||
@Component({ components: { QuickNav } })
|
@Component({ components: { QuickNav } })
|
||||||
export default class IdentitySwitcherView extends Vue {
|
export default class IdentitySwitcherView extends Vue {
|
||||||
$notify!: (notification: NotificationIface, timeout?: number) => void;
|
$notify!: (notification: NotificationIface, timeout?: number) => void;
|
||||||
@@ -127,7 +122,8 @@ export default class IdentitySwitcherView extends Vue {
|
|||||||
|
|
||||||
async created() {
|
async created() {
|
||||||
try {
|
try {
|
||||||
const settings = await retrieveSettingsForActiveAccount();
|
const platform = this.$platform;
|
||||||
|
const settings = await platform.getActiveAccountSettings();
|
||||||
this.activeDid = settings.activeDid || "";
|
this.activeDid = settings.activeDid || "";
|
||||||
this.apiServer = settings.apiServer || "";
|
this.apiServer = settings.apiServer || "";
|
||||||
this.apiServerInput = settings.apiServer || "";
|
this.apiServerInput = settings.apiServer || "";
|
||||||
@@ -162,10 +158,8 @@ export default class IdentitySwitcherView extends Vue {
|
|||||||
if (did === "0") {
|
if (did === "0") {
|
||||||
did = undefined;
|
did = undefined;
|
||||||
}
|
}
|
||||||
await db.open();
|
const platform = this.$platform;
|
||||||
await db.settings.update(MASTER_SETTINGS_KEY, {
|
await platform.updateAccountSettings(this.activeDid, { activeDid: did });
|
||||||
activeDid: did,
|
|
||||||
});
|
|
||||||
this.$router.push({ name: "account" });
|
this.$router.push({ name: "account" });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,9 +171,8 @@ export default class IdentitySwitcherView extends Vue {
|
|||||||
title: "Delete Identity?",
|
title: "Delete Identity?",
|
||||||
text: "Are you sure you want to erase this identity? (There is no undo. You may want to select it and back it up just in case.)",
|
text: "Are you sure you want to erase this identity? (There is no undo. You may want to select it and back it up just in case.)",
|
||||||
onYes: async () => {
|
onYes: async () => {
|
||||||
// one of the few times we use accountsDBPromise directly; try to avoid more usage
|
const platform = this.$platform;
|
||||||
const accountsDB = await accountsDBPromise;
|
await platform.deleteAccount(id);
|
||||||
await accountsDB.accounts.delete(id);
|
|
||||||
this.otherIdentities = this.otherIdentities.filter(
|
this.otherIdentities = this.otherIdentities.filter(
|
||||||
(ident) => ident.id !== id,
|
(ident) => ident.id !== id,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -328,19 +328,57 @@ export default class InviteOneView extends Vue {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
addNewContact(did: string, notes: string) {
|
async addNewContact(did: string, notes: string) {
|
||||||
(this.$refs.contactNameDialog as ContactNameDialog).open(
|
(this.$refs.contactNameDialog as ContactNameDialog).open(
|
||||||
"To Whom Did You Send The Invite?",
|
"To Whom Did You Send The Invite?",
|
||||||
"Their name will be added to your contact list.",
|
"Their name will be added to your contact list.",
|
||||||
(name) => {
|
async (name) => {
|
||||||
// the person obviously registered themselves and this user already granted visibility, so we just add them
|
try {
|
||||||
|
// Get the SQLite interface from the platform service
|
||||||
|
const sqlite = await this.$platform.getSQLite();
|
||||||
|
|
||||||
|
// Create the contact object
|
||||||
const contact = {
|
const contact = {
|
||||||
did: did,
|
did: did,
|
||||||
name: name,
|
name: name,
|
||||||
registered: true,
|
registered: true,
|
||||||
|
notes: notes,
|
||||||
|
// Convert contact methods to JSON string as per schema
|
||||||
|
contactMethods: JSON.stringify([]),
|
||||||
|
// Other fields can be null/undefined as they're optional
|
||||||
|
nextPubKeyHashB64: null,
|
||||||
|
profileImageUrl: null,
|
||||||
|
publicKeyBase64: null,
|
||||||
|
seesMe: null,
|
||||||
};
|
};
|
||||||
db.contacts.add(contact);
|
|
||||||
|
// Insert the contact using a transaction
|
||||||
|
await sqlite.transaction([
|
||||||
|
{
|
||||||
|
sql: `
|
||||||
|
INSERT INTO contacts (
|
||||||
|
did, name, registered, notes, contactMethods,
|
||||||
|
nextPubKeyHashB64, profileImageUrl, publicKeyBase64, seesMe
|
||||||
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
|
`,
|
||||||
|
params: [
|
||||||
|
contact.did,
|
||||||
|
contact.name,
|
||||||
|
contact.registered ? 1 : 0, // Convert boolean to integer for SQLite
|
||||||
|
contact.notes,
|
||||||
|
contact.contactMethods,
|
||||||
|
contact.nextPubKeyHashB64,
|
||||||
|
contact.profileImageUrl,
|
||||||
|
contact.publicKeyBase64,
|
||||||
|
contact.seesMe ? 1 : 0, // Convert boolean to integer for SQLite
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Update the local contacts cache
|
||||||
this.contactsRedeemed[did] = contact;
|
this.contactsRedeemed[did] = contact;
|
||||||
|
|
||||||
|
// Notify success
|
||||||
this.$notify(
|
this.$notify(
|
||||||
{
|
{
|
||||||
group: "alert",
|
group: "alert",
|
||||||
@@ -350,8 +388,21 @@ export default class InviteOneView extends Vue {
|
|||||||
},
|
},
|
||||||
3000,
|
3000,
|
||||||
);
|
);
|
||||||
|
} catch (error) {
|
||||||
|
// Handle any errors
|
||||||
|
this.$notify(
|
||||||
|
{
|
||||||
|
group: "alert",
|
||||||
|
type: "danger",
|
||||||
|
title: "Error Adding Contact",
|
||||||
|
text: "Failed to add contact to database.",
|
||||||
},
|
},
|
||||||
() => {},
|
5000,
|
||||||
|
);
|
||||||
|
logger.error("Error adding contact:", error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
() => {}, // onCancel callback
|
||||||
notes,
|
notes,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,11 +154,6 @@ import GiftedDialog from "../components/GiftedDialog.vue";
|
|||||||
import QuickNav from "../components/QuickNav.vue";
|
import QuickNav from "../components/QuickNav.vue";
|
||||||
import EntityIcon from "../components/EntityIcon.vue";
|
import EntityIcon from "../components/EntityIcon.vue";
|
||||||
import { NotificationIface } from "../constants/app";
|
import { NotificationIface } from "../constants/app";
|
||||||
import {
|
|
||||||
db,
|
|
||||||
retrieveSettingsForActiveAccount,
|
|
||||||
updateAccountSettings,
|
|
||||||
} from "../db/index";
|
|
||||||
import { Contact } from "../db/tables/contacts";
|
import { Contact } from "../db/tables/contacts";
|
||||||
import { Router } from "vue-router";
|
import { Router } from "vue-router";
|
||||||
import { OfferSummaryRecord, OfferToPlanSummaryRecord } from "../interfaces";
|
import { OfferSummaryRecord, OfferToPlanSummaryRecord } from "../interfaces";
|
||||||
@@ -169,6 +164,7 @@ import {
|
|||||||
getNewOffersToUserProjects,
|
getNewOffersToUserProjects,
|
||||||
} from "../libs/endorserServer";
|
} from "../libs/endorserServer";
|
||||||
import { retrieveAccountDids } from "../libs/util";
|
import { retrieveAccountDids } from "../libs/util";
|
||||||
|
import { logger } from "../utils/logger";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
components: { GiftedDialog, QuickNav, EntityIcon },
|
components: { GiftedDialog, QuickNav, EntityIcon },
|
||||||
@@ -194,14 +190,15 @@ export default class NewActivityView extends Vue {
|
|||||||
|
|
||||||
async created() {
|
async created() {
|
||||||
try {
|
try {
|
||||||
const settings = await retrieveSettingsForActiveAccount();
|
const platform = this.$platform;
|
||||||
|
const settings = await platform.getActiveAccountSettings();
|
||||||
this.apiServer = settings.apiServer || "";
|
this.apiServer = settings.apiServer || "";
|
||||||
this.activeDid = settings.activeDid || "";
|
this.activeDid = settings.activeDid || "";
|
||||||
this.lastAckedOfferToUserJwtId = settings.lastAckedOfferToUserJwtId || "";
|
this.lastAckedOfferToUserJwtId = settings.lastAckedOfferToUserJwtId || "";
|
||||||
this.lastAckedOfferToUserProjectsJwtId =
|
this.lastAckedOfferToUserProjectsJwtId =
|
||||||
settings.lastAckedOfferToUserProjectsJwtId || "";
|
settings.lastAckedOfferToUserProjectsJwtId || "";
|
||||||
|
|
||||||
this.allContacts = await db.contacts.toArray();
|
this.allContacts = await platform.getContacts();
|
||||||
this.allMyDids = await retrieveAccountDids();
|
this.allMyDids = await retrieveAccountDids();
|
||||||
|
|
||||||
const offersToUserData = await getNewOffersToUser(
|
const offersToUserData = await getNewOffersToUser(
|
||||||
@@ -240,7 +237,8 @@ export default class NewActivityView extends Vue {
|
|||||||
async expandOffersToUserAndMarkRead() {
|
async expandOffersToUserAndMarkRead() {
|
||||||
this.showOffersDetails = !this.showOffersDetails;
|
this.showOffersDetails = !this.showOffersDetails;
|
||||||
if (this.showOffersDetails) {
|
if (this.showOffersDetails) {
|
||||||
await updateAccountSettings(this.activeDid, {
|
const platform = this.$platform;
|
||||||
|
await platform.updateAccountSettings(this.activeDid, {
|
||||||
lastAckedOfferToUserJwtId: this.newOffersToUser[0].jwtId,
|
lastAckedOfferToUserJwtId: this.newOffersToUser[0].jwtId,
|
||||||
});
|
});
|
||||||
// note that we don't update this.lastAckedOfferToUserJwtId in case they
|
// note that we don't update this.lastAckedOfferToUserJwtId in case they
|
||||||
@@ -261,14 +259,15 @@ export default class NewActivityView extends Vue {
|
|||||||
const index = this.newOffersToUser.findIndex(
|
const index = this.newOffersToUser.findIndex(
|
||||||
(offer) => offer.jwtId === jwtId,
|
(offer) => offer.jwtId === jwtId,
|
||||||
);
|
);
|
||||||
|
const platform = this.$platform;
|
||||||
if (index !== -1 && index < this.newOffersToUser.length - 1) {
|
if (index !== -1 && index < this.newOffersToUser.length - 1) {
|
||||||
// Set to the next offer's jwtId
|
// Set to the next offer's jwtId
|
||||||
await updateAccountSettings(this.activeDid, {
|
await platform.updateAccountSettings(this.activeDid, {
|
||||||
lastAckedOfferToUserJwtId: this.newOffersToUser[index + 1].jwtId,
|
lastAckedOfferToUserJwtId: this.newOffersToUser[index + 1].jwtId,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// it's the last entry (or not found), so just keep it the same
|
// it's the last entry (or not found), so just keep it the same
|
||||||
await updateAccountSettings(this.activeDid, {
|
await platform.updateAccountSettings(this.activeDid, {
|
||||||
lastAckedOfferToUserJwtId: this.lastAckedOfferToUserJwtId,
|
lastAckedOfferToUserJwtId: this.lastAckedOfferToUserJwtId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -287,7 +286,8 @@ export default class NewActivityView extends Vue {
|
|||||||
this.showOffersToUserProjectsDetails =
|
this.showOffersToUserProjectsDetails =
|
||||||
!this.showOffersToUserProjectsDetails;
|
!this.showOffersToUserProjectsDetails;
|
||||||
if (this.showOffersToUserProjectsDetails) {
|
if (this.showOffersToUserProjectsDetails) {
|
||||||
await updateAccountSettings(this.activeDid, {
|
const platform = this.$platform;
|
||||||
|
await platform.updateAccountSettings(this.activeDid, {
|
||||||
lastAckedOfferToUserProjectsJwtId:
|
lastAckedOfferToUserProjectsJwtId:
|
||||||
this.newOffersToUserProjects[0].jwtId,
|
this.newOffersToUserProjects[0].jwtId,
|
||||||
});
|
});
|
||||||
@@ -309,15 +309,16 @@ export default class NewActivityView extends Vue {
|
|||||||
const index = this.newOffersToUserProjects.findIndex(
|
const index = this.newOffersToUserProjects.findIndex(
|
||||||
(offer) => offer.jwtId === jwtId,
|
(offer) => offer.jwtId === jwtId,
|
||||||
);
|
);
|
||||||
|
const platform = this.$platform;
|
||||||
if (index !== -1 && index < this.newOffersToUserProjects.length - 1) {
|
if (index !== -1 && index < this.newOffersToUserProjects.length - 1) {
|
||||||
// Set to the next offer's jwtId
|
// Set to the next offer's jwtId
|
||||||
await updateAccountSettings(this.activeDid, {
|
await platform.updateAccountSettings(this.activeDid, {
|
||||||
lastAckedOfferToUserProjectsJwtId:
|
lastAckedOfferToUserProjectsJwtId:
|
||||||
this.newOffersToUserProjects[index + 1].jwtId,
|
this.newOffersToUserProjects[index + 1].jwtId,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// it's the last entry (or not found), so just keep it the same
|
// it's the last entry (or not found), so just keep it the same
|
||||||
await updateAccountSettings(this.activeDid, {
|
await platform.updateAccountSettings(this.activeDid, {
|
||||||
lastAckedOfferToUserProjectsJwtId:
|
lastAckedOfferToUserProjectsJwtId:
|
||||||
this.lastAckedOfferToUserProjectsJwtId,
|
this.lastAckedOfferToUserProjectsJwtId,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -145,11 +145,6 @@ import { Router } from "vue-router";
|
|||||||
import QuickNav from "../components/QuickNav.vue";
|
import QuickNav from "../components/QuickNav.vue";
|
||||||
import TopMessage from "../components/TopMessage.vue";
|
import TopMessage from "../components/TopMessage.vue";
|
||||||
import { NotificationIface } from "../constants/app";
|
import { NotificationIface } from "../constants/app";
|
||||||
import {
|
|
||||||
accountsDBPromise,
|
|
||||||
db,
|
|
||||||
retrieveSettingsForActiveAccount,
|
|
||||||
} from "../db/index";
|
|
||||||
import { Contact } from "../db/tables/contacts";
|
import { Contact } from "../db/tables/contacts";
|
||||||
import {
|
import {
|
||||||
GenericCredWrapper,
|
GenericCredWrapper,
|
||||||
@@ -165,6 +160,7 @@ import {
|
|||||||
getHeaders,
|
getHeaders,
|
||||||
} from "../libs/endorserServer";
|
} from "../libs/endorserServer";
|
||||||
import { logger } from "../utils/logger";
|
import { logger } from "../utils/logger";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
methods: { claimSpecialDescription },
|
methods: { claimSpecialDescription },
|
||||||
components: {
|
components: {
|
||||||
@@ -172,7 +168,7 @@ import { logger } from "../utils/logger";
|
|||||||
TopMessage,
|
TopMessage,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
export default class QuickActionBvcBeginView extends Vue {
|
export default class QuickActionBvcEndView extends Vue {
|
||||||
$notify!: (notification: NotificationIface, timeout?: number) => void;
|
$notify!: (notification: NotificationIface, timeout?: number) => void;
|
||||||
|
|
||||||
activeDid = "";
|
activeDid = "";
|
||||||
@@ -191,10 +187,11 @@ export default class QuickActionBvcBeginView extends Vue {
|
|||||||
async created() {
|
async created() {
|
||||||
this.loadingConfirms = true;
|
this.loadingConfirms = true;
|
||||||
|
|
||||||
const settings = await retrieveSettingsForActiveAccount();
|
const platform = this.$platform;
|
||||||
|
const settings = await platform.getActiveAccountSettings();
|
||||||
this.apiServer = settings.apiServer || "";
|
this.apiServer = settings.apiServer || "";
|
||||||
this.activeDid = settings.activeDid || "";
|
this.activeDid = settings.activeDid || "";
|
||||||
this.allContacts = await db.contacts.toArray();
|
this.allContacts = await platform.getContacts();
|
||||||
|
|
||||||
let currentOrPreviousSat = DateTime.now().setZone("America/Denver");
|
let currentOrPreviousSat = DateTime.now().setZone("America/Denver");
|
||||||
if (currentOrPreviousSat.weekday < 6) {
|
if (currentOrPreviousSat.weekday < 6) {
|
||||||
@@ -213,10 +210,8 @@ export default class QuickActionBvcBeginView extends Vue {
|
|||||||
suppressMilliseconds: true,
|
suppressMilliseconds: true,
|
||||||
}) || "";
|
}) || "";
|
||||||
|
|
||||||
const accountsDB = await accountsDBPromise;
|
const accounts = await platform.getAllAccounts();
|
||||||
await accountsDB.open();
|
this.allMyDids = accounts.map((acc) => acc.did);
|
||||||
const allAccounts = await accountsDB.accounts.toArray();
|
|
||||||
this.allMyDids = allAccounts.map((acc) => acc.did);
|
|
||||||
const headers = await getHeaders(this.activeDid);
|
const headers = await getHeaders(this.activeDid);
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
|
|||||||
@@ -113,9 +113,9 @@ import { Router } from "vue-router";
|
|||||||
|
|
||||||
import QuickNav from "../components/QuickNav.vue";
|
import QuickNav from "../components/QuickNav.vue";
|
||||||
import { NotificationIface } from "../constants/app";
|
import { NotificationIface } from "../constants/app";
|
||||||
import { db, retrieveSettingsForActiveAccount } from "../db/index";
|
import { BoundingBox } from "../db/tables/settings";
|
||||||
import { BoundingBox, MASTER_SETTINGS_KEY } from "../db/tables/settings";
|
|
||||||
import { logger } from "../utils/logger";
|
import { logger } from "../utils/logger";
|
||||||
|
|
||||||
const DEFAULT_LAT_LONG_DIFF = 0.01;
|
const DEFAULT_LAT_LONG_DIFF = 0.01;
|
||||||
const WORLD_ZOOM = 2;
|
const WORLD_ZOOM = 2;
|
||||||
const DEFAULT_ZOOM = 2;
|
const DEFAULT_ZOOM = 2;
|
||||||
@@ -147,7 +147,8 @@ export default class SearchAreaView extends Vue {
|
|||||||
searchBox: { name: string; bbox: BoundingBox } | null = null;
|
searchBox: { name: string; bbox: BoundingBox } | null = null;
|
||||||
|
|
||||||
async mounted() {
|
async mounted() {
|
||||||
const settings = await retrieveSettingsForActiveAccount();
|
const platform = this.$platform;
|
||||||
|
const settings = await platform.getActiveAccountSettings();
|
||||||
this.searchBox = settings.searchBoxes?.[0] || null;
|
this.searchBox = settings.searchBoxes?.[0] || null;
|
||||||
this.resetLatLong();
|
this.resetLatLong();
|
||||||
}
|
}
|
||||||
@@ -204,8 +205,8 @@ export default class SearchAreaView extends Vue {
|
|||||||
westLong: this.localCenterLong - this.localLongDiff,
|
westLong: this.localCenterLong - this.localLongDiff,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
await db.open();
|
const platform = this.$platform;
|
||||||
await db.settings.update(MASTER_SETTINGS_KEY, {
|
await platform.updateMasterSettings({
|
||||||
searchBoxes: [newSearchBox],
|
searchBoxes: [newSearchBox],
|
||||||
});
|
});
|
||||||
this.searchBox = newSearchBox;
|
this.searchBox = newSearchBox;
|
||||||
@@ -251,8 +252,8 @@ export default class SearchAreaView extends Vue {
|
|||||||
|
|
||||||
public async forgetSearchBox() {
|
public async forgetSearchBox() {
|
||||||
try {
|
try {
|
||||||
await db.open();
|
const platform = this.$platform;
|
||||||
await db.settings.update(MASTER_SETTINGS_KEY, {
|
await platform.updateMasterSettings({
|
||||||
searchBoxes: [],
|
searchBoxes: [],
|
||||||
filterFeedByNearby: false,
|
filterFeedByNearby: false,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
"include": [
|
"include": [
|
||||||
"src/electron/**/*.ts",
|
"src/electron/**/*.ts",
|
||||||
"src/utils/**/*.ts",
|
"src/utils/**/*.ts",
|
||||||
"src/constants/**/*.ts"
|
"src/constants/**/*.ts",
|
||||||
|
"src/services/**/*.ts"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,12 @@
|
|||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite";
|
||||||
import { createBuildConfig } from "./vite.config.common.mts";
|
import { createBuildConfig } from "./vite.config.common.mts";
|
||||||
|
|
||||||
export default defineConfig(async () => createBuildConfig('capacitor'));
|
export default defineConfig(
|
||||||
|
async () => {
|
||||||
|
const baseConfig = await createBuildConfig('capacitor');
|
||||||
|
return mergeConfig(baseConfig, {
|
||||||
|
optimizeDeps: {
|
||||||
|
include: ['@capacitor-community/sqlite']
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -4,6 +4,7 @@ import dotenv from "dotenv";
|
|||||||
import { loadAppConfig } from "./vite.config.utils.mts";
|
import { loadAppConfig } from "./vite.config.utils.mts";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
|
import { nodePolyfills } from 'vite-plugin-node-polyfills';
|
||||||
|
|
||||||
// Load environment variables
|
// Load environment variables
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
@@ -25,8 +26,20 @@ export async function createBuildConfig(mode: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
base: isElectron || isPyWebView ? "./" : "/",
|
base: isElectron || isPyWebView ? "./" : "./",
|
||||||
plugins: [vue()],
|
plugins: [
|
||||||
|
vue(),
|
||||||
|
// Add Node.js polyfills for Electron environment
|
||||||
|
isElectron ? nodePolyfills({
|
||||||
|
include: ['util', 'stream', 'buffer', 'events', 'assert', 'crypto'],
|
||||||
|
globals: {
|
||||||
|
Buffer: true,
|
||||||
|
global: true,
|
||||||
|
process: true,
|
||||||
|
},
|
||||||
|
protocolImports: true,
|
||||||
|
}) : null,
|
||||||
|
].filter(Boolean),
|
||||||
server: {
|
server: {
|
||||||
port: parseInt(process.env.VITE_PORT || "8080"),
|
port: parseInt(process.env.VITE_PORT || "8080"),
|
||||||
fs: { strict: false },
|
fs: { strict: false },
|
||||||
@@ -35,12 +48,51 @@ export async function createBuildConfig(mode: string) {
|
|||||||
outDir: isElectron ? "dist-electron" : "dist",
|
outDir: isElectron ? "dist-electron" : "dist",
|
||||||
assetsDir: 'assets',
|
assetsDir: 'assets',
|
||||||
chunkSizeWarningLimit: 1000,
|
chunkSizeWarningLimit: 1000,
|
||||||
|
target: isElectron ? 'node18' : 'esnext',
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
external: isCapacitor
|
external: isCapacitor
|
||||||
? ['@capacitor/app']
|
? ['@capacitor/app']
|
||||||
|
: isElectron
|
||||||
|
? [
|
||||||
|
'sqlite3',
|
||||||
|
'sqlite',
|
||||||
|
'electron',
|
||||||
|
'fs',
|
||||||
|
'path',
|
||||||
|
'crypto',
|
||||||
|
'util',
|
||||||
|
'stream',
|
||||||
|
'buffer',
|
||||||
|
'events',
|
||||||
|
'assert',
|
||||||
|
'constants',
|
||||||
|
'os',
|
||||||
|
'net',
|
||||||
|
'tls',
|
||||||
|
'dns',
|
||||||
|
'http',
|
||||||
|
'https',
|
||||||
|
'zlib',
|
||||||
|
'url',
|
||||||
|
'querystring',
|
||||||
|
'punycode',
|
||||||
|
'string_decoder',
|
||||||
|
'timers',
|
||||||
|
'domain',
|
||||||
|
'dgram',
|
||||||
|
'child_process',
|
||||||
|
'cluster',
|
||||||
|
'module',
|
||||||
|
'vm',
|
||||||
|
'readline',
|
||||||
|
'repl',
|
||||||
|
'tty',
|
||||||
|
'v8',
|
||||||
|
'worker_threads'
|
||||||
|
]
|
||||||
: [],
|
: [],
|
||||||
output: {
|
output: {
|
||||||
format: 'es',
|
format: isElectron ? 'cjs' : 'es',
|
||||||
generatedCode: {
|
generatedCode: {
|
||||||
preset: 'es2015'
|
preset: 'es2015'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ export default defineConfig(async () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
optimizeDeps: {
|
optimizeDeps: {
|
||||||
include: ['@/utils/logger']
|
include: ['@/utils/logger', '@capacitor-community/sqlite']
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export default defineConfig(async () => {
|
|||||||
const appConfig = await loadAppConfig();
|
const appConfig = await loadAppConfig();
|
||||||
|
|
||||||
return mergeConfig(baseConfig, {
|
return mergeConfig(baseConfig, {
|
||||||
|
base: process.env.NODE_ENV === 'production' ? 'https://timesafari.anomalistdesign.com/' : './',
|
||||||
plugins: [
|
plugins: [
|
||||||
VitePWA({
|
VitePWA({
|
||||||
registerType: 'autoUpdate',
|
registerType: 'autoUpdate',
|
||||||
@@ -19,7 +20,22 @@ export default defineConfig(async () => {
|
|||||||
cleanupOutdatedCaches: true,
|
cleanupOutdatedCaches: true,
|
||||||
skipWaiting: true,
|
skipWaiting: true,
|
||||||
clientsClaim: true,
|
clientsClaim: true,
|
||||||
sourcemap: true
|
sourcemap: true,
|
||||||
|
navigateFallback: 'index.html',
|
||||||
|
runtimeCaching: [{
|
||||||
|
urlPattern: /^https:\/\/timesafari\.anomalistdesign\.com\/.*/i,
|
||||||
|
handler: 'CacheFirst',
|
||||||
|
options: {
|
||||||
|
cacheName: 'timesafari-cache',
|
||||||
|
expiration: {
|
||||||
|
maxEntries: 50,
|
||||||
|
maxAgeSeconds: 60 * 60 * 24 * 30 // 30 days
|
||||||
|
},
|
||||||
|
cacheableResponse: {
|
||||||
|
statuses: [0, 200]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user