Compare commits
1 Commits
streamline
...
android-15
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d49be45ca |
@@ -7,13 +7,13 @@ alwaysApply: true
|
||||
|
||||
## 1. Platform Support Matrix
|
||||
|
||||
| Feature | Web (PWA) | Capacitor (Mobile) | Electron (Desktop) |
|
||||
|---------|-----------|-------------------|-------------------|
|
||||
| QR Code Scanning | WebInlineQRScanner | @capacitor-mlkit/barcode-scanning | Not Implemented |
|
||||
| Deep Linking | URL Parameters | App URL Open Events | Not Implemented |
|
||||
| File System | Limited (Browser API) | Capacitor Filesystem | Electron fs |
|
||||
| Camera Access | MediaDevices API | Capacitor Camera | Not Implemented |
|
||||
| Platform Detection | Web APIs | Capacitor.isNativePlatform() | process.env checks |
|
||||
| Feature | Web (PWA) | Capacitor (Mobile) | Electron (Desktop) | PyWebView (Desktop) |
|
||||
|---------|-----------|-------------------|-------------------|-------------------|
|
||||
| QR Code Scanning | WebInlineQRScanner | @capacitor-mlkit/barcode-scanning | Not Implemented | Not Implemented |
|
||||
| Deep Linking | URL Parameters | App URL Open Events | Not Implemented | Not Implemented |
|
||||
| File System | Limited (Browser API) | Capacitor Filesystem | Electron fs | PyWebView Python Bridge |
|
||||
| Camera Access | MediaDevices API | Capacitor Camera | Not Implemented | Not Implemented |
|
||||
| Platform Detection | Web APIs | Capacitor.isNativePlatform() | process.env checks | process.env checks |
|
||||
|
||||
## 2. Project Structure
|
||||
|
||||
@@ -42,6 +42,7 @@ src/
|
||||
├── main.common.ts # Shared initialization
|
||||
├── main.capacitor.ts # Mobile entry
|
||||
├── main.electron.ts # Electron entry
|
||||
├── main.pywebview.ts # PyWebView entry
|
||||
└── main.web.ts # Web/PWA entry
|
||||
```
|
||||
|
||||
@@ -51,7 +52,9 @@ root/
|
||||
├── vite.config.common.mts # Shared config
|
||||
├── vite.config.capacitor.mts # Mobile build
|
||||
├── vite.config.electron.mts # Electron build
|
||||
└── vite.config.web.mts # Web/PWA build
|
||||
├── vite.config.pywebview.mts # PyWebView build
|
||||
├── vite.config.web.mts # Web/PWA build
|
||||
└── vite.config.utils.mts # Build utilities
|
||||
```
|
||||
|
||||
## 3. Service Architecture
|
||||
@@ -65,7 +68,8 @@ services/
|
||||
├── platforms/ # Platform-specific services
|
||||
│ ├── WebPlatformService.ts
|
||||
│ ├── CapacitorPlatformService.ts
|
||||
│ └── ElectronPlatformService.ts
|
||||
│ ├── ElectronPlatformService.ts
|
||||
│ └── PyWebViewPlatformService.ts
|
||||
└── factory/ # Service factories
|
||||
└── PlatformServiceFactory.ts
|
||||
```
|
||||
@@ -163,7 +167,8 @@ export function createBuildConfig(mode: string) {
|
||||
# Build commands from package.json
|
||||
"build:web": "vite build --config vite.config.web.mts",
|
||||
"build:capacitor": "vite build --config vite.config.capacitor.mts",
|
||||
"build:electron": "vite build --config vite.config.electron.mts"
|
||||
"build:electron": "vite build --config vite.config.electron.mts",
|
||||
"build:pywebview": "vite build --config vite.config.pywebview.mts"
|
||||
```
|
||||
|
||||
## 6. Testing Strategy
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
---
|
||||
description:
|
||||
globs:
|
||||
alwaysApply: true
|
||||
---
|
||||
use system date command to timestamp all interactions with accurate date and time
|
||||
python script files must always have a blank line
|
||||
remove whitespace at the end of lines
|
||||
never git add or commit for me. always preview changes and commit message to use and allow me to copy and paste
|
||||
✅ Preferred Commit Message Format
|
||||
|
||||
Short summary in the first line (concise and high-level).
|
||||
Avoid long commit bodies unless truly necessary.
|
||||
|
||||
✅ Valued Content in Commit Messages
|
||||
|
||||
Specific fixes or features.
|
||||
Symptoms or problems that were fixed.
|
||||
Notes about tests passing or TS/linting errors being resolved (briefly).
|
||||
|
||||
❌ Avoid in Commit Messages
|
||||
|
||||
Vague terms: “improved”, “enhanced”, “better” — especially from AI.
|
||||
Minor changes: small doc tweaks, one-liners, cleanup, or lint fixes.
|
||||
Redundant blurbs: repeated across files or too generic.
|
||||
Multiple overlapping purposes in a single commit — prefer narrow, focused commits.
|
||||
Long explanations of what can be deduced from good in-line code comments.
|
||||
|
||||
Guiding Principle
|
||||
|
||||
Let code and inline documentation speak for themselves. Use commits to highlight what isn't obvious from reading the code.
|
||||
@@ -1,6 +0,0 @@
|
||||
---
|
||||
description:
|
||||
globs:
|
||||
alwaysApply: true
|
||||
---
|
||||
All references in the codebase to Dexie apply only to migration from IndexedDb to Sqlite and will be deprecated in future versions.
|
||||
267
.cursor/rules/wa-sqlite.mdc
Normal file
267
.cursor/rules/wa-sqlite.mdc
Normal file
@@ -0,0 +1,267 @@
|
||||
---
|
||||
description:
|
||||
globs:
|
||||
alwaysApply: true
|
||||
---
|
||||
# wa-sqlite Usage Guide
|
||||
|
||||
## Table of Contents
|
||||
- [1. Overview](#1-overview)
|
||||
- [2. Installation](#2-installation)
|
||||
- [3. Basic Setup](#3-basic-setup)
|
||||
- [3.1 Import and Initialize](#31-import-and-initialize)
|
||||
- [3.2 Basic Database Operations](#32-basic-database-operations)
|
||||
- [4. Virtual File Systems (VFS)](#4-virtual-file-systems-vfs)
|
||||
- [4.1 Available VFS Options](#41-available-vfs-options)
|
||||
- [4.2 Using a VFS](#42-using-a-vfs)
|
||||
- [5. Best Practices](#5-best-practices)
|
||||
- [5.1 Error Handling](#51-error-handling)
|
||||
- [5.2 Transaction Management](#52-transaction-management)
|
||||
- [5.3 Prepared Statements](#53-prepared-statements)
|
||||
- [6. Performance Considerations](#6-performance-considerations)
|
||||
- [7. Common Issues and Solutions](#7-common-issues-and-solutions)
|
||||
- [8. TypeScript Support](#8-typescript-support)
|
||||
|
||||
## 1. Overview
|
||||
wa-sqlite is a WebAssembly build of SQLite that enables SQLite database operations in web browsers and JavaScript environments. It provides both synchronous and asynchronous builds, with support for custom virtual file systems (VFS) for persistent storage.
|
||||
|
||||
## 2. Installation
|
||||
```bash
|
||||
npm install wa-sqlite
|
||||
# or
|
||||
yarn add wa-sqlite
|
||||
```
|
||||
|
||||
## 3. Basic Setup
|
||||
|
||||
### 3.1 Import and Initialize
|
||||
```javascript
|
||||
// Choose one of these imports based on your needs:
|
||||
// - wa-sqlite.mjs: Synchronous build
|
||||
// - wa-sqlite-async.mjs: Asynchronous build (required for async VFS)
|
||||
// - wa-sqlite-jspi.mjs: JSPI-based async build (experimental, Chromium only)
|
||||
import SQLiteESMFactory from 'wa-sqlite/dist/wa-sqlite.mjs';
|
||||
import * as SQLite from 'wa-sqlite';
|
||||
|
||||
async function initDatabase() {
|
||||
// Initialize SQLite module
|
||||
const module = await SQLiteESMFactory();
|
||||
const sqlite3 = SQLite.Factory(module);
|
||||
|
||||
// Open database (returns a Promise)
|
||||
const db = await sqlite3.open_v2('myDatabase');
|
||||
return { sqlite3, db };
|
||||
}
|
||||
```
|
||||
|
||||
### 3.2 Basic Database Operations
|
||||
```javascript
|
||||
async function basicOperations() {
|
||||
const { sqlite3, db } = await initDatabase();
|
||||
|
||||
try {
|
||||
// Create a table
|
||||
await sqlite3.exec(db, `
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
email TEXT UNIQUE
|
||||
)
|
||||
`);
|
||||
|
||||
// Insert data
|
||||
await sqlite3.exec(db, `
|
||||
INSERT INTO users (name, email)
|
||||
VALUES ('John Doe', 'john@example.com')
|
||||
`);
|
||||
|
||||
// Query data
|
||||
const results = [];
|
||||
await sqlite3.exec(db, 'SELECT * FROM users', (row, columns) => {
|
||||
results.push({ row, columns });
|
||||
});
|
||||
|
||||
return results;
|
||||
} finally {
|
||||
// Always close the database when done
|
||||
await sqlite3.close(db);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 4. Virtual File Systems (VFS)
|
||||
|
||||
### 4.1 Available VFS Options
|
||||
wa-sqlite provides several VFS implementations for persistent storage:
|
||||
|
||||
1. **IDBBatchAtomicVFS** (Recommended for general use)
|
||||
- Uses IndexedDB with batch atomic writes
|
||||
- Works in all contexts (Window, Worker, Service Worker)
|
||||
- Supports WAL mode
|
||||
- Best performance with `PRAGMA synchronous=normal`
|
||||
|
||||
2. **IDBMirrorVFS**
|
||||
- Keeps files in memory, persists to IndexedDB
|
||||
- Works in all contexts
|
||||
- Good for smaller databases
|
||||
|
||||
3. **OPFS-based VFS** (Origin Private File System)
|
||||
- Various implementations available:
|
||||
- AccessHandlePoolVFS
|
||||
- OPFSAdaptiveVFS
|
||||
- OPFSCoopSyncVFS
|
||||
- OPFSPermutedVFS
|
||||
- Better performance but limited to Worker contexts
|
||||
|
||||
### 4.2 Using a VFS
|
||||
```javascript
|
||||
import { IDBBatchAtomicVFS } from 'wa-sqlite/src/examples/IDBBatchAtomicVFS.js';
|
||||
import SQLiteESMFactory from 'wa-sqlite/dist/wa-sqlite-async.mjs';
|
||||
import * as SQLite from 'wa-sqlite';
|
||||
|
||||
async function initDatabaseWithVFS() {
|
||||
const module = await SQLiteESMFactory();
|
||||
const sqlite3 = SQLite.Factory(module);
|
||||
|
||||
// Register VFS
|
||||
const vfs = await IDBBatchAtomicVFS.create('myApp', module);
|
||||
sqlite3.vfs_register(vfs, true);
|
||||
|
||||
// Open database with VFS
|
||||
const db = await sqlite3.open_v2('myDatabase');
|
||||
|
||||
// Configure for better performance
|
||||
await sqlite3.exec(db, 'PRAGMA synchronous = normal');
|
||||
await sqlite3.exec(db, 'PRAGMA journal_mode = WAL');
|
||||
|
||||
return { sqlite3, db };
|
||||
}
|
||||
```
|
||||
|
||||
## 5. Best Practices
|
||||
|
||||
### 5.1 Error Handling
|
||||
```javascript
|
||||
async function safeDatabaseOperation() {
|
||||
const { sqlite3, db } = await initDatabase();
|
||||
|
||||
try {
|
||||
await sqlite3.exec(db, 'SELECT * FROM non_existent_table');
|
||||
} catch (error) {
|
||||
if (error.code === SQLite.SQLITE_ERROR) {
|
||||
console.error('SQL error:', error.message);
|
||||
} else {
|
||||
console.error('Database error:', error);
|
||||
}
|
||||
} finally {
|
||||
await sqlite3.close(db);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 5.2 Transaction Management
|
||||
```javascript
|
||||
async function transactionExample() {
|
||||
const { sqlite3, db } = await initDatabase();
|
||||
|
||||
try {
|
||||
await sqlite3.exec(db, 'BEGIN TRANSACTION');
|
||||
|
||||
// Perform multiple operations
|
||||
await sqlite3.exec(db, 'INSERT INTO users (name) VALUES (?)', ['Alice']);
|
||||
await sqlite3.exec(db, 'INSERT INTO users (name) VALUES (?)', ['Bob']);
|
||||
|
||||
await sqlite3.exec(db, 'COMMIT');
|
||||
} catch (error) {
|
||||
await sqlite3.exec(db, 'ROLLBACK');
|
||||
throw error;
|
||||
} finally {
|
||||
await sqlite3.close(db);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 5.3 Prepared Statements
|
||||
```javascript
|
||||
async function preparedStatementExample() {
|
||||
const { sqlite3, db } = await initDatabase();
|
||||
|
||||
try {
|
||||
// Prepare statement
|
||||
const stmt = await sqlite3.prepare(db, 'SELECT * FROM users WHERE id = ?');
|
||||
|
||||
// Execute with different parameters
|
||||
await sqlite3.bind(stmt, 1, 1);
|
||||
while (await sqlite3.step(stmt) === SQLite.SQLITE_ROW) {
|
||||
const row = sqlite3.row(stmt);
|
||||
console.log(row);
|
||||
}
|
||||
|
||||
// Reset and reuse
|
||||
await sqlite3.reset(stmt);
|
||||
await sqlite3.bind(stmt, 1, 2);
|
||||
// ... execute again
|
||||
|
||||
await sqlite3.finalize(stmt);
|
||||
} finally {
|
||||
await sqlite3.close(db);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 6. Performance Considerations
|
||||
|
||||
1. **VFS Selection**
|
||||
- Use IDBBatchAtomicVFS for general-purpose applications
|
||||
- Consider OPFS-based VFS for better performance in Worker contexts
|
||||
- Use MemoryVFS for temporary databases
|
||||
|
||||
2. **Configuration**
|
||||
- Set appropriate page size (default is usually fine)
|
||||
- Use WAL mode for better concurrency
|
||||
- Consider `PRAGMA synchronous=normal` for better performance
|
||||
- Adjust cache size based on your needs
|
||||
|
||||
3. **Concurrency**
|
||||
- Use transactions for multiple operations
|
||||
- Be aware of VFS-specific concurrency limitations
|
||||
- Consider using Web Workers for heavy database operations
|
||||
|
||||
## 7. Common Issues and Solutions
|
||||
|
||||
1. **Database Locking**
|
||||
- Use appropriate transaction isolation levels
|
||||
- Implement retry logic for busy errors
|
||||
- Consider using WAL mode
|
||||
|
||||
2. **Storage Limitations**
|
||||
- Be aware of browser storage quotas
|
||||
- Implement cleanup strategies
|
||||
- Monitor database size
|
||||
|
||||
3. **Cross-Context Access**
|
||||
- Use appropriate VFS for your context
|
||||
- Consider message passing for cross-context communication
|
||||
- Be aware of storage access limitations
|
||||
|
||||
## 8. TypeScript Support
|
||||
wa-sqlite includes TypeScript definitions. The main types are:
|
||||
|
||||
```typescript
|
||||
type SQLiteCompatibleType = number | string | Uint8Array | Array<number> | bigint | null;
|
||||
|
||||
interface SQLiteAPI {
|
||||
open_v2(filename: string, flags?: number, zVfs?: string): Promise<number>;
|
||||
exec(db: number, sql: string, callback?: (row: any[], columns: string[]) => void): Promise<number>;
|
||||
close(db: number): Promise<number>;
|
||||
// ... other methods
|
||||
}
|
||||
```
|
||||
|
||||
## Additional Resources
|
||||
|
||||
- [Official GitHub Repository](https://github.com/rhashimoto/wa-sqlite)
|
||||
- [Online Demo](https://rhashimoto.github.io/wa-sqlite/demo/)
|
||||
- [API Reference](https://rhashimoto.github.io/wa-sqlite/docs/)
|
||||
- [FAQ](https://github.com/rhashimoto/wa-sqlite/issues?q=is%3Aissue+label%3Afaq+)
|
||||
- [Discussion Forums](https://github.com/rhashimoto/wa-sqlite/discussions)
|
||||
171
.dockerignore
171
.dockerignore
@@ -1,171 +0,0 @@
|
||||
# TimeSafari Docker Ignore File
|
||||
# Author: Matthew Raymer
|
||||
# Description: Excludes unnecessary files from Docker build context
|
||||
#
|
||||
# Benefits:
|
||||
# - Faster build times
|
||||
# - Smaller build context
|
||||
# - Reduced image size
|
||||
# - Better security (excludes sensitive files)
|
||||
|
||||
# Dependencies
|
||||
node_modules
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Build outputs
|
||||
dist
|
||||
dist-*
|
||||
build
|
||||
*.tsbuildinfo
|
||||
|
||||
# Development files
|
||||
.git
|
||||
.gitignore
|
||||
README.md
|
||||
CHANGELOG.md
|
||||
CONTRIBUTING.md
|
||||
BUILDING.md
|
||||
LICENSE
|
||||
|
||||
# IDE and editor files
|
||||
.vscode
|
||||
.idea
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
|
||||
# OS generated files
|
||||
.DS_Store
|
||||
.DS_Store?
|
||||
._*
|
||||
.Spotlight-V100
|
||||
.Trashes
|
||||
ehthumbs.db
|
||||
Thumbs.db
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Dependency directories
|
||||
jspm_packages/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
.parcel-cache
|
||||
|
||||
# next.js build output
|
||||
.next
|
||||
|
||||
# nuxt.js build output
|
||||
.nuxt
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
# Test files
|
||||
test-playwright
|
||||
test-playwright-results
|
||||
test-results
|
||||
test-scripts
|
||||
|
||||
# Documentation
|
||||
doc
|
||||
|
||||
# Scripts (keep only what's needed for build)
|
||||
scripts/test-*.sh
|
||||
scripts/*.js
|
||||
scripts/README.md
|
||||
|
||||
# Platform-specific files
|
||||
android
|
||||
ios
|
||||
electron
|
||||
|
||||
# Docker files (avoid recursive copying)
|
||||
Dockerfile*
|
||||
docker-compose*
|
||||
.dockerignore
|
||||
|
||||
# CI/CD files
|
||||
.github
|
||||
.gitlab-ci.yml
|
||||
.travis.yml
|
||||
.circleci
|
||||
|
||||
# Temporary files
|
||||
tmp
|
||||
temp
|
||||
|
||||
# Backup files
|
||||
*.bak
|
||||
*.backup
|
||||
|
||||
# Archive files
|
||||
*.tar
|
||||
*.tar.gz
|
||||
*.zip
|
||||
*.rar
|
||||
|
||||
# Certificate files
|
||||
*.pem
|
||||
*.key
|
||||
*.crt
|
||||
*.p12
|
||||
|
||||
# Configuration files that might contain secrets
|
||||
*.secrets
|
||||
secrets.json
|
||||
config.local.json
|
||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -54,6 +54,5 @@ build_logs/
|
||||
# PWA icon files generated by capacitor-assets
|
||||
icons
|
||||
|
||||
*.log
|
||||
android/app/src/main/res/
|
||||
sql-wasm.wasm
|
||||
|
||||
android/app/src/main/res/
|
||||
66
BUILDING.md
66
BUILDING.md
@@ -41,7 +41,6 @@ Install dependencies:
|
||||
1. Run the production build:
|
||||
|
||||
```bash
|
||||
rm -rf dist
|
||||
npm run build:web
|
||||
```
|
||||
|
||||
@@ -63,18 +62,16 @@ Install dependencies:
|
||||
|
||||
* Update the ClickUp tasks & CHANGELOG.md & the version in package.json, run `npm install`.
|
||||
|
||||
* Run a build to make sure package-lock version is updated, linting works, etc: `npm install && npm run build`
|
||||
|
||||
* Commit everything (since the commit hash is used the app).
|
||||
|
||||
* Put the commit hash in the changelog (which will help you remember to bump the version in the step later).
|
||||
* Put the commit hash in the changelog (which will help you remember to bump the version later).
|
||||
|
||||
* Tag with the new version, [online](https://gitea.anomalistdesign.com/trent_larson/crowd-funder-for-time-pwa/releases) or `git tag 1.0.2 && git push origin 1.0.2`.
|
||||
* Tag with the new version, [online](https://gitea.anomalistdesign.com/trent_larson/crowd-funder-for-time-pwa/releases) or `git tag 0.3.55 && git push origin 0.3.55`.
|
||||
|
||||
* For test, build the app (because test server is not yet set up to build):
|
||||
|
||||
```bash
|
||||
TIME_SAFARI_APP_TITLE="TimeSafari_Test" VITE_APP_SERVER=https://test.timesafari.app VITE_BVC_MEETUPS_PROJECT_CLAIM_ID=https://endorser.ch/entity/01HWE8FWHQ1YGP7GFZYYPS272F VITE_DEFAULT_ENDORSER_API_SERVER=https://test-api.endorser.ch VITE_DEFAULT_IMAGE_API_SERVER=https://test-image-api.timesafari.app VITE_DEFAULT_PARTNER_API_SERVER=https://test-partner-api.endorser.ch VITE_DEFAULT_PUSH_SERVER=https://test.timesafari.app VITE_PASSKEYS_ENABLED=true npm run build:web
|
||||
TIME_SAFARI_APP_TITLE="TimeSafari_Test" VITE_APP_SERVER=https://test.timesafari.app VITE_BVC_MEETUPS_PROJECT_CLAIM_ID=https://endorser.ch/entity/01HWE8FWHQ1YGP7GFZYYPS272F VITE_DEFAULT_ENDORSER_API_SERVER=https://test-api.endorser.ch VITE_DEFAULT_IMAGE_API_SERVER=https://test-image-api.timesafari.app VITE_DEFAULT_PARTNER_API_SERVER=https://test-partner-api.endorser.ch VITE_DEFAULT_PUSH_SERVER=https://test.timesafari.app VITE_PASSKEYS_ENABLED=true npm run build
|
||||
```
|
||||
|
||||
... and transfer to the test server:
|
||||
@@ -93,13 +90,13 @@ TIME_SAFARI_APP_TITLE="TimeSafari_Test" VITE_APP_SERVER=https://test.timesafari.
|
||||
|
||||
* `pkgx +npm sh`
|
||||
|
||||
* `cd crowd-funder-for-time-pwa && git checkout master && git pull && git checkout 1.0.2 && npm install && npm run build:web && cd -`
|
||||
* `cd crowd-funder-for-time-pwa && git checkout master && git pull && git checkout 0.3.55 && npm install && npm run build && cd -`
|
||||
|
||||
(The plain `npm run build:web` uses the .env.production file.)
|
||||
(The plain `npm run build` uses the .env.production file.)
|
||||
|
||||
* Back up the time-safari/dist folder & deploy: `mv time-safari/dist time-safari-dist-prev-2 && mv crowd-funder-for-time-pwa/dist time-safari/`
|
||||
* Back up the time-safari/dist folder & deploy: `mv time-safari/dist time-safari-dist-prev.0 && mv crowd-funder-for-time-pwa/dist time-safari/`
|
||||
|
||||
* Record the new hash in the changelog. Edit package.json to increment version & add "-beta", `npm install`, commit, and push. Also record what version is on production.
|
||||
* Record the new hash in the changelog. Edit package.json to increment version & add "-beta", `npm install`, and commit. Also record what version is on production.
|
||||
|
||||
## Docker Deployment
|
||||
|
||||
@@ -316,36 +313,6 @@ npm run build:electron-prod && npm run electron:start
|
||||
|
||||
Prerequisites: macOS with Xcode installed
|
||||
|
||||
#### Automated Build Script
|
||||
|
||||
The recommended way to build for iOS is using the automated build script:
|
||||
|
||||
```bash
|
||||
# Standard build and open Xcode
|
||||
./scripts/build-ios.sh
|
||||
|
||||
# Build with specific version numbers
|
||||
./scripts/build-ios.sh --version 1.0.3 --build-number 35
|
||||
|
||||
# Build without opening Xcode (for CI/CD)
|
||||
./scripts/build-ios.sh --no-xcode
|
||||
|
||||
# Show all available options
|
||||
./scripts/build-ios.sh --help
|
||||
```
|
||||
|
||||
The script handles all the necessary steps including:
|
||||
- Environment setup and validation
|
||||
- Web asset building
|
||||
- Capacitor synchronization
|
||||
- iOS asset generation
|
||||
- Version number updates
|
||||
- Xcode project opening
|
||||
|
||||
#### Manual Build Process
|
||||
|
||||
If you need to build manually or want to understand the individual steps:
|
||||
|
||||
#### First-time iOS Configuration
|
||||
|
||||
- Generate certificates inside XCode.
|
||||
@@ -367,18 +334,25 @@ If you need to build manually or want to understand the individual steps:
|
||||
export GEM_PATH=$shortened_path
|
||||
```
|
||||
|
||||
1. Build the web assets & update ios:
|
||||
1. Check the iOS flag isIOS in CapacitorPlatformService (currently hard-coded for iOS build).
|
||||
|
||||
2. Build the web assets:
|
||||
|
||||
```bash
|
||||
rm -rf dist
|
||||
npm run build:web
|
||||
npm run build:capacitor
|
||||
```
|
||||
|
||||
3. Update iOS project with latest build:
|
||||
|
||||
```bash
|
||||
npx cap sync ios
|
||||
```
|
||||
|
||||
- If that fails with "Could not find..." then look at the "gem_path" instructions above.
|
||||
|
||||
3. Copy the assets:
|
||||
4. Copy the assets:
|
||||
|
||||
```bash
|
||||
# It makes no sense why capacitor-assets will not run without these but it actually changes the contents.
|
||||
@@ -392,9 +366,12 @@ If you need to build manually or want to understand the individual steps:
|
||||
4. Bump the version to match Android & package.json:
|
||||
|
||||
```
|
||||
cd ios/App && xcrun agvtool new-version 35 && perl -p -i -e "s/MARKETING_VERSION = .*;/MARKETING_VERSION = 1.0.2;/g" App.xcodeproj/project.pbxproj && cd -
|
||||
cd ios/App
|
||||
xcrun agvtool new-version 30
|
||||
# Unfortunately this edits Info.plist directly.
|
||||
#xcrun agvtool new-marketing-version 0.4.5
|
||||
cat App.xcodeproj/project.pbxproj | sed "s/MARKETING_VERSION = .*;/MARKETING_VERSION = 0.5.4;/g" > temp && mv temp App.xcodeproj/project.pbxproj
|
||||
cd -
|
||||
```
|
||||
|
||||
5. Open the project in Xcode:
|
||||
@@ -421,6 +398,8 @@ If you need to build manually or want to understand the individual steps:
|
||||
* You'll probably have to "Manage" something about encryption, disallowed in France.
|
||||
* Then "Save" and "Add to Review" and "Resubmit to App Review".
|
||||
|
||||
8. Revert the iOS flag isIOS in CapacitorPlatformService.
|
||||
|
||||
### Android Build
|
||||
|
||||
Prerequisites: Android Studio with Java SDK installed
|
||||
@@ -462,6 +441,7 @@ Prerequisites: Android Studio with Java SDK installed
|
||||
./gradlew clean
|
||||
./gradlew build -Dlint.baselines.continue=true
|
||||
cd -
|
||||
npx cap run android
|
||||
```
|
||||
|
||||
... or, to create the `aab` file, `bundle` instead of `build`:
|
||||
|
||||
22
CHANGELOG.md
22
CHANGELOG.md
@@ -6,28 +6,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
|
||||
## [1.0.2] - 2025.06.20 - 276e0a741bc327de3380c4e508cccb7fee58c06d
|
||||
### Added
|
||||
- Version on feed title
|
||||
|
||||
|
||||
## [1.0.1] - 2025.06.20
|
||||
### Added
|
||||
- Allow a user to block someone else's content from view
|
||||
|
||||
|
||||
## [1.0.0] - 2025.06.20 - 5aa693de6337e5dbb278bfddc6bd39094bc14f73
|
||||
### Added
|
||||
- Web-oriented migration from IndexedDB to SQLite
|
||||
|
||||
|
||||
## [0.5.8]
|
||||
### Added
|
||||
- /deep-link/ path for URLs that are shared with people
|
||||
### Changed
|
||||
- External links now go to /deep-link/...
|
||||
- Feed visuals now have arrow imagery from giver to receiver
|
||||
|
||||
|
||||
## [0.4.7]
|
||||
### Fixed
|
||||
|
||||
201
Dockerfile
201
Dockerfile
@@ -1,209 +1,36 @@
|
||||
# TimeSafari Docker Build
|
||||
# Author: Matthew Raymer
|
||||
# Description: Multi-stage Docker build for TimeSafari web application
|
||||
#
|
||||
# Build Process:
|
||||
# 1. Base stage: Node.js with build dependencies
|
||||
# 2. Builder stage: Compile web assets with Vite
|
||||
# 3. Production stage: Nginx server with optimized assets
|
||||
#
|
||||
# Security Features:
|
||||
# - Non-root user execution
|
||||
# - Minimal attack surface with Alpine Linux
|
||||
# - Multi-stage build to reduce image size
|
||||
# - No build dependencies in final image
|
||||
#
|
||||
# Usage:
|
||||
# Production: docker build -t timesafari:latest .
|
||||
# Staging: docker build --build-arg BUILD_MODE=staging -t timesafari:staging .
|
||||
# Development: docker build --build-arg BUILD_MODE=development -t timesafari:dev .
|
||||
#
|
||||
# Build Arguments:
|
||||
# BUILD_MODE: development, staging, or production (default: production)
|
||||
# NODE_ENV: node environment (default: production)
|
||||
# VITE_PLATFORM: vite platform (default: web)
|
||||
# VITE_PWA_ENABLED: enable PWA (default: true)
|
||||
# VITE_DISABLE_PWA: disable PWA (default: false)
|
||||
#
|
||||
# Environment Variables:
|
||||
# NODE_ENV: Build environment (development/production)
|
||||
# VITE_APP_SERVER: Application server URL
|
||||
# VITE_DEFAULT_ENDORSER_API_SERVER: Endorser API server URL
|
||||
# VITE_DEFAULT_IMAGE_API_SERVER: Image API server URL
|
||||
# VITE_DEFAULT_PARTNER_API_SERVER: Partner API server URL
|
||||
# VITE_DEFAULT_PUSH_SERVER: Push notification server URL
|
||||
# VITE_PASSKEYS_ENABLED: Enable passkeys feature
|
||||
# Build stage
|
||||
FROM node:22-alpine3.20 AS builder
|
||||
|
||||
# =============================================================================
|
||||
# BASE STAGE - Common dependencies and setup
|
||||
# =============================================================================
|
||||
FROM node:22-alpine3.20 AS base
|
||||
# Install build dependencies
|
||||
|
||||
# Install system dependencies for build process
|
||||
RUN apk add --no-cache \
|
||||
bash \
|
||||
git \
|
||||
python3 \
|
||||
py3-pip \
|
||||
py3-setuptools \
|
||||
make \
|
||||
g++ \
|
||||
gcc \
|
||||
&& rm -rf /var/cache/apk/*
|
||||
|
||||
# Create non-root user for security
|
||||
RUN addgroup -g 1001 -S nodejs && \
|
||||
adduser -S nextjs -u 1001
|
||||
RUN apk add --no-cache bash git python3 py3-pip py3-setuptools make g++ gcc
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files for dependency installation
|
||||
# Copy package files
|
||||
COPY package*.json ./
|
||||
|
||||
# Install dependencies with security audit
|
||||
RUN npm ci --only=production --audit --fund=false && \
|
||||
npm audit fix --audit-level=moderate || true
|
||||
|
||||
# =============================================================================
|
||||
# BUILDER STAGE - Compile web assets
|
||||
# =============================================================================
|
||||
FROM base AS builder
|
||||
|
||||
# Define build arguments with defaults
|
||||
ARG BUILD_MODE=production
|
||||
ARG NODE_ENV=production
|
||||
ARG VITE_PLATFORM=web
|
||||
ARG VITE_PWA_ENABLED=true
|
||||
ARG VITE_DISABLE_PWA=false
|
||||
|
||||
# Set environment variables from build arguments
|
||||
ENV BUILD_MODE=${BUILD_MODE}
|
||||
ENV NODE_ENV=${NODE_ENV}
|
||||
ENV VITE_PLATFORM=${VITE_PLATFORM}
|
||||
ENV VITE_PWA_ENABLED=${VITE_PWA_ENABLED}
|
||||
ENV VITE_DISABLE_PWA=${VITE_DISABLE_PWA}
|
||||
|
||||
# Install all dependencies (including dev dependencies)
|
||||
RUN npm ci --audit --fund=false && \
|
||||
npm audit fix --audit-level=moderate || true
|
||||
# Install dependencies
|
||||
RUN npm ci
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Build the application with proper error handling
|
||||
RUN echo "Building TimeSafari in ${BUILD_MODE} mode..." && \
|
||||
npm run build:web || (echo "Build failed. Check the logs above." && exit 1)
|
||||
# Build the application
|
||||
RUN npm run build:web
|
||||
|
||||
# Verify build output exists
|
||||
RUN ls -la dist/ || (echo "Build output not found in dist/ directory" && exit 1)
|
||||
|
||||
# =============================================================================
|
||||
# PRODUCTION STAGE - Nginx server
|
||||
# =============================================================================
|
||||
FROM nginx:alpine AS production
|
||||
|
||||
# Define build arguments for production stage
|
||||
ARG BUILD_MODE=production
|
||||
ARG NODE_ENV=production
|
||||
|
||||
# Set environment variables
|
||||
ENV BUILD_MODE=${BUILD_MODE}
|
||||
ENV NODE_ENV=${NODE_ENV}
|
||||
|
||||
# Install security updates and clean cache
|
||||
RUN apk update && \
|
||||
apk upgrade && \
|
||||
apk add --no-cache \
|
||||
curl \
|
||||
&& rm -rf /var/cache/apk/*
|
||||
|
||||
# Create non-root user for nginx
|
||||
RUN addgroup -g 1001 -S nginx && \
|
||||
adduser -S nginx -u 1001 -G nginx
|
||||
|
||||
# Copy appropriate nginx configuration based on build mode
|
||||
COPY docker/nginx.conf /etc/nginx/nginx.conf
|
||||
COPY docker/default.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
# Copy staging configuration if needed
|
||||
COPY docker/staging.conf /etc/nginx/conf.d/staging.conf
|
||||
# Production stage
|
||||
FROM nginx:alpine
|
||||
|
||||
# Copy built assets from builder stage
|
||||
COPY --from=builder --chown=nginx:nginx /app/dist /usr/share/nginx/html
|
||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||
|
||||
# Create necessary directories with proper permissions
|
||||
RUN mkdir -p /var/cache/nginx /var/log/nginx /var/run && \
|
||||
chown -R nginx:nginx /var/cache/nginx /var/log/nginx /var/run && \
|
||||
chown -R nginx:nginx /usr/share/nginx/html
|
||||
|
||||
# Switch to non-root user
|
||||
USER nginx
|
||||
# Copy nginx configuration if needed
|
||||
# COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
# Expose port 80
|
||||
EXPOSE 80
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||||
CMD curl -f http://localhost/ || exit 1
|
||||
|
||||
# Start nginx with proper signal handling
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
|
||||
# =============================================================================
|
||||
# DEVELOPMENT STAGE - For development with hot reloading
|
||||
# =============================================================================
|
||||
FROM base AS development
|
||||
|
||||
# Define build arguments for development stage
|
||||
ARG BUILD_MODE=development
|
||||
ARG NODE_ENV=development
|
||||
ARG VITE_PLATFORM=web
|
||||
ARG VITE_PWA_ENABLED=true
|
||||
ARG VITE_DISABLE_PWA=false
|
||||
|
||||
# Set environment variables
|
||||
ENV BUILD_MODE=${BUILD_MODE}
|
||||
ENV NODE_ENV=${NODE_ENV}
|
||||
ENV VITE_PLATFORM=${VITE_PLATFORM}
|
||||
ENV VITE_PWA_ENABLED=${VITE_PWA_ENABLED}
|
||||
ENV VITE_DISABLE_PWA=${VITE_DISABLE_PWA}
|
||||
|
||||
# Install all dependencies including dev dependencies
|
||||
RUN npm ci --audit --fund=false && \
|
||||
npm audit fix --audit-level=moderate || true
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Expose development port
|
||||
EXPOSE 5173
|
||||
|
||||
# Start development server
|
||||
CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0"]
|
||||
|
||||
# =============================================================================
|
||||
# STAGING STAGE - For staging environment testing
|
||||
# =============================================================================
|
||||
FROM production AS staging
|
||||
|
||||
# Define build arguments for staging stage
|
||||
ARG BUILD_MODE=staging
|
||||
ARG NODE_ENV=staging
|
||||
|
||||
# Set environment variables
|
||||
ENV BUILD_MODE=${BUILD_MODE}
|
||||
ENV NODE_ENV=${NODE_ENV}
|
||||
|
||||
# Copy staging-specific nginx configuration
|
||||
COPY docker/staging.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
# Expose port 80
|
||||
EXPOSE 80
|
||||
|
||||
# Health check for staging
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||||
CMD curl -f http://localhost/health || exit 1
|
||||
|
||||
# Start nginx
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
47
README.md
47
README.md
@@ -3,32 +3,6 @@
|
||||
[Time Safari](https://timesafari.org/) allows people to ease into collaboration: start with expressions of gratitude
|
||||
and expand to crowd-fund with time & money, then record and see the impact of contributions.
|
||||
|
||||
## Database Migration Status
|
||||
|
||||
**Current Status**: The application is undergoing a migration from Dexie (IndexedDB) to SQLite using absurd-sql. This migration is in **Phase 2** with a well-defined migration fence in place.
|
||||
|
||||
### Migration Progress
|
||||
- ✅ **SQLite Database Service**: Fully implemented with absurd-sql
|
||||
- ✅ **Platform Service Layer**: Unified database interface across platforms
|
||||
- ✅ **Settings Migration**: Core user settings transferred
|
||||
- ✅ **Account Migration**: Identity and key management
|
||||
- 🔄 **Contact Migration**: User contact data (via import interface)
|
||||
- 📋 **Code Cleanup**: Remove unused Dexie imports
|
||||
|
||||
### Migration Fence
|
||||
The migration is controlled by a **migration fence** that separates legacy Dexie code from the new SQLite implementation. See [Migration Fence Definition](doc/migration-fence-definition.md) for complete details.
|
||||
|
||||
**Key Points**:
|
||||
- Legacy Dexie database is disabled by default (`USE_DEXIE_DB = false`)
|
||||
- All database operations go through `PlatformService`
|
||||
- Migration tools provide controlled access to both databases
|
||||
- Clear separation between legacy and new code
|
||||
|
||||
### Migration Documentation
|
||||
- [Migration Guide](doc/migration-to-wa-sqlite.md) - Complete migration process
|
||||
- [Migration Fence Definition](doc/migration-fence-definition.md) - Fence boundaries and rules
|
||||
- [Database Migration Guide](doc/database-migration-guide.md) - User-facing migration tools
|
||||
|
||||
## Roadmap
|
||||
|
||||
See [project.task.yaml](project.task.yaml) for current priorities.
|
||||
@@ -47,10 +21,16 @@ npm run dev
|
||||
|
||||
See [BUILDING.md](BUILDING.md) for more details.
|
||||
|
||||
|
||||
|
||||
|
||||
## Tests
|
||||
|
||||
See [TESTING.md](test-playwright/TESTING.md) for detailed test instructions.
|
||||
|
||||
|
||||
|
||||
|
||||
## Icons
|
||||
|
||||
Application icons are in the `assets` directory, processed by the `capacitor-assets` command.
|
||||
@@ -86,21 +66,6 @@ Key principles:
|
||||
- Common interfaces are shared through `common.ts`
|
||||
- Type definitions are generated from Zod schemas where possible
|
||||
|
||||
### Database Architecture
|
||||
|
||||
The application uses a platform-agnostic database layer:
|
||||
|
||||
* `src/services/PlatformService.ts` - Database interface definition
|
||||
* `src/services/PlatformServiceFactory.ts` - Platform-specific service factory
|
||||
* `src/services/AbsurdSqlDatabaseService.ts` - SQLite implementation
|
||||
* `src/db/` - Legacy Dexie database (migration in progress)
|
||||
|
||||
**Development Guidelines**:
|
||||
- Always use `PlatformService` for database operations
|
||||
- Never import Dexie directly in application code
|
||||
- Test with `USE_DEXIE_DB = false` for new features
|
||||
- Use migration tools for data transfer between systems
|
||||
|
||||
### Kudos
|
||||
|
||||
Gifts make the world go 'round!
|
||||
|
||||
@@ -31,8 +31,8 @@ android {
|
||||
applicationId "app.timesafari.app"
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode 35
|
||||
versionName "1.0.2"
|
||||
versionCode 30
|
||||
versionName "0.5.4"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
aaptOptions {
|
||||
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"appId": "app.timesafari",
|
||||
"appName": "TimeSafari",
|
||||
"webDir": "dist",
|
||||
"bundledWebRuntime": false,
|
||||
"server": {
|
||||
"cleartext": true
|
||||
},
|
||||
@@ -16,7 +17,7 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"CapacitorSQLite": {
|
||||
"SQLite": {
|
||||
"iosDatabaseLocation": "Library/CapacitorDatabase",
|
||||
"iosIsEncryption": false,
|
||||
"iosBiometric": {
|
||||
@@ -27,8 +28,7 @@
|
||||
"androidBiometric": {
|
||||
"biometricAuth": false,
|
||||
"biometricTitle": "Biometric login for TimeSafari"
|
||||
},
|
||||
"electronIsEncryption": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"ios": {
|
||||
@@ -52,56 +52,5 @@
|
||||
"*.jsdelivr.net",
|
||||
"api.endorser.ch"
|
||||
]
|
||||
},
|
||||
"electron": {
|
||||
"deepLinking": {
|
||||
"schemes": [
|
||||
"timesafari"
|
||||
]
|
||||
},
|
||||
"buildOptions": {
|
||||
"appId": "app.timesafari",
|
||||
"productName": "TimeSafari",
|
||||
"directories": {
|
||||
"output": "dist-electron-packages"
|
||||
},
|
||||
"files": [
|
||||
"dist/**/*",
|
||||
"electron/**/*"
|
||||
],
|
||||
"mac": {
|
||||
"category": "public.app-category.productivity",
|
||||
"target": [
|
||||
{
|
||||
"target": "dmg",
|
||||
"arch": [
|
||||
"x64",
|
||||
"arm64"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"win": {
|
||||
"target": [
|
||||
{
|
||||
"target": "nsis",
|
||||
"arch": [
|
||||
"x64"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"linux": {
|
||||
"target": [
|
||||
{
|
||||
"target": "AppImage",
|
||||
"arch": [
|
||||
"x64"
|
||||
]
|
||||
}
|
||||
],
|
||||
"category": "Utility"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ buildscript {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:8.10.1'
|
||||
classpath 'com.android.tools.build:gradle:8.9.1'
|
||||
classpath 'com.google.gms:google-services:4.4.0'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"appId": "app.timesafari",
|
||||
"appName": "TimeSafari",
|
||||
"webDir": "dist",
|
||||
"bundledWebRuntime": false,
|
||||
"server": {
|
||||
"cleartext": true
|
||||
},
|
||||
@@ -16,7 +17,7 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"CapacitorSQLite": {
|
||||
"SQLite": {
|
||||
"iosDatabaseLocation": "Library/CapacitorDatabase",
|
||||
"iosIsEncryption": false,
|
||||
"iosBiometric": {
|
||||
@@ -27,8 +28,7 @@
|
||||
"androidBiometric": {
|
||||
"biometricAuth": false,
|
||||
"biometricTitle": "Biometric login for TimeSafari"
|
||||
},
|
||||
"electronIsEncryption": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"ios": {
|
||||
@@ -52,47 +52,5 @@
|
||||
"*.jsdelivr.net",
|
||||
"api.endorser.ch"
|
||||
]
|
||||
},
|
||||
"electron": {
|
||||
"deepLinking": {
|
||||
"schemes": ["timesafari"]
|
||||
},
|
||||
"buildOptions": {
|
||||
"appId": "app.timesafari",
|
||||
"productName": "TimeSafari",
|
||||
"directories": {
|
||||
"output": "dist-electron-packages"
|
||||
},
|
||||
"files": [
|
||||
"dist/**/*",
|
||||
"electron/**/*"
|
||||
],
|
||||
"mac": {
|
||||
"category": "public.app-category.productivity",
|
||||
"target": [
|
||||
{
|
||||
"target": "dmg",
|
||||
"arch": ["x64", "arm64"]
|
||||
}
|
||||
]
|
||||
},
|
||||
"win": {
|
||||
"target": [
|
||||
{
|
||||
"target": "nsis",
|
||||
"arch": ["x64"]
|
||||
}
|
||||
]
|
||||
},
|
||||
"linux": {
|
||||
"target": [
|
||||
{
|
||||
"target": "AppImage",
|
||||
"arch": ["x64"]
|
||||
}
|
||||
],
|
||||
"category": "Utility"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,6 @@ try {
|
||||
- `src/interfaces/deepLinks.ts`: Type definitions and validation schemas
|
||||
- `src/services/deepLinks.ts`: Deep link processing service
|
||||
- `src/main.capacitor.ts`: Capacitor integration
|
||||
- `src/views/DeepLinkRedirectView.vue`: Page to handle links to both mobile and web
|
||||
|
||||
## Type Safety Examples
|
||||
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
# TimeSafari Build Modernization Context
|
||||
|
||||
**Author:** Matthew Raymer
|
||||
|
||||
## Motivation
|
||||
- Eliminate manual hacks and post-build scripts for Electron builds
|
||||
- Ensure maintainability, reproducibility, and security of build outputs
|
||||
- Unify build, test, and deployment scripts for developer experience and CI/CD
|
||||
|
||||
## Key Technical Decisions
|
||||
- **Vite is the single source of truth for build output**
|
||||
- All Electron build output (main process, preload, renderer HTML/CSS/JS) is managed by `vite.config.electron.mts`
|
||||
- **CSS injection for Electron is handled by a Vite plugin**
|
||||
- No more manual HTML/CSS edits or post-build scripts
|
||||
- **Build scripts are unified and robust**
|
||||
- Use `./scripts/build-electron.sh` for all Electron builds
|
||||
- No more `fix-inject-css.js` or similar hacks
|
||||
- **Output structure is deterministic and ASAR-friendly**
|
||||
- Main process: `dist-electron/main.js`
|
||||
- Preload: `dist-electron/preload.js`
|
||||
- Renderer assets: `dist-electron/www/` (HTML, CSS, JS)
|
||||
|
||||
## Security & Maintenance Checklist
|
||||
- [x] All scripts and configs are committed and documented
|
||||
- [x] No manual file hacks remain
|
||||
- [x] All build output is deterministic and reproducible
|
||||
- [x] No sensitive data is exposed in the build process
|
||||
- [x] Documentation (`BUILDING.md`) is up to date
|
||||
|
||||
## How to Build Electron
|
||||
1. Run:
|
||||
```bash
|
||||
./scripts/build-electron.sh
|
||||
```
|
||||
2. Output will be in `dist-electron/`:
|
||||
- `main.js`, `preload.js` in root
|
||||
- `www/` contains all renderer assets
|
||||
3. No manual post-processing is required
|
||||
|
||||
## Customization
|
||||
- **Vite config:** All build output and asset handling is controlled in `vite.config.electron.mts`
|
||||
- **CSS/HTML injection:** Use Vite plugins (see `electron-css-injection` in the config) for further customization
|
||||
- **Build scripts:** All orchestration is in `scripts/` and documented in `BUILDING.md`
|
||||
|
||||
## For Future Developers
|
||||
- Always use Vite plugins/config for build output changes
|
||||
- Never manually edit built files or inject assets post-build
|
||||
- Keep documentation and scripts in sync with the build process
|
||||
|
||||
---
|
||||
This file documents the context and rationale for the build modernization and should be included in the repository for onboarding and future reference.
|
||||
@@ -1,295 +0,0 @@
|
||||
# Database Migration Guide
|
||||
|
||||
## Overview
|
||||
|
||||
The Database Migration feature allows you to compare and migrate data between Dexie (IndexedDB) and SQLite databases in the TimeSafari application. This is particularly useful during the transition from the old Dexie-based storage system to the new SQLite-based system.
|
||||
|
||||
## Features
|
||||
|
||||
### 1. Database Comparison
|
||||
|
||||
- Compare data between Dexie and SQLite databases
|
||||
- View detailed differences in contacts and settings
|
||||
- Identify added, modified, and missing records
|
||||
- Export comparison results for analysis
|
||||
|
||||
### 2. Data Migration
|
||||
|
||||
- Migrate contacts from Dexie to SQLite
|
||||
- Migrate settings from Dexie to SQLite
|
||||
- Option to overwrite existing records or skip them
|
||||
- Comprehensive error handling and reporting
|
||||
|
||||
### 3. User Interface
|
||||
|
||||
- Modern, responsive UI built with Tailwind CSS
|
||||
- Real-time loading states and progress indicators
|
||||
- Clear success and error messaging
|
||||
- Export functionality for comparison data
|
||||
|
||||
## Prerequisites
|
||||
|
||||
### Enable Dexie Database
|
||||
|
||||
Before using the migration features, you must enable the Dexie database by setting:
|
||||
|
||||
```typescript
|
||||
// In constants/app.ts
|
||||
export const USE_DEXIE_DB = true;
|
||||
```
|
||||
|
||||
**Note**: This should only be enabled temporarily during migration. Remember to set it back to `false` after migration is complete.
|
||||
|
||||
## Accessing the Migration Interface
|
||||
|
||||
1. Navigate to the **Account** page in the TimeSafari app
|
||||
2. Scroll down to find the **Database Migration** link
|
||||
3. Click the link to open the migration interface
|
||||
|
||||
## Using the Migration Interface
|
||||
|
||||
### Step 1: Compare Databases
|
||||
|
||||
1. Click the **"Compare Databases"** button
|
||||
2. The system will retrieve data from both Dexie and SQLite databases
|
||||
3. Review the comparison results showing:
|
||||
- Summary counts for each database
|
||||
- Detailed differences (added, modified, missing records)
|
||||
- Specific records that need attention
|
||||
|
||||
### Step 2: Review Differences
|
||||
|
||||
The comparison results are displayed in several sections:
|
||||
|
||||
#### Summary Cards
|
||||
|
||||
- **Dexie Contacts**: Number of contacts in Dexie database
|
||||
- **SQLite Contacts**: Number of contacts in SQLite database
|
||||
- **Dexie Settings**: Number of settings in Dexie database
|
||||
- **SQLite Settings**: Number of settings in SQLite database
|
||||
|
||||
#### Contact Differences
|
||||
|
||||
- **Added**: Contacts in Dexie but not in SQLite
|
||||
- **Modified**: Contacts that differ between databases
|
||||
- **Missing**: Contacts in SQLite but not in Dexie
|
||||
|
||||
#### Settings Differences
|
||||
|
||||
- **Added**: Settings in Dexie but not in SQLite
|
||||
- **Modified**: Settings that differ between databases
|
||||
- **Missing**: Settings in SQLite but not in Dexie
|
||||
|
||||
### Step 3: Configure Migration Options
|
||||
|
||||
Before migrating data, configure the migration options:
|
||||
|
||||
- **Overwrite existing records**: When enabled, existing records in SQLite will be updated with data from Dexie. When disabled, existing records will be skipped.
|
||||
|
||||
### Step 4: Migrate Data
|
||||
|
||||
#### Migrate Contacts
|
||||
|
||||
1. Click the **"Migrate Contacts"** button
|
||||
2. The system will transfer contacts from Dexie to SQLite
|
||||
3. Review the migration results showing:
|
||||
- Number of contacts successfully migrated
|
||||
- Any warnings or errors encountered
|
||||
|
||||
#### Migrate Settings
|
||||
|
||||
1. Click the **"Migrate Settings"** button
|
||||
2. The system will transfer settings from Dexie to SQLite
|
||||
3. Review the migration results showing:
|
||||
- Number of settings successfully migrated
|
||||
- Any warnings or errors encountered
|
||||
|
||||
### Step 5: Export Comparison (Optional)
|
||||
|
||||
1. Click the **"Export Comparison"** button
|
||||
2. A JSON file will be downloaded containing the complete comparison data
|
||||
3. This file can be used for analysis or backup purposes
|
||||
|
||||
## Migration Process Details
|
||||
|
||||
### Contact Migration
|
||||
|
||||
The contact migration process:
|
||||
|
||||
1. **Retrieves** all contacts from Dexie database
|
||||
2. **Checks** for existing contacts in SQLite by DID
|
||||
3. **Inserts** new contacts or **updates** existing ones (if overwrite is enabled)
|
||||
4. **Handles** complex fields like `contactMethods` (JSON arrays)
|
||||
5. **Reports** success/failure for each contact
|
||||
|
||||
### Settings Migration
|
||||
|
||||
The settings migration process:
|
||||
|
||||
1. **Retrieves** all settings from Dexie database
|
||||
2. **Focuses** on key user-facing settings:
|
||||
- `firstName`
|
||||
- `isRegistered`
|
||||
- `profileImageUrl`
|
||||
- `showShortcutBvc`
|
||||
- `searchBoxes`
|
||||
3. **Preserves** other settings in SQLite
|
||||
4. **Reports** success/failure for each setting
|
||||
|
||||
## Error Handling
|
||||
|
||||
### Common Issues
|
||||
|
||||
#### Dexie Database Not Enabled
|
||||
|
||||
**Error**: "Dexie database is not enabled"
|
||||
**Solution**: Set `USE_DEXIE_DB = true` in `constants/app.ts`
|
||||
|
||||
#### Database Connection Issues
|
||||
|
||||
**Error**: "Failed to retrieve Dexie contacts"
|
||||
**Solution**: Check that the Dexie database is properly initialized and accessible
|
||||
|
||||
#### SQLite Query Errors
|
||||
|
||||
**Error**: "Failed to retrieve SQLite contacts"
|
||||
**Solution**: Verify that the SQLite database is properly set up and the platform service is working
|
||||
|
||||
#### Migration Failures
|
||||
|
||||
**Error**: "Migration failed: [specific error]"
|
||||
**Solution**: Review the error details and check data integrity in both databases
|
||||
|
||||
### Error Recovery
|
||||
|
||||
1. **Review** the error messages carefully
|
||||
2. **Check** the browser console for additional details
|
||||
3. **Verify** database connectivity and permissions
|
||||
4. **Retry** the operation if appropriate
|
||||
5. **Export** comparison data for manual review if needed
|
||||
|
||||
## Best Practices
|
||||
|
||||
### Before Migration
|
||||
|
||||
1. **Backup** your data if possible
|
||||
2. **Test** the migration on a small dataset first
|
||||
3. **Verify** that both databases are accessible
|
||||
4. **Review** the comparison results before migrating
|
||||
|
||||
### During Migration
|
||||
|
||||
1. **Don't** interrupt the migration process
|
||||
2. **Monitor** the progress and error messages
|
||||
3. **Note** any warnings or skipped records
|
||||
4. **Export** comparison data for reference
|
||||
|
||||
### After Migration
|
||||
|
||||
1. **Verify** that data was migrated correctly
|
||||
2. **Test** the application functionality
|
||||
3. **Disable** Dexie database (`USE_DEXIE_DB = false`)
|
||||
4. **Clean up** any temporary files or exports
|
||||
|
||||
## Technical Details
|
||||
|
||||
### Database Schema
|
||||
|
||||
The migration handles the following data structures:
|
||||
|
||||
#### Contacts Table
|
||||
|
||||
```typescript
|
||||
interface Contact {
|
||||
did: string; // Decentralized Identifier
|
||||
name: string; // Contact name
|
||||
contactMethods: ContactMethod[]; // Array of contact methods
|
||||
nextPubKeyHashB64: string; // Next public key hash
|
||||
notes: string; // Contact notes
|
||||
profileImageUrl: string; // Profile image URL
|
||||
publicKeyBase64: string; // Public key in base64
|
||||
seesMe: boolean; // Visibility flag
|
||||
registered: boolean; // Registration status
|
||||
}
|
||||
```
|
||||
|
||||
#### Settings Table
|
||||
|
||||
```typescript
|
||||
interface Settings {
|
||||
id: number; // Settings ID
|
||||
accountDid: string; // Account DID
|
||||
activeDid: string; // Active DID
|
||||
firstName: string; // User's first name
|
||||
isRegistered: boolean; // Registration status
|
||||
profileImageUrl: string; // Profile image URL
|
||||
showShortcutBvc: boolean; // UI preference
|
||||
searchBoxes: any[]; // Search configuration
|
||||
// ... other fields
|
||||
}
|
||||
```
|
||||
|
||||
### Migration Logic
|
||||
|
||||
The migration service uses sophisticated comparison logic:
|
||||
|
||||
1. **Primary Key Matching**: Uses DID for contacts, ID for settings
|
||||
2. **Deep Comparison**: Compares all fields including complex objects
|
||||
3. **JSON Handling**: Properly handles JSON fields like `contactMethods` and `searchBoxes`
|
||||
4. **Conflict Resolution**: Provides options for handling existing records
|
||||
|
||||
### Performance Considerations
|
||||
|
||||
- **Batch Processing**: Processes records one by one for reliability
|
||||
- **Error Isolation**: Individual record failures don't stop the entire migration
|
||||
- **Memory Management**: Handles large datasets efficiently
|
||||
- **Progress Reporting**: Provides real-time feedback during migration
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Migration Stuck
|
||||
|
||||
If the migration appears to be stuck:
|
||||
|
||||
1. **Check** the browser console for errors
|
||||
2. **Refresh** the page and try again
|
||||
3. **Verify** database connectivity
|
||||
4. **Check** for large datasets that might take time
|
||||
|
||||
### Incomplete Migration
|
||||
|
||||
If migration doesn't complete:
|
||||
|
||||
1. **Review** error messages
|
||||
2. **Check** data integrity in both databases
|
||||
3. **Export** comparison data for manual review
|
||||
4. **Consider** migrating in smaller batches
|
||||
|
||||
### Data Inconsistencies
|
||||
|
||||
If you notice data inconsistencies:
|
||||
|
||||
1. **Export** comparison data
|
||||
2. **Review** the differences carefully
|
||||
3. **Manually** verify critical records
|
||||
4. **Consider** selective migration of specific records
|
||||
|
||||
## Support
|
||||
|
||||
For issues with the Database Migration feature:
|
||||
|
||||
1. **Check** this documentation first
|
||||
2. **Review** the browser console for error details
|
||||
3. **Export** comparison data for analysis
|
||||
4. **Contact** the development team with specific error details
|
||||
|
||||
## Security Considerations
|
||||
|
||||
- **Data Privacy**: Migration data is processed locally and not sent to external servers
|
||||
- **Access Control**: Only users with access to the account can perform migration
|
||||
- **Data Integrity**: Migration preserves data integrity and handles conflicts gracefully
|
||||
- **Audit Trail**: Export functionality provides an audit trail of migration operations
|
||||
|
||||
---
|
||||
|
||||
**Note**: This migration tool is designed for the transition period between database systems. Once migration is complete and verified, the Dexie database should be disabled to avoid confusion and potential data conflicts.
|
||||
@@ -3,7 +3,6 @@
|
||||
## Schema Mapping
|
||||
|
||||
### Current Dexie Schema
|
||||
|
||||
```typescript
|
||||
// Current Dexie schema
|
||||
const db = new Dexie('TimeSafariDB');
|
||||
@@ -16,7 +15,6 @@ db.version(1).stores({
|
||||
```
|
||||
|
||||
### New SQLite Schema
|
||||
|
||||
```sql
|
||||
-- New SQLite schema
|
||||
CREATE TABLE accounts (
|
||||
@@ -52,7 +50,6 @@ CREATE INDEX idx_settings_updated_at ON settings(updated_at);
|
||||
### 1. Account Operations
|
||||
|
||||
#### Get Account by DID
|
||||
|
||||
```typescript
|
||||
// Dexie
|
||||
const account = await db.accounts.get(did);
|
||||
@@ -65,7 +62,6 @@ const account = result[0]?.values[0];
|
||||
```
|
||||
|
||||
#### Get All Accounts
|
||||
|
||||
```typescript
|
||||
// Dexie
|
||||
const accounts = await db.accounts.toArray();
|
||||
@@ -78,7 +74,6 @@ const accounts = result[0]?.values || [];
|
||||
```
|
||||
|
||||
#### Add Account
|
||||
|
||||
```typescript
|
||||
// Dexie
|
||||
await db.accounts.add({
|
||||
@@ -96,7 +91,6 @@ await db.run(`
|
||||
```
|
||||
|
||||
#### Update Account
|
||||
|
||||
```typescript
|
||||
// Dexie
|
||||
await db.accounts.update(did, {
|
||||
@@ -106,7 +100,7 @@ await db.accounts.update(did, {
|
||||
|
||||
// absurd-sql
|
||||
await db.run(`
|
||||
UPDATE accounts
|
||||
UPDATE accounts
|
||||
SET public_key_hex = ?, updated_at = ?
|
||||
WHERE did = ?
|
||||
`, [publicKeyHex, Date.now(), did]);
|
||||
@@ -115,7 +109,6 @@ await db.run(`
|
||||
### 2. Settings Operations
|
||||
|
||||
#### Get Setting
|
||||
|
||||
```typescript
|
||||
// Dexie
|
||||
const setting = await db.settings.get(key);
|
||||
@@ -128,7 +121,6 @@ const setting = result[0]?.values[0];
|
||||
```
|
||||
|
||||
#### Set Setting
|
||||
|
||||
```typescript
|
||||
// Dexie
|
||||
await db.settings.put({
|
||||
@@ -150,7 +142,6 @@ await db.run(`
|
||||
### 3. Contact Operations
|
||||
|
||||
#### Get Contacts by Account
|
||||
|
||||
```typescript
|
||||
// Dexie
|
||||
const contacts = await db.contacts
|
||||
@@ -160,7 +151,7 @@ const contacts = await db.contacts
|
||||
|
||||
// absurd-sql
|
||||
const result = await db.exec(`
|
||||
SELECT * FROM contacts
|
||||
SELECT * FROM contacts
|
||||
WHERE did = ?
|
||||
ORDER BY created_at DESC
|
||||
`, [accountDid]);
|
||||
@@ -168,7 +159,6 @@ const contacts = result[0]?.values || [];
|
||||
```
|
||||
|
||||
#### Add Contact
|
||||
|
||||
```typescript
|
||||
// Dexie
|
||||
await db.contacts.add({
|
||||
@@ -189,7 +179,6 @@ await db.run(`
|
||||
## Transaction Mapping
|
||||
|
||||
### Batch Operations
|
||||
|
||||
```typescript
|
||||
// Dexie
|
||||
await db.transaction('rw', [db.accounts, db.contacts], async () => {
|
||||
@@ -221,11 +210,10 @@ try {
|
||||
## Migration Helper Functions
|
||||
|
||||
### 1. Data Export (Dexie to JSON)
|
||||
|
||||
```typescript
|
||||
async function exportDexieData(): Promise<MigrationData> {
|
||||
const db = new Dexie('TimeSafariDB');
|
||||
|
||||
|
||||
return {
|
||||
accounts: await db.accounts.toArray(),
|
||||
settings: await db.settings.toArray(),
|
||||
@@ -240,7 +228,6 @@ async function exportDexieData(): Promise<MigrationData> {
|
||||
```
|
||||
|
||||
### 2. Data Import (JSON to absurd-sql)
|
||||
|
||||
```typescript
|
||||
async function importToAbsurdSql(data: MigrationData): Promise<void> {
|
||||
await db.exec('BEGIN TRANSACTION;');
|
||||
@@ -252,7 +239,7 @@ async function importToAbsurdSql(data: MigrationData): Promise<void> {
|
||||
VALUES (?, ?, ?, ?)
|
||||
`, [account.did, account.publicKeyHex, account.createdAt, account.updatedAt]);
|
||||
}
|
||||
|
||||
|
||||
// Import settings
|
||||
for (const setting of data.settings) {
|
||||
await db.run(`
|
||||
@@ -260,7 +247,7 @@ async function importToAbsurdSql(data: MigrationData): Promise<void> {
|
||||
VALUES (?, ?, ?)
|
||||
`, [setting.key, setting.value, setting.updatedAt]);
|
||||
}
|
||||
|
||||
|
||||
// Import contacts
|
||||
for (const contact of data.contacts) {
|
||||
await db.run(`
|
||||
@@ -277,7 +264,6 @@ async function importToAbsurdSql(data: MigrationData): Promise<void> {
|
||||
```
|
||||
|
||||
### 3. Verification
|
||||
|
||||
```typescript
|
||||
async function verifyMigration(dexieData: MigrationData): Promise<boolean> {
|
||||
// Verify account count
|
||||
@@ -286,21 +272,21 @@ async function verifyMigration(dexieData: MigrationData): Promise<boolean> {
|
||||
if (accountCount !== dexieData.accounts.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Verify settings count
|
||||
const settingsResult = await db.exec('SELECT COUNT(*) as count FROM settings');
|
||||
const settingsCount = settingsResult[0].values[0][0];
|
||||
if (settingsCount !== dexieData.settings.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Verify contacts count
|
||||
const contactsResult = await db.exec('SELECT COUNT(*) as count FROM contacts');
|
||||
const contactsCount = contactsResult[0].values[0][0];
|
||||
if (contactsCount !== dexieData.contacts.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Verify data integrity
|
||||
for (const account of dexieData.accounts) {
|
||||
const result = await db.exec(
|
||||
@@ -308,12 +294,12 @@ async function verifyMigration(dexieData: MigrationData): Promise<boolean> {
|
||||
[account.did]
|
||||
);
|
||||
const migratedAccount = result[0]?.values[0];
|
||||
if (!migratedAccount ||
|
||||
if (!migratedAccount ||
|
||||
migratedAccount[1] !== account.publicKeyHex) { // public_key_hex is second column
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
```
|
||||
@@ -321,21 +307,18 @@ async function verifyMigration(dexieData: MigrationData): Promise<boolean> {
|
||||
## Performance Considerations
|
||||
|
||||
### 1. Indexing
|
||||
|
||||
- Dexie automatically creates indexes based on the schema
|
||||
- absurd-sql requires explicit index creation
|
||||
- Added indexes for frequently queried fields
|
||||
- Use `PRAGMA journal_mode=MEMORY;` for better performance
|
||||
|
||||
### 2. Batch Operations
|
||||
|
||||
- Dexie has built-in bulk operations
|
||||
- absurd-sql uses transactions for batch operations
|
||||
- Consider chunking large datasets
|
||||
- Use prepared statements for repeated queries
|
||||
|
||||
### 3. Query Optimization
|
||||
|
||||
- Dexie uses IndexedDB's native indexing
|
||||
- absurd-sql requires explicit query optimization
|
||||
- Use prepared statements for repeated queries
|
||||
@@ -344,7 +327,6 @@ async function verifyMigration(dexieData: MigrationData): Promise<boolean> {
|
||||
## Error Handling
|
||||
|
||||
### 1. Common Errors
|
||||
|
||||
```typescript
|
||||
// Dexie errors
|
||||
try {
|
||||
@@ -369,7 +351,6 @@ try {
|
||||
```
|
||||
|
||||
### 2. Transaction Recovery
|
||||
|
||||
```typescript
|
||||
// Dexie transaction
|
||||
try {
|
||||
@@ -415,4 +396,4 @@ try {
|
||||
- Remove Dexie database
|
||||
- Clear IndexedDB storage
|
||||
- Update application code
|
||||
- Remove old dependencies
|
||||
- Remove old dependencies
|
||||
@@ -1,272 +0,0 @@
|
||||
# Migration Fence Definition: Dexie to SQLite
|
||||
|
||||
## Overview
|
||||
|
||||
This document defines the **migration fence** - the boundary between the legacy Dexie (IndexedDB) storage system and the new SQLite-based storage system in TimeSafari. The fence ensures controlled migration while maintaining data integrity and application stability.
|
||||
|
||||
## Current Migration Status
|
||||
|
||||
### ✅ Completed Components
|
||||
- **SQLite Database Service**: Fully implemented with absurd-sql
|
||||
- **Platform Service Layer**: Unified database interface across platforms
|
||||
- **Migration Tools**: Data comparison and transfer utilities
|
||||
- **Schema Migration**: Complete table structure migration
|
||||
- **Data Export/Import**: Backup and restore functionality
|
||||
|
||||
### 🔄 Active Migration Components
|
||||
- **Settings Migration**: Core user settings transferred
|
||||
- **Account Migration**: Identity and key management
|
||||
- **Contact Migration**: User contact data (via import interface)
|
||||
|
||||
### ❌ Legacy Components (Fence Boundary)
|
||||
- **Dexie Database**: Legacy IndexedDB storage (disabled by default)
|
||||
- **Dexie-Specific Code**: Direct database access patterns
|
||||
- **Legacy Migration Paths**: Old data transfer methods
|
||||
|
||||
## Migration Fence Definition
|
||||
|
||||
### 1. Configuration Boundary
|
||||
|
||||
```typescript
|
||||
// src/constants/app.ts
|
||||
export const USE_DEXIE_DB = false; // FENCE: Controls legacy database access
|
||||
```
|
||||
|
||||
**Fence Rule**: When `USE_DEXIE_DB = false`:
|
||||
- All new data operations use SQLite
|
||||
- Legacy Dexie database is not initialized
|
||||
- Migration tools are the only path to legacy data
|
||||
|
||||
**Fence Rule**: When `USE_DEXIE_DB = true`:
|
||||
- Legacy database is available for migration
|
||||
- Dual-write operations may be enabled
|
||||
- Migration tools can access both databases
|
||||
|
||||
### 2. Service Layer Boundary
|
||||
|
||||
```typescript
|
||||
// src/services/PlatformServiceFactory.ts
|
||||
export class PlatformServiceFactory {
|
||||
public static getInstance(): PlatformService {
|
||||
// FENCE: All database operations go through platform service
|
||||
// No direct Dexie access outside migration tools
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Fence Rule**: All database operations must use:
|
||||
- `PlatformService.dbQuery()` for read operations
|
||||
- `PlatformService.dbExec()` for write operations
|
||||
- No direct `db.` or `accountsDBPromise` access in application code
|
||||
|
||||
### 3. Data Access Patterns
|
||||
|
||||
#### ✅ Allowed (Inside Fence)
|
||||
```typescript
|
||||
// Use platform service for all database operations
|
||||
const platformService = PlatformServiceFactory.getInstance();
|
||||
const contacts = await platformService.dbQuery(
|
||||
"SELECT * FROM contacts WHERE did = ?",
|
||||
[accountDid]
|
||||
);
|
||||
```
|
||||
|
||||
#### ❌ Forbidden (Outside Fence)
|
||||
```typescript
|
||||
// Direct Dexie access (legacy pattern)
|
||||
const contacts = await db.contacts.where('did').equals(accountDid).toArray();
|
||||
|
||||
// Direct database reference
|
||||
const result = await accountsDBPromise;
|
||||
```
|
||||
|
||||
### 4. Migration Tool Boundary
|
||||
|
||||
```typescript
|
||||
// src/services/indexedDBMigrationService.ts
|
||||
// FENCE: Only migration tools can access both databases
|
||||
export async function compareDatabases(): Promise<DataComparison> {
|
||||
// This is the ONLY place where both databases are accessed
|
||||
}
|
||||
```
|
||||
|
||||
**Fence Rule**: Migration tools are the exclusive interface between:
|
||||
- Legacy Dexie database
|
||||
- New SQLite database
|
||||
- Data comparison and transfer operations
|
||||
|
||||
## Migration Fence Guidelines
|
||||
|
||||
### 1. Code Development Rules
|
||||
|
||||
#### New Feature Development
|
||||
- **Always** use `PlatformService` for database operations
|
||||
- **Never** import or reference Dexie directly
|
||||
- **Always** test with `USE_DEXIE_DB = false`
|
||||
|
||||
#### Legacy Code Maintenance
|
||||
- **Only** modify Dexie code for migration purposes
|
||||
- **Always** add migration tests for schema changes
|
||||
- **Never** add new Dexie-specific features
|
||||
|
||||
### 2. Data Integrity Rules
|
||||
|
||||
#### Migration Safety
|
||||
- **Always** create backups before migration
|
||||
- **Always** verify data integrity after migration
|
||||
- **Never** delete legacy data until verified
|
||||
|
||||
#### Rollback Strategy
|
||||
- **Always** maintain ability to rollback to Dexie
|
||||
- **Always** preserve migration logs
|
||||
- **Never** assume migration is irreversible
|
||||
|
||||
### 3. Testing Requirements
|
||||
|
||||
#### Migration Testing
|
||||
```typescript
|
||||
// Required test pattern for migration
|
||||
describe('Database Migration', () => {
|
||||
it('should migrate data without loss', async () => {
|
||||
// 1. Enable Dexie
|
||||
// 2. Create test data
|
||||
// 3. Run migration
|
||||
// 4. Verify data integrity
|
||||
// 5. Disable Dexie
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
#### Application Testing
|
||||
```typescript
|
||||
// Required test pattern for application features
|
||||
describe('Feature with Database', () => {
|
||||
it('should work with SQLite only', async () => {
|
||||
// Test with USE_DEXIE_DB = false
|
||||
// Verify all operations use PlatformService
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
## Migration Fence Enforcement
|
||||
|
||||
### 1. Static Analysis
|
||||
|
||||
#### ESLint Rules
|
||||
```json
|
||||
{
|
||||
"rules": {
|
||||
"no-restricted-imports": [
|
||||
"error",
|
||||
{
|
||||
"patterns": [
|
||||
{
|
||||
"group": ["../db/index"],
|
||||
"message": "Use PlatformService instead of direct Dexie access"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### TypeScript Rules
|
||||
```json
|
||||
{
|
||||
"compilerOptions": {
|
||||
"strict": true,
|
||||
"noImplicitAny": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2. Runtime Checks
|
||||
|
||||
#### Development Mode Validation
|
||||
```typescript
|
||||
// Development-only fence validation
|
||||
if (import.meta.env.DEV && USE_DEXIE_DB) {
|
||||
console.warn('⚠️ Dexie is enabled - migration mode active');
|
||||
}
|
||||
```
|
||||
|
||||
#### Production Safety
|
||||
```typescript
|
||||
// Production fence enforcement
|
||||
if (import.meta.env.PROD && USE_DEXIE_DB) {
|
||||
throw new Error('Dexie cannot be enabled in production');
|
||||
}
|
||||
```
|
||||
|
||||
## Migration Fence Timeline
|
||||
|
||||
### Phase 1: Fence Establishment ✅
|
||||
- [x] Define migration fence boundaries
|
||||
- [x] Implement PlatformService layer
|
||||
- [x] Create migration tools
|
||||
- [x] Set `USE_DEXIE_DB = false` by default
|
||||
|
||||
### Phase 2: Data Migration 🔄
|
||||
- [x] Migrate core settings
|
||||
- [x] Migrate account data
|
||||
- [ ] Complete contact migration
|
||||
- [ ] Verify all data integrity
|
||||
|
||||
### Phase 3: Code Cleanup 📋
|
||||
- [ ] Remove unused Dexie imports
|
||||
- [ ] Clean up legacy database code
|
||||
- [ ] Update all documentation
|
||||
- [ ] Remove migration tools
|
||||
|
||||
### Phase 4: Fence Removal 🎯
|
||||
- [ ] Remove `USE_DEXIE_DB` constant
|
||||
- [ ] Remove Dexie dependencies
|
||||
- [ ] Remove migration service
|
||||
- [ ] Finalize SQLite-only architecture
|
||||
|
||||
## Security Considerations
|
||||
|
||||
### 1. Data Protection
|
||||
- **Encryption**: Maintain encryption standards across migration
|
||||
- **Access Control**: Preserve user privacy during migration
|
||||
- **Audit Trail**: Log all migration operations
|
||||
|
||||
### 2. Error Handling
|
||||
- **Graceful Degradation**: Handle migration failures gracefully
|
||||
- **User Communication**: Clear messaging about migration status
|
||||
- **Recovery Options**: Provide rollback mechanisms
|
||||
|
||||
## Performance Considerations
|
||||
|
||||
### 1. Migration Performance
|
||||
- **Batch Operations**: Use transactions for bulk data transfer
|
||||
- **Progress Indicators**: Show migration progress to users
|
||||
- **Background Processing**: Non-blocking migration operations
|
||||
|
||||
### 2. Application Performance
|
||||
- **Query Optimization**: Optimize SQLite queries for performance
|
||||
- **Indexing Strategy**: Maintain proper database indexes
|
||||
- **Memory Management**: Efficient memory usage during migration
|
||||
|
||||
## Documentation Requirements
|
||||
|
||||
### 1. Code Documentation
|
||||
- **Migration Fence Comments**: Document fence boundaries in code
|
||||
- **API Documentation**: Update all database API documentation
|
||||
- **Migration Guides**: Comprehensive migration documentation
|
||||
|
||||
### 2. User Documentation
|
||||
- **Migration Instructions**: Clear user migration steps
|
||||
- **Troubleshooting**: Common migration issues and solutions
|
||||
- **Rollback Instructions**: How to revert if needed
|
||||
|
||||
## Conclusion
|
||||
|
||||
The migration fence provides a controlled boundary between legacy and new database systems, ensuring:
|
||||
- **Data Integrity**: No data loss during migration
|
||||
- **Application Stability**: Consistent behavior across platforms
|
||||
- **Development Clarity**: Clear guidelines for code development
|
||||
- **Migration Safety**: Controlled and reversible migration process
|
||||
|
||||
This fence will remain in place until all data is successfully migrated and verified, at which point the legacy system can be safely removed.
|
||||
@@ -1,355 +0,0 @@
|
||||
# Database Migration Security Audit Checklist
|
||||
|
||||
## Overview
|
||||
|
||||
This document provides a comprehensive security audit checklist for the Dexie to SQLite migration in TimeSafari. The checklist ensures that data protection, privacy, and security are maintained throughout the migration process.
|
||||
|
||||
## Pre-Migration Security Assessment
|
||||
|
||||
### 1. Data Classification and Sensitivity
|
||||
|
||||
- [ ] **Data Inventory**
|
||||
- [ ] Identify all sensitive data types (DIDs, private keys, personal information)
|
||||
- [ ] Document data retention requirements
|
||||
- [ ] Map data relationships and dependencies
|
||||
- [ ] Assess data sensitivity levels (public, internal, confidential, restricted)
|
||||
|
||||
- [ ] **Encryption Assessment**
|
||||
- [ ] Verify current encryption methods for sensitive data
|
||||
- [ ] Document encryption keys and their management
|
||||
- [ ] Assess encryption strength and compliance
|
||||
- [ ] Plan encryption migration strategy
|
||||
|
||||
### 2. Access Control Review
|
||||
|
||||
- [ ] **User Access Rights**
|
||||
- [ ] Audit current user permissions and roles
|
||||
- [ ] Document access control mechanisms
|
||||
- [ ] Verify principle of least privilege
|
||||
- [ ] Plan access control migration
|
||||
|
||||
- [ ] **System Access**
|
||||
- [ ] Review database access patterns
|
||||
- [ ] Document authentication mechanisms
|
||||
- [ ] Assess session management
|
||||
- [ ] Plan authentication migration
|
||||
|
||||
### 3. Compliance Requirements
|
||||
|
||||
- [ ] **Regulatory Compliance**
|
||||
- [ ] Identify applicable regulations (GDPR, CCPA, etc.)
|
||||
- [ ] Document data processing requirements
|
||||
- [ ] Assess privacy impact
|
||||
- [ ] Plan compliance verification
|
||||
|
||||
- [ ] **Industry Standards**
|
||||
- [ ] Review security standards compliance
|
||||
- [ ] Document security controls
|
||||
- [ ] Assess audit requirements
|
||||
- [ ] Plan standards compliance
|
||||
|
||||
## Migration Security Controls
|
||||
|
||||
### 1. Data Protection During Migration
|
||||
|
||||
- [ ] **Encryption in Transit**
|
||||
- [ ] Verify all data transfers are encrypted
|
||||
- [ ] Use secure communication protocols (TLS 1.3+)
|
||||
- [ ] Implement secure API endpoints
|
||||
- [ ] Monitor encryption status
|
||||
|
||||
- [ ] **Encryption at Rest**
|
||||
- [ ] Maintain encryption for stored data
|
||||
- [ ] Verify encryption key management
|
||||
- [ ] Test encryption/decryption processes
|
||||
- [ ] Document encryption procedures
|
||||
|
||||
### 2. Access Control During Migration
|
||||
|
||||
- [ ] **Authentication**
|
||||
- [ ] Maintain user authentication during migration
|
||||
- [ ] Verify session management
|
||||
- [ ] Implement secure token handling
|
||||
- [ ] Monitor authentication events
|
||||
|
||||
- [ ] **Authorization**
|
||||
- [ ] Preserve user permissions during migration
|
||||
- [ ] Verify role-based access control
|
||||
- [ ] Implement audit logging
|
||||
- [ ] Monitor access patterns
|
||||
|
||||
### 3. Data Integrity
|
||||
|
||||
- [ ] **Data Validation**
|
||||
- [ ] Implement input validation for all data
|
||||
- [ ] Verify data format consistency
|
||||
- [ ] Test data transformation processes
|
||||
- [ ] Document validation rules
|
||||
|
||||
- [ ] **Data Verification**
|
||||
- [ ] Implement checksums for data integrity
|
||||
- [ ] Verify data completeness after migration
|
||||
- [ ] Test data consistency checks
|
||||
- [ ] Document verification procedures
|
||||
|
||||
## Migration Process Security
|
||||
|
||||
### 1. Backup Security
|
||||
|
||||
- [ ] **Backup Creation**
|
||||
- [ ] Create encrypted backups before migration
|
||||
- [ ] Verify backup integrity
|
||||
- [ ] Store backups securely
|
||||
- [ ] Test backup restoration
|
||||
|
||||
- [ ] **Backup Access**
|
||||
- [ ] Limit backup access to authorized personnel
|
||||
- [ ] Implement backup access logging
|
||||
- [ ] Verify backup encryption
|
||||
- [ ] Document backup procedures
|
||||
|
||||
### 2. Migration Tool Security
|
||||
|
||||
- [ ] **Tool Authentication**
|
||||
- [ ] Implement secure authentication for migration tools
|
||||
- [ ] Verify tool access controls
|
||||
- [ ] Monitor tool usage
|
||||
- [ ] Document tool security
|
||||
|
||||
- [ ] **Tool Validation**
|
||||
- [ ] Verify migration tool integrity
|
||||
- [ ] Test tool security features
|
||||
- [ ] Validate tool outputs
|
||||
- [ ] Document tool validation
|
||||
|
||||
### 3. Error Handling
|
||||
|
||||
- [ ] **Error Security**
|
||||
- [ ] Implement secure error handling
|
||||
- [ ] Avoid information disclosure in errors
|
||||
- [ ] Log security-relevant errors
|
||||
- [ ] Document error procedures
|
||||
|
||||
- [ ] **Recovery Security**
|
||||
- [ ] Implement secure recovery procedures
|
||||
- [ ] Verify recovery data protection
|
||||
- [ ] Test recovery processes
|
||||
- [ ] Document recovery security
|
||||
|
||||
## Post-Migration Security
|
||||
|
||||
### 1. Data Verification
|
||||
|
||||
- [ ] **Data Completeness**
|
||||
- [ ] Verify all data was migrated successfully
|
||||
- [ ] Check for data corruption
|
||||
- [ ] Validate data relationships
|
||||
- [ ] Document verification results
|
||||
|
||||
- [ ] **Data Accuracy**
|
||||
- [ ] Verify data accuracy after migration
|
||||
- [ ] Test data consistency
|
||||
- [ ] Validate data integrity
|
||||
- [ ] Document accuracy checks
|
||||
|
||||
### 2. Access Control Verification
|
||||
|
||||
- [ ] **User Access**
|
||||
- [ ] Verify user access rights after migration
|
||||
- [ ] Test authentication mechanisms
|
||||
- [ ] Validate authorization rules
|
||||
- [ ] Document access verification
|
||||
|
||||
- [ ] **System Access**
|
||||
- [ ] Verify system access controls
|
||||
- [ ] Test API security
|
||||
- [ ] Validate session management
|
||||
- [ ] Document system security
|
||||
|
||||
### 3. Security Testing
|
||||
|
||||
- [ ] **Penetration Testing**
|
||||
- [ ] Conduct security penetration testing
|
||||
- [ ] Test for common vulnerabilities
|
||||
- [ ] Verify security controls
|
||||
- [ ] Document test results
|
||||
|
||||
- [ ] **Vulnerability Assessment**
|
||||
- [ ] Scan for security vulnerabilities
|
||||
- [ ] Assess security posture
|
||||
- [ ] Identify security gaps
|
||||
- [ ] Document assessment results
|
||||
|
||||
## Monitoring and Logging
|
||||
|
||||
### 1. Security Monitoring
|
||||
|
||||
- [ ] **Access Monitoring**
|
||||
- [ ] Monitor database access patterns
|
||||
- [ ] Track user authentication events
|
||||
- [ ] Monitor system access
|
||||
- [ ] Document monitoring procedures
|
||||
|
||||
- [ ] **Data Monitoring**
|
||||
- [ ] Monitor data access patterns
|
||||
- [ ] Track data modification events
|
||||
- [ ] Monitor data integrity
|
||||
- [ ] Document data monitoring
|
||||
|
||||
### 2. Security Logging
|
||||
|
||||
- [ ] **Audit Logging**
|
||||
- [ ] Implement comprehensive audit logging
|
||||
- [ ] Log all security-relevant events
|
||||
- [ ] Secure log storage and access
|
||||
- [ ] Document logging procedures
|
||||
|
||||
- [ ] **Log Analysis**
|
||||
- [ ] Implement log analysis tools
|
||||
- [ ] Monitor for security incidents
|
||||
- [ ] Analyze security trends
|
||||
- [ ] Document analysis procedures
|
||||
|
||||
## Incident Response
|
||||
|
||||
### 1. Security Incident Planning
|
||||
|
||||
- [ ] **Incident Response Plan**
|
||||
- [ ] Develop security incident response plan
|
||||
- [ ] Define incident response procedures
|
||||
- [ ] Train incident response team
|
||||
- [ ] Document response procedures
|
||||
|
||||
- [ ] **Incident Detection**
|
||||
- [ ] Implement incident detection mechanisms
|
||||
- [ ] Monitor for security incidents
|
||||
- [ ] Establish incident reporting procedures
|
||||
- [ ] Document detection procedures
|
||||
|
||||
### 2. Recovery Procedures
|
||||
|
||||
- [ ] **Data Recovery**
|
||||
- [ ] Develop data recovery procedures
|
||||
- [ ] Test recovery processes
|
||||
- [ ] Verify recovery data integrity
|
||||
- [ ] Document recovery procedures
|
||||
|
||||
- [ ] **System Recovery**
|
||||
- [ ] Develop system recovery procedures
|
||||
- [ ] Test system recovery
|
||||
- [ ] Verify system security after recovery
|
||||
- [ ] Document recovery procedures
|
||||
|
||||
## Compliance Verification
|
||||
|
||||
### 1. Regulatory Compliance
|
||||
|
||||
- [ ] **Privacy Compliance**
|
||||
- [ ] Verify GDPR compliance
|
||||
- [ ] Check CCPA compliance
|
||||
- [ ] Assess other privacy regulations
|
||||
- [ ] Document compliance status
|
||||
|
||||
- [ ] **Security Compliance**
|
||||
- [ ] Verify security standard compliance
|
||||
- [ ] Check industry requirements
|
||||
- [ ] Assess security certifications
|
||||
- [ ] Document compliance status
|
||||
|
||||
### 2. Audit Requirements
|
||||
|
||||
- [ ] **Audit Trail**
|
||||
- [ ] Maintain comprehensive audit trail
|
||||
- [ ] Verify audit log integrity
|
||||
- [ ] Test audit log accessibility
|
||||
- [ ] Document audit procedures
|
||||
|
||||
- [ ] **Audit Reporting**
|
||||
- [ ] Generate audit reports
|
||||
- [ ] Verify report accuracy
|
||||
- [ ] Distribute reports securely
|
||||
- [ ] Document reporting procedures
|
||||
|
||||
## Documentation and Training
|
||||
|
||||
### 1. Security Documentation
|
||||
|
||||
- [ ] **Security Procedures**
|
||||
- [ ] Document security procedures
|
||||
- [ ] Update security policies
|
||||
- [ ] Create security guidelines
|
||||
- [ ] Maintain documentation
|
||||
|
||||
- [ ] **Security Training**
|
||||
- [ ] Develop security training materials
|
||||
- [ ] Train staff on security procedures
|
||||
- [ ] Verify training effectiveness
|
||||
- [ ] Document training procedures
|
||||
|
||||
### 2. Ongoing Security
|
||||
|
||||
- [ ] **Security Maintenance**
|
||||
- [ ] Establish security maintenance procedures
|
||||
- [ ] Schedule security updates
|
||||
- [ ] Monitor security trends
|
||||
- [ ] Document maintenance procedures
|
||||
|
||||
- [ ] **Security Review**
|
||||
- [ ] Conduct regular security reviews
|
||||
- [ ] Update security controls
|
||||
- [ ] Assess security effectiveness
|
||||
- [ ] Document review procedures
|
||||
|
||||
## Risk Assessment
|
||||
|
||||
### 1. Risk Identification
|
||||
|
||||
- [ ] **Security Risks**
|
||||
- [ ] Identify potential security risks
|
||||
- [ ] Assess risk likelihood and impact
|
||||
- [ ] Prioritize security risks
|
||||
- [ ] Document risk assessment
|
||||
|
||||
- [ ] **Mitigation Strategies**
|
||||
- [ ] Develop risk mitigation strategies
|
||||
- [ ] Implement risk controls
|
||||
- [ ] Monitor risk status
|
||||
- [ ] Document mitigation procedures
|
||||
|
||||
### 2. Risk Monitoring
|
||||
|
||||
- [ ] **Risk Tracking**
|
||||
- [ ] Track identified risks
|
||||
- [ ] Monitor risk status
|
||||
- [ ] Update risk assessments
|
||||
- [ ] Document risk tracking
|
||||
|
||||
- [ ] **Risk Reporting**
|
||||
- [ ] Generate risk reports
|
||||
- [ ] Distribute risk information
|
||||
- [ ] Update risk documentation
|
||||
- [ ] Document reporting procedures
|
||||
|
||||
## Conclusion
|
||||
|
||||
This security audit checklist ensures that the database migration maintains the highest standards of data protection, privacy, and security. Regular review and updates of this checklist are essential to maintain security throughout the migration process and beyond.
|
||||
|
||||
### Security Checklist Summary
|
||||
|
||||
- [ ] **Pre-Migration Assessment**: Complete
|
||||
- [ ] **Migration Controls**: Complete
|
||||
- [ ] **Process Security**: Complete
|
||||
- [ ] **Post-Migration Verification**: Complete
|
||||
- [ ] **Monitoring and Logging**: Complete
|
||||
- [ ] **Incident Response**: Complete
|
||||
- [ ] **Compliance Verification**: Complete
|
||||
- [ ] **Documentation and Training**: Complete
|
||||
- [ ] **Risk Assessment**: Complete
|
||||
|
||||
**Overall Security Status**: [ ] Secure [ ] Needs Attention [ ] Critical Issues
|
||||
|
||||
**Next Review Date**: _______________
|
||||
|
||||
**Reviewed By**: _______________
|
||||
|
||||
**Approved By**: _______________
|
||||
@@ -4,223 +4,610 @@
|
||||
|
||||
This document outlines the migration process from Dexie.js to absurd-sql for the TimeSafari app's storage implementation. The migration aims to provide a consistent SQLite-based storage solution across all platforms while maintaining data integrity and ensuring a smooth transition for users.
|
||||
|
||||
**Current Status**: The migration is in **Phase 2** with a well-defined migration fence in place. Core settings and account data have been migrated, with contact migration in progress. **ActiveDid migration has been implemented** to ensure user identity continuity.
|
||||
|
||||
## Migration Goals
|
||||
|
||||
1. **Data Integrity**
|
||||
- Preserve all existing data
|
||||
- Maintain data relationships
|
||||
- Ensure data consistency
|
||||
- **Preserve user's active identity**
|
||||
|
||||
2. **Performance**
|
||||
- Improve query performance
|
||||
- Reduce storage overhead
|
||||
- Optimize for platform-specific capabilities
|
||||
- Optimize for platform-specific features
|
||||
|
||||
3. **User Experience**
|
||||
- Seamless transition with no data loss
|
||||
- Maintain user's active identity and preferences
|
||||
- Preserve application state
|
||||
3. **Security**
|
||||
- Maintain or improve encryption
|
||||
- Preserve access controls
|
||||
- Enhance data protection
|
||||
|
||||
## Migration Architecture
|
||||
4. **User Experience**
|
||||
- Zero data loss
|
||||
- Minimal downtime
|
||||
- Automatic migration where possible
|
||||
|
||||
### Migration Fence
|
||||
The migration fence is defined by the `USE_DEXIE_DB` constant in `src/constants/app.ts`:
|
||||
- `USE_DEXIE_DB = false` (default): Uses SQLite database
|
||||
- `USE_DEXIE_DB = true`: Uses Dexie database (for migration purposes)
|
||||
## Prerequisites
|
||||
|
||||
### Migration Order
|
||||
The migration follows a specific order to maintain data integrity:
|
||||
|
||||
1. **Accounts** (foundational - contains DIDs)
|
||||
2. **Settings** (references accountDid, activeDid)
|
||||
3. **ActiveDid** (depends on accounts and settings) ⭐ **NEW**
|
||||
4. **Contacts** (independent, but migrated after accounts for consistency)
|
||||
|
||||
## ActiveDid Migration ⭐ **NEW FEATURE**
|
||||
|
||||
### Problem Solved
|
||||
Previously, the `activeDid` setting was not migrated from Dexie to SQLite, causing users to lose their active identity after migration.
|
||||
|
||||
### Solution Implemented
|
||||
The migration now includes a dedicated step for migrating the `activeDid`:
|
||||
|
||||
1. **Detection**: Identifies the `activeDid` from Dexie master settings
|
||||
2. **Validation**: Verifies the `activeDid` exists in SQLite accounts
|
||||
3. **Migration**: Updates SQLite master settings with the `activeDid`
|
||||
4. **Error Handling**: Graceful handling of missing accounts
|
||||
|
||||
### Implementation Details
|
||||
|
||||
#### New Function: `migrateActiveDid()`
|
||||
```typescript
|
||||
export async function migrateActiveDid(): Promise<MigrationResult> {
|
||||
// 1. Get Dexie settings to find the activeDid
|
||||
const dexieSettings = await getDexieSettings();
|
||||
const masterSettings = dexieSettings.find(setting => !setting.accountDid);
|
||||
|
||||
// 2. Verify the activeDid exists in SQLite accounts
|
||||
const accountExists = await platformService.dbQuery(
|
||||
"SELECT did FROM accounts WHERE did = ?",
|
||||
[dexieActiveDid],
|
||||
);
|
||||
|
||||
// 3. Update SQLite master settings
|
||||
await updateDefaultSettings({ activeDid: dexieActiveDid });
|
||||
1. **Backup Requirements**
|
||||
```typescript
|
||||
interface MigrationBackup {
|
||||
timestamp: number;
|
||||
accounts: Account[];
|
||||
settings: Setting[];
|
||||
contacts: Contact[];
|
||||
metadata: {
|
||||
version: string;
|
||||
platform: string;
|
||||
dexieVersion: string;
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
#### Enhanced `migrateSettings()` Function
|
||||
The settings migration now includes activeDid handling:
|
||||
- Extracts `activeDid` from Dexie master settings
|
||||
- Validates account existence in SQLite
|
||||
- Updates SQLite master settings with the `activeDid`
|
||||
2. **Dependencies**
|
||||
```json
|
||||
{
|
||||
"@jlongster/sql.js": "^1.8.0",
|
||||
"absurd-sql": "^1.8.0"
|
||||
}
|
||||
```
|
||||
|
||||
#### Updated `migrateAll()` Function
|
||||
The complete migration now includes a dedicated step for activeDid:
|
||||
```typescript
|
||||
// Step 3: Migrate ActiveDid (depends on accounts and settings)
|
||||
logger.info("[MigrationService] Step 3: Migrating activeDid...");
|
||||
const activeDidResult = await migrateActiveDid();
|
||||
```
|
||||
3. **Storage Requirements**
|
||||
- Sufficient IndexedDB quota
|
||||
- Available disk space for SQLite
|
||||
- Backup storage space
|
||||
|
||||
### Benefits
|
||||
- ✅ **User Identity Preservation**: Users maintain their active identity
|
||||
- ✅ **Seamless Experience**: No need to manually select identity after migration
|
||||
- ✅ **Data Consistency**: Ensures all identity-related settings are preserved
|
||||
- ✅ **Error Resilience**: Graceful handling of edge cases
|
||||
4. **Platform Support**
|
||||
- Web: Modern browser with IndexedDB support
|
||||
- iOS: iOS 13+ with SQLite support
|
||||
- Android: Android 5+ with SQLite support
|
||||
- Electron: Latest version with SQLite support
|
||||
|
||||
## Migration Process
|
||||
|
||||
### Phase 1: Preparation ✅
|
||||
- [x] Enable Dexie database access
|
||||
- [x] Implement data comparison tools
|
||||
- [x] Create migration service structure
|
||||
### 1. Preparation
|
||||
|
||||
### Phase 2: Core Migration ✅
|
||||
- [x] Account migration with `importFromMnemonic`
|
||||
- [x] Settings migration (excluding activeDid)
|
||||
- [x] **ActiveDid migration** ⭐ **COMPLETED**
|
||||
- [x] Contact migration framework
|
||||
|
||||
### Phase 3: Validation and Cleanup 🔄
|
||||
- [ ] Comprehensive data validation
|
||||
- [ ] Performance testing
|
||||
- [ ] User acceptance testing
|
||||
- [ ] Dexie removal
|
||||
|
||||
## Usage
|
||||
|
||||
### Manual Migration
|
||||
```typescript
|
||||
import { migrateAll, migrateActiveDid } from '../services/indexedDBMigrationService';
|
||||
// src/services/storage/migration/MigrationService.ts
|
||||
import initSqlJs from '@jlongster/sql.js';
|
||||
import { SQLiteFS } from 'absurd-sql';
|
||||
import IndexedDBBackend from 'absurd-sql/dist/indexeddb-backend';
|
||||
|
||||
// Complete migration
|
||||
const result = await migrateAll();
|
||||
export class MigrationService {
|
||||
private static instance: MigrationService;
|
||||
private backup: MigrationBackup | null = null;
|
||||
private sql: any = null;
|
||||
private db: any = null;
|
||||
|
||||
// Or migrate just the activeDid
|
||||
const activeDidResult = await migrateActiveDid();
|
||||
async prepare(): Promise<void> {
|
||||
try {
|
||||
// 1. Check prerequisites
|
||||
await this.checkPrerequisites();
|
||||
|
||||
// 2. Create backup
|
||||
this.backup = await this.createBackup();
|
||||
|
||||
// 3. Verify backup integrity
|
||||
await this.verifyBackup();
|
||||
|
||||
// 4. Initialize absurd-sql
|
||||
await this.initializeAbsurdSql();
|
||||
} catch (error) {
|
||||
throw new StorageError(
|
||||
'Migration preparation failed',
|
||||
StorageErrorCodes.MIGRATION_FAILED,
|
||||
error
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private async initializeAbsurdSql(): Promise<void> {
|
||||
// Initialize SQL.js
|
||||
this.sql = await initSqlJs({
|
||||
locateFile: (file: string) => {
|
||||
return new URL(`/node_modules/@jlongster/sql.js/dist/${file}`, import.meta.url).href;
|
||||
}
|
||||
});
|
||||
|
||||
// Setup SQLiteFS with IndexedDB backend
|
||||
const sqlFS = new SQLiteFS(this.sql.FS, new IndexedDBBackend());
|
||||
this.sql.register_for_idb(sqlFS);
|
||||
|
||||
// Create and mount filesystem
|
||||
this.sql.FS.mkdir('/sql');
|
||||
this.sql.FS.mount(sqlFS, {}, '/sql');
|
||||
|
||||
// Open database
|
||||
const path = '/sql/db.sqlite';
|
||||
if (typeof SharedArrayBuffer === 'undefined') {
|
||||
let stream = this.sql.FS.open(path, 'a+');
|
||||
await stream.node.contents.readIfFallback();
|
||||
this.sql.FS.close(stream);
|
||||
}
|
||||
|
||||
this.db = new this.sql.Database(path, { filename: true });
|
||||
if (!this.db) {
|
||||
throw new StorageError(
|
||||
'Database initialization failed',
|
||||
StorageErrorCodes.INITIALIZATION_FAILED
|
||||
);
|
||||
}
|
||||
|
||||
// Configure database
|
||||
await this.db.exec(`PRAGMA journal_mode=MEMORY;`);
|
||||
}
|
||||
|
||||
private async checkPrerequisites(): Promise<void> {
|
||||
// Check IndexedDB availability
|
||||
if (!window.indexedDB) {
|
||||
throw new StorageError(
|
||||
'IndexedDB not available',
|
||||
StorageErrorCodes.INITIALIZATION_FAILED
|
||||
);
|
||||
}
|
||||
|
||||
// Check storage quota
|
||||
const quota = await navigator.storage.estimate();
|
||||
if (quota.quota && quota.usage && quota.usage > quota.quota * 0.9) {
|
||||
throw new StorageError(
|
||||
'Insufficient storage space',
|
||||
StorageErrorCodes.STORAGE_FULL
|
||||
);
|
||||
}
|
||||
|
||||
// Check platform support
|
||||
const capabilities = await PlatformDetection.getCapabilities();
|
||||
if (!capabilities.hasFileSystem) {
|
||||
throw new StorageError(
|
||||
'Platform does not support required features',
|
||||
StorageErrorCodes.INITIALIZATION_FAILED
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private async createBackup(): Promise<MigrationBackup> {
|
||||
const dexieDB = new Dexie('TimeSafariDB');
|
||||
|
||||
return {
|
||||
timestamp: Date.now(),
|
||||
accounts: await dexieDB.accounts.toArray(),
|
||||
settings: await dexieDB.settings.toArray(),
|
||||
contacts: await dexieDB.contacts.toArray(),
|
||||
metadata: {
|
||||
version: '1.0.0',
|
||||
platform: await PlatformDetection.getPlatform(),
|
||||
dexieVersion: Dexie.version
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Migration Verification
|
||||
### 2. Data Migration
|
||||
|
||||
```typescript
|
||||
import { compareDatabases } from '../services/indexedDBMigrationService';
|
||||
// src/services/storage/migration/DataMigration.ts
|
||||
export class DataMigration {
|
||||
async migrate(backup: MigrationBackup): Promise<void> {
|
||||
try {
|
||||
// 1. Create new database schema
|
||||
await this.createSchema();
|
||||
|
||||
// 2. Migrate accounts
|
||||
await this.migrateAccounts(backup.accounts);
|
||||
|
||||
// 3. Migrate settings
|
||||
await this.migrateSettings(backup.settings);
|
||||
|
||||
// 4. Migrate contacts
|
||||
await this.migrateContacts(backup.contacts);
|
||||
|
||||
// 5. Verify migration
|
||||
await this.verifyMigration(backup);
|
||||
} catch (error) {
|
||||
// 6. Handle failure
|
||||
await this.handleMigrationFailure(error, backup);
|
||||
}
|
||||
}
|
||||
|
||||
const comparison = await compareDatabases();
|
||||
console.log('Migration differences:', comparison.differences);
|
||||
private async migrateAccounts(accounts: Account[]): Promise<void> {
|
||||
// Use transaction for atomicity
|
||||
await this.db.exec('BEGIN TRANSACTION;');
|
||||
try {
|
||||
for (const account of accounts) {
|
||||
await this.db.run(`
|
||||
INSERT INTO accounts (did, public_key_hex, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?)
|
||||
`, [
|
||||
account.did,
|
||||
account.publicKeyHex,
|
||||
account.createdAt,
|
||||
account.updatedAt
|
||||
]);
|
||||
}
|
||||
await this.db.exec('COMMIT;');
|
||||
} catch (error) {
|
||||
await this.db.exec('ROLLBACK;');
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
private async verifyMigration(backup: MigrationBackup): Promise<void> {
|
||||
// Verify account count
|
||||
const result = await this.db.exec('SELECT COUNT(*) as count FROM accounts');
|
||||
const accountCount = result[0].values[0][0];
|
||||
|
||||
if (accountCount !== backup.accounts.length) {
|
||||
throw new StorageError(
|
||||
'Account count mismatch',
|
||||
StorageErrorCodes.VERIFICATION_FAILED
|
||||
);
|
||||
}
|
||||
|
||||
// Verify data integrity
|
||||
await this.verifyDataIntegrity(backup);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
### 3. Rollback Strategy
|
||||
|
||||
### ActiveDid Migration Errors
|
||||
- **Missing Account**: If the `activeDid` from Dexie doesn't exist in SQLite accounts
|
||||
- **Database Errors**: Connection or query failures
|
||||
- **Settings Update Failures**: Issues updating SQLite master settings
|
||||
```typescript
|
||||
// src/services/storage/migration/RollbackService.ts
|
||||
export class RollbackService {
|
||||
async rollback(backup: MigrationBackup): Promise<void> {
|
||||
try {
|
||||
// 1. Stop all database operations
|
||||
await this.stopDatabaseOperations();
|
||||
|
||||
// 2. Restore from backup
|
||||
await this.restoreFromBackup(backup);
|
||||
|
||||
// 3. Verify restoration
|
||||
await this.verifyRestoration(backup);
|
||||
|
||||
// 4. Clean up absurd-sql
|
||||
await this.cleanupAbsurdSql();
|
||||
} catch (error) {
|
||||
throw new StorageError(
|
||||
'Rollback failed',
|
||||
StorageErrorCodes.ROLLBACK_FAILED,
|
||||
error
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
### Recovery Strategies
|
||||
1. **Automatic Recovery**: Migration continues even if activeDid migration fails
|
||||
2. **Manual Recovery**: Users can manually select their identity after migration
|
||||
3. **Fallback**: System creates new identity if none exists
|
||||
|
||||
## Security Considerations
|
||||
|
||||
### Data Protection
|
||||
- All sensitive data (mnemonics, private keys) are encrypted
|
||||
- Migration preserves encryption standards
|
||||
- No plaintext data exposure during migration
|
||||
|
||||
### Identity Verification
|
||||
- ActiveDid migration validates account existence
|
||||
- Prevents setting non-existent identities as active
|
||||
- Maintains cryptographic integrity
|
||||
|
||||
## Testing
|
||||
|
||||
### Migration Testing
|
||||
```bash
|
||||
# Enable Dexie for testing
|
||||
# Set USE_DEXIE_DB = true in constants/app.ts
|
||||
|
||||
# Run migration
|
||||
npm run migrate
|
||||
|
||||
# Verify results
|
||||
npm run test:migration
|
||||
private async restoreFromBackup(backup: MigrationBackup): Promise<void> {
|
||||
const dexieDB = new Dexie('TimeSafariDB');
|
||||
|
||||
// Restore accounts
|
||||
await dexieDB.accounts.bulkPut(backup.accounts);
|
||||
|
||||
// Restore settings
|
||||
await dexieDB.settings.bulkPut(backup.settings);
|
||||
|
||||
// Restore contacts
|
||||
await dexieDB.contacts.bulkPut(backup.contacts);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### ActiveDid Testing
|
||||
## Migration UI
|
||||
|
||||
```vue
|
||||
<!-- src/components/MigrationProgress.vue -->
|
||||
<template>
|
||||
<div class="migration-progress">
|
||||
<h2>Database Migration</h2>
|
||||
|
||||
<div class="progress-container">
|
||||
<div class="progress-bar" :style="{ width: `${progress}%` }" />
|
||||
<div class="progress-text">{{ progress }}%</div>
|
||||
</div>
|
||||
|
||||
<div class="status-message">{{ statusMessage }}</div>
|
||||
|
||||
<div v-if="error" class="error-message">
|
||||
{{ error }}
|
||||
<button @click="retryMigration">Retry</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue';
|
||||
import { MigrationService } from '@/services/storage/migration/MigrationService';
|
||||
|
||||
const progress = ref(0);
|
||||
const statusMessage = ref('Preparing migration...');
|
||||
const error = ref<string | null>(null);
|
||||
|
||||
const migrationService = MigrationService.getInstance();
|
||||
|
||||
async function startMigration() {
|
||||
try {
|
||||
// 1. Preparation
|
||||
statusMessage.value = 'Creating backup...';
|
||||
await migrationService.prepare();
|
||||
progress.value = 20;
|
||||
|
||||
// 2. Data migration
|
||||
statusMessage.value = 'Migrating data...';
|
||||
await migrationService.migrate();
|
||||
progress.value = 80;
|
||||
|
||||
// 3. Verification
|
||||
statusMessage.value = 'Verifying migration...';
|
||||
await migrationService.verify();
|
||||
progress.value = 100;
|
||||
|
||||
statusMessage.value = 'Migration completed successfully!';
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : 'Migration failed';
|
||||
statusMessage.value = 'Migration failed';
|
||||
}
|
||||
}
|
||||
|
||||
async function retryMigration() {
|
||||
error.value = null;
|
||||
progress.value = 0;
|
||||
await startMigration();
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
startMigration();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.migration-progress {
|
||||
padding: 2rem;
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.progress-container {
|
||||
position: relative;
|
||||
height: 20px;
|
||||
background: #eee;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
margin: 1rem 0;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
position: absolute;
|
||||
height: 100%;
|
||||
background: #4CAF50;
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
|
||||
.progress-text {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
line-height: 20px;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.status-message {
|
||||
text-align: center;
|
||||
margin: 1rem 0;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
color: #f44336;
|
||||
text-align: center;
|
||||
margin: 1rem 0;
|
||||
}
|
||||
|
||||
button {
|
||||
margin-top: 1rem;
|
||||
padding: 0.5rem 1rem;
|
||||
background: #2196F3;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background: #1976D2;
|
||||
}
|
||||
</style>
|
||||
```
|
||||
|
||||
## Testing Strategy
|
||||
|
||||
1. **Unit Tests**
|
||||
```typescript
|
||||
// Test activeDid migration specifically
|
||||
const result = await migrateActiveDid();
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.warnings).toContain('Successfully migrated activeDid');
|
||||
```
|
||||
// src/services/storage/migration/__tests__/MigrationService.spec.ts
|
||||
describe('MigrationService', () => {
|
||||
it('should initialize absurd-sql correctly', async () => {
|
||||
const service = MigrationService.getInstance();
|
||||
await service.initializeAbsurdSql();
|
||||
|
||||
expect(service.isInitialized()).toBe(true);
|
||||
expect(service.getDatabase()).toBeDefined();
|
||||
});
|
||||
|
||||
## Troubleshooting
|
||||
it('should create valid backup', async () => {
|
||||
const service = MigrationService.getInstance();
|
||||
const backup = await service.createBackup();
|
||||
|
||||
expect(backup).toBeDefined();
|
||||
expect(backup.accounts).toBeInstanceOf(Array);
|
||||
expect(backup.settings).toBeInstanceOf(Array);
|
||||
expect(backup.contacts).toBeInstanceOf(Array);
|
||||
});
|
||||
|
||||
### Common Issues
|
||||
it('should migrate data correctly', async () => {
|
||||
const service = MigrationService.getInstance();
|
||||
const backup = await service.createBackup();
|
||||
|
||||
await service.migrate(backup);
|
||||
|
||||
// Verify migration
|
||||
const accounts = await service.getMigratedAccounts();
|
||||
expect(accounts).toHaveLength(backup.accounts.length);
|
||||
});
|
||||
|
||||
1. **ActiveDid Not Found**
|
||||
- Ensure accounts were migrated before activeDid migration
|
||||
- Check that the Dexie activeDid exists in SQLite accounts
|
||||
|
||||
2. **Migration Failures**
|
||||
- Verify Dexie database is accessible
|
||||
- Check SQLite database permissions
|
||||
- Review migration logs for specific errors
|
||||
|
||||
3. **Data Inconsistencies**
|
||||
- Use `compareDatabases()` to identify differences
|
||||
- Re-run migration if necessary
|
||||
- Check for duplicate or conflicting records
|
||||
|
||||
### Debugging
|
||||
```typescript
|
||||
// Enable detailed logging
|
||||
logger.setLevel('debug');
|
||||
|
||||
// Check migration status
|
||||
const comparison = await compareDatabases();
|
||||
console.log('Settings differences:', comparison.differences.settings);
|
||||
it('should handle rollback correctly', async () => {
|
||||
const service = MigrationService.getInstance();
|
||||
const backup = await service.createBackup();
|
||||
|
||||
// Simulate failed migration
|
||||
await service.migrate(backup);
|
||||
await service.simulateFailure();
|
||||
|
||||
// Perform rollback
|
||||
await service.rollback(backup);
|
||||
|
||||
// Verify rollback
|
||||
const accounts = await service.getOriginalAccounts();
|
||||
expect(accounts).toHaveLength(backup.accounts.length);
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
## Future Enhancements
|
||||
2. **Integration Tests**
|
||||
```typescript
|
||||
// src/services/storage/migration/__tests__/integration/Migration.spec.ts
|
||||
describe('Migration Integration', () => {
|
||||
it('should handle concurrent access during migration', async () => {
|
||||
const service = MigrationService.getInstance();
|
||||
|
||||
// Start migration
|
||||
const migrationPromise = service.migrate();
|
||||
|
||||
// Simulate concurrent access
|
||||
const accessPromises = Array(5).fill(null).map(() =>
|
||||
service.getAccount('did:test:123')
|
||||
);
|
||||
|
||||
// Wait for all operations
|
||||
const [migrationResult, ...accessResults] = await Promise.allSettled([
|
||||
migrationPromise,
|
||||
...accessPromises
|
||||
]);
|
||||
|
||||
// Verify results
|
||||
expect(migrationResult.status).toBe('fulfilled');
|
||||
expect(accessResults.some(r => r.status === 'rejected')).toBe(true);
|
||||
});
|
||||
|
||||
### Planned Improvements
|
||||
1. **Batch Processing**: Optimize for large datasets
|
||||
2. **Incremental Migration**: Support partial migrations
|
||||
3. **Rollback Capability**: Ability to revert migration
|
||||
4. **Progress Tracking**: Real-time migration progress
|
||||
it('should maintain data integrity during platform transition', async () => {
|
||||
const service = MigrationService.getInstance();
|
||||
|
||||
// Simulate platform change
|
||||
await service.simulatePlatformChange();
|
||||
|
||||
// Verify data
|
||||
const accounts = await service.getAllAccounts();
|
||||
const settings = await service.getAllSettings();
|
||||
const contacts = await service.getAllContacts();
|
||||
|
||||
expect(accounts).toBeDefined();
|
||||
expect(settings).toBeDefined();
|
||||
expect(contacts).toBeDefined();
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
### Performance Optimizations
|
||||
1. **Parallel Processing**: Migrate independent data concurrently
|
||||
2. **Memory Management**: Optimize for large datasets
|
||||
3. **Transaction Batching**: Reduce database round trips
|
||||
## Success Criteria
|
||||
|
||||
## Conclusion
|
||||
1. **Data Integrity**
|
||||
- [ ] All accounts migrated successfully
|
||||
- [ ] All settings preserved
|
||||
- [ ] All contacts transferred
|
||||
- [ ] No data corruption
|
||||
|
||||
The Dexie to SQLite migration provides a robust, secure, and user-friendly transition path. The addition of activeDid migration ensures that users maintain their identity continuity throughout the migration process, significantly improving the user experience.
|
||||
2. **Performance**
|
||||
- [ ] Migration completes within acceptable time
|
||||
- [ ] No significant performance degradation
|
||||
- [ ] Efficient storage usage
|
||||
- [ ] Smooth user experience
|
||||
|
||||
The migration fence architecture allows for controlled, reversible migration while maintaining application stability and data integrity.
|
||||
3. **Security**
|
||||
- [ ] Encrypted data remains secure
|
||||
- [ ] Access controls maintained
|
||||
- [ ] No sensitive data exposure
|
||||
- [ ] Secure backup process
|
||||
|
||||
4. **User Experience**
|
||||
- [ ] Clear migration progress
|
||||
- [ ] Informative error messages
|
||||
- [ ] Automatic recovery from failures
|
||||
- [ ] No data loss
|
||||
|
||||
## Rollback Plan
|
||||
|
||||
1. **Automatic Rollback**
|
||||
- Triggered by migration failure
|
||||
- Restores from verified backup
|
||||
- Maintains data consistency
|
||||
- Logs rollback reason
|
||||
|
||||
2. **Manual Rollback**
|
||||
- Available through settings
|
||||
- Requires user confirmation
|
||||
- Preserves backup data
|
||||
- Provides rollback status
|
||||
|
||||
3. **Emergency Recovery**
|
||||
- Manual backup restoration
|
||||
- Database repair tools
|
||||
- Data recovery procedures
|
||||
- Support contact information
|
||||
|
||||
## Post-Migration
|
||||
|
||||
1. **Verification**
|
||||
- Data integrity checks
|
||||
- Performance monitoring
|
||||
- Error rate tracking
|
||||
- User feedback collection
|
||||
|
||||
2. **Cleanup**
|
||||
- Remove old database
|
||||
- Clear migration artifacts
|
||||
- Update application state
|
||||
- Archive backup data
|
||||
|
||||
3. **Monitoring**
|
||||
- Track migration success rate
|
||||
- Monitor performance metrics
|
||||
- Collect error reports
|
||||
- Gather user feedback
|
||||
|
||||
## Support
|
||||
|
||||
For assistance with migration:
|
||||
1. Check the troubleshooting guide
|
||||
2. Review error logs
|
||||
3. Contact support team
|
||||
4. Submit issue report
|
||||
|
||||
## Timeline
|
||||
|
||||
1. **Preparation Phase** (1 week)
|
||||
- Backup system implementation
|
||||
- Migration service development
|
||||
- Testing framework setup
|
||||
|
||||
2. **Testing Phase** (2 weeks)
|
||||
- Unit testing
|
||||
- Integration testing
|
||||
- Performance testing
|
||||
- Security testing
|
||||
|
||||
3. **Deployment Phase** (1 week)
|
||||
- Staged rollout
|
||||
- Monitoring
|
||||
- Support preparation
|
||||
- Documentation updates
|
||||
|
||||
4. **Post-Deployment** (2 weeks)
|
||||
- Monitoring
|
||||
- Bug fixes
|
||||
- Performance optimization
|
||||
- User feedback collection
|
||||
@@ -1,210 +0,0 @@
|
||||
# TimeSafari Docker Compose Configuration
|
||||
# Author: Matthew Raymer
|
||||
# Description: Multi-environment Docker Compose setup for TimeSafari
|
||||
#
|
||||
# Usage:
|
||||
# Development: docker-compose up dev
|
||||
# Staging: docker-compose up staging
|
||||
# Production: docker-compose up production
|
||||
# Custom: BUILD_MODE=staging docker-compose up custom
|
||||
#
|
||||
# Environment Variables:
|
||||
# BUILD_MODE: development, staging, or production (default: production)
|
||||
# NODE_ENV: node environment (default: production)
|
||||
# VITE_PLATFORM: vite platform (default: web)
|
||||
# VITE_PWA_ENABLED: enable PWA (default: true)
|
||||
# VITE_DISABLE_PWA: disable PWA (default: false)
|
||||
# PORT: port to expose (default: 80 for production, 5173 for dev)
|
||||
# ENV_FILE: environment file to use (default: .env.production)
|
||||
#
|
||||
# See .env files for application-specific configuration
|
||||
# VITE_APP_SERVER: Application server URL
|
||||
# VITE_DEFAULT_ENDORSER_API_SERVER: Endorser API server URL
|
||||
|
||||
version: '3.8'
|
||||
|
||||
# Default values that can be overridden
|
||||
x-defaults: &defaults
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
args:
|
||||
BUILD_MODE: ${BUILD_MODE:-production}
|
||||
NODE_ENV: ${NODE_ENV:-production}
|
||||
VITE_PLATFORM: ${VITE_PLATFORM:-web}
|
||||
VITE_PWA_ENABLED: ${VITE_PWA_ENABLED:-true}
|
||||
VITE_DISABLE_PWA: ${VITE_DISABLE_PWA:-false}
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost/health"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 40s
|
||||
|
||||
services:
|
||||
# Development service with hot reloading
|
||||
dev:
|
||||
<<: *defaults
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
target: development
|
||||
args:
|
||||
BUILD_MODE: development
|
||||
NODE_ENV: development
|
||||
VITE_PLATFORM: web
|
||||
VITE_PWA_ENABLED: true
|
||||
VITE_DISABLE_PWA: false
|
||||
ports:
|
||||
- "${DEV_PORT:-5173}:5173"
|
||||
volumes:
|
||||
- .:/app
|
||||
- /app/node_modules
|
||||
environment:
|
||||
- NODE_ENV=development
|
||||
- VITE_PLATFORM=web
|
||||
- VITE_PWA_ENABLED=true
|
||||
- VITE_DISABLE_PWA=false
|
||||
env_file:
|
||||
- ${DEV_ENV_FILE:-.env.development}
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:5173"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 40s
|
||||
|
||||
# Staging service for testing
|
||||
staging:
|
||||
<<: *defaults
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
target: staging
|
||||
args:
|
||||
BUILD_MODE: staging
|
||||
NODE_ENV: staging
|
||||
VITE_PLATFORM: web
|
||||
VITE_PWA_ENABLED: true
|
||||
VITE_DISABLE_PWA: false
|
||||
ports:
|
||||
- "${STAGING_PORT:-8080}:80"
|
||||
environment:
|
||||
- NODE_ENV=staging
|
||||
- VITE_PLATFORM=web
|
||||
- VITE_PWA_ENABLED=true
|
||||
- VITE_DISABLE_PWA=false
|
||||
env_file:
|
||||
- ${STAGING_ENV_FILE:-.env.staging}
|
||||
|
||||
# Production service
|
||||
production:
|
||||
<<: *defaults
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
target: production
|
||||
args:
|
||||
BUILD_MODE: production
|
||||
NODE_ENV: production
|
||||
VITE_PLATFORM: web
|
||||
VITE_PWA_ENABLED: true
|
||||
VITE_DISABLE_PWA: false
|
||||
ports:
|
||||
- "${PROD_PORT:-80}:80"
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- VITE_PLATFORM=web
|
||||
- VITE_PWA_ENABLED=true
|
||||
- VITE_DISABLE_PWA=false
|
||||
env_file:
|
||||
- ${PROD_ENV_FILE:-.env.production}
|
||||
|
||||
# Production service with SSL (requires certificates)
|
||||
production-ssl:
|
||||
<<: *defaults
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
target: production
|
||||
args:
|
||||
BUILD_MODE: production
|
||||
NODE_ENV: production
|
||||
VITE_PLATFORM: web
|
||||
VITE_PWA_ENABLED: true
|
||||
VITE_DISABLE_PWA: false
|
||||
ports:
|
||||
- "${SSL_PORT:-443}:443"
|
||||
- "${HTTP_PORT:-80}:80"
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- VITE_PLATFORM=web
|
||||
- VITE_PWA_ENABLED=true
|
||||
- VITE_DISABLE_PWA=false
|
||||
env_file:
|
||||
- ${PROD_ENV_FILE:-.env.production}
|
||||
volumes:
|
||||
- ./ssl:/etc/nginx/ssl:ro
|
||||
- ./docker/nginx-ssl.conf:/etc/nginx/conf.d/default.conf:ro
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "https://localhost/health"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 40s
|
||||
|
||||
# Custom service - configurable via environment variables
|
||||
custom:
|
||||
<<: *defaults
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
target: ${BUILD_TARGET:-production}
|
||||
args:
|
||||
BUILD_MODE: ${BUILD_MODE:-production}
|
||||
NODE_ENV: ${NODE_ENV:-production}
|
||||
VITE_PLATFORM: ${VITE_PLATFORM:-web}
|
||||
VITE_PWA_ENABLED: ${VITE_PWA_ENABLED:-true}
|
||||
VITE_DISABLE_PWA: ${VITE_DISABLE_PWA:-false}
|
||||
ports:
|
||||
- "${CUSTOM_PORT:-8080}:${CUSTOM_INTERNAL_PORT:-80}"
|
||||
environment:
|
||||
- NODE_ENV=${NODE_ENV:-production}
|
||||
- VITE_PLATFORM=${VITE_PLATFORM:-web}
|
||||
- VITE_PWA_ENABLED=${VITE_PWA_ENABLED:-true}
|
||||
- VITE_DISABLE_PWA=${VITE_DISABLE_PWA:-false}
|
||||
env_file:
|
||||
- ${CUSTOM_ENV_FILE:-.env.production}
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:${CUSTOM_INTERNAL_PORT:-80}/health"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 40s
|
||||
|
||||
# Load balancer for production (optional)
|
||||
nginx-lb:
|
||||
image: nginx:alpine
|
||||
ports:
|
||||
- "${LB_PORT:-80}:80"
|
||||
- "${LB_SSL_PORT:-443}:443"
|
||||
volumes:
|
||||
- ./docker/nginx-lb.conf:/etc/nginx/nginx.conf:ro
|
||||
- ./ssl:/etc/nginx/ssl:ro
|
||||
depends_on:
|
||||
- production
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost/health"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 40s
|
||||
|
||||
networks:
|
||||
default:
|
||||
driver: bridge
|
||||
ipam:
|
||||
config:
|
||||
- subnet: 172.20.0.0/16
|
||||
509
docker/README.md
509
docker/README.md
@@ -1,509 +0,0 @@
|
||||
# TimeSafari Docker Setup
|
||||
|
||||
## Overview
|
||||
|
||||
This directory contains Docker configuration files for building and deploying TimeSafari across different environments with full configurability.
|
||||
|
||||
## Files
|
||||
|
||||
- `Dockerfile` - Multi-stage Docker build for TimeSafari
|
||||
- `nginx.conf` - Main nginx configuration with security headers
|
||||
- `default.conf` - Production server configuration
|
||||
- `staging.conf` - Staging server configuration with relaxed caching
|
||||
- `docker-compose.yml` - Multi-environment Docker Compose setup
|
||||
- `.dockerignore` - Optimizes build context
|
||||
- `run.sh` - Convenient script to run different configurations
|
||||
|
||||
## Quick Start
|
||||
|
||||
### Using the Run Script (Recommended)
|
||||
|
||||
```bash
|
||||
# Development mode with hot reloading
|
||||
./docker/run.sh dev
|
||||
|
||||
# Staging mode for testing
|
||||
./docker/run.sh staging
|
||||
|
||||
# Production mode
|
||||
./docker/run.sh production
|
||||
|
||||
# Custom mode with environment variables
|
||||
BUILD_MODE=staging ./docker/run.sh custom
|
||||
|
||||
# Show build arguments for a mode
|
||||
./docker/run.sh dev --build-args
|
||||
|
||||
# Custom port and environment file
|
||||
./docker/run.sh staging --port 9000 --env .env.test
|
||||
```
|
||||
|
||||
### Using Docker Compose
|
||||
|
||||
```bash
|
||||
# Development environment with hot reloading
|
||||
docker-compose up dev
|
||||
|
||||
# Staging environment
|
||||
docker-compose up staging
|
||||
|
||||
# Production environment
|
||||
docker-compose up production
|
||||
|
||||
# Custom environment with variables
|
||||
BUILD_MODE=staging docker-compose up custom
|
||||
```
|
||||
|
||||
## Build Commands
|
||||
|
||||
### Manual Docker Build
|
||||
|
||||
```bash
|
||||
# Build production image (default)
|
||||
docker build -t timesafari:latest .
|
||||
|
||||
# Build staging image
|
||||
docker build --build-arg BUILD_MODE=staging -t timesafari:staging .
|
||||
|
||||
# Build development image
|
||||
docker build --build-arg BUILD_MODE=development -t timesafari:dev .
|
||||
|
||||
# Build with custom arguments
|
||||
docker build \
|
||||
--build-arg BUILD_MODE=staging \
|
||||
--build-arg NODE_ENV=staging \
|
||||
--build-arg VITE_PWA_ENABLED=true \
|
||||
-t timesafari:custom .
|
||||
```
|
||||
|
||||
### Run Container
|
||||
|
||||
```bash
|
||||
# Run production container
|
||||
docker run -d -p 80:80 timesafari:latest
|
||||
|
||||
# Run with environment file
|
||||
docker run -d -p 80:80 --env-file .env.production timesafari:latest
|
||||
|
||||
# Run with custom environment variables
|
||||
docker run -d -p 80:80 \
|
||||
-e VITE_APP_SERVER=https://myapp.com \
|
||||
-e VITE_DEFAULT_ENDORSER_API_SERVER=https://api.myapp.com \
|
||||
timesafari:latest
|
||||
```
|
||||
|
||||
## Configuration Options
|
||||
|
||||
### Build Arguments
|
||||
|
||||
The Dockerfile supports these build arguments:
|
||||
|
||||
| Argument | Default | Description |
|
||||
|----------|---------|-------------|
|
||||
| `BUILD_MODE` | `production` | Build mode: development, staging, or production |
|
||||
| `NODE_ENV` | `production` | Node.js environment |
|
||||
| `VITE_PLATFORM` | `web` | Vite platform type |
|
||||
| `VITE_PWA_ENABLED` | `true` | Enable PWA features |
|
||||
| `VITE_DISABLE_PWA` | `false` | Disable PWA features |
|
||||
|
||||
### Environment Variables
|
||||
|
||||
Docker Compose supports these environment variables:
|
||||
|
||||
| Variable | Default | Description |
|
||||
|----------|---------|-------------|
|
||||
| `BUILD_MODE` | `production` | Build mode |
|
||||
| `NODE_ENV` | `production` | Node environment |
|
||||
| `VITE_PLATFORM` | `web` | Vite platform |
|
||||
| `VITE_PWA_ENABLED` | `true` | Enable PWA |
|
||||
| `VITE_DISABLE_PWA` | `false` | Disable PWA |
|
||||
| `DEV_PORT` | `5173` | Development port |
|
||||
| `STAGING_PORT` | `8080` | Staging port |
|
||||
| `PROD_PORT` | `80` | Production port |
|
||||
| `DEV_ENV_FILE` | `.env.development` | Development env file |
|
||||
| `STAGING_ENV_FILE` | `.env.staging` | Staging env file |
|
||||
| `PROD_ENV_FILE` | `.env.production` | Production env file |
|
||||
|
||||
### Environment Files
|
||||
|
||||
Create environment files for different deployments:
|
||||
|
||||
```bash
|
||||
# .env.development
|
||||
VITE_APP_SERVER=https://dev.timesafari.app
|
||||
VITE_DEFAULT_ENDORSER_API_SERVER=https://dev-api.endorser.ch
|
||||
VITE_DEFAULT_IMAGE_API_SERVER=https://dev-image-api.timesafari.app
|
||||
VITE_DEFAULT_PARTNER_API_SERVER=https://dev-partner-api.endorser.ch
|
||||
VITE_DEFAULT_PUSH_SERVER=https://dev.timesafari.app
|
||||
VITE_PASSKEYS_ENABLED=true
|
||||
|
||||
# .env.staging
|
||||
VITE_APP_SERVER=https://staging.timesafari.app
|
||||
VITE_DEFAULT_ENDORSER_API_SERVER=https://staging-api.endorser.ch
|
||||
VITE_DEFAULT_IMAGE_API_SERVER=https://staging-image-api.timesafari.app
|
||||
VITE_DEFAULT_PARTNER_API_SERVER=https://staging-partner-api.endorser.ch
|
||||
VITE_DEFAULT_PUSH_SERVER=https://staging.timesafari.app
|
||||
VITE_PASSKEYS_ENABLED=true
|
||||
|
||||
# .env.production
|
||||
VITE_APP_SERVER=https://timesafari.app
|
||||
VITE_DEFAULT_ENDORSER_API_SERVER=https://api.endorser.ch
|
||||
VITE_DEFAULT_IMAGE_API_SERVER=https://image-api.timesafari.app
|
||||
VITE_DEFAULT_PARTNER_API_SERVER=https://partner-api.endorser.ch
|
||||
VITE_DEFAULT_PUSH_SERVER=https://timesafari.app
|
||||
VITE_PASSKEYS_ENABLED=true
|
||||
```
|
||||
|
||||
## Build Modes
|
||||
|
||||
### Development Mode
|
||||
- **Target**: `development`
|
||||
- **Features**: Hot reloading, development server
|
||||
- **Port**: 5173
|
||||
- **Caching**: Disabled
|
||||
- **Use Case**: Local development
|
||||
|
||||
```bash
|
||||
./docker/run.sh dev
|
||||
# or
|
||||
docker build --target development -t timesafari:dev .
|
||||
```
|
||||
|
||||
### Staging Mode
|
||||
- **Target**: `staging`
|
||||
- **Features**: Production build with relaxed caching
|
||||
- **Port**: 8080 (mapped from 80)
|
||||
- **Caching**: Short-term (1 hour)
|
||||
- **Use Case**: Testing and QA
|
||||
|
||||
```bash
|
||||
./docker/run.sh staging
|
||||
# or
|
||||
docker build --build-arg BUILD_MODE=staging -t timesafari:staging .
|
||||
```
|
||||
|
||||
### Production Mode
|
||||
- **Target**: `production`
|
||||
- **Features**: Optimized production build
|
||||
- **Port**: 80
|
||||
- **Caching**: Long-term (1 year for assets)
|
||||
- **Use Case**: Live deployment
|
||||
|
||||
```bash
|
||||
./docker/run.sh production
|
||||
# or
|
||||
docker build -t timesafari:latest .
|
||||
```
|
||||
|
||||
### Custom Mode
|
||||
- **Target**: Configurable via `BUILD_TARGET`
|
||||
- **Features**: Fully configurable
|
||||
- **Port**: Configurable via `CUSTOM_PORT`
|
||||
- **Use Case**: Special deployments
|
||||
|
||||
```bash
|
||||
BUILD_MODE=staging NODE_ENV=staging ./docker/run.sh custom
|
||||
```
|
||||
|
||||
## Advanced Usage
|
||||
|
||||
### Custom Build Configuration
|
||||
|
||||
```bash
|
||||
# Build with specific environment
|
||||
docker build \
|
||||
--build-arg BUILD_MODE=staging \
|
||||
--build-arg NODE_ENV=staging \
|
||||
--build-arg VITE_PWA_ENABLED=false \
|
||||
-t timesafari:staging-no-pwa .
|
||||
|
||||
# Run with custom configuration
|
||||
docker run -d -p 9000:80 \
|
||||
-e VITE_APP_SERVER=https://test.example.com \
|
||||
timesafari:staging-no-pwa
|
||||
```
|
||||
|
||||
### Docker Compose with Custom Variables
|
||||
|
||||
```bash
|
||||
# Set environment variables
|
||||
export BUILD_MODE=staging
|
||||
export NODE_ENV=staging
|
||||
export STAGING_PORT=9000
|
||||
export STAGING_ENV_FILE=.env.test
|
||||
|
||||
# Run staging with custom config
|
||||
docker-compose up staging
|
||||
```
|
||||
|
||||
### Multi-Environment Deployment
|
||||
|
||||
```bash
|
||||
# Development
|
||||
./docker/run.sh dev
|
||||
|
||||
# Staging in another terminal
|
||||
./docker/run.sh staging --port 8081
|
||||
|
||||
# Production in another terminal
|
||||
./docker/run.sh production --port 8082
|
||||
```
|
||||
|
||||
## Security Features
|
||||
|
||||
### Built-in Security
|
||||
- **Non-root user execution**: All containers run as non-root users
|
||||
- **Security headers**: XSS protection, content type options, frame options
|
||||
- **Rate limiting**: API request rate limiting
|
||||
- **File access restrictions**: Hidden files and backup files blocked
|
||||
- **Minimal attack surface**: Alpine Linux base images
|
||||
|
||||
### Security Headers
|
||||
- `X-Frame-Options: SAMEORIGIN`
|
||||
- `X-Content-Type-Options: nosniff`
|
||||
- `X-XSS-Protection: 1; mode=block`
|
||||
- `Referrer-Policy: strict-origin-when-cross-origin`
|
||||
- `Content-Security-Policy`: Comprehensive CSP policy
|
||||
|
||||
## Performance Optimizations
|
||||
|
||||
### Caching Strategy
|
||||
- **Static assets**: 1 year cache with immutable flag (production)
|
||||
- **HTML files**: 1 hour cache (production) / no cache (staging)
|
||||
- **Service worker**: No cache
|
||||
- **Manifest**: 1 day cache (production) / 1 hour cache (staging)
|
||||
|
||||
### Compression
|
||||
- **Gzip compression**: Enabled for text-based files
|
||||
- **Compression level**: 6 (balanced)
|
||||
- **Minimum size**: 1024 bytes
|
||||
|
||||
### Nginx Optimizations
|
||||
- **Sendfile**: Enabled for efficient file serving
|
||||
- **TCP optimizations**: nopush and nodelay enabled
|
||||
- **Keepalive**: 65 second timeout
|
||||
- **Worker processes**: Auto-detected based on CPU cores
|
||||
|
||||
## Health Checks
|
||||
|
||||
### Built-in Health Checks
|
||||
All services include health checks that:
|
||||
- Check every 30 seconds
|
||||
- Timeout after 10 seconds
|
||||
- Retry 3 times before marking unhealthy
|
||||
- Start checking after 40 seconds
|
||||
|
||||
### Health Check Endpoints
|
||||
- **Production/Staging**: `http://localhost/health`
|
||||
- **Development**: `http://localhost:5173`
|
||||
|
||||
## SSL/HTTPS Setup
|
||||
|
||||
### SSL Certificates
|
||||
For SSL deployment, create an `ssl` directory with certificates:
|
||||
|
||||
```bash
|
||||
mkdir ssl
|
||||
# Copy your certificates to ssl/ directory
|
||||
cp your-cert.pem ssl/
|
||||
cp your-key.pem ssl/
|
||||
```
|
||||
|
||||
### SSL Configuration
|
||||
Use the `production-ssl` service in docker-compose:
|
||||
|
||||
```bash
|
||||
docker-compose up production-ssl
|
||||
```
|
||||
|
||||
## Monitoring and Logging
|
||||
|
||||
### Log Locations
|
||||
- **Access logs**: `/var/log/nginx/access.log`
|
||||
- **Error logs**: `/var/log/nginx/error.log`
|
||||
|
||||
### Log Format
|
||||
```
|
||||
$remote_addr - $remote_user [$time_local] "$request"
|
||||
$status $body_bytes_sent "$http_referer"
|
||||
"$http_user_agent" "$http_x_forwarded_for"
|
||||
```
|
||||
|
||||
### Log Levels
|
||||
- **Production**: `warn` level
|
||||
- **Staging**: `debug` level
|
||||
- **Development**: Full logging
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
#### Build Failures
|
||||
```bash
|
||||
# Check build logs
|
||||
docker build -t timesafari:latest . 2>&1 | tee build.log
|
||||
|
||||
# Verify dependencies
|
||||
docker run --rm timesafari:latest npm list --depth=0
|
||||
|
||||
# Check build arguments
|
||||
./docker/run.sh dev --build-args
|
||||
```
|
||||
|
||||
#### Container Won't Start
|
||||
```bash
|
||||
# Check container logs
|
||||
docker logs <container_id>
|
||||
|
||||
# Check health status
|
||||
docker inspect <container_id> | grep -A 10 "Health"
|
||||
|
||||
# Verify port availability
|
||||
netstat -tulpn | grep :80
|
||||
```
|
||||
|
||||
#### Environment Variables Not Set
|
||||
```bash
|
||||
# Check environment in container
|
||||
docker exec <container_id> env | grep VITE_
|
||||
|
||||
# Verify .env file
|
||||
cat .env.production
|
||||
|
||||
# Check build arguments
|
||||
./docker/run.sh production --build-args
|
||||
```
|
||||
|
||||
#### Performance Issues
|
||||
```bash
|
||||
# Check container resources
|
||||
docker stats <container_id>
|
||||
|
||||
# Check nginx configuration
|
||||
docker exec <container_id> nginx -t
|
||||
|
||||
# Monitor access logs
|
||||
docker exec <container_id> tail -f /var/log/nginx/access.log
|
||||
```
|
||||
|
||||
### Debug Commands
|
||||
|
||||
#### Container Debugging
|
||||
```bash
|
||||
# Enter running container
|
||||
docker exec -it <container_id> /bin/sh
|
||||
|
||||
# Check nginx status
|
||||
docker exec <container_id> nginx -t
|
||||
|
||||
# Check file permissions
|
||||
docker exec <container_id> ls -la /usr/share/nginx/html
|
||||
```
|
||||
|
||||
#### Network Debugging
|
||||
```bash
|
||||
# Check container network
|
||||
docker network inspect bridge
|
||||
|
||||
# Test connectivity
|
||||
docker exec <container_id> curl -I http://localhost
|
||||
|
||||
# Check DNS resolution
|
||||
docker exec <container_id> nslookup google.com
|
||||
```
|
||||
|
||||
## Production Deployment
|
||||
|
||||
### Recommended Production Setup
|
||||
1. **Use specific version tags**: `timesafari:1.0.0`
|
||||
2. **Implement health checks**: Already included
|
||||
3. **Configure proper logging**: Use external log aggregation
|
||||
4. **Set up reverse proxy**: Use nginx-lb service
|
||||
5. **Use Docker secrets**: For sensitive data
|
||||
|
||||
### Production Commands
|
||||
```bash
|
||||
# Build with specific version
|
||||
docker build -t timesafari:1.0.0 .
|
||||
|
||||
# Run with production settings
|
||||
docker run -d \
|
||||
--name timesafari \
|
||||
-p 80:80 \
|
||||
--restart unless-stopped \
|
||||
--env-file .env.production \
|
||||
timesafari:1.0.0
|
||||
|
||||
# Update production deployment
|
||||
docker stop timesafari
|
||||
docker rm timesafari
|
||||
docker build -t timesafari:1.0.1 .
|
||||
docker run -d --name timesafari -p 80:80 --restart unless-stopped --env-file .env.production timesafari:1.0.1
|
||||
```
|
||||
|
||||
## Development Workflow
|
||||
|
||||
### Local Development
|
||||
```bash
|
||||
# Start development environment
|
||||
./docker/run.sh dev
|
||||
|
||||
# Make changes to code (hot reloading enabled)
|
||||
# Access at http://localhost:5173
|
||||
|
||||
# Stop development environment
|
||||
docker-compose down dev
|
||||
```
|
||||
|
||||
### Testing Changes
|
||||
```bash
|
||||
# Build and test staging
|
||||
./docker/run.sh staging
|
||||
|
||||
# Test production build locally
|
||||
./docker/run.sh production
|
||||
```
|
||||
|
||||
### Continuous Integration
|
||||
```bash
|
||||
# Build and test in CI
|
||||
docker build -t timesafari:test .
|
||||
docker run -d --name timesafari-test -p 8080:80 timesafari:test
|
||||
|
||||
# Run tests against container
|
||||
curl -f http://localhost:8080/health
|
||||
|
||||
# Cleanup
|
||||
docker stop timesafari-test
|
||||
docker rm timesafari-test
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
### Security
|
||||
- Always use non-root users
|
||||
- Keep base images updated
|
||||
- Scan images for vulnerabilities
|
||||
- Use secrets for sensitive data
|
||||
- Implement proper access controls
|
||||
|
||||
### Performance
|
||||
- Use multi-stage builds
|
||||
- Optimize layer caching
|
||||
- Minimize image size
|
||||
- Use appropriate base images
|
||||
- Implement proper caching
|
||||
|
||||
### Monitoring
|
||||
- Use health checks
|
||||
- Monitor resource usage
|
||||
- Set up log aggregation
|
||||
- Implement metrics collection
|
||||
- Use proper error handling
|
||||
|
||||
### Maintenance
|
||||
- Regular security updates
|
||||
- Monitor for vulnerabilities
|
||||
- Keep dependencies updated
|
||||
- Document configuration changes
|
||||
- Test deployment procedures
|
||||
@@ -1,110 +0,0 @@
|
||||
# TimeSafari Default Server Configuration
|
||||
# Author: Matthew Raymer
|
||||
# Description: Production server configuration for TimeSafari web application
|
||||
#
|
||||
# Features:
|
||||
# - Vue.js SPA routing support
|
||||
# - Static file caching optimization
|
||||
# - Security hardening
|
||||
# - Performance optimization
|
||||
# - Proper error handling
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# Security headers
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
||||
add_header Permissions-Policy "geolocation=(), microphone=(), camera=()" always;
|
||||
|
||||
# Handle Vue.js SPA routing
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
|
||||
# Cache static assets
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
add_header Vary "Accept-Encoding";
|
||||
}
|
||||
|
||||
# Cache HTML files for a shorter time
|
||||
location ~* \.html$ {
|
||||
expires 1h;
|
||||
add_header Cache-Control "public, must-revalidate";
|
||||
}
|
||||
}
|
||||
|
||||
# Handle service worker
|
||||
location /sw.js {
|
||||
expires 0;
|
||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||
add_header Pragma "no-cache";
|
||||
}
|
||||
|
||||
# Handle manifest file
|
||||
location /manifest.json {
|
||||
expires 1d;
|
||||
add_header Cache-Control "public";
|
||||
}
|
||||
|
||||
# Handle API requests (if needed)
|
||||
location /api/ {
|
||||
limit_req zone=api burst=20 nodelay;
|
||||
proxy_pass http://backend:3000;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# Handle health check
|
||||
location /health {
|
||||
access_log off;
|
||||
return 200 "healthy\n";
|
||||
add_header Content-Type text/plain;
|
||||
}
|
||||
|
||||
# Handle robots.txt
|
||||
location /robots.txt {
|
||||
expires 1d;
|
||||
add_header Cache-Control "public";
|
||||
}
|
||||
|
||||
# Handle favicon
|
||||
location /favicon.ico {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
|
||||
# Security: Deny access to hidden files
|
||||
location ~ /\. {
|
||||
deny all;
|
||||
access_log off;
|
||||
log_not_found off;
|
||||
}
|
||||
|
||||
# Security: Deny access to backup files
|
||||
location ~ ~$ {
|
||||
deny all;
|
||||
access_log off;
|
||||
log_not_found off;
|
||||
}
|
||||
|
||||
# Error pages
|
||||
error_page 404 /index.html;
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
|
||||
location = /50x.html {
|
||||
root /usr/share/nginx/html;
|
||||
}
|
||||
|
||||
# Logging
|
||||
access_log /var/log/nginx/access.log main;
|
||||
error_log /var/log/nginx/error.log warn;
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
# TimeSafari Nginx Configuration
|
||||
# Author: Matthew Raymer
|
||||
# Description: Main nginx configuration for TimeSafari web application
|
||||
#
|
||||
# Features:
|
||||
# - Security headers for web application
|
||||
# - Gzip compression for better performance
|
||||
# - Proper handling of Vue.js SPA routing
|
||||
# - Static file caching optimization
|
||||
# - Security hardening
|
||||
|
||||
user nginx;
|
||||
worker_processes auto;
|
||||
error_log /var/log/nginx/error.log warn;
|
||||
pid /var/run/nginx.pid;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
use epoll;
|
||||
multi_accept on;
|
||||
}
|
||||
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
# Logging format
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
'$status $body_bytes_sent "$http_referer" '
|
||||
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
access_log /var/log/nginx/access.log main;
|
||||
|
||||
# Performance optimizations
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
keepalive_timeout 65;
|
||||
types_hash_max_size 2048;
|
||||
client_max_body_size 16M;
|
||||
|
||||
# Gzip compression
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_min_length 1024;
|
||||
gzip_proxied any;
|
||||
gzip_comp_level 6;
|
||||
gzip_types
|
||||
text/plain
|
||||
text/css
|
||||
text/xml
|
||||
text/javascript
|
||||
application/json
|
||||
application/javascript
|
||||
application/xml+rss
|
||||
application/atom+xml
|
||||
image/svg+xml;
|
||||
|
||||
# Security headers
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
||||
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self' data:; connect-src 'self' https:; frame-ancestors 'self';" always;
|
||||
|
||||
# Rate limiting
|
||||
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
|
||||
limit_req_zone $binary_remote_addr zone=login:10m rate=1r/s;
|
||||
|
||||
# Include server configurations
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
}
|
||||
272
docker/run.sh
272
docker/run.sh
@@ -1,272 +0,0 @@
|
||||
#!/bin/bash
|
||||
# TimeSafari Docker Run Script
|
||||
# Author: Matthew Raymer
|
||||
# Description: Convenient script to run TimeSafari in different Docker configurations
|
||||
#
|
||||
# Usage:
|
||||
# ./docker/run.sh dev # Run development mode
|
||||
# ./docker/run.sh staging # Run staging mode
|
||||
# ./docker/run.sh production # Run production mode
|
||||
# ./docker/run.sh custom # Run custom mode with environment variables
|
||||
#
|
||||
# Environment Variables:
|
||||
# BUILD_MODE: development, staging, or production
|
||||
# NODE_ENV: node environment
|
||||
# VITE_PLATFORM: vite platform
|
||||
# VITE_PWA_ENABLED: enable PWA
|
||||
# VITE_DISABLE_PWA: disable PWA
|
||||
# PORT: port to expose
|
||||
# ENV_FILE: environment file to use
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
readonly RED='\033[0;31m'
|
||||
readonly GREEN='\033[0;32m'
|
||||
readonly YELLOW='\033[1;33m'
|
||||
readonly BLUE='\033[0;34m'
|
||||
readonly NC='\033[0m' # No Color
|
||||
|
||||
# Logging functions
|
||||
log_info() {
|
||||
echo -e "${BLUE}[$(date '+%Y-%m-%d %H:%M:%S')] [INFO]${NC} $1"
|
||||
}
|
||||
|
||||
log_success() {
|
||||
echo -e "${GREEN}[$(date '+%Y-%m-%d %H:%M:%S')] [SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
log_warn() {
|
||||
echo -e "${YELLOW}[$(date '+%Y-%m-%d %H:%M:%S')] [WARN]${NC} $1"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo -e "${RED}[$(date '+%Y-%m-%d %H:%M:%S')] [ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Function to show usage
|
||||
show_usage() {
|
||||
echo "TimeSafari Docker Run Script"
|
||||
echo ""
|
||||
echo "Usage: $0 <mode> [options]"
|
||||
echo ""
|
||||
echo "Modes:"
|
||||
echo " dev - Development mode with hot reloading"
|
||||
echo " staging - Staging mode for testing"
|
||||
echo " production - Production mode"
|
||||
echo " custom - Custom mode with environment variables"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " --port <port> - Custom port (default: 5173 for dev, 8080 for staging, 80 for production)"
|
||||
echo " --env <file> - Environment file (default: .env.<mode>)"
|
||||
echo " --build-args - Show build arguments for the mode"
|
||||
echo " --help - Show this help message"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " $0 dev"
|
||||
echo " $0 staging --port 9000"
|
||||
echo " $0 production --env .env.prod"
|
||||
echo " BUILD_MODE=staging $0 custom"
|
||||
echo ""
|
||||
echo "Environment Variables:"
|
||||
echo " BUILD_MODE: development, staging, or production"
|
||||
echo " NODE_ENV: node environment"
|
||||
echo " VITE_PLATFORM: vite platform"
|
||||
echo " VITE_PWA_ENABLED: enable PWA"
|
||||
echo " VITE_DISABLE_PWA: disable PWA"
|
||||
echo " PORT: port to expose"
|
||||
echo " ENV_FILE: environment file to use"
|
||||
}
|
||||
|
||||
# Function to show build arguments for a mode
|
||||
show_build_args() {
|
||||
local mode=$1
|
||||
echo "Build arguments for $mode mode:"
|
||||
echo ""
|
||||
case $mode in
|
||||
dev)
|
||||
echo " BUILD_MODE: development"
|
||||
echo " NODE_ENV: development"
|
||||
echo " VITE_PLATFORM: web"
|
||||
echo " VITE_PWA_ENABLED: true"
|
||||
echo " VITE_DISABLE_PWA: false"
|
||||
echo " Target: development"
|
||||
echo " Port: 5173"
|
||||
;;
|
||||
staging)
|
||||
echo " BUILD_MODE: staging"
|
||||
echo " NODE_ENV: staging"
|
||||
echo " VITE_PLATFORM: web"
|
||||
echo " VITE_PWA_ENABLED: true"
|
||||
echo " VITE_DISABLE_PWA: false"
|
||||
echo " Target: staging"
|
||||
echo " Port: 80 (mapped to 8080)"
|
||||
;;
|
||||
production)
|
||||
echo " BUILD_MODE: production"
|
||||
echo " NODE_ENV: production"
|
||||
echo " VITE_PLATFORM: web"
|
||||
echo " VITE_PWA_ENABLED: true"
|
||||
echo " VITE_DISABLE_PWA: false"
|
||||
echo " Target: production"
|
||||
echo " Port: 80"
|
||||
;;
|
||||
custom)
|
||||
echo " BUILD_MODE: \${BUILD_MODE:-production}"
|
||||
echo " NODE_ENV: \${NODE_ENV:-production}"
|
||||
echo " VITE_PLATFORM: \${VITE_PLATFORM:-web}"
|
||||
echo " VITE_PWA_ENABLED: \${VITE_PWA_ENABLED:-true}"
|
||||
echo " VITE_DISABLE_PWA: \${VITE_DISABLE_PWA:-false}"
|
||||
echo " Target: \${BUILD_TARGET:-production}"
|
||||
echo " Port: \${CUSTOM_PORT:-8080}:\${CUSTOM_INTERNAL_PORT:-80}"
|
||||
;;
|
||||
*)
|
||||
log_error "Unknown mode: $mode"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Function to check if Docker is running
|
||||
check_docker() {
|
||||
if ! docker info > /dev/null 2>&1; then
|
||||
log_error "Docker is not running. Please start Docker and try again."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to check if docker-compose is available
|
||||
check_docker_compose() {
|
||||
if ! command -v docker-compose > /dev/null 2>&1; then
|
||||
log_error "docker-compose is not installed. Please install docker-compose and try again."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to check if required files exist
|
||||
check_files() {
|
||||
local mode=$1
|
||||
local env_file=$2
|
||||
|
||||
if [ ! -f "Dockerfile" ]; then
|
||||
log_error "Dockerfile not found. Please run this script from the project root."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "docker-compose.yml" ]; then
|
||||
log_error "docker-compose.yml not found. Please run this script from the project root."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -n "$env_file" ] && [ ! -f "$env_file" ]; then
|
||||
log_warn "Environment file $env_file not found. Using defaults."
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to run the container
|
||||
run_container() {
|
||||
local mode=$1
|
||||
local port=$2
|
||||
local env_file=$3
|
||||
|
||||
log_info "Starting TimeSafari in $mode mode..."
|
||||
|
||||
# Set environment variables based on mode
|
||||
case $mode in
|
||||
dev)
|
||||
export DEV_PORT=${port:-5173}
|
||||
if [ -n "$env_file" ]; then
|
||||
export DEV_ENV_FILE="$env_file"
|
||||
fi
|
||||
docker-compose up dev
|
||||
;;
|
||||
staging)
|
||||
export STAGING_PORT=${port:-8080}
|
||||
if [ -n "$env_file" ]; then
|
||||
export STAGING_ENV_FILE="$env_file"
|
||||
fi
|
||||
docker-compose up staging
|
||||
;;
|
||||
production)
|
||||
export PROD_PORT=${port:-80}
|
||||
if [ -n "$env_file" ]; then
|
||||
export PROD_ENV_FILE="$env_file"
|
||||
fi
|
||||
docker-compose up production
|
||||
;;
|
||||
custom)
|
||||
export CUSTOM_PORT=${port:-8080}
|
||||
if [ -n "$env_file" ]; then
|
||||
export CUSTOM_ENV_FILE="$env_file"
|
||||
fi
|
||||
docker-compose up custom
|
||||
;;
|
||||
*)
|
||||
log_error "Unknown mode: $mode"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Main script
|
||||
main() {
|
||||
local mode=""
|
||||
local port=""
|
||||
local env_file=""
|
||||
local show_args=false
|
||||
|
||||
# Parse command line arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
dev|staging|production|custom)
|
||||
mode="$1"
|
||||
shift
|
||||
;;
|
||||
--port)
|
||||
port="$2"
|
||||
shift 2
|
||||
;;
|
||||
--env)
|
||||
env_file="$2"
|
||||
shift 2
|
||||
;;
|
||||
--build-args)
|
||||
show_args=true
|
||||
shift
|
||||
;;
|
||||
--help|-h)
|
||||
show_usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
log_error "Unknown option: $1"
|
||||
show_usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Check if mode is provided
|
||||
if [ -z "$mode" ]; then
|
||||
log_error "No mode specified."
|
||||
show_usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Show build arguments if requested
|
||||
if [ "$show_args" = true ]; then
|
||||
show_build_args "$mode"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check prerequisites
|
||||
check_docker
|
||||
check_docker_compose
|
||||
check_files "$mode" "$env_file"
|
||||
|
||||
# Run the container
|
||||
run_container "$mode" "$port" "$env_file"
|
||||
}
|
||||
|
||||
# Run main function with all arguments
|
||||
main "$@"
|
||||
@@ -1,110 +0,0 @@
|
||||
# TimeSafari Staging Server Configuration
|
||||
# Author: Matthew Raymer
|
||||
# Description: Staging server configuration for TimeSafari web application
|
||||
#
|
||||
# Features:
|
||||
# - Relaxed caching for testing
|
||||
# - Debug-friendly settings
|
||||
# - Same security as production
|
||||
# - Development-friendly error handling
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# Security headers (same as production)
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
||||
add_header Permissions-Policy "geolocation=(), microphone=(), camera=()" always;
|
||||
|
||||
# Handle Vue.js SPA routing
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
|
||||
# Relaxed caching for staging
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||
expires 1h;
|
||||
add_header Cache-Control "public, must-revalidate";
|
||||
add_header Vary "Accept-Encoding";
|
||||
}
|
||||
|
||||
# No caching for HTML files in staging
|
||||
location ~* \.html$ {
|
||||
expires 0;
|
||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||
add_header Pragma "no-cache";
|
||||
}
|
||||
}
|
||||
|
||||
# Handle service worker (no caching)
|
||||
location /sw.js {
|
||||
expires 0;
|
||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||
add_header Pragma "no-cache";
|
||||
}
|
||||
|
||||
# Handle manifest file (short cache)
|
||||
location /manifest.json {
|
||||
expires 1h;
|
||||
add_header Cache-Control "public, must-revalidate";
|
||||
}
|
||||
|
||||
# Handle API requests (if needed)
|
||||
location /api/ {
|
||||
limit_req zone=api burst=20 nodelay;
|
||||
proxy_pass http://backend:3000;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# Handle health check
|
||||
location /health {
|
||||
access_log off;
|
||||
return 200 "healthy-staging\n";
|
||||
add_header Content-Type text/plain;
|
||||
}
|
||||
|
||||
# Handle robots.txt (no caching in staging)
|
||||
location /robots.txt {
|
||||
expires 0;
|
||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||
}
|
||||
|
||||
# Handle favicon (short cache)
|
||||
location /favicon.ico {
|
||||
expires 1h;
|
||||
add_header Cache-Control "public, must-revalidate";
|
||||
}
|
||||
|
||||
# Security: Deny access to hidden files
|
||||
location ~ /\. {
|
||||
deny all;
|
||||
access_log off;
|
||||
log_not_found off;
|
||||
}
|
||||
|
||||
# Security: Deny access to backup files
|
||||
location ~ ~$ {
|
||||
deny all;
|
||||
access_log off;
|
||||
log_not_found off;
|
||||
}
|
||||
|
||||
# Error pages (more verbose for staging)
|
||||
error_page 404 /index.html;
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
|
||||
location = /50x.html {
|
||||
root /usr/share/nginx/html;
|
||||
}
|
||||
|
||||
# Enhanced logging for staging
|
||||
access_log /var/log/nginx/access.log main;
|
||||
error_log /var/log/nginx/error.log debug;
|
||||
}
|
||||
221
docs/DATABASE_CONNECTION_FIXES.md
Normal file
221
docs/DATABASE_CONNECTION_FIXES.md
Normal file
@@ -0,0 +1,221 @@
|
||||
# Database Connection Fixes for TimeSafari
|
||||
|
||||
## Overview
|
||||
|
||||
This document outlines the fixes implemented to resolve database connection issues in the TimeSafari application, particularly for Capacitor SQLite on Android devices.
|
||||
|
||||
## Issues Identified
|
||||
|
||||
### 1. CapacitorSQLitePlugin Errors
|
||||
- Multiple `*** ERROR CapacitorSQLitePlugin: null` messages in Android logs
|
||||
- Database connection conflicts and initialization failures
|
||||
- Connection leaks causing "Connection timesafari.sqlite already exists" errors
|
||||
|
||||
### 2. Performance Issues
|
||||
- App skipping 57 frames due to main thread blocking
|
||||
- Null pointer exceptions in garbage collection
|
||||
- Memory management issues
|
||||
|
||||
### 3. Connection Management
|
||||
- Lack of proper connection cleanup on app lifecycle events
|
||||
- No retry logic for failed connections
|
||||
- Missing error handling and recovery mechanisms
|
||||
|
||||
## Implemented Fixes
|
||||
|
||||
### 1. Enhanced Database Initialization
|
||||
|
||||
#### Connection Cleanup
|
||||
- Added `cleanupExistingConnections()` method to properly close existing connections
|
||||
- Implemented connection consistency checks before creating new connections
|
||||
- Added proper error handling for connection cleanup failures
|
||||
|
||||
#### Retry Logic
|
||||
- Implemented exponential backoff retry mechanism for database connections
|
||||
- Maximum of 3 retry attempts with increasing delays
|
||||
- Comprehensive error logging for each attempt
|
||||
|
||||
#### Database Configuration
|
||||
- Configured optimal SQLite settings for performance and stability:
|
||||
- `PRAGMA journal_mode=WAL` for better concurrency
|
||||
- `PRAGMA synchronous=NORMAL` for balanced performance
|
||||
- `PRAGMA cache_size=10000` for improved caching
|
||||
- `PRAGMA temp_store=MEMORY` for faster temporary operations
|
||||
- `PRAGMA mmap_size=268435456` (256MB) for memory mapping
|
||||
|
||||
### 2. Lifecycle Management
|
||||
|
||||
#### App Lifecycle Listeners
|
||||
- Added event listeners for `beforeunload` and `visibilitychange`
|
||||
- Automatic database cleanup when app goes to background
|
||||
- Proper resource management to prevent connection leaks
|
||||
|
||||
#### Health Monitoring
|
||||
- Implemented `healthCheck()` method for connection status monitoring
|
||||
- Added `reinitializeDatabase()` for forced reconnection
|
||||
- Performance metrics tracking for database operations
|
||||
|
||||
### 3. Error Handling and Diagnostics
|
||||
|
||||
#### Comprehensive Error Handling
|
||||
- Enhanced error logging with detailed context
|
||||
- Graceful degradation when database operations fail
|
||||
- User-friendly error messages with recovery suggestions
|
||||
|
||||
#### Diagnostic Tools
|
||||
- Created `databaseDiagnostics.ts` utility for troubleshooting
|
||||
- Database stress testing capabilities
|
||||
- Performance monitoring and reporting
|
||||
- System information collection for debugging
|
||||
|
||||
### 4. Configuration Changes
|
||||
|
||||
#### Capacitor Configuration
|
||||
- Temporarily disabled encryption to isolate connection issues
|
||||
- Disabled biometric authentication to reduce complexity
|
||||
- Maintained proper database location settings
|
||||
|
||||
#### Camera Integration Fixes
|
||||
- Fixed `CameraDirection` enum usage for Capacitor Camera v6
|
||||
- Updated from string literals to proper enum values
|
||||
- Resolved TypeScript compilation errors
|
||||
|
||||
## Usage
|
||||
|
||||
### Running Diagnostics
|
||||
|
||||
```typescript
|
||||
import { runDatabaseDiagnostics, stressTestDatabase } from '@/utils/databaseDiagnostics';
|
||||
|
||||
// Run comprehensive diagnostics
|
||||
const diagnosticInfo = await runDatabaseDiagnostics();
|
||||
console.log('Database status:', diagnosticInfo.connectionStatus);
|
||||
|
||||
// Run stress test
|
||||
await stressTestDatabase(20);
|
||||
```
|
||||
|
||||
### Health Checks
|
||||
|
||||
```typescript
|
||||
import { PlatformServiceFactory } from '@/services/PlatformServiceFactory';
|
||||
|
||||
const platformService = PlatformServiceFactory.getInstance();
|
||||
const health = await platformService.healthCheck();
|
||||
|
||||
if (!health.healthy) {
|
||||
console.error('Database health check failed:', health.error);
|
||||
// Attempt reinitialization
|
||||
await platformService.reinitializeDatabase();
|
||||
}
|
||||
```
|
||||
|
||||
### Performance Monitoring
|
||||
|
||||
```typescript
|
||||
import { logDatabasePerformance } from '@/utils/databaseDiagnostics';
|
||||
|
||||
// Wrap database operations with performance monitoring
|
||||
const start = Date.now();
|
||||
await platformService.dbQuery("SELECT * FROM users");
|
||||
const duration = Date.now() - start;
|
||||
logDatabasePerformance("User query", duration);
|
||||
```
|
||||
|
||||
## Troubleshooting Guide
|
||||
|
||||
### Common Issues and Solutions
|
||||
|
||||
#### 1. "Connection timesafari.sqlite already exists"
|
||||
**Cause**: Multiple database connections not properly closed
|
||||
**Solution**:
|
||||
- Use the enhanced cleanup methods
|
||||
- Check for existing connections before creating new ones
|
||||
- Implement proper app lifecycle management
|
||||
|
||||
#### 2. CapacitorSQLitePlugin null errors
|
||||
**Cause**: Database initialization failures or connection conflicts
|
||||
**Solution**:
|
||||
- Use retry logic with exponential backoff
|
||||
- Check connection consistency
|
||||
- Verify database configuration settings
|
||||
|
||||
#### 3. Performance Issues
|
||||
**Cause**: Main thread blocking or inefficient database operations
|
||||
**Solution**:
|
||||
- Use WAL journal mode for better concurrency
|
||||
- Implement proper connection pooling
|
||||
- Monitor and optimize query performance
|
||||
|
||||
#### 4. Memory Leaks
|
||||
**Cause**: Database connections not properly closed
|
||||
**Solution**:
|
||||
- Implement proper cleanup on app lifecycle events
|
||||
- Use health checks to monitor connection status
|
||||
- Force reinitialization when issues are detected
|
||||
|
||||
### Debugging Steps
|
||||
|
||||
1. **Check Logs**: Look for database-related error messages
|
||||
2. **Run Diagnostics**: Use `runDatabaseDiagnostics()` to get system status
|
||||
3. **Monitor Performance**: Track query execution times
|
||||
4. **Test Connections**: Use stress testing to identify issues
|
||||
5. **Verify Configuration**: Check Capacitor and SQLite settings
|
||||
|
||||
### Recovery Procedures
|
||||
|
||||
#### Automatic Recovery
|
||||
- Health checks run periodically
|
||||
- Automatic reinitialization on connection failures
|
||||
- Graceful degradation for non-critical operations
|
||||
|
||||
#### Manual Recovery
|
||||
- Force app restart to clear all connections
|
||||
- Clear app data if persistent issues occur
|
||||
- Check device storage and permissions
|
||||
|
||||
## Security Considerations
|
||||
|
||||
### Data Protection
|
||||
- Encryption can be re-enabled once connection issues are resolved
|
||||
- Biometric authentication can be restored after stability is confirmed
|
||||
- Proper error handling prevents data corruption
|
||||
|
||||
### Privacy
|
||||
- Diagnostic information is logged locally only
|
||||
- No sensitive data is exposed in error messages
|
||||
- User data remains protected during recovery procedures
|
||||
|
||||
## Performance Impact
|
||||
|
||||
### Improvements
|
||||
- Reduced connection initialization time
|
||||
- Better memory usage through proper cleanup
|
||||
- Improved app responsiveness with background processing
|
||||
- Enhanced error recovery reduces user impact
|
||||
|
||||
### Monitoring
|
||||
- Performance metrics are tracked automatically
|
||||
- Slow operations are logged with warnings
|
||||
- System resource usage is monitored
|
||||
|
||||
## Future Enhancements
|
||||
|
||||
### Planned Improvements
|
||||
1. **Connection Pooling**: Implement proper connection pooling for better performance
|
||||
2. **Encryption Re-enablement**: Restore encryption once stability is confirmed
|
||||
3. **Advanced Monitoring**: Add real-time performance dashboards
|
||||
4. **Automated Recovery**: Implement self-healing mechanisms
|
||||
|
||||
### Research Areas
|
||||
1. **Alternative Storage**: Investigate other storage solutions for specific use cases
|
||||
2. **Migration Tools**: Develop tools for seamless data migration
|
||||
3. **Cross-Platform Optimization**: Optimize for different device capabilities
|
||||
|
||||
## Conclusion
|
||||
|
||||
These fixes address the core database connection issues while maintaining application stability and user experience. The enhanced error handling, monitoring, and recovery mechanisms provide a robust foundation for reliable database operations across all platforms.
|
||||
|
||||
## Author
|
||||
|
||||
Matthew Raymer - Database Architecture and Mobile Platform Development
|
||||
@@ -1,115 +0,0 @@
|
||||
# AbsurdSQL Enhanced Logging - Security Audit Checklist
|
||||
|
||||
**Date:** July 1, 2025
|
||||
**Author:** Matthew Raymer
|
||||
**Changes:** Enhanced AbsurdSQL logging with comprehensive failure tracking
|
||||
|
||||
## Overview
|
||||
|
||||
This security audit covers the enhanced logging implementation for AbsurdSQL database service, including diagnostic capabilities and health monitoring features.
|
||||
|
||||
## Security Audit Checklist
|
||||
|
||||
### 1. Data Exposure and Privacy
|
||||
|
||||
- [x] **Sensitive Data Logging**: Verified that SQL parameters are logged but PII data is not exposed in plain text
|
||||
- [x] **SQL Injection Prevention**: Confirmed parameterized queries are used throughout, no string concatenation
|
||||
- [x] **Error Message Sanitization**: Error messages don't expose internal system details to external users
|
||||
- [x] **Diagnostic Data Scope**: Diagnostic information includes only operational metrics, not user data
|
||||
- [x] **Log Level Appropriateness**: Debug logs contain operational details, info logs contain high-level status
|
||||
|
||||
### 2. Authentication and Authorization
|
||||
|
||||
- [x] **Access Control**: Diagnostic methods are internal to the application, not exposed via external APIs
|
||||
- [x] **Method Visibility**: All diagnostic methods are properly scoped and not publicly accessible
|
||||
- [x] **Component Security**: Test component is development-only and should not be included in production builds
|
||||
- [x] **Service Layer Protection**: Database service maintains singleton pattern preventing unauthorized instantiation
|
||||
|
||||
### 3. Input Validation and Sanitization
|
||||
|
||||
- [x] **Parameter Validation**: SQL parameters are validated through existing platform service layer
|
||||
- [x] **Query Sanitization**: All queries use parameterized statements, preventing SQL injection
|
||||
- [x] **Log Message Sanitization**: Log messages are properly escaped and truncated to prevent log injection
|
||||
- [x] **Diagnostic Output Sanitization**: Diagnostic output is structured JSON, preventing injection attacks
|
||||
|
||||
### 4. Resource Management and DoS Prevention
|
||||
|
||||
- [x] **Queue Size Monitoring**: Warning logs when operation queue exceeds 50 items
|
||||
- [x] **Memory Management**: Diagnostic data is bounded and doesn't accumulate indefinitely
|
||||
- [x] **Performance Impact**: Logging operations are asynchronous and non-blocking
|
||||
- [x] **Log Rotation**: Relies on external log management system for rotation and cleanup
|
||||
- [x] **Resource Cleanup**: Proper cleanup of diagnostic resources and temporary data
|
||||
|
||||
### 5. Information Disclosure
|
||||
|
||||
- [x] **Stack Trace Handling**: Full stack traces only logged at debug level, not exposed to users
|
||||
- [x] **System Information**: Minimal system information logged (platform, browser type only)
|
||||
- [x] **Database Schema Protection**: No database schema information exposed in logs
|
||||
- [x] **Operational Metrics**: Only performance metrics exposed, not sensitive operational data
|
||||
|
||||
### 6. Error Handling and Recovery
|
||||
|
||||
- [x] **Graceful Degradation**: Diagnostic features fail gracefully without affecting core functionality
|
||||
- [x] **Error Isolation**: Logging failures don't cascade to database operations
|
||||
- [x] **Recovery Mechanisms**: Initialization failures are properly handled with retry logic
|
||||
- [x] **State Consistency**: Database state remains consistent even if logging fails
|
||||
|
||||
### 7. Cross-Platform Security
|
||||
|
||||
- [x] **Web Platform**: Browser-based logging doesn't expose server-side information
|
||||
- [x] **Mobile Platform**: Capacitor implementation properly sandboxes diagnostic data
|
||||
- [x] **Platform Isolation**: Platform-specific diagnostic data is properly isolated
|
||||
- [x] **Interface Consistency**: All platforms implement the same security model
|
||||
|
||||
### 8. Compliance and Audit Trail
|
||||
|
||||
- [x] **Audit Logging**: Comprehensive audit trail for database operations and health checks
|
||||
- [x] **Timestamp Accuracy**: All logs include accurate ISO timestamps
|
||||
- [x] **Data Retention**: Logs are managed by external system for compliance requirements
|
||||
- [x] **Traceability**: Operation IDs enable tracing of database operations
|
||||
|
||||
## Security Recommendations
|
||||
|
||||
### High Priority
|
||||
1. **Production Builds**: Ensure `DiagnosticsTestComponent` is excluded from production builds
|
||||
2. **Log Level Configuration**: Implement runtime log level configuration for production
|
||||
3. **Rate Limiting**: Consider implementing rate limiting for diagnostic operations
|
||||
|
||||
### Medium Priority
|
||||
1. **Log Encryption**: Consider encrypting sensitive diagnostic data at rest
|
||||
2. **Access Logging**: Add logging for diagnostic method access patterns
|
||||
3. **Automated Monitoring**: Implement automated alerting for diagnostic anomalies
|
||||
|
||||
### Low Priority
|
||||
1. **Log Aggregation**: Implement centralized log aggregation for better analysis
|
||||
2. **Metrics Dashboard**: Create operational dashboard for diagnostic metrics
|
||||
3. **Performance Profiling**: Add performance profiling for diagnostic operations
|
||||
|
||||
## Compliance Notes
|
||||
|
||||
- **GDPR**: No personal data is logged in diagnostic information
|
||||
- **HIPAA**: Medical data is not exposed through diagnostic channels
|
||||
- **SOC 2**: Audit trails are maintained for all database operations
|
||||
- **ISO 27001**: Information security controls are implemented for logging
|
||||
|
||||
## Testing and Validation
|
||||
|
||||
### Security Tests Required
|
||||
- [ ] Penetration testing of diagnostic endpoints
|
||||
- [ ] Log injection attack testing
|
||||
- [ ] Resource exhaustion testing
|
||||
- [ ] Cross-site scripting (XSS) testing of diagnostic output
|
||||
- [ ] Authentication bypass testing
|
||||
|
||||
### Monitoring and Alerting
|
||||
- [ ] Set up alerts for unusual diagnostic patterns
|
||||
- [ ] Monitor for potential information disclosure
|
||||
- [ ] Track diagnostic performance impact
|
||||
- [ ] Monitor queue growth patterns
|
||||
|
||||
## Sign-off
|
||||
|
||||
**Security Review Completed:** July 1, 2025
|
||||
**Reviewer:** Matthew Raymer
|
||||
**Status:** ✅ Approved with recommendations
|
||||
**Next Review:** October 1, 2025
|
||||
@@ -1,209 +0,0 @@
|
||||
# Compact Database API - Before vs After Comparison
|
||||
|
||||
## The Problem: Verbose Database Operations
|
||||
|
||||
The current database operations require significant boilerplate code, making simple operations unnecessarily complex.
|
||||
|
||||
## Before: Verbose & Repetitive ❌
|
||||
|
||||
### Loading Data
|
||||
```typescript
|
||||
// 6 lines for a simple query!
|
||||
@Component
|
||||
export default class ContactsView extends Vue {
|
||||
async loadContacts() {
|
||||
const platformService = PlatformServiceFactory.getInstance();
|
||||
const result = await platformService.dbQuery("SELECT * FROM contacts WHERE visible = ?", [1]);
|
||||
const contacts = databaseUtil.mapQueryResultToValues(result) as Contact[];
|
||||
await databaseUtil.logToDb(`Loaded ${contacts.length} contacts`);
|
||||
this.contacts = contacts;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Saving Data
|
||||
```typescript
|
||||
// 8+ lines for a simple insert!
|
||||
async saveContact(contact: Contact) {
|
||||
const platformService = PlatformServiceFactory.getInstance();
|
||||
const { sql, params } = databaseUtil.generateInsertStatement(contact, "contacts");
|
||||
const result = await platformService.dbExec(sql, params);
|
||||
await databaseUtil.logToDb(`Contact saved with ID: ${result.lastId}`);
|
||||
if (result.changes !== 1) {
|
||||
throw new Error("Failed to save contact");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
```
|
||||
|
||||
### Settings Management
|
||||
```typescript
|
||||
// 4+ lines for settings
|
||||
async updateAppSettings(newSettings: Partial<Settings>) {
|
||||
const success = await databaseUtil.updateDefaultSettings(newSettings as Settings);
|
||||
await databaseUtil.logToDb(success ? "Settings saved" : "Settings save failed", success ? "info" : "error");
|
||||
return success;
|
||||
}
|
||||
```
|
||||
|
||||
## After: Compact & Clean ✅
|
||||
|
||||
### Loading Data
|
||||
```typescript
|
||||
// 2 lines - 70% reduction!
|
||||
@Component
|
||||
export default class ContactsView extends Vue {
|
||||
private db = useCompactDatabase();
|
||||
|
||||
async loadContacts() {
|
||||
const contacts = await this.db.query<Contact>("SELECT * FROM contacts WHERE visible = ?", [1]);
|
||||
await this.db.log(`Loaded ${contacts.length} contacts`);
|
||||
this.contacts = contacts;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Saving Data
|
||||
```typescript
|
||||
// 2 lines - 75% reduction!
|
||||
async saveContact(contact: Contact) {
|
||||
const result = await this.db.insert("contacts", contact);
|
||||
await this.db.log(`Contact saved with ID: ${result.lastId}`);
|
||||
return result;
|
||||
}
|
||||
```
|
||||
|
||||
### Settings Management
|
||||
```typescript
|
||||
// 1 line - 75% reduction!
|
||||
async updateAppSettings(newSettings: Partial<Settings>) {
|
||||
return await this.db.saveSettings(newSettings);
|
||||
}
|
||||
```
|
||||
|
||||
## Advanced Examples
|
||||
|
||||
### Multiple Usage Patterns
|
||||
|
||||
#### 1. Vue-Facing-Decorator Class Components
|
||||
```typescript
|
||||
@Component
|
||||
export default class MyComponent extends Vue {
|
||||
private db = useCompactDatabase(); // Composable in class
|
||||
|
||||
async mounted() {
|
||||
// Query with type safety
|
||||
const users = await this.db.query<User>("SELECT * FROM users WHERE active = ?", [1]);
|
||||
|
||||
// Get single record
|
||||
const setting = await this.db.queryOne<Setting>("SELECT * FROM settings WHERE key = ?", ["theme"]);
|
||||
|
||||
// CRUD operations
|
||||
await this.db.insert("logs", { message: "Component mounted", date: new Date().toISOString() });
|
||||
await this.db.update("users", { lastActive: Date.now() }, "id = ?", [this.userId]);
|
||||
await this.db.delete("temp_data", "created < ?", [Date.now() - 86400000]);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 2. Composition API Setup
|
||||
```typescript
|
||||
export default {
|
||||
setup() {
|
||||
const db = useCompactDatabase();
|
||||
|
||||
const loadData = async () => {
|
||||
const items = await db.query("SELECT * FROM items");
|
||||
await db.log("Data loaded");
|
||||
return items;
|
||||
};
|
||||
|
||||
return { loadData };
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 3. Direct Import (Non-Composable)
|
||||
```typescript
|
||||
import { db } from "@/composables/useCompactDatabase";
|
||||
|
||||
// Use anywhere without setup
|
||||
export async function backgroundTask() {
|
||||
const data = await db.query("SELECT * FROM background_jobs");
|
||||
await db.log(`Processing ${data.length} jobs`);
|
||||
}
|
||||
```
|
||||
|
||||
## Feature Comparison
|
||||
|
||||
| Operation | Before (Lines) | After (Lines) | Reduction |
|
||||
|-----------|----------------|---------------|-----------|
|
||||
| Simple Query | 4 lines | 1 line | **75%** |
|
||||
| Insert Record | 4 lines | 1 line | **75%** |
|
||||
| Update Record | 5 lines | 1 line | **80%** |
|
||||
| Delete Record | 3 lines | 1 line | **67%** |
|
||||
| Get Settings | 3 lines | 1 line | **67%** |
|
||||
| Save Settings | 4 lines | 1 line | **75%** |
|
||||
| Log Message | 1 line | 1 line | **0%** (already compact) |
|
||||
|
||||
## Benefits
|
||||
|
||||
### 🎯 Massive Code Reduction
|
||||
- **70-80% less boilerplate** for common operations
|
||||
- **Cleaner, more readable code**
|
||||
- **Faster development** with less typing
|
||||
|
||||
### 🔧 Developer Experience
|
||||
- **Auto-completion** for all database operations
|
||||
- **Type safety** with generic query methods
|
||||
- **Consistent API** across all database operations
|
||||
- **Built-in logging** for debugging
|
||||
|
||||
### 🛡️ Safety & Reliability
|
||||
- **Same security** as existing functions (wraps them)
|
||||
- **Parameterized queries** prevent SQL injection
|
||||
- **Error handling** built into the composable
|
||||
- **Type checking** prevents runtime errors
|
||||
|
||||
### 🔄 Flexibility
|
||||
- **Works with vue-facing-decorator** (your current pattern)
|
||||
- **Works with Composition API** (future-proof)
|
||||
- **Works with direct imports** (utility functions)
|
||||
- **Progressive adoption** - use alongside existing code
|
||||
|
||||
## Migration Path
|
||||
|
||||
### Phase 1: New Code
|
||||
```typescript
|
||||
// Start using in new components immediately
|
||||
const db = useCompactDatabase();
|
||||
const data = await db.query("SELECT * FROM table");
|
||||
```
|
||||
|
||||
### Phase 2: Gradual Replacement
|
||||
```typescript
|
||||
// Replace verbose patterns as you encounter them
|
||||
// Old:
|
||||
const platformService = PlatformServiceFactory.getInstance();
|
||||
const result = await platformService.dbQuery(sql, params);
|
||||
const mapped = databaseUtil.mapQueryResultToValues(result);
|
||||
|
||||
// New:
|
||||
const mapped = await db.query(sql, params);
|
||||
```
|
||||
|
||||
### Phase 3: Full Adoption
|
||||
```typescript
|
||||
// Eventually all database operations use the compact API
|
||||
```
|
||||
|
||||
## Performance Impact
|
||||
|
||||
- **Zero performance overhead** - same underlying functions
|
||||
- **Slight memory improvement** - fewer service instantiations
|
||||
- **Better caching** - singleton pattern for platform service
|
||||
- **Reduced bundle size** - less repeated boilerplate code
|
||||
|
||||
---
|
||||
|
||||
**The compact database composable transforms verbose, error-prone database operations into clean, type-safe one-liners while maintaining all existing security and functionality.**
|
||||
@@ -1,206 +0,0 @@
|
||||
# HomeView Migration Results - Compact Database Success ✅
|
||||
|
||||
## Overview (Tue Jul 1 08:49:04 AM UTC 2025)
|
||||
|
||||
Successfully migrated **HomeView.vue** from verbose database patterns to the compact database API. This migration demonstrates the dramatic code reduction and improved maintainability achieved with the new approach.
|
||||
|
||||
## Migration Statistics
|
||||
|
||||
### 📊 **Code Reduction Summary**
|
||||
- **5 methods migrated** with database operations
|
||||
- **Lines of code reduced**: 12 lines → 5 lines (**58% reduction**)
|
||||
- **Import statements reduced**: 2 imports → 1 import
|
||||
- **Complexity reduced**: Eliminated boilerplate in all database operations
|
||||
|
||||
### 🎯 **Specific Method Improvements**
|
||||
|
||||
#### 1. `loadContacts()` - Most Dramatic Improvement
|
||||
```typescript
|
||||
// BEFORE (3 lines)
|
||||
const platformService = PlatformServiceFactory.getInstance();
|
||||
const dbContacts = await platformService.dbQuery("SELECT * FROM contacts");
|
||||
this.allContacts = databaseUtil.mapQueryResultToValues(dbContacts) as unknown as Contact[];
|
||||
|
||||
// AFTER (1 line) ✅
|
||||
this.allContacts = await this.db.query<Contact>("SELECT * FROM contacts");
|
||||
```
|
||||
**Result**: 67% reduction, **cleaner types**, **better readability**
|
||||
|
||||
#### 2. Settings Methods - Consistent Simplification
|
||||
```typescript
|
||||
// BEFORE (1 line each)
|
||||
const settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
|
||||
// AFTER (1 line each) ✅
|
||||
const settings = await this.db.getSettings();
|
||||
```
|
||||
**Result**: **Shorter**, **more semantic**, **consistent API**
|
||||
|
||||
#### 3. Import Cleanup
|
||||
```typescript
|
||||
// BEFORE (2 imports)
|
||||
import * as databaseUtil from "../db/databaseUtil";
|
||||
import { PlatformServiceFactory } from "@/services/PlatformServiceFactory";
|
||||
|
||||
// AFTER (1 import) ✅
|
||||
import { useCompactDatabase } from "@/composables/useCompactDatabase";
|
||||
```
|
||||
**Result**: **Cleaner imports**, **single dependency**, **better organization**
|
||||
|
||||
## Methods Successfully Migrated
|
||||
|
||||
### ✅ **5 Methods Converted**
|
||||
|
||||
1. **`loadSettings()`**
|
||||
- `databaseUtil.retrieveSettingsForActiveAccount()` → `this.db.getSettings()`
|
||||
|
||||
2. **`loadContacts()`**
|
||||
- 3-line query pattern → 1-line typed query
|
||||
- Automatic result mapping
|
||||
- Type safety with `<Contact>`
|
||||
|
||||
3. **`checkRegistrationStatus()`**
|
||||
- Settings retrieval simplified
|
||||
- Maintained complex update logic (not yet migrated)
|
||||
|
||||
4. **`checkOnboarding()`**
|
||||
- Settings retrieval simplified
|
||||
|
||||
5. **`reloadFeedOnChange()`**
|
||||
- Settings retrieval simplified
|
||||
|
||||
## Benefits Demonstrated
|
||||
|
||||
### 🚀 **Developer Experience**
|
||||
- **Less typing**: Fewer lines of boilerplate code
|
||||
- **Better IntelliSense**: Typed methods with clear signatures
|
||||
- **Consistent API**: Same patterns across all operations
|
||||
- **Reduced errors**: Fewer manual mapping steps
|
||||
|
||||
### 🔧 **Maintainability**
|
||||
- **Single point of change**: Database logic centralized
|
||||
- **Clear separation**: Business logic vs database operations
|
||||
- **Better testing**: Easier to mock and test
|
||||
- **Reduced complexity**: Fewer moving parts
|
||||
|
||||
### 📈 **Performance**
|
||||
- **Singleton pattern**: Reused database instance
|
||||
- **Optimized queries**: Direct result mapping
|
||||
- **Reduced memory**: Fewer intermediate objects
|
||||
- **Better caching**: Centralized database management
|
||||
|
||||
## Code Quality Improvements
|
||||
|
||||
### ✅ **Linting & Formatting**
|
||||
- **Zero lint errors**: All code passes ESLint
|
||||
- **Consistent formatting**: Auto-formatted with Prettier
|
||||
- **TypeScript compliance**: Full type safety maintained
|
||||
- **Import optimization**: Unused imports removed
|
||||
|
||||
### ✅ **Vue-Facing-Decorator Compatibility**
|
||||
- **Class-based syntax**: Works perfectly with decorator pattern
|
||||
- **Private instance**: `private db = useCompactDatabase()`
|
||||
- **Method integration**: Seamless integration with existing methods
|
||||
- **Component lifecycle**: No conflicts with Vue lifecycle
|
||||
|
||||
## Migration Patterns Identified
|
||||
|
||||
### 🔄 **Reusable Patterns**
|
||||
|
||||
#### Pattern 1: Simple Query
|
||||
```typescript
|
||||
// BEFORE
|
||||
const platformService = PlatformServiceFactory.getInstance();
|
||||
const result = await platformService.dbQuery(sql, params);
|
||||
const data = databaseUtil.mapQueryResultToValues(result) as Type[];
|
||||
|
||||
// AFTER
|
||||
const data = await this.db.query<Type>(sql, params);
|
||||
```
|
||||
|
||||
#### Pattern 2: Settings Retrieval
|
||||
```typescript
|
||||
// BEFORE
|
||||
const settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
|
||||
// AFTER
|
||||
const settings = await this.db.getSettings();
|
||||
```
|
||||
|
||||
#### Pattern 3: Settings Update (Future)
|
||||
```typescript
|
||||
// FUTURE MIGRATION TARGET
|
||||
const settings = await this.db.getSettings();
|
||||
await databaseUtil.updateDidSpecificSettings(did, changes);
|
||||
|
||||
// COULD BECOME
|
||||
await this.db.updateSettings(did, changes);
|
||||
```
|
||||
|
||||
## Remaining Migration Opportunities
|
||||
|
||||
### 🎯 **Next Steps**
|
||||
1. **Settings updates**: Migrate `updateDidSpecificSettings()` calls
|
||||
2. **Other views**: Apply same patterns to other Vue components
|
||||
3. **Service methods**: Migrate services that use database operations
|
||||
4. **CRUD operations**: Use compact database CRUD helpers
|
||||
|
||||
### 📋 **Migration Checklist for Other Components**
|
||||
- [ ] Add `useCompactDatabase` import
|
||||
- [ ] Create `private db = useCompactDatabase()` instance
|
||||
- [ ] Replace query patterns with `db.query<Type>()`
|
||||
- [ ] Replace settings patterns with `db.getSettings()`
|
||||
- [ ] Remove unused imports
|
||||
- [ ] Run lint-fix
|
||||
|
||||
## Testing Recommendations
|
||||
|
||||
### 🧪 **Validation Steps**
|
||||
1. **Functional testing**: Verify all HomeView features work
|
||||
2. **Database operations**: Confirm queries return expected data
|
||||
3. **Settings management**: Test settings load/save operations
|
||||
4. **Error handling**: Ensure error scenarios are handled
|
||||
5. **Performance**: Monitor query performance
|
||||
|
||||
### 🔍 **What to Test**
|
||||
- Contact loading and display
|
||||
- Settings persistence across sessions
|
||||
- Registration status checks
|
||||
- Onboarding flow
|
||||
- Feed filtering functionality
|
||||
|
||||
## Security Considerations
|
||||
|
||||
### 🔒 **Security Maintained**
|
||||
- **Same SQL queries**: No query logic changed
|
||||
- **Same permissions**: No privilege escalation
|
||||
- **Same validation**: Input validation preserved
|
||||
- **Same error handling**: Error patterns maintained
|
||||
|
||||
### ✅ **Security Checklist**
|
||||
- [x] No SQL injection vectors introduced
|
||||
- [x] Same data access patterns maintained
|
||||
- [x] Error messages don't leak sensitive data
|
||||
- [x] Database permissions unchanged
|
||||
- [x] Input validation preserved
|
||||
|
||||
## Conclusion
|
||||
|
||||
The HomeView migration to compact database is a **complete success**. It demonstrates:
|
||||
|
||||
- **Significant code reduction** (58% fewer lines)
|
||||
- **Improved readability** and maintainability
|
||||
- **Better developer experience** with typed APIs
|
||||
- **Zero regression** in functionality
|
||||
- **Clear migration patterns** for other components
|
||||
|
||||
This migration serves as a **proof of concept** and **template** for migrating the entire codebase to the compact database approach.
|
||||
|
||||
## Next Migration Targets
|
||||
|
||||
1. **ContactsView** - Likely heavy database usage
|
||||
2. **ProjectsView** - Complex query patterns
|
||||
3. **ServicesView** - Business logic integration
|
||||
4. **ClaimView** - Data persistence operations
|
||||
|
||||
The compact database approach is **production-ready** and **ready for full codebase adoption**.
|
||||
8
electron/.gitignore
vendored
8
electron/.gitignore
vendored
@@ -1,8 +0,0 @@
|
||||
# NPM renames .gitignore to .npmignore
|
||||
# In order to prevent that, we remove the initial "."
|
||||
# And the CLI then renames it
|
||||
app
|
||||
node_modules
|
||||
build
|
||||
dist
|
||||
logs
|
||||
@@ -1,251 +0,0 @@
|
||||
# Building TimeSafari Electron App
|
||||
|
||||
This guide explains how to build distributable packages for the TimeSafari Electron desktop application.
|
||||
|
||||
## Quick Start
|
||||
|
||||
### From Project Root
|
||||
```bash
|
||||
# Build all Linux packages (AppImage, deb)
|
||||
npm run electron:build
|
||||
|
||||
# Build specific package types
|
||||
npm run electron:build:appimage # AppImage only
|
||||
npm run electron:build:deb # Debian package only
|
||||
```
|
||||
|
||||
### From Electron Directory
|
||||
```bash
|
||||
cd electron
|
||||
|
||||
# Build all packages
|
||||
./build-packages.sh
|
||||
|
||||
# Build specific types
|
||||
./build-packages.sh appimage
|
||||
./build-packages.sh deb
|
||||
./build-packages.sh pack # Unpacked directory (for testing)
|
||||
```
|
||||
|
||||
## Package Types
|
||||
|
||||
### 1. AppImage (Recommended for Linux)
|
||||
- **File**: `TimeSafari-1.0.0.AppImage`
|
||||
- **Size**: ~145MB
|
||||
- **Usage**: Download and run directly, no installation required
|
||||
- **Distribution**: Upload to GitHub releases or website
|
||||
|
||||
```bash
|
||||
# Make executable and run
|
||||
chmod +x TimeSafari-1.0.0.AppImage
|
||||
./TimeSafari-1.0.0.AppImage
|
||||
```
|
||||
|
||||
### 2. Debian Package (.deb)
|
||||
- **File**: `TimeSafari_1.0.0_amd64.deb`
|
||||
- **Size**: ~96MB
|
||||
- **Usage**: Install via package manager
|
||||
- **Distribution**: Upload to repositories or direct download
|
||||
|
||||
```bash
|
||||
# Install
|
||||
sudo dpkg -i TimeSafari_1.0.0_amd64.deb
|
||||
|
||||
# Run
|
||||
timesafari
|
||||
```
|
||||
|
||||
### 3. RPM Package (.rpm)
|
||||
- **File**: `TimeSafari-1.0.0.x86_64.rpm`
|
||||
- **Requirements**: `rpmbuild` must be installed
|
||||
- **Usage**: Install via package manager
|
||||
|
||||
```bash
|
||||
# Install rpmbuild (Arch Linux)
|
||||
sudo pacman -S rpm-tools
|
||||
|
||||
# Build RPM
|
||||
./build-packages.sh rpm
|
||||
|
||||
# Install (on RPM-based systems)
|
||||
sudo rpm -i TimeSafari-1.0.0.x86_64.rpm
|
||||
```
|
||||
|
||||
## Build Requirements
|
||||
|
||||
### System Dependencies
|
||||
- Node.js 18+
|
||||
- npm or yarn
|
||||
- Python 3 (for native module compilation)
|
||||
- Build tools (gcc, make)
|
||||
|
||||
### Optional Dependencies
|
||||
- `rpmbuild` - for RPM packages
|
||||
- `fpm` - automatically downloaded by electron-builder
|
||||
|
||||
### Node Dependencies
|
||||
All required dependencies are in `package.json`:
|
||||
- `electron-builder` - Main build tool
|
||||
- `better-sqlite3-multiple-ciphers` - SQLite with encryption
|
||||
- Native module compilation tools
|
||||
|
||||
## Build Process
|
||||
|
||||
### 1. Preparation
|
||||
```bash
|
||||
# Install dependencies
|
||||
npm install
|
||||
|
||||
# Build TypeScript
|
||||
npm run build
|
||||
```
|
||||
|
||||
### 2. Package Creation
|
||||
The build process:
|
||||
1. Compiles TypeScript to JavaScript
|
||||
2. Rebuilds native modules for Electron
|
||||
3. Packages the app with electron-builder
|
||||
4. Creates platform-specific installers
|
||||
|
||||
### 3. Output Location
|
||||
All built packages are saved to `electron/dist/`:
|
||||
```
|
||||
dist/
|
||||
├── TimeSafari-1.0.0.AppImage # Portable AppImage
|
||||
├── TimeSafari_1.0.0_amd64.deb # Debian package
|
||||
├── TimeSafari-1.0.0.x86_64.rpm # RPM package (if built)
|
||||
└── linux-unpacked/ # Unpacked directory
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
### App Metadata
|
||||
App information is configured in `electron/package.json`:
|
||||
```json
|
||||
{
|
||||
"name": "TimeSafari",
|
||||
"version": "1.0.0",
|
||||
"description": "Time Safari - Community building through gifts, gratitude, and collaborative projects",
|
||||
"homepage": "https://timesafari.app",
|
||||
"author": {
|
||||
"name": "Matthew Raymer",
|
||||
"email": "matthew@timesafari.app"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Build Configuration
|
||||
Build settings are in `electron/electron-builder.config.json`:
|
||||
- Package formats and architectures
|
||||
- Icons and assets
|
||||
- Platform-specific settings
|
||||
- Signing and publishing options
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
#### 1. Native Module Compilation Errors
|
||||
```bash
|
||||
# Clear cache and rebuild
|
||||
npm run build
|
||||
```
|
||||
|
||||
#### 2. Missing Dependencies
|
||||
```bash
|
||||
# Install system dependencies (Arch Linux)
|
||||
sudo pacman -S base-devel python
|
||||
|
||||
# Install Node dependencies
|
||||
npm install
|
||||
```
|
||||
|
||||
#### 3. RPM Build Fails
|
||||
```bash
|
||||
# Install rpmbuild
|
||||
sudo pacman -S rpm-tools
|
||||
|
||||
# Try building again
|
||||
./build-packages.sh rpm
|
||||
```
|
||||
|
||||
#### 4. Large Package Size
|
||||
The packages are large (~100-150MB) because they include:
|
||||
- Complete Electron runtime
|
||||
- Node.js runtime
|
||||
- SQLite native modules
|
||||
- Application assets
|
||||
|
||||
This is normal for Electron applications.
|
||||
|
||||
### Debug Mode
|
||||
For detailed build information:
|
||||
```bash
|
||||
DEBUG=electron-builder npx electron-builder build
|
||||
```
|
||||
|
||||
## Distribution
|
||||
|
||||
### GitHub Releases
|
||||
1. Create a new release on GitHub
|
||||
2. Upload the built packages as release assets
|
||||
3. Users can download and install directly
|
||||
|
||||
### Package Repositories
|
||||
- **Debian/Ubuntu**: Upload `.deb` to repository
|
||||
- **Fedora/CentOS**: Upload `.rpm` to repository
|
||||
- **Arch Linux**: Create PKGBUILD for AUR
|
||||
|
||||
### Direct Download
|
||||
Host the packages on your website for direct download.
|
||||
|
||||
## Cross-Platform Building
|
||||
|
||||
### Current Support
|
||||
- **Linux**: Full support (AppImage, deb, rpm)
|
||||
- **Windows**: Configured but requires Windows build environment
|
||||
- **macOS**: Configured but requires macOS build environment
|
||||
|
||||
### Building for Other Platforms
|
||||
To build for Windows or macOS, you need:
|
||||
- The target platform's build environment
|
||||
- Platform-specific signing certificates
|
||||
- Updated build configuration
|
||||
|
||||
## Security Considerations
|
||||
|
||||
### Code Signing
|
||||
For production releases, consider code signing:
|
||||
- **Linux**: Not required but recommended
|
||||
- **Windows**: Required for Windows SmartScreen
|
||||
- **macOS**: Required for Gatekeeper
|
||||
|
||||
### Package Integrity
|
||||
- Verify package checksums
|
||||
- Use HTTPS for distribution
|
||||
- Consider GPG signatures for packages
|
||||
|
||||
## Performance Tips
|
||||
|
||||
### Build Optimization
|
||||
- Use `--dir` flag for faster development builds
|
||||
- Cache node_modules between builds
|
||||
- Use CI/CD for automated builds
|
||||
|
||||
### Package Size Reduction
|
||||
- Remove unnecessary dependencies
|
||||
- Use electron-builder's file filtering
|
||||
- Consider using electron-updater for delta updates
|
||||
|
||||
## Support
|
||||
|
||||
For build issues:
|
||||
1. Check the console output for specific errors
|
||||
2. Verify all dependencies are installed
|
||||
3. Try cleaning and rebuilding
|
||||
4. Check electron-builder documentation
|
||||
5. Open an issue with build logs
|
||||
|
||||
---
|
||||
|
||||
**Happy Building! 🚀**
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 142 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 121 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 159 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 12 KiB |
@@ -1,56 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# TimeSafari Electron Build Script
|
||||
# Usage: ./build-packages.sh [pack|appimage|deb|rpm|all]
|
||||
|
||||
set -e
|
||||
|
||||
echo "🚀 TimeSafari Electron Build Script"
|
||||
echo "=================================="
|
||||
|
||||
# Build TypeScript and rebuild native modules
|
||||
echo "📦 Building TypeScript and native modules..."
|
||||
npm run build
|
||||
|
||||
BUILD_TYPE="${1:-all}"
|
||||
|
||||
case "$BUILD_TYPE" in
|
||||
"pack")
|
||||
echo "📦 Creating unpacked build..."
|
||||
npx electron-builder build --dir -c ./electron-builder.config.json
|
||||
;;
|
||||
"appimage")
|
||||
echo "📦 Creating AppImage..."
|
||||
npx electron-builder build --linux AppImage -c ./electron-builder.config.json
|
||||
;;
|
||||
"deb")
|
||||
echo "📦 Creating Debian package..."
|
||||
npx electron-builder build --linux deb -c ./electron-builder.config.json
|
||||
;;
|
||||
"rpm")
|
||||
echo "📦 Creating RPM package..."
|
||||
if ! command -v rpmbuild &> /dev/null; then
|
||||
echo "⚠️ rpmbuild not found. Install with: sudo pacman -S rpm-tools"
|
||||
exit 1
|
||||
fi
|
||||
npx electron-builder build --linux rpm -c ./electron-builder.config.json
|
||||
;;
|
||||
"all")
|
||||
echo "📦 Creating all Linux packages..."
|
||||
npx electron-builder build --linux -c ./electron-builder.config.json
|
||||
;;
|
||||
*)
|
||||
echo "❌ Unknown build type: $BUILD_TYPE"
|
||||
echo "Usage: $0 [pack|appimage|deb|rpm|all]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
echo ""
|
||||
echo "✅ Build completed successfully!"
|
||||
echo "📁 Output files in: ./dist/"
|
||||
echo ""
|
||||
echo "📦 Available packages:"
|
||||
ls -la dist/ | grep -E '\.(AppImage|deb|rpm)$' || echo " No packages found"
|
||||
echo ""
|
||||
echo "🎉 Ready to distribute!"
|
||||
@@ -1,98 +0,0 @@
|
||||
{
|
||||
"appId": "app.timesafari",
|
||||
"appName": "TimeSafari",
|
||||
"webDir": "dist",
|
||||
"server": {
|
||||
"cleartext": true
|
||||
},
|
||||
"plugins": {
|
||||
"App": {
|
||||
"appUrlOpen": {
|
||||
"handlers": [
|
||||
{
|
||||
"url": "timesafari://*",
|
||||
"autoVerify": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"CapacitorSQLite": {
|
||||
"iosDatabaseLocation": "Library/CapacitorDatabase",
|
||||
"iosIsEncryption": false,
|
||||
"iosBiometric": {
|
||||
"biometricAuth": false,
|
||||
"biometricTitle": "Biometric login for TimeSafari"
|
||||
},
|
||||
"androidIsEncryption": false,
|
||||
"androidBiometric": {
|
||||
"biometricAuth": false,
|
||||
"biometricTitle": "Biometric login for TimeSafari"
|
||||
},
|
||||
"electronIsEncryption": false
|
||||
}
|
||||
},
|
||||
"ios": {
|
||||
"contentInset": "never",
|
||||
"allowsLinkPreview": true,
|
||||
"scrollEnabled": true,
|
||||
"limitsNavigationsToAppBoundDomains": true,
|
||||
"backgroundColor": "#ffffff",
|
||||
"allowNavigation": [
|
||||
"*.timesafari.app",
|
||||
"*.jsdelivr.net",
|
||||
"api.endorser.ch"
|
||||
]
|
||||
},
|
||||
"android": {
|
||||
"allowMixedContent": false,
|
||||
"captureInput": true,
|
||||
"webContentsDebuggingEnabled": false,
|
||||
"allowNavigation": [
|
||||
"*.timesafari.app",
|
||||
"*.jsdelivr.net",
|
||||
"api.endorser.ch"
|
||||
]
|
||||
},
|
||||
"electron": {
|
||||
"deepLinking": {
|
||||
"schemes": ["timesafari"]
|
||||
},
|
||||
"buildOptions": {
|
||||
"appId": "app.timesafari",
|
||||
"productName": "TimeSafari",
|
||||
"directories": {
|
||||
"output": "dist-electron-packages"
|
||||
},
|
||||
"files": [
|
||||
"dist/**/*",
|
||||
"electron/**/*"
|
||||
],
|
||||
"mac": {
|
||||
"category": "public.app-category.productivity",
|
||||
"target": [
|
||||
{
|
||||
"target": "dmg",
|
||||
"arch": ["x64", "arm64"]
|
||||
}
|
||||
]
|
||||
},
|
||||
"win": {
|
||||
"target": [
|
||||
{
|
||||
"target": "nsis",
|
||||
"arch": ["x64"]
|
||||
}
|
||||
]
|
||||
},
|
||||
"linux": {
|
||||
"target": [
|
||||
{
|
||||
"target": "AppImage",
|
||||
"arch": ["x64"]
|
||||
}
|
||||
],
|
||||
"category": "Utility"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
{
|
||||
"appId": "app.timesafari.desktop",
|
||||
"productName": "TimeSafari",
|
||||
"directories": {
|
||||
"buildResources": "resources",
|
||||
"output": "dist"
|
||||
},
|
||||
"files": [
|
||||
"assets/**/*",
|
||||
"build/**/*",
|
||||
"capacitor.config.*",
|
||||
"app/**/*"
|
||||
],
|
||||
"publish": {
|
||||
"provider": "github"
|
||||
},
|
||||
"linux": {
|
||||
"target": [
|
||||
{
|
||||
"target": "AppImage",
|
||||
"arch": ["x64"]
|
||||
},
|
||||
{
|
||||
"target": "deb",
|
||||
"arch": ["x64"]
|
||||
},
|
||||
{
|
||||
"target": "rpm",
|
||||
"arch": ["x64"]
|
||||
}
|
||||
],
|
||||
"icon": "assets/appIcon.png",
|
||||
"category": "Office",
|
||||
"description": "Time Safari - Community building through gifts, gratitude, and collaborative projects",
|
||||
"maintainer": "Matthew Raymer <matthew@timesafari.app>",
|
||||
"vendor": "TimeSafari"
|
||||
},
|
||||
"nsis": {
|
||||
"allowElevation": true,
|
||||
"oneClick": false,
|
||||
"allowToChangeInstallationDirectory": true,
|
||||
"createDesktopShortcut": true,
|
||||
"createStartMenuShortcut": true
|
||||
},
|
||||
"win": {
|
||||
"target": [
|
||||
{
|
||||
"target": "nsis",
|
||||
"arch": ["x64"]
|
||||
}
|
||||
],
|
||||
"icon": "assets/appIcon.ico"
|
||||
},
|
||||
"mac": {
|
||||
"category": "public.app-category.productivity",
|
||||
"target": [
|
||||
{
|
||||
"target": "dmg",
|
||||
"arch": ["x64", "arm64"]
|
||||
}
|
||||
],
|
||||
"icon": "assets/appIcon.png"
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
/* eslint-disable no-undef */
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
const cp = require('child_process');
|
||||
const chokidar = require('chokidar');
|
||||
const electron = require('electron');
|
||||
|
||||
let child = null;
|
||||
const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
||||
const reloadWatcher = {
|
||||
debouncer: null,
|
||||
ready: false,
|
||||
watcher: null,
|
||||
restarting: false,
|
||||
};
|
||||
|
||||
///*
|
||||
function runBuild() {
|
||||
return new Promise((resolve, _reject) => {
|
||||
let tempChild = cp.spawn(npmCmd, ['run', 'build']);
|
||||
tempChild.once('exit', () => {
|
||||
resolve();
|
||||
});
|
||||
tempChild.stdout.pipe(process.stdout);
|
||||
});
|
||||
}
|
||||
//*/
|
||||
|
||||
async function spawnElectron() {
|
||||
if (child !== null) {
|
||||
child.stdin.pause();
|
||||
child.kill();
|
||||
child = null;
|
||||
await runBuild();
|
||||
}
|
||||
child = cp.spawn(electron, ['--inspect=5858', './']);
|
||||
child.on('exit', () => {
|
||||
if (!reloadWatcher.restarting) {
|
||||
process.exit(0);
|
||||
}
|
||||
});
|
||||
child.stdout.pipe(process.stdout);
|
||||
}
|
||||
|
||||
function setupReloadWatcher() {
|
||||
reloadWatcher.watcher = chokidar
|
||||
.watch('./src/**/*', {
|
||||
ignored: /[/\\]\./,
|
||||
persistent: true,
|
||||
})
|
||||
.on('ready', () => {
|
||||
reloadWatcher.ready = true;
|
||||
})
|
||||
.on('all', (_event, _path) => {
|
||||
if (reloadWatcher.ready) {
|
||||
clearTimeout(reloadWatcher.debouncer);
|
||||
reloadWatcher.debouncer = setTimeout(async () => {
|
||||
console.log('Restarting');
|
||||
reloadWatcher.restarting = true;
|
||||
await spawnElectron();
|
||||
reloadWatcher.restarting = false;
|
||||
reloadWatcher.ready = false;
|
||||
clearTimeout(reloadWatcher.debouncer);
|
||||
reloadWatcher.debouncer = null;
|
||||
reloadWatcher.watcher = null;
|
||||
setupReloadWatcher();
|
||||
}, 500);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
(async () => {
|
||||
await runBuild();
|
||||
await spawnElectron();
|
||||
setupReloadWatcher();
|
||||
})();
|
||||
6115
electron/package-lock.json
generated
6115
electron/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,52 +0,0 @@
|
||||
{
|
||||
"name": "TimeSafari",
|
||||
"version": "1.0.0",
|
||||
"description": "Time Safari - Community building through gifts, gratitude, and collaborative projects",
|
||||
"homepage": "https://timesafari.app",
|
||||
"author": {
|
||||
"name": "Matthew Raymer",
|
||||
"email": "matthew@timesafari.app"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/trentlarson/crowd-master"
|
||||
},
|
||||
"license": "MIT",
|
||||
"main": "build/src/index.js",
|
||||
"scripts": {
|
||||
"build": "tsc && electron-rebuild",
|
||||
"electron:start-live": "node ./live-runner.js",
|
||||
"electron:start": "npm run build && electron --inspect=5858 ./",
|
||||
"electron:pack": "npm run build && electron-builder build --dir -c ./electron-builder.config.json",
|
||||
"electron:make": "npm run build && electron-builder build -c ./electron-builder.config.json -p always"
|
||||
},
|
||||
"dependencies": {
|
||||
"@capacitor-community/electron": "^5.0.0",
|
||||
"@capacitor-community/sqlite": "^6.0.2",
|
||||
"better-sqlite3-multiple-ciphers": "^12.1.1",
|
||||
"chokidar": "~3.5.3",
|
||||
"crypto": "^1.0.1",
|
||||
"crypto-js": "^4.2.0",
|
||||
"electron-is-dev": "~2.0.0",
|
||||
"electron-json-storage": "^4.6.0",
|
||||
"electron-serve": "~1.1.0",
|
||||
"electron-unhandled": "~4.0.1",
|
||||
"electron-updater": "^5.3.0",
|
||||
"electron-window-state": "^5.0.3",
|
||||
"jszip": "^3.10.1",
|
||||
"node-fetch": "^2.6.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/better-sqlite3": "^7.6.13",
|
||||
"@types/crypto-js": "^4.2.2",
|
||||
"@types/electron-json-storage": "^4.5.4",
|
||||
"electron": "^26.2.2",
|
||||
"electron-builder": "~23.6.0",
|
||||
"electron-rebuild": "^3.2.9",
|
||||
"typescript": "~5.2.2"
|
||||
},
|
||||
"keywords": [
|
||||
"capacitor",
|
||||
"electron"
|
||||
]
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
/* eslint-disable no-undef */
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
const electronPublish = require('electron-publish');
|
||||
|
||||
class Publisher extends electronPublish.Publisher {
|
||||
async upload(task) {
|
||||
console.log('electron-publisher-custom', task.file);
|
||||
}
|
||||
}
|
||||
module.exports = Publisher;
|
||||
@@ -1,108 +0,0 @@
|
||||
import type { CapacitorElectronConfig } from '@capacitor-community/electron';
|
||||
import { getCapacitorElectronConfig, setupElectronDeepLinking } from '@capacitor-community/electron';
|
||||
import type { MenuItemConstructorOptions } from 'electron';
|
||||
import { app, MenuItem } from 'electron';
|
||||
import electronIsDev from 'electron-is-dev';
|
||||
import unhandled from 'electron-unhandled';
|
||||
import { autoUpdater } from 'electron-updater';
|
||||
|
||||
import { ElectronCapacitorApp, setupContentSecurityPolicy, setupReloadWatcher } from './setup';
|
||||
|
||||
// Graceful handling of unhandled errors.
|
||||
unhandled({
|
||||
logger: (error) => {
|
||||
// Suppress EPIPE errors which are common in AppImages due to console output issues
|
||||
if (error.message && error.message.includes('EPIPE')) {
|
||||
return; // Don't log EPIPE errors
|
||||
}
|
||||
console.error('Unhandled error:', error);
|
||||
}
|
||||
});
|
||||
|
||||
// Handle EPIPE errors on stdout/stderr to prevent crashes
|
||||
process.stdout.on('error', (err) => {
|
||||
if (err.code === 'EPIPE') {
|
||||
// Ignore EPIPE errors on stdout
|
||||
return;
|
||||
}
|
||||
console.error('stdout error:', err);
|
||||
});
|
||||
|
||||
process.stderr.on('error', (err) => {
|
||||
if (err.code === 'EPIPE') {
|
||||
// Ignore EPIPE errors on stderr
|
||||
return;
|
||||
}
|
||||
console.error('stderr error:', err);
|
||||
});
|
||||
|
||||
// Define our menu templates (these are optional)
|
||||
const trayMenuTemplate: (MenuItemConstructorOptions | MenuItem)[] = [new MenuItem({ label: 'Quit App', role: 'quit' })];
|
||||
const appMenuBarMenuTemplate: (MenuItemConstructorOptions | MenuItem)[] = [
|
||||
{ role: process.platform === 'darwin' ? 'appMenu' : 'fileMenu' },
|
||||
{ role: 'viewMenu' },
|
||||
];
|
||||
|
||||
// Get Config options from capacitor.config
|
||||
const capacitorFileConfig: CapacitorElectronConfig = getCapacitorElectronConfig();
|
||||
|
||||
// Initialize our app. You can pass menu templates into the app here.
|
||||
// const myCapacitorApp = new ElectronCapacitorApp(capacitorFileConfig);
|
||||
const myCapacitorApp = new ElectronCapacitorApp(capacitorFileConfig, trayMenuTemplate, appMenuBarMenuTemplate);
|
||||
|
||||
// If deeplinking is enabled then we will set it up here.
|
||||
if (capacitorFileConfig.electron?.deepLinkingEnabled) {
|
||||
setupElectronDeepLinking(myCapacitorApp, {
|
||||
customProtocol: capacitorFileConfig.electron.deepLinkingCustomProtocol ?? 'mycapacitorapp',
|
||||
});
|
||||
}
|
||||
|
||||
// If we are in Dev mode, use the file watcher components.
|
||||
if (electronIsDev) {
|
||||
setupReloadWatcher(myCapacitorApp);
|
||||
}
|
||||
|
||||
// Configure auto-updater
|
||||
autoUpdater.on('error', (error) => {
|
||||
console.log('Auto-updater error (suppressed):', error.message);
|
||||
// Don't show error dialogs for update check failures
|
||||
});
|
||||
|
||||
// Run Application
|
||||
(async () => {
|
||||
// Wait for electron app to be ready.
|
||||
await app.whenReady();
|
||||
// Security - Set Content-Security-Policy based on whether or not we are in dev mode.
|
||||
setupContentSecurityPolicy(myCapacitorApp.getCustomURLScheme());
|
||||
// Initialize our app, build windows, and load content.
|
||||
await myCapacitorApp.init();
|
||||
|
||||
// Only check for updates in production builds, not in development or AppImage
|
||||
if (!electronIsDev && !process.env.APPIMAGE) {
|
||||
try {
|
||||
autoUpdater.checkForUpdatesAndNotify();
|
||||
} catch (error) {
|
||||
console.log('Update check failed (suppressed):', error);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
// Handle when all of our windows are close (platforms have their own expectations).
|
||||
app.on('window-all-closed', function () {
|
||||
// On OS X it is common for applications and their menu bar
|
||||
// to stay active until the user quits explicitly with Cmd + Q
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
// When the dock icon is clicked.
|
||||
app.on('activate', async function () {
|
||||
// On OS X it's common to re-create a window in the app when the
|
||||
// dock icon is clicked and there are no other windows open.
|
||||
if (myCapacitorApp.getMainWindow().isDestroyed()) {
|
||||
await myCapacitorApp.init();
|
||||
}
|
||||
});
|
||||
|
||||
// Place all ipc or other electron api calls and custom functionality under this line
|
||||
@@ -1,4 +0,0 @@
|
||||
require('./rt/electron-rt');
|
||||
//////////////////////////////
|
||||
// User Defined Preload scripts below
|
||||
console.log('User Preload!');
|
||||
@@ -1,6 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
const CapacitorCommunitySqlite = require('../../../node_modules/@capacitor-community/sqlite/electron/dist/plugin.js');
|
||||
|
||||
module.exports = {
|
||||
CapacitorCommunitySqlite,
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
import { randomBytes } from 'crypto';
|
||||
import { ipcRenderer, contextBridge } from 'electron';
|
||||
import { EventEmitter } from 'events';
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const plugins = require('./electron-plugins');
|
||||
|
||||
const randomId = (length = 5) => randomBytes(length).toString('hex');
|
||||
|
||||
const contextApi: {
|
||||
[plugin: string]: { [functionName: string]: () => Promise<any> };
|
||||
} = {};
|
||||
|
||||
Object.keys(plugins).forEach((pluginKey) => {
|
||||
Object.keys(plugins[pluginKey])
|
||||
.filter((className) => className !== 'default')
|
||||
.forEach((classKey) => {
|
||||
const functionList = Object.getOwnPropertyNames(plugins[pluginKey][classKey].prototype).filter(
|
||||
(v) => v !== 'constructor'
|
||||
);
|
||||
|
||||
if (!contextApi[classKey]) {
|
||||
contextApi[classKey] = {};
|
||||
}
|
||||
|
||||
functionList.forEach((functionName) => {
|
||||
if (!contextApi[classKey][functionName]) {
|
||||
contextApi[classKey][functionName] = (...args) => ipcRenderer.invoke(`${classKey}-${functionName}`, ...args);
|
||||
}
|
||||
});
|
||||
|
||||
// Events
|
||||
if (plugins[pluginKey][classKey].prototype instanceof EventEmitter) {
|
||||
const listeners: { [key: string]: { type: string; listener: (...args: any[]) => void } } = {};
|
||||
const listenersOfTypeExist = (type) =>
|
||||
!!Object.values(listeners).find((listenerObj) => listenerObj.type === type);
|
||||
|
||||
Object.assign(contextApi[classKey], {
|
||||
addListener(type: string, callback: (...args) => void) {
|
||||
const id = randomId();
|
||||
|
||||
// Deduplicate events
|
||||
if (!listenersOfTypeExist(type)) {
|
||||
ipcRenderer.send(`event-add-${classKey}`, type);
|
||||
}
|
||||
|
||||
const eventHandler = (_, ...args) => callback(...args);
|
||||
|
||||
ipcRenderer.addListener(`event-${classKey}-${type}`, eventHandler);
|
||||
listeners[id] = { type, listener: eventHandler };
|
||||
|
||||
return id;
|
||||
},
|
||||
removeListener(id: string) {
|
||||
if (!listeners[id]) {
|
||||
throw new Error('Invalid id');
|
||||
}
|
||||
|
||||
const { type, listener } = listeners[id];
|
||||
|
||||
ipcRenderer.removeListener(`event-${classKey}-${type}`, listener);
|
||||
|
||||
delete listeners[id];
|
||||
|
||||
if (!listenersOfTypeExist(type)) {
|
||||
ipcRenderer.send(`event-remove-${classKey}-${type}`);
|
||||
}
|
||||
},
|
||||
removeAllListeners(type: string) {
|
||||
Object.entries(listeners).forEach(([id, listenerObj]) => {
|
||||
if (!type || listenerObj.type === type) {
|
||||
ipcRenderer.removeListener(`event-${classKey}-${listenerObj.type}`, listenerObj.listener);
|
||||
ipcRenderer.send(`event-remove-${classKey}-${listenerObj.type}`);
|
||||
delete listeners[id];
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
contextBridge.exposeInMainWorld('CapacitorCustomPlatform', {
|
||||
name: 'electron',
|
||||
plugins: contextApi,
|
||||
});
|
||||
////////////////////////////////////////////////////////
|
||||
@@ -1,233 +0,0 @@
|
||||
import type { CapacitorElectronConfig } from '@capacitor-community/electron';
|
||||
import {
|
||||
CapElectronEventEmitter,
|
||||
CapacitorSplashScreen,
|
||||
setupCapacitorElectronPlugins,
|
||||
} from '@capacitor-community/electron';
|
||||
import chokidar from 'chokidar';
|
||||
import type { MenuItemConstructorOptions } from 'electron';
|
||||
import { app, BrowserWindow, Menu, MenuItem, nativeImage, Tray, session } from 'electron';
|
||||
import electronIsDev from 'electron-is-dev';
|
||||
import electronServe from 'electron-serve';
|
||||
import windowStateKeeper from 'electron-window-state';
|
||||
import { join } from 'path';
|
||||
|
||||
// Define components for a watcher to detect when the webapp is changed so we can reload in Dev mode.
|
||||
const reloadWatcher = {
|
||||
debouncer: null,
|
||||
ready: false,
|
||||
watcher: null,
|
||||
};
|
||||
export function setupReloadWatcher(electronCapacitorApp: ElectronCapacitorApp): void {
|
||||
reloadWatcher.watcher = chokidar
|
||||
.watch(join(app.getAppPath(), 'app'), {
|
||||
ignored: /[/\\]\./,
|
||||
persistent: true,
|
||||
})
|
||||
.on('ready', () => {
|
||||
reloadWatcher.ready = true;
|
||||
})
|
||||
.on('all', (_event, _path) => {
|
||||
if (reloadWatcher.ready) {
|
||||
clearTimeout(reloadWatcher.debouncer);
|
||||
reloadWatcher.debouncer = setTimeout(async () => {
|
||||
electronCapacitorApp.getMainWindow().webContents.reload();
|
||||
reloadWatcher.ready = false;
|
||||
clearTimeout(reloadWatcher.debouncer);
|
||||
reloadWatcher.debouncer = null;
|
||||
reloadWatcher.watcher = null;
|
||||
setupReloadWatcher(electronCapacitorApp);
|
||||
}, 1500);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Define our class to manage our app.
|
||||
export class ElectronCapacitorApp {
|
||||
private MainWindow: BrowserWindow | null = null;
|
||||
private SplashScreen: CapacitorSplashScreen | null = null;
|
||||
private TrayIcon: Tray | null = null;
|
||||
private CapacitorFileConfig: CapacitorElectronConfig;
|
||||
private TrayMenuTemplate: (MenuItem | MenuItemConstructorOptions)[] = [
|
||||
new MenuItem({ label: 'Quit App', role: 'quit' }),
|
||||
];
|
||||
private AppMenuBarMenuTemplate: (MenuItem | MenuItemConstructorOptions)[] = [
|
||||
{ role: process.platform === 'darwin' ? 'appMenu' : 'fileMenu' },
|
||||
{ role: 'viewMenu' },
|
||||
];
|
||||
private mainWindowState;
|
||||
private loadWebApp;
|
||||
private customScheme: string;
|
||||
|
||||
constructor(
|
||||
capacitorFileConfig: CapacitorElectronConfig,
|
||||
trayMenuTemplate?: (MenuItemConstructorOptions | MenuItem)[],
|
||||
appMenuBarMenuTemplate?: (MenuItemConstructorOptions | MenuItem)[]
|
||||
) {
|
||||
this.CapacitorFileConfig = capacitorFileConfig;
|
||||
|
||||
this.customScheme = this.CapacitorFileConfig.electron?.customUrlScheme ?? 'capacitor-electron';
|
||||
|
||||
if (trayMenuTemplate) {
|
||||
this.TrayMenuTemplate = trayMenuTemplate;
|
||||
}
|
||||
|
||||
if (appMenuBarMenuTemplate) {
|
||||
this.AppMenuBarMenuTemplate = appMenuBarMenuTemplate;
|
||||
}
|
||||
|
||||
// Setup our web app loader, this lets us load apps like react, vue, and angular without changing their build chains.
|
||||
this.loadWebApp = electronServe({
|
||||
directory: join(app.getAppPath(), 'app'),
|
||||
scheme: this.customScheme,
|
||||
});
|
||||
}
|
||||
|
||||
// Helper function to load in the app.
|
||||
private async loadMainWindow(thisRef: any) {
|
||||
await thisRef.loadWebApp(thisRef.MainWindow);
|
||||
}
|
||||
|
||||
// Expose the mainWindow ref for use outside of the class.
|
||||
getMainWindow(): BrowserWindow {
|
||||
return this.MainWindow;
|
||||
}
|
||||
|
||||
getCustomURLScheme(): string {
|
||||
return this.customScheme;
|
||||
}
|
||||
|
||||
async init(): Promise<void> {
|
||||
const icon = nativeImage.createFromPath(
|
||||
join(app.getAppPath(), 'assets', process.platform === 'win32' ? 'appIcon.ico' : 'appIcon.png')
|
||||
);
|
||||
this.mainWindowState = windowStateKeeper({
|
||||
defaultWidth: 1000,
|
||||
defaultHeight: 800,
|
||||
});
|
||||
// Setup preload script path and construct our main window.
|
||||
const preloadPath = join(app.getAppPath(), 'build', 'src', 'preload.js');
|
||||
this.MainWindow = new BrowserWindow({
|
||||
icon,
|
||||
show: false,
|
||||
x: this.mainWindowState.x,
|
||||
y: this.mainWindowState.y,
|
||||
width: this.mainWindowState.width,
|
||||
height: this.mainWindowState.height,
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
contextIsolation: true,
|
||||
// Use preload to inject the electron varriant overrides for capacitor plugins.
|
||||
// preload: join(app.getAppPath(), "node_modules", "@capacitor-community", "electron", "dist", "runtime", "electron-rt.js"),
|
||||
preload: preloadPath,
|
||||
},
|
||||
});
|
||||
this.mainWindowState.manage(this.MainWindow);
|
||||
|
||||
if (this.CapacitorFileConfig.backgroundColor) {
|
||||
this.MainWindow.setBackgroundColor(this.CapacitorFileConfig.electron.backgroundColor);
|
||||
}
|
||||
|
||||
// If we close the main window with the splashscreen enabled we need to destory the ref.
|
||||
this.MainWindow.on('closed', () => {
|
||||
if (this.SplashScreen?.getSplashWindow() && !this.SplashScreen.getSplashWindow().isDestroyed()) {
|
||||
this.SplashScreen.getSplashWindow().close();
|
||||
}
|
||||
});
|
||||
|
||||
// When the tray icon is enabled, setup the options.
|
||||
if (this.CapacitorFileConfig.electron?.trayIconAndMenuEnabled) {
|
||||
this.TrayIcon = new Tray(icon);
|
||||
this.TrayIcon.on('double-click', () => {
|
||||
if (this.MainWindow) {
|
||||
if (this.MainWindow.isVisible()) {
|
||||
this.MainWindow.hide();
|
||||
} else {
|
||||
this.MainWindow.show();
|
||||
this.MainWindow.focus();
|
||||
}
|
||||
}
|
||||
});
|
||||
this.TrayIcon.on('click', () => {
|
||||
if (this.MainWindow) {
|
||||
if (this.MainWindow.isVisible()) {
|
||||
this.MainWindow.hide();
|
||||
} else {
|
||||
this.MainWindow.show();
|
||||
this.MainWindow.focus();
|
||||
}
|
||||
}
|
||||
});
|
||||
this.TrayIcon.setToolTip(app.getName());
|
||||
this.TrayIcon.setContextMenu(Menu.buildFromTemplate(this.TrayMenuTemplate));
|
||||
}
|
||||
|
||||
// Setup the main manu bar at the top of our window.
|
||||
Menu.setApplicationMenu(Menu.buildFromTemplate(this.AppMenuBarMenuTemplate));
|
||||
|
||||
// If the splashscreen is enabled, show it first while the main window loads then switch it out for the main window, or just load the main window from the start.
|
||||
if (this.CapacitorFileConfig.electron?.splashScreenEnabled) {
|
||||
this.SplashScreen = new CapacitorSplashScreen({
|
||||
imageFilePath: join(
|
||||
app.getAppPath(),
|
||||
'assets',
|
||||
this.CapacitorFileConfig.electron?.splashScreenImageName ?? 'splash.png'
|
||||
),
|
||||
windowWidth: 400,
|
||||
windowHeight: 400,
|
||||
});
|
||||
this.SplashScreen.init(this.loadMainWindow, this);
|
||||
} else {
|
||||
this.loadMainWindow(this);
|
||||
}
|
||||
|
||||
// Security
|
||||
this.MainWindow.webContents.setWindowOpenHandler((details) => {
|
||||
if (!details.url.includes(this.customScheme)) {
|
||||
return { action: 'deny' };
|
||||
} else {
|
||||
return { action: 'allow' };
|
||||
}
|
||||
});
|
||||
this.MainWindow.webContents.on('will-navigate', (event, _newURL) => {
|
||||
if (!this.MainWindow.webContents.getURL().includes(this.customScheme)) {
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
// Link electron plugins into the system.
|
||||
setupCapacitorElectronPlugins();
|
||||
|
||||
// When the web app is loaded we hide the splashscreen if needed and show the mainwindow.
|
||||
this.MainWindow.webContents.on('dom-ready', () => {
|
||||
if (this.CapacitorFileConfig.electron?.splashScreenEnabled) {
|
||||
this.SplashScreen.getSplashWindow().hide();
|
||||
}
|
||||
if (!this.CapacitorFileConfig.electron?.hideMainWindowOnLaunch) {
|
||||
this.MainWindow.show();
|
||||
}
|
||||
setTimeout(() => {
|
||||
if (electronIsDev) {
|
||||
this.MainWindow.webContents.openDevTools();
|
||||
}
|
||||
CapElectronEventEmitter.emit('CAPELECTRON_DeeplinkListenerInitialized', '');
|
||||
}, 400);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Set a CSP up for our application based on the custom scheme
|
||||
export function setupContentSecurityPolicy(customScheme: string): void {
|
||||
session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
|
||||
callback({
|
||||
responseHeaders: {
|
||||
...details.responseHeaders,
|
||||
'Content-Security-Policy': [
|
||||
electronIsDev
|
||||
? `default-src ${customScheme}://* 'unsafe-inline' devtools://* 'unsafe-eval' data: https:; style-src ${customScheme}://* 'unsafe-inline' https://fonts.googleapis.com; font-src ${customScheme}://* https://fonts.gstatic.com data:`
|
||||
: `default-src ${customScheme}://* 'unsafe-inline' data: https:; style-src ${customScheme}://* 'unsafe-inline' https://fonts.googleapis.com; font-src ${customScheme}://* https://fonts.gstatic.com data:`,
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
{
|
||||
"compileOnSave": true,
|
||||
"include": ["./src/**/*", "./capacitor.config.ts", "./capacitor.config.js"],
|
||||
"compilerOptions": {
|
||||
"outDir": "./build",
|
||||
"importHelpers": true,
|
||||
"target": "ES2017",
|
||||
"module": "CommonJS",
|
||||
"moduleResolution": "node",
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"typeRoots": ["./node_modules/@types"],
|
||||
"allowJs": true,
|
||||
"rootDir": ".",
|
||||
"skipLibCheck": true,
|
||||
"strict": false,
|
||||
"noImplicitAny": false
|
||||
}
|
||||
}
|
||||
155
experiment.sh
155
experiment.sh
@@ -1,155 +0,0 @@
|
||||
#!/bin/bash
|
||||
# experiment.sh
|
||||
# Author: Matthew Raymer
|
||||
# Description: Build script for TimeSafari Electron application
|
||||
# This script handles the complete build process for the TimeSafari Electron app,
|
||||
# including web asset compilation and Capacitor sync.
|
||||
#
|
||||
# Build Process:
|
||||
# 1. Environment setup and dependency checks
|
||||
# 2. Web asset compilation (Vite)
|
||||
# 3. Capacitor sync
|
||||
# 4. Electron start
|
||||
#
|
||||
# Dependencies:
|
||||
# - Node.js and npm
|
||||
# - TypeScript
|
||||
# - Vite
|
||||
# - @capacitor-community/electron
|
||||
#
|
||||
# Usage: ./experiment.sh
|
||||
#
|
||||
# Exit Codes:
|
||||
# 1 - Required command not found
|
||||
# 2 - TypeScript installation failed
|
||||
# 3 - Build process failed
|
||||
# 4 - Capacitor sync failed
|
||||
# 5 - Electron start failed
|
||||
|
||||
# Exit on any error
|
||||
set -e
|
||||
|
||||
# ANSI color codes for better output formatting
|
||||
readonly RED='\033[0;31m'
|
||||
readonly GREEN='\033[0;32m'
|
||||
readonly YELLOW='\033[1;33m'
|
||||
readonly BLUE='\033[0;34m'
|
||||
readonly NC='\033[0m' # No Color
|
||||
|
||||
# Logging functions
|
||||
log_info() {
|
||||
echo -e "${BLUE}[$(date '+%Y-%m-%d %H:%M:%S')] [INFO]${NC} $1"
|
||||
}
|
||||
|
||||
log_success() {
|
||||
echo -e "${GREEN}[$(date '+%Y-%m-%d %H:%M:%S')] [SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
log_warn() {
|
||||
echo -e "${YELLOW}[$(date '+%Y-%m-%d %H:%M:%S')] [WARN]${NC} $1"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo -e "${RED}[$(date '+%Y-%m-%d %H:%M:%S')] [ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Function to check if a command exists
|
||||
check_command() {
|
||||
if ! command -v "$1" &> /dev/null; then
|
||||
log_error "$1 is required but not installed."
|
||||
exit 1
|
||||
fi
|
||||
log_info "Found $1: $(command -v "$1")"
|
||||
}
|
||||
|
||||
# Function to measure and log execution time
|
||||
measure_time() {
|
||||
local start_time=$(date +%s)
|
||||
"$@"
|
||||
local end_time=$(date +%s)
|
||||
local duration=$((end_time - start_time))
|
||||
log_success "Completed in ${duration} seconds"
|
||||
}
|
||||
|
||||
# Print build header
|
||||
echo -e "\n${BLUE}=== TimeSafari Electron Build Process ===${NC}\n"
|
||||
log_info "Starting build process at $(date)"
|
||||
|
||||
# Check required commands
|
||||
log_info "Checking required dependencies..."
|
||||
check_command node
|
||||
check_command npm
|
||||
check_command git
|
||||
|
||||
# Create application data directory
|
||||
log_info "Setting up application directories..."
|
||||
mkdir -p ~/.local/share/TimeSafari/timesafari
|
||||
|
||||
# Clean up previous builds
|
||||
log_info "Cleaning previous builds..."
|
||||
rm -rf dist* || log_warn "No previous builds to clean"
|
||||
|
||||
# Set environment variables for the build
|
||||
log_info "Configuring build environment..."
|
||||
export VITE_PLATFORM=electron
|
||||
export VITE_PWA_ENABLED=false
|
||||
export VITE_DISABLE_PWA=true
|
||||
export DEBUG_MIGRATIONS=0
|
||||
|
||||
# Ensure TypeScript is installed
|
||||
log_info "Verifying TypeScript installation..."
|
||||
if [ ! -f "./node_modules/.bin/tsc" ]; then
|
||||
log_info "Installing TypeScript..."
|
||||
if ! npm install --save-dev typescript@~5.2.2; then
|
||||
log_error "TypeScript installation failed!"
|
||||
exit 2
|
||||
fi
|
||||
# Verify installation
|
||||
if [ ! -f "./node_modules/.bin/tsc" ]; then
|
||||
log_error "TypeScript installation verification failed!"
|
||||
exit 2
|
||||
fi
|
||||
log_success "TypeScript installed successfully"
|
||||
else
|
||||
log_info "TypeScript already installed"
|
||||
fi
|
||||
|
||||
# Get git hash for versioning
|
||||
GIT_HASH=$(git log -1 --pretty=format:%h)
|
||||
log_info "Using git hash: ${GIT_HASH}"
|
||||
|
||||
# Build web assets
|
||||
log_info "Building web assets with Vite..."
|
||||
if ! measure_time env VITE_GIT_HASH="$GIT_HASH" npx vite build --config vite.config.app.electron.mts --mode electron; then
|
||||
log_error "Web asset build failed!"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
# Sync with Capacitor
|
||||
log_info "Syncing with Capacitor..."
|
||||
if ! measure_time npx cap sync electron; then
|
||||
log_error "Capacitor sync failed!"
|
||||
exit 4
|
||||
fi
|
||||
|
||||
# Restore capacitor config
|
||||
log_info "Restoring capacitor config..."
|
||||
if ! git checkout electron/capacitor.config.json; then
|
||||
log_error "Failed to restore capacitor config!"
|
||||
exit 4
|
||||
fi
|
||||
|
||||
# Start Electron
|
||||
log_info "Starting Electron..."
|
||||
cd electron/
|
||||
if ! measure_time npm run electron:start; then
|
||||
log_error "Electron start failed!"
|
||||
exit 5
|
||||
fi
|
||||
|
||||
# Print build summary
|
||||
log_success "Build and start completed successfully!"
|
||||
echo -e "\n${GREEN}=== End of Build Process ===${NC}\n"
|
||||
|
||||
# Exit with success
|
||||
exit 0
|
||||
@@ -18,10 +18,14 @@
|
||||
case 'capacitor':
|
||||
import('./src/main.capacitor.ts');
|
||||
break;
|
||||
case 'web':
|
||||
case 'electron':
|
||||
import('./src/main.electron.ts');
|
||||
break;
|
||||
case 'pywebview':
|
||||
import('./src/main.pywebview.ts');
|
||||
break;
|
||||
default:
|
||||
import('./src/main.web.ts');
|
||||
break;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
@@ -403,7 +403,7 @@
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 35;
|
||||
CURRENT_PROJECT_VERSION = 30;
|
||||
DEVELOPMENT_TEAM = GM3FS5JQPH;
|
||||
ENABLE_APP_SANDBOX = NO;
|
||||
ENABLE_USER_SCRIPT_SANDBOXING = NO;
|
||||
@@ -413,7 +413,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.0.2;
|
||||
MARKETING_VERSION = 0.5.4;
|
||||
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\"";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = app.timesafari;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
@@ -430,7 +430,7 @@
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 35;
|
||||
CURRENT_PROJECT_VERSION = 30;
|
||||
DEVELOPMENT_TEAM = GM3FS5JQPH;
|
||||
ENABLE_APP_SANDBOX = NO;
|
||||
ENABLE_USER_SCRIPT_SANDBOXING = NO;
|
||||
@@ -440,7 +440,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.0.2;
|
||||
MARKETING_VERSION = 0.5.4;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = app.timesafari;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "";
|
||||
|
||||
@@ -49,16 +49,5 @@
|
||||
</array>
|
||||
<key>UIViewControllerBasedStatusBarAppearance</key>
|
||||
<true/>
|
||||
<key>CFBundleURLTypes</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>CFBundleURLName</key>
|
||||
<string>app.timesafari</string>
|
||||
<key>CFBundleURLSchemes</key>
|
||||
<array>
|
||||
<string>timesafari</string>
|
||||
</array>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
2835
package-lock.json
generated
2835
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
101
package.json
101
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "timesafari",
|
||||
"version": "1.0.3-beta",
|
||||
"version": "0.5.4",
|
||||
"description": "Time Safari Application",
|
||||
"author": {
|
||||
"name": "Time Safari Team"
|
||||
@@ -12,37 +12,40 @@
|
||||
"lint": "eslint --ext .js,.ts,.vue --ignore-path .gitignore src",
|
||||
"lint-fix": "eslint --ext .js,.ts,.vue --ignore-path .gitignore --fix src",
|
||||
"prebuild": "eslint --ext .js,.ts,.vue --ignore-path .gitignore src && node sw_combine.js && node scripts/copy-wasm.js",
|
||||
"test:all": "./scripts/test-all.sh",
|
||||
"test:all": "npm run test:prerequisites && npm run build && npm run test:web && npm run test:mobile",
|
||||
"test:prerequisites": "node scripts/check-prerequisites.js",
|
||||
"test:web": "npx playwright test -c playwright.config-local.ts --trace on",
|
||||
"test:mobile": "./scripts/test-mobile.sh",
|
||||
"test:mobile": "npm run build:capacitor && npm run test:android && npm run test:ios",
|
||||
"test:android": "node scripts/test-android.js",
|
||||
"test:ios": "node scripts/test-ios.js",
|
||||
"check:android-device": "adb devices | grep -w 'device' || (echo 'No Android device connected' && exit 1)",
|
||||
"check:ios-device": "xcrun xctrace list devices 2>&1 | grep -w 'Booted' || (echo 'No iOS simulator running' && exit 1)",
|
||||
"build:capacitor": "VITE_GIT_HASH=`git log -1 --pretty=format:%h` vite build --mode capacitor --config vite.config.capacitor.mts",
|
||||
"clean:electron": "rimraf dist-electron",
|
||||
"build:pywebview": "vite build --config vite.config.pywebview.mts",
|
||||
"build:electron": "npm run clean:electron && tsc -p tsconfig.electron.json && vite build --config vite.config.electron.mts && node scripts/build-electron.js",
|
||||
"build:capacitor": "vite build --mode capacitor --config vite.config.capacitor.mts",
|
||||
"build:web": "VITE_GIT_HASH=`git log -1 --pretty=format:%h` vite build --config vite.config.web.mts",
|
||||
"electron:dev": "npm run build:capacitor && npx cap copy electron && cd electron && npm run electron:start",
|
||||
"electron:setup": "./scripts/setup-electron.sh",
|
||||
"electron:dev-full": "./scripts/electron-dev.sh",
|
||||
"electron:build": "npm run build:capacitor && npx cap copy electron && cd electron && ./build-packages.sh",
|
||||
"electron:build:appimage": "npm run build:capacitor && npx cap copy electron && cd electron && ./build-packages.sh appimage",
|
||||
"electron:build:deb": "npm run build:capacitor && npx cap copy electron && cd electron && ./build-packages.sh deb",
|
||||
"electron:dev": "npm run build && electron .",
|
||||
"electron:start": "electron .",
|
||||
"clean:android": "adb uninstall app.timesafari.app || true",
|
||||
"clean:electron": "rm -rf electron/app/* electron/dist/* || true",
|
||||
"clean:ios": "rm -rf ios/App/build ios/App/Pods ios/App/output ios/App/App/public ios/DerivedData ios/capacitor-cordova-ios-plugins ios/App/App/capacitor.config.json ios/App/App/config.xml || true",
|
||||
"build:android": "./scripts/build-android.sh",
|
||||
"build:electron": "./scripts/build-electron.sh",
|
||||
"build:electron:package": "./scripts/build-electron.sh --package",
|
||||
"build:electron:appimage": "./scripts/build-electron.sh --appimage",
|
||||
"build:electron:deb": "./scripts/build-electron.sh --deb",
|
||||
"build:android": "npm run clean:android && rm -rf dist && npm run build:web && npm run build:capacitor && cd android && ./gradlew clean && ./gradlew assembleDebug && cd .. && npx cap sync android && npx capacitor-assets generate --android && npx cap open android",
|
||||
"electron:build-linux": "npm run build:electron && electron-builder --linux AppImage",
|
||||
"electron:build-linux-deb": "npm run build:electron && electron-builder --linux deb",
|
||||
"electron:build-linux-prod": "NODE_ENV=production npm run build:electron && electron-builder --linux AppImage",
|
||||
"build:electron-prod": "NODE_ENV=production npm run build:electron",
|
||||
"pywebview:dev": "vite build --config vite.config.pywebview.mts && .venv/bin/python src/pywebview/main.py",
|
||||
"pywebview:build": "vite build --config vite.config.pywebview.mts && .venv/bin/python src/pywebview/main.py",
|
||||
"pywebview:package-linux": "vite build --mode pywebview --config vite.config.pywebview.mts && .venv/bin/python -m PyInstaller --name TimeSafari --add-data 'dist:www' src/pywebview/main.py",
|
||||
"pywebview:package-win": "vite build --mode pywebview --config vite.config.pywebview.mts && .venv/Scripts/python -m PyInstaller --name TimeSafari --add-data 'dist;www' src/pywebview/main.py",
|
||||
"pywebview:package-mac": "vite build --mode pywebview --config vite.config.pywebview.mts && .venv/bin/python -m PyInstaller --name TimeSafari --add-data 'dist:www' src/pywebview/main.py",
|
||||
"fastlane:ios:beta": "cd ios && fastlane beta",
|
||||
"fastlane:ios:release": "cd ios && fastlane release",
|
||||
"fastlane:android:beta": "cd android && fastlane beta",
|
||||
"fastlane:android:release": "cd android && fastlane release"
|
||||
"fastlane:android:release": "cd android && fastlane release",
|
||||
"electron:build-mac": "npm run build:electron-prod && electron-builder --mac",
|
||||
"electron:build-mac-universal": "npm run build:electron-prod && electron-builder --mac --universal"
|
||||
},
|
||||
"dependencies": {
|
||||
"@capacitor-community/electron": "^5.0.1",
|
||||
"@capacitor-community/sqlite": "6.0.2",
|
||||
"@capacitor-mlkit/barcode-scanning": "^6.0.0",
|
||||
"@capacitor/android": "^6.2.0",
|
||||
@@ -62,7 +65,6 @@
|
||||
"@fortawesome/free-solid-svg-icons": "^6.5.1",
|
||||
"@fortawesome/vue-fontawesome": "^3.0.6",
|
||||
"@jlongster/sql.js": "^1.6.7",
|
||||
"@nostr/tools": "npm:@jsr/nostr__tools@^2.15.0",
|
||||
"@peculiar/asn1-ecc": "^2.3.8",
|
||||
"@peculiar/asn1-schema": "^2.3.8",
|
||||
"@pvermeer/dexie-encrypted-addon": "^3.0.0",
|
||||
@@ -91,7 +93,6 @@
|
||||
"did-jwt": "^7.4.7",
|
||||
"did-resolver": "^4.1.0",
|
||||
"dotenv": "^16.0.3",
|
||||
"electron-builder": "^26.0.12",
|
||||
"ethereum-cryptography": "^2.1.3",
|
||||
"ethereumjs-util": "^7.1.5",
|
||||
"jdenticon": "^3.2.0",
|
||||
@@ -103,6 +104,7 @@
|
||||
"lru-cache": "^10.2.0",
|
||||
"luxon": "^3.4.4",
|
||||
"merkletreejs": "^0.3.11",
|
||||
"nostr-tools": "^2.10.4",
|
||||
"notiwind": "^2.0.2",
|
||||
"papaparse": "^5.4.1",
|
||||
"pina": "^0.20.2204228",
|
||||
@@ -145,11 +147,11 @@
|
||||
"@vitejs/plugin-vue": "^5.2.1",
|
||||
"@vue/eslint-config-typescript": "^11.0.3",
|
||||
"autoprefixer": "^10.4.19",
|
||||
"better-sqlite3-multiple-ciphers": "^12.1.1",
|
||||
"browserify-fs": "^1.0.0",
|
||||
"concurrently": "^8.2.2",
|
||||
"crypto-browserify": "^3.12.1",
|
||||
"electron-json-storage": "^4.6.0",
|
||||
"electron": "^33.2.1",
|
||||
"electron-builder": "^25.1.8",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-plugin-prettier": "^5.2.1",
|
||||
@@ -166,5 +168,58 @@
|
||||
"typescript": "~5.2.2",
|
||||
"vite": "^5.2.0",
|
||||
"vite-plugin-pwa": "^1.0.0"
|
||||
},
|
||||
"main": "./dist-electron/main.js",
|
||||
"build": {
|
||||
"appId": "app.timesafari.app",
|
||||
"productName": "TimeSafari",
|
||||
"directories": {
|
||||
"output": "dist-electron-packages"
|
||||
},
|
||||
"files": [
|
||||
"dist-electron/**/*",
|
||||
"dist/**/*"
|
||||
],
|
||||
"extraResources": [
|
||||
{
|
||||
"from": "dist-electron/www",
|
||||
"to": "www"
|
||||
}
|
||||
],
|
||||
"linux": {
|
||||
"target": [
|
||||
"AppImage",
|
||||
"deb"
|
||||
],
|
||||
"category": "Office",
|
||||
"icon": "build/icon.png"
|
||||
},
|
||||
"asar": true,
|
||||
"mac": {
|
||||
"target": [
|
||||
"dmg",
|
||||
"zip"
|
||||
],
|
||||
"category": "public.app-category.productivity",
|
||||
"icon": "build/icon.png",
|
||||
"hardenedRuntime": true,
|
||||
"gatekeeperAssess": false,
|
||||
"entitlements": "ios/App/App/entitlements.mac.plist",
|
||||
"entitlementsInherit": "ios/App/App/entitlements.mac.plist"
|
||||
},
|
||||
"dmg": {
|
||||
"contents": [
|
||||
{
|
||||
"x": 130,
|
||||
"y": 220
|
||||
},
|
||||
{
|
||||
"x": 410,
|
||||
"y": 220,
|
||||
"type": "link",
|
||||
"path": "/Applications"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
6
requirements.txt
Normal file
6
requirements.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
eth_keys
|
||||
pywebview
|
||||
pyinstaller>=6.12.0
|
||||
setuptools>=69.0.0 # Required for distutils for electron-builder on macOS
|
||||
# For development
|
||||
watchdog>=3.0.0 # For file watching support
|
||||
@@ -1,280 +0,0 @@
|
||||
# TimeSafari Build Scripts
|
||||
|
||||
This directory contains unified build and test scripts for the TimeSafari application. All scripts use a common utilities library to eliminate redundancy and provide consistent logging, error handling, timing, and environment variable management.
|
||||
|
||||
## Architecture
|
||||
|
||||
### Common Utilities (`common.sh`)
|
||||
|
||||
The `common.sh` script provides shared functionality used by all build scripts:
|
||||
|
||||
- **Logging Functions**: `log_info`, `log_success`, `log_warn`, `log_error`, `log_debug`, `log_step`
|
||||
- **Timing**: `measure_time` for execution time tracking
|
||||
- **Headers/Footers**: `print_header`, `print_footer` for consistent output formatting
|
||||
- **Validation**: `check_command`, `check_directory`, `check_file`, `check_venv`
|
||||
- **Execution**: `safe_execute` for error-handled command execution
|
||||
- **Utilities**: `get_git_hash`, `clean_build_artifacts`, `validate_env_vars`
|
||||
- **Environment Management**: `setup_build_env`, `setup_app_directories`, `load_env_file`, `print_env_vars`
|
||||
- **CLI**: `parse_args`, `print_usage` for command-line argument handling
|
||||
|
||||
### Environment Variable Management
|
||||
|
||||
All scripts automatically handle environment variables for different build types:
|
||||
|
||||
#### Build Types and Environment Variables
|
||||
|
||||
| Platform | Mode | PWA Enabled | Native Features | Build Script |
|
||||
|----------|------|-------------|-----------------|--------------|
|
||||
| `web` | web | true | false | `build-web.sh` |
|
||||
| `capacitor` | capacitor | false | true | `build-capacitor.sh` |
|
||||
|
||||
#### Automatic Environment Setup
|
||||
|
||||
Each script automatically:
|
||||
1. **Sets platform-specific variables** based on build type
|
||||
2. **Gets git hash** for versioning (`VITE_GIT_HASH`)
|
||||
3. **Creates application directories** (`~/.local/share/TimeSafari/timesafari`)
|
||||
4. **Loads .env file** if it exists
|
||||
5. **Validates required variables** when needed
|
||||
|
||||
#### Environment Functions
|
||||
|
||||
- `setup_build_env(build_type, production)` - Sets environment for specific build type
|
||||
- `setup_app_directories()` - Creates necessary application directories
|
||||
- `load_env_file(filename)` - Loads variables from .env file
|
||||
- `print_env_vars(prefix)` - Displays current environment variables
|
||||
- `validate_env_vars(var1, var2, ...)` - Validates required variables exist
|
||||
|
||||
### Script Structure
|
||||
|
||||
All scripts follow this unified pattern:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
# script-name.sh
|
||||
# Author: Matthew Raymer
|
||||
# Description: Brief description of what the script does
|
||||
#
|
||||
# Exit Codes: List of exit codes and their meanings
|
||||
# Usage: ./scripts/script-name.sh [options]
|
||||
|
||||
# Exit on any error
|
||||
set -e
|
||||
|
||||
# Source common utilities
|
||||
source "$(dirname "$0")/common.sh"
|
||||
|
||||
# Parse command line arguments
|
||||
parse_args "$@"
|
||||
|
||||
# Print header
|
||||
print_header "Script Title"
|
||||
log_info "Starting process at $(date)"
|
||||
|
||||
# Setup environment (automatic)
|
||||
setup_build_env "build_type"
|
||||
setup_app_directories
|
||||
load_env_file ".env"
|
||||
|
||||
# Execute steps with safe_execute
|
||||
safe_execute "Step description" "command to execute" || exit 1
|
||||
|
||||
# Print footer
|
||||
print_footer "Script Title"
|
||||
exit 0
|
||||
```
|
||||
|
||||
## Available Scripts
|
||||
|
||||
### Test Scripts
|
||||
|
||||
- **`test-all.sh`**: Comprehensive test suite (prerequisites, build, web tests, mobile tests)
|
||||
- **`test-mobile.sh`**: Mobile test suite (Capacitor build, Android tests, iOS tests)
|
||||
- **`test-common.sh`**: Test script to verify common utilities work correctly
|
||||
- **`test-env.sh`**: Test script to verify environment variable handling
|
||||
|
||||
### Build Scripts
|
||||
|
||||
- **`build-android.sh`**: Complete Android build process
|
||||
|
||||
### Development Scripts
|
||||
|
||||
- **`electron-dev.sh`**: Electron development workflow
|
||||
|
||||
## Benefits of Unification
|
||||
|
||||
### Before (Redundant)
|
||||
```bash
|
||||
# Each script had 50+ lines of duplicate code:
|
||||
readonly RED='\033[0;31m'
|
||||
readonly GREEN='\033[0;32m'
|
||||
# ... 40+ more lines of duplicate logging functions
|
||||
log_info "Step 1/4: Doing something..."
|
||||
if ! measure_time some_command; then
|
||||
log_error "Step failed!"
|
||||
exit 1
|
||||
fi
|
||||
# Manual environment variable setup
|
||||
export VITE_PLATFORM=electron
|
||||
export VITE_PWA_ENABLED=false
|
||||
# ... more manual exports
|
||||
```
|
||||
|
||||
### After (Unified)
|
||||
```bash
|
||||
# Each script is now ~20 lines of focused logic:
|
||||
source "$(dirname "$0")/common.sh"
|
||||
print_header "Script Title"
|
||||
setup_build_env "electron" # Automatic environment setup
|
||||
safe_execute "Step description" "some_command" || exit 1
|
||||
print_footer "Script Title"
|
||||
```
|
||||
|
||||
## Usage Examples
|
||||
|
||||
### Running Tests
|
||||
```bash
|
||||
# Run all tests
|
||||
./scripts/test-all.sh
|
||||
|
||||
# Run mobile tests only
|
||||
./scripts/test-mobile.sh
|
||||
|
||||
# Run with verbose logging
|
||||
./scripts/test-all.sh --verbose
|
||||
|
||||
# Show environment variables
|
||||
./scripts/test-env.sh --env
|
||||
```
|
||||
|
||||
### Building Applications
|
||||
|
||||
```bash
|
||||
# Build Android
|
||||
./scripts/build-android.sh
|
||||
|
||||
# Build Linux package
|
||||
./scripts/build-electron-linux.sh deb
|
||||
|
||||
# Build universal Mac package
|
||||
./scripts/build-electron-mac.sh universal
|
||||
|
||||
# Show environment variables for build
|
||||
./scripts/build-electron.sh --env
|
||||
```
|
||||
|
||||
### Development Workflows
|
||||
|
||||
```bash
|
||||
# Start development
|
||||
npm run dev
|
||||
```
|
||||
|
||||
## Environment Variable Features
|
||||
|
||||
### Automatic Setup
|
||||
|
||||
All scripts automatically configure the correct environment variables for their build type:
|
||||
|
||||
```bash
|
||||
# Capacitor builds automatically get:
|
||||
export VITE_PLATFORM=capacitor
|
||||
export VITE_PWA_ENABLED=false
|
||||
export VITE_DISABLE_PWA=true
|
||||
export DEBUG_MIGRATIONS=0
|
||||
export VITE_GIT_HASH=<git-hash>
|
||||
|
||||
# Production builds also get:
|
||||
export NODE_ENV=production
|
||||
```
|
||||
|
||||
### .env File Support
|
||||
Scripts automatically load variables from `.env` files if they exist:
|
||||
|
||||
```bash
|
||||
# .env file example:
|
||||
VITE_API_URL=https://api.example.com
|
||||
VITE_DEBUG=true
|
||||
CUSTOM_VAR=value
|
||||
```
|
||||
|
||||
### Environment Validation
|
||||
Required environment variables can be validated:
|
||||
|
||||
```bash
|
||||
# In your script
|
||||
validate_env_vars "VITE_API_URL" "VITE_DEBUG" || exit 1
|
||||
```
|
||||
|
||||
### Environment Inspection
|
||||
View current environment variables with the `--env` flag:
|
||||
|
||||
```bash
|
||||
./scripts/test-env.sh --env
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
All scripts use consistent error handling:
|
||||
|
||||
- **Exit Codes**: Each script documents specific exit codes
|
||||
- **Safe Execution**: `safe_execute` provides timing and error handling
|
||||
- **Graceful Failure**: Scripts stop on first error with clear messages
|
||||
- **Logging**: All operations are logged with timestamps and colors
|
||||
- **Environment Validation**: Required variables are checked before execution
|
||||
|
||||
## Testing
|
||||
|
||||
To verify the common utilities work correctly:
|
||||
|
||||
```bash
|
||||
# Test all common functions
|
||||
./scripts/test-common.sh
|
||||
|
||||
# Test environment variable handling
|
||||
./scripts/test-env.sh
|
||||
|
||||
# Test with verbose logging
|
||||
./scripts/test-env.sh --verbose
|
||||
```
|
||||
|
||||
## Maintenance
|
||||
|
||||
### Adding New Scripts
|
||||
|
||||
1. Create new script following the unified pattern
|
||||
2. Source `common.sh` at the top
|
||||
3. Use `setup_build_env()` for environment setup
|
||||
4. Use `safe_execute` for command execution
|
||||
5. Document exit codes and usage
|
||||
6. Make executable: `chmod +x scripts/new-script.sh`
|
||||
|
||||
### Modifying Common Utilities
|
||||
|
||||
1. Update `common.sh` with new functions
|
||||
2. Export new functions with `export -f function_name`
|
||||
3. Update this README if adding new categories
|
||||
4. Test with `test-common.sh` and `test-env.sh`
|
||||
|
||||
### Adding New Build Types
|
||||
|
||||
1. Add new case to `setup_build_env()` function
|
||||
2. Define appropriate environment variables
|
||||
3. Update this README with new build type
|
||||
4. Test with `test-env.sh`
|
||||
|
||||
## Security Considerations
|
||||
|
||||
- All scripts use `set -e` for immediate failure on errors
|
||||
- Commands are executed through `safe_execute` for consistent error handling
|
||||
- No direct execution of user input without validation
|
||||
- Environment variables are validated when required
|
||||
- .env files are loaded safely with proper parsing
|
||||
|
||||
## Performance
|
||||
|
||||
- Common utilities are sourced once per script execution
|
||||
- Timing information is automatically collected for all operations
|
||||
- Build artifacts are cleaned up automatically
|
||||
- No redundant command execution or file operations
|
||||
- Environment variables are set efficiently with minimal overhead
|
||||
@@ -1,68 +0,0 @@
|
||||
#!/bin/bash
|
||||
# build-android.sh
|
||||
# Author: Matthew Raymer
|
||||
# Description: Android build script for TimeSafari application
|
||||
# This script handles the complete Android build process including cleanup,
|
||||
# web build, Capacitor build, Gradle build, and Android Studio launch.
|
||||
#
|
||||
# Exit Codes:
|
||||
# 1 - Android cleanup failed
|
||||
# 2 - Web build failed
|
||||
# 3 - Capacitor build failed
|
||||
# 4 - Gradle clean failed
|
||||
# 5 - Gradle assemble failed
|
||||
# 6 - Capacitor sync failed
|
||||
# 7 - Asset generation failed
|
||||
# 8 - Android Studio launch failed
|
||||
|
||||
# Exit on any error
|
||||
set -e
|
||||
|
||||
# Source common utilities
|
||||
source "$(dirname "$0")/common.sh"
|
||||
|
||||
# Parse command line arguments
|
||||
parse_args "$@"
|
||||
|
||||
# Print build header
|
||||
print_header "TimeSafari Android Build Process"
|
||||
log_info "Starting Android build process at $(date)"
|
||||
|
||||
# Setup environment for Capacitor build
|
||||
setup_build_env "capacitor"
|
||||
|
||||
# Setup application directories
|
||||
setup_app_directories
|
||||
|
||||
# Load environment from .env file if it exists
|
||||
load_env_file ".env"
|
||||
|
||||
# Step 1: Clean Android app
|
||||
safe_execute "Cleaning Android app" "npm run clean:android" || exit 1
|
||||
|
||||
# Step 2: Clean dist directory
|
||||
log_info "Cleaning dist directory..."
|
||||
clean_build_artifacts "dist"
|
||||
|
||||
# Step 3: Build Capacitor version
|
||||
safe_execute "Building Capacitor version" "npm run build:capacitor" || exit 3
|
||||
|
||||
# Step 4: Clean Gradle build
|
||||
safe_execute "Cleaning Gradle build" "cd android && ./gradlew clean && cd .." || exit 4
|
||||
|
||||
# Step 5: Assemble debug build
|
||||
safe_execute "Assembling debug build" "cd android && ./gradlew assembleDebug && cd .." || exit 5
|
||||
|
||||
# Step 6: Sync with Capacitor
|
||||
safe_execute "Syncing with Capacitor" "npx cap sync android" || exit 6
|
||||
|
||||
# Step 7: Generate assets and open Android Studio
|
||||
safe_execute "Generating assets" "npx capacitor-assets generate --android" || exit 7
|
||||
safe_execute "Opening Android Studio" "npx cap open android" || exit 8
|
||||
|
||||
# Print build summary
|
||||
log_success "Android build completed successfully!"
|
||||
print_footer "Android Build"
|
||||
|
||||
# Exit with success
|
||||
exit 0
|
||||
165
scripts/build-electron.js
Normal file
165
scripts/build-electron.js
Normal file
@@ -0,0 +1,165 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
console.log('Starting electron build process...');
|
||||
|
||||
// Define paths
|
||||
const electronDistPath = path.join(__dirname, '..', 'dist-electron');
|
||||
const wwwPath = path.join(electronDistPath, 'www');
|
||||
|
||||
// Create www directory if it doesn't exist
|
||||
if (!fs.existsSync(wwwPath)) {
|
||||
fs.mkdirSync(wwwPath, { recursive: true });
|
||||
}
|
||||
|
||||
// Create a platform-specific index.html for Electron
|
||||
const initialIndexContent = `<!DOCTYPE html>
|
||||
<html lang="">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0,viewport-fit=cover">
|
||||
<link rel="icon" href="/favicon.ico">
|
||||
<title>TimeSafari</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>
|
||||
<strong>We're sorry but TimeSafari doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
|
||||
</noscript>
|
||||
<div id="app"></div>
|
||||
<script type="module">
|
||||
// Force electron platform
|
||||
window.process = { env: { VITE_PLATFORM: 'electron' } };
|
||||
import('./src/main.electron.ts');
|
||||
</script>
|
||||
</body>
|
||||
</html>`;
|
||||
|
||||
// Write the Electron-specific index.html
|
||||
fs.writeFileSync(path.join(wwwPath, 'index.html'), initialIndexContent);
|
||||
|
||||
// Copy only necessary assets from web build
|
||||
const webDistPath = path.join(__dirname, '..', 'dist');
|
||||
if (fs.existsSync(webDistPath)) {
|
||||
// Copy assets directory
|
||||
const assetsSrc = path.join(webDistPath, 'assets');
|
||||
const assetsDest = path.join(wwwPath, 'assets');
|
||||
if (fs.existsSync(assetsSrc)) {
|
||||
fs.cpSync(assetsSrc, assetsDest, { recursive: true });
|
||||
}
|
||||
|
||||
// Copy favicon
|
||||
const faviconSrc = path.join(webDistPath, 'favicon.ico');
|
||||
if (fs.existsSync(faviconSrc)) {
|
||||
fs.copyFileSync(faviconSrc, path.join(wwwPath, 'favicon.ico'));
|
||||
}
|
||||
}
|
||||
|
||||
// Remove service worker files
|
||||
const swFilesToRemove = [
|
||||
'sw.js',
|
||||
'sw.js.map',
|
||||
'workbox-*.js',
|
||||
'workbox-*.js.map',
|
||||
'registerSW.js',
|
||||
'manifest.webmanifest',
|
||||
'**/workbox-*.js',
|
||||
'**/workbox-*.js.map',
|
||||
'**/sw.js',
|
||||
'**/sw.js.map',
|
||||
'**/registerSW.js',
|
||||
'**/manifest.webmanifest'
|
||||
];
|
||||
|
||||
console.log('Removing service worker files...');
|
||||
swFilesToRemove.forEach(pattern => {
|
||||
const files = fs.readdirSync(wwwPath).filter(file =>
|
||||
file.match(new RegExp(pattern.replace(/\*/g, '.*')))
|
||||
);
|
||||
files.forEach(file => {
|
||||
const filePath = path.join(wwwPath, file);
|
||||
console.log(`Removing ${filePath}`);
|
||||
try {
|
||||
fs.unlinkSync(filePath);
|
||||
} catch (err) {
|
||||
console.warn(`Could not remove ${filePath}:`, err.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Also check and remove from assets directory
|
||||
const assetsPath = path.join(wwwPath, 'assets');
|
||||
if (fs.existsSync(assetsPath)) {
|
||||
swFilesToRemove.forEach(pattern => {
|
||||
const files = fs.readdirSync(assetsPath).filter(file =>
|
||||
file.match(new RegExp(pattern.replace(/\*/g, '.*')))
|
||||
);
|
||||
files.forEach(file => {
|
||||
const filePath = path.join(assetsPath, file);
|
||||
console.log(`Removing ${filePath}`);
|
||||
try {
|
||||
fs.unlinkSync(filePath);
|
||||
} catch (err) {
|
||||
console.warn(`Could not remove ${filePath}:`, err.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Modify index.html to remove service worker registration
|
||||
const indexPath = path.join(wwwPath, 'index.html');
|
||||
if (fs.existsSync(indexPath)) {
|
||||
console.log('Modifying index.html to remove service worker registration...');
|
||||
let indexContent = fs.readFileSync(indexPath, 'utf8');
|
||||
|
||||
// Remove service worker registration script
|
||||
indexContent = indexContent
|
||||
.replace(/<script[^>]*id="vite-plugin-pwa:register-sw"[^>]*><\/script>/g, '')
|
||||
.replace(/<script[^>]*registerServiceWorker[^>]*><\/script>/g, '')
|
||||
.replace(/<link[^>]*rel="manifest"[^>]*>/g, '')
|
||||
.replace(/<link[^>]*rel="serviceworker"[^>]*>/g, '')
|
||||
.replace(/navigator\.serviceWorker\.register\([^)]*\)/g, '')
|
||||
.replace(/if\s*\(\s*['"]serviceWorker['"]\s*in\s*navigator\s*\)\s*{[^}]*}/g, '');
|
||||
|
||||
fs.writeFileSync(indexPath, indexContent);
|
||||
console.log('Successfully modified index.html');
|
||||
}
|
||||
|
||||
// Fix asset paths
|
||||
console.log('Fixing asset paths in index.html...');
|
||||
let modifiedIndexContent = fs.readFileSync(indexPath, 'utf8');
|
||||
modifiedIndexContent = modifiedIndexContent
|
||||
.replace(/\/assets\//g, './assets/')
|
||||
.replace(/href="\//g, 'href="./')
|
||||
.replace(/src="\//g, 'src="./');
|
||||
|
||||
fs.writeFileSync(indexPath, modifiedIndexContent);
|
||||
|
||||
// Verify no service worker references remain
|
||||
const finalContent = fs.readFileSync(indexPath, 'utf8');
|
||||
if (finalContent.includes('serviceWorker') || finalContent.includes('workbox')) {
|
||||
console.warn('Warning: Service worker references may still exist in index.html');
|
||||
}
|
||||
|
||||
// Check for remaining /assets/ paths
|
||||
console.log('After path fixing, checking for remaining /assets/ paths:', finalContent.includes('/assets/'));
|
||||
console.log('Sample of fixed content:', finalContent.substring(0, 500));
|
||||
|
||||
console.log('Copied and fixed web files in:', wwwPath);
|
||||
|
||||
// Copy main process files
|
||||
console.log('Copying main process files...');
|
||||
|
||||
// Copy the main process file instead of creating a template
|
||||
const mainSrcPath = path.join(__dirname, '..', 'dist-electron', 'main.js');
|
||||
const mainDestPath = path.join(electronDistPath, 'main.js');
|
||||
|
||||
if (fs.existsSync(mainSrcPath)) {
|
||||
fs.copyFileSync(mainSrcPath, mainDestPath);
|
||||
console.log('Copied main process file successfully');
|
||||
} else {
|
||||
console.error('Main process file not found at:', mainSrcPath);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log('Electron build process completed successfully');
|
||||
@@ -1,147 +0,0 @@
|
||||
#!/bin/bash
|
||||
# build-electron.sh
|
||||
# Author: Matthew Raymer
|
||||
# Description: Electron build script for TimeSafari application
|
||||
# This script handles the complete Electron build process including cleanup,
|
||||
# web build, Capacitor build, TypeScript compilation, and Electron packaging.
|
||||
#
|
||||
# Usage:
|
||||
# ./scripts/build-electron.sh # Development build (runs app)
|
||||
# ./scripts/build-electron.sh --dev # Development build (runs app)
|
||||
# ./scripts/build-electron.sh --package # Package build (creates distributable)
|
||||
# ./scripts/build-electron.sh --appimage # Build AppImage package
|
||||
# ./scripts/build-electron.sh --deb # Build Debian package
|
||||
# ./scripts/build-electron.sh --help # Show help
|
||||
# ./scripts/build-electron.sh --verbose # Enable verbose logging
|
||||
#
|
||||
# NPM Script Equivalents:
|
||||
# npm run build:electron # Development build
|
||||
# npm run build:electron:package # Package build
|
||||
# npm run build:electron:appimage # AppImage package
|
||||
# npm run build:electron:deb # Debian package
|
||||
#
|
||||
# Exit Codes:
|
||||
# 1 - Electron cleanup failed
|
||||
# 2 - Web build failed
|
||||
# 3 - Capacitor build failed
|
||||
# 4 - TypeScript compilation failed
|
||||
# 5 - Electron packaging failed
|
||||
# 6 - Capacitor sync failed
|
||||
# 7 - Asset generation failed
|
||||
# 8 - Electron app launch failed
|
||||
|
||||
# Exit on any error
|
||||
set -e
|
||||
|
||||
# Source common utilities
|
||||
source "$(dirname "$0")/common.sh"
|
||||
|
||||
# Parse command line arguments
|
||||
parse_args "$@"
|
||||
|
||||
# Print build header
|
||||
print_header "TimeSafari Electron Build Process"
|
||||
log_info "Starting Electron build process at $(date)"
|
||||
|
||||
# Setup environment for Electron build
|
||||
setup_build_env "electron"
|
||||
|
||||
# Setup application directories
|
||||
setup_app_directories
|
||||
|
||||
# Load environment from .env file if it exists
|
||||
load_env_file ".env"
|
||||
|
||||
# Step 1: Clean Electron app
|
||||
safe_execute "Cleaning Electron app" "npm run clean:electron || true" || exit 1
|
||||
|
||||
# Step 2: Clean dist directory
|
||||
log_info "Cleaning dist directory..."
|
||||
clean_build_artifacts "dist" "electron/app"
|
||||
|
||||
# Step 3: Build Capacitor version for Electron
|
||||
safe_execute "Building Capacitor version" "npm run build:capacitor" || exit 2
|
||||
|
||||
# Step 4: Prepare Electron app directory
|
||||
log_info "Preparing Electron app directory..."
|
||||
mkdir -p electron/app
|
||||
|
||||
# Step 5: Copy built files to Electron
|
||||
safe_execute "Copying web assets to Electron" "cp -r dist/* electron/app/" || exit 3
|
||||
|
||||
# Step 6: Validate and copy Capacitor configuration
|
||||
safe_execute "Validating Capacitor configuration" "cp capacitor.config.json electron/capacitor.config.json" || exit 3
|
||||
|
||||
# Step 7: Navigate to electron directory and build TypeScript
|
||||
safe_execute "Compiling TypeScript" "cd electron && npm run build && cd .." || exit 4
|
||||
|
||||
# Step 8: Sync with Capacitor (if needed)
|
||||
safe_execute "Syncing with Capacitor" "npx cap sync electron || true" || exit 6
|
||||
|
||||
# Step 9: Generate assets (if available)
|
||||
safe_execute "Generating assets" "npx capacitor-assets generate --electron || true" || exit 7
|
||||
|
||||
# Determine build action based on arguments
|
||||
BUILD_ACTION="dev"
|
||||
PACKAGE_TYPE=""
|
||||
|
||||
# Parse additional arguments for build type
|
||||
for arg in "$@"; do
|
||||
case $arg in
|
||||
--package|--build)
|
||||
BUILD_ACTION="package"
|
||||
;;
|
||||
--appimage)
|
||||
BUILD_ACTION="package"
|
||||
PACKAGE_TYPE="appimage"
|
||||
;;
|
||||
--deb)
|
||||
BUILD_ACTION="package"
|
||||
PACKAGE_TYPE="deb"
|
||||
;;
|
||||
--dev|--development)
|
||||
BUILD_ACTION="dev"
|
||||
;;
|
||||
*)
|
||||
# Ignore unknown arguments
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Execute build action
|
||||
case $BUILD_ACTION in
|
||||
"package")
|
||||
if [ -n "$PACKAGE_TYPE" ]; then
|
||||
safe_execute "Building Electron package ($PACKAGE_TYPE)" "cd electron && ./build-packages.sh $PACKAGE_TYPE && cd .." || exit 5
|
||||
else
|
||||
safe_execute "Building Electron package" "cd electron && ./build-packages.sh && cd .." || exit 5
|
||||
fi
|
||||
;;
|
||||
"dev")
|
||||
safe_execute "Starting Electron development app" "cd electron && npm run electron:start && cd .." || exit 8
|
||||
;;
|
||||
*)
|
||||
log_error "Unknown build action: $BUILD_ACTION"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Print build summary
|
||||
case $BUILD_ACTION in
|
||||
"package")
|
||||
log_success "Electron package build completed successfully!"
|
||||
if [ -d "electron/dist" ]; then
|
||||
log_info "Package files available in: electron/dist/"
|
||||
ls -la electron/dist/ || true
|
||||
fi
|
||||
;;
|
||||
"dev")
|
||||
log_success "Electron development build completed successfully!"
|
||||
log_info "Electron app should now be running"
|
||||
;;
|
||||
esac
|
||||
|
||||
print_footer "Electron Build"
|
||||
|
||||
# Exit with success
|
||||
exit 0
|
||||
@@ -1,273 +0,0 @@
|
||||
#!/bin/bash
|
||||
# build-ios.sh
|
||||
# Author: Matthew Raymer
|
||||
# Description: iOS build script for TimeSafari application
|
||||
# This script handles the complete iOS build process including cleanup,
|
||||
# web build, Capacitor build, asset generation, version management, and Xcode launch.
|
||||
#
|
||||
# Prerequisites:
|
||||
# - macOS with Xcode installed
|
||||
# - iOS development certificates configured
|
||||
# - Capacitor dependencies installed
|
||||
#
|
||||
# Usage:
|
||||
# ./scripts/build-ios.sh # Standard build and open Xcode
|
||||
# ./scripts/build-ios.sh --version 1.0.3 # Build with specific version
|
||||
# ./scripts/build-ios.sh --build-number 35 # Build with specific build number
|
||||
# ./scripts/build-ios.sh --no-xcode # Build without opening Xcode
|
||||
# ./scripts/build-ios.sh --help # Show help
|
||||
# ./scripts/build-ios.sh --verbose # Enable verbose logging
|
||||
#
|
||||
# NPM Script Equivalents:
|
||||
# npm run build:ios # Standard iOS build
|
||||
# npm run build:ios:release # Release build with version bump
|
||||
#
|
||||
# Exit Codes:
|
||||
# 1 - iOS cleanup failed
|
||||
# 2 - Web build failed
|
||||
# 3 - Capacitor build failed
|
||||
# 4 - Capacitor sync failed
|
||||
# 5 - Asset generation failed
|
||||
# 6 - Version update failed
|
||||
# 7 - Xcode project opening failed
|
||||
# 8 - Ruby/Gem environment setup failed
|
||||
# 9 - iOS directory structure validation failed
|
||||
|
||||
# Exit on any error
|
||||
set -e
|
||||
|
||||
# Source common utilities
|
||||
source "$(dirname "$0")/common.sh"
|
||||
|
||||
# Default values
|
||||
VERSION=""
|
||||
BUILD_NUMBER=""
|
||||
OPEN_XCODE=true
|
||||
MARKETING_VERSION=""
|
||||
|
||||
# Function to show usage
|
||||
show_usage() {
|
||||
cat << EOF
|
||||
Usage: $0 [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
--version VERSION Set marketing version (e.g., 1.0.3)
|
||||
--build-number NUMBER Set build number (e.g., 35)
|
||||
--marketing-version VER Set marketing version explicitly
|
||||
--no-xcode Skip opening Xcode after build
|
||||
--help Show this help message
|
||||
--verbose Enable verbose logging
|
||||
--debug Enable debug mode
|
||||
|
||||
EXAMPLES:
|
||||
$0 # Standard build
|
||||
$0 --version 1.0.3 --build-number 35 # Build with specific version
|
||||
$0 --no-xcode # Build without opening Xcode
|
||||
$0 --verbose # Build with verbose output
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
# Parse command line arguments
|
||||
parse_ios_args() {
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--version)
|
||||
VERSION="$2"
|
||||
MARKETING_VERSION="$2"
|
||||
shift 2
|
||||
;;
|
||||
--build-number)
|
||||
BUILD_NUMBER="$2"
|
||||
shift 2
|
||||
;;
|
||||
--marketing-version)
|
||||
MARKETING_VERSION="$2"
|
||||
shift 2
|
||||
;;
|
||||
--no-xcode)
|
||||
OPEN_XCODE=false
|
||||
shift
|
||||
;;
|
||||
--help)
|
||||
show_usage
|
||||
exit 0
|
||||
;;
|
||||
--verbose)
|
||||
VERBOSE=true
|
||||
shift
|
||||
;;
|
||||
--debug)
|
||||
DEBUG=true
|
||||
set -x
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
log_warn "Unknown option: $1"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# Function to validate iOS build environment
|
||||
validate_ios_environment() {
|
||||
log_info "Validating iOS build environment..."
|
||||
|
||||
# Check if running on macOS
|
||||
if [[ "$(uname)" != "Darwin" ]]; then
|
||||
log_error "iOS builds require macOS"
|
||||
exit 9
|
||||
fi
|
||||
|
||||
# Check if Xcode is installed
|
||||
if ! command -v xcodebuild &> /dev/null; then
|
||||
log_error "Xcode is not installed or not in PATH"
|
||||
exit 9
|
||||
fi
|
||||
|
||||
# Check if iOS directory exists
|
||||
if [ ! -d "ios" ]; then
|
||||
log_error "iOS directory not found. Run 'npx cap add ios' first."
|
||||
exit 9
|
||||
fi
|
||||
|
||||
log_success "iOS build environment validated"
|
||||
}
|
||||
|
||||
# Function to setup Ruby/Gem environment for Capacitor
|
||||
setup_ruby_environment() {
|
||||
log_info "Setting up Ruby/Gem environment..."
|
||||
|
||||
# Check if we're in a pkgx environment and setup gem paths
|
||||
if command -v gem &> /dev/null; then
|
||||
gem_path=$(which gem)
|
||||
if [[ "$gem_path" == *"pkgx"* ]]; then
|
||||
log_info "Detected pkgx environment, setting up gem paths..."
|
||||
shortened_path="${gem_path%/*/*}"
|
||||
export GEM_HOME="$shortened_path"
|
||||
export GEM_PATH="$shortened_path"
|
||||
log_info "GEM_HOME set to: $GEM_HOME"
|
||||
fi
|
||||
else
|
||||
log_error "Ruby gem command not found"
|
||||
exit 8
|
||||
fi
|
||||
|
||||
log_success "Ruby/Gem environment configured"
|
||||
}
|
||||
|
||||
# Function to setup iOS asset directories
|
||||
setup_ios_asset_directories() {
|
||||
log_info "Setting up iOS asset directories..."
|
||||
|
||||
# Create required asset directories that capacitor-assets expects
|
||||
mkdir -p "ios/App/App/Assets.xcassets/AppIcon.appiconset"
|
||||
echo '{"images":[]}' > "ios/App/App/Assets.xcassets/AppIcon.appiconset/Contents.json"
|
||||
|
||||
mkdir -p "ios/App/App/Assets.xcassets/Splash.imageset"
|
||||
echo '{"images":[]}' > "ios/App/App/Assets.xcassets/Splash.imageset/Contents.json"
|
||||
|
||||
log_success "iOS asset directories prepared"
|
||||
}
|
||||
|
||||
# Function to update iOS version numbers
|
||||
update_ios_version() {
|
||||
if [ -n "$BUILD_NUMBER" ] || [ -n "$MARKETING_VERSION" ]; then
|
||||
log_info "Updating iOS version information..."
|
||||
|
||||
cd ios/App
|
||||
|
||||
# Update build number if provided
|
||||
if [ -n "$BUILD_NUMBER" ]; then
|
||||
log_info "Setting build number to: $BUILD_NUMBER"
|
||||
safe_execute "Updating build number" "xcrun agvtool new-version $BUILD_NUMBER" || exit 6
|
||||
fi
|
||||
|
||||
# Update marketing version if provided
|
||||
if [ -n "$MARKETING_VERSION" ]; then
|
||||
log_info "Setting marketing version to: $MARKETING_VERSION"
|
||||
safe_execute "Updating marketing version" "perl -p -i -e 's/MARKETING_VERSION = .*/MARKETING_VERSION = $MARKETING_VERSION;/g' App.xcodeproj/project.pbxproj" || exit 6
|
||||
fi
|
||||
|
||||
cd ../..
|
||||
log_success "iOS version information updated"
|
||||
else
|
||||
log_info "No version updates requested"
|
||||
fi
|
||||
}
|
||||
|
||||
# Parse command line arguments
|
||||
parse_ios_args "$@"
|
||||
|
||||
# Print build header
|
||||
print_header "TimeSafari iOS Build Process"
|
||||
log_info "Starting iOS build process at $(date)"
|
||||
|
||||
# Validate iOS build environment
|
||||
validate_ios_environment
|
||||
|
||||
# Setup environment for Capacitor build
|
||||
setup_build_env "capacitor"
|
||||
|
||||
# Setup application directories
|
||||
setup_app_directories
|
||||
|
||||
# Load environment from .env file if it exists
|
||||
load_env_file ".env"
|
||||
|
||||
# Setup Ruby/Gem environment
|
||||
setup_ruby_environment
|
||||
|
||||
# Step 1: Clean iOS app
|
||||
safe_execute "Cleaning iOS app" "npm run clean:ios || true" || exit 1
|
||||
|
||||
# Step 2: Clean dist directory
|
||||
log_info "Cleaning dist directory..."
|
||||
clean_build_artifacts "dist"
|
||||
|
||||
# Step 3: Build web assets
|
||||
safe_execute "Building web assets" "npm run build:web" || exit 2
|
||||
|
||||
# Step 4: Build Capacitor version
|
||||
safe_execute "Building Capacitor version" "npm run build:capacitor" || exit 3
|
||||
|
||||
# Step 5: Sync with Capacitor
|
||||
safe_execute "Syncing with Capacitor" "npx cap sync ios" || exit 4
|
||||
|
||||
# Step 6: Setup iOS asset directories
|
||||
setup_ios_asset_directories
|
||||
|
||||
# Step 7: Generate iOS assets
|
||||
safe_execute "Generating iOS assets" "npx capacitor-assets generate --ios" || exit 5
|
||||
|
||||
# Step 8: Update version information
|
||||
update_ios_version
|
||||
|
||||
# Step 9: Open Xcode (if requested)
|
||||
if [ "$OPEN_XCODE" = true ]; then
|
||||
safe_execute "Opening Xcode" "npx cap open ios" || exit 7
|
||||
log_info "Xcode opened. You can now build and run on simulator or device."
|
||||
log_info "Next steps in Xcode:"
|
||||
log_info " 1. Select Product -> Destination with a Simulator version"
|
||||
log_info " 2. Click the run arrow to build and test"
|
||||
log_info " 3. For release: Choose Product -> Destination -> Any iOS Device"
|
||||
log_info " 4. For release: Choose Product -> Archive"
|
||||
else
|
||||
log_info "Skipping Xcode opening as requested"
|
||||
fi
|
||||
|
||||
# Print build summary
|
||||
log_success "iOS build completed successfully!"
|
||||
|
||||
if [ -n "$BUILD_NUMBER" ] || [ -n "$MARKETING_VERSION" ]; then
|
||||
log_info "Version Information:"
|
||||
[ -n "$BUILD_NUMBER" ] && log_info " Build Number: $BUILD_NUMBER"
|
||||
[ -n "$MARKETING_VERSION" ] && log_info " Marketing Version: $MARKETING_VERSION"
|
||||
fi
|
||||
|
||||
log_info "iOS project ready at: ios/App/"
|
||||
print_footer "iOS Build"
|
||||
|
||||
# Exit with success
|
||||
exit 0
|
||||
@@ -1,326 +0,0 @@
|
||||
#!/bin/bash
|
||||
# common.sh
|
||||
# Author: Matthew Raymer
|
||||
# Description: Common utilities and functions for TimeSafari build scripts
|
||||
# This script provides shared logging, timing, and utility functions
|
||||
# that can be sourced by other build scripts to eliminate redundancy.
|
||||
#
|
||||
# Usage: source ./scripts/common.sh
|
||||
#
|
||||
# Provides:
|
||||
# - Color constants
|
||||
# - Logging functions (log_info, log_success, log_warn, log_error)
|
||||
# - Timing function (measure_time)
|
||||
# - Common utility functions
|
||||
# - Environment variable management
|
||||
|
||||
# ANSI color codes for better output formatting
|
||||
readonly RED='\033[0;31m'
|
||||
readonly GREEN='\033[0;32m'
|
||||
readonly YELLOW='\033[1;33m'
|
||||
readonly BLUE='\033[0;34m'
|
||||
readonly PURPLE='\033[0;35m'
|
||||
readonly CYAN='\033[0;36m'
|
||||
readonly NC='\033[0m' # No Color
|
||||
|
||||
# Logging functions
|
||||
log_info() {
|
||||
echo -e "${BLUE}[$(date '+%Y-%m-%d %H:%M:%S')] [INFO]${NC} $1"
|
||||
}
|
||||
|
||||
log_success() {
|
||||
echo -e "${GREEN}[$(date '+%Y-%m-%d %H:%M:%S')] [SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
log_warn() {
|
||||
echo -e "${YELLOW}[$(date '+%Y-%m-%d %H:%M:%S')] [WARN]${NC} $1"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo -e "${RED}[$(date '+%Y-%m-%d %H:%M:%S')] [ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
log_debug() {
|
||||
echo -e "${PURPLE}[$(date '+%Y-%m-%d %H:%M:%S')] [DEBUG]${NC} $1"
|
||||
}
|
||||
|
||||
log_step() {
|
||||
echo -e "${CYAN}[$(date '+%Y-%m-%d %H:%M:%S')] [STEP]${NC} $1"
|
||||
}
|
||||
|
||||
# Function to measure and log execution time
|
||||
measure_time() {
|
||||
local start_time=$(date +%s)
|
||||
"$@"
|
||||
local end_time=$(date +%s)
|
||||
local duration=$((end_time - start_time))
|
||||
log_success "Completed in ${duration} seconds"
|
||||
}
|
||||
|
||||
# Function to print section headers
|
||||
print_header() {
|
||||
local title="$1"
|
||||
echo -e "\n${BLUE}=== $title ===${NC}\n"
|
||||
}
|
||||
|
||||
print_footer() {
|
||||
local title="$1"
|
||||
echo -e "\n${GREEN}=== $title Complete ===${NC}\n"
|
||||
}
|
||||
|
||||
# Function to check if a command exists
|
||||
check_command() {
|
||||
if ! command -v "$1" &> /dev/null; then
|
||||
log_error "$1 is required but not installed."
|
||||
return 1
|
||||
fi
|
||||
log_debug "Found $1: $(command -v "$1")"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Function to check if a directory exists
|
||||
check_directory() {
|
||||
if [ ! -d "$1" ]; then
|
||||
log_error "Directory not found: $1"
|
||||
return 1
|
||||
fi
|
||||
log_debug "Directory exists: $1"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Function to check if a file exists
|
||||
check_file() {
|
||||
if [ ! -f "$1" ]; then
|
||||
log_error "File not found: $1"
|
||||
return 1
|
||||
fi
|
||||
log_debug "File exists: $1"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Function to safely execute a command with error handling
|
||||
safe_execute() {
|
||||
local step_name="$1"
|
||||
local command="$2"
|
||||
|
||||
log_step "$step_name"
|
||||
if ! measure_time eval "$command"; then
|
||||
log_error "$step_name failed!"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# Function to check virtual environment for Python scripts
|
||||
check_venv() {
|
||||
if [ ! -d ".venv" ]; then
|
||||
log_error "Virtual environment not found. Please create it first:"
|
||||
log_error "python -m venv .venv"
|
||||
log_error "source .venv/bin/activate"
|
||||
log_error "pip install -r requirements.txt"
|
||||
return 1
|
||||
fi
|
||||
log_debug "Virtual environment found: .venv"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Function to get git hash for versioning
|
||||
get_git_hash() {
|
||||
if command -v git &> /dev/null; then
|
||||
git log -1 --pretty=format:%h 2>/dev/null || echo "unknown"
|
||||
else
|
||||
echo "unknown"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to clean build artifacts
|
||||
clean_build_artifacts() {
|
||||
local artifacts=("$@")
|
||||
for artifact in "${artifacts[@]}"; do
|
||||
if [ -e "$artifact" ]; then
|
||||
log_info "Cleaning $artifact"
|
||||
rm -rf "$artifact"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Function to validate environment variables
|
||||
validate_env_vars() {
|
||||
local required_vars=("$@")
|
||||
local missing_vars=()
|
||||
|
||||
for var in "${required_vars[@]}"; do
|
||||
if [ -z "${!var}" ]; then
|
||||
missing_vars+=("$var")
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${#missing_vars[@]} -gt 0 ]; then
|
||||
log_error "Missing required environment variables: ${missing_vars[*]}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# Function to set environment variables for different build types
|
||||
setup_build_env() {
|
||||
local build_type="$1"
|
||||
local production="${2:-false}"
|
||||
|
||||
log_info "Setting up environment for $build_type build"
|
||||
|
||||
# Get git hash for versioning
|
||||
local git_hash=$(get_git_hash)
|
||||
export VITE_GIT_HASH="$git_hash"
|
||||
log_debug "Set VITE_GIT_HASH=$git_hash"
|
||||
|
||||
case $build_type in
|
||||
"capacitor")
|
||||
export VITE_PLATFORM=capacitor
|
||||
export VITE_PWA_ENABLED=false
|
||||
export VITE_DISABLE_PWA=true
|
||||
export DEBUG_MIGRATIONS=0
|
||||
;;
|
||||
"electron")
|
||||
export VITE_PLATFORM=capacitor
|
||||
export VITE_PWA_ENABLED=false
|
||||
export VITE_DISABLE_PWA=true
|
||||
export DEBUG_MIGRATIONS=0
|
||||
;;
|
||||
"web")
|
||||
export VITE_PLATFORM=web
|
||||
export VITE_PWA_ENABLED=true
|
||||
export VITE_DISABLE_PWA=false
|
||||
export DEBUG_MIGRATIONS=0
|
||||
;;
|
||||
*)
|
||||
log_warn "Unknown build type: $build_type, using default environment"
|
||||
export VITE_PLATFORM=web
|
||||
export VITE_PWA_ENABLED=true
|
||||
export VITE_DISABLE_PWA=false
|
||||
export DEBUG_MIGRATIONS=0
|
||||
;;
|
||||
esac
|
||||
|
||||
# Log environment setup
|
||||
log_debug "Environment variables set:"
|
||||
log_debug " VITE_PLATFORM=$VITE_PLATFORM"
|
||||
log_debug " VITE_PWA_ENABLED=$VITE_PWA_ENABLED"
|
||||
log_debug " VITE_DISABLE_PWA=$VITE_DISABLE_PWA"
|
||||
log_debug " DEBUG_MIGRATIONS=$DEBUG_MIGRATIONS"
|
||||
if [ -n "$NODE_ENV" ]; then
|
||||
log_debug " NODE_ENV=$NODE_ENV"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to create application directories
|
||||
setup_app_directories() {
|
||||
log_info "Setting up application directories..."
|
||||
|
||||
# Create TimeSafari data directory
|
||||
mkdir -p ~/.local/share/TimeSafari/timesafari
|
||||
|
||||
# Create build directories if they don't exist
|
||||
mkdir -p dist
|
||||
|
||||
log_debug "Application directories created"
|
||||
}
|
||||
|
||||
# Function to load environment from .env file if it exists
|
||||
load_env_file() {
|
||||
local env_file="$1"
|
||||
|
||||
if [ -f "$env_file" ]; then
|
||||
log_info "Loading environment from $env_file"
|
||||
# Export variables from .env file (simple key=value format)
|
||||
while IFS='=' read -r key value; do
|
||||
# Skip comments and empty lines
|
||||
[[ $key =~ ^#.*$ ]] && continue
|
||||
[[ -z $key ]] && continue
|
||||
|
||||
# Remove quotes from value if present
|
||||
value=$(echo "$value" | sed 's/^["'\'']//;s/["'\'']$//')
|
||||
|
||||
export "$key=$value"
|
||||
log_debug "Loaded: $key=$value"
|
||||
done < "$env_file"
|
||||
else
|
||||
log_debug "No $env_file file found"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to print current environment variables
|
||||
print_env_vars() {
|
||||
local prefix="$1"
|
||||
|
||||
if [ -n "$prefix" ]; then
|
||||
log_info "Environment variables with prefix '$prefix':"
|
||||
env | grep "^$prefix" | sort | while read -r line; do
|
||||
log_debug " $line"
|
||||
done
|
||||
else
|
||||
log_info "Current environment variables:"
|
||||
env | sort | while read -r line; do
|
||||
log_debug " $line"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to print script usage
|
||||
print_usage() {
|
||||
local script_name="$1"
|
||||
local usage_text="$2"
|
||||
|
||||
echo "Usage: $script_name $usage_text"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " -h, --help Show this help message"
|
||||
echo " -v, --verbose Enable verbose logging"
|
||||
echo " -e, --env Show environment variables"
|
||||
echo ""
|
||||
}
|
||||
|
||||
# Function to parse command line arguments
|
||||
parse_args() {
|
||||
local args=("$@")
|
||||
local verbose=false
|
||||
local show_env=false
|
||||
|
||||
for arg in "${args[@]}"; do
|
||||
case $arg in
|
||||
-h|--help)
|
||||
print_usage "$0" "[options]"
|
||||
exit 0
|
||||
;;
|
||||
-v|--verbose)
|
||||
verbose=true
|
||||
;;
|
||||
-e|--env)
|
||||
show_env=true
|
||||
;;
|
||||
*)
|
||||
# Handle other arguments in child scripts
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$verbose" = true ]; then
|
||||
# Enable debug logging
|
||||
set -x
|
||||
fi
|
||||
|
||||
if [ "$show_env" = true ]; then
|
||||
print_env_vars "VITE_"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
# Export functions for use in child scripts
|
||||
export -f log_info log_success log_warn log_error log_debug log_step
|
||||
export -f measure_time print_header print_footer
|
||||
export -f check_command check_directory check_file
|
||||
export -f safe_execute check_venv get_git_hash
|
||||
export -f clean_build_artifacts validate_env_vars
|
||||
export -f setup_build_env setup_app_directories load_env_file print_env_vars
|
||||
export -f print_usage parse_args
|
||||
@@ -1,40 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# TimeSafari Electron Development Script
|
||||
# This script builds the web app and runs it in Electron
|
||||
|
||||
set -e
|
||||
|
||||
echo "🔧 Starting Electron development workflow..."
|
||||
|
||||
# Navigate to project root
|
||||
cd /home/noone/projects/timesafari/crowd-master
|
||||
|
||||
# Build for Capacitor
|
||||
echo "📦 Building for Capacitor..."
|
||||
npm run build:capacitor
|
||||
|
||||
# Create electron/app directory if it doesn't exist
|
||||
echo "📁 Preparing Electron app directory..."
|
||||
mkdir -p electron/app
|
||||
|
||||
# Copy built files to Electron
|
||||
echo "📋 Copying web assets to Electron..."
|
||||
cp -r dist/* electron/app/
|
||||
|
||||
# Ensure capacitor config is valid JSON (remove any comments)
|
||||
echo "🔧 Validating Capacitor configuration..."
|
||||
cp capacitor.config.json electron/capacitor.config.json
|
||||
|
||||
# Navigate to electron directory
|
||||
cd electron
|
||||
|
||||
# Build Electron
|
||||
echo "🔨 Building Electron..."
|
||||
npm run build
|
||||
|
||||
# Start Electron
|
||||
echo "🚀 Starting Electron app..."
|
||||
npm run electron:start
|
||||
|
||||
echo "✅ Electron development workflow complete!"
|
||||
@@ -1,30 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# TimeSafari Electron Setup Script
|
||||
# This script installs all required dependencies for the Electron platform
|
||||
|
||||
set -e
|
||||
|
||||
echo "🔧 Setting up Electron dependencies..."
|
||||
|
||||
# Navigate to electron directory
|
||||
cd electron
|
||||
|
||||
# Install required dependencies for Capacitor SQLite plugin
|
||||
echo "📦 Installing better-sqlite3-multiple-ciphers..."
|
||||
npm install better-sqlite3-multiple-ciphers
|
||||
|
||||
echo "📦 Installing electron-json-storage..."
|
||||
npm install electron-json-storage
|
||||
|
||||
# Rebuild native modules
|
||||
echo "🔨 Rebuilding native modules..."
|
||||
npm run build
|
||||
|
||||
echo "✅ Electron setup complete!"
|
||||
echo ""
|
||||
echo "To run the Electron app:"
|
||||
echo " npm run electron:start"
|
||||
echo ""
|
||||
echo "Or from the project root:"
|
||||
echo " npm run electron:dev"
|
||||
@@ -1,44 +0,0 @@
|
||||
#!/bin/bash
|
||||
# test-all.sh
|
||||
# Author: Matthew Raymer
|
||||
# Description: Comprehensive test suite for TimeSafari application
|
||||
# This script runs all tests including prerequisites, web tests, and mobile tests
|
||||
# with proper error handling and logging.
|
||||
#
|
||||
# Exit Codes:
|
||||
# 1 - Prerequisites check failed
|
||||
# 2 - Build failed
|
||||
# 3 - Web tests failed
|
||||
# 4 - Mobile tests failed
|
||||
|
||||
# Exit on any error
|
||||
set -e
|
||||
|
||||
# Source common utilities
|
||||
source "$(dirname "$0")/common.sh"
|
||||
|
||||
# Parse command line arguments
|
||||
parse_args "$@"
|
||||
|
||||
# Print test header
|
||||
print_header "TimeSafari Test Suite"
|
||||
log_info "Starting comprehensive test suite at $(date)"
|
||||
|
||||
# Step 1: Check prerequisites
|
||||
safe_execute "Checking prerequisites" "npm run test:prerequisites" || exit 1
|
||||
|
||||
# Step 2: Build the application
|
||||
safe_execute "Building application" "npm run build" || exit 2
|
||||
|
||||
# Step 3: Run web tests
|
||||
safe_execute "Running web tests" "npm run test:web" || exit 3
|
||||
|
||||
# Step 4: Run mobile tests
|
||||
safe_execute "Running mobile tests" "npm run test:mobile" || exit 4
|
||||
|
||||
# Print test summary
|
||||
log_success "All tests completed successfully!"
|
||||
print_footer "Test Suite"
|
||||
|
||||
# Exit with success
|
||||
exit 0
|
||||
@@ -1,74 +0,0 @@
|
||||
#!/bin/bash
|
||||
# test-common.sh
|
||||
# Author: Matthew Raymer
|
||||
# Description: Test script to verify common utilities work correctly
|
||||
# This script tests the common.sh utilities to ensure they function properly.
|
||||
|
||||
# Exit on any error
|
||||
set -e
|
||||
|
||||
# Source common utilities
|
||||
source "$(dirname "$0")/common.sh"
|
||||
|
||||
# Parse command line arguments
|
||||
parse_args "$@"
|
||||
|
||||
# Print test header
|
||||
print_header "Common Utilities Test"
|
||||
log_info "Testing common utilities at $(date)"
|
||||
|
||||
# Test logging functions
|
||||
log_info "Testing info logging"
|
||||
log_success "Testing success logging"
|
||||
log_warn "Testing warning logging"
|
||||
log_error "Testing error logging (this is expected)"
|
||||
log_debug "Testing debug logging"
|
||||
log_step "Testing step logging"
|
||||
|
||||
# Test timing function
|
||||
log_info "Testing timing function..."
|
||||
measure_time sleep 1
|
||||
|
||||
# Test command checking
|
||||
log_info "Testing command checking..."
|
||||
if check_command "echo"; then
|
||||
log_success "echo command found"
|
||||
else
|
||||
log_error "echo command not found"
|
||||
fi
|
||||
|
||||
# Test directory checking
|
||||
log_info "Testing directory checking..."
|
||||
if check_directory "scripts"; then
|
||||
log_success "scripts directory found"
|
||||
else
|
||||
log_error "scripts directory not found"
|
||||
fi
|
||||
|
||||
# Test file checking
|
||||
log_info "Testing file checking..."
|
||||
if check_file "scripts/common.sh"; then
|
||||
log_success "common.sh file found"
|
||||
else
|
||||
log_error "common.sh file not found"
|
||||
fi
|
||||
|
||||
# Test git hash function
|
||||
log_info "Testing git hash function..."
|
||||
GIT_HASH=$(get_git_hash)
|
||||
log_info "Git hash: $GIT_HASH"
|
||||
|
||||
# Test safe execute
|
||||
log_info "Testing safe execute..."
|
||||
safe_execute "Testing safe execute" "echo 'Hello from safe_execute'"
|
||||
|
||||
# Test build artifact cleaning
|
||||
log_info "Testing build artifact cleaning..."
|
||||
clean_build_artifacts "test-file-1" "test-file-2"
|
||||
|
||||
# Print test summary
|
||||
log_success "All common utilities tests completed successfully!"
|
||||
print_footer "Common Utilities Test"
|
||||
|
||||
# Exit with success
|
||||
exit 0
|
||||
@@ -1,56 +0,0 @@
|
||||
#!/bin/bash
|
||||
# test-env.sh
|
||||
# Author: Matthew Raymer
|
||||
# Description: Test script to verify environment variable handling
|
||||
# This script tests the environment variable setup functions.
|
||||
|
||||
# Exit on any error
|
||||
set -e
|
||||
|
||||
# Source common utilities
|
||||
source "$(dirname "$0")/common.sh"
|
||||
|
||||
# Parse command line arguments
|
||||
parse_args "$@"
|
||||
|
||||
# Print test header
|
||||
print_header "Environment Variable Test"
|
||||
log_info "Testing environment variable handling at $(date)"
|
||||
|
||||
# Test 1: Capacitor environment
|
||||
log_info "Test 1: Setting up Capacitor environment..."
|
||||
setup_build_env "capacitor"
|
||||
print_env_vars "VITE_"
|
||||
echo ""
|
||||
|
||||
# Test 2: Web environment
|
||||
log_info "Test 2: Setting up Web environment..."
|
||||
setup_build_env "web"
|
||||
print_env_vars "VITE_"
|
||||
echo ""
|
||||
|
||||
# Test 3: Production Capacitor environment
|
||||
log_info "Test 3: Setting up Production Capacitor environment..."
|
||||
setup_build_env "capacitor" "true"
|
||||
print_env_vars "VITE_"
|
||||
echo ""
|
||||
|
||||
# Test 4: Application directories
|
||||
log_info "Test 4: Setting up application directories..."
|
||||
setup_app_directories
|
||||
|
||||
# Test 5: Load .env file (if it exists)
|
||||
log_info "Test 5: Loading .env file..."
|
||||
load_env_file ".env"
|
||||
|
||||
# Test 6: Git hash
|
||||
log_info "Test 6: Getting git hash..."
|
||||
GIT_HASH=$(get_git_hash)
|
||||
log_info "Git hash: $GIT_HASH"
|
||||
|
||||
# Print test summary
|
||||
log_success "All environment variable tests completed successfully!"
|
||||
print_footer "Environment Variable Test"
|
||||
|
||||
# Exit with success
|
||||
exit 0
|
||||
@@ -1,40 +0,0 @@
|
||||
#!/bin/bash
|
||||
# test-mobile.sh
|
||||
# Author: Matthew Raymer
|
||||
# Description: Mobile test suite for TimeSafari application
|
||||
# This script builds the Capacitor version and runs Android and iOS tests
|
||||
# with proper error handling and logging.
|
||||
#
|
||||
# Exit Codes:
|
||||
# 1 - Capacitor build failed
|
||||
# 2 - Android tests failed
|
||||
# 3 - iOS tests failed
|
||||
|
||||
# Exit on any error
|
||||
set -e
|
||||
|
||||
# Source common utilities
|
||||
source "$(dirname "$0")/common.sh"
|
||||
|
||||
# Parse command line arguments
|
||||
parse_args "$@"
|
||||
|
||||
# Print test header
|
||||
print_header "TimeSafari Mobile Test Suite"
|
||||
log_info "Starting mobile test suite at $(date)"
|
||||
|
||||
# Step 1: Build Capacitor version
|
||||
safe_execute "Building Capacitor version" "npm run build:capacitor" || exit 1
|
||||
|
||||
# Step 2: Run Android tests
|
||||
safe_execute "Running Android tests" "npm run test:android" || exit 2
|
||||
|
||||
# Step 3: Run iOS tests
|
||||
safe_execute "Running iOS tests" "npm run test:ios" || exit 3
|
||||
|
||||
# Print test summary
|
||||
log_success "Mobile test suite completed successfully!"
|
||||
print_footer "Mobile Test Suite"
|
||||
|
||||
# Exit with success
|
||||
exit 0
|
||||
@@ -331,8 +331,9 @@
|
||||
<script lang="ts">
|
||||
import { Vue, Component } from "vue-facing-decorator";
|
||||
|
||||
import { NotificationIface } from "./constants/app";
|
||||
import { NotificationIface, USE_DEXIE_DB } from "./constants/app";
|
||||
import * as databaseUtil from "./db/databaseUtil";
|
||||
import { retrieveSettingsForActiveAccount } from "./db/index";
|
||||
import { logConsoleAndDb } from "./db/databaseUtil";
|
||||
import { logger } from "./utils/logger";
|
||||
|
||||
@@ -398,8 +399,11 @@ export default class App extends Vue {
|
||||
|
||||
try {
|
||||
logger.log("Retrieving settings for the active account...");
|
||||
const settings: Settings =
|
||||
let settings: Settings =
|
||||
await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
if (USE_DEXIE_DB) {
|
||||
settings = await retrieveSettingsForActiveAccount();
|
||||
}
|
||||
logger.log("Retrieved settings:", settings);
|
||||
|
||||
const notifyingNewActivity = !!settings?.notifyingNewActivityTime;
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
{
|
||||
"warning": {
|
||||
"fillRule": "evenodd",
|
||||
"d": "M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z",
|
||||
"clipRule": "evenodd"
|
||||
},
|
||||
"spinner": {
|
||||
"d": "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
||||
},
|
||||
"chart": {
|
||||
"strokeLinecap": "round",
|
||||
"strokeLinejoin": "round",
|
||||
"strokeWidth": "2",
|
||||
"d": "M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"
|
||||
},
|
||||
"plus": {
|
||||
"strokeLinecap": "round",
|
||||
"strokeLinejoin": "round",
|
||||
"strokeWidth": "2",
|
||||
"d": "M12 4v16m8-8H4"
|
||||
},
|
||||
"settings": {
|
||||
"strokeLinecap": "round",
|
||||
"strokeLinejoin": "round",
|
||||
"strokeWidth": "2",
|
||||
"d": "M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"
|
||||
},
|
||||
"settingsDot": {
|
||||
"strokeLinecap": "round",
|
||||
"strokeLinejoin": "round",
|
||||
"strokeWidth": "2",
|
||||
"d": "M15 12a3 3 0 11-6 0 3 3 0 016 0z"
|
||||
},
|
||||
"lock": {
|
||||
"strokeLinecap": "round",
|
||||
"strokeLinejoin": "round",
|
||||
"strokeWidth": "2",
|
||||
"d": "M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"
|
||||
},
|
||||
"download": {
|
||||
"strokeLinecap": "round",
|
||||
"strokeLinejoin": "round",
|
||||
"strokeWidth": "2",
|
||||
"d": "M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"
|
||||
},
|
||||
"check": {
|
||||
"strokeLinecap": "round",
|
||||
"strokeLinejoin": "round",
|
||||
"strokeWidth": "2",
|
||||
"d": "M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"
|
||||
},
|
||||
"edit": {
|
||||
"strokeLinecap": "round",
|
||||
"strokeLinejoin": "round",
|
||||
"strokeWidth": "2",
|
||||
"d": "M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"
|
||||
},
|
||||
"trash": {
|
||||
"strokeLinecap": "round",
|
||||
"strokeLinejoin": "round",
|
||||
"strokeWidth": "2",
|
||||
"d": "M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"
|
||||
},
|
||||
"plusCircle": {
|
||||
"strokeLinecap": "round",
|
||||
"strokeLinejoin": "round",
|
||||
"strokeWidth": "2",
|
||||
"d": "M12 6v6m0 0v6m0-6h6m-6 0H6"
|
||||
},
|
||||
"info": {
|
||||
"fillRule": "evenodd",
|
||||
"d": "M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z",
|
||||
"clipRule": "evenodd"
|
||||
}
|
||||
}
|
||||
@@ -141,6 +141,10 @@ export default class DataExportSection extends Vue {
|
||||
result,
|
||||
) as unknown as Contact[];
|
||||
}
|
||||
// if (USE_DEXIE_DB) {
|
||||
// await db.open();
|
||||
// allContacts = await db.contacts.toArray();
|
||||
// }
|
||||
|
||||
// Convert contacts to export format
|
||||
const exportData = contactsToExportJson(allContacts);
|
||||
|
||||
@@ -100,7 +100,10 @@ import {
|
||||
} from "@vue-leaflet/vue-leaflet";
|
||||
import { Router } from "vue-router";
|
||||
|
||||
import { USE_DEXIE_DB } from "@/constants/app";
|
||||
import * as databaseUtil from "../db/databaseUtil";
|
||||
import { MASTER_SETTINGS_KEY } from "../db/tables/settings";
|
||||
import { db, retrieveSettingsForActiveAccount } from "../db/index";
|
||||
|
||||
@Component({
|
||||
components: {
|
||||
@@ -122,7 +125,10 @@ export default class FeedFilters extends Vue {
|
||||
async open(onCloseIfChanged: () => void) {
|
||||
this.onCloseIfChanged = onCloseIfChanged;
|
||||
|
||||
const settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
let settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
if (USE_DEXIE_DB) {
|
||||
settings = await retrieveSettingsForActiveAccount();
|
||||
}
|
||||
this.hasVisibleDid = !!settings.filterFeedByVisible;
|
||||
this.isNearby = !!settings.filterFeedByNearby;
|
||||
if (settings.searchBoxes && settings.searchBoxes.length > 0) {
|
||||
@@ -139,6 +145,12 @@ export default class FeedFilters extends Vue {
|
||||
await databaseUtil.updateDefaultSettings({
|
||||
filterFeedByVisible: this.hasVisibleDid,
|
||||
});
|
||||
|
||||
if (USE_DEXIE_DB) {
|
||||
await db.settings.update(MASTER_SETTINGS_KEY, {
|
||||
filterFeedByVisible: this.hasVisibleDid,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async toggleNearby() {
|
||||
@@ -147,6 +159,12 @@ export default class FeedFilters extends Vue {
|
||||
await databaseUtil.updateDefaultSettings({
|
||||
filterFeedByNearby: this.isNearby,
|
||||
});
|
||||
|
||||
if (USE_DEXIE_DB) {
|
||||
await db.settings.update(MASTER_SETTINGS_KEY, {
|
||||
filterFeedByNearby: this.isNearby,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async clearAll() {
|
||||
@@ -159,6 +177,13 @@ export default class FeedFilters extends Vue {
|
||||
filterFeedByVisible: false,
|
||||
});
|
||||
|
||||
if (USE_DEXIE_DB) {
|
||||
await db.settings.update(MASTER_SETTINGS_KEY, {
|
||||
filterFeedByNearby: false,
|
||||
filterFeedByVisible: false,
|
||||
});
|
||||
}
|
||||
|
||||
this.hasVisibleDid = false;
|
||||
this.isNearby = false;
|
||||
}
|
||||
@@ -173,6 +198,13 @@ export default class FeedFilters extends Vue {
|
||||
filterFeedByVisible: true,
|
||||
});
|
||||
|
||||
if (USE_DEXIE_DB) {
|
||||
await db.settings.update(MASTER_SETTINGS_KEY, {
|
||||
filterFeedByNearby: true,
|
||||
filterFeedByVisible: true,
|
||||
});
|
||||
}
|
||||
|
||||
this.hasVisibleDid = true;
|
||||
this.isNearby = true;
|
||||
}
|
||||
|
||||
@@ -89,13 +89,14 @@
|
||||
<script lang="ts">
|
||||
import { Vue, Component, Prop } from "vue-facing-decorator";
|
||||
|
||||
import { NotificationIface } from "../constants/app";
|
||||
import { NotificationIface, USE_DEXIE_DB } from "../constants/app";
|
||||
import {
|
||||
createAndSubmitGive,
|
||||
didInfo,
|
||||
serverMessageForUser,
|
||||
} from "../libs/endorserServer";
|
||||
import * as libsUtil from "../libs/util";
|
||||
import { db, retrieveSettingsForActiveAccount } from "../db/index";
|
||||
import { Contact } from "../db/tables/contacts";
|
||||
import * as databaseUtil from "../db/databaseUtil";
|
||||
import { retrieveAccountDids } from "../libs/util";
|
||||
@@ -145,7 +146,10 @@ export default class GiftedDialog extends Vue {
|
||||
this.offerId = offerId || "";
|
||||
|
||||
try {
|
||||
const settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
let settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
if (USE_DEXIE_DB) {
|
||||
settings = await retrieveSettingsForActiveAccount();
|
||||
}
|
||||
this.apiServer = settings.apiServer || "";
|
||||
this.activeDid = settings.activeDid || "";
|
||||
|
||||
@@ -156,6 +160,9 @@ export default class GiftedDialog extends Vue {
|
||||
result,
|
||||
) as unknown as Contact[];
|
||||
}
|
||||
if (USE_DEXIE_DB) {
|
||||
this.allContacts = await db.contacts.toArray();
|
||||
}
|
||||
|
||||
this.allMyDids = await retrieveAccountDids();
|
||||
|
||||
|
||||
@@ -74,7 +74,8 @@
|
||||
import { Vue, Component } from "vue-facing-decorator";
|
||||
import { Router } from "vue-router";
|
||||
|
||||
import { AppString, NotificationIface } from "../constants/app";
|
||||
import { AppString, NotificationIface, USE_DEXIE_DB } from "../constants/app";
|
||||
import { db } from "../db/index";
|
||||
import { Contact } from "../db/tables/contacts";
|
||||
import * as databaseUtil from "../db/databaseUtil";
|
||||
import { GiverReceiverInputInfo } from "../libs/util";
|
||||
@@ -135,6 +136,9 @@ export default class GivenPrompts extends Vue {
|
||||
if (result) {
|
||||
this.numContacts = result.values[0][0] as number;
|
||||
}
|
||||
if (USE_DEXIE_DB) {
|
||||
this.numContacts = await db.contacts.count();
|
||||
}
|
||||
this.shownContactDbIndices = new Array<boolean>(this.numContacts); // all undefined to start
|
||||
}
|
||||
|
||||
@@ -245,6 +249,12 @@ export default class GivenPrompts extends Vue {
|
||||
const mappedContacts = databaseUtil.mapQueryResultToValues(result);
|
||||
this.currentContact = mappedContacts[0] as unknown as Contact;
|
||||
}
|
||||
if (USE_DEXIE_DB) {
|
||||
await db.open();
|
||||
this.currentContact = await db.contacts
|
||||
.offset(someContactDbIndex)
|
||||
.first();
|
||||
}
|
||||
this.shownContactDbIndices[someContactDbIndex] = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
If you'd like an introduction,
|
||||
<a
|
||||
class="text-blue-500"
|
||||
@click="copyToClipboard('A link to this page', deepLinkUrl)"
|
||||
@click="copyToClipboard('A link to this page', windowLocation)"
|
||||
>click here to copy this page, paste it into a message, and ask if
|
||||
they'll tell you more about the {{ roleName }}.</a
|
||||
>
|
||||
@@ -104,7 +104,7 @@ import * as R from "ramda";
|
||||
import { useClipboard } from "@vueuse/core";
|
||||
import { Contact } from "../db/tables/contacts";
|
||||
import * as serverUtil from "../libs/endorserServer";
|
||||
import { APP_SERVER, NotificationIface } from "../constants/app";
|
||||
import { NotificationIface } from "../constants/app";
|
||||
|
||||
@Component
|
||||
export default class HiddenDidDialog extends Vue {
|
||||
@@ -117,8 +117,7 @@ export default class HiddenDidDialog extends Vue {
|
||||
activeDid = "";
|
||||
allMyDids: Array<string> = [];
|
||||
canShare = false;
|
||||
deepLinkPathSuffix = "";
|
||||
deepLinkUrl = window.location.href; // this is changed to a deep link in the setup
|
||||
windowLocation = window.location.href;
|
||||
|
||||
R = R;
|
||||
serverUtil = serverUtil;
|
||||
@@ -130,21 +129,17 @@ export default class HiddenDidDialog extends Vue {
|
||||
}
|
||||
|
||||
open(
|
||||
deepLinkPathSuffix: string,
|
||||
roleName: string,
|
||||
visibleToDids: string[],
|
||||
allContacts: Array<Contact>,
|
||||
activeDid: string,
|
||||
allMyDids: Array<string>,
|
||||
) {
|
||||
this.deepLinkPathSuffix = deepLinkPathSuffix;
|
||||
this.roleName = roleName;
|
||||
this.visibleToDids = visibleToDids;
|
||||
this.allContacts = allContacts;
|
||||
this.activeDid = activeDid;
|
||||
this.allMyDids = allMyDids;
|
||||
|
||||
this.deepLinkUrl = APP_SERVER + "/deep-link/" + this.deepLinkPathSuffix;
|
||||
this.isOpen = true;
|
||||
}
|
||||
|
||||
@@ -178,11 +173,11 @@ export default class HiddenDidDialog extends Vue {
|
||||
}
|
||||
|
||||
onClickShareClaim() {
|
||||
this.copyToClipboard("A link to this page", this.deepLinkUrl);
|
||||
this.copyToClipboard("A link to this page", this.windowLocation);
|
||||
window.navigator.share({
|
||||
title: "Help Connect Me",
|
||||
text: "I'm trying to find the people who recorded this. Can you help me?",
|
||||
url: this.deepLinkUrl,
|
||||
url: this.windowLocation,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
<template>
|
||||
<svg
|
||||
v-if="iconData"
|
||||
:class="svgClass"
|
||||
:fill="fill"
|
||||
:stroke="stroke"
|
||||
:viewBox="viewBox"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path v-for="(path, index) in iconData.paths" :key="index" v-bind="path" />
|
||||
</svg>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Component, Prop, Vue } from "vue-facing-decorator";
|
||||
import icons from "../assets/icons.json";
|
||||
import { logger } from "../utils/logger";
|
||||
|
||||
/**
|
||||
* Icon path interface
|
||||
*/
|
||||
interface IconPath {
|
||||
d: string;
|
||||
fillRule?: string;
|
||||
clipRule?: string;
|
||||
strokeLinecap?: string;
|
||||
strokeLinejoin?: string;
|
||||
strokeWidth?: string | number;
|
||||
fill?: string;
|
||||
stroke?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Icon data interface
|
||||
*/
|
||||
interface IconData {
|
||||
paths: IconPath[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Icons JSON structure
|
||||
*/
|
||||
interface IconsJson {
|
||||
[key: string]: IconPath | IconData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Icon Renderer Component
|
||||
*
|
||||
* This component loads SVG icon definitions from a JSON file and renders them
|
||||
* as SVG elements. It provides a clean way to use icons without cluttering
|
||||
* templates with long SVG path definitions.
|
||||
*
|
||||
* @author Matthew Raymer
|
||||
* @version 1.0.0
|
||||
* @since 2024
|
||||
*/
|
||||
@Component({
|
||||
name: "IconRenderer",
|
||||
})
|
||||
export default class IconRenderer extends Vue {
|
||||
@Prop({ required: true }) readonly iconName!: string;
|
||||
@Prop({ default: "h-5 w-5" }) readonly svgClass!: string;
|
||||
@Prop({ default: "none" }) readonly fill!: string;
|
||||
@Prop({ default: "currentColor" }) readonly stroke!: string;
|
||||
@Prop({ default: "0 0 24 24" }) readonly viewBox!: string;
|
||||
|
||||
/**
|
||||
* Get the icon data for the specified icon name
|
||||
*
|
||||
* @returns {IconData | null} The icon data object or null if not found
|
||||
*/
|
||||
get iconData(): IconData | null {
|
||||
const icon = (icons as IconsJson)[this.iconName];
|
||||
if (!icon) {
|
||||
logger.warn(`Icon "${this.iconName}" not found in icons.json`);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Convert single path to array format for consistency
|
||||
if ("d" in icon) {
|
||||
return {
|
||||
paths: [icon as IconPath],
|
||||
};
|
||||
}
|
||||
|
||||
return icon as IconData;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -261,22 +261,35 @@ import { ref } from "vue";
|
||||
import { Component, Vue } from "vue-facing-decorator";
|
||||
import VuePictureCropper, { cropper } from "vue-picture-cropper";
|
||||
import { Capacitor } from "@capacitor/core";
|
||||
import { DEFAULT_IMAGE_API_SERVER, NotificationIface } from "../constants/app";
|
||||
import {
|
||||
DEFAULT_IMAGE_API_SERVER,
|
||||
NotificationIface,
|
||||
USE_DEXIE_DB,
|
||||
} from "../constants/app";
|
||||
import { retrieveSettingsForActiveAccount } from "../db/index";
|
||||
import { accessToken } from "../libs/crypto";
|
||||
import { logger } from "../utils/logger";
|
||||
import { PlatformServiceFactory } from "../services/PlatformServiceFactory";
|
||||
import * as databaseUtil from "../db/databaseUtil";
|
||||
import { Prop } from "vue-facing-decorator";
|
||||
import { Router } from "vue-router";
|
||||
|
||||
const inputImageFileNameRef = ref<Blob>();
|
||||
|
||||
@Component({
|
||||
components: { VuePictureCropper },
|
||||
props: {
|
||||
isRegistered: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
defaultCameraMode: {
|
||||
type: String,
|
||||
default: "environment",
|
||||
validator: (value: string) => ["environment", "user"].includes(value),
|
||||
},
|
||||
},
|
||||
})
|
||||
export default class ImageMethodDialog extends Vue {
|
||||
$notify!: (notification: NotificationIface, timeout?: number) => void;
|
||||
$router!: Router;
|
||||
|
||||
/** Active DID for user authentication */
|
||||
activeDid = "";
|
||||
@@ -294,7 +307,7 @@ export default class ImageMethodDialog extends Vue {
|
||||
fileName?: string;
|
||||
|
||||
/** Callback function to set image URL after upload */
|
||||
imageCallback: (imageUrl: string) => void = () => {};
|
||||
imageCallback: (imageUrl?: string) => void = () => {};
|
||||
|
||||
/** URL for image input */
|
||||
imageUrl?: string;
|
||||
@@ -342,21 +355,16 @@ export default class ImageMethodDialog extends Vue {
|
||||
cameraStateMessage?: string;
|
||||
error: string | null = null;
|
||||
|
||||
// Props
|
||||
@Prop({ default: true }) isRegistered!: boolean;
|
||||
@Prop({
|
||||
default: "environment",
|
||||
validator: (value: string) => ["environment", "user"].includes(value),
|
||||
})
|
||||
defaultCameraMode!: string;
|
||||
|
||||
/**
|
||||
* Lifecycle hook: Initializes component and retrieves user settings
|
||||
* @throws {Error} When settings retrieval fails
|
||||
*/
|
||||
async mounted() {
|
||||
try {
|
||||
const settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
let settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
if (USE_DEXIE_DB) {
|
||||
settings = await retrieveSettingsForActiveAccount();
|
||||
}
|
||||
this.activeDid = settings.activeDid || "";
|
||||
} catch (error: unknown) {
|
||||
logger.error("Error retrieving settings from database:", error);
|
||||
@@ -410,7 +418,7 @@ export default class ImageMethodDialog extends Vue {
|
||||
type: file.type,
|
||||
});
|
||||
this.blob = blob;
|
||||
this.fileName = (file as File).name;
|
||||
this.fileName = file.name;
|
||||
this.showRetry = false;
|
||||
}
|
||||
};
|
||||
@@ -441,7 +449,7 @@ export default class ImageMethodDialog extends Vue {
|
||||
);
|
||||
}
|
||||
} else {
|
||||
this.imageCallback(this.imageUrl as string);
|
||||
this.imageCallback(this.imageUrl);
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +159,11 @@
|
||||
<script lang="ts">
|
||||
import { Component, Vue, Prop } from "vue-facing-decorator";
|
||||
|
||||
import { logConsoleAndDb } from "../db/index";
|
||||
import {
|
||||
logConsoleAndDb,
|
||||
retrieveSettingsForActiveAccount,
|
||||
db,
|
||||
} from "../db/index";
|
||||
import {
|
||||
errorStringForLog,
|
||||
getHeaders,
|
||||
@@ -170,7 +174,7 @@ import { decryptMessage } from "../libs/crypto";
|
||||
import { Contact } from "../db/tables/contacts";
|
||||
import * as databaseUtil from "../db/databaseUtil";
|
||||
import * as libsUtil from "../libs/util";
|
||||
import { NotificationIface } from "../constants/app";
|
||||
import { NotificationIface, USE_DEXIE_DB } from "../constants/app";
|
||||
import { PlatformServiceFactory } from "@/services/PlatformServiceFactory";
|
||||
|
||||
interface Member {
|
||||
@@ -207,7 +211,10 @@ export default class MembersList extends Vue {
|
||||
contacts: Array<Contact> = [];
|
||||
|
||||
async created() {
|
||||
const settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
let settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
if (USE_DEXIE_DB) {
|
||||
settings = await retrieveSettingsForActiveAccount();
|
||||
}
|
||||
this.activeDid = settings.activeDid || "";
|
||||
this.apiServer = settings.apiServer || "";
|
||||
this.firstName = settings.firstName || "";
|
||||
@@ -360,6 +367,9 @@ export default class MembersList extends Vue {
|
||||
result,
|
||||
) as unknown as Contact[];
|
||||
}
|
||||
if (USE_DEXIE_DB) {
|
||||
this.contacts = await db.contacts.toArray();
|
||||
}
|
||||
}
|
||||
|
||||
getContactFor(did: string): Contact | undefined {
|
||||
@@ -448,6 +458,9 @@ export default class MembersList extends Vue {
|
||||
"UPDATE contacts SET registered = ? WHERE did = ?",
|
||||
[true, decrMember.did],
|
||||
);
|
||||
if (USE_DEXIE_DB) {
|
||||
await db.contacts.update(decrMember.did, { registered: true });
|
||||
}
|
||||
oldContact.registered = true;
|
||||
}
|
||||
this.$notify(
|
||||
@@ -505,6 +518,9 @@ export default class MembersList extends Vue {
|
||||
"INSERT INTO contacts (did, name) VALUES (?, ?)",
|
||||
[member.did, member.name],
|
||||
);
|
||||
if (USE_DEXIE_DB) {
|
||||
await db.contacts.add(newContact);
|
||||
}
|
||||
this.contacts.push(newContact);
|
||||
|
||||
this.$notify(
|
||||
|
||||
@@ -82,10 +82,14 @@
|
||||
<script lang="ts">
|
||||
import { Vue, Component, Prop } from "vue-facing-decorator";
|
||||
|
||||
import { NotificationIface } from "../constants/app";
|
||||
import { createAndSubmitOffer } from "../libs/endorserServer";
|
||||
import { NotificationIface, USE_DEXIE_DB } from "../constants/app";
|
||||
import {
|
||||
createAndSubmitOffer,
|
||||
serverMessageForUser,
|
||||
} from "../libs/endorserServer";
|
||||
import * as libsUtil from "../libs/util";
|
||||
import * as databaseUtil from "../db/databaseUtil";
|
||||
import { retrieveSettingsForActiveAccount } from "../db/index";
|
||||
import { logger } from "../utils/logger";
|
||||
|
||||
@Component
|
||||
@@ -113,7 +117,10 @@ export default class OfferDialog extends Vue {
|
||||
this.recipientDid = recipientDid;
|
||||
this.recipientName = recipientName;
|
||||
|
||||
const settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
let settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
if (USE_DEXIE_DB) {
|
||||
settings = await retrieveSettingsForActiveAccount();
|
||||
}
|
||||
this.apiServer = settings.apiServer || "";
|
||||
this.activeDid = settings.activeDid || "";
|
||||
|
||||
|
||||
@@ -200,7 +200,12 @@
|
||||
import { Component, Vue } from "vue-facing-decorator";
|
||||
import { Router } from "vue-router";
|
||||
|
||||
import { NotificationIface } from "../constants/app";
|
||||
import { NotificationIface, USE_DEXIE_DB } from "../constants/app";
|
||||
import {
|
||||
db,
|
||||
retrieveSettingsForActiveAccount,
|
||||
updateAccountSettings,
|
||||
} from "../db/index";
|
||||
import * as databaseUtil from "../db/databaseUtil";
|
||||
import { OnboardPage } from "../libs/util";
|
||||
import { PlatformServiceFactory } from "@/services/PlatformServiceFactory";
|
||||
@@ -228,7 +233,10 @@ export default class OnboardingDialog extends Vue {
|
||||
|
||||
async open(page: OnboardPage) {
|
||||
this.page = page;
|
||||
const settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
let settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
if (USE_DEXIE_DB) {
|
||||
settings = await retrieveSettingsForActiveAccount();
|
||||
}
|
||||
this.activeDid = settings.activeDid || "";
|
||||
this.isRegistered = !!settings.isRegistered;
|
||||
const platformService = PlatformServiceFactory.getInstance();
|
||||
@@ -241,12 +249,24 @@ export default class OnboardingDialog extends Vue {
|
||||
]) as unknown as Contact;
|
||||
this.firstContactName = fullContact.name || "";
|
||||
}
|
||||
if (USE_DEXIE_DB) {
|
||||
const contacts = await db.contacts.toArray();
|
||||
this.numContacts = contacts.length;
|
||||
if (this.numContacts > 0) {
|
||||
this.firstContactName = contacts[0].name || "";
|
||||
}
|
||||
}
|
||||
this.visible = true;
|
||||
if (this.page === OnboardPage.Create) {
|
||||
// we'll assume that they've been through all the other pages
|
||||
await databaseUtil.updateDidSpecificSettings(this.activeDid, {
|
||||
finishedOnboarding: true,
|
||||
});
|
||||
if (USE_DEXIE_DB) {
|
||||
await updateAccountSettings(this.activeDid, {
|
||||
finishedOnboarding: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,6 +276,11 @@ export default class OnboardingDialog extends Vue {
|
||||
await databaseUtil.updateDidSpecificSettings(this.activeDid, {
|
||||
finishedOnboarding: true,
|
||||
});
|
||||
if (USE_DEXIE_DB) {
|
||||
await updateAccountSettings(this.activeDid, {
|
||||
finishedOnboarding: true,
|
||||
});
|
||||
}
|
||||
if (goHome) {
|
||||
this.$router.push({ name: "home" });
|
||||
}
|
||||
|
||||
@@ -119,8 +119,13 @@ PhotoDialog.vue */
|
||||
import axios from "axios";
|
||||
import { Component, Vue } from "vue-facing-decorator";
|
||||
import VuePictureCropper, { cropper } from "vue-picture-cropper";
|
||||
import { DEFAULT_IMAGE_API_SERVER, NotificationIface } from "../constants/app";
|
||||
import {
|
||||
DEFAULT_IMAGE_API_SERVER,
|
||||
NotificationIface,
|
||||
USE_DEXIE_DB,
|
||||
} from "../constants/app";
|
||||
import * as databaseUtil from "../db/databaseUtil";
|
||||
import { retrieveSettingsForActiveAccount } from "../db/index";
|
||||
import { accessToken } from "../libs/crypto";
|
||||
import { logger } from "../utils/logger";
|
||||
import { PlatformServiceFactory } from "../services/PlatformServiceFactory";
|
||||
@@ -175,7 +180,10 @@ export default class PhotoDialog extends Vue {
|
||||
async mounted() {
|
||||
// logger.log("PhotoDialog mounted");
|
||||
try {
|
||||
const settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
let settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
if (USE_DEXIE_DB) {
|
||||
settings = await retrieveSettingsForActiveAccount();
|
||||
}
|
||||
this.activeDid = settings.activeDid || "";
|
||||
this.isRegistered = !!settings.isRegistered;
|
||||
logger.log("isRegistered:", this.isRegistered);
|
||||
|
||||
@@ -102,9 +102,17 @@
|
||||
<script lang="ts">
|
||||
import { Component, Vue } from "vue-facing-decorator";
|
||||
|
||||
import { DEFAULT_PUSH_SERVER, NotificationIface } from "../constants/app";
|
||||
import {
|
||||
DEFAULT_PUSH_SERVER,
|
||||
NotificationIface,
|
||||
USE_DEXIE_DB,
|
||||
} from "../constants/app";
|
||||
import * as databaseUtil from "../db/databaseUtil";
|
||||
import { logConsoleAndDb, secretDB } from "../db/index";
|
||||
import {
|
||||
logConsoleAndDb,
|
||||
retrieveSettingsForActiveAccount,
|
||||
secretDB,
|
||||
} from "../db/index";
|
||||
import { MASTER_SECRET_KEY } from "../db/tables/secret";
|
||||
import { urlBase64ToUint8Array } from "../libs/crypto/vc/util";
|
||||
import * as libsUtil from "../libs/util";
|
||||
@@ -166,7 +174,10 @@ export default class PushNotificationPermission extends Vue {
|
||||
this.isVisible = true;
|
||||
this.pushType = pushType;
|
||||
try {
|
||||
const settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
let settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
if (USE_DEXIE_DB) {
|
||||
settings = await retrieveSettingsForActiveAccount();
|
||||
}
|
||||
let pushUrl = DEFAULT_PUSH_SERVER;
|
||||
if (settings?.webPushServer) {
|
||||
pushUrl = settings.webPushServer;
|
||||
|
||||
@@ -15,8 +15,9 @@
|
||||
<script lang="ts">
|
||||
import { Component, Vue, Prop } from "vue-facing-decorator";
|
||||
|
||||
import { AppString, NotificationIface } from "../constants/app";
|
||||
import { AppString, NotificationIface, USE_DEXIE_DB } from "../constants/app";
|
||||
import * as databaseUtil from "../db/databaseUtil";
|
||||
import { retrieveSettingsForActiveAccount } from "../db/index";
|
||||
|
||||
@Component
|
||||
export default class TopMessage extends Vue {
|
||||
@@ -28,7 +29,10 @@ export default class TopMessage extends Vue {
|
||||
|
||||
async mounted() {
|
||||
try {
|
||||
const settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
let settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
if (USE_DEXIE_DB) {
|
||||
settings = await retrieveSettingsForActiveAccount();
|
||||
}
|
||||
if (
|
||||
settings.warnIfTestServer &&
|
||||
settings.apiServer !== AppString.PROD_ENDORSER_API_SERVER
|
||||
@@ -40,7 +44,8 @@ export default class TopMessage extends Vue {
|
||||
settings.apiServer === AppString.PROD_ENDORSER_API_SERVER
|
||||
) {
|
||||
const didPrefix = settings.activeDid?.slice(11, 15);
|
||||
this.message = "You are using prod, user " + didPrefix;
|
||||
this.message =
|
||||
"You are using prod, user " + didPrefix;
|
||||
}
|
||||
} catch (err: unknown) {
|
||||
this.$notify(
|
||||
|
||||
@@ -37,7 +37,8 @@
|
||||
<script lang="ts">
|
||||
import { Vue, Component, Prop } from "vue-facing-decorator";
|
||||
|
||||
import { NotificationIface } from "../constants/app";
|
||||
import { NotificationIface, USE_DEXIE_DB } from "../constants/app";
|
||||
import { db, retrieveSettingsForActiveAccount } from "../db/index";
|
||||
import * as databaseUtil from "../db/databaseUtil";
|
||||
import { MASTER_SETTINGS_KEY } from "../db/tables/settings";
|
||||
import { PlatformServiceFactory } from "@/services/PlatformServiceFactory";
|
||||
@@ -62,7 +63,10 @@ export default class UserNameDialog extends Vue {
|
||||
*/
|
||||
async open(aCallback?: (name?: string) => void) {
|
||||
this.callback = aCallback || this.callback;
|
||||
const settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
let settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
if (USE_DEXIE_DB) {
|
||||
settings = await retrieveSettingsForActiveAccount();
|
||||
}
|
||||
this.givenName = settings.firstName || "";
|
||||
this.visible = true;
|
||||
}
|
||||
@@ -73,6 +77,11 @@ export default class UserNameDialog extends Vue {
|
||||
"UPDATE settings SET firstName = ? WHERE id = ?",
|
||||
[this.givenName, MASTER_SETTINGS_KEY],
|
||||
);
|
||||
if (USE_DEXIE_DB) {
|
||||
await db.settings.update(MASTER_SETTINGS_KEY, {
|
||||
firstName: this.givenName,
|
||||
});
|
||||
}
|
||||
this.visible = false;
|
||||
this.callback(this.givenName);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@ import * as THREE from "three";
|
||||
import { GLTFLoader } from "three/addons/loaders/GLTFLoader";
|
||||
import * as SkeletonUtils from "three/addons/utils/SkeletonUtils";
|
||||
import * as TWEEN from "@tweenjs/tween.js";
|
||||
import { USE_DEXIE_DB } from "../../../../constants/app";
|
||||
import * as databaseUtil from "../../../../db/databaseUtil";
|
||||
import { retrieveSettingsForActiveAccount } from "../../../../db";
|
||||
import { getHeaders } from "../../../../libs/endorserServer";
|
||||
import { logger } from "../../../../utils/logger";
|
||||
|
||||
@@ -14,7 +16,10 @@ export async function loadLandmarks(vue, world, scene, loop) {
|
||||
vue.setWorldProperty("animationDurationSeconds", ANIMATION_DURATION_SECS);
|
||||
|
||||
try {
|
||||
const settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
let settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
if (USE_DEXIE_DB) {
|
||||
settings = await retrieveSettingsForActiveAccount();
|
||||
}
|
||||
const activeDid = settings.activeDid || "";
|
||||
const apiServer = settings.apiServer;
|
||||
const headers = await getHeaders(activeDid);
|
||||
|
||||
@@ -1,312 +0,0 @@
|
||||
/**
|
||||
* @file useCompactDatabase.ts
|
||||
* @description Compact database composable that eliminates boilerplate code
|
||||
*
|
||||
* This composable provides a streamlined, compact API for database operations
|
||||
* that works with both vue-facing-decorator class components and Composition API.
|
||||
* It automatically handles service instantiation, result mapping, and logging.
|
||||
*
|
||||
* @author Matthew Raymer
|
||||
* @version 1.0.0
|
||||
* @since 2025-07-01
|
||||
*/
|
||||
|
||||
import { PlatformServiceFactory } from "@/services/PlatformServiceFactory";
|
||||
import { PlatformService } from "@/services/PlatformService";
|
||||
import { Settings } from "@/db/tables/settings";
|
||||
import * as databaseUtil from "@/db/databaseUtil";
|
||||
import { logger } from "@/utils/logger";
|
||||
|
||||
// Singleton pattern for platform service
|
||||
let platformInstance: PlatformService | null = null;
|
||||
|
||||
/**
|
||||
* Gets the platform service instance (lazy singleton)
|
||||
*/
|
||||
function getPlatform(): PlatformService {
|
||||
if (!platformInstance) {
|
||||
platformInstance = PlatformServiceFactory.getInstance();
|
||||
}
|
||||
return platformInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compact database interface with automatic result mapping and logging
|
||||
*/
|
||||
export interface CompactDB {
|
||||
// Query operations (auto-mapped results)
|
||||
query<T = Record<string, unknown>>(
|
||||
sql: string,
|
||||
params?: unknown[],
|
||||
): Promise<T[]>;
|
||||
queryOne<T = Record<string, unknown>>(
|
||||
sql: string,
|
||||
params?: unknown[],
|
||||
): Promise<T | null>;
|
||||
|
||||
// Execute operations
|
||||
exec(
|
||||
sql: string,
|
||||
params?: unknown[],
|
||||
): Promise<{ changes: number; lastId?: number }>;
|
||||
|
||||
// CRUD helpers
|
||||
insert(
|
||||
tableName: string,
|
||||
data: Record<string, unknown>,
|
||||
): Promise<{ changes: number; lastId?: number }>;
|
||||
update(
|
||||
tableName: string,
|
||||
data: Record<string, unknown>,
|
||||
where: string,
|
||||
whereParams?: unknown[],
|
||||
): Promise<{ changes: number; lastId?: number }>;
|
||||
delete(
|
||||
tableName: string,
|
||||
where: string,
|
||||
whereParams?: unknown[],
|
||||
): Promise<{ changes: number; lastId?: number }>;
|
||||
|
||||
// Settings shortcuts
|
||||
getSettings(): Promise<Settings>;
|
||||
saveSettings(settings: Partial<Settings>): Promise<boolean>;
|
||||
|
||||
// Logging shortcuts
|
||||
log(message: string, level?: string): Promise<void>;
|
||||
logError(message: string): Promise<void>;
|
||||
|
||||
// Diagnostics and monitoring
|
||||
getDiagnostics(): any;
|
||||
checkHealth(): Promise<boolean>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compact database implementation
|
||||
*/
|
||||
class CompactDatabase implements CompactDB {
|
||||
private platform = getPlatform();
|
||||
|
||||
/**
|
||||
* Execute query and return auto-mapped results
|
||||
*/
|
||||
async query<T = Record<string, unknown>>(
|
||||
sql: string,
|
||||
params?: unknown[],
|
||||
): Promise<T[]> {
|
||||
const result = await this.platform.dbQuery(sql, params);
|
||||
return databaseUtil.mapQueryResultToValues(result) as T[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute query and return first result or null
|
||||
*/
|
||||
async queryOne<T = Record<string, unknown>>(
|
||||
sql: string,
|
||||
params?: unknown[],
|
||||
): Promise<T | null> {
|
||||
const results = await this.query<T>(sql, params);
|
||||
return results.length > 0 ? results[0] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute SQL statement
|
||||
*/
|
||||
async exec(
|
||||
sql: string,
|
||||
params?: unknown[],
|
||||
): Promise<{ changes: number; lastId?: number }> {
|
||||
return this.platform.dbExec(sql, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert data into table (auto-generates SQL)
|
||||
*/
|
||||
async insert(
|
||||
tableName: string,
|
||||
data: Record<string, unknown>,
|
||||
): Promise<{ changes: number; lastId?: number }> {
|
||||
const { sql, params } = databaseUtil.generateInsertStatement(
|
||||
data,
|
||||
tableName,
|
||||
);
|
||||
return this.exec(sql, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update data in table (auto-generates SQL)
|
||||
*/
|
||||
async update(
|
||||
tableName: string,
|
||||
data: Record<string, unknown>,
|
||||
where: string,
|
||||
whereParams: unknown[] = [],
|
||||
): Promise<{ changes: number; lastId?: number }> {
|
||||
const { sql, params } = databaseUtil.generateUpdateStatement(
|
||||
data,
|
||||
tableName,
|
||||
where,
|
||||
whereParams,
|
||||
);
|
||||
return this.exec(sql, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete from table
|
||||
*/
|
||||
async delete(
|
||||
tableName: string,
|
||||
where: string,
|
||||
whereParams: unknown[] = [],
|
||||
): Promise<{ changes: number; lastId?: number }> {
|
||||
return this.exec(`DELETE FROM ${tableName} WHERE ${where}`, whereParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get active account settings (with account-specific overrides)
|
||||
*/
|
||||
async getSettings(): Promise<Settings> {
|
||||
return databaseUtil.retrieveSettingsForActiveAccount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings changes
|
||||
*/
|
||||
async saveSettings(settings: Partial<Settings>): Promise<boolean> {
|
||||
return databaseUtil.updateDefaultSettings(settings as Settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log message to database
|
||||
*/
|
||||
async log(message: string, level: string = "info"): Promise<void> {
|
||||
return databaseUtil.logToDb(message, level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log error message to database
|
||||
*/
|
||||
async logError(message: string): Promise<void> {
|
||||
return databaseUtil.logToDb(message, "error");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get diagnostic information about the database service state
|
||||
* @returns Diagnostic information from the underlying database service
|
||||
*/
|
||||
getDiagnostics(): any {
|
||||
try {
|
||||
return this.platform.getDatabaseDiagnostics();
|
||||
} catch (error) {
|
||||
logger.error("[CompactDB] Failed to get diagnostics", {
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
return {
|
||||
error: "Failed to get diagnostics",
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a health check on the database service
|
||||
* @returns Promise resolving to true if the database is healthy
|
||||
*/
|
||||
async checkHealth(): Promise<boolean> {
|
||||
try {
|
||||
const isHealthy = await this.platform.checkDatabaseHealth();
|
||||
logger.info("[CompactDB] Health check completed", {
|
||||
isHealthy,
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
return isHealthy;
|
||||
} catch (error) {
|
||||
logger.error("[CompactDB] Health check failed", {
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Singleton instance
|
||||
let dbInstance: CompactDatabase | null = null;
|
||||
|
||||
/**
|
||||
* Compact database composable for streamlined database operations
|
||||
*
|
||||
* This composable eliminates boilerplate by providing:
|
||||
* - Automatic result mapping for queries
|
||||
* - Auto-generated INSERT/UPDATE statements
|
||||
* - Built-in logging shortcuts
|
||||
* - Settings management shortcuts
|
||||
* - Simplified error handling
|
||||
*
|
||||
* Usage Examples:
|
||||
*
|
||||
* ```typescript
|
||||
* // In vue-facing-decorator class component:
|
||||
* @Component
|
||||
* export default class MyComponent extends Vue {
|
||||
* private db = useCompactDatabase();
|
||||
*
|
||||
* async loadContacts() {
|
||||
* // One line instead of 4!
|
||||
* const contacts = await this.db.query<Contact>("SELECT * FROM contacts WHERE visible = ?", [1]);
|
||||
* await this.db.log(`Loaded ${contacts.length} contacts`);
|
||||
* }
|
||||
*
|
||||
* async saveContact(contact: Contact) {
|
||||
* // Auto-generates INSERT statement
|
||||
* const result = await this.db.insert("contacts", contact);
|
||||
* await this.db.log(`Contact saved with ID: ${result.lastId}`);
|
||||
* }
|
||||
*
|
||||
* // Diagnostic and health monitoring
|
||||
* async checkDatabaseHealth() {
|
||||
* const isHealthy = await this.db.checkHealth();
|
||||
* const diagnostics = this.db.getDiagnostics();
|
||||
*
|
||||
* await this.db.log(`Database health: ${isHealthy ? 'OK' : 'FAILED'}`);
|
||||
* await this.db.log(`Queue length: ${diagnostics.queueLength}`);
|
||||
* await this.db.log(`Success rate: ${diagnostics.successRate}`);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* // In Composition API:
|
||||
* export default {
|
||||
* setup() {
|
||||
* const db = useCompactDatabase();
|
||||
*
|
||||
* const loadData = async () => {
|
||||
* const data = await db.query("SELECT * FROM table");
|
||||
* await db.log("Data loaded");
|
||||
* };
|
||||
*
|
||||
* const monitorHealth = async () => {
|
||||
* const isHealthy = await db.checkHealth();
|
||||
* if (!isHealthy) {
|
||||
* const diagnostics = db.getDiagnostics();
|
||||
* console.error("Database unhealthy:", diagnostics);
|
||||
* }
|
||||
* };
|
||||
*
|
||||
* return { loadData, monitorHealth };
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @returns CompactDB interface with streamlined database operations
|
||||
*/
|
||||
export function useCompactDatabase(): CompactDB {
|
||||
if (!dbInstance) {
|
||||
dbInstance = new CompactDatabase();
|
||||
}
|
||||
return dbInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Direct access to compact database (for non-composable usage)
|
||||
*/
|
||||
export const db = useCompactDatabase();
|
||||
@@ -51,6 +51,8 @@ export const IMAGE_TYPE_PROFILE = "profile";
|
||||
export const PASSKEYS_ENABLED =
|
||||
!!import.meta.env.VITE_PASSKEYS_ENABLED || false;
|
||||
|
||||
export const USE_DEXIE_DB = false;
|
||||
|
||||
/**
|
||||
* The possible values for "group" and "type" are in App.vue.
|
||||
* Some of this comes from the notiwind package, some is custom.
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import {
|
||||
registerMigration,
|
||||
runMigrations as runMigrationsService,
|
||||
} from "../services/migrationService";
|
||||
import migrationService from "../services/migrationService";
|
||||
import { DEFAULT_ENDORSER_API_SERVER } from "@/constants/app";
|
||||
import { arrayBufferToBase64 } from "@/libs/crypto";
|
||||
|
||||
@@ -34,6 +31,7 @@ const secretBase64 = arrayBufferToBase64(randomBytes);
|
||||
const MIGRATIONS = [
|
||||
{
|
||||
name: "001_initial",
|
||||
// see ../db/tables files for explanations of the fields
|
||||
sql: `
|
||||
CREATE TABLE IF NOT EXISTS accounts (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
@@ -118,12 +116,6 @@ const MIGRATIONS = [
|
||||
);
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "002_add_iViewContent_to_contacts",
|
||||
sql: `
|
||||
ALTER TABLE contacts ADD COLUMN iViewContent BOOLEAN DEFAULT TRUE;
|
||||
`,
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -131,12 +123,16 @@ const MIGRATIONS = [
|
||||
* @param extractMigrationNames - A function that extracts the names (string array) from "select name from migrations"
|
||||
*/
|
||||
export async function runMigrations<T>(
|
||||
sqlExec: (sql: string, params?: unknown[]) => Promise<unknown>,
|
||||
sqlQuery: (sql: string, params?: unknown[]) => Promise<T>,
|
||||
sqlExec: (sql: string) => Promise<unknown>,
|
||||
sqlQuery: (sql: string) => Promise<T>,
|
||||
extractMigrationNames: (result: T) => Set<string>,
|
||||
): Promise<void> {
|
||||
for (const migration of MIGRATIONS) {
|
||||
registerMigration(migration);
|
||||
migrationService.registerMigration(migration);
|
||||
}
|
||||
await runMigrationsService(sqlExec, sqlQuery, extractMigrationNames);
|
||||
await migrationService.runMigrations(
|
||||
sqlExec,
|
||||
sqlQuery,
|
||||
extractMigrationNames,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -169,70 +169,47 @@ export async function retrieveSettingsForActiveAccount(): Promise<Settings> {
|
||||
let lastCleanupDate: string | null = null;
|
||||
export let memoryLogs: string[] = [];
|
||||
|
||||
// Flag to prevent circular dependency during database initialization
|
||||
let isDatabaseLogginAvailable = false;
|
||||
|
||||
/**
|
||||
* Enable database logging (call this after database is fully initialized)
|
||||
*/
|
||||
export function enableDatabaseLogging(): void {
|
||||
isDatabaseLogginAvailable = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable database logging (call this when database writes are failing)
|
||||
*/
|
||||
export function disableDatabaseLogging(): void {
|
||||
isDatabaseLogginAvailable = false;
|
||||
console.warn("[DatabaseUtil] Database logging disabled due to write failures");
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a message to the database with proper handling of concurrent writes
|
||||
* @param message - The message to log
|
||||
* @param level - The log level (error, warn, info, debug)
|
||||
* @author Matthew Raymer
|
||||
*/
|
||||
export async function logToDb(
|
||||
message: string,
|
||||
level: string = "info",
|
||||
): Promise<void> {
|
||||
// If database logging is not available, only log to console and return immediately
|
||||
if (!isDatabaseLogginAvailable) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`[DB-DISABLED] ${level.toUpperCase()}: ${message}`);
|
||||
return; // Exit early - do not attempt any database operations
|
||||
}
|
||||
|
||||
// Add to memory log for debugging
|
||||
memoryLogs.push(`${new Date().toISOString()} [${level}] ${message}`);
|
||||
if (memoryLogs.length > 1000) {
|
||||
memoryLogs = memoryLogs.slice(-500); // Keep last 500 entries
|
||||
}
|
||||
export async function logToDb(message: string): Promise<void> {
|
||||
const platform = PlatformServiceFactory.getInstance();
|
||||
const todayKey = new Date().toDateString();
|
||||
const nowKey = new Date().toISOString();
|
||||
|
||||
try {
|
||||
// Get platform service for database operations
|
||||
const platformService = PlatformServiceFactory.getInstance();
|
||||
|
||||
const logData = {
|
||||
timestamp: Date.now(),
|
||||
level,
|
||||
message: message.substring(0, 1000), // Limit message length
|
||||
};
|
||||
memoryLogs.push(`${new Date().toISOString()} ${message}`);
|
||||
// Try to insert first, if it fails due to UNIQUE constraint, update instead
|
||||
await platform.dbExec("INSERT INTO logs (date, message) VALUES (?, ?)", [
|
||||
nowKey,
|
||||
message,
|
||||
]);
|
||||
|
||||
await platformService.dbExec(
|
||||
"INSERT INTO logs (timestamp, level, message) VALUES (?, ?, ?)",
|
||||
[logData.timestamp, logData.level, logData.message],
|
||||
);
|
||||
// Clean up old logs (keep only last 7 days) - do this less frequently
|
||||
// Only clean up if the date is different from the last cleanup
|
||||
if (!lastCleanupDate || lastCleanupDate !== todayKey) {
|
||||
const sevenDaysAgo = new Date(
|
||||
new Date().getTime() - 7 * 24 * 60 * 60 * 1000,
|
||||
);
|
||||
memoryLogs = memoryLogs.filter(
|
||||
(log) => log.split(" ")[0] > sevenDaysAgo.toDateString(),
|
||||
);
|
||||
await platform.dbExec("DELETE FROM logs WHERE date < ?", [
|
||||
sevenDaysAgo.toDateString(),
|
||||
]);
|
||||
lastCleanupDate = todayKey;
|
||||
}
|
||||
} catch (error) {
|
||||
// If database write fails, disable database logging immediately
|
||||
console.error("[DatabaseUtil] Database write failed, disabling database logging:",
|
||||
error instanceof Error ? error.message : String(error));
|
||||
disableDatabaseLogging();
|
||||
|
||||
// Log the original message to console as fallback
|
||||
// Log to console as fallback
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`[DB-FALLBACK] ${level.toUpperCase()}: ${message}`);
|
||||
console.error(
|
||||
"Error logging to database:",
|
||||
error,
|
||||
" ... for original message:",
|
||||
message,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,62 +218,26 @@ export async function logConsoleAndDb(
|
||||
message: string,
|
||||
isError = false,
|
||||
): Promise<void> {
|
||||
const level = isError ? "error" : "info";
|
||||
if (isError) {
|
||||
logger.error(`${new Date().toISOString()}`, message);
|
||||
logger.error(`${new Date().toISOString()} ${message}`);
|
||||
} else {
|
||||
logger.log(`${new Date().toISOString()}`, message);
|
||||
logger.log(`${new Date().toISOString()} ${message}`);
|
||||
}
|
||||
await logToDb(message, level);
|
||||
await logToDb(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates SQL INSERT statement and parameters from a model object
|
||||
*
|
||||
* This helper function creates a parameterized SQL INSERT statement
|
||||
* from a JavaScript object. It filters out undefined values and
|
||||
* creates the appropriate SQL syntax with placeholders.
|
||||
*
|
||||
* The function is used internally by the migration functions to
|
||||
* safely insert data into the SQLite database.
|
||||
*
|
||||
* @function generateInsertStatement
|
||||
* @param {Record<string, unknown>} model - The model object containing fields to insert
|
||||
* @param {string} tableName - The name of the table to insert into
|
||||
* @returns {Object} Object containing the SQL statement and parameters array
|
||||
* @returns {string} returns.sql - The SQL INSERT statement
|
||||
* @returns {unknown[]} returns.params - Array of parameter values
|
||||
* @example
|
||||
* ```typescript
|
||||
* const contact = { did: 'did:example:123', name: 'John Doe' };
|
||||
* const { sql, params } = generateInsertStatement(contact, 'contacts');
|
||||
* // sql: "INSERT INTO contacts (did, name) VALUES (?, ?)"
|
||||
* // params: ['did:example:123', 'John Doe']
|
||||
* ```
|
||||
* Generates an SQL INSERT statement and parameters from a model object.
|
||||
* @param model The model object containing fields to update
|
||||
* @param tableName The name of the table to update
|
||||
* @returns Object containing the SQL statement and parameters array
|
||||
*/
|
||||
export function generateInsertStatement(
|
||||
model: Record<string, unknown>,
|
||||
tableName: string,
|
||||
): { sql: string; params: unknown[] } {
|
||||
const columns = Object.keys(model).filter((key) => model[key] !== undefined);
|
||||
const values = Object.values(model)
|
||||
.filter((value) => value !== undefined)
|
||||
.map((value) => {
|
||||
// Convert values to SQLite-compatible types
|
||||
if (value === null || value === undefined) {
|
||||
return null;
|
||||
}
|
||||
if (typeof value === "object" && value !== null) {
|
||||
// Convert objects and arrays to JSON strings
|
||||
return JSON.stringify(value);
|
||||
}
|
||||
if (typeof value === "boolean") {
|
||||
// Convert boolean to integer (0 or 1)
|
||||
return value ? 1 : 0;
|
||||
}
|
||||
// Numbers, strings, bigints, and buffers are already supported
|
||||
return value;
|
||||
});
|
||||
const values = Object.values(model).filter((value) => value !== undefined);
|
||||
const placeholders = values.map(() => "?").join(", ");
|
||||
const insertSql = `INSERT INTO ${tableName} (${columns.join(", ")}) VALUES (${placeholders})`;
|
||||
|
||||
@@ -307,30 +248,12 @@ export function generateInsertStatement(
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates SQL UPDATE statement and parameters from a model object
|
||||
*
|
||||
* This helper function creates a parameterized SQL UPDATE statement
|
||||
* from a JavaScript object. It filters out undefined values and
|
||||
* creates the appropriate SQL syntax with placeholders.
|
||||
*
|
||||
* The function is used internally by the migration functions to
|
||||
* safely update data in the SQLite database.
|
||||
*
|
||||
* @function generateUpdateStatement
|
||||
* @param {Record<string, unknown>} model - The model object containing fields to update
|
||||
* @param {string} tableName - The name of the table to update
|
||||
* @param {string} whereClause - The WHERE clause for the update (e.g. "id = ?")
|
||||
* @param {unknown[]} [whereParams=[]] - Parameters for the WHERE clause
|
||||
* @returns {Object} Object containing the SQL statement and parameters array
|
||||
* @returns {string} returns.sql - The SQL UPDATE statement
|
||||
* @returns {unknown[]} returns.params - Array of parameter values
|
||||
* @example
|
||||
* ```typescript
|
||||
* const contact = { name: 'Jane Doe' };
|
||||
* const { sql, params } = generateUpdateStatement(contact, 'contacts', 'did = ?', ['did:example:123']);
|
||||
* // sql: "UPDATE contacts SET name = ? WHERE did = ?"
|
||||
* // params: ['Jane Doe', 'did:example:123']
|
||||
* ```
|
||||
* Generates an SQL UPDATE statement and parameters from a model object.
|
||||
* @param model The model object containing fields to update
|
||||
* @param tableName The name of the table to update
|
||||
* @param whereClause The WHERE clause for the update (e.g. "id = ?")
|
||||
* @param whereParams Parameters for the WHERE clause
|
||||
* @returns Object containing the SQL statement and parameters array
|
||||
*/
|
||||
export function generateUpdateStatement(
|
||||
model: Record<string, unknown>,
|
||||
@@ -344,18 +267,7 @@ export function generateUpdateStatement(
|
||||
|
||||
Object.entries(model).forEach(([key, value]) => {
|
||||
setClauses.push(`${key} = ?`);
|
||||
// Convert values to SQLite-compatible types
|
||||
let convertedValue = value ?? null;
|
||||
if (convertedValue !== null) {
|
||||
if (typeof convertedValue === "object") {
|
||||
// Convert objects and arrays to JSON strings
|
||||
convertedValue = JSON.stringify(convertedValue);
|
||||
} else if (typeof convertedValue === "boolean") {
|
||||
// Convert boolean to integer (0 or 1)
|
||||
convertedValue = convertedValue ? 1 : 0;
|
||||
}
|
||||
}
|
||||
params.push(convertedValue);
|
||||
params.push(value ?? null);
|
||||
});
|
||||
|
||||
if (setClauses.length === 0) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* This is the original IndexedDB version of the database.
|
||||
* It will eventually be replaced fully by the SQL version in databaseUtil.ts.
|
||||
*
|
||||
* Turn this on or off with the USE_DEXIE_DB constant in constants/app.ts.
|
||||
*/
|
||||
|
||||
import BaseDexie, { Table } from "dexie";
|
||||
|
||||
@@ -1 +1 @@
|
||||
# Check the contact & settings export to see whether you want your new table to be included in it
|
||||
Check the contact & settings export to see whether you want your new table to be included in it.
|
||||
|
||||
@@ -45,7 +45,7 @@ export type Account = {
|
||||
publicKeyHex: string;
|
||||
};
|
||||
|
||||
// TODO: When finished with USE_DEXIE_DB, move these fields to Account and move identity and mnemonic here.
|
||||
// When finished with USE_DEXIE_DB, move these fields to Account and move identity and mnemonic here.
|
||||
export type AccountEncrypted = Account & {
|
||||
identityEncrBase64: string;
|
||||
mnemonicEncrBase64: string;
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
export type ContactMethod = {
|
||||
export interface ContactMethod {
|
||||
label: string;
|
||||
type: string; // eg. "EMAIL", "SMS", "WHATSAPP", maybe someday "GOOGLE-CONTACT-API"
|
||||
value: string;
|
||||
};
|
||||
}
|
||||
|
||||
export type Contact = {
|
||||
export interface Contact {
|
||||
//
|
||||
// When adding a property, consider whether it should be added when exporting & sharing contacts, eg. DataExportSection
|
||||
// When adding a property, consider whether it should be added when exporting & sharing contacts.
|
||||
|
||||
did: string;
|
||||
contactMethods?: Array<ContactMethod>;
|
||||
iViewContent?: boolean;
|
||||
name?: string;
|
||||
nextPubKeyHashB64?: string; // base64-encoded SHA256 hash of next public key
|
||||
notes?: string;
|
||||
@@ -18,17 +17,7 @@ export type Contact = {
|
||||
publicKeyBase64?: string;
|
||||
seesMe?: boolean; // cached value of the server setting
|
||||
registered?: boolean; // cached value of the server setting
|
||||
};
|
||||
|
||||
/**
|
||||
* This is for those cases (eg. with a DB) where every field is a primitive (and not an object).
|
||||
*
|
||||
* This is so that we can reuse most of the type and don't have to maintain another copy.
|
||||
* Another approach uses typescript conditionals: https://chatgpt.com/share/6855cdc3-ab5c-8007-8525-726612016eb2
|
||||
*/
|
||||
export type ContactWithJsonStrings = Omit<Contact, "contactMethods"> & {
|
||||
contactMethods?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export const ContactSchema = {
|
||||
contacts: "&did, name", // no need to key by other things
|
||||
|
||||
@@ -64,11 +64,6 @@ export type Settings = {
|
||||
webPushServer?: string; // Web Push server URL
|
||||
};
|
||||
|
||||
// type of settings where the searchBoxes are JSON strings instead of objects
|
||||
export type SettingsWithJsonStrings = Settings & {
|
||||
searchBoxes: string;
|
||||
};
|
||||
|
||||
export function checkIsAnyFeedFilterOn(settings: Settings): boolean {
|
||||
return !!(settings?.filterFeedByNearby || settings?.filterFeedByVisible);
|
||||
}
|
||||
|
||||
174
src/electron/main.js
Normal file
174
src/electron/main.js
Normal file
@@ -0,0 +1,174 @@
|
||||
const { app, BrowserWindow } = require("electron");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const logger = require("../utils/logger");
|
||||
|
||||
// Check if running in dev mode
|
||||
const isDev = process.argv.includes("--inspect");
|
||||
|
||||
function createWindow() {
|
||||
// Add before createWindow function
|
||||
const preloadPath = path.join(__dirname, "preload.js");
|
||||
logger.log("Checking preload path:", preloadPath);
|
||||
logger.log("Preload exists:", fs.existsSync(preloadPath));
|
||||
|
||||
// Create the browser window.
|
||||
const mainWindow = new BrowserWindow({
|
||||
width: 1200,
|
||||
height: 800,
|
||||
webPreferences: {
|
||||
nodeIntegration: false,
|
||||
contextIsolation: true,
|
||||
webSecurity: true,
|
||||
allowRunningInsecureContent: false,
|
||||
preload: path.join(__dirname, "preload.js"),
|
||||
},
|
||||
});
|
||||
|
||||
// Always open DevTools for now
|
||||
mainWindow.webContents.openDevTools();
|
||||
|
||||
// Intercept requests to fix asset paths
|
||||
mainWindow.webContents.session.webRequest.onBeforeRequest(
|
||||
{
|
||||
urls: [
|
||||
"file://*/*/assets/*",
|
||||
"file://*/assets/*",
|
||||
"file:///assets/*", // Catch absolute paths
|
||||
"<all_urls>", // Catch all URLs as a fallback
|
||||
],
|
||||
},
|
||||
(details, callback) => {
|
||||
let url = details.url;
|
||||
|
||||
// Handle paths that don't start with file://
|
||||
if (!url.startsWith("file://") && url.includes("/assets/")) {
|
||||
url = `file://${path.join(__dirname, "www", url)}`;
|
||||
}
|
||||
|
||||
// Handle absolute paths starting with /assets/
|
||||
if (url.includes("/assets/") && !url.includes("/www/assets/")) {
|
||||
const baseDir = url.includes("dist-electron")
|
||||
? url.substring(
|
||||
0,
|
||||
url.indexOf("/dist-electron") + "/dist-electron".length,
|
||||
)
|
||||
: `file://${__dirname}`;
|
||||
const assetPath = url.split("/assets/")[1];
|
||||
const newUrl = `${baseDir}/www/assets/${assetPath}`;
|
||||
callback({ redirectURL: newUrl });
|
||||
return;
|
||||
}
|
||||
|
||||
callback({}); // No redirect for other URLs
|
||||
},
|
||||
);
|
||||
|
||||
if (isDev) {
|
||||
// Debug info
|
||||
logger.log("Debug Info:");
|
||||
logger.log("Running in dev mode:", isDev);
|
||||
logger.log("App is packaged:", app.isPackaged);
|
||||
logger.log("Process resource path:", process.resourcesPath);
|
||||
logger.log("App path:", app.getAppPath());
|
||||
logger.log("__dirname:", __dirname);
|
||||
logger.log("process.cwd():", process.cwd());
|
||||
}
|
||||
|
||||
const indexPath = path.join(__dirname, "www", "index.html");
|
||||
|
||||
if (isDev) {
|
||||
logger.log("Loading index from:", indexPath);
|
||||
logger.log("www path:", path.join(__dirname, "www"));
|
||||
logger.log("www assets path:", path.join(__dirname, "www", "assets"));
|
||||
}
|
||||
|
||||
if (!fs.existsSync(indexPath)) {
|
||||
logger.error(`Index file not found at: ${indexPath}`);
|
||||
throw new Error("Index file not found");
|
||||
}
|
||||
|
||||
// Add CSP headers to allow API connections
|
||||
mainWindow.webContents.session.webRequest.onHeadersReceived(
|
||||
(details, callback) => {
|
||||
callback({
|
||||
responseHeaders: {
|
||||
...details.responseHeaders,
|
||||
"Content-Security-Policy": [
|
||||
"default-src 'self';" +
|
||||
"connect-src 'self' https://api.endorser.ch https://*.timesafari.app;" +
|
||||
"img-src 'self' data: https: blob:;" +
|
||||
"script-src 'self' 'unsafe-inline' 'unsafe-eval';" +
|
||||
"style-src 'self' 'unsafe-inline';" +
|
||||
"font-src 'self' data:;",
|
||||
],
|
||||
},
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
// Load the index.html
|
||||
mainWindow
|
||||
.loadFile(indexPath)
|
||||
.then(() => {
|
||||
logger.log("Successfully loaded index.html");
|
||||
if (isDev) {
|
||||
mainWindow.webContents.openDevTools();
|
||||
logger.log("DevTools opened - running in dev mode");
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
logger.error("Failed to load index.html:", err);
|
||||
logger.error("Attempted path:", indexPath);
|
||||
});
|
||||
|
||||
// Listen for console messages from the renderer
|
||||
mainWindow.webContents.on("console-message", (_event, level, message) => {
|
||||
logger.log("Renderer Console:", message);
|
||||
});
|
||||
|
||||
// Add right after creating the BrowserWindow
|
||||
mainWindow.webContents.on(
|
||||
"did-fail-load",
|
||||
(event, errorCode, errorDescription) => {
|
||||
logger.error("Page failed to load:", errorCode, errorDescription);
|
||||
},
|
||||
);
|
||||
|
||||
mainWindow.webContents.on("preload-error", (event, preloadPath, error) => {
|
||||
logger.error("Preload script error:", preloadPath, error);
|
||||
});
|
||||
|
||||
mainWindow.webContents.on(
|
||||
"console-message",
|
||||
(event, level, message, line, sourceId) => {
|
||||
logger.log("Renderer Console:", line, sourceId, message);
|
||||
},
|
||||
);
|
||||
|
||||
// Enable remote debugging when in dev mode
|
||||
if (isDev) {
|
||||
mainWindow.webContents.openDevTools();
|
||||
}
|
||||
}
|
||||
|
||||
// Handle app ready
|
||||
app.whenReady().then(createWindow);
|
||||
|
||||
// Handle all windows closed
|
||||
app.on("window-all-closed", () => {
|
||||
if (process.platform !== "darwin") {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
app.on("activate", () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
createWindow();
|
||||
}
|
||||
});
|
||||
|
||||
// Handle any errors
|
||||
process.on("uncaughtException", (error) => {
|
||||
logger.error("Uncaught Exception:", error);
|
||||
});
|
||||
215
src/electron/main.ts
Normal file
215
src/electron/main.ts
Normal file
@@ -0,0 +1,215 @@
|
||||
import { app, BrowserWindow } from "electron";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
// Simple logger implementation
|
||||
const logger = {
|
||||
// eslint-disable-next-line no-console
|
||||
log: (...args: unknown[]) => console.log(...args),
|
||||
// eslint-disable-next-line no-console
|
||||
error: (...args: unknown[]) => console.error(...args),
|
||||
// eslint-disable-next-line no-console
|
||||
info: (...args: unknown[]) => console.info(...args),
|
||||
// eslint-disable-next-line no-console
|
||||
warn: (...args: unknown[]) => console.warn(...args),
|
||||
// eslint-disable-next-line no-console
|
||||
debug: (...args: unknown[]) => console.debug(...args),
|
||||
};
|
||||
|
||||
// Check if running in dev mode
|
||||
const isDev = process.argv.includes("--inspect");
|
||||
|
||||
function createWindow(): void {
|
||||
// Add before createWindow function
|
||||
const preloadPath = path.join(__dirname, "preload.js");
|
||||
logger.log("Checking preload path:", preloadPath);
|
||||
logger.log("Preload exists:", fs.existsSync(preloadPath));
|
||||
|
||||
// Log environment and paths
|
||||
logger.log("process.cwd():", process.cwd());
|
||||
logger.log("__dirname:", __dirname);
|
||||
logger.log("app.getAppPath():", app.getAppPath());
|
||||
logger.log("app.isPackaged:", app.isPackaged);
|
||||
|
||||
// List files in __dirname and __dirname/www
|
||||
try {
|
||||
logger.log("Files in __dirname:", fs.readdirSync(__dirname));
|
||||
const wwwDir = path.join(__dirname, "www");
|
||||
if (fs.existsSync(wwwDir)) {
|
||||
logger.log("Files in www:", fs.readdirSync(wwwDir));
|
||||
} else {
|
||||
logger.log("www directory does not exist in __dirname");
|
||||
}
|
||||
} catch (e) {
|
||||
logger.error("Error reading directories:", e);
|
||||
}
|
||||
|
||||
// Create the browser window.
|
||||
const mainWindow = new BrowserWindow({
|
||||
width: 1200,
|
||||
height: 800,
|
||||
webPreferences: {
|
||||
nodeIntegration: false,
|
||||
contextIsolation: true,
|
||||
webSecurity: true,
|
||||
allowRunningInsecureContent: false,
|
||||
preload: path.join(__dirname, "preload.js"),
|
||||
},
|
||||
});
|
||||
|
||||
// Always open DevTools for now
|
||||
mainWindow.webContents.openDevTools();
|
||||
|
||||
// Intercept requests to fix asset paths
|
||||
mainWindow.webContents.session.webRequest.onBeforeRequest(
|
||||
{
|
||||
urls: [
|
||||
"file://*/*/assets/*",
|
||||
"file://*/assets/*",
|
||||
"file:///assets/*", // Catch absolute paths
|
||||
"<all_urls>", // Catch all URLs as a fallback
|
||||
],
|
||||
},
|
||||
(details, callback) => {
|
||||
let url = details.url;
|
||||
|
||||
// Handle paths that don't start with file://
|
||||
if (!url.startsWith("file://") && url.includes("/assets/")) {
|
||||
url = `file://${path.join(__dirname, "www", url)}`;
|
||||
}
|
||||
|
||||
// Handle absolute paths starting with /assets/
|
||||
if (url.includes("/assets/") && !url.includes("/www/assets/")) {
|
||||
const baseDir = url.includes("dist-electron")
|
||||
? url.substring(
|
||||
0,
|
||||
url.indexOf("/dist-electron") + "/dist-electron".length,
|
||||
)
|
||||
: `file://${__dirname}`;
|
||||
const assetPath = url.split("/assets/")[1];
|
||||
const newUrl = `${baseDir}/www/assets/${assetPath}`;
|
||||
callback({ redirectURL: newUrl });
|
||||
return;
|
||||
}
|
||||
|
||||
callback({}); // No redirect for other URLs
|
||||
},
|
||||
);
|
||||
|
||||
if (isDev) {
|
||||
// Debug info
|
||||
logger.log("Debug Info:");
|
||||
logger.log("Running in dev mode:", isDev);
|
||||
logger.log("App is packaged:", app.isPackaged);
|
||||
logger.log("Process resource path:", process.resourcesPath);
|
||||
logger.log("App path:", app.getAppPath());
|
||||
logger.log("__dirname:", __dirname);
|
||||
logger.log("process.cwd():", process.cwd());
|
||||
}
|
||||
|
||||
let indexPath = path.resolve(__dirname, "dist-electron", "www", "index.html");
|
||||
if (!fs.existsSync(indexPath)) {
|
||||
// Fallback for dev mode
|
||||
indexPath = path.resolve(
|
||||
process.cwd(),
|
||||
"dist-electron",
|
||||
"www",
|
||||
"index.html",
|
||||
);
|
||||
}
|
||||
|
||||
if (isDev) {
|
||||
logger.log("Loading index from:", indexPath);
|
||||
logger.log("www path:", path.join(__dirname, "www"));
|
||||
logger.log("www assets path:", path.join(__dirname, "www", "assets"));
|
||||
}
|
||||
|
||||
if (!fs.existsSync(indexPath)) {
|
||||
logger.error(`Index file not found at: ${indexPath}`);
|
||||
throw new Error("Index file not found");
|
||||
}
|
||||
|
||||
// Add CSP headers to allow API connections
|
||||
mainWindow.webContents.session.webRequest.onHeadersReceived(
|
||||
(details, callback) => {
|
||||
callback({
|
||||
responseHeaders: {
|
||||
...details.responseHeaders,
|
||||
"Content-Security-Policy": [
|
||||
"default-src 'self';" +
|
||||
"connect-src 'self' https://api.endorser.ch https://*.timesafari.app;" +
|
||||
"img-src 'self' data: https: blob:;" +
|
||||
"script-src 'self' 'unsafe-inline' 'unsafe-eval';" +
|
||||
"style-src 'self' 'unsafe-inline';" +
|
||||
"font-src 'self' data:;",
|
||||
],
|
||||
},
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
// Load the index.html
|
||||
mainWindow
|
||||
.loadFile(indexPath)
|
||||
.then(() => {
|
||||
logger.log("Successfully loaded index.html");
|
||||
if (isDev) {
|
||||
mainWindow.webContents.openDevTools();
|
||||
logger.log("DevTools opened - running in dev mode");
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
logger.error("Failed to load index.html:", err);
|
||||
logger.error("Attempted path:", indexPath);
|
||||
});
|
||||
|
||||
// Listen for console messages from the renderer
|
||||
mainWindow.webContents.on("console-message", (_event, _level, message) => {
|
||||
logger.log("Renderer Console:", message);
|
||||
});
|
||||
|
||||
// Add right after creating the BrowserWindow
|
||||
mainWindow.webContents.on(
|
||||
"did-fail-load",
|
||||
(_event, errorCode, errorDescription) => {
|
||||
logger.error("Page failed to load:", errorCode, errorDescription);
|
||||
},
|
||||
);
|
||||
|
||||
mainWindow.webContents.on("preload-error", (_event, preloadPath, error) => {
|
||||
logger.error("Preload script error:", preloadPath, error);
|
||||
});
|
||||
|
||||
mainWindow.webContents.on(
|
||||
"console-message",
|
||||
(_event, _level, message, line, sourceId) => {
|
||||
logger.log("Renderer Console:", line, sourceId, message);
|
||||
},
|
||||
);
|
||||
|
||||
// Enable remote debugging when in dev mode
|
||||
if (isDev) {
|
||||
mainWindow.webContents.openDevTools();
|
||||
}
|
||||
}
|
||||
|
||||
// Handle app ready
|
||||
app.whenReady().then(createWindow);
|
||||
|
||||
// Handle all windows closed
|
||||
app.on("window-all-closed", () => {
|
||||
if (process.platform !== "darwin") {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
app.on("activate", () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
createWindow();
|
||||
}
|
||||
});
|
||||
|
||||
// Handle any errors
|
||||
process.on("uncaughtException", (error) => {
|
||||
logger.error("Uncaught Exception:", error);
|
||||
});
|
||||
91
src/electron/preload.js
Normal file
91
src/electron/preload.js
Normal file
@@ -0,0 +1,91 @@
|
||||
const { contextBridge, ipcRenderer } = require("electron");
|
||||
|
||||
const logger = {
|
||||
log: (message, ...args) => {
|
||||
// Always log in development, log with context in production
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
/* eslint-disable no-console */
|
||||
console.log(`[Preload] ${message}`, ...args);
|
||||
/* eslint-enable no-console */
|
||||
}
|
||||
},
|
||||
warn: (message, ...args) => {
|
||||
// Always log warnings
|
||||
/* eslint-disable no-console */
|
||||
console.warn(`[Preload] ${message}`, ...args);
|
||||
/* eslint-enable no-console */
|
||||
},
|
||||
error: (message, ...args) => {
|
||||
// Always log errors
|
||||
/* eslint-disable no-console */
|
||||
console.error(`[Preload] ${message}`, ...args);
|
||||
/* eslint-enable no-console */
|
||||
},
|
||||
info: (message, ...args) => {
|
||||
// Always log info in development, log with context in production
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
/* eslint-disable no-console */
|
||||
console.info(`[Preload] ${message}`, ...args);
|
||||
/* eslint-enable no-console */
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
// Use a more direct path resolution approach
|
||||
const getPath = (pathType) => {
|
||||
switch (pathType) {
|
||||
case "userData":
|
||||
return (
|
||||
process.env.APPDATA ||
|
||||
(process.platform === "darwin"
|
||||
? `${process.env.HOME}/Library/Application Support`
|
||||
: `${process.env.HOME}/.local/share`)
|
||||
);
|
||||
case "home":
|
||||
return process.env.HOME;
|
||||
case "appPath":
|
||||
return process.resourcesPath;
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
logger.info("Preload script starting...");
|
||||
|
||||
// Force electron platform in the renderer process
|
||||
window.process = { env: { VITE_PLATFORM: "electron" } };
|
||||
|
||||
try {
|
||||
contextBridge.exposeInMainWorld("electronAPI", {
|
||||
// Path utilities
|
||||
getPath,
|
||||
|
||||
// IPC functions
|
||||
send: (channel, data) => {
|
||||
const validChannels = ["toMain"];
|
||||
if (validChannels.includes(channel)) {
|
||||
ipcRenderer.send(channel, data);
|
||||
}
|
||||
},
|
||||
receive: (channel, func) => {
|
||||
const validChannels = ["fromMain"];
|
||||
if (validChannels.includes(channel)) {
|
||||
ipcRenderer.on(channel, (event, ...args) => func(...args));
|
||||
}
|
||||
},
|
||||
// Environment info
|
||||
env: {
|
||||
isElectron: true,
|
||||
isDev: process.env.NODE_ENV === "development",
|
||||
platform: "electron", // Explicitly set platform
|
||||
},
|
||||
// Path utilities
|
||||
getBasePath: () => {
|
||||
return process.env.NODE_ENV === "development" ? "/" : "./";
|
||||
},
|
||||
});
|
||||
|
||||
logger.info("Preload script completed successfully");
|
||||
} catch (error) {
|
||||
logger.error("Error in preload script:", error);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user