clinkx 1.3.0 → 1.4.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/CHANGELOG.md +28 -0
- package/README.md +13 -6
- package/clinkx-workflows/dist/child-env.d.ts +3 -0
- package/clinkx-workflows/dist/child-env.js +11 -0
- package/clinkx-workflows/dist/child-env.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/api-routes.d.ts +21 -0
- package/clinkx-workflows/dist/dashboard/api-routes.js +27 -0
- package/clinkx-workflows/dist/dashboard/api-routes.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/auth/challenge-store.d.ts +13 -0
- package/clinkx-workflows/dist/dashboard/auth/challenge-store.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/auth/controller.d.ts +27 -0
- package/clinkx-workflows/dist/dashboard/auth/controller.js +262 -23
- package/clinkx-workflows/dist/dashboard/auth/controller.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/auth/settings-step-up.d.ts +62 -0
- package/clinkx-workflows/dist/dashboard/auth/settings-step-up.js +70 -0
- package/clinkx-workflows/dist/dashboard/auth/settings-step-up.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/request-admission.d.ts +6 -0
- package/clinkx-workflows/dist/dashboard/request-admission.js +9 -0
- package/clinkx-workflows/dist/dashboard/request-admission.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/server-factory.js +15 -1
- package/clinkx-workflows/dist/dashboard/server-factory.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/settings-contract.d.ts +1806 -0
- package/clinkx-workflows/dist/dashboard/settings-contract.js +630 -0
- package/clinkx-workflows/dist/dashboard/settings-contract.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/settings-process-reader.d.ts +48 -0
- package/clinkx-workflows/dist/dashboard/settings-process-reader.js +195 -0
- package/clinkx-workflows/dist/dashboard/settings-process-reader.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/settings-routes.d.ts +87 -0
- package/clinkx-workflows/dist/dashboard/settings-routes.js +690 -0
- package/clinkx-workflows/dist/dashboard/settings-routes.js.map +1 -0
- package/clinkx-workflows/dist/dashboard-ui/assets/index-DSOtuS0p.js +122 -0
- package/clinkx-workflows/dist/dashboard-ui/assets/style-C5guUjwN.css +1 -0
- package/clinkx-workflows/dist/dashboard-ui/index.html +2 -2
- package/clinkx-workflows/dist/durable-file-core.d.ts +76 -0
- package/clinkx-workflows/dist/durable-file-core.js +146 -0
- package/clinkx-workflows/dist/durable-file-core.js.map +1 -0
- package/clinkx-workflows/dist/durable-file.d.ts +8 -64
- package/clinkx-workflows/dist/durable-file.js +14 -137
- package/clinkx-workflows/dist/durable-file.js.map +1 -1
- package/clinkx-workflows/dist/index.js +68 -2
- package/clinkx-workflows/dist/index.js.map +1 -1
- package/clinkx-workflows/dist/settings/audit.d.ts +101 -0
- package/clinkx-workflows/dist/settings/audit.js +318 -0
- package/clinkx-workflows/dist/settings/audit.js.map +1 -0
- package/clinkx-workflows/dist/settings/bootstrap.d.ts +35 -0
- package/clinkx-workflows/dist/settings/bootstrap.js +52 -0
- package/clinkx-workflows/dist/settings/bootstrap.js.map +1 -0
- package/clinkx-workflows/dist/settings/codec.d.ts +51 -0
- package/clinkx-workflows/dist/settings/codec.js +410 -0
- package/clinkx-workflows/dist/settings/codec.js.map +1 -0
- package/clinkx-workflows/dist/settings/durable-write.d.ts +48 -0
- package/clinkx-workflows/dist/settings/durable-write.js +31 -0
- package/clinkx-workflows/dist/settings/durable-write.js.map +1 -0
- package/clinkx-workflows/dist/settings/index.d.ts +20 -0
- package/clinkx-workflows/dist/settings/index.js +23 -0
- package/clinkx-workflows/dist/settings/index.js.map +1 -0
- package/clinkx-workflows/dist/settings/loader.d.ts +80 -0
- package/clinkx-workflows/dist/settings/loader.js +577 -0
- package/clinkx-workflows/dist/settings/loader.js.map +1 -0
- package/clinkx-workflows/dist/settings/lock.d.ts +108 -0
- package/clinkx-workflows/dist/settings/lock.js +344 -0
- package/clinkx-workflows/dist/settings/lock.js.map +1 -0
- package/clinkx-workflows/dist/settings/paths.d.ts +65 -0
- package/clinkx-workflows/dist/settings/paths.js +173 -0
- package/clinkx-workflows/dist/settings/paths.js.map +1 -0
- package/clinkx-workflows/dist/settings/process-heartbeat.d.ts +47 -0
- package/clinkx-workflows/dist/settings/process-heartbeat.js +305 -0
- package/clinkx-workflows/dist/settings/process-heartbeat.js.map +1 -0
- package/clinkx-workflows/dist/settings/registry.d.ts +178 -0
- package/clinkx-workflows/dist/settings/registry.js +1285 -0
- package/clinkx-workflows/dist/settings/registry.js.map +1 -0
- package/clinkx-workflows/dist/settings/schema.d.ts +404 -0
- package/clinkx-workflows/dist/settings/schema.js +415 -0
- package/clinkx-workflows/dist/settings/schema.js.map +1 -0
- package/clinkx-workflows/dist/settings/store.d.ts +157 -0
- package/clinkx-workflows/dist/settings/store.js +842 -0
- package/clinkx-workflows/dist/settings/store.js.map +1 -0
- package/clinkx-workflows/dist/stdio-entry.d.ts +2 -0
- package/clinkx-workflows/dist/stdio-entry.js +52 -0
- package/clinkx-workflows/dist/stdio-entry.js.map +1 -0
- package/dist/dashboard-cli.js +50 -1
- package/dist/dashboard-cli.js.map +1 -1
- package/dist/dashboard-companion/protocol.js +17 -0
- package/dist/dashboard-companion/protocol.js.map +1 -1
- package/dist/dashboard-gateway/control-plane/contracts.d.ts +38 -38
- package/dist/dashboard-gateway/tunnel-http.js +20 -0
- package/dist/dashboard-gateway/tunnel-http.js.map +1 -1
- package/dist/elaris/config.d.ts +10 -0
- package/dist/elaris/config.js +27 -1
- package/dist/elaris/config.js.map +1 -1
- package/dist/elaris/tools.js +4 -1
- package/dist/elaris/tools.js.map +1 -1
- package/dist/index.d.ts +0 -31
- package/dist/index.js +41 -404
- package/dist/index.js.map +1 -1
- package/dist/lib.d.ts +17 -0
- package/dist/lib.js +17 -0
- package/dist/lib.js.map +1 -0
- package/dist/progress-report/lock.d.ts +17 -59
- package/dist/progress-report/lock.js +25 -329
- package/dist/progress-report/lock.js.map +1 -1
- package/dist/server.js +75 -4
- package/dist/server.js.map +1 -1
- package/dist/settings-cli/clients.d.ts +137 -0
- package/dist/settings-cli/clients.js +1124 -0
- package/dist/settings-cli/clients.js.map +1 -0
- package/dist/settings-cli/commands.d.ts +67 -0
- package/dist/settings-cli/commands.js +726 -0
- package/dist/settings-cli/commands.js.map +1 -0
- package/dist/settings-cli/format.d.ts +34 -0
- package/dist/settings-cli/format.js +40 -0
- package/dist/settings-cli/format.js.map +1 -0
- package/dist/settings-cli/main.d.ts +18 -0
- package/dist/settings-cli/main.js +256 -0
- package/dist/settings-cli/main.js.map +1 -0
- package/dist/stdio-main.d.ts +73 -0
- package/dist/stdio-main.js +455 -0
- package/dist/stdio-main.js.map +1 -0
- package/docs/configuration.md +340 -39
- package/docs/security.md +150 -6
- package/package.json +2 -2
- package/clinkx-workflows/dist/dashboard-ui/assets/index-DRId2DVA.js +0 -119
- package/clinkx-workflows/dist/dashboard-ui/assets/style-CHAw57y5.css +0 -1
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type ProcessHeartbeatV1 } from "../settings/schema.js";
|
|
2
|
+
/** Defensive cap on candidate files examined per listing (matches the writer's prune). */
|
|
3
|
+
export declare const MAX_PROCESS_FILES_SCANNED = 512;
|
|
4
|
+
/** A heartbeat older than this on a foreign host is stale (worker-lock-observer rule). */
|
|
5
|
+
export declare const FOREIGN_HEARTBEAT_STALE_AFTER_MS: number;
|
|
6
|
+
/** A heartbeat mtime further ahead than this is a clock disagreement, not liveness. */
|
|
7
|
+
export declare const FOREIGN_HEARTBEAT_FUTURE_UNKNOWN_MS = 60000;
|
|
8
|
+
export interface SettingsProcessEntry {
|
|
9
|
+
/**
|
|
10
|
+
* Stable identity = the document's `boot_nonce` (T09 wire delta, S4): the
|
|
11
|
+
* hostname-pid-nonce composition overflowed the wire cap on long hostnames.
|
|
12
|
+
* The file NAME still binds host+pid+nonce, and name/content identity is
|
|
13
|
+
* still verified before a row is admitted.
|
|
14
|
+
*/
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly document: ProcessHeartbeatV1;
|
|
17
|
+
/** mtime (the refreshed liveness signal), RFC3339. */
|
|
18
|
+
readonly lastSeenAt: string;
|
|
19
|
+
readonly liveness: "live" | "stale" | "unknown";
|
|
20
|
+
}
|
|
21
|
+
/** Bounded skip diagnostics carried back to the route (logged, never fatal). */
|
|
22
|
+
export declare const MAX_PROCESS_READER_WARNINGS = 8;
|
|
23
|
+
export interface SettingsProcessListResult {
|
|
24
|
+
readonly processes: readonly SettingsProcessEntry[];
|
|
25
|
+
/** True when valid entries were dropped by the 200-row cap or the scan cap. */
|
|
26
|
+
readonly truncated: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Why candidate entries were skipped (T09 wire delta): one bounded line per
|
|
29
|
+
* skipped heartbeat-shaped file. A row that fails validation is skipped
|
|
30
|
+
* with a warning; it never fails the whole response.
|
|
31
|
+
*/
|
|
32
|
+
readonly warnings: readonly string[];
|
|
33
|
+
}
|
|
34
|
+
export interface SettingsProcessReaderDeps {
|
|
35
|
+
readonly hostname?: () => string;
|
|
36
|
+
readonly now?: () => number;
|
|
37
|
+
/**
|
|
38
|
+
* Same-host liveness probe. Default: `process.kill(pid, 0)` — success or
|
|
39
|
+
* EPERM is a live process, ESRCH is dead, anything else is unknown.
|
|
40
|
+
*/
|
|
41
|
+
readonly probePid?: (pid: number) => "live" | "stale" | "unknown";
|
|
42
|
+
/** Test seam for the candidate-scan cap. */
|
|
43
|
+
readonly maxScanEntries?: number;
|
|
44
|
+
}
|
|
45
|
+
export interface SettingsProcessReader {
|
|
46
|
+
list(processesDir: string): Promise<SettingsProcessListResult>;
|
|
47
|
+
}
|
|
48
|
+
export declare function createSettingsProcessReader(deps?: SettingsProcessReaderDeps): SettingsProcessReader;
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dashboard reader for per-process settings heartbeats — B1-4.
|
|
3
|
+
*
|
|
4
|
+
* Reads every `<settingsDir>/processes/<hostname>-<pid>-<bootNonce>.json`
|
|
5
|
+
* document written by `settings/process-heartbeat.ts` (A1-3) and classifies
|
|
6
|
+
* liveness with the worker-lock-observer pattern:
|
|
7
|
+
*
|
|
8
|
+
* - same hostname → the PID probe is authoritative (`process.kill(pid, 0)`:
|
|
9
|
+
* alive → live, ESRCH → stale; an unexpected probe error → unknown);
|
|
10
|
+
* - foreign hostname (containerized/bind-mounted dashboard) → the heartbeat
|
|
11
|
+
* mtime is the liveness signal: age ≤ max(60 s, 6 × 30 s interval) → live,
|
|
12
|
+
* older → stale, mtime more than 60 s in the future → unknown (a
|
|
13
|
+
* disagreeing clock must never be able to declare a live run dead).
|
|
14
|
+
*
|
|
15
|
+
* Reads are bounded and no-follow: the scan admits at most
|
|
16
|
+
* `MAX_PROCESS_FILES_SCANNED` candidate entries, each file must lstat as a
|
|
17
|
+
* regular file at or under the loader's settings byte cap, and the descriptor
|
|
18
|
+
* open uses O_NOFOLLOW so a swapped-in symlink is refused rather than read.
|
|
19
|
+
* Files whose name does not parse, whose bytes are not valid JSON, whose
|
|
20
|
+
* document fails the frozen `clinkx-settings-process-v1` schema, or whose
|
|
21
|
+
* name parts disagree with the document identity are SKIPPED with a bounded
|
|
22
|
+
* warning in the result (a heartbeat is observability; one malformed file
|
|
23
|
+
* must not hide the others, and never fails the whole response).
|
|
24
|
+
*
|
|
25
|
+
* The result carries documents only — this module projects nothing; the wire
|
|
26
|
+
* projection (key-name lists, never values) lives in settings-routes.ts.
|
|
27
|
+
*/
|
|
28
|
+
import { constants as fsConstants } from "node:fs";
|
|
29
|
+
import { lstat, open, readdir } from "node:fs/promises";
|
|
30
|
+
import { hostname as osHostname } from "node:os";
|
|
31
|
+
import { join } from "node:path";
|
|
32
|
+
import { MAX_SETTINGS_FILE_BYTES } from "../settings/loader.js";
|
|
33
|
+
import { ProcessHeartbeatV1Schema } from "../settings/schema.js";
|
|
34
|
+
import { parseProcessHeartbeatFileName } from "../settings/paths.js";
|
|
35
|
+
import { SETTINGS_HEARTBEAT_INTERVAL_MS } from "../settings/process-heartbeat.js";
|
|
36
|
+
import { MAX_SETTINGS_PROCESSES } from "./settings-contract.js";
|
|
37
|
+
/** Defensive cap on candidate files examined per listing (matches the writer's prune). */
|
|
38
|
+
export const MAX_PROCESS_FILES_SCANNED = 512;
|
|
39
|
+
/** A heartbeat older than this on a foreign host is stale (worker-lock-observer rule). */
|
|
40
|
+
export const FOREIGN_HEARTBEAT_STALE_AFTER_MS = Math.max(60_000, SETTINGS_HEARTBEAT_INTERVAL_MS * 6);
|
|
41
|
+
/** A heartbeat mtime further ahead than this is a clock disagreement, not liveness. */
|
|
42
|
+
export const FOREIGN_HEARTBEAT_FUTURE_UNKNOWN_MS = 60_000;
|
|
43
|
+
/** Bounded skip diagnostics carried back to the route (logged, never fatal). */
|
|
44
|
+
export const MAX_PROCESS_READER_WARNINGS = 8;
|
|
45
|
+
function defaultProbePid(pid) {
|
|
46
|
+
try {
|
|
47
|
+
process.kill(pid, 0);
|
|
48
|
+
return "live";
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
const code = error.code;
|
|
52
|
+
if (code === "ESRCH")
|
|
53
|
+
return "stale";
|
|
54
|
+
// EPERM: the process exists but is not ours — still alive.
|
|
55
|
+
if (code === "EPERM")
|
|
56
|
+
return "live";
|
|
57
|
+
return "unknown";
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function foreignLiveness(mtimeMs, nowMs) {
|
|
61
|
+
const ageMs = nowMs - mtimeMs;
|
|
62
|
+
if (ageMs < -FOREIGN_HEARTBEAT_FUTURE_UNKNOWN_MS)
|
|
63
|
+
return "unknown";
|
|
64
|
+
if (ageMs <= FOREIGN_HEARTBEAT_STALE_AFTER_MS)
|
|
65
|
+
return "live";
|
|
66
|
+
return "stale";
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Read one heartbeat file body without following symlinks. The descriptor
|
|
70
|
+
* fstat re-checks kind and size after the open (the lstat/open pair alone
|
|
71
|
+
* leaves a swap window).
|
|
72
|
+
*/
|
|
73
|
+
async function readHeartbeatFile(path) {
|
|
74
|
+
let stats;
|
|
75
|
+
try {
|
|
76
|
+
stats = await lstat(path);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return { ok: false };
|
|
80
|
+
}
|
|
81
|
+
if (stats.isSymbolicLink() || !stats.isFile())
|
|
82
|
+
return { ok: false };
|
|
83
|
+
if (stats.size > MAX_SETTINGS_FILE_BYTES)
|
|
84
|
+
return { ok: false };
|
|
85
|
+
const flags = fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW | fsConstants.O_NONBLOCK;
|
|
86
|
+
let handle;
|
|
87
|
+
try {
|
|
88
|
+
handle = await open(path, flags);
|
|
89
|
+
const openStats = await handle.stat();
|
|
90
|
+
if (!openStats.isFile() || openStats.size > MAX_SETTINGS_FILE_BYTES) {
|
|
91
|
+
return { ok: false };
|
|
92
|
+
}
|
|
93
|
+
const buffer = Buffer.alloc(openStats.size);
|
|
94
|
+
let offset = 0;
|
|
95
|
+
while (offset < buffer.length) {
|
|
96
|
+
const { bytesRead } = await handle.read(buffer, offset, buffer.length - offset, null);
|
|
97
|
+
if (bytesRead === 0)
|
|
98
|
+
break;
|
|
99
|
+
offset += bytesRead;
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
ok: true,
|
|
103
|
+
bytes: offset === buffer.length ? buffer : buffer.subarray(0, offset),
|
|
104
|
+
mtimeMs: openStats.mtimeMs,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return { ok: false };
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
await handle?.close().catch(() => undefined);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
export function createSettingsProcessReader(deps = {}) {
|
|
115
|
+
const hostname = deps.hostname ?? (() => osHostname());
|
|
116
|
+
const now = deps.now ?? Date.now;
|
|
117
|
+
const probePid = deps.probePid ?? defaultProbePid;
|
|
118
|
+
const maxScanEntries = deps.maxScanEntries ?? MAX_PROCESS_FILES_SCANNED;
|
|
119
|
+
return {
|
|
120
|
+
async list(processesDir) {
|
|
121
|
+
let names;
|
|
122
|
+
try {
|
|
123
|
+
names = await readdir(processesDir);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
// No processes dir yet (or briefly unreadable): an empty, untruncated
|
|
127
|
+
// listing — the same honest shape as "nothing is running".
|
|
128
|
+
return { processes: [], truncated: false, warnings: [] };
|
|
129
|
+
}
|
|
130
|
+
const scanTruncated = names.length > maxScanEntries;
|
|
131
|
+
const entries = [];
|
|
132
|
+
const warnings = [];
|
|
133
|
+
let skipped = 0;
|
|
134
|
+
const warnSkip = (name, why) => {
|
|
135
|
+
skipped += 1;
|
|
136
|
+
if (warnings.length < MAX_PROCESS_READER_WARNINGS) {
|
|
137
|
+
warnings.push(`skipped ${name}: ${why}`);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
for (const name of names.slice(0, maxScanEntries)) {
|
|
141
|
+
const parts = parseProcessHeartbeatFileName(name);
|
|
142
|
+
if (parts == null)
|
|
143
|
+
continue;
|
|
144
|
+
const read = await readHeartbeatFile(join(processesDir, name));
|
|
145
|
+
if (!read.ok) {
|
|
146
|
+
warnSkip(name, "unreadable, non-regular, symlinked, or over the byte cap");
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
let parsed;
|
|
150
|
+
try {
|
|
151
|
+
parsed = JSON.parse(read.bytes.toString("utf8"));
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
warnSkip(name, "not valid JSON");
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const validated = ProcessHeartbeatV1Schema.safeParse(parsed);
|
|
158
|
+
if (!validated.success) {
|
|
159
|
+
warnSkip(name, "failed the clinkx-settings-process-v1 schema");
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
const document = validated.data;
|
|
163
|
+
// Name/content identity must agree; a mismatched pair is skipped.
|
|
164
|
+
if (document.hostname !== parts.hostname ||
|
|
165
|
+
document.pid !== parts.pid ||
|
|
166
|
+
document.boot_nonce !== parts.bootNonce) {
|
|
167
|
+
warnSkip(name, "file name disagrees with the document identity");
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
const liveness = document.hostname === hostname()
|
|
171
|
+
? probePid(document.pid)
|
|
172
|
+
: foreignLiveness(read.mtimeMs, now());
|
|
173
|
+
entries.push({
|
|
174
|
+
id: document.boot_nonce,
|
|
175
|
+
document,
|
|
176
|
+
lastSeenAt: new Date(read.mtimeMs).toISOString(),
|
|
177
|
+
liveness,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
if (skipped > warnings.length) {
|
|
181
|
+
warnings.push(`(+${String(skipped - warnings.length)} more skipped entries)`);
|
|
182
|
+
}
|
|
183
|
+
entries.sort((left, right) => left.document.started_at < right.document.started_at ? -1
|
|
184
|
+
: left.document.started_at > right.document.started_at ? 1
|
|
185
|
+
: left.id < right.id ? -1 : left.id > right.id ? 1 : 0);
|
|
186
|
+
const rowTruncated = entries.length > MAX_SETTINGS_PROCESSES;
|
|
187
|
+
return {
|
|
188
|
+
processes: entries.slice(0, MAX_SETTINGS_PROCESSES),
|
|
189
|
+
truncated: rowTruncated || scanTruncated,
|
|
190
|
+
warnings,
|
|
191
|
+
};
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=settings-process-reader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings-process-reader.js","sourceRoot":"","sources":["../../src/dashboard/settings-process-reader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACx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AC,CAAC,CAAC,CAAC;oBACxD,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAC3D,CAAC;YACF,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,GAAG,sBAAsB,CAAC;YAC7D,OAAO;gBACL,SAAS,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,sBAAsB,CAAC;gBACnD,SAAS,EAAE,YAAY,IAAI,aAAa;gBACxC,QAAQ;aACT,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dashboard Settings API routes — B1-4 (OQ-7 auth matrix).
|
|
3
|
+
*
|
|
4
|
+
* Serves the five frozen routes from settings-contract.ts:
|
|
5
|
+
*
|
|
6
|
+
* GET /api/settings store.read() + secretStatus() projection
|
|
7
|
+
* GET /api/settings/processes heartbeat liveness/shadow reporting
|
|
8
|
+
* POST /api/settings/save store.save (tuning/retention/feature/
|
|
9
|
+
* reader_first) — step-up bound when the
|
|
10
|
+
* server-side class computation finds a
|
|
11
|
+
* policy key
|
|
12
|
+
* POST /api/settings/secrets/save store.saveSecrets — always step-up bound
|
|
13
|
+
* POST /api/settings/step-up controller.stepUpOptions over the
|
|
14
|
+
* secret-free intent projection
|
|
15
|
+
*
|
|
16
|
+
* Auth matrix (OQ-7 overrides the plan's bearer/none blanket 403):
|
|
17
|
+
* - tuning/retention/feature/reader_first saves are allowed in passkey,
|
|
18
|
+
* bearer AND none modes (Origin enforcement stays with the factory: a POST
|
|
19
|
+
* on a write path without an Origin header is rejected there);
|
|
20
|
+
* - any op touching the policy or secret class requires a valid step-up
|
|
21
|
+
* assertion ON the save request (`stepUp.challengeId` + the browser's
|
|
22
|
+
* AuthenticationResponseJSON); the server recomputes the intent digest from
|
|
23
|
+
* THIS request and the controller consumes the challenge atomically with
|
|
24
|
+
* the write attempt;
|
|
25
|
+
* - bearer/none modes cannot mint or verify a step-up: policy/secret intents
|
|
26
|
+
* get 403 `step_up_unavailable`.
|
|
27
|
+
*
|
|
28
|
+
* The class of change is computed SERVER-SIDE from the registry — the client
|
|
29
|
+
* cannot downgrade a policy save to tuning, and a tuning-only step-up options
|
|
30
|
+
* request is answered `required:false` without minting a challenge.
|
|
31
|
+
*
|
|
32
|
+
* `published_uncertain` (frozen response schemas carry no outcome field) maps
|
|
33
|
+
* to HTTP 500 `settings_published_uncertain` carrying the published revision
|
|
34
|
+
* (T09 wire delta) and an explicit "the document WAS published at revision N"
|
|
35
|
+
* message — never a clean rejection, and the client must re-read rather than
|
|
36
|
+
* blind-retry (the revision CAS makes a retry against the landed write a 409,
|
|
37
|
+
* so a double apply is impossible either way).
|
|
38
|
+
*
|
|
39
|
+
* Secret values never appear in any response: the store never returns them,
|
|
40
|
+
* the step-up intent projection strips them, and the processes wire carries
|
|
41
|
+
* key names only.
|
|
42
|
+
*/
|
|
43
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
44
|
+
import { SettingsStore } from "../settings/store.js";
|
|
45
|
+
import type { SettingsAuth } from "../settings/schema.js";
|
|
46
|
+
import type { DashboardPasskeyAuth } from "./auth/controller.js";
|
|
47
|
+
import type { SettingsProcessReader } from "./settings-process-reader.js";
|
|
48
|
+
/** `["api","settings"]` — the GET read route. */
|
|
49
|
+
export declare function isSettingsReadSegments(segments: readonly string[]): boolean;
|
|
50
|
+
/** `["api","settings","processes"]` — the GET processes route. */
|
|
51
|
+
export declare function isSettingsProcessesSegments(segments: readonly string[]): boolean;
|
|
52
|
+
/** `["api","settings","save"]` — the settings save POST. */
|
|
53
|
+
export declare function isSettingsSaveSegments(segments: readonly string[]): boolean;
|
|
54
|
+
/** `["api","settings","secrets","save"]` — the secrets save POST. */
|
|
55
|
+
export declare function isSettingsSecretsSaveSegments(segments: readonly string[]): boolean;
|
|
56
|
+
/** `["api","settings","step-up"]` — the step-up options POST. */
|
|
57
|
+
export declare function isSettingsStepUpSegments(segments: readonly string[]): boolean;
|
|
58
|
+
/** Exactly the five settings routes — used by `isKnownDashboardApiRoute`. */
|
|
59
|
+
export declare function isSettingsApiSegments(segments: readonly string[]): boolean;
|
|
60
|
+
/** The three settings POSTs — used by `isDashboardWritePathSegments`. */
|
|
61
|
+
export declare function isSettingsWriteSegments(segments: readonly string[]): boolean;
|
|
62
|
+
/** Step-up options requests carry an intent projection only. */
|
|
63
|
+
export declare const MAX_SETTINGS_STEP_UP_BODY_BYTES: number;
|
|
64
|
+
/** Saves may carry a WebAuthn assertion alongside up to 64 ops. */
|
|
65
|
+
export declare const MAX_SETTINGS_SAVE_BODY_BYTES: number;
|
|
66
|
+
/** Structural twin of request-admission's DashboardRequestTarget (no cycle). */
|
|
67
|
+
export interface SettingsRequestTarget {
|
|
68
|
+
readonly path: string;
|
|
69
|
+
readonly query: URLSearchParams;
|
|
70
|
+
readonly segments: readonly string[];
|
|
71
|
+
}
|
|
72
|
+
export interface DashboardSettingsRoutesOptions {
|
|
73
|
+
readonly store: SettingsStore;
|
|
74
|
+
readonly processReader: SettingsProcessReader;
|
|
75
|
+
/** `<settingsDir>/processes`. */
|
|
76
|
+
readonly processesDir: string;
|
|
77
|
+
/** Passkey authority; presence selects passkey step-up semantics. */
|
|
78
|
+
readonly passkeyAuth?: DashboardPasskeyAuth | undefined;
|
|
79
|
+
/** Audit/step-up auth mode; defaults to "passkey" when passkeyAuth is present. */
|
|
80
|
+
readonly authMode?: SettingsAuth | undefined;
|
|
81
|
+
readonly now?: (() => Date) | undefined;
|
|
82
|
+
}
|
|
83
|
+
export interface DashboardSettingsRoutes {
|
|
84
|
+
handles(segments: readonly string[]): boolean;
|
|
85
|
+
handle(request: IncomingMessage, response: ServerResponse, target: SettingsRequestTarget): Promise<void>;
|
|
86
|
+
}
|
|
87
|
+
export declare function createDashboardSettingsRoutes(options: DashboardSettingsRoutesOptions): DashboardSettingsRoutes;
|