@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.
@@ -172,7 +172,61 @@ declare class CatalogAuthController {
172
172
  private runHook;
173
173
  }
174
174
 
175
- interface CatalogDashboardOptions {
175
+ /**
176
+ * Every screen the console can show. `search` is the one reached by `⌘K` and
177
+ * `#search` rather than by a tab.
178
+ *
179
+ * The client keeps the same list in `src/client/console-config.ts`, because the
180
+ * server and the SPA are separate builds with separate roots;
181
+ * `console-options.spec.ts` fails if the two drift.
182
+ */
183
+ declare const CATALOG_CONSOLE_SCREENS: readonly ["model", "objects", "query", "dashboards", "workflows", "connections", "lineage", "activity", "access", "search"];
184
+ type CatalogConsoleScreen = (typeof CATALOG_CONSOLE_SCREENS)[number];
185
+ /** What a host may say about the console it serves. Every field is optional. */
186
+ interface CatalogConsoleOptions {
187
+ /**
188
+ * The screens to show, and only these. Default: all of them.
189
+ *
190
+ * A hidden screen gets no tab, no panel and no requests, and an address
191
+ * naming it lands on the first screen shown. `'search'` hides the search
192
+ * button, `⌘K` and `#search`. Must name at least one screen other than
193
+ * `'search'`, since search alone has no tab to come back to.
194
+ */
195
+ screens?: readonly CatalogConsoleScreen[];
196
+ /**
197
+ * Whether the Model screen shows **Loaded by** and **Load expectation**, the
198
+ * two sections served by the host's pipeline endpoints. Default `true`. Set
199
+ * `false` for a host that does not mount them: neither section renders and
200
+ * neither `/pipeline/workflows` nor `/pipeline/expectations/:type` is
201
+ * requested.
202
+ */
203
+ pipeline?: boolean;
204
+ /**
205
+ * Set `true` when the host authenticates every request itself and serves no
206
+ * `/auth/me`. The console then shows no sign-in and never calls `/auth/me`.
207
+ * Default `false`. Configuring `auth` already hides the sign-in, but keeps
208
+ * asking `/auth/me` for the Access screen.
209
+ */
210
+ hostAuthenticates?: boolean;
211
+ }
212
+ /** What the SPA reads from `config.js`, in the shape `readConsoleConfig` expects. */
213
+ interface ResolvedConsoleOptions {
214
+ screens: CatalogConsoleScreen[];
215
+ pipeline: boolean;
216
+ hostAuthenticates: boolean;
217
+ }
218
+ /**
219
+ * The options with their defaults, refused at module definition when they name
220
+ * something that does not exist. A typo in `screens` would otherwise hide a
221
+ * screen the host meant to show, silently.
222
+ */
223
+ declare function resolveConsoleOptions(options?: CatalogConsoleOptions): ResolvedConsoleOptions;
224
+
225
+ /**
226
+ * Includes {@link CatalogConsoleOptions}: `screens`, `pipeline` and
227
+ * `hostAuthenticates`, which shape what the SPA shows and asks for.
228
+ */
229
+ interface CatalogDashboardOptions extends CatalogConsoleOptions {
176
230
  /**
177
231
  * Where the console is served. Default `/catalog`.
178
232
  *
@@ -361,6 +415,8 @@ declare class CatalogApiSessionGuard implements CanActivate {
361
415
  declare const DASHBOARD_BASE_PATH: unique symbol;
362
416
  /** DI token carrying the JSON API base the SPA fetches from (e.g. `/api/catalog`). */
363
417
  declare const DASHBOARD_API_PATH: unique symbol;
418
+ /** DI token carrying the resolved console options: screens, pipeline, host authentication. */
419
+ declare const DASHBOARD_CONSOLE: unique symbol;
364
420
  /**
365
421
  * Serves the bundled control-plane SPA at the configured base (+ hashed assets at `<base>/assets`).
366
422
  * The path comes from `RouterModule` (set by `CatalogDashboardModule.forRoot({ basePath })`), so the
@@ -378,6 +434,7 @@ declare class CatalogUiController {
378
434
  private readonly basePath;
379
435
  private readonly apiBasePath;
380
436
  private readonly auth;
437
+ private readonly console;
381
438
  private readonly dir;
382
439
  /**
383
440
  * The rewritten index.html, with the file version it was rendered from. A
@@ -385,10 +442,24 @@ declare class CatalogUiController {
385
442
  * renders it again instead of pointing at hashed assets that are gone.
386
443
  */
387
444
  private rendered?;
388
- constructor(basePath: string, apiBasePath: string, auth?: unknown);
445
+ constructor(basePath: string, apiBasePath: string, auth?: unknown, console?: ResolvedConsoleOptions);
389
446
  index(): string;
390
447
  private render;
448
+ /**
449
+ * The values the SPA reads at startup.
450
+ *
451
+ * __CATALOG_BASE__ = where assets load; __CATALOG_API__ = where the SPA fetches the JSON API;
452
+ * __CATALOG_HOST_AUTH__ = whether the HOST authenticates, in which case the SPA must not show its
453
+ * own sign-in (a console mounted inside an application that already knows who you are and then
454
+ * asks you to log in again is not a smaller problem than one that lets anybody in);
455
+ * __CATALOG_CONSOLE__ = which screens to show, whether the Model screen reads the pipeline
456
+ * endpoints, and whether the SPA may ask `/auth/me` who is calling.
457
+ *
458
+ * Every value goes through `JSON.stringify`, so a path can never close the string it sits in.
459
+ * Not cached by the browser: it is tiny, and it changes with the module's options.
460
+ */
461
+ config(): string;
391
462
  asset(file: string): StreamableFile;
392
463
  }
393
464
 
394
- export { CatalogApiSessionGuard, CatalogAuthController, type CatalogDashboardAsyncOptions, CatalogDashboardModule, type CatalogDashboardOptions, CatalogUiController, CatalogUiSessionGuard, DASHBOARD_API_PATH, DASHBOARD_AUTH, DASHBOARD_BASE_PATH, type DashboardAuthOptions, type DashboardSession, type DashboardSessionUser, type ResolvedDashboardAuth, type UnauthenticatedPageContext, type UnauthenticatedPageHook, catalogDashboardMountPaths, readSessionFromRequest as readCatalogConsoleSession };
465
+ export { CATALOG_CONSOLE_SCREENS, CatalogApiSessionGuard, CatalogAuthController, type CatalogConsoleOptions, type CatalogConsoleScreen, type CatalogDashboardAsyncOptions, CatalogDashboardModule, type CatalogDashboardOptions, CatalogUiController, CatalogUiSessionGuard, DASHBOARD_API_PATH, DASHBOARD_AUTH, DASHBOARD_BASE_PATH, DASHBOARD_CONSOLE, type DashboardAuthOptions, type DashboardSession, type DashboardSessionUser, type ResolvedConsoleOptions, type ResolvedDashboardAuth, type UnauthenticatedPageContext, type UnauthenticatedPageHook, catalogDashboardMountPaths, readSessionFromRequest as readCatalogConsoleSession, resolveConsoleOptions };
@@ -172,7 +172,61 @@ declare class CatalogAuthController {
172
172
  private runHook;
173
173
  }
174
174
 
175
- interface CatalogDashboardOptions {
175
+ /**
176
+ * Every screen the console can show. `search` is the one reached by `⌘K` and
177
+ * `#search` rather than by a tab.
178
+ *
179
+ * The client keeps the same list in `src/client/console-config.ts`, because the
180
+ * server and the SPA are separate builds with separate roots;
181
+ * `console-options.spec.ts` fails if the two drift.
182
+ */
183
+ declare const CATALOG_CONSOLE_SCREENS: readonly ["model", "objects", "query", "dashboards", "workflows", "connections", "lineage", "activity", "access", "search"];
184
+ type CatalogConsoleScreen = (typeof CATALOG_CONSOLE_SCREENS)[number];
185
+ /** What a host may say about the console it serves. Every field is optional. */
186
+ interface CatalogConsoleOptions {
187
+ /**
188
+ * The screens to show, and only these. Default: all of them.
189
+ *
190
+ * A hidden screen gets no tab, no panel and no requests, and an address
191
+ * naming it lands on the first screen shown. `'search'` hides the search
192
+ * button, `⌘K` and `#search`. Must name at least one screen other than
193
+ * `'search'`, since search alone has no tab to come back to.
194
+ */
195
+ screens?: readonly CatalogConsoleScreen[];
196
+ /**
197
+ * Whether the Model screen shows **Loaded by** and **Load expectation**, the
198
+ * two sections served by the host's pipeline endpoints. Default `true`. Set
199
+ * `false` for a host that does not mount them: neither section renders and
200
+ * neither `/pipeline/workflows` nor `/pipeline/expectations/:type` is
201
+ * requested.
202
+ */
203
+ pipeline?: boolean;
204
+ /**
205
+ * Set `true` when the host authenticates every request itself and serves no
206
+ * `/auth/me`. The console then shows no sign-in and never calls `/auth/me`.
207
+ * Default `false`. Configuring `auth` already hides the sign-in, but keeps
208
+ * asking `/auth/me` for the Access screen.
209
+ */
210
+ hostAuthenticates?: boolean;
211
+ }
212
+ /** What the SPA reads from `config.js`, in the shape `readConsoleConfig` expects. */
213
+ interface ResolvedConsoleOptions {
214
+ screens: CatalogConsoleScreen[];
215
+ pipeline: boolean;
216
+ hostAuthenticates: boolean;
217
+ }
218
+ /**
219
+ * The options with their defaults, refused at module definition when they name
220
+ * something that does not exist. A typo in `screens` would otherwise hide a
221
+ * screen the host meant to show, silently.
222
+ */
223
+ declare function resolveConsoleOptions(options?: CatalogConsoleOptions): ResolvedConsoleOptions;
224
+
225
+ /**
226
+ * Includes {@link CatalogConsoleOptions}: `screens`, `pipeline` and
227
+ * `hostAuthenticates`, which shape what the SPA shows and asks for.
228
+ */
229
+ interface CatalogDashboardOptions extends CatalogConsoleOptions {
176
230
  /**
177
231
  * Where the console is served. Default `/catalog`.
178
232
  *
@@ -361,6 +415,8 @@ declare class CatalogApiSessionGuard implements CanActivate {
361
415
  declare const DASHBOARD_BASE_PATH: unique symbol;
362
416
  /** DI token carrying the JSON API base the SPA fetches from (e.g. `/api/catalog`). */
363
417
  declare const DASHBOARD_API_PATH: unique symbol;
418
+ /** DI token carrying the resolved console options: screens, pipeline, host authentication. */
419
+ declare const DASHBOARD_CONSOLE: unique symbol;
364
420
  /**
365
421
  * Serves the bundled control-plane SPA at the configured base (+ hashed assets at `<base>/assets`).
366
422
  * The path comes from `RouterModule` (set by `CatalogDashboardModule.forRoot({ basePath })`), so the
@@ -378,6 +434,7 @@ declare class CatalogUiController {
378
434
  private readonly basePath;
379
435
  private readonly apiBasePath;
380
436
  private readonly auth;
437
+ private readonly console;
381
438
  private readonly dir;
382
439
  /**
383
440
  * The rewritten index.html, with the file version it was rendered from. A
@@ -385,10 +442,24 @@ declare class CatalogUiController {
385
442
  * renders it again instead of pointing at hashed assets that are gone.
386
443
  */
387
444
  private rendered?;
388
- constructor(basePath: string, apiBasePath: string, auth?: unknown);
445
+ constructor(basePath: string, apiBasePath: string, auth?: unknown, console?: ResolvedConsoleOptions);
389
446
  index(): string;
390
447
  private render;
448
+ /**
449
+ * The values the SPA reads at startup.
450
+ *
451
+ * __CATALOG_BASE__ = where assets load; __CATALOG_API__ = where the SPA fetches the JSON API;
452
+ * __CATALOG_HOST_AUTH__ = whether the HOST authenticates, in which case the SPA must not show its
453
+ * own sign-in (a console mounted inside an application that already knows who you are and then
454
+ * asks you to log in again is not a smaller problem than one that lets anybody in);
455
+ * __CATALOG_CONSOLE__ = which screens to show, whether the Model screen reads the pipeline
456
+ * endpoints, and whether the SPA may ask `/auth/me` who is calling.
457
+ *
458
+ * Every value goes through `JSON.stringify`, so a path can never close the string it sits in.
459
+ * Not cached by the browser: it is tiny, and it changes with the module's options.
460
+ */
461
+ config(): string;
391
462
  asset(file: string): StreamableFile;
392
463
  }
393
464
 
394
- export { CatalogApiSessionGuard, CatalogAuthController, type CatalogDashboardAsyncOptions, CatalogDashboardModule, type CatalogDashboardOptions, CatalogUiController, CatalogUiSessionGuard, DASHBOARD_API_PATH, DASHBOARD_AUTH, DASHBOARD_BASE_PATH, type DashboardAuthOptions, type DashboardSession, type DashboardSessionUser, type ResolvedDashboardAuth, type UnauthenticatedPageContext, type UnauthenticatedPageHook, catalogDashboardMountPaths, readSessionFromRequest as readCatalogConsoleSession };
465
+ export { CATALOG_CONSOLE_SCREENS, CatalogApiSessionGuard, CatalogAuthController, type CatalogConsoleOptions, type CatalogConsoleScreen, type CatalogDashboardAsyncOptions, CatalogDashboardModule, type CatalogDashboardOptions, CatalogUiController, CatalogUiSessionGuard, DASHBOARD_API_PATH, DASHBOARD_AUTH, DASHBOARD_BASE_PATH, DASHBOARD_CONSOLE, type DashboardAuthOptions, type DashboardSession, type DashboardSessionUser, type ResolvedConsoleOptions, type ResolvedDashboardAuth, type UnauthenticatedPageContext, type UnauthenticatedPageHook, catalogDashboardMountPaths, readSessionFromRequest as readCatalogConsoleSession, resolveConsoleOptions };
@@ -676,6 +676,37 @@ DashboardSessionRequiredFilter = _ts_decorate2([
676
676
  ])
677
677
  ], DashboardSessionRequiredFilter);
