@forinda/kickjs-devtools 1.6.0 → 1.7.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/dist/adapter.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type AppAdapter, type AdapterMiddleware, type Container, type Ref, type ComputedRef } from '@forinda/kickjs-core';
1
+ import { type AppAdapter, type AdapterContext, type AdapterMiddleware, type Ref, type ComputedRef } from '@forinda/kickjs-core';
2
2
  /** Per-route latency stats */
3
3
  interface RouteStats {
4
4
  count: number;
@@ -97,10 +97,10 @@ export declare class DevToolsAdapter implements AppAdapter {
97
97
  * constructor-provided refs.
98
98
  */
99
99
  private getPeerAdapters;
100
- beforeMount(app: any, container: Container): void;
100
+ beforeMount({ app, container }: AdapterContext): void;
101
101
  middleware(): AdapterMiddleware[];
102
102
  onRouteMount(controllerClass: any, mountPath: string): void;
103
- afterStart(_server: any, _container: Container): void;
103
+ afterStart({}: AdapterContext): void;
104
104
  shutdown(): void;
105
105
  /** Find the public/devtools directory relative to the built dist or source */
106
106
  private resolvePublicDir;
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,SAAS,EAOd,KAAK,GAAG,EACR,KAAK,WAAW,EACjB,MAAM,sBAAsB,CAAA;AAa7B,8BAA8B;AAC9B,UAAU,UAAU;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,eAAe;IAC9B,yDAAyD;IACzD,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,qFAAqF;IACrF,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,mFAAmF;IACnF,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB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B;IAmDzC;;;;OAIG;IACH,OAAO,CAAC,eAAe;IAQvB,WAAW,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,cAAc,GAAG,IAAI;IA4JrD,UAAU,IAAI,iBAAiB,EAAE;IAuCjC,YAAY,CAAC,eAAe,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IA8B3D,UAAU,CAAC,EAAE,EAAE,cAAc,GAAG,IAAI;IAQpC,QAAQ,IAAI,IAAI;IAKhB,8EAA8E;IAC9E,OAAO,CAAC,gBAAgB;CAYzB"}
package/dist/index.js CHANGED
@@ -26,40 +26,40 @@ var h = S("DevTools"), j = class {
26
26
  adapterStatuses = {};
27
27
  stopErrorWatch = null;
28
28
  peerAdapters = [];
29
- constructor(r = {}) {
30
- if (this.basePath = r.basePath ?? "/_debug", this.enabled = r.enabled ?? process.env.NODE_ENV !== "production", this.exposeConfig = r.exposeConfig ?? !1, this.configPrefixes = r.configPrefixes ?? ["APP_", "NODE_ENV"], this.errorRateThreshold = r.errorRateThreshold ?? 0.5, this.peerAdapters = r.adapters ?? [], r.secret === !1 ? this.secret = !1 : r.secret ? this.secret = r.secret : this.secret = D(16).toString("hex"), this.requestCount = l(0), this.errorCount = l(0), this.clientErrorCount = l(0), this.startedAt = l(Date.now()), this.routeLatency = C({}), this.errorRate = p(() => this.requestCount.value > 0 ? this.errorCount.value / this.requestCount.value : 0), this.uptimeSeconds = p(() => Math.floor((Date.now() - this.startedAt.value) / 1e3)), r.onErrorRateExceeded) {
31
- const n = r.onErrorRateExceeded, s = this.errorRateThreshold;
29
+ constructor(s = {}) {
30
+ if (this.basePath = s.basePath ?? "/_debug", this.enabled = s.enabled ?? process.env.NODE_ENV !== "production", this.exposeConfig = s.exposeConfig ?? !1, this.configPrefixes = s.configPrefixes ?? ["APP_", "NODE_ENV"], this.errorRateThreshold = s.errorRateThreshold ?? 0.5, this.peerAdapters = s.adapters ?? [], s.secret === !1 ? this.secret = !1 : s.secret ? this.secret = s.secret : this.secret = D(16).toString("hex"), this.requestCount = l(0), this.errorCount = l(0), this.clientErrorCount = l(0), this.startedAt = l(Date.now()), this.routeLatency = C({}), this.errorRate = p(() => this.requestCount.value > 0 ? this.errorCount.value / this.requestCount.value : 0), this.uptimeSeconds = p(() => Math.floor((Date.now() - this.startedAt.value) / 1e3)), s.onErrorRateExceeded) {
31
+ const n = s.onErrorRateExceeded, r = this.errorRateThreshold;
32
32
  this.stopErrorWatch = m(this.errorRate, (i) => {
33
- i > s && n(i);
33
+ i > r && n(i);
34
34
  });
35
35
  } else this.stopErrorWatch = m(this.errorRate, (n) => {
36
36
  n > this.errorRateThreshold && h.warn(`Error rate elevated: ${(n * 100).toFixed(1)}%`);
37
37
  });
38
38
  }
39
39
  getPeerAdapters() {
40
- const r = this.appRef?.__kickApp;
41
- return r && typeof r.getAdapters == "function" ? r.getAdapters() : this.peerAdapters;
40
+ const s = this.appRef?.__kickApp;
41
+ return s && typeof s.getAdapters == "function" ? s.getAdapters() : this.peerAdapters;
42
42
  }
43
- beforeMount(r, n) {
43
+ beforeMount({ app: s, container: n }) {
44
44
  if (!this.enabled) return;
45
- this.appRef = r, this.container = n, this.startedAt.value = Date.now(), this.routes = [], this.adapterStatuses[this.name] = "running";
46
- const s = v();
45
+ this.appRef = s, this.container = n, this.startedAt.value = Date.now(), this.routes = [], this.adapterStatuses[this.name] = "running";
46
+ const r = v();
47
47
  if (this.secret !== !1) {
48
48
  const o = this.secret;
49
- s.use((e, t, a) => {
49
+ r.use((e, t, a) => {
50
50
  if ((e.headers["x-devtools-token"] ?? e.query?.token) === o || e.path === "/" && e.method === "GET" && !e.query?.token || e.path.endsWith(".js") || e.path.endsWith(".css")) return a();
51
51
  t.status(403).json({ error: "Forbidden — invalid or missing devtools token" });
52
52
  });
53
53
  }
54
- s.get("/routes", (o, e) => {
54
+ r.get("/routes", (o, e) => {
55
55
  e.json({ routes: this.routes });
56
- }), s.get("/container", (o, e) => {
56
+ }), r.get("/container", (o, e) => {
57
57
  const t = this.container?.getRegistrations() ?? [];
58
58
  e.json({
59
59
  registrations: t,
60
60
  count: t.length
61
61
  });
62
- }), s.get("/metrics", (o, e) => {
62
+ }), r.get("/metrics", (o, e) => {
63
63
  e.json({
64
64
  requests: this.requestCount.value,
65
65
  serverErrors: this.errorCount.value,
@@ -69,7 +69,7 @@ var h = S("DevTools"), j = class {
69
69
  startedAt: new Date(this.startedAt.value).toISOString(),
70
70
  routeLatency: this.routeLatency
71
71
  });
72
- }), s.get("/health", (o, e) => {
72
+ }), r.get("/health", (o, e) => {
73
73
  const t = this.errorRate.value < this.errorRateThreshold, a = t ? "healthy" : "degraded";
74
74
  e.status(t ? 200 : 503).json({
75
75
  status: a,
@@ -77,7 +77,7 @@ var h = S("DevTools"), j = class {
77
77
  uptime: this.uptimeSeconds.value,
78
78
  adapters: this.adapterStatuses
79
79
  });
80
- }), s.get("/state", (o, e) => {
80
+ }), r.get("/state", (o, e) => {
81
81
  const t = this.getPeerAdapters().find((a) => a.name === "WsAdapter" && typeof a.getStats == "function");
82
82
  e.json({
83
83
  reactive: {
@@ -93,7 +93,7 @@ var h = S("DevTools"), j = class {
93
93
  routeLatency: this.routeLatency,
94
94
  ...t ? { ws: t.getStats() } : {}
95
95
  });
96
- }), s.get("/ws", (o, e) => {
96
+ }), r.get("/ws", (o, e) => {
97
97
  const t = this.getPeerAdapters().find((a) => a.name === "WsAdapter" && typeof a.getStats == "function");
98
98
  if (!t) {
99
99
  e.json({
@@ -106,7 +106,7 @@ var h = S("DevTools"), j = class {
106
106
  enabled: !0,
107
107
  ...t.getStats()
108
108
  });
109
- }), s.get("/queues", async (o, e) => {
109
+ }), r.get("/queues", async (o, e) => {
110
110
  const t = this.getPeerAdapters().find((a) => a.name === "QueueAdapter" && typeof a.getQueueNames == "function");
111
111
  if (!t) {
112
112
  e.json({
@@ -135,7 +135,7 @@ var h = S("DevTools"), j = class {
135
135
  error: "Failed to fetch queue stats"
136
136
  });
137
137
  }
138
- }), this.exposeConfig && s.get("/config", (o, e) => {
138
+ }), this.exposeConfig && r.get("/config", (o, e) => {
139
139
  const t = {};
140
140
  for (const [a, u] of Object.entries(process.env))
141
141
  u !== void 0 && (t[a] = this.configPrefixes.some((d) => a.startsWith(d)) ? u : "[REDACTED]");
@@ -143,24 +143,24 @@ var h = S("DevTools"), j = class {
143
143
  });
144
144
  const i = this.resolvePublicDir();
145
145
  if (i) {
146
- s.use(A(i));
146
+ r.use(A(i));
147
147
  const o = E(c(i, "index.html"), "utf-8");
148
- s.get("/", (e, t) => {
148
+ r.get("/", (e, t) => {
149
149
  const a = o.replace("<body", `<body data-base="${this.basePath}"`);
150
150
  t.type("html").send(a);
151
151
  });
152
- } else s.get("/", (o, e) => {
152
+ } else r.get("/", (o, e) => {
153
153
  e.type("html").send("<h1>DevTools: public directory not found</h1>");
154
154
  });
155
- r.use(this.basePath, s), this.secret ? (h.info(`DevTools mounted at ${this.basePath} [token: ${this.secret}]`), h.info(`Access: ${this.basePath}?token=${this.secret}`)) : h.info(`DevTools mounted at ${this.basePath} [no guard]`);
155
+ s.use(this.basePath, r), this.secret ? (h.info(`DevTools mounted at ${this.basePath} [token: ${this.secret}]`), h.info(`Access: ${this.basePath}?token=${this.secret}`)) : h.info(`DevTools mounted at ${this.basePath} [no guard]`);
156
156
  }
157
157
  middleware() {
158
158
  return this.enabled ? [{
159
- handler: (r, n, s) => {
159
+ handler: (s, n, r) => {
160
160
  const i = Date.now();
161
161
  this.requestCount.value++, n.on("finish", () => {
162
162
  n.statusCode >= 500 ? this.errorCount.value++ : n.statusCode >= 400 && this.clientErrorCount.value++;
163
- const o = `${r.method} ${r.route?.path ?? r.path}`, e = Date.now() - i;
163
+ const o = `${s.method} ${s.route?.path ?? s.path}`, e = Date.now() - i;
164
164
  this.routeLatency[o] || (this.routeLatency[o] = {
165
165
  count: 0,
166
166
  totalMs: 0,
@@ -169,34 +169,34 @@ var h = S("DevTools"), j = class {
169
169
  });
170
170
  const t = this.routeLatency[o];
171
171
  t.count++, t.totalMs += e, t.minMs = Math.min(t.minMs, e), t.maxMs = Math.max(t.maxMs, e);
172
- }), s();
172
+ }), r();
173
173
  },
174
174
  phase: "beforeGlobal"
175
175
  }] : [];
176
176
  }
177
- onRouteMount(r, n) {
177
+ onRouteMount(s, n) {
178
178
  if (!this.enabled) return;
179
- const s = Reflect.getMetadata(f.ROUTES, r) ?? [], i = Reflect.getMetadata(f.CLASS_MIDDLEWARES, r) ?? [];
180
- for (const o of s) {
181
- const e = Reflect.getMetadata(f.METHOD_MIDDLEWARES, r.prototype, o.handlerName) ?? [];
179
+ const r = Reflect.getMetadata(f.ROUTES, s) ?? [], i = Reflect.getMetadata(f.CLASS_MIDDLEWARES, s) ?? [];
180
+ for (const o of r) {
181
+ const e = Reflect.getMetadata(f.METHOD_MIDDLEWARES, s.prototype, o.handlerName) ?? [];
182
182
  this.routes.push({
183
183
  method: o.method.toUpperCase(),
184
184
  path: `${n}${o.path === "/" ? "" : o.path}`,
185
- controller: r.name,
185
+ controller: s.name,
186
186
  handler: o.handlerName,
187
187
  middleware: [...i.map((t) => t.name || "anonymous"), ...e.map((t) => t.name || "anonymous")]
188
188
  });
189
189
  }
190
190
  }
191
- afterStart(r, n) {
191
+ afterStart({}) {
192
192
  this.enabled && h.info(`DevTools ready — ${this.routes.length} routes tracked, ${this.container?.getRegistrations().length ?? 0} DI bindings`);
193
193
  }
194
194
  shutdown() {
195
195
  this.stopErrorWatch?.(), this.adapterStatuses[this.name] = "stopped";
196
196
  }
197
197
  resolvePublicDir() {
198
- const r = b(R(import.meta.url)), n = [c(r, "..", "public", "devtools"), c(r, "..", "..", "public", "devtools")];
199
- for (const s of n) if (y(c(s, "index.html"))) return s;
198
+ const s = b(R(import.meta.url)), n = [c(s, "..", "public", "devtools"), c(s, "..", "..", "public", "devtools")];
199
+ for (const r of n) if (y(c(r, "index.html"))) return r;
200
200
  return null;
201
201
  }
202
202
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forinda/kickjs-devtools",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "Development introspection dashboard for KickJS — routes, DI container, metrics, health",
5
5
  "keywords": [
6
6
  "kickjs",
@@ -53,7 +53,7 @@
53
53
  ],
54
54
  "dependencies": {
55
55
  "reflect-metadata": "^0.2.2",
56
- "@forinda/kickjs-core": "1.6.0"
56
+ "@forinda/kickjs-core": "1.7.0"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "express": "^5.1.0"