svamp-cli 0.2.267 → 0.2.269

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.
Files changed (26) hide show
  1. package/dist/{agentCommands-C-GPVVEh.mjs → agentCommands-Dzk4e5se.mjs} +7 -5
  2. package/dist/{auth-D95JIId0.mjs → auth-Bsp6Mn7W.mjs} +3 -1
  3. package/dist/{cli-Cf1ogBJ0.mjs → cli-COQg5XhV.mjs} +63 -63
  4. package/dist/cli.mjs +4 -2
  5. package/dist/{commands-Ddf4WJ7T.mjs → commands-BS1nRSti.mjs} +4 -2
  6. package/dist/{commands-XaQfalRc.mjs → commands-BbsqugoB.mjs} +4 -2
  7. package/dist/{commands-CZUC9mKz.mjs → commands-C-UQ3PbA.mjs} +3 -1
  8. package/dist/{commands-ByvuMAH7.mjs → commands-CJxlXlTy.mjs} +7 -7
  9. package/dist/{commands-BpoCTRmH.mjs → commands-DqyqbI0p.mjs} +3 -1
  10. package/dist/{commands-DnZIJg2B.mjs → commands-Y-Nna_A4.mjs} +4 -2
  11. package/dist/{commands-CI_YQANp.mjs → commands-v-bJG0B0.mjs} +3 -1
  12. package/dist/{fleet-D9WjmmSK.mjs → fleet-BNJf0oiF.mjs} +3 -1
  13. package/dist/{frpc-Dch3Eq_f.mjs → frpc-D0O_ho2a.mjs} +2 -1
  14. package/dist/{headlessCli-AfuoPfwV.mjs → headlessCli-CDajSqLP.mjs} +4 -2
  15. package/dist/index.mjs +3 -1
  16. package/dist/{package-B-3yvmAt.mjs → package-C4LMqtdL.mjs} +1 -1
  17. package/dist/{rpc-iRm5bxwr.mjs → rpc-CiB0ZTCJ.mjs} +3 -1
  18. package/dist/{rpc-BctBAWZg.mjs → rpc-KQlBd_Kl.mjs} +3 -1
  19. package/dist/{run-BblWx9WQ.mjs → run-BwLjjDzE.mjs} +3 -1
  20. package/dist/{run-Dn6ZqBs9.mjs → run-ZZJd3r3N.mjs} +10684 -9383
  21. package/dist/{scheduler-D4CmcA1u.mjs → scheduler-dJbWmJa6.mjs} +3 -1
  22. package/dist/{serveCommands-D6NMXj6M.mjs → serveCommands-Wy_O_dIQ.mjs} +5 -5
  23. package/dist/{sideband-DAbvCvgz.mjs → sideband-DgvSqT9x.mjs} +3 -1
  24. package/package.json +1 -1
  25. package/dist/serveManager-DFt3WQpJ.mjs +0 -902
  26. package/dist/staticFileServer-CbYnj2bH.mjs +0 -255
