@dudousxd/nestjs-catalog-dashboard 0.36.0 → 0.37.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/README.md CHANGED
@@ -80,9 +80,42 @@ pulls it in.
80
80
  When the host authenticates, the SPA skips its own sign-in entirely — a console embedded in an
81
81
  application that already knows who you are has no business asking again.
82
82
 
83
+ ## Showing part of the console
84
+
85
+ Three options shape what the SPA shows and asks for. Each defaults to today's behaviour.
86
+
87
+ ```ts
88
+ CatalogDashboardModule.forRoot({
89
+ path: '/admin/ontology',
90
+ apiPath: '/api/catalog',
91
+ screens: ['model', 'objects'], // only these tabs; the rest get no tab, no panel, no requests
92
+ pipeline: false, // Model leaves out Loaded by and Load expectation
93
+ hostAuthenticates: true, // no sign-in, and no call to /auth/me
94
+ });
95
+ ```
96
+
97
+ - `screens` lists the screens to show: `model`, `objects`, `query`, `dashboards`, `workflows`,
98
+ `connections`, `lineage`, `activity`, `access` and `search` (the `⌘K` screen, which has no tab).
99
+ Default: all of them. An address naming a hidden screen lands on the first one shown. An unknown
100
+ name, or a list with no screen other than `search`, fails at module definition.
101
+ - `pipeline: false` is for a host that does not mount the pipeline endpoints. The Model screen then
102
+ renders neither section and never requests `/pipeline/workflows` or `/pipeline/expectations/:type`.
103
+ - `hostAuthenticates: true` is for a host that authenticates every request itself and serves no
104
+ `/auth/me`. Configuring `auth` already hides the sign-in, but keeps asking `/auth/me` for the
105
+ Access screen.
106
+
107
+ Whatever the options, a host that serves no `/environments` (a 404) is read as one environment, and
108
+ the environment picker is left out instead of failing.
109
+
83
110
  ## How the console is served
84
111
 
85
- `index.html` is rendered once (asset URLs rewritten to `path`, the API base filled in) and kept in
112
+ The page loads nothing from another origin and runs no inline script, so it works under a strict
113
+ Content-Security-Policy (`script-src 'self'`) and in an air-gapped deployment. The values it needs
114
+ (asset base, API base, the options above) come from `<path>/config.js`, a small script the module
115
+ serves and `index.html` loads first in its head. The fonts are named in the stylesheet and fall back
116
+ to the system's; nothing is fetched from Google Fonts.
117
+
118
+ `index.html` is rendered once (asset URLs rewritten to `path`, the `config.js` tag added) and kept in
86
119
  memory. Each request checks the file's mtime and size, and renders it again when they change, so a
87
120
  rebuilt bundle is picked up without a restart. It is always sent `Cache-Control: no-store`. Files
88
121
  under `assets/` are streamed from disk with a `Content-Length`; a path that is not a file is a 404.
@@ -22,6 +22,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
22
22
  // src/server/index.ts
23
23
  var index_exports = {};
24
24
  __export(index_exports, {
25
+ CATALOG_CONSOLE_SCREENS: () => CATALOG_CONSOLE_SCREENS,
25
26
  CatalogApiSessionGuard: () => CatalogApiSessionGuard,
26
27
  CatalogAuthController: () => CatalogAuthController,
27
28
  CatalogDashboardModule: () => CatalogDashboardModule,
@@ -30,8 +31,10 @@ __export(index_exports, {
30
31
  DASHBOARD_API_PATH: () => DASHBOARD_API_PATH,
31
32
  DASHBOARD_AUTH: () => DASHBOARD_AUTH,
32
33
  DASHBOARD_BASE_PATH: () => DASHBOARD_BASE_PATH,
34
+ DASHBOARD_CONSOLE: () => DASHBOARD_CONSOLE,
33
35
  catalogDashboardMountPaths: () => catalogDashboardMountPaths,
34
- readCatalogConsoleSession: () => readSessionFromRequest
36
+ readCatalogConsoleSession: () => readSessionFromRequest,
37
+ resolveConsoleOptions: () => resolveConsoleOptions
35
38
  });
36
39
  module.exports = __toCommonJS(index_exports);
37
40
 
@@ -710,6 +713,37 @@ DashboardSessionRequiredFilter = _ts_decorate2([
710
713
  ])
711
714
  ], DashboardSessionRequiredFilter);
712
715
 
