@dudousxd/nestjs-catalog-dashboard 0.4.0 → 0.6.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.
@@ -66,180 +66,46 @@ function resolveDashboardAuth(options) {
66
66
  }
67
67
  __name(resolveDashboardAuth, "resolveDashboardAuth");
68
68
 
69
- // src/server/catalog-auth.controller.ts
70
- import { BadRequestException, Body, Controller as Controller2, Get as Get2, Header as Header2, HttpCode, Inject as Inject3, Logger as Logger2, NotFoundException as NotFoundException2, Optional as Optional3, Post, Req, Res, UnauthorizedException } from "@nestjs/common";
71
-
72
- // src/server/auth/login-page.ts
73
- function page(content, title = "Catalog") {
74
- return `<!doctype html>
75
- <html lang="en">
76
- <head>
77
- <meta charset="utf-8" />
78
- <meta name="viewport" content="width=device-width, initial-scale=1" />
79
- <meta name="robots" content="noindex, nofollow" />
80
- <title>${title}</title>
81
- <style>
82
- :root { color-scheme: dark; }
83
- * { box-sizing: border-box; }
84
- body {
85
- margin: 0;
86
- min-height: 100vh;
87
- display: flex;
88
- align-items: center;
89
- justify-content: center;
90
- background: #09090b;
91
- color: #e4e4e7;
92
- font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
93
- padding: 16px;
94
- }
95
- .card {
96
- width: 100%;
97
- max-width: 384px;
98
- border: 1px solid #27272a;
99
- background: #18181b;
100
- border-radius: 8px;
101
- padding: 32px;
102
- box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.5);
103
- }
104
- .brand {
105
- margin: 0 0 24px;
106
- text-align: center;
107
- font-size: 18px;
108
- font-weight: 600;
109
- color: #34d399;
110
- }
111
- h1 {
112
- margin: 0 0 12px;
113
- font-size: 16px;
114
- font-weight: 600;
115
- color: #f4f4f5;
116
- }
117
- p { margin: 0 0 16px; color: #a1a1aa; }
118
- form { display: flex; flex-direction: column; gap: 16px; }
119
- label { display: flex; flex-direction: column; gap: 6px; }
120
- .field-label {
121
- font-size: 11px;
122
- text-transform: uppercase;
123
- letter-spacing: 0.05em;
124
- color: #71717a;
125
- }
126
- input {
127
- border-radius: 4px;
128
- border: 1px solid #3f3f46;
129
- background: #09090b;
130
- color: #f4f4f5;
131
- padding: 8px 12px;
132
- font: inherit;
133
- outline: none;
134
- }
135
- input:focus { border-color: rgb(52 211 153 / 0.6); }
136
- #error {
137
- display: none;
138
- margin: 0;
139
- font-size: 12px;
140
- color: #fb7185;
141
- }
142
- button, .button {
143
- margin-top: 8px;
144
- border-radius: 4px;
145
- border: 1px solid rgb(52 211 153 / 0.4);
146
- background: rgb(52 211 153 / 0.1);
147
- color: #6ee7b7;
148
- padding: 8px 12px;
149
- font: inherit;
150
- font-size: 12px;
151
- font-weight: 500;
152
- text-transform: uppercase;
153
- letter-spacing: 0.05em;
154
- cursor: pointer;
155
- display: inline-block;
156
- text-align: center;
157
- text-decoration: none;
158
- box-sizing: border-box;
159
- }
160
- button:hover:not(:disabled), .button:hover { background: rgb(52 211 153 / 0.2); }
161
- button:disabled { opacity: 0.6; cursor: default; }
162
- </style>
163
- </head>
164
- <body>
165
- <div class="card">
166
- ${content}
167
- </div>
168
- </body>
169
- </html>`;
170
- }
171
- __name(page, "page");
172
- function renderLoginPage(basePath) {
173
- const loginAction = `${basePath}/login`;
174
- const defaultReturnTo = basePath;
175
- return page(`<p class="brand">Catalog</p>
176
- <form id="login-form" autocomplete="on">
177
- <label>
178
- <span class="field-label">Username</span>
179
- <input id="username" name="username" type="text" autocomplete="username" required autofocus />
180
- </label>
181
- <label>
182
- <span class="field-label">Password</span>
183
- <input id="password" name="password" type="password" autocomplete="current-password" />
184
- </label>
185
- <p id="error" role="alert">Invalid username or password.</p>
186
- <button id="submit" type="submit">Sign in</button>
187
- </form>
188
- <script>
189
- (function () {
190
- var LOGIN_ACTION = ${JSON.stringify(loginAction)};
191
- var DEFAULT_RETURN_TO = ${JSON.stringify(defaultReturnTo)};
192
- var params = new URLSearchParams(window.location.search);
193
- var errorBox = document.getElementById('error');
194
- if (params.get('error')) errorBox.style.display = 'block';
195
-
196
- function sameOriginReturnTo(value) {
197
- if (typeof value !== 'string' || value === '') return DEFAULT_RETURN_TO;
198
- if (value.charAt(0) !== '/' || value.charAt(1) === '/' || value.indexOf('://') !== -1) {
199
- return DEFAULT_RETURN_TO;
69
+ // src/server/auth/cookie-header.ts
70
+ function parseCookieHeader(header) {
71
+ const cookies = {};
72
+ if (typeof header !== "string" || header === "") return cookies;
73
+ for (const segment of header.split(";")) {
74
+ const eq = segment.indexOf("=");
75
+ if (eq <= 0) continue;
76
+ const name = segment.slice(0, eq).trim();
77
+ if (name === "") continue;
78
+ let rawValue = segment.slice(eq + 1).trim();
79
+ if (rawValue.length >= 2 && rawValue.startsWith('"') && rawValue.endsWith('"')) {
80
+ rawValue = rawValue.slice(1, -1);
81
+ }
82
+ if (name in cookies) continue;
83
+ try {
84
+ cookies[name] = decodeURIComponent(rawValue);
85
+ } catch {
86
+ cookies[name] = rawValue;
200
87
  }
201
- return value;
202
88
  }
203
-
204
- var form = document.getElementById('login-form');
205
- var submitButton = document.getElementById('submit');
206
- form.addEventListener('submit', function (event) {
207
- event.preventDefault();
208
- submitButton.disabled = true;
209
- errorBox.style.display = 'none';
210
- var returnTo = sameOriginReturnTo(params.get('returnTo'));
211
- fetch(LOGIN_ACTION, {
212
- method: 'POST',
213
- headers: { 'content-type': 'application/json' },
214
- credentials: 'same-origin',
215
- body: JSON.stringify({
216
- username: document.getElementById('username').value,
217
- password: document.getElementById('password').value,
218
- returnTo: returnTo,
219
- }),
220
- })
221
- .then(function (response) {
222
- if (!response.ok) throw new Error('unauthorized');
223
- return response.json();
224
- })
225
- .then(function (data) {
226
- window.location.href = data.redirectTo || DEFAULT_RETURN_TO;
227
- })
228
- .catch(function () {
229
- errorBox.style.display = 'block';
230
- submitButton.disabled = false;
231
- });
232
- });
233
- })();
234
- </script>`, "Sign in \u2014 Catalog");
89
+ return cookies;
235
90
  }
