@dudousxd/nestjs-durable-dashboard 0.37.1 → 0.38.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.
@@ -593,6 +593,9 @@ function resolveDashboardAuth(options) {
593
593
  if (options.revalidate !== void 0 && typeof options.revalidate !== "function") {
594
594
  throw new Error("DurableDashboardModule: dashboardAuth.revalidate must be a function.");
595
595
  }
596
+ if (options.unauthenticatedPage !== void 0 && typeof options.unauthenticatedPage !== "function") {
597
+ throw new Error("DurableDashboardModule: dashboardAuth.unauthenticatedPage must be a function.");
598
+ }
596
599
  if (modes.length === 0) {
597
600
  throw new Error("DurableDashboardModule: dashboardAuth needs at least one of `session` or `login` (otherwise the cookie can never be minted). Failing closed.");
598
601
  }
@@ -608,6 +611,9 @@ function resolveDashboardAuth(options) {
608
611
  } : {},
609
612
  ...options.revalidate !== void 0 ? {
610
613
  revalidate: options.revalidate
614
+ } : {},
615
+ ...options.unauthenticatedPage !== void 0 ? {
616
+ unauthenticatedPage: options.unauthenticatedPage
611
617
  } : {}
612
618
  };
613
619
  }
@@ -884,6 +890,11 @@ function redirectRaw(response, location, status = 302) {
884
890
  raw.end();
885
891
  }
886
892
  __name(redirectRaw, "redirectRaw");
893
+ function responseAlreadyWritten(response) {
894
+ const raw = resolveRedirectResponse(response);
895
+ return raw?.headersSent === true;
896
+ }
897
+ __name(responseAlreadyWritten, "responseAlreadyWritten");
887
898
  function writeHtmlRaw(response, html, status = 200) {
888
899
  const raw = resolveRedirectResponse(response);
889
900
  if (!raw) return;
@@ -1137,6 +1148,16 @@ function _ts_decorate4(decorators, target, key, desc) {
1137
1148
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1138
1149
  }
1139
1150
  __name(_ts_decorate4, "_ts_decorate");
1151
+ function _ts_metadata3(k, v) {
1152
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1153
+ }
1154
+ __name(_ts_metadata3, "_ts_metadata");
1155
+ function _ts_param3(paramIndex, decorator) {
1156
+ return function(target, key) {
1157
+ decorator(target, key, paramIndex);
1158
+ };
1159
+ }
1160
+ __name(_ts_param3, "_ts_param");
1140
1161
  var DashboardSessionRequiredException = class extends import_common4.HttpException {
1141
1162
  static {
1142
1163
  __name(this, "DashboardSessionRequiredException");
@@ -1148,17 +1169,51 @@ var DashboardSessionRequiredException = class extends import_common4.HttpExcepti
1148
1169
  }, import_common4.HttpStatus.UNAUTHORIZED), this.basePath = basePath;
1149
1170
  }
1150
1171
  };
