@dudousxd/nestjs-catalog-dashboard 0.3.3 → 0.5.0

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.
@@ -30,7 +30,8 @@ __export(index_exports, {
30
30
  DASHBOARD_API_PATH: () => DASHBOARD_API_PATH,
31
31
  DASHBOARD_AUTH: () => DASHBOARD_AUTH,
32
32
  DASHBOARD_BASE_PATH: () => DASHBOARD_BASE_PATH,
33
- catalogDashboardMountPaths: () => catalogDashboardMountPaths
33
+ catalogDashboardMountPaths: () => catalogDashboardMountPaths,
34
+ readCatalogConsoleSession: () => readSessionFromRequest
34
35
  });
35
36
  module.exports = __toCommonJS(index_exports);
36
37
 
@@ -99,180 +100,46 @@ function resolveDashboardAuth(options) {
99
100
  }
100
101
  __name(resolveDashboardAuth, "resolveDashboardAuth");
101
102
 
102
- // src/server/catalog-auth.controller.ts
103
- var import_common4 = require("@nestjs/common");
104
-
105
- // src/server/auth/login-page.ts
106
- function page(content, title = "Catalog") {
107
- return `<!doctype html>
108
- <html lang="en">
109
- <head>
110
- <meta charset="utf-8" />
111
- <meta name="viewport" content="width=device-width, initial-scale=1" />
112
- <meta name="robots" content="noindex, nofollow" />
113
- <title>${title}</title>
114
- <style>
115
- :root { color-scheme: dark; }
116
- * { box-sizing: border-box; }
117
- body {
118
- margin: 0;
119
- min-height: 100vh;
120
- display: flex;
121
- align-items: center;
122
- justify-content: center;
123
- background: #09090b;
124
- color: #e4e4e7;
125
- font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
126
- padding: 16px;
127
- }
128
- .card {
129
- width: 100%;
130
- max-width: 384px;
131
- border: 1px solid #27272a;
132
- background: #18181b;
133
- border-radius: 8px;
134
- padding: 32px;
135
- box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.5);
136
- }
137
- .brand {
138
- margin: 0 0 24px;
139
- text-align: center;
140
- font-size: 18px;
141
- font-weight: 600;
142
- color: #34d399;
143
- }
144
- h1 {
145
- margin: 0 0 12px;
146
- font-size: 16px;
147
- font-weight: 600;
148
- color: #f4f4f5;
149
- }
150
- p { margin: 0 0 16px; color: #a1a1aa; }
151
- form { display: flex; flex-direction: column; gap: 16px; }
152
- label { display: flex; flex-direction: column; gap: 6px; }
153
- .field-label {
154
- font-size: 11px;
155
- text-transform: uppercase;
156
- letter-spacing: 0.05em;
157
- color: #71717a;
158
- }
159
- input {
160
- border-radius: 4px;
161
- border: 1px solid #3f3f46;
162
- background: #09090b;
163
- color: #f4f4f5;
164
- padding: 8px 12px;
165
- font: inherit;
166
- outline: none;
167
- }
168
- input:focus { border-color: rgb(52 211 153 / 0.6); }
169
- #error {
170
- display: none;
171
- margin: 0;
172
- font-size: 12px;
173
- color: #fb7185;
174
- }
175
- button, .button {
176
- margin-top: 8px;
177
- border-radius: 4px;
178
- border: 1px solid rgb(52 211 153 / 0.4);
179
- background: rgb(52 211 153 / 0.1);
180
- color: #6ee7b7;
181
- padding: 8px 12px;
182
- font: inherit;
183
- font-size: 12px;
184
- font-weight: 500;
185
- text-transform: uppercase;
186
- letter-spacing: 0.05em;
187
- cursor: pointer;
188
- display: inline-block;
189
- text-align: center;
190
- text-decoration: none;
191
- box-sizing: border-box;
192
- }
193
- button:hover:not(:disabled), .button:hover { background: rgb(52 211 153 / 0.2); }
194
- button:disabled { opacity: 0.6; cursor: default; }
195
- </style>
196
- </head>
197
- <body>
198
- <div class="card">
199
- ${content}
200
- </div>
201
- </body>
202
- </html>`;
203
- }
204
- __name(page, "page");
205
- function renderLoginPage(basePath) {
206
- const loginAction = `${basePath}/login`;
207
- const defaultReturnTo = basePath;
208
- return page(`<p class="brand">Catalog</p>
209
- <form id="login-form" autocomplete="on">
210
- <label>
211
- <span class="field-label">Username</span>
212
- <input id="username" name="username" type="text" autocomplete="username" required autofocus />
213
- </label>
214
- <label>
215
- <span class="field-label">Password</span>
216
- <input id="password" name="password" type="password" autocomplete="current-password" />
217
- </label>
218
- <p id="error" role="alert">Invalid username or password.</p>
219
- <button id="submit" type="submit">Sign in</button>
220
- </form>
221
- <script>
222
- (function () {
223
- var LOGIN_ACTION = ${JSON.stringify(loginAction)};
224
- var DEFAULT_RETURN_TO = ${JSON.stringify(defaultReturnTo)};
225
- var params = new URLSearchParams(window.location.search);
226
- var errorBox = document.getElementById('error');
227
- if (params.get('error')) errorBox.style.display = 'block';
228
-
229
- function sameOriginReturnTo(value) {
230
- if (typeof value !== 'string' || value === '') return DEFAULT_RETURN_TO;
231
- if (value.charAt(0) !== '/' || value.charAt(1) === '/' || value.indexOf('://') !== -1) {
232
- return DEFAULT_RETURN_TO;
103
+ // src/server/auth/cookie-header.ts
104
+ function parseCookieHeader(header) {
105
+ const cookies = {};
106
+ if (typeof header !== "string" || header === "") return cookies;
107
+ for (const segment of header.split(";")) {
108
+ const eq = segment.indexOf("=");
109
+ if (eq <= 0) continue;
110
+ const name = segment.slice(0, eq).trim();
111
+ if (name === "") continue;
112
+ let rawValue = segment.slice(eq + 1).trim();
113
+ if (rawValue.length >= 2 && rawValue.startsWith('"') && rawValue.endsWith('"')) {
114
+ rawValue = rawValue.slice(1, -1);
115
+ }
116
+ if (name in cookies) continue;
117
+ try {
118
+ cookies[name] = decodeURIComponent(rawValue);
119
+ } catch {
120
+ cookies[name] = rawValue;
233
121
  }
234
- return value;
235
122
  }
236
-
237
- var form = document.getElementById('login-form');
238
- var submitButton = document.getElementById('submit');
239
- form.addEventListener('submit', function (event) {
240
- event.preventDefault();
241
- submitButton.disabled = true;
242
- errorBox.style.display = 'none';
243
- var returnTo = sameOriginReturnTo(params.get('returnTo'));
244
- fetch(LOGIN_ACTION, {
245
- method: 'POST',
246
- headers: { 'content-type': 'application/json' },
247
- credentials: 'same-origin',
248
- body: JSON.stringify({
249
- username: document.getElementById('username').value,
250
- password: document.getElementById('password').value,
251
- returnTo: returnTo,
252
- }),
253
- })
254
- .then(function (response) {
255
- if (!response.ok) throw new Error('unauthorized');
256
- return response.json();
257
- })
258
- .then(function (data) {
259
- window.location.href = data.redirectTo || DEFAULT_RETURN_TO;
260
- })
261
- .catch(function () {
262
- errorBox.style.display = 'block';
263
- submitButton.disabled = false;
264
- });
265
- });
266
- })();
267
- </script>`, "Sign in \u2014 Catalog");
123
+ return cookies;
268
124
  }
