@dudousxd/nestjs-catalog-dashboard 0.4.0 → 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;
@@ -583,6 +409,181 @@ async function maybeRenewSession(auth, session, request, response, now = Date.no
583
409
  }
584
410
  __name(maybeRenewSession, "maybeRenewSession");
585
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");
578
+ }
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>`);
584
+ }
585
+ __name(renderSessionRequiredPage, "renderSessionRequiredPage");
586
+
586
587
  // src/server/catalog-ui.controller.ts
587
588
  var import_node_fs = require("fs");
588
589
  var import_node_path = require("path");
@@ -1222,6 +1223,7 @@ __name(normalise, "normalise");
1222
1223
  DASHBOARD_API_PATH,
1223
1224
  DASHBOARD_AUTH,
1224
1225
  DASHBOARD_BASE_PATH,
1225
- catalogDashboardMountPaths
1226
+ catalogDashboardMountPaths,
1227
+ readCatalogConsoleSession
1226
1228
  });
1227
1229
  //# sourceMappingURL=index.cjs.map