@basaltkit/deploy-ui 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +167 -2
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +3 -0
- package/dist/cli.d.ts +34 -0
- package/dist/cli.js +124 -0
- package/dist/client/api.js +203 -0
- package/dist/client/app.js +235 -0
- package/dist/client/dialog.js +47 -0
- package/dist/client/dom.js +51 -0
- package/dist/client/main.js +81 -0
- package/dist/client/messages.d.ts +58 -0
- package/dist/client/messages.js +1 -0
- package/dist/client/reply.js +40 -0
- package/dist/client/sanitize.js +16 -0
- package/dist/client/view-history.js +52 -0
- package/dist/client/view-plan.js +154 -0
- package/dist/client/view-run.js +311 -0
- package/dist/client/view-status.js +38 -0
- package/dist/client/view-targets.js +132 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +14 -0
- package/dist/open.d.ts +13 -0
- package/dist/open.js +31 -0
- package/dist/page.d.ts +7 -0
- package/dist/page.js +101 -0
- package/dist/remote.d.ts +68 -0
- package/dist/remote.js +220 -0
- package/dist/security.d.ts +38 -0
- package/dist/security.js +64 -0
- package/dist/server.d.ts +39 -0
- package/dist/server.js +513 -0
- package/dist/session.d.ts +66 -0
- package/dist/session.js +123 -0
- package/dist/ssh.d.ts +71 -0
- package/dist/ssh.js +186 -0
- package/dist/stream.d.ts +70 -0
- package/dist/stream.js +155 -0
- package/dist/targets.d.ts +80 -0
- package/dist/targets.js +242 -0
- package/package.json +51 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @basaltkit/deploy-ui — a local UI for @basaltkit/deploy (RFC 0009). The
|
|
3
|
+
* package is a program (`basalt-deploy-ui`); these exports are its building
|
|
4
|
+
* blocks, for tests and for a wrapper that starts it differently.
|
|
5
|
+
*/
|
|
6
|
+
export { main, parseFlags, USAGE } from './cli.js';
|
|
7
|
+
export { startUiServer, MAX_SSH_SESSIONS } from './server.js';
|
|
8
|
+
export { checkRequest, SECURITY_HEADERS } from './security.js';
|
|
9
|
+
export { IdleTimer, Session, LAUNCH_TTL_MS } from './session.js';
|
|
10
|
+
export { checkTarget, checkTargetsFile, defaultTargetsPath, readTargets, writeTargets, TargetsFileError } from './targets.js';
|
|
11
|
+
export { classifySshFailure, DEPLOY_BIN, remoteCommand, shQuote, sshArgs, sshProgram, SSH_OPTIONS } from './ssh.js';
|
|
12
|
+
export { ProtocolReader, sanitizeText, MAX_LINE_BYTES } from './stream.js';
|
|
13
|
+
export { execRemote, follow } from './remote.js';
|
|
14
|
+
export { openerCommand } from './open.js';
|
package/dist/open.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Spawn } from './remote.js';
|
|
2
|
+
/**
|
|
3
|
+
* The platform's browser opener, as argv (RFC 0009 §4.6): never a shell —
|
|
4
|
+
* `cmd /c start` would need one and mangles `&` and `#`. On Windows an
|
|
5
|
+
* absolute `rundll32.exe`: a bare name is looked up in the working directory
|
|
6
|
+
* first.
|
|
7
|
+
*/
|
|
8
|
+
export declare function openerCommand(platform: NodeJS.Platform, url: string, env?: NodeJS.ProcessEnv): {
|
|
9
|
+
command: string;
|
|
10
|
+
args: string[];
|
|
11
|
+
};
|
|
12
|
+
/** Starts the opener, detached and silent, in `cwd` (the home directory, never the app's); resolves false when it could not start or failed. */
|
|
13
|
+
export declare function openBrowser(spawn: Spawn, platform: NodeJS.Platform, url: string, cwd?: string, env?: NodeJS.ProcessEnv): Promise<boolean>;
|
package/dist/open.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { win32 } from 'node:path';
|
|
2
|
+
import { windowsSystemRoot } from './ssh.js';
|
|
3
|
+
/**
|
|
4
|
+
* The platform's browser opener, as argv (RFC 0009 §4.6): never a shell —
|
|
5
|
+
* `cmd /c start` would need one and mangles `&` and `#`. On Windows an
|
|
6
|
+
* absolute `rundll32.exe`: a bare name is looked up in the working directory
|
|
7
|
+
* first.
|
|
8
|
+
*/
|
|
9
|
+
export function openerCommand(platform, url, env = {}) {
|
|
10
|
+
if (platform === 'darwin')
|
|
11
|
+
return { command: 'open', args: [url] };
|
|
12
|
+
if (platform === 'win32')
|
|
13
|
+
return { command: win32.join(windowsSystemRoot(env), 'System32', 'rundll32.exe'), args: ['url.dll,FileProtocolHandler', url] };
|
|
14
|
+
return { command: 'xdg-open', args: [url] };
|
|
15
|
+
}
|
|
16
|
+
/** Starts the opener, detached and silent, in `cwd` (the home directory, never the app's); resolves false when it could not start or failed. */
|
|
17
|
+
export function openBrowser(spawn, platform, url, cwd, env = {}) {
|
|
18
|
+
const { command, args } = openerCommand(platform, url, env);
|
|
19
|
+
return new Promise((resolve) => {
|
|
20
|
+
try {
|
|
21
|
+
const options = { shell: false, stdio: 'ignore', detached: platform !== 'win32', windowsHide: true, ...(cwd ? { cwd } : {}) };
|
|
22
|
+
const child = spawn(command, args, options);
|
|
23
|
+
child.on('error', () => resolve(false));
|
|
24
|
+
child.on('exit', (code) => resolve(code === 0));
|
|
25
|
+
child.unref();
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
resolve(false);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
package/dist/page.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page and its stylesheet, as strings (the way the `*-ui` packages ship
|
|
3
|
+
* markup): no inline script, no inline style — the CSP allows neither. The
|
|
4
|
+
* one module script is `/client/main.js`, compiled by tsc from `src/client`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const INDEX_HTML = "<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n<meta name=\"referrer\" content=\"no-referrer\">\n<title>Basalt deploy</title>\n<link rel=\"stylesheet\" href=\"/app.css\">\n<script type=\"module\" src=\"/client/main.js\"></script>\n</head>\n<body>\n<header class=\"top\">\n <h1 class=\"brand\">Basalt deploy</h1>\n <nav id=\"nav\" aria-label=\"Screens\"></nav>\n <div id=\"session\" class=\"session\"></div>\n</header>\n<div id=\"target-bar\" class=\"target-bar\" aria-live=\"polite\"></div>\n<main id=\"app\" class=\"app\">\n <p class=\"muted\">Starting\u2026</p>\n <noscript><p>This UI needs JavaScript (its own module only; nothing is loaded from elsewhere).</p></noscript>\n</main>\n<footer class=\"foot\"><p class=\"muted\">Local only: this page talks to 127.0.0.1, which talks to your servers over your own ssh.</p></footer>\n</body>\n</html>\n";
|
|
7
|
+
export declare const APP_CSS = ":root {\n --bg: #f7f7f5; --fg: #1d1d1b; --muted: #5f5f5a; --panel: #ffffff; --line: #d9d9d4;\n --accent: #8a3b12; --accent-fg: #ffffff; --ok: #1f6b3a; --warn: #8a5a00; --err: #a3231b; --code: #efefea;\n color-scheme: light dark;\n}\n@media (prefers-color-scheme: dark) {\n :root {\n --bg: #161615; --fg: #ecece8; --muted: #a5a59e; --panel: #1f1f1d; --line: #3a3a36;\n --accent: #e0864d; --accent-fg: #161615; --ok: #6fcf8f; --warn: #e6b450; --err: #ff7b72; --code: #262623;\n }\n}\n* { box-sizing: border-box; }\nhtml, body { margin: 0; background: var(--bg); color: var(--fg); }\nbody { font: 15px/1.5 system-ui, -apple-system, \"Segoe UI\", sans-serif; }\n.top { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }\n.brand { font-size: 1.1rem; margin: 0; }\nnav { display: flex; flex-wrap: wrap; gap: 4px; }\n.session { margin-left: auto; display: flex; gap: 8px; align-items: center; }\n.target-bar { padding: 8px 16px; border-bottom: 1px solid var(--line); font-family: ui-monospace, monospace; font-size: 0.9rem; overflow-wrap: anywhere; }\n.target-bar:empty { display: none; }\n.app { max-width: 1100px; margin: 0 auto; padding: 16px; }\n.foot { max-width: 1100px; margin: 0 auto; padding: 0 16px 24px; }\nh2 { font-size: 1.2rem; margin: 1.2em 0 0.5em; }\nh3 { font-size: 1rem; margin: 1em 0 0.4em; }\n.muted { color: var(--muted); }\nbutton, .button { font: inherit; padding: 6px 12px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--fg); cursor: pointer; }\nbutton:hover { border-color: var(--accent); }\nbutton:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }\nbutton.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }\nbutton.danger { border-color: var(--err); color: var(--err); }\nbutton[aria-current=\"page\"] { border-color: var(--accent); font-weight: 600; }\nbutton:disabled { opacity: 0.5; cursor: not-allowed; }\n.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 16px; margin: 12px 0; }\n.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }\ntable { border-collapse: collapse; width: 100%; }\nth, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }\n.table-wrap { overflow-x: auto; }\ncode, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }\ncode { background: var(--code); padding: 1px 4px; border-radius: 4px; overflow-wrap: anywhere; }\n.field { display: grid; gap: 4px; margin: 10px 0; }\n.field input[type=\"text\"], .field input[type=\"password\"], .field input[type=\"number\"], .field select { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); width: 100%; max-width: 32rem; }\n.field-error { color: var(--err); font-size: 0.9rem; }\n.required { color: var(--err); }\n.status-ok { color: var(--ok); }\n.status-warn { color: var(--warn); }\n.status-err { color: var(--err); }\n.banner { border-left: 4px solid var(--line); padding: 8px 12px; margin: 12px 0; background: var(--panel); }\n.banner.ok { border-color: var(--ok); }\n.banner.warn { border-color: var(--warn); }\n.banner.err { border-color: var(--err); }\n.steps { list-style: none; padding: 0; margin: 0; }\n.steps li { padding: 2px 0; }\n.log { list-style: none; margin: 0; padding: 8px; max-height: 60vh; overflow-y: auto; background: var(--code); border-radius: 6px; font-family: ui-monospace, monospace; font-size: 0.85rem; white-space: pre-wrap; overflow-wrap: anywhere; }\n.log li { padding: 0 0 1px; }\n.log .warn { color: var(--warn); }\n.log .error { color: var(--err); }\n.log .src { color: var(--muted); }\n.diagnostics { white-space: pre-wrap; overflow-wrap: anywhere; font-family: ui-monospace, monospace; font-size: 0.85rem; }\ndialog { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--fg); max-width: min(36rem, calc(100vw - 32px)); }\ndialog::backdrop { background: rgb(0 0 0 / 0.45); }\n.hidden { display: none; }\n.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }\n@media (max-width: 640px) {\n .top { padding: 10px 16px; }\n .session { margin-left: 0; }\n th, td { padding: 4px; }\n}\n@media (prefers-reduced-motion: reduce) {\n * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }\n}\n";
|
package/dist/page.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page and its stylesheet, as strings (the way the `*-ui` packages ship
|
|
3
|
+
* markup): no inline script, no inline style — the CSP allows neither. The
|
|
4
|
+
* one module script is `/client/main.js`, compiled by tsc from `src/client`.
|
|
5
|
+
*/
|
|
6
|
+
export const INDEX_HTML = `<!doctype html>
|
|
7
|
+
<html lang="en">
|
|
8
|
+
<head>
|
|
9
|
+
<meta charset="utf-8">
|
|
10
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
11
|
+
<meta name="referrer" content="no-referrer">
|
|
12
|
+
<title>Basalt deploy</title>
|
|
13
|
+
<link rel="stylesheet" href="/app.css">
|
|
14
|
+
<script type="module" src="/client/main.js"></script>
|
|
15
|
+
</head>
|
|
16
|
+
<body>
|
|
17
|
+
<header class="top">
|
|
18
|
+
<h1 class="brand">Basalt deploy</h1>
|
|
19
|
+
<nav id="nav" aria-label="Screens"></nav>
|
|
20
|
+
<div id="session" class="session"></div>
|
|
21
|
+
</header>
|
|
22
|
+
<div id="target-bar" class="target-bar" aria-live="polite"></div>
|
|
23
|
+
<main id="app" class="app">
|
|
24
|
+
<p class="muted">Starting…</p>
|
|
25
|
+
<noscript><p>This UI needs JavaScript (its own module only; nothing is loaded from elsewhere).</p></noscript>
|
|
26
|
+
</main>
|
|
27
|
+
<footer class="foot"><p class="muted">Local only: this page talks to 127.0.0.1, which talks to your servers over your own ssh.</p></footer>
|
|
28
|
+
</body>
|
|
29
|
+
</html>
|
|
30
|
+
`;
|
|
31
|
+
export const APP_CSS = `:root {
|
|
32
|
+
--bg: #f7f7f5; --fg: #1d1d1b; --muted: #5f5f5a; --panel: #ffffff; --line: #d9d9d4;
|
|
33
|
+
--accent: #8a3b12; --accent-fg: #ffffff; --ok: #1f6b3a; --warn: #8a5a00; --err: #a3231b; --code: #efefea;
|
|
34
|
+
color-scheme: light dark;
|
|
35
|
+
}
|
|
36
|
+
@media (prefers-color-scheme: dark) {
|
|
37
|
+
:root {
|
|
38
|
+
--bg: #161615; --fg: #ecece8; --muted: #a5a59e; --panel: #1f1f1d; --line: #3a3a36;
|
|
39
|
+
--accent: #e0864d; --accent-fg: #161615; --ok: #6fcf8f; --warn: #e6b450; --err: #ff7b72; --code: #262623;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
* { box-sizing: border-box; }
|
|
43
|
+
html, body { margin: 0; background: var(--bg); color: var(--fg); }
|
|
44
|
+
body { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
|
|
45
|
+
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
|
|
46
|
+
.brand { font-size: 1.1rem; margin: 0; }
|
|
47
|
+
nav { display: flex; flex-wrap: wrap; gap: 4px; }
|
|
48
|
+
.session { margin-left: auto; display: flex; gap: 8px; align-items: center; }
|
|
49
|
+
.target-bar { padding: 8px 16px; border-bottom: 1px solid var(--line); font-family: ui-monospace, monospace; font-size: 0.9rem; overflow-wrap: anywhere; }
|
|
50
|
+
.target-bar:empty { display: none; }
|
|
51
|
+
.app { max-width: 1100px; margin: 0 auto; padding: 16px; }
|
|
52
|
+
.foot { max-width: 1100px; margin: 0 auto; padding: 0 16px 24px; }
|
|
53
|
+
h2 { font-size: 1.2rem; margin: 1.2em 0 0.5em; }
|
|
54
|
+
h3 { font-size: 1rem; margin: 1em 0 0.4em; }
|
|
55
|
+
.muted { color: var(--muted); }
|
|
56
|
+
button, .button { font: inherit; padding: 6px 12px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--fg); cursor: pointer; }
|
|
57
|
+
button:hover { border-color: var(--accent); }
|
|
58
|
+
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
59
|
+
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
|
|
60
|
+
button.danger { border-color: var(--err); color: var(--err); }
|
|
61
|
+
button[aria-current="page"] { border-color: var(--accent); font-weight: 600; }
|
|
62
|
+
button:disabled { opacity: 0.5; cursor: not-allowed; }
|
|
63
|
+
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 16px; margin: 12px 0; }
|
|
64
|
+
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
|
|
65
|
+
table { border-collapse: collapse; width: 100%; }
|
|
66
|
+
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
|
|
67
|
+
.table-wrap { overflow-x: auto; }
|
|
68
|
+
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }
|
|
69
|
+
code { background: var(--code); padding: 1px 4px; border-radius: 4px; overflow-wrap: anywhere; }
|
|
70
|
+
.field { display: grid; gap: 4px; margin: 10px 0; }
|
|
71
|
+
.field input[type="text"], .field input[type="password"], .field input[type="number"], .field select { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); width: 100%; max-width: 32rem; }
|
|
72
|
+
.field-error { color: var(--err); font-size: 0.9rem; }
|
|
73
|
+
.required { color: var(--err); }
|
|
74
|
+
.status-ok { color: var(--ok); }
|
|
75
|
+
.status-warn { color: var(--warn); }
|
|
76
|
+
.status-err { color: var(--err); }
|
|
77
|
+
.banner { border-left: 4px solid var(--line); padding: 8px 12px; margin: 12px 0; background: var(--panel); }
|
|
78
|
+
.banner.ok { border-color: var(--ok); }
|
|
79
|
+
.banner.warn { border-color: var(--warn); }
|
|
80
|
+
.banner.err { border-color: var(--err); }
|
|
81
|
+
.steps { list-style: none; padding: 0; margin: 0; }
|
|
82
|
+
.steps li { padding: 2px 0; }
|
|
83
|
+
.log { list-style: none; margin: 0; padding: 8px; max-height: 60vh; overflow-y: auto; background: var(--code); border-radius: 6px; font-family: ui-monospace, monospace; font-size: 0.85rem; white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
84
|
+
.log li { padding: 0 0 1px; }
|
|
85
|
+
.log .warn { color: var(--warn); }
|
|
86
|
+
.log .error { color: var(--err); }
|
|
87
|
+
.log .src { color: var(--muted); }
|
|
88
|
+
.diagnostics { white-space: pre-wrap; overflow-wrap: anywhere; font-family: ui-monospace, monospace; font-size: 0.85rem; }
|
|
89
|
+
dialog { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--fg); max-width: min(36rem, calc(100vw - 32px)); }
|
|
90
|
+
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
|
|
91
|
+
.hidden { display: none; }
|
|
92
|
+
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
|
|
93
|
+
@media (max-width: 640px) {
|
|
94
|
+
.top { padding: 10px 16px; }
|
|
95
|
+
.session { margin-left: 0; }
|
|
96
|
+
th, td { padding: 4px; }
|
|
97
|
+
}
|
|
98
|
+
@media (prefers-reduced-motion: reduce) {
|
|
99
|
+
* { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
|
|
100
|
+
}
|
|
101
|
+
`;
|
package/dist/remote.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { ChildProcess, SpawnOptions } from 'node:child_process';
|
|
2
|
+
import type { DeployEvent, DoneEvent, ErrorEvent, HelloEvent } from '@basaltkit/deploy/protocol';
|
|
3
|
+
import type { CommandReply, Failure, StreamMessage } from './client/messages.js';
|
|
4
|
+
import { type RemoteSpec } from './ssh.js';
|
|
5
|
+
import type { Target } from './targets.js';
|
|
6
|
+
/**
|
|
7
|
+
* One remote command over ssh, read through {@link ProtocolReader}: the
|
|
8
|
+
* events, the result, the error and how it ended. Answers go on stdin, up
|
|
9
|
+
* front, then stdin is closed and the buffer zero-filled.
|
|
10
|
+
*/
|
|
11
|
+
export type Spawn = (command: string, args: readonly string[], options: SpawnOptions) => ChildProcess;
|
|
12
|
+
export interface SshRunner {
|
|
13
|
+
/** `ssh`, `ssh.exe` or `--ssh=<path>` (a test: node). */
|
|
14
|
+
program: string;
|
|
15
|
+
/** Arguments before ssh's own (a test: the fake ssh script). Empty in use. */
|
|
16
|
+
prefix: readonly string[];
|
|
17
|
+
spawn: Spawn;
|
|
18
|
+
/** The UI process's own environment, unchanged: nothing is added to it. */
|
|
19
|
+
env: NodeJS.ProcessEnv;
|
|
20
|
+
/** Where ssh starts: the operator's home, never the directory the UI was started from (a cloned app). */
|
|
21
|
+
cwd?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface ExecOptions {
|
|
24
|
+
actor?: string;
|
|
25
|
+
/** The answer lines, sent on stdin and then zero-filled. */
|
|
26
|
+
stdin?: Buffer;
|
|
27
|
+
timeoutMs?: number;
|
|
28
|
+
signal?: AbortSignal;
|
|
29
|
+
onEvent?: (event: DeployEvent, known: boolean) => void;
|
|
30
|
+
onInner?: (event: DeployEvent, known: boolean) => void;
|
|
31
|
+
onDiagnostic?: (text: string) => void;
|
|
32
|
+
}
|
|
33
|
+
export interface RemoteOutcome {
|
|
34
|
+
hello?: HelloEvent;
|
|
35
|
+
error?: ErrorEvent;
|
|
36
|
+
result?: unknown;
|
|
37
|
+
done?: DoneEvent;
|
|
38
|
+
innerDone?: DoneEvent;
|
|
39
|
+
lastInnerSeq?: number;
|
|
40
|
+
failure?: Failure;
|
|
41
|
+
/** Foreign text before `hello`, then ssh's stderr. */
|
|
42
|
+
diagnostics: string[];
|
|
43
|
+
/** ssh's stderr alone, sanitised. */
|
|
44
|
+
stderr: string[];
|
|
45
|
+
sshExit: number | null;
|
|
46
|
+
}
|
|
47
|
+
export declare const isPermanent: (failure: Failure) => boolean;
|
|
48
|
+
export declare function execRemote(runner: SshRunner, target: Target, spec: RemoteSpec, options?: ExecOptions): Promise<RemoteOutcome>;
|
|
49
|
+
/** The reply of a collected command: it succeeded only with `done` exit 0 and no failure. */
|
|
50
|
+
export declare function toReply(outcome: RemoteOutcome): CommandReply;
|
|
51
|
+
export interface FollowOptions {
|
|
52
|
+
signal: AbortSignal;
|
|
53
|
+
actor?: string;
|
|
54
|
+
sleep?: (ms: number, signal: AbortSignal) => Promise<void>;
|
|
55
|
+
now?: () => number;
|
|
56
|
+
/** How long to keep reconnecting without progress (RFC 0009 §7: 10 minutes). */
|
|
57
|
+
windowMs?: number;
|
|
58
|
+
}
|
|
59
|
+
export declare const RECONNECT_FIRST_MS = 1000;
|
|
60
|
+
export declare const RECONNECT_MAX_MS = 30000;
|
|
61
|
+
export declare const RECONNECT_WINDOW_MS: number;
|
|
62
|
+
/**
|
|
63
|
+
* `attach --follow` that survives a dropped connection: when ssh ends without
|
|
64
|
+
* the run's `done`, it attaches again from the last run seq + 1 (1 s, 2 s, 4 s
|
|
65
|
+
* … 30 s, for up to 10 minutes without progress). The page never sees a
|
|
66
|
+
* duplicate or a gap: the reader checks the run's sequence on every attach.
|
|
67
|
+
*/
|
|
68
|
+
export declare function follow(runner: SshRunner, target: Target, runId: string, fromSeq: number, emit: (message: StreamMessage) => void, options: FollowOptions): Promise<void>;
|
package/dist/remote.js
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { classifySshFailure, remoteCommand, sshArgs } from './ssh.js';
|
|
2
|
+
import { Diagnostics, ProtocolReader } from './stream.js';
|
|
3
|
+
/** Failures that a retry cannot fix: the key, the host key, the server's setup, or a stream that lied. */
|
|
4
|
+
const PERMANENT = new Set(['ssh-missing', 'auth', 'passphrase', 'host-key', 'no-node', 'no-dir', 'no-deploy', 'corrupt', 'protocol-version', 'no-protocol', 'unsafe', 'cancelled']);
|
|
5
|
+
export const isPermanent = (failure) => PERMANENT.has(failure.code);
|
|
6
|
+
export async function execRemote(runner, target, spec, options = {}) {
|
|
7
|
+
const stdin = options.stdin;
|
|
8
|
+
let args;
|
|
9
|
+
try {
|
|
10
|
+
args = [...runner.prefix, ...sshArgs(target, remoteCommand(target, spec, options.actor))];
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
stdin?.fill(0);
|
|
14
|
+
return { failure: { code: 'unsafe', message: error.message }, diagnostics: [], stderr: [], sshExit: null };
|
|
15
|
+
}
|
|
16
|
+
let result;
|
|
17
|
+
let error;
|
|
18
|
+
const reader = new ProtocolReader({
|
|
19
|
+
...(spec.command === 'attach' ? { attach: { fromSeq: spec.fromSeq ?? 0 } } : {}),
|
|
20
|
+
onEvent: (event, known) => {
|
|
21
|
+
if (event.type === 'result')
|
|
22
|
+
result = event.data;
|
|
23
|
+
if (event.type === 'error')
|
|
24
|
+
error = event;
|
|
25
|
+
options.onEvent?.(event, known);
|
|
26
|
+
},
|
|
27
|
+
...(options.onInner ? { onInner: options.onInner } : {}),
|
|
28
|
+
...(options.onDiagnostic ? { onDiagnostic: options.onDiagnostic } : {}),
|
|
29
|
+
});
|
|
30
|
+
const stderr = new Diagnostics();
|
|
31
|
+
let rawStderr = '';
|
|
32
|
+
let timedOut = false;
|
|
33
|
+
let cancelled = false;
|
|
34
|
+
let spawnError;
|
|
35
|
+
const exit = await new Promise((resolve) => {
|
|
36
|
+
let child;
|
|
37
|
+
try {
|
|
38
|
+
child = runner.spawn(runner.program, args, {
|
|
39
|
+
shell: false,
|
|
40
|
+
windowsHide: true,
|
|
41
|
+
stdio: [stdin ? 'pipe' : 'ignore', 'pipe', 'pipe'],
|
|
42
|
+
env: runner.env,
|
|
43
|
+
...(runner.cwd ? { cwd: runner.cwd } : {}),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
catch (caught) {
|
|
47
|
+
spawnError = caught;
|
|
48
|
+
stdin?.fill(0);
|
|
49
|
+
resolve(null);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const stop = () => { if (child.exitCode === null && child.signalCode === null)
|
|
53
|
+
child.kill('SIGTERM'); };
|
|
54
|
+
const timer = options.timeoutMs ? setTimeout(() => { timedOut = true; stop(); }, options.timeoutMs) : undefined;
|
|
55
|
+
const onAbort = () => { cancelled = true; stop(); };
|
|
56
|
+
if (options.signal?.aborted)
|
|
57
|
+
onAbort();
|
|
58
|
+
options.signal?.addEventListener('abort', onAbort, { once: true });
|
|
59
|
+
child.on('error', (caught) => { spawnError = caught; });
|
|
60
|
+
child.stdout?.on('data', (chunk) => { if (!reader.push(chunk))
|
|
61
|
+
stop(); });
|
|
62
|
+
child.stderr?.on('data', (chunk) => {
|
|
63
|
+
if (rawStderr.length < 64 * 1024)
|
|
64
|
+
rawStderr += chunk.toString('utf8');
|
|
65
|
+
stderr.add(chunk.toString('utf8'));
|
|
66
|
+
});
|
|
67
|
+
if (stdin && child.stdin) {
|
|
68
|
+
// The reader may be gone already (a refused connection): EPIPE is not an error of ours.
|
|
69
|
+
child.stdin.on('error', () => undefined);
|
|
70
|
+
child.stdin.end(stdin, () => stdin.fill(0));
|
|
71
|
+
}
|
|
72
|
+
else
|
|
73
|
+
stdin?.fill(0);
|
|
74
|
+
child.on('close', (code) => {
|
|
75
|
+
if (timer)
|
|
76
|
+
clearTimeout(timer);
|
|
77
|
+
options.signal?.removeEventListener('abort', onAbort);
|
|
78
|
+
stdin?.fill(0);
|
|
79
|
+
resolve(code);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
reader.end();
|
|
83
|
+
const stderrLines = stderr.lines.filter((line) => line.trim() !== '');
|
|
84
|
+
if (stderr.dropped > 0)
|
|
85
|
+
stderrLines.push(`(${stderr.dropped} more bytes of stderr not shown)`);
|
|
86
|
+
const diagnostics = [...reader.diagnostics.lines, ...stderrLines];
|
|
87
|
+
const outcome = {
|
|
88
|
+
...(reader.hello ? { hello: reader.hello } : {}),
|
|
89
|
+
...(error ? { error } : {}),
|
|
90
|
+
...(result !== undefined ? { result } : {}),
|
|
91
|
+
...(reader.done ? { done: reader.done } : {}),
|
|
92
|
+
...(reader.innerDone ? { innerDone: reader.innerDone } : {}),
|
|
93
|
+
...(reader.lastInnerSeq !== undefined ? { lastInnerSeq: reader.lastInnerSeq } : {}),
|
|
94
|
+
diagnostics,
|
|
95
|
+
stderr: stderrLines,
|
|
96
|
+
sshExit: exit,
|
|
97
|
+
};
|
|
98
|
+
const failure = describeFailure(reader, { spawnError, timedOut, cancelled, exit, stderr: rawStderr, destination: target.ssh });
|
|
99
|
+
if (failure)
|
|
100
|
+
outcome.failure = failure;
|
|
101
|
+
return outcome;
|
|
102
|
+
}
|
|
103
|
+
function describeFailure(reader, how) {
|
|
104
|
+
if (how.spawnError) {
|
|
105
|
+
return how.spawnError.code === 'ENOENT'
|
|
106
|
+
? { code: 'ssh-missing', message: 'no ssh client was found', hint: 'install OpenSSH (on Windows: the OpenSSH Client optional feature), or pass --ssh=<absolute path>' }
|
|
107
|
+
: { code: 'ssh', message: `ssh could not start: ${how.spawnError.message}` };
|
|
108
|
+
}
|
|
109
|
+
if (reader.failure && reader.failure.kind !== 'truncated')
|
|
110
|
+
return { code: reader.failure.kind, message: reader.failure.message };
|
|
111
|
+
if (how.cancelled)
|
|
112
|
+
return { code: 'cancelled', message: 'stopped by the UI' };
|
|
113
|
+
if (how.timedOut)
|
|
114
|
+
return { code: 'timeout', message: 'the command took too long and was stopped' };
|
|
115
|
+
if (reader.done)
|
|
116
|
+
return undefined;
|
|
117
|
+
const ssh = classifySshFailure(how.exit, how.stderr, how.destination);
|
|
118
|
+
if (!reader.hello) {
|
|
119
|
+
return ssh ?? {
|
|
120
|
+
code: 'no-protocol',
|
|
121
|
+
message: 'no protocol output from the server',
|
|
122
|
+
hint: 'is the account\'s login shell POSIX (sh, bash, zsh)? Does the app\'s @basaltkit/deploy speak protocol 1 (the release with RFC 0008)? Upgrade it in the app and deploy once from a terminal',
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const cut = reader.failure ? `${reader.failure.message}, ` : '';
|
|
126
|
+
return { code: 'abnormal', message: `the output ended without done (${cut}exit ${how.exit ?? 'by signal'}) — never a success`, ...(ssh ? { hint: ssh.message } : {}) };
|
|
127
|
+
}
|
|
128
|
+
/** The reply of a collected command: it succeeded only with `done` exit 0 and no failure. */
|
|
129
|
+
export function toReply(outcome) {
|
|
130
|
+
return {
|
|
131
|
+
ok: !outcome.failure && outcome.done?.exitCode === 0,
|
|
132
|
+
...(outcome.hello ? { hello: outcome.hello } : {}),
|
|
133
|
+
...(outcome.result !== undefined ? { result: outcome.result } : {}),
|
|
134
|
+
...(outcome.error ? { error: outcome.error } : {}),
|
|
135
|
+
...(outcome.done ? { exitCode: outcome.done.exitCode } : {}),
|
|
136
|
+
...(outcome.failure ? { failure: outcome.failure } : {}),
|
|
137
|
+
diagnostics: outcome.diagnostics,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
export const RECONNECT_FIRST_MS = 1000;
|
|
141
|
+
export const RECONNECT_MAX_MS = 30_000;
|
|
142
|
+
export const RECONNECT_WINDOW_MS = 10 * 60_000;
|
|
143
|
+
const abortableSleep = (ms, signal) => new Promise((resolve) => {
|
|
144
|
+
const timer = setTimeout(done, ms);
|
|
145
|
+
function done() { clearTimeout(timer); signal.removeEventListener('abort', done); resolve(); }
|
|
146
|
+
signal.addEventListener('abort', done, { once: true });
|
|
147
|
+
});
|
|
148
|
+
/**
|
|
149
|
+
* `attach --follow` that survives a dropped connection: when ssh ends without
|
|
150
|
+
* the run's `done`, it attaches again from the last run seq + 1 (1 s, 2 s, 4 s
|
|
151
|
+
* … 30 s, for up to 10 minutes without progress). The page never sees a
|
|
152
|
+
* duplicate or a gap: the reader checks the run's sequence on every attach.
|
|
153
|
+
*/
|
|
154
|
+
export async function follow(runner, target, runId, fromSeq, emit, options) {
|
|
155
|
+
const sleep = options.sleep ?? abortableSleep;
|
|
156
|
+
const now = options.now ?? Date.now;
|
|
157
|
+
const windowMs = options.windowMs ?? RECONNECT_WINDOW_MS;
|
|
158
|
+
let next = fromSeq;
|
|
159
|
+
let delay = RECONNECT_FIRST_MS;
|
|
160
|
+
let since = now();
|
|
161
|
+
let greeted = false;
|
|
162
|
+
emit({ kind: 'state', state: 'connecting' });
|
|
163
|
+
for (;;) {
|
|
164
|
+
if (options.signal.aborted) {
|
|
165
|
+
emit({ kind: 'state', state: 'ended', code: 'stopped', reason: 'the UI stopped watching; the run goes on on the server' });
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
let progressed = false;
|
|
169
|
+
const outcome = await execRemote(runner, target, { command: 'attach', runId, fromSeq: next, follow: true }, {
|
|
170
|
+
signal: options.signal,
|
|
171
|
+
onEvent: (event) => {
|
|
172
|
+
if (event.type === 'hello' && !greeted) {
|
|
173
|
+
greeted = true;
|
|
174
|
+
emit({ kind: 'hello', hello: event });
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
onInner: (event, known) => {
|
|
178
|
+
next = event.seq + 1;
|
|
179
|
+
progressed = true;
|
|
180
|
+
emit({ kind: 'event', event, known });
|
|
181
|
+
},
|
|
182
|
+
onDiagnostic: (text) => emit({ kind: 'diagnostic', text }),
|
|
183
|
+
});
|
|
184
|
+
if (outcome.innerDone) {
|
|
185
|
+
emit({ kind: 'state', state: 'ended', exitCode: outcome.innerDone.exitCode });
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (outcome.error) {
|
|
189
|
+
emit({ kind: 'state', state: 'ended', code: outcome.error.code, reason: outcome.error.message, ...(outcome.error.hint ? { hint: outcome.error.hint } : {}) });
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (outcome.done && !outcome.failure) {
|
|
193
|
+
// Attach ended cleanly without the run's `done` in this window: the run's
|
|
194
|
+
// `done` came before `fromSeq` (RFC 0008 §8.4 — attach's exit code is the
|
|
195
|
+
// run's). The run has finished; reconnecting would never see more.
|
|
196
|
+
emit({ kind: 'state', state: 'ended', exitCode: outcome.done.exitCode, reason: 'the run had already finished' });
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const failure = outcome.failure ?? { code: 'abnormal', message: 'attach ended without the run\'s done' };
|
|
200
|
+
if (isPermanent(failure)) {
|
|
201
|
+
if (failure.code === 'cancelled')
|
|
202
|
+
continue;
|
|
203
|
+
for (const text of outcome.stderr)
|
|
204
|
+
emit({ kind: 'diagnostic', text });
|
|
205
|
+
emit({ kind: 'state', state: 'ended', code: failure.code, reason: failure.message, ...(failure.hint ? { hint: failure.hint } : {}) });
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (progressed) {
|
|
209
|
+
since = now();
|
|
210
|
+
delay = RECONNECT_FIRST_MS;
|
|
211
|
+
}
|
|
212
|
+
if (now() - since >= windowMs) {
|
|
213
|
+
emit({ kind: 'state', state: 'ended', code: 'disconnected', reason: `the connection kept dropping (${failure.message}); the run goes on on the server`, hint: 're-attach when the network is back' });
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
emit({ kind: 'state', state: 'reconnecting', code: failure.code, reason: failure.message, retryInMs: delay });
|
|
217
|
+
await sleep(delay, options.signal);
|
|
218
|
+
delay = Math.min(delay * 2, RECONNECT_MAX_MS);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The checks every request passes before routing (RFC 0009 §4.3), and the
|
|
3
|
+
* headers every response carries (§4.4). Pure: a request's method, path and
|
|
4
|
+
* headers in, a verdict out.
|
|
5
|
+
*
|
|
6
|
+
* The UI's server is reachable by every process on the machine and is the
|
|
7
|
+
* target of every page the browser opens: exact `Host` (DNS rebinding), a
|
|
8
|
+
* POST-only JSON API with an exact `Origin` (CSRF, cross-origin fetch), a
|
|
9
|
+
* bearer token no other page can read, and no CORS, ever.
|
|
10
|
+
*/
|
|
11
|
+
export declare const SECURITY_HEADERS: Readonly<Record<string, string>>;
|
|
12
|
+
export declare const MAX_BODY_BYTES: number;
|
|
13
|
+
/** A static file's name under /client/: flat, lowercase, `.js` — never a path. */
|
|
14
|
+
export declare const CLIENT_FILE: RegExp;
|
|
15
|
+
export interface RequestFacts {
|
|
16
|
+
method: string;
|
|
17
|
+
/** The raw request target (`req.url`). */
|
|
18
|
+
url: string;
|
|
19
|
+
headers: Record<string, string | string[] | undefined>;
|
|
20
|
+
}
|
|
21
|
+
export type Verdict = {
|
|
22
|
+
kind: 'static';
|
|
23
|
+
file: 'index' | 'css' | {
|
|
24
|
+
client: string;
|
|
25
|
+
};
|
|
26
|
+
} | {
|
|
27
|
+
kind: 'api';
|
|
28
|
+
route: string;
|
|
29
|
+
} | {
|
|
30
|
+
kind: 'refuse';
|
|
31
|
+
status: number;
|
|
32
|
+
reason: string;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Host, method, path, content type, origin and fetch metadata. The token is
|
|
36
|
+
* checked by the caller (it needs the session), after this verdict.
|
|
37
|
+
*/
|
|
38
|
+
export declare function checkRequest(facts: RequestFacts, port: number): Verdict;
|
package/dist/security.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The checks every request passes before routing (RFC 0009 §4.3), and the
|
|
3
|
+
* headers every response carries (§4.4). Pure: a request's method, path and
|
|
4
|
+
* headers in, a verdict out.
|
|
5
|
+
*
|
|
6
|
+
* The UI's server is reachable by every process on the machine and is the
|
|
7
|
+
* target of every page the browser opens: exact `Host` (DNS rebinding), a
|
|
8
|
+
* POST-only JSON API with an exact `Origin` (CSRF, cross-origin fetch), a
|
|
9
|
+
* bearer token no other page can read, and no CORS, ever.
|
|
10
|
+
*/
|
|
11
|
+
export const SECURITY_HEADERS = {
|
|
12
|
+
'Content-Security-Policy': "default-src 'none'; script-src 'self'; style-src 'self'; connect-src 'self'; img-src 'self'; font-src 'none'; form-action 'none'; base-uri 'none'; frame-ancestors 'none'",
|
|
13
|
+
'X-Frame-Options': 'DENY',
|
|
14
|
+
'X-Content-Type-Options': 'nosniff',
|
|
15
|
+
'Referrer-Policy': 'no-referrer',
|
|
16
|
+
'Cache-Control': 'no-store',
|
|
17
|
+
'Cross-Origin-Opener-Policy': 'same-origin',
|
|
18
|
+
'Cross-Origin-Resource-Policy': 'same-origin',
|
|
19
|
+
'Permissions-Policy': 'camera=(), microphone=(), geolocation=(), clipboard-read=()',
|
|
20
|
+
};
|
|
21
|
+
export const MAX_BODY_BYTES = 1024 * 1024;
|
|
22
|
+
/** A static file's name under /client/: flat, lowercase, `.js` — never a path. */
|
|
23
|
+
export const CLIENT_FILE = /^[a-z0-9-]+\.js$/;
|
|
24
|
+
const header = (facts, name) => {
|
|
25
|
+
const value = facts.headers[name];
|
|
26
|
+
return Array.isArray(value) ? undefined : value;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Host, method, path, content type, origin and fetch metadata. The token is
|
|
30
|
+
* checked by the caller (it needs the session), after this verdict.
|
|
31
|
+
*/
|
|
32
|
+
export function checkRequest(facts, port) {
|
|
33
|
+
const origin = `http://127.0.0.1:${port}`;
|
|
34
|
+
if (header(facts, 'host') !== `127.0.0.1:${port}`)
|
|
35
|
+
return { kind: 'refuse', status: 421, reason: 'wrong Host' };
|
|
36
|
+
// The request target is a path, nothing else: no absolute form, no query, no encoded or dot segment.
|
|
37
|
+
const path = facts.url;
|
|
38
|
+
if (!/^\/[A-Za-z0-9/._-]*$/.test(path) || path.includes('//') || path.split('/').some((s) => s === '.' || s === '..')) {
|
|
39
|
+
return { kind: 'refuse', status: 404, reason: 'not found' };
|
|
40
|
+
}
|
|
41
|
+
if (!path.startsWith('/api/')) {
|
|
42
|
+
if (facts.method !== 'GET' && facts.method !== 'HEAD')
|
|
43
|
+
return { kind: 'refuse', status: 405, reason: 'method not allowed' };
|
|
44
|
+
if (path === '/')
|
|
45
|
+
return { kind: 'static', file: 'index' };
|
|
46
|
+
if (path === '/app.css')
|
|
47
|
+
return { kind: 'static', file: 'css' };
|
|
48
|
+
const name = path.startsWith('/client/') ? path.slice('/client/'.length) : '';
|
|
49
|
+
if (CLIENT_FILE.test(name))
|
|
50
|
+
return { kind: 'static', file: { client: name } };
|
|
51
|
+
return { kind: 'refuse', status: 404, reason: 'not found' };
|
|
52
|
+
}
|
|
53
|
+
if (facts.method !== 'POST')
|
|
54
|
+
return { kind: 'refuse', status: 405, reason: 'POST only' };
|
|
55
|
+
const type = header(facts, 'content-type');
|
|
56
|
+
if (!type || !/^application\/json\s*(?:;\s*charset=utf-8\s*)?$/i.test(type))
|
|
57
|
+
return { kind: 'refuse', status: 415, reason: 'application/json only' };
|
|
58
|
+
if (header(facts, 'origin') !== origin)
|
|
59
|
+
return { kind: 'refuse', status: 403, reason: 'wrong Origin' };
|
|
60
|
+
const site = header(facts, 'sec-fetch-site');
|
|
61
|
+
if (site !== undefined && site !== 'same-origin')
|
|
62
|
+
return { kind: 'refuse', status: 403, reason: 'cross-site request' };
|
|
63
|
+
return { kind: 'api', route: path.slice('/api/'.length) };
|
|
64
|
+
}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type FollowOptions, type SshRunner } from './remote.js';
|
|
2
|
+
import { type TimerApi } from './session.js';
|
|
3
|
+
/**
|
|
4
|
+
* The UI's local server (RFC 0009 §4, §7): `node:http` on 127.0.0.1 and a
|
|
5
|
+
* port the OS picks, one browser session, ~10 POST routes. A request never
|
|
6
|
+
* carries a host, a path or a flag: it names a target, and the server builds
|
|
7
|
+
* everything else from the operator's targets file.
|
|
8
|
+
*/
|
|
9
|
+
export interface UiServerOptions {
|
|
10
|
+
targetsPath: string;
|
|
11
|
+
runner: SshRunner;
|
|
12
|
+
/** The OS user name, the actor when the targets file names none (if it matches the server's pattern). */
|
|
13
|
+
osUser?: string;
|
|
14
|
+
/** Default 15, at most 240. */
|
|
15
|
+
idleMinutes?: number;
|
|
16
|
+
/** Where the compiled client modules are (default: `dist/client` next to this file); null: none. */
|
|
17
|
+
clientDir?: string | null;
|
|
18
|
+
/** One line to the terminal. Never a request body, never an answer. */
|
|
19
|
+
log: (line: string) => void;
|
|
20
|
+
/** Called once when the server stops on its own (idle, quit). */
|
|
21
|
+
onStop?: (reason: 'idle' | 'quit') => void;
|
|
22
|
+
now?: () => number;
|
|
23
|
+
random?: (size: number) => Buffer;
|
|
24
|
+
timers?: TimerApi;
|
|
25
|
+
/** Reconnect pacing for attach (tests). */
|
|
26
|
+
follow?: Pick<FollowOptions, 'sleep' | 'now' | 'windowMs'>;
|
|
27
|
+
timeouts?: Partial<Record<'status' | 'plan' | 'detach' | 'cancel', number>>;
|
|
28
|
+
}
|
|
29
|
+
export interface UiServer {
|
|
30
|
+
port: number;
|
|
31
|
+
/** `http://127.0.0.1:<port>/` */
|
|
32
|
+
url: string;
|
|
33
|
+
/** The URL with the one-time launch code in its fragment. */
|
|
34
|
+
launchUrl: string;
|
|
35
|
+
close(): Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
export declare const MAX_SSH_SESSIONS = 4;
|
|
38
|
+
export declare const MAX_IDLE_MINUTES = 240;
|
|
39
|
+
export declare function startUiServer(options: UiServerOptions): Promise<UiServer>;
|