@dudousxd/nestjs-catalog-dashboard 0.3.0 → 0.3.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Davide Carvalho
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # @dudousxd/nestjs-catalog-dashboard
2
+
3
+ The console for [`@dudousxd/nestjs-catalog`](https://www.npmjs.com/package/@dudousxd/nestjs-catalog):
4
+ Model, Objects, Query, Dashboards, Connectors, Workflows, Lineage, Activity, Access.
5
+
6
+ The screens come from [`@dudousxd/nestjs-catalog-react`](https://www.npmjs.com/package/@dudousxd/nestjs-catalog-react).
7
+ This package is the part a component library cannot do for itself: mounting them, serving their
8
+ assets, and guarding the way in.
9
+
10
+ ```bash
11
+ pnpm add @dudousxd/nestjs-catalog-dashboard
12
+ ```
13
+
14
+ ## Mount it
15
+
16
+ ```ts
17
+ import { CatalogDashboardModule } from '@dudousxd/nestjs-catalog-dashboard';
18
+
19
+ CatalogDashboardModule.forRoot({
20
+ path: '/catalog', // where the console is served
21
+ apiPath: '/api/catalog-service', // where its API already lives
22
+ auth: { secret, session, revalidate },
23
+ });
24
+ ```
25
+
26
+ `forRootAsync` is the same mount with the auth built from DI, for when validating a session means
27
+ asking a user store or a session service.
28
+
29
+ **It does not proxy the API.** `apiPath` only tells the SPA where to call — the catalog's HTTP
30
+ surface is mounted by `CatalogModule` and `CatalogPipelineModule`, and a second copy behind this
31
+ console would be a second set of routes to keep authorised.
32
+
33
+ ## Two things a host must get right
34
+
35
+ **Exclude the console from a global API prefix.** A host calling `setGlobalPrefix('api')` otherwise
36
+ moves it to `/api/catalog` while the SPA still asks for `/catalog/assets/…`, and it loads as a blank
37
+ page with 404s — which reads as a broken build rather than a routing mistake.
38
+
39
+ ```ts
40
+ setGlobalPrefix('api', {
41
+ exclude: [...catalogDashboardMountPaths({ path: '/catalog' })],
42
+ });
43
+ ```
44
+
45
+ The helper derives its paths from the same defaulting `forRoot` mounts with, so the two cannot drift.
46
+
47
+ **Decide whether it is open.** Omit `auth` and the console is open — and it can rewrite a catalog's
48
+ model and run its connectors. A host that would rather be shut than open passes a denying `guards`
49
+ entry, which needs no secret, no DI and no session:
50
+
51
+ ```ts
52
+ guards: process.env.CONSOLE_SECRET ? [] : [DenyEverythingGuard],
53
+ ```
54
+
55
+ `auth` and `guards` are separate for exactly this: `auth` describes how a session is *validated*, so
56
+ a host that has not configured it yet has an open console. `guards` is what makes "unconfigured" mean
57
+ shut.
58
+
59
+ ## Opening it from your own UI
60
+
61
+ Minting the session is this library's business, so it ships the call rather than documenting an
62
+ endpoint. Three levels:
63
+
64
+ ```ts
65
+ import { openCatalogConsole } from '@dudousxd/nestjs-catalog-dashboard/client';
66
+ import {
67
+ useOpenCatalogConsole,
68
+ OpenCatalogConsoleButton,
69
+ } from '@dudousxd/nestjs-catalog-dashboard/react';
70
+ ```
71
+
72
+ - `openCatalogConsole(...)` — no React, you own everything
73
+ - `useOpenCatalogConsole(...)` — state for a launcher, you own the markup
74
+ - `<OpenCatalogConsoleButton />` — drop-in, unstyled
75
+
76
+ `openCatalogConsoleMutationOptions` wires the same call into TanStack Query without this package
77
+ depending on TanStack. React is an optional peer: a host that only mounts the NestJS module never
78
+ pulls it in.
79
+
80
+ When the host authenticates, the SPA skips its own sign-in entirely — a console embedded in an
81
+ application that already knows who you are has no business asking again.
@@ -36,6 +36,7 @@ module.exports = __toCommonJS(index_exports);
36
36
 
37
37
  // src/server/auth/dashboard-auth-config.ts
38
38
  var DASHBOARD_AUTH = Symbol("DASHBOARD_AUTH");
39
+ var DEFAULT_TTL = "8h";
39
40
  var DEFAULT_TTL_MS = 8 * 60 * 60 * 1e3;
40
41
  var DURATION_UNITS = {
41
42
  s: 1e3,
@@ -43,6 +44,60 @@ var DURATION_UNITS = {
43
44
  h: 60 * 60 * 1e3,
44
45
  d: 24 * 60 * 60 * 1e3
45
46
  };
47
+ function durationToMs(ttl) {
48
+ const match = /^(\d+)([smhd])$/.exec(ttl.trim());
49
+ if (!match) return DEFAULT_TTL_MS;
50
+ const unit = DURATION_UNITS[match[2] ?? ""];
51
+ if (unit === void 0) return DEFAULT_TTL_MS;
52
+ return Number(match[1]) * unit;
53
+ }
54
+ __name(durationToMs, "durationToMs");
55
+ function resolveDashboardAuth(options) {
56
+ if (options === void 0) return null;
57
+ if (typeof options.secret !== "string" || options.secret === "") {
58
+ throw new Error("CatalogDashboardModule: dashboardAuth.secret is required and must be a non-empty string (HMAC-SHA256 signing key, 32+ bytes recommended). Failing closed.");
59
+ }
60
+ const modes = [];
61
+ if (options.session !== void 0) {
62
+ if (typeof options.session !== "function") {
63
+ throw new Error("CatalogDashboardModule: dashboardAuth.session must be a function.");
64
+ }
65
+ modes.push("session");
66
+ }
67
+ if (options.login !== void 0) {
68
+ if (typeof options.login !== "function") {
69
+ throw new Error("CatalogDashboardModule: dashboardAuth.login must be a function.");
70
+ }
71
+ modes.push("login");
72
+ }
73
+ if (options.revalidate !== void 0 && typeof options.revalidate !== "function") {
74
+ throw new Error("CatalogDashboardModule: dashboardAuth.revalidate must be a function.");
75
+ }
76
+ if (options.unauthenticatedPage !== void 0 && typeof options.unauthenticatedPage !== "function") {
77
+ throw new Error("CatalogDashboardModule: dashboardAuth.unauthenticatedPage must be a function.");
78
+ }
79
+ if (modes.length === 0) {
80
+ throw new Error("CatalogDashboardModule: dashboardAuth needs at least one of `session` or `login` (otherwise the cookie can never be minted). Failing closed.");
81
+ }
82
+ return {
83
+ secret: options.secret,
84
+ ttlMs: durationToMs(options.ttl ?? DEFAULT_TTL),
85
+ modes,
86
+ ...options.session !== void 0 ? {
87
+ session: options.session
88
+ } : {},
89
+ ...options.login !== void 0 ? {
90
+ login: options.login
91
+ } : {},
92
+ ...options.revalidate !== void 0 ? {
93
+ revalidate: options.revalidate
94
+ } : {},
95
+ ...options.unauthenticatedPage !== void 0 ? {
96
+ unauthenticatedPage: options.unauthenticatedPage
97
+ } : {}
98
+ };
99
+ }
100
+ __name(resolveDashboardAuth, "resolveDashboardAuth");
46
101
 
47
102
  // src/server/catalog-auth.controller.ts
48
103
  var import_common4 = require("@nestjs/common");
@@ -941,7 +996,7 @@ var CatalogDashboardModule = class {
941
996
  static forRoot(options = {}) {
942
997
  return build(options, {
943
998
  provide: DASHBOARD_AUTH,
944
- useValue: options.auth ?? null
999
+ useValue: options.auth ? resolveDashboardAuth(options.auth) : null
945
1000
  });
946
1001
  }
947
1002
  /**
@@ -953,9 +1008,15 @@ var CatalogDashboardModule = class {
953
1008
  * which is why `guards` stays a static option on both forms.
954
1009
  */
955
1010
  static forRootAsync(options) {
1011
+ const factory = options.useDashboardAuth;
956
1012
  const mounted = build(options, {
957
1013
  provide: DASHBOARD_AUTH,
958
- useFactory: options.useDashboardAuth,
1014
+ // Same resolution as `forRoot`, wrapped around the host's factory so the
1015
+ // async path cannot skip it.
1016
+ useFactory: /* @__PURE__ */ __name(async (...args) => {
1017
+ const auth = await factory(...args);
1018
+ return auth ? resolveDashboardAuth(auth) : null;
1019
+ }, "useFactory"),
959
1020
  inject: options.inject ?? []
960
1021
  });
961
1022
  return {