716
+ // src/server/console-options.ts
717
+ var CATALOG_CONSOLE_SCREENS = [
718
+ "model",
719
+ "objects",
720
+ "query",
721
+ "dashboards",
722
+ "workflows",
723
+ "connections",
724
+ "lineage",
725
+ "activity",
726
+ "access",
727
+ "search"
728
+ ];
729
+ function resolveConsoleOptions(options = {}) {
730
+ const screens = options.screens ?? CATALOG_CONSOLE_SCREENS;
731
+ const unknown = screens.filter((screen) => !CATALOG_CONSOLE_SCREENS.includes(screen));
732
+ if (unknown.length > 0) {
733
+ throw new Error(`CatalogDashboardModule: unknown console screen(s) ${unknown.map((s) => `"${s}"`).join(", ")}. Known screens: ${CATALOG_CONSOLE_SCREENS.join(", ")}.`);
734
+ }
735
+ if (!screens.some((screen) => screen !== "search")) {
736
+ throw new Error('CatalogDashboardModule: `screens` must name at least one screen other than "search".');
737
+ }
738
+ return {
739
+ // In the console's own order, whatever order the host listed them in, and once each.
740
+ screens: CATALOG_CONSOLE_SCREENS.filter((screen) => screens.includes(screen)),
741
+ pipeline: options.pipeline !== false,
742
+ hostAuthenticates: options.hostAuthenticates === true
743
+ };
744
+ }
745
+ __name(resolveConsoleOptions, "resolveConsoleOptions");
746
+
713
747
  // src/server/catalog-ui.controller.ts
