@ant0/cli 0.0.0-stage → 0.3.22-beta.8
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 +11615 -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 +217 -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 +72 -0
- package/dist/shared/proxy-parse.js +294 -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
package/dist/program.js
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `ant0` command tree. Commander is configured to never call
|
|
3
|
+
* `process.exit` and to write through the injected streams, so `run()` is testable in-process.
|
|
4
|
+
*/
|
|
5
|
+
import { Command, InvalidArgumentError } from "commander";
|
|
6
|
+
import { Readable, Writable } from "node:stream";
|
|
7
|
+
import { registerAccount } from "./commands/account.js";
|
|
8
|
+
import { registerBrowsers } from "./commands/browsers.js";
|
|
9
|
+
import { registerDaemon } from "./commands/daemon.js";
|
|
10
|
+
import { registerEvents } from "./commands/events.js";
|
|
11
|
+
import { registerExtensions } from "./commands/extensions.js";
|
|
12
|
+
import { registerProfiles } from "./commands/profiles.js";
|
|
13
|
+
import { registerProxies } from "./commands/proxies.js";
|
|
14
|
+
import { registerSync } from "./commands/sync.js";
|
|
15
|
+
import { registerTeam } from "./commands/team.js";
|
|
16
|
+
import { registerTrash } from "./commands/trash.js";
|
|
17
|
+
import { registerWorkspace } from "./commands/workspace.js";
|
|
18
|
+
import { registerApiKeys } from "./commands/api-keys.js";
|
|
19
|
+
import { Context } from "./context.js";
|
|
20
|
+
import { CLI_VERSION } from "./version.js";
|
|
21
|
+
export { CLI_VERSION };
|
|
22
|
+
import { CliError, DaemonNotRunningError, UsageError } from "./errors.js";
|
|
23
|
+
function parsePort(value) {
|
|
24
|
+
const n = Number(value);
|
|
25
|
+
if (!Number.isInteger(n) || n < 1 || n > 65535) {
|
|
26
|
+
throw new InvalidArgumentError("expected a port number (1-65535)");
|
|
27
|
+
}
|
|
28
|
+
return n;
|
|
29
|
+
}
|
|
30
|
+
const API_KEY_ARGV = "API keys are not accepted as arguments; set ANT0_API_KEY or pipe the key with --api-key-stdin";
|
|
31
|
+
function rejectSecretArgv(argv, options) {
|
|
32
|
+
const args = argv.slice(options?.from === "user" ? 0 : 2);
|
|
33
|
+
if (args.some((arg) => arg === "--api-key" || arg.startsWith("--api-key=") || /ant0_sk_/i.test(arg)))
|
|
34
|
+
throw new UsageError(API_KEY_ARGV);
|
|
35
|
+
}
|
|
36
|
+
const FILE_KEY_COMMANDS = [
|
|
37
|
+
"profiles ls",
|
|
38
|
+
"profiles run",
|
|
39
|
+
"profiles start",
|
|
40
|
+
"profiles stop",
|
|
41
|
+
"profiles status",
|
|
42
|
+
"proxies ls",
|
|
43
|
+
"key-status",
|
|
44
|
+
"mcp serve",
|
|
45
|
+
"api-keys create",
|
|
46
|
+
];
|
|
47
|
+
const API_KEY_COMMANDS = FILE_KEY_COMMANDS.filter((name) => name !== "api-keys create");
|
|
48
|
+
class Ant0Command extends Command {
|
|
49
|
+
mcpInvocation = false;
|
|
50
|
+
rememberInvocation(argv = process.argv, options) {
|
|
51
|
+
this.mcpInvocation = false;
|
|
52
|
+
for (let i = options?.from === "user" ? 0 : 2; i < argv.length; i++) {
|
|
53
|
+
const arg = argv[i];
|
|
54
|
+
if (arg === "--home" || arg === "--port" || arg === "--credential-file") {
|
|
55
|
+
i++;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (arg.startsWith("-"))
|
|
59
|
+
continue;
|
|
60
|
+
this.mcpInvocation = arg === "mcp";
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
parse(argv, options) {
|
|
65
|
+
rejectSecretArgv(argv ?? process.argv, options);
|
|
66
|
+
this.rememberInvocation(argv, options);
|
|
67
|
+
return super.parse(argv, options);
|
|
68
|
+
}
|
|
69
|
+
parseAsync(argv, options) {
|
|
70
|
+
rejectSecretArgv(argv ?? process.argv, options);
|
|
71
|
+
this.rememberInvocation(argv, options);
|
|
72
|
+
return super.parseAsync(argv, options);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export function buildProgram(ctx) {
|
|
76
|
+
let mcpParseDiagnostic = false;
|
|
77
|
+
const program = new Ant0Command("ant0")
|
|
78
|
+
.description("Ant0: profile manager for Ant0 Browser (client of the local ant0d daemon)")
|
|
79
|
+
.version(CLI_VERSION, "-V, --version", "print the CLI version")
|
|
80
|
+
.option("--home <dir>", "data directory (default: $ANT0_HOME, else the platform data folder)")
|
|
81
|
+
.option("--port <n>", "daemon port (default: from ant0d.pid, $ANT0D_PORT or 27100)", parsePort)
|
|
82
|
+
.option("--json", "print the API payload verbatim instead of a table")
|
|
83
|
+
.option("--credential-file <path>", "private API-key file for supported reads, profile operations or creation recovery")
|
|
84
|
+
.option("--api-key-stdin", "read an API key from the first line of stdin (or set ANT0_API_KEY)")
|
|
85
|
+
.showHelpAfterError("(run with --help for usage)")
|
|
86
|
+
.exitOverride()
|
|
87
|
+
.configureOutput({
|
|
88
|
+
writeOut: (str) => ctx.io.stdout.write(str),
|
|
89
|
+
writeErr: (str) => {
|
|
90
|
+
// Commander normally echoes invalid option values. In MCP mode keep even pre-start
|
|
91
|
+
// parse failures bounded and independent of user-supplied paths/credentials.
|
|
92
|
+
if (!program.mcpInvocation)
|
|
93
|
+
ctx.io.stderr.write(str);
|
|
94
|
+
else if (!mcpParseDiagnostic) {
|
|
95
|
+
mcpParseDiagnostic = true;
|
|
96
|
+
ctx.io.stderr.write("ant0: mcp: invalid command arguments\n");
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
// Subcommands created with `.command()` inherit exitOverride/configureOutput; the global flags
|
|
101
|
+
// may appear anywhere on the line and are read from the root when a command runs.
|
|
102
|
+
ctx.bindGlobals(() => program.opts());
|
|
103
|
+
program.hook("preAction", async (_root, action) => {
|
|
104
|
+
const globals = ctx.globals;
|
|
105
|
+
const fileKey = globals.credentialFile !== undefined;
|
|
106
|
+
const envKey = ctx.io.env.ANT0_API_KEY !== undefined;
|
|
107
|
+
const stdinKey = globals.apiKeyStdin === true;
|
|
108
|
+
if (!fileKey && !envKey && !stdinKey)
|
|
109
|
+
return;
|
|
110
|
+
if ([fileKey, envKey, stdinKey].filter(Boolean).length > 1)
|
|
111
|
+
throw new UsageError("use only one of --credential-file, ANT0_API_KEY and --api-key-stdin");
|
|
112
|
+
const names = [];
|
|
113
|
+
for (let node = action; node && node !== program; node = node.parent)
|
|
114
|
+
names.unshift(node.name());
|
|
115
|
+
const command = names.join(" ");
|
|
116
|
+
if (!(fileKey ? FILE_KEY_COMMANDS : API_KEY_COMMANDS).includes(command))
|
|
117
|
+
throw new UsageError(fileKey
|
|
118
|
+
? "credential file is not supported for this command"
|
|
119
|
+
: "an API key is not supported for this command; unset ANT0_API_KEY to use the local token");
|
|
120
|
+
if (stdinKey) {
|
|
121
|
+
if (command === "mcp serve")
|
|
122
|
+
throw new UsageError("mcp serve reads its API key from ANT0_API_KEY; stdin carries the MCP protocol");
|
|
123
|
+
ctx.apiKey = await ctx.readStdinLine();
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
// A host may replace the `daemon` group with its own lifecycle commands.
|
|
127
|
+
if (ctx.runtime?.registerLifecycle)
|
|
128
|
+
ctx.runtime.registerLifecycle(program, ctx);
|
|
129
|
+
else
|
|
130
|
+
registerDaemon(program, ctx);
|
|
131
|
+
registerBrowsers(program, ctx);
|
|
132
|
+
registerProfiles(program, ctx);
|
|
133
|
+
registerTrash(program, ctx);
|
|
134
|
+
registerProxies(program, ctx);
|
|
135
|
+
registerExtensions(program, ctx);
|
|
136
|
+
registerEvents(program, ctx);
|
|
137
|
+
registerAccount(program, ctx);
|
|
138
|
+
registerWorkspace(program, ctx);
|
|
139
|
+
registerSync(program, ctx);
|
|
140
|
+
registerTeam(program, ctx);
|
|
141
|
+
registerApiKeys(program, ctx);
|
|
142
|
+
program
|
|
143
|
+
.command("mcp")
|
|
144
|
+
.description("Local MCP server: identity and inventory reads, profile run/stop, cookie and export tools, " +
|
|
145
|
+
"and beta page actions (snapshot, navigate, click, type, fill, select, keys, wait, " +
|
|
146
|
+
"screenshot, text, tabs); local connection only")
|
|
147
|
+
.command("serve")
|
|
148
|
+
.description("Serve MCP over stdio using an already-running local daemon (--http is the desktop-local mode)")
|
|
149
|
+
.option("--stdio", "use the stdio MCP transport")
|
|
150
|
+
.option("--http", "desktop-local mode, started by the Ant0 app: 127.0.0.1 only, --port is the listen port, " +
|
|
151
|
+
"the bearer token is the first line of stdin (requires --token-stdin)")
|
|
152
|
+
.option("--token-stdin", "read the HTTP bearer token from the first line of stdin")
|
|
153
|
+
.action(async (options) => {
|
|
154
|
+
if (options.http && options.stdio)
|
|
155
|
+
throw new UsageError("use only one of --stdio and --http");
|
|
156
|
+
if (!options.stdio && !options.http)
|
|
157
|
+
throw new UsageError("mcp serve requires --stdio");
|
|
158
|
+
if (ctx.json)
|
|
159
|
+
throw new UsageError("mcp serve does not accept --json");
|
|
160
|
+
if (options.http) {
|
|
161
|
+
if (!options.tokenStdin)
|
|
162
|
+
throw new UsageError("mcp serve --http requires --token-stdin");
|
|
163
|
+
if (ctx.globals.port === undefined)
|
|
164
|
+
throw new UsageError("mcp serve --http requires --port");
|
|
165
|
+
if (ctx.globals.credentialFile !== undefined ||
|
|
166
|
+
ctx.io.env.ANT0_API_KEY !== undefined ||
|
|
167
|
+
ctx.globals.apiKeyStdin === true)
|
|
168
|
+
throw new UsageError("mcp serve --http uses the local token, not an API key");
|
|
169
|
+
}
|
|
170
|
+
else if (options.tokenStdin) {
|
|
171
|
+
throw new UsageError("--token-stdin is only for mcp serve --http");
|
|
172
|
+
}
|
|
173
|
+
const stdin = ctx.io.stdin ?? process.stdin;
|
|
174
|
+
if (!(stdin instanceof Readable) || !(ctx.io.stdout instanceof Writable)) {
|
|
175
|
+
throw new CliError("mcp: stdio streams required");
|
|
176
|
+
}
|
|
177
|
+
let mcp;
|
|
178
|
+
try {
|
|
179
|
+
mcp = await import("@ant0/mcp");
|
|
180
|
+
if (options.http) {
|
|
181
|
+
// Here --port is the LISTEN port, not the daemon's: the daemon is found from the
|
|
182
|
+
// home (ant0d.pid), $ANT0D_HOST and $ANT0D_PORT, and the two must differ.
|
|
183
|
+
// The only stdout line in this mode, written after the bind succeeded (no token).
|
|
184
|
+
await mcp.serveDesktopLocalFromStdin(stdin, {
|
|
185
|
+
...(ctx.globals.home !== undefined ? { home: ctx.globals.home } : {}),
|
|
186
|
+
listenPort: ctx.globals.port,
|
|
187
|
+
env: ctx.io.env,
|
|
188
|
+
...(ctx.io.signal ? { signal: ctx.io.signal } : {}),
|
|
189
|
+
}, (handle) => void ctx.io.stdout.write(`ant0: mcp: listening 127.0.0.1:${handle.port}\n`));
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
await mcp.serveStdio({
|
|
193
|
+
...(ctx.globals.home !== undefined ? { home: ctx.globals.home } : {}),
|
|
194
|
+
...(ctx.globals.port !== undefined ? { port: ctx.globals.port } : {}),
|
|
195
|
+
...(ctx.globals.credentialFile !== undefined
|
|
196
|
+
? { credentialFile: ctx.globals.credentialFile }
|
|
197
|
+
: {}),
|
|
198
|
+
env: ctx.io.env,
|
|
199
|
+
stdin,
|
|
200
|
+
stdout: ctx.io.stdout,
|
|
201
|
+
...(ctx.io.signal ? { signal: ctx.io.signal } : {}),
|
|
202
|
+
}, ctx.runtime?.outputWorker);
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
if (mcp && error instanceof mcp.PortInUseFailure)
|
|
206
|
+
throw new CliError("mcp: port in use");
|
|
207
|
+
if (mcp && error instanceof mcp.McpFailure) {
|
|
208
|
+
if (error.code === "unavailable")
|
|
209
|
+
throw new DaemonNotRunningError("mcp: local daemon unavailable");
|
|
210
|
+
throw new CliError(`mcp: ${error.message}`);
|
|
211
|
+
}
|
|
212
|
+
throw new CliError("mcp: adapter failed");
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
return program;
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=program.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import type { OutputWorkerCommand } from "@ant0/mcp";
|
|
3
|
+
import type { Context } from "./context.js";
|
|
4
|
+
/** A program and its leading arguments, spawned to start the daemon. */
|
|
5
|
+
export interface DaemonCommand {
|
|
6
|
+
readonly command: string;
|
|
7
|
+
readonly args: readonly string[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Hooks for an embedding host that supplies its own daemon launcher and lifecycle commands. The
|
|
11
|
+
* ordinary CLI passes none: it starts the daemon found by `resolveDaemonCommand` and registers
|
|
12
|
+
* the built-in `daemon` command group.
|
|
13
|
+
*/
|
|
14
|
+
export interface RuntimeCommands {
|
|
15
|
+
readonly daemon: DaemonCommand;
|
|
16
|
+
readonly outputWorker: OutputWorkerCommand;
|
|
17
|
+
/** Registers the host's lifecycle commands in place of the built-in `daemon` group. */
|
|
18
|
+
readonly registerLifecycle?: (program: Command, ctx: Context) => void;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=runtime-types.d.ts.map
|
package/dist/set.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Manifest paths whose value is a list (the profile manifest). */
|
|
2
|
+
export declare const ARRAY_PATHS: ReadonlySet<string>;
|
|
3
|
+
export type Scalar = string | number | boolean | null;
|
|
4
|
+
export declare function parseScalar(raw: string): Scalar;
|
|
5
|
+
export declare function parseSetValue(raw: string, path: string): unknown;
|
|
6
|
+
/** Parse one `key=value` pair. */
|
|
7
|
+
export declare function parseSetPair(item: string): {
|
|
8
|
+
path: string;
|
|
9
|
+
value: unknown;
|
|
10
|
+
};
|
|
11
|
+
/** Assign `value` at the dotted `path` inside `target`, creating intermediate objects. */
|
|
12
|
+
export declare function assignPath(target: Record<string, unknown>, path: string, value: unknown): void;
|
|
13
|
+
/** Build the PATCH body from every `--set` argument. */
|
|
14
|
+
export declare function parseSetArgs(items: readonly string[]): Record<string, unknown>;
|
|
15
|
+
//# sourceMappingURL=set.d.ts.map
|
package/dist/set.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `--set key=value` parsing for `ant0 profiles edit`.
|
|
3
|
+
*
|
|
4
|
+
* Keys are dotted paths into the PATCH body (`network.geo.timezone`). Values: `true`/`false`,
|
|
5
|
+
* `null`, numbers, comma lists (`tags=a,b`), and JSON when the value starts with `[`, `{` or `"`
|
|
6
|
+
* (the way to force a string containing commas or digits: `--set 'notes="1,2"'`). Paths known to
|
|
7
|
+
* hold arrays are always sent as arrays, so `--set tags=a` yields `["a"]`.
|
|
8
|
+
*/
|
|
9
|
+
import { UsageError } from "./errors.js";
|
|
10
|
+
const KEY_RE = /^[A-Za-z_][\w-]*(\.[A-Za-z_][\w-]*)*$/;
|
|
11
|
+
/** Manifest paths whose value is a list (the profile manifest). */
|
|
12
|
+
export const ARRAY_PATHS = new Set([
|
|
13
|
+
"tags",
|
|
14
|
+
"network.geo.languages",
|
|
15
|
+
"launch.start_urls",
|
|
16
|
+
"launch.extensions",
|
|
17
|
+
"launch.extra_args",
|
|
18
|
+
]);
|
|
19
|
+
export function parseScalar(raw) {
|
|
20
|
+
const text = raw.trim();
|
|
21
|
+
if (text === "true")
|
|
22
|
+
return true;
|
|
23
|
+
if (text === "false")
|
|
24
|
+
return false;
|
|
25
|
+
if (text === "null")
|
|
26
|
+
return null;
|
|
27
|
+
if (/^-?\d+(\.\d+)?$/.test(text))
|
|
28
|
+
return Number(text);
|
|
29
|
+
return text;
|
|
30
|
+
}
|
|
31
|
+
export function parseSetValue(raw, path) {
|
|
32
|
+
const text = raw.trim();
|
|
33
|
+
if (text.startsWith("[") || text.startsWith("{") || text.startsWith('"')) {
|
|
34
|
+
try {
|
|
35
|
+
return JSON.parse(text);
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
throw new UsageError(`--set ${path}: invalid JSON value (${err.message})`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (ARRAY_PATHS.has(path)) {
|
|
42
|
+
if (text === "")
|
|
43
|
+
return [];
|
|
44
|
+
return text.split(",").map((part) => parseScalar(part));
|
|
45
|
+
}
|
|
46
|
+
if (text.includes(","))
|
|
47
|
+
return text.split(",").map((part) => parseScalar(part));
|
|
48
|
+
return parseScalar(text);
|
|
49
|
+
}
|
|
50
|
+
/** Parse one `key=value` pair. */
|
|
51
|
+
export function parseSetPair(item) {
|
|
52
|
+
const eq = item.indexOf("=");
|
|
53
|
+
if (eq <= 0)
|
|
54
|
+
throw new UsageError(`--set expects key=value, got "${item}"`);
|
|
55
|
+
const path = item.slice(0, eq).trim();
|
|
56
|
+
if (!KEY_RE.test(path))
|
|
57
|
+
throw new UsageError(`--set: invalid key "${path}"`);
|
|
58
|
+
return { path, value: parseSetValue(item.slice(eq + 1), path) };
|
|
59
|
+
}
|
|
60
|
+
/** Assign `value` at the dotted `path` inside `target`, creating intermediate objects. */
|
|
61
|
+
export function assignPath(target, path, value) {
|
|
62
|
+
const parts = path.split(".");
|
|
63
|
+
let node = target;
|
|
64
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
65
|
+
const key = parts[i];
|
|
66
|
+
const next = node[key];
|
|
67
|
+
if (next === null || typeof next !== "object" || Array.isArray(next)) {
|
|
68
|
+
const fresh = {};
|
|
69
|
+
node[key] = fresh;
|
|
70
|
+
node = fresh;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
node = next;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
node[parts[parts.length - 1]] = value;
|
|
77
|
+
}
|
|
78
|
+
/** Build the PATCH body from every `--set` argument. */
|
|
79
|
+
export function parseSetArgs(items) {
|
|
80
|
+
const body = {};
|
|
81
|
+
for (const item of items) {
|
|
82
|
+
const { path, value } = parseSetPair(item);
|
|
83
|
+
assignPath(body, path, value);
|
|
84
|
+
}
|
|
85
|
+
return body;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=set.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Thrown by the text parsers (proxy lines/URLs, cookies, CSV) on malformed input. */
|
|
2
|
+
export declare class ParseError extends Error {
|
|
3
|
+
readonly name = "ParseError";
|
|
4
|
+
constructor(message: string, options?: ErrorOptions);
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=parse-error.d.ts.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { ProxyCreate } from "./proxy-types.js";
|
|
2
|
+
/**
|
|
3
|
+
* This module must stay side-effect free and renderer-safe: it is published as the
|
|
4
|
+
* `@ant0/schemas/proxy-parse` subpath so the desktop webview can use it without the package barrel
|
|
5
|
+
* (which compiles Ajv validators at import and needs `unsafe-eval`). Import only `./errors.js` and
|
|
6
|
+
* types; no Node built-ins, no top-level work.
|
|
7
|
+
*/
|
|
8
|
+
/** Stable, input-free reason for a rejected line (see {@link inspectProxyLine}). */
|
|
9
|
+
export type ProxyParseCode = "empty" | "whitespace" | "not_url" | "bad_scheme" | "has_path" | "missing_host" | "bad_host" | "bad_ipv6_host" | "bad_port" | "port_range" | "ipv6_bracket" | "ipv6_bare" | "missing_port" | "trailing" | "bad_encoding" | "socks4_password" | "expected_form";
|
|
10
|
+
export interface ParsedHostPort {
|
|
11
|
+
host: string;
|
|
12
|
+
port: number;
|
|
13
|
+
}
|
|
14
|
+
/** Display form used for default names: IPv6 hosts are bracketed. */
|
|
15
|
+
export declare function formatHostPort(host: string, port: number): string;
|
|
16
|
+
/** Outcome of {@link inspectProxyLine}. */
|
|
17
|
+
export type ProxyLineInspection = {
|
|
18
|
+
ok: true;
|
|
19
|
+
proxy: ProxyCreate;
|
|
20
|
+
} | {
|
|
21
|
+
ok: false;
|
|
22
|
+
code: ProxyParseCode;
|
|
23
|
+
/** The same generic message `parseProxyLine` throws. */
|
|
24
|
+
message: string;
|
|
25
|
+
/**
|
|
26
|
+
* The offending piece of the input (host, port text, scheme, trailing text), when the
|
|
27
|
+
* code has one. It can contain user input: show it on screen to the person who typed it,
|
|
28
|
+
* but never log it, send it anywhere or put it in an error.
|
|
29
|
+
*/
|
|
30
|
+
fragment?: string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* `parseProxyLine` as a result instead of a throw, with the stable failure code (and the
|
|
34
|
+
* offending fragment) so a UI can phrase its own message. Same grammar, same checks, same order.
|
|
35
|
+
* Unlike a thrown error, a failure here may carry input fragments; see {@link ProxyLineInspection}.
|
|
36
|
+
*/
|
|
37
|
+
export declare function inspectProxyLine(line: string): ProxyLineInspection;
|
|
38
|
+
/**
|
|
39
|
+
* Parse `scheme://[user[:pass]@]host[:port][/]` for `http`, `https`, `socks5` (and `socks5h`,
|
|
40
|
+
* mapped to `socks5`) and `socks4` (and `socks4a`, mapped to `socks4`; no password). Credentials before `@` are percent-decoded; a raw `@` inside the password
|
|
41
|
+
* is tolerated (the last `@` separates user info from the host). Missing port falls back to
|
|
42
|
+
* 80 / 443 / 1080. The provider export form `scheme://host:port:user:pass` is also accepted;
|
|
43
|
+
* its credentials are taken verbatim (no percent-decoding).
|
|
44
|
+
*
|
|
45
|
+
* @throws {ParseError}
|
|
46
|
+
*/
|
|
47
|
+
export declare function parseProxyUrl(url: string): ProxyCreate;
|
|
48
|
+
/**
|
|
49
|
+
* Parse one provider-style line. Accepted forms (type defaults to `http`):
|
|
50
|
+
*
|
|
51
|
+
* - `host:port`
|
|
52
|
+
* - `host:port:user:pass` (a password may itself contain `:`)
|
|
53
|
+
* - `user:pass@host:port`
|
|
54
|
+
* - `scheme://...` (delegates to `parseProxyUrl`)
|
|
55
|
+
*
|
|
56
|
+
* IPv6 hosts must be bracketed, e.g. `[2001:db8::1]:1080:user:pass`.
|
|
57
|
+
*
|
|
58
|
+
* @throws {ParseError}
|
|
59
|
+
*/
|
|
60
|
+
export declare function parseProxyLine(line: string): ProxyCreate;
|
|
61
|
+
export interface ProxyLineError {
|
|
62
|
+
/** 1-based line number in the input text. */
|
|
63
|
+
line: number;
|
|
64
|
+
message: string;
|
|
65
|
+
}
|
|
66
|
+
export interface ParsedProxyLines {
|
|
67
|
+
proxies: ProxyCreate[];
|
|
68
|
+
errors: ProxyLineError[];
|
|
69
|
+
}
|
|
70
|
+
/** Parse a multi-line provider export; blank lines and `#` comments are skipped. */
|
|
71
|
+
export declare function parseProxyLines(text: string): ParsedProxyLines;
|
|
72
|
+
//# sourceMappingURL=proxy-parse.d.ts.map
|