1151
- var DashboardSessionRequiredFilter = class {
1172
+ var DashboardSessionRequiredFilter = class _DashboardSessionRequiredFilter {
1152
1173
  static {
1153
1174
  __name(this, "DashboardSessionRequiredFilter");
1154
1175
  }
1155
- catch(exception, host) {
1156
- const response = host.switchToHttp().getResponse();
1176
+ auth;
1177
+ logger = new import_common4.Logger(_DashboardSessionRequiredFilter.name);
1178
+ warned = false;
1179
+ constructor(auth = null) {
1180
+ this.auth = auth;
1181
+ }
1182
+ async catch(exception, host) {
1183
+ const http = host.switchToHttp();
1184
+ const response = http.getResponse();
1185
+ const hook = this.auth?.unauthenticatedPage;
1186
+ if (hook) {
1187
+ try {
1188
+ await hook({
1189
+ request: http.getRequest(),
1190
+ response,
1191
+ basePath: exception.basePath
1192
+ });
1193
+ if (responseAlreadyWritten(response)) return;
1194
+ this.warnOnce("dashboardAuth.unauthenticatedPage returned without writing a response; falling back to the built-in page. The hook must write AND end the response it is given.");
1195
+ } catch (error) {
1196
+ this.warnOnce(`dashboardAuth.unauthenticatedPage threw; falling back to the built-in page. ${String(error)}`);
1197
+ if (responseAlreadyWritten(response)) return;
1198
+ }
1199
+ }
1157
1200
  writeHtmlRaw(response, renderSessionRequiredPage(exception.basePath), import_common4.HttpStatus.UNAUTHORIZED);
1158
1201
  }
1202
+ /** Once per process, not once per request: a broken hook fires on every denied navigation. */
1203
+ warnOnce(message) {
1204
+ if (this.warned) return;
1205
+ this.warned = true;
1206
+ this.logger.warn(message);
1207
+ }
1159
1208
  };
1160
1209
  DashboardSessionRequiredFilter = _ts_decorate4([
1161
- (0, import_common4.Catch)(DashboardSessionRequiredException)
1210
+ (0, import_common4.Catch)(DashboardSessionRequiredException),
1211
+ _ts_param3(0, (0, import_common4.Optional)()),
1212
+ _ts_param3(0, (0, import_common4.Inject)(DASHBOARD_AUTH)),
1213
+ _ts_metadata3("design:type", Function),
1214
+ _ts_metadata3("design:paramtypes", [
1215
+ Object
1216
+ ])
1162
1217
  ], DashboardSessionRequiredFilter);
1163
1218
 
1164
1219
  // src/server/durable-ui.controller.ts
@@ -1169,16 +1224,16 @@ function _ts_decorate5(decorators, target, key, desc) {
1169
1224
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1170
1225
  }
1171
1226
  __name(_ts_decorate5, "_ts_decorate");
1172
- function _ts_metadata3(k, v) {
1227
+ function _ts_metadata4(k, v) {
1173
1228
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1174
1229
  }
1175
- __name(_ts_metadata3, "_ts_metadata");
1176
- function _ts_param3(paramIndex, decorator) {
1230
+ __name(_ts_metadata4, "_ts_metadata");
1231
+ function _ts_param4(paramIndex, decorator) {
1177
1232
  return function(target, key) {
1178
1233
  decorator(target, key, paramIndex);
1179
1234
  };
1180
1235
  }
1181
- __name(_ts_param3, "_ts_param");
1236
+ __name(_ts_param4, "_ts_param");
1182
1237
  var DASHBOARD_BASE_PATH = Symbol("DASHBOARD_BASE_PATH");
1183
1238
  var DASHBOARD_API_PATH = Symbol("DASHBOARD_API_PATH");
1184
1239
  var BUILD_BASE = "/durable";
@@ -1235,27 +1290,27 @@ _ts_decorate5([
1235
1290
  (0, import_common5.Get)(),
1236
1291
  (0, import_common5.Header)("Content-Type", "text/html; charset=utf-8"),
1237
1292
  (0, import_common5.Header)("Cache-Control", "no-store, must-revalidate"),
1238
- _ts_metadata3("design:type", Function),
1239
- _ts_metadata3("design:paramtypes", []),
1240
- _ts_metadata3("design:returntype", String)
1293
+ _ts_metadata4("design:type", Function),
1294
+ _ts_metadata4("design:paramtypes", []),
1295
+ _ts_metadata4("design:returntype", String)
1241
1296
  ], DurableUiController.prototype, "index", null);
1242
1297
  _ts_decorate5([
1243
1298
  (0, import_common5.Get)("assets/:file"),
1244
1299
  (0, import_common5.Header)("Cache-Control", "public, max-age=31536000, immutable"),
1245
- _ts_param3(0, (0, import_common5.Param)("file")),
1246
- _ts_metadata3("design:type", Function),
1247
- _ts_metadata3("design:paramtypes", [
1300
+ _ts_param4(0, (0, import_common5.Param)("file")),
1301
+ _ts_metadata4("design:type", Function),
1302
+ _ts_metadata4("design:paramtypes", [
1248
1303
  String
1249
1304
  ]),
1250
- _ts_metadata3("design:returntype", typeof import_common5.StreamableFile === "undefined" ? Object : import_common5.StreamableFile)
1305
+ _ts_metadata4("design:returntype", typeof import_common5.StreamableFile === "undefined" ? Object : import_common5.StreamableFile)
1251
1306
  ], DurableUiController.prototype, "asset", null);
1252
1307
  DurableUiController = _ts_decorate5([
1253
1308
  (0, import_common5.UseFilters)(DashboardLoginRedirectFilter, DashboardSessionRequiredFilter),
1254
1309
  (0, import_common5.Controller)(),
1255
- _ts_param3(0, (0, import_common5.Inject)(DASHBOARD_BASE_PATH)),
1256
- _ts_param3(1, (0, import_common5.Inject)(DASHBOARD_API_PATH)),
1257
- _ts_metadata3("design:type", Function),
1258
- _ts_metadata3("design:paramtypes", [
1310
+ _ts_param4(0, (0, import_common5.Inject)(DASHBOARD_BASE_PATH)),
1311
+ _ts_param4(1, (0, import_common5.Inject)(DASHBOARD_API_PATH)),
1312
+ _ts_metadata4("design:type", Function),
1313
+ _ts_metadata4("design:paramtypes", [
1259
1314
  String,
1260
1315
  String
1261
1316
  ])
@@ -1269,16 +1324,16 @@ function _ts_decorate6(decorators, target, key, desc) {
1269
1324
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1270
1325
  }
1271
1326
  __name(_ts_decorate6, "_ts_decorate");
1272
- function _ts_metadata4(k, v) {
1327
+ function _ts_metadata5(k, v) {
1273
1328
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1274
1329
  }
1275
- __name(_ts_metadata4, "_ts_metadata");
1276
- function _ts_param4(paramIndex, decorator) {
1330
+ __name(_ts_metadata5, "_ts_metadata");
1331
+ function _ts_param5(paramIndex, decorator) {
1277
1332
  return function(target, key) {
1278
1333
  decorator(target, key, paramIndex);
1279
1334
  };
1280
1335
  }
1281
- __name(_ts_param4, "_ts_param");
1336
+ __name(_ts_param5, "_ts_param");
1282
1337
  function isString(value) {
1283
1338
  return typeof value === "string";
1284
1339
  }
@@ -1378,58 +1433,58 @@ _ts_decorate6([
1378
1433
  (0, import_common6.Get)("login"),
1379
1434
  (0, import_common6.Header)("Content-Type", "text/html; charset=utf-8"),
1380
1435
  (0, import_common6.Header)("Cache-Control", "no-store, must-revalidate"),
1381
- _ts_metadata4("design:type", Function),
1382
- _ts_metadata4("design:paramtypes", []),
1383
- _ts_metadata4("design:returntype", String)
1436
+ _ts_metadata5("design:type", Function),
1437
+ _ts_metadata5("design:paramtypes", []),
1438
+ _ts_metadata5("design:returntype", String)
1384
1439
  ], DurableAuthController.prototype, "loginPage", null);
1385
1440
  _ts_decorate6([
1386
1441
  (0, import_common6.Post)("login"),
1387
1442
  (0, import_common6.HttpCode)(200),
1388
- _ts_param4(0, (0, import_common6.Body)()),
1389
- _ts_param4(1, (0, import_common6.Req)()),
1390
- _ts_param4(2, (0, import_common6.Res)({
1443
+ _ts_param5(0, (0, import_common6.Body)()),
1444
+ _ts_param5(1, (0, import_common6.Req)()),
1445
+ _ts_param5(2, (0, import_common6.Res)({
1391
1446
  passthrough: true
1392
1447
  })),
1393
- _ts_metadata4("design:type", Function),
1394
- _ts_metadata4("design:paramtypes", [
1448
+ _ts_metadata5("design:type", Function),
1449
+ _ts_metadata5("design:paramtypes", [
1395
1450
  typeof LoginBody === "undefined" ? Object : LoginBody,
1396
1451
  Object,
1397
1452
  Object
1398
1453
  ]),
1399
- _ts_metadata4("design:returntype", Promise)
1454
+ _ts_metadata5("design:returntype", Promise)
1400
1455
  ], DurableAuthController.prototype, "login", null);
1401
1456
  _ts_decorate6([
1402
1457
  (0, import_common6.Post)("session"),
1403
1458
  (0, import_common6.HttpCode)(204),
1404
- _ts_param4(0, (0, import_common6.Req)()),
1405
- _ts_param4(1, (0, import_common6.Res)({
1459
+ _ts_param5(0, (0, import_common6.Req)()),
1460
+ _ts_param5(1, (0, import_common6.Res)({
1406
1461
  passthrough: true
1407
1462
  })),
1408
- _ts_metadata4("design:type", Function),
1409
- _ts_metadata4("design:paramtypes", [
1463
+ _ts_metadata5("design:type", Function),
1464
+ _ts_metadata5("design:paramtypes", [
1410
1465
  Object,
1411
1466
  Object
1412
1467
  ]),
1413
- _ts_metadata4("design:returntype", Promise)
1468
+ _ts_metadata5("design:returntype", Promise)
1414
1469
  ], DurableAuthController.prototype, "session", null);
1415
1470
  _ts_decorate6([
1416
1471
  (0, import_common6.Get)("logout"),
1417
- _ts_param4(0, (0, import_common6.Req)()),
1418
- _ts_param4(1, (0, import_common6.Res)()),
1419
- _ts_metadata4("design:type", Function),
1420
- _ts_metadata4("design:paramtypes", [
1472
+ _ts_param5(0, (0, import_common6.Req)()),
1473
+ _ts_param5(1, (0, import_common6.Res)()),
1474
+ _ts_metadata5("design:type", Function),
1475
+ _ts_metadata5("design:paramtypes", [
1421
1476
  Object,
1422
1477
  Object
1423
1478
  ]),
1424
- _ts_metadata4("design:returntype", void 0)
1479
+ _ts_metadata5("design:returntype", void 0)
1425
1480
  ], DurableAuthController.prototype, "logout", null);
1426
1481
  DurableAuthController = _ts_decorate6([
1427
1482
  (0, import_common6.Controller)(),
1428
- _ts_param4(0, (0, import_common6.Optional)()),
1429
- _ts_param4(0, (0, import_common6.Inject)(DASHBOARD_AUTH)),
1430
- _ts_param4(1, (0, import_common6.Inject)(DASHBOARD_BASE_PATH)),
1431
- _ts_metadata4("design:type", Function),
1432
- _ts_metadata4("design:paramtypes", [
1483
+ _ts_param5(0, (0, import_common6.Optional)()),
1484
+ _ts_param5(0, (0, import_common6.Inject)(DASHBOARD_AUTH)),
1485
+ _ts_param5(1, (0, import_common6.Inject)(DASHBOARD_BASE_PATH)),
1486
+ _ts_metadata5("design:type", Function),
1487
+ _ts_metadata5("design:paramtypes", [
1433
1488
  Object,
1434
1489
  String
1435
1490
  ])
@@ -1449,16 +1504,16 @@ function _ts_decorate7(decorators, target, key, desc) {
1449
1504
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1450
1505
  }
1451
1506
  __name(_ts_decorate7, "_ts_decorate");
1452
- function _ts_metadata5(k, v) {
1507
+ function _ts_metadata6(k, v) {
1453
1508
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1454
1509
  }
1455
- __name(_ts_metadata5, "_ts_metadata");
1456
- function _ts_param5(paramIndex, decorator) {
1510
+ __name(_ts_metadata6, "_ts_metadata");
1511
+ function _ts_param6(paramIndex, decorator) {
1457
1512
  return function(target, key) {
1458
1513
  decorator(target, key, paramIndex);
1459
1514
  };
1460
1515
  }
1461
- __name(_ts_param5, "_ts_param");
1516
+ __name(_ts_param6, "_ts_param");
1462
1517
  var DurableUiSessionGuard = class {
1463
1518
  static {
1464
1519
  __name(this, "DurableUiSessionGuard");
@@ -1501,10 +1556,10 @@ var DurableUiSessionGuard = class {
1501
1556
  };
1502
1557
  DurableUiSessionGuard = _ts_decorate7([
1503
1558
  (0, import_common7.Injectable)(),
1504
- _ts_param5(0, (0, import_common7.Inject)(DASHBOARD_AUTH)),
1505
- _ts_param5(1, (0, import_common7.Inject)(DASHBOARD_BASE_PATH)),
1506
- _ts_metadata5("design:type", Function),
1507
- _ts_metadata5("design:paramtypes", [
1559
+ _ts_param6(0, (0, import_common7.Inject)(DASHBOARD_AUTH)),
1560
+ _ts_param6(1, (0, import_common7.Inject)(DASHBOARD_BASE_PATH)),
1561
+ _ts_metadata6("design:type", Function),
1562
+ _ts_metadata6("design:paramtypes", [
1508
1563
  Object,
1509
1564
  String
1510
1565
  ])
@@ -1545,9 +1600,9 @@ var DurableApiSessionGuard = class {
1545
1600
  };
1546
1601
  DurableApiSessionGuard = _ts_decorate7([
1547
1602
  (0, import_common7.Injectable)(),
1548
- _ts_param5(0, (0, import_common7.Inject)(DASHBOARD_AUTH)),
1549
- _ts_metadata5("design:type", Function),
1550
- _ts_metadata5("design:paramtypes", [
1603
+ _ts_param6(0, (0, import_common7.Inject)(DASHBOARD_AUTH)),
1604
+ _ts_metadata6("design:type", Function),
1605
+ _ts_metadata6("design:paramtypes", [
1551
1606
  Object
1552
1607
  ])
1553
1608
  ], DurableApiSessionGuard);