refactor(server): shrink the seam bridges to their live exports

This commit is contained in:
jubnl
2026-08-11 16:23:46 +02:00
parent 7880eba6fb
commit 0718bd1b0c
14 changed files with 87 additions and 181 deletions
+11 -20
View File
@@ -3,19 +3,18 @@ import { DatabaseService } from '../database/database.service';
import { AddonsService } from './addons.service';
/**
* Non-Nest entry point for the addons domain — for code running OUTSIDE the
* Nest container (the legacy MCP registrars/resources, systemNotices, the
* pre-init platform.routes Express router, the module-level `when:` gate
* closures in the DI-discovered *.mcp.ts files, and the legacy
* oauthService/airtrailSync/thumbnailService modules). Exports the legacy
* services/adminService names 1:1 so repointing a consumer is an
* import-path-only diff. Inside the container, inject AddonsService instead.
* Delete this file when the last legacy consumer migrates.
* Non-Nest entry point for the addons domain — pinned by the MCP/OAuth
* transport (src/mcp/index.ts) and the pre-init platform.routes Express
* router, both mounted BEFORE app.init(), so the container is not available
* to them; systemNotices/conditions.ts reads it too until its enablement
* check is threaded in from the DI side. Inside the container, inject
* AddonsService instead (the `when:` gates in *.mcp.ts files do, via
* addon-gate.ts). Delete this file when the MCP/OAuth mount moves behind the
* container.
*
* Only the enablement READS are bridged — the paired writers
* (updateBagTracking/updateCollabFeatures) have in-container consumers only.
* The reads are uncached per-call queries on purpose: admin toggles must stay
* immediately visible without invalidation wiring.
* Only the enablement READ is bridged, as an uncached per-call query on
* purpose: admin toggles must stay immediately visible without invalidation
* wiring.
*
* Module-level construction is safe: `db` is the reinitialize-proof Proxy onto
* the shared better-sqlite3 singleton.
@@ -25,11 +24,3 @@ const addons = new AddonsService(new DatabaseService(db));
export function isAddonEnabled(addonId: string): boolean {
return addons.isAddonEnabled(addonId);
}
export function getBagTracking(): { enabled: boolean } {
return addons.getBagTracking();
}
export function getCollabFeatures(): { chat: boolean; notes: boolean; polls: boolean; whatsnext: boolean } {
return addons.getCollabFeatures();
}
+2 -2
View File
@@ -12,8 +12,8 @@ import { cacheKeyFor, getCached, nominatimFetch, setCached } from '../geo/nomina
// per-country store, geocode/region caches, country poly/box indexes, the
// shared Nominatim throttle and the geocodingInFlight dedup set) are
// file-scoped so their lifetime stays process-global no matter how many
// AtlasService instances exist (container singleton + auth.bridge.ts +
// test helpers) — instance state would duplicate the multi-MB indexes the
// AtlasService instances exist (container singleton + test helpers) —
// instance state would duplicate the multi-MB indexes the
// #1576 OOM fix exists to avoid and split the ≥1.1s Nominatim throttle.
// Relocated verbatim from the legacy services/atlasService.ts fold.
+1 -1
View File
@@ -46,7 +46,7 @@ function countryCodeFromRegionCode(regionCode: string): string {
* The pure-geo machinery (bundled admin0/admin1 boundaries, point-in-polygon
* indexes, Nominatim geocoding and its caches) lives in ./atlas-geo — a plain
* module so the multi-MB caches stay process-global across the container
* instance, the auth.bridge.ts instance, and test helpers (#1576).
* instance and test helpers (#1576).
* Returns native service shapes; the client-facing contracts live in
* @trek/shared. No broadcasts: atlas rows are uid-scoped, not trip-scoped.
*/
+6 -10
View File
@@ -3,13 +3,12 @@ import { DatabaseService } from '../database/database.service';
import { AuditService } from './audit.service';
/**
* Non-Nest entry point for the audit domain — for code running OUTSIDE the
* Nest container (src/index.ts lazy-requires, src/mcp/index.ts and
* oauthProvider.ts, and the legacy airtrail/immich/oauth services). Exports
* the full legacy services/auditLog surface 1:1 so repointing a consumer is an
* import-path-only diff (log*-only consumers import audit-log.logger
* directly). Inside the container, inject AuditService instead. Delete this
* file when the last legacy consumer migrates.
* Non-Nest entry point for the audit domain — pinned by the MCP/OAuth
* transport (src/mcp/index.ts and oauthProvider.ts), which platform.routes.ts
* mounts on the Express app BEFORE app.init(), so the container is not
* available to it. Inside the container, inject AuditService instead; log*-only
* consumers import audit-log.logger directly. Delete this file when the
* MCP/OAuth mount moves behind the container.
*
* Module-level construction is safe: `db` is the reinitialize-proof Proxy onto
* the shared better-sqlite3 singleton.
@@ -21,6 +20,3 @@ export function writeAudit(entry: Parameters<AuditService['writeAudit']>[0]): vo
}
export { getClientIp } from './client-ip';
// LOG_LEVEL has no external consumers today — re-exported purely for 1:1
// surface parity with the legacy module.
export { LOG_LEVEL, logInfo, logDebug, logError, logWarn } from './audit-log.logger';
+13 -40
View File
@@ -11,31 +11,23 @@ import { User } from '../../types';
import { EphemeralTokenService } from './ephemeral-token.service';
/**
* Non-Nest entry point for the auth domain — for code running OUTSIDE the
* Nest container: the legacy MCP transport (mcp/index.ts token verification),
* the legacy tool registrars (mcp/tools/journey|notifications|transports), the
* not-yet-migrated services/adminService, and — as the one in-container
* exception —
* atlas.mcp.ts. The cycle that used to make that mandatory is gone
* (getTravelStats moved to AtlasService, so AuthModule no longer imports
* AtlasModule); what keeps it here is cost, not correctness: a direct import
* would drag the whole auth chain into every Atlas consumer for one
* isDemoUser call. Same open trade-off as places.mcp.ts keeping its
* assignments.bridge imports.
* Non-Nest entry point for the auth domain — pinned by the MCP transport
* (src/mcp/index.ts token verification), which platform.routes.ts mounts on
* the Express app BEFORE app.init(), so the container is not available to it.
* Inside the container, inject AuthService/TokenService instead. Delete this
* file when the MCP/OAuth mount moves behind the container.
*
* Exports the legacy services/authService names 1:1 so repointing a consumer
* is an import-path-only diff. Inside the container, inject AuthService
* instead. Delete exports as their last legacy consumer migrates.
*
* stripUserForClient is pure and re-exported straight from auth.helpers.ts;
* avatarUrl keeps the legacy re-export shape (services/avatarUrl). The
* pending-MFA and reset-throttle maps are module-scoped in auth.service.ts,
* so this instance and the container singleton share one copy.
* Only two exports remain: verifyMcpToken lives on TokenService, but
* verifyJwtToken is login identity and deliberately stays on AuthService
* (see token.service.ts), so the whole AuthService collaborator graph below
* exists to serve that one call. WebauthnConfigService and UserCleanupService
* are constructed only because AuthService takes them — nothing this file
* exports reaches either one. The pending-MFA and reset-throttle maps are
* module-scoped in auth.service.ts, so this instance and the container
* singleton share one copy.
*
* Module-level construction is safe: `db` is the reinitialize-proof Proxy onto
* the shared better-sqlite3 singleton (same pattern as permissions.bridge.ts).
* WebauthnConfigService and UserCleanupService are constructed only because
* AuthService takes them — nothing this file exports reaches either one.
*/
const dbs = new DatabaseService(db);
const permissions = new PermissionsService(dbs);
@@ -51,13 +43,6 @@ const auth = new AuthService(
const tokens = new TokenService(dbs, new EphemeralTokenService());
export { stripUserForClient } from './auth.helpers';
export { avatarUrl } from '../common/avatarUrl';
export function isDemoUser(userId: number): boolean {
return auth.isDemoUser(userId);
}
export function verifyMcpToken(rawToken: string): User | null {
return tokens.verifyMcpToken(rawToken);
}
@@ -65,15 +50,3 @@ export function verifyMcpToken(rawToken: string): User | null {
export function verifyJwtToken(token: string): User | null {
return auth.verifyJwtToken(token);
}
export function resolveAuthToggles() {
return auth.resolveAuthToggles();
}
export function generateToken(user: { id: number | bigint; password_version?: number }, rememberMe = false) {
return auth.generateToken(user, rememberMe);
}
export function createWsToken(userId: number) {
return tokens.createWsToken(userId);
}
+2 -7
View File
@@ -19,13 +19,12 @@ import { OauthService } from './oauth.service';
* pending authorization codes — is module-scoped in oauth.pending-codes.ts, so
* this instance and the container singleton see the same map. That is load-
* bearing: the consent controller writes the code through the container and
* the SDK reads it back through here.
* the SDK reads it back through here (which is why consumeAuthCode is bridged
* and createAuthCode is not).
*/
const dbs = new DatabaseService(db);
const oauth = new OauthService(dbs, new AddonsService(dbs), new AuditService(dbs));
export type { OAuthTokenInfo, PendingCode } from './oauth.service';
export function getUserByAccessToken(rawToken: string) {
return oauth.getUserByAccessToken(rawToken);
}
@@ -34,10 +33,6 @@ export function createOAuthClient(...args: Parameters<OauthService['createOAuthC
return oauth.createOAuthClient(...args);
}
export function createAuthCode(params: Parameters<OauthService['createAuthCode']>[0]) {
return oauth.createAuthCode(params);
}
export function consumeAuthCode(code: string) {
return oauth.consumeAuthCode(code);
}
@@ -1,44 +1,27 @@
import { db } from '../../db/database';
import { DatabaseService } from '../database/database.service';
import { PermissionsService } from './permissions.service';
import type { PermissionLevel } from './permissions.service';
/**
* Non-Nest entry point for the permissions domain — for code running OUTSIDE
* the Nest container (the legacy MCP _shared.ts hasTripPermission helper and
* the legacy adminService/authService/backupService).
* Exports the legacy services/permissions names 1:1 so repointing a consumer
* is an import-path-only diff. Inside the container, inject PermissionsService
* instead. Delete this file when the last legacy consumer migrates.
* Non-Nest entry point for the permissions domain — pinned by the MCP
* transport's hasTripPermission helper (src/mcp/tools/_shared.ts), which the
* pre-app.init() MCP/OAuth mount evaluates before the container exists.
* Inside the container, inject PermissionsService instead. Delete this file
* when the MCP/OAuth mount moves behind the container.
*
* The permissions cache is module-scoped in permissions.service.ts, so this
* instance and the container singleton share one cache — invalidating through
* either flushes both (backupService restores depend on this).
* either flushes both (backup restores depend on this).
*
* Module-level construction is safe: `db` is the reinitialize-proof Proxy onto
* the shared better-sqlite3 singleton.
*/
const permissions = new PermissionsService(new DatabaseService(db));
export { PERMISSION_ACTIONS } from './permissions.service';
export type { PermissionLevel, PermissionAction } from './permissions.service';
export function invalidatePermissionsCache(): void {
permissions.invalidatePermissionsCache();
}
export function getPermissionLevel(actionKey: string): PermissionLevel {
return permissions.getPermissionLevel(actionKey);
}
export function getAllPermissions(): Record<string, PermissionLevel> {
return permissions.getAllPermissions();
}
export function savePermissions(settings: Record<string, string>): { skipped: string[] } {
return permissions.savePermissions(settings);
}
export function checkPermission(
actionKey: string,
userRole: string,