@singhak/nodeui-core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # @singhak/nodeui-core
2
+
3
+ Framework-neutral engine for the NodeUI developer console: observability
4
+ providers, the REST contract, the safety gate, and the static console server.
5
+ The Express and NestJS adapters build on this package; you normally consume
6
+ those instead of using `@singhak/nodeui-core` directly.
7
+
8
+ ## Providers
9
+
10
+ Each provider exposes one panel through `GET {path}/api/{id}`:
11
+
12
+ | id | Panel | Notes |
13
+ | --------------- | -------------- | ------------------------------------------------ |
14
+ | `health` | Health | Derives status from event-loop + memory samples. |
15
+ | `memory` | Memory | Samples process + OS memory on start. |
16
+ | `cpu` | CPU | Process CPU percent from `/proc`-style clocks. |
17
+ | `event-loop` | Event-loop lag | Drift vs. a 1ms `setInterval`, last 600 samples. |
18
+ | `heap-snapshot` | Heap snapshot | Writes `nodeui-heap-<pid>-<ts>.heapsnapshot`. |
19
+ | `startup` | Startup | Timing marks recorded via `server.mark(name)`. |
20
+ | `requests` | Requests | Ring buffer of app HTTP requests (default 500). |
21
+
22
+ ## API
23
+
24
+ All endpoints live under `{path}/api` and return
25
+ `{ ok: true, data } | { ok: false, error: { code, message } }`:
26
+
27
+ - `GET /config` — effective configuration.
28
+ - `GET /{provider-id}` — panel data for the seven ids above.
29
+ - `POST /confirmations` — issue a single-use nonce.
30
+ - `POST /heap-snapshot` — capture a snapshot; must send
31
+ `x-nodeui-confirm: <nonce>` from a fresh confirmation. A missing, expired, or
32
+ replayed nonce returns `409` with error code `confirmation-required`.
33
+
34
+ `GET /` serves the bundled React console with an SPA fallback to `index.html`.
35
+
36
+ ## Safety
37
+
38
+ - **Activation:** active when `NODE_ENV` is non-production, or when
39
+ `NODEUI_ENABLED=true` forces it; fail-closed in production.
40
+ - **Loopback-only:** remote hosts are rejected with `403`.
41
+ - **Secret masking:** keys matching `TOKEN|KEY|SECRET|PASSWORD` have their
42
+ values replaced with `[REDACTED]` in every API payload.
43
+ - **Read-only default:** the heap snapshot is the only mutating action and is
44
+ gated behind a fresh nonce.
45
+ - **Zero-cost when disabled:** the middleware is a pass-through; no timers or
46
+ hooks are created.
47
+
48
+ ## Configuration
49
+
50
+ Environment variables are read at `createNodeUI()` time (overridable via the
51
+ `options.env` map for tests):
52
+
53
+ | Variable | Default | Description |
54
+ | ------------------------------ | ----------- | --------------------------------- |
55
+ | `NODEUI_ENABLED` | unset | Force activation (`true`). |
56
+ | `NODEUI_HOST` | `127.0.0.1` | Loopback host the console trusts. |
57
+ | `NODEUI_PATH` | `/nodeui` | URL prefix for console + API. |
58
+ | `NODEUI_REQUEST_LOG_SIZE` | `500` | Request ring-buffer capacity. |
59
+ | `NODEUI_POLL_INTERVAL_MS` | `2000` | Sampling interval. |
60
+ | `NODEUI_INACTIVITY_TIMEOUT_MS` | `60000` | Provider idle timeout. |
61
+ | `NODEUI_CONFIRM_TTL_MS` | `60000` | Nonce lifetime. |
62
+ | `NODEUI_HEAP_SNAPSHOT_DIR` | OS tmpdir | Snapshot output directory. |
63
+
64
+ ## Usage
65
+
66
+ ```ts
67
+ import { createNodeUI, type NodeUIServer } from '@singhak/nodeui-core';
68
+
69
+ const server: NodeUIServer = createNodeUI();
70
+ const middleware = server.middleware();
71
+ // middleware is (req, res, next) => void; mount it before your routes.
72
+ server.mark('listening');
73
+ server.shutdown();
74
+ ```
75
+
76
+ ## Development
77
+
78
+ ```bash
79
+ npm run typecheck # tsc --noEmit
80
+ npm test # vitest run (unit + e2e)
81
+ npm run build # emit dist/
82
+ ```