236
- __name(renderLoginPage, "renderLoginPage");
237
- function renderSessionRequiredPage(basePath) {
238
- return page(`<h1>Open this console from your application</h1>
239
- <p>Your session is minted by the host app. Use its console launcher to sign in, then reload.</p>
240
- <a class="button" href="${basePath}">Retry</a>`);
91
+ __name(parseCookieHeader, "parseCookieHeader");
92
+ function serializeSetCookie(name, value, options) {
93
+ const parts = [
94
+ `${name}=${options.clear ? "" : encodeURIComponent(value)}`
95
+ ];
96
+ parts.push(`Path=${options.path}`);
97
+ parts.push("HttpOnly");
98
+ parts.push("SameSite=Lax");
99
+ if (options.secure) parts.push("Secure");
100
+ if (options.clear) {
101
+ parts.push("Max-Age=0");
102
+ parts.push("Expires=Thu, 01 Jan 1970 00:00:00 GMT");
103
+ } else {
104
+ parts.push(`Max-Age=${options.maxAgeSeconds}`);
105
+ }
106
+ return parts.join("; ");
241
107
  }
242
- __name(renderSessionRequiredPage, "renderSessionRequiredPage");
108
+ __name(serializeSetCookie, "serializeSetCookie");
243
109
 
244
110
  // src/server/auth/request.ts
245
111
  function isRecord(value) {
@@ -355,47 +221,6 @@ function writeHtmlRaw(response, html, status = 200) {
355
221
  }
356
222
  __name(writeHtmlRaw, "writeHtmlRaw");
357
223
 
358
- // src/server/auth/cookie-header.ts
359
- function parseCookieHeader(header) {
360
- const cookies = {};
361
- if (typeof header !== "string" || header === "") return cookies;
362
- for (const segment of header.split(";")) {
363
- const eq = segment.indexOf("=");
364
- if (eq <= 0) continue;
365
- const name = segment.slice(0, eq).trim();
366
- if (name === "") continue;
367
- let rawValue = segment.slice(eq + 1).trim();
368
- if (rawValue.length >= 2 && rawValue.startsWith('"') && rawValue.endsWith('"')) {
369
- rawValue = rawValue.slice(1, -1);
370
- }
371
- if (name in cookies) continue;
372
- try {
373
- cookies[name] = decodeURIComponent(rawValue);
374
- } catch {
375
- cookies[name] = rawValue;
376
- }
377
- }
378
- return cookies;
379
- }
380
- __name(parseCookieHeader, "parseCookieHeader");
381
- function serializeSetCookie(name, value, options) {
382
- const parts = [
383
- `${name}=${options.clear ? "" : encodeURIComponent(value)}`
384
- ];
385
- parts.push(`Path=${options.path}`);
386
- parts.push("HttpOnly");
387
- parts.push("SameSite=Lax");
388
- if (options.secure) parts.push("Secure");
389
- if (options.clear) {
390
- parts.push("Max-Age=0");
391
- parts.push("Expires=Thu, 01 Jan 1970 00:00:00 GMT");
392
- } else {
393
- parts.push(`Max-Age=${options.maxAgeSeconds}`);
394
- }
395
- return parts.join("; ");
396
- }
397
- __name(serializeSetCookie, "serializeSetCookie");
398
-
399
224
  // src/server/auth/session-cookie.ts
400
225
  import { createHmac, timingSafeEqual } from "node:crypto";
401
226
  var EXP_GRACE_MS = 3e4;
@@ -550,6 +375,181 @@ async function maybeRenewSession(auth, session, request, response, now = Date.no
550
375
  }
551
376
  __name(maybeRenewSession, "maybeRenewSession");
552
377
 
378
+ // src/server/catalog-auth.controller.ts
379
+ import { BadRequestException, Body, Controller as Controller2, Get as Get2, Header as Header2, HttpCode, Inject as Inject3, Logger as Logger2, NotFoundException as NotFoundException2, Optional as Optional3, Post, Req, Res, UnauthorizedException } from "@nestjs/common";
380
+
381
+ // src/server/auth/login-page.ts
382
+ function page(content, title = "Catalog") {
383
+ return `<!doctype html>
384
+ <html lang="en">
385
+ <head>
386
+ <meta charset="utf-8" />
387
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
388
+ <meta name="robots" content="noindex, nofollow" />
389
+ <title>${title}</title>
390
+ <style>
391
+ :root { color-scheme: dark; }
392
+ * { box-sizing: border-box; }
393
+ body {
394
+ margin: 0;
395
+ min-height: 100vh;
396
+ display: flex;
397
+ align-items: center;
398
+ justify-content: center;
399
+ background: #09090b;
400
+ color: #e4e4e7;
401
+ font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
402
+ padding: 16px;
403
+ }
404
+ .card {
405
+ width: 100%;
406
+ max-width: 384px;
407
+ border: 1px solid #27272a;
408
+ background: #18181b;
409
+ border-radius: 8px;
410
+ padding: 32px;
411
+ box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.5);
412
+ }
413
+ .brand {
414
+ margin: 0 0 24px;
415
+ text-align: center;
416
+ font-size: 18px;
417
+ font-weight: 600;
418
+ color: #34d399;
419
+ }
420
+ h1 {
421
+ margin: 0 0 12px;
422
+ font-size: 16px;
423
+ font-weight: 600;
424
+ color: #f4f4f5;
425
+ }
426
+ p { margin: 0 0 16px; color: #a1a1aa; }
427
+ form { display: flex; flex-direction: column; gap: 16px; }
428
+ label { display: flex; flex-direction: column; gap: 6px; }
429
+ .field-label {
430
+ font-size: 11px;
431
+ text-transform: uppercase;
432
+ letter-spacing: 0.05em;
433
+ color: #71717a;
434
+ }
435
+ input {
436
+ border-radius: 4px;
437
+ border: 1px solid #3f3f46;
438
+ background: #09090b;
439
+ color: #f4f4f5;
440
+ padding: 8px 12px;
441
+ font: inherit;
442
+ outline: none;
443
+ }
444
+ input:focus { border-color: rgb(52 211 153 / 0.6); }
445
+ #error {
446
+ display: none;
447
+ margin: 0;
448
+ font-size: 12px;
449
+ color: #fb7185;
450
+ }
451
+ button, .button {
452
+ margin-top: 8px;
453
+ border-radius: 4px;
454
+ border: 1px solid rgb(52 211 153 / 0.4);
455
+ background: rgb(52 211 153 / 0.1);
456
+ color: #6ee7b7;
457
+ padding: 8px 12px;
458
+ font: inherit;
459
+ font-size: 12px;
460
+ font-weight: 500;
461
+ text-transform: uppercase;
462
+ letter-spacing: 0.05em;
463
+ cursor: pointer;
464
+ display: inline-block;
465
+ text-align: center;
466
+ text-decoration: none;
467
+ box-sizing: border-box;
468
+ }
469
+ button:hover:not(:disabled), .button:hover { background: rgb(52 211 153 / 0.2); }
470
+ button:disabled { opacity: 0.6; cursor: default; }
471
+ </style>
472
+ </head>
473
+ <body>
474
+ <div class="card">
475
+ ${content}
476
+ </div>
477
+ </body>
478
+ </html>`;
479
+ }
480
+ __name(page, "page");
481
+ function renderLoginPage(basePath) {
482
+ const loginAction = `${basePath}/login`;
483
+ const defaultReturnTo = basePath;
484
+ return page(`<p class="brand">Catalog</p>
485
+ <form id="login-form" autocomplete="on">
486
+ <label>
487
+ <span class="field-label">Username</span>
488
+ <input id="username" name="username" type="text" autocomplete="username" required autofocus />
489
+ </label>
490
+ <label>
491
+ <span class="field-label">Password</span>
492
+ <input id="password" name="password" type="password" autocomplete="current-password" />
493
+ </label>
494
+ <p id="error" role="alert">Invalid username or password.</p>
495
+ <button id="submit" type="submit">Sign in</button>
496
+ </form>
497
+ <script>
498
+ (function () {
499
+ var LOGIN_ACTION = ${JSON.stringify(loginAction)};
500
+ var DEFAULT_RETURN_TO = ${JSON.stringify(defaultReturnTo)};
501
+ var params = new URLSearchParams(window.location.search);
502
+ var errorBox = document.getElementById('error');
503
+ if (params.get('error')) errorBox.style.display = 'block';
504
+
505
+ function sameOriginReturnTo(value) {
506
+ if (typeof value !== 'string' || value === '') return DEFAULT_RETURN_TO;
507
+ if (value.charAt(0) !== '/' || value.charAt(1) === '/' || value.indexOf('://') !== -1) {
508
+ return DEFAULT_RETURN_TO;
509
+ }
510
+ return value;
511
+ }
512
+
513
+ var form = document.getElementById('login-form');
514
+ var submitButton = document.getElementById('submit');
515
+ form.addEventListener('submit', function (event) {
516
+ event.preventDefault();
517
+ submitButton.disabled = true;
518
+ errorBox.style.display = 'none';
519
+ var returnTo = sameOriginReturnTo(params.get('returnTo'));
520
+ fetch(LOGIN_ACTION, {
521
+ method: 'POST',
522
+ headers: { 'content-type': 'application/json' },
523
+ credentials: 'same-origin',
524
+ body: JSON.stringify({
525
+ username: document.getElementById('username').value,
526
+ password: document.getElementById('password').value,
527
+ returnTo: returnTo,
528
+ }),
529
+ })
530
+ .then(function (response) {
531
+ if (!response.ok) throw new Error('unauthorized');
532
+ return response.json();
533
+ })
534
+ .then(function (data) {
535
+ window.location.href = data.redirectTo || DEFAULT_RETURN_TO;
536
+ })
537
+ .catch(function () {
538
+ errorBox.style.display = 'block';
539
+ submitButton.disabled = false;
540
+ });
541
+ });
542
+ })();
543
+ </script>`, "Sign in \u2014 Catalog");
544
+ }
545
+ __name(renderLoginPage, "renderLoginPage");
546
+ function renderSessionRequiredPage(basePath) {
547
+ return page(`<h1>Open this console from your application</h1>
548
+ <p>Your session is minted by the host app. Use its console launcher to sign in, then reload.</p>
549
+ <a class="button" href="${basePath}">Retry</a>`);
550
+ }
551
+ __name(renderSessionRequiredPage, "renderSessionRequiredPage");
552
+
553
553
  // src/server/catalog-ui.controller.ts
554
554
  import { existsSync, readFileSync } from "node:fs";
555
555
  import { basename, extname, join, resolve, sep } from "node:path";
@@ -1188,6 +1188,7 @@ export {
1188
1188
  DASHBOARD_API_PATH,
1189
1189
  DASHBOARD_AUTH,
1190
1190
  DASHBOARD_BASE_PATH,
1191
- catalogDashboardMountPaths
1191
+ catalogDashboardMountPaths,
1192
+ readSessionFromRequest as readCatalogConsoleSession
1192
1193
  };
1193
1194
  //# sourceMappingURL=index.js.map