714
748
  function _ts_decorate3(decorators, target, key, desc) {
715
749
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -739,6 +773,11 @@ function _ts_param2(paramIndex, decorator) {
739
773
  __name(_ts_param2, "_ts_param");
740
774
  var DASHBOARD_BASE_PATH = /* @__PURE__ */ Symbol("DASHBOARD_BASE_PATH");
741
775
  var DASHBOARD_API_PATH = /* @__PURE__ */ Symbol("DASHBOARD_API_PATH");
776
+ var DASHBOARD_CONSOLE = /* @__PURE__ */ Symbol("DASHBOARD_CONSOLE");
777
+ function attribute(value) {
778
+ return value.replaceAll("&", "&amp;").replaceAll('"', "&quot;");
779
+ }
780
+ __name(attribute, "attribute");
742
781
  var BUILD_BASE = "/catalog";
743
782
  function spaDir() {
744
783
  return (0, import_node_url.fileURLToPath)(new URL("../spa", __importMetaUrl));
@@ -760,6 +799,7 @@ var CatalogUiController = class {
760
799
  basePath;
761
800
  apiBasePath;
762
801
  auth;
802
+ console;
763
803
  dir = spaDir();
764
804
  /**
765
805
  * The rewritten index.html, with the file version it was rendered from. A
@@ -767,10 +807,11 @@ var CatalogUiController = class {
767
807
  * renders it again instead of pointing at hashed assets that are gone.
768
808
  */
769
809
  rendered;
770
- constructor(basePath, apiBasePath, auth = null) {
810
+ constructor(basePath, apiBasePath, auth = null, console = resolveConsoleOptions()) {
771
811
  this.basePath = basePath;
772
812
  this.apiBasePath = apiBasePath;
773
813
  this.auth = auth;
814
+ this.console = console;
774
815
  }
775
816
  // index.html references hash-named bundles, so it MUST NOT be cached (stale bundle = the
776
817
  // classic "stuck loading after a deploy"). The hashed assets below are immutable.
@@ -793,10 +834,41 @@ var CatalogUiController = class {
793
834
  return html;
794
835
  }
795
836
  render(source) {
796
- const html = source.replaceAll(`="${BUILD_BASE}/`, `="${this.basePath}/`);
797
- const hostAuth = this.auth ? "true" : "false";
798
- const inject = `<script>window.__CATALOG_BASE__='${this.basePath}';window.__CATALOG_API__='${this.apiBasePath}';window.__CATALOG_HOST_AUTH__=${hostAuth};</script>`;
799
- return html.includes("</head>") ? html.replace("</head>", `${inject}</head>`) : inject + html;
837
+ const base = attribute(this.basePath);
838
+ const html = source.replaceAll(`="${BUILD_BASE}/`, `="${base}/`);
839
+ const inject = `<script src="${base}/config.js"></script>`;
840
+ const head = /<head\b[^>]*>/i.exec(html);
841
+ if (!head) return inject + html;
842
+ const at = head.index + head[0].length;
843
+ return html.slice(0, at) + inject + html.slice(at);
844
+ }
845
+ /**
846
+ * The values the SPA reads at startup.
847
+ *
848
+ * __CATALOG_BASE__ = where assets load; __CATALOG_API__ = where the SPA fetches the JSON API;
849
+ * __CATALOG_HOST_AUTH__ = whether the HOST authenticates, in which case the SPA must not show its
850
+ * own sign-in (a console mounted inside an application that already knows who you are and then
851
+ * asks you to log in again is not a smaller problem than one that lets anybody in);
852
+ * __CATALOG_CONSOLE__ = which screens to show, whether the Model screen reads the pipeline
853
+ * endpoints, and whether the SPA may ask `/auth/me` who is calling.
854
+ *
855
+ * Every value goes through `JSON.stringify`, so a path can never close the string it sits in.
856
+ * Not cached by the browser: it is tiny, and it changes with the module's options.
857
+ */
858
+ config() {
859
+ const hostAuth = Boolean(this.auth) || this.console.hostAuthenticates;
860
+ const consoleConfig = {
861
+ screens: this.console.screens,
862
+ pipeline: this.console.pipeline,
863
+ identity: !this.console.hostAuthenticates
864
+ };
865
+ return [
866
+ `window.__CATALOG_BASE__=${JSON.stringify(this.basePath)};`,
867
+ `window.__CATALOG_API__=${JSON.stringify(this.apiBasePath)};`,
868
+ `window.__CATALOG_HOST_AUTH__=${JSON.stringify(hostAuth)};`,
869
+ `window.__CATALOG_CONSOLE__=${JSON.stringify(consoleConfig)};`,
870
+ ""
871
+ ].join("\n");
800
872
  }
801
873
  asset(file) {
802
874
  const safe = (0, import_node_path.basename)(file);
@@ -823,6 +895,14 @@ _ts_decorate3([
823
895
  _ts_metadata2("design:paramtypes", []),
824
896
  _ts_metadata2("design:returntype", String)
825
897
  ], CatalogUiController.prototype, "index", null);
898
+ _ts_decorate3([
899
+ (0, import_common3.Get)("config.js"),
900
+ (0, import_common3.Header)("Content-Type", "text/javascript; charset=utf-8"),
901
+ (0, import_common3.Header)("Cache-Control", "no-store, must-revalidate"),
902
+ _ts_metadata2("design:type", Function),
903
+ _ts_metadata2("design:paramtypes", []),
904
+ _ts_metadata2("design:returntype", String)
905
+ ], CatalogUiController.prototype, "config", null);
826
906
  _ts_decorate3([
827
907
  (0, import_common3.Get)("assets/:file"),
828
908
  (0, import_common3.Header)("Cache-Control", "public, max-age=31536000, immutable"),
@@ -840,11 +920,14 @@ CatalogUiController = _ts_decorate3([
840
920
  _ts_param2(1, (0, import_common3.Inject)(DASHBOARD_API_PATH)),
841
921
  _ts_param2(2, (0, import_common3.Optional)()),
842
922
  _ts_param2(2, (0, import_common3.Inject)(DASHBOARD_AUTH)),
923
+ _ts_param2(3, (0, import_common3.Optional)()),
924
+ _ts_param2(3, (0, import_common3.Inject)(DASHBOARD_CONSOLE)),
843
925
  _ts_metadata2("design:type", Function),
844
926
  _ts_metadata2("design:paramtypes", [
845
927
  String,
846
928
  String,
847
- Object
929
+ Object,
930
+ typeof ResolvedConsoleOptions === "undefined" ? Object : ResolvedConsoleOptions
848
931
  ])
849
932
  ], CatalogUiController);
850
933
 
@@ -1232,6 +1315,17 @@ var sessionGuardStamped = false;
1232
1315
  function build(options, auth) {
1233
1316
  const path = normalise(options.path ?? "/catalog");
1234
1317
  const apiPath = normalise(options.apiPath ?? "/api/catalog-service");
1318
+ const consoleOptions = resolveConsoleOptions({
1319
+ ...options.screens ? {
1320
+ screens: options.screens
1321
+ } : {},
1322
+ ...options.pipeline !== void 0 ? {
1323
+ pipeline: options.pipeline
1324
+ } : {},
1325
+ ...options.hostAuthenticates !== void 0 ? {
1326
+ hostAuthenticates: options.hostAuthenticates
1327
+ } : {}
1328
+ });
1235
1329
  if (!sessionGuardStamped) {
1236
1330
  (0, import_common6.UseGuards)(CatalogUiSessionGuard)(CatalogUiController);
1237
1331
  sessionGuardStamped = true;
@@ -1249,6 +1343,10 @@ function build(options, auth) {
1249
1343
  provide: DASHBOARD_API_PATH,
1250
1344
  useValue: apiPath
1251
1345
  },
1346
+ {
1347
+ provide: DASHBOARD_CONSOLE,
1348
+ useValue: consoleOptions
1349
+ },
1252
1350
  auth,
1253
1351
  // Constructed by Nest, so it must be declared here — a guard stamped by
1254
1352
  // `UseGuards` is still resolved from the declaring module's injector.
@@ -1311,6 +1409,7 @@ function normalise(path) {
1311
1409
  __name(normalise, "normalise");
1312
1410
  // Annotate the CommonJS export names for ESM import in node:
1313
1411
  0 && (module.exports = {
1412
+ CATALOG_CONSOLE_SCREENS,
1314
1413
  CatalogApiSessionGuard,
1315
1414
  CatalogAuthController,
1316
1415
  CatalogDashboardModule,
@@ -1319,7 +1418,9 @@ __name(normalise, "normalise");
1319
1418
  DASHBOARD_API_PATH,
1320
1419
  DASHBOARD_AUTH,
1321
1420
  DASHBOARD_BASE_PATH,
1421
+ DASHBOARD_CONSOLE,
1322
1422
  catalogDashboardMountPaths,
1323
- readCatalogConsoleSession
1423
+ readCatalogConsoleSession,
1424
+ resolveConsoleOptions
1324
1425
  });
1325
1426
  //# sourceMappingURL=index.cjs.map