@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.
- package/dist/server/index.cjs +371 -359
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +17 -1
- package/dist/server/index.d.ts +17 -1
- package/dist/server/index.js +363 -352
- package/dist/server/index.js.map +1 -1
- package/dist/spa/assets/{index-CK21cSYi.js → index-BDuhn7Y1.js} +76 -76
- package/dist/spa/assets/index-HC2bFpBt.css +1 -0
- package/dist/spa/index.html +2 -2
- package/package.json +2 -2
- package/dist/spa/assets/index-CweNfj1K.css +0 -1
package/dist/server/index.js
CHANGED
|
@@ -66,180 +66,46 @@ function resolveDashboardAuth(options) {
|
|
|
66
66
|
}
|
|
67
67
|
__name(resolveDashboardAuth, "resolveDashboardAuth");
|
|
68
68
|
|
|
69
|
-
// src/server/
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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(
|
|
237
|
-
function
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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(
|
|
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;
|
|
@@ -519,36 +344,211 @@ function revalidateOnce(auth, user) {
|
|
|
519
344
|
const call = Promise.resolve().then(() => revalidate(user)).catch(() => false).finally(() => {
|
|
520
345
|
inFlightRevalidations.delete(key);
|
|
521
346
|
});
|
|
522
|
-
inFlightRevalidations.set(key, call);
|
|
523
|
-
return call;
|
|
347
|
+
inFlightRevalidations.set(key, call);
|
|
348
|
+
return call;
|
|
349
|
+
}
|
|
350
|
+
__name(revalidateOnce, "revalidateOnce");
|
|
351
|
+
async function maybeRenewSession(auth, session, request, response, now = Date.now()) {
|
|
352
|
+
if (now - session.iat <= auth.ttlMs / 2) return true;
|
|
353
|
+
const user = {
|
|
354
|
+
id: session.sub,
|
|
355
|
+
...session.name !== void 0 ? {
|
|
356
|
+
name: session.name
|
|
357
|
+
} : {},
|
|
358
|
+
roles: session.roles
|
|
359
|
+
};
|
|
360
|
+
const allowed = await revalidateOnce(auth, user);
|
|
361
|
+
if (!allowed) {
|
|
362
|
+
clearSessionCookie({
|
|
363
|
+
request,
|
|
364
|
+
response
|
|
365
|
+
});
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
issueSessionCookie(user, {
|
|
369
|
+
auth,
|
|
370
|
+
request,
|
|
371
|
+
response,
|
|
372
|
+
now
|
|
373
|
+
});
|
|
374
|
+
return true;
|
|
375
|
+
}
|
|
376
|
+
__name(maybeRenewSession, "maybeRenewSession");
|
|
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");
|
|
524
544
|
}
|
|
525
|
-
__name(
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
...session.name !== void 0 ? {
|
|
531
|
-
name: session.name
|
|
532
|
-
} : {},
|
|
533
|
-
roles: session.roles
|
|
534
|
-
};
|
|
535
|
-
const allowed = await revalidateOnce(auth, user);
|
|
536
|
-
if (!allowed) {
|
|
537
|
-
clearSessionCookie({
|
|
538
|
-
request,
|
|
539
|
-
response
|
|
540
|
-
});
|
|
541
|
-
return false;
|
|
542
|
-
}
|
|
543
|
-
issueSessionCookie(user, {
|
|
544
|
-
auth,
|
|
545
|
-
request,
|
|
546
|
-
response,
|
|
547
|
-
now
|
|
548
|
-
});
|
|
549
|
-
return true;
|
|
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
550
|
}
|
|
551
|
-
__name(
|
|
551
|
+
__name(renderSessionRequiredPage, "renderSessionRequiredPage");
|
|
552
552
|
|
|
553
553
|
// src/server/catalog-ui.controller.ts
|
|
554
554
|
import { existsSync, readFileSync } from "node:fs";
|
|
@@ -949,124 +949,16 @@ CatalogAuthController = _ts_decorate4([
|
|
|
949
949
|
// src/server/catalog-dashboard.module.ts
|
|
950
950
|
import { Module, UseGuards } from "@nestjs/common";
|
|
951
951
|
import { RouterModule } from "@nestjs/core";
|
|
952
|
-
function _ts_decorate5(decorators, target, key, desc) {
|
|
953
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
954
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
955
|
-
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;
|
|
956
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
957
|
-
}
|
|
958
|
-
__name(_ts_decorate5, "_ts_decorate");
|
|
959
|
-
var CatalogDashboardModule = class {
|
|
960
|
-
static {
|
|
961
|
-
__name(this, "CatalogDashboardModule");
|
|
962
|
-
}
|
|
963
|
-
static forRoot(options = {}) {
|
|
964
|
-
return build(options, {
|
|
965
|
-
provide: DASHBOARD_AUTH,
|
|
966
|
-
useValue: options.auth ? resolveDashboardAuth(options.auth) : null
|
|
967
|
-
});
|
|
968
|
-
}
|
|
969
|
-
/**
|
|
970
|
-
* Same mount, but the auth is built from DI.
|
|
971
|
-
*
|
|
972
|
-
* Needed whenever validating a session means asking something the host owns —
|
|
973
|
-
* a user store, a session service. `forRoot` cannot express that: `guards` and
|
|
974
|
-
* the router are bound at module-DEFINITION time, before any injector exists,
|
|
975
|
-
* which is why `guards` stays a static option on both forms.
|
|
976
|
-
*/
|
|
977
|
-
static forRootAsync(options) {
|
|
978
|
-
const factory = options.useDashboardAuth;
|
|
979
|
-
const mounted = build(options, {
|
|
980
|
-
provide: DASHBOARD_AUTH,
|
|
981
|
-
// Same resolution as `forRoot`, wrapped around the host's factory so the
|
|
982
|
-
// async path cannot skip it.
|
|
983
|
-
useFactory: /* @__PURE__ */ __name(async (...args) => {
|
|
984
|
-
const auth = await factory(...args);
|
|
985
|
-
return auth ? resolveDashboardAuth(auth) : null;
|
|
986
|
-
}, "useFactory"),
|
|
987
|
-
inject: options.inject ?? []
|
|
988
|
-
});
|
|
989
|
-
return {
|
|
990
|
-
...mounted,
|
|
991
|
-
imports: [
|
|
992
|
-
...mounted.imports ?? [],
|
|
993
|
-
...options.imports ?? []
|
|
994
|
-
]
|
|
995
|
-
};
|
|
996
|
-
}
|
|
997
|
-
};
|
|
998
|
-
CatalogDashboardModule = _ts_decorate5([
|
|
999
|
-
Module({})
|
|
1000
|
-
], CatalogDashboardModule);
|
|
1001
|
-
function build(options, auth) {
|
|
1002
|
-
const path = normalise(options.path ?? "/catalog");
|
|
1003
|
-
const apiPath = normalise(options.apiPath ?? "/api/catalog-service");
|
|
1004
|
-
for (const guard of options.guards ?? []) {
|
|
1005
|
-
UseGuards(guard)(CatalogUiController);
|
|
1006
|
-
UseGuards(guard)(CatalogAuthController);
|
|
1007
|
-
}
|
|
1008
|
-
const providers = [
|
|
1009
|
-
{
|
|
1010
|
-
provide: DASHBOARD_BASE_PATH,
|
|
1011
|
-
useValue: path
|
|
1012
|
-
},
|
|
1013
|
-
{
|
|
1014
|
-
provide: DASHBOARD_API_PATH,
|
|
1015
|
-
useValue: apiPath
|
|
1016
|
-
},
|
|
1017
|
-
auth
|
|
1018
|
-
];
|
|
1019
|
-
return {
|
|
1020
|
-
module: CatalogDashboardModule,
|
|
1021
|
-
// The controllers are `@Controller()` with no path of their own, and the
|
|
1022
|
-
// prefix arrives here instead. That is what lets `path` be configurable at
|
|
1023
|
-
// all: a decorator argument is fixed at class-definition time, so a
|
|
1024
|
-
// hardcoded one would pin every host to the same mount point.
|
|
1025
|
-
//
|
|
1026
|
-
// Without this the controllers inherit whatever the host's global prefix is
|
|
1027
|
-
// — they answered on `/api` — and the console 404s at its configured path
|
|
1028
|
-
// while the module reports itself initialised, which is a confusing pair of
|
|
1029
|
-
// symptoms to hold at once.
|
|
1030
|
-
imports: [
|
|
1031
|
-
RouterModule.register([
|
|
1032
|
-
{
|
|
1033
|
-
path,
|
|
1034
|
-
module: CatalogDashboardModule
|
|
1035
|
-
}
|
|
1036
|
-
])
|
|
1037
|
-
],
|
|
1038
|
-
controllers: [
|
|
1039
|
-
CatalogUiController,
|
|
1040
|
-
CatalogAuthController
|
|
1041
|
-
],
|
|
1042
|
-
providers,
|
|
1043
|
-
exports: providers
|
|
1044
|
-
};
|
|
1045
|
-
}
|
|
1046
|
-
__name(build, "build");
|
|
1047
|
-
function catalogDashboardMountPaths(options = {}) {
|
|
1048
|
-
const base = normalise(options.path ?? "/catalog").replace(/^\//, "");
|
|
1049
|
-
return [
|
|
1050
|
-
base,
|
|
1051
|
-
`${base}/{*splat}`
|
|
1052
|
-
];
|
|
1053
|
-
}
|
|
1054
|
-
__name(catalogDashboardMountPaths, "catalogDashboardMountPaths");
|
|
1055
|
-
function normalise(path) {
|
|
1056
|
-
const withLeading = path.startsWith("/") ? path : `/${path}`;
|
|
1057
|
-
return withLeading.length > 1 ? withLeading.replace(/\/+$/, "") : withLeading;
|
|
1058
|
-
}
|
|
1059
|
-
__name(normalise, "normalise");
|
|
1060
952
|
|
|
1061
953
|
// src/server/catalog-session.guard.ts
|
|
1062
954
|
import { Inject as Inject4, Injectable, UnauthorizedException as UnauthorizedException2 } from "@nestjs/common";
|
|
1063
|
-
function
|
|
955
|
+
function _ts_decorate5(decorators, target, key, desc) {
|
|
1064
956
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1065
957
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1066
958
|
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;
|
|
1067
959
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1068
960
|
}
|
|
1069
|
-
__name(
|
|
961
|
+
__name(_ts_decorate5, "_ts_decorate");
|
|
1070
962
|
function _ts_metadata4(k, v) {
|
|
1071
963
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1072
964
|
}
|
|
@@ -1117,7 +1009,7 @@ var CatalogUiSessionGuard = class {
|
|
|
1117
1009
|
throw new DashboardLoginRedirectException(`${this.basePath}/login?returnTo=${returnTo}`);
|
|
1118
1010
|
}
|
|
1119
1011
|
};
|
|
1120
|
-
CatalogUiSessionGuard =
|
|
1012
|
+
CatalogUiSessionGuard = _ts_decorate5([
|
|
1121
1013
|
Injectable(),
|
|
1122
1014
|
_ts_param4(0, Inject4(DASHBOARD_AUTH)),
|
|
1123
1015
|
_ts_param4(1, Inject4(DASHBOARD_BASE_PATH)),
|
|
@@ -1161,7 +1053,7 @@ var CatalogApiSessionGuard = class {
|
|
|
1161
1053
|
});
|
|
1162
1054
|
}
|
|
1163
1055
|
};
|
|
1164
|
-
CatalogApiSessionGuard =
|
|
1056
|
+
CatalogApiSessionGuard = _ts_decorate5([
|
|
1165
1057
|
Injectable(),
|
|
1166
1058
|
_ts_param4(0, Inject4(DASHBOARD_AUTH)),
|
|
1167
1059
|
_ts_metadata4("design:type", Function),
|
|
@@ -1169,6 +1061,124 @@ CatalogApiSessionGuard = _ts_decorate6([
|
|
|
1169
1061
|
Object
|
|
1170
1062
|
])
|
|
1171
1063
|
], CatalogApiSessionGuard);
|
|
1064
|
+
|
|
1065
|
+
// src/server/catalog-dashboard.module.ts
|
|
1066
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
1067
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1068
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1069
|
+
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;
|
|
1070
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1071
|
+
}
|
|
1072
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
1073
|
+
var CatalogDashboardModule = class {
|
|
1074
|
+
static {
|
|
1075
|
+
__name(this, "CatalogDashboardModule");
|
|
1076
|
+
}
|
|
1077
|
+
static forRoot(options = {}) {
|
|
1078
|
+
return build(options, {
|
|
1079
|
+
provide: DASHBOARD_AUTH,
|
|
1080
|
+
useValue: options.auth ? resolveDashboardAuth(options.auth) : null
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
/**
|
|
1084
|
+
* Same mount, but the auth is built from DI.
|
|
1085
|
+
*
|
|
1086
|
+
* Needed whenever validating a session means asking something the host owns —
|
|
1087
|
+
* a user store, a session service. `forRoot` cannot express that: `guards` and
|
|
1088
|
+
* the router are bound at module-DEFINITION time, before any injector exists,
|
|
1089
|
+
* which is why `guards` stays a static option on both forms.
|
|
1090
|
+
*/
|
|
1091
|
+
static forRootAsync(options) {
|
|
1092
|
+
const factory = options.useDashboardAuth;
|
|
1093
|
+
const mounted = build(options, {
|
|
1094
|
+
provide: DASHBOARD_AUTH,
|
|
1095
|
+
// Same resolution as `forRoot`, wrapped around the host's factory so the
|
|
1096
|
+
// async path cannot skip it.
|
|
1097
|
+
useFactory: /* @__PURE__ */ __name(async (...args) => {
|
|
1098
|
+
const auth = await factory(...args);
|
|
1099
|
+
return auth ? resolveDashboardAuth(auth) : null;
|
|
1100
|
+
}, "useFactory"),
|
|
1101
|
+
inject: options.inject ?? []
|
|
1102
|
+
});
|
|
1103
|
+
return {
|
|
1104
|
+
...mounted,
|
|
1105
|
+
imports: [
|
|
1106
|
+
...mounted.imports ?? [],
|
|
1107
|
+
...options.imports ?? []
|
|
1108
|
+
]
|
|
1109
|
+
};
|
|
1110
|
+
}
|
|
1111
|
+
};
|
|
1112
|
+
CatalogDashboardModule = _ts_decorate6([
|
|
1113
|
+
Module({})
|
|
1114
|
+
], CatalogDashboardModule);
|
|
1115
|
+
var sessionGuardStamped = false;
|
|
1116
|
+
function build(options, auth) {
|
|
1117
|
+
const path = normalise(options.path ?? "/catalog");
|
|
1118
|
+
const apiPath = normalise(options.apiPath ?? "/api/catalog-service");
|
|
1119
|
+
if (!sessionGuardStamped) {
|
|
1120
|
+
UseGuards(CatalogUiSessionGuard)(CatalogUiController);
|
|
1121
|
+
sessionGuardStamped = true;
|
|
1122
|
+
}
|
|
1123
|
+
for (const guard of options.guards ?? []) {
|
|
1124
|
+
UseGuards(guard)(CatalogUiController);
|
|
1125
|
+
UseGuards(guard)(CatalogAuthController);
|
|
1126
|
+
}
|
|
1127
|
+
const providers = [
|
|
1128
|
+
{
|
|
1129
|
+
provide: DASHBOARD_BASE_PATH,
|
|
1130
|
+
useValue: path
|
|
1131
|
+
},
|
|
1132
|
+
{
|
|
1133
|
+
provide: DASHBOARD_API_PATH,
|
|
1134
|
+
useValue: apiPath
|
|
1135
|
+
},
|
|
1136
|
+
auth,
|
|
1137
|
+
// Constructed by Nest, so it must be declared here — a guard stamped by
|
|
1138
|
+
// `UseGuards` is still resolved from the declaring module's injector.
|
|
1139
|
+
CatalogUiSessionGuard
|
|
1140
|
+
];
|
|
1141
|
+
return {
|
|
1142
|
+
module: CatalogDashboardModule,
|
|
1143
|
+
// The controllers are `@Controller()` with no path of their own, and the
|
|
1144
|
+
// prefix arrives here instead. That is what lets `path` be configurable at
|
|
1145
|
+
// all: a decorator argument is fixed at class-definition time, so a
|
|
1146
|
+
// hardcoded one would pin every host to the same mount point.
|
|
1147
|
+
//
|
|
1148
|
+
// Without this the controllers inherit whatever the host's global prefix is
|
|
1149
|
+
// — they answered on `/api` — and the console 404s at its configured path
|
|
1150
|
+
// while the module reports itself initialised, which is a confusing pair of
|
|
1151
|
+
// symptoms to hold at once.
|
|
1152
|
+
imports: [
|
|
1153
|
+
RouterModule.register([
|
|
1154
|
+
{
|
|
1155
|
+
path,
|
|
1156
|
+
module: CatalogDashboardModule
|
|
1157
|
+
}
|
|
1158
|
+
])
|
|
1159
|
+
],
|
|
1160
|
+
controllers: [
|
|
1161
|
+
CatalogUiController,
|
|
1162
|
+
CatalogAuthController
|
|
1163
|
+
],
|
|
1164
|
+
providers,
|
|
1165
|
+
exports: providers
|
|
1166
|
+
};
|
|
1167
|
+
}
|
|
1168
|
+
__name(build, "build");
|
|
1169
|
+
function catalogDashboardMountPaths(options = {}) {
|
|
1170
|
+
const base = normalise(options.path ?? "/catalog").replace(/^\//, "");
|
|
1171
|
+
return [
|
|
1172
|
+
base,
|
|
1173
|
+
`${base}/{*splat}`
|
|
1174
|
+
];
|
|
1175
|
+
}
|
|
1176
|
+
__name(catalogDashboardMountPaths, "catalogDashboardMountPaths");
|
|
1177
|
+
function normalise(path) {
|
|
1178
|
+
const withLeading = path.startsWith("/") ? path : `/${path}`;
|
|
1179
|
+
return withLeading.length > 1 ? withLeading.replace(/\/+$/, "") : withLeading;
|
|
1180
|
+
}
|
|
1181
|
+
__name(normalise, "normalise");
|
|
1172
1182
|
export {
|
|
1173
1183
|
CatalogApiSessionGuard,
|
|
1174
1184
|
CatalogAuthController,
|
|
@@ -1178,6 +1188,7 @@ export {
|
|
|
1178
1188
|
DASHBOARD_API_PATH,
|
|
1179
1189
|
DASHBOARD_AUTH,
|
|
1180
1190
|
DASHBOARD_BASE_PATH,
|
|
1181
|
-
catalogDashboardMountPaths
|
|
1191
|
+
catalogDashboardMountPaths,
|
|
1192
|
+
readSessionFromRequest as readCatalogConsoleSession
|
|
1182
1193
|
};
|
|
1183
1194
|
//# sourceMappingURL=index.js.map
|