nestlens 0.8.12 → 0.9.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.
Files changed (169) hide show
  1. package/dist/api/content-encoding.d.ts +20 -0
  2. package/dist/api/content-encoding.js +92 -0
  3. package/dist/api/dashboard.controller.d.ts +37 -5
  4. package/dist/api/dashboard.controller.js +114 -28
  5. package/dist/api/dto/api-response.dto.d.ts +0 -8
  6. package/dist/api/dto/api-response.dto.js +0 -33
  7. package/dist/api/dto/cursor-query.dto.d.ts +5 -0
  8. package/dist/api/dto/cursor-query.dto.js +1 -0
  9. package/dist/api/dto/index.d.ts +0 -2
  10. package/dist/api/dto/index.js +0 -2
  11. package/dist/api/dto/transformers/query-transformers.d.ts +0 -4
  12. package/dist/api/dto/transformers/query-transformers.js +0 -7
  13. package/dist/api/dto/transformers/query-validators.d.ts +12 -0
  14. package/dist/api/dto/transformers/query-validators.js +22 -5
  15. package/dist/api/route-path.js +19 -1
  16. package/dist/core/collector.service.d.ts +12 -1
  17. package/dist/core/collector.service.js +37 -5
  18. package/dist/core/data-masker.service.d.ts +10 -0
  19. package/dist/core/data-masker.service.js +8 -1
  20. package/dist/core/pruning.service.js +4 -1
  21. package/dist/core/storage/index.js +4 -3
  22. package/dist/core/storage/memory.storage.d.ts +2 -2
  23. package/dist/core/storage/memory.storage.js +5 -3
  24. package/dist/core/storage/redis.storage.d.ts +2 -2
  25. package/dist/core/storage/redis.storage.js +5 -3
  26. package/dist/core/storage/sqlite.storage.d.ts +23 -2
  27. package/dist/core/storage/sqlite.storage.js +59 -7
  28. package/dist/core/storage/storage.factory.js +26 -0
  29. package/dist/core/storage/tag-normalization.d.ts +10 -0
  30. package/dist/core/storage/tag-normalization.js +14 -0
  31. package/dist/core/tag.service.js +5 -2
  32. package/dist/dashboard/public/assets/BatchDetailView-D8PKMRJK.js +1 -0
  33. package/dist/dashboard/public/assets/BatchesPage-DT5Mywoo.js +1 -0
  34. package/dist/dashboard/public/assets/CacheDetailView-BKg5s6do.js +6 -0
  35. package/dist/dashboard/public/assets/CachePage-Dv0sIWfb.js +1 -0
  36. package/dist/dashboard/public/assets/CommandDetailView-34Fp3Zse.js +1 -0
  37. package/dist/dashboard/public/assets/CommandsPage-DfJBmcAu.js +1 -0
  38. package/dist/dashboard/public/assets/CopyButton-CVTvd0EZ.js +3 -0
  39. package/dist/dashboard/public/assets/{DashboardPage-DF6wLAIo.js → DashboardPage-Bl0QYNJ5.js} +2 -2
  40. package/dist/dashboard/public/assets/DataTable-DNJpoFzh.js +53 -0
  41. package/dist/dashboard/public/assets/DetailRow-CouZ8riB.js +1 -0
  42. package/dist/dashboard/public/assets/DumpDetailView-B6-Nre38.js +11 -0
  43. package/dist/dashboard/public/assets/DumpsPage-Cd0B4s9o.js +1 -0
  44. package/dist/dashboard/public/assets/EntryDetailPage-QTrST2MQ.js +27 -0
  45. package/dist/dashboard/public/assets/EntrySearchInput-DqIRbpja.js +1 -0
  46. package/dist/dashboard/public/assets/EventDetailView-2SmuXgrJ.js +1 -0
  47. package/dist/dashboard/public/assets/EventsPage-DCpLnIob.js +1 -0
  48. package/dist/dashboard/public/assets/ExceptionDetailView-DxGim-Jg.js +8 -0
  49. package/dist/dashboard/public/assets/ExceptionsPage-Qa60iwA4.js +6 -0
  50. package/dist/dashboard/public/assets/GateDetailView-DFVtRPBk.js +6 -0
  51. package/dist/dashboard/public/assets/GatesPage-DHGIZzbG.js +1 -0
  52. package/dist/dashboard/public/assets/GraphQLDetailView-DvHekddm.js +6 -0
  53. package/dist/dashboard/public/assets/GraphQLPage-Cft-KFpI.js +6 -0
  54. package/dist/dashboard/public/assets/HttpClientDetailView-qU0JPxsC.js +1 -0
  55. package/dist/dashboard/public/assets/HttpClientPage-Kxa5nm75.js +1 -0
  56. package/dist/dashboard/public/assets/JobDetailView-BfAICIc4.js +6 -0
  57. package/dist/dashboard/public/assets/JobsPage-BpBk0bYd.js +1 -0
  58. package/dist/dashboard/public/assets/LogDetailView-CdSLEf4Q.js +1 -0
  59. package/dist/dashboard/public/assets/LogsPage-CaCtKQZ0.js +1 -0
  60. package/dist/dashboard/public/assets/MailDetailView-BiBUkOXW.js +9 -0
  61. package/dist/dashboard/public/assets/MailPage-DAkydOVp.js +1 -0
  62. package/dist/dashboard/public/assets/ModelDetailView-CXCgDnpy.js +1 -0
  63. package/dist/dashboard/public/assets/ModelsPage-BwK3r0-I.js +1 -0
  64. package/dist/dashboard/public/assets/NotificationDetailView-Bljgzgiz.js +1 -0
  65. package/dist/dashboard/public/assets/NotificationsPage-DMGpuTU-.js +1 -0
  66. package/dist/dashboard/public/assets/PageHeader-BAc6Jvef.js +1 -0
  67. package/dist/dashboard/public/assets/QueriesPage-DPls44cD.js +1 -0
  68. package/dist/dashboard/public/assets/QueryDetailView-BEwgxDtv.js +29 -0
  69. package/dist/dashboard/public/assets/RedisDetailView-Ds3Hzc8m.js +1 -0
  70. package/dist/dashboard/public/assets/RedisPage-DhAhXwAd.js +1 -0
  71. package/dist/dashboard/public/assets/RequestDetailView-BwTcMKOH.js +1 -0
  72. package/dist/dashboard/public/assets/RequestsPage-CIHqEF5P.js +1 -0
  73. package/dist/dashboard/public/assets/ScheduleDetailView-2RmRtcvM.js +1 -0
  74. package/dist/dashboard/public/assets/SchedulePage-D3MuXtV1.js +1 -0
  75. package/dist/dashboard/public/assets/UserCard-Cbu0ICp6.js +1 -0
  76. package/dist/dashboard/public/assets/ViewDetailView-rCONPvjG.js +1 -0
  77. package/dist/dashboard/public/assets/ViewsPage-CW5aN_D5.js +1 -0
  78. package/dist/dashboard/public/assets/badgeColors-DQ_P_DOX.js +1 -0
  79. package/dist/dashboard/public/assets/{calendar-DOXgQvoy.js → calendar-DcK1CETU.js} +1 -1
  80. package/dist/dashboard/public/assets/circle-alert-CgZfn5uS.js +6 -0
  81. package/dist/dashboard/public/assets/{circle-check-big-Bs8iwE6r.js → circle-check-big-1S8vooWx.js} +1 -1
  82. package/dist/dashboard/public/assets/circle-x-BOe5goDy.js +6 -0
  83. package/dist/dashboard/public/assets/{eye-BjAVlTOb.js → eye-PnSIQ7GH.js} +1 -1
  84. package/dist/dashboard/public/assets/index-B9BCPNKv.css +1 -0
  85. package/dist/dashboard/public/assets/index-DyvNu-oR.js +361 -0
  86. package/dist/dashboard/public/assets/{search-0RwEOnAF.js → search-D9V4itpU.js} +1 -1
  87. package/dist/dashboard/public/assets/send-DOt7lNQl.js +6 -0
  88. package/dist/dashboard/public/assets/timer-CZxO8Y_Q.js +6 -0
  89. package/dist/dashboard/public/assets/types-DZUckfsW.js +1 -0
  90. package/dist/dashboard/public/assets/users-9cJRsfQV.js +6 -0
  91. package/dist/dashboard/public/assets/{zap-ozodPZ3e.js → zap-B0E2zzJ8.js} +1 -1
  92. package/dist/dashboard/public/index.html +2 -2
  93. package/dist/nestlens.config.d.ts +0 -13
  94. package/dist/nestlens.module.js +13 -0
  95. package/dist/watchers/query/types.d.ts +0 -5
  96. package/dist/watchers/query/types.js +0 -13
  97. package/package.json +51 -10
  98. package/dist/api/dto/filters/batch-filters.dto.d.ts +0 -4
  99. package/dist/api/dto/filters/batch-filters.dto.js +0 -31
  100. package/dist/api/dto/filters/cache-filters.dto.d.ts +0 -3
  101. package/dist/api/dto/filters/cache-filters.dto.js +0 -24
  102. package/dist/api/dto/filters/command-filters.dto.d.ts +0 -4
  103. package/dist/api/dto/filters/command-filters.dto.js +0 -31
  104. package/dist/api/dto/filters/common-filters.dto.d.ts +0 -4
  105. package/dist/api/dto/filters/common-filters.dto.js +0 -29
  106. package/dist/api/dto/filters/dump-filters.dto.d.ts +0 -5
  107. package/dist/api/dto/filters/dump-filters.dto.js +0 -38
  108. package/dist/api/dto/filters/event-filters.dto.d.ts +0 -3
  109. package/dist/api/dto/filters/event-filters.dto.js +0 -24
  110. package/dist/api/dto/filters/exception-filters.dto.d.ts +0 -4
  111. package/dist/api/dto/filters/exception-filters.dto.js +0 -30
  112. package/dist/api/dto/filters/gate-filters.dto.d.ts +0 -4
  113. package/dist/api/dto/filters/gate-filters.dto.js +0 -31
  114. package/dist/api/dto/filters/graphql-filters.dto.d.ts +0 -6
  115. package/dist/api/dto/filters/graphql-filters.dto.js +0 -43
  116. package/dist/api/dto/filters/http-client-filters.dto.d.ts +0 -6
  117. package/dist/api/dto/filters/http-client-filters.dto.js +0 -10
  118. package/dist/api/dto/filters/index.d.ts +0 -20
  119. package/dist/api/dto/filters/index.js +0 -36
  120. package/dist/api/dto/filters/job-filters.dto.d.ts +0 -5
  121. package/dist/api/dto/filters/job-filters.dto.js +0 -38
  122. package/dist/api/dto/filters/log-filters.dto.d.ts +0 -4
  123. package/dist/api/dto/filters/log-filters.dto.js +0 -31
  124. package/dist/api/dto/filters/mail-filters.dto.d.ts +0 -3
  125. package/dist/api/dto/filters/mail-filters.dto.js +0 -24
  126. package/dist/api/dto/filters/model-filters.dto.d.ts +0 -5
  127. package/dist/api/dto/filters/model-filters.dto.js +0 -38
  128. package/dist/api/dto/filters/notification-filters.dto.d.ts +0 -4
  129. package/dist/api/dto/filters/notification-filters.dto.js +0 -31
  130. package/dist/api/dto/filters/query-filters.dto.d.ts +0 -5
  131. package/dist/api/dto/filters/query-filters.dto.js +0 -37
  132. package/dist/api/dto/filters/redis-filters.dto.d.ts +0 -4
  133. package/dist/api/dto/filters/redis-filters.dto.js +0 -31
  134. package/dist/api/dto/filters/request-filters.dto.d.ts +0 -8
  135. package/dist/api/dto/filters/request-filters.dto.js +0 -58
  136. package/dist/api/dto/filters/schedule-filters.dto.d.ts +0 -4
  137. package/dist/api/dto/filters/schedule-filters.dto.js +0 -31
  138. package/dist/api/dto/filters/view-filters.dto.d.ts +0 -4
  139. package/dist/api/dto/filters/view-filters.dto.js +0 -31
  140. package/dist/api/dto/pagination.dto.d.ts +0 -12
  141. package/dist/api/dto/pagination.dto.js +0 -81
  142. package/dist/core/input-validator.d.ts +0 -61
  143. package/dist/core/input-validator.js +0 -141
  144. package/dist/dashboard/public/assets/BatchesPage-CfKKM_7T.js +0 -1
  145. package/dist/dashboard/public/assets/CachePage-D-0-LS48.js +0 -1
  146. package/dist/dashboard/public/assets/ClickableBadge-Cm2obiA-.js +0 -1
  147. package/dist/dashboard/public/assets/CommandsPage-Kt35tHzp.js +0 -1
  148. package/dist/dashboard/public/assets/DumpsPage-F6tHPx1A.js +0 -1
  149. package/dist/dashboard/public/assets/EntryDetailPage-6jAej2HO.js +0 -126
  150. package/dist/dashboard/public/assets/EntrySearchInput-DCrG1xhu.js +0 -1
  151. package/dist/dashboard/public/assets/EventsPage-fh4ucpAD.js +0 -1
  152. package/dist/dashboard/public/assets/ExceptionsPage-CUUHUqmB.js +0 -6
  153. package/dist/dashboard/public/assets/GatesPage-CygTmC_O.js +0 -1
  154. package/dist/dashboard/public/assets/GraphQLPage-Da957Pvf.js +0 -6
  155. package/dist/dashboard/public/assets/HttpClientPage-DimC0ow-.js +0 -1
  156. package/dist/dashboard/public/assets/JobsPage-ZwD2zSMX.js +0 -1
  157. package/dist/dashboard/public/assets/LogsPage-DWgOb1ho.js +0 -1
  158. package/dist/dashboard/public/assets/MailPage-BbwcbjgO.js +0 -1
  159. package/dist/dashboard/public/assets/ModelsPage-Byl4KdOI.js +0 -1
  160. package/dist/dashboard/public/assets/NotificationsPage-DD62t7Ba.js +0 -1
  161. package/dist/dashboard/public/assets/PageHeader-CothD0Ar.js +0 -1
  162. package/dist/dashboard/public/assets/QueriesPage-Bb86qDZB.js +0 -1
  163. package/dist/dashboard/public/assets/RedisPage-DyhlhPno.js +0 -1
  164. package/dist/dashboard/public/assets/RequestsPage-BBjRdVuK.js +0 -1
  165. package/dist/dashboard/public/assets/SchedulePage-DL2d_nRi.js +0 -1
  166. package/dist/dashboard/public/assets/ViewsPage-BTnVSgHO.js +0 -1
  167. package/dist/dashboard/public/assets/index-BvhIlCeL.js +0 -361
  168. package/dist/dashboard/public/assets/index-FAG28XEI.css +0 -1
  169. package/dist/dashboard/public/assets/types-DjCa11Sv.js +0 -53