678
678
 
679
+ // src/server/console-options.ts
680
+ var CATALOG_CONSOLE_SCREENS = [
681
+ "model",
682
+ "objects",
683
+ "query",
684
+ "dashboards",
685
+ "workflows",
686
+ "connections",
687
+ "lineage",
688
+ "activity",
689
+ "access",
690
+ "search"
691
+ ];
692
+ function resolveConsoleOptions(options = {}) {
693
+ const screens = options.screens ?? CATALOG_CONSOLE_SCREENS;
694
+ const unknown = screens.filter((screen) => !CATALOG_CONSOLE_SCREENS.includes(screen));
695
+ if (unknown.length > 0) {
696
+ throw new Error(`CatalogDashboardModule: unknown console screen(s) ${unknown.map((s) => `"${s}"`).join(", ")}. Known screens: ${CATALOG_CONSOLE_SCREENS.join(", ")}.`);
697
+ }
698
+ if (!screens.some((screen) => screen !== "search")) {
699
+ throw new Error('CatalogDashboardModule: `screens` must name at least one screen other than "search".');
700
+ }
701
+ return {
702
+ // In the console's own order, whatever order the host listed them in, and once each.
703
+ screens: CATALOG_CONSOLE_SCREENS.filter((screen) => screens.includes(screen)),
704
+ pipeline: options.pipeline !== false,
705
+ hostAuthenticates: options.hostAuthenticates === true
706
+ };
707
+ }
708
+ __name(resolveConsoleOptions, "resolveConsoleOptions");
709
+
679
710
  // src/server/catalog-ui.controller.ts
