@eum-agent/network-proxy 1.1.0 → 1.2.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/dist/index.js +18 -21
- package/package.json +4 -4
- package/ui/ui.js +1 -2
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { dirname } from "node:path";
|
|
1
2
|
import { existsSync } from "node:fs";
|
|
2
3
|
import { fileURLToPath } from "node:url";
|
|
3
4
|
import { z } from "zod";
|
|
4
5
|
import { createHash, randomUUID } from "node:crypto";
|
|
5
6
|
import { BlockList, isIP } from "node:net";
|
|
6
7
|
//#region src/bypass-schema.ts
|
|
7
|
-
/** Supported bypass syntax, shared by persisted and discovered routes. */
|
|
8
8
|
const ProxyBypassSchema = z.string().max(4096).refine((value) => value.split(",").every((raw) => {
|
|
9
9
|
const rule = raw.trim().toLowerCase();
|
|
10
10
|
if (!rule || rule === "*" || rule === "<local>") return true;
|
|
@@ -27,7 +27,6 @@ const ProxyBypassSchema = z.string().max(4096).refine((value) => value.split(","
|
|
|
27
27
|
}), "proxy-bypass-unsupported");
|
|
28
28
|
//#endregion
|
|
29
29
|
//#region src/windows-proxy.ts
|
|
30
|
-
/** Converts the supported fixed Windows grammar without widening bypass matching. */
|
|
31
30
|
function windowsProxy(snapshot) {
|
|
32
31
|
if (snapshot.autoDetect || snapshot.autoConfigUrl.trim()) throw new Error("proxy-pac-unsupported");
|
|
33
32
|
const endpoint = (value) => {
|
|
@@ -78,7 +77,6 @@ function windowsProxy(snapshot) {
|
|
|
78
77
|
}
|
|
79
78
|
//#endregion
|
|
80
79
|
//#region src/resolve.ts
|
|
81
|
-
/** Validates a fixed, unauthenticated HTTP proxy without exposing the input in errors. */
|
|
82
80
|
function proxyUrl(value) {
|
|
83
81
|
let url;
|
|
84
82
|
try {
|
|
@@ -95,7 +93,6 @@ function bypassRules(value) {
|
|
|
95
93
|
if (!ProxyBypassSchema.safeParse(value).success) throw new Error("proxy-bypass-unsupported");
|
|
96
94
|
return value;
|
|
97
95
|
}
|
|
98
|
-
/** Resolves fixed proxy settings without contacting any endpoint. */
|
|
99
96
|
function resolveProxy(settings, env, system, platform = process.platform) {
|
|
100
97
|
if (settings.mode === "direct") return {
|
|
101
98
|
source: "direct",
|
|
@@ -152,11 +149,9 @@ function resolveProxy(settings, env, system, platform = process.platform) {
|
|
|
152
149
|
noProxy: bypassRules(noProxy.join(","))
|
|
153
150
|
};
|
|
154
151
|
}
|
|
155
|
-
/** Produces stable identities for approval and connection snapshots, never raw environment. */
|
|
156
152
|
function proxyRevision(value) {
|
|
157
153
|
return createHash("sha256").update(JSON.stringify(value)).digest("hex").slice(0, 24);
|
|
158
154
|
}
|
|
159
|
-
/** Tests a URL against explicit bypass patterns, without DNS lookup or authorization. */
|
|
160
155
|
function bypassesProxy(url, patterns) {
|
|
161
156
|
const host = url.hostname.toLowerCase().replace(/^\[|\]$/g, "").replace(/\.$/, "");
|
|
162
157
|
const port = url.port || (url.protocol === "https:" ? "443" : "80");
|
|
@@ -188,7 +183,6 @@ function bypassesProxy(url, patterns) {
|
|
|
188
183
|
return host === name;
|
|
189
184
|
});
|
|
190
185
|
}
|
|
191
|
-
/** Creates consistent upper/lowercase child variables, or no variables for direct routes. */
|
|
192
186
|
function proxyEnvironment(proxy, platform = process.platform) {
|
|
193
187
|
if (proxy.error) throw new Error(proxy.error);
|
|
194
188
|
const env = {};
|
|
@@ -206,7 +200,6 @@ function proxyEnvironment(proxy, platform = process.platform) {
|
|
|
206
200
|
}
|
|
207
201
|
//#endregion
|
|
208
202
|
//#region src/system.ts
|
|
209
|
-
/** GNOME fixed proxy settings; absence of a desktop settings reader means no OS proxy. */
|
|
210
203
|
async function readLinuxProxy(host) {
|
|
211
204
|
const execute = async (command, args) => {
|
|
212
205
|
const result = await host.execute(command, args);
|
|
@@ -254,7 +247,6 @@ async function readLinuxProxy(host) {
|
|
|
254
247
|
const exceptions = entries ? entries.split(",").map((entry) => string(entry.trim())) : [];
|
|
255
248
|
return `<dictionary> {\n HTTPEnable : ${httpHost ? 1 : 0}\n HTTPProxy : ${httpHost}\n HTTPPort : ${httpPort}\n HTTPSEnable : ${httpsHost ? 1 : 0}\n HTTPSProxy : ${httpsHost}\n HTTPSPort : ${same === "true" ? httpPort : httpsPort}\n ExceptionsList : <array> {\n${exceptions.map((host, index) => `${index} : ${host}`).join("\n")}\n }\n}`;
|
|
256
249
|
}
|
|
257
|
-
/** Reads the machine's fixed proxy settings with bounded output and duration. */
|
|
258
250
|
async function readSystemProxy(host) {
|
|
259
251
|
if (host.platform === "win32") return host.windows();
|
|
260
252
|
if (host.platform === "linux") return readLinuxProxy(host);
|
|
@@ -265,8 +257,7 @@ async function readSystemProxy(host) {
|
|
|
265
257
|
}
|
|
266
258
|
//#endregion
|
|
267
259
|
//#region src/service.ts
|
|
268
|
-
|
|
269
|
-
function createRoutingPolicy(settings, host, signal, options = {}) {
|
|
260
|
+
function createRoutingPolicy(settings, host, signal, options) {
|
|
270
261
|
const env = { ...host.environment };
|
|
271
262
|
const epoch = randomUUID();
|
|
272
263
|
let generation = 0;
|
|
@@ -309,6 +300,7 @@ function createRoutingPolicy(settings, host, signal, options = {}) {
|
|
|
309
300
|
resolved = resolveProxy(saved, env, await system(refresh), host.platform);
|
|
310
301
|
}
|
|
311
302
|
} catch (error) {
|
|
303
|
+
if (error instanceof Error && error.message === "system-proxy-unavailable") cached = void 0;
|
|
312
304
|
resolved = {
|
|
313
305
|
source: saved.mode === "system" ? Object.entries(env).some(([key, value]) => /^(?:https?|all)_proxy$/i.test(key) && value?.trim()) ? "environment" : "system" : saved.mode,
|
|
314
306
|
noProxy: "",
|
|
@@ -343,7 +335,16 @@ function createRoutingPolicy(settings, host, signal, options = {}) {
|
|
|
343
335
|
},
|
|
344
336
|
async snapshot() {
|
|
345
337
|
const effective = (await status()).effective;
|
|
346
|
-
if (effective.error)
|
|
338
|
+
if (effective.error) {
|
|
339
|
+
const unavailable = effective.error === "system-proxy-unavailable";
|
|
340
|
+
throw options.failures.create({
|
|
341
|
+
code: unavailable ? "proxy-unavailable" : "proxy-unsupported",
|
|
342
|
+
stage: "transport",
|
|
343
|
+
category: "network",
|
|
344
|
+
source: "transport",
|
|
345
|
+
retryable: unavailable
|
|
346
|
+
}, { cause: new Error(effective.error) });
|
|
347
|
+
}
|
|
347
348
|
return {
|
|
348
349
|
revision: effective.revision,
|
|
349
350
|
proxyFor(input) {
|
|
@@ -363,7 +364,6 @@ function createRoutingPolicy(settings, host, signal, options = {}) {
|
|
|
363
364
|
}
|
|
364
365
|
//#endregion
|
|
365
366
|
//#region src/settings-schema.ts
|
|
366
|
-
/** Connection routing only; changing it never grants network access. */
|
|
367
367
|
const ProxySettingsSchema = z.discriminatedUnion("mode", [
|
|
368
368
|
z.object({ mode: z.literal("system") }).strict(),
|
|
369
369
|
z.object({ mode: z.literal("direct") }).strict(),
|
|
@@ -380,7 +380,6 @@ const ProxySettingsSchema = z.discriminatedUnion("mode", [
|
|
|
380
380
|
noProxy: ProxyBypassSchema.default("")
|
|
381
381
|
}).strict()
|
|
382
382
|
]);
|
|
383
|
-
/** Resolved routing without credentials or raw OS output. */
|
|
384
383
|
const EffectiveProxySchema = z.object({
|
|
385
384
|
source: z.enum([
|
|
386
385
|
"manual",
|
|
@@ -394,21 +393,18 @@ const EffectiveProxySchema = z.object({
|
|
|
394
393
|
revision: z.string(),
|
|
395
394
|
error: z.string().optional()
|
|
396
395
|
}).strict();
|
|
397
|
-
/** Authenticated settings response, including failures resolving system settings. */
|
|
398
396
|
const ProxyStatusSchema = z.object({
|
|
399
397
|
settings: ProxySettingsSchema,
|
|
400
398
|
effective: EffectiveProxySchema
|
|
401
399
|
}).strict();
|
|
402
400
|
//#endregion
|
|
403
401
|
//#region src/settings.ts
|
|
404
|
-
/** Persists validated routing preferences in the producing owner's cooperative storage. */
|
|
405
402
|
function createNetworkSettings(storage) {
|
|
406
403
|
const name = storage.tableName("routing_settings");
|
|
407
404
|
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) throw new Error("invalid routing table identity");
|
|
408
405
|
const table = `"${name}"`;
|
|
409
406
|
storage.db.exec(`CREATE TABLE IF NOT EXISTS ${table} (id INTEGER NOT NULL PRIMARY KEY CHECK(id=1), settings_json TEXT NOT NULL)`);
|
|
410
407
|
storage.db.prepare(`INSERT OR IGNORE INTO ${table}(id,settings_json) VALUES(1,?)`).run("{\"mode\":\"system\"}");
|
|
411
|
-
/** Reads validated preferences from owner storage; damaged stored data refuses activation. */
|
|
412
408
|
function read() {
|
|
413
409
|
const row = storage.db.prepare(`SELECT settings_json FROM ${table} WHERE id=1`).get();
|
|
414
410
|
return ProxySettingsSchema.parse(JSON.parse(row.settings_json));
|
|
@@ -416,7 +412,6 @@ function createNetworkSettings(storage) {
|
|
|
416
412
|
read();
|
|
417
413
|
return {
|
|
418
414
|
read,
|
|
419
|
-
/** Commits validated preferences; any failure leaves the previous value intact. */
|
|
420
415
|
write(input) {
|
|
421
416
|
const next = ProxySettingsSchema.parse(input);
|
|
422
417
|
storage.db.prepare(`UPDATE ${table} SET settings_json=? WHERE id=1`).run(JSON.stringify(next));
|
|
@@ -425,13 +420,12 @@ function createNetworkSettings(storage) {
|
|
|
425
420
|
}
|
|
426
421
|
//#endregion
|
|
427
422
|
//#region src/index.ts
|
|
428
|
-
/** Owns proxy preferences, routing strategy and browser management for one activation. */
|
|
429
423
|
const plugin = {
|
|
430
424
|
name: "@eum-agent/network-proxy",
|
|
431
425
|
requires: ["network-proxy-host"],
|
|
432
426
|
provides: ["network-routing"],
|
|
433
427
|
apply(ctx) {
|
|
434
|
-
const routing = createRoutingPolicy(createNetworkSettings(ctx.storage.open()), ctx.services.get("network-proxy-host"), ctx.signal);
|
|
428
|
+
const routing = createRoutingPolicy(createNetworkSettings(ctx.storage.open()), ctx.services.get("network-proxy-host"), ctx.signal, { failures: ctx.models.failures });
|
|
435
429
|
ctx.services.provide("network-routing", routing);
|
|
436
430
|
ctx.client.registerMethod({
|
|
437
431
|
name: "proxyGet",
|
|
@@ -452,7 +446,10 @@ const plugin = {
|
|
|
452
446
|
handle: (input) => routing.set(input)
|
|
453
447
|
});
|
|
454
448
|
const module = fileURLToPath(new URL("../ui/ui.js", import.meta.url));
|
|
455
|
-
if (existsSync(module)) ctx.client.
|
|
449
|
+
if (existsSync(module)) ctx.client.registerPackageFiles({
|
|
450
|
+
root: dirname(module),
|
|
451
|
+
entry: "ui.js"
|
|
452
|
+
});
|
|
456
453
|
}
|
|
457
454
|
};
|
|
458
455
|
//#endregion
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"en-US": "Network Proxy",
|
|
5
5
|
"zh-CN": "网络代理"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.
|
|
7
|
+
"version": "1.2.0",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"description": "Outbound proxy routing and preferences",
|
|
10
10
|
"license": "MIT",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"zod": "^4.4.3"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@eum-agent/plugin": "1.
|
|
24
|
+
"@eum-agent/plugin": "1.2.0",
|
|
25
25
|
"@types/react": "^19.2.18",
|
|
26
26
|
"@types/react-dom": "^19.2.5",
|
|
27
27
|
"react": "^19.2.0",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {},
|
|
42
42
|
"foundationDependencies": {
|
|
43
|
-
"@eum-agent/infra-local": "1.0
|
|
44
|
-
"@eum-agent/storage-sqlite": "1.
|
|
43
|
+
"@eum-agent/infra-local": "1.2.0",
|
|
44
|
+
"@eum-agent/storage-sqlite": "1.2.0"
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
package/ui/ui.js
CHANGED
|
@@ -397,8 +397,7 @@ function NetworkPanel({ api }) {
|
|
|
397
397
|
}),
|
|
398
398
|
children: /* @__PURE__ */ jsx(RefreshCw, {
|
|
399
399
|
"aria-hidden": "true",
|
|
400
|
-
className: "size-3.5"
|
|
401
|
-
strokeWidth: 1.75
|
|
400
|
+
className: "size-3.5"
|
|
402
401
|
})
|
|
403
402
|
}), /* @__PURE__ */ jsx(TooltipContent, {
|
|
404
403
|
side: "top",
|