@@ -0,0 +1,20 @@
1
+ /** The encodings the dashboard can produce, best first. */
2
+ export type ContentEncoding = 'br' | 'gzip';
3
+ /**
4
+ * Below this, compression is a loss: the gzip and brotli framing costs tens of
5
+ * bytes, and a small body often comes back larger than it went in.
6
+ */
7
+ export declare const MIN_COMPRESSED_BYTES = 1024;
8
+ export declare const isCompressible: (contentType: string, byteLength: number) => boolean;
9
+ /**
10
+ * Picks the encoding to answer with, or `undefined` for the bytes as they are.
11
+ *
12
+ * `q=0` is a refusal, not a weak preference — `gzip;q=0` means the client would
13
+ * rather have the file uncompressed, and a proxy that ignores that serves a body
14
+ * the client cannot read. `*` stands in for anything not named.
15
+ *
16
+ * An equal preference is broken in brotli's favour: at the quality used here it
17
+ * is both smaller and faster to produce than gzip.
18
+ */
19
+ export declare const negotiateEncoding: (header?: string) => ContentEncoding | undefined;
20
+ export declare const compress: (payload: Buffer, encoding: ContentEncoding) => Promise<Buffer>;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compress = exports.negotiateEncoding = exports.isCompressible = exports.MIN_COMPRESSED_BYTES = void 0;
4
+ const node_zlib_1 = require("node:zlib");
5
+ const node_util_1 = require("node:util");
6
+ const brotliAsync = (0, node_util_1.promisify)(node_zlib_1.brotliCompress);
7
+ const gzipAsync = (0, node_util_1.promisify)(node_zlib_1.gzip);
8
+ const SUPPORTED = ['br', 'gzip'];
9
+ /**
10
+ * Brotli quality, chosen by measurement rather than by the default.
11
+ *
12
+ * The largest bundled chunk (452 KB of JavaScript) compresses like this:
13
+ *
14
+ * gzip level 6 106.8 KB 9.0 ms
15
+ * brotli quality 4 103.7 KB 7.8 ms
16
+ * brotli quality 5 95.7 KB 5.8 ms ← chosen
17
+ * brotli quality 6 94.1 KB 9.8 ms
18
+ * brotli quality 11 84.8 KB 614.2 ms
19
+ *
20
+ * Quality 5 is smaller *and* faster than gzip; quality 11 buys another 11 KB for
21
+ * a hundredfold cost. NestLens runs inside the application it observes, so a
22
+ * measurable stall on first load is the one thing worth avoiding — and every
23
+ * compression here also runs off the event loop, on zlib's thread pool.
24
+ */
25
+ const BROTLI_QUALITY = 5;
26
+ /**
27
+ * Below this, compression is a loss: the gzip and brotli framing costs tens of
28
+ * bytes, and a small body often comes back larger than it went in.
29
+ */
30
+ exports.MIN_COMPRESSED_BYTES = 1024;
31
+ /**
32
+ * Types whose bytes still contain redundancy.
33
+ *
34
+ * Images, fonts and archives are already compressed by their own formats —
35
+ * running them through brotli spends CPU to produce something the same size or
36
+ * slightly bigger. WOFF2 in particular is brotli internally.
37
+ */
38
+ const COMPRESSIBLE_TYPE = /^(?:text\/|application\/(?:javascript|json|manifest\+json)|image\/svg\+xml)/;
39
+ const isCompressible = (contentType, byteLength) => byteLength >= exports.MIN_COMPRESSED_BYTES && COMPRESSIBLE_TYPE.test(contentType);
40
+ exports.isCompressible = isCompressible;
41
+ /** `token;q=0.5, other` → `{ token: 0.5, other: 1 }`. */
42
+ const parsePreferences = (header) => {
43
+ const preferences = new Map();
44
+ for (const entry of header.split(',')) {
45
+ const [token, ...parameters] = entry.trim().split(';');
46
+ if (!token)
47
+ continue;
48
+ const quality = parameters
49
+ .map((parameter) => parameter.trim())
50
+ .find((parameter) => parameter.startsWith('q='));
51
+ const parsed = quality ? Number.parseFloat(quality.slice(2)) : 1;
52
+ preferences.set(token.trim().toLowerCase(), Number.isFinite(parsed) ? parsed : 0);
53
+ }
54
+ return preferences;
55
+ };
56
+ /**
57
+ * Picks the encoding to answer with, or `undefined` for the bytes as they are.
58
+ *
59
+ * `q=0` is a refusal, not a weak preference — `gzip;q=0` means the client would
60
+ * rather have the file uncompressed, and a proxy that ignores that serves a body
61
+ * the client cannot read. `*` stands in for anything not named.
62
+ *
63
+ * An equal preference is broken in brotli's favour: at the quality used here it
64
+ * is both smaller and faster to produce than gzip.
65
+ */
66
+ const negotiateEncoding = (header) => {
67
+ if (!header)
68
+ return undefined;
69
+ const preferences = parsePreferences(header);
70
+ const wildcard = preferences.get('*');
71
+ const qualityOf = (encoding) => preferences.get(encoding) ?? wildcard ?? 0;
72
+ let best;
73
+ let bestQuality = 0;
74
+ for (const encoding of SUPPORTED) {
75
+ const quality = qualityOf(encoding);
76
+ if (quality > bestQuality) {
77
+ best = encoding;
78
+ bestQuality = quality;
79
+ }
80
+ }
81
+ return best;
82
+ };
83
+ exports.negotiateEncoding = negotiateEncoding;
84
+ const compress = (payload, encoding) => encoding === 'br'
85
+ ? brotliAsync(payload, {
86
+ params: {
87
+ [node_zlib_1.constants.BROTLI_PARAM_QUALITY]: BROTLI_QUALITY,
88
+ [node_zlib_1.constants.BROTLI_PARAM_SIZE_HINT]: payload.length,
89
+ },
90
+ })
91
+ : gzipAsync(payload);
92
+ exports.compress = compress;
@@ -6,10 +6,30 @@ export declare class DashboardController {
6
6
  private readonly httpAdapterHost;
7
7
  private readonly dashboardPath;
8
8
  private readonly fileCache;
9
+ /**
10
+ * Compressed asset bodies, keyed by file and encoding.
11
+ *
12
+ * Only files read off disk are cached here. `index.html` is rebuilt per
13
+ * request with the mount point injected, and under `trustProxy` that mount
14
+ * point comes from a header — caching by its value would let a caller grow
15
+ * this map without limit. It stays below the compression threshold anyway.
16
+ */
17
+ private readonly compressedCache;
18
+ /** Bundled directories, listed once: the bundle cannot change while the process runs. */
19
+ private readonly directoryListings;
9
20
  constructor(config: NestLensConfig, applicationConfig: ApplicationConfig, httpAdapterHost: HttpAdapterHost);
10
- serveAssets(filename: string, res: unknown): void;
11
- serveStaticFile(filename: string, res: unknown): void;
12
- serveDashboard(res: unknown, forwarded?: string): void;
21
+ /**
22
+ * What a bundled file may be called.
23
+ *
24
+ * Vite emits `index-Bu05f2IL.js`, `nestlens-icon.svg` and nothing stranger.
25
+ * Checking the name before it reaches `resolve()` means a traversal attempt
26
+ * never becomes a path at all — the containment check below stays as the
27
+ * second line, not the only one.
28
+ */
29
+ private static readonly SAFE_FILENAME;
30
+ serveAssets(filename: string, res: unknown, acceptEncoding?: string): Promise<void>;
31
+ serveStaticFile(filename: string, res: unknown, acceptEncoding?: string): Promise<void>;
32
+ serveDashboard(res: unknown, forwarded?: string, acceptEncoding?: string): Promise<void>;
13
33
  /**
14
34
  * Every other path under the mount point belongs to the SPA's client-side
15
35
  * router, so it gets index.html and React decides what to render — including
@@ -21,7 +41,7 @@ export declare class DashboardController {
21
41
  * {@link SpaRouteRegistrar} replaces it with whichever form the adapter in use
22
42
  * actually wants, before Nest resolves routes.
23
43
  */
24
- serveSpaRoute(res: unknown, forwarded?: string): void;
44
+ serveSpaRoute(res: unknown, forwarded?: string, acceptEncoding?: string): Promise<void>;
25
45
  /**
26
46
  * The dashboard bundle is built once but can be mounted anywhere, so the
27
47
  * mount point is injected into `index.html` at request time: `<base>` resolves
@@ -29,7 +49,7 @@ export declare class DashboardController {
29
49
  * SPA where to put its router basename and API calls.
30
50
  */
31
51
  private sendIndexHtml;
32
- private sendFile;
52
+ private sendResolvedFile;
33
53
  /**
34
54
  * Reads a bundled file once and keeps it in memory.
35
55
  *
@@ -52,6 +72,7 @@ export declare class DashboardController {
52
72
  * response keeps NestLens's own surface out of that pipeline.
53
73
  */
54
74
  private send;
75
+ private compressed;
55
76
  /**
56
77
  * Where the dashboard actually lives, from the browser's point of view.
57
78
  *
@@ -68,6 +89,17 @@ export declare class DashboardController {
68
89
  */
69
90
  private mountPoint;
70
91
  private injectBasePath;
92
+ /**
93
+ * The name of a bundled file, or a 404.
94
+ *
95
+ * The request selects from what is on disk rather than describing a path: the
96
+ * directory is listed once, and the value returned here is the entry from
97
+ * that listing, not the string the caller sent. A traversal cannot be
98
+ * expressed, because nothing the caller writes is ever joined to a directory.
99
+ *
100
+ * The containment check below stays as the second line — this is the first.
101
+ */
102
+ private bundledFile;
71
103
  /**
72
104
  * Resolve a path inside the dashboard directory, rejecting anything that
73
105
  * escapes it (path traversal) or does not exist.
@@ -11,6 +11,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
+ var DashboardController_1;
14
15
  Object.defineProperty(exports, "__esModule", { value: true });
15
16
  exports.DashboardController = void 0;
16
17
  const common_1 = require("@nestjs/common");
@@ -20,8 +21,10 @@ const core_1 = require("@nestjs/core");
20
21
  const nestlens_config_1 = require("../nestlens.config");
21
22
  const api_guard_1 = require("./api.guard");
22
23
  const route_path_1 = require("./route-path");
24
+ const content_encoding_1 = require("./content-encoding");
23
25
  /** Set by reverse proxies that serve the application under a stripped path. */
24
26
  const FORWARDED_PREFIX_HEADER = 'x-forwarded-prefix';
27
+ const ACCEPT_ENCODING_HEADER = 'accept-encoding';
25
28
  /**
26
29
  * Cache policies for the bundled dashboard.
27
30
  *
@@ -61,24 +64,35 @@ const MIME_TYPES = {
61
64
  };
62
65
  // The prefix here is only the default; `NestLensModule.forRoot()` rewrites it
63
66
  // from `config.path` before Nest resolves routes.
64
- let DashboardController = class DashboardController {
67
+ let DashboardController = DashboardController_1 = class DashboardController {
65
68
  constructor(config, applicationConfig, httpAdapterHost) {
66
69
  this.config = config;
67
70
  this.applicationConfig = applicationConfig;
68
71
  this.httpAdapterHost = httpAdapterHost;
69
72
  this.fileCache = new Map();
73
+ /**
74
+ * Compressed asset bodies, keyed by file and encoding.
75
+ *
76
+ * Only files read off disk are cached here. `index.html` is rebuilt per
77
+ * request with the mount point injected, and under `trustProxy` that mount
78
+ * point comes from a header — caching by its value would let a caller grow
79
+ * this map without limit. It stays below the compression threshold anyway.
80
+ */
81
+ this.compressedCache = new Map();
82
+ /** Bundled directories, listed once: the bundle cannot change while the process runs. */
83
+ this.directoryListings = new Map();
70
84
  // Dashboard static files are bundled in dist/dashboard/public
71
85
  this.dashboardPath = (0, path_1.join)(__dirname, '..', 'dashboard', 'public');
72
86
  }