269
- __name(renderLoginPage, "renderLoginPage");
270
- function renderSessionRequiredPage(basePath) {
271
- return page(`<h1>Open this console from your application</h1>
272
- <p>Your session is minted by the host app. Use its console launcher to sign in, then reload.</p>
273
- <a class="button" href="${basePath}">Retry</a>`);
125
+ __name(parseCookieHeader, "parseCookieHeader");
126
+ function serializeSetCookie(name, value, options) {
127
+ const parts = [
128
+ `${name}=${options.clear ? "" : encodeURIComponent(value)}`
129
+ ];
130
+ parts.push(`Path=${options.path}`);
131
+ parts.push("HttpOnly");
132
+ parts.push("SameSite=Lax");
133
+ if (options.secure) parts.push("Secure");
134
+ if (options.clear) {
135
+ parts.push("Max-Age=0");
136
+ parts.push("Expires=Thu, 01 Jan 1970 00:00:00 GMT");
137
+ } else {
138
+ parts.push(`Max-Age=${options.maxAgeSeconds}`);
139
+ }
140
+ return parts.join("; ");
274
141
  }
275
- __name(renderSessionRequiredPage, "renderSessionRequiredPage");
142
+ __name(serializeSetCookie, "serializeSetCookie");
276
143
 
277
144
  // src/server/auth/request.ts
278
145
  function isRecord(value) {
@@ -388,47 +255,6 @@ function writeHtmlRaw(response, html, status = 200) {
388
255
  }
389
256
  __name(writeHtmlRaw, "writeHtmlRaw");
390
257
 
391
- // src/server/auth/cookie-header.ts
392
- function parseCookieHeader(header) {
393
- const cookies = {};
394
- if (typeof header !== "string" || header === "") return cookies;
395
- for (const segment of header.split(";")) {
396
- const eq = segment.indexOf("=");
397
- if (eq <= 0) continue;
398
- const name = segment.slice(0, eq).trim();
399
- if (name === "") continue;
400
- let rawValue = segment.slice(eq + 1).trim();
401
- if (rawValue.length >= 2 && rawValue.startsWith('"') && rawValue.endsWith('"')) {
402
- rawValue = rawValue.slice(1, -1);
403
- }
404
- if (name in cookies) continue;
405
- try {
406
- cookies[name] = decodeURIComponent(rawValue);
407
- } catch {
408
- cookies[name] = rawValue;
409
- }
410
- }
411
- return cookies;
412
- }
413
- __name(parseCookieHeader, "parseCookieHeader");
414
- function serializeSetCookie(name, value, options) {
415
- const parts = [
416
- `${name}=${options.clear ? "" : encodeURIComponent(value)}`
417
- ];
418
- parts.push(`Path=${options.path}`);
419
- parts.push("HttpOnly");
420
- parts.push("SameSite=Lax");
421
- if (options.secure) parts.push("Secure");
422
- if (options.clear) {
423
- parts.push("Max-Age=0");
424
- parts.push("Expires=Thu, 01 Jan 1970 00:00:00 GMT");
425
- } else {
426
- parts.push(`Max-Age=${options.maxAgeSeconds}`);
427
- }
428
- return parts.join("; ");
429
- }
430
- __name(serializeSetCookie, "serializeSetCookie");
431
-
432
258
  // src/server/auth/session-cookie.ts
433
259
  var import_node_crypto = require("crypto");
434
260
  var EXP_GRACE_MS = 3e4;
@@ -552,36 +378,211 @@ function revalidateOnce(auth, user) {
552
378
  const call = Promise.resolve().then(() => revalidate(user)).catch(() => false).finally(() => {
553
379
  inFlightRevalidations.delete(key);
554
380
  });
555
- inFlightRevalidations.set(key, call);
556
- return call;
381
+ inFlightRevalidations.set(key, call);
382
+ return call;
383
+ }
384
+ __name(revalidateOnce, "revalidateOnce");
385
+ async function maybeRenewSession(auth, session, request, response, now = Date.now()) {
386
+ if (now - session.iat <= auth.ttlMs / 2) return true;
387
+ const user = {
388
+ id: session.sub,
389
+ ...session.name !== void 0 ? {
390
+ name: session.name
391
+ } : {},
392
+ roles: session.roles
393
+ };
394
+ const allowed = await revalidateOnce(auth, user);
395
+ if (!allowed) {
396
+ clearSessionCookie({
397
+ request,
398
+ response
399
+ });
400
+ return false;
401
+ }
402
+ issueSessionCookie(user, {
403
+ auth,
404
+ request,
405
+ response,
406
+ now
407
+ });
408
+ return true;
409
+ }
410
+ __name(maybeRenewSession, "maybeRenewSession");
411
+
412
+ // src/server/catalog-auth.controller.ts
413
+ var import_common4 = require("@nestjs/common");
414
+
415
+ // src/server/auth/login-page.ts
416
+ function page(content, title = "Catalog") {
417
+ return `<!doctype html>
418
+ <html lang="en">
419
+ <head>
420
+ <meta charset="utf-8" />
421
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
422
+ <meta name="robots" content="noindex, nofollow" />
423
+ <title>${title}</title>
424
+ <style>
425
+ :root { color-scheme: dark; }
426
+ * { box-sizing: border-box; }
427
+ body {
428
+ margin: 0;
429
+ min-height: 100vh;
430
+ display: flex;
431
+ align-items: center;
432
+ justify-content: center;
433
+ background: #09090b;
434
+ color: #e4e4e7;
435
+ font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
436
+ padding: 16px;
437
+ }
438
+ .card {
439
+ width: 100%;
440
+ max-width: 384px;
441
+ border: 1px solid #27272a;
442
+ background: #18181b;
443
+ border-radius: 8px;
444
+ padding: 32px;
445
+ box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.5);
446
+ }
447
+ .brand {
448
+ margin: 0 0 24px;
449
+ text-align: center;
450
+ font-size: 18px;
451
+ font-weight: 600;
452
+ color: #34d399;
453
+ }
454
+ h1 {
455
+ margin: 0 0 12px;
456
+ font-size: 16px;
457
+ font-weight: 600;
458
+ color: #f4f4f5;
459
+ }
460
+ p { margin: 0 0 16px; color: #a1a1aa; }
461
+ form { display: flex; flex-direction: column; gap: 16px; }
462
+ label { display: flex; flex-direction: column; gap: 6px; }
463
+ .field-label {
464
+ font-size: 11px;
465
+ text-transform: uppercase;
466
+ letter-spacing: 0.05em;
467
+ color: #71717a;
468
+ }
469
+ input {
470
+ border-radius: 4px;
471
+ border: 1px solid #3f3f46;
472
+ background: #09090b;
473
+ color: #f4f4f5;
474
+ padding: 8px 12px;
475
+ font: inherit;
476
+ outline: none;
477
+ }
478
+ input:focus { border-color: rgb(52 211 153 / 0.6); }
479
+ #error {
480
+ display: none;
481
+ margin: 0;
482
+ font-size: 12px;
483
+ color: #fb7185;
484
+ }
485
+ button, .button {
486
+ margin-top: 8px;
487
+ border-radius: 4px;
488
+ border: 1px solid rgb(52 211 153 / 0.4);
489
+ background: rgb(52 211 153 / 0.1);
490
+ color: #6ee7b7;
491
+ padding: 8px 12px;
492
+ font: inherit;
493
+ font-size: 12px;
494
+ font-weight: 500;
495
+ text-transform: uppercase;
496
+ letter-spacing: 0.05em;
497
+ cursor: pointer;
498
+ display: inline-block;
499
+ text-align: center;
500
+ text-decoration: none;
501
+ box-sizing: border-box;
502
+ }
503
+ button:hover:not(:disabled), .button:hover { background: rgb(52 211 153 / 0.2); }
504
+ button:disabled { opacity: 0.6; cursor: default; }
505
+ </style>
506
+ </head>
507
+ <body>
508
+ <div class="card">
509
+ ${content}
510
+ </div>
511
+ </body>
512
+ </html>`;
513
+ }
514
+ __name(page, "page");
515
+ function renderLoginPage(basePath) {
516
+ const loginAction = `${basePath}/login`;
517
+ const defaultReturnTo = basePath;
518
+ return page(`<p class="brand">Catalog</p>
519
+ <form id="login-form" autocomplete="on">
520
+ <label>
521
+ <span class="field-label">Username</span>
522
+ <input id="username" name="username" type="text" autocomplete="username" required autofocus />
523
+ </label>
524
+ <label>
525
+ <span class="field-label">Password</span>
526
+ <input id="password" name="password" type="password" autocomplete="current-password" />
527
+ </label>
528
+ <p id="error" role="alert">Invalid username or password.</p>
529
+ <button id="submit" type="submit">Sign in</button>
530
+ </form>
531
+ <script>
532
+ (function () {
533
+ var LOGIN_ACTION = ${JSON.stringify(loginAction)};
534
+ var DEFAULT_RETURN_TO = ${JSON.stringify(defaultReturnTo)};
535
+ var params = new URLSearchParams(window.location.search);
536
+ var errorBox = document.getElementById('error');
537
+ if (params.get('error')) errorBox.style.display = 'block';
538
+
539
+ function sameOriginReturnTo(value) {
540
+ if (typeof value !== 'string' || value === '') return DEFAULT_RETURN_TO;
541
+ if (value.charAt(0) !== '/' || value.charAt(1) === '/' || value.indexOf('://') !== -1) {
542
+ return DEFAULT_RETURN_TO;
543
+ }
544
+ return value;
545
+ }
546
+
547
+ var form = document.getElementById('login-form');
548
+ var submitButton = document.getElementById('submit');
549
+ form.addEventListener('submit', function (event) {
550
+ event.preventDefault();
551
+ submitButton.disabled = true;
552
+ errorBox.style.display = 'none';
553
+ var returnTo = sameOriginReturnTo(params.get('returnTo'));
554
+ fetch(LOGIN_ACTION, {
555
+ method: 'POST',
556
+ headers: { 'content-type': 'application/json' },
557
+ credentials: 'same-origin',
558
+ body: JSON.stringify({
559
+ username: document.getElementById('username').value,
560
+ password: document.getElementById('password').value,
561
+ returnTo: returnTo,
562
+ }),
563
+ })
564
+ .then(function (response) {
565
+ if (!response.ok) throw new Error('unauthorized');
566
+ return response.json();
567
+ })
568
+ .then(function (data) {
569
+ window.location.href = data.redirectTo || DEFAULT_RETURN_TO;
570
+ })
571
+ .catch(function () {
572
+ errorBox.style.display = 'block';
573
+ submitButton.disabled = false;
574
+ });
575
+ });
576
+ })();
577
+ </script>`, "Sign in \u2014 Catalog");
557
578
  }
558
- __name(revalidateOnce, "revalidateOnce");
559
- async function maybeRenewSession(auth, session, request, response, now = Date.now()) {
560
- if (now - session.iat <= auth.ttlMs / 2) return true;
561
- const user = {
562
- id: session.sub,
563
- ...session.name !== void 0 ? {
564
- name: session.name
565
- } : {},
566
- roles: session.roles
567
- };
568
- const allowed = await revalidateOnce(auth, user);
569
- if (!allowed) {
570
- clearSessionCookie({
571
- request,
572
- response
573
- });
574
- return false;
575
- }
576
- issueSessionCookie(user, {
577
- auth,
578
- request,
579
- response,
580
- now
581
- });
582
- return true;
579
+ __name(renderLoginPage, "renderLoginPage");
580
+ function renderSessionRequiredPage(basePath) {
581
+ return page(`<h1>Open this console from your application</h1>
582
+ <p>Your session is minted by the host app. Use its console launcher to sign in, then reload.</p>
583
+ <a class="button" href="${basePath}">Retry</a>`);
583
584
  }
584
- __name(maybeRenewSession, "maybeRenewSession");
585
+ __name(renderSessionRequiredPage, "renderSessionRequiredPage");
585
586
 
586
587
  // src/server/catalog-ui.controller.ts
587
588
  var import_node_fs = require("fs");
@@ -980,8 +981,11 @@ CatalogAuthController = _ts_decorate4([
980
981
  ], CatalogAuthController);
981
982
 
982
983
  // src/server/catalog-dashboard.module.ts
983
- var import_common5 = require("@nestjs/common");
984
+ var import_common6 = require("@nestjs/common");
984
985
  var import_core = require("@nestjs/core");
986
+
987
+ // src/server/catalog-session.guard.ts
988
+ var import_common5 = require("@nestjs/common");
985
989
  function _ts_decorate5(decorators, target, key, desc) {
986
990
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
987
991
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -989,6 +993,117 @@ function _ts_decorate5(decorators, target, key, desc) {
989
993
  return c > 3 && r && Object.defineProperty(target, key, r), r;
990
994
  }
991
995
  __name(_ts_decorate5, "_ts_decorate");
996
+ function _ts_metadata4(k, v) {
997
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
998
+ }
999
+ __name(_ts_metadata4, "_ts_metadata");
1000
+ function _ts_param4(paramIndex, decorator) {
1001
+ return function(target, key) {
1002
+ decorator(target, key, paramIndex);
1003
+ };
1004
+ }
1005
+ __name(_ts_param4, "_ts_param");
1006
+ var CatalogUiSessionGuard = class {
1007
+ static {
1008
+ __name(this, "CatalogUiSessionGuard");
1009
+ }
1010
+ auth;
1011
+ basePath;
1012
+ constructor(auth, basePath) {
1013
+ this.auth = auth;
1014
+ this.basePath = basePath;
1015
+ }
1016
+ async canActivate(context) {
1017
+ if (!this.auth) return true;
1018
+ const auth = this.auth;
1019
+ const http = context.switchToHttp();
1020
+ const request = http.getRequest();
1021
+ const session = readSessionFromRequest(auth, request);
1022
+ if (!session) {
1023
+ this.denyUnauthenticated(auth, request);
1024
+ }
1025
+ if (!await maybeRenewSession(auth, session, request, http.getResponse())) {
1026
+ this.denyUnauthenticated(auth, request);
1027
+ }
1028
+ return true;
1029
+ }
1030
+ /**
1031
+ * A revoked session (the host's `revalidate` hook says no) is denied exactly like an absent
1032
+ * one — by design, there is nothing left to distinguish "never had a session" from "had one,
1033
+ * then lost it" once the cookie is cleared, so both get the same Mode-aware treatment.
1034
+ *
1035
+ * Takes `auth` explicitly rather than reading `this.auth`: `canActivate`'s `!this.auth` early
1036
+ * return narrows the field within that method only — TS doesn't carry it across a method call
1037
+ * — so callers pass the already-narrowed value instead of this method re-deriving (or
1038
+ * asserting away) the nullability.
1039
+ */
1040
+ denyUnauthenticated(auth, request) {
1041
+ if (!auth.modes.includes("login")) throw new DashboardSessionRequiredException(this.basePath);
1042
+ const returnTo = encodeURIComponent(originalRequestUrl(request));
1043
+ throw new DashboardLoginRedirectException(`${this.basePath}/login?returnTo=${returnTo}`);
1044
+ }
1045
+ };
1046
+ CatalogUiSessionGuard = _ts_decorate5([
1047
+ (0, import_common5.Injectable)(),
1048
+ _ts_param4(0, (0, import_common5.Inject)(DASHBOARD_AUTH)),
1049
+ _ts_param4(1, (0, import_common5.Inject)(DASHBOARD_BASE_PATH)),
1050
+ _ts_metadata4("design:type", Function),
1051
+ _ts_metadata4("design:paramtypes", [
1052
+ Object,
1053
+ String
1054
+ ])
1055
+ ], CatalogUiSessionGuard);
1056
+ var CatalogApiSessionGuard = class {
1057
+ static {
1058
+ __name(this, "CatalogApiSessionGuard");
1059
+ }
1060
+ auth;
1061
+ constructor(auth) {
1062
+ this.auth = auth;
1063
+ }
1064
+ async canActivate(context) {
1065
+ if (!this.auth) return true;
1066
+ const auth = this.auth;
1067
+ const http = context.switchToHttp();
1068
+ const request = http.getRequest();
1069
+ const session = readSessionFromRequest(auth, request);
1070
+ if (!session) throw this.unauthorized(auth);
1071
+ if (!await maybeRenewSession(auth, session, request, http.getResponse())) {
1072
+ throw this.unauthorized(auth);
1073
+ }
1074
+ return true;
1075
+ }
1076
+ /**
1077
+ * A bare 401 body carrying `{ auth: { modes } }` — mirrors `@dudousxd/nestjs-telescope`'s
1078
+ * dashboardAuth 401. The API is fetched (never navigated), so this is the ONLY way the console
1079
+ * SPA (`catalog-client.ts`) learns which auth surface to send the operator to on a mid-session
1080
+ * 401; `CatalogUiSessionGuard`'s redirect/session-required exceptions above don't reach it.
1081
+ */
1082
+ unauthorized(auth) {
1083
+ return new import_common5.UnauthorizedException({
1084
+ auth: {
1085
+ modes: auth.modes
1086
+ }
1087
+ });
1088
+ }
1089
+ };
1090
+ CatalogApiSessionGuard = _ts_decorate5([
1091
+ (0, import_common5.Injectable)(),
1092
+ _ts_param4(0, (0, import_common5.Inject)(DASHBOARD_AUTH)),
1093
+ _ts_metadata4("design:type", Function),
1094
+ _ts_metadata4("design:paramtypes", [
1095
+ Object
1096
+ ])
1097
+ ], CatalogApiSessionGuard);
1098
+
1099
+ // src/server/catalog-dashboard.module.ts
1100
+ function _ts_decorate6(decorators, target, key, desc) {
1101
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1102
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1103
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1104
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1105
+ }
1106
+ __name(_ts_decorate6, "_ts_decorate");
992
1107
  var CatalogDashboardModule = class {
993
1108
  static {
994
1109
  __name(this, "CatalogDashboardModule");
@@ -1028,15 +1143,20 @@ var CatalogDashboardModule = class {
1028
1143
  };
1029
1144
  }
1030
1145
  };
1031
- CatalogDashboardModule = _ts_decorate5([
1032
- (0, import_common5.Module)({})
1146
+ CatalogDashboardModule = _ts_decorate6([
1147
+ (0, import_common6.Module)({})
1033
1148
  ], CatalogDashboardModule);
1149
+ var sessionGuardStamped = false;
1034
1150
  function build(options, auth) {
1035
1151
  const path = normalise(options.path ?? "/catalog");
1036
1152
  const apiPath = normalise(options.apiPath ?? "/api/catalog-service");
1153
+ if (!sessionGuardStamped) {
1154
+ (0, import_common6.UseGuards)(CatalogUiSessionGuard)(CatalogUiController);
1155
+ sessionGuardStamped = true;
1156
+ }
1037
1157
  for (const guard of options.guards ?? []) {
1038
- (0, import_common5.UseGuards)(guard)(CatalogUiController);
1039
- (0, import_common5.UseGuards)(guard)(CatalogAuthController);
1158
+ (0, import_common6.UseGuards)(guard)(CatalogUiController);
1159
+ (0, import_common6.UseGuards)(guard)(CatalogAuthController);
1040
1160
  }
1041
1161
  const providers = [
1042
1162
  {
@@ -1047,7 +1167,10 @@ function build(options, auth) {
1047
1167
  provide: DASHBOARD_API_PATH,
1048
1168
  useValue: apiPath
1049
1169
  },
1050
- auth
1170
+ auth,
1171
+ // Constructed by Nest, so it must be declared here — a guard stamped by
1172
+ // `UseGuards` is still resolved from the declaring module's injector.
1173
+ CatalogUiSessionGuard
1051
1174
  ];
1052
1175
  return {
1053
1176
  module: CatalogDashboardModule,
@@ -1090,118 +1213,6 @@ function normalise(path) {
1090
1213
  return withLeading.length > 1 ? withLeading.replace(/\/+$/, "") : withLeading;
1091
1214
  }
1092
1215
  __name(normalise, "normalise");
1093
-
1094
- // src/server/catalog-session.guard.ts
1095
- var import_common6 = require("@nestjs/common");
1096
- function _ts_decorate6(decorators, target, key, desc) {
1097
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1098
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1099
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1100
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1101
- }
1102
- __name(_ts_decorate6, "_ts_decorate");
1103
- function _ts_metadata4(k, v) {
1104
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1105
- }
1106
- __name(_ts_metadata4, "_ts_metadata");
1107
- function _ts_param4(paramIndex, decorator) {
1108
- return function(target, key) {
1109
- decorator(target, key, paramIndex);
1110
- };
1111
- }
1112
- __name(_ts_param4, "_ts_param");
1113
- var CatalogUiSessionGuard = class {
1114
- static {
1115
- __name(this, "CatalogUiSessionGuard");
1116
- }
1117
- auth;
1118
- basePath;
1119
- constructor(auth, basePath) {
1120
- this.auth = auth;
1121
- this.basePath = basePath;
1122
- }
1123
- async canActivate(context) {
1124
- if (!this.auth) return true;
1125
- const auth = this.auth;
1126
- const http = context.switchToHttp();
1127
- const request = http.getRequest();
1128
- const session = readSessionFromRequest(auth, request);
1129
- if (!session) {
1130
- this.denyUnauthenticated(auth, request);
1131
- }
1132
- if (!await maybeRenewSession(auth, session, request, http.getResponse())) {
1133
- this.denyUnauthenticated(auth, request);
1134
- }
1135
- return true;
1136
- }
1137
- /**
1138
- * A revoked session (the host's `revalidate` hook says no) is denied exactly like an absent
1139
- * one — by design, there is nothing left to distinguish "never had a session" from "had one,
1140
- * then lost it" once the cookie is cleared, so both get the same Mode-aware treatment.
1141
- *
1142
- * Takes `auth` explicitly rather than reading `this.auth`: `canActivate`'s `!this.auth` early
1143
- * return narrows the field within that method only — TS doesn't carry it across a method call
1144
- * — so callers pass the already-narrowed value instead of this method re-deriving (or
1145
- * asserting away) the nullability.
1146
- */
1147
- denyUnauthenticated(auth, request) {
1148
- if (!auth.modes.includes("login")) throw new DashboardSessionRequiredException(this.basePath);
1149
- const returnTo = encodeURIComponent(originalRequestUrl(request));
1150
- throw new DashboardLoginRedirectException(`${this.basePath}/login?returnTo=${returnTo}`);
1151
- }
1152
- };
1153
- CatalogUiSessionGuard = _ts_decorate6([
1154
- (0, import_common6.Injectable)(),
1155
- _ts_param4(0, (0, import_common6.Inject)(DASHBOARD_AUTH)),
1156
- _ts_param4(1, (0, import_common6.Inject)(DASHBOARD_BASE_PATH)),
1157
- _ts_metadata4("design:type", Function),
1158
- _ts_metadata4("design:paramtypes", [
1159
- Object,
1160
- String
1161
- ])
1162
- ], CatalogUiSessionGuard);
1163
- var CatalogApiSessionGuard = class {
1164
- static {
1165
- __name(this, "CatalogApiSessionGuard");
1166
- }
1167
- auth;
1168
- constructor(auth) {
1169
- this.auth = auth;
1170
- }
1171
- async canActivate(context) {
1172
- if (!this.auth) return true;
1173
- const auth = this.auth;
1174
- const http = context.switchToHttp();
1175
- const request = http.getRequest();
1176
- const session = readSessionFromRequest(auth, request);
1177
- if (!session) throw this.unauthorized(auth);
1178
- if (!await maybeRenewSession(auth, session, request, http.getResponse())) {
1179
- throw this.unauthorized(auth);
1180
- }
1181
- return true;
1182
- }
1183
- /**
1184
- * A bare 401 body carrying `{ auth: { modes } }` — mirrors `@dudousxd/nestjs-telescope`'s
1185
- * dashboardAuth 401. The API is fetched (never navigated), so this is the ONLY way the console
1186
- * SPA (`catalog-client.ts`) learns which auth surface to send the operator to on a mid-session
1187
- * 401; `CatalogUiSessionGuard`'s redirect/session-required exceptions above don't reach it.
1188
- */
1189
- unauthorized(auth) {
1190
- return new import_common6.UnauthorizedException({
1191
- auth: {
1192
- modes: auth.modes
1193
- }
1194
- });
1195
- }
1196
- };
1197
- CatalogApiSessionGuard = _ts_decorate6([
1198
- (0, import_common6.Injectable)(),
1199
- _ts_param4(0, (0, import_common6.Inject)(DASHBOARD_AUTH)),
1200
- _ts_metadata4("design:type", Function),
1201
- _ts_metadata4("design:paramtypes", [
1202
- Object
1203
- ])
1204
- ], CatalogApiSessionGuard);
1205
1216
  // Annotate the CommonJS export names for ESM import in node:
1206
1217
  0 && (module.exports = {
1207
1218
  CatalogApiSessionGuard,
@@ -1212,6 +1223,7 @@ CatalogApiSessionGuard = _ts_decorate6([
1212
1223
  DASHBOARD_API_PATH,
1213
1224
  DASHBOARD_AUTH,
1214
1225
  DASHBOARD_BASE_PATH,
1215
- catalogDashboardMountPaths
1226
+ catalogDashboardMountPaths,
1227
+ readCatalogConsoleSession
1216
1228
  });
1217
1229
  //# sourceMappingURL=index.cjs.map