@ant0/cli 0.0.0-stage → 0.3.22-beta.3
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 +28 -0
- package/README.md +97 -2
- package/dist/api/generated/schema.d.ts +11600 -0
- package/dist/api/generated/schema.js +6 -0
- package/dist/api/index.d.ts +219 -0
- package/dist/api/index.js +342 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.js +12 -0
- package/dist/bulk.d.ts +38 -0
- package/dist/bulk.js +66 -0
- package/dist/commands/account.d.ts +48 -0
- package/dist/commands/account.js +337 -0
- package/dist/commands/api-keys.d.ts +5 -0
- package/dist/commands/api-keys.js +310 -0
- package/dist/commands/browsers.d.ts +4 -0
- package/dist/commands/browsers.js +165 -0
- package/dist/commands/daemon.d.ts +15 -0
- package/dist/commands/daemon.js +202 -0
- package/dist/commands/events.d.ts +8 -0
- package/dist/commands/events.js +81 -0
- package/dist/commands/extensions.d.ts +4 -0
- package/dist/commands/extensions.js +74 -0
- package/dist/commands/profiles.d.ts +36 -0
- package/dist/commands/profiles.js +552 -0
- package/dist/commands/proxies.d.ts +23 -0
- package/dist/commands/proxies.js +170 -0
- package/dist/commands/sync.d.ts +4 -0
- package/dist/commands/sync.js +435 -0
- package/dist/commands/team.d.ts +7 -0
- package/dist/commands/team.js +403 -0
- package/dist/commands/trash.d.ts +10 -0
- package/dist/commands/trash.js +54 -0
- package/dist/commands/workspace.d.ts +10 -0
- package/dist/commands/workspace.js +56 -0
- package/dist/context.d.ts +111 -0
- package/dist/context.js +300 -0
- package/dist/errors.d.ts +27 -0
- package/dist/errors.js +96 -0
- package/dist/format.d.ts +23 -0
- package/dist/format.js +85 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +35 -0
- package/dist/inventory.d.ts +50 -0
- package/dist/inventory.js +202 -0
- package/dist/management-transport.d.ts +3 -0
- package/dist/management-transport.js +90 -0
- package/dist/native-terminal.d.ts +50 -0
- package/dist/native-terminal.js +228 -0
- package/dist/program.d.ts +10 -0
- package/dist/program.js +185 -0
- package/dist/runtime-types.d.ts +20 -0
- package/dist/runtime-types.js +2 -0
- package/dist/set.d.ts +15 -0
- package/dist/set.js +87 -0
- package/dist/shared/parse-error.d.ts +6 -0
- package/dist/shared/parse-error.js +8 -0
- package/dist/shared/proxy-parse.d.ts +42 -0
- package/dist/shared/proxy-parse.js +238 -0
- package/dist/shared/proxy-types.d.ts +21 -0
- package/dist/shared/proxy-types.js +2 -0
- package/dist/shared/recovery-code.d.ts +7 -0
- package/dist/shared/recovery-code.js +53 -0
- package/dist/version.d.ts +8 -0
- package/dist/version.js +18 -0
- package/licenses/README.md +5 -0
- package/licenses/THIRD_PARTY_NOTICES +96 -0
- package/package.json +63 -4
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { lstatSync } from "node:fs";
|
|
3
|
+
import { createAnt0Client, TokenFileNotPrivateError, isAnt0ApiError, unwrap, } from "../api/index.js";
|
|
4
|
+
import { canonicalOrigin } from "@ant0/mcp";
|
|
5
|
+
import { CredentialFailure, CredentialCollision, keyId, keyName, lifetime, keyScopes, operateScopes, readScopes, newCredential, projectExpectedContext, projectKeyMetadata, projectKeyList, projectGrantStatus, matchingMetadata, readCredentialFile, saveCredentialFile, flushCredentialBeforeSubmission, rejectCredentialEcho, withCredentialLock, } from "@ant0/mcp/credentials";
|
|
6
|
+
import { CliError, DaemonNotRunningError, UsageError } from "../errors.js";
|
|
7
|
+
import { keyValues, flatten, table } from "../format.js";
|
|
8
|
+
import { directManagementFetch } from "../management-transport.js";
|
|
9
|
+
const boundedClients = new WeakMap();
|
|
10
|
+
/** Management remains local-master authenticated even when --credential-file selects its output. */
|
|
11
|
+
function management(ctx) {
|
|
12
|
+
const cached = boundedClients.get(ctx);
|
|
13
|
+
if (cached)
|
|
14
|
+
return cached;
|
|
15
|
+
const connection = ctx.authenticatedConnection();
|
|
16
|
+
if (!connection.token)
|
|
17
|
+
throw new DaemonNotRunningError();
|
|
18
|
+
const client = createAnt0Client({
|
|
19
|
+
baseUrl: canonicalOrigin(connection.baseUrl),
|
|
20
|
+
token: connection.token,
|
|
21
|
+
fetch: ctx.io.fetch ?? directManagementFetch,
|
|
22
|
+
});
|
|
23
|
+
client.use({
|
|
24
|
+
onRequest({ request }) {
|
|
25
|
+
const url = new URL(request.url);
|
|
26
|
+
const origin = canonicalOrigin(url.origin);
|
|
27
|
+
if (!/^\/v1\/automation\/api-keys(?:\/(?:context|provision|[0-9a-f-]{36}))?$/.test(url.pathname))
|
|
28
|
+
throw new CliError("invalid local API key management destination");
|
|
29
|
+
return new Request(new Request(`${origin}${url.pathname}${url.search}`, request), {
|
|
30
|
+
redirect: "error",
|
|
31
|
+
signal: AbortSignal.any([
|
|
32
|
+
request.signal,
|
|
33
|
+
AbortSignal.timeout(10_000),
|
|
34
|
+
...(ctx.io.signal ? [ctx.io.signal] : []),
|
|
35
|
+
]),
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
async onResponse({ response }) {
|
|
39
|
+
if (response.status === 204)
|
|
40
|
+
return response;
|
|
41
|
+
const reader = response.body?.getReader();
|
|
42
|
+
if (!reader)
|
|
43
|
+
throw new CliError("invalid API key response");
|
|
44
|
+
const chunks = [];
|
|
45
|
+
let size = 0;
|
|
46
|
+
try {
|
|
47
|
+
for (;;) {
|
|
48
|
+
const { done, value } = await reader.read();
|
|
49
|
+
if (done)
|
|
50
|
+
break;
|
|
51
|
+
size += value.length;
|
|
52
|
+
if (size > 1024 * 1024)
|
|
53
|
+
throw new CliError("API key response exceeds limit");
|
|
54
|
+
chunks.push(value);
|
|
55
|
+
}
|
|
56
|
+
const text = new TextDecoder("utf-8", { fatal: true }).decode(Buffer.concat(chunks));
|
|
57
|
+
return new Response(text, {
|
|
58
|
+
status: response.status,
|
|
59
|
+
headers: { "content-type": "application/json" },
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
await reader.cancel().catch(() => { });
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
boundedClients.set(ctx, client);
|
|
68
|
+
return client;
|
|
69
|
+
}
|
|
70
|
+
async function safely(fn) {
|
|
71
|
+
try {
|
|
72
|
+
return await fn();
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
if (error instanceof CliError)
|
|
76
|
+
throw error;
|
|
77
|
+
if (error instanceof TokenFileNotPrivateError)
|
|
78
|
+
throw new CliError(error.message);
|
|
79
|
+
if (isAnt0ApiError(error))
|
|
80
|
+
throw new CliError(`API key request failed (HTTP ${error.status})`);
|
|
81
|
+
if (error instanceof CredentialFailure)
|
|
82
|
+
throw new CliError(error.message);
|
|
83
|
+
throw new CliError("API key operation unavailable");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function uuid(value) {
|
|
87
|
+
if (!keyId.safeParse(value).success)
|
|
88
|
+
throw new UsageError("expected a lowercase UUID");
|
|
89
|
+
return value;
|
|
90
|
+
}
|
|
91
|
+
function name(value) {
|
|
92
|
+
if (!keyName.safeParse(value).success)
|
|
93
|
+
throw new UsageError("name requires 1–100 printable characters");
|
|
94
|
+
return value;
|
|
95
|
+
}
|
|
96
|
+
function seconds(value) {
|
|
97
|
+
const n = Number(value);
|
|
98
|
+
if (!lifetime.safeParse(n).success)
|
|
99
|
+
throw new UsageError("lifetime must be 60–31536000 integer seconds");
|
|
100
|
+
return n;
|
|
101
|
+
}
|
|
102
|
+
function pageSize(value) {
|
|
103
|
+
const n = Number(value);
|
|
104
|
+
if (!Number.isInteger(n) || n < 1 || n > 100)
|
|
105
|
+
throw new UsageError("limit must be 1–100");
|
|
106
|
+
return n;
|
|
107
|
+
}
|
|
108
|
+
function collect(value, previous) {
|
|
109
|
+
return [...previous, value];
|
|
110
|
+
}
|
|
111
|
+
export function provisionScopes(preset, selected = []) {
|
|
112
|
+
if (preset !== "read" && preset !== "operate")
|
|
113
|
+
throw new UsageError("preset must be read or operate");
|
|
114
|
+
for (const scope of selected) {
|
|
115
|
+
if (!keyScopes.includes(scope))
|
|
116
|
+
throw new UsageError(`unsupported API key scope: ${scope}`);
|
|
117
|
+
}
|
|
118
|
+
return [
|
|
119
|
+
...new Set([
|
|
120
|
+
...(preset === "operate" ? operateScopes : readScopes),
|
|
121
|
+
...selected,
|
|
122
|
+
]),
|
|
123
|
+
];
|
|
124
|
+
}
|
|
125
|
+
async function context(ctx, workspace) {
|
|
126
|
+
const value = projectExpectedContext(unwrap(await management(ctx).GET("/v1/automation/api-keys/context")));
|
|
127
|
+
if (workspace !== undefined && workspace !== value.workspace_id)
|
|
128
|
+
throw new UsageError("workspace must match the selected daemon workspace");
|
|
129
|
+
return value;
|
|
130
|
+
}
|
|
131
|
+
function oneKey(value) {
|
|
132
|
+
if (!value || typeof value !== "object" || !("key" in value))
|
|
133
|
+
throw new CredentialFailure("invalid API key metadata");
|
|
134
|
+
return projectKeyMetadata(value.key);
|
|
135
|
+
}
|
|
136
|
+
export function registerApiKeys(program, ctx) {
|
|
137
|
+
const keys = program
|
|
138
|
+
.command("api-keys")
|
|
139
|
+
.description("Manage delegated API keys using the local master bearer");
|
|
140
|
+
keys
|
|
141
|
+
.command("create [name]")
|
|
142
|
+
.description("Durably provision or exactly replay a private credential file")
|
|
143
|
+
.option("--name <name>", "key name", name)
|
|
144
|
+
.requiredOption("--preset <preset>", "scope preset (read or operate)")
|
|
145
|
+
.option("--scope <scope>", "explicit scope added to the preset, such as profiles:cdp (repeatable)", collect, [])
|
|
146
|
+
.option("--lifetime-seconds <seconds>", "finite lifetime (default 2592000)", seconds)
|
|
147
|
+
.option("--workspace <uuid>", "require selected workspace", uuid)
|
|
148
|
+
.action(async (positional, opts) => safely(async () => {
|
|
149
|
+
const path = ctx.globals.credentialFile;
|
|
150
|
+
if (!path)
|
|
151
|
+
throw new UsageError("create requires --credential-file");
|
|
152
|
+
const requestedScopes = provisionScopes(opts.preset, opts.scope);
|
|
153
|
+
if (positional !== undefined)
|
|
154
|
+
name(positional);
|
|
155
|
+
if (positional !== undefined && opts.name !== undefined && positional !== opts.name)
|
|
156
|
+
throw new UsageError("conflicting key names");
|
|
157
|
+
const requestedName = opts.name ?? positional;
|
|
158
|
+
await withCredentialLock(path, async () => {
|
|
159
|
+
let saved;
|
|
160
|
+
try {
|
|
161
|
+
lstatSync(path);
|
|
162
|
+
saved = readCredentialFile(path);
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
if (error.code !== "ENOENT")
|
|
166
|
+
throw error;
|
|
167
|
+
}
|
|
168
|
+
if (saved) {
|
|
169
|
+
if ((requestedName !== undefined && requestedName !== saved.value.create.name) ||
|
|
170
|
+
(opts.lifetimeSeconds !== undefined &&
|
|
171
|
+
opts.lifetimeSeconds !== saved.value.create.lifetime_seconds) ||
|
|
172
|
+
[...saved.value.create.scopes].sort().join() !==
|
|
173
|
+
[...requestedScopes].sort().join() ||
|
|
174
|
+
(opts.workspace !== undefined &&
|
|
175
|
+
opts.workspace !== saved.value.expected.workspace_id))
|
|
176
|
+
throw new UsageError("creation options do not match the saved credential file");
|
|
177
|
+
}
|
|
178
|
+
else if (requestedName === undefined)
|
|
179
|
+
throw new UsageError("new keys require a name");
|
|
180
|
+
const expected = await context(ctx, opts.workspace);
|
|
181
|
+
if (saved && JSON.stringify(saved.value.expected) !== JSON.stringify(expected))
|
|
182
|
+
throw new UsageError("saved credential context does not match the daemon context");
|
|
183
|
+
if (!saved) {
|
|
184
|
+
const id = randomUUID();
|
|
185
|
+
try {
|
|
186
|
+
saved = saveCredentialFile(path, {
|
|
187
|
+
schema: "ant0-api-key/v1",
|
|
188
|
+
expected,
|
|
189
|
+
create: {
|
|
190
|
+
id,
|
|
191
|
+
credential: newCredential(id),
|
|
192
|
+
name: requestedName,
|
|
193
|
+
scopes: requestedScopes,
|
|
194
|
+
lifetime_seconds: opts.lifetimeSeconds ?? 2_592_000,
|
|
195
|
+
},
|
|
196
|
+
phase: "pending",
|
|
197
|
+
key: null,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
if (!(error instanceof CredentialCollision))
|
|
202
|
+
throw error;
|
|
203
|
+
saved = readCredentialFile(path);
|
|
204
|
+
if (JSON.stringify(saved.rawValue.expected) !== JSON.stringify(expected) ||
|
|
205
|
+
saved.rawValue.create.name !== requestedName ||
|
|
206
|
+
saved.rawValue.create.lifetime_seconds !== (opts.lifetimeSeconds ?? 2_592_000) ||
|
|
207
|
+
[...saved.rawValue.create.scopes].sort().join() !==
|
|
208
|
+
[...requestedScopes].sort().join())
|
|
209
|
+
throw new UsageError("concurrent credential does not match creation options");
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const pinned = flushCredentialBeforeSubmission(saved);
|
|
213
|
+
let response;
|
|
214
|
+
try {
|
|
215
|
+
const body = {
|
|
216
|
+
expected: saved.rawValue.expected,
|
|
217
|
+
create: saved.rawValue.create,
|
|
218
|
+
};
|
|
219
|
+
response = unwrap(await management(ctx).POST("/v1/automation/api-keys/provision", {
|
|
220
|
+
body,
|
|
221
|
+
...(ctx.io.signal ? { signal: ctx.io.signal } : {}),
|
|
222
|
+
}));
|
|
223
|
+
}
|
|
224
|
+
finally {
|
|
225
|
+
pinned.close();
|
|
226
|
+
}
|
|
227
|
+
const key = oneKey(response);
|
|
228
|
+
rejectCredentialEcho(key, saved.value.create.credential);
|
|
229
|
+
if (!matchingMetadata(saved.value, key))
|
|
230
|
+
throw new CredentialFailure("API key reply does not match the saved request");
|
|
231
|
+
// saveCredentialFile revalidates the exact source and receipt before publication.
|
|
232
|
+
saveCredentialFile(path, { ...saved.value, phase: "ready", key }, saved);
|
|
233
|
+
ctx.emit({ key, credential_file: saved.path }, () => keyValues(flatten({ key, credential_file: saved.path })));
|
|
234
|
+
});
|
|
235
|
+
}));
|
|
236
|
+
keys
|
|
237
|
+
.command("list")
|
|
238
|
+
.option("--workspace <uuid>", "require selected workspace", uuid)
|
|
239
|
+
.option("--limit <n>", "page size (default 50)", pageSize, 50)
|
|
240
|
+
.option("--cursor <cursor>", "opaque next-page cursor")
|
|
241
|
+
.action(async (opts) => safely(async () => {
|
|
242
|
+
if (opts.cursor !== undefined && (opts.cursor.length === 0 || opts.cursor.length > 4096))
|
|
243
|
+
throw new UsageError("invalid cursor length");
|
|
244
|
+
const expected = await context(ctx, opts.workspace);
|
|
245
|
+
const data = projectKeyList(unwrap(await management(ctx).GET("/v1/automation/api-keys", {
|
|
246
|
+
params: {
|
|
247
|
+
query: {
|
|
248
|
+
limit: opts.limit,
|
|
249
|
+
...(opts.cursor !== undefined ? { cursor: opts.cursor } : {}),
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
})));
|
|
253
|
+
if (data.items.length > opts.limit ||
|
|
254
|
+
data.items.some((key) => key.workspace_id !== expected.workspace_id) ||
|
|
255
|
+
(data.next_cursor !== null &&
|
|
256
|
+
(data.items.length === 0 || data.next_cursor === opts.cursor)))
|
|
257
|
+
throw new CredentialFailure("invalid API key metadata");
|
|
258
|
+
ctx.emit(data, () => table(["id", "name", "status", "expires"], data.items.map((key) => [key.id, key.name, key.status, key.expires_at])) +
|
|
259
|
+
(data.next_cursor === null ? "" : `\nnext_cursor: ${JSON.stringify(data.next_cursor)}`));
|
|
260
|
+
}));
|
|
261
|
+
keys
|
|
262
|
+
.command("show <id>")
|
|
263
|
+
.option("--workspace <uuid>", "require selected workspace", uuid)
|
|
264
|
+
.action(async (id, opts) => safely(async () => {
|
|
265
|
+
uuid(id);
|
|
266
|
+
const expected = await context(ctx, opts.workspace);
|
|
267
|
+
const key = oneKey(unwrap(await management(ctx).GET("/v1/automation/api-keys/{id}", { params: { path: { id } } })));
|
|
268
|
+
if (key.id !== id || key.workspace_id !== expected.workspace_id)
|
|
269
|
+
throw new CredentialFailure("invalid API key metadata");
|
|
270
|
+
ctx.emit({ key }, () => keyValues(flatten(key)));
|
|
271
|
+
}));
|
|
272
|
+
keys
|
|
273
|
+
.command("rename <id> <name>")
|
|
274
|
+
.option("--workspace <uuid>", "require selected workspace", uuid)
|
|
275
|
+
.action(async (id, newName, opts) => safely(async () => {
|
|
276
|
+
uuid(id);
|
|
277
|
+
name(newName);
|
|
278
|
+
const expected = await context(ctx, opts.workspace);
|
|
279
|
+
const key = oneKey(unwrap(await management(ctx).PATCH("/v1/automation/api-keys/{id}", {
|
|
280
|
+
params: { path: { id } },
|
|
281
|
+
body: { name: newName },
|
|
282
|
+
})));
|
|
283
|
+
if (key.id !== id || key.workspace_id !== expected.workspace_id || key.name !== newName)
|
|
284
|
+
throw new CredentialFailure("invalid API key metadata");
|
|
285
|
+
ctx.emit({ key }, () => keyValues(flatten(key)));
|
|
286
|
+
}));
|
|
287
|
+
keys
|
|
288
|
+
.command("revoke <id>")
|
|
289
|
+
.option("--workspace <uuid>", "require selected workspace", uuid)
|
|
290
|
+
.action(async (id, opts) => safely(async () => {
|
|
291
|
+
uuid(id);
|
|
292
|
+
await context(ctx, opts.workspace);
|
|
293
|
+
unwrap(await management(ctx).DELETE("/v1/automation/api-keys/{id}", {
|
|
294
|
+
params: { path: { id } },
|
|
295
|
+
}));
|
|
296
|
+
ctx.emit(undefined, () => `revoked ${id}`);
|
|
297
|
+
}));
|
|
298
|
+
program
|
|
299
|
+
.command("key-status")
|
|
300
|
+
.description("Read current delegated key authorization status")
|
|
301
|
+
.action(async () => safely(async () => {
|
|
302
|
+
if (!ctx.keyMode())
|
|
303
|
+
throw new UsageError("key-status requires --credential-file or ANT0_API_KEY");
|
|
304
|
+
const client = ctx.client();
|
|
305
|
+
const grant = (await ctx.keyGrant());
|
|
306
|
+
const data = projectGrantStatus(unwrap(await client.GET("/v1/automation/status")), grant);
|
|
307
|
+
ctx.emit(data, () => keyValues(flatten(data)));
|
|
308
|
+
}));
|
|
309
|
+
}
|
|
310
|
+
//# sourceMappingURL=api-keys.js.map
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ant0 browsers ls | available [--channel] | install [--release|--channel] [--no-wait]
|
|
3
|
+
* | default <version> | rm <version>`, and
|
|
4
|
+
* `install --release <exact> --repair-proof` (adds the signed file proof of an installed release) and
|
|
5
|
+
* `install --release <exact> --replace` (downloads and verifies an installed release again and swaps
|
|
6
|
+
* it in only on success; needs a daemon that supports `replace`).
|
|
7
|
+
*
|
|
8
|
+
* `default` is the release that profiles without a pinned `browser.version` launch (`PUT /browsers/default`); `ls` marks it with `*` in the DEFAULT column.
|
|
9
|
+
*/
|
|
10
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
11
|
+
import { Ant0ApiError, unwrap } from "../api/index.js";
|
|
12
|
+
import { formatBytes, keyValues, table } from "../format.js";
|
|
13
|
+
const JOB_POLL_MS = 1000;
|
|
14
|
+
const BROWSER_HEADERS = ["version", "default", "chromium", "target", "size", "installed", "path"];
|
|
15
|
+
/** `ls` adds a status column: whether the installed files still match the signed proof. */
|
|
16
|
+
const LISTED_HEADERS = [...BROWSER_HEADERS.slice(0, 6), "status", "path"];
|
|
17
|
+
function browserRows(items) {
|
|
18
|
+
return items.map((b) => [
|
|
19
|
+
b.version,
|
|
20
|
+
b.default ? "*" : null,
|
|
21
|
+
b.chromium,
|
|
22
|
+
b.target,
|
|
23
|
+
formatBytes(b.size_bytes),
|
|
24
|
+
b.installed_at,
|
|
25
|
+
b.path,
|
|
26
|
+
]);
|
|
27
|
+
}
|
|
28
|
+
/** One cell: `ok`, `FAILED <file>` for a release whose files changed, `unchecked` otherwise. */
|
|
29
|
+
function integrityCell(b) {
|
|
30
|
+
const integrity = b.integrity;
|
|
31
|
+
if (integrity === undefined)
|
|
32
|
+
return "";
|
|
33
|
+
if (integrity.status === "failed") {
|
|
34
|
+
return integrity.path === undefined ? "FAILED" : `FAILED ${integrity.path}`;
|
|
35
|
+
}
|
|
36
|
+
return integrity.status;
|
|
37
|
+
}
|
|
38
|
+
function listedRows(items) {
|
|
39
|
+
return items.map((b) => [
|
|
40
|
+
b.version,
|
|
41
|
+
b.default ? "*" : null,
|
|
42
|
+
b.chromium,
|
|
43
|
+
b.target,
|
|
44
|
+
formatBytes(b.size_bytes),
|
|
45
|
+
b.installed_at,
|
|
46
|
+
integrityCell(b),
|
|
47
|
+
b.path,
|
|
48
|
+
]);
|
|
49
|
+
}
|
|
50
|
+
/** What to do about a release whose files no longer match its signed proof. */
|
|
51
|
+
function repairLines(items) {
|
|
52
|
+
return items
|
|
53
|
+
.filter((b) => b.integrity?.status === "failed")
|
|
54
|
+
.map((b) => `${b.version} failed its integrity check (${b.integrity?.message ?? "files changed"}). ` +
|
|
55
|
+
`Reinstall it: ant0 browsers rm ${b.version} && ant0 browsers install --release ${b.version}, ` +
|
|
56
|
+
`then set it as the default again: ant0 browsers default ${b.version}`);
|
|
57
|
+
}
|
|
58
|
+
export function registerBrowsers(program, ctx) {
|
|
59
|
+
const browsers = program.command("browsers").description("Installed Ant0 Browser releases");
|
|
60
|
+
browsers
|
|
61
|
+
.command("ls")
|
|
62
|
+
.description("List installed releases (the STATUS column is a corruption check for display, not an anti-tamper control)")
|
|
63
|
+
.action(async () => {
|
|
64
|
+
const data = unwrap(await ctx.client().GET("/v1/browsers", { params: { query: { integrity: true } } }));
|
|
65
|
+
ctx.emit(data, () => [table(LISTED_HEADERS, listedRows(data.items)), ...repairLines(data.items)].join("\n"));
|
|
66
|
+
});
|
|
67
|
+
browsers
|
|
68
|
+
.command("default <version>")
|
|
69
|
+
.description("Make an installed release the one unpinned profiles launch")
|
|
70
|
+
.action(async (version) => {
|
|
71
|
+
const data = unwrap(await ctx.client().PUT("/v1/browsers/default", { body: { version } }));
|
|
72
|
+
ctx.emit(data, () => table(BROWSER_HEADERS, browserRows(data.items)));
|
|
73
|
+
});
|
|
74
|
+
browsers
|
|
75
|
+
.command("available")
|
|
76
|
+
.description("Show the current release of a channel")
|
|
77
|
+
.option("--channel <name>", "release channel", "stable")
|
|
78
|
+
.action(async (opts) => {
|
|
79
|
+
const data = unwrap(await ctx.client().GET("/v1/browsers/available", {
|
|
80
|
+
params: { query: { channel: opts.channel } },
|
|
81
|
+
}));
|
|
82
|
+
ctx.emit(data, () => keyValues([
|
|
83
|
+
["channel", data.channel],
|
|
84
|
+
["version", data.version],
|
|
85
|
+
["chromium", data.chromium],
|
|
86
|
+
["installed", data.installed],
|
|
87
|
+
]));
|
|
88
|
+
});
|
|
89
|
+
browsers
|
|
90
|
+
.command("install")
|
|
91
|
+
.description("Download and verify a release (the channel's current one by default)")
|
|
92
|
+
.option("--release <version>", "pin a release version (e.g. 149.0.7827.114-ant0.2)")
|
|
93
|
+
.option("--channel <name>", "release channel", "stable")
|
|
94
|
+
.option("--repair-proof", "add the signed file proof of an already installed --release (public metadata only; no reinstall)")
|
|
95
|
+
.option("--replace", "download and verify an already installed --release again and swap it in only on success (keeps the default, pins and profiles; needs a daemon that supports it)")
|
|
96
|
+
.option("--no-wait", "return the job id immediately instead of waiting for completion")
|
|
97
|
+
.action(async (opts) => {
|
|
98
|
+
if (opts.repairProof && !opts.release) {
|
|
99
|
+
throw new Error("--repair-proof needs an exact --release <version>");
|
|
100
|
+
}
|
|
101
|
+
if (opts.replace && !opts.release) {
|
|
102
|
+
throw new Error("--replace needs an exact --release <version>");
|
|
103
|
+
}
|
|
104
|
+
if (opts.replace && opts.repairProof) {
|
|
105
|
+
throw new Error("--replace and --repair-proof cannot be used together");
|
|
106
|
+
}
|
|
107
|
+
const client = ctx.client();
|
|
108
|
+
const result = await client.POST("/v1/browsers/install", {
|
|
109
|
+
body: {
|
|
110
|
+
channel: opts.channel,
|
|
111
|
+
...(opts.release ? { version: opts.release } : {}),
|
|
112
|
+
...(opts.repairProof ? { repair_proof: true } : {}),
|
|
113
|
+
...(opts.replace ? { replace: true } : {}),
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
// A daemon from before in-place reinstall refuses the unknown `replace` field: every daemon's
|
|
117
|
+
// install body schema is strict (additionalProperties: false), so it answers 400
|
|
118
|
+
// validation_failed and never runs a plain install instead. Say so, and say what to do,
|
|
119
|
+
// instead of a bare validation error.
|
|
120
|
+
if (opts.replace && result.error !== undefined && result.response.status === 400) {
|
|
121
|
+
throw new Error(`This daemon does not support --replace (reinstall in place). Update Ant0, or run: ` +
|
|
122
|
+
`ant0 browsers rm ${opts.release} && ant0 browsers install --release ${opts.release}, ` +
|
|
123
|
+
`then ant0 browsers default ${opts.release} if it was your default.`);
|
|
124
|
+
}
|
|
125
|
+
const accepted = unwrap(result);
|
|
126
|
+
if (!opts.wait) {
|
|
127
|
+
ctx.emit(accepted, () => `install job ${accepted.job_id} started`);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (!ctx.json)
|
|
131
|
+
ctx.err(`installing ${opts.release ?? `${opts.channel} channel`}...`);
|
|
132
|
+
let job;
|
|
133
|
+
for (;;) {
|
|
134
|
+
job = unwrap(await client.GET("/v1/browsers/jobs/{id}", {
|
|
135
|
+
params: { path: { id: accepted.job_id } },
|
|
136
|
+
}));
|
|
137
|
+
if (job.status !== "running")
|
|
138
|
+
break;
|
|
139
|
+
await sleep(JOB_POLL_MS);
|
|
140
|
+
}
|
|
141
|
+
if (job.status === "error" || !job.browser) {
|
|
142
|
+
const e = job.error;
|
|
143
|
+
throw new Ant0ApiError(500, e?.error ?? "browser.install_failed", e?.message ?? "install failed", e?.details);
|
|
144
|
+
}
|
|
145
|
+
const b = job.browser;
|
|
146
|
+
ctx.emit(job, () => keyValues([
|
|
147
|
+
["version", b.version],
|
|
148
|
+
["chromium", b.chromium],
|
|
149
|
+
["target", b.target],
|
|
150
|
+
["size", formatBytes(b.size_bytes)],
|
|
151
|
+
["path", b.path],
|
|
152
|
+
...(job.engine_proof
|
|
153
|
+
? [["file proof", `${job.engine_proof.status}: ${job.engine_proof.message}`]]
|
|
154
|
+
: []),
|
|
155
|
+
]));
|
|
156
|
+
});
|
|
157
|
+
browsers
|
|
158
|
+
.command("rm <version>")
|
|
159
|
+
.description("Remove an installed release (refused while a profile uses it)")
|
|
160
|
+
.action(async (version) => {
|
|
161
|
+
unwrap(await ctx.client().DELETE("/v1/browsers/{version}", { params: { path: { version } } }));
|
|
162
|
+
ctx.emit(undefined, () => `removed ${version}`);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=browsers.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import type { Context } from "../context.js";
|
|
3
|
+
import type { DaemonCommand, RuntimeCommands } from "../runtime-types.js";
|
|
4
|
+
export declare const START_TIMEOUT_MS = 10000;
|
|
5
|
+
export declare const STOP_TIMEOUT_MS = 10000;
|
|
6
|
+
type Env = Record<string, string | undefined>;
|
|
7
|
+
/**
|
|
8
|
+
* The daemon to launch: `$ANT0D_BIN` (a `.js` file runs under this Node), else `ant0d` on PATH,
|
|
9
|
+
* else the desktop app's install location. Throws when none exists.
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveDaemonCommand(runtime?: RuntimeCommands, env?: Env, platform?: NodeJS.Platform): DaemonCommand;
|
|
12
|
+
export declare function processAlive(pid: number): boolean;
|
|
13
|
+
export declare function registerDaemon(program: Command, ctx: Context): void;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=daemon.d.ts.map
|