73
- serveAssets(filename, res) {
74
- this.sendFile(res, (0, path_1.join)('assets', filename), 'Asset not found', IMMUTABLE);
87
+ serveAssets(filename, res, acceptEncoding) {
88
+ return this.sendResolvedFile(res, this.bundledFile('assets', filename, 'Asset not found'), IMMUTABLE, acceptEncoding);
75
89
  }
76
90
  // Favicon and other root-level static files.
77
- serveStaticFile(filename, res) {
78
- this.sendFile(res, `${filename}.svg`, 'File not found', NO_CACHE);
91
+ serveStaticFile(filename, res, acceptEncoding) {
92
+ return this.sendResolvedFile(res, this.bundledFile('', `${filename}.svg`, 'File not found'), NO_CACHE, acceptEncoding);
79
93
  }
80
- serveDashboard(res, forwarded) {
81
- this.sendIndexHtml(res, forwarded);
94
+ serveDashboard(res, forwarded, acceptEncoding) {
95
+ return this.sendIndexHtml(res, forwarded, acceptEncoding);
82
96
  }
83
97
  /**
84
98
  * Every other path under the mount point belongs to the SPA's client-side
@@ -91,8 +105,8 @@ let DashboardController = class DashboardController {
91
105
  * {@link SpaRouteRegistrar} replaces it with whichever form the adapter in use
92
106
  * actually wants, before Nest resolves routes.
93
107
  */
94
- serveSpaRoute(res, forwarded) {
95
- this.sendIndexHtml(res, forwarded);
108
+ serveSpaRoute(res, forwarded, acceptEncoding) {
109
+ return this.sendIndexHtml(res, forwarded, acceptEncoding);
96
110
  }
97
111
  /**
98
112
  * The dashboard bundle is built once but can be mounted anywhere, so the
@@ -100,14 +114,13 @@ let DashboardController = class DashboardController {
100
114
  * the bundle's relative asset URLs, and `window.__NESTLENS_BASE__` tells the
101
115
  * SPA where to put its router basename and API calls.
102
116
  */
103
- sendIndexHtml(res, forwardedPrefix) {
117
+ sendIndexHtml(res, forwardedPrefix, acceptEncoding) {
104
118
  const absolutePath = this.resolveDashboardFile('index.html', 'Dashboard not found');
105
119
  const html = this.injectBasePath(this.readCached(absolutePath).toString('utf8'), forwardedPrefix);
106
- this.send(res, html, MIME_TYPES['.html'], NO_CACHE);
120
+ return this.send(res, html, MIME_TYPES['.html'], NO_CACHE, acceptEncoding);
107
121
  }
108
- sendFile(res, relativePath, notFoundMessage, cacheControl) {
109
- const absolutePath = this.resolveDashboardFile(relativePath, notFoundMessage);
110
- this.send(res, this.readCached(absolutePath), this.contentTypeFor(absolutePath), cacheControl);
122
+ sendResolvedFile(res, absolutePath, cacheControl, acceptEncoding) {
123
+ return this.send(res, this.readCached(absolutePath), this.contentTypeFor(absolutePath), cacheControl, acceptEncoding, absolutePath);
111
124
  }
112
125
  /**
113
126
  * Reads a bundled file once and keeps it in memory.
@@ -125,9 +138,18 @@ let DashboardController = class DashboardController {
125
138
  const cached = this.fileCache.get(absolutePath);
126
139
  if (cached)
127
140
  return cached;
128
- const contents = (0, fs_1.readFileSync)(absolutePath);
129
- this.fileCache.set(absolutePath, contents);
130
- return contents;
141
+ // A file that vanished after the listing was taken is a 404, not a 500:
142
+ // the bundle ships inside the package and is not supposed to move, but an
143
+ // upgrade that replaces it under a running process should not surface as a
144
+ // server error.
145
+ try {
146
+ const contents = (0, fs_1.readFileSync)(absolutePath);
147
+ this.fileCache.set(absolutePath, contents);
148
+ return contents;
149
+ }
150
+ catch {
151
+ throw new common_1.NotFoundException('File not found');
152
+ }
131
153
  }
132
154
  /**
133
155
  * Writes the response directly instead of returning it.
@@ -137,17 +159,38 @@ let DashboardController = class DashboardController {
137
159
  * this HTML into JSON — the dashboard then loads nothing. Taking over the
138
160
  * response keeps NestLens's own surface out of that pipeline.
139
161
  */
140
- send(res, body, contentType, cacheControl) {
162
+ async send(res, body, contentType, cacheControl, acceptEncoding, cacheKey) {
141
163
  const adapter = this.httpAdapterHost.httpAdapter;
142
- const payload = Buffer.isBuffer(body) ? body : Buffer.from(body, 'utf8');
164
+ const raw = Buffer.isBuffer(body) ? body : Buffer.from(body, 'utf8');
165
+ const encoding = (0, content_encoding_1.isCompressible)(contentType, raw.length)
166
+ ? (0, content_encoding_1.negotiateEncoding)(acceptEncoding)
167
+ : undefined;
168
+ const payload = encoding ? await this.compressed(raw, encoding, cacheKey) : raw;
143
169
  adapter.setHeader(res, 'Content-Type', contentType);
144
170
  adapter.setHeader(res, 'Cache-Control', cacheControl);
171
+ // Set whether or not this particular response was compressed: the body a
172
+ // shared cache stores depends on the request's Accept-Encoding either way,
173
+ // and `immutable` tells that cache to keep it for a year.
174
+ adapter.setHeader(res, 'Vary', 'Accept-Encoding');
175
+ if (encoding)
176
+ adapter.setHeader(res, 'Content-Encoding', encoding);
145
177
  // A raw Buffer cannot go through `reply()`: Express treats any object as
146
178
  // JSON and serialises it to `{"type":"Buffer","data":[...]}`, which turns
147
179
  // every script and font into garbage. StreamableFile is the shape both
148
180
  // adapters special-case for binary payloads.
149
181
  adapter.reply(res, new common_1.StreamableFile(payload, { length: payload.length }), 200);
150
182
  }
183
+ async compressed(raw, encoding, cacheKey) {
184
+ if (!cacheKey)
185
+ return (0, content_encoding_1.compress)(raw, encoding);
186
+ const key = `${cacheKey}|${encoding}`;
187
+ const cached = this.compressedCache.get(key);
188
+ if (cached)
189
+ return cached;
190
+ const compressedBody = await (0, content_encoding_1.compress)(raw, encoding);
191
+ this.compressedCache.set(key, compressedBody);
192
+ return compressedBody;
193
+ }
151
194
  /**
152
195
  * Where the dashboard actually lives, from the browser's point of view.
153
196
  *
@@ -183,6 +226,36 @@ let DashboardController = class DashboardController {
183
226
  `<script>window.__NESTLENS_BASE__=${JSON.stringify(baseHref)}</script>`;
184
227
  return html.replace('<head>', `<head>${injection}`);
185
228
  }
229
+ /**
230
+ * The name of a bundled file, or a 404.
231
+ *
232
+ * The request selects from what is on disk rather than describing a path: the
233
+ * directory is listed once, and the value returned here is the entry from
234
+ * that listing, not the string the caller sent. A traversal cannot be
235
+ * expressed, because nothing the caller writes is ever joined to a directory.
236
+ *
237
+ * The containment check below stays as the second line — this is the first.
238
+ */
239
+ bundledFile(directory, filename, notFoundMessage) {
240
+ if (!DashboardController_1.SAFE_FILENAME.test(filename) || filename.includes('..')) {
241
+ throw new common_1.NotFoundException(notFoundMessage);
242
+ }
243
+ let listing = this.directoryListings.get(directory);
244
+ if (!listing) {
245
+ const root = (0, path_1.resolve)(this.dashboardPath);
246
+ const absoluteDirectory = directory === '' ? root : (0, path_1.join)(root, directory);
247
+ listing = new Map(((0, fs_1.existsSync)(absoluteDirectory) ? (0, fs_1.readdirSync)(absoluteDirectory) : []).map((name) => [
248
+ name,
249
+ (0, path_1.join)(absoluteDirectory, name),
250
+ ]));
251
+ this.directoryListings.set(directory, listing);
252
+ }
253
+ const found = listing.get(filename);
254
+ if (!found) {
255
+ throw new common_1.NotFoundException(notFoundMessage);
256
+ }
257
+ return found;
258
+ }
186
259
  /**
187
260
  * Resolve a path inside the dashboard directory, rejecting anything that
188
261
  * escapes it (path traversal) or does not exist.
@@ -203,39 +276,52 @@ let DashboardController = class DashboardController {
203
276
  }
204
277
  };
205
278
  exports.DashboardController = DashboardController;
279
+ /**
280
+ * What a bundled file may be called.
281
+ *
282
+ * Vite emits `index-Bu05f2IL.js`, `nestlens-icon.svg` and nothing stranger.
283
+ * Checking the name before it reaches `resolve()` means a traversal attempt
284
+ * never becomes a path at all — the containment check below stays as the
285
+ * second line, not the only one.
286
+ */
287
+ DashboardController.SAFE_FILENAME = /^[A-Za-z0-9._-]+$/;
206
288
  __decorate([
207
289
  (0, common_1.Get)('assets/:filename'),
208
290
  __param(0, (0, common_1.Param)('filename')),
209
291
  __param(1, (0, common_1.Res)()),
292
+ __param(2, (0, common_1.Headers)(ACCEPT_ENCODING_HEADER)),
210
293
  __metadata("design:type", Function),
211
- __metadata("design:paramtypes", [String, Object]),
212
- __metadata("design:returntype", void 0)
294
+ __metadata("design:paramtypes", [String, Object, String]),
295
+ __metadata("design:returntype", Promise)
213
296
  ], DashboardController.prototype, "serveAssets", null);
214
297
  __decorate([
215
298
  (0, common_1.Get)(':filename.svg'),
216
299
  __param(0, (0, common_1.Param)('filename')),
217
300
  __param(1, (0, common_1.Res)()),
301
+ __param(2, (0, common_1.Headers)(ACCEPT_ENCODING_HEADER)),
218
302
  __metadata("design:type", Function),
219
- __metadata("design:paramtypes", [String, Object]),
220
- __metadata("design:returntype", void 0)
303
+ __metadata("design:paramtypes", [String, Object, String]),
304
+ __metadata("design:returntype", Promise)
221
305
  ], DashboardController.prototype, "serveStaticFile", null);
222
306
  __decorate([
223
307
  (0, common_1.Get)(),
224
308
  __param(0, (0, common_1.Res)()),
225
309
  __param(1, (0, common_1.Headers)(FORWARDED_PREFIX_HEADER)),
310
+ __param(2, (0, common_1.Headers)(ACCEPT_ENCODING_HEADER)),
226
311
  __metadata("design:type", Function),
227
- __metadata("design:paramtypes", [Object, String]),
228
- __metadata("design:returntype", void 0)
312
+ __metadata("design:paramtypes", [Object, String, String]),
313
+ __metadata("design:returntype", Promise)
229
314
  ], DashboardController.prototype, "serveDashboard", null);
230
315
  __decorate([
231
316
  (0, common_1.Get)('*'),
232
317
  __param(0, (0, common_1.Res)()),
233
318
  __param(1, (0, common_1.Headers)(FORWARDED_PREFIX_HEADER)),
319
+ __param(2, (0, common_1.Headers)(ACCEPT_ENCODING_HEADER)),
234
320
  __metadata("design:type", Function),
235
- __metadata("design:paramtypes", [Object, String]),
236
- __metadata("design:returntype", void 0)
321
+ __metadata("design:paramtypes", [Object, String, String]),
322
+ __metadata("design:returntype", Promise)
237
323
  ], DashboardController.prototype, "serveSpaRoute", null);
238
- exports.DashboardController = DashboardController = __decorate([
324
+ exports.DashboardController = DashboardController = DashboardController_1 = __decorate([
239
325
  (0, common_1.Controller)('nestlens'),
240
326
  (0, common_1.UseGuards)(api_guard_1.NestLensGuard),
241
327
  __param(0, (0, common_1.Inject)(nestlens_config_1.NESTLENS_CONFIG)),
@@ -68,11 +68,3 @@ export interface CursorPaginatedApiResponse<T> extends ApiResponse<T[]> {
68
68
  };
69
69
  };
70
70
  }
71
- /**
72
- * Helper to create a success response.
73
- */
74
- export declare function createSuccessResponse<T>(data: T, meta?: Partial<ResponseMeta>): ApiResponse<T>;
75
- /**
76
- * Helper to create an error response.
77
- */
78
- export declare function createErrorResponse(code: ErrorCode, message: string, details?: Record<string, unknown>): ApiResponse<null>;
@@ -1,35 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createSuccessResponse = createSuccessResponse;
4
- exports.createErrorResponse = createErrorResponse;
5
- /**
6
- * Helper to create a success response.
7
- */
8
- function createSuccessResponse(data, meta) {
9
- return {
10
- success: true,
11
- data,
12
- error: null,
13
- meta: {
14
- timestamp: new Date().toISOString(),
15
- ...meta,
16
- },
17
- };
18
- }
19
- /**
20
- * Helper to create an error response.
21
- */
22
- function createErrorResponse(code, message, details) {
23
- return {
24
- success: false,
25
- data: null,
26
- error: {
27
- code,
28
- message,
29
- details,
30
- },
31
- meta: {
32
- timestamp: new Date().toISOString(),
33
- },
34
- };
35
- }
@@ -52,6 +52,11 @@ export declare class CursorQueryDto {
52
52
  hasErrors?: boolean;
53
53
  hasN1?: boolean;
54
54
  tags?: string[];
55
+ /**
56
+ * Capped for the same reason the filter arrays are: every entry's payload is
57
+ * stringified and searched, and `security.validation.maxSearchLength` was
58
+ * documented while nothing enforced it.
59
+ */
55
60
  search?: string;
56
61
  /**
57
62
  * Keys that are pagination params (not filters)
@@ -347,5 +347,6 @@ __decorate([
347
347
  __decorate([
348
348
  (0, class_validator_1.IsOptional)(),
349
349
  (0, class_validator_1.IsString)(),
350
+ (0, class_validator_1.MaxLength)(transformers_1.MAX_SEARCH_LENGTH),
350
351
  __metadata("design:type", String)
351
352
  ], CursorQueryDto.prototype, "search", void 0);
@@ -1,7 +1,5 @@
1
- export * from './pagination.dto';
2
1
  export * from './cursor-query.dto';
3
2
  export * from './transformers';
4
- export * from './filters';
5
3
  export * from './api-response.dto';
6
4
  export * from './recording.dto';
7
5
  export * from './tags.dto';
@@ -14,10 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./pagination.dto"), exports);
18
17
  __exportStar(require("./cursor-query.dto"), exports);
19
18
  __exportStar(require("./transformers"), exports);
20
- __exportStar(require("./filters"), exports);
21
19
  __exportStar(require("./api-response.dto"), exports);
22
20
  __exportStar(require("./recording.dto"), exports);
23
21
  __exportStar(require("./tags.dto"), exports);
@@ -31,10 +31,6 @@ export declare function TransformToInt(options?: {
31
31
  * Transforms limit query parameter with bounds
32
32
  */
33
33
  export declare function TransformLimit(): PropertyDecorator;
34
- /**
35
- * Transforms offset query parameter
36
- */
37
- export declare function TransformOffset(): PropertyDecorator;
38
34
  /**
39
35
  * Transforms sequence number for cursor pagination
40
36
  */
@@ -6,7 +6,6 @@ exports.TransformCommaSeparatedNumbersOrErr = TransformCommaSeparatedNumbersOrEr
6
6
  exports.TransformStringToBoolean = TransformStringToBoolean;
7
7
  exports.TransformToInt = TransformToInt;
8
8
  exports.TransformLimit = TransformLimit;
9
- exports.TransformOffset = TransformOffset;
10
9
  exports.TransformSequence = TransformSequence;
11
10
  const class_transformer_1 = require("class-transformer");
12
11
  /**
@@ -84,12 +83,6 @@ function TransformToInt(options) {
84
83
  function TransformLimit() {
85
84
  return TransformToInt({ min: 1, max: exports.MAX_LIMIT, default: exports.DEFAULT_LIMIT });
86
85
  }
87
- /**
88
- * Transforms offset query parameter
89
- */
90
- function TransformOffset() {
91
- return TransformToInt({ min: 0, default: 0 });
92
- }
93
86
  /**
94
87
  * Transforms sequence number for cursor pagination
95
88
  */
@@ -19,6 +19,18 @@ import { ValidationOptions } from 'class-validator';
19
19
  * Accepts a comma-separated string (raw query param) or an array of strings
20
20
  * (after TransformCommaSeparatedArray has run).
21
21
  */
22
+ /**
23
+ * How many values one filter may carry.
24
+ *
25
+ * Documented under `security.validation.maxFilterArrayLength` and enforced
26
+ * nowhere: a request asking for two thousand statuses was answered, and every
27
+ * value becomes another `IN` placeholder or another comparison per entry. The
28
+ * limit lives with the validators the filters already run through, so it covers
29
+ * every filter field at once rather than one decorator at a time.
30
+ */
31
+ export declare const MAX_FILTER_VALUES = 100;
32
+ /** How long a search term may be, for the same reason. */
33
+ export declare const MAX_SEARCH_LENGTH = 500;
22
34
  export declare function IsCommaSeparatedStrings(validationOptions?: ValidationOptions): PropertyDecorator;
23
35
  /**
24
36
  * Accepts a comma-separated string (raw query param) or an array
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MAX_SEARCH_LENGTH = exports.MAX_FILTER_VALUES = void 0;
3
4
  exports.IsCommaSeparatedStrings = IsCommaSeparatedStrings;
4
5
  exports.IsCommaSeparatedList = IsCommaSeparatedList;
5
6
  exports.IsBooleanLike = IsBooleanLike;
@@ -24,13 +25,28 @@ const class_validator_1 = require("class-validator");
24
25
  * Accepts a comma-separated string (raw query param) or an array of strings
25
26
  * (after TransformCommaSeparatedArray has run).
26
27
  */
28
+ /**
29
+ * How many values one filter may carry.
30
+ *
31
+ * Documented under `security.validation.maxFilterArrayLength` and enforced
32
+ * nowhere: a request asking for two thousand statuses was answered, and every
33
+ * value becomes another `IN` placeholder or another comparison per entry. The
34
+ * limit lives with the validators the filters already run through, so it covers
35
+ * every filter field at once rather than one decorator at a time.
36
+ */
37
+ exports.MAX_FILTER_VALUES = 100;
38
+ /** How long a search term may be, for the same reason. */
39
+ exports.MAX_SEARCH_LENGTH = 500;
40
+ const withinFilterLimit = (value) => !Array.isArray(value) || value.length <= exports.MAX_FILTER_VALUES;
27
41
  function IsCommaSeparatedStrings(validationOptions) {
28
42
  return (0, class_validator_1.ValidateBy)({
29
43
  name: 'isCommaSeparatedStrings',
30
44
  validator: {
31
- validate: (value) => typeof value === 'string' ||
32
- (Array.isArray(value) && value.every((item) => typeof item === 'string')),
33
- defaultMessage: (0, class_validator_1.buildMessage)((eachPrefix) => `${eachPrefix}$property must be a comma-separated string or an array of strings`, validationOptions),
45
+ validate: (value) => withinFilterLimit(value) &&
46
+ (typeof value === 'string' ||
47
+ (Array.isArray(value) && value.every((item) => typeof item === 'string'))),
48
+ defaultMessage: (0, class_validator_1.buildMessage)((eachPrefix) => `${eachPrefix}$property must be a comma-separated string or an array of strings, ` +
49
+ `with at most ${exports.MAX_FILTER_VALUES} values`, validationOptions),
34
50
  },
35
51
  }, validationOptions);
36
52
  }
@@ -42,8 +58,9 @@ function IsCommaSeparatedList(validationOptions) {
42
58
  return (0, class_validator_1.ValidateBy)({
43
59
  name: 'isCommaSeparatedList',
44
60
  validator: {
45
- validate: (value) => typeof value === 'string' || Array.isArray(value),
46
- defaultMessage: (0, class_validator_1.buildMessage)((eachPrefix) => `${eachPrefix}$property must be a comma-separated string or an array`, validationOptions),
61
+ validate: (value) => withinFilterLimit(value) && (typeof value === 'string' || Array.isArray(value)),
62
+ defaultMessage: (0, class_validator_1.buildMessage)((eachPrefix) => `${eachPrefix}$property must be a comma-separated string or an array, ` +
63
+ `with at most ${exports.MAX_FILTER_VALUES} values`, validationOptions),
47
64
  },
48
65
  }, validationOptions);
49
66
  }