All files / demo demo-mode.ts

100% Statements 8/8
100% Branches 2/2
100% Functions 2/2
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36                            360x               4x 4x     4x   4x 3x 3x     4x    
/**
 * Demo mode lifecycle — boots Stork with an unencrypted, pre-seeded database
 * and read-only middleware. Used for the hosted public demo.
 *
 * Activated by STORK_DEMO_MODE=1 environment variable.
 */
 
import { existsSync } from "node:fs";
import { join } from "node:path";
import type Database from "better-sqlite3-multiple-ciphers";
import { openDatabase } from "../storage/db.js";
import { seedDemoData } from "./seed.js";
 
export function isDemoMode(): boolean {
	return process.env.STORK_DEMO_MODE === "1";
}
 
/**
 * Boot a demo database: unencrypted, pre-seeded with sample data.
 * Returns the open database handle.
 */
export function bootDemoDatabase(dataDir: string): Database.Database {
	const dbPath = join(dataDir, "stork.db");
	const needsSeed = !existsSync(dbPath);
 
	// Open unencrypted (no vault key)
	const db = openDatabase("stork.db", dataDir);
 
	if (needsSeed) {
		seedDemoData(db);
		console.log("  Demo data seeded: 19 messages, 12 labels, 2 identities (Connector mode)");
	}
 
	return db;
}