@@ -1,255 +0,0 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
-
4
- const MIME = {
5
- ".html": "text/html; charset=utf-8",
6
- ".htm": "text/html; charset=utf-8",
7
- ".js": "text/javascript; charset=utf-8",
8
- ".mjs": "text/javascript; charset=utf-8",
9
- ".css": "text/css; charset=utf-8",
10
- ".json": "application/json; charset=utf-8",
11
- ".map": "application/json; charset=utf-8",
12
- ".txt": "text/plain; charset=utf-8",
13
- ".md": "text/plain; charset=utf-8",
14
- ".xml": "application/xml; charset=utf-8",
15
- ".csv": "text/csv; charset=utf-8",
16
- ".svg": "image/svg+xml",
17
- ".png": "image/png",
18
- ".jpg": "image/jpeg",
19
- ".jpeg": "image/jpeg",
20
- ".gif": "image/gif",
21
- ".webp": "image/webp",
22
- ".avif": "image/avif",
23
- ".ico": "image/x-icon",
24
- ".bmp": "image/bmp",
25
- ".mp4": "video/mp4",
26
- ".webm": "video/webm",
27
- ".mov": "video/quicktime",
28
- ".m4v": "video/mp4",
29
- ".mp3": "audio/mpeg",
30
- ".wav": "audio/wav",
31
- ".ogg": "audio/ogg",
32
- ".m4a": "audio/mp4",
33
- ".flac": "audio/flac",
34
- ".pdf": "application/pdf",
35
- ".wasm": "application/wasm",
36
- ".zip": "application/zip",
37
- ".gz": "application/gzip",
38
- ".tar": "application/x-tar",
39
- ".woff": "font/woff",
40
- ".woff2": "font/woff2",
41
- ".ttf": "font/ttf",
42
- ".otf": "font/otf",
43
- ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
44
- ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
45
- ".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation"
46
- };
47
- function contentTypeFor(filePath) {
48
- return MIME[path.extname(filePath).toLowerCase()] || "application/octet-stream";
49
- }
50
- function containedPath(rootDir, relPath) {
51
- const base = path.resolve(rootDir);
52
- const decoded = safeDecode(relPath);
53
- const fp = path.resolve(path.join(base, decoded));
54
- if (fp !== base && !fp.startsWith(base + path.sep)) return null;
55
- return fp;
56
- }
57
- function realContainedPath(rootDir, candidate) {
58
- try {
59
- const realRoot = fs.realpathSync(path.resolve(rootDir));
60
- const real = fs.realpathSync(candidate);
61
- if (real === realRoot || real.startsWith(realRoot + path.sep)) return real;
62
- return null;
63
- } catch {
64
- return null;
65
- }
66
- }
67
- function safeDecode(p) {
68
- try {
69
- return decodeURIComponent(p);
70
- } catch {
71
- return p;
72
- }
73
- }
74
- function parseRange(header, size) {
75
- if (!header) return null;
76
- const m = /^bytes=(\d*)-(\d*)$/.exec(header.trim());
77
- if (!m) return null;
78
- const [, s, e] = m;
79
- if (s === "" && e === "") return null;
80
- let start, end;
81
- if (s === "") {
82
- const n = parseInt(e, 10);
83
- if (n <= 0) return "unsatisfiable";
84
- start = Math.max(0, size - n);
85
- end = size - 1;
86
- } else {
87
- start = parseInt(s, 10);
88
- end = e === "" ? size - 1 : parseInt(e, 10);
89
- }
90
- if (Number.isNaN(start) || Number.isNaN(end) || start > end || start >= size) return "unsatisfiable";
91
- if (end >= size) end = size - 1;
92
- return { start, end };
93
- }
94
- function directoryListingHtml(mountRelUrl, entries) {
95
- const esc = (s) => s.replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]);
96
- const base = mountRelUrl.endsWith("/") ? mountRelUrl : mountRelUrl + "/";
97
- const rows = entries.sort((a, b) => a.isDir === b.isDir ? a.name.localeCompare(b.name) : a.isDir ? -1 : 1).map((e) => {
98
- const href = base + encodeURIComponent(e.name) + (e.isDir ? "/" : "");
99
- return `<li><a href="${esc(href)}">${esc(e.name)}${e.isDir ? "/" : ""}</a></li>`;
100
- }).join("\n");
101
- return `<!DOCTYPE html><html><head><meta charset="utf-8"><title>${esc(base)}</title>
102
- <style>body{font-family:system-ui,sans-serif;max-width:760px;margin:40px auto;padding:0 20px;color:#333}
103
- h1{font-size:1.15rem;word-break:break-all}ul{list-style:none;padding:0}li{padding:6px 0;border-bottom:1px solid #eee}
104
- a{color:#0969da;text-decoration:none}a:hover{text-decoration:underline}</style></head>
105
- <body><h1>${esc(base)}</h1><ul>${rows || "<li>(empty)</li>"}</ul></body></html>`;
106
- }
107
- const CORS = {
108
- "Access-Control-Allow-Origin": "*",
109
- "Access-Control-Allow-Methods": "GET, HEAD, OPTIONS",
110
- "Access-Control-Allow-Headers": "*"
111
- };
112
- function serveStaticMount(req, res, opts) {
113
- const { rootDir, relPath, mountUrlPrefix } = opts;
114
- const browse = opts.browse !== false;
115
- const method = (req.method || "GET").toUpperCase();
116
- if (method === "OPTIONS") {
117
- res.writeHead(204, CORS);
118
- res.end();
119
- return;
120
- }
121
- if (method !== "GET" && method !== "HEAD") {
122
- res.writeHead(405, { ...CORS, Allow: "GET, HEAD, OPTIONS" });
123
- res.end("Method Not Allowed");
124
- return;
125
- }
126
- let rootStat;
127
- try {
128
- rootStat = fs.statSync(rootDir);
129
- } catch {
130
- res.writeHead(404, CORS);
131
- res.end("Not Found");
132
- return;
133
- }
134
- if (rootStat.isFile()) {
135
- sendFile(req, res, rootDir, rootStat);
136
- return;
137
- }
138
- const lexTarget = containedPath(rootDir, relPath.replace(/^\/+/, ""));
139
- if (!lexTarget) {
140
- res.writeHead(403, { ...CORS, "Content-Type": "text/plain" });
141
- res.end("Forbidden");
142
- return;
143
- }
144
- const target = realContainedPath(rootDir, lexTarget);
145
- if (!target) {
146
- res.writeHead(404, { ...CORS, "Content-Type": "text/plain" });
147
- res.end("Not Found");
148
- return;
149
- }
150
- let st;
151
- try {
152
- st = fs.statSync(target);
153
- } catch {
154
- res.writeHead(404, { ...CORS, "Content-Type": "text/plain" });
155
- res.end("Not Found");
156
- return;
157
- }
158
- if (st.isDirectory()) {
159
- const reqPath = (req.url || "/").split("?")[0];
160
- if (!reqPath.endsWith("/")) {
161
- res.writeHead(302, { ...CORS, Location: reqPath + "/" });
162
- res.end();
163
- return;
164
- }
165
- const indexPath = realContainedPath(rootDir, path.join(target, "index.html"));
166
- if (indexPath && fs.statSync(indexPath).isFile()) {
167
- sendFile(req, res, indexPath, fs.statSync(indexPath));
168
- return;
169
- }
170
- if (!browse) {
171
- res.writeHead(403, { ...CORS, "Content-Type": "text/plain" });
172
- res.end("Directory listing disabled");
173
- return;
174
- }
175
- let entries;
176
- try {
177
- entries = fs.readdirSync(target, { withFileTypes: true }).filter((d) => !d.name.startsWith(".")).map((d) => ({ name: d.name, isDir: d.isDirectory() }));
178
- } catch {
179
- res.writeHead(500, CORS);
180
- res.end("Listing failed");
181
- return;
182
- }
183
- const listUrl = mountUrlPrefix + (relPath === "/" ? "/" : relPath);
184
- const html = directoryListingHtml(listUrl, entries);
185
- res.writeHead(200, { ...CORS, "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-store" });
186
- res.end(method === "HEAD" ? void 0 : html);
187
- return;
188
- }
189
- if (st.isFile()) {
190
- sendFile(req, res, target, st);
191
- return;
192
- }
193
- res.writeHead(404, CORS);
194
- res.end("Not Found");
195
- }
196
- function etagFor(st) {
197
- return `"${st.size.toString(16)}-${Math.floor(st.mtimeMs).toString(16)}"`;
198
- }
199
- function sendFile(req, res, filePath, st) {
200
- const method = (req.method || "GET").toUpperCase();
201
- const etag = etagFor(st);
202
- const lastMod = new Date(st.mtimeMs).toUTCString();
203
- const baseHeaders = {
204
- ...CORS,
205
- "Content-Type": contentTypeFor(filePath),
206
- "Accept-Ranges": "bytes",
207
- ETag: etag,
208
- "Last-Modified": lastMod,
209
- "Cache-Control": "no-cache"
210
- // revalidate via ETag; content can change under a mount
211
- };
212
- const inm = req.headers["if-none-match"];
213
- const ims = req.headers["if-modified-since"];
214
- if (inm && inm === etag || !inm && ims && new Date(ims).getTime() >= Math.floor(st.mtimeMs / 1e3) * 1e3) {
215
- res.writeHead(304, baseHeaders);
216
- res.end();
217
- return;
218
- }
219
- const range = parseRange(req.headers.range, st.size);
220
- if (range === "unsatisfiable") {
221
- res.writeHead(416, { ...baseHeaders, "Content-Range": `bytes */${st.size}` });
222
- res.end();
223
- return;
224
- }
225
- if (range) {
226
- const len = range.end - range.start + 1;
227
- res.writeHead(206, { ...baseHeaders, "Content-Range": `bytes ${range.start}-${range.end}/${st.size}`, "Content-Length": String(len) });
228
- if (method === "HEAD") {
229
- res.end();
230
- return;
231
- }
232
- pipeStream(fs.createReadStream(filePath, { start: range.start, end: range.end }), res);
233
- return;
234
- }
235
- res.writeHead(200, { ...baseHeaders, "Content-Length": String(st.size) });
236
- if (method === "HEAD") {
237
- res.end();
238
- return;
239
- }
240
- pipeStream(fs.createReadStream(filePath), res);
241
- }
242
- function pipeStream(stream, res) {
243
- stream.on("error", () => {
244
- try {
245
- res.destroy();
246
- } catch {
247
- }
248
- });
249
- res.on("close", () => {
250
- stream.destroy();
251
- });
252
- stream.pipe(res);
253
- }
254
-
255
- export { containedPath, contentTypeFor, directoryListingHtml, parseRange, realContainedPath, serveStaticMount };