680
711
  function _ts_decorate3(decorators, target, key, desc) {
681
712
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -705,6 +736,11 @@ function _ts_param2(paramIndex, decorator) {
705
736
  __name(_ts_param2, "_ts_param");
706
737
  var DASHBOARD_BASE_PATH = /* @__PURE__ */ Symbol("DASHBOARD_BASE_PATH");
707
738
  var DASHBOARD_API_PATH = /* @__PURE__ */ Symbol("DASHBOARD_API_PATH");
739
+ var DASHBOARD_CONSOLE = /* @__PURE__ */ Symbol("DASHBOARD_CONSOLE");
740
+ function attribute(value) {
741
+ return value.replaceAll("&", "&amp;").replaceAll('"', "&quot;");
742
+ }
743
+ __name(attribute, "attribute");
708
744
  var BUILD_BASE = "/catalog";
709
745
  function spaDir() {
710
746
  return fileURLToPath(new URL("../spa", import.meta.url));
@@ -726,6 +762,7 @@ var CatalogUiController = class {
726
762
  basePath;
727
763
  apiBasePath;
728
764
  auth;
765
+ console;
729
766
  dir = spaDir();
730
767
  /**
731
768
  * The rewritten index.html, with the file version it was rendered from. A
@@ -733,10 +770,11 @@ var CatalogUiController = class {
733
770
  * renders it again instead of pointing at hashed assets that are gone.
734
771
  */
735
772
  rendered;
736
- constructor(basePath, apiBasePath, auth = null) {
773
+ constructor(basePath, apiBasePath, auth = null, console = resolveConsoleOptions()) {
737
774
  this.basePath = basePath;
738
775
  this.apiBasePath = apiBasePath;
739
776
  this.auth = auth;
777
+ this.console = console;
740
778
  }
741
779
  // index.html references hash-named bundles, so it MUST NOT be cached (stale bundle = the
742
780
  // classic "stuck loading after a deploy"). The hashed assets below are immutable.
@@ -759,10 +797,41 @@ var CatalogUiController = class {
759
797
  return html;
760
798
  }
761
799
  render(source) {
762
- const html = source.replaceAll(`="${BUILD_BASE}/`, `="${this.basePath}/`);
763
- const hostAuth = this.auth ? "true" : "false";
764
- const inject = `<script>window.__CATALOG_BASE__='${this.basePath}';window.__CATALOG_API__='${this.apiBasePath}';window.__CATALOG_HOST_AUTH__=${hostAuth};</script>`;
765
- return html.includes("</head>") ? html.replace("</head>", `${inject}</head>`) : inject + html;
800
+ const base = attribute(this.basePath);
801
+ const html = source.replaceAll(`="${BUILD_BASE}/`, `="${base}/`);
802
+ const inject = `<script src="${base}/config.js"></script>`;
803
+ const head = /<head\b[^>]*>/i.exec(html);
804
+ if (!head) return inject + html;
805
+ const at = head.index + head[0].length;
806
+ return html.slice(0, at) + inject + html.slice(at);
807
+ }
808
+ /**
809
+ * The values the SPA reads at startup.
810
+ *
811
+ * __CATALOG_BASE__ = where assets load; __CATALOG_API__ = where the SPA fetches the JSON API;
812
+ * __CATALOG_HOST_AUTH__ = whether the HOST authenticates, in which case the SPA must not show its
813
+ * own sign-in (a console mounted inside an application that already knows who you are and then
814
+ * asks you to log in again is not a smaller problem than one that lets anybody in);
815
+ * __CATALOG_CONSOLE__ = which screens to show, whether the Model screen reads the pipeline
816
+ * endpoints, and whether the SPA may ask `/auth/me` who is calling.
817
+ *
818
+ * Every value goes through `JSON.stringify`, so a path can never close the string it sits in.
819
+ * Not cached by the browser: it is tiny, and it changes with the module's options.
820
+ */
821
+ config() {
822
+ const hostAuth = Boolean(this.auth) || this.console.hostAuthenticates;
823
+ const consoleConfig = {
824
+ screens: this.console.screens,
825
+ pipeline: this.console.pipeline,
826
+ identity: !this.console.hostAuthenticates
827
+ };
828
+ return [
829
+ `window.__CATALOG_BASE__=${JSON.stringify(this.basePath)};`,
830
+ `window.__CATALOG_API__=${JSON.stringify(this.apiBasePath)};`,
831
+ `window.__CATALOG_HOST_AUTH__=${JSON.stringify(hostAuth)};`,
832
+ `window.__CATALOG_CONSOLE__=${JSON.stringify(consoleConfig)};`,
833
+ ""
834
+ ].join("\n");
766
835
  }
767
836
  asset(file) {
768
837
  const safe = basename(file);
@@ -789,6 +858,14 @@ _ts_decorate3([
789
858
  _ts_metadata2("design:paramtypes", []),
790
859
  _ts_metadata2("design:returntype", String)
791
860
  ], CatalogUiController.prototype, "index", null);
861
+ _ts_decorate3([
862
+ Get("config.js"),
863
+ Header("Content-Type", "text/javascript; charset=utf-8"),
864
+ Header("Cache-Control", "no-store, must-revalidate"),
865
+ _ts_metadata2("design:type", Function),
866
+ _ts_metadata2("design:paramtypes", []),
867
+ _ts_metadata2("design:returntype", String)
868
+ ], CatalogUiController.prototype, "config", null);
792
869
  _ts_decorate3([
793
870
  Get("assets/:file"),
794
871
  Header("Cache-Control", "public, max-age=31536000, immutable"),
@@ -806,11 +883,14 @@ CatalogUiController = _ts_decorate3([
806
883
  _ts_param2(1, Inject2(DASHBOARD_API_PATH)),
807
884
  _ts_param2(2, Optional2()),
808
885
  _ts_param2(2, Inject2(DASHBOARD_AUTH)),
886
+ _ts_param2(3, Optional2()),
887
+ _ts_param2(3, Inject2(DASHBOARD_CONSOLE)),
809
888
  _ts_metadata2("design:type", Function),
810
889
  _ts_metadata2("design:paramtypes", [
811
890
  String,
812
891
  String,
813
- Object
892
+ Object,
893
+ typeof ResolvedConsoleOptions === "undefined" ? Object : ResolvedConsoleOptions
814
894
  ])
815
895
  ], CatalogUiController);
816
896
 
@@ -1198,6 +1278,17 @@ var sessionGuardStamped = false;
1198
1278
  function build(options, auth) {
1199
1279
  const path = normalise(options.path ?? "/catalog");
1200
1280
  const apiPath = normalise(options.apiPath ?? "/api/catalog-service");
1281
+ const consoleOptions = resolveConsoleOptions({
1282
+ ...options.screens ? {
1283
+ screens: options.screens
1284
+ } : {},
1285
+ ...options.pipeline !== void 0 ? {
1286
+ pipeline: options.pipeline
1287
+ } : {},
1288
+ ...options.hostAuthenticates !== void 0 ? {
1289
+ hostAuthenticates: options.hostAuthenticates
1290
+ } : {}
1291
+ });
1201
1292
  if (!sessionGuardStamped) {
1202
1293
  UseGuards(CatalogUiSessionGuard)(CatalogUiController);
1203
1294
  sessionGuardStamped = true;
@@ -1215,6 +1306,10 @@ function build(options, auth) {
1215
1306
  provide: DASHBOARD_API_PATH,
1216
1307
  useValue: apiPath
1217
1308
  },
1309
+ {
1310
+ provide: DASHBOARD_CONSOLE,
1311
+ useValue: consoleOptions
1312
+ },
1218
1313
  auth,
1219
1314
  // Constructed by Nest, so it must be declared here — a guard stamped by
1220
1315
  // `UseGuards` is still resolved from the declaring module's injector.
@@ -1276,6 +1371,7 @@ function normalise(path) {
1276
1371
  }
1277
1372
  __name(normalise, "normalise");
1278
1373
  export {
1374
+ CATALOG_CONSOLE_SCREENS,
1279
1375
  CatalogApiSessionGuard,
1280
1376
  CatalogAuthController,
1281
1377
  CatalogDashboardModule,
@@ -1284,7 +1380,9 @@ export {
1284
1380
  DASHBOARD_API_PATH,
1285
1381
  DASHBOARD_AUTH,
1286
1382
  DASHBOARD_BASE_PATH,
1383
+ DASHBOARD_CONSOLE,
1287
1384
  catalogDashboardMountPaths,
1288
- readSessionFromRequest as readCatalogConsoleSession
1385
+ readSessionFromRequest as readCatalogConsoleSession,
1386
+ resolveConsoleOptions
1289
1387
  };
1290
1388
  //# sourceMappingURL=index.js.map