@lenne.tech/nest-server 11.31.2 → 11.31.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/rules/architecture.md +2 -0
- package/.claude/rules/configurable-features.md +2 -0
- package/CLAUDE.md +28 -1
- package/FRAMEWORK-API.md +4 -1
- package/dist/config.env.d.ts +4 -0
- package/dist/config.env.js +32 -2
- package/dist/config.env.js.map +1 -1
- package/dist/core/common/helpers/logging.helper.d.ts +1 -0
- package/dist/core/common/helpers/logging.helper.js +12 -0
- package/dist/core/common/helpers/logging.helper.js.map +1 -1
- package/dist/core/common/helpers/meta.helper.d.ts +1 -0
- package/dist/core/common/helpers/meta.helper.js +32 -1
- package/dist/core/common/helpers/meta.helper.js.map +1 -1
- package/dist/core/common/interfaces/server-options.interface.d.ts +9 -0
- package/dist/core/common/services/email.service.d.ts +3 -1
- package/dist/core/common/services/email.service.js +33 -2
- package/dist/core/common/services/email.service.js.map +1 -1
- package/dist/core/common/services/template.service.js +9 -4
- package/dist/core/common/services/template.service.js.map +1 -1
- package/dist/core/modules/hub/core-hub-actions.controller.d.ts +22 -0
- package/dist/core/modules/hub/core-hub-actions.controller.js +141 -0
- package/dist/core/modules/hub/core-hub-actions.controller.js.map +1 -0
- package/dist/core/modules/hub/core-hub-html.service.d.ts +8 -0
- package/dist/core/modules/hub/core-hub-html.service.js +123 -0
- package/dist/core/modules/hub/core-hub-html.service.js.map +1 -0
- package/dist/core/modules/hub/core-hub.controller.d.ts +56 -0
- package/dist/core/modules/hub/core-hub.controller.js +398 -0
- package/dist/core/modules/hub/core-hub.controller.js.map +1 -0
- package/dist/core/modules/hub/core-hub.module.d.ts +17 -0
- package/dist/core/modules/hub/core-hub.module.js +109 -0
- package/dist/core/modules/hub/core-hub.module.js.map +1 -0
- package/dist/core/modules/hub/core-hub.service.d.ts +18 -0
- package/dist/core/modules/hub/core-hub.service.js +153 -0
- package/dist/core/modules/hub/core-hub.service.js.map +1 -0
- package/dist/core/modules/hub/helpers/hub-client-js.helper.d.ts +1 -0
- package/dist/core/modules/hub/helpers/hub-client-js.helper.js +755 -0
- package/dist/core/modules/hub/helpers/hub-client-js.helper.js.map +1 -0
- package/dist/core/modules/hub/helpers/hub-command-shape.helper.d.ts +1 -0
- package/dist/core/modules/hub/helpers/hub-command-shape.helper.js +33 -0
- package/dist/core/modules/hub/helpers/hub-command-shape.helper.js.map +1 -0
- package/dist/core/modules/hub/helpers/hub-mask.helper.d.ts +1 -0
- package/dist/core/modules/hub/helpers/hub-mask.helper.js +46 -0
- package/dist/core/modules/hub/helpers/hub-mask.helper.js.map +1 -0
- package/dist/core/modules/hub/helpers/hub-mermaid.helper.d.ts +10 -0
- package/dist/core/modules/hub/helpers/hub-mermaid.helper.js +35 -0
- package/dist/core/modules/hub/helpers/hub-mermaid.helper.js.map +1 -0
- package/dist/core/modules/hub/helpers/hub-shell.helper.d.ts +9 -0
- package/dist/core/modules/hub/helpers/hub-shell.helper.js +62 -0
- package/dist/core/modules/hub/helpers/hub-shell.helper.js.map +1 -0
- package/dist/core/modules/hub/hub-action-messages.d.ts +17 -0
- package/dist/core/modules/hub/hub-action-messages.js +21 -0
- package/dist/core/modules/hub/hub-action-messages.js.map +1 -0
- package/dist/core/modules/hub/hub-config.helper.d.ts +11 -0
- package/dist/core/modules/hub/hub-config.helper.js +164 -0
- package/dist/core/modules/hub/hub-config.helper.js.map +1 -0
- package/dist/core/modules/hub/hub-nav.d.ts +12 -0
- package/dist/core/modules/hub/hub-nav.js +43 -0
- package/dist/core/modules/hub/hub-nav.js.map +1 -0
- package/dist/core/modules/hub/hub-ring-buffer.d.ts +22 -0
- package/dist/core/modules/hub/hub-ring-buffer.js +59 -0
- package/dist/core/modules/hub/hub-ring-buffer.js.map +1 -0
- package/dist/core/modules/hub/hub.constants.d.ts +18 -0
- package/dist/core/modules/hub/hub.constants.js +22 -0
- package/dist/core/modules/hub/hub.constants.js.map +1 -0
- package/dist/core/modules/hub/index.d.ts +25 -0
- package/dist/core/modules/hub/index.js +42 -0
- package/dist/core/modules/hub/index.js.map +1 -0
- package/dist/core/modules/hub/interfaces/hub-config.interface.d.ts +115 -0
- package/dist/core/modules/hub/interfaces/hub-config.interface.js +3 -0
- package/dist/core/modules/hub/interfaces/hub-config.interface.js.map +1 -0
- package/dist/core/modules/hub/interfaces/hub-panels.interface.d.ts +231 -0
- package/dist/core/modules/hub/interfaces/hub-panels.interface.js +3 -0
- package/dist/core/modules/hub/interfaces/hub-panels.interface.js.map +1 -0
- package/dist/core/modules/hub/middleware/hub-trace.middleware.d.ts +8 -0
- package/dist/core/modules/hub/middleware/hub-trace.middleware.js +50 -0
- package/dist/core/modules/hub/middleware/hub-trace.middleware.js.map +1 -0
- package/dist/core/modules/hub/services/core-hub-actions.service.d.ts +48 -0
- package/dist/core/modules/hub/services/core-hub-actions.service.js +136 -0
- package/dist/core/modules/hub/services/core-hub-actions.service.js.map +1 -0
- package/dist/core/modules/hub/services/core-hub-db.service.d.ts +19 -0
- package/dist/core/modules/hub/services/core-hub-db.service.js +180 -0
- package/dist/core/modules/hub/services/core-hub-db.service.js.map +1 -0
- package/dist/core/modules/hub/services/core-hub-email.service.d.ts +24 -0
- package/dist/core/modules/hub/services/core-hub-email.service.js +148 -0
- package/dist/core/modules/hub/services/core-hub-email.service.js.map +1 -0
- package/dist/core/modules/hub/services/core-hub-mailbox.service.d.ts +20 -0
- package/dist/core/modules/hub/services/core-hub-mailbox.service.js +103 -0
- package/dist/core/modules/hub/services/core-hub-mailbox.service.js.map +1 -0
- package/dist/core/modules/hub/services/core-hub-migrations.service.d.ts +25 -0
- package/dist/core/modules/hub/services/core-hub-migrations.service.js +115 -0
- package/dist/core/modules/hub/services/core-hub-migrations.service.js.map +1 -0
- package/dist/core/modules/hub/services/core-hub-sources.service.d.ts +28 -0
- package/dist/core/modules/hub/services/core-hub-sources.service.js +187 -0
- package/dist/core/modules/hub/services/core-hub-sources.service.js.map +1 -0
- package/dist/core/modules/hub/services/hub-log-buffer.service.d.ts +24 -0
- package/dist/core/modules/hub/services/hub-log-buffer.service.js +210 -0
- package/dist/core/modules/hub/services/hub-log-buffer.service.js.map +1 -0
- package/dist/core/modules/hub/services/hub-query-profiler.service.d.ts +38 -0
- package/dist/core/modules/hub/services/hub-query-profiler.service.js +235 -0
- package/dist/core/modules/hub/services/hub-query-profiler.service.js.map +1 -0
- package/dist/core/modules/hub/services/hub-trace-buffer.service.d.ts +18 -0
- package/dist/core/modules/hub/services/hub-trace-buffer.service.js +123 -0
- package/dist/core/modules/hub/services/hub-trace-buffer.service.js.map +1 -0
- package/dist/core.module.js +42 -1
- package/dist/core.module.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/docs/REQUEST-LIFECYCLE.md +1 -0
- package/migration-guides/11.31.2-to-11.31.3.md +135 -0
- package/package.json +5 -4
- package/src/config.env.ts +75 -2
- package/src/core/common/helpers/logging.helper.spec.ts +61 -0
- package/src/core/common/helpers/logging.helper.ts +48 -0
- package/src/core/common/helpers/meta.helper.ts +46 -1
- package/src/core/common/interfaces/server-options.interface.ts +46 -0
- package/src/core/common/services/email.service.ts +33 -1
- package/src/core/common/services/template.service.ts +21 -16
- package/src/core/modules/hub/INTEGRATION-CHECKLIST.md +64 -0
- package/src/core/modules/hub/README.md +159 -0
- package/src/core/modules/hub/core-hub-actions.controller.ts +137 -0
- package/src/core/modules/hub/core-hub-html.service.ts +135 -0
- package/src/core/modules/hub/core-hub.controller.ts +286 -0
- package/src/core/modules/hub/core-hub.module.spec.ts +108 -0
- package/src/core/modules/hub/core-hub.module.ts +159 -0
- package/src/core/modules/hub/core-hub.service.ts +169 -0
- package/src/core/modules/hub/helpers/hub-client-js.helper.ts +768 -0
- package/src/core/modules/hub/helpers/hub-command-shape.helper.spec.ts +48 -0
- package/src/core/modules/hub/helpers/hub-command-shape.helper.ts +47 -0
- package/src/core/modules/hub/helpers/hub-mask.helper.spec.ts +67 -0
- package/src/core/modules/hub/helpers/hub-mask.helper.ts +78 -0
- package/src/core/modules/hub/helpers/hub-mermaid.helper.spec.ts +54 -0
- package/src/core/modules/hub/helpers/hub-mermaid.helper.ts +62 -0
- package/src/core/modules/hub/helpers/hub-shell.helper.spec.ts +106 -0
- package/src/core/modules/hub/helpers/hub-shell.helper.ts +90 -0
- package/src/core/modules/hub/hub-action-messages.ts +47 -0
- package/src/core/modules/hub/hub-config.helper.spec.ts +108 -0
- package/src/core/modules/hub/hub-config.helper.ts +233 -0
- package/src/core/modules/hub/hub-nav.ts +66 -0
- package/src/core/modules/hub/hub-ring-buffer.spec.ts +95 -0
- package/src/core/modules/hub/hub-ring-buffer.ts +101 -0
- package/src/core/modules/hub/hub.constants.ts +84 -0
- package/src/core/modules/hub/index.ts +25 -0
- package/src/core/modules/hub/interfaces/hub-config.interface.ts +265 -0
- package/src/core/modules/hub/interfaces/hub-panels.interface.ts +186 -0
- package/src/core/modules/hub/middleware/hub-trace.middleware.ts +45 -0
- package/src/core/modules/hub/services/core-hub-actions.service.ts +133 -0
- package/src/core/modules/hub/services/core-hub-db.service.ts +185 -0
- package/src/core/modules/hub/services/core-hub-email.service.ts +158 -0
- package/src/core/modules/hub/services/core-hub-mailbox.service.spec.ts +116 -0
- package/src/core/modules/hub/services/core-hub-mailbox.service.ts +121 -0
- package/src/core/modules/hub/services/core-hub-migrations.service.ts +112 -0
- package/src/core/modules/hub/services/core-hub-sources.service.ts +194 -0
- package/src/core/modules/hub/services/hub-log-buffer.service.ts +252 -0
- package/src/core/modules/hub/services/hub-query-profiler.service.ts +274 -0
- package/src/core/modules/hub/services/hub-trace-buffer.service.spec.ts +112 -0
- package/src/core/modules/hub/services/hub-trace-buffer.service.ts +134 -0
- package/src/core.module.ts +61 -1
- package/src/index.ts +6 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { Inject, Injectable, Optional } from '@nestjs/common';
|
|
2
|
+
import { InjectConnection } from '@nestjs/mongoose';
|
|
3
|
+
import { Connection } from 'mongoose';
|
|
4
|
+
|
|
5
|
+
import { getBuildInfo } from '../../common/helpers/meta.helper';
|
|
6
|
+
import { ConfigService } from '../../common/services/config.service';
|
|
7
|
+
|
|
8
|
+
import { HUB_CONFIG } from './hub.constants';
|
|
9
|
+
import { HUB_PANEL_GROUPS, HUB_PANELS } from './hub-nav';
|
|
10
|
+
import { maskConfigDeep } from './helpers/hub-mask.helper';
|
|
11
|
+
import { CoreHubSourcesService } from './services/core-hub-sources.service';
|
|
12
|
+
import { HubDashboardData, HubDiagnosticsData, HubSessionData } from './interfaces/hub-panels.interface';
|
|
13
|
+
import { ResolvedHubConfig } from './interfaces/hub-config.interface';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Framework-default secret field names (see CheckSecurityInterceptor). Union with the pattern-based
|
|
17
|
+
* masking in {@link maskConfigDeep} and the project's `security.secretFields`.
|
|
18
|
+
*/
|
|
19
|
+
const FRAMEWORK_SECRET_FIELDS = [
|
|
20
|
+
'password',
|
|
21
|
+
'verificationToken',
|
|
22
|
+
'passwordResetToken',
|
|
23
|
+
'refreshTokens',
|
|
24
|
+
'tempTokens',
|
|
25
|
+
'apiKeyEncrypted',
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
const MONGO_STATES: Record<number, string> = {
|
|
29
|
+
0: 'disconnected',
|
|
30
|
+
1: 'connected',
|
|
31
|
+
2: 'connecting',
|
|
32
|
+
3: 'disconnecting',
|
|
33
|
+
99: 'uninitialized',
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Aggregator for the Hub's own data (dashboard + diagnostics + the feature matrix). Panel-specific
|
|
38
|
+
* data lives in the focused services (`CoreHubDbService`, `CoreHubMigrationsService`, …).
|
|
39
|
+
*
|
|
40
|
+
* Overridable via `overrides.hub.service`.
|
|
41
|
+
*/
|
|
42
|
+
@Injectable()
|
|
43
|
+
export class CoreHubService {
|
|
44
|
+
constructor(
|
|
45
|
+
@Inject(HUB_CONFIG) protected readonly config: ResolvedHubConfig,
|
|
46
|
+
protected readonly configService: ConfigService,
|
|
47
|
+
protected readonly sources: CoreHubSourcesService,
|
|
48
|
+
@Optional() @InjectConnection() protected readonly connection?: Connection,
|
|
49
|
+
) {}
|
|
50
|
+
|
|
51
|
+
/** Data for the dashboard panel. */
|
|
52
|
+
getDashboard(): HubDashboardData {
|
|
53
|
+
const mem = process.memoryUsage();
|
|
54
|
+
const build = getBuildInfo({ env: this.config.env, version: this.config.version });
|
|
55
|
+
const readyState = this.connection?.readyState ?? 0;
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
build: { commit: build.commit, env: this.config.env, version: this.config.version },
|
|
59
|
+
features: this.featureMatrix(),
|
|
60
|
+
links: { ...this.config.links },
|
|
61
|
+
memory: { heapTotal: mem.heapTotal, heapUsed: mem.heapUsed, rss: mem.rss },
|
|
62
|
+
mongo: { readyState, state: MONGO_STATES[readyState] ?? 'unknown' },
|
|
63
|
+
time: new Date().toISOString(),
|
|
64
|
+
uptimeSeconds: Math.round(process.uptime()),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Data for the diagnostics panel. `buffers` is filled once the collectors are wired (Phase 6). */
|
|
69
|
+
getDiagnostics(buffers: HubDiagnosticsData['buffers'] = {}): HubDiagnosticsData {
|
|
70
|
+
const mem = process.memoryUsage();
|
|
71
|
+
const cpu = process.cpuUsage();
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
arch: process.arch,
|
|
75
|
+
buffers,
|
|
76
|
+
cpuUsage: { system: cpu.system, user: cpu.user },
|
|
77
|
+
env: this.config.env,
|
|
78
|
+
memory: {
|
|
79
|
+
arrayBuffers: mem.arrayBuffers,
|
|
80
|
+
external: mem.external,
|
|
81
|
+
heapTotal: mem.heapTotal,
|
|
82
|
+
heapUsed: mem.heapUsed,
|
|
83
|
+
rss: mem.rss,
|
|
84
|
+
},
|
|
85
|
+
nodeVersion: process.version,
|
|
86
|
+
pid: process.pid,
|
|
87
|
+
platform: process.platform,
|
|
88
|
+
time: new Date().toISOString(),
|
|
89
|
+
uptimeSeconds: Math.round(process.uptime()),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The full server config with all secrets masked. Deep-cloned first (never mutate the live config),
|
|
95
|
+
* then masked by key heuristics + the framework/project secret-field lists.
|
|
96
|
+
*/
|
|
97
|
+
getConfigMasked(): Record<string, unknown> {
|
|
98
|
+
const raw = this.configService.configFastButReadOnly as Record<string, unknown>;
|
|
99
|
+
const projectSecretFields = this.configService.get<string[]>('security.secretFields', []) ?? [];
|
|
100
|
+
return maskConfigDeep(raw, [...FRAMEWORK_SECRET_FIELDS, ...projectSecretFields]);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The resolved Hub config (for controller/actions/gating decisions). */
|
|
104
|
+
getResolvedConfig(): ResolvedHubConfig {
|
|
105
|
+
return this.config;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Cockpit-chrome data the client needs to build the navigation AFTER a successful ADMIN auth check.
|
|
110
|
+
* Served ADMIN-gated via `GET /{hub}/session.json`. Because it sits behind the roles guard, the
|
|
111
|
+
* public shell can carry NO nav/env/links — an unauthenticated request reveals nothing of the Hub.
|
|
112
|
+
*/
|
|
113
|
+
getSessionPayload(): HubSessionData {
|
|
114
|
+
// Availability of the optional-source panels, so the client can grey out + disable dead nav
|
|
115
|
+
// entries. `mailbox` depends on config (its service is only provided when enabled); everything not
|
|
116
|
+
// covered is intrinsic to the Hub and always available.
|
|
117
|
+
const sourceAvailability = this.sources.getPanelAvailability();
|
|
118
|
+
const isAvailable = (id: string): boolean => {
|
|
119
|
+
if (id === 'mailbox') {
|
|
120
|
+
return this.config.mailbox !== false;
|
|
121
|
+
}
|
|
122
|
+
return sourceAvailability[id] ?? true;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
authenticated: true,
|
|
127
|
+
env: this.config.env,
|
|
128
|
+
links: { ...this.config.links },
|
|
129
|
+
logoutEndpoint: this.config.logoutEndpoint,
|
|
130
|
+
panelGroups: [...HUB_PANEL_GROUPS],
|
|
131
|
+
panels: HUB_PANELS.map((panel) => ({
|
|
132
|
+
available: isAvailable(panel.id),
|
|
133
|
+
group: panel.group,
|
|
134
|
+
id: panel.id,
|
|
135
|
+
optional: !!panel.optional,
|
|
136
|
+
path: panel.path,
|
|
137
|
+
title: panel.title,
|
|
138
|
+
})),
|
|
139
|
+
version: this.config.version,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Which optional framework features are active, for the dashboard feature matrix. */
|
|
144
|
+
protected featureMatrix(): Record<string, boolean> {
|
|
145
|
+
const has = (key: string): boolean => {
|
|
146
|
+
const value = this.configService.get(key);
|
|
147
|
+
if (value === undefined || value === null || value === false) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
if (typeof value === 'object') {
|
|
151
|
+
return (value as { enabled?: boolean }).enabled !== false;
|
|
152
|
+
}
|
|
153
|
+
return true;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
ai: has('ai'),
|
|
158
|
+
// Runtime check: BetterAuth can be active via BetterAuthModule.forRoot() without an obvious
|
|
159
|
+
// config flag, so config-sniffing is unreliable — ask whether it is actually wired in.
|
|
160
|
+
betterAuth: this.sources.isBetterAuthActive(),
|
|
161
|
+
cookies: this.configService.get('cookies') !== false,
|
|
162
|
+
graphQl: this.configService.get('graphQl') !== false,
|
|
163
|
+
healthCheck: has('healthCheck'),
|
|
164
|
+
multiTenancy: has('multiTenancy'),
|
|
165
|
+
permissions: has('permissions'),
|
|
166
|
+
tus: has('tus'),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|