@dudousxd/nestjs-catalog-dashboard 0.3.3 → 0.4.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 +128 -118
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.js +122 -112
- package/dist/server/index.js.map +1 -1
- package/dist/spa/assets/{index-CK21cSYi.js → index-CaOjuXIq.js} +76 -76
- package/dist/spa/assets/index-CkTR3G5F.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.cjs
CHANGED
|
@@ -980,8 +980,11 @@ CatalogAuthController = _ts_decorate4([
|
|
|
980
980
|
], CatalogAuthController);
|
|
981
981
|
|
|
982
982
|
// src/server/catalog-dashboard.module.ts
|
|
983
|
-
var
|
|
983
|
+
var import_common6 = require("@nestjs/common");
|
|
984
984
|
var import_core = require("@nestjs/core");
|
|
985
|
+
|
|
986
|
+
// src/server/catalog-session.guard.ts
|
|
987
|
+
var import_common5 = require("@nestjs/common");
|
|
985
988
|
function _ts_decorate5(decorators, target, key, desc) {
|
|
986
989
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
987
990
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -989,6 +992,117 @@ function _ts_decorate5(decorators, target, key, desc) {
|
|
|
989
992
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
990
993
|
}
|
|
991
994
|
__name(_ts_decorate5, "_ts_decorate");
|
|
995
|
+
function _ts_metadata4(k, v) {
|
|
996
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
997
|
+
}
|
|
998
|
+
__name(_ts_metadata4, "_ts_metadata");
|
|
999
|
+
function _ts_param4(paramIndex, decorator) {
|
|
1000
|
+
return function(target, key) {
|
|
1001
|
+
decorator(target, key, paramIndex);
|
|
1002
|
+
};
|
|
1003
|
+
}
|
|
1004
|
+
__name(_ts_param4, "_ts_param");
|
|
1005
|
+
var CatalogUiSessionGuard = class {
|
|
1006
|
+
static {
|
|
1007
|
+
__name(this, "CatalogUiSessionGuard");
|
|
1008
|
+
}
|
|
1009
|
+
auth;
|
|
1010
|
+
basePath;
|
|
1011
|
+
constructor(auth, basePath) {
|
|
1012
|
+
this.auth = auth;
|
|
1013
|
+
this.basePath = basePath;
|
|
1014
|
+
}
|
|
1015
|
+
async canActivate(context) {
|
|
1016
|
+
if (!this.auth) return true;
|
|
1017
|
+
const auth = this.auth;
|
|
1018
|
+
const http = context.switchToHttp();
|
|
1019
|
+
const request = http.getRequest();
|
|
1020
|
+
const session = readSessionFromRequest(auth, request);
|
|
1021
|
+
if (!session) {
|
|
1022
|
+
this.denyUnauthenticated(auth, request);
|
|
1023
|
+
}
|
|
1024
|
+
if (!await maybeRenewSession(auth, session, request, http.getResponse())) {
|
|
1025
|
+
this.denyUnauthenticated(auth, request);
|
|
1026
|
+
}
|
|
1027
|
+
return true;
|
|
1028
|
+
}
|
|
1029
|
+
/**
|
|
1030
|
+
* A revoked session (the host's `revalidate` hook says no) is denied exactly like an absent
|
|
1031
|
+
* one — by design, there is nothing left to distinguish "never had a session" from "had one,
|
|
1032
|
+
* then lost it" once the cookie is cleared, so both get the same Mode-aware treatment.
|
|
1033
|
+
*
|
|
1034
|
+
* Takes `auth` explicitly rather than reading `this.auth`: `canActivate`'s `!this.auth` early
|
|
1035
|
+
* return narrows the field within that method only — TS doesn't carry it across a method call
|
|
1036
|
+
* — so callers pass the already-narrowed value instead of this method re-deriving (or
|
|
1037
|
+
* asserting away) the nullability.
|
|
1038
|
+
*/
|
|
1039
|
+
denyUnauthenticated(auth, request) {
|
|
1040
|
+
if (!auth.modes.includes("login")) throw new DashboardSessionRequiredException(this.basePath);
|
|
1041
|
+
const returnTo = encodeURIComponent(originalRequestUrl(request));
|
|
1042
|
+
throw new DashboardLoginRedirectException(`${this.basePath}/login?returnTo=${returnTo}`);
|
|
1043
|
+
}
|
|
1044
|
+
};
|
|
1045
|
+
CatalogUiSessionGuard = _ts_decorate5([
|
|
1046
|
+
(0, import_common5.Injectable)(),
|
|
1047
|
+
_ts_param4(0, (0, import_common5.Inject)(DASHBOARD_AUTH)),
|
|
1048
|
+
_ts_param4(1, (0, import_common5.Inject)(DASHBOARD_BASE_PATH)),
|
|
1049
|
+
_ts_metadata4("design:type", Function),
|
|
1050
|
+
_ts_metadata4("design:paramtypes", [
|
|
1051
|
+
Object,
|
|
1052
|
+
String
|
|
1053
|
+
])
|
|
1054
|
+
], CatalogUiSessionGuard);
|
|
1055
|
+
var CatalogApiSessionGuard = class {
|
|
1056
|
+
static {
|
|
1057
|
+
__name(this, "CatalogApiSessionGuard");
|
|
1058
|
+
}
|
|
1059
|
+
auth;
|
|
1060
|
+
constructor(auth) {
|
|
1061
|
+
this.auth = auth;
|
|
1062
|
+
}
|
|
1063
|
+
async canActivate(context) {
|
|
1064
|
+
if (!this.auth) return true;
|
|
1065
|
+
const auth = this.auth;
|
|
1066
|
+
const http = context.switchToHttp();
|
|
1067
|
+
const request = http.getRequest();
|
|
1068
|
+
const session = readSessionFromRequest(auth, request);
|
|
1069
|
+
if (!session) throw this.unauthorized(auth);
|
|
1070
|
+
if (!await maybeRenewSession(auth, session, request, http.getResponse())) {
|
|
1071
|
+
throw this.unauthorized(auth);
|
|
1072
|
+
}
|
|
1073
|
+
return true;
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* A bare 401 body carrying `{ auth: { modes } }` — mirrors `@dudousxd/nestjs-telescope`'s
|
|
1077
|
+
* dashboardAuth 401. The API is fetched (never navigated), so this is the ONLY way the console
|
|
1078
|
+
* SPA (`catalog-client.ts`) learns which auth surface to send the operator to on a mid-session
|
|
1079
|
+
* 401; `CatalogUiSessionGuard`'s redirect/session-required exceptions above don't reach it.
|
|
1080
|
+
*/
|
|
1081
|
+
unauthorized(auth) {
|
|
1082
|
+
return new import_common5.UnauthorizedException({
|
|
1083
|
+
auth: {
|
|
1084
|
+
modes: auth.modes
|
|
1085
|
+
}
|
|
1086
|
+
});
|
|
1087
|
+
}
|
|
1088
|
+
};
|
|
1089
|
+
CatalogApiSessionGuard = _ts_decorate5([
|
|
1090
|
+
(0, import_common5.Injectable)(),
|
|
1091
|
+
_ts_param4(0, (0, import_common5.Inject)(DASHBOARD_AUTH)),
|
|
1092
|
+
_ts_metadata4("design:type", Function),
|
|
1093
|
+
_ts_metadata4("design:paramtypes", [
|
|
1094
|
+
Object
|
|
1095
|
+
])
|
|
1096
|
+
], CatalogApiSessionGuard);
|
|
1097
|
+
|
|
1098
|
+
// src/server/catalog-dashboard.module.ts
|
|
1099
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
1100
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1101
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1102
|
+
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;
|
|
1103
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1104
|
+
}
|
|
1105
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
992
1106
|
var CatalogDashboardModule = class {
|
|
993
1107
|
static {
|
|
994
1108
|
__name(this, "CatalogDashboardModule");
|
|
@@ -1028,15 +1142,20 @@ var CatalogDashboardModule = class {
|
|
|
1028
1142
|
};
|
|
1029
1143
|
}
|
|
1030
1144
|
};
|
|
1031
|
-
CatalogDashboardModule =
|
|
1032
|
-
(0,
|
|
1145
|
+
CatalogDashboardModule = _ts_decorate6([
|
|
1146
|
+
(0, import_common6.Module)({})
|
|
1033
1147
|
], CatalogDashboardModule);
|
|
1148
|
+
var sessionGuardStamped = false;
|
|
1034
1149
|
function build(options, auth) {
|
|
1035
1150
|
const path = normalise(options.path ?? "/catalog");
|
|
1036
1151
|
const apiPath = normalise(options.apiPath ?? "/api/catalog-service");
|
|
1152
|
+
if (!sessionGuardStamped) {
|
|
1153
|
+
(0, import_common6.UseGuards)(CatalogUiSessionGuard)(CatalogUiController);
|
|
1154
|
+
sessionGuardStamped = true;
|
|
1155
|
+
}
|
|
1037
1156
|
for (const guard of options.guards ?? []) {
|
|
1038
|
-
(0,
|
|
1039
|
-
(0,
|
|
1157
|
+
(0, import_common6.UseGuards)(guard)(CatalogUiController);
|
|
1158
|
+
(0, import_common6.UseGuards)(guard)(CatalogAuthController);
|
|
1040
1159
|
}
|
|
1041
1160
|
const providers = [
|
|
1042
1161
|
{
|
|
@@ -1047,7 +1166,10 @@ function build(options, auth) {
|
|
|
1047
1166
|
provide: DASHBOARD_API_PATH,
|
|
1048
1167
|
useValue: apiPath
|
|
1049
1168
|
},
|
|
1050
|
-
auth
|
|
1169
|
+
auth,
|
|
1170
|
+
// Constructed by Nest, so it must be declared here — a guard stamped by
|
|
1171
|
+
// `UseGuards` is still resolved from the declaring module's injector.
|
|
1172
|
+
CatalogUiSessionGuard
|
|
1051
1173
|
];
|
|
1052
1174
|
return {
|
|
1053
1175
|
module: CatalogDashboardModule,
|
|
@@ -1090,118 +1212,6 @@ function normalise(path) {
|
|
|
1090
1212
|
return withLeading.length > 1 ? withLeading.replace(/\/+$/, "") : withLeading;
|
|
1091
1213
|
}
|
|
1092
1214
|
__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
1215
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1206
1216
|
0 && (module.exports = {
|
|
1207
1217
|
CatalogApiSessionGuard,
|