From a309145829b653f9cd2c6bf34b60e4c462c2da40 Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Thu, 12 Feb 2026 14:20:42 +0000 Subject: [PATCH] fix(cache): use user-writable ~/.serve.zone/dcrouter for TsmDB and centralize data path logic --- changelog.md | 9 +++++++++ readme.hints.md | 6 +++--- readme.md | 6 +++--- ts/00_commitinfo_data.ts | 2 +- ts/cache/classes.cachedb.ts | 5 +++-- ts/classes.dcrouter.ts | 4 ++-- ts/paths.ts | 16 +++++++++++----- ts_web/00_commitinfo_data.ts | 2 +- 8 files changed, 33 insertions(+), 17 deletions(-) diff --git a/changelog.md b/changelog.md index e1e3ac7..99b76cd 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,14 @@ # Changelog +## 2026-02-12 - 5.0.4 - fix(cache) +use user-writable ~/.serve.zone/dcrouter for TsmDB and centralize data path logic + +- Default TsmDB storage changed from /etc/dcrouter/tsmdb to ~/.serve.zone/dcrouter/tsmdb +- Introduced dcrouterHomeDir, dataDir, and defaultTsmDbPath in ts/paths.ts +- CacheDb now defaults to defaultTsmDbPath when no storagePath is provided +- DcRouter initialization updated to use paths.defaultTsmDbPath; README and readme.hints updated to document the new defaults +- Avoids /etc permission issues and prevents starting a real MongoDB process in tests by using a user-writable default path + ## 2026-02-12 - 5.0.3 - fix(packaging) add files whitelist to package.json and remove Playwright-generated screenshots diff --git a/readme.hints.md b/readme.hints.md index f2517c3..3705e89 100644 --- a/readme.hints.md +++ b/readme.hints.md @@ -46,7 +46,7 @@ Source at `../../push.rocks/smartmta`, release with `gitzone commit -ypbrt` ### SmartProxy v23.1.2 Route Validation - SmartProxy 23.1.2 enforces stricter route validation - Forward actions MUST use `targets` (array) instead of `target` (singular) -- Test configurations that call `DcRouter.start()` need `cacheConfig: { enabled: false }` to avoid `/etc/dcrouter` permission errors +- Test configurations that call `DcRouter.start()` need `cacheConfig: { enabled: false }` to avoid starting a real MongoDB process in tests ```typescript // WRONG - will fail validation @@ -693,7 +693,7 @@ The configuration UI has been converted from an editable interface to a read-onl ## Smartdata Cache System (2026-02-03) ### Overview -DcRouter now uses smartdata + LocalTsmDb for persistent caching. Data is stored at `/etc/dcrouter/tsmdb`. +DcRouter now uses smartdata + LocalTsmDb for persistent caching. Data is stored at `~/.serve.zone/dcrouter/tsmdb`. ### Technology Stack | Layer | Package | Purpose | @@ -747,7 +747,7 @@ await email.delete(); const dcRouter = new DcRouter({ cacheConfig: { enabled: true, - storagePath: '/etc/dcrouter/tsmdb', + storagePath: '~/.serve.zone/dcrouter/tsmdb', dbName: 'dcrouter', cleanupIntervalHours: 1, ttlConfig: { diff --git a/readme.md b/readme.md index d8ab042..ca2eec4 100644 --- a/readme.md +++ b/readme.md @@ -219,7 +219,7 @@ const router = new DcRouter({ storage: { fsPath: '/var/lib/dcrouter/data' }, // Cache database - cacheConfig: { enabled: true, storagePath: '/etc/dcrouter/tsmdb' }, + cacheConfig: { enabled: true, storagePath: '~/.serve.zone/dcrouter/tsmdb' }, // TLS & ACME tls: { contactEmail: 'admin@example.com' }, @@ -388,7 +388,7 @@ interface IDcRouterOptions { }; cacheConfig?: { enabled?: boolean; // default: true - storagePath?: string; // default: '/etc/dcrouter/tsmdb' + storagePath?: string; // default: '~/.serve.zone/dcrouter/tsmdb' dbName?: string; // default: 'dcrouter' cleanupIntervalHours?: number; // default: 1 ttlConfig?: { @@ -734,7 +734,7 @@ An embedded MongoDB-compatible database (via smartdata + LocalTsmDb) for persist ```typescript cacheConfig: { enabled: true, - storagePath: '/etc/dcrouter/tsmdb', + storagePath: '~/.serve.zone/dcrouter/tsmdb', dbName: 'dcrouter', cleanupIntervalHours: 1, ttlConfig: { diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index f53629e..75b9b86 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@serve.zone/dcrouter', - version: '5.0.3', + version: '5.0.4', description: 'A multifaceted routing service handling mail and SMS delivery functions.' } diff --git a/ts/cache/classes.cachedb.ts b/ts/cache/classes.cachedb.ts index 3296c96..5dc1f15 100644 --- a/ts/cache/classes.cachedb.ts +++ b/ts/cache/classes.cachedb.ts @@ -1,11 +1,12 @@ import * as plugins from '../plugins.js'; import { logger } from '../logger.js'; +import { defaultTsmDbPath } from '../paths.js'; /** * Configuration options for CacheDb */ export interface ICacheDbOptions { - /** Base storage path for TsmDB data (default: /etc/dcrouter/tsmdb) */ + /** Base storage path for TsmDB data (default: ~/.serve.zone/dcrouter/tsmdb) */ storagePath?: string; /** Database name (default: dcrouter) */ dbName?: string; @@ -29,7 +30,7 @@ export class CacheDb { constructor(options: ICacheDbOptions = {}) { this.options = { - storagePath: options.storagePath || '/etc/dcrouter/tsmdb', + storagePath: options.storagePath || defaultTsmDbPath, dbName: options.dbName || 'dcrouter', debug: options.debug || false, }; diff --git a/ts/classes.dcrouter.ts b/ts/classes.dcrouter.ts index b859584..bb5061e 100644 --- a/ts/classes.dcrouter.ts +++ b/ts/classes.dcrouter.ts @@ -122,7 +122,7 @@ export interface IDcRouterOptions { cacheConfig?: { /** Enable cache database (default: true) */ enabled?: boolean; - /** Storage path for TsmDB data (default: /etc/dcrouter/tsmdb) */ + /** Storage path for TsmDB data (default: ~/.serve.zone/dcrouter/tsmdb) */ storagePath?: string; /** Database name (default: dcrouter) */ dbName?: string; @@ -349,7 +349,7 @@ export class DcRouter { // Initialize CacheDb singleton this.cacheDb = CacheDb.getInstance({ - storagePath: cacheConfig.storagePath || '/etc/dcrouter/tsmdb', + storagePath: cacheConfig.storagePath || paths.defaultTsmDbPath, dbName: cacheConfig.dbName || 'dcrouter', debug: false, }); diff --git a/ts/paths.ts b/ts/paths.ts index 9949bb6..5c9eb40 100644 --- a/ts/paths.ts +++ b/ts/paths.ts @@ -8,11 +8,17 @@ export const packageDir = plugins.path.join( ); export const distServe = plugins.path.join(packageDir, './dist_serve'); -// Configure data directory with environment variable or default to .nogit/data -const DEFAULT_DATA_PATH = '.nogit/data'; -export const dataDir = process.env.DATA_DIR - ? process.env.DATA_DIR - : plugins.path.join(baseDir, DEFAULT_DATA_PATH); +// Default base for all dcrouter data (always user-writable) +export const dcrouterHomeDir = plugins.path.join(plugins.os.homedir(), '.serve.zone', 'dcrouter'); + +// Configure data directory with environment variable or default to ~/.serve.zone/dcrouter/data +const DEFAULT_DATA_PATH = plugins.path.join(dcrouterHomeDir, 'data'); +export const dataDir = process.env.DATA_DIR + ? process.env.DATA_DIR + : DEFAULT_DATA_PATH; + +// Default TsmDB path for CacheDb +export const defaultTsmDbPath = plugins.path.join(dcrouterHomeDir, 'tsmdb'); // MTA directories export const keysDir = plugins.path.join(dataDir, 'keys'); diff --git a/ts_web/00_commitinfo_data.ts b/ts_web/00_commitinfo_data.ts index f53629e..75b9b86 100644 --- a/ts_web/00_commitinfo_data.ts +++ b/ts_web/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@serve.zone/dcrouter', - version: '5.0.3', + version: '5.0.4', description: 'A multifaceted routing service handling mail and SMS delivery functions.' }