@dudousxd/nestjs-catalog-dashboard 0.34.0 → 0.34.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/README.md CHANGED
@@ -79,3 +79,10 @@ pulls it in.
79
79
 
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
+
83
+ ## How the console is served
84
+
85
+ `index.html` is rendered once (asset URLs rewritten to `path`, the API base filled in) and kept in
86
+ memory. Each request checks the file's mtime and size, and renders it again when they change, so a
87
+ rebuilt bundle is picked up without a restart. It is always sent `Cache-Control: no-store`. Files
88
+ under `assets/` are streamed from disk with a `Content-Length`; a path that is not a file is a 404.
@@ -22,5 +22,5 @@ export interface OpenCatalogConsoleButtonProps extends Omit<ButtonHTMLAttributes
22
22
  * The error is rendered by default rather than swallowed: a refused mint is the case a launcher most
23
23
  * needs to surface, and a button that silently does nothing reads as broken rather than forbidden.
24
24
  */
25
- export declare function OpenCatalogConsoleButton({ children, pendingLabel, renderError, basePath, headers, fetch: fetchImpl, signal, navigate, disabled, ...buttonProps }: OpenCatalogConsoleButtonProps): import("react/jsx-runtime").JSX.Element;
25
+ export declare function OpenCatalogConsoleButton({ children, pendingLabel, renderError, basePath, headers, fetch: fetchImpl, signal, navigate, disabled, ...buttonProps }: OpenCatalogConsoleButtonProps): import("react").JSX.Element;
26
26
  //# sourceMappingURL=open-console-button.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"open-console-button.d.ts","sourceRoot":"","sources":["../../src/react/open-console-button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAGvE,MAAM,WAAW,6BACf,SAAQ,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EAAE,SAAS,GAAG,UAAU,CAAC,EAC3E,kBAAkB;IACpB,gDAAgD;IAChD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,uEAAuE;IACvE,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,SAAS,CAAC,GAAG,IAAI,CAAC;CACpD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,EACvC,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,OAAO,EACP,KAAK,EAAE,SAAS,EAChB,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,GAAG,WAAW,EACf,EAAE,6BAA6B,2CAyB/B"}
1
+ {"version":3,"file":"open-console-button.d.ts","sourceRoot":"","sources":["../../src/react/open-console-button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAGvE,MAAM,WAAW,6BACf,SAAQ,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EAAE,SAAS,GAAG,UAAU,CAAC,EAC3E,kBAAkB;IACpB,gDAAgD;IAChD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,uEAAuE;IACvE,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,SAAS,CAAC,GAAG,IAAI,CAAC;CACpD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,EACvC,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,OAAO,EACP,KAAK,EAAE,SAAS,EAChB,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,GAAG,WAAW,EACf,EAAE,6BAA6B,+BAyB/B"}
@@ -36,7 +36,7 @@ __export(index_exports, {
36
36
  module.exports = __toCommonJS(index_exports);
37
37
 
38
38
  // src/server/auth/dashboard-auth-config.ts
39
- var DASHBOARD_AUTH = Symbol("DASHBOARD_AUTH");
39
+ var DASHBOARD_AUTH = /* @__PURE__ */ Symbol("DASHBOARD_AUTH");
40
40
  var DEFAULT_TTL = "8h";
41
41
  var DEFAULT_TTL_MS = 8 * 60 * 60 * 1e3;
42
42
  var DURATION_UNITS = {
@@ -588,8 +588,15 @@ var import_common3 = require("@nestjs/common");
588
588
  var import_common = require("@nestjs/common");
589
589
  function _ts_decorate(decorators, target, key, desc) {
590
590
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
591
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
592
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
591
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
592
+ r = Reflect.decorate(decorators, target, key, desc);
593
+ } else {
594
+ for (var i = decorators.length - 1; i >= 0; i--) {
595
+ if (d = decorators[i]) {
596
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
597
+ }
598
+ }
599
+ }
593
600
  return c > 3 && r && Object.defineProperty(target, key, r), r;
594
601
  }
595
602
  __name(_ts_decorate, "_ts_decorate");
@@ -621,13 +628,22 @@ DashboardLoginRedirectFilter = _ts_decorate([
621
628
  var import_common2 = require("@nestjs/common");
622
629
  function _ts_decorate2(decorators, target, key, desc) {
623
630
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
624
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
625
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
631
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
632
+ r = Reflect.decorate(decorators, target, key, desc);
633
+ } else {
634
+ for (var i = decorators.length - 1; i >= 0; i--) {
635
+ if (d = decorators[i]) {
636
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
637
+ }
638
+ }
639
+ }
626
640
  return c > 3 && r && Object.defineProperty(target, key, r), r;
627
641
  }
628
642
  __name(_ts_decorate2, "_ts_decorate");
629
- function _ts_metadata(k, v) {
630
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
643
+ function _ts_metadata(metadataKey, metadataValue) {
644
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
645
+ return Reflect.metadata(metadataKey, metadataValue);
646
+ }
631
647
  }
632
648
  __name(_ts_metadata, "_ts_metadata");
633
649
  function _ts_param(paramIndex, decorator) {
@@ -697,13 +713,22 @@ DashboardSessionRequiredFilter = _ts_decorate2([
697
713
  // src/server/catalog-ui.controller.ts
698
714
  function _ts_decorate3(decorators, target, key, desc) {
699
715
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
700
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
701
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
716
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
717
+ r = Reflect.decorate(decorators, target, key, desc);
718
+ } else {
719
+ for (var i = decorators.length - 1; i >= 0; i--) {
720
+ if (d = decorators[i]) {
721
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
722
+ }
723
+ }
724
+ }
702
725
  return c > 3 && r && Object.defineProperty(target, key, r), r;
703
726
  }
704
727
  __name(_ts_decorate3, "_ts_decorate");
705
- function _ts_metadata2(k, v) {
706
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
728
+ function _ts_metadata2(metadataKey, metadataValue) {
729
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
730
+ return Reflect.metadata(metadataKey, metadataValue);
731
+ }
707
732
  }
708
733
  __name(_ts_metadata2, "_ts_metadata");
709
734
  function _ts_param2(paramIndex, decorator) {
@@ -712,8 +737,8 @@ function _ts_param2(paramIndex, decorator) {
712
737
  };
713
738
  }
714
739
  __name(_ts_param2, "_ts_param");
715
- var DASHBOARD_BASE_PATH = Symbol("DASHBOARD_BASE_PATH");
716
- var DASHBOARD_API_PATH = Symbol("DASHBOARD_API_PATH");
740
+ var DASHBOARD_BASE_PATH = /* @__PURE__ */ Symbol("DASHBOARD_BASE_PATH");
741
+ var DASHBOARD_API_PATH = /* @__PURE__ */ Symbol("DASHBOARD_API_PATH");
717
742
  var BUILD_BASE = "/catalog";
718
743
  function spaDir() {
719
744
  return (0, import_node_url.fileURLToPath)(new URL("../spa", __importMetaUrl));
@@ -736,6 +761,12 @@ var CatalogUiController = class {
736
761
  apiBasePath;
737
762
  auth;
738
763
  dir = spaDir();
764
+ /**
765
+ * The rewritten index.html, with the file version it was rendered from. A
766
+ * rebuilt bundle changes the file's mtime or size, and the next request
767
+ * renders it again instead of pointing at hashed assets that are gone.
768
+ */
769
+ rendered;
739
770
  constructor(basePath, apiBasePath, auth = null) {
740
771
  this.basePath = basePath;
741
772
  this.apiBasePath = apiBasePath;
@@ -745,10 +776,24 @@ var CatalogUiController = class {
745
776
  // classic "stuck loading after a deploy"). The hashed assets below are immutable.
746
777
  index() {
747
778
  const indexPath = (0, import_node_path.join)(this.dir, "index.html");
748
- if (!(0, import_node_fs.existsSync)(indexPath)) {
779
+ const stat = (0, import_node_fs.statSync)(indexPath, {
780
+ throwIfNoEntry: false
781
+ });
782
+ if (!stat) {
749
783
  throw new import_common3.NotFoundException("Dashboard is not built. Run the package build.");
750
784
  }
751
- const html = (0, import_node_fs.readFileSync)(indexPath, "utf8").replaceAll(`="${BUILD_BASE}/`, `="${this.basePath}/`);
785
+ const cached = this.rendered;
786
+ if (cached && cached.mtimeMs === stat.mtimeMs && cached.size === stat.size) return cached.html;
787
+ const html = this.render((0, import_node_fs.readFileSync)(indexPath, "utf8"));
788
+ this.rendered = {
789
+ mtimeMs: stat.mtimeMs,
790
+ size: stat.size,
791
+ html
792
+ };
793
+ return html;
794
+ }
795
+ render(source) {
796
+ const html = source.replaceAll(`="${BUILD_BASE}/`, `="${this.basePath}/`);
752
797
  const hostAuth = this.auth ? "true" : "false";
753
798
  const inject = `<script>window.__CATALOG_BASE__='${this.basePath}';window.__CATALOG_API__='${this.apiBasePath}';window.__CATALOG_HOST_AUTH__=${hostAuth};</script>`;
754
799
  return html.includes("</head>") ? html.replace("</head>", `${inject}</head>`) : inject + html;
@@ -758,12 +803,15 @@ var CatalogUiController = class {
758
803
  if (safe !== file) throw new import_common3.NotFoundException();
759
804
  const root = (0, import_node_path.resolve)(this.dir, "assets");
760
805
  const assetPath = (0, import_node_path.resolve)(root, safe);
761
- if (!assetPath.startsWith(root + import_node_path.sep) || !(0, import_node_fs.existsSync)(assetPath)) {
762
- throw new import_common3.NotFoundException();
763
- }
806
+ if (!assetPath.startsWith(root + import_node_path.sep)) throw new import_common3.NotFoundException();
807
+ const stat = (0, import_node_fs.statSync)(assetPath, {
808
+ throwIfNoEntry: false
809
+ });
810
+ if (!stat?.isFile()) throw new import_common3.NotFoundException();
764
811
  const type = CONTENT_TYPES[(0, import_node_path.extname)(safe)] ?? "application/octet-stream";
765
- return new import_common3.StreamableFile((0, import_node_fs.readFileSync)(assetPath), {
766
- type
812
+ return new import_common3.StreamableFile((0, import_node_fs.createReadStream)(assetPath), {
813
+ type,
814
+ length: stat.size
767
815
  });
768
816
  }
769
817
  };
@@ -803,13 +851,22 @@ CatalogUiController = _ts_decorate3([
803
851
  // src/server/catalog-auth.controller.ts
804
852
  function _ts_decorate4(decorators, target, key, desc) {
805
853
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
806
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
807
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
854
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
855
+ r = Reflect.decorate(decorators, target, key, desc);
856
+ } else {
857
+ for (var i = decorators.length - 1; i >= 0; i--) {
858
+ if (d = decorators[i]) {
859
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
860
+ }
861
+ }
862
+ }
808
863
  return c > 3 && r && Object.defineProperty(target, key, r), r;
809
864
  }
810
865
  __name(_ts_decorate4, "_ts_decorate");
811
- function _ts_metadata3(k, v) {
812
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
866
+ function _ts_metadata3(metadataKey, metadataValue) {
867
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
868
+ return Reflect.metadata(metadataKey, metadataValue);
869
+ }
813
870
  }
814
871
  __name(_ts_metadata3, "_ts_metadata");
815
872
  function _ts_param3(paramIndex, decorator) {
@@ -994,13 +1051,22 @@ var import_core = require("@nestjs/core");
994
1051
  var import_common5 = require("@nestjs/common");
995
1052
  function _ts_decorate5(decorators, target, key, desc) {
996
1053
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
997
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
998
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1054
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1055
+ r = Reflect.decorate(decorators, target, key, desc);
1056
+ } else {
1057
+ for (var i = decorators.length - 1; i >= 0; i--) {
1058
+ if (d = decorators[i]) {
1059
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1060
+ }
1061
+ }
1062
+ }
999
1063
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1000
1064
  }
1001
1065
  __name(_ts_decorate5, "_ts_decorate");
1002
- function _ts_metadata4(k, v) {
1003
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1066
+ function _ts_metadata4(metadataKey, metadataValue) {
1067
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1068
+ return Reflect.metadata(metadataKey, metadataValue);
1069
+ }
1004
1070
  }
1005
1071
  __name(_ts_metadata4, "_ts_metadata");
1006
1072
  function _ts_param4(paramIndex, decorator) {
@@ -1108,8 +1174,15 @@ CatalogApiSessionGuard = _ts_decorate5([
1108
1174
  // src/server/catalog-dashboard.module.ts
1109
1175
  function _ts_decorate6(decorators, target, key, desc) {
1110
1176
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1111
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1112
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1177
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1178
+ r = Reflect.decorate(decorators, target, key, desc);
1179
+ } else {
1180
+ for (var i = decorators.length - 1; i >= 0; i--) {
1181
+ if (d = decorators[i]) {
1182
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1183
+ }
1184
+ }
1185
+ }
1113
1186
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1114
1187
  }
1115
1188
  __name(_ts_decorate6, "_ts_decorate");