@dudousxd/nestjs-media-dashboard 0.6.1 → 0.7.1

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.
@@ -80,6 +80,28 @@ function resolveConsoleAuth(options) {
80
80
  }
81
81
  __name(resolveConsoleAuth, "resolveConsoleAuth");
82
82
 
83
+ // src/server/guards.ts
84
+ var import_reflect_metadata = require("reflect-metadata");
85
+ var GUARDS_METADATA = "__guards__";
86
+ function isGuardClass(guard) {
87
+ return typeof guard === "function";
88
+ }
89
+ __name(isGuardClass, "isGuardClass");
90
+ function baseGuards(controller) {
91
+ return Reflect.getOwnMetadata(GUARDS_METADATA, controller) ?? [];
92
+ }
93
+ __name(baseGuards, "baseGuards");
94
+ function stampGuards(guards, entries) {
95
+ if (guards === void 0 || guards.length === 0) return;
96
+ for (const [controller, base] of entries) {
97
+ Reflect.defineMetadata(GUARDS_METADATA, [
98
+ ...base,
99
+ ...guards
100
+ ], controller);
101
+ }
102
+ }
103
+ __name(stampGuards, "stampGuards");
104
+
83
105
  // src/server/media-console-api.module.ts
84
106
  var import_common6 = require("@nestjs/common");
85
107
 
@@ -1392,11 +1414,23 @@ function _ts_decorate6(decorators, target, key, desc) {
1392
1414
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1393
1415
  }
1394
1416
  __name(_ts_decorate6, "_ts_decorate");
1417
+ var READ_BASE_GUARDS = baseGuards(MediaConsoleReadController);
1418
+ var ACTIONS_BASE_GUARDS = baseGuards(MediaConsoleActionsController);
1395
1419
  var MediaConsoleApiModule = class _MediaConsoleApiModule {
1396
1420
  static {
1397
1421
  __name(this, "MediaConsoleApiModule");
1398
1422
  }
1399
1423
  static register(options) {
1424
+ stampGuards(options.guards, [
1425
+ [
1426
+ MediaConsoleReadController,
1427
+ READ_BASE_GUARDS
1428
+ ],
1429
+ [
1430
+ MediaConsoleActionsController,
1431
+ ACTIONS_BASE_GUARDS
1432
+ ]
1433
+ ]);
1400
1434
  return {
1401
1435
  module: _MediaConsoleApiModule,
1402
1436
  imports: options.imports ?? [],
@@ -1418,7 +1452,11 @@ var MediaConsoleApiModule = class _MediaConsoleApiModule {
1418
1452
  provide: MEDIA_CONSOLE_COOKIE_PATH,
1419
1453
  useValue: options.cookiePath
1420
1454
  },
1421
- options.authProvider
1455
+ options.authProvider,
1456
+ // Class guards need a DI provider so Nest can instantiate them in THIS module's context
1457
+ // (where `imports` above resolves their dependencies). An already-instantiated guard needs
1458
+ // none — it's used as-is.
1459
+ ...(options.guards ?? []).filter(isGuardClass)
1422
1460
  ],
1423
1461
  exports: [
1424
1462
  MediaConsoleService
@@ -1552,7 +1590,7 @@ var MediaDashboardModule = class _MediaDashboardModule {
1552
1590
  return _MediaDashboardModule.build(options, apiBasePath, {
1553
1591
  provide: MEDIA_CONSOLE_AUTH,
1554
1592
  useValue: resolveConsoleAuth(options.auth)
1555
- });
1593
+ }, options.imports);
1556
1594
  }
1557
1595
  static forRootAsync(options) {
1558
1596
  const apiBasePath = normalize(options.apiBasePath ?? `${normalize(options.basePath ?? "/media")}/api`);
@@ -1567,14 +1605,24 @@ var MediaDashboardModule = class _MediaDashboardModule {
1567
1605
  static build(options, apiBasePath, authProvider, imports) {
1568
1606
  const basePath = normalize(options.basePath ?? "/media");
1569
1607
  const actions = options.actions === true;
1608
+ stampGuards(options.guards, [
1609
+ [
1610
+ MediaDashboardUiController,
1611
+ []
1612
+ ]
1613
+ ]);
1570
1614
  return {
1571
1615
  module: _MediaDashboardModule,
1572
1616
  imports: [
1617
+ ...imports ?? [],
1573
1618
  MediaConsoleApiModule.register({
1574
1619
  actions,
1575
1620
  cookiePath: apiBasePath,
1576
1621
  authProvider,
1577
- imports
1622
+ imports,
1623
+ ...options.guards ? {
1624
+ guards: options.guards
1625
+ } : {}
1578
1626
  }),
1579
1627
  import_core.RouterModule.register([
1580
1628
  {
@@ -1598,7 +1646,10 @@ var MediaDashboardModule = class _MediaDashboardModule {
1598
1646
  {
1599
1647
  provide: MEDIA_DASHBOARD_API_PATH,
1600
1648
  useValue: apiBasePath
1601
- }
1649
+ },
1650
+ // MediaDashboardUiController is hosted HERE, so its guards DI-instantiate from this
1651
+ // module — class guards need a provider; an already-instantiated guard needs none.
1652
+ ...(options.guards ?? []).filter(isGuardClass)
1602
1653
  ],
1603
1654
  // Re-export the API module so its MediaConsoleService reaches importers if they want it.
1604
1655
  exports: [