refactor(server): fold the in-container bridge edges

This commit is contained in:
jubnl
2026-08-11 16:32:02 +02:00
parent 0718bd1b0c
commit 2b2c6462ec
18 changed files with 101 additions and 43 deletions
+6 -2
View File
@@ -1,11 +1,15 @@
import semver from 'semver';
import { isAddonEnabled } from '../nest/addons/addons.bridge.js';
import type { NoticeCondition, SystemNotice } from './types.js';
interface ConditionContext {
user: { login_count: number; first_seen_version: string; role: string; noTrips: number };
currentAppVersion: string;
now: Date;
/**
* Addon-enablement check, threaded in by the caller (the Nest service passes
* its injected AddonsService) so this plain module carries no bridge import.
*/
addonEnabled: (addonId: string) => boolean;
}
// Custom predicate registry — extensible without modifying this file
@@ -48,7 +52,7 @@ function evaluateOne(condition: NoticeCondition, ctx: ConditionContext): boolean
return condition.roles.includes(ctx.user.role as 'admin' | 'user');
case 'addonEnabled':
return isAddonEnabled(condition.addonId);
return ctx.addonEnabled(condition.addonId);
case 'custom': {
const fn = customPredicates.get(condition.id);
+5 -2
View File
@@ -36,7 +36,10 @@ function severityWeight(s: string): number {
return s === 'critical' ? 2 : s === 'warn' ? 1 : 0;
}
export function getActiveNoticesFor(userId: number): SystemNoticeDTO[] {
export function getActiveNoticesFor(
userId: number,
addonEnabled: (addonId: string) => boolean
): SystemNoticeDTO[] {
const user = db.prepare(
'SELECT login_count, first_seen_version, role FROM users WHERE id = ?'
).get(userId) as { login_count: number; first_seen_version: string; role: string } | undefined;
@@ -56,7 +59,7 @@ export function getActiveNoticesFor(userId: number): SystemNoticeDTO[] {
const now = new Date();
const currentAppVersion = getCurrentAppVersion();
const ctx = { user: { ...user, noTrips: tripCount }, currentAppVersion, now };
const ctx = { user: { ...user, noTrips: tripCount }, currentAppVersion, now, addonEnabled };
const appVer = semver.coerce(currentAppVersion)?.version ?? '0.0.0';
const isStillDismissed = (n: SystemNotice): boolean => {