@qodalis/cli-server-plugin-admin 1.0.0-beta.1 → 1.0.0-beta.13
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 +226 -0
- package/dashboard/assets/index-BVWEEAZ_.js +248 -0
- package/dashboard/assets/index-DDYjltKc.css +32 -0
- package/dashboard/assets/wasm/qodalis_cli_wasm_bg.wasm +0 -0
- package/dashboard/index.html +14 -0
- package/dist/auth/auth-controller.d.ts +11 -2
- package/dist/auth/auth-controller.d.ts.map +1 -1
- package/dist/auth/auth-controller.js +59 -6
- package/dist/auth/auth-controller.js.map +1 -1
- package/dist/auth/auth-middleware.d.ts +2 -1
- package/dist/auth/auth-middleware.d.ts.map +1 -1
- package/dist/auth/auth-middleware.js +64 -1
- package/dist/auth/auth-middleware.js.map +1 -1
- package/dist/auth/auth-provider.d.ts +42 -0
- package/dist/auth/auth-provider.d.ts.map +1 -0
- package/dist/auth/auth-provider.js +16 -0
- package/dist/auth/auth-provider.js.map +1 -0
- package/dist/auth/jwt-service.d.ts +12 -2
- package/dist/auth/jwt-service.d.ts.map +1 -1
- package/dist/auth/jwt-service.js +11 -2
- package/dist/auth/jwt-service.js.map +1 -1
- package/dist/cli-admin-builder.d.ts +49 -9
- package/dist/cli-admin-builder.d.ts.map +1 -1
- package/dist/cli-admin-builder.js +87 -51
- package/dist/cli-admin-builder.js.map +1 -1
- package/dist/controllers/plugins-controller.d.ts.map +1 -1
- package/dist/controllers/plugins-controller.js +1 -2
- package/dist/controllers/plugins-controller.js.map +1 -1
- package/dist/controllers/status-controller.d.ts +1 -0
- package/dist/controllers/status-controller.d.ts.map +1 -1
- package/dist/controllers/status-controller.js.map +1 -1
- package/dist/controllers/ws-clients-controller.d.ts +1 -0
- package/dist/controllers/ws-clients-controller.d.ts.map +1 -1
- package/dist/controllers/ws-clients-controller.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/services/admin-config.d.ts +32 -3
- package/dist/services/admin-config.d.ts.map +1 -1
- package/dist/services/admin-config.js +56 -3
- package/dist/services/admin-config.js.map +1 -1
- package/dist/services/admin-theme.d.ts +31 -0
- package/dist/services/admin-theme.d.ts.map +1 -0
- package/dist/services/admin-theme.js +94 -0
- package/dist/services/admin-theme.js.map +1 -0
- package/dist/services/dashboard-dir.d.ts +10 -0
- package/dist/services/dashboard-dir.d.ts.map +1 -0
- package/dist/services/dashboard-dir.js +51 -0
- package/dist/services/dashboard-dir.js.map +1 -0
- package/dist/services/log-ring-buffer.d.ts +6 -0
- package/dist/services/log-ring-buffer.d.ts.map +1 -1
- package/dist/services/log-ring-buffer.js +13 -0
- package/dist/services/log-ring-buffer.js.map +1 -1
- package/dist/services/module-registry.d.ts +20 -7
- package/dist/services/module-registry.d.ts.map +1 -1
- package/dist/services/module-registry.js +22 -10
- package/dist/services/module-registry.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -2
package/README.md
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
# @qodalis/cli-server-plugin-admin
|
|
2
|
+
|
|
3
|
+
Admin dashboard plugin for [Qodalis CLI Server (Node.js)](https://github.com/qodalis-solutions/cli-server-node). Provides JWT authentication, server status, plugin management, configuration, log viewing, and WebSocket client monitoring via a REST API and bundled SPA dashboard.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @qodalis/cli-server-plugin-admin
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { createCliServer } from '@qodalis/cli-server-node';
|
|
15
|
+
import { CliAdminBuilder } from '@qodalis/cli-server-plugin-admin';
|
|
16
|
+
|
|
17
|
+
const { app, registry, builder, eventSocketManager } = createCliServer({
|
|
18
|
+
configure: (builder) => {
|
|
19
|
+
// register your modules...
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const adminPlugin = new CliAdminBuilder()
|
|
24
|
+
.setCredentials('admin', 'my-secret-password')
|
|
25
|
+
.setJwtSecret('my-jwt-secret')
|
|
26
|
+
.build({ registry, eventSocketManager, builder });
|
|
27
|
+
|
|
28
|
+
// Using createCliServer:
|
|
29
|
+
mountPlugin(adminPlugin);
|
|
30
|
+
|
|
31
|
+
// Or on an existing Express app:
|
|
32
|
+
app.use(adminPlugin.prefix, adminPlugin.router);
|
|
33
|
+
app.use(adminPlugin.dashboardPrefix, adminPlugin.dashboardRouter);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Configuration
|
|
37
|
+
|
|
38
|
+
When the users plugin is installed, pass `setAuthProvider(usersPlugin.serverAuth)`: the dashboard then logs in with users credentials, its token is a users session token, and every admin route requires `admin:access`. The static credentials below are only used when the users plugin is absent.
|
|
39
|
+
|
|
40
|
+
Credentials and JWT secret can be set via the builder or environment variables:
|
|
41
|
+
|
|
42
|
+
| Environment Variable | Default | Description |
|
|
43
|
+
|---|---|---|
|
|
44
|
+
| `QCLI_ADMIN_USERNAME` | `admin` | Admin login username |
|
|
45
|
+
| `QCLI_ADMIN_PASSWORD` | `admin` | Admin login password |
|
|
46
|
+
| `QCLI_ADMIN_JWT_SECRET` | Random | JWT signing secret |
|
|
47
|
+
|
|
48
|
+
## Builder Options
|
|
49
|
+
|
|
50
|
+
| Method | Description |
|
|
51
|
+
|---|---|
|
|
52
|
+
| `setCredentials(username, password)` | Set admin login credentials (only used without the users plugin) |
|
|
53
|
+
| `setAuthProvider(usersPlugin.serverAuth)` | Log in through the users plugin; requires the `admin:access` permission (`admin` has it via `*`) |
|
|
54
|
+
| `setJwtSecret(secret)` | Set JWT signing secret |
|
|
55
|
+
| `setSignInUrl(url)` | Where the host app signs users in, for external sign-in mode (see [Sign in with the host app's session](#sign-in-with-the-host-apps-session)); `build()` throws on an invalid URL |
|
|
56
|
+
| `setRegisteredJobs(count)` | Report job count in the status endpoint (`jobs` is listed in `enabledFeatures` once the jobs plugin is mounted, or with a count above 0) |
|
|
57
|
+
| `setEnabledFeatures(features)` | Add custom feature flags to the status endpoint |
|
|
58
|
+
| `setDashboardDir(dir)` | Override the path to the dashboard SPA dist directory |
|
|
59
|
+
| `setTheme(theme)` | Dashboard color scheme: mode and per-scheme colors (see [Color scheme](#color-scheme)) |
|
|
60
|
+
|
|
61
|
+
## REST API
|
|
62
|
+
|
|
63
|
+
All endpoints are mounted at the plugin's built-in prefix (`/api/v1/qcli`). Routes below `/auth/login` require a valid JWT in the `Authorization: Bearer <token>` header.
|
|
64
|
+
|
|
65
|
+
### Authentication
|
|
66
|
+
|
|
67
|
+
| Method | Endpoint | Description |
|
|
68
|
+
|---|---|---|
|
|
69
|
+
| GET | `/auth/mode` | Public. Which sign-in the dashboard shows: `{ "mode": "password" \| "external", "signInUrl": string \| null }` (`Cache-Control: no-store`) |
|
|
70
|
+
| POST | `/auth/login` | Authenticate with username/password, receive JWT (501 in external mode) |
|
|
71
|
+
| GET | `/auth/me` | Get current user info from token |
|
|
72
|
+
|
|
73
|
+
### Status
|
|
74
|
+
|
|
75
|
+
| Method | Endpoint | Description |
|
|
76
|
+
|---|---|---|
|
|
77
|
+
| GET | `/status` | Server uptime, memory, platform, connections, registered commands, enabled features |
|
|
78
|
+
|
|
79
|
+
### Plugins
|
|
80
|
+
|
|
81
|
+
| Method | Endpoint | Description |
|
|
82
|
+
|---|---|---|
|
|
83
|
+
| GET | `/plugins` | List all registered modules |
|
|
84
|
+
| POST | `/plugins/:id/toggle` | Enable or disable a module |
|
|
85
|
+
|
|
86
|
+
### Configuration
|
|
87
|
+
|
|
88
|
+
When the users plugin is installed, pass `setAuthProvider(usersPlugin.serverAuth)`: the dashboard then logs in with users credentials, its token is a users session token, and every admin route requires `admin:access`. The static credentials below are only used when the users plugin is absent.
|
|
89
|
+
|
|
90
|
+
| Method | Endpoint | Description |
|
|
91
|
+
|---|---|---|
|
|
92
|
+
| GET | `/config` | Return structured config sections (server, auth, custom) |
|
|
93
|
+
| PUT | `/config` | Update mutable (custom) settings |
|
|
94
|
+
|
|
95
|
+
### Logs
|
|
96
|
+
|
|
97
|
+
| Method | Endpoint | Description |
|
|
98
|
+
|---|---|---|
|
|
99
|
+
| GET | `/logs` | Query log entries with optional `level`, `search`, `limit`, `offset` params |
|
|
100
|
+
|
|
101
|
+
The log buffer captures `console.log`/`warn`/`error` output. As a safety net, a value written after a `password`, `passwd`, `secret` or `token` label (`password: x`, `token=x`, `password for user "root": x`) is replaced with `[REDACTED]` before the entry is stored or broadcast.
|
|
102
|
+
|
|
103
|
+
### WebSocket Clients
|
|
104
|
+
|
|
105
|
+
| Method | Endpoint | Description |
|
|
106
|
+
|---|---|---|
|
|
107
|
+
| GET | `/ws/clients` | List connected WebSocket clients |
|
|
108
|
+
|
|
109
|
+
### Sign in with the host app's session
|
|
110
|
+
|
|
111
|
+
The full setup (adapter, middleware order, permissions) is in [Use with your app's sign-in](../../README.md#use-with-your-apps-sign-in).
|
|
112
|
+
|
|
113
|
+
When the users plugin delegates authentication to your application (`setAuthAdapter`), the dashboard runs in **external** mode. The users plugin sets the server's `serverOptions.externalAuthentication` when it is mounted (`mountPlugin(usersPlugin)` or `createCliServer({ auth })`), and the admin plugin reads it on every request, so the mounting order does not matter.
|
|
114
|
+
|
|
115
|
+
- `GET /api/v1/qcli/auth/mode` answers `{ "mode": "external", "signInUrl": "<setSignInUrl>" }`. It is public, also on protected servers, so the dashboard can call it before anyone signs in. Otherwise it answers `"password"`.
|
|
116
|
+
- The dashboard hides its username/password form and shows "Sign in at `<signInUrl>`" with a Retry button (or tells users to sign in through the host application when no sign-in URL is set). Any 401 leads to that screen.
|
|
117
|
+
- `POST /api/v1/qcli/auth/login` signs no one in: it answers `501` with `code: "EXTERNAL_AUTH"`, a message pointing to the host's sign-in and `signInUrl`. The static admin credentials are never accepted in this mode.
|
|
118
|
+
- With `setAuthProvider(usersPlugin.serverAuth)`, admin routes authenticate the request through the users plugin (your adapter) and require `admin:access` (`isAdmin` grants it through the `admin` group).
|
|
119
|
+
|
|
120
|
+
The sign-in URL must be an absolute `http`/`https` URL or a root-relative path (`/sign-in`); anything else (for example `javascript:` or `//host`) makes `build()` throw.
|
|
121
|
+
|
|
122
|
+
**Handoff.** Send signed-in users to the dashboard with your bearer token in the URL fragment:
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
/qcli/admin/#token=<host bearer token>
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
A fragment is never sent to servers or written to access logs. The dashboard reads it on startup, stores it as its admin token, removes it from the address bar (`history.replaceState`) and sends it as `Authorization: Bearer …` on every API call, where your external auth adapter validates it like any other request from your app.
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
// Host app: the adapter accepts the app's own JWT (verified by your middleware, which sets req.user).
|
|
132
|
+
const usersPlugin = new CliUsersBuilder()
|
|
133
|
+
.setAuthAdapter((req) => {
|
|
134
|
+
const principal = (req as any).user;
|
|
135
|
+
if (!principal) return null;
|
|
136
|
+
return { user: { id: principal.sub, name: principal.name, email: principal.email ?? '', groups: [], createdAt: 0, updatedAt: 0 }, isAdmin: principal.roles?.includes('admin') };
|
|
137
|
+
})
|
|
138
|
+
.build((msg) => eventSocketManager.broadcastMessage(msg));
|
|
139
|
+
|
|
140
|
+
const adminPlugin = new CliAdminBuilder()
|
|
141
|
+
.setAuthProvider(usersPlugin.serverAuth)
|
|
142
|
+
.setSignInUrl('/sign-in?returnUrl=%2Fadmin%2Fconsole')
|
|
143
|
+
.build({ registry, eventSocketManager, builder });
|
|
144
|
+
|
|
145
|
+
mountPlugin(adminPlugin);
|
|
146
|
+
mountPlugin(usersPlugin);
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
// Host front end: an "Open console" button for a signed-in admin.
|
|
151
|
+
window.location.href = `/qcli/admin/#token=${encodeURIComponent(accessToken)}`;
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
When the token expires, the next API call answers 401 and the dashboard shows the sign-in screen; after signing in again, the host repeats the handoff.
|
|
155
|
+
|
|
156
|
+
## Dashboard
|
|
157
|
+
|
|
158
|
+
The plugin includes a bundled SPA dashboard served at the built-in prefix (`/qcli/admin`). The dashboard is found in this order: the directory given to `setDashboardDir()`, a sibling `cli-server-dashboard/dist` build (development), the package's bundled `dashboard/` directory, and the `@qodalis/cli-server-dashboard` package if installed separately. The same order applies whether the plugin runs compiled or from source (`tsx`).
|
|
159
|
+
|
|
160
|
+
## Color scheme
|
|
161
|
+
|
|
162
|
+
Match the dashboard to your own design with `setTheme()`:
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
const adminPlugin = new CliAdminBuilder()
|
|
166
|
+
.setCredentials('admin', 'my-secret-password')
|
|
167
|
+
.setTheme({
|
|
168
|
+
mode: 'system',
|
|
169
|
+
light: {
|
|
170
|
+
primary: '#2a6bba', primaryHover: '#1f5596', accent: '#2a6bba',
|
|
171
|
+
background: '#f1f6fa', backgroundAccent: '#f1f6fa', surface: '#ffffff',
|
|
172
|
+
border: '#d9e3ec', heading: '#142231', text: '#142231', muted: '#5d6f82',
|
|
173
|
+
},
|
|
174
|
+
dark: {
|
|
175
|
+
primary: '#4f9be0', primaryHover: '#3f8ad3', onPrimary: '#0d1823', accent: '#4f9be0',
|
|
176
|
+
background: '#0d1823', backgroundAccent: '#0d1823', surface: '#13212f', popover: '#13212f',
|
|
177
|
+
border: '#22364a', text: '#e6eef6', muted: '#93a6b9',
|
|
178
|
+
},
|
|
179
|
+
})
|
|
180
|
+
.build({ registry, eventSocketManager, builder, executor });
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
`setTheme()` throws on an invalid theme. The types (`AdminTheme`, `AdminThemeColors`, `AdminThemeMode`) and
|
|
184
|
+
`validateAdminTheme()` are exported.
|
|
185
|
+
|
|
186
|
+
`mode` is `dark` (default), `light`, or `system` to follow the browser's `prefers-color-scheme`. Each scheme takes any
|
|
187
|
+
subset of the tokens below; the ones you leave out keep their defaults.
|
|
188
|
+
|
|
189
|
+
Values must be plain CSS colors: hex (`#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`), a color function with numeric arguments
|
|
190
|
+
(`rgb()`, `rgba()`, `hsl()`, `hsla()`, `hwb()`, `lab()`, `lch()`, `oklab()`, `oklch()`) or a named color. Anything else
|
|
191
|
+
(an unknown mode or token, `var()`, `url()`, `;` ...) is rejected at startup with an error naming the token, so a theme
|
|
192
|
+
cannot inject CSS.
|
|
193
|
+
|
|
194
|
+
The plugin serves the validated scheme at `GET /qcli/admin/theme.json` (public, like the dashboard files, since the
|
|
195
|
+
sign-in page uses it), e.g. `{"mode":"system","dark":{"primary":"#4f9be0"},"light":{"primary":"#2a6bba"}}`. The
|
|
196
|
+
dashboard applies it before its first render.
|
|
197
|
+
|
|
198
|
+
The defaults match the Qodalis CLI panel: its grays, indigo accent with the violet glow, and status colors in dark; the same palette for light backgrounds in light.
|
|
199
|
+
|
|
200
|
+
| Token | CSS variable | Used for | Dark default | Light default |
|
|
201
|
+
| --- | --- | --- | --- | --- |
|
|
202
|
+
| `primary` | `--qcli-primary` | Primary buttons, active navigation, toggles, focus rings | `#818cf8` | `#4f46e5` |
|
|
203
|
+
| `primaryHover` | `--qcli-primary-hover` | Primary buttons on hover | `#a5b4fc` | `#4338ca` |
|
|
204
|
+
| `onPrimary` | `--qcli-on-primary` | Text and icons on `primary` | `#111827` | `#ffffff` |
|
|
205
|
+
| `accent` | `--qcli-accent` | Highlighted text: links, command names, active items | `#a78bfa` | `#7c3aed` |
|
|
206
|
+
| `background` | `--qcli-background` | Page background | `#111827` | `#f9fafb` |
|
|
207
|
+
| `backgroundAccent` | `--qcli-background-accent` | Start of the page background gradient (set it to `background` for a flat page) | `#1f2937` | `#eef2ff` |
|
|
208
|
+
| `sidebar` | `--qcli-sidebar` | Sidebar background | `#1f2937` | `#ffffff` |
|
|
209
|
+
| `surface` | `--qcli-surface` | Cards, panels and tables | `rgba(255, 255, 255, 0.04)` | `#ffffff` |
|
|
210
|
+
| `popover` | `--qcli-popover` | Dialogs and dropdown menus (opaque) | `#1f2937` | `#ffffff` |
|
|
211
|
+
| `control` | `--qcli-control` | Inputs, secondary buttons, chips | `rgba(255, 255, 255, 0.06)` | `rgba(17, 24, 39, 0.05)` |
|
|
212
|
+
| `controlHover` | `--qcli-control-hover` | Inputs and secondary buttons on hover | `rgba(255, 255, 255, 0.1)` | `rgba(17, 24, 39, 0.1)` |
|
|
213
|
+
| `border` | `--qcli-border` | Borders and dividers | `#374151` | `#e5e7eb` |
|
|
214
|
+
| `overlay` | `--qcli-overlay` | Backdrop behind dialogs | `rgba(0, 0, 0, 0.6)` | `rgba(17, 24, 39, 0.45)` |
|
|
215
|
+
| `heading` | `--qcli-heading` | Headings and values | `#ffffff` | `#111827` |
|
|
216
|
+
| `text` | `--qcli-text` | Body text | `rgba(255, 255, 255, 0.87)` | `#1f2937` |
|
|
217
|
+
| `muted` | `--qcli-muted` | Secondary text and labels | `rgba(255, 255, 255, 0.6)` | `#4b5563` |
|
|
218
|
+
| `subtle` | `--qcli-subtle` | Hints, placeholders, timestamps | `rgba(255, 255, 255, 0.4)` | `#6b7280` |
|
|
219
|
+
| `success` | `--qcli-success` | Success states | `#3fb950` | `#1a7f37` |
|
|
220
|
+
| `warning` | `--qcli-warning` | Warning states | `#f0883e` | `#bc4c00` |
|
|
221
|
+
| `error` | `--qcli-error` | Errors and destructive actions | `#f85149` | `#cf222e` |
|
|
222
|
+
| `info` | `--qcli-info` | Informational states | `#58a6ff` | `#0969da` |
|
|
223
|
+
|
|
224
|
+
## License
|
|
225
|
+
|
|
226
|